Nektar++
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Nektar::LibUtilities::CADSystem Class Reference

Base class for CAD interface system. More...

#include <CADSystem.h>

Collaboration diagram for Nektar::LibUtilities::CADSystem:
Collaboration graph
[legend]

Public Member Functions

 CADSystem (const std::string &name)
 Default constructor. More...
 
std::string GetName ()
 Return the name of the CAD system. More...
 
bool LoadCAD ()
 Initialises CAD and makes surface and curve maps. More...
 
void Report ()
 Reports basic properties to screen. More...
 
Array< OneD, NekDoubleGetBoundingBox ()
 Returns bounding box of the domain. More...
 
int GetNumSurf ()
 Return number of surfaces. More...
 
int GetNumCurve ()
 Return number of curves. More...
 
const CADCurveSharedPtr GetCurve (int i)
 Gets curve type from map. More...
 
CADSurfSharedPtr GetSurf (int i)
 Gets suface from map. More...
 
int GetEPC ()
 Return Euler-Poincare number. More...
 

Private Member Functions

void AddCurve (int i, TopoDS_Shape in)
 Private function to add curve to CADSystem::m_curves. More...
 
void AddSurf (int i, TopoDS_Shape in, std::vector< std::vector< std::pair< int, int > > > ein)
 Private function to add surface to CADSystem::m_surfs. More...
 

Private Attributes

std::string m_name
 Name of cad file to be opened, including file extension. More...
 
int m_epc
 Euler-Poincare number of the CAD. More...
 
std::map< int, CADCurveSharedPtrm_curves
 map of curves More...
 
std::map< int, CADSurfSharedPtrm_surfs
 map of surfaces More...
 

Friends

class MemoryManager< CADSystem >
 

Detailed Description

Base class for CAD interface system.

A class which can load and interact with CAD for Nektar++ using OpenCascade. This class contains maps to subclasses surface and curves.

Definition at line 59 of file CADSystem.h.

Constructor & Destructor Documentation

Nektar::LibUtilities::CADSystem::CADSystem ( const std::string &  name)
inline

Default constructor.

Definition at line 67 of file CADSystem.h.

67  : m_name(name)
68  {
69  }
std::string m_name
Name of cad file to be opened, including file extension.
Definition: CADSystem.h:131

Member Function Documentation

void Nektar::LibUtilities::CADSystem::AddCurve ( int  i,
TopoDS_Shape  in 
)
private

Private function to add curve to CADSystem::m_curves.

Definition at line 261 of file CADSystem.cpp.

262 {
264  AllocateSharedPtr(i,in);
265  m_curves[i] = newCurve;
266 }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
boost::shared_ptr< CADCurve > CADCurveSharedPtr
Definition: CADCurve.h:92
std::map< int, CADCurveSharedPtr > m_curves
map of curves
Definition: CADSystem.h:135
void Nektar::LibUtilities::CADSystem::AddSurf ( int  i,
TopoDS_Shape  in,
std::vector< std::vector< std::pair< int, int > > >  ein 
)
private

Private function to add surface to CADSystem::m_surfs.

Definition at line 268 of file CADSystem.cpp.

270 {
272  AllocateSharedPtr(i,in,ein);
273  m_surfs[i] = newSurf;
274 }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
std::map< int, CADSurfSharedPtr > m_surfs
map of surfaces
Definition: CADSystem.h:137
boost::shared_ptr< CADSurf > CADSurfSharedPtr
Definition: CADSurf.h:109
Array< OneD, NekDouble > Nektar::LibUtilities::CADSystem::GetBoundingBox ( )

Returns bounding box of the domain.

Gets the bounding box of the domain by considering the start and end points of each curve in the geometry.

Returns
Array with 6 entries: xmin, xmax, ymin, ymax, zmin and zmax.

Definition at line 77 of file CADSystem.cpp.

78 {
79  Array<OneD, NekDouble> bound(6);
80  bound[0] = numeric_limits<double>::max(); //xmin
81  bound[1] = numeric_limits<double>::min(); //xmax
82  bound[2] = numeric_limits<double>::max(); //ymin
83  bound[3] = numeric_limits<double>::min(); //ymax
84  bound[4] = numeric_limits<double>::max(); //zmin
85  bound[5] = numeric_limits<double>::min(); //zmax
86 
87  for(int i = 1; i <= m_curves.size(); i++)
88  {
89  gp_Pnt start, end;
91  Array<OneD, NekDouble> ends = c->GetMinMax();
92 
93  bound[0] = min(bound[0], min(ends[0],ends[3]));
94  bound[1] = max(bound[1], max(ends[0],ends[3]));
95 
96  bound[2] = min(bound[2], min(ends[1],ends[4]));
97  bound[3] = max(bound[3], max(ends[1],ends[4]));
98 
99  bound[4] = min(bound[4], min(ends[2],ends[5]));
100  bound[5] = max(bound[5], max(ends[2],ends[5]));
101  }
102 
103  return bound;
104 }
boost::shared_ptr< CADCurve > CADCurveSharedPtr
Definition: CADCurve.h:92
const CADCurveSharedPtr GetCurve(int i)
Gets curve type from map.
Definition: CADSystem.h:95
std::map< int, CADCurveSharedPtr > m_curves
map of curves
Definition: CADSystem.h:135
const CADCurveSharedPtr Nektar::LibUtilities::CADSystem::GetCurve ( int  i)
inline

