Nektar++
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Nektar::SpatialDomains::CADSystem Class Referenceabstract

Base class for CAD interface system. More...

#include <CADSystem.h>

Inheritance diagram for Nektar::SpatialDomains::CADSystem:
[legend]

Public Member Functions

 CADSystem (std::string name, std::string engine)
 Default constructor.
 
virtual ~CADSystem ()
 
std::string GetName ()
 Return the name of the CAD file.
 
void Set2D ()
 Set the CAD engine up to handle 2D geometries explicitly.
 
bool Is2D ()
 Returns whether the CAD engine is set in 2D mode.
 
const std::string & GetConfig (const std::string &key) const
 Gets a configuration option.
 
void SetConfig (const std::string &key, const std::string &value)
 Sets a configuration option key to value.
 
virtual bool LoadCAD ()=0
 Initialises CAD and makes surface, curve and vertex maps.
 
virtual std::array< NekDouble, 6 > GetBoundingBox ()=0
 Returns bounding box of the domain.
 
int GetNumSurf ()
 Get the number of surfaces.
 
int GetNumCurve ()
 Get the number of curves.
 
CADCurveSharedPtr GetCurve (int i)
 Gets a curve from the map.
 
CADSurfSharedPtr GetSurf (int i)
 Gets a surface from the map.
 
CADVertSharedPtr GetVert (int i)
 Gets a vert from the map.
 
std::map< int, CADVertSharedPtr > GetVerts ()
 Gets map of all vertices.
 
int GetNumVerts () const
 Gets number of vertices.
 
std::vector< std::array< NekDouble, 3 > > GetVoidPoints ()
 Gets void points for tetrahedral meshing.
 
void SetVoidPoints (const std::vector< std::array< NekDouble, 3 > > &voidPts)
 Sets void points for tetrahedral meshing.
 
std::array< NekDouble, 3 > GetPeriodicTranslationVector (int first, int second)
 Return the vector of translation from one curve to another to allow for periodic mesh generation in 2D.
 
std::string GetEngine () const
 Return the name of the CAD system engine (e.g. OCE).
 
void SetLogger (Logger &log)
 
void CheckClosed ()
 Fail unless every curve is bounded by exactly two surfaces.
 

Protected Member Functions

void Report ()
 Reports basic properties to screen.
 

Protected Attributes

std::string m_name
 Name of CAD file.
 
std::string m_engine
 Name of CAD engine.
 
std::map< int, CADCurveSharedPtr > m_curves
 Map of curves.
 
std::map< int, CADSurfSharedPtr > m_surfs
 Map of surfaces.
 
std::map< int, CADVertSharedPtr > m_verts
 Map of vertices.
 
bool m_2d = false
 2D cad flag
 
std::map< std::string, std::string > m_config
 Configuration options which might be used per-engine, serialised in strings.
 
std::vector< std::array< NekDouble, 3 > > m_voidPoints
 Points contained within volume voids for tetrahedralisation.
 
Logger m_log
 Logger object.
 

Friends

class MemoryManager< CADSystem >
 

Detailed Description

Base class for CAD interface system.

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

Definition at line 71 of file CADSystem.h.

Constructor & Destructor Documentation

◆ CADSystem()

Nektar::SpatialDomains::CADSystem::CADSystem ( std::string  name,
std::string  engine 
)
inline

Default constructor.

Definition at line 79 of file CADSystem.h.

80 : m_name(name), m_engine(engine)
81 {
82 }
std::string m_engine
Name of CAD engine.
Definition CADSystem.h:319
std::string m_name
Name of CAD file.
Definition CADSystem.h:317

◆ ~CADSystem()

virtual Nektar::SpatialDomains::CADSystem::~CADSystem ( )
inlinevirtual

Definition at line 84 of file CADSystem.h.

85 {
86 }

Member Function Documentation

◆ CheckClosed()

void Nektar::SpatialDomains::CADSystem::CheckClosed ( )
inline

Fail unless every curve is bounded by exactly two surfaces.

Anything else is not a closed manifold solid and the surface mesher has no closed boundary to work from. This is the condition the sewing in the OpenCASCADE engine exists to establish, so when it fails the sewing tolerance is the first thing to look at: a curve bounded by one surface is a seam that did not close, and one bounded by three or more is a genuine non-manifold join in the model.

Definition at line 265 of file CADSystem.h.

