Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InputCAD.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: InputCAD.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: create mesh from cad using mesh utils
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
38 
39 #include <boost/filesystem.hpp>
40 
42 
48 
49 #include "InputCAD.h"
50 
51 using namespace std;
52 using namespace Nektar::NekMeshUtils;
53 
54 namespace Nektar
55 {
56 namespace Utilities
57 {
58 
59 ModuleKey InputCAD::className = GetModuleFactory().RegisterCreatorFunction(
60  ModuleKey(eInputModule, "mcf"),
61  InputCAD::create,
62  "Reads CAD geometry and will generate the mesh file.");
63 
64 /**
65  * @brief Set up InputCAD object.
66  */
67 InputCAD::InputCAD(MeshSharedPtr m) : InputModule(m)
68 {
69 }
70 
72 {
73 }
74 
76 {
77  vector<string> filename;
78  filename.push_back(m_config["infile"].as<string>());
79  string fn = filename[0].substr(0, filename[0].find("."));
80 
83 
84  // these parameters must be defined for any mesh generation to work
85  pSession->LoadParameter("MinDelta", m_minDelta);
86  pSession->LoadParameter("MaxDelta", m_maxDelta);
87  pSession->LoadParameter("EPS", m_eps);
88  pSession->LoadParameter("Order", m_order);
89  m_CADName = pSession->GetSolverInfo("CADFile");
90 
91  if (pSession->DefinesSolverInfo("MeshType"))
92  {
93  if (pSession->GetSolverInfo("MeshType") == "BL")
94  {
95  m_makeBL = true;
96  pSession->LoadParameter("BLThick", m_blthick);
97  }
98  else
99  {
100  m_makeBL = false;
101  }
102  }
103  else
104  {
105  m_makeBL = false;
106  }
107 
108  if (pSession->DefinesSolverInfo("WriteOctree"))
109  {
110  m_writeoctree = pSession->GetSolverInfo("WriteOctree") == "TRUE";
111  }
112 
113  vector<unsigned int> symsurfs;
114  vector<unsigned int> blsurfs;
115  if (m_makeBL)
116  {
117  string sym, bl;
118  sym = pSession->GetSolverInfo("SymPlane");
119  bl = pSession->GetSolverInfo("BLSurfs");
120  ParseUtils::GenerateSeqVector(sym.c_str(), symsurfs);
121  ParseUtils::GenerateSeqVector(bl.c_str(), blsurfs);
122  sort(symsurfs.begin(), symsurfs.end());
123  sort(blsurfs.begin(), blsurfs.end());
124  ASSERTL0(blsurfs.size() > 0,
125  "No surfaces selected to make boundary layer on");
126  }
127 
128  if (pSession->DefinesSolverInfo("UserDefinedSpacing"))
129  {
130  m_udsName = pSession->GetSolverInfo("UserDefinedSpacing");
131  ASSERTL0(boost::filesystem::exists(m_udsName.c_str()),
132  "UserDefinedSpacing file does not exist");
133  }
134  else
135  {
136  m_udsName = "N";
137  }
138 
139  CADSystemSharedPtr m_cad =
141 
142  if (m_mesh->m_verbose)
143  {
144  cout << "Building mesh for: " << m_CADName << endl;
145  }
146 
147  ASSERTL0(m_cad->LoadCAD(), "Failed to load CAD");
148 
149  if (m_mesh->m_verbose)
150  {
151  cout << "With parameters:" << endl;
152  cout << "\tmin delta: " << m_minDelta << endl
153  << "\tmax delta: " << m_maxDelta << endl
154  << "\tesp: " << m_eps << endl
155  << "\torder: " << m_order << endl;
156  m_cad->Report();
157  }
158 
159  if (m_makeBL && m_mesh->m_verbose)
160  {
161 
162  cout << "\tWill make boundary layers on surfs: ";
163  for (int i = 0; i < blsurfs.size(); i++)
164  {
165  cout << blsurfs[i] << " ";
166  }
167  cout << endl << "\tWith the symmetry planes: ";
168  for (int i = 0; i < symsurfs.size(); i++)
169  {
170  cout << symsurfs[i] << " ";
171  }
172  cout << endl << "\tWith thickness " << m_blthick << endl;
173  }
174 
175  // create octree
177  m_cad, m_mesh->m_verbose, m_minDelta, m_maxDelta, m_eps, m_udsName);
178 
179  m_octree->Build();
180 
181  if (m_writeoctree)
182  {
183  MeshSharedPtr oct = boost::shared_ptr<Mesh>(new Mesh());
184  oct->m_expDim = 3;
185  oct->m_spaceDim = 3;
186  oct->m_nummode = 2;
187 
188  m_octree->GetOctreeMesh(oct);
189 
191  ModuleKey(eOutputModule, "xml"), oct);
192  mod->RegisterConfig("outfile", fn + "_oct.xml");
193  mod->ProcessVertices();
194  mod->ProcessEdges();
195  mod->ProcessFaces();
196  mod->ProcessElements();
197  mod->ProcessComposites();
198  mod->Process();
199  }
200 
201  m_mesh->m_expDim = 3;
202  m_mesh->m_spaceDim = 3;
203  m_mesh->m_nummode = m_order + 1;
204  if (m_makeBL)
205  {
206  m_mesh->m_numcomp = 2; // prisms and tets
207  }
208  else
209  {
210  m_mesh->m_numcomp = 1; // just tets
211  }
212  // m_mesh->m_nummode = 2;
213 
214  // create surface mesh
215  m_mesh->m_expDim--; // just to make it easier to surface mesh for now
216  SurfaceMeshSharedPtr m_surfacemesh =
218  m_mesh, m_cad, m_octree, symsurfs, m_blthick);
219 
220  m_surfacemesh->Mesh();
221 
222  ProcessVertices();
223  ProcessEdges();
224  ProcessFaces();
225  ProcessElements();
227 
228  m_surfacemesh->Report();
229 
230  m_mesh->m_expDim = 3;
231  m_mesh->m_fields.push_back("u");
232  m_mesh->m_fields.push_back("v");
233  m_mesh->m_fields.push_back("w");
234  m_mesh->m_fields.push_back("p");
235 
236  map<int, FaceSharedPtr> surftopriface;
237  // map of surface element id to opposite prism
238  // face for psudo surface in tetmesh
239 
240  TetMeshSharedPtr m_tet;
241  if (m_makeBL)
242  {
244  m_mesh, blsurfs, symsurfs, m_blthick);
245 
246  m_blmesh->Mesh();
247 
248  // create tet mesh
250  m_mesh, m_octree, m_blmesh);
251  }
252  else
253  {
255  }
256 
257  m_tet->Mesh();
258 
260  ProcessVertices();
261  ProcessEdges();
262  ProcessFaces();
263  ProcessElements();
265 
266  m_surfacemesh->HOSurf();
267 
268  if (m_mesh->m_verbose)
269  {
270  cout << endl;
271  cout << m_mesh->m_element[3].size() << endl;
272  }
273 }
274 }
275 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
pair< ModuleType, string > ModuleKey
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
virtual void Process()
Definition: InputCAD.cpp:75
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< SurfaceMesh > SurfaceMeshSharedPtr
Definition: SurfaceMesh.h:106
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
static bool GenerateSeqVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:79
virtual void ClearElementLinks()
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
virtual void ProcessVertices()
Extract element vertices.
boost::shared_ptr< BLMesh > BLMeshSharedPtr
Definition: BLMesh.h:89
virtual void ProcessElements()
Generate element IDs.
boost::shared_ptr< TetMesh > TetMeshSharedPtr
Definition: TetMesh.h:103
virtual void ProcessComposites()
Generate composites.
boost::shared_ptr< Module > ModuleSharedPtr
boost::shared_ptr< Octree > OctreeSharedPtr
Definition: Octree.h:186
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:137
boost::shared_ptr< CADSystem > CADSystemSharedPtr
Definition: CADSystem.h:185
virtual void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:315
ModuleFactory & GetModuleFactory()
Abstract base class for input modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215