gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
HarmonicToTime.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 "HarmonicToTime.h"
7 #include "GmshDefines.h"
8 
10  {GMSH_FULLRC, "RealPart", nullptr, 0.},
11  {GMSH_FULLRC, "ImaginaryPart", nullptr, 1.},
12  {GMSH_FULLRC, "NumSteps", nullptr, 20.},
13  {GMSH_FULLRC, "TimeSign", nullptr, -1.},
14  {GMSH_FULLRC, "Frequency", nullptr, 1},
15  {GMSH_FULLRC, "NumPeriods", nullptr, 1},
16  {GMSH_FULLRC, "View", nullptr, -1.}};
17 
18 extern "C" {
20 {
21  return new GMSH_HarmonicToTimePlugin();
22 }
23 }
24 
26 {
27  return "Plugin(HarmonicToTime) takes the values in the "
28  "time steps `RealPart' and `ImaginaryPart' of "
29  "the view `View', and creates a new view "
30  "containing\n\n"
31  "`View'[`RealPart'] * cos(p) +- `View'[`ImaginaryPart'] * sin(p)\n"
32  "with\n p = 2*Pi*k/`NumSteps', k = 0, ..., `NumSteps'-1\n"
33  "and 'NumSteps' the total number of time steps\n"
34  "over 'NumPeriods' periods at frequency 'Frequency' [Hz].\n"
35  "The '+' sign is used if `TimeSign'>0, the '-' sign otherwise.\n\n"
36  "If `View' < 0, the plugin is run on the current view.\n\n"
37  "Plugin(HarmonicToTime) creates one new list-based view.";
38 }
39 
41 {
42  return sizeof(HarmonicToTimeOptions_Number) / sizeof(StringXNumber);
43 }
44 
46 {
47  return &HarmonicToTimeOptions_Number[iopt];
48 }
49 
51 {
52  int rIndex = (int)HarmonicToTimeOptions_Number[0].def;
53  int iIndex = (int)HarmonicToTimeOptions_Number[1].def;
54  int nSteps = (int)HarmonicToTimeOptions_Number[2].def;
55  double tsign = HarmonicToTimeOptions_Number[3].def > 0 ? 1. : -1.;
56  double frequency = HarmonicToTimeOptions_Number[4].def;
57  int nPeriods = (int)HarmonicToTimeOptions_Number[5].def;
58  int iView = (int)HarmonicToTimeOptions_Number[6].def;
59 
60  PView *v1 = getView(iView, v);
61  if(!v1) return v;
62  PViewData *data1 = v1->getData(true);
63 
64  if(data1->hasMultipleMeshes()) {
65  Msg::Error("HarmonicToTime plugin cannot be applied to multi-mesh views");
66  return v1;
67  }
68 
69  if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || iIndex < 0 ||
70  iIndex >= data1->getNumTimeSteps()) {
71  Msg::Error("Wrong real or imaginary part index");
72  return v1;
73  }
74 
75  if(nSteps <= 0) {
76  Msg::Error("nSteps should be > 0");
77  return v1;
78  }
79 
80  PView *v2 = new PView();
81  PViewDataList *data2 = getDataList(v2);
82 
83  for(int ent = 0; ent < data1->getNumEntities(0); ent++) {
84  for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) {
85  if(data1->skipElement(0, ent, ele)) continue;
86  int numNodes = data1->getNumNodes(0, ent, ele);
87  int type = data1->getType(0, ent, ele);
88  int numComp = data1->getNumComponents(0, ent, ele);
89  std::vector<double> *out = data2->incrementList(numComp, type, numNodes);
90  std::vector<double> x(numNodes), y(numNodes), z(numNodes);
91  std::vector<double> vr(numNodes * numComp), vi(numNodes * numComp);
92  for(int nod = 0; nod < numNodes; nod++) {
93  data1->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]);
94  for(int comp = 0; comp < numComp; comp++) {
95  data1->getValue(rIndex, ent, ele, nod, comp,
96  vr[numComp * nod + comp]);
97  data1->getValue(iIndex, ent, ele, nod, comp,
98  vi[numComp * nod + comp]);
99  }
100  }
101  for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]);
102  for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]);
103  for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]);
104  for(int k = 0; k < nSteps; k++) {
105  // if frequency == 0 is requested, simply use real part
106  double p = frequency ? 2. * M_PI * nPeriods * k / nSteps : 0.;
107  for(int nod = 0; nod < numNodes; nod++) {
108  for(int comp = 0; comp < numComp; comp++) {
109  double val = vr[numComp * nod + comp] * cos(p) +
110  tsign * vi[numComp * nod + comp] * sin(p);
111  out->push_back(val);
112  }
113  }
114  }
115  }
116  }
117 
118  for(int k = 0; k < nSteps; k++) {
119  double t =
120  frequency ? (2. * M_PI * nPeriods * k / frequency / (double)nSteps) : 0.;
121  data2->Time.push_back(t);
122  }
123  data2->setName(data1->getName() + "_HarmonicToTime");
124  data2->setFileName(data1->getName() + "_HarmonicToTime.pos");
125  data2->finalize();
126 
127  return v2;
128 }
PView
Definition: PView.h:27
GMSH_HarmonicToTimePlugin
Definition: HarmonicToTime.h:15
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
StringXNumber::def
double def
Definition: Options.h:922
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
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
HarmonicToTime.h
PViewData::hasMultipleMeshes
virtual bool hasMultipleMeshes()
Definition: PViewData.h:216
GMSH_HarmonicToTimePlugin::getNbOptions
int getNbOptions() const
Definition: HarmonicToTime.cpp:40
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
GMSH_HarmonicToTimePlugin::execute
PView * execute(PView *)
Definition: HarmonicToTime.cpp:50
PViewData::getType
virtual int getType(int step, int ent, int ele)
Definition: PViewData.h:183
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
HarmonicToTimeOptions_Number
StringXNumber HarmonicToTimeOptions_Number[]
Definition: HarmonicToTime.cpp:9
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_HarmonicToTimePlugin::getHelp
std::string getHelp() const
Definition: HarmonicToTime.cpp:25
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
PViewDataList::Time
std::vector< double > Time
Definition: PViewDataList.h:25
GMSH_RegisterHarmonicToTimePlugin
GMSH_Plugin * GMSH_RegisterHarmonicToTimePlugin()
Definition: HarmonicToTime.cpp:19
GMSH_HarmonicToTimePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: HarmonicToTime.cpp:45
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_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107