Gets curve type from map.

Definition at line 95 of file CADSystem.h.

References ASSERTL0, Nektar::iterator, and m_curves.

96  {
98  search = m_curves.find(i);
99  ASSERTL0(search != m_curves.end(), "curve does not exist");
100 
101  return search->second;
102  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< int, CADCurveSharedPtr > m_curves
map of curves
Definition: CADSystem.h:135
int Nektar::LibUtilities::CADSystem::GetEPC ( )
inline

Return Euler-Poincare number.

Definition at line 119 of file CADSystem.h.

References m_epc.

120  {
121  return m_epc;
122  }
int m_epc
Euler-Poincare number of the CAD.
Definition: CADSystem.h:133
string Nektar::LibUtilities::CADSystem::GetName ( )

Return the name of the CAD system.

Definition at line 53 of file CADSystem.cpp.

54 {
55  return m_name;
56 }
std::string m_name
Name of cad file to be opened, including file extension.
Definition: CADSystem.h:131
int Nektar::LibUtilities::CADSystem::GetNumCurve ( )
inline

Return number of curves.

Definition at line 87 of file CADSystem.h.

References m_curves.

88  {
89  return m_curves.size();
90  }
std::map< int, CADCurveSharedPtr > m_curves
map of curves
Definition: CADSystem.h:135
int Nektar::LibUtilities::CADSystem::GetNumSurf ( )
inline

Return number of surfaces.

Definition at line 79 of file CADSystem.h.

References m_surfs.

80  {
81  return m_surfs.size();
82  }
std::map< int, CADSurfSharedPtr > m_surfs
map of surfaces
Definition: CADSystem.h:137
CADSurfSharedPtr Nektar::LibUtilities::CADSystem::GetSurf ( int  i)
inline

Gets suface from map.

Definition at line 107 of file CADSystem.h.

References ASSERTL0, Nektar::iterator, and m_surfs.

108  {
110  search = m_surfs.find(i);
111  ASSERTL0(search != m_surfs.end(), "surface does not exist");
112 
113  return search->second;
114  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
std::map< int, CADSurfSharedPtr > m_surfs
map of surfaces
Definition: CADSystem.h:137
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
bool Nektar::LibUtilities::CADSystem::LoadCAD ( )

Initialises CAD and makes surface and curve maps.

Returns
true if completed successfully

Definition at line 111 of file CADSystem.cpp.

References ASSERTL0, and Nektar::iterator.

112 {
113  if (!boost::filesystem::exists(m_name.c_str()))
114  {
115  return false;
116  }
117 
118  string ext;
119  size_t pos = m_name.find(".");
120  ext = m_name.substr(pos);
121 
122  TopoDS_Shape shape;
123 
124  if (boost::iequals(ext,".STEP") || boost::iequals(ext,".STP"))
125  {
126  // Takes step file and makes OpenCascade shape
127  STEPControl_Reader reader;
128  reader = STEPControl_Reader();
129  reader.ReadFile(m_name.c_str());
130  reader.NbRootsForTransfer();
131  reader.TransferRoots();
132  shape = reader.OneShape();
133  if(shape.IsNull())
134  {
135  return false;
136  }
137  }
138  else if(boost::iequals(ext,".IGES") || boost::iequals(ext,".IGS"))
139  {
140  // Takes IGES file and makes OpenCascade shape
141  IGESControl_Reader reader;
142  reader = IGESControl_Reader();
143  reader.ReadFile(m_name.c_str());
144  reader.NbRootsForTransfer();
145  reader.TransferRoots();
146  shape = reader.OneShape();
147  if(shape.IsNull())
148  {
149  return false;
150  }
151  }
152  else
153  {
154  return false;
155  }
156 
157  // From OpenCascade maps calculate Euler-Poincare number.
158  TopTools_IndexedMapOfShape fc, vc, ec;
159  TopExp::MapShapes(shape, TopAbs_FACE, fc);
160  TopExp::MapShapes(shape, TopAbs_EDGE, ec);
161  TopExp::MapShapes(shape, TopAbs_VERTEX, vc);
162 
163  m_epc = vc.Extent() - ec.Extent() + fc.Extent();
164 
165  TopTools_IndexedMapOfShape mapOfFaces;
166  TopTools_IndexedMapOfShape mapOfEdges;
167  TopExp::MapShapes(shape, TopAbs_FACE, mapOfFaces);
168 
169  // For each face of the geometry, get the local edges which bound it. If
170  // they are valid (their type != 7), then add them to an edge map. This
171  // filters out the dummy edges which OCC uses.
172  for(int i = 1; i <= mapOfFaces.Extent(); i++)
173  {
174  TopoDS_Shape face= mapOfFaces.FindKey(i);
175 
176  TopTools_IndexedMapOfShape localEdges;
177  TopExp::MapShapes(face, TopAbs_EDGE, localEdges);
178 
179  for(int j = 1; j <= localEdges.Extent(); j++)
180  {
181  TopoDS_Shape edge = localEdges.FindKey(j);
182  BRepAdaptor_Curve curve = BRepAdaptor_Curve(TopoDS::Edge(edge));
183  if(curve.GetType() != 7)
184  {
185  if(!(mapOfEdges.Contains(edge)))
186  {
187  mapOfEdges.Add(edge);
188  }
189  }
190  }
191  }
192 
193  map<int, vector<int> > adjsurfmap;
194 
195  // Adds edges to our type and map
196  for(int i = 1; i <= mapOfEdges.Extent(); i++)
197  {
198  TopoDS_Shape edge = mapOfEdges.FindKey(i);
199  AddCurve(i, edge);
200  }
201 
202  // For each face, examine all the wires (i.e. bounding loops) and
203  // investigates the loop. Using this information, connectivity is determined
204  // and edges are associated with surfaces.
205  for(int i = 1; i <= mapOfFaces.Extent(); i++)
206  {
207  vector<vector<pair<int,int> > > edges;
208 
209  TopoDS_Shape face = mapOfFaces.FindKey(i);
210 
211  TopTools_IndexedMapOfShape mapOfWires;
212  TopExp::MapShapes(face, TopAbs_WIRE, mapOfWires);
213 
214  for(int j = 1; j <= mapOfWires.Extent(); j++)
215  {
216  vector<pair<int,int> > edgeloop;
217 
218  TopoDS_Shape wire = mapOfWires.FindKey(j);
219 
220  ShapeAnalysis_Wire wiretest(TopoDS::Wire(wire),
221  TopoDS::Face(face),
222  1E-6);
223 
224  BRepTools_WireExplorer exp;
225 
226  exp.Init(TopoDS::Wire(wire));
227 
228  while(exp.More())
229  {
230  TopoDS_Shape edge = exp.Current();
231 
232  if(mapOfEdges.Contains(edge))
233  {
234  pair<int,int> e;
235  e.first = mapOfEdges.FindIndex(edge);
236  adjsurfmap[e.first].push_back(i);
237  e.second = exp.Orientation();
238  edgeloop.push_back(e);
239  }
240 
241  exp.Next();
242  }
243 
244  edges.push_back(edgeloop);
245  }
246 
247  AddSurf(i, face, edges);
248  }
249 
250  // This checks that all edges are bound by two surfaces, sanity check.
251  for(map<int,vector<int> >::iterator it = adjsurfmap.begin();
252  it != adjsurfmap.end(); it++)
253  {
254  ASSERTL0(it->second.size() == 2, "no three curve surfaces");
255  m_curves[it->first]->SetAdjSurf(it->second);
256  }
257 
258  return true;
259 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
void AddCurve(int i, TopoDS_Shape in)
Private function to add curve to CADSystem::m_curves.
Definition: CADSystem.cpp:261
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< int, CADCurveSharedPtr > m_curves
map of curves
Definition: CADSystem.h:135
int m_epc
Euler-Poincare number of the CAD.
Definition: CADSystem.h:133
std::string m_name
Name of cad file to be opened, including file extension.
Definition: CADSystem.h:131
void AddSurf(int i, TopoDS_Shape in, std::vector< std::vector< std::pair< int, int > > > ein)
Private function to add surface to CADSystem::m_surfs.
Definition: CADSystem.cpp:268
void Nektar::LibUtilities::CADSystem::Report ( )

Reports basic properties to screen.

Definition at line 61 of file CADSystem.cpp.

62 {
63  cout << endl << "CAD report:" << endl;
64  cout << "\tCAD has: " << m_curves.size() << " curves." << endl;
65  cout << "\tCAD has: " << m_surfs.size() << " surfaces." << endl;
66  cout << "\tCAD Euler-PoincarĂ© characteristic: " << m_epc << endl;
67 }
std::map< int, CADSurfSharedPtr > m_surfs
map of surfaces
Definition: CADSystem.h:137
std::map< int, CADCurveSharedPtr > m_curves
map of curves
Definition: CADSystem.h:135
int m_epc
Euler-Poincare number of the CAD.
Definition: CADSystem.h:133

Friends And Related Function Documentation

friend class MemoryManager< CADSystem >
friend

Definition at line 62 of file CADSystem.h.

Member Data Documentation

std::map<int,CADCurveSharedPtr> Nektar::LibUtilities::CADSystem::m_curves
private

map of curves

Definition at line 135 of file CADSystem.h.

Referenced by GetCurve(), and GetNumCurve().

int Nektar::LibUtilities::CADSystem::m_epc
private

Euler-Poincare number of the CAD.

Definition at line 133 of file CADSystem.h.

Referenced by GetEPC().

std::string Nektar::LibUtilities::CADSystem::m_name
private

Name of cad file to be opened, including file extension.

Definition at line 131 of file CADSystem.h.

std::map<int,CADSurfSharedPtr> Nektar::LibUtilities::CADSystem::m_surfs
private

map of surfaces

Definition at line 137 of file CADSystem.h.

Referenced by GetNumSurf(), and GetSurf().