From f230dcc6cf0674bfcad0b9951574391dcee7bdd5 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Thu, 17 Jan 2013 13:01:23 +0000 Subject: [PATCH] simple mesh partitioner (slices_ --- Geo/GModelIO_MSH2.cpp | 2 +- Plugin/CMakeLists.txt | 1 + Plugin/PluginManager.cpp | 5 +- Plugin/SimplePartition.cpp | 79 +++++++++++++++++++ Plugin/SimplePartition.h | 31 ++++++++ Post/PViewDataIO.cpp | 4 +- .../CreateVolumeAroundFalcon_FrontalISO.geo | 6 +- .../3d/Falcon/SurfaceMeshAnisoCurvature.geo | 6 +- benchmarks/3d/Falcon/SurfaceMeshUniform.geo | 30 +++++++ 9 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 Plugin/SimplePartition.cpp create mode 100644 Plugin/SimplePartition.h create mode 100644 benchmarks/3d/Falcon/SurfaceMeshUniform.geo diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp index 4ef614e613..3a7813cb67 100644 --- a/Geo/GModelIO_MSH2.cpp +++ b/Geo/GModelIO_MSH2.cpp @@ -818,7 +818,7 @@ static int getNumElementsMSH(GModel *m, bool saveAll, int saveSinglePartition) int GModel::_writeMSH2(const std::string &name, double version, bool binary, bool saveAll, bool saveParametric, double scalingFactor, - int elementStartNum, int saveSinglePartition,bool multipleView) + int elementStartNum, int saveSinglePartition, bool multipleView) { FILE *fp; if(multipleView) diff --git a/Plugin/CMakeLists.txt b/Plugin/CMakeLists.txt index eb589809df..02342647a3 100644 --- a/Plugin/CMakeLists.txt +++ b/Plugin/CMakeLists.txt @@ -31,6 +31,7 @@ set(SRC Scal2Vec.cpp CutMesh.cpp NewView.cpp + SimplePartition.cpp ) file(GLOB HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h) diff --git a/Plugin/PluginManager.cpp b/Plugin/PluginManager.cpp index ca6b701bed..fb0ab5f7a5 100644 --- a/Plugin/PluginManager.cpp +++ b/Plugin/PluginManager.cpp @@ -22,6 +22,7 @@ #include "AnalyseCurvedMesh.h" #include "MathEval.h" #include "ExtractElements.h" +#include "SimplePartition.h" #include "HarmonicToTime.h" #include "ModulusPhase.h" #include "Integrate.h" @@ -240,8 +241,10 @@ void PluginManager::registerDefaultPlugins() ("DiscretizationError", GMSH_RegisterDiscretizationErrorPlugin())); allPlugins.insert(std::pair<std::string, GMSH_Plugin*> ("Scal2Vec", GMSH_RegisterScal2VecPlugin())); - allPlugins.insert(std::pair<std::string, GMSH_Plugin*> + allPlugins.insert(std::pair<std::string, GMSH_Plugin*> ("NewView", GMSH_RegisterNewViewPlugin())); + allPlugins.insert(std::pair<std::string, GMSH_Plugin*> + ("SimplePartition", GMSH_RegisterSimplePartitionPlugin())); #if defined(HAVE_TETGEN) allPlugins.insert(std::pair<std::string, GMSH_Plugin*> ("Tetrahedralize", GMSH_RegisterTetrahedralizePlugin())); diff --git a/Plugin/SimplePartition.cpp b/Plugin/SimplePartition.cpp new file mode 100644 index 0000000000..a5e1a8d69c --- /dev/null +++ b/Plugin/SimplePartition.cpp @@ -0,0 +1,79 @@ +// Gmsh - Copyright (C) 1997-2013 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 "SimplePartition.h" +#include "GModel.h" +#include "MElement.h" +#if defined(HAVE_MESH) +#include "meshPartition.h" +#endif + +StringXNumber SimplePartitionOptions_Number[] = { + {GMSH_FULLRC, "NumSlices", NULL, 4.}, + {GMSH_FULLRC, "Direction", NULL, 0.}, +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSimplePartitionPlugin() + { + return new GMSH_SimplePartitionPlugin(); + } +} + +std::string GMSH_SimplePartitionPlugin::getHelp() const +{ + return "Plugin(SimplePartition) partitions the current mesh into " + "`NumSlices' slices, along the X-, Y- or Z-axis depending on " + "the value of `Direction' (0,1,2)."; +} + +int GMSH_SimplePartitionPlugin::getNbOptions() const +{ + return sizeof(SimplePartitionOptions_Number) / sizeof(StringXNumber); +} + +StringXNumber *GMSH_SimplePartitionPlugin::getOption(int iopt) +{ + return &SimplePartitionOptions_Number[iopt]; +} + +PView *GMSH_SimplePartitionPlugin::execute(PView *v) +{ + int numSlices = (int)SimplePartitionOptions_Number[0].def; + int direction = (int)SimplePartitionOptions_Number[1].def; + + // partition the current model + GModel *m = GModel::current(); + SBoundingBox3d bbox = m->bounds(); + double pmin = bbox.min()[direction], pmax = bbox.max()[direction]; + std::vector<GEntity*> entities; + m->getEntities(entities); + for(unsigned int i = 0; i < entities.size(); i++){ + int n = entities[i]->getNumMeshElements(); + for(int j = 0; j < n; j++){ + MElement *e = entities[i]->getMeshElement(j); + double val = pmax; + for(int k = 0; k < e->getNumVertices(); k++){ + MVertex *v = e->getVertex(k); + val = std::min(val, v->point()[direction]); + } + for(int p = 0; p < numSlices; p++){ + double p1 = pmin + p * (pmax - pmin) / numSlices; + double p2 = pmin + (p + 1) * (pmax - pmin) / numSlices; + if(val >= p1 && val < p2){ + e->setPartition(p + 1); + break; + } + } + } + } + m->recomputeMeshPartitions(); + +#if defined(HAVE_MESH) + CreatePartitionBoundaries(m, false, false); +#endif + return v; +} diff --git a/Plugin/SimplePartition.h b/Plugin/SimplePartition.h new file mode 100644 index 0000000000..b436070c46 --- /dev/null +++ b/Plugin/SimplePartition.h @@ -0,0 +1,31 @@ +// Gmsh - Copyright (C) 1997-2013 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 _SIMPLE_PARTITION_H_ +#define _SIMPLE_PARTITION_H_ + +#include "Plugin.h" + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterSimplePartitionPlugin(); +} + +class GMSH_SimplePartitionPlugin : public GMSH_PostPlugin +{ + public: + GMSH_SimplePartitionPlugin(){} + std::string getName() const { return "SimplePartition"; } + std::string getShortHelp() const + { + return "Simple mesh partitioner"; + } + std::string getHelp() const; + int getNbOptions() const; + StringXNumber* getOption(int iopt); + PView *execute(PView *); +}; + +#endif diff --git a/Post/PViewDataIO.cpp b/Post/PViewDataIO.cpp index 6f0b87e42b..5d4610d559 100644 --- a/Post/PViewDataIO.cpp +++ b/Post/PViewDataIO.cpp @@ -176,8 +176,8 @@ bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed, return true; } -bool PViewData::writeMSH(const std::string &fileName, double version, bool binary, bool savemesh, - bool multipleView) +bool PViewData::writeMSH(const std::string &fileName, double version, bool binary, + bool savemesh, bool multipleView) { Msg::Error("MSH export not implemented for this view type"); return false; diff --git a/benchmarks/3d/Falcon/CreateVolumeAroundFalcon_FrontalISO.geo b/benchmarks/3d/Falcon/CreateVolumeAroundFalcon_FrontalISO.geo index 250f4b73cd..e4261b2f19 100644 --- a/benchmarks/3d/Falcon/CreateVolumeAroundFalcon_FrontalISO.geo +++ b/benchmarks/3d/Falcon/CreateVolumeAroundFalcon_FrontalISO.geo @@ -1,8 +1,10 @@ Mesh.Algorithm3D=4; //1-Delaunay, 4-Frontal, 5-Frontal Delaunay 6-Frontal hex, 7-MMG3D, 9-RTree -Mesh.CharacteristicLengthFactor = 1.2; +Mesh.CharacteristicLengthFactor = 1.2/10; -Merge "SurfaceMeshAnisoCurvature.stl"; +Merge "InitialMeshFalcon.stl"; +//Merge "SurfaceMeshUniform.stl"; +//Merge "SurfaceMeshAnisoCurvature.stl"; CreateTopology; diff --git a/benchmarks/3d/Falcon/SurfaceMeshAnisoCurvature.geo b/benchmarks/3d/Falcon/SurfaceMeshAnisoCurvature.geo index 92c94aba0f..a294856c05 100644 --- a/benchmarks/3d/Falcon/SurfaceMeshAnisoCurvature.geo +++ b/benchmarks/3d/Falcon/SurfaceMeshAnisoCurvature.geo @@ -1,5 +1,5 @@ Mesh.RemeshParametrization=7; //0=harmonic_circle, 1=conformal, 2=rbf, 3=harmonic_plane, 4=convex_circle, 5=convex_plane, 6=harmonic square -Mesh.RemeshAlgorithm=1; //(0) nosplit (1) automatic (2) split only with metis +Mesh.RemeshAlgorithm=1; //(0) nosplit (1) automatic (2) split only with metis Mesh.Algorithm=7; //(1=MeshAdapt, 2=Automatic, 5=Delaunay, 6=Frontal, 7=bamg, 8=delquad) @@ -34,10 +34,10 @@ For i In {0 : #ss[]-1} Physical Surface(i+1) = { i+100 }; EndFor -// The trailing edge of the horizontal tail surface +// The trailing edge of the horizontal tail surface // should be an attractor -//Point(100000) = {16.858,2.0482,0.018793,0.1}; +//Point(100000) = {16.858,2.0482,0.018793,0.1}; Point(100000) = {-1.16411804,1.83824622,0.29113513}; Field[1] = Attractor; Field[1].NodesList = { 100000 }; diff --git a/benchmarks/3d/Falcon/SurfaceMeshUniform.geo b/benchmarks/3d/Falcon/SurfaceMeshUniform.geo new file mode 100644 index 0000000000..e15d7b85a7 --- /dev/null +++ b/benchmarks/3d/Falcon/SurfaceMeshUniform.geo @@ -0,0 +1,30 @@ +Mesh.RemeshParametrization=7; //0=harmonic_circle, 1=conformal, 2=rbf, 3=harmonic_plane, 4=convex_circle, 5=convex_plane, 6=harmonic square +Mesh.RemeshAlgorithm=1; //(0) nosplit (1) automatic (2) split only with metis +Mesh.Algorithm=6; //(1=MeshAdapt, 2=Automatic, 5=Delaunay, 6=Frontal, 7=bamg, 8=delquad) + +Mesh.CharacteristicLengthFromPoints = 0; +Mesh.CharacteristicLengthMin = 0.02; +Mesh.CharacteristicLengthMax = 0.02; +Mesh.LcIntegrationPrecision = 1.e-5; +Mesh.MinimumCirclePoints = 50; +Mesh.CharacteristicLengthExtendFromBoundary = 0; +Mesh.CharacteristicLengthFromCurvature = 0; +Mesh.CharacteristicLengthFromPoints = 0; + +Merge "InitialMeshFalcon.msh"; + +CreateTopology; + +// Make all lines compound: +ll[] = Line "*"; +For j In {0 : #ll[]-1} + Compound Line(1000+j) = ll[j]; + Physical Line(1000+j) = (1000+j); +EndFor + +// Make all surfaces compound and physical: +ss[] = Surface "*"; +For i In {0 : #ss[]-1} + Compound Surface(i+100) = ss[i]; + Physical Surface(i+1) = { i+100 }; +EndFor -- GitLab