diff --git a/Plugin/CMakeLists.txt b/Plugin/CMakeLists.txt index 32d1d68b92d8534691d77282fd735aa375617b52..73833f10b4f29db422b31b5ce2ae3c082ddd816d 100644 --- a/Plugin/CMakeLists.txt +++ b/Plugin/CMakeLists.txt @@ -37,6 +37,7 @@ set(SRC MeshSubEntities.cpp CVTRemesh.cpp ShowNeighborElements.cpp + GaussPoints.cpp ) file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) diff --git a/Plugin/GaussPoints.cpp b/Plugin/GaussPoints.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7eaf6af38a749634a350c646c468b40b8f90cdc2 --- /dev/null +++ b/Plugin/GaussPoints.cpp @@ -0,0 +1,94 @@ +// Gmsh - Copyright (C) 1997-2016 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@onelab.info>. + +#include "GaussPoints.h" +#include "GModel.h" +#include "MElement.h" +#include "PView.h" + +StringXNumber GaussPointsOptions_Number[] = { + {GMSH_FULLRC, "Order", NULL, 0}, + {GMSH_FULLRC, "Dimension", NULL, 2}, + {GMSH_FULLRC, "PhysicalGroup", NULL, 0} +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterGaussPointsPlugin() + { + return new GMSH_GaussPointsPlugin(); + } +} + +int GMSH_GaussPointsPlugin::getNbOptions() const +{ + return sizeof(GaussPointsOptions_Number) / sizeof(StringXNumber); +} + +StringXNumber *GMSH_GaussPointsPlugin::getOption(int iopt) +{ + return &GaussPointsOptions_Number[iopt]; +} + +std::string GMSH_GaussPointsPlugin::getHelp() const +{ + return "Given an input mesh, Plugin(GaussPoints) creates a view containing " + "the Gauss points for a given polynomial `Order'.\n\n" + "If `PhysicalGroup' is nonzero, the plugin only creates points for the " + "elements belonging to the group."; +} + +PView* GMSH_GaussPointsPlugin::execute(PView *v) +{ + int order = (int)GaussPointsOptions_Number[0].def; + int dim = (int)GaussPointsOptions_Number[1].def; + int physical = (int)GaussPointsOptions_Number[2].def; + + GModel *m = GModel::current(); + std::vector<GEntity*> entities; + if(physical){ + std::map<int, std::vector<GEntity*> > groups[4]; + m->getPhysicalGroups(groups); + entities = groups[dim][physical]; + } + else{ + m->getEntities(entities, dim); + } + + if(entities.empty()){ + Msg::Error("No entities"); + return v; + } + + PView *v2 = new PView(); + PViewDataList *data2 = getDataList(v2); + for(unsigned int i = 0; i < entities.size(); i++){ + for(unsigned int j = 0; j < entities[i]->getNumMeshElements(); j++){ + MElement *e = entities[i]->getMeshElement(j); + int npts; IntPt *gp; + e->getIntegrationPoints(order, &npts, &gp); + for (int i = 0; i < npts; i++){ + double u = gp[i].pt[0]; + double v = gp[i].pt[1]; + double w = gp[i].pt[2]; + double weight = gp[i].weight; + SPoint3 p; + e->pnt(u, v, w, p); + data2->SP.push_back(p.x()); + data2->SP.push_back(p.y()); + data2->SP.push_back(p.z()); + data2->SP.push_back(e->getNum()); + data2->NbSP++; + } + } + } + + data2->setName("GaussPoints"); + data2->setFileName("GaussPoints.pos"); + data2->finalize(); + + return v; +} + diff --git a/Plugin/GaussPoints.h b/Plugin/GaussPoints.h new file mode 100644 index 0000000000000000000000000000000000000000..0d507b5a6730dcd5c2a7076829d418b448f6c8da --- /dev/null +++ b/Plugin/GaussPoints.h @@ -0,0 +1,32 @@ +// Gmsh - Copyright (C) 1997-2016 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@onelab.info>. + +#ifndef _GAUSS_POINTS_H_ +#define _GAUSS_POINTS_H_ + +#include "Plugin.h" + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterGaussPointsPlugin(); +} + + +class GMSH_GaussPointsPlugin : public GMSH_PostPlugin +{ + public: + GMSH_GaussPointsPlugin(){} + std::string getName() const { return "GaussPoints"; } + std::string getShortHelp() const + { + return "Gauss points"; + } + std::string getHelp() const; + int getNbOptions() const; + StringXNumber* getOption(int iopt); + PView *execute(PView *); +}; + +#endif diff --git a/Plugin/PluginManager.cpp b/Plugin/PluginManager.cpp index 538dae0c121f821c0ebffee3d8a940f95f45f185..d27f37ce1359e090b7345c2fd347de6d3bf523d9 100644 --- a/Plugin/PluginManager.cpp +++ b/Plugin/PluginManager.cpp @@ -66,6 +66,7 @@ #include "MeshSubEntities.h" #include "CVTRemesh.h" #include "ShowNeighborElements.h" +#include "GaussPoints.h" // for testing purposes only :-) #undef HAVE_DLOPEN @@ -266,6 +267,8 @@ void PluginManager::registerDefaultPlugins() ("ShowNeighborElements", GMSH_RegisterShowNeighborElementsPlugin())); allPlugins.insert(std::pair<std::string, GMSH_Plugin*> ("MeshSubEntities", GMSH_RegisterMeshSubEntitiesPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin*> + ("GaussPoints", GMSH_RegisterGaussPointsPlugin())); #if defined(HAVE_MESH) allPlugins.insert(std::pair<std::string, GMSH_Plugin*> ("AnalyseCurvedMesh", GMSH_RegisterAnalyseCurvedMeshPlugin()));