G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMPBESMapB2D.h
Go to the documentation of this file.
1 
14 // This class gsMPBESMapB2D has the sole purpose of creating a mapping of the type gsWeightMapper
15 
16 #pragma once
17 
18 #include <gsCore/gsBasis.h>
19 #include <gsCore/gsBoxTopology.h>
20 #include <gsNurbs/gsKnotVector.h>
21 
24 
25 #define TO_BSPLINE(x) static_cast<const gsTensorBSplineBasis<d,T> *>(x)
26 
27 namespace gismo
28 {
29 
38 template<short_t d,class T>
39 class gsMPBESMapB2D : public gsMPBESMapTensor<d,T>
40 {
41  //static const index_t d = 2;
42 private:
43  typedef gsBasis<T> BasisType;
45 public:
46  gsMPBESMapB2D(index_t incrSmoothnessDegree, gsBoxTopology * topol, gsMPBESBasis<d,T> * basis) :
47  Base(incrSmoothnessDegree,topol,basis)
48  { }
49 
50  ~gsMPBESMapB2D() { }
51 
52 private:
53  using Base::m_incrSmoothnessDegree;
54  using Base::m_topol;
55  using Base::m_basis;
56  using Base::m_mapper;
57  using Base::m_global;
58  using Base::_setTensorMappingOfPatch;
59  using Base::_getPatch;
60  using Base::_getPatchIndex;
61  using Base::_getLocalIndex;
62 
63 private:
65  // general help functions for checking, finalizing and building of the mapping
67 
68  bool _checkMapping() const
69  {
70  bool consistent = true;
71 // for(index_t i=0;i<m_local_to_global.rows();i++)
72 // {
73 // IndexContainer globals = _local2global(i);
74 // index_t size=globals.size();
75 // if(size!=1&&size!=2&&(size!=degree(0)&&size!=degree(1))&&size>degree(0)&&size>degree(1))
76 // {
82 // }
83 // }
84 // for(index_t i=0;i<m_local_to_global.cols();i++)
85 // {
86 // IndexContainer locals = _global2local(i);
87 // index_t size=locals.size();
88 // if(size!=1&&size!=4)
89 // {
90 // std::cout << "Error in " << i << ".th col:";
91 // print(std::cout,-1,i);
92 // std::cout << std::endl;
93 // //GISMO_ERROR("mapping wrong");
94 // }
95 // }
96  return consistent;
97  }
98 
99  void _finalize() const
100  {
101  gsSparseMatrix<T> mat=m_mapper->asMatrix();
102  mat.conservativeResize(mat.rows(),m_global);
103  delete m_mapper;
104  m_mapper=new gsWeightMapper<T>(mat);
105  m_mapper->optimize(gsWeightMapper<T>::optTargetToSource);
106  }
107 
108  void _setMappingOfPatch(index_t const patch) const
109  {
110  _setTensorMappingOfPatch(patch);
111  }
112 
113  index_t getDistanceOfVertex(const patchCorner& pc,const patchSide& ps) const
114  {
115  std::vector<T> endpoints;
116  T parametricDistance = m_basis->getParametricDistanceOfVertex(pc,ps);
117  index_t patch = ps.patch;
118 
119  if(math::almostEqual<T>(parametricDistance,0.0))
120  return 0;
121 
122  index_t deg = m_basis->degree(patch,1-(ps.direction()));
123  gsKnotVector<T> knots = TO_BSPLINE(&(m_basis->getBase(patch)))->knots(1-(ps.direction()));
124  gsVector<bool> pars;
125  pc.parameters_into(d,pars);
126  if(!pars(1-ps.direction()))
127  knots.reverse();
128  for(size_t i = deg+1;i<knots.size();i++)
129  endpoints.push_back(knots.at(i));
130  std::sort(endpoints.begin(),endpoints.end());
131  index_t nr=0;
132  for(;nr<(index_t)(endpoints.size());nr++)
133  if(math::almostEqual<T>(endpoints[nr],parametricDistance)||endpoints[nr]>=parametricDistance)
134  break;
135  return nr+1;
136  }
137 
138 
139 private:
141  // functions calculating the weights for the mapping
143 
144  gsKnotVector<T> _getKnotVector(index_t const patch,index_t const par) const
145  {
146  return TO_BSPLINE(&(m_basis->getBase(patch)))->knots(par);
147  }
148 
149  index_t _getParMax(index_t patch,bool par) const
150  {
151  return TO_BSPLINE(&(m_basis->getBase(patch)))->size(par)-1;
152  }
153 
154 private:
156  // functions for working with Indexes
158 
159  bool _getLocalIndex_into(index_t const patch,index_t const u,index_t const v,index_t & localIndex) const
160  {
161  localIndex=_getLocalIndex(patch,u,v);
162  return true;
163  }
164 
165  index_t _getLocalIndex(index_t const patch,index_t u, index_t v) const
166  {
167  return _getLocalIndex(patch,_getPatchIndex(patch,u,v));
168  }
169 
170  index_t _getPatchIndex(index_t const patch,boxSide const side,bool const flag) const
171  {
172  index_t u_amount=_getParMax(patch,0);
173  index_t v_amount=_getParMax(patch,1);
174  if(side.direction())
175  if(side.parameter())
176  return _getPatchIndex(patch,flag?u_amount:0,v_amount);
177  else
178  return _getPatchIndex(patch,flag?u_amount:0,0);
179  else
180  if(side.parameter())
181  return _getPatchIndex(patch,u_amount,flag?v_amount:0);
182  else
183  return _getPatchIndex(patch,0,flag?v_amount:0);
184  }
185 
186  index_t _getPatchIndex(index_t const patch,index_t const u,index_t const v) const
187  {
189  vec(0)=u,vec(1)=v;
190  return TO_BSPLINE(&(m_basis->getBase(patch)))->index(vec);
191  }
192 
193  index_t _getPar(index_t localIndex,bool par) const
194  {
195  return _getPar(_getPatch(localIndex),_getPatchIndex(localIndex),par);
196  }
197 
198  index_t _getPar(index_t patch,index_t patchIndex, bool par) const
199  {
200  gsVector<index_t,d> vec = TO_BSPLINE(&(m_basis->getBase(patch)))->tensorIndex(patchIndex);
201  return vec(par);
202  }
203 };
204 
205 }
206 
207 #undef TO_BSPLINE
Knot vector for B-splines.
void parameters_into(index_t dim, gsVector< bool > &param) const
returns a vector of parameters describing the position of the corner
Definition: gsBoundary.h:322
Provides declaration of Basis abstract interface.
Struct which represents a certain side of a patch.
Definition: gsBoundary.h:231
Provides declaration of the BoxTopology class.
bool parameter() const
Returns the parameter value (false=0=start, true=1=end) that corresponds to this side.
Definition: gsBoundary.h:128
A univariate Lagrange basis.
Definition: gsMPBESMapTensor.h:32
Provides declaration of Basis abstract interface.
size_t size() const
Number of knots (including repetitions).
Definition: gsKnotVector.h:242
#define index_t
Definition: gsConfig.h:32
Struct which represents a certain corner of a patch.
Definition: gsBoundary.h:392
A univariate Lagrange basis.
Definition: gsMPBESMapB2D.h:39
Provides declaration of Basis abstract interface.
Purely abstract class gsMappedBasis, which gives means of combining basis functions to new...
Definition: gsMPBESBasis.h:46
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
T at(const size_t &i) const
Returns the value of the i - th knot (counted with repetitions).
Definition: gsKnotVector.h:865
void reverse()
Better directly use affineTransformTo.
Definition: gsKnotVector.hpp:468
Class for representing a knot vector.
Definition: gsKnotVector.h:79
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 patch
The index of the patch.
Definition: gsBoundary.h:234
short_t direction() const
Returns the parametric direction orthogonal to this side.
Definition: gsBoundary.h:113
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78