Salome HOME
Copyrights update 2015.
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_NETGEN_2D.cxx
1 // Copyright (C) 2007-2015  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_2D.cxx
25 // Author : Michael Sazonov (OCN)
26 // Date   : 20/03/2006
27 // Project   : SALOME
28 //=============================================================================
29 //
30 #include "NETGENPlugin_NETGEN_2D.hxx"
31 #include "NETGENPlugin_Hypothesis_2D.hxx"
32 #include "NETGENPlugin_SimpleHypothesis_2D.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_ViscousLayers2D.hxx>
40 #include <utilities.h>
41
42 #include <list>
43
44 namespace nglib {
45 #include <nglib.h>
46 }
47 #include <meshing.hpp>
48
49 using namespace std;
50
51 //=============================================================================
52 /*!
53  *  
54  */
55 //=============================================================================
56
57 NETGENPlugin_NETGEN_2D::NETGENPlugin_NETGEN_2D(int hypId, int studyId,
58                                                SMESH_Gen* gen)
59   : SMESH_2D_Algo(hypId, studyId, gen)
60 {
61   MESSAGE("NETGENPlugin_NETGEN_2D::NETGENPlugin_NETGEN_2D");
62   _name = "NETGEN_2D";
63   _shapeType = (1 << TopAbs_FACE); // 1 bit /shape type
64   _compatibleHypothesis.push_back("NETGEN_Parameters_2D");
65   _compatibleHypothesis.push_back("NETGEN_SimpleParameters_2D");
66   _compatibleHypothesis.push_back( StdMeshers_ViscousLayers2D::GetHypType() );
67   _requireDiscreteBoundary = false;
68   _onlyUnaryInput          = false;
69   _hypothesis              = NULL;
70   _supportSubmeshes        = true;
71 }
72
73 //=============================================================================
74 /*!
75  *  
76  */
77 //=============================================================================
78
79 NETGENPlugin_NETGEN_2D::~NETGENPlugin_NETGEN_2D()
80 {
81   MESSAGE("NETGENPlugin_NETGEN_2D::~NETGENPlugin_NETGEN_2D");
82 }
83
84 //=============================================================================
85 /*!
86  *  
87  */
88 //=============================================================================
89
90 bool NETGENPlugin_NETGEN_2D::CheckHypothesis (SMESH_Mesh&         aMesh,
91                                               const TopoDS_Shape& aShape,
92                                               Hypothesis_Status&  aStatus)
93 {
94   _hypothesis        = NULL;
95   _isViscousLayers2D = false;
96   _mesher            = NULL;
97
98   // can work with no hypothesis
99   aStatus = SMESH_Hypothesis::HYP_OK;
100
101   const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape, /*skipAux=*/false);
102   list<const SMESHDS_Hypothesis*>::const_iterator h = hyps.begin();
103   for ( ; h != hyps.end(); ++h )
104   {
105     const SMESHDS_Hypothesis* theHyp = *h;
106     string hypName = theHyp->GetName();
107     if ( hypName == StdMeshers_ViscousLayers2D::GetHypType() )
108       _isViscousLayers2D = true;
109     else if ( _hypothesis )
110       aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
111     else
112       _hypothesis = theHyp;
113   }
114
115   if ( aStatus == HYP_OK && _isViscousLayers2D )
116     error( StdMeshers_ViscousLayers2D::CheckHypothesis( aMesh, aShape, aStatus ));
117
118   return aStatus == SMESH_Hypothesis::HYP_OK;
119 }
120
121 //=============================================================================
122 /*!
123  *
124  */
125 //=============================================================================
126
127 bool NETGENPlugin_NETGEN_2D::Compute(SMESH_Mesh&         aMesh,
128                                      const TopoDS_Shape& aShape)
129 {
130   netgen::multithread.terminate = 0;
131
132   NETGENPlugin_Mesher mesher(&aMesh, aShape, /*is3D = */false);
133   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
134   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
135   mesher.SetViscousLayers2DAssigned( _isViscousLayers2D );
136   mesher.SetSelfPointer( &_mesher );
137   return mesher.Compute();
138 }
139
140 //=============================================================================
141 /*!
142  * Terminate Compute()
143  */
144 //=============================================================================
145
146 void NETGENPlugin_NETGEN_2D::CancelCompute()
147 {
148   SMESH_Algo::CancelCompute();
149   netgen::multithread.terminate = 1;
150 }
151
152 //================================================================================
153 /*!
154  * \brief Return progress of Compute() [0.,1]
155  */
156 //================================================================================
157
158 double NETGENPlugin_NETGEN_2D::GetProgress() const
159 {
160   return _mesher ? _mesher->GetProgress(this, &_progressTic, &_progress) : 0;
161 }
162
163 //=============================================================================
164 /*!
165  *
166  */
167 //=============================================================================
168
169 bool NETGENPlugin_NETGEN_2D::Evaluate(SMESH_Mesh&         aMesh,
170                                       const TopoDS_Shape& aShape,
171                                       MapShapeNbElems& aResMap)
172 {
173
174   NETGENPlugin_Mesher mesher(&aMesh, aShape, false);
175   mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
176   mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
177   return mesher.Evaluate(aResMap);
178 }