gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Scal2Tens.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 "Scal2Tens.h"
7 #include "PViewOptions.h"
8 #include "shapeFunctions.h"
9 
11  {GMSH_FULLRC, "NumberOfComponents", nullptr, 9},
12  {GMSH_FULLRC, "View0", nullptr, -1},
13  {GMSH_FULLRC, "View1", nullptr, -1},
14  {GMSH_FULLRC, "View2", nullptr, -1},
15  {GMSH_FULLRC, "View3", nullptr, -1},
16  {GMSH_FULLRC, "View4", nullptr, -1},
17  {GMSH_FULLRC, "View5", nullptr, -1},
18  {GMSH_FULLRC, "View6", nullptr, -1},
19  {GMSH_FULLRC, "View7", nullptr, -1},
20  {GMSH_FULLRC, "View8", nullptr, -1}};
21 
23  {GMSH_FULLRC, "NameNewView", nullptr, "NewView"}};
24 
25 extern "C" {
27 {
28  return new GMSH_Scal2TensPlugin();
29 }
30 }
31 
32 std::string GMSH_Scal2TensPlugin::getHelp() const
33 {
34  return "Plugin(Scal2Tens) converts some scalar fields into a tensor field. "
35  "The number of components must be given (max. 9). "
36  "The new view 'NameNewView' contains the new tensor field. If the "
37  "number "
38  "of a view is -1, the value of the corresponding component is 0.";
39 }
40 
42 {
43  return sizeof(Scal2TensOptions_Number) / sizeof(StringXNumber);
44 }
45 
47 {
48  return &Scal2TensOptions_Number[iopt];
49 }
50 
52 {
53  return sizeof(Scal2TensOptions_String) / sizeof(StringXString);
54 }
55 
57 {
58  return &Scal2TensOptions_String[iopt];
59 }
60 
62 {
63  // Load options
64  int numComp = (int)Scal2TensOptions_Number[0].def;
65  if((numComp < 1) || (numComp > 9)) {
66  Msg::Error(
67  "Scal2Tens plugin: NumberOfComponents must be between 1 and 9 (not '%i')",
68  numComp);
69  return v;
70  }
71  int iView[9];
72  for(int comp = 0; comp < numComp; comp++)
73  iView[comp] = (int)Scal2TensOptions_Number[comp + 1].def;
74 
75  // Load data
76  PView *vRef = nullptr, *vComp[9];
77  for(int comp = 0; comp < numComp; comp++) {
78  if(iView[comp] < 0)
79  vComp[comp] = nullptr;
80  else {
81  vComp[comp] = getView(iView[comp], v);
82  if(!vComp[comp]) {
83  Msg::Error("Scal2Tens plugin could not find View '%i'", iView[comp]);
84  return v;
85  }
86  if(!vRef) vRef = vComp[comp];
87  }
88  }
89  if(!vRef) {
90  Msg::Error("Scal2Tens plugin could not find any view.");
91  return v;
92  }
93  PViewData *dataRef = vRef->getData();
94 
95  // Initialize the new view
96  PView *vNew = new PView();
97  PViewDataList *dataNew = getDataList(vNew);
98 
99  int step0 = dataRef->getFirstNonEmptyTimeStep();
100  for(int ent = 0; ent < dataRef->getNumEntities(step0); ent++) {
101  for(int ele = 0; ele < dataRef->getNumElements(step0, ent); ele++) {
102  if(dataRef->skipElement(step0, ent, ele)) continue;
103  int type = dataRef->getType(step0, ent, ele);
104  int numNodes = dataRef->getNumNodes(step0, ent, ele);
105  std::vector<double> *out = dataNew->incrementList(
106  numComp, type, numNodes); // Pointer in data of the new view
107  if(!out) continue;
108  double x[8], y[8], z[8];
109  for(int nod = 0; nod < numNodes; nod++)
110  dataRef->getNode(step0, ent, ele, nod, x[nod], y[nod], z[nod]);
111  int dim = dataRef->getDimension(step0, ent, ele);
112  elementFactory factory;
113  element *element = factory.create(numNodes, dim, x, y, z);
114  if(!element) continue;
115  for(int nod = 0; nod < numNodes; nod++)
116  out->push_back(x[nod]); // Save coordinates (x,y,z)
117  for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
118  for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]);
119  for(int step = step0; step < dataRef->getNumTimeSteps(); step++) {
120  if(!dataRef->hasTimeStep(step)) continue;
121  for(int nod = 0; nod < numNodes; nod++) {
122  for(int comp = 0; comp < numComp; comp++) {
123  double val = 0.;
124  if(vComp[comp])
125  vComp[comp]->getData()->getValue(step, ent, ele, nod, 0, val);
126  out->push_back(val); // Save value
127  }
128  }
129  }
130  delete element;
131  }
132  }
133 
134  for(int step = step0; step < dataRef->getNumTimeSteps(); step++) {
135  if(!dataRef->hasTimeStep(step)) continue;
136  dataNew->Time.push_back(dataRef->getTime(step));
137  }
138 
139  std::string nameNewView = Scal2TensOptions_String[0].def;
140  dataNew->setName(nameNewView);
141  dataNew->setFileName(nameNewView + ".pos");
142  dataNew->finalize();
143 
144  return vNew;
145 }
StringXString
Definition: Options.h:910
GMSH_Scal2TensPlugin
Definition: Scal2Tens.h:15
PView
Definition: PView.h:27
GMSH_Scal2TensPlugin::getNbOptionsStr
int getNbOptionsStr() const
Definition: Scal2Tens.cpp:51
GMSH_Scal2TensPlugin::getNbOptions
int getNbOptions() const
Definition: Scal2Tens.cpp:41
PViewData::skipElement
virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, int samplingRate=1)
Definition: PViewData.cpp:90
GMSH_Scal2TensPlugin::getHelp
std::string getHelp() const
Definition: Scal2Tens.cpp:32
GMSH_Plugin
Definition: Plugin.h:26
StringXNumber::def
double def
Definition: Options.h:922
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
Scal2TensOptions_String
StringXString Scal2TensOptions_String[]
Definition: Scal2Tens.cpp:22
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
GMSH_Scal2TensPlugin::execute
PView * execute(PView *)
Definition: Scal2Tens.cpp:61
Scal2Tens.h
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
elementFactory
Definition: shapeFunctions.h:1402
Scal2TensOptions_Number
StringXNumber Scal2TensOptions_Number[]
Definition: Scal2Tens.cpp:10
PViewData::getDimension
virtual int getDimension(int step, int ent, int ele)
Definition: PViewData.h:134
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
PViewData::hasTimeStep
virtual bool hasTimeStep(int step)
Definition: PViewData.h:211
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
GMSH_Scal2TensPlugin::getOptionStr
StringXString * getOptionStr(int iopt)
Definition: Scal2Tens.cpp:56
PViewOptions.h
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
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
StringXString::def
std::string def
Definition: Options.h:914
elementFactory::create
element * create(int numNodes, int dimension, double *x, double *y, double *z, bool copy=false)
Definition: shapeFunctions.h:1404
element
Definition: shapeFunctions.h:12
PViewData
Definition: PViewData.h:29
z
const double z
Definition: GaussQuadratureQuad.cpp:56
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
GMSH_Scal2TensPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Scal2Tens.cpp:46
PViewDataList::Time
std::vector< double > Time
Definition: PViewDataList.h:25
GMSH_RegisterScal2TensPlugin
GMSH_Plugin * GMSH_RegisterScal2TensPlugin()
Definition: Scal2Tens.cpp:26
PViewData::getNumElements
virtual int getNumElements(int step=-1, int ent=-1)
Definition: PViewData.h:131
shapeFunctions.h
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107
PViewData::getFirstNonEmptyTimeStep
virtual int getFirstNonEmptyTimeStep(int start=0)
Definition: PViewData.h:91