G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsFieldCreator.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <gsCore/gsField.h>
17
18namespace gismo
19{
20
21
31template<class T>
32class gsAbsError : public gsFunction<T>
33{
34public:
36 typedef memory::shared_ptr< gsAbsError > Ptr;
37
39 typedef memory::unique_ptr< gsAbsError > uPtr;
40
41 gsAbsError( gsFunction<T> const & f1,
42 gsGeometry<T> const & geo,
43 gsFunction<T> const & f2,
44 bool _f2param = false)
45 : m_geo(geo), m_f1(f1), m_f2(f2), f2param(_f2param)
46 {
47
48 }
49
50 GISMO_CLONE_FUNCTION(gsAbsError)
51
52 void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
53 {
54 gsMatrix<T> tmp;
55 m_geo.eval_into(u, tmp);
56
57 if(!f2param)
58 result.noalias() = ( m_f1.eval(u) - m_f2.eval(tmp) ).cwiseAbs();
59 else
60 result.noalias() = ( m_f1.eval(u) - m_f2.eval(u) ).cwiseAbs(); // f2 parametric function
61
62 }
63
64 short_t domainDim() const { return m_f1.domainDim(); }
65 short_t targetDim() const { return m_f1.targetDim(); }
66
68 std::ostream &print(std::ostream &os) const
69 { os << "Absolute error.\n"; return os; };
70private:
71 const gsGeometry<T> & m_geo;
72
73 const gsFunction<T> & m_f1;
74 const gsFunction<T> & m_f2;
75
76 bool f2param;
77
78private:
79// gsAbsError() { }
80};
81
82
90template<class T>
91class gsGradientField : public gsFunction<T>
92{
93public:
95 typedef memory::shared_ptr< gsGradientField > Ptr;
96
98 typedef memory::unique_ptr< gsGradientField > uPtr;
99
100 gsGradientField( gsGeometry<T> const & geo, gsFunction<T> const & f)
101 : m_geo(geo), m_f(f)
102 { }
103
104 GISMO_CLONE_FUNCTION(gsGradientField)
105
106 void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
107 {
108 gsMatrix<T> tmp;
109 m_geo.eval_into(u, tmp);
110 m_f.deriv_into(tmp, result);
111 }
112
113 short_t domainDim() const { return m_geo.parDim(); }
114 short_t targetDim() const { return m_geo.geoDim(); }
115
117 std::ostream &print(std::ostream &os) const
118 { os << "Gradient field of "; return os; };
119private:
120 const gsGeometry<T> & m_geo;
121 const gsFunction<T> & m_f ;
122};
123
131template<class T>
132class gsJacDetField : public gsFunction<T>
133{
134public:
136 typedef memory::shared_ptr< gsJacDetField > Ptr;
137
139 typedef memory::unique_ptr< gsJacDetField > uPtr;
140
141 gsJacDetField( gsGeometry<T> const & geo)
142 : m_geo(geo), m_dim(m_geo.parDim())
143 {
144 GISMO_ENSURE(m_dim == m_geo.geoDim(), "Not extended to surface case yet." );
145 }
146
147 GISMO_CLONE_FUNCTION(gsJacDetField)
148
149 void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
150 {
151 result.resize(1, u.cols() );
152 gsMatrix<T> tmp;
153 for (index_t k=0; k!= u.cols(); ++k)
154 result(0,k) = m_geo.deriv(u.col(k)).reshape(m_dim,m_dim).determinant();
155 }
156
157 short_t domainDim() const { return m_geo.parDim(); }
158 short_t targetDim() const { return 1; }
159
161 std::ostream &print(std::ostream &os) const
162 { os << "Jacobian determinant field of "; return os; };
163private:
164 const gsGeometry<T> & m_geo;
165 const int m_dim;
166};
167
175template<class T>
176class gsNormalField : public gsFunction<T>
177{
178public:
180 typedef memory::shared_ptr< gsNormalField > Ptr;
181
183 typedef memory::unique_ptr< gsNormalField > uPtr;
184
185 gsNormalField( gsGeometry<T> const & geo) : m_geo(geo)
186 {
187
188 }
189
190 GISMO_CLONE_FUNCTION(gsNormalField)
191
192 void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
193 {
194 const short_t ParDim = m_geo.parDim();
195 result.resize(ParDim+1, u.cols()) ;
196
197 gsMatrix<T> Jk;
198
199 for( index_t j=0; j < u.cols(); ++j )
200 {
201 Jk = m_geo.jacobian( u.col(j) );
202 T alt_sgn(1.0);
203 gsMatrix<T> mm(ParDim,ParDim);
204 for (int i = 0; i <= ParDim; ++i) // for all components of the normal vector
205 {
206 Jk.rowMinor(i, mm);
207 result(i,j) = alt_sgn * mm.determinant();
208 alt_sgn = -alt_sgn;
209 }
210 }
211 }
212
213 short_t domainDim() const { return m_geo.parDim(); }
214 short_t targetDim() const { return m_geo.geoDim();}
215
217 std::ostream &print(std::ostream &os) const
218 { os << "NormalField"; return os; };
219private:
220 const gsGeometry<T> & m_geo;
221
222private:
223// gsNormalField() { }
224};
225
234template<class T>
235class gsParamField : public gsFunction<T>
236{
237public:
239 typedef memory::shared_ptr< gsParamField > Ptr;
240
242 typedef memory::unique_ptr< gsParamField > uPtr;
243
244 gsParamField(gsGeometry<T> const & geo)
245 : m_geo(geo)
246 {
247
248 }
249
250 GISMO_CLONE_FUNCTION(gsParamField)
251
252 void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
253 { result = u; }
254
255 short_t domainDim() const { return m_geo.domainDim(); }
256 short_t targetDim() const { return m_geo.domainDim(); }
257
259 std::ostream &print(std::ostream &os) const
260 { os << "Parameter field.\n"; return os; };
261
262private:
263 const gsGeometry<T> & m_geo;
264};
265
266
276template<class T>
277class gsPatchIdField : public gsFunction<T>
278{
279public:
281 typedef memory::shared_ptr< gsPatchIdField > Ptr;
282
284 typedef memory::unique_ptr< gsPatchIdField > uPtr;
285
286 explicit gsPatchIdField(gsGeometry<T> const & geo_)
287 : geo(geo_), m_supp(geo.support())
288 { }
289
290 GISMO_CLONE_FUNCTION(gsPatchIdField)
291
292 void eval_into(const gsMatrix<T>& u, gsMatrix<T>& result) const
293 {
294 result.setZero(2, u.cols() );
295 result.row(0).setConstant(geo.id());
296
297 const int d = geo.parDim();
298 for (boxSide c=boxSide::getFirst(d); c<boxSide::getEnd(d); ++c)
299 {
300 const index_t dir = c.direction();
301 const T par = m_supp(dir, c.parameter() );
302
303 for (index_t v = 0; v != u.cols(); ++v) // for all columns of u
304 {
305 if ( math::abs( u(dir,v) - par ) < 1e-2 )
306 result(1,v) = static_cast<T>(c);
307 }
308 }
309 }
310
311 short_t domainDim() const { return geo.domainDim(); }
312 short_t targetDim() const { return 2; }
313
315 std::ostream &print(std::ostream &os) const
316 { os << "Boundary side indicator field.\n"; return os; };
317
318private:
319 const gsGeometry<T> & geo;
320 gsMatrix<T> m_supp;
321};
322
323
324
331template<class T>
333{
334
335 static gsField<T> absError(gsField<T> const & field, gsFunction<T> const & f, bool fparam = false)
336 {
337 const gsMultiPatch<T> & mp = field.patches();
338
339 gsPiecewiseFunction<T> * nFields = new gsPiecewiseFunction<T>(mp.nPatches());
340
341 for (size_t k=0; k< mp.nPatches(); ++k)
342 nFields->addPiecePointer( new gsAbsError<T>(field.function(k), mp.patch(k), f, fparam) );
343
344 return gsField<T>(mp, typename gsPiecewiseFunction<T>::Ptr(nFields), true );
345 }
346
347
348 static gsField<T> gradient(gsMultiPatch<T> const & mp, gsFunction<T> const & f)
349 {
350 gsPiecewiseFunction<T> * nFields = new gsPiecewiseFunction<T>(mp.nPatches());
351
352
353 for (size_t k=0; k< mp.nPatches(); ++k)
354 nFields->addPiecePointer( new gsGradientField<T>(mp.patch(k), f) );
355
356 return gsField<T>(mp, typename gsPiecewiseFunction<T>::Ptr(nFields), true );
357 }
358
359 static gsField<T> normal(gsMultiPatch<T> const & mp)
360 {
361 gsPiecewiseFunction<T> * nFields = new gsPiecewiseFunction<T>(mp.nPatches());
362
363
364 for (size_t k=0; k< mp.nPatches(); ++k)
365 nFields->addPiecePointer( new gsNormalField<T>(mp.patch(k)) );
366
367 return gsField<T>(mp, typename gsPiecewiseFunction<T>::Ptr(nFields), true );
368 }
369
370
371 static gsField<T> jacDet(gsMultiPatch<T> const & mp)
372 {
373 gsPiecewiseFunction<T> * nFields = new gsPiecewiseFunction<T>(mp.nPatches());
374
375
376 for (size_t k=0; k< mp.nPatches(); ++k)
377 nFields->addPiecePointer( new gsJacDetField<T>(mp.patch(k)) );
378
379 return gsField<T>(mp, typename gsPiecewiseFunction<T>::Ptr(nFields), true );
380 }
381
382 static gsField<T> parameters(gsMultiPatch<T> const & mp)
383 {
384 gsPiecewiseFunction<T> * nFields = new gsPiecewiseFunction<T>(mp.nPatches());
385
386
387 for (size_t k=0; k< mp.nPatches(); ++k)
388 nFields->addPiecePointer( new gsParamField<T>(mp.patch(k)) );
389
390 return gsField<T>(mp, typename gsPiecewiseFunction<T>::Ptr(nFields), true );
391 }
392
393 static gsField<T> patchIds(gsMultiPatch<T> const & mp)
394 {
395 gsPiecewiseFunction<T> * nFields = new gsPiecewiseFunction<T>(mp.nPatches());
396 for (size_t k=0; k< mp.nPatches(); ++k)
397 nFields->addPiecePointer( new gsPatchIdField<T>(mp.patch(k)) );
398 return gsField<T>(mp, typename gsPiecewiseFunction<T>::Ptr(nFields), true );
399 }
400
401}; // struct gsFieldCreator
402
403
404
405} // namespace gismo
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
static boxSide getEnd(short_t dim)
helper for iterating on sides of an n-dimensional box
Definition gsBoundary.h:176
static boxSide getFirst(short_t)
helper for iterating on sides of an n-dimensional box
Definition gsBoundary.h:160
Generates a field with value the absolute difference (error) between and isogeometric function and a ...
Definition gsFieldCreator.h:33
memory::shared_ptr< gsAbsError > Ptr
Shared pointer for gsAbsError.
Definition gsFieldCreator.h:36
short_t targetDim() const
Dimension of the target space.
Definition gsFieldCreator.h:65
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsFieldCreator.h:52
short_t domainDim() const
Dimension of the (source) domain.
Definition gsFieldCreator.h:64
memory::unique_ptr< gsAbsError > uPtr
Unique pointer for gsAbsError.
Definition gsFieldCreator.h:39
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsFieldCreator.h:68
A scalar of vector field defined on a m_parametric geometry.
Definition gsField.h:55
const gsFunction< T > & function(int i=0) const
Returns the gsFunction of patch i.
Definition gsField.h:231
const gsMultiPatch< T > & patches() const
Returns gsMultiPatch containing the geometric information on the domain.
Definition gsField.h:210
A function from a n-dimensional domain to an m-dimensional image.
Definition gsFunction.h:60
Abstract base class representing a geometry map.
Definition gsGeometry.h:93
Generates a field with value being the gradient of an isogeometric function.
Definition gsFieldCreator.h:92
memory::shared_ptr< gsGradientField > Ptr
Shared pointer for gsGradientField.
Definition gsFieldCreator.h:95
short_t targetDim() const
Dimension of the target space.
Definition gsFieldCreator.h:114
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsFieldCreator.h:106
memory::unique_ptr< gsGradientField > uPtr
Unique pointer for gsGradientField.
Definition gsFieldCreator.h:98
short_t domainDim() const
Dimension of the (source) domain.
Definition gsFieldCreator.h:113
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsFieldCreator.h:117
Generates a field with value the Jacobian determinant of a geometry.
Definition gsFieldCreator.h:133
short_t targetDim() const
Dimension of the target space.
Definition gsFieldCreator.h:158
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsFieldCreator.h:149
short_t domainDim() const
Dimension of the (source) domain.
Definition gsFieldCreator.h:157
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsFieldCreator.h:161
memory::shared_ptr< gsJacDetField > Ptr
Shared pointer for gsJacDetField.
Definition gsFieldCreator.h:136
memory::unique_ptr< gsJacDetField > uPtr
Unique pointer for gsJacDetField.
Definition gsFieldCreator.h:139
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
void rowMinor(index_t i, RowMinorMatrixType &result) const
Definition gsMatrix.h:331
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
Generates the normal field of a geometry.
Definition gsFieldCreator.h:177
short_t targetDim() const
Dimension of the target space.
Definition gsFieldCreator.h:214
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsFieldCreator.h:192
short_t domainDim() const
Dimension of the (source) domain.
Definition gsFieldCreator.h:213
memory::unique_ptr< gsNormalField > uPtr
Unique pointer for gsNormalField.
Definition gsFieldCreator.h:183
memory::shared_ptr< gsNormalField > Ptr
Shared pointer for gsNormalField.
Definition gsFieldCreator.h:180
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsFieldCreator.h:217
Generates a field that attaches the parameter values on each physical point.
Definition gsFieldCreator.h:236
memory::shared_ptr< gsParamField > Ptr
Shared pointer for gsParamField.
Definition gsFieldCreator.h:239
short_t targetDim() const
Dimension of the target space.
Definition gsFieldCreator.h:256
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsFieldCreator.h:252
short_t domainDim() const
Dimension of the (source) domain.
Definition gsFieldCreator.h:255
memory::unique_ptr< gsParamField > uPtr
Unique pointer for gsParamField.
Definition gsFieldCreator.h:242
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsFieldCreator.h:259
Generates a field that indicates the boundary sides on the geometry.
Definition gsFieldCreator.h:278
memory::shared_ptr< gsPatchIdField > Ptr
Shared pointer for gsPatchIdField.
Definition gsFieldCreator.h:281
memory::unique_ptr< gsPatchIdField > uPtr
Unique pointer for gsPatchIdField.
Definition gsFieldCreator.h:284
short_t targetDim() const
Dimension of the target space.
Definition gsFieldCreator.h:312
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the function at points u into result.
Definition gsFieldCreator.h:292
short_t domainDim() const
Dimension of the (source) domain.
Definition gsFieldCreator.h:311
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsFieldCreator.h:315
A function depending on an index i, typically referring to a patch/sub-domain. On each patch a differ...
Definition gsPiecewiseFunction.h:29
memory::shared_ptr< gsPiecewiseFunction > Ptr
Shared pointer for gsPiecewiseFunction.
Definition gsPiecewiseFunction.h:37
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition gsDebug.h:102
Provides declaration of the Field class.
The G+Smo namespace, containing all definitions for the library.
Class that creates standard fields on a given parametric (multipatch) geometry.
Definition gsFieldCreator.h:333