35 : m_g(&g), m_pt(&pt), m_gd(2) { }
40 m_g->eval_into(u, m_gd[0]);
41 result.resize(1, u.cols());
42 result.
at(0) = 0.5 * (m_gd[0]-*m_pt).squaredNorm();
47 bool sameElement =
false)
const
51 m_g->evalAllDers_into(u, n, m_gd, sameElement);
54 result[0].resize(1, 1);
55 result[0].at(0) = 0.5 * (m_gd[0]-*m_pt).squaredNorm();
59 auto jacT = m_gd[1].reshaped(u.rows(),m_pt->rows());
60 result[1].noalias() = jacT * (m_gd[0] - *m_pt);
64 tmp.noalias() = jacT * jacT.transpose();
65 index_t d2 = u.rows() * (u.rows()+1) / 2;
67 for (
index_t k=0; k < m_g->coefs().cols(); ++k )
69 hm = util::secDerToHessian(m_gd[2].block(k*d2,0,d2,1),u.rows()).reshaped(u.rows(),u.rows());
70 tmp += (m_gd[0].at(k)-m_pt->
at(k)) * hm;
72 util::hessianToSecDer(tmp,u.rows(),result[2]);
78 result.resize(u.rows(), u.cols());
79 for (
index_t i=0; i != u.cols(); i++ )
82 m_g->eval_into(tmp,m_gd[0]);
83 m_g->jacobian_into(tmp,m_gd[1]);
84 result.col(i).noalias() = m_gd[1].transpose() * (m_gd[0] - *m_pt);
92 m_g->eval_into(u,m_gd[0]);
93 m_g->jacobian_into(u,m_gd[1]);
94 result.noalias() = m_gd[1].transpose() * m_gd[1];
95 for (
index_t k=0; k < m_g->coefs().cols(); ++k )
97 tmp = m_g->hessian(u,k);
98 result.noalias() += (m_gd[0].at(k)-m_pt->
at(k))*tmp;
102 gsMatrix<T> support()
const {
return m_g->support() ;}
109 mutable std::vector<gsMatrix<T> > m_gd;
158 : m_coefs(o.m_coefs), m_basis(o.m_basis != NULL ? o.basis().clone().
release() : NULL), m_id(o.m_id)
162 gsGeometry<T>::~gsGeometry()
167 { this->basis().evalFunc_into(u, m_coefs, result); }
171 { this->basis().derivFunc_into(u, m_coefs, result); }
175 { this->basis().deriv2Func_into(u, m_coefs, result); }
180 bool sameElement)
const
181 { this->basis().evalAllDersFunc_into(u, m_coefs, n, result, sameElement); }
194 {
return this->basis().support(); }
199 {
return this->basis().support(); }
208 m_basis = o.
basis().clone().release() ;
221 for (
index_t i=0; i != ind.size(); i++ )
223 coeffs.row(i) = m_coefs.row( ind(i,0) );
243 typename gsBasis<T>::uPtr Bs = this->basis().componentBasis_withIndices(bc, ind,
false);
246 for (
index_t i=0; i != ind.size(); i++ )
248 coefs.row(i) = m_coefs.row( ind(i,0) );
257 const int pDim = parDim();
258 const int gDim = geoDim();
264 if (1==gDim && 3>pDim)
265 for (
size_t i = 0; i!= mesh.numVertices(); ++i)
267 eval_into( mesh.vertex(i).topRows(pDim), tmp );
268 mesh.vertex(i).middleRows(pDim, gDim) = tmp;
271 for (
size_t i = 0; i!= mesh.numVertices(); ++i)
273 eval_into( mesh.vertex(i).topRows(pDim), tmp );
274 const index_t gd = math::min(3,gDim);
275 mesh.vertex(i).topRows(gd) = tmp.topRows(gd);
295 return this->m_coefs.row(this->basis().functionAtCorner(c));
302 return this->m_coefs.row(this->basis().functionAtCorner(c));
308 this->basis().uniformRefine_withCoefs( m_coefs, numKnots, mul, dir);
314 this->basis().uniformCoarsen_withCoefs( m_coefs, numKnots);
320 this->basis().refineElements_withCoefs(this->m_coefs, boxes );
326 this->basis().unrefineElements_withCoefs(this->m_coefs, boxes );
330 inline typename gsGeometry<T>::uPtr gsGeometry<T>::coord(
const index_t c)
const {
return this->basis().makeGeometry( this->coefs().col(c) ); }
335 {
return this->basis().degree(i); }
342 const bool useInitialPoint)
const
344 GISMO_ASSERT( pt.rows() == targetDim(),
"Invalid input point." <<
345 pt.rows() <<
"!="<< targetDim() );
348 gsMinimizer<T> fmin(dist2);
350 result = fmin.currentDesign();
353 result = useInitialPoint ? dist2.argMin(accuracy*accuracy, 100, result)
354 : dist2.argMin(accuracy*accuracy, 100) ;
356 return math::sqrt( dist2.
eval(result).value() );
363 gsMatrix<T> uv = gsPointGrid<T>(this->support(),nsamples);
365 this->eval_into(uv,pts);
367 T maxDist=std::numeric_limits<T>::min();
369 for (
index_t k=0; k!=pts.cols(); k++)
371 maxDist = std::max(maxDist,other.
closestPointTo(pts.col(k),tmp,accuracy,
false));
373 return math::sqrt(2*maxDist);
379 T this2other, other2this;
380 this2other = this->directedHausdorffDistance(other,nsamples,accuracy);
386 return std::max(other2this,this2other);
398 os <<
"Geometry "<<
"R^"<< this->parDim() <<
399 " --> R^"<< this->geoDim()<<
", #control pnts= "<< coefsSize() <<
400 ": "<< coef(0) <<
" ... "<< coef(this->coefsSize()-1);
401 os<<
"\nBasis:\n" << this->basis();
414 typename gsGeometry<T>::uPtr
415 gsGeometry<T>::approximateLinearly()
const
441 this->eval_into(iPts, iVals);
444 std::swap(m_basis, g->
m_basis);
445 g->
coefs().swap(this->coefs());
454 this->eval_into(iPts, iVals);
457 std::swap(m_basis, g->
m_basis);
458 g->
coefs().swap(this->coefs());
467 this->eval_into(iPts, iVals);
470 std::swap(m_basis, g->
m_basis);
471 g->
coefs().swap(this->coefs());
480 this->eval_into(iPts, iVals);
483 std::swap(m_basis, g->
m_basis);
484 g->
coefs().swap(this->coefs());
487 template<
class T>
void
491 const unsigned d = this->domainDim();
492 GISMO_ASSERT( coord<targetDim(),
"Invalid coordinate function "<<coord);
500 m_basis->deriv2_into(u, B) ;
502 m_basis->active_into(u, ind);
508 for (
index_t i=0; i< ind.rows() ; i++ )
510 unsigned r = i*d*(d+1)/2;
513 for (
unsigned k=0; k<d; ++k )
516 for (
unsigned l=k+1; l<d; ++l )
517 tmp(k,l) = tmp(l,k) = B(r + m++,0);
519 result += C(ind(i,j), coord) * tmp;
525 { basis().connectivity(m_coefs, mesh); }
529 template <
typename T>
532 out.resize(actives.rows(), in.cols());
533 for (
index_t r=0; r<actives.rows();++r)
534 out.row(r)=in.row(actives(r,0));
542 const index_t numPt = in.cols();
543 const index_t numCo = m_coefs.cols();
545 gsFuncData<T> tmp(flags);
546 this->basis().compute(in, tmp);
548 out.values.resize(out.maxDeriv()+1);
549 out.dim.first = tmp.dim.first;
550 out.dim.second = numCo;
554 extractRows(m_coefs,tmp.active(0),coefM);
557 out.values[0].noalias()=coefM.transpose()*tmp.values[0];
560 const index_t derS = tmp.derivSize();
561 out.values[1].resize(derS*numCo,numPt);
562 for (
index_t p=0; p< numPt; ++p)
563 out.values[1].reshapeCol(p, derS, numCo).noalias() = tmp.deriv(p)*coefM;
567 const index_t derS = tmp.deriv2Size();
568 out.values[2].resize(derS*numCo,numPt);
569 for (
index_t p=0; p< numPt; ++p)
570 out.values[2].reshapeCol(p, derS, numCo).noalias() = tmp.deriv2(p)*coefM;
573 this->active_into(in.col(0), out.actives);
578 const index_t derS = tmp.derivSize();
579 const index_t der2S = tmp.deriv2Size();
581 if (flags &
NEED_VALUE) out.values[0].resize(numCo,numPt);
582 if (flags &
NEED_DERIV) out.values[1].resize(numCo*derS,numPt);
583 if (flags &
NEED_DERIV2) out.values[2].resize(numCo*der2S,numPt);
584 if (flags &
NEED_ACTIVE) this->active_into(in, out.actives);
588 extractRows(m_coefs,tmp.active(p),coefM);
589 if (flags & NEED_VALUE)
590 out.values[0].reshapeCol(p,1,numCo).noalias() = tmp.eval(p)*coefM;
591 if (flags & NEED_DERIV)
592 out.values[1].reshapeCol(p, derS, numCo).noalias() = tmp.deriv(p)*coefM;
593 if (flags & NEED_DERIV2)
594 out.values[2].reshapeCol(p, der2S, numCo).noalias() = tmp.deriv2(p)*coefM;
608 onGeo.resize(u.cols());
609 std::vector<boxSide> sides(u.cols());
611 for(
index_t i = 0; i < onGeo.size(); i++)
614 preIm.resize(geoDim(), u.cols());
617 for(
index_t i = 0; i < u.cols(); i++)
619 this->invertPoints(u.col(i), tmp, tol);
620 pr = this->parameterRange();
623 if ((tmp.array() >= pr.col(0).array() - 1.e-4).all()
624 && (tmp.array() <= pr.col(1).array() + 1.e-4).all())
632 if (lookForBoundary ==
true)
635 for (
int d = 0; d < geoDim(); d++) {
636 if ((
math::abs(tmp(d, 0) - pr(d, 0)) < tol))
642 if ((
math::abs(tmp(d, 0) - pr(d, 1)) < tol))
virtual void compute(const gsMatrix< T > &in, gsFuncData< T > &out) const
Computes function data.
Definition: gsGeometry.hpp:539
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:606
virtual std::vector< gsGeometry< T > * > uniformSplit(index_t dir=-1) const
Definition: gsGeometry.hpp:280
gsGeometry()
Default constructor. Note: Derived constructors (except for the default) should assign m_basis to a v...
Definition: gsGeometry.h:111
void evaluateMesh(gsMesh< T > &mesh) const
Definition: gsGeometry.hpp:255
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
gsMatrix< T > m_coefs
Coefficient matrix of size coefsSize() x geoDim()
Definition: gsGeometry.h:624
std::vector< T * > release(std::vector< unique_ptr< T > > &cont)
Takes a vector of smart pointers, releases them and returns the corresponding raw pointers...
Definition: gsMemory.h:228
void controlNet(gsMesh< T > &mesh) const
Return the control net of the geometry.
Definition: gsGeometry.hpp:524
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
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
Gradient of the object.
Definition: gsForwardDeclarations.h:73
gsMatrix< T > parameterRange() const
Returns the range of parameters as a matrix with two columns, [lower upper].
Definition: gsGeometry.hpp:198
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:45
gsBasis< T > * m_basis
Pointer to the basis of this geometry.
Definition: gsGeometry.h:627
virtual void degreeIncrease(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve knots multiplicity. ...
Definition: gsBasis.hpp:588
short_t domainDim() const
Dimension of the (source) domain.
Definition: gsGeometry.hpp:103
#define short_t
Definition: gsConfig.h:35
void outerNormal_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Computes the outer normals at parametric points u.
Definition: gsGeometry.hpp:419
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
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:436
short_t degree(const short_t &i) const
Returns the degree wrt direction i.
Definition: gsGeometry.hpp:333
Provides declaration of Basis abstract interface.
S give(S &x)
Definition: gsMemory.h:266
gsMatrix< T > eval(const gsMatrix< T > &u) const
Evaluate the function,.
Definition: gsFunctionSet.hpp:120
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:449
Second derivatives.
Definition: gsForwardDeclarations.h:80
#define index_t
Definition: gsConfig.h:32
A function from a n-dimensional domain to an m-dimensional image.
Definition: gsFunction.h:59
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
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate derivatives of the function at points u into result.
Definition: gsGeometry.hpp:76
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:462
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
virtual void insertKnot(T knot, index_t dir, index_t i=1)
Inserts knot knot at direction dir, i times.
Definition: gsGeometry.hpp:430
virtual void merge(gsGeometry *other)
Merge the given other geometry into this one.
Definition: gsGeometry.hpp:406
Squared distance function from a fixed point to a gsGeometry.
Definition: gsGeometry.hpp:31
Class Representing a triangle mesh with 3D vertices.
Definition: gsMesh.h:31
memory::unique_ptr< gsGeometry< T > > interpolateData(gsMatrix< T > const &vals, gsMatrix< T > const &pts) const
Applies interpolation given the parameter values pts and values vals.
Definition: gsBasis.hpp:217
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition: gsMatrix.h:211
virtual std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsGeometry.hpp:396
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
virtual void degreeDecrease(short_t const &i=1, short_t const dir=-1)
Lower the degree of the basis by the given amount, preserving knots multiplicity. ...
Definition: gsBasis.hpp:592
gsMatrix< T > anchors() const
Returns the anchor points that represent the members of the basis. There is exactly one anchor point ...
Definition: gsBasis.h:437
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
short_t coDim() const
Co-dimension of the geometric object.
Definition: gsGeometry.hpp:187
virtual short_t domainDim() const
Dimension d of the parameter domain (overriding gsFunction::domainDim()).
Definition: gsGeometry.hpp:184
std::vector< gsGeometry * > boundary() const
Get boundary of this geometry as a vector of new gsGeometry instances.
Definition: gsGeometry.hpp:423
Active function ids.
Definition: gsForwardDeclarations.h:84
virtual memory::unique_ptr< gsGeometry< T > > makeGeometry(gsMatrix< T > coefs) const =0
Create a gsGeometry of proper type for this basis with the given coefficient matrix.
gsGeometrySlice is a class representing an iso parametric slice of a geometry object. It stores a pointer to the geometry object, which is only valid as long as this object is alive. Methods for printing to paraview are available in gsWriteToParaview.h
Definition: gsGeometrySlice.h:27
virtual void uniformRefine(int numKnots=1, int mul=1, int dir=-1)
Refine the geometry uniformly, inserting numKnots new knots into each knot span.
Definition: gsGeometry.hpp:306
T at(index_t i) const
Returns the i-th element of the vector.
Definition: gsVector.h:177
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
short_t parDim() const
Dimension d of the parameter domain (same as domainDim()).
Definition: gsGeometry.hpp:190
gsGeometry & operator=(const gsGeometry &o)
Definition: gsGeometry.hpp:202
Provides declaration of the Mesh class.
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition: gsGeometry.h:100
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
Enable optimizations based on the assumption that all evaluation points are in the same bezier domain...
Definition: gsForwardDeclarations.h:89
memory::unique_ptr< gsBasis > uPtr
Unique pointer for gsBasis.
Definition: gsBasis.h:89
Provides definition of the FuncCoordinate class.
T closestPointTo(const gsVector< T > &pt, gsVector< T > &result, const T accuracy=1e-6, const bool useInitialPoint=false) const
Definition: gsGeometry.hpp:339
short_t m_index
Index of the side.
Definition: gsBoundary.h:92
gsMatrix< T > support() const
Returns the range of parameters (same as parameterRange())
Definition: gsGeometry.hpp:193
Value of the object.
Definition: gsForwardDeclarations.h:72
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 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:475
Provides functions to generate structured point data.
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition: gsGeometry.hpp:38
short_t targetDim() const
Dimension of the target space.
Definition: gsGeometry.hpp:104
virtual void degreeElevate(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve smoothness.
Definition: gsBasis.hpp:580
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4488
gsGeometry::uPtr component(boxComponent const &bc) const
Get parametrization of box component bc as a new gsGeometry uPtr.
Definition: gsGeometry.hpp:240
gsGeometrySlice< T > getIsoParametricSlice(index_t dir_fixed, T par) const
Definition: gsGeometry.hpp:286
Struct which represents an interface between two patches.
Definition: gsBoundary.h:649
virtual void hessian_into(const gsMatrix< T > &u, gsMatrix< T > &result, index_t coord) const
Definition: gsGeometry.hpp:488
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
This object is a cache for computed values from an evaluator.
size_t m_id
Definition: gsGeometry.h:631
Struct which represents a certain corner of a hyper-cube.
Definition: gsBoundary.h:291
T directedHausdorffDistance(const gsGeometry &other, const index_t nsamples=1000, const T accuracy=1e-6) const
Definition: gsGeometry.hpp:360
Provides declaration of the gsGeometrySlice class.
virtual void uniformCoarsen(int numKnots=1)
Coarsen the geometry uniformly, removing numKnots new knots into each knot span.
Definition: gsGeometry.hpp:312
gsMatrix< T > & coefs()
Definition: gsGeometry.h:340
Struct which represents a certain component (interior, face, egde, corner).
Definition: gsBoundary.h:445
virtual void degreeReduce(short_t const &i=1, short_t const dir=-1)
Reduce the degree of the basis by the given amount, preserve smoothness.
Definition: gsBasis.hpp:584