diff --git a/Plugin/CMakeLists.txt b/Plugin/CMakeLists.txt index e68d68267ee353e4aadf133c712b16cd70224ac2..48fc3a408caac0a29362f3b0996619d61c42306c 100644 --- a/Plugin/CMakeLists.txt +++ b/Plugin/CMakeLists.txt @@ -6,13 +6,13 @@ set(SRC Plugin.cpp PluginManager.cpp Levelset.cpp - CutPlane.cpp CutSphere.cpp Isosurface.cpp + CutPlane.cpp CutSphere.cpp Isosurface.cpp Smooth.cpp CutParametric.cpp Lambda2.cpp Eigenvectors.cpp Eigenvalues.cpp StreamLines.cpp Particles.cpp CutGrid.cpp CutBox.cpp Transform.cpp - LongitudeLatitude.cpp + LongitudeLatitude.cpp Triangulate.cpp Tetrahedralize.cpp Warp.cpp SphericalRaise.cpp Skin.cpp @@ -29,7 +29,7 @@ set(SRC FieldFromAmplitudePhase.cpp Bubbles.cpp NearToFarField.cpp DiscretizationError.cpp - Scal2Vec.cpp + Scal2Tens.cpp Scal2Vec.cpp CutMesh.cpp NewView.cpp SimplePartition.cpp Crack.cpp diff --git a/Plugin/PluginManager.cpp b/Plugin/PluginManager.cpp index 2aa18ba377ec71840394e39dea21f090280c4a24..573a9391e8389fc25c9595317cfbf6b48b8289ad 100644 --- a/Plugin/PluginManager.cpp +++ b/Plugin/PluginManager.cpp @@ -56,6 +56,7 @@ #include "Bubbles.h" #include "NearToFarField.h" #include "DiscretizationError.h" +#include "Scal2Tens.h" #include "Scal2Vec.h" #include "CutMesh.h" #include "NewView.h" @@ -245,7 +246,7 @@ void PluginManager::registerDefaultPlugins() allPlugins.insert(std::pair<std::string, GMSH_Plugin*> ("DiscretizationError", GMSH_RegisterDiscretizationErrorPlugin())); allPlugins.insert(std::pair<std::string, GMSH_Plugin*> - ("Scal2Vec", GMSH_RegisterScal2VecPlugin())); + ("Scal2Tens", GMSH_RegisterScal2TensPlugin())); allPlugins.insert(std::pair<std::string, GMSH_Plugin*> ("NewView", GMSH_RegisterNewViewPlugin())); allPlugins.insert(std::pair<std::string, GMSH_Plugin*> diff --git a/Plugin/Scal2Tens.cpp b/Plugin/Scal2Tens.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4cca612cd040104ab65014a3de076392560b65a3 --- /dev/null +++ b/Plugin/Scal2Tens.cpp @@ -0,0 +1,142 @@ +// Gmsh - Copyright (C) 1997-2014 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to the public mailing list <gmsh@geuz.org>. + +#include "Scal2Tens.h" +#include "PViewOptions.h" +#include "shapeFunctions.h" + +StringXNumber Scal2TensOptions_Number[] = { + {GMSH_FULLRC, "NumberOfComponents", NULL, 3.}, + {GMSH_FULLRC, "Comp0", NULL, -1.}, + {GMSH_FULLRC, "Comp1", NULL, -1.}, + {GMSH_FULLRC, "Comp2", NULL, -1.}, + {GMSH_FULLRC, "Comp3", NULL, -1.}, + {GMSH_FULLRC, "Comp4", NULL, -1.}, + {GMSH_FULLRC, "Comp5", NULL, -1.}, + {GMSH_FULLRC, "Comp6", NULL, -1.}, + {GMSH_FULLRC, "Comp7", NULL, -1.}, + {GMSH_FULLRC, "Comp8", NULL, -1.} +}; + +StringXString Scal2TensOptions_String[] = { + {GMSH_FULLRC, "NameNewView", NULL, "NewView"} +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterScal2TensPlugin() + { + return new GMSH_Scal2TensPlugin(); + } +} + +std::string GMSH_Scal2TensPlugin::getHelp() const +{ + return "Plugin(Scal2Tens) converts some scalar fields into a field " + "with several components. The number of components must be given (max. 9). " + "The new view 'NameNewView' contains the new field. If the number " + "of a view is -1, the value of the corresponding component is 0."; +} + +int GMSH_Scal2TensPlugin::getNbOptions() const +{ + return sizeof(Scal2TensOptions_Number) / sizeof(StringXNumber); +} + +StringXNumber *GMSH_Scal2TensPlugin::getOption(int iopt) +{ + return &Scal2TensOptions_Number[iopt]; +} + +int GMSH_Scal2TensPlugin::getNbOptionsStr() const +{ + return sizeof(Scal2TensOptions_String) / sizeof(StringXString); +} + +StringXString *GMSH_Scal2TensPlugin::getOptionStr(int iopt) +{ + return &Scal2TensOptions_String[iopt]; +} + + +PView *GMSH_Scal2TensPlugin::execute(PView *v) +{ + // Load options + int numComp = (int)Scal2TensOptions_Number[0].def; + if ((numComp<1) || (numComp>9)) { + Msg::Error("Scal2Tens plugin: NumberOfComponents must be between 1 and 9 (not '%i')", numComp); + return v; + } + int iView[9]; + for (int comp=0; comp<numComp; comp++) + iView[comp] = (int)Scal2TensOptions_Number[comp+1].def; + + // Load data + PView *vRef=0, *vComp[9]; + for (int comp=0; comp<numComp; comp++) { + if (iView[comp]<0) vComp[comp] = 0; + else { + vComp[comp] = getView(iView[comp], v); + if (!vComp[comp]) { + Msg::Error("Scal2Tens plugin could not find View '%i'", iView[comp]); + return v; + } + if (!vRef) vRef = vComp[comp]; + } + } + if (!vRef) { + Msg::Error("Scal2Tens plugin could not find any view."); + return v; + } + PViewData *dataRef = vRef->getData(); + + // Initialize the new view + PView *vNew = new PView(); + PViewDataList *dataNew = getDataList(vNew); + + int step0 = dataRef->getFirstNonEmptyTimeStep(); + for (int ent=0; ent < dataRef->getNumEntities(step0); ent++) { + for (int ele=0; ele < dataRef->getNumElements(step0, ent); ele++) { + if (dataRef->skipElement(step0, ent, ele)) continue; + int type = dataRef->getType(step0, ent, ele); + int numNodes = dataRef->getNumNodes(step0, ent, ele); + std::vector<double> *out = dataNew->incrementList(numComp, type, numNodes); // Pointer in data of the new view + if (!out) continue; + double x[8], y[8], z[8]; + for (int nod=0; nod<numNodes; nod++) + dataRef->getNode(step0, ent, ele, nod, x[nod], y[nod], z[nod]); + int dim = dataRef->getDimension(step0, ent, ele); + elementFactory factory; + element *element = factory.create(numNodes, dim, x, y, z); + if (!element) continue; + for (int nod=0; nod<numNodes; nod++) out->push_back(x[nod]); // Save coordinates (x,y,z) + for (int nod=0; nod<numNodes; nod++) out->push_back(y[nod]); + for (int nod=0; nod<numNodes; nod++) out->push_back(z[nod]); + for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { + if (!dataRef->hasTimeStep(step)) continue; + for (int nod=0; nod<numNodes; nod++) { + for (int comp=0; comp<numComp; comp++) { + double val=0.; + if(vComp[comp]) vComp[comp]->getData()->getValue(step, ent, ele, nod, 0, val); + out->push_back(val); // Save value + } + } + } + delete element; + } + } + + for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { + if (!dataRef->hasTimeStep(step)) continue; + dataNew->Time.push_back(dataRef->getTime(step)); + } + + std::string nameNewView = Scal2TensOptions_String[0].def; + dataNew->setName(nameNewView); + dataNew->setFileName(nameNewView + ".pos"); + dataNew->finalize(); + + return vNew; +} diff --git a/Plugin/Scal2Tens.h b/Plugin/Scal2Tens.h new file mode 100644 index 0000000000000000000000000000000000000000..41c945487996d2ede2692897a13572a72a652003 --- /dev/null +++ b/Plugin/Scal2Tens.h @@ -0,0 +1,33 @@ +// Gmsh - Copyright (C) 1997-2014 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to the public mailing list <gmsh@geuz.org>. + +#ifndef _SCAL2TENS_H_ +#define _SCAL2TENS_H_ + +#include "Plugin.h" + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterScal2TensPlugin(); +} + +class GMSH_Scal2TensPlugin : public GMSH_PostPlugin +{ + public: + GMSH_Scal2TensPlugin(){} + std::string getName() const { return "Scal2Tens"; } + std::string getShortHelp() const + { + return "Convert some scalar fields into a tensor field with several components"; + } + std::string getHelp() const; + int getNbOptions() const; + StringXNumber *getOption(int iopt); + int getNbOptionsStr() const; + StringXString* getOptionStr(int iopt); + PView *execute(PView *); +}; + +#endif diff --git a/Plugin/Scal2Vec.cpp b/Plugin/Scal2Vec.cpp index 82f269b0488bd83a1aa8a0b56f2bb030cf0e983c..8a8bccb129ff0fc3cbbc6df59c1aa5bee1b4b9ff 100644 --- a/Plugin/Scal2Vec.cpp +++ b/Plugin/Scal2Vec.cpp @@ -27,11 +27,12 @@ extern "C" std::string GMSH_Scal2VecPlugin::getHelp() const { - return "Plugin(Scal2Vec) converts the scalar fields of 'ViewX', " - "'ViewY' and/or 'ViewZ' into a vectorial field. " - "The new view 'NameNewView' contains it.\n\n" - "If the value of 'ViewX', 'ViewY' or 'ViewZ' is -1, " - "the value of the vectorial field in the corresponding direction is 0."; + return "Plugin(Scal2Vec) converts the scalar fields into a vectorial field. " + "The new view 'NameNewView' contains it. " + "If the number of a view is -1, the value of the corresponding " + "component of the vector field is 0." + "\n\n" + "DEPRECATE: Use plugin 'Scal2Tens' instead.'"; } int GMSH_Scal2VecPlugin::getNbOptions() const diff --git a/Plugin/Scal2Vec.h b/Plugin/Scal2Vec.h index d83ee6cffd273dd64f1b8501be862619ba362234..cc5dd2c02d15cd5bbaa0dd66df4cf240b57d9528 100644 --- a/Plugin/Scal2Vec.h +++ b/Plugin/Scal2Vec.h @@ -20,7 +20,7 @@ class GMSH_Scal2VecPlugin : public GMSH_PostPlugin std::string getName() const { return "Scal2Vec"; } std::string getShortHelp() const { - return "Convert some scalar fields into a vector field"; + return "Convert some scalar fields into a vector field [DEPRECATE]"; } std::string getHelp() const; int getNbOptions() const;