G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMultiPatch.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsBoxTopology.h>
17 #include <gsCore/gsGeometry.h>
18 
19 #include <gsCore/gsMultiBasis.h>
20 
21 namespace gismo
22 {
23 
32 template<class T>
33 class gsMultiPatch : public gsBoxTopology, public gsFunctionSet<T>
34 {
35 
36 public:
37  typedef gsBoxTopology BaseA;
38  typedef gsFunctionSet<T> BaseB;
39 
41  typedef memory::shared_ptr< gsMultiPatch > Ptr;
43  typedef memory::unique_ptr< gsMultiPatch > uPtr;
44 
45  typedef std::vector<gsGeometry<T> *> PatchContainer;
46  typedef std::map<boundaryInterface,typename gsGeometry<T>::uPtr> InterfaceRep;
47  typedef std::map<patchSide,typename gsGeometry<T>::uPtr> BoundaryRep;
48 
49  typedef typename PatchContainer::iterator iterator;
50  typedef typename PatchContainer::const_iterator const_iterator;
51 
52 public:
53 
56 
58  gsMultiPatch( const gsMultiPatch& other );
59 
60 #if ! EIGEN_HAS_RVALUE_REFERENCES
61 
64  {
65  this->swap(other);
66  return *this;
67  }
68 
69 #else
70  gsMultiPatch( gsMultiPatch&& other )
72  : BaseA( give(other) ), m_patches( give(other.m_patches) )
73  {}
74 
76  gsMultiPatch& operator= ( const gsMultiPatch& other );
77 
80 
81 #endif
82 
84  explicit gsMultiPatch( PatchContainer & patches );
85 
87  gsMultiPatch( const gsGeometry<T> & geo );
88 
90  gsMultiPatch( PatchContainer & patches,
91  const std::vector<patchSide>& boundary,
92  const std::vector<boundaryInterface>& interfaces );
93 
95  ~gsMultiPatch();
96 
97  GISMO_CLONE_FUNCTION(gsMultiPatch)
98 
99 public:
100 
103  const_iterator begin() const
104  { return m_patches.begin(); }
105 
108  const_iterator end() const
109  { return m_patches.end(); }
110 
113  iterator begin()
114  { return m_patches.begin(); }
115 
118  iterator end()
119  { return m_patches.end(); }
120 
121 public:
122 
123  const gsGeometry<T> & piece(const index_t i) const { return patch(i); }
124 
125  gsMultiPatch<T> coord(const index_t c) const;
126 
127  index_t nPieces() const { return static_cast<index_t>(m_patches.size()); }
128 
129  index_t size() const { return 1; }
130 
133  {
134  index_t sz = 0;
135  for (typename PatchContainer::const_iterator it =
136  m_patches.begin(); it != m_patches.end(); ++it )
137  sz += (*it)->coefsSize();
138  return sz;
139  }
140 
143  {
144  gsMatrix<T> result(this->coefsSize(),this->geoDim());
145  result.setZero();
146  index_t offset = 0;
147  for (typename PatchContainer::const_iterator it =
148  m_patches.begin(); it != m_patches.end(); ++it )
149  {
150  result.block(offset,0,(*it)->coefsSize(),(*it)->geoDim()) = (*it)->coefs();
151  offset += (*it)->coefsSize();
152  }
153  return result;
154  }
155 
156 public:
167  gsAffineFunction<T> getMapForInterface(const boundaryInterface &bi, T scaling=0) const;
168 
170  void swap(gsMultiPatch& other)
171  {
172  BaseA::swap( other );
173  m_patches.swap( other.m_patches );
174  }
175 
177  std::ostream& print( std::ostream& os ) const;
178 
180  std::string detail() const;
181 
183  short_t parDim() const
184  {
185  //GISMO_ASSERT( m_patches.size() > 0 , "Empty multipatch object.");
186  return m_dim;
187  }
188  short_t domainDim () const {return parDim();}
189 
191  short_t geoDim() const;
192  short_t targetDim () const {return geoDim();}
193 
195  short_t coDim() const;
196 
199  bool isClosed() { return this->nBoundary() == 0; }
200 
202  bool empty() const { return m_patches.empty(); }
203 
205  gsMatrix<T> parameterRange(int i = 0) const;
206 
208  size_t nPatches() const { return m_patches.size(); }
209 
211  PatchContainer const& patches() const { return m_patches; }
212 
213  const BaseA & topology() const { return *this; }
214 
216  const gsGeometry<T> & operator []( size_t i ) const { return *m_patches[i]; }
217 
223  std::vector<gsBasis<T> *> basesCopy(bool numeratorOnly = false) const;
224 
226  gsGeometry<T>& patch( size_t i ) const
227  {
228  GISMO_ASSERT( i < m_patches.size(), "Invalid patch index "<<i<<" requested from gsMultiPatch" );
229  return *m_patches[i];
230  }
231 
233  void permute(const std::vector<short_t> & perm);
234 
236  gsBasis<T> & basis( const size_t i ) const;
237 
240 
242  index_t addPatch(const gsGeometry<T> & g);
243 
245  size_t findPatchIndex( gsGeometry<T>* g ) const;
246 
251  GISMO_DEPRECATED void addInterface( gsGeometry<T>* g1, boxSide s1,
252  gsGeometry<T>* g2, boxSide s2 );
253 
254  using BaseA::addInterface; // unhide base function
255 
258  size_t p = findPatchIndex( g );
259  BaseA::addBoundary( patchSide( p, s ) );
260  }
261 
263  gsMatrix<T> pointOn( const patchCorner& pc );
264 
269  gsMatrix<T> pointOn( const patchSide& ps );
270 
273  void uniformRefine(int numKnots = 1, int mul = 1);
274 
276  void degreeElevate(short_t const elevationSteps = 1, short_t const dir = -1);
278  void degreeIncrease(short_t const elevationSteps = 1, short_t const dir = -1);
279 
281  void degreeReduce(int elevationSteps = 1);
282 
285  void uniformCoarsen(int numKnots = 1);
286 
287  void embed(const index_t N)
288  {
289  for ( typename PatchContainer::const_iterator it = m_patches.begin();
290  it != m_patches.end(); ++it )
291  {
292  ( *it )->embed(N);
293  }
294  }
295 
302  bool computeTopology( T tol = 1e-4, bool cornersOnly = false, bool tjunctions = false);
303 
305  void fixOrientation();
306 
310  void closeGaps( T tol = 1e-4 );
311 
313  gsDofMapper getMapper(T tol) const;
314 
316  gsSurfMesh toMesh() const;
317 
319  void clear()
320  {
321  BaseA::clearAll();
322  freeAll(m_patches);
323  m_patches.clear();
324  }
325 
329  void boundingBox(gsMatrix<T> & result) const;
330 
335  gsMultiPatch<T> uniformSplit(index_t dir =-1) const;
336 
337 
345  {
346  std::vector< boundaryInterface > bivec = interfaces();
347  size_t kmax = 2*bivec.size();
348  size_t k = 0;
349  bool sthChanged = false;
350  bool change = false;
351  do
352  {
353  sthChanged = false;
354  for( size_t i = 0; i < bivec.size(); i++ )
355  {
356  change = repairInterface( bivec[i] );
357  sthChanged = sthChanged || change;
358  }
359  k++; // just to be sure this cannot go on infinitely
360  }
361  while( sthChanged && k <= kmax );
362  }
363 
372  bool repairInterface( const boundaryInterface & bi );
373 
376 
381  void locatePoints(const gsMatrix<T> & points, gsVector<index_t> & pids, gsMatrix<T> & preim, const T accuracy = 1e-6) const;
382 
387  void locatePoints(const gsMatrix<T> & points, index_t pid1, gsVector<index_t> & pid2, gsMatrix<T> & preim) const;
388 
389  T closestDistance(const gsVector<T> & pt,std::pair<index_t,gsVector<T> > & result,
390  const T accuracy = 1e-6) const;
391 
392  std::pair<index_t,gsVector<T> > closestPointTo(const gsVector<T> & pt,
393  const T accuracy = 1e-6) const;
394 
396  std::vector<T> HausdorffDistance( const gsMultiPatch<T> & other,
397  const index_t nsamples = 1000,
398  const T accuracy = 1e-6,
399  const bool directed=false);
400 
401  T averageHausdorffDistance( const gsMultiPatch<T> & other,
402  const index_t nsamples = 1000,
403  const T accuracy = 1e-6,
404  const bool directed=false);
405 
406  void constructInterfaceRep();
408  void constructBoundaryRep();
409  void constructSides();
410 
412  void constructInterfaceRep(const std::string l);
414  void constructBoundaryRep(const std::string l);
415 
416  const InterfaceRep & interfaceRep() const { return m_ifaces; }
417  const BoundaryRep & boundaryRep() const { return m_bdr; }
418  const BoundaryRep & sides() const { return m_sides; }
419 
420 protected:
421 
422  void setIds();
423 
424  // Data members
425 private:
426 
427  PatchContainer m_patches;
428 
429  InterfaceRep m_ifaces;
430  BoundaryRep m_bdr, m_sides;
431 
432 private:
433  // implementation functions
434 
435  // match the vertices in ci1 starting from start to the end with the vertices
436  // in ci2 that are still non matched
437  // cc1 and cc2 are the physical coordinates of the vertices
438  // ci1 and ci2 are the indices corner indices
439  // start is the index in ci1 of the vertex to match
440  // reference is the image of the vertex ci1(0) and it is used to compute orientation
441  // tol is the allowed distance between two vertexes in physical domain
442  // matched keeps track of the already matched vertices
443  // dirMap and dirO are the output orientation of the match
444  // return true if all the vertices starting from start are matched
445  static bool matchVerticesOnSide (
446  const gsMatrix<T> &cc1, const std::vector<boxCorner> &ci1, index_t start,
447  const gsMatrix<T> &cc2, const std::vector<boxCorner> &ci2,
448  const gsVector<bool> &matched,
449  gsVector<index_t> &dirMap, gsVector<bool> &dirO,
450  T tol, index_t reference=0);
451 
452 }; // class gsMultiPatch
453 
454 
456 template<class T>
457 std::ostream& operator<<( std::ostream& os, const gsMultiPatch<T>& b )
458 {
459  return b.print( os );
460 }
461 
462 #ifdef GISMO_WITH_PYBIND11
463 
467  void pybind11_init_gsMultiPatch(pybind11::module &m);
468 
469 #endif // GISMO_WITH_PYBIND11
470 
471 
472 } // namespace gismo
473 
474 
475 #ifndef GISMO_BUILD_LIB
476 #include GISMO_HPP_HEADER(gsMultiPatch.hpp)
477 #endif
478 
memory::shared_ptr< gsMultiPatch > Ptr
Shared pointer for gsMultiPatch.
Definition: gsMultiPatch.h:41
index_t addPatch(typename gsGeometry< T >::uPtr g)
Add a patch from a gsGeometry&lt;T&gt;::uPtr.
Definition: gsMultiPatch.hpp:210
void addBoundary(index_t p, boxSide s, std::string l="")
Set side s of box p to a boundary.
Definition: gsBoxTopology.h:208
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
gsMultiPatch & operator=(gsMultiPatch other)
Assignment operator (uses copy-and-swap idiom)
Definition: gsMultiPatch.h:63
void clear()
Clear (delete) all patches.
Definition: gsMultiPatch.h:319
Struct which represents a certain side of a patch.
Definition: gsBoundary.h:231
Provides declaration of the BoxTopology class.
short_t m_dim
Dimension of the boxes held.
Definition: gsBoxTopology.h:377
short_t geoDim() const
Dimension of the geometry (must match for all patches).
Definition: gsMultiPatch.hpp:149
#define short_t
Definition: gsConfig.h:35
index_t nPieces() const
Number of pieces in the domain of definition.
Definition: gsMultiPatch.h:127
gsBasis< T > & basis(const size_t i) const
Return the basis of the i-th patch.
Definition: gsMultiPatch.hpp:171
Provides declaration of MultiBasis class.
bool repairInterface(const boundaryInterface &bi)
Checks if the interface is fully matching, and if not, repairs it.
Definition: gsMultiPatch.hpp:737
short_t parDim() const
Dimension of the parameter domain (must match for all patches).
Definition: gsMultiPatch.h:183
gsSurfMesh toMesh() const
Creates a surface mesh out of this multipatch.
Definition: gsMultiPatch.hpp:641
S give(S &x)
Definition: gsMemory.h:266
Provides declaration of Geometry abstract interface.
iterator begin()
Definition: gsMultiPatch.h:113
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
#define index_t
Definition: gsConfig.h:32
void fixOrientation()
Provides positive orientation for all patches.
Definition: gsMultiPatch.hpp:485
void uniformRefine(int numKnots=1, int mul=1)
Refine uniformly all patches by inserting numKnots in each knot-span with multipliplicity mul...
Definition: gsMultiPatch.hpp:270
void locatePoints(const gsMatrix< T > &points, gsVector< index_t > &pids, gsMatrix< T > &preim, const T accuracy=1e-6) const
For each point in points, locates the parametric coordinates of the point.
Definition: gsMultiPatch.hpp:779
Struct which represents a certain corner of a patch.
Definition: gsBoundary.h:392
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void boundingBox(gsMatrix< T > &result) const
Returns a bounding box for the multipatch domain. The output result is a matrix with two columns...
Definition: gsMultiPatch.hpp:321
gsMatrix< T > coefs() const
Returns the coefficient matrix of the multi-patch geometry.
Definition: gsMultiPatch.h:142
const gsGeometry< T > & operator[](size_t i) const
Return the i-th patch.
Definition: gsMultiPatch.h:216
void uniformCoarsen(int numKnots=1)
Coarsen uniformly all patches by removing numKnots in each knot-span.
Definition: gsMultiPatch.hpp:311
gsMatrix< T > parameterRange(int i=0) const
Returns the range of parameter.
Definition: gsMultiPatch.hpp:164
index_t size() const
size
Definition: gsMultiPatch.h:129
gsMultiPatch< T > approximateLinearly(index_t nsamples) const
Computes linear approximation of the patches using nsamples per direction.
Definition: gsMultiPatch.hpp:722
Representation of an affine function.
Definition: gsAffineFunction.h:29
short_t targetDim() const
Dimension of the target space.
Definition: gsMultiPatch.h:192
memory::unique_ptr< gsMultiPatch > uPtr
Unique pointer for gsMultiPatch.
Definition: gsMultiPatch.h:43
void swap(gsMultiPatch &other)
Swap with another gsMultiPatch.
Definition: gsMultiPatch.h:170
short_t domainDim() const
Dimension of the (source) domain.
Definition: gsMultiPatch.h:188
gsGeometry< T > & patch(size_t i) const
Return the i-th patch.
Definition: gsMultiPatch.h:226
size_t nPatches() const
Number of patches.
Definition: gsMultiPatch.h:208
void permute(const std::vector< short_t > &perm)
Permutes the patches according to perm.
Definition: gsMultiPatch.hpp:203
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsMultiPatch.hpp:124
void repairInterfaces()
Checks if all patch-interfaces are fully matching, and if not, repairs them, i.e., makes them fully matching.
Definition: gsMultiPatch.h:344
const gsGeometry< T > & piece(const index_t i) const
Returns the piece(s) of the function(s) at subdomain k.
Definition: gsMultiPatch.h:123
size_t findPatchIndex(gsGeometry< T > *g) const
Search for the given geometry and return its patch index.
Definition: gsMultiPatch.hpp:234
const_iterator end() const
Definition: gsMultiPatch.h:108
void addPatchBoundary(gsGeometry< T > *g, boxSide s)
Add side s of patch g to the outer boundary of the domain.
Definition: gsMultiPatch.h:257
void degreeReduce(int elevationSteps=1)
Reduce the degree of all patches by elevationSteps.
Definition: gsMultiPatch.hpp:301
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition: gsMemory.h:312
std::vector< gsBasis< T > * > basesCopy(bool numeratorOnly=false) const
Makes a deep copy of all bases and puts them in a vector.
Definition: gsMultiPatch.hpp:178
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition: gsMultiPatch.h:33
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
void constructBoundaryRep()
Construct the boundary representation.
Definition: gsMultiPatch.hpp:944
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition: gsGeometry.h:100
gsAffineFunction< T > getMapForInterface(const boundaryInterface &bi, T scaling=0) const
construct the affine map that places bi.first() next to bi.second() and identifies the two matching s...
Definition: gsMultiPatch.hpp:697
bool isClosed()
Returns true if the multipatch object is a closed manifold (ie. it has no boundaries) ...
Definition: gsMultiPatch.h:199
size_t nBoundary() const
Number of boundaries.
Definition: gsBoxTopology.h:111
void swap(gsBoxTopology &other)
Swap with another gsBoxTopology.
Definition: gsBoxTopology.h:174
void closeGaps(T tol=1e-4)
Attempt to close gaps between the interfaces. Assumes that the topology is computed, ie. computeTopology() has been called.
Definition: gsMultiPatch.hpp:566
index_t coefsSize() const
Return the number of coefficients (control points)
Definition: gsMultiPatch.h:132
gsMatrix< T > pointOn(const patchCorner &pc)
Get coordinates of the patchCorner pc in the physical domain.
Definition: gsMultiPatch.hpp:253
void clearAll()
Clear all boxes, boundary and interface data.
Definition: gsBoxTopology.h:165
std::string detail() const
Prints the object as a string with extended details.
Definition: gsMultiPatch.hpp:137
iterator end()
Definition: gsMultiPatch.h:118
std::vector< T > HausdorffDistance(const gsMultiPatch< T > &other, const index_t nsamples=1000, const T accuracy=1e-6, const bool directed=false)
Construct the interface representation.
Definition: gsMultiPatch.hpp:895
Struct which represents an interface between two patches.
Definition: gsBoundary.h:649
const_iterator begin() const
Definition: gsMultiPatch.h:103
~gsMultiPatch()
Destructor.
Definition: gsMultiPatch.hpp:108
gsMultiPatch()
Default empty constructor.
Definition: gsMultiPatch.h:55
const ifContainer & interfaces() const
Return the vector of interfaces.
Definition: gsBoxTopology.h:252
Defines a topological arrangement of a collection of &quot;boxes&quot; (e.g., parameter domains that map to phy...
Definition: gsBoxTopology.h:38
short_t coDim() const
Co-dimension of the geometry (must match for all patches).
Definition: gsMultiPatch.hpp:156
PatchContainer const & patches() const
Returns a vector of patches // to do : replace by copies.
Definition: gsMultiPatch.h:211
GISMO_DEPRECATED void addInterface(gsGeometry< T > *g1, boxSide s1, gsGeometry< T > *g2, boxSide s2)
Add an interface joint between side s1 of geometry g1 side s2 of geometry g2.
Definition: gsMultiPatch.hpp:244
void degreeIncrease(short_t const elevationSteps=1, short_t const dir=-1)
Increase the degree of all patches by elevationSteps, preserves multiplicity.
Definition: gsMultiPatch.hpp:291
bool empty() const
Returns true if gsMultiPatch is empty.
Definition: gsMultiPatch.h:202
gsDofMapper getMapper(T tol) const
Used to get a mapper with unique vertices.
Definition: gsMultiPatch.hpp:593
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
bool computeTopology(T tol=1e-4, bool cornersOnly=false, bool tjunctions=false)
Attempt to compute interfaces and boundaries automatically.
Definition: gsMultiPatch.hpp:366
void degreeElevate(short_t const elevationSteps=1, short_t const dir=-1)
Elevate the degree of all patches by elevationSteps, preserves smoothness.
Definition: gsMultiPatch.hpp:281
gsMultiPatch< T > uniformSplit(index_t dir=-1) const
Splits each patch uniformly in each direction (if dir = -1) into two new patches, giving a total numb...
Definition: gsMultiPatch.hpp:340