Nektar++
ProcessInsertSurface.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessInsertSurface.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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Calculate Jacobians of elements.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <boost/geometry.hpp>
36 #include <boost/geometry/geometries/point.hpp>
37 #include <boost/geometry/geometries/box.hpp>
38 #include <boost/geometry/index/rtree.hpp>
39 
41 #include "ProcessInsertSurface.h"
42 
43 namespace bg = boost::geometry;
44 namespace bgi = boost::geometry::index;
45 
46 using namespace std;
47 using namespace Nektar::NekMeshUtils;
48 
49 namespace Nektar
50 {
51 namespace Utilities
52 {
53 
54 ModuleKey ProcessInsertSurface::className = GetModuleFactory().RegisterCreatorFunction(
55  ModuleKey(eProcessModule, "insertsurface"),
56  ProcessInsertSurface::create,
57  "Insert high-order surface mesh into current working mesh.");
58 
59 ProcessInsertSurface::ProcessInsertSurface(MeshSharedPtr m) : ProcessModule(m)
60 {
61  m_config["mesh"] =
62  ConfigOption(false, "", "Mesh to be inserted.");
63  m_config["nonconforming"] =
64  ConfigOption(false,"", "Relax tests for nonconforming boundries");
65 }
66 
68 {
69 }
70 
72 {
73  typedef bg::model::point<NekDouble, 3, bg::cs::cartesian> Point;
74  typedef pair<Point, unsigned int> PointI;
75 
76  if (m_mesh->m_verbose)
77  {
78  cout << "ProcessInsertSurface: Inserting mesh... " << endl;
79  }
80 
81  string file = m_config["mesh"].as<string>();
82  bool nonconform = m_config["nonconforming"].beenSet;
83 
84  if (m_mesh->m_verbose)
85  {
86  cout << "inserting surface from " << file << endl;
87  }
88  MeshSharedPtr inMsh = std::shared_ptr<Mesh>(new Mesh());
89  inMsh->m_verbose = m_mesh->m_verbose;
91  ModuleKey(eInputModule, "xml"), inMsh);
92  mod->RegisterConfig("infile", file);
93  mod->Process();
94 
95  //build ann tree of surface verticies from inMsh
96  //match surface vertices in ccm mesh to inMsh and copy information
97 
98  //tolerance of matching vertices
99  NekDouble tol = 1e-5;
100 
101  NodeSet surfaceNodes;
102  for(int i = 0; i < inMsh->m_element[2].size(); i++)
103  {
104  vector<NodeSharedPtr> ns = inMsh->m_element[2][i]->GetVertexList();
105  for(int j = 0; j < ns.size(); j++)
106  {
107  surfaceNodes.insert(ns[j]);
108  }
109  }
110 
111  vector<NodeSharedPtr> inMshnodeList(surfaceNodes.begin(), surfaceNodes.end());
112 
113  vector<PointI> dataPts;
114  for(int i = 0; i < inMshnodeList.size(); i++)
115  {
116  dataPts.push_back(make_pair(Point( inMshnodeList[i]->m_x,
117  inMshnodeList[i]->m_y,
118  inMshnodeList[i]->m_z), i));
119  }
120 
121  //Build tree
122  bgi::rtree<PointI, bgi::rstar<16> > rtree;
123  rtree.insert(dataPts.begin(), dataPts.end());
124 
125  surfaceNodes.clear();
126  for(int i = 0; i < m_mesh->m_element[2].size(); i++)
127  {
128  vector<NodeSharedPtr> ns = m_mesh->m_element[2][i]->GetVertexList();
129  for(int j = 0; j < ns.size(); j++)
130  {
131  surfaceNodes.insert(ns[j]);
132  }
133  }
134 
135  if(!nonconform)
136  {
137  ASSERTL0(surfaceNodes.size() == inMshnodeList.size(),
138  "surface mesh node count mismatch, will not work");
139  }
140 
141  EdgeSet surfEdges;
142  for(int i = 0; i < m_mesh->m_element[2].size(); i++)
143  {
144  FaceSharedPtr f = m_mesh->m_element[2][i]->GetFaceLink();
145  vector<EdgeSharedPtr> es = f->m_edgeList;
146  for(int j = 0; j < es.size(); j++)
147  {
148  surfEdges.insert(es[j]);
149  }
150  }
151 
152  for(auto &it : surfEdges)
153  {
154  Point queryPt1(it->m_n1->m_x, it->m_n1->m_y, it->m_n1->m_z);
155  vector<PointI> result;
156  rtree.query(bgi::nearest(queryPt1, 1), std::back_inserter(result));
157 
158  NekDouble dist1 = bg::distance(result[0].first, queryPt1);
159  if(nonconform)
160  {
161  if(dist1 > tol)
162  {
163  continue;
164  }
165  }
166  else
167  {
168  ASSERTL0(dist1 < tol, "cannot locate point accurately enough");
169  }
170 
171  NodeSharedPtr inN1 = inMshnodeList[result[0].second];
172 
173  Point queryPt2(it->m_n2->m_x, it->m_n2->m_y, it->m_n2->m_z);
174  result.clear();
175  rtree.query(bgi::nearest(queryPt2, 1), std::back_inserter(result));
176 
177  NekDouble dist2 = bg::distance(result[0].first, queryPt2);
178  if(nonconform)
179  {
180  if(dist2 > tol)
181  {
182  continue;
183  }
184  }
185  else
186  {
187  ASSERTL0(dist2 < tol, "cannot locate point accurately enough");
188  }
189  NodeSharedPtr inN2 = inMshnodeList[result[0].second];
190 
191  EdgeSharedPtr tst = std::shared_ptr<Edge>(new Edge(inN1,inN2));
192 
193  auto f = inMsh->m_edgeSet.find(tst);
194 
195  ASSERTL0(f != inMsh->m_edgeSet.end(),"could not find edge in input");
196 
197  it->m_edgeNodes = (*f)->m_edgeNodes;
198  it->m_curveType = (*f)->m_curveType;
199 
200  if((*f)->m_n1->Distance(it->m_n1) > tol)
201  {
202  reverse(it->m_edgeNodes.begin(), it->m_edgeNodes.end());
203  }
204  }
205 }
206 }
207 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
Represents an edge which joins two points.
Definition: Edge.h:58
std::unordered_set< EdgeSharedPtr, EdgeHash > EdgeSet
Definition: Edge.h:159
std::shared_ptr< Module > ModuleSharedPtr
STL namespace.
virtual void Process()
Write mesh to output file.
std::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:156
std::shared_ptr< Node > NodeSharedPtr
Definition: CADVert.h:49
std::unordered_set< NodeSharedPtr, NodeHash > NodeSet
Definition: Node.h:447
std::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:155
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::pair< ModuleType, std::string > ModuleKey
A 0-dimensional vertex.
Definition: Point.h:48
Represents a command-line configuration option.
double NekDouble
std::map< std::string, ConfigOption > m_config
List of configuration values.
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()