Salome HOME
updated copyright message
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D3D.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  NETGENPlugin : C++ implementation
24 // File   : NETGENPlugin_NETGEN_2D3D.cxx
25 // Author : Michael Sazonov (OCN)
26 // Date   : 20/03/2006
27 // Project   : SALOME
28 //=============================================================================
29 //
30 #include "NETGENPlugin_NETGEN_2D3D.hxx"
31 #include "NETGENPlugin_Hypothesis.hxx"
32 #include "NETGENPlugin_SimpleHypothesis_3D.hxx"
33 #include "NETGENPlugin_Mesher.hxx"
34
35 #include <SMESHDS_Mesh.hxx>
36 #include <SMESH_ControlsDef.hxx>
37 #include <SMESH_Gen.hxx>
38 #include <SMESH_Mesh.hxx>
39 #include <StdMeshers_ViscousLayers.hxx>
40
41 #include <utilities.h>
42
43 #include <list>
44
45 namespace nglib {
46 #include <nglib.h>
47 }
48 #include <meshing.hpp>
49
50 using namespace std;
51
52 //=============================================================================
53 /*!
54  *  
55  */
56 //=============================================================================
57
58 NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D(int hypId,
59                                                    SMESH_Gen* gen)
60   : SMESH_3D_Algo(hypId, gen)
61 {
62   //MESSAGE("NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D");
63   _name = "NETGEN_2D3D";
64   _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
65   _compatibleHypothesis.push_back("NETGEN_Parameters");
66   _compatibleHypothesis.push_back("NETGEN_SimpleParameters_3D");
67   _compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() );
68   _requireDiscreteBoundary = false;
69   _onlyUnaryInput = false;
70   _hypothesis = NULL;
71   _supportSubmeshes = true;
72 }
73
74 //=============================================================================
75 /*!
76  *
77  */
78 //=============================================================================
79
80 NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D()
81 {
82   //MESSAGE("NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D");
83 }
84
85 //=============================================================================
86 /*!
87  *
88  */
89 //=============================================================================
90
91 bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis (SMESH_Mesh&         aMesh,
92                                                 const TopoDS_Shape& aShape,
93                                                 Hypothesis_Status&  aStatus)
94 {
95   _hypothesis       = NULL;
96   _viscousLayersHyp = NULL;
97   _mesher           = NULL;
98
99   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape, /*noAux=*/false);
100   if ( hyps.empty() )
101   {
102     aStatus = SMESH_Hypothesis::HYP_OK;
103     return true;  // can work with no hypothesis
104   }
105
106   list<const SMESHDS_Hypothesis*>::const_iterator h = hyps.begin();
107   for ( ; h != hyps.end(); ++h )
108   {
109     const SMESHDS_Hypothesis* aHyp = *h;
110     std::string            hypName = aHyp->GetName();
111
112     if ( std::find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
113                     hypName ) != _compatibleHypothesis.end() )
114     {
115       if ( hypName == StdMeshers_ViscousLayers::GetHypType() )
116         _viscousLayersHyp = dynamic_cast<const StdMeshers_ViscousLayers*>( aHyp );
117       else
118         _hypothesis = aHyp;
119       aStatus = SMESH_Hypothesis::HYP_OK;
120     }
121     else
122     {
123       aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
124       break;
125     }
126   }
127
128   return aStatus == SMESH_Hypothesis::HYP_OK;
129 }
130
131 //=============================================================================
132 /*!
133  *  Here we are going to use the NETGEN mesher
134  */
135 //=============================================================================
136
137 bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh&         aMesh,
138                                        const TopoDS_Shape& aShape)
139 {
140   netgen::multithread.terminate = 0;
141
142   NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
143   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
144   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_3D*>(_hypothesis));
145   mesher.SetParameters(_viscousLayersHyp);
146   mesher.SetSelfPointer( &_mesher );
147   return mesher.Compute();
148 }
149
150 //=============================================================================
151 /*!
152  *
153  */
154 //=============================================================================
155
156 void NETGENPlugin_NETGEN_2D3D::CancelCompute()
157 {
158   SMESH_Algo::CancelCompute();
159   netgen::multithread.terminate = 1;
160 }
161
162 //================================================================================
163 /*!
164  * \brief Return progress of Compute() [0.,1]
165  */
166 //================================================================================
167
168 double NETGENPlugin_NETGEN_2D3D::GetProgress() const
169 {
170   double & progress = (double &)_progress;
171   if ( _mesher )
172     progress = _mesher->GetProgress(this, &_progressTic, &_progress);
173   else if ( _progress > 0.001 )
174     progress = 0.99;
175
176   return _progress;
177 }
178
179 //=============================================================================
180 /*!
181  *
182  */
183 //=============================================================================
184
185 bool NETGENPlugin_NETGEN_2D3D::Evaluate(SMESH_Mesh&         aMesh,
186                                         const TopoDS_Shape& aShape,
187                                         MapShapeNbElems& aResMap)
188 {
189   NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
190   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
191   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
192   return mesher.Evaluate(aResMap);
193 }