Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InputMCF.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 
37 
38 #include <boost/thread.hpp>
39 
40 #include <tinyxml.h>
41 
42 #include "InputMCF.h"
43 
44 using namespace std;
45 using namespace Nektar::NekMeshUtils;
46 
47 namespace Nektar
48 {
49 namespace Utilities
50 {
51 
52 ModuleKey InputMCF::className = GetModuleFactory().RegisterCreatorFunction(
53  ModuleKey(eInputModule, "mcf"), InputMCF::create,
54  "Reads mesh configuration and will generate the mesh file.");
55 
56 /**
57  * @brief Set up InputCAD object.
58  */
59 InputMCF::InputMCF(MeshSharedPtr m) : InputModule(m)
60 {
61 }
62 
64 {
65 }
66 
67 void InputMCF::ParseFile(string nm)
68 {
69  vector<string> filename;
70  filename.push_back(nm);
73 
74  ASSERTL0(pSession->DefinesElement("NEKTAR/MESHING"), "no meshing tag");
75  ASSERTL0(pSession->DefinesElement("NEKTAR/MESHING/INFORMATION"),
76  "no information tag");
77  ASSERTL0(pSession->DefinesElement("NEKTAR/MESHING/PARAMETERS"),
78  "no parameters tag");
79 
80  TiXmlElement *mcf = pSession->GetElement("NEKTAR/MESHING");
81 
82  TiXmlElement *info = mcf->FirstChildElement("INFORMATION");
83  TiXmlElement *I = info->FirstChildElement("I");
84  map<string, string> information;
85  while (I)
86  {
87  string tmp1, tmp2;
88  I->QueryStringAttribute("PROPERTY", &tmp1);
89  I->QueryStringAttribute("VALUE", &tmp2);
90  information[tmp1] = tmp2;
91  I = I->NextSiblingElement("I");
92  }
93 
94  TiXmlElement *param = mcf->FirstChildElement("PARAMETERS");
95  TiXmlElement *P = param->FirstChildElement("P");
96  map<string, string> parameters;
97  while (P)
98  {
99  string tmp1, tmp2;
100  P->QueryStringAttribute("PARAM", &tmp1);
101  P->QueryStringAttribute("VALUE", &tmp2);
102  parameters[tmp1] = tmp2;
103  P = P->NextSiblingElement("P");
104  }
105 
106  set<string> boolparameters;
107 
108  if (pSession->DefinesElement("NEKTAR/MESHING/BOOLPARAMETERS"))
109  {
110  TiXmlElement *bparam = mcf->FirstChildElement("BOOLPARAMETERS");
111  TiXmlElement *BP = bparam->FirstChildElement("P");
112 
113  while (BP)
114  {
115  string tmp;
116  BP->QueryStringAttribute("VALUE", &tmp);
117  boolparameters.insert(tmp);
118  BP = BP->NextSiblingElement("P");
119  }
120  }
121 
122  set<string> refinement;
123  if(pSession->DefinesElement("NEKTAR/MESHING/REFINEMENT"))
124  {
125  TiXmlElement *refine = mcf->FirstChildElement("REFINEMENT");
126  TiXmlElement *L = refine->FirstChildElement("LINE");
127 
128  while (L)
129  {
130  stringstream ss;
131  TiXmlElement *T = L->FirstChildElement("X1");
132  ss << T->GetText() << ",";
133  T = L->FirstChildElement("Y1");
134  ss << T->GetText() << ",";
135  T = L->FirstChildElement("Z1");
136  ss << T->GetText() << ",";
137  T = L->FirstChildElement("X2");
138  ss << T->GetText() << ",";
139  T = L->FirstChildElement("Y2");
140  ss << T->GetText() << ",";
141  T = L->FirstChildElement("Z2");
142  ss << T->GetText() << ",";
143  T = L->FirstChildElement("R");
144  ss << T->GetText() << ",";
145  T = L->FirstChildElement("D");
146  ss << T->GetText();
147 
148  refinement.insert(ss.str());
149 
150  L = L->NextSiblingElement("LINE");
151  }
152  }
153 
155 
156  it = information.find("CADFile");
157  ASSERTL0(it != information.end(), "no cadfile defined");
158  m_cadfile = it->second;
159 
160  it = information.find("MeshType");
161  ASSERTL0(it != information.end(), "no meshtype defined");
162  m_makeBL = it->second == "3DBndLayer";
163  m_2D = it->second == "2D";
164  if (it->second == "2DBndLayer")
165  {
166  m_makeBL = true;
167  m_2D = true;
168  }
169  if(!m_makeBL && !m_2D)
170  {
171  ASSERTL0(it->second == "3D", "unsure on MeshType")
172  }
173 
174 
175  it = parameters.find("MinDelta");
176  ASSERTL0(it != parameters.end(), "no mindelta defined");
177  m_minDelta = it->second;
178 
179  it = parameters.find("MaxDelta");
180  ASSERTL0(it != parameters.end(), "no maxdelta defined");
181  m_maxDelta = it->second;
182 
183  it = parameters.find("EPS");
184  ASSERTL0(it != parameters.end(), "no eps defined");
185  m_eps = it->second;
186 
187  it = parameters.find("Order");
188  ASSERTL0(it != parameters.end(), "no order defined");
189  m_order = it->second;
190 
191  if (m_makeBL)
192  {
193  it = parameters.find("BndLayerSurfaces");
194  ASSERTL0(it != parameters.end(), "no BndLayersurfs defined");
195  m_blsurfs = it->second;
196 
197  it = parameters.find("BndLayerThickness");
198  ASSERTL0(it != parameters.end(), "no BndLayerthick defined");
199  m_blthick = it->second;
200 
201  it = parameters.find("BndLayerLayers");
202  m_splitBL = it != parameters.end();
203  if(m_splitBL)
204  {
205  m_bllayers = it->second;
206  it = parameters.find("BndLayerProgression");
207  m_blprog = it != parameters.end() ? it->second : "2.0";
208  }
209  }
210 
211  m_naca = false;
212  if(m_2D && m_cadfile.find('.') == std::string::npos)
213  {
214  m_naca = true;
215 
216  stringstream ss;
217  it = parameters.find("Xmin");
218  ASSERTL0(it != parameters.end(), "no xmin defined");
219  ss << it->second << ",";
220  it = parameters.find("Ymin");
221  ASSERTL0(it != parameters.end(), "no ymin defined");
222  ss << it->second << ",";
223  it = parameters.find("Xmax");
224  ASSERTL0(it != parameters.end(), "no xmax defined");
225  ss << it->second << ",";
226  it = parameters.find("Ymax");
227  ASSERTL0(it != parameters.end(), "no zmax defined");
228  ss << it->second << ",";
229  it = parameters.find("AOA");
230  ASSERTL0(it != parameters.end(), "no aoa defined");
231  ss << it->second;
232 
233  m_nacadomain = ss.str();
234  }
235 
237  sit = boolparameters.find("SurfaceOptimiser");
238  m_surfopti = sit != boolparameters.end();
239  sit = boolparameters.find("WriteOctree");
240  m_woct = sit != boolparameters.end();
241  sit = boolparameters.find("VariationalOptimiser");
242  m_varopti = sit != boolparameters.end();
243 
244  m_refine = refinement.size() > 0;
245  if(m_refine)
246  {
247  stringstream ss;
248  for(sit = refinement.begin(); sit != refinement.end(); sit++)
249  {
250  ss << *sit;
251  ss << ":";
252  }
253  m_refinement = ss.str();
254  m_refinement.erase(m_refinement.end()-1);
255  }
256 }
257 
259 {
260  ParseFile(m_config["infile"].as<string>());
261 
262  m_mesh->m_expDim = 3;
263  m_mesh->m_spaceDim = 3;
264  m_mesh->m_nummode = boost::lexical_cast<int>(m_order) + 1;
265 
266  vector<ModuleSharedPtr> mods;
267 
268  ////**** CAD ****////
269  mods.push_back(GetModuleFactory().CreateInstance(
270  ModuleKey(eProcessModule, "loadcad"), m_mesh));
271  mods.back()->RegisterConfig("filename", m_cadfile);
272 
273  if(m_2D)
274  {
275  mods.back()->RegisterConfig("2D","");
276  }
277  if(m_naca)
278  {
279  mods.back()->RegisterConfig("NACA",m_nacadomain);
280  }
281 
282  ////**** Octree ****////
283  mods.push_back(GetModuleFactory().CreateInstance(
284  ModuleKey(eProcessModule, "loadoctree"), m_mesh));
285  mods.back()->RegisterConfig("mindel", m_minDelta);
286  mods.back()->RegisterConfig("maxdel", m_maxDelta);
287  mods.back()->RegisterConfig("eps", m_eps);
288  if (m_refine)
289  {
290  mods.back()->RegisterConfig("refinement", m_refinement);
291  }
292  if (m_woct)
293  {
294  mods.back()->RegisterConfig("writeoctree", "");
295  }
296 
297  if(m_2D)
298  {
299  m_mesh->m_expDim = 2;
300  m_mesh->m_spaceDim = 2;
301  mods.push_back(GetModuleFactory().CreateInstance(
302  ModuleKey(eProcessModule, "2dgenerator"), m_mesh));
303  if (m_makeBL)
304  {
305  mods.back()->RegisterConfig("blcurves", m_blsurfs);
306  mods.back()->RegisterConfig("blthick", m_blthick);
307  }
308  }
309  else
310  {
311  ////**** SurfaceMesh ****////
312  mods.push_back(GetModuleFactory().CreateInstance(
313  ModuleKey(eProcessModule, "surfacemesh"), m_mesh));
314 
315  ////**** VolumeMesh ****////
316  mods.push_back(GetModuleFactory().CreateInstance(
317  ModuleKey(eProcessModule, "volumemesh"), m_mesh));
318  if(m_makeBL)
319  {
320  mods.back()->RegisterConfig("blsurfs",m_blsurfs);
321  mods.back()->RegisterConfig("blthick",m_blthick);
322  mods.back()->RegisterConfig("bllayers",m_bllayers);
323  mods.back()->RegisterConfig("blprog",m_blprog);
324  }
325  }
326 
327  ////**** HOSurface ****////
328  mods.push_back(GetModuleFactory().CreateInstance(
329  ModuleKey(eProcessModule, "hosurface"), m_mesh));
330  if (m_surfopti)
331  {
332  mods.back()->RegisterConfig("opti", "");
333  }
334 
335  ////*** VARIATIONAL OPTIMISATION ****////
336  if(m_varopti)
337  {
338  unsigned int np = boost::thread::physical_concurrency();
339  if(m_mesh->m_verbose)
340  {
341  cout << "Detecting 4 cores, will attempt to run in parrallel" << endl;
342  }
343  mods.push_back(GetModuleFactory().CreateInstance(
344  ModuleKey(eProcessModule, "varopti"), m_mesh));
345  mods.back()->RegisterConfig("hyperelastic","");
346  mods.back()->RegisterConfig("maxiter","10");
347  mods.back()->RegisterConfig("numthreads",boost::lexical_cast<string>(np));
348  }
349 
350  ////**** SPLIT BL ****////
351  if(m_splitBL)
352  {
353  mods.push_back(GetModuleFactory().CreateInstance(
354  ModuleKey(eProcessModule, "bl"), m_mesh));
355  mods.back()->RegisterConfig("layers",m_bllayers);
356  mods.back()->RegisterConfig("surf",m_blsurfs);
357  mods.back()->RegisterConfig("nq",boost::lexical_cast<string>(m_mesh->m_nummode));
358  mods.back()->RegisterConfig("r",m_blprog);
359  }
360 
361  for(int i = 0; i < mods.size(); i++)
362  {
363  mods[i]->SetDefaults();
364  mods[i]->Process();
365  }
366 }
367 }
368 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
STL namespace.
pair< ModuleType, string > ModuleKey
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
std::string m_nacadomain
Definition: InputMCF.h:64
void ParseFile(std::string nm)
Definition: InputMCF.cpp:67
std::map< std::string, ConfigOption > m_config
List of configuration values.
NekDouble L
Abstract base class for input modules.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:147
std::string m_refinement
Definition: InputMCF.h:64
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215