diff --git a/Plugin/DisplacementRaise.cpp b/Plugin/DisplacementRaise.cpp deleted file mode 100644 index 05f352ff3b14eb41bee6f28f8a55243b71f8e6ec..0000000000000000000000000000000000000000 --- a/Plugin/DisplacementRaise.cpp +++ /dev/null @@ -1,203 +0,0 @@ -// $Id: DisplacementRaise.cpp,v 1.21 2006-01-06 00:34:32 geuzaine Exp $ -// -// Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -// USA. -// -// Please report all bugs and problems to <gmsh@geuz.org>. - -#include "Plugin.h" -#include "DisplacementRaise.h" -#include "List.h" -#include "Views.h" -#include "Context.h" -#include "Numeric.h" - -extern Context_T CTX; - -StringXNumber DisplacementRaiseOptions_Number[] = { - {GMSH_FULLRC, "Factor", NULL, 1.}, - {GMSH_FULLRC, "dTimeStep", NULL, 0.}, - {GMSH_FULLRC, "dView", NULL, -1.}, - {GMSH_FULLRC, "iView", NULL, -1.} -}; - -extern "C" -{ - GMSH_Plugin *GMSH_RegisterDisplacementRaisePlugin() - { - return new GMSH_DisplacementRaisePlugin(); - } -} - - -GMSH_DisplacementRaisePlugin::GMSH_DisplacementRaisePlugin() -{ - ; -} - -void GMSH_DisplacementRaisePlugin::getName(char *name) const -{ - strcpy(name, "Displacement Raise"); -} - -void GMSH_DisplacementRaisePlugin::getInfos(char *author, char *copyright, - char *help_text) const -{ - strcpy(author, "C. Geuzaine (geuz@geuz.org)"); - strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Plugin(DisplacementRaise) transforms the\n" - "coordinates of the elements in the view `iView'\n" - "using the vectorial values (the displacements)\n" - "stored in the `dTimeStep'-th time step of the\n" - "view `dView'. If `iView' < 0, the plugin is run\n" - "on the current view. If `dView' < 0, the plugin\n" - "looks for the displacements in the view located\n" - "just after `iView' in the view list.\n" - "\n" - "Plugin(DisplacementRaise) is executed in-place.\n"); -} - -int GMSH_DisplacementRaisePlugin::getNbOptions() const -{ - return sizeof(DisplacementRaiseOptions_Number) / sizeof(StringXNumber); -} - -StringXNumber *GMSH_DisplacementRaisePlugin::getOption(int iopt) -{ - return &DisplacementRaiseOptions_Number[iopt]; -} - -void GMSH_DisplacementRaisePlugin::catchErrorMessage(char *errorMessage) const -{ - strcpy(errorMessage, "DisplacementRaise failed..."); -} - -static void displacementRaiseList(Post_View * iView, List_T * iList, int iNbElm, - Post_View * dView, List_T * dList, int dNbElm, - int nbNod, double factor, int dTimeStep) -{ - if(!iNbElm || !dNbElm) - return; - - if(iNbElm != dNbElm){ - Msg(GERROR, "View[%d] and View[%d] have a different number of elements (%d != %d)", - iView->Index, dView->Index, iNbElm, dNbElm); - return; - } - - // should we treat multiple time steps by generating new views - // (cf. time dependent CutMaps)? - if(dTimeStep < 0 || dTimeStep > dView->NbTimeStep - 1){ - Msg(GERROR, "Invalid TimeStep (%d) in View[%d]", dTimeStep, dView->Index); - return; - } - - iView->Changed = 1; - - // for each element - // for each node - // compute (x,y,z)_new = (x,y,z)_old + factor*(valx,valy,valz) - - int iNb = List_Nbr(iList) / iNbElm; - int dNb = List_Nbr(dList) / dNbElm; - for(int i = 0, j = 0; i < List_Nbr(iList); i += iNb, j += dNb) { - double *x = (double *)List_Pointer_Fast(iList, i); - double *y = (double *)List_Pointer_Fast(iList, i + nbNod); - double *z = (double *)List_Pointer_Fast(iList, i + 2 * nbNod); - double *val = (double *)List_Pointer_Fast(dList, j + 3 * nbNod); - for(int k = 0; k < nbNod; k++) { - x[k] += factor * val[3 * nbNod * dTimeStep + 3 * k]; - y[k] += factor * val[3 * nbNod * dTimeStep + 3 * k + 1]; - z[k] += factor * val[3 * nbNod * dTimeStep + 3 * k + 2]; - if(x[k] < iView->BBox[0]) iView->BBox[0] = x[k]; - if(x[k] > iView->BBox[1]) iView->BBox[1] = x[k]; - if(y[k] < iView->BBox[2]) iView->BBox[2] = y[k]; - if(y[k] > iView->BBox[3]) iView->BBox[3] = y[k]; - if(z[k] < iView->BBox[4]) iView->BBox[4] = z[k]; - if(z[k] > iView->BBox[5]) iView->BBox[5] = z[k]; - } - } - -} - -static void displacementRaise(Post_View * v, Post_View * w, double factor, int ts) -{ - for(int i = 0; i < 3; i++) { - v->BBox[2 * i] = VAL_INF; - v->BBox[2 * i + 1] = -VAL_INF; - } - - displacementRaiseList(v, v->SP, v->NbSP, w, w->VP, w->NbVP, 1, factor, ts); - displacementRaiseList(v, v->SL, v->NbSL, w, w->VL, w->NbVL, 2, factor, ts); - displacementRaiseList(v, v->ST, v->NbST, w, w->VT, w->NbVT, 3, factor, ts); - displacementRaiseList(v, v->SQ, v->NbSQ, w, w->VQ, w->NbVQ, 4, factor, ts); - displacementRaiseList(v, v->SS, v->NbSS, w, w->VS, w->NbVS, 4, factor, ts); - displacementRaiseList(v, v->SH, v->NbSH, w, w->VH, w->NbVH, 8, factor, ts); - displacementRaiseList(v, v->SI, v->NbSI, w, w->VI, w->NbVI, 6, factor, ts); - displacementRaiseList(v, v->SY, v->NbSY, w, w->VY, w->NbVY, 5, factor, ts); - - displacementRaiseList(v, v->VP, v->NbVP, w, w->VP, w->NbVP, 1, factor, ts); - displacementRaiseList(v, v->VL, v->NbVL, w, w->VL, w->NbVL, 2, factor, ts); - displacementRaiseList(v, v->VT, v->NbVT, w, w->VT, w->NbVT, 3, factor, ts); - displacementRaiseList(v, v->VQ, v->NbVQ, w, w->VQ, w->NbVQ, 4, factor, ts); - displacementRaiseList(v, v->VS, v->NbVS, w, w->VS, w->NbVS, 4, factor, ts); - displacementRaiseList(v, v->VH, v->NbVH, w, w->VH, w->NbVH, 8, factor, ts); - displacementRaiseList(v, v->VI, v->NbVI, w, w->VI, w->NbVI, 6, factor, ts); - displacementRaiseList(v, v->VY, v->NbVY, w, w->VY, w->NbVY, 5, factor, ts); - - displacementRaiseList(v, v->TP, v->NbTP, w, w->VP, w->NbVP, 1, factor, ts); - displacementRaiseList(v, v->TL, v->NbTL, w, w->VL, w->NbVL, 2, factor, ts); - displacementRaiseList(v, v->TT, v->NbTT, w, w->VT, w->NbVT, 3, factor, ts); - displacementRaiseList(v, v->TQ, v->NbTQ, w, w->VQ, w->NbVQ, 4, factor, ts); - displacementRaiseList(v, v->TS, v->NbTS, w, w->VS, w->NbVS, 4, factor, ts); - displacementRaiseList(v, v->TH, v->NbTH, w, w->VH, w->NbVH, 8, factor, ts); - displacementRaiseList(v, v->TI, v->NbTI, w, w->VI, w->NbVI, 6, factor, ts); - displacementRaiseList(v, v->TY, v->NbTY, w, w->VY, w->NbVY, 5, factor, ts); -} - -Post_View *GMSH_DisplacementRaisePlugin::execute(Post_View * v) -{ - double factor = DisplacementRaiseOptions_Number[0].def; - int dTimeStep = (int)DisplacementRaiseOptions_Number[1].def; - int dView = (int)DisplacementRaiseOptions_Number[2].def; - int iView = (int)DisplacementRaiseOptions_Number[3].def; - - if(iView < 0) - iView = v ? v->Index : 0; - - if(!List_Pointer_Test(CTX.post.list, iView)) { - Msg(GERROR, "View[%d] does not exist", iView); - return v; - } - - if(dView < 0) - dView = iView + 1; // by default, try to use the next view - - if(!List_Pointer_Test(CTX.post.list, dView)) { - Msg(GERROR, "View[%d] does not exist", dView); - return v; - } - - Post_View *v1 = *(Post_View **)List_Pointer(CTX.post.list, iView); - Post_View *v2 = *(Post_View **)List_Pointer(CTX.post.list, dView); - - displacementRaise(v1, v2, factor, dTimeStep); - - return v1; -} - diff --git a/Plugin/Makefile b/Plugin/Makefile index 4fe3959d087b4a89831f27f01947e5bb8c973d5d..b88b283bdaf19baf3fda4fcd77149ee22db4ee14 100644 --- a/Plugin/Makefile +++ b/Plugin/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.96 2006-04-01 23:02:23 geuzaine Exp $ +# $Id: Makefile,v 1.97 2006-04-15 17:21:18 geuzaine Exp $ # # Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle # @@ -36,8 +36,7 @@ SRC = Plugin.cpp\ StreamLines.cpp CutGrid.cpp\ Transform.cpp\ Triangulate.cpp\ - SphericalRaise.cpp\ - DisplacementRaise.cpp\ + Warp.cpp\ StructuralSolver.cpp\ Skin.cpp\ Extract.cpp ExtractElements.cpp ExtractEdges.cpp\ @@ -80,14 +79,14 @@ Plugin.o: Plugin.cpp Plugin.h ../Common/Options.h ../Common/Message.h \ CutParametric.h CutSphere.h Skin.h ../DataStr/Tree.h ../DataStr/avl.h \ Extract.h ExtractElements.h ExtractEdges.h HarmonicToTime.h \ ModulusPhase.h Integrate.h Gradient.h Curl.h Divergence.h Annotate.h \ - Remove.h DecomposeInSimplex.h Smooth.h Transform.h Triangulate.h \ - SphericalRaise.h DisplacementRaise.h StructuralSolver.h ../Geo/Geo.h \ - ../Mesh/Mesh.h ../Mesh/Vertex.h ../Mesh/Element.h ../Mesh/Vertex.h \ - ../Mesh/Simplex.h ../Mesh/Vertex.h ../Mesh/Element.h ../Mesh/Face.h \ - ../Mesh/Vertex.h ../Mesh/Element.h ../Mesh/Edge.h ../Mesh/Vertex.h \ - ../Mesh/Simplex.h ../Geo/ExtrudeParams.h ../Mesh/Metric.h \ - ../Mesh/Vertex.h ../Mesh/Simplex.h ../Mesh/Mesh.h ../Mesh/Matrix.h \ - ../Common/GmshUI.h Eigenvectors.h Eigenvalues.h Lambda2.h Evaluate.h \ + Remove.h DecomposeInSimplex.h Smooth.h Transform.h Triangulate.h Warp.h \ + StructuralSolver.h ../Geo/Geo.h ../Mesh/Mesh.h ../Mesh/Vertex.h \ + ../Mesh/Element.h ../Mesh/Vertex.h ../Mesh/Simplex.h ../Mesh/Vertex.h \ + ../Mesh/Element.h ../Mesh/Face.h ../Mesh/Vertex.h ../Mesh/Element.h \ + ../Mesh/Edge.h ../Mesh/Vertex.h ../Mesh/Simplex.h \ + ../Geo/ExtrudeParams.h ../Mesh/Metric.h ../Mesh/Vertex.h \ + ../Mesh/Simplex.h ../Mesh/Mesh.h ../Mesh/Matrix.h ../Common/GmshUI.h \ + Eigenvectors.h Eigenvalues.h Lambda2.h Evaluate.h \ ../Common/OctreePost.h ../Common/Octree.h ../Common/OctreeInternals.h \ Probe.h ../Common/Context.h # 1 "/Users/geuzaine/.gmsh/Plugin//" @@ -215,17 +214,11 @@ Triangulate.o: Triangulate.cpp ../Common/Gmsh.h ../Common/Message.h \ ../Mesh/Vertex.h ../Mesh/Mesh.h ../Mesh/Create.h ../Mesh/Vertex.h \ ../Mesh/Mesh.h # 1 "/Users/geuzaine/.gmsh/Plugin//" -SphericalRaise.o: SphericalRaise.cpp Plugin.h ../Common/Options.h \ - ../Common/Message.h ../Common/Views.h ../Common/ColorTable.h \ - ../DataStr/List.h ../Common/VertexArray.h ../Common/SmoothNormals.h \ - ../Numeric/Numeric.h ../Common/GmshMatrix.h ../Common/AdaptiveViews.h \ - ../Common/GmshMatrix.h SphericalRaise.h ../Common/Context.h -# 1 "/Users/geuzaine/.gmsh/Plugin//" -DisplacementRaise.o: DisplacementRaise.cpp Plugin.h ../Common/Options.h \ - ../Common/Message.h ../Common/Views.h ../Common/ColorTable.h \ - ../DataStr/List.h ../Common/VertexArray.h ../Common/SmoothNormals.h \ - ../Numeric/Numeric.h ../Common/GmshMatrix.h ../Common/AdaptiveViews.h \ - ../Common/GmshMatrix.h DisplacementRaise.h ../Common/Context.h +Warp.o: Warp.cpp Plugin.h ../Common/Options.h ../Common/Message.h \ + ../Common/Views.h ../Common/ColorTable.h ../DataStr/List.h \ + ../Common/VertexArray.h ../Common/SmoothNormals.h ../Numeric/Numeric.h \ + ../Common/GmshMatrix.h ../Common/AdaptiveViews.h ../Common/GmshMatrix.h \ + Warp.h ../Common/Context.h # 1 "/Users/geuzaine/.gmsh/Plugin//" StructuralSolver.o: StructuralSolver.cpp StructuralSolver.h ../Geo/Geo.h \ ../DataStr/List.h ../Mesh/Mesh.h ../DataStr/Tree.h ../DataStr/avl.h \ diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index c89beddfe55ec43b2191e4974aa7b1657d34aa35..ff88605e4b3b88328802c0f2398062e83b5cc40c 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -1,4 +1,4 @@ -// $Id: Plugin.cpp,v 1.81 2006-03-15 18:00:45 geuzaine Exp $ +// $Id: Plugin.cpp,v 1.82 2006-04-15 17:21:18 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -54,8 +54,7 @@ #include "Smooth.h" #include "Transform.h" #include "Triangulate.h" -#include "SphericalRaise.h" -#include "DisplacementRaise.h" +#include "Warp.h" #include "StructuralSolver.h" #include "Eigenvectors.h" #include "Eigenvalues.h" @@ -201,9 +200,7 @@ void GMSH_PluginManager::registerDefaultPlugins() allPlugins.insert(std::pair < char *, GMSH_Plugin * > ("Transform", GMSH_RegisterTransformPlugin())); allPlugins.insert(std::pair < char *, GMSH_Plugin * > - ("SphericalRaise", GMSH_RegisterSphericalRaisePlugin())); - allPlugins.insert(std::pair < char *, GMSH_Plugin * > - ("DisplacementRaise", GMSH_RegisterDisplacementRaisePlugin())); + ("Warp", GMSH_RegisterWarpPlugin())); allPlugins.insert(std::pair < char *, GMSH_Plugin * > ("HarmonicToTime", GMSH_RegisterHarmonicToTimePlugin())); allPlugins.insert(std::pair < char *, GMSH_Plugin * > diff --git a/Plugin/SphericalRaise.cpp b/Plugin/SphericalRaise.cpp deleted file mode 100644 index c6a07286fe3f98762e52182121a8c8945a036e85..0000000000000000000000000000000000000000 --- a/Plugin/SphericalRaise.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// $Id: SphericalRaise.cpp,v 1.23 2006-01-06 00:34:33 geuzaine Exp $ -// -// Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -// USA. -// -// Please report all bugs and problems to <gmsh@geuz.org>. - -#include "Plugin.h" -#include "SphericalRaise.h" -#include "List.h" -#include "Views.h" -#include "Context.h" -#include "Numeric.h" - -extern Context_T CTX; - -StringXNumber SphericalRaiseOptions_Number[] = { - {GMSH_FULLRC, "Xc", NULL, 0.}, - {GMSH_FULLRC, "Yc", NULL, 0.}, - {GMSH_FULLRC, "Zc", NULL, 0.}, - {GMSH_FULLRC, "Raise", NULL, 1.}, - {GMSH_FULLRC, "TimeStep", NULL, 0.}, - {GMSH_FULLRC, "iView", NULL, -1.} -}; - -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin() - { - return new GMSH_SphericalRaisePlugin(); - } -} - - -GMSH_SphericalRaisePlugin::GMSH_SphericalRaisePlugin() -{ - ; -} - -void GMSH_SphericalRaisePlugin::getName(char *name) const -{ - strcpy(name, "Spherical Raise"); -} - -void GMSH_SphericalRaisePlugin::getInfos(char *author, char *copyright, - char *help_text) const -{ - strcpy(author, "C. Geuzaine (geuz@geuz.org)"); - strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Plugin(SphericalRaise) transforms the\n" - "coordinates of the elements in the view `iView'\n" - "using the values associated with the\n" - "`TimeStep'-th time step. Instead of elevating\n" - "the nodes along the X, Y and Z axes as in\n" - "View[`iView'].RaiseX, View[`iView'].RaiseY\n" - "and View[`iView'].RaiseZ, the raise is applied\n" - " along the radius of a sphere centered at (`Xc',\n" - "`Yc', `Zc'). If `iView' < 0, the plugin is run\n" - "on the current view.\n" - "\n" - "Plugin(SphericalRaise) is executed in-place.\n"); -} - -int GMSH_SphericalRaisePlugin::getNbOptions() const -{ - return sizeof(SphericalRaiseOptions_Number) / sizeof(StringXNumber); -} - -StringXNumber *GMSH_SphericalRaisePlugin::getOption(int iopt) -{ - return &SphericalRaiseOptions_Number[iopt]; -} - -void GMSH_SphericalRaisePlugin::catchErrorMessage(char *errorMessage) const -{ - strcpy(errorMessage, "SphericalRaise failed..."); -} - -static void sphericalRaiseList(Post_View * v, List_T * list, int nbElm, - int nbNod, int timeStep, double center[3], - double raise) -{ - double *x, *y, *z, *val, d[3], coef; - int nb, i, j; - - if(!nbElm) - return; - - if(timeStep > v->NbTimeStep - 1){ - Msg(GERROR, "Invalid TimeStep (%d) in View[%d]", timeStep, v->Index); - return; - } - - v->Changed = 1; - - // for each element - // for each node - // compute d=(x-Xc,y-Yc,z-Zc) - // norm d - // get nodal value val at xyz - // compute (x,y,z)_new = (x,y,z)_old + raise*val*(dx,dy,dz) - - nb = List_Nbr(list) / nbElm; - for(i = 0; i < List_Nbr(list); i += nb) { - x = (double *)List_Pointer_Fast(list, i); - y = (double *)List_Pointer_Fast(list, i + nbNod); - z = (double *)List_Pointer_Fast(list, i + 2 * nbNod); - val = (double *)List_Pointer_Fast(list, i + 3 * nbNod); - for(j = 0; j < nbNod; j++) { - d[0] = x[j] - center[0]; - d[1] = y[j] - center[1]; - d[2] = z[j] - center[2]; - norme(d); - if(timeStep < 0) - coef = raise; - else - coef = raise * val[nbNod * timeStep + j]; - x[j] += coef * d[0]; - y[j] += coef * d[1]; - z[j] += coef * d[2]; - if(x[j] < v->BBox[0]) v->BBox[0] = x[j]; - if(x[j] > v->BBox[1]) v->BBox[1] = x[j]; - if(y[j] < v->BBox[2]) v->BBox[2] = y[j]; - if(y[j] > v->BBox[3]) v->BBox[3] = y[j]; - if(z[j] < v->BBox[4]) v->BBox[4] = z[j]; - if(z[j] > v->BBox[5]) v->BBox[5] = z[j]; - } - } -} - -static void sphericalRaise(Post_View * v, int timeStep, double center[3], - double raise) -{ - for(int i = 0; i < 3; i++) { - v->BBox[2 * i] = VAL_INF; - v->BBox[2 * i + 1] = -VAL_INF; - } - sphericalRaiseList(v, v->SP, v->NbSP, 1, timeStep, center, raise); - sphericalRaiseList(v, v->SL, v->NbSL, 2, timeStep, center, raise); - sphericalRaiseList(v, v->ST, v->NbST, 3, timeStep, center, raise); - sphericalRaiseList(v, v->SQ, v->NbSQ, 4, timeStep, center, raise); - sphericalRaiseList(v, v->SS, v->NbSS, 4, timeStep, center, raise); - sphericalRaiseList(v, v->SH, v->NbSH, 8, timeStep, center, raise); - sphericalRaiseList(v, v->SI, v->NbSI, 6, timeStep, center, raise); - sphericalRaiseList(v, v->SY, v->NbSY, 5, timeStep, center, raise); -} - -Post_View *GMSH_SphericalRaisePlugin::execute(Post_View * v) -{ - double center[3], raise; - - center[0] = SphericalRaiseOptions_Number[0].def; - center[1] = SphericalRaiseOptions_Number[1].def; - center[2] = SphericalRaiseOptions_Number[2].def; - raise = SphericalRaiseOptions_Number[3].def; - int timeStep = (int)SphericalRaiseOptions_Number[4].def; - int iView = (int)SphericalRaiseOptions_Number[5].def; - - if(iView < 0) - iView = v ? v->Index : 0; - - if(!List_Pointer_Test(CTX.post.list, iView)) { - Msg(GERROR, "View[%d] does not exist", iView); - return v; - } - - Post_View *v1 = *(Post_View **)List_Pointer(CTX.post.list, iView); - - sphericalRaise(v1, timeStep, center, raise); - return v1; -} - diff --git a/Plugin/SphericalRaise.h b/Plugin/SphericalRaise.h deleted file mode 100644 index 6dc8f57c7b8d10004088aace0b8e23a9bf32f131..0000000000000000000000000000000000000000 --- a/Plugin/SphericalRaise.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _SPHERICAL_RAISE_H_ -#define _SPHERICAL_RAISE_H_ - -// Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -// USA. -// -// Please report all bugs and problems to <gmsh@geuz.org>. - -#include "Plugin.h" - -extern "C" -{ - GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin(); -} - -class GMSH_SphericalRaisePlugin : public GMSH_Post_Plugin -{ -public: - GMSH_SphericalRaisePlugin(); - void getName(char *name) const; - void getInfos(char *author, char *copyright, char *helpText) const; - void catchErrorMessage(char *errorMessage) const; - int getNbOptions() const; - StringXNumber* getOption(int iopt); - Post_View *execute(Post_View *); -}; - -#endif diff --git a/Plugin/Warp.cpp b/Plugin/Warp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..468e2fb4c42209b9a689fad1fafa337802640e06 --- /dev/null +++ b/Plugin/Warp.cpp @@ -0,0 +1,264 @@ +// $Id: Warp.cpp,v 1.1 2006-04-15 17:21:18 geuzaine Exp $ +// +// Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems to <gmsh@geuz.org>. + +#include "Plugin.h" +#include "Warp.h" +#include "List.h" +#include "Views.h" +#include "Context.h" +#include "Numeric.h" +#include "SmoothNormals.h" + +extern Context_T CTX; + +StringXNumber WarpOptions_Number[] = { + {GMSH_FULLRC, "Factor", NULL, 1.}, + {GMSH_FULLRC, "TimeStep", NULL, 0.}, + {GMSH_FULLRC, "SmoothingAngle", NULL, 180.}, + {GMSH_FULLRC, "dView", NULL, -1.}, + {GMSH_FULLRC, "iView", NULL, -1.} +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterWarpPlugin() + { + return new GMSH_WarpPlugin(); + } +} + + +GMSH_WarpPlugin::GMSH_WarpPlugin() +{ + ; +} + +void GMSH_WarpPlugin::getName(char *name) const +{ + strcpy(name, "Warp"); +} + +void GMSH_WarpPlugin::getInfos(char *author, char *copyright, + char *help_text) const +{ + strcpy(author, "C. Geuzaine (geuz@geuz.org)"); + strcpy(copyright, "DGR (www.multiphysics.com)"); + strcpy(help_text, + "Plugin(Warp) transforms the elements in the view\n" + "`iView' by adding to their node coordinates the\n" + "the vector field stored in the `TimeStep'-th time\n" + "step of the view `dView', scaled by `Factor'. If\n" + "`dView' < 0, the vector field is taken as the field\n" + "of surface normals multiplied by the `TimeStep'\n" + "value in `iView'. (The smoothing of the surface\n" + "normals is controlled by the `SmoothingAngle'\n" + "parameter.). If `iView' < 0, the plugin is run on the\n" + "current view.\n" + "\n" + "Plugin(Warp) is executed in-place.\n"); +} + +int GMSH_WarpPlugin::getNbOptions() const +{ + return sizeof(WarpOptions_Number) / sizeof(StringXNumber); +} + +StringXNumber *GMSH_WarpPlugin::getOption(int iopt) +{ + return &WarpOptions_Number[iopt]; +} + +void GMSH_WarpPlugin::catchErrorMessage(char *errorMessage) const +{ + strcpy(errorMessage, "Warp failed..."); +} + +static void addNormals(List_T *listElm, int nbElm, int nbNod, + smooth_normals *normals) +{ + if(!nbElm || nbNod < 3) return; + int nb = List_Nbr(listElm) / nbElm; + for(int i = 0; i < List_Nbr(listElm); i += nb) { + double *x = (double *)List_Pointer_Fast(listElm, i); + double *y = (double *)List_Pointer_Fast(listElm, i + nbNod); + double *z = (double *)List_Pointer_Fast(listElm, i + 2 * nbNod); + double nn[3]; + normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], nn); + for(int k = 0; k < nbNod; k++) + normals->add(x[k], y[k], z[k], nn[0], nn[1], nn[2]); + } +} + +static void warpList(Post_View * iView, List_T * iList, int iNbElm, + Post_View * dView, List_T * dList, int dNbElm, + int nbNod, double factor, int TimeStep, + int nbComp, smooth_normals *normals) +{ + if(!iNbElm) + return; + + if(!normals && (iNbElm != dNbElm)){ + Msg(GERROR, "View[%d] and View[%d] have a different number of elements (%d != %d)", + iView->Index, dView->Index, iNbElm, dNbElm); + return; + } + + iView->Changed = 1; + + // for each element + // for each node + // (x,y,z) += factor * (valx,valy,valz) + + int iNb = List_Nbr(iList) / iNbElm; + int dNb = List_Nbr(dList) / dNbElm; + for(int i = 0, j = 0; i < List_Nbr(iList); i += iNb, j += dNb) { + double *x = (double *)List_Pointer_Fast(iList, i); + double *y = (double *)List_Pointer_Fast(iList, i + nbNod); + double *z = (double *)List_Pointer_Fast(iList, i + 2 * nbNod); + double *val; + if(normals) + val = (double *)List_Pointer_Fast(iList, i + 3 * nbNod); + else + val = (double *)List_Pointer_Fast(dList, j + 3 * nbNod); + + double nn[3] = {0., 0., 1.}; + if(normals && nbNod > 2) + normal3points(x[0], y[0], z[0], x[1], y[1], z[1], x[2], y[2], z[2], nn); + + for(int k = 0; k < nbNod; k++) { + if(normals){ + double d = 1.; + if(TimeStep >= 0){ + double *v = &val[nbComp * nbNod * TimeStep + nbComp * k]; + if(nbComp == 1) + d = v[0]; + else if(nbComp == 3) + d = sqrt(DSQR(v[0]) + DSQR(v[1]) + DSQR(v[2])); + else if(nbComp == 9) + d = ComputeVonMises(v); + } + normals->get(x[k], y[k], z[k], nn[0], nn[1], nn[2]); + x[k] += factor * d * nn[0]; + y[k] += factor * d * nn[1]; + z[k] += factor * d * nn[2]; + } + else{ + if(TimeStep < 0) TimeStep = 0; + x[k] += factor * val[3 * nbNod * TimeStep + 3 * k]; + y[k] += factor * val[3 * nbNod * TimeStep + 3 * k + 1]; + z[k] += factor * val[3 * nbNod * TimeStep + 3 * k + 2]; + } + if(x[k] < iView->BBox[0]) iView->BBox[0] = x[k]; + if(x[k] > iView->BBox[1]) iView->BBox[1] = x[k]; + if(y[k] < iView->BBox[2]) iView->BBox[2] = y[k]; + if(y[k] > iView->BBox[3]) iView->BBox[3] = y[k]; + if(z[k] < iView->BBox[4]) iView->BBox[4] = z[k]; + if(z[k] > iView->BBox[5]) iView->BBox[5] = z[k]; + } + } + +} + +static void warp(Post_View * v, Post_View * w, double factor, int ts, double tol) +{ + for(int i = 0; i < 3; i++) { + v->BBox[2 * i] = VAL_INF; + v->BBox[2 * i + 1] = -VAL_INF; + } + + smooth_normals *nn = 0; + if(WarpOptions_Number[3].def < 0){ + nn = new smooth_normals(tol); + addNormals(v->ST, v->NbST, 3, nn); + addNormals(v->VT, v->NbVT, 3, nn); + addNormals(v->TT, v->NbTT, 3, nn); + addNormals(v->SQ, v->NbSQ, 4, nn); + addNormals(v->VQ, v->NbVQ, 4, nn); + addNormals(v->TQ, v->NbTQ, 4, nn); + } + + warpList(v, v->SP, v->NbSP, w, w->VP, w->NbVP, 1, factor, ts, 1, nn); + warpList(v, v->SL, v->NbSL, w, w->VL, w->NbVL, 2, factor, ts, 1, nn); + warpList(v, v->ST, v->NbST, w, w->VT, w->NbVT, 3, factor, ts, 1, nn); + warpList(v, v->SQ, v->NbSQ, w, w->VQ, w->NbVQ, 4, factor, ts, 1, nn); + warpList(v, v->SS, v->NbSS, w, w->VS, w->NbVS, 4, factor, ts, 1, nn); + warpList(v, v->SH, v->NbSH, w, w->VH, w->NbVH, 8, factor, ts, 1, nn); + warpList(v, v->SI, v->NbSI, w, w->VI, w->NbVI, 6, factor, ts, 1, nn); + warpList(v, v->SY, v->NbSY, w, w->VY, w->NbVY, 5, factor, ts, 1, nn); + + warpList(v, v->VP, v->NbVP, w, w->VP, w->NbVP, 1, factor, ts, 3, nn); + warpList(v, v->VL, v->NbVL, w, w->VL, w->NbVL, 2, factor, ts, 3, nn); + warpList(v, v->VT, v->NbVT, w, w->VT, w->NbVT, 3, factor, ts, 3, nn); + warpList(v, v->VQ, v->NbVQ, w, w->VQ, w->NbVQ, 4, factor, ts, 3, nn); + warpList(v, v->VS, v->NbVS, w, w->VS, w->NbVS, 4, factor, ts, 3, nn); + warpList(v, v->VH, v->NbVH, w, w->VH, w->NbVH, 8, factor, ts, 3, nn); + warpList(v, v->VI, v->NbVI, w, w->VI, w->NbVI, 6, factor, ts, 3, nn); + warpList(v, v->VY, v->NbVY, w, w->VY, w->NbVY, 5, factor, ts, 3, nn); + + warpList(v, v->TP, v->NbTP, w, w->VP, w->NbVP, 1, factor, ts, 9, nn); + warpList(v, v->TL, v->NbTL, w, w->VL, w->NbVL, 2, factor, ts, 9, nn); + warpList(v, v->TT, v->NbTT, w, w->VT, w->NbVT, 3, factor, ts, 9, nn); + warpList(v, v->TQ, v->NbTQ, w, w->VQ, w->NbVQ, 4, factor, ts, 9, nn); + warpList(v, v->TS, v->NbTS, w, w->VS, w->NbVS, 4, factor, ts, 9, nn); + warpList(v, v->TH, v->NbTH, w, w->VH, w->NbVH, 8, factor, ts, 9, nn); + warpList(v, v->TI, v->NbTI, w, w->VI, w->NbVI, 6, factor, ts, 9, nn); + warpList(v, v->TY, v->NbTY, w, w->VY, w->NbVY, 5, factor, ts, 9, nn); + + if(nn) delete nn; +} + +Post_View *GMSH_WarpPlugin::execute(Post_View * v) +{ + double factor = WarpOptions_Number[0].def; + int TimeStep = (int)WarpOptions_Number[1].def; + double AngleTol = WarpOptions_Number[2].def; + int dView = (int)WarpOptions_Number[3].def; + int iView = (int)WarpOptions_Number[4].def; + + if(iView < 0) + iView = v ? v->Index : 0; + + if(!List_Pointer_Test(CTX.post.list, iView)) { + Msg(GERROR, "View[%d] does not exist", iView); + return v; + } + + if(dView < 0) + dView = iView; + + if(!List_Pointer_Test(CTX.post.list, dView)) { + Msg(GERROR, "View[%d] does not exist", dView); + return v; + } + + Post_View *v1 = *(Post_View **)List_Pointer(CTX.post.list, iView); + Post_View *v2 = *(Post_View **)List_Pointer(CTX.post.list, dView); + + if(TimeStep > v2->NbTimeStep - 1){ + // we allow TimeStep < 0 (to apply fixed warps) + Msg(GERROR, "Invalid TimeStep (%d) in View[%d]", TimeStep, v2->Index); + return v; + } + + warp(v1, v2, factor, TimeStep, AngleTol); + + return v1; +} diff --git a/Plugin/DisplacementRaise.h b/Plugin/Warp.h similarity index 84% rename from Plugin/DisplacementRaise.h rename to Plugin/Warp.h index b3829cc9c5e663e4453868cd77f3bff0c16ee9e6..7f61c7dd34266731aaaaeb1e15c5c570475c3040 100644 --- a/Plugin/DisplacementRaise.h +++ b/Plugin/Warp.h @@ -1,5 +1,5 @@ -#ifndef _DISPLACEMENT_RAISE_H_ -#define _DISPLACEMENT_RAISE_H_ +#ifndef _WARP_H_ +#define _WARP_H_ // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -24,13 +24,13 @@ extern "C" { - GMSH_Plugin *GMSH_RegisterDisplacementRaisePlugin(); + GMSH_Plugin *GMSH_RegisterWarpPlugin(); } -class GMSH_DisplacementRaisePlugin : public GMSH_Post_Plugin +class GMSH_WarpPlugin : public GMSH_Post_Plugin { public: - GMSH_DisplacementRaisePlugin(); + GMSH_WarpPlugin(); void getName(char *name) const; void getInfos(char *author, char *copyright, char *help_text) const; void catchErrorMessage(char *errorMessage) const; diff --git a/doc/FAQ b/doc/FAQ index 7f62edd85463de6fe9a479f8088ab3e1dcb4c597..4f4563a3f96db1e9a45721e2dcb85665ad6f0c54 100644 --- a/doc/FAQ +++ b/doc/FAQ @@ -1,4 +1,4 @@ -$Id: FAQ,v 1.73 2006-03-11 02:19:32 geuzaine Exp $ +$Id: FAQ,v 1.74 2006-04-15 17:21:18 geuzaine Exp $ This is the Gmsh FAQ @@ -394,7 +394,7 @@ Another solution is to use the 'General transformation expressions' (in 'View->Options->Offset') on the field you want to display, with the displacement map selected as the data source. -And yet another solution is to use the DiplacementRaise plugin. +And yet another solution is to use the Warp plugin. * 7.7 Can I color the arrows representing a vector field with data from a scalar field? diff --git a/doc/TODO b/doc/TODO index 891e85505b73c5491339c45ea08c9df222657d5b..f7db692cbf5af547d36f3f53ce9dab85f5389db7 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,4 +1,4 @@ -$Id: TODO,v 1.5 2006-03-29 01:45:13 geuzaine Exp $ +$Id: TODO,v 1.6 2006-04-15 17:21:18 geuzaine Exp $ ******************************************************************** @@ -77,11 +77,6 @@ normals...) ******************************************************************** -Create a plugin that computes the normals of a surface view; could be -used to remove SphericalRaise... - -******************************************************************** - Would be nice to have Plugin(CutBox) and Plugin(CutCylinder) (Box: using Xc, Yc, Zc, Xl, Yl, Zl, Xr, Yr, Zr, or 4 points. 4 points is more general: can be wedge. Cylinder should be able to degenerate diff --git a/doc/VERSIONS b/doc/VERSIONS index 6111cb1f9be5f267d57ea6968f966012519e167b..f9ac31d9a614c0cfcf635c92aea494b76b52efd2 100644 --- a/doc/VERSIONS +++ b/doc/VERSIONS @@ -1,6 +1,6 @@ -$Id: VERSIONS,v 1.361 2006-02-28 18:50:08 geuzaine Exp $ +$Id: VERSIONS,v 1.362 2006-04-15 17:21:18 geuzaine Exp $ -New in 1.64: Windows versions do no depend on Cygwin anymore. Various +New in 1.64: Windows versions do no depend on Cygwin anymore; various bug fixes and cleanups. New in 1.63: post-processing views can now be exported as meshes; diff --git a/doc/texinfo/opt_mesh.texi b/doc/texinfo/opt_mesh.texi index 5d701926c9f7e54bfc35322b804029fc9a9981ed..2c75d73fb8683bd64176d87e9e0a6c8c5e2da64b 100644 --- a/doc/texinfo/opt_mesh.texi +++ b/doc/texinfo/opt_mesh.texi @@ -119,6 +119,11 @@ Mesh output format (1=msh, 2=unv, 3=gref, 19=vrml)@* Default value: @code{1}@* Saved in: @code{General.OptionsFileName} +@item Mesh.InitialOnly +Only contruct the n-dimensional initial mesh (no refinement)@* +Default value: @code{0}@* +Saved in: @code{General.OptionsFileName} + @item Mesh.Interactive Show the construction of 2D anisotropic mesh in real time@* Default value: @code{0}@* diff --git a/doc/texinfo/opt_plugin.texi b/doc/texinfo/opt_plugin.texi index 0a4f31f954081bbf92f8a55309f31644e2114cf2..2df8a2bdd41d9527250511cb4f495d7637faf35e 100644 --- a/doc/texinfo/opt_plugin.texi +++ b/doc/texinfo/opt_plugin.texi @@ -242,30 +242,6 @@ Numeric options: Default value: @code{-1} @end table -@item Plugin(DisplacementRaise) -Plugin(DisplacementRaise) transforms the -coordinates of the elements in the view `iView' -using the vectorial values (the displacements) -stored in the `dTimeStep'-th time step of the -view `dView'. If `iView' < 0, the plugin is run -on the current view. If `dView' < 0, the plugin -looks for the displacements in the view located -just after `iView' in the view list. - -Plugin(DisplacementRaise) is executed in-place. - -Numeric options: -@table @code -@item Factor -Default value: @code{1} -@item dTimeStep -Default value: @code{0} -@item dView -Default value: @code{-1} -@item iView -Default value: @code{-1} -@end table - @item Plugin(Divergence) Plugin(Divergence) computes the divergence of the field in the view `iView'. If `iView' < 0, the plugin @@ -405,7 +381,7 @@ Plugin(Extract) creates one new view. String options: @table @code @item Expression0 -Default value: @code{"v0"} +Default value: @code{"Sqrt(v0^2+v1^2+v2^2)"} @item Expression1 Default value: @code{""} @item Expression2 @@ -432,10 +408,10 @@ Default value: @code{-1} @end table @item Plugin(ExtractEdges) -Plugin(ExtractEdges) extracts the geometry edges of -the view `iView', using `Angle' as the dihedral angle -tolerance. If `iView' < 0, the plugin is run on the -current view. +Plugin(ExtractEdges) extracts the geometry edges +from the surface view `iView', using `Angle' as +the dihedral angle tolerance. If `iView' < 0, then +plugin is run on the current view. Plugin(ExtractEdges) creates one new view. @@ -654,36 +630,6 @@ Numeric options: Default value: @code{-1} @end table -@item Plugin(SphericalRaise) -Plugin(SphericalRaise) transforms the -coordinates of the elements in the view `iView' -using the values associated with the -`TimeStep'-th time step. Instead of elevating -the nodes along the X, Y and Z axes as in -View[`iView'].RaiseX, View[`iView'].RaiseY -and View[`iView'].RaiseZ, the raise is applied - along the radius of a sphere centered at (`Xc', -`Yc', `Zc'). If `iView' < 0, the plugin is run -on the current view. - -Plugin(SphericalRaise) is executed in-place. - -Numeric options: -@table @code -@item Xc -Default value: @code{0} -@item Yc -Default value: @code{0} -@item Zc -Default value: @code{0} -@item Raise -Default value: @code{1} -@item TimeStep -Default value: @code{0} -@item iView -Default value: @code{-1} -@end table - @item Plugin(StreamLines) Plugin(StreamLines) computes stream lines from a vector view `iView' and optionally @@ -800,4 +746,32 @@ Numeric options: Default value: @code{-1} @end table +@item Plugin(Warp) +Plugin(Warp) transforms the elements in the view +`iView' by adding to their node coordinates the +the vector field stored in the `TimeStep'-th time +step of the view `dView', scaled by `Factor'. If +`dView' < 0, the vector field is taken as the field +of surface normals multiplied by the `TimeStep' +value in `iView'. (The smoothing of the surface +normals is controlled by the `SmoothingAngle' +parameter.). If `iView' < 0, the plugin is run on the +current view. + +Plugin(Warp) is executed in-place. + +Numeric options: +@table @code +@item Factor +Default value: @code{1} +@item TimeStep +Default value: @code{0} +@item SmoothingAngle +Default value: @code{180} +@item dView +Default value: @code{-1} +@item iView +Default value: @code{-1} +@end table + @end ftable