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