gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Integrate.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 "Integrate.h"
7 #include "shapeFunctions.h"
8 #include "PViewOptions.h"
9 
11  {GMSH_FULLRC, "View", nullptr, -1.},
12  {GMSH_FULLRC, "OverTime", nullptr, -1.},
13  {GMSH_FULLRC, "Dimension", nullptr, -1.},
14  {GMSH_FULLRC, "Visible", nullptr, 1.}};
15 
16 extern "C" {
18 {
19  return new GMSH_IntegratePlugin();
20 }
21 }
22 
23 std::string GMSH_IntegratePlugin::getHelp() const
24 {
25  return "Plugin(Integrate) integrates a scalar field over all the elements "
26  "of the view `View' (if `Dimension' < 0), or over all elements of "
27  "the prescribed dimension (if `Dimension' > 0). If the field is a "
28  "vector field, the circulation/flux of the field over line/surface "
29  "elements is calculated.\n\n"
30  "If `View' < 0, the plugin is run on the current view.\n\n"
31  "If `OverTime' = i > -1 , the plugin integrates the scalar view "
32  "over time (using the trapezoidal rule) instead of over space, "
33  "starting at step i. If `Visible' = 1, the plugin only integrates "
34  "over visible entities.\n\n"
35  "Plugin(Integrate) creates one new list-based view.";
36 }
37 
39 {
40  return sizeof(IntegrateOptions_Number) / sizeof(StringXNumber);
41 }
42 
44 {
45  return &IntegrateOptions_Number[iopt];
46 }
47 
49 {
50  int iView = (int)IntegrateOptions_Number[0].def;
51  int overTime = (int)IntegrateOptions_Number[1].def;
52  int dimension = (int)IntegrateOptions_Number[2].def;
53  bool visible = (bool)IntegrateOptions_Number[3].def;
54 
55  PView *v1 = getView(iView, v);
56  if(!v1) return v;
57 
59  PView *v2 = new PView();
60  PViewDataList *data2 = getDataList(v2);
61 
62  if(overTime == -1) {
63  double x = data1->getBoundingBox().center().x();
64  double y = data1->getBoundingBox().center().y();
65  double z = data1->getBoundingBox().center().z();
66  data2->SP.push_back(x);
67  data2->SP.push_back(y);
68  data2->SP.push_back(z);
69  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
70  double res = 0, resv[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
71  bool simpleSum = false;
72  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
73  if(visible && data1->skipEntity(step, ent)) continue;
74  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
75  if(data1->skipElement(step, ent, ele, visible)) continue;
76  int numComp = data1->getNumComponents(step, ent, ele);
77  int numEdges = data1->getNumEdges(step, ent, ele);
78  bool scalar = (numComp == 1);
79  bool circulation = (numComp == 3 && numEdges == 1);
80  bool flux = (numComp == 3 && (numEdges == 3 || numEdges == 4));
81  int numNodes = data1->getNumNodes(step, ent, ele);
82  int dim = data1->getDimension(step, ent, ele);
83  if((dimension > 0) && (dim != dimension)) continue;
84  double x[8], y[8], z[8], val[8 * 3] = {0.};
85  for(int nod = 0; nod < numNodes; nod++) {
86  data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]);
87  for(int comp = 0; comp < numComp; comp++)
88  data1->getValue(step, ent, ele, nod, comp,
89  val[numComp * nod + comp]);
90  }
91  if(numNodes == 1) {
92  simpleSum = true;
93  res += val[0];
94  for(int comp = 0; comp < numComp; comp++) resv[comp] += val[comp];
95  }
96  else {
97  elementFactory factory;
98  element *element = factory.create(numNodes, dim, x, y, z);
99  if(!element) continue;
100  if(scalar)
101  res += element->integrate(val);
102  else if(circulation)
103  res += element->integrateCirculation(val);
104  else if(flux)
105  res += element->integrateFlux(val);
106  delete element;
107  }
108  }
109  }
110  if(simpleSum)
111  Msg::Info("Step %d: sum = %g %g %g %g %g %g %g %g %g", step, resv[0],
112  resv[1], resv[2], resv[3], resv[4], resv[5], resv[6], resv[7],
113  resv[8]);
114  else
115  Msg::Info("Step %d: integral = %.16g", step, res);
116  data2->SP.push_back(res);
117  }
118  data2->NbSP = 1;
120 
121  for(int i = 0; i < data1->getNumTimeSteps(); i++) {
122  double time = data1->getTime(i);
123  data2->Time.push_back(time);
124  }
125  }
126  else {
127  int firstStep = data1->getFirstNonEmptyTimeStep();
128  int numSteps = data1->getNumTimeSteps();
129  for(int ent = 0; ent < data1->getNumEntities(firstStep); ent++) {
130  for(int ele = 0; ele < data1->getNumElements(firstStep, ent); ele++) {
131  if(data1->skipElement(firstStep, ent, ele)) continue;
132  int dim = data1->getDimension(firstStep, ent, ele);
133  if((dimension > 0) && (dim != dimension)) continue;
134 
135  int numNodes = data1->getNumNodes(firstStep, ent, ele);
136  int type = data1->getType(firstStep, ent, ele);
137  int numComp = data1->getNumComponents(firstStep, ent, ele);
138  if(numComp != 1)
139  Msg::Error("Can only integrate scalar views over time");
140  std::vector<double> *out =
141  data2->incrementList(numComp, type, numNodes);
142  std::vector<double> x(numNodes), y(numNodes), z(numNodes);
143  for(int nod = 0; nod < numNodes; nod++)
144  data1->getNode(firstStep, ent, ele, nod, x[nod], y[nod], z[nod]);
145  for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]);
146  for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
147  for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]);
148 
149  std::vector<double> val, t;
150  for(int step = firstStep + overTime; step < numSteps - 1; step++) {
151  if(!data1->hasTimeStep(step)) continue;
152  t.push_back(data1->getTime(step));
153  for(int nod = 0; nod < numNodes; nod++) {
154  double v;
155  data1->getValue(step, ent, ele, nod, 0, v);
156  val.push_back(v);
157  }
158  }
159  std::vector<double> timeIntegral(numNodes, 0.);
160  for(std::size_t step = 0; step < t.size() - 1; step++) {
161  double dt = t[step + 1] - t[step];
162  for(int nod = 0; nod < numNodes; nod++) {
163  timeIntegral[nod] += 0.5 *
164  (val[step * numNodes + nod] + val[(step + 1) * numNodes + nod]) * dt;
165  }
166  }
167  for(int nod = 0; nod < numNodes; nod++)
168  out->push_back(timeIntegral[nod]);
169  }
170  }
171  }
172 
173  data2->setName(data1->getName() + "_Integrate");
174  data2->setFileName(data1->getName() + "_Integrate.pos");
175  data2->finalize();
176 
177  return v2;
178 }
PViewData::getNumEdges
virtual int getNumEdges(int step, int ent, int ele)
Definition: PViewData.h:180
GMSH_IntegratePlugin::getHelp
std::string getHelp() const
Definition: Integrate.cpp:23
GMSH_RegisterIntegratePlugin
GMSH_Plugin * GMSH_RegisterIntegratePlugin()
Definition: Integrate.cpp:17
PView
Definition: PView.h:27
element::integrate
double integrate(double val[], int stride=1)
Definition: shapeFunctions.h:212
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
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
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::NbSP
int NbSP
Definition: PViewDataList.h:26
PViewDataList::incrementList
std::vector< double > * incrementList(int numComp, int type, int numNodes=0)
Definition: PViewDataList.cpp:1243
GMSH_IntegratePlugin::getNbOptions
int getNbOptions() const
Definition: Integrate.cpp:38
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
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
elementFactory
Definition: shapeFunctions.h:1402
SBoundingBox3d::center
SPoint3 center() const
Definition: SBoundingBox3d.h:92
PViewOptions::Numeric
@ Numeric
Definition: PViewOptions.h:19
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
PViewData::getDimension
virtual int getDimension(int step, int ent, int ele)
Definition: PViewData.h:134
GMSH_IntegratePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Integrate.cpp:43
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
Integrate.h
PViewDataList::SP
std::vector< double > SP
Definition: PViewDataList.h:27
PViewData::getBoundingBox
virtual SBoundingBox3d getBoundingBox(int step=-1)=0
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
PViewData::hasTimeStep
virtual bool hasTimeStep(int step)
Definition: PViewData.h:211
PViewOptions::intervalsType
int intervalsType
Definition: PViewOptions.h:54
PViewOptions.h
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
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
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
IntegrateOptions_Number
StringXNumber IntegrateOptions_Number[]
Definition: Integrate.cpp:10
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_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
element::integrateCirculation
virtual double integrateCirculation(double val[])
Definition: shapeFunctions.h:238
GMSH_PostPlugin::getPossiblyAdaptiveData
virtual PViewData * getPossiblyAdaptiveData(PView *view)
Definition: Plugin.cpp:94
PViewDataList::Time
std::vector< double > Time
Definition: PViewDataList.h:25
PView::getOptions
PViewOptions * getOptions()
Definition: PView.h:81
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
element::integrateFlux
virtual double integrateFlux(double val[])
Definition: shapeFunctions.h:243
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
GMSH_IntegratePlugin::execute
PView * execute(PView *)
Definition: Integrate.cpp:48
shapeFunctions.h
GMSH_IntegratePlugin
Definition: Integrate.h:15
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
PViewData::getFirstNonEmptyTimeStep
virtual int getFirstNonEmptyTimeStep(int start=0)
Definition: PViewData.h:91