266 {
267 std::stringstream ss;
268 int nBad = 0;
269
270 const int maxReported = 10;
271
272 for (auto &[id, curve] : m_curves)
273 {
274 size_t nAdj = curve->GetAdjSurf().size();
275 if (nAdj == 2)
276 {
277 continue;
278 }
279
280 // Report where, because a curve ID on its own cannot be looked up
281 // in a CAD package, and which surfaces, because that is what
282 // names the feature.
283 if (++nBad <= maxReported)
284 {
285 auto mm = curve->GetMinMax();
286 ss << std::endl
287 << " curve " << id << ", (" << mm[0] << ", " << mm[1]
288 << ", " << mm[2] << ") -> (" << mm[3] << ", " << mm[4]
289 << ", " << mm[5] << "), bounded by " << nAdj << " surface"
290 << (nAdj == 1 ? "" : "s");
291
292 for (auto &adj : curve->GetAdjSurf())
293 {
294 ss << " " << adj.first.lock()->GetId();
295 }
296 }
297 }
298
299 if (nBad > maxReported)
300 {
301 ss << std::endl << " ... and " << nBad - maxReported << " more.";
302 }
303
304 if (nBad > 0)
305 {
306 m_log(FATAL) << "the CAD model is not a closed solid: " << nBad
307 << " of its " << m_curves.size()
308 << " curves are not bounded by exactly two surfaces, "
309 "so the surface mesher has no closed boundary to "
310 "work from."
311 << ss.str() << std::endl;
312 }
313 }
Logger m_log
Logger object.
Definition CADSystem.h:334
std::map< int, CADCurveSharedPtr > m_curves
Map of curves.
Definition CADSystem.h:321
@ FATAL
Fatal errors that trigger exceptions.
Definition Log.hpp:65

References Nektar::FATAL, m_curves, and m_log.

Referenced by Nektar::SpatialDomains::CADSystemOCE::LoadCAD().

◆ GetBoundingBox()

virtual std::array< NekDouble, 6 > Nektar::SpatialDomains::CADSystem::GetBoundingBox ( )
pure virtual

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.

Implemented in Nektar::SpatialDomains::CADSystemOCE.

Referenced by Report().

◆ GetConfig()

const std::string & Nektar::SpatialDomains::CADSystem::GetConfig ( const std::string &  key) const
inline

Gets a configuration option.

Parameters
keyConfiguration key.
Returns
The configuration value.

Definition at line 119 of file CADSystem.h.

120 {
121 auto it = m_config.find(key);
122 return it->second;
123 }
std::map< std::string, std::string > m_config
Configuration options which might be used per-engine, serialised in strings.
Definition CADSystem.h:330

References m_config.

◆ GetCurve()

CADCurveSharedPtr Nektar::SpatialDomains::CADSystem::GetCurve ( int  i)
inline

Gets a curve from the map.

Definition at line 172 of file CADSystem.h.

173 {
174 auto search = m_curves.find(i);
175 ASSERTL1(search != m_curves.end(), "curve does not exist");
176
177 return search->second;
178 }
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....

References ASSERTL1, and m_curves.

Referenced by Nektar::SpatialDomains::CADSystemOCE::GetBoundingBox(), and GetPeriodicTranslationVector().

◆ GetEngine()

std::string Nektar::SpatialDomains::CADSystem::GetEngine ( ) const
inline

Return the name of the CAD system engine (e.g. OCE).

Definition at line 244 of file CADSystem.h.

245 {
246 return m_engine;
247 }

References m_engine.

◆ GetName()

std::string Nektar::SpatialDomains::CADSystem::GetName ( )
inline

Return the name of the CAD file.

Definition at line 91 of file CADSystem.h.

92 {
93 return m_name;
94 }

References m_name.

◆ GetNumCurve()

int Nektar::SpatialDomains::CADSystem::GetNumCurve ( )
inline

Get the number of curves.

Definition at line 164 of file CADSystem.h.

165 {
166 return m_curves.size();
167 }

References m_curves.

◆ GetNumSurf()

int Nektar::SpatialDomains::CADSystem::GetNumSurf ( )
inline

Get the number of surfaces.

Definition at line 156 of file CADSystem.h.

157 {
158 return m_surfs.size();
159 }
std::map< int, CADSurfSharedPtr > m_surfs
Map of surfaces.
Definition CADSystem.h:323

References m_surfs.

Referenced by GetPeriodicTranslationVector().

◆ GetNumVerts()

int Nektar::SpatialDomains::CADSystem::GetNumVerts ( ) const
inline

Gets number of vertices.

Definition at line 213 of file CADSystem.h.

214 {
215 return m_verts.size();
216 }
std::map< int, CADVertSharedPtr > m_verts
Map of vertices.
Definition CADSystem.h:325

