gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
ExtractElements.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 "ExtractElements.h"
7 #include "Numeric.h"
8 
10  {GMSH_FULLRC, "MinVal", nullptr, 0.},
11  {GMSH_FULLRC, "MaxVal", nullptr, 0.},
12  {GMSH_FULLRC, "TimeStep", nullptr, 0.},
13  {GMSH_FULLRC, "Visible", nullptr, 1.},
14  {GMSH_FULLRC, "Dimension", nullptr, -1.},
15  {GMSH_FULLRC, "View", nullptr, -1.}};
16 
17 extern "C" {
19 {
20  return new GMSH_ExtractElementsPlugin();
21 }
22 }
23 
25 {
26  return "Plugin(ExtractElements) extracts some elements "
27  "from the view `View'. If `MinVal' != `MaxVal', it extracts "
28  "the elements whose `TimeStep'-th values (averaged by element) "
29  "are comprised between `MinVal' and `MaxVal'. If `Visible' != 0, "
30  "it extracts visible elements. "
31  "\n\n"
32  "If `View' < 0, the plugin is run on the current view.\n\n"
33  "Plugin(ExtractElements) creates one new list-based view.";
34 }
35 
37 {
38  return sizeof(ExtractElementsOptions_Number) / sizeof(StringXNumber);
39 }
40 
42 {
43  return &ExtractElementsOptions_Number[iopt];
44 }
45 
47 {
48  double MinVal = ExtractElementsOptions_Number[0].def;
49  double MaxVal = ExtractElementsOptions_Number[1].def;
50  int thisStep = (int)ExtractElementsOptions_Number[2].def;
51  int visible = (int)ExtractElementsOptions_Number[3].def;
52  int dimension = (int)ExtractElementsOptions_Number[4].def;
53  int iView = (int)ExtractElementsOptions_Number[5].def;
54 
55  PView *v1 = getView(iView, v);
56  if(!v1) return v;
58  bool checkMinMax = MinVal != MaxVal;
59 
60  int step = (thisStep < 0) ? 0 : thisStep;
61  if(thisStep > data1->getNumTimeSteps() - 1) {
62  Msg::Error("Invalid time step (%d) in View[%d]: using first step instead",
63  thisStep, v1->getIndex());
64  step = 0;
65  }
66 
67  PView *v2 = new PView();
68  PViewDataList *data2 = getDataList(v2);
69 
70  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
71  if(visible && data1->skipEntity(step, ent)) continue;
72  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
73  if(data1->skipElement(step, ent, ele, visible)) continue;
74 
75  int dim = data1->getDimension(step, ent, ele);
76  if((dimension > 0) && (dim != dimension)) continue;
77 
78  int numNodes = data1->getNumNodes(step, ent, ele);
79  if(checkMinMax) {
80  double d = 0.;
81  for(int nod = 0; nod < numNodes; nod++) {
82  double val;
83  data1->getScalarValue(step, ent, ele, nod, val);
84  d += val;
85  }
86  d /= (double)numNodes;
87  // use '>=' and '<' so that we can do segmentation without
88  // worrying about roundoff errors
89  if(d < MinVal || d >= MaxVal) continue;
90  }
91 
92  int type = data1->getType(step, ent, ele);
93  int numComp = data1->getNumComponents(step, ent, ele);
94  std::vector<double> *out = data2->incrementList(numComp, type, numNodes);
95  std::vector<double> x(numNodes), y(numNodes), z(numNodes);
96  std::vector<double> v(numNodes * numComp);
97  for(int nod = 0; nod < numNodes; nod++)
98  data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]);
99  for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]);
100  for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
101  for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]);
102 
103  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
104  if(!data1->hasTimeStep(step)) continue;
105  if((thisStep >= 0) && (thisStep != step)) continue;
106 
107  for(int nod = 0; nod < numNodes; nod++) {
108  for(int comp = 0; comp < numComp; comp++) {
109  double temp;
110  data1->getValue(step, ent, ele, nod, comp, temp);
111  out->push_back(temp);
112  }
113  }
114  }
115  }
116  }
117 
118  if(thisStep >= 0)
119  data2->Time.push_back(data1->getTime(thisStep));
120  else {
121  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
122  data2->Time.push_back(data1->getTime(step));
123  }
124  }
125 
126  data2->setName(data1->getName() + "_ExtractElements");
127  data2->setFileName(data1->getName() + "_ExtractElements.pos");
128  data2->finalize();
129 
130  return v2;
131 }
PView
Definition: PView.h:27
PViewData::skipElement
virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, int samplingRate=1)
Definition: PViewData.cpp:90
GMSH_Plugin
Definition: Plugin.h:26
StringXNumber::def
double def
Definition: Options.h:922
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
PViewDataList
Definition: PViewDataList.h:17
GMSH_ExtractElementsPlugin
Definition: ExtractElements.h:15
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
ExtractElements.h
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
PView::getIndex
int getIndex()
Definition: PView.h:92
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
dimension
int dimension
Definition: GModelIO_TOCHNOG.cpp:18
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
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_RegisterExtractElementsPlugin
GMSH_Plugin * GMSH_RegisterExtractElementsPlugin()
Definition: ExtractElements.cpp:18
PViewData::getScalarValue
void getScalarValue(int step, int ent, int ele, int nod, double &val, int tensorRep=0, int forceNumComponents=0, int componentMap[9]=nullptr)
Definition: PViewData.cpp:97
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
Numeric.h
PViewData::hasTimeStep
virtual bool hasTimeStep(int step)
Definition: PViewData.h:211
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
GMSH_ExtractElementsPlugin::execute
PView * execute(PView *)
Definition: ExtractElements.cpp:46
PViewData
Definition: PViewData.h:29
PViewData::getNumComponents
virtual int getNumComponents(int step, int ent, int ele)
Definition: PViewData.h:152
z
const double z
Definition: GaussQuadratureQuad.cpp:56
GMSH_ExtractElementsPlugin::getHelp
std::string getHelp() const
Definition: ExtractElements.cpp:24
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
GMSH_PostPlugin::getPossiblyAdaptiveData
virtual PViewData * getPossiblyAdaptiveData(PView *view)
Definition: Plugin.cpp:94
PViewDataList::Time
std::vector< double > Time
Definition: PViewDataList.h:25
GMSH_ExtractElementsPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: ExtractElements.cpp:41
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
ExtractElementsOptions_Number
StringXNumber ExtractElementsOptions_Number[]
Definition: ExtractElements.cpp:9
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107
PViewData::skipEntity
virtual bool skipEntity(int step, int ent)
Definition: PViewData.h:206
GMSH_ExtractElementsPlugin::getNbOptions
int getNbOptions() const
Definition: ExtractElements.cpp:36