G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsGeometry.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <gsCore/gsFunction.h>
17#include <gsCore/gsBoundary.h>
18
19
20#define GISMO_BASIS_ACCESSORS \
21 Basis & basis() { return static_cast<Basis&>(*this->m_basis); } \
22 const Basis & basis() const { return static_cast<const Basis&>(*this->m_basis); }
23 // bool isProjective() const{ return Basis::IsRational; }
24
25namespace gismo
26{
27
91template<class T>
92class gsGeometry : public gsFunction<T>
93{
94
95public:
97 typedef memory::shared_ptr< gsGeometry > Ptr;
98
100 typedef memory::unique_ptr< gsGeometry > uPtr;
101
102 typedef T Scalar_t;
103
104public:
105
108
111 gsGeometry() :m_basis( NULL ), m_id(0)
112 { }
113
119 m_basis(basis.clone().release()), m_id(0)
120 {
121 m_coefs.swap(coefs);
122 GISMO_ASSERT( basis.size() == m_coefs.rows(),
123 "The coefficient matrix of the geometry (rows="<<m_coefs.rows()
124 <<") does not match the number of basis functions in its basis("
125 << basis.size() <<").");
126 }
127
129 gsGeometry(const gsGeometry & o);
131
132 gsGeometry& operator=( const gsGeometry & o);
133
134 virtual ~gsGeometry();
135
136
137#if EIGEN_HAS_RVALUE_REFERENCES
138 gsGeometry(gsGeometry&& other)
139 : m_coefs(std::move(other.m_coefs)), m_basis(other.m_basis),
140 m_id(std::move(other.m_id))
141 {
142 other.m_basis = NULL;
143 }
144 gsGeometry & operator=(gsGeometry&& other)
145 {
146 m_coefs.swap(other.m_coefs); other.m_coefs.clear();
147 delete m_basis;
148 m_basis = other.m_basis; other.m_basis = NULL;
149 m_id = std::move(other.m_id);
150 return *this;
151 }
152#endif
153
154public:
155
175 // Look at gsFunction class for documentation
176 void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const;
177
221 // Look at gsFunction class for documentation
222 virtual void deriv_into(const gsMatrix<T>& u, gsMatrix<T>& result) const;
223
224
243 // Look at gsFunctionSet class for documentation
244 virtual void deriv2_into(const gsMatrix<T>& u, gsMatrix<T>& result) const;
245
246 virtual void evalAllDers_into(const gsMatrix<T> & u, int n,
247 std::vector<gsMatrix<T> > & result,
248 bool sameElement = false) const;
249
250 // Look at gsFunctionSet for documentation
251 virtual void compute(const gsMatrix<T> & in, gsFuncData<T> & out) const;
252
254
260 int orientation() const
261 {
262 if ( parDim() == geoDim() )
263 {
264 const T val = gsFunction<T>::jacobian( this->parameterCenter() ).determinant();
265 return (T(0) < val) - (val < (T)(0));
266 }
267 return 1;
268 }
269
270 virtual void toggleOrientation();
271
272 /*************************************************************************/
276
279 virtual const gsBasis<T> & basis() const = 0;
280
283 virtual gsBasis<T> & basis() = 0;
284
286 short_t targetDim() const { return this->coefDim(); }
287
289 short_t coefDim() const { return static_cast<short_t>(m_coefs.cols()); }
290
292 short_t geoDim() const { return this->coefDim(); }
293
295 virtual short_t domainDim() const;
296
298 short_t parDim() const;
299
301 short_t coDim() const;
302
304 gsMatrix<T> support() const;
305
308
310 //boxSide sideOf(const gsVector<T> & u); //
311
313
322 std::vector<boxSide> locateOn(const gsMatrix<T> & u, gsVector<bool> & onG2, gsMatrix<T> & preIm, bool lookForBoundary = false, real_t tol = 1.e-6) const; //
323
324 // Whether the coefficients of this geometry are stored in projective or affine form
325 //virtual bool isProjective() const = 0;
326
328
329 /*************************************************************************/
330
339 // todo: coefsSize() x (geoDim() + 1) if projective
340 gsMatrix<T> & coefs() { return this->m_coefs; }
341
343 const gsMatrix<T> & coefs() const { return this->m_coefs; }
344
346 typename gsMatrix<T>::RowXpr coef(index_t i) { return m_coefs.row(i); }
347
349 typename gsMatrix<T>::ConstRowXpr coef(index_t i) const { return m_coefs.row(i); }
350
353 {
354 GISMO_ASSERT( ((i < m_coefs.rows()) && (j < m_coefs.cols()) ),
355 "Coefficient or coordinate which is out of range requested.");
356 return m_coefs(i,j);
357 }
358
360 const T coef(index_t i, index_t j) const
361 {
362 GISMO_ASSERT( ((i < m_coefs.rows()) && (j < m_coefs.cols()) ),
363 "Coefficient or coordinate which is out of range requested.");
364 return m_coefs(i,j);
365 }
366
368 void setCoefs(gsMatrix<T> cc) { this->m_coefs.swap(cc); }
369
371 index_t coefsSize() const { return m_coefs.rows(); }
372 // Warning: This can cause some clash while using periodic basis, since the ghost coefs are stored but ignored.
373
374
375
377
378 /*************************************************************************/
379
389 {
390 this->m_coefs = this->m_coefs * mat.transpose();
391 }
392
394 void rotate(T angle, const gsVector<T,3> & axis )
395 {
396 assert( geoDim() == 3 );
397 gsEigen::Transform<T,3,gsEigen::Affine>
398 rot( gsEigen::AngleAxis<T> (angle,axis.normalized()) );
399 // To do: Simpler way to use transforms ?
400 this->m_coefs = (this->m_coefs.rowwise().homogeneous() *
401 rot.matrix().transpose() ).leftCols(3) ;
402 }
403
405 void rotate(T angle)
406 {
407 GISMO_ASSERT( geoDim() == 2, "Only for 2D");
408 gsEigen::Rotation2D<T> rot(angle);
409 this->m_coefs *= rot.matrix().transpose();
410 }
411
413 void scale(T s, int coord = -1)
414 {
415 if ( coord == -1) // Uniform scaling
416 this->m_coefs *= s;
417 else if ( coord <geoDim() )//scale coordinate coord
418 this->m_coefs.col(coord) *= s;
419 }
420
422 void scale(gsVector<T> const & v)
423 {
424 GISMO_ASSERT( v.rows() == this->m_coefs.cols(), "Sizes do not agree." );
425 this->m_coefs.array().rowwise() *= v.array().transpose();
426 }
427
429 void translate(gsVector<T> const & v)
430 {
431 this->m_coefs.rowwise() += v.transpose();
432 }
433
435 typename gsMatrix<T>::RowXpr
436 coefAtCorner(boxCorner const & c);
437
440 coefAtCorner(boxCorner const & c) const;
441
443
444 /*************************************************************************/
445
448
450 virtual void uniformRefine(int numKnots = 1, int mul = 1, short_t const dir = -1);
451
453 virtual void uniformCoarsen(int numKnots = 1); // todo: int dir = -1
454
460 void refineElements( std::vector<index_t> const & boxes );
461
462 void unrefineElements( std::vector<index_t> const & boxes );
463
464 typename gsGeometry::uPtr coord(const index_t c) const;
465
467 void embed3d()
468 {
469 embed(3);
470 }
471
476 void embed(index_t N, bool pad_right = true)
477 {
478 GISMO_ASSERT( N > 0, "Embed dimension must be positive");
479
480 const index_t nc = N - m_coefs.cols();
481 if ( nc == 0 ) return;
482
483 if (!pad_right && nc<0)
484 m_coefs.leftCols(N) = m_coefs.rightCols(N);
485 m_coefs.conservativeResize(gsEigen::NoChange, N);
486
487 if ( nc > 0 )
488 {
489 if (pad_right)
490 m_coefs.rightCols(nc).setZero();
491 else
492 {
493 m_coefs.rightCols(N-nc) = m_coefs.leftCols(N-nc);
494 m_coefs.leftCols(nc).setZero();
495 }
496 }
497# ifndef NDEBUG
498 else gsWarn<<"Coefficients projected (deleted)..\n";
499# endif
500 }
501
503 short_t degree(const short_t & i) const;
504
506 virtual void insertKnot( T knot, index_t dir, index_t i = 1);
507
511 virtual void degreeElevate(short_t const i = 1, short_t const dir = -1);
512
516 virtual void degreeIncrease(short_t const i = 1, short_t const dir = -1);
517
521 virtual void degreeReduce(short_t const i = 1, short_t const dir = -1);
522
526 virtual void degreeDecrease(short_t const i = 1, short_t const dir = -1);
527
530 virtual void hessian_into(const gsMatrix<T>& u, gsMatrix<T> & result,
531 index_t coord) const;
532
534 void controlNet( gsMesh<T> & mesh) const;
535
539 void outerNormal_into(const gsMatrix<T>& u, gsMatrix<T> & result) const;
540
542 std::vector<gsGeometry *> boundary() const;
543
545 virtual typename gsGeometry::uPtr boundary(boxSide const& s) const;
546
548 virtual typename gsGeometry::uPtr iface(const boundaryInterface & bi,
549 const gsGeometry & other) const;
550
552 typename gsGeometry::uPtr component(boxComponent const& bc) const;
553
554 GISMO_UPTR_FUNCTION_PURE(gsGeometry, clone)
555
556
557 virtual std::ostream &print(std::ostream &os) const;
558
560 virtual void merge( gsGeometry * other );
561
562 virtual void toMesh(gsMesh<T> & msh, int npoints) const;
563
564 typename gsGeometry::uPtr approximateLinearly() const;
565
572 void evaluateMesh(gsMesh<T>& mesh) const;
573
574
578 virtual std::vector<gsGeometry<T>* > uniformSplit(index_t dir =-1 ) const;
579
581
584 gsGeometrySlice<T> getIsoParametricSlice(index_t dir_fixed, T par) const;
585
588 T closestPointTo(const gsVector<T> & pt,
589 gsVector<T> & result,
590 const T accuracy = 1e-6,
591 const bool useInitialPoint = false) const;
592
597 const index_t nsamples = 1000,
598 const T accuracy = 1e-6) const;
599
601 T HausdorffDistance( const gsGeometry & other,
602 const index_t nsamples = 1000,
603 const T accuracy = 1e-6,
604 const bool directed=false) const;
605
607 void recoverPoints(gsMatrix<T> & xyz,
608 gsMatrix<T> & uv, index_t k,
609 const T accuracy) const;
610
612 void setId(const size_t i) { m_id = i; }
613
615 size_t id() const { return m_id; }
616
617protected:
618 void swap(gsGeometry & other)
619 {
620 std::swap(m_basis, other.m_basis);
621 m_coefs.swap(other.m_coefs);
622 std::swap(m_id, other.m_id);
623 }
624
625protected:
626
628 //todo: coefsSize() x (geoDim() + 1) if projective
630
633
636 size_t m_id;
637
638}; // class gsGeometry
639
641template<class T>
642std::ostream &operator<<(std::ostream &os, const gsGeometry<T>& b)
643{return b.print(os); }
644
645} // namespace gismo
646
647#include <gsCore/gsCurve.h>
648#include <gsCore/gsSurface.h>
649#include <gsCore/gsVolume.h>
650#include <gsCore/gsBulk.h>
651
652namespace gismo
653{
654
655// Generic traits for geometry with dimension known at compile time
656template <short_t d, typename T>
657struct gsGeoTraits
658{
659 typedef gsGeometry<T> GeometryBase;
660};
661
662// Traits for curve
663template <typename T>
664struct gsGeoTraits<1,T>
665{
666 typedef gsCurve<T> GeometryBase;
667};
668
669// Traits for surface
670template <typename T>
671struct gsGeoTraits<2,T>
672{
673 typedef gsSurface<T> GeometryBase;
674};
675
676// Traits for volume
677template <typename T>
678struct gsGeoTraits<3,T>
679{
680 typedef gsVolume<T> GeometryBase;
681};
682
683// Traits for bulk
684template <typename T>
685struct gsGeoTraits<4,T>
686{
687 typedef gsBulk<T> GeometryBase;
688};
689
690#ifdef GISMO_WITH_PYBIND11
691
695 void pybind11_init_gsGeometry(pybind11::module &m);
696
697#endif // GISMO_WITH_PYBIND11
698
699} // namespace gismo
700
701
702#ifndef GISMO_BUILD_LIB
703#include GISMO_HPP_HEADER(gsGeometry.hpp)
704#endif
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
uPtr clone()
Clone methode. Produceds a deep copy inside a uPtr.
A function from a n-dimensional domain to an m-dimensional image.
Definition gsFunction.h:60
virtual gsMatrix< T > parameterCenter() const
Returns a "central" point inside inside the parameter domain.
Definition gsFunction.h:261
gsGeometrySlice is a class representing an iso parametric slice of a geometry object....
Definition gsGeometrySlice.h:28
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
virtual void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate second derivatives of the function at points u into result.
Definition gsGeometry.hpp:174
gsMatrix< T > & coefs()
Definition gsGeometry.h:340
T HausdorffDistance(const gsGeometry &other, const index_t nsamples=1000, const T accuracy=1e-6, const bool directed=false) const
Computes the Hausdorff distance between *this to other.
Definition gsGeometry.hpp:377
std::vector< gsGeometry * > boundary() const
Get boundary of this geometry as a vector of new gsGeometry instances.
Definition gsGeometry.hpp:437
virtual void uniformCoarsen(int numKnots=1)
Coarsen the geometry uniformly, removing numKnots new knots into each knot span.
Definition gsGeometry.hpp:312
void scale(gsVector< T > const &v)
Apply Scaling coord-wise by a vector v.
Definition gsGeometry.h:422
gsMatrix< T >::RowXpr coefAtCorner(boxCorner const &c)
Returns the control point at corner c.
Definition gsGeometry.hpp:293
virtual void degreeElevate(short_t const i=1, short_t const dir=-1)
Elevate the degree by the given amount i for the direction dir. If dir is -1 then degree elevation is...
Definition gsGeometry.hpp:450
virtual void degreeIncrease(short_t const i=1, short_t const dir=-1)
Elevate the degree by the given amount i for the direction dir. If dir is -1 then degree elevation is...
Definition gsGeometry.hpp:476
void setCoefs(gsMatrix< T > cc)
Set the coefficient matrix of the geometry, taking ownership of the matrix.
Definition gsGeometry.h:368
void setId(const size_t i)
Sets the patch index for this patch.
Definition gsGeometry.h:612
void scale(T s, int coord=-1)
Apply Scaling by factor s.
Definition gsGeometry.h:413
gsMatrix< T >::RowXpr coef(index_t i)
Returns the i-th coefficient of the geometry as a row expression.
Definition gsGeometry.h:346
void translate(gsVector< T > const &v)
Apply translation by vector v.
Definition gsGeometry.h:429
short_t degree(const short_t &i) const
Returns the degree wrt direction i.
Definition gsGeometry.hpp:333
void embed(index_t N, bool pad_right=true)
Embeds coefficients in N dimensions For the new dimensions zeros are added (or removed) on the right ...
Definition gsGeometry.h:476
size_t id() const
Returns the patch index for this patch.
Definition gsGeometry.h:615
short_t coDim() const
Co-dimension of the geometric object.
Definition gsGeometry.hpp:187
void rotate(T angle)
Apply 2D Rotation by angle radians.
Definition gsGeometry.h:405
void evaluateMesh(gsMesh< T > &mesh) const
Definition gsGeometry.hpp:255
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition gsGeometry.h:100
std::vector< boxSide > locateOn(const gsMatrix< T > &u, gsVector< bool > &onG2, gsMatrix< T > &preIm, bool lookForBoundary=false, real_t tol=1.e-6) const
Get back the side of point u.
Definition gsGeometry.hpp:620
virtual void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result.
Definition gsGeometry.hpp:178
short_t targetDim() const
Dimension of the ambient physical space (overriding gsFunction::targetDim())
Definition gsGeometry.h:286
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsGeometry.hpp:166
virtual void merge(gsGeometry *other)
Merge the given other geometry into this one.
Definition gsGeometry.hpp:420
gsGeometry()
Default constructor. Note: Derived constructors (except for the default) should assign m_basis to a v...
Definition gsGeometry.h:111
virtual void hessian_into(const gsMatrix< T > &u, gsMatrix< T > &result, index_t coord) const
Definition gsGeometry.hpp:502
virtual void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition gsGeometry.hpp:553
virtual std::vector< gsGeometry< T > * > uniformSplit(index_t dir=-1) const
Definition gsGeometry.hpp:280
void outerNormal_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Computes the outer normals at parametric points u.
Definition gsGeometry.hpp:433
short_t geoDim() const
Dimension n of the absent physical space.
Definition gsGeometry.h:292
void recoverPoints(gsMatrix< T > &xyz, gsMatrix< T > &uv, index_t k, const T accuracy) const
Recovers the points of the geometry from the given points xyz and parameters uv.
Definition gsGeometry.hpp:393
virtual void degreeReduce(short_t const i=1, short_t const dir=-1)
Reduces the degree by the given amount i for the direction dir. If dir is -1 then degree reduction is...
Definition gsGeometry.hpp:463
short_t coefDim() const
Dimension n of the coefficients (control points)
Definition gsGeometry.h:289
T directedHausdorffDistance(const gsGeometry &other, const index_t nsamples=1000, const T accuracy=1e-6) const
Definition gsGeometry.hpp:360
int orientation() const
Evaluates if the geometry orientation coincide with the ambient orientation. This is computed in the ...
Definition gsGeometry.h:260
virtual short_t domainDim() const
Dimension d of the parameter domain (overriding gsFunction::domainDim()).
Definition gsGeometry.hpp:184
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
virtual gsGeometry::uPtr iface(const boundaryInterface &bi, const gsGeometry &other) const
Computes and returns the interface with other as a new geometry.
Definition gsGeometry.hpp:232
gsGeometry::uPtr component(boxComponent const &bc) const
Get parametrization of box component bc as a new gsGeometry uPtr.
Definition gsGeometry.hpp:240
virtual void uniformRefine(int numKnots=1, int mul=1, short_t const dir=-1)
Refine the geometry uniformly, inserting numKnots new knots into each knot span.
Definition gsGeometry.hpp:306
short_t parDim() const
Dimension d of the parameter domain (same as domainDim()).
Definition gsGeometry.hpp:190
virtual void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition gsGeometry.hpp:170
gsBasis< T > * m_basis
Pointer to the basis of this geometry.
Definition gsGeometry.h:632
gsMatrix< T > support() const
Returns the range of parameters (same as parameterRange())
Definition gsGeometry.hpp:193
void rotate(T angle, const gsVector< T, 3 > &axis)
Apply 3D Rotation by angle radians around axis axis.
Definition gsGeometry.h:394
T closestPointTo(const gsVector< T > &pt, gsVector< T > &result, const T accuracy=1e-6, const bool useInitialPoint=false) const
Definition gsGeometry.hpp:339
const gsMatrix< T > & coefs() const
Returns the coefficient matrix of the geometry.
Definition gsGeometry.h:343
memory::shared_ptr< gsGeometry > Ptr
Shared pointer for gsGeometry.
Definition gsGeometry.h:97
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition gsGeometry.h:629
size_t m_id
Definition gsGeometry.h:636
void linearTransform(const gsMatrix< T > &mat)
Apply the given square matrix to every control point.
Definition gsGeometry.h:388
virtual std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsGeometry.hpp:410
void controlNet(gsMesh< T > &mesh) const
Return the control net of the geometry.
Definition gsGeometry.hpp:538
gsGeometrySlice< T > getIsoParametricSlice(index_t dir_fixed, T par) const
Definition gsGeometry.hpp:286
index_t coefsSize() const
Return the number of coefficients (control points)
Definition gsGeometry.h:371
const T coef(index_t i, index_t j) const
Returns the j-th coordinate of the i-th coefficient of the geometry.
Definition gsGeometry.h:360
virtual gsBasis< T > & basis()=0
Returns a reference to the basis of the geometry.
T & coef(index_t i, index_t j)
Returns the j-th coordinate of the i-th coefficient of the geometry.
Definition gsGeometry.h:352
void refineElements(std::vector< index_t > const &boxes)
Refines the basis and adjusts the coefficients to keep the geometry the same.
Definition gsGeometry.hpp:318
virtual void insertKnot(T knot, index_t dir, index_t i=1)
Inserts knot knot at direction dir, i times.
Definition gsGeometry.hpp:444
gsMatrix< T >::ConstRowXpr coef(index_t i) const
Returns the i-th coefficient of the geometry as a row expression.
Definition gsGeometry.h:349
virtual void degreeDecrease(short_t const i=1, short_t const dir=-1)
Reduces the degree by the given amount i for the direction dir. If dir is -1 then degree reduction is...
Definition gsGeometry.hpp:489
gsMatrix< T > parameterRange() const
Returns the range of parameters as a matrix with two columns, [lower upper].
Definition gsGeometry.hpp:198
void embed3d()
Embeds coefficients in 3D.
Definition gsGeometry.h:467
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Provides structs and classes related to interfaces and boundaries.
Provides declaration of a 4D bulk.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
Provides declaration of Curve abstract interface.
#define gsWarn
Definition gsDebug.h:50
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Provides declaration of Function abstract interface.
Provides declaration of Surface abstract interface.
Provides declaration of Volume abstract interface.
The G+Smo namespace, containing all definitions for the library.
Struct which represents an interface between two patches.
Definition gsBoundary.h:650
Struct which represents a certain component (interior, face, egde, corner).
Definition gsBoundary.h:445
Struct which represents a certain corner of a hyper-cube.
Definition gsBoundary.h:292