Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
2DGenerator.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: Generator2D.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: 2D generator object methods.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 #include <algorithm>
36 
38 
41 
42 using namespace std;
43 namespace Nektar
44 {
45 namespace NekMeshUtils
46 {
47 
48 ModuleKey Generator2D::className = GetModuleFactory().RegisterCreatorFunction(
49  ModuleKey(eProcessModule, "2dgenerator"), Generator2D::create,
50  "Generates a 2D mesh");
51 
52 Generator2D::Generator2D(MeshSharedPtr m) : ProcessModule(m)
53 {
54  m_config["blcurves"] =
55  ConfigOption(false, "", "Generate parallelograms on these curves");
56  m_config["blthick"] =
57  ConfigOption(false, "0.0", "Parallelogram layer thickness");
58 }
59 
61 {
62 }
63 
65 {
66  // Check that cad is 2D
67  Array<OneD, NekDouble> bndBox = m_mesh->m_cad->GetBoundingBox();
68  ASSERTL0(fabs(bndBox[5] - bndBox[4]) < 1.0e-7, "CAD isn't 2D");
69 
70  if (m_mesh->m_verbose)
71  {
72  cout << endl << "2D meshing" << endl;
73  cout << endl << "\tCurve meshing:" << endl << endl;
74  }
75 
76  m_mesh->m_numNodes = m_mesh->m_cad->GetNumVerts();
77 
79  m_thickness.DefineFunction("x y z", m_config["blthick"].as<string>());
80 
81  ParseUtils::GenerateSeqVector(m_config["blcurves"].as<string>().c_str(),
82  m_blCurves);
83 
84  // linear mesh all curves
85  for (int i = 1; i <= m_mesh->m_cad->GetNumCurve(); i++)
86  {
87  if (m_mesh->m_verbose)
88  {
89  LibUtilities::PrintProgressbar(i, m_mesh->m_cad->GetNumCurve(),
90  "Curve progress");
91  }
92 
94  find(m_blCurves.begin(), m_blCurves.end(), i);
95 
96  if (f == m_blCurves.end())
97  {
98  m_curvemeshes[i] =
100  }
101  else
102  {
104  i, m_mesh, m_config["blthick"].as<string>());
105  }
106 
107  m_curvemeshes[i]->Mesh();
108  }
109 
110  ////////////////////////////////////////
111 
112  if (m_config["blcurves"].beenSet)
113  {
114  // we need to do the boundary layer generation in a face by face basis
115  MakeBLPrep();
116 
117  for (int i = 1; i <= m_mesh->m_cad->GetNumSurf(); i++)
118  {
119  MakeBL(i);
120  }
121  }
122 
123  if (m_mesh->m_verbose)
124  {
125  cout << endl << "\tFace meshing:" << endl << endl;
126  }
127 
128  // linear mesh all surfaces
129  for (int i = 1; i <= m_mesh->m_cad->GetNumSurf(); i++)
130  {
131  if (m_mesh->m_verbose)
132  {
133  LibUtilities::PrintProgressbar(i, m_mesh->m_cad->GetNumSurf(),
134  "Face progress");
135  }
136 
137  m_facemeshes[i] =
139  m_curvemeshes, 99+i);
140  m_facemeshes[i]->Mesh();
141  }
142 
143  ////////////////////////////////////
144 
146  for (it = m_mesh->m_edgeSet.begin(); it != m_mesh->m_edgeSet.end(); it++)
147  {
148  vector<NodeSharedPtr> ns;
149  ns.push_back((*it)->m_n1);
150  ns.push_back((*it)->m_n2);
151 
152  // for each iterator create a LibUtilities::eSegement
153  // push segment into m_mesh->m_element[1]
154  // tag for the elements shoudl be the CAD number of the curves
155 
156  ElmtConfig conf(LibUtilities::eSegment, 1, false, false);
157 
158  vector<int> tags;
159  tags.push_back((*it)->m_parentCAD->GetId());
160 
162  LibUtilities::eSegment, conf, ns, tags);
163 
164  m_mesh->m_element[1].push_back(E2);
165  }
166 
167  ProcessVertices();
168  ProcessEdges();
169  ProcessFaces();
170  ProcessElements();
172 
173  Report();
174 }
175 
177 {
178  if (m_mesh->m_verbose)
179  {
180  cout << endl << "\tBoundary layer meshing:" << endl << endl;
181  }
182 
183  // identify the nodes which will become the boundary layer.
184 
185  for (vector<unsigned>::iterator it = m_blCurves.begin();
186  it != m_blCurves.end(); ++it)
187  {
188  vector<EdgeSharedPtr> localedges = m_curvemeshes[*it]->GetMeshEdges();
189  for (int i = 0; i < localedges.size(); i++)
190  {
191  m_nodesToEdge[localedges[i]->m_n1].push_back(localedges[i]);
192  m_nodesToEdge[localedges[i]->m_n2].push_back(localedges[i]);
193  }
194  }
195 }
196 
197 void Generator2D::MakeBL(int faceid)
198 {
199  map<int, Array<OneD, NekDouble> > edgeNormals;
200 
201  int eid = 0;
202 
203  for (vector<unsigned>::iterator it = m_blCurves.begin();
204  it != m_blCurves.end(); ++it)
205  {
207  m_mesh->m_cad->GetCurve(*it)->GetOrienationWRT(faceid);
208 
209  vector<EdgeSharedPtr> es = m_curvemeshes[*it]->GetMeshEdges();
210 
211  // on each !!!EDGE!!! calculate a normal
212  // always to the left unless edgeo is 1
213  // normal must be done in the parametric space (and then projected back)
214  // because of face orientation
215  for (int j = 0; j < es.size(); j++)
216  {
217  es[j]->m_id = eid++;
218  Array<OneD, NekDouble> p1, p2;
219  p1 = es[j]->m_n1->GetCADSurfInfo(faceid);
220  p2 = es[j]->m_n2->GetCADSurfInfo(faceid);
221  if (edgeo == CADOrientation::eBackwards)
222  {
223  swap(p1, p2);
224  }
226  n[0] = p1[1] - p2[1];
227  n[1] = p2[0] - p1[0];
228  NekDouble mag = sqrt(n[0] * n[0] + n[1] * n[1]);
229  n[0] /= mag;
230  n[1] /= mag;
231 
232  Array<OneD, NekDouble> np = es[j]->m_n1->GetCADSurfInfo(faceid);
233  np[0] += n[0];
234  np[1] += n[1];
235 
236  Array<OneD, NekDouble> loc = es[j]->m_n1->GetLoc();
237  Array<OneD, NekDouble> locp = m_mesh->m_cad->GetSurf(faceid)->P(np);
238 
239  n[0] = locp[0] - loc[0];
240  n[1] = locp[1] - loc[1];
241  mag = sqrt(n[0] * n[0] + n[1] * n[1]);
242  n[0] /= mag;
243  n[1] /= mag;
244 
245  edgeNormals[es[j]->m_id] = n;
246  }
247  }
248 
249  map<NodeSharedPtr, NodeSharedPtr> nodeNormals;
250  map<NodeSharedPtr, vector<EdgeSharedPtr> >::iterator it;
251  for (it = m_nodesToEdge.begin(); it != m_nodesToEdge.end(); it++)
252  {
254  ASSERTL0(it->second.size() == 2,
255  "wierdness, most likely bl_surfs are incorrect");
256  Array<OneD, NekDouble> n1 = edgeNormals[it->second[0]->m_id];
257  Array<OneD, NekDouble> n2 = edgeNormals[it->second[1]->m_id];
258 
259  n[0] = (n1[0] + n2[0]) / 2.0;
260  n[1] = (n1[1] + n2[1]) / 2.0;
261  NekDouble mag = sqrt(n[0] * n[0] + n[1] * n[1]);
262  n[0] /= mag;
263  n[1] /= mag;
264 
265  NekDouble t = m_thickness.Evaluate(m_thickness_ID, it->first->m_x,
266  it->first->m_y, 0.0, 0.0);
267 
268  n[0] = n[0] * t + it->first->m_x;
269  n[1] = n[1] * t + it->first->m_y;
270  n[2] = 0.0;
271 
272  NodeSharedPtr nn = boost::shared_ptr<Node>(
273  new Node(m_mesh->m_numNodes++, n[0], n[1], 0.0));
274  CADSurfSharedPtr s = m_mesh->m_cad->GetSurf(faceid);
275  Array<OneD, NekDouble> uv = s->locuv(n);
276  nn->SetCADSurf(faceid, s, uv);
277  nodeNormals[it->first] = nn;
278  }
279 
280  for (vector<unsigned>::iterator it = m_blCurves.begin();
281  it != m_blCurves.end(); ++it)
282  {
284  m_mesh->m_cad->GetCurve(*it)->GetOrienationWRT(faceid);
285 
286  vector<NodeSharedPtr> ns = m_curvemeshes[*it]->GetMeshPoints();
287  vector<NodeSharedPtr> newNs;
288  for (int i = 0; i < ns.size(); i++)
289  {
290  newNs.push_back(nodeNormals[ns[i]]);
291  }
292  m_curvemeshes[*it] =
294 
295  if (edgeo == CADOrientation::eBackwards)
296  {
297  reverse(ns.begin(), ns.end());
298  }
299  for (int i = 0; i < ns.size() - 1; ++i)
300  {
301  vector<NodeSharedPtr> qns;
302 
303  qns.push_back(ns[i]);
304  qns.push_back(ns[i + 1]);
305  qns.push_back(nodeNormals[ns[i + 1]]);
306  qns.push_back(nodeNormals[ns[i]]);
307 
308  ElmtConfig conf(LibUtilities::eQuadrilateral, 1, false, false);
309 
310  vector<int> tags;
311  tags.push_back(101);
312 
314  LibUtilities::eQuadrilateral, conf, qns, tags);
315 
316  E->m_parentCAD = m_mesh->m_cad->GetSurf(faceid);
317 
318  for (int j = 0; j < E->GetEdgeCount(); ++j)
319  {
320  pair<EdgeSet::iterator, bool> testIns;
321  EdgeSharedPtr ed = E->GetEdge(j);
322  // look for edge in m_mesh edgeset from curves
323  EdgeSet::iterator s = m_mesh->m_edgeSet.find(ed);
324  if (!(s == m_mesh->m_edgeSet.end()))
325  {
326  ed = *s;
327  E->SetEdge(j, *s);
328  }
329  }
330  m_mesh->m_element[2].push_back(E);
331  }
332  }
333 }
334 
336 {
337  if (m_mesh->m_verbose)
338  {
339  int ns = m_mesh->m_vertexSet.size();
340  int es = m_mesh->m_edgeSet.size();
341  int ts = m_mesh->m_element[2].size();
342  int ep = ns - es + ts;
343  cout << endl << "\tSurface mesh statistics" << endl;
344  cout << "\t\tNodes: " << ns << endl;
345  cout << "\t\tEdges: " << es << endl;
346  cout << "\t\tTriangles " << ts << endl;
347  cout << "\t\tEuler-PoincarĂ© characteristic: " << ep << endl;
348  }
349 }
350 }
351 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
Basic information about an element.
Definition: ElementConfig.h:50
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
int PrintProgressbar(const int position, const int goal, const string message, int lastprogress=-1)
Prints a progressbar.
Definition: Progressbar.hpp:69
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
std::vector< unsigned int > m_blCurves
Definition: 2DGenerator.h:80
std::map< int, FaceMeshSharedPtr > m_facemeshes
map of individual surface meshes from parametric surfaces
Definition: 2DGenerator.h:76
NekDouble Evaluate(const int AnalyticExpression_id)
Evaluation method for expressions depending on parameters only.
STL namespace.
pair< ModuleType, string > ModuleKey
ElementFactory & GetElementFactory()
Definition: Element.cpp:47
static bool GenerateSeqVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:79
LibUtilities::AnalyticExpressionEvaluator m_thickness
Definition: 2DGenerator.h:81
virtual NEKMESHUTILS_EXPORT void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
virtual NEKMESHUTILS_EXPORT void ProcessElements()
Generate element IDs.
Represents a command-line configuration option.
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
double NekDouble
std::map< std::string, ConfigOption > m_config
List of configuration values.
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
boost::shared_ptr< CADSurf > CADSurfSharedPtr
Definition: CADSurf.h:172
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
int DefineFunction(const std::string &vlist, const std::string &function)
This function allows one to define a function to evaluate. The first argument (vlist) is a list of va...
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:147
Abstract base class for processing modules.
virtual NEKMESHUTILS_EXPORT void ProcessVertices()
Extract element vertices.
virtual NEKMESHUTILS_EXPORT void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:316
boost::shared_ptr< Element > ElementSharedPtr
Definition: Edge.h:49
std::map< NodeSharedPtr, std::vector< EdgeSharedPtr > > m_nodesToEdge
Definition: 2DGenerator.h:83
std::pair< ModuleType, std::string > ModuleKey
std::map< int, CurveMeshSharedPtr > m_curvemeshes
map of individual curve meshes of the curves in the domain
Definition: 2DGenerator.h:78
virtual NEKMESHUTILS_EXPORT void ProcessComposites()
Generate composites.
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215