G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsBoxTopology.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <gsCore/gsExport.h>
18 
19 #include <gsCore/gsBoundary.h>
20 #include <gsMesh2/gsProperty.h>
21 
22 namespace gismo
23 {
24 
38 class GISMO_EXPORT gsBoxTopology
39 {
40 
41 public:
43  typedef memory::shared_ptr< gsBoxTopology > Ptr;
44  typedef memory::unique_ptr< gsBoxTopology > uPtr;
45 
46  typedef std::vector< patchSide > bContainer;
47  typedef bContainer::iterator biterator;
48  typedef bContainer::const_iterator const_biterator;
49 
50  typedef std::vector<boundaryInterface> ifContainer;
51  typedef ifContainer::iterator iiterator;
52  typedef ifContainer::const_iterator const_iiterator;
53 
54  typedef const boundaryInterface * InterfacePtr;
55  typedef patchSide * BoundaryPtr;
56 public:
57 
59  gsBoxTopology(short_t d = -1, index_t n = 0) : m_dim(d), nboxes(0)
60  {
61  addBox(n);
62  }
63 
64  gsBoxTopology( short_t d, index_t boxes,
65  const bContainer & boundary,
66  const ifContainer & interfaces )
67  : m_dim(d), nboxes(0), m_boundary(boundary), m_interfaces(interfaces)
68  {
69  addBox(boxes);
70  }
71 
72  // Default copy constructor does the same as the following:
73  //gsBoxTopology(const gsBoxTopology & other) : dim(other.dim), nboxes(other.nboxes),
74  // m_boundary(other.m_boundary), m_interfaces(other.m_interfaces)
75  // { }
76 
78  gsBoxTopology * clone() const
79  {
80  return new gsBoxTopology(*this);
81  }
82 
83 public:
84 
86  std::ostream &print(std::ostream &os) const;
87 
89  friend std::ostream& operator<<( std::ostream& os, const gsBoxTopology& b )
90  {
91  return b.print( os );
92  }
93 
95  index_t nBoxes() const { return nboxes; }
96 
98  short_t dim () const { return m_dim; }
99 
101  void setDim (short_t i)
102  {
103  GISMO_ASSERT(m_dim==-1 || i==m_dim, "Changing box dimension.");
104  m_dim = i;
105  }
106 
108  size_t nInterfaces() const { return m_interfaces.size(); }
109 
111  size_t nBoundary() const { return m_boundary.size(); }
112 
113 /*
114  * Additional members for Multipatch geometries
115  */
116 
119  const_iiterator iBegin() const
120  { return m_interfaces.begin(); }
121 
124  const_iiterator iEnd() const
125  { return m_interfaces.end(); }
126 
129  iiterator iBegin()
130  { return m_interfaces.begin(); }
131 
134  iiterator iEnd()
135  { return m_interfaces.end(); }
136 
139  const_biterator bBegin() const
140  { return m_boundary.begin(); }
141 
144  const_biterator bEnd() const
145  { return m_boundary.end(); }
146 
149  biterator bBegin()
150  { return m_boundary.begin(); }
151 
154  biterator bEnd()
155  { return m_boundary.end(); }
156 
159  {
160  m_boundary .clear();
161  m_interfaces.clear();
162  }
163 
165  void clearAll()
166  {
167  clearTopology();
168  m_dim = -1;
169  nboxes = 0;
170  m_boxProp.clear();
171  }
172 
174  void swap(gsBoxTopology& other)
175  {
176  std::swap( m_dim, other.m_dim );
177  std::swap( nboxes, other.nboxes );
178  m_boundary.swap( other.m_boundary );
179  m_interfaces.swap( other.m_interfaces );
180  std::swap( m_boxProp, other.m_boxProp );
181  }
182 
185  index_t p2, boxSide s2,
186  std::string l = "")
187  {
188  addInterface(boundaryInterface(patchSide(p1, s1), patchSide(p2, s2), m_dim,l));
189  }
190 
192  void addInterface( const boundaryInterface& bi )
193  {
194  m_interfaces.push_back( bi );
195  }
196 
198  void addBox(index_t i = 1)
199  {
200  nboxes += i;
201 
202  m_boxProp.reserve(m_boxProp.size()+i);
203  for (index_t k=0; k!=i; k++)
204  m_boxProp.push_back();
205  }
206 
208  void addBoundary(index_t p, boxSide s, std::string l = "")
209  {
210  addBoundary(patchSide(p, s, l));
211  }
212 
214  void addBoundary(const patchSide& ps)
215  {
216  m_boundary.push_back( ps );
217  }
218 
220  void addAutoBoundaries();
221 
223  bool isBoundary(const patchSide& ps) const
224  {
225  return std::find(m_boundary.begin(), m_boundary.end(), ps) != m_boundary.end();
226  }
227 
230  {
231  return isBoundary( patchSide(p,s) );
232  }
233 
235  bool isInterface(const patchSide& ps) const;
236 
238  const bContainer & boundaries() const { return m_boundary;}
239  bContainer & boundaries() { return m_boundary;}
240 
242  bContainer boundaries(const std::string l) const
243  {
244  bContainer result;
245  for (const_biterator bit = bBegin(); bit!=bEnd(); bit++)
246  if (bit->label() == l)
247  result.push_back(*bit);
248  return result;
249  }
250 
252  const ifContainer & interfaces() const { return m_interfaces; }
253  ifContainer & interfaces() { return m_interfaces; }
254 
256  ifContainer interfaces(const std::string l) const
257  {
258  ifContainer result;
259  for (const_iiterator iit = iBegin(); iit!=iEnd(); iit++)
260  if (iit->label() == l)
261  result.push_back(*iit);
262  return result;
263  }
264 
265  ifContainer selectInterfaces(interaction::type ifc_type) const;
266 
268  void checkConsistency() const;
269 
271  const boundaryInterface & bInterface(int i) const {return m_interfaces[i];}
272 
275  bool getNeighbour(const patchSide& ps ,patchSide& result, int & ii) const;
276 
279  bool getNeighbour(const patchSide& ps ,patchSide& result) const;
280 
283  InterfacePtr findInterface(const index_t b1, const index_t b2) const;
284 
286  BoundaryPtr getBoundary(const patchSide & ps);
287 
290  bool getInterface(const patchSide& ps,boundaryInterface & result) const
291  {
292  for ( unsigned i = 0; i < m_interfaces.size(); ++i )
293  if ( m_interfaces[i].first() == ps || m_interfaces[i].second() == ps )
294  {
295  result = m_interfaces[i];
296  return true;
297  }
298  return false;
299  }
300 
303  bool getCornerList(const patchCorner& start, std::vector<patchCorner> & cornerList) const;
304 
306  int getMaxValence() const;
307 
317  std::vector< std::vector<patchComponent> > allComponents(bool combineCorners = false) const;
318 
324  void getEVs(std::vector<std::vector<patchCorner> > & cornerLists, bool boundaries = false) const;
325 
331  void getOVs(std::vector<std::vector<patchCorner> > & cornerLists) const;
332 
333 
334  std::vector<std::vector<patchCorner>> vertices() const;
335 
344  template <class T>
345  gsProperty<T> addBoxProperty(const std::string& name, T t=T())
346  {
347  return m_boxProp.add<T>(name, give(t));
348  }
349 
357  template <class T>
358  gsProperty<T> getBoxProperty(const std::string& name) const
359  {
360  return m_boxProp.get<T>(name);
361  }
362 
369  {
370  return m_boxProp.n_properties();
371  }
372 
373 protected:
374  // Data members
375 
378 
381 
383  bContainer m_boundary;
384 
386  ifContainer m_interfaces;
387 
389  gsProperty_container m_boxProp;
390 
391 }; // class gsBoxTopology
392 
393 #ifdef GISMO_WITH_PYBIND11
394 
398  void pybind11_init_gsBoxTopology(pybind11::module &m);
399 
400 #endif // GISMO_WITH_PYBIND11
401 
402 } // namespace gismo
403 
void addBoundary(index_t p, boxSide s, std::string l="")
Set side s of box p to a boundary.
Definition: gsBoxTopology.h:208
Struct which represents a certain side of a patch.
Definition: gsBoundary.h:231
ifContainer m_interfaces
List of intefaces between boxes.
Definition: gsBoxTopology.h:386
iiterator iBegin()
Definition: gsBoxTopology.h:129
gsBoxTopology * clone() const
Clone function. Used to make a copy of the object.
Definition: gsBoxTopology.h:78
short_t m_dim
Dimension of the boxes held.
Definition: gsBoxTopology.h:377
short_t dim() const
Dimension of the boxes.
Definition: gsBoxTopology.h:98
#define short_t
Definition: gsConfig.h:35
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsBoxTopology.cpp:40
Provides structs and classes related to interfaces and boundaries.
const bContainer & boundaries() const
Return the vector of boundaries.
Definition: gsBoxTopology.h:238
const_iiterator iBegin() const
Definition: gsBoxTopology.h:119
Struct that defines the boundary sides and corners and types of a geometric object.
Definition: gsBoundary.h:55
void setDim(short_t i)
Set the dimension of the boxes.
Definition: gsBoxTopology.h:101
const_biterator bBegin() const
Definition: gsBoxTopology.h:139
S give(S &x)
Definition: gsMemory.h:266
void addInterface(index_t p1, boxSide s1, index_t p2, boxSide s2, std::string l="")
Add an interface between side s1 of box p1 and side s2 of box p2.
Definition: gsBoxTopology.h:184
bool isBoundary(const patchSide &ps) const
Is the given patch side ps set to a boundary?
Definition: gsBoxTopology.h:223
#define index_t
Definition: gsConfig.h:32
Struct which represents a certain corner of a patch.
Definition: gsBoundary.h:392
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Handles shared library creation and other class attributes.
gsBoxTopology(short_t d=-1, index_t n=0)
Default constructor.
Definition: gsBoxTopology.h:59
void clearTopology()
Clear all boundary and interface data.
Definition: gsBoxTopology.h:158
bool getInterface(const patchSide &ps, boundaryInterface &result) const
Definition: gsBoxTopology.h:290
memory::shared_ptr< gsBoxTopology > Ptr
Shared pointer for gsBoxTopology.
Definition: gsBoxTopology.h:43
gsProperty_container m_boxProp
List of properties for each box.
Definition: gsBoxTopology.h:389
iiterator iEnd()
Definition: gsBoxTopology.h:134
size_t nInterfaces() const
Number of interfaces.
Definition: gsBoxTopology.h:108
index_t nboxes
Number of boxes held.
Definition: gsBoxTopology.h:380
const_iiterator iEnd() const
Definition: gsBoxTopology.h:124
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
index_t nBoxes() const
Number of boxes.
Definition: gsBoxTopology.h:95
gsProperty< T > addBoxProperty(const std::string &name, T t=T())
Adds a box property.
Definition: gsBoxTopology.h:345
ifContainer interfaces(const std::string l) const
Return the vector of interfaces with label l.
Definition: gsBoxTopology.h:256
biterator bEnd()
Definition: gsBoxTopology.h:154
void addInterface(const boundaryInterface &bi)
Add an interface described by bi.
Definition: gsBoxTopology.h:192
bContainer m_boundary
List of boundaries of the boxes.
Definition: gsBoxTopology.h:383
size_t nBoundary() const
Number of boundaries.
Definition: gsBoxTopology.h:111
void swap(gsBoxTopology &other)
Swap with another gsBoxTopology.
Definition: gsBoxTopology.h:174
void clearAll()
Clear all boxes, boundary and interface data.
Definition: gsBoxTopology.h:165
bool isBoundary(index_t p, boxSide s)
Returns true if side s on patch p is a boundary.
Definition: gsBoxTopology.h:229
bContainer boundaries(const std::string l) const
Return the vector of boundaries with label l.
Definition: gsBoxTopology.h:242
void addBox(index_t i=1)
Add i new boxes.
Definition: gsBoxTopology.h:198
Struct which represents an interface between two patches.
Definition: gsBoundary.h:649
const ifContainer & interfaces() const
Return the vector of interfaces.
Definition: gsBoxTopology.h:252
const_biterator bEnd() const
Definition: gsBoxTopology.h:144
biterator bBegin()
Definition: gsBoxTopology.h:149
Defines a topological arrangement of a collection of &quot;boxes&quot; (e.g., parameter domains that map to phy...
Definition: gsBoxTopology.h:38
index_t numBoxProperties() const
Returns the number of assigned box properties.
Definition: gsBoxTopology.h:368
void addBoundary(const patchSide &ps)
Set patch side ps to a boundary.
Definition: gsBoxTopology.h:214
friend std::ostream & operator<<(std::ostream &os, const gsBoxTopology &b)
Print (as string) a boxTopology object.
Definition: gsBoxTopology.h:89
const boundaryInterface & bInterface(int i) const
Access i-th boundary interface.
Definition: gsBoxTopology.h:271
gsProperty< T > getBoxProperty(const std::string &name) const
Adds a box property.
Definition: gsBoxTopology.h:358