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