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