Skip to content
Snippets Groups Projects
Commit 94013971 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

fix plugins with model-based ElementNodeData datasets

parent 7187a751
No related branches found
No related tags found
No related merge requests found
......@@ -68,14 +68,14 @@ PView *GMSH_FieldFromAmplitudePhasePlugin::execute(PView *v)
int phiView = (int)FieldFromAmplitudePhaseOptions_Number[2].def;
std::string fileName = FieldFromAmplitudePhaseOptions_String[0].def;
std::string name_model("") ;
std::string name_model("") ;
if(fileName==""){
Msg::Info("Could not find mesh file for interpolating U=A*exp(j*k*phi)."
Msg::Info("Could not find mesh file for interpolating U=A*exp(j*k*phi)."
" Trying to use current model mesh, instead.") ;
name_model = GModel::current()->getName() ;
name_model = GModel::current()->getName() ;
fileName = name_model + ".msh" ;
}
}
PView *va = getView(aView, v);
if(!va) return v;
......@@ -91,33 +91,33 @@ PView *GMSH_FieldFromAmplitudePhasePlugin::execute(PView *v)
return v;
}
PViewData *phiData = vphi->getData();
if(aData->hasMultipleMeshes() || phiData->hasMultipleMeshes()){
Msg::Error("FieldFromAmplitudePhase plugin cannot be run on multi-mesh views");
return v;
}
OctreePost *oA = 0, *oPhi = 0 ;
oA = new OctreePost(va);
oPhi = new OctreePost(vphi);
oA = new OctreePost(va);
oPhi = new OctreePost(vphi);
GModel::current()->setVisibility(0);
GModel *umodel = new GModel ;
umodel->readMSH(fileName) ;
GModel *umodel = new GModel ;
umodel->readMSH(fileName) ;
std::vector<GEntity*> _entities ;
umodel->getEntities(_entities) ;
umodel->getEntities(_entities) ;
std::set<MVertex*> ve;
std::map<int, std::vector<double> > dataR ;
std::map<int, std::vector<double> > dataI ;
for(unsigned int ent = 0; ent < _entities.size(); ent++)
for(unsigned int ele = 0; ele < _entities[ent]->getNumMeshElements(); ele++){
MElement *e = _entities[ent]->getMeshElement(ele);
for(unsigned int ele = 0; ele < _entities[ent]->getNumMeshElements(); ele++){
MElement *e = _entities[ent]->getMeshElement(ele);
for(int nod = 0; nod < e->getNumVertices() ; nod++)
ve.insert(e->getVertex(nod));
}
for (std::set<MVertex*>::iterator it = ve.begin(); it != ve.end(); ++it){
double phi, ar, ai ;
std::vector<double> uR(1) ;
......@@ -125,18 +125,18 @@ PView *GMSH_FieldFromAmplitudePhasePlugin::execute(PView *v)
oPhi->searchScalar((*it)->x(), (*it)->y(), (*it)->z(), &phi, 0);
oA->searchScalar((*it)->x(), (*it)->y(), (*it)->z(), &ar, 0);
oA->searchScalar((*it)->x(), (*it)->y(), (*it)->z(), &ai, 1);
uR[0] = ar * cos(k*phi) - ai * sin(k*phi) ;
uI[0] = ar * sin(k*phi) + ai* cos(k*phi) ;
dataR[(*it)->getNum()] = uR ;
dataI[(*it)->getNum()] = uI ;
dataR[(*it)->getNum()] = uR ;
dataI[(*it)->getNum()] = uI ;
}
delete oA ;
delete oPhi;
PView *vu = new PView("FieldFromAPhi","NodeData", umodel, dataR, 0.0, 1) ;
PView *vu = new PView("FieldFromAPhi", "NodeData", umodel, dataR, 0.0, 1) ;
vu->addStep(umodel, dataI, 1);
if(name_model.empty())
......
......@@ -39,21 +39,23 @@ StringXNumber *GMSH_LongituteLatitudePlugin::getOption(int iopt)
PView *GMSH_LongituteLatitudePlugin::execute(PView *v)
{
int iView = (int)LongituteLatitudeOptions_Number[0].def;
PView *v1 = getView(iView, v);
if(!v1) return v;
PViewData *data1 = v1->getData();
// 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);
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);
}
}
}
}
}
double gxmin = 180, gxmax = -180, gymin = 90, gymax = -90;
// transform all "0" nodes
for(int step = 0; step < data1->getNumTimeSteps(); step++){
......@@ -66,32 +68,31 @@ PView *GMSH_LongituteLatitudePlugin::execute(PView *v)
for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){
double x, y, z;
int tag = data1->getNode(step, ent, ele, nod, x, y, z);
if(!tag){
double x2, y2, z2;
z2 = sqrt(x * x + y * y + z * z);
y2 = asin(z / z2);
x2 = atan2(y, x);
xmin=std::min(x2, xmin);
xmax=std::max(x2, xmax);
gxmin = std::min(x2 * 180 / M_PI, gxmin);
gxmax = std::max(x2 * 180 / M_PI, gxmax);
gymin = std::min(y2 * 180 / M_PI, gymin);
gymax = std::max(y2 * 180 / M_PI, gymax);
data1->setNode(step, ent, ele, nod, x2 * 180 / M_PI, y2 * 180 / M_PI, 0);
data1->tagNode(step, ent, ele, nod, 1);
if(nbComp == 3){
for(int i = 0; i < 3; i++)
data1->getValue(step, ent, ele, nod, i, vin[i]);
vout[0] = -sin(x2) * vin[0] + cos(x2) * vin[1];
vout[1] =
-sin(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) +
cos(y2) * vin[2];
vout[2] =
cos(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) +
sin(y2) * vin[2];
for(int i = 0; i < 3; i++)
data1->setValue(step, ent, ele, nod, i, vout[i]);
}
if(data1->isNodeData() && tag) continue;
double x2, y2, z2;
z2 = sqrt(x * x + y * y + z * z);
y2 = asin(z / z2);
x2 = atan2(y, x);
xmin=std::min(x2, xmin);
xmax=std::max(x2, xmax);
gxmin = std::min(x2 * 180 / M_PI, gxmin);
gxmax = std::max(x2 * 180 / M_PI, gxmax);
gymin = std::min(y2 * 180 / M_PI, gymin);
gymax = std::max(y2 * 180 / M_PI, gymax);
data1->setNode(step, ent, ele, nod, x2 * 180 / M_PI, y2 * 180 / M_PI, 0);
if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
if(nbComp == 3){
for(int i = 0; i < 3; i++)
data1->getValue(step, ent, ele, nod, i, vin[i]);
vout[0] = -sin(x2) * vin[0] + cos(x2) * vin[1];
vout[1] =
-sin(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) +
cos(y2) * vin[2];
vout[2] =
cos(y2) * (cos(x2) * vin[0] + sin(x2) * vin[1]) +
sin(y2) * vin[2];
for(int i = 0; i < 3; i++)
data1->setValue(step, ent, ele, nod, i, vout[i]);
}
}
if(xmax - xmin > M_PI){ // periodicity check (broken for continuous views)
......
......@@ -157,12 +157,14 @@ PView *GMSH_ModifyComponentPlugin::execute(PView *view)
double time = data1->getTime(step);
int step2 = (otherTimeStep < 0) ? step : otherTimeStep;
// tag all the nodes with "0" (the default tag)
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);
if(data1->isNodeData()){
// tag all the nodes with "0" (the default tag)
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);
}
}
}
......@@ -172,12 +174,14 @@ PView *GMSH_ModifyComponentPlugin::execute(PView *view)
int numComp = data1->getNumComponents(step, ent, ele);
int numComp2 = octree ? 9 : data2->getNumComponents(step2, ent, ele);
int numNodes = data1->getNumNodes(step, ent, ele);
std::vector<int> tag(numNodes);
std::vector<double> x(numNodes), y(numNodes), z(numNodes);
for(int nod = 0; nod < numNodes; nod++)
tag[nod] = data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]);
std::vector<int> tag(numNodes, 0.);
if(data1->isNodeData()){
for(int nod = 0; nod < numNodes; nod++)
tag[nod] = data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]);
}
for(int nod = 0; nod < numNodes; nod++){
if(tag[nod]) continue; // node has already been modified
if(data1->isNodeData() && tag[nod]) continue; // node has already been modified
std::vector<double> v(std::max(9, numComp), 0.);
for(int comp = 0; comp < numComp; comp++)
data1->getValue(step, ent, ele, nod, comp, v[comp]);
......@@ -204,7 +208,7 @@ PView *GMSH_ModifyComponentPlugin::execute(PView *view)
for(int i = 0; i < 9; i++) values[16 + i] = w[i];
if(f.eval(values, res))
data1->setValue(step, ent, ele, nod, comp, res[0]);
data1->tagNode(step, ent, ele, nod, 1);
if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
}
}
}
......
......@@ -61,13 +61,15 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v)
return v1;
}
// 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);
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);
}
}
}
}
......@@ -79,7 +81,7 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v)
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(tag) continue;
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);
......@@ -88,8 +90,10 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v)
double phase = atan2(vi, vr);
data1->setValue(rIndex, ent, ele, nod, comp, modulus);
data1->setValue(iIndex, ent, ele, nod, comp, phase);
data1->tagNode(rIndex, ent, ele, nod, 1);
data1->tagNode(iIndex, ent, ele, nod, 1);
if(data1->isNodeData()){
data1->tagNode(rIndex, ent, ele, nod, 1);
data1->tagNode(iIndex, ent, ele, nod, 1);
}
}
}
}
......
......@@ -74,13 +74,15 @@ PView *GMSH_SphericalRaisePlugin::execute(PView *v)
return v;
}
// 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);
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);
}
}
}
}
......@@ -93,20 +95,19 @@ PView *GMSH_SphericalRaisePlugin::execute(PView *v)
for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){
double x, y, z;
int tag = data1->getNode(step, ent, ele, nod, x, y, z);
if(!tag){
double r[3], val;
r[0] = x - center[0];
r[1] = y - center[1];
r[2] = z - center[2];
norme(r);
data1->getScalarValue(step, ent, ele, nod, val);
double coef = offset + raise * val;
x += coef * r[0];
y += coef * r[1];
z += coef * r[2];
data1->setNode(step, ent, ele, nod, x, y, z);
data1->tagNode(step, ent, ele, nod, 1);
}
if(data1->isNodeData() && tag) continue;
double r[3], val;
r[0] = x - center[0];
r[1] = y - center[1];
r[2] = z - center[2];
norme(r);
data1->getScalarValue(step, ent, ele, nod, val);
double coef = offset + raise * val;
x += coef * r[0];
y += coef * r[1];
z += coef * r[2];
data1->setNode(step, ent, ele, nod, x, y, z);
if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
}
}
}
......
......@@ -80,14 +80,16 @@ PView *GMSH_TransformPlugin::execute(PView *v)
PViewData *data1 = v1->getData();
// 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;
if(swap) data1->reverseElement(step, ent, ele);
for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++)
data1->tagNode(step, ent, ele, nod, 0);
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;
if(swap) data1->reverseElement(step, ent, ele);
for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++)
data1->tagNode(step, ent, ele, nod, 0);
}
}
}
}
......@@ -100,14 +102,13 @@ PView *GMSH_TransformPlugin::execute(PView *v)
for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){
double x, y, z;
int tag = data1->getNode(step, ent, ele, nod, x, y, z);
if(!tag){
double x2, y2, z2;
x2 = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3];
y2 = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3];
z2 = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3];
data1->setNode(step, ent, ele, nod, x2, y2, z2);
data1->tagNode(step, ent, ele, nod, 1);
}
if(data1->isNodeData() && tag) continue;
double x2, y2, z2;
x2 = mat[0][0] * x + mat[0][1] * y + mat[0][2] * z + mat[0][3];
y2 = mat[1][0] * x + mat[1][1] * y + mat[1][2] * z + mat[1][3];
z2 = mat[2][0] * x + mat[2][1] * y + mat[2][2] * z + mat[2][3];
data1->setNode(step, ent, ele, nod, x2, y2, z2);
if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
}
}
}
......
......@@ -96,13 +96,15 @@ PView *GMSH_WarpPlugin::execute(PView *v)
}
}
// 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);
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);
}
}
}
}
......@@ -115,14 +117,16 @@ PView *GMSH_WarpPlugin::execute(PView *v)
int numNodes = data1->getNumNodes(step, ent, ele);
if(numNodes < 2) continue;
double x[8], y[8], z[8], n[3] = {0., 0., 0.};
int tag[8];
for(int nod = 0; nod < numNodes; nod++)
tag[nod] = data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]);
std::vector<int> tag(8, 0);
if(data1->isNodeData()){
for(int nod = 0; nod < numNodes; nod++)
tag[nod] = data1->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]);
}
int dim = data1->getDimension(step, ent, ele);
if(normals && dim == 2)
normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], n);
for(int nod = 0; nod < numNodes; nod++){
if(tag[nod]) continue; // already transformed
if(data1->isNodeData() && tag[nod]) continue; // already transformed
double mult = 1., val[3] = {n[0], n[1], n[2]};
if(normals){
if(dim == 2){
......@@ -139,7 +143,7 @@ PView *GMSH_WarpPlugin::execute(PView *v)
y[nod] += factor * mult * val[1];
z[nod] += factor * mult * val[2];
data1->setNode(step, ent, ele, nod, x[nod], y[nod], z[nod]);
data1->tagNode(step, ent, ele, nod, 1);
if(data1->isNodeData()) data1->tagNode(step, ent, ele, nod, 1);
}
}
}
......
......@@ -189,6 +189,7 @@ class PViewData {
virtual bool hasPartition(int step, int part){ return false; }
virtual bool hasMultipleMeshes(){ return false; }
virtual bool hasModel(GModel *model, int step=-1){ return false; }
virtual bool isNodeData(){ return false; }
// true if data is given at Gauss points (instead of vertices)
virtual bool useGaussPoints(){ return false; }
......
......@@ -227,6 +227,7 @@ class PViewDataGModel : public PViewData {
bool hasPartition(int step, int part);
bool hasMultipleMeshes();
bool hasModel(GModel *model, int step=-1);
bool isNodeData(){ return _type == NodeData; }
bool useGaussPoints(){ return _type == GaussPointData; }
GModel* getModel(int step){ return _steps[step]->getModel(); }
GEntity *getEntity(int step, int ent);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment