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  if (m_mesh->m_verbose)
67  {
68  cout << endl << "2D meshing" << endl;
69  cout << endl << "\tCurve meshing:" << endl << endl;
70  }
71 
72  m_mesh->m_numNodes = m_mesh->m_cad->GetNumVerts();
73 
75  m_thickness.DefineFunction("x y z", m_config["blthick"].as<string>());
76 
77  ParseUtils::GenerateSeqVector(m_config["blcurves"].as<string>().c_str(),
78  m_blCurves);
79 
80  // linear mesh all curves
81  for (int i = 1; i <= m_mesh->m_cad->GetNumCurve(); i++)
82  {
83  if (m_mesh->m_verbose)
84  {
85  LibUtilities::PrintProgressbar(i, m_mesh->m_cad->GetNumCurve(),
86  "Curve progress");
87  }
88 
90  find(m_blCurves.begin(), m_blCurves.end(), i);
91 
92  if (f == m_blCurves.end())
93  {
94  m_curvemeshes[i] =
96  }
97  else
98  {
100  i, m_mesh, m_config["blthick"].as<string>());
101  }
102 
103  m_curvemeshes[i]->Mesh();
104  }
105 
106  ////////////////////////////////////////
107 
108  if (m_config["blcurves"].beenSet)
109  {
110  // we need to do the boundary layer generation in a face by face basis
111  MakeBLPrep();
112 
113  for (int i = 1; i <= m_mesh->m_cad->GetNumSurf(); i++)
114  {
115  MakeBL(i);
116  }
117  }
118 
119  if (m_mesh->m_verbose)
120  {
121  cout << endl << "\tFace meshing:" << endl << endl;
122  }
123 
124  // linear mesh all surfaces
125  for (int i = 1; i <= m_mesh->m_cad->GetNumSurf(); i++)
126  {
127  if (m_mesh->m_verbose)
128  {
129  LibUtilities::PrintProgressbar(i, m_mesh->m_cad->GetNumSurf(),
130  "Face progress");
131  }
132 
133  m_facemeshes[i] =
135  m_curvemeshes, 99+i);
136  m_facemeshes[i]->Mesh();
137  }
138 
139  ////////////////////////////////////
140 
142  for (it = m_mesh->m_edgeSet.begin(); it != m_mesh->m_edgeSet.end(); it++)
143  {
144  vector<NodeSharedPtr> ns;
145  ns.push_back((*it)->m_n1);
146  ns.push_back((*it)->m_n2);
147 
148  // for each iterator create a LibUtilities::eSegement
149  // push segment into m_mesh->m_element[1]
150  // tag for the elements shoudl be the CAD number of the curves
151 
152  ElmtConfig conf(LibUtilities::eSegment, 1, false, false);
153 
154  vector<int> tags;
155  tags.push_back((*it)->m_parentCAD->GetId());
156 
158  LibUtilities::eSegment, conf, ns, tags);
159 
160  m_mesh->m_element[1].push_back(E2);
161  }
162 
163  ProcessVertices();
164  ProcessEdges();
165  ProcessFaces();
166  ProcessElements();
168 
169  Report();
170 }
171 
173 {
174  if (m_mesh->m_verbose)
175  {
176  cout << endl << "\tBoundary layer meshing:" << endl << endl;
177  }
178 
179  // identify the nodes which will become the boundary layer.
180 
181  for (vector<unsigned>::iterator it = m_blCurves.begin();
182  it != m_blCurves.end(); ++it)
183  {
184  vector<EdgeSharedPtr> localedges = m_curvemeshes[*it]->GetMeshEdges();
185  for (int i = 0; i < localedges.size(); i++)
186  {
187  m_nodesToEdge[localedges[i]->m_n1].push_back(localedges[i]);
188  m_nodesToEdge[localedges[i]->m_n2].push_back(localedges[i]);
189  }
190  }
191 }
192 
193 void Generator2D::MakeBL(int faceid)
194 {
195  map<int, Array<OneD, NekDouble> > edgeNormals;
196 
197  int eid = 0;
198 
199  for (vector<unsigned>::iterator it = m_blCurves.begin();
200  it != m_blCurves.end(); ++it)
201  {
203  m_mesh->m_cad->GetCurve(*it)->GetOrienationWRT(faceid);
204 
205  vector<EdgeSharedPtr> es = m_curvemeshes[*it]->GetMeshEdges();
206 
207  // on each !!!EDGE!!! calculate a normal
208  // always to the left unless edgeo is 1
209  // normal must be done in the parametric space (and then projected back)
210  // because of face orientation
211  for (int j = 0; j < es.size(); j++)
212  {
213  es[j]->m_id = eid++;
214  Array<OneD, NekDouble> p1, p2;
215  p1 = es[j]->m_n1->GetCADSurfInfo(faceid);
216  p2 = es[j]->m_n2->GetCADSurfInfo(faceid);
217  if (edgeo == CADOrientation::eBackwards)
218  {
219  swap(p1, p2);
220  }
222  n[0] = p1[1] - p2[1];
223  n[1] = p2[0] - p1[0];
224  NekDouble mag = sqrt(n[0] * n[0] + n[1] * n[1]);
225  n[0] /= mag;
226  n[1] /= mag;
227 
228  Array<OneD, NekDouble> np = es[j]->m_n1->GetCADSurfInfo(faceid);
229  np[0] += n[0];
230  np[1] += n[1];
231 
232  Array<OneD, NekDouble> loc = es[j]->m_n1->GetLoc();
233  Array<OneD, NekDouble> locp = m_mesh->m_cad->GetSurf(faceid)->P(np);
234 
235  n[0] = locp[0] - loc[0];
236  n[1] = locp[1] - loc[1];
237  mag = sqrt(n[0] * n[0] + n[1] * n[1]);
238  n[0] /= mag;
239  n[1] /= mag;
240 
241  edgeNormals[es[j]->m_id] = n;
242  }
243  }
244 
245  map<NodeSharedPtr, NodeSharedPtr> nodeNormals;
246  map<NodeSharedPtr, vector<EdgeSharedPtr> >::iterator it;
247  for (it = m_nodesToEdge.begin(); it != m_nodesToEdge.end(); it++)
248  {
250  ASSERTL0(it->second.size() == 2,
251  "wierdness, most likely bl_surfs are incorrect");
252  Array<OneD, NekDouble> n1 = edgeNormals[it->second[0]->m_id];
253  Array<OneD, NekDouble> n2 = edgeNormals[it->second[1]->m_id];
254 
255  n[0] = (n1[0] + n2[0]) / 2.0;
256  n[1] = (n1[1] + n2[1]) / 2.0;
257  NekDouble mag = sqrt(n[0] * n[0] + n[1] * n[1]);
258  n[0] /= mag;
259  n[1] /= mag;
260 
261  NekDouble t = m_thickness.Evaluate(m_thickness_ID, it->first->m_x,
262  it->first->m_y, 0.0, 0.0);
263 
264  n[0] = n[0] * t + it->first->m_x;
265  n[1] = n[1] * t + it->first->m_y;
266  n[2] = 0.0;
267 
268  NodeSharedPtr nn = boost::shared_ptr<Node>(
269  new Node(m_mesh->m_numNodes++, n[0], n[1], 0.0));
270  CADSurfSharedPtr s = m_mesh->m_cad->GetSurf(faceid);
271  Array<OneD, NekDouble> uv = s->locuv(n);
272  nn->SetCADSurf(faceid, s, uv);
273  nodeNormals[it->first] = nn;
274  }
275 
276  for (vector<unsigned>::iterator it = m_blCurves.begin();
277  it != m_blCurves.end(); ++it)
278  {
280  m_mesh->m_cad->GetCurve(*it)->GetOrienationWRT(faceid);
281 
282  vector<NodeSharedPtr> ns = m_curvemeshes[*it]->GetMeshPoints();
283  vector<NodeSharedPtr> newNs;
284  for (int i = 0; i < ns.size(); i++)
285  {
286  newNs.push_back(nodeNormals[ns[i]]);
287  }
288  m_curvemeshes[*it] =
290 
291  if (edgeo == CADOrientation::eBackwards)
292  {
293  reverse(ns.begin(), ns.end());
294  }
295  for (int i = 0; i < ns.size() - 1; ++i)
296  {
297  vector<NodeSharedPtr> qns;
298 
299  qns.push_back(ns[i]);
300  qns.push_back(ns[i + 1]);
301  qns.push_back(nodeNormals[ns[i + 1]]);
302  qns.push_back(nodeNormals[ns[i]]);
303 
304  ElmtConfig conf(LibUtilities::eQuadrilateral, 1, false, false);
305 
306  vector<int> tags;
307  tags.push_back(101);
308 
310  LibUtilities::eQuadrilateral, conf, qns, tags);
311 
312  E->m_parentCAD = m_mesh->m_cad->GetSurf(faceid);
313 
314  for (int j = 0; j < E->GetEdgeCount(); ++j)
315  {
316  pair<EdgeSet::iterator, bool> testIns;
317  EdgeSharedPtr ed = E->GetEdge(j);
318  // look for edge in m_mesh edgeset from curves
319  EdgeSet::iterator s = m_mesh->m_edgeSet.find(ed);
320  if (!(s == m_mesh->m_edgeSet.end()))
321  {
322  ed = *s;
323  E->SetEdge(j, *s);
324  }
325  }
326  m_mesh->m_element[2].push_back(E);
327  }
328  }
329 }
330 
332 {
333  if (m_mesh->m_verbose)
334  {
335  int ns = m_mesh->m_vertexSet.size();
336  int es = m_mesh->m_edgeSet.size();
337  int ts = m_mesh->m_element[2].size();
338  int ep = ns - es + ts;
339  cout << endl << "\tSurface mesh statistics" << endl;
340  cout << "\t\tNodes: " << ns << endl;
341  cout << "\t\tEdges: " << es << endl;
342  cout << "\t\tTriangles " << ts << endl;
343  cout << "\t\tEuler-PoincarĂ© characteristic: " << ep << endl;
344  }
345 }
346 }
347 }
#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:135
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