G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsMPBESMapHB2D.h
Go to the documentation of this file.
1
14// This class gsMPBESMapHB2D has the sole purpose of creating a mapping of the type gsWeightMapper
15
16#pragma once
17
18#include <gsCore/gsBasis.h>
21
24
25#define TO_HTENSOR(x) static_cast<const gsHTensorBasis<d,T> *>(x)
26#define TO_BSPLINE(x) static_cast<const gsTensorBSplineBasis<d,T> *>(x)
27
28namespace gismo
29{
30
39template<short_t d,class T>
41{
42 //static const index_t d = 2;
43private:
44 typedef gsBasis<T> BasisType;
46public:
47 gsMPBESMapHB2D(index_t incrSmoothnessDegree, gsBoxTopology * topol, gsMPBESBasis<d,T> * basis) :
48 Base(incrSmoothnessDegree,topol,basis)
49 { }
50
51 ~gsMPBESMapHB2D() { }
52
53private:
54 using Base::m_basis;
55 using Base::m_incrSmoothnessDegree;
56 using Base::m_topol;
57 using Base::m_mapper;
58 using Base::m_global;
59 using Base::_setTensorMappingOfPatch;
60 using Base::_getPatch;
61 using Base::_getPatchIndex;
62 using Base::_getLocalIndex;
63
64private:
66 // general help functions for checking, finalizing and building of the mapping
68
69 bool _checkMapping() const
70 {
71 return true;
72 }
73
74 void _finalize() const
75 {
76 m_level = _getMaxLevel();
77 gsSparseMatrix<T> mat=m_mapper->asMatrix();
78 mat.conservativeResize(mat.rows(),m_global);
79 delete m_mapper;
80 m_mapper=new gsWeightMapper<T>(mat);
81 m_mapper->optimize(gsWeightMapper<T>::optTargetToSource);
82 }
83
84 void _setMappingOfPatch(index_t const patch) const
85 {
86 m_level=0;
87 for(index_t i = 0;i<=_getMaxLevel();i++)
88 {
89 if(m_level<=_getMaxLevel(patch))
90 _setTensorMappingOfPatch(patch);
91 m_level++;
92 }
93 }
94
95 index_t _getMaxLevel() const
96 {
97 index_t level = 0;
98 for (size_t i = 0; i < m_basis->nPatches(); i++)
99 {
100 level = std::max(level, _getMaxLevel(i));
101 }
102 return level;
103 }
104
105 index_t _getMaxLevel(index_t patch) const
106 {
107 return TO_HTENSOR(&(m_basis->getBase(patch)))->maxLevel();
108 }
109
110
111 index_t getDistanceOfVertex(const patchCorner& pc,const patchSide& ps) const
112 {
113 std::vector<T> endpoints;
114 T parametricDistance = m_basis->getParametricDistanceOfVertex(pc,ps);
115 if(math::almostEqual<T>(parametricDistance,0.0))
116 return 0;
117 index_t patch = ps.patch;
118 index_t deg = m_basis->degree(patch,1-ps.direction());
119 gsTensorBSplineBasis<d,T>* basis = TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[m_level];
120 gsKnotVector<T> knots = basis->knots(1-(ps.direction()));
121 gsVector<bool> pars;
122 pc.parameters_into(d,pars);
123 if(!pars(1-ps.direction()))
124 knots.reverse();
125 for(size_t i = deg+1;i<knots.size();i++)
126 endpoints.push_back(knots.at(i));
127 std::sort(endpoints.begin(),endpoints.end());
128 index_t nr=0;
129 for(;nr<(index_t)(endpoints.size());nr++)
130 if(math::almostEqual<T>(endpoints[nr],parametricDistance)||endpoints[nr]>=parametricDistance)
131 break;
132 return nr+1;
133 }
134
135private:
137 // functions calculating the weights for the mapping
139
140 gsKnotVector<T> _getKnotVector(index_t const patch,index_t const par) const
141 {// todo: remove
142 gsKnotVector<T> kvComp = TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[m_level]->knots(par);
143 return gsKnotVector<T>(kvComp);
144 }
145
146 index_t _getParMax(index_t patch,bool par) const
147 {
148 return TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[m_level]->size(par)-1;
149 }
150
151private:
153 // functions for working with Indexes
155 // localIndex = hierachical index of hierachical splines collected over all patches.
156
157 bool _getLocalIndex_into(index_t const patch,index_t const u,index_t const v,index_t & localIndex) const
158 {
159 index_t patchIndex = _getPatchIndex(patch,u,v);
160 localIndex=_getLocalIndex(patch,patchIndex);
161 if(patchIndex==-1)
162 return false;
163 else
164 return true;
165 }
166
167 index_t _getLocalIndex(index_t const patch,index_t u, index_t v) const
168 {
169 return _getLocalIndex(patch,_getPatchIndex(patch,u,v));
170 }
171
172 index_t _getPatchIndex(index_t const patch,boxSide const side,bool const flag) const
173 {
174 index_t u,v;
175 index_t level = 0;
177 index_t index, patchindex;
178 do
179 {
180 if(level>(index_t)(TO_HTENSOR(&(m_basis->getBase(patch)))->maxLevel()))
181 GISMO_ERROR("did not find the patchindex");
182
183 const index_t u_amount=TO_HTENSOR(&(m_basis->getBase(patch)))->tensorLevel(level).size(0);
184 const index_t v_amount=TO_HTENSOR(&(m_basis->getBase(patch)))->tensorLevel(level).size(1);
185 if(side.direction())
186 if(side.parameter())
187 {
188 u=flag ? (u_amount-1) : 0;
189 v=v_amount-1;
190 }
191 else
192 {
193 u=flag ? (u_amount-1) :0;
194 v=0;
195 }
196 else
197 if(side.parameter())
198 {
199 u=u_amount-1;
200 v=flag ? (v_amount-1) : 0;
201 }
202 else
203 {
204 u=0;
205 v=flag ? (v_amount-1) : 0;
206 }
207 vec(0)=u,vec(1)=v;
208 index=TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[level]->index(vec);
209 patchindex=TO_HTENSOR(&(m_basis->getBase(patch)))->flatTensorIndexToHierachicalIndex(index,level);
210 level++;
211 }while(-1==patchindex);
212 return patchindex;
213 }
214
215 index_t _getPatchIndex(index_t const patch,index_t const u,index_t const v) const
216 {
217 index_t index=_getTensorIndex(patch,u,v);
218 return TO_HTENSOR(&(m_basis->getBase(patch)))->flatTensorIndexToHierachicalIndex(index,m_level);
219 }
220
221 // tensorIndex = flat tensor index of one level of hierarchical splines
222 index_t _getTensorIndex(index_t const patch,index_t const u, index_t const v) const
223 {
225 vec(0)=u,vec(1)=v;
226 return TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[m_level]->index(vec);
227 }
228
229 index_t _getTensorIndex(index_t const patch,index_t const patchIndex) const
230 {
231 index_t combIndex = TO_HTENSOR(&(m_basis->getBase(patch)))->flatTensorIndexOf(patchIndex,m_level);
232// for(index_t i = 0;i<m_level;i++)
233// combIndex-= TO_HTENSOR((*m_bases)[patch])->m_bases[i]->size();
234 return combIndex;
235 }
236
237 index_t _getPar(index_t localIndex,bool par) const
238 {
239 index_t patch = _getPatch(localIndex);
240 index_t patchIndex = _getPatchIndex(localIndex);
241 return _getPar(patch,_getTensorIndex(patch,patchIndex),par);
242 }
243
244 index_t _getPar(index_t patch,index_t tensorIndex, bool par) const
245 {
246 gsVector<index_t,d> vec = TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[m_level]->tensorIndex(tensorIndex);
247 GISMO_ASSERT(static_cast<index_t>(vec(par))<TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[m_level]->size(par),"wrong tensorIndex");
248 GISMO_ASSERT(static_cast<index_t>(vec(!par))<TO_HTENSOR(&(m_basis->getBase(patch)))->getBases()[m_level]->size(!par),"wrong tensorIndex");
249 return vec(par);
250 }
251
252private:
253 mutable index_t m_level; // used in the construction to determine the level, after the construction it is used to say the max_level of the H-Splines
254};
255
256}
257
258#undef TO_BSPLINE
259#undef TO_HTENSOR
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
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:79
Defines a topological arrangement of a collection of "boxes" (e.g., parameter domains that map to phy...
Definition gsBoxTopology.h:39
Class for representing a knot vector.
Definition gsKnotVector.h:80
T at(const size_t &i) const
Returns the value of the i - th knot (counted with repetitions).
Definition gsKnotVector.h:865
size_t size() const
Number of knots (including repetitions).
Definition gsKnotVector.h:242
void reverse()
Better directly use affineTransformTo.
Definition gsKnotVector.hpp:468
Purely abstract class gsMappedBasis, which gives means of combining basis functions to new,...
Definition gsMPBESBasis.h:47
A univariate Lagrange basis.
Definition gsMPBESMapHB2D.h:41
A univariate Lagrange basis.
Definition gsMPBESMapTensor.h:33
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
A tensor product B-spline basis.
Definition gsTensorBSplineBasis.h:37
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Provides declaration of Basis abstract interface.
Provides declaration of the BoxTopology class.
#define index_t
Definition gsConfig.h:32
#define GISMO_ERROR(message)
Definition gsDebug.h:118
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
Knot vector for B-splines.
Provides declaration of Basis abstract interface.
Provides declaration of Basis abstract interface.
The G+Smo namespace, containing all definitions for the library.
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
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
index_t patch
The index of the patch.
Definition gsBoundary.h:234