gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
ModulusPhase.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 "ModulusPhase.h"
7 
9  {GMSH_FULLRC, "RealPart", nullptr, 0.},
10  {GMSH_FULLRC, "ImaginaryPart", nullptr, 1.},
11  {GMSH_FULLRC, "View", nullptr, -1.}};
12 
13 extern "C" {
15 {
16  return new GMSH_ModulusPhasePlugin();
17 }
18 }
19 
21 {
22  return "Plugin(ModulusPhase) interprets the time steps "
23  "`realPart' and `imaginaryPart' in the view `View' "
24  "as the real and imaginary parts of a complex field "
25  "and replaces them with their corresponding "
26  "modulus and phase.\n\n"
27  "If `View' < 0, the plugin is run on the current view.\n\n"
28  "Plugin(ModulusPhase) is executed in-place.";
29 }
30 
32 {
33  return sizeof(ModulusPhaseOptions_Number) / sizeof(StringXNumber);
34 }
35 
37 {
38  return &ModulusPhaseOptions_Number[iopt];
39 }
40 
42 {
43  int rIndex = (int)ModulusPhaseOptions_Number[0].def;
44  int iIndex = (int)ModulusPhaseOptions_Number[1].def;
45  int iView = (int)ModulusPhaseOptions_Number[2].def;
46 
47  PView *v1 = getView(iView, v);
48  if(!v1) return v;
49 
50  PViewData *data1 = v1->getData();
51  if(data1->hasMultipleMeshes()) {
52  Msg::Error("ModulusPhase plugin cannot be run on multi-mesh views");
53  return v;
54  }
55 
56  if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || iIndex < 0 ||
57  iIndex >= data1->getNumTimeSteps()) {
58  Msg::Error("Wrong real or imaginary part index");
59  return v1;
60  }
61 
62  if(data1->isNodeData()) {
63  // tag all the nodes with "0" (the default tag)
64  for(int step = 0; step < data1->getNumTimeSteps(); step++) {
65  for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
66  for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
67  if(data1->skipElement(step, ent, ele)) continue;
68  for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++)
69  data1->tagNode(step, ent, ele, nod, 0);
70  }
71  }
72  }
73  }
74 
75  // transform all "0" nodes
76  for(int ent = 0; ent < data1->getNumEntities(rIndex); ent++) {
77  for(int ele = 0; ele < data1->getNumElements(rIndex, ent); ele++) {
78  if(data1->skipElement(rIndex, ent, ele)) continue;
79  for(int nod = 0; nod < data1->getNumNodes(rIndex, ent, ele); nod++) {
80  double x, y, z;
81  int tag = data1->getNode(rIndex, ent, ele, nod, x, y, z);
82  if(data1->isNodeData() && tag) continue;
83  for(int comp = 0; comp < data1->getNumComponents(rIndex, ent, ele);
84  comp++) {
85  double vr, vi;
86  data1->getValue(rIndex, ent, ele, nod, comp, vr);
87  data1->getValue(iIndex, ent, ele, nod, comp, vi);
88  double modulus = sqrt(vr * vr + vi * vi);
89  double phase = atan2(vi, vr);
90  data1->setValue(rIndex, ent, ele, nod, comp, modulus);
91  data1->setValue(iIndex, ent, ele, nod, comp, phase);
92  if(data1->isNodeData()) {
93  data1->tagNode(rIndex, ent, ele, nod, 1);
94  data1->tagNode(iIndex, ent, ele, nod, 1);
95  }
96  }
97  }
98  }
99  }
100 
101  data1->setName(data1->getName() + "_ModulusPhase");
102  data1->setName(data1->getName() + ".pos");
103  data1->finalize();
104 
105  v1->setChanged(true);
106  return v1;
107 }
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
PViewData::setValue
virtual void setValue(int step, int ent, int ele, int nod, int comp, double val)
Definition: PViewData.cpp:130
PViewData::isNodeData
virtual bool isNodeData()
Definition: PViewData.h:218
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
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
ModulusPhaseOptions_Number
StringXNumber ModulusPhaseOptions_Number[]
Definition: ModulusPhase.cpp:8
GMSH_RegisterModulusPhasePlugin
GMSH_Plugin * GMSH_RegisterModulusPhasePlugin()
Definition: ModulusPhase.cpp:14
PViewData::hasMultipleMeshes
virtual bool hasMultipleMeshes()
Definition: PViewData.h:216
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
GMSH_ModulusPhasePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: ModulusPhase.cpp:36
GMSH_ModulusPhasePlugin::getHelp
std::string getHelp() const
Definition: ModulusPhase.cpp:20
PView::setChanged
void setChanged(bool val)
Definition: PView.cpp:241
PViewData::tagNode
virtual void tagNode(int step, int ent, int ele, int nod, int tag)
Definition: PViewData.h:148
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
ModulusPhase.h
PViewData::setName
virtual void setName(const std::string &val)
Definition: PViewData.h:71
GMSH_ModulusPhasePlugin::getNbOptions
int getNbOptions() const
Definition: ModulusPhase.cpp:31
PViewData
Definition: PViewData.h: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_ModulusPhasePlugin
Definition: ModulusPhase.h:15
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
GMSH_ModulusPhasePlugin::execute
PView * execute(PView *)
Definition: ModulusPhase.cpp:41
PViewData::finalize
virtual bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewData.cpp:30