1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
// Gmsh - Copyright (C) 1997-2021 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
#include "ModulusPhase.h"
StringXNumber ModulusPhaseOptions_Number[] = {
{GMSH_FULLRC, "RealPart", nullptr, 0.},
{GMSH_FULLRC, "ImaginaryPart", nullptr, 1.},
{GMSH_FULLRC, "View", nullptr, -1.}};
extern "C" {
GMSH_Plugin *GMSH_RegisterModulusPhasePlugin()
{
return new GMSH_ModulusPhasePlugin();
}
}
std::string GMSH_ModulusPhasePlugin::getHelp() const
{
return "Plugin(ModulusPhase) interprets the time steps "
"`realPart' and `imaginaryPart' in the view `View' "
"as the real and imaginary parts of a complex field "
"and replaces them with their corresponding "
"modulus and phase.\n\n"
"If `View' < 0, the plugin is run on the current view.\n\n"
"Plugin(ModulusPhase) is executed in-place.";
}
int GMSH_ModulusPhasePlugin::getNbOptions() const
{
return sizeof(ModulusPhaseOptions_Number) / sizeof(StringXNumber);
}
StringXNumber *GMSH_ModulusPhasePlugin::getOption(int iopt)
{
return &ModulusPhaseOptions_Number[iopt];
}
PView *GMSH_ModulusPhasePlugin::execute(PView *v)
{
int rIndex = (int)ModulusPhaseOptions_Number[0].def;
int iIndex = (int)ModulusPhaseOptions_Number[1].def;
int iView = (int)ModulusPhaseOptions_Number[2].def;
PView *v1 = getView(iView, v);
if(!v1) return v;
PViewData *data1 = v1->getData();
if(data1->hasMultipleMeshes()) {
Msg::Error("ModulusPhase plugin cannot be run on multi-mesh views");
return v;
}
if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || iIndex < 0 ||
iIndex >= data1->getNumTimeSteps()) {
Msg::Error("Wrong real or imaginary part index");
return v1;
}
if(data1->isNodeData()) {
// tag all the nodes with "0" (the default tag)
for(int step = 0; step < data1->getNumTimeSteps(); step++) {
for(int ent = 0; ent < data1->getNumEntities(step); ent++) {
for(int ele = 0; ele < data1->getNumElements(step, ent); ele++) {
if(data1->skipElement(step, ent, ele)) continue;
for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++)
data1->tagNode(step, ent, ele, nod, 0);
}
}
}
}
// transform all "0" nodes
for(int ent = 0; ent < data1->getNumEntities(rIndex); ent++) {
for(int ele = 0; ele < data1->getNumElements(rIndex, ent); ele++) {
if(data1->skipElement(rIndex, ent, ele)) continue;
for(int nod = 0; nod < data1->getNumNodes(rIndex, ent, ele); nod++) {
double x, y, z;
int tag = data1->getNode(rIndex, ent, ele, nod, x, y, z);
if(data1->isNodeData() && tag) continue;
for(int comp = 0; comp < data1->getNumComponents(rIndex, ent, ele);
comp++) {
double vr, vi;
data1->getValue(rIndex, ent, ele, nod, comp, vr);
data1->getValue(iIndex, ent, ele, nod, comp, vi);
double modulus = sqrt(vr * vr + vi * vi);
double phase = atan2(vi, vr);
data1->setValue(rIndex, ent, ele, nod, comp, modulus);
data1->setValue(iIndex, ent, ele, nod, comp, phase);
if(data1->isNodeData()) {
data1->tagNode(rIndex, ent, ele, nod, 1);
data1->tagNode(iIndex, ent, ele, nod, 1);
}
}
}
}
}
data1->setName(data1->getName() + "_ModulusPhase");
data1->setName(data1->getName() + ".pos");
data1->finalize();
v1->setChanged(true);
return v1;
}
|