References m_verts.

◆ GetPeriodicTranslationVector()

std::array< NekDouble, 3 > CADSystem::GetPeriodicTranslationVector ( int  first,
int  second 
)

Return the vector of translation from one curve to another to allow for periodic mesh generation in 2D.

Definition at line 65 of file CADSystem.cpp.

67{
68 if (GetNumSurf() != 1)
69 {
70 m_log(FATAL) << "Periodic translation does not yet work "
71 << "for multiple surfaces." << endl;
72 }
73
74 CADCurveSharedPtr c1 = GetCurve(first);
75 CADCurveSharedPtr c2 = GetCurve(second);
76
77 NekDouble tst = c1->GetTotLength() - c2->GetTotLength();
78
79 if (fabs(tst) > 1e-6)
80 {
81 m_log(FATAL) << "Periodic curves are not of the same length" << endl;
82 }
83
84 vector<CADVertSharedPtr> v1 = c1->GetVertex();
85 auto p1 = v1[0]->GetLoc();
86
87 std::array<NekDouble, 3> p2;
88 vector<CADVertSharedPtr> v2 = c2->GetVertex();
89 if (c1->GetOrienationWRT(1) == c2->GetOrienationWRT(1))
90 {
91 p2 = v2[1]->GetLoc();
92 }
93 else
94 {
95 p2 = v2[0]->GetLoc();
96 }
97
98 return {p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]};
99}
CADCurveSharedPtr GetCurve(int i)
Gets a curve from the map.
Definition CADSystem.h:172
int GetNumSurf()
Get the number of surfaces.
Definition CADSystem.h:156
std::shared_ptr< CADCurve > CADCurveSharedPtr
Definition CADCurve.h:247

References Nektar::FATAL, GetCurve(), GetNumSurf(), and m_log.

◆ GetSurf()

CADSurfSharedPtr Nektar::SpatialDomains::CADSystem::GetSurf ( int  i)
inline

Gets a surface from the map.

Definition at line 183 of file CADSystem.h.

184 {
185 auto search = m_surfs.find(i);
186 ASSERTL1(search != m_surfs.end(), "surface does not exist");
187
188 return search->second;
189 }

References ASSERTL1, and m_surfs.

◆ GetVert()

CADVertSharedPtr Nektar::SpatialDomains::CADSystem::GetVert ( int  i)
inline

Gets a vert from the map.

Definition at line 194 of file CADSystem.h.

195 {
196 auto search = m_verts.find(i);
197 ASSERTL1(search != m_verts.end(), "vert does not exist");
198
199 return search->second;
200 }

References ASSERTL1, and m_verts.

◆ GetVerts()

std::map< int, CADVertSharedPtr > Nektar::SpatialDomains::CADSystem::GetVerts ( )
inline

Gets map of all vertices.

Definition at line 205 of file CADSystem.h.

206 {
207 return m_verts;
208 }

References m_verts.

◆ GetVoidPoints()

std::vector< std::array< NekDouble, 3 > > Nektar::SpatialDomains::CADSystem::GetVoidPoints ( )
inline

Gets void points for tetrahedral meshing.

Definition at line 221 of file CADSystem.h.

222 {
223 return m_voidPoints;
224 }
std::vector< std::array< NekDouble, 3 > > m_voidPoints
Points contained within volume voids for tetrahedralisation.
Definition CADSystem.h:332

References m_voidPoints.

◆ Is2D()

bool Nektar::SpatialDomains::CADSystem::Is2D ( )
inline

Returns whether the CAD engine is set in 2D mode.

Definition at line 107 of file CADSystem.h.

108 {
109 return m_2d;
110 }

References m_2d.

◆ LoadCAD()

virtual bool Nektar::SpatialDomains::CADSystem::LoadCAD ( )
pure virtual

Initialises CAD and makes surface, curve and vertex maps.

Returns
true if completed successfully

Implemented in Nektar::SpatialDomains::CADSystemOCE.

◆ Report()

void Nektar::SpatialDomains::CADSystem::Report ( )
inlineprotected

Reports basic properties to screen.

Definition at line 339 of file CADSystem.h.

