gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
|
Go to the documentation of this file.
6 #include "GmshConfig.h"
23 {
GMSH_FULLRC,
"Expression0",
nullptr,
"Sqrt(v0^2+v1^2+v2^2)"},
39 return "Plugin(MathEval) creates a new view using "
40 "data from the time step `TimeStep' in the view "
42 "If only `Expression0' is given (and `Expression1', "
43 "..., `Expression8' are all empty), the plugin "
44 "creates a scalar view. If `Expression0', `Expression1' "
45 "and/or `Expression2' are given (and `Expression3', "
46 "..., `Expression8' are all empty) the plugin creates "
47 "a vector view. Otherwise the plugin creates a tensor "
49 "In addition to the usual mathematical functions "
50 "(Exp, Log, Sqrt, Sin, Cos, Fabs, etc.) and operators "
51 "(+, -, *, /, ^), all expressions can contain:\n\n"
52 "- the symbols v0, v1, v2, ..., vn, which represent "
53 "the n components in `View';\n\n"
54 "- the symbols w0, w1, w2, ..., wn, which represent "
55 "the n components of `OtherView', at time step "
56 "`OtherTimeStep';\n\n"
57 "- the symbols x, y and z, which represent the three "
58 "spatial coordinates.\n\n"
59 "If `TimeStep' < 0, the plugin extracts data from all "
60 "the time steps in the view.\n\n"
61 "If `View' < 0, the plugin is run on the current view.\n\n"
62 "Plugin(MathEval) creates one new view."
63 "If `PhysicalRegion' < 0, the plugin is run "
64 "on all physical regions.\n\n"
65 "Plugin(MathEval) creates one new list-based view.";
96 std::vector<std::string> expr(9);
104 Msg::Error(
"MathEval plugin cannot be applied to multi-mesh views");
108 PView *otherView = v1;
109 if(iOtherView >= 0) {
110 otherView =
getView(iOtherView, view);
112 Msg::Error(
"MathEval plugin could not find other view %i", iOtherView);
119 Msg::Error(
"MathEval plugin cannot be applied to multi-mesh views");
123 if(otherTimeStep < 0 &&
125 Msg::Error(
"Number of time steps don't match: using step 0");
129 Msg::Error(
"Invalid time step (%d) in View[%d]: using step 0 instead",
130 otherTimeStep, otherView->
getIndex());
135 if(expr[3].size() || expr[4].size() || expr[5].size() || expr[6].size() ||
136 expr[7].size() || expr[8].size()) {
138 for(
int i = 0; i < 9; i++)
139 if(expr[i].empty()) expr[i] =
"0";
141 else if(expr[1].size() || expr[2].size()) {
143 for(
int i = 0; i < 3; i++)
144 if(expr[i].empty()) expr[i] =
"0";
149 expr.resize(numComp2);
151 const char *names[] = {
"x",
"y",
"z",
"v0",
"v1",
"v2",
"v3",
152 "v4",
"v5",
"v6",
"v7",
"v8",
"w0",
"w1",
153 "w2",
"w3",
"w4",
"w5",
"w6",
"w7",
"w8"};
154 std::size_t numVariables =
sizeof(names) /
sizeof(names[0]);
155 std::vector<std::string> variables(numVariables);
156 for(std::size_t i = 0; i < numVariables; i++) variables[i] = names[i];
158 if(expr.empty())
return view;
159 std::vector<double> values(numVariables), res(numComp2);
162 if(forceInterpolation ||
165 Msg::Info(
"Other view based on different grid: interpolating...");
174 Msg::Error(
"Invalid time step (%d) in View[%d]: using all steps instead",
180 int timeBeg = (timeStep < 0) ? firstNonEmptyStep : timeStep;
181 int timeEnd = (timeStep < 0) ? -timeStep : timeStep + 1;
183 bool ok = (physicalRegion <= 0);
184 if(physicalRegion > 0) {
193 for(
int ele = 0; ele < data1->
getNumElements(timeBeg, ent); ele++) {
194 if(data1->
skipElement(timeBeg, ent, ele))
continue;
195 int numNodes = data1->
getNumNodes(timeBeg, ent, ele);
196 int type = data1->
getType(timeBeg, ent, ele);
198 int otherNumComp = (!otherData || octree) ?
201 std::vector<double> *out = data2->
incrementList(numComp2, type, numNodes);
202 std::vector<double> v(std::max(9, numComp), 0.);
203 std::vector<double> w(std::max(9, otherNumComp), 0.);
204 std::vector<double> x(numNodes), y(numNodes),
z(numNodes);
205 for(
int nod = 0; nod < numNodes; nod++)
206 data1->
getNode(timeBeg, ent, ele, nod, x[nod], y[nod],
z[nod]);
207 for(
int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]);
208 for(
int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
209 for(
int nod = 0; nod < numNodes; nod++) out->push_back(
z[nod]);
210 for(
int step = timeBeg; step < timeEnd; step++) {
212 int step2 = (otherTimeStep < 0) ? step : otherTimeStep;
213 for(
int nod = 0; nod < numNodes; nod++) {
214 for(
int comp = 0; comp < numComp; comp++)
215 data1->
getValue(step, ent, ele, nod, comp, v[comp]);
218 int qn = forceInterpolation ? numNodes : 0;
219 if(!octree->
searchScalar(x[nod], y[nod],
z[nod], &w[0], step2,
220 nullptr, qn, &x[0], &y[0], &
z[0]))
221 if(!octree->
searchVector(x[nod], y[nod],
z[nod], &w[0], step2,
222 nullptr, qn, &x[0], &y[0], &
z[0]))
224 nullptr, qn, &x[0], &y[0], &
z[0]);
227 for(
int comp = 0; comp < otherNumComp; comp++)
228 otherData->
getValue(step2, ent, ele, nod, comp, w[comp]);
233 for(
int i = 0; i < 9; i++) values[3 + i] = v[i];
234 for(
int i = 0; i < 9; i++) values[12 + i] = w[i];
235 if(
f.eval(values, res)) {
236 for(
int i = 0; i < numComp2; i++) out->push_back(res[i]);
247 if(octree)
delete octree;
std::string getHelp() const
bool searchScalar(double x, double y, double z, double *values, int step=-1, double *size=nullptr, int qn=0, double *qx=nullptr, double *qy=nullptr, double *qz=nullptr, bool grad=false, int dim=-1)
virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, int samplingRate=1)
static void Info(const char *fmt,...)
virtual int getNumTimeSteps()=0
virtual int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z)
static void Error(const char *fmt,...)
std::vector< double > * incrementList(int numComp, int type, int numNodes=0)
std::vector< int > physicals
void f(int n, double u, double *val)
virtual void getValue(int step, int ent, int ele, int idx, double &val)
GMSH_Plugin * GMSH_RegisterMathEvalPlugin()
virtual bool hasMultipleMeshes()
virtual int getNumEntities(int step=-1)
virtual void setFileName(const std::string &val)
int getNbOptionsStr() const
virtual double getTime(int step)
virtual int getType(int step, int ent, int ele)
StringXNumber * getOption(int iopt)
virtual bool hasTimeStep(int step)
virtual int getNumNodes(int step, int ent, int ele)
StringXString * getOptionStr(int iopt)
bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
virtual void setName(const std::string &val)
StringXString MathEvalOptions_String[]
virtual int getNumComponents(int step, int ent, int ele)
bool searchVector(double x, double y, double z, double *values, int step=-1, double *size=nullptr, int qn=0, double *qx=nullptr, double *qy=nullptr, double *qz=nullptr, bool grad=false, int dim=-1)
virtual PView * getView(int index, PView *view)
virtual PViewData * getPossiblyAdaptiveData(PView *view)
std::vector< double > Time
virtual int getNumElements(int step=-1, int ent=-1)
virtual std::string getName()
StringXNumber MathEvalOptions_Number[]
virtual PViewDataList * getDataList(PView *view, bool showError=true)
bool searchTensor(double x, double y, double z, double *values, int step=-1, double *size=nullptr, int qn=0, double *qx=nullptr, double *qy=nullptr, double *qz=nullptr, bool grad=false, int dim=-1)
virtual GEntity * getEntity(int step, int entity)
virtual int getFirstNonEmptyTimeStep(int start=0)