diff --git a/Plugin/ModulusPhase.cpp b/Plugin/ModulusPhase.cpp index e1a1bb69149bc14c9892a6c968a3fc8f598b7508..e3ec3a6bba500d5dd41e5d1ecb22fd7f1624c293 100644 --- a/Plugin/ModulusPhase.cpp +++ b/Plugin/ModulusPhase.cpp @@ -1,4 +1,4 @@ -// $Id: ModulusPhase.cpp,v 1.9 2008-03-20 11:44:14 geuzaine Exp $ +// $Id: ModulusPhase.cpp,v 1.10 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -35,12 +35,6 @@ extern "C" } } - -GMSH_ModulusPhasePlugin::GMSH_ModulusPhasePlugin() -{ - ; -} - void GMSH_ModulusPhasePlugin::getName(char *name) const { strcpy(name, "Modulus Phase"); @@ -77,33 +71,6 @@ void GMSH_ModulusPhasePlugin::catchErrorMessage(char *errorMessage) const strcpy(errorMessage, "ModulusPhase failed..."); } - -static void mp(int nb1, List_T *list1, int nbNod, int nbComp) -{ - if(!nb1) return; - - int rIndex = (int)ModulusPhaseOptions_Number[0].def; - int iIndex = (int)ModulusPhaseOptions_Number[1].def; - - int nb = List_Nbr(list1) / nb1; - for(int i = 0; i < List_Nbr(list1); i += nb) { - double *valr = (double *)List_Pointer_Fast(list1, i + 3 * nbNod + - nbNod * nbComp * rIndex); - double *vali = (double *)List_Pointer_Fast(list1, i + 3 * nbNod + - nbNod * nbComp * iIndex); - for(int j = 0; j < nbNod; j++) { - for(int k = 0; k < nbComp; k++) { - double vr = valr[nbComp * j + k]; - double vi = vali[nbComp * j + k]; - double modulus = sqrt(vr*vr+vi*vi); - double phase = atan2(vi, vr); - valr[nbComp * j + k] = modulus; - vali[nbComp * j + k] = phase; - } - } - } -} - PView *GMSH_ModulusPhasePlugin::execute(PView *v) { int rIndex = (int)ModulusPhaseOptions_Number[0].def; @@ -113,8 +80,11 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v) PView *v1 = getView(iView, v); if(!v1) return v; - PViewDataList *data1 = getDataList(v1); - if(!data1) return v; + PViewData *data1 = v1->getData(); + if(data1->hasMultipleMeshes()){ + Msg(GERROR, "Gradient plugin cannot be run on multi-mesh views"); + return v; + } if(rIndex < 0 || rIndex >= data1->getNumTimeSteps() || iIndex < 0 || iIndex >= data1->getNumTimeSteps()){ @@ -122,34 +92,44 @@ PView *GMSH_ModulusPhasePlugin::execute(PView *v) return v1; } - mp(data1->NbSP, data1->SP, 1, 1); - mp(data1->NbVP, data1->VP, 1, 3); - mp(data1->NbTP, data1->TP, 1, 9); - mp(data1->NbSL, data1->SL, 2, 1); - mp(data1->NbVL, data1->VL, 2, 3); - mp(data1->NbTL, data1->TL, 2, 9); - mp(data1->NbST, data1->ST, 3, 1); - mp(data1->NbVT, data1->VT, 3, 3); - mp(data1->NbTT, data1->TT, 3, 9); - mp(data1->NbSQ, data1->SQ, 4, 1); - mp(data1->NbVQ, data1->VQ, 4, 3); - mp(data1->NbTQ, data1->TQ, 4, 9); - mp(data1->NbSS, data1->SS, 4, 1); - mp(data1->NbVS, data1->VS, 4, 3); - mp(data1->NbTS, data1->TS, 4, 9); - mp(data1->NbSH, data1->SH, 8, 1); - mp(data1->NbVH, data1->VH, 8, 3); - mp(data1->NbTH, data1->TH, 8, 9); - mp(data1->NbSI, data1->SI, 6, 1); - mp(data1->NbVI, data1->VI, 6, 3); - mp(data1->NbTI, data1->TI, 6, 9); - mp(data1->NbSY, data1->SY, 5, 1); - mp(data1->NbVY, data1->VY, 5, 3); - mp(data1->NbTY, data1->TY, 5, 9); + // 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(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); + 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; } diff --git a/Plugin/ModulusPhase.h b/Plugin/ModulusPhase.h index e5b6806b0d7b103fd5c25303fd329b3bf62a039f..b2dec43a6d8669f100477aef1d7dbc731bbc23e5 100644 --- a/Plugin/ModulusPhase.h +++ b/Plugin/ModulusPhase.h @@ -30,12 +30,12 @@ extern "C" class GMSH_ModulusPhasePlugin : public GMSH_Post_Plugin { public: - GMSH_ModulusPhasePlugin(); + GMSH_ModulusPhasePlugin(){} void getName(char *name) const; void getInfos(char *author, char *copyright, char *help_text) const; void catchErrorMessage(char *errorMessage) const; int getNbOptions() const; - StringXNumber* getOption(int iopt); + StringXNumber *getOption(int iopt); PView *execute(PView *); }; diff --git a/Plugin/SphericalRaise.cpp b/Plugin/SphericalRaise.cpp index 9624fd84b731bfc96514b49b62424e4311c20972..3a11da23c471e6c5dff1592151d65673a9f77540 100644 --- a/Plugin/SphericalRaise.cpp +++ b/Plugin/SphericalRaise.cpp @@ -1,4 +1,4 @@ -// $Id: SphericalRaise.cpp,v 1.33 2008-04-05 17:49:23 geuzaine Exp $ +// $Id: SphericalRaise.cpp,v 1.34 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -110,12 +110,8 @@ PView *GMSH_SphericalRaisePlugin::execute(PView *v) 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; - int numNodes = data1->getNumNodes(step, ent, ele); - for(int nod = 0; nod < numNodes; nod++){ - double x, y, z; - data1->getNode(step, ent, ele, nod, x, y, z); - data1->setNode(step, ent, ele, nod, x, y, z, 0); - } + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) + data1->tagNode(step, ent, ele, nod, 0); } } } @@ -125,8 +121,7 @@ PView *GMSH_SphericalRaisePlugin::execute(PView *v) 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; - int numNodes = data1->getNumNodes(step, ent, ele); - for(int nod = 0; nod < numNodes; nod++){ + 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){ @@ -140,7 +135,8 @@ PView *GMSH_SphericalRaisePlugin::execute(PView *v) x += coef * r[0]; y += coef * r[1]; z += coef * r[2]; - data1->setNode(step, ent, ele, nod, x, y, z, 1); + data1->setNode(step, ent, ele, nod, x, y, z); + data1->tagNode(step, ent, ele, nod, 1); } } } diff --git a/Plugin/Transform.cpp b/Plugin/Transform.cpp index 38c413449edfaa77e9851027b11008d0d4071cf1..cc4e68728445998c930669fc30cd32cb89caad5a 100644 --- a/Plugin/Transform.cpp +++ b/Plugin/Transform.cpp @@ -1,4 +1,4 @@ -// $Id: Transform.cpp,v 1.40 2008-04-05 17:49:23 geuzaine Exp $ +// $Id: Transform.cpp,v 1.41 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -117,23 +117,18 @@ PView *GMSH_TransformPlugin::execute(PView *v) for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){ if(data1->skipElement(step, ent, ele)) continue; if(swap) data1->revertElement(step, ent, ele); - int numNodes = data1->getNumNodes(step, ent, ele); - for(int nod = 0; nod < numNodes; nod++){ - double x, y, z; - data1->getNode(step, ent, ele, nod, x, y, z); - data1->setNode(step, ent, ele, nod, x, y, z, 0); - } + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) + data1->tagNode(step, ent, ele, nod, 0); } } } - + // transform all "0" nodes 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; - int numNodes = data1->getNumNodes(step, ent, ele); - for(int nod = 0; nod < numNodes; nod++){ + 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){ @@ -141,7 +136,8 @@ PView *GMSH_TransformPlugin::execute(PView *v) 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, 1); + data1->setNode(step, ent, ele, nod, x2, y2, z2); + data1->tagNode(step, ent, ele, nod, 1); } } } diff --git a/Plugin/Warp.cpp b/Plugin/Warp.cpp index e342ccca78bf6055fcc2b7637fc67c51fd7fa3a5..d1bd5d97408a7d199ca56ef1d12cb3832fab5f15 100644 --- a/Plugin/Warp.cpp +++ b/Plugin/Warp.cpp @@ -1,4 +1,4 @@ -// $Id: Warp.cpp,v 1.14 2008-04-05 17:49:23 geuzaine Exp $ +// $Id: Warp.cpp,v 1.15 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -132,16 +132,12 @@ PView *GMSH_WarpPlugin::execute(PView *v) 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; - int numNodes = data1->getNumNodes(step, ent, ele); - for(int nod = 0; nod < numNodes; nod++){ - double x, y, z; - data1->getNode(step, ent, ele, nod, x, y, z); - data1->setNode(step, ent, ele, nod, x, y, z, 0); - } + for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++) + data1->tagNode(step, ent, ele, nod, 0); } } } - + // transform each "0" node: (x,y,z) += factor * mult * (valx, valy, valz) for(int step = 0; step < data1->getNumTimeSteps(); step++){ for(int ent = 0; ent < data1->getNumEntities(step); ent++){ @@ -172,7 +168,8 @@ PView *GMSH_WarpPlugin::execute(PView *v) x[nod] += factor * mult * val[0]; y[nod] += factor * mult * val[1]; z[nod] += factor * mult * val[2]; - data1->setNode(step, ent, ele, nod, x[nod], y[nod], z[nod], 1); + data1->setNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); + data1->tagNode(step, ent, ele, nod, 1); } } } diff --git a/Post/PViewData.cpp b/Post/PViewData.cpp index 628ef6cbd16b4a2f6ba7222eafc066cee79db5d5..72544dc6f7476b82786574d133ccbae81f4235f7 100644 --- a/Post/PViewData.cpp +++ b/Post/PViewData.cpp @@ -1,4 +1,4 @@ -// $Id: PViewData.cpp,v 1.16 2008-04-05 09:21:37 geuzaine Exp $ +// $Id: PViewData.cpp,v 1.17 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -39,14 +39,13 @@ bool PViewData::empty() void PViewData::getScalarValue(int step, int ent, int ele, int nod, double &val) { int numComp = getNumComponents(step, ent, ele); - double d[9]; + std::vector<double> d(numComp); for(int comp = 0; comp < numComp; comp++) getValue(step, ent, ele, nod, comp, d[comp]); - val = ComputeScalarRep(numComp, d); + val = ComputeScalarRep(numComp, &d[0]); } -void PViewData::setNode(int step, int ent, int ele, int nod, double x, double y, double z, - int tag) +void PViewData::setNode(int step, int ent, int ele, int nod, double x, double y, double z) { Msg(GERROR, "Cannot change node coordinates in this view"); } diff --git a/Post/PViewData.h b/Post/PViewData.h index ad656676133e19f5a7eadab28d227395ef93149f..9566fa294d979257d4f23041da03b982f2196281 100644 --- a/Post/PViewData.h +++ b/Post/PViewData.h @@ -78,12 +78,14 @@ class PViewData { // Returns the number of nodes of the ele-th element in the ent-th // entity virtual int getNumNodes(int step, int ent, int ele) = 0; - // Gets/Sets the coordinates of the nod-th node from the ele-th element - // in the ent-th entity (if the node has a tag, getNode returns it) + // Gets/Sets the coordinates and tag of the nod-th node from the + // ele-th element in the ent-th entity (if the node has a tag, + // getNode returns it) virtual int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z) = 0; virtual void setNode(int step, int ent, int ele, int nod, - double x, double y, double z, int tag=0); + double x, double y, double z); + virtual void tagNode(int step, int ent, int ele, int nod, int tag){} // Returns the number of componts available for the ele-th element // in the ent-th entity virtual int getNumComponents(int step, int ent, int ele) = 0; diff --git a/Post/PViewDataGModel.cpp b/Post/PViewDataGModel.cpp index 7550ca42312d53222c13fc929b3d707e5ff7621a..148b912cd8df1eb2158cd6d54433cb5c83bf62bc 100644 --- a/Post/PViewDataGModel.cpp +++ b/Post/PViewDataGModel.cpp @@ -1,4 +1,4 @@ -// $Id: PViewDataGModel.cpp,v 1.48 2008-04-05 09:21:37 geuzaine Exp $ +// $Id: PViewDataGModel.cpp,v 1.49 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -41,9 +41,22 @@ bool PViewDataGModel::finalize() { _min = VAL_INF; _max = -VAL_INF; - for(unsigned int i = 0; i < _steps.size(); i++){ - _min = std::min(_min, _steps[i]->getMin()); - _max = std::max(_max, _steps[i]->getMax()); + for(int step = 0; step < getNumTimeSteps(); step++){ + _steps[step]->setMin(VAL_INF); + _steps[step]->setMax(-VAL_INF); + for(int ent = 0; ent < getNumEntities(step); ent++){ + for(int ele = 0; ele < getNumElements(step, ent); ele++){ + if(skipElement(step, ent, ele)) continue; + for(int nod = 0; nod < getNumNodes(step, ent, ele); nod++){ + double val; + getScalarValue(step, ent, ele, nod, val); + _steps[step]->setMin(std::min(_steps[step]->getMin(), val)); + _steps[step]->setMax(std::max(_steps[step]->getMax(), val)); + } + } + } + _min = std::min(_min, _steps[step]->getMin()); + _max = std::max(_max, _steps[step]->getMax()); } setDirty(false); return true; @@ -186,13 +199,19 @@ int PViewDataGModel::getNode(int step, int ent, int ele, int nod, } void PViewDataGModel::setNode(int step, int ent, int ele, int nod, - double x, double y, double z, int tag) + double x, double y, double z) { // no sanity checks (assumed to be guarded by skipElement) MVertex *v = _steps[step]->getEntity(ent)->getMeshElement(ele)->getVertex(nod); v->x() = x; v->y() = y; v->z() = z; +} + +void PViewDataGModel::tagNode(int step, int ent, int ele, int nod, int tag) +{ + // no sanity checks (assumed to be guarded by skipElement) + MVertex *v = _steps[step]->getEntity(ent)->getMeshElement(ele)->getVertex(nod); v->setIndex(tag); } @@ -286,9 +305,6 @@ void PViewDataGModel::smooth() if(d){ double f = nodeConnect[i]; if(f) for(int j = 0; j < numComp; j++) d[j] /= f; - double s = ComputeScalarRep(numComp, d); - _steps2[step]->setMin(std::min(_steps2[step]->getMin(), s)); - _steps2[step]->setMax(std::max(_steps2[step]->getMax(), s)); } } } diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index e7b8d5fcbedc4a26faffb073090d897254f526d6..a87922afc511cb959e6b336fa8e19565deb48cbd 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -159,8 +159,8 @@ class PViewDataGModel : public PViewData { int getDimension(int step, int ent, int ele); int getNumNodes(int step, int ent, int ele); int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z); - void setNode(int step, int ent, int ele, int nod, double x, double y, double z, - int tag=0); + void setNode(int step, int ent, int ele, int nod, double x, double y, double z); + void tagNode(int step, int ent, int ele, int nod, int tag); int getNumComponents(int step, int ent, int ele); void getValue(int step, int ent, int ele, int node, int comp, double &val); void setValue(int step, int ent, int ele, int node, int comp, double val); diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index 8be3af98dfa6339e08b22cff9fcbda810e7a4429..357821c759a6d2aa7ffaa70296b30e043dbe543f 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -1,4 +1,4 @@ -// $Id: PViewDataGModelIO.cpp,v 1.39 2008-04-06 07:51:37 geuzaine Exp $ +// $Id: PViewDataGModelIO.cpp,v 1.40 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -81,11 +81,6 @@ bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp, for(int j = 0; j < numComp * mult; j++) if(fscanf(fp, "%lf", &d[j]) != 1) return false; } - for(int j = 0; j < mult; j++){ - double s = ComputeScalarRep(numComp, &d[numComp *j]); - _steps[step]->setMin(std::min(_steps[step]->getMin(), s)); - _steps[step]->setMax(std::max(_steps[step]->getMax(), s)); - } } _partitions.insert(partition); @@ -379,9 +374,6 @@ bool PViewDataGModel::readMED(std::string fileName, int fileIndex) int j2 = (ent == MED_NOEUD_ELEMENT) ? med2mshNodeIndex(ele, j) : j; for(int k = 0; k < numComp; k++) d[numCompMsh * j + k] = val[numComp * mult * i + numComp * j2 + k]; - double s = ComputeScalarRep(numCompMsh, &d[numCompMsh * j]); - _steps[step]->setMin(std::min(_steps[step]->getMin(), s)); - _steps[step]->setMax(std::max(_steps[step]->getMax(), s)); } } } diff --git a/Post/PViewDataList.cpp b/Post/PViewDataList.cpp index 83cc55ea319b1bed50a930638e7b77fcaae3669f..81a0f5335e31c5e3201979a933703866f57ef9cf 100644 --- a/Post/PViewDataList.cpp +++ b/Post/PViewDataList.cpp @@ -1,4 +1,4 @@ -// $Id: PViewDataList.cpp,v 1.20 2008-04-05 09:21:37 geuzaine Exp $ +// $Id: PViewDataList.cpp,v 1.21 2008-04-06 09:20:17 geuzaine Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -344,7 +344,7 @@ int PViewDataList::getNode(int step, int ent, int ele, int nod, } void PViewDataList::setNode(int step, int ent, int ele, int nod, - double x, double y, double z, int tag) + double x, double y, double z) { if(step) return; if(ele != _lastElement) _setLast(ele); diff --git a/Post/PViewDataList.h b/Post/PViewDataList.h index 227080d05628a139d5d6cfbd130937994327567f..4355a87d9378abc82979ade1a6f4e8e65dcd48f5 100644 --- a/Post/PViewDataList.h +++ b/Post/PViewDataList.h @@ -95,8 +95,7 @@ class PViewDataList : public PViewData { int getDimension(int step, int ent, int ele); int getNumNodes(int step, int ent, int ele); int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z); - void setNode(int step, int ent, int ele, int nod, double x, double y, double z, - int tag=0); + void setNode(int step, int ent, int ele, int nod, double x, double y, double z); int getNumComponents(int step, int ent, int ele); void getValue(int step, int ent, int ele, int nod, int comp, double &val); void setValue(int step, int ent, int ele, int nod, int comp, double val);