gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Summation.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 "GmshConfig.h"
7 #include "GmshDefines.h"
8 #include "Summation.h"
9 #include "OctreePost.h"
10 #include "GEntity.h"
11 #include <algorithm>
12 
14  {GMSH_FULLRC, "View 0", nullptr, -1.}, {GMSH_FULLRC, "View 1", nullptr, -1.},
15  {GMSH_FULLRC, "View 2", nullptr, -1.}, {GMSH_FULLRC, "View 3", nullptr, -1.},
16  {GMSH_FULLRC, "View 4", nullptr, -1.}, {GMSH_FULLRC, "View 5", nullptr, -1.},
17  {GMSH_FULLRC, "View 6", nullptr, -1.}, {GMSH_FULLRC, "View 7", nullptr, -1.}};
18 
20  {GMSH_FULLRC, "Resuling View Name", nullptr, "default"}};
21 
22 extern "C" {
24 {
25  return new GMSH_SummationPlugin();
26 }
27 }
28 
29 std::string GMSH_SummationPlugin::getHelp() const
30 {
31  return "Plugin(Summation) sums every time steps "
32  "of 'Reference View' and (every) 'Other View X'"
33  "and store the result in a new view.\n"
34  "If 'View 0' < 0 then the current view is selected.\n"
35  "If 'View 1...8' < 0 then this view is skipped.\n"
36  "Views can have different number of time steps\n"
37  "Warning: the Plugin assume that every views share"
38  "the same mesh and that meshes do not move between time steps!";
39 }
40 
42 {
43  return sizeof(SummationOptions_Number) / sizeof(StringXNumber);
44 }
45 
47 {
48  return &SummationOptions_Number[iopt];
49 }
50 
52 {
53  return sizeof(SummationOptions_String) / sizeof(StringXString);
54 }
55 
57 {
58  return &SummationOptions_String[iopt];
59 }
60 
62 {
63  int nviewmax = 8;
64  std::vector<int> views_indices;
65  std::vector<PView *> pviews;
66  std::vector<PViewData *> pviewsdata;
67 
68  // Get view indices and PViews
69  for(int i = 0; i < nviewmax; i++) {
70  int iview = (int)SummationOptions_Number[i].def;
71  if(i == 0 || iview > -1) {
72  views_indices.push_back(iview);
73  pviews.push_back(getView(iview, view));
74  if(!pviews.back()) {
75  Msg::Error("Summation plugin could not find view %i", iview);
76  return view;
77  }
78  pviewsdata.push_back(getPossiblyAdaptiveData(pviews.back()));
79  if(pviewsdata.back()->hasMultipleMeshes()) {
80  Msg::Error("Summation plugin cannot be applied to multi-mesh views");
81  return view;
82  }
83  }
84  }
85  // Number of view to sum
86  int nviews = pviews.size();
87  // Check if the views share the same mesh
88  //(at least same number of elements and entities)
89  // If a view has an empty timestep: skip it, no problem.
90  for(int j = 1; j < nviews; j++) {
91  if(pviewsdata[j]->getNumEntities() == 0 &&
92  pviewsdata[j]->getNumElements() == 0)
93  continue; // empty time step
94  if((pviewsdata[0]->getNumEntities() != pviewsdata[j]->getNumEntities()) ||
95  (pviewsdata[0]->getNumElements() != pviewsdata[j]->getNumElements())) {
96  Msg::Error("Summation plugin: views based on different grid.");
97  }
98  }
99  // get min/max indices of time steps
100  int timeBeg = pviewsdata[0]->getFirstNonEmptyTimeStep();
101  int timeEnd = pviewsdata[0]->getNumTimeSteps();
102  int iref = 0; // reference view and time step to get mesh's info
103  int stepref = timeBeg;
104  for(int i = 1; i < nviews; i++) {
105  if(timeBeg > pviewsdata[i]->getFirstNonEmptyTimeStep()) {
106  timeBeg = pviewsdata[i]->getFirstNonEmptyTimeStep();
107  iref = i;
108  stepref = timeBeg;
109  }
110  timeEnd = std::max(timeEnd, pviewsdata[i]->getNumTimeSteps());
111  }
112  // Init result
113  PView *v2 = new PView();
114  PViewDataList *data2 = getDataList(v2);
115 
116  for(int ent = 0; ent < pviewsdata[iref]->getNumEntities(stepref); ent++) {
117  for(int ele = 0; ele < pviewsdata[iref]->getNumElements(stepref, ent);
118  ele++) {
119  // if(pviewsdata[0]->skipElement(timeBeg, ent, ele)) continue;
120  int numNodes = pviewsdata[iref]->getNumNodes(stepref, ent, ele);
121  int type = pviewsdata[iref]->getType(stepref, ent, ele);
122  int numComp = pviewsdata[iref]->getNumComponents(stepref, ent, ele);
123  int numComp2 = numComp;
124  std::vector<double> *out = data2->incrementList(numComp2, type, numNodes);
125  std::vector<double> v(std::max(9, numComp), 0.);
126  std::vector<double> x(numNodes), y(numNodes), z(numNodes);
127  for(int nod = 0; nod < numNodes; nod++)
128  pviewsdata[iref]->getNode(stepref, ent, ele, nod, x[nod], y[nod],
129  z[nod]);
130  for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]);
131  for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
132  for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]);
133  for(int step = timeBeg; step < timeEnd; step++) {
134  for(int nod = 0; nod < numNodes; nod++) {
135  for(int comp = 0; comp < numComp; comp++) {
136  v[comp] = 0;
137  for(int iview = 0; iview < nviews; iview++) {
138  if(!pviewsdata[iview]->hasTimeStep(step)) continue;
139  double d;
140  pviewsdata[iview]->getValue(step, ent, ele, nod, comp, d);
141  v[comp] += d;
142  }
143  }
144  for(int i = 0; i < numComp2; i++) out->push_back(v[i]);
145  }
146  }
147  }
148  }
149 
150  // Set time
151  for(int step = timeBeg; step < timeEnd; step++) {
152  int iview = 0;
153  for(iview = 0; iview < nviews; iview++) {
154  if(!pviewsdata[iview]->hasTimeStep(step)) continue;
155  break;
156  }
157  data2->Time.push_back(pviewsdata[iview]->getTime(step));
158  }
159 
160  std::string outputname = SummationOptions_String[0].def;
161  if(outputname == "default")
162  outputname = pviewsdata[0]->getName() + "_Summation";
163 
164  data2->setName(outputname);
165  data2->setFileName(outputname + "_Summation.pos");
166  data2->finalize();
167 
168  return v2;
169 }
StringXString
Definition: Options.h:910
PView
Definition: PView.h:27
GMSH_Plugin
Definition: Plugin.h:26
GEntity.h
OctreePost.h
PViewDataList
Definition: PViewDataList.h:17
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
SummationOptions_String
StringXString SummationOptions_String[]
Definition: Summation.cpp:19
SummationOptions_Number
StringXNumber SummationOptions_Number[]
Definition: Summation.cpp:13
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
GMSH_RegisterSummationPlugin
GMSH_Plugin * GMSH_RegisterSummationPlugin()
Definition: Summation.cpp:23
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
GmshDefines.h
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
GMSH_SummationPlugin
Definition: Summation.h:15
GMSH_SummationPlugin::getNbOptionsStr
int getNbOptionsStr() const
Definition: Summation.cpp:51
GMSH_SummationPlugin::getOptionStr
StringXString * getOptionStr(int iopt)
Definition: Summation.cpp:56
GMSH_SummationPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Summation.cpp:46
z
const double z
Definition: GaussQuadratureQuad.cpp:56
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_SummationPlugin::execute
PView * execute(PView *)
Definition: Summation.cpp:61
GMSH_SummationPlugin::getNbOptions
int getNbOptions() const
Definition: Summation.cpp:41
Summation.h
GMSH_SummationPlugin::getHelp
std::string getHelp() const
Definition: Summation.cpp:29
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107