Salome HOME
Updated copyright comment
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPlugin_Mesher.hxx
1 // Copyright (C) 2012-2015  ALNEOS
2 // Copyright (C) 2016-2024  EDF
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.alneos.com/ or email : contact@alneos.fr
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21
22 #ifndef _GMSHPlugin_Mesher_HXX_
23 #define _GMSHPlugin_Mesher_HXX_
24
25 #include <stdio.h>
26 #include "GmshVersion.h"
27 #if GMSH_MAJOR_VERSION >=4
28 #include "gmsh.h"
29 #else
30 #include "Gmsh.h"
31 #endif
32 #include "GmshConfig.h"
33 #include "GModelIO_OCC.h"
34 #include "GModelIO_GEO.h"
35 #include "Geo.h"
36 #if GMSH_MAJOR_VERSION >=4
37 #include "GEdge.h"
38 #include "GFace.h"
39 #else
40 #include "GEdgeCompound.h"
41 #include "GFaceCompound.h"
42 #endif
43 #include "MElement.h"
44
45 #include <SMDS_MeshElement.hxx>
46 #include "GMSHPlugin_Defs.hxx"
47 #include "SMESH_Algo.hxx"
48
49 #include <map>
50 #include <set>
51
52 class SMESH_Mesh;
53 class SMESH_Comment;
54 class SMESHDS_Mesh;
55 class TopoDS_Shape;
56 //class TopTools_DataMapOfShapeShape;
57 //class TopTools_IndexedMapOfShape;
58 class GMSHPlugin_Hypothesis;
59
60
61 //=============================================================================
62 /*!
63  * \brief This class calls the GMSH mesher of OCC geometry
64  */
65 //=============================================================================
66
67 class GMSHPLUGIN_EXPORT GMSHPlugin_Mesher
68 {
69  public:
70   // ---------- PUBLIC METHODS ----------
71
72   GMSHPlugin_Mesher (SMESH_Mesh* mesh, const TopoDS_Shape& aShape, bool is2D, bool is3D);
73
74   void SetParameters(const GMSHPlugin_Hypothesis*          hyp);
75
76   bool Compute3D( std::vector< const SMDS_MeshNode* >& nodeVec, 
77                   std::map<const SMDS_MeshElement*, bool, TIDCompare>& listElements, 
78                   bool addElements );
79   bool Compute();
80
81   bool Evaluate(MapShapeNbElems& aResMap);
82
83   static float DistBoundingBox(const SBoundingBox3d& bounds, const SPoint3& point);
84
85   void FillGMSHMesh();
86   void FillGeomMapMeshUsing2DMeshIterator( std::map<const SMDS_MeshElement*, bool, TIDCompare>& listElements );
87   GModel* GetGModel(){ return _gModel;};
88   void finalizeGModel();
89   const SMDS_MeshNode* Node( const MVertex* v );
90   const SMDS_MeshNode* PremeshedNode( const MVertex* v );
91
92  private:
93   SMESH_Mesh*          _mesh;
94   const TopoDS_Shape&  _shape;
95   int                  _algo2d;
96   int                  _algo3d;
97   int                  _recomb2DAlgo;
98   bool                 _recombineAll;
99   int                  _subdivAlgo;
100   int                  _remeshAlgo;
101   int                  _remeshPara;
102   double               _smouthSteps;
103   double               _sizeFactor;
104   double               _minSize, _maxSize;
105   bool                 _secondOrder, _useIncomplElem;
106   bool                 _is2d;
107   bool                 _is3d;
108   int                  _verbLvl;
109   GModel*              _gModel;
110 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=3
111   double               _maxThreads;
112 #endif
113 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
114   double               _meshCurvatureSize;
115 #endif
116
117   std::set<std::string> _compounds;
118
119   std::map< const MVertex *, const SMDS_MeshNode* > _nodeMap;
120   std::map< const MVertex *, const SMDS_MeshNode* > _premeshednodeMap; // used for the SA version
121   SMESHDS_SubMesh* HasSubMesh( const TopoDS_Shape& s );
122
123   void SetGmshOptions();
124   void CreateGmshCompounds();
125   void FillSMesh();
126   void HideComputedEntities( GModel* gModel, bool hideAnyway = false );
127   void RestoreVisibility( GModel* gModel );
128   void Set1DSubMeshes( GModel* );
129   void Set2DSubMeshes( GModel* );
130   void toPython( GModel* );
131   bool IsAllNodesInSameFace( const SMDS_MeshElement* triangle, const TopoDS_Face& F, std::vector<gp_XY>& uvValues );
132   std::map<int,std::vector<std::tuple<smIdType,bool,std::vector<gp_XY>>>> AssociateElementsToFaces( std::map<const SMDS_MeshElement*, bool, TIDCompare>& listElements );
133   void Set2DMeshes( std::vector< const SMDS_MeshNode* >& nodeVec, std::map<const SMDS_MeshElement*, bool, TIDCompare>& listElements );
134
135 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=3
136   void SetMaxThreadsGmsh();
137   void SetCompoundMeshVisibility();
138 #endif
139   class mymsg : public GmshMessage
140   {
141   private:
142     GModel* _gModel;
143   public:
144     mymsg(GModel* _gModel) :  GmshMessage(), _gModel(_gModel) {}
145     void operator()(std::string level, std::string msg);
146   };
147 };
148
149 #endif