gmsh-TingyuanDoc
0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
FieldFromAmplitudePhase.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 <stdlib.h>
7
#include "
GmshGlobal.h
"
8
#include "GmshConfig.h"
9
#include "
GModel.h
"
10
#include "
MElement.h
"
11
#include "
OctreePost.h
"
12
#include "
FieldFromAmplitudePhase.h
"
13
14
StringXNumber
FieldFromAmplitudePhaseOptions_Number
[] = {
15
{
GMSH_FULLRC
,
"Wavenumber"
,
nullptr
, 5.},
16
{
GMSH_FULLRC
,
"AmplitudeView"
,
nullptr
, 0.},
17
{
GMSH_FULLRC
,
"PhaseView"
,
nullptr
, 1.},
18
};
19
20
StringXString
FieldFromAmplitudePhaseOptions_String
[] = {
21
{
GMSH_FULLRC
,
"MeshFile"
,
nullptr
,
"fine.msh"
}};
22
23
extern
"C"
{
24
GMSH_Plugin
*
GMSH_RegisterFieldFromAmplitudePhasePlugin
()
25
{
26
return
new
GMSH_FieldFromAmplitudePhasePlugin
();
27
}
28
}
29
30
std::string
GMSH_FieldFromAmplitudePhasePlugin::getHelp
()
const
31
{
32
return
"Plugin(FieldFromAmplitudePhase) builds a complex field 'u' from "
33
"amplitude 'a' (complex) and phase 'phi' given in two different "
34
"'Views' "
35
"u = a * exp(k*phi), with k the wavenumber. \n\n"
36
"The result is to be interpolated in a sufficiently fine mesh: "
37
"'MeshFile'. \n\n"
38
"Plugin(FieldFromAmplitudePhase) generates one new view."
;
39
}
40
41
int
GMSH_FieldFromAmplitudePhasePlugin::getNbOptions
()
const
42
{
43
return
sizeof
(
FieldFromAmplitudePhaseOptions_Number
) /
sizeof
(
StringXNumber
);
44
}
45
46
StringXNumber
*
GMSH_FieldFromAmplitudePhasePlugin::getOption
(
int
iopt)
47
{
48
return
&
FieldFromAmplitudePhaseOptions_Number
[iopt];
49
}
50
51
int
GMSH_FieldFromAmplitudePhasePlugin::getNbOptionsStr
()
const
52
{
53
return
sizeof
(
FieldFromAmplitudePhaseOptions_String
) /
sizeof
(
StringXString
);
54
}
55
56
StringXString
*
GMSH_FieldFromAmplitudePhasePlugin::getOptionStr
(
int
iopt)
57
{
58
return
&
FieldFromAmplitudePhaseOptions_String
[iopt];
59
}
60
61
PView
*
GMSH_FieldFromAmplitudePhasePlugin::execute
(
PView
*v)
62
{
63
double
k = (double)
FieldFromAmplitudePhaseOptions_Number
[0].def;
64
int
aView = (int)
FieldFromAmplitudePhaseOptions_Number
[1].def;
65
int
phiView = (int)
FieldFromAmplitudePhaseOptions_Number
[2].def;
66
std::string fileName =
FieldFromAmplitudePhaseOptions_String
[0].
def
;
67
68
std::string name_model(
""
);
69
70
if
(fileName ==
""
) {
71
Msg::Info
(
"Could not find mesh file for interpolating U=A*exp(j*k*phi)."
72
" Trying to use current model mesh, instead."
);
73
name_model =
GModel::current
()->
getName
();
74
fileName = name_model +
".msh"
;
75
}
76
77
PView
*va =
getView
(aView, v);
78
if
(!va)
return
v;
79
PViewData
*aData = va->
getData
();
80
if
(aData->
getNumTimeSteps
() != 2) {
81
Msg::Error
(
"Invalid number of time steps for AView, it must be complex!"
);
82
return
v;
83
}
84
85
PView
*vphi =
getView
(phiView, v);
86
if
(!vphi) {
87
Msg::Error
(
"FieldFromAmplitudePhase plugin could not find PhiView %i"
,
88
phiView);
89
return
v;
90
}
91
PViewData
*phiData = vphi->
getData
();
92
93
if
(aData->
hasMultipleMeshes
() || phiData->
hasMultipleMeshes
()) {
94
Msg::Error
(
95
"FieldFromAmplitudePhase plugin cannot be run on multi-mesh views"
);
96
return
v;
97
}
98
99
OctreePost
*oA =
nullptr
, *oPhi =
nullptr
;
100
oA =
new
OctreePost
(va);
101
oPhi =
new
OctreePost
(vphi);
102
103
GModel::current
()->
setVisibility
(0);
104
GModel
*umodel =
new
GModel
;
105
umodel->
readMSH
(fileName);
106
std::vector<GEntity *> _entities;
107
umodel->
getEntities
(_entities);
108
109
std::set<MVertex *> ve;
110
std::map<int, std::vector<double> > dataR;
111
std::map<int, std::vector<double> > dataI;
112
113
for
(std::size_t ent = 0; ent < _entities.size(); ent++)
114
for
(std::size_t ele = 0; ele < _entities[ent]->getNumMeshElements();
115
ele++) {
116
MElement
*e = _entities[ent]->getMeshElement(ele);
117
for
(std::size_t nod = 0; nod < e->
getNumVertices
(); nod++)
118
ve.insert(e->
getVertex
(nod));
119
}
120
121
for
(
auto
it = ve.begin(); it != ve.end(); ++it) {
122
double
phi, ar, ai;
123
std::vector<double> uR(1);
124
std::vector<double> uI(1);
125
oPhi->searchScalar((*it)->x(), (*it)->y(), (*it)->z(), &phi, 0);
126
oA->
searchScalar
((*it)->x(), (*it)->y(), (*it)->z(), &ar, 0);
127
oA->
searchScalar
((*it)->x(), (*it)->y(), (*it)->z(), &ai, 1);
128
129
uR[0] = ar * cos(k * phi) - ai * sin(k * phi);
130
uI[0] = ar * sin(k * phi) + ai * cos(k * phi);
131
132
dataR[(*it)->getNum()] = uR;
133
dataI[(*it)->getNum()] = uI;
134
}
135
136
delete
oA;
137
delete
oPhi;
138
139
PView
*vu =
new
PView
(
"FieldFromAPhi"
,
"NodeData"
, umodel, dataR, 0.0, 1);
140
vu->
addStep
(umodel, dataI, 1);
141
142
if
(name_model.empty())
143
umodel->
setName
(
"fine"
);
144
else
145
umodel->
setName
(name_model);
146
147
return
vu;
148
}
StringXString
Definition:
Options.h:910
GMSH_RegisterFieldFromAmplitudePhasePlugin
GMSH_Plugin * GMSH_RegisterFieldFromAmplitudePhasePlugin()
Definition:
FieldFromAmplitudePhase.cpp:24
GModel::setVisibility
void setVisibility(char val)
Definition:
GModel.h:341
PView
Definition:
PView.h:27
OctreePost::searchScalar
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)
Definition:
OctreePost.cpp:578
GMSH_FieldFromAmplitudePhasePlugin::getNbOptionsStr
int getNbOptionsStr() const
Definition:
FieldFromAmplitudePhase.cpp:51
GMSH_Plugin
Definition:
Plugin.h:26
Msg::Info
static void Info(const char *fmt,...)
Definition:
GmshMessage.cpp:587
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
OctreePost.h
FieldFromAmplitudePhase.h
GModel::getName
std::string getName() const
Definition:
GModel.h:329
Msg::Error
static void Error(const char *fmt,...)
Definition:
GmshMessage.cpp:482
StringXNumber
Definition:
Options.h:918
GMSH_FieldFromAmplitudePhasePlugin::getOption
StringXNumber * getOption(int iopt)
Definition:
FieldFromAmplitudePhase.cpp:46
OctreePost
Definition:
BoundaryLayers.cpp:23
PViewData::hasMultipleMeshes
virtual bool hasMultipleMeshes()
Definition:
PViewData.h:216
MElement::getNumVertices
virtual std::size_t getNumVertices() const =0
GModel::readMSH
int readMSH(const std::string &name)
Definition:
GModelIO_MSH.cpp:12
GMSH_FieldFromAmplitudePhasePlugin::getOptionStr
StringXString * getOptionStr(int iopt)
Definition:
FieldFromAmplitudePhase.cpp:56
MElement::getVertex
virtual const MVertex * getVertex(int num) const =0
FieldFromAmplitudePhaseOptions_String
StringXString FieldFromAmplitudePhaseOptions_String[]
Definition:
FieldFromAmplitudePhase.cpp:20
GModel::setName
void setName(const std::string &name)
Definition:
GModel.h:328
GMSH_FULLRC
#define GMSH_FULLRC
Definition:
Options.h:20
GModel
Definition:
GModel.h:44
GMSH_FieldFromAmplitudePhasePlugin
Definition:
FieldFromAmplitudePhase.h:15
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition:
PView.cpp:233
StringXString::def
std::string def
Definition:
Options.h:914
MElement
Definition:
MElement.h:30
GMSH_FieldFromAmplitudePhasePlugin::execute
PView * execute(PView *)
Definition:
FieldFromAmplitudePhase.cpp:61
GModel::getEntities
void getEntities(std::vector< GEntity * > &entities, int dim=-1) const
Definition:
GModel.cpp:651
GmshGlobal.h
PViewData
Definition:
PViewData.h:29
GMSH_FieldFromAmplitudePhasePlugin::getHelp
std::string getHelp() const
Definition:
FieldFromAmplitudePhase.cpp:30
MElement.h
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition:
Plugin.cpp:81
FieldFromAmplitudePhaseOptions_Number
StringXNumber FieldFromAmplitudePhaseOptions_Number[]
Definition:
FieldFromAmplitudePhase.cpp:14
GModel.h
GMSH_FieldFromAmplitudePhasePlugin::getNbOptions
int getNbOptions() const
Definition:
FieldFromAmplitudePhase.cpp:41
PView::addStep
void addStep(GModel *model, const std::map< int, std::vector< double > > &data, double time=0., int numComp=-1)
Definition:
PView.cpp:168
GModel::current
static GModel * current(int index=-1)
Definition:
GModel.cpp:136
src
plugin
FieldFromAmplitudePhase.cpp
Generated by
1.8.18