gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MinMax.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 "MinMax.h"
7 #include "PViewOptions.h"
8 
9 StringXNumber MinMaxOptions_Number[] = {{GMSH_FULLRC, "View", nullptr, -1.},
10  {GMSH_FULLRC, "OverTime", nullptr, 0},
11  {GMSH_FULLRC, "Argument", nullptr, 0},
12  {GMSH_FULLRC, "Visible", nullptr, 1}};
13 
14 extern "C" {
16 }
17 
18 std::string GMSH_MinMaxPlugin::getHelp() const
19 {
20  return "Plugin(MinMax) computes the min/max of a view.\n\n"
21  "If `View' < 0, the plugin is run on the current view. "
22  "If `OverTime' = 1, the plugin calculates the min/max over "
23  "space and time. If `Argument' = 1, the plugin calculates the "
24  "min/max and the argmin/argmax. If `Visible' = 1, the plugin "
25  "is only applied to visible entities.\n\n"
26  "Plugin(MinMax) creates two new list-based views.";
27 }
28 
30 {
31  return sizeof(MinMaxOptions_Number) / sizeof(StringXNumber);
32 }
33 
35 {
36  return &MinMaxOptions_Number[iopt];
37 }
38 
40 {
41  int iView = (int)MinMaxOptions_Number[0].def;
42  int overTime = (int)MinMaxOptions_Number[1].def;
43  int argument = (int)MinMaxOptions_Number[2].def;
44  bool visible = (bool)MinMaxOptions_Number[3].def;
45 
46  PView *v1 = getView(iView, v);
47  if(!v1) return v;
48 
49  PViewData *data1 = v1->getData(true);
50  PView *vMin = new PView();
51  PView *vMax = new PView();
52  PViewDataList *dataMin = getDataList(vMin);
53  PViewDataList *dataMax = getDataList(vMax);
54 
55  if(!argument) {
56  double x = data1->getBoundingBox().center().x();
57  double y = data1->getBoundingBox().center().y();
58  double z = data1->getBoundingBox().center().z();
59  dataMin->SP.push_back(x);
60  dataMin->SP.push_back(y);
61  dataMin->SP.push_back(z);
62  dataMax->SP.push_back(x);
63  dataMax->SP.push_back(y);
64  dataMax->SP.push_back(z);
65  dataMin->NbSP = 1;
66  dataMax->NbSP = 1;
67  }
68 
69  double min = VAL_INF, max = -VAL_INF, timeMin = 0, timeMax = 0;
70 
71  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
72  if(data1->hasTimeStep(step)) {
73  double minView = VAL_INF, maxView = -VAL_INF;
74  double xmin = 0., ymin = 0., zmin = 0., xmax = 0., ymax = 0., zmax = 0.;
75  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
76  if(visible && data1->skipEntity(step, ent)) continue;
77  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
78  if(data1->skipElement(step, ent, ele, visible)) continue;
79  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) {
80  double val;
81  data1->getScalarValue(step, ent, ele, nod, val);
82  if(val < minView) {
83  data1->getNode(step, ent, ele, nod, xmin, ymin, zmin);
84  minView = val;
85  }
86  if(val > maxView) {
87  data1->getNode(step, ent, ele, nod, xmax, ymax, zmax);
88  maxView = val;
89  }
90  }
91  }
92  }
93 
94  if(!overTime) {
95  if(argument) {
96  dataMin->SP.push_back(xmin);
97  dataMin->SP.push_back(ymin);
98  dataMin->SP.push_back(zmin);
99  dataMax->SP.push_back(xmax);
100  dataMax->SP.push_back(ymax);
101  dataMax->SP.push_back(zmax);
102  (dataMin->NbSP)++;
103  (dataMax->NbSP)++;
104  }
105  else {
106  double time = data1->getTime(step);
107  dataMin->Time.push_back(time);
108  dataMax->Time.push_back(time);
109  }
110  dataMin->SP.push_back(minView);
111  dataMax->SP.push_back(maxView);
112  }
113  else {
114  if(minView < min) {
115  min = minView;
116  timeMin = data1->getTime(step);
117  }
118  if(maxView > max) {
119  max = maxView;
120  timeMax = data1->getTime(step);
121  }
122  }
123  }
124  }
125 
126  if(overTime) {
127  dataMin->SP.push_back(min);
128  dataMax->SP.push_back(max);
129  dataMin->Time.push_back(timeMin);
130  dataMax->Time.push_back(timeMax);
131  }
132 
135 
136  dataMin->setName(data1->getName() + "_Min");
137  dataMin->setFileName(data1->getName() + "_Min.pos");
138  dataMin->finalize();
139  dataMax->setName(data1->getName() + "_Max");
140  dataMax->setFileName(data1->getName() + "_Max.pos");
141  dataMax->finalize();
142 
143  return nullptr;
144 }
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
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
PViewDataList::NbSP
int NbSP
Definition: PViewDataList.h:26
StringXNumber
Definition: Options.h:918
VAL_INF
#define VAL_INF
Definition: PViewData.h:16
MinMaxOptions_Number
StringXNumber MinMaxOptions_Number[]
Definition: MinMax.cpp:9
GMSH_MinMaxPlugin::getHelp
std::string getHelp() const
Definition: MinMax.cpp:18
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
MinMax.h
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
GMSH_MinMaxPlugin
Definition: MinMax.h:15
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::getTime
virtual double getTime(int step)
Definition: PViewData.h:94
PViewDataList::SP
std::vector< double > SP
Definition: PViewDataList.h:27
PViewData::getBoundingBox
virtual SBoundingBox3d getBoundingBox(int step=-1)=0
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
PViewData::hasTimeStep
virtual bool hasTimeStep(int step)
Definition: PViewData.h:211
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
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
GMSH_MinMaxPlugin::execute
PView * execute(PView *)
Definition: MinMax.cpp:39
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
PViewData
Definition: PViewData.h:29
GMSH_MinMaxPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: MinMax.cpp:34
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
PView::getOptions
PViewOptions * getOptions()
Definition: PView.h:81
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
PViewData::getNumElements
virtual int getNumElements(int step=-1, int ent=-1)
Definition: PViewData.h:131
GMSH_RegisterMinMaxPlugin
GMSH_Plugin * GMSH_RegisterMinMaxPlugin()
Definition: MinMax.cpp:15
PViewData::getName
virtual std::string getName()
Definition: PViewData.h:70
GMSH_MinMaxPlugin::getNbOptions
int getNbOptions() const
Definition: MinMax.cpp:29
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