gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Divergence.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 "Divergence.h"
7 #include "shapeFunctions.h"
8 #include "GmshDefines.h"
9 
11  {GMSH_FULLRC, "View", nullptr, -1.}};
12 
13 extern "C" {
15 {
16  return new GMSH_DivergencePlugin();
17 }
18 }
19 
20 std::string GMSH_DivergencePlugin::getHelp() const
21 {
22  return "Plugin(Divergence) computes the divergence of the "
23  "field in the view `View'.\n\n"
24  "If `View' < 0, the plugin is run on the current view.\n\n"
25  "Plugin(Divergence) creates one new list-based view.";
26 }
27 
29 {
30  return sizeof(DivergenceOptions_Number) / sizeof(StringXNumber);
31 }
32 
34 {
35  return &DivergenceOptions_Number[iopt];
36 }
37 
39 {
40  int iView = (int)DivergenceOptions_Number[0].def;
41 
42  PView *v1 = getView(iView, v);
43  if(!v1) return v;
44 
46  if(data1->hasMultipleMeshes()) {
47  Msg::Error("Divergence plugin cannot be run on multi-mesh views");
48  return v;
49  }
50 
51  PView *v2 = new PView();
52  PViewDataList *data2 = getDataList(v2);
53  int firstNonEmptyStep = data1->getFirstNonEmptyTimeStep();
54 
55  for(int ent = 0; ent < data1->getNumEntities(firstNonEmptyStep); ent++) {
56  for(int ele = 0; ele < data1->getNumElements(firstNonEmptyStep, ent);
57  ele++) {
58  if(data1->skipElement(firstNonEmptyStep, ent, ele)) continue;
59  int numComp = data1->getNumComponents(firstNonEmptyStep, ent, ele);
60  if(numComp != 3) continue;
61  int type = data1->getType(firstNonEmptyStep, ent, ele);
62  int numNodes = data1->getNumNodes(firstNonEmptyStep, ent, ele);
63  std::vector<double> *out = data2->incrementList(1, type, numNodes);
64  if(!out) continue;
65  double x[8], y[8], z[8], val[8 * 3];
66  for(int nod = 0; nod < numNodes; nod++)
67  data1->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod],
68  z[nod]);
69  int dim = data1->getDimension(firstNonEmptyStep, ent, ele);
70  elementFactory factory;
71  element *element = factory.create(numNodes, dim, x, y, z);
72  if(!element) continue;
73  for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]);
74  for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
75  for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]);
76  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
77  if(!data1->hasTimeStep(step)) continue;
78  for(int nod = 0; nod < numNodes; nod++)
79  for(int comp = 0; comp < numComp; comp++)
80  data1->getValue(step, ent, ele, nod, comp,
81  val[numComp * nod + comp]);
82  for(int nod = 0; nod < numNodes; nod++) {
83  double u, v, w;
84  element->getNode(nod, u, v, w);
85  double f = element->interpolateDiv(val, u, v, w, 3);
86  out->push_back(f);
87  }
88  }
89  delete element;
90  }
91  }
92 
93  for(int i = 0; i < data1->getNumTimeSteps(); i++) {
94  if(!data1->hasTimeStep(i)) continue;
95  double time = data1->getTime(i);
96  data2->Time.push_back(time);
97  }
98  data2->setName(data1->getName() + "_Divergence");
99  data2->setFileName(data1->getName() + "_Divergence.pos");
100  data2->finalize();
101 
102  return v2;
103 }
DivergenceOptions_Number
StringXNumber DivergenceOptions_Number[]
Definition: Divergence.cpp:10
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
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
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
GMSH_DivergencePlugin::getHelp
std::string getHelp() const
Definition: Divergence.cpp:20
GMSH_DivergencePlugin
Definition: Divergence.h:15
PViewData::hasMultipleMeshes
virtual bool hasMultipleMeshes()
Definition: PViewData.h:216
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
GMSH_RegisterDivergencePlugin
GMSH_Plugin * GMSH_RegisterDivergencePlugin()
Definition: Divergence.cpp:14
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
element::interpolateDiv
double interpolateDiv(double val[], double u, double v, double w, int stride=3)
Definition: shapeFunctions.h:201
elementFactory
Definition: shapeFunctions.h:1402
GMSH_DivergencePlugin::execute
PView * execute(PView *)
Definition: Divergence.cpp:38
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
Divergence.h
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
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
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
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
PViewData
Definition: PViewData.h:29
PViewData::getNumComponents
virtual int getNumComponents(int step, int ent, int ele)
Definition: PViewData.h:152
GMSH_DivergencePlugin::getNbOptions
int getNbOptions() const
Definition: Divergence.cpp:28
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
element::getNode
virtual void getNode(int num, double &u, double &v, double &w)=0
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
shapeFunctions.h
GMSH_DivergencePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Divergence.cpp:33
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