340 {
341 m_log(VERBOSE) << "Using CAD engine: '" << m_engine << "'" << std::endl;
342 m_log(VERBOSE) << " - CAD has: " << m_verts.size() << " verts."
343 << std::endl;
344 m_log(VERBOSE) << " - CAD has: " << m_curves.size() << " curves."
345 << std::endl;
346 m_log(VERBOSE) << " - CAD has: " << m_surfs.size() << " surfaces."
347 << std::endl;
348
349 // The extent is in mesh units, and is the quickest way to see that a
350 // model has come in at the wrong scale: it is the same number the
351 // user sizes MinDelta and MaxDelta against, so if it does not look
352 // like the part they drew, nothing downstream will either.
353 auto bb = GetBoundingBox();
354 m_log(VERBOSE) << " - CAD extent: " << bb[1] - bb[0] << " x "
355 << bb[3] - bb[2] << " x " << bb[5] - bb[4]
356 << " (mesh units)" << std::endl;
357 }
virtual std::array< NekDouble, 6 > GetBoundingBox()=0
Returns bounding box of the domain.
@ VERBOSE
Verbose output.
Definition Log.hpp:68

References GetBoundingBox(), m_curves, m_engine, m_log, m_surfs, m_verts, and Nektar::VERBOSE.

Referenced by Nektar::SpatialDomains::CADSystemOCE::LoadCAD().

◆ Set2D()

void Nektar::SpatialDomains::CADSystem::Set2D ( )
inline

Set the CAD engine up to handle 2D geometries explicitly.

Definition at line 99 of file CADSystem.h.

100 {
101 m_2d = true;
102 }

References m_2d.

◆ SetConfig()

void Nektar::SpatialDomains::CADSystem::SetConfig ( const std::string &  key,
const std::string &  value 
)
inline

Sets a configuration option key to value.

Parameters
keyConfiguration key.
valueThe configuration value.

Definition at line 131 of file CADSystem.h.

132 {
133 m_config[key] = value;
134 }

References m_config.

◆ SetLogger()

void Nektar::SpatialDomains::CADSystem::SetLogger ( Logger &  log)
inline

Definition at line 249 of file CADSystem.h.

250 {
251 m_log = log;
252 m_log.SetPrefix("CADSystem");
253 }
void SetPrefix(const std::string &prefix)
Sets the prefix for this Logger that is automatically preprended to all messages.
Definition Log.hpp:425
scalarT< T > log(scalarT< T > in)
Definition scalar.hpp:309

References tinysimd::log(), m_log, and Nektar::Logger::SetPrefix().

◆ SetVoidPoints()

void Nektar::SpatialDomains::CADSystem::SetVoidPoints ( const std::vector< std::array< NekDouble, 3 > > &  voidPts)
inline

Sets void points for tetrahedral meshing.

Definition at line 229 of file CADSystem.h.

230 {
231 m_voidPoints = voidPts;
232 }

References m_voidPoints.

Friends And Related Symbol Documentation

◆ MemoryManager< CADSystem >

friend class MemoryManager< CADSystem >
friend

Definition at line 364 of file CADSystem.h.

Member Data Documentation

◆ m_2d

bool Nektar::SpatialDomains::CADSystem::m_2d = false
protected

◆ m_config

std::map<std::string, std::string> Nektar::SpatialDomains::CADSystem::m_config
protected

Configuration options which might be used per-engine, serialised in strings.

Definition at line 330 of file CADSystem.h.

Referenced by Nektar::SpatialDomains::CADSystemOCE::BuildNACA(), GetConfig(), Nektar::SpatialDomains::CADSystemOCE::LoadCAD(), and SetConfig().

◆ m_curves

std::map<int, CADCurveSharedPtr> Nektar::SpatialDomains::CADSystem::m_curves
protected

◆ m_engine

std::string Nektar::SpatialDomains::CADSystem::m_engine
protected

Name of CAD engine.

Definition at line 319 of file CADSystem.h.

Referenced by GetEngine(), and Report().

◆ m_log

Logger Nektar::SpatialDomains::CADSystem::m_log
protected

◆ m_name

std::string Nektar::SpatialDomains::CADSystem::m_name
protected

Name of CAD file.

Definition at line 317 of file CADSystem.h.

Referenced by GetName(), and Nektar::SpatialDomains::CADSystemOCE::LoadCAD().

◆ m_surfs

std::map<int, CADSurfSharedPtr> Nektar::SpatialDomains::CADSystem::m_surfs
protected

◆ m_verts

std::map<int, CADVertSharedPtr> Nektar::SpatialDomains::CADSystem::m_verts
protected

◆ m_voidPoints

std::vector<std::array<NekDouble, 3> > Nektar::SpatialDomains::CADSystem::m_voidPoints
protected

Points contained within volume voids for tetrahedralisation.

Definition at line 332 of file CADSystem.h.

Referenced by GetVoidPoints(), and SetVoidPoints().