gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Eigenvectors.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include "Eigenvectors.h"
7 #include "Numeric.h"
8 #include "fullMatrix.h"
9 #include "GmshDefines.h"
10 
12  {GMSH_FULLRC, "ScaleByEigenvalues", nullptr, 1.},
13  {GMSH_FULLRC, "View", nullptr, -1.}};
14 
15 extern "C" {
17 {
18  return new GMSH_EigenvectorsPlugin();
19 }
20 }
21 
23 {
24  return "Plugin(Eigenvectors) computes the three (right) "
25  "eigenvectors of each tensor in the view `View' "
26  "and sorts them according to the value of the "
27  "associated eigenvalues.\n\n"
28  "If `ScaleByEigenvalues' is set, each eigenvector is "
29  "scaled by its associated eigenvalue. The plugin "
30  "gives an error if the eigenvectors are complex.\n\n"
31  "If `View' < 0, the plugin is run on the current view.\n\n"
32  "Plugin(Eigenvectors) creates three new list-based vector view.";
33 }
34 
36 {
37  return sizeof(EigenvectorsOptions_Number) / sizeof(StringXNumber);
38 }
39 
41 {
42  return &EigenvectorsOptions_Number[iopt];
43 }
44 
46 {
47  int scale = (int)EigenvectorsOptions_Number[0].def;
48  int iView = (int)EigenvectorsOptions_Number[1].def;
49 
50  PView *v1 = getView(iView, v);
51  if(!v1) return v;
52 
54  if(data1->hasMultipleMeshes()) {
55  Msg::Error("Eigenvectors plugin cannot be run on multi-mesh views");
56  return v;
57  }
58 
59  PView *min = new PView();
60  PView *mid = new PView();
61  PView *max = new PView();
62 
63  PViewDataList *dmin = getDataList(min);
64  PViewDataList *dmid = getDataList(mid);
65  PViewDataList *dmax = getDataList(max);
66 
67  int nbcomplex = 0;
68  fullMatrix<double> mat(3, 3), vl(3, 3), vr(3, 3);
69  fullVector<double> dr(3), di(3);
70  for(int ent = 0; ent < data1->getNumEntities(0); ent++) {
71  for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) {
72  if(data1->skipElement(0, ent, ele)) continue;
73  int numComp = data1->getNumComponents(0, ent, ele);
74  if(numComp != 9) continue;
75  int type = data1->getType(0, ent, ele);
76  int numNodes = data1->getNumNodes(0, ent, ele);
77  std::vector<double> *outmin = dmin->incrementList(3, type, numNodes);
78  std::vector<double> *outmid = dmid->incrementList(3, type, numNodes);
79  std::vector<double> *outmax = dmax->incrementList(3, type, numNodes);
80  if(!outmin || !outmid || !outmax) continue;
81  double xyz[3][8];
82  for(int nod = 0; nod < numNodes; nod++)
83  data1->getNode(0, ent, ele, nod, xyz[0][nod], xyz[1][nod], xyz[2][nod]);
84  for(int i = 0; i < 3; i++) {
85  for(int nod = 0; nod < numNodes; nod++) {
86  outmin->push_back(xyz[i][nod]);
87  outmid->push_back(xyz[i][nod]);
88  outmax->push_back(xyz[i][nod]);
89  }
90  }
91  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
92  for(int nod = 0; nod < numNodes; nod++) {
93  for(int i = 0; i < 3; i++)
94  for(int j = 0; j < 3; j++)
95  data1->getValue(step, ent, ele, nod, 3 * i + j, mat(i, j));
96  if(mat.eig(dr, di, vl, vr, true)) {
97  if(!scale) dr(0) = dr(1) = dr(2) = 1.;
98  for(int i = 0; i < 3; i++) {
99  double res;
100  res = dr(0) * vr(i, 0);
101  outmin->push_back(res);
102  res = dr(1) * vr(i, 1);
103  outmid->push_back(res);
104  res = dr(2) * vr(i, 2);
105  outmax->push_back(res);
106  }
107  if(di(0) || di(1) || di(2)) nbcomplex++;
108  }
109  else {
110  Msg::Error("Could not compute eigenvalues/vectors");
111  }
112  }
113  }
114  }
115  }
116 
117  if(nbcomplex) Msg::Error("%d tensors have complex eigenvalues", nbcomplex);
118 
119  for(int i = 0; i < data1->getNumTimeSteps(); i++) {
120  double time = data1->getTime(i);
121  dmin->Time.push_back(time);
122  dmid->Time.push_back(time);
123  dmax->Time.push_back(time);
124  }
125  dmin->setName(data1->getName() + "_MinEigenvectors");
126  dmin->setFileName(data1->getName() + "_MinEigenvectors.pos");
127  dmin->finalize();
128  dmid->setName(data1->getName() + "_MidEigenvectors");
129  dmid->setFileName(data1->getName() + "_MidEigenvectors.pos");
130  dmid->finalize();
131  dmax->setName(data1->getName() + "_MaxEigenvectors");
132  dmax->setFileName(data1->getName() + "_MaxEigenvectors.pos");
133  dmax->finalize();
134 
135  return nullptr;
136 }
PView
Definition: PView.h:27
EigenvectorsOptions_Number
StringXNumber EigenvectorsOptions_Number[]
Definition: Eigenvectors.cpp:11
PViewData::skipElement
virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, int samplingRate=1)
Definition: PViewData.cpp:90
fullVector< double >
GMSH_Plugin
Definition: Plugin.h:26
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
PViewDataList
Definition: PViewDataList.h:17
PViewData::getNode
virtual int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z)
Definition: PViewData.h:141
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
PViewDataList::incrementList
std::vector< double > * incrementList(int numComp, int type, int numNodes=0)
Definition: PViewDataList.cpp:1243
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
GMSH_EigenvectorsPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Eigenvectors.cpp:40
PViewData::hasMultipleMeshes
virtual bool hasMultipleMeshes()
Definition: PViewData.h:216
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
GMSH_EigenvectorsPlugin::getNbOptions
int getNbOptions() const
Definition: Eigenvectors.cpp:35
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
GMSH_EigenvectorsPlugin::execute
PView * execute(PView *)
Definition: Eigenvectors.cpp:45
fullMatrix< double >
PViewData::getTime
virtual double getTime(int step)
Definition: PViewData.h:94
PViewData::getType
virtual int getType(int step, int ent, int ele)
Definition: PViewData.h:183
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
Numeric.h
GMSH_EigenvectorsPlugin
Definition: Eigenvectors.h:15
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
GmshDefines.h
PViewDataList::finalize
bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewDataList.cpp:81
PViewData::setName
virtual void setName(const std::string &val)
Definition: PViewData.h:71
PViewData
Definition: PViewData.h:29
PViewData::getNumComponents
virtual int getNumComponents(int step, int ent, int ele)
Definition: PViewData.h:152
Eigenvectors.h
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
GMSH_EigenvectorsPlugin::getHelp
std::string getHelp() const
Definition: Eigenvectors.cpp:22
GMSH_PostPlugin::getPossiblyAdaptiveData
virtual PViewData * getPossiblyAdaptiveData(PView *view)
Definition: Plugin.cpp:94
PViewDataList::Time
std::vector< double > Time
Definition: PViewDataList.h:25
PViewData::getNumElements
virtual int getNumElements(int step=-1, int ent=-1)
Definition: PViewData.h:131
PViewData::getName
virtual std::string getName()
Definition: PViewData.h:70
fullMatrix.h
GMSH_RegisterEigenvectorsPlugin
GMSH_Plugin * GMSH_RegisterEigenvectorsPlugin()
Definition: Eigenvectors.cpp:16
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107
scale
static void scale(std::vector< double > &x, double s)
Definition: ConjugateGradients.cpp:21