G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsMultiPatch.h
Go to the documentation of this file.
1
14#pragma once
15
17#include <gsCore/gsGeometry.h>
18
19#include <gsCore/gsMultiBasis.h>
20
21namespace gismo
22{
23
24namespace internal
25{
26
78struct ElementBlock
79{
80 index_t numElements; // NE
81 std::list<gsMatrix<index_t>> actives; // Nodes ( size = NE )
82 std::list<gsMatrix<real_t>> coefVectors; // Bezier Coefficient Vectors ID ( size = NE )
83 index_t PR; // Polynomial degree in R direction
84 index_t PS; // Polynomial degree in S direction
85 index_t PT; // Polynomial degree in T direction
86};
87} // end namespace internal
88
89
98template<class T>
99class gsMultiPatch : public gsBoxTopology, public gsFunctionSet<T>
100{
101
102public:
103 typedef gsBoxTopology BaseA;
104 typedef gsFunctionSet<T> BaseB;
105
107 typedef memory::shared_ptr< gsMultiPatch > Ptr;
109 typedef memory::unique_ptr< gsMultiPatch > uPtr;
110
111 typedef std::vector<gsGeometry<T> *> PatchContainer;
112 typedef std::map<boundaryInterface,typename gsGeometry<T>::uPtr> InterfaceRep;
113 typedef std::map<patchSide,typename gsGeometry<T>::uPtr> BoundaryRep;
114
115 typedef typename PatchContainer::iterator iterator;
116 typedef typename PatchContainer::const_iterator const_iterator;
117
118public:
119
122
124 gsMultiPatch( const gsMultiPatch& other );
125
126#if ! EIGEN_HAS_RVALUE_REFERENCES
127
130 {
131 this->swap(other);
132 return *this;
133 }
134
135#else
137 gsMultiPatch( gsMultiPatch&& other )
138 : BaseA( give(other) ), m_patches( give(other.m_patches) )
139 {}
140
142 gsMultiPatch& operator= ( const gsMultiPatch& other );
143
146
147#endif
148
150 explicit gsMultiPatch( PatchContainer & patches );
151
153 gsMultiPatch( const gsGeometry<T> & geo );
154
156 gsMultiPatch( PatchContainer & patches,
157 const std::vector<patchSide>& boundary,
158 const std::vector<boundaryInterface>& interfaces );
159
162
163 GISMO_CLONE_FUNCTION(gsMultiPatch)
164
165public:
166
169 const_iterator begin() const
170 { return m_patches.begin(); }
171
174 const_iterator end() const
175 { return m_patches.end(); }
176
179 iterator begin()
180 { return m_patches.begin(); }
181
184 iterator end()
185 { return m_patches.end(); }
186
187public:
188
189 const gsGeometry<T> & piece(const index_t i) const { return patch(i); }
190
191 gsMultiPatch<T> coord(const index_t c) const;
192
193 index_t nPieces() const { return static_cast<index_t>(m_patches.size()); }
194
195 index_t size() const { return 1; }
196
199 {
200 index_t sz = 0;
201 for (typename PatchContainer::const_iterator it =
202 m_patches.begin(); it != m_patches.end(); ++it )
203 sz += (*it)->coefsSize();
204 return sz;
205 }
206
209 {
210 gsMatrix<T> result(this->coefsSize(),this->geoDim());
211 result.setZero();
212 index_t offset = 0;
213 for (typename PatchContainer::const_iterator it =
214 m_patches.begin(); it != m_patches.end(); ++it )
215 {
216 result.block(offset,0,(*it)->coefsSize(),(*it)->geoDim()) = (*it)->coefs();
217 offset += (*it)->coefsSize();
218 }
219 return result;
220 }
221
222public:
233 gsAffineFunction<T> getMapForInterface(const boundaryInterface &bi, T scaling=0) const;
234
236 void swap(gsMultiPatch& other)
237 {
238 BaseA::swap( other );
239 m_patches.swap( other.m_patches );
240 }
241
243 std::ostream& print( std::ostream& os ) const;
244
246 std::string detail() const;
247
250 {
251 //GISMO_ASSERT( m_patches.size() > 0 , "Empty multipatch object.");
252 return m_dim;
253 }
254 short_t domainDim () const {return parDim();}
255
257 short_t geoDim() const;
258 short_t targetDim () const {return geoDim();}
259
261 short_t coDim() const;
262
265 bool isClosed() { return this->nBoundary() == 0; }
266
268 bool empty() const { return m_patches.empty(); }
269
271 gsMatrix<T> parameterRange(int i = 0) const;
272
274 size_t nPatches() const { return m_patches.size(); }
275
277 PatchContainer const& patches() const { return m_patches; }
278
279 const BaseA & topology() const { return *this; }
280
282 const gsGeometry<T> & operator []( size_t i ) const { return *m_patches[i]; }
283
289 std::vector<gsBasis<T> *> basesCopy(bool numeratorOnly = false) const;
290
292 gsGeometry<T>& patch( size_t i ) const
293 {
294 GISMO_ASSERT( i < m_patches.size(), "Invalid patch index "<<i<<" requested from gsMultiPatch" );
295 return *m_patches[i];
296 }
297
299 void permute(const std::vector<short_t> & perm);
300
302 gsBasis<T> & basis( const size_t i ) const;
303
306
308 index_t addPatch(const gsGeometry<T> & g);
309
311 size_t findPatchIndex( gsGeometry<T>* g ) const;
312
317 GISMO_DEPRECATED void addInterface( gsGeometry<T>* g1, boxSide s1,
318 gsGeometry<T>* g2, boxSide s2 );
319
320 using BaseA::addInterface; // unhide base function
321
324 size_t p = findPatchIndex( g );
325 BaseA::addBoundary( patchSide( p, s ) );
326 }
327
329 gsMatrix<T> pointOn( const patchCorner& pc );
330
335 gsMatrix<T> pointOn( const patchSide& ps );
336
339 void uniformRefine(int numKnots = 1, int mul = 1, short_t const dir = -1);
340
342 void degreeElevate(short_t const elevationSteps = 1, short_t const dir = -1);
344 void degreeIncrease(short_t const elevationSteps = 1, short_t const dir = -1);
345
347 void degreeReduce(int elevationSteps = 1);
348
350 void degreeDecrease(int elevationSteps = 1);
351
354 void uniformCoarsen(int numKnots = 1);
355
356 void embed(const index_t N)
357 {
358 for ( typename PatchContainer::const_iterator it = m_patches.begin();
359 it != m_patches.end(); ++it )
360 {
361 ( *it )->embed(N);
362 }
363 }
364
371 bool computeTopology( T tol = 1e-4, bool cornersOnly = false, bool tjunctions = false);
372
374 void fixOrientation();
375
379 void closeGaps( T tol = 1e-4 );
380
382 gsDofMapper getMapper(T tol) const;
383
385 gsSurfMesh toMesh() const;
386
388 void clear()
389 {
391 freeAll(m_patches);
392 m_patches.clear();
393 }
394
398 void boundingBox(gsMatrix<T> & result) const;
399
404 gsMultiPatch<T> uniformSplit(index_t dir =-1) const;
405
406
414 {
415 std::vector< boundaryInterface > bivec = interfaces();
416 size_t kmax = 2*bivec.size();
417 size_t k = 0;
418 bool sthChanged = false;
419 bool change = false;
420 do
421 {
422 sthChanged = false;
423 for( size_t i = 0; i < bivec.size(); i++ )
424 {
425 if ( bivec[i].type() != interaction::contact)
426 {
427 change = repairInterface( bivec[i] );
428 sthChanged = sthChanged || change;
429 }
430 }
431 k++; // just to be sure this cannot go on infinitely
432 }
433 while( sthChanged && k <= kmax );
434 }
435
444 bool repairInterface( const boundaryInterface & bi );
445
448
453 void locatePoints(const gsMatrix<T> & points, gsVector<index_t> & pids, gsMatrix<T> & preim, const T accuracy = 1e-6) const;
454
459 void locatePoints(const gsMatrix<T> & points, index_t pid1, gsVector<index_t> & pid2, gsMatrix<T> & preim) const;
460
461 T closestDistance(const gsVector<T> & pt,std::pair<index_t,gsVector<T> > & result,
462 const T accuracy = 1e-6) const;
463
464 std::pair<index_t,gsVector<T> > closestPointTo(const gsVector<T> & pt,
465 const T accuracy = 1e-6) const;
466
468 std::vector<T> HausdorffDistance( const gsMultiPatch<T> & other,
469 const index_t nsamples = 1000,
470 const T accuracy = 1e-6,
471 const bool directed=false);
472
473 T averageHausdorffDistance( const gsMultiPatch<T> & other,
474 const index_t nsamples = 1000,
475 const T accuracy = 1e-6,
476 const bool directed=false);
477
478 void constructInterfaceRep();
481 void constructSides();
482
484 void constructInterfaceRep(const std::string l);
486 void constructBoundaryRep(const std::string l);
487
488 const InterfaceRep & interfaceRep() const { return m_ifaces; }
489 const BoundaryRep & boundaryRep() const { return m_bdr; }
490 const BoundaryRep & sides() const { return m_sides; }
491
502 gsMultiPatch<T> extractBezier() const;
503
504protected:
505
506 void setIds();
507
508 // Data members
509private:
510
511 PatchContainer m_patches;
512
513 InterfaceRep m_ifaces;
514 BoundaryRep m_bdr, m_sides;
515
516private:
517 // implementation functions
518
519 // match the vertices in ci1 starting from start to the end with the vertices
520 // in ci2 that are still non matched
521 // cc1 and cc2 are the physical coordinates of the vertices
522 // ci1 and ci2 are the indices corner indices
523 // start is the index in ci1 of the vertex to match
524 // reference is the image of the vertex ci1(0) and it is used to compute orientation
525 // tol is the allowed distance between two vertexes in physical domain
526 // matched keeps track of the already matched vertices
527 // dirMap and dirO are the output orientation of the match
528 // return true if all the vertices starting from start are matched
529 static bool matchVerticesOnSide (
530 const gsMatrix<T> &cc1, const std::vector<boxCorner> &ci1, index_t start,
531 const gsMatrix<T> &cc2, const std::vector<boxCorner> &ci2,
532 const gsVector<bool> &matched,
533 gsVector<index_t> &dirMap, gsVector<bool> &dirO,
534 T tol, index_t reference=0);
535
536public:
539 std::map< std::array<size_t, 4>, internal::ElementBlock> BezierOperator() const;
540
541}; // class gsMultiPatch
542
543
545template<class T>
546std::ostream& operator<<( std::ostream& os, const gsMultiPatch<T>& b )
547{
548 return b.print( os );
549}
550
551#ifdef GISMO_WITH_PYBIND11
552
556 void pybind11_init_gsMultiPatch(pybind11::module &m);
557
558#endif // GISMO_WITH_PYBIND11
559
560
561} // namespace gismo
562
563
564#ifndef GISMO_BUILD_LIB
565#include GISMO_HPP_HEADER(gsMultiPatch.hpp)
566#endif
567
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
Representation of an affine function.
Definition gsAffineFunction.h:30
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
Defines a topological arrangement of a collection of "boxes" (e.g., parameter domains that map to phy...
Definition gsBoxTopology.h:39
const ifContainer & interfaces() const
Return the vector of interfaces.
Definition gsBoxTopology.h:252
short_t m_dim
Dimension of the boxes held.
Definition gsBoxTopology.h:377
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
void clearAll()
Clear all boxes, boundary and interface data.
Definition gsBoxTopology.h:165
void swap(gsBoxTopology &other)
Swap with another gsBoxTopology.
Definition gsBoxTopology.h:174
void addBoundary(index_t p, boxSide s, std::string l="")
Set side s of box p to a boundary.
Definition gsBoxTopology.h:208
size_t nBoundary() const
Number of boundaries.
Definition gsBoxTopology.h:111
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition gsFunctionSet.h:219
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition gsGeometry.h:100
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
const gsGeometry< T > & operator[](size_t i) const
Return the i-th patch.
Definition gsMultiPatch.h:282
bool repairInterface(const boundaryInterface &bi)
Checks if the interface is fully matching, and if not, repairs it.
Definition gsMultiPatch.hpp:748
void addPatchBoundary(gsGeometry< T > *g, boxSide s)
Add side s of patch g to the outer boundary of the domain.
Definition gsMultiPatch.h:323
void uniformCoarsen(int numKnots=1)
Coarsen uniformly all patches by removing numKnots in each knot-span.
Definition gsMultiPatch.hpp:322
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:282
const_iterator begin() const
Definition gsMultiPatch.h:169
void constructBoundaryRep()
Construct the boundary representation.
Definition gsMultiPatch.hpp:955
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:906
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:292
PatchContainer const & patches() const
Returns a vector of patches // to do : replace by copies.
Definition gsMultiPatch.h:277
gsMultiPatch< T > approximateLinearly(index_t nsamples) const
Computes linear approximation of the patches using nsamples per direction.
Definition gsMultiPatch.hpp:733
gsMatrix< T > parameterRange(int i=0) const
Returns the range of parameter.
Definition gsMultiPatch.hpp:165
size_t findPatchIndex(gsGeometry< T > *g) const
Search for the given geometry and return its patch index.
Definition gsMultiPatch.hpp:235
std::map< std::array< size_t, 4 >, internal::ElementBlock > BezierOperator() const
Performs Bezier extraction on the multipatch.
Definition gsMultiPatch.hpp:1009
gsMatrix< T > pointOn(const patchCorner &pc)
Get coordinates of the patchCorner pc in the physical domain.
Definition gsMultiPatch.hpp:254
short_t coDim() const
Co-dimension of the geometry (must match for all patches).
Definition gsMultiPatch.hpp:157
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:708
bool empty() const
Returns true if gsMultiPatch is empty.
Definition gsMultiPatch.h:268
bool computeTopology(T tol=1e-4, bool cornersOnly=false, bool tjunctions=false)
Attempt to compute interfaces and boundaries automatically.
Definition gsMultiPatch.hpp:377
gsDofMapper getMapper(T tol) const
Used to get a mapper with unique vertices.
Definition gsMultiPatch.hpp:604
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:790
short_t targetDim() const
Dimension of the target space.
Definition gsMultiPatch.h:258
index_t size() const
size
Definition gsMultiPatch.h:195
std::string detail() const
Prints the object as a string with extended details.
Definition gsMultiPatch.hpp:138
memory::shared_ptr< gsMultiPatch > Ptr
Shared pointer for gsMultiPatch.
Definition gsMultiPatch.h:107
short_t geoDim() const
Dimension of the geometry (must match for all patches).
Definition gsMultiPatch.hpp:150
gsMultiPatch & operator=(gsMultiPatch other)
Assignment operator (uses copy-and-swap idiom)
Definition gsMultiPatch.h:129
gsMultiPatch()
Default empty constructor.
Definition gsMultiPatch.h:121
~gsMultiPatch()
Destructor.
Definition gsMultiPatch.hpp:109
gsGeometry< T > & patch(size_t i) const
Return the i-th patch.
Definition gsMultiPatch.h:292
gsMatrix< T > coefs() const
Returns the coefficient matrix of the multi-patch geometry.
Definition gsMultiPatch.h:208
index_t addPatch(typename gsGeometry< T >::uPtr g)
Add a patch from a gsGeometry<T>::uPtr.
Definition gsMultiPatch.hpp:211
bool isClosed()
Returns true if the multipatch object is a closed manifold (ie. it has no boundaries)
Definition gsMultiPatch.h:265
index_t nPieces() const
Number of pieces in the domain of definition.
Definition gsMultiPatch.h:193
void permute(const std::vector< short_t > &perm)
Permutes the patches according to perm.
Definition gsMultiPatch.hpp:204
short_t domainDim() const
Dimension of the (source) domain.
Definition gsMultiPatch.h:254
void swap(gsMultiPatch &other)
Swap with another gsMultiPatch.
Definition gsMultiPatch.h:236
void uniformRefine(int numKnots=1, int mul=1, short_t const dir=-1)
Refine uniformly all patches by inserting numKnots in each knot-span with multipliplicity mul.
Definition gsMultiPatch.hpp:271
short_t parDim() const
Dimension of the parameter domain (must match for all patches).
Definition gsMultiPatch.h:249
void degreeReduce(int elevationSteps=1)
Reduce the degree of all patches by elevationSteps.
Definition gsMultiPatch.hpp:312
void fixOrientation()
Provides positive orientation for all patches.
Definition gsMultiPatch.hpp:496
gsBasis< T > & basis(const size_t i) const
Return the basis of the i-th patch.
Definition gsMultiPatch.hpp:172
void degreeDecrease(int elevationSteps=1)
Decrease the degree of all patches by elevationSteps.
Definition gsMultiPatch.hpp:302
void clear()
Clear (delete) all patches.
Definition gsMultiPatch.h:388
iterator end()
Definition gsMultiPatch.h:184
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:351
const_iterator end() const
Definition gsMultiPatch.h:174
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:332
iterator begin()
Definition gsMultiPatch.h:179
memory::unique_ptr< gsMultiPatch > uPtr
Unique pointer for gsMultiPatch.
Definition gsMultiPatch.h:109
gsSurfMesh toMesh() const
Creates a surface mesh out of this multipatch.
Definition gsMultiPatch.hpp:652
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsMultiPatch.hpp:125
const gsGeometry< T > & piece(const index_t i) const
Returns the piece(s) of the function(s) at subdomain k.
Definition gsMultiPatch.h:189
gsMultiPatch< T > extractBezier() const
Extracts a Bezier representation of the current gsMultiPatch object.
Definition gsMultiPatch.hpp:1085
index_t coefsSize() const
Return the number of coefficients (control points)
Definition gsMultiPatch.h:198
void repairInterfaces()
Checks if all patch-interfaces are fully matching, and if not, repairs them, i.e.,...
Definition gsMultiPatch.h:413
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:179
size_t nPatches() const
Number of patches.
Definition gsMultiPatch.h:274
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:245
void closeGaps(T tol=1e-4)
Attempt to close gaps between the interfaces. Assumes that the topology is computed,...
Definition gsMultiPatch.hpp:577
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Provides declaration of the BoxTopology class.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of Geometry abstract interface.
Provides declaration of MultiBasis class.
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition gsMemory.h:312
Struct which represents an interface between two patches.
Definition gsBoundary.h:650
Struct which represents a certain corner of a patch.
Definition gsBoundary.h:393
Struct which represents a certain side of a patch.
Definition gsBoundary.h:232