G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsField.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 #include <gsCore/gsFunctionSet.h>
17 #include <gsCore/gsGeometry.h>
18 #include <gsCore/gsMultiPatch.h>
19 #include <gsCore/gsMultiBasis.h>
20 #include <gsUtils/gsPointGrid.h>
21 
22 namespace gismo
23 {
53 template<class T>
54 class gsField
55 {
56 
57 public:
58  typedef memory::shared_ptr< gsField > Ptr;// todo: remove
59  typedef memory::unique_ptr< gsField > uPtr;// todo: remove
60 
61  gsField(): m_patches(NULL) { }
62 
63  gsField( const gsFunctionSet<T> & mp,
64  typename gsFunctionSet<T>::Ptr fs,
65  const bool isparam)
66  : m_patches(&mp), m_fields(fs), m_parametric(isparam)
67  { }
68 
69  gsField( const gsGeometry<T> & sp, const gsFunctionSet<T> & pf, const bool isparam = false)
71  { }
72 
73  gsField( const gsGeometry<T> & sp, const gsGeometry<T> & pf)
75  { }
76 
77  gsField( const gsMultiPatch<T> & mp, const gsFunctionSet<T> & f, const bool isparam = false)
79  { }
80 
81  gsField( const gsMultiPatch<T> & mp, const gsMultiPatch<T> & f)
83  { }
84 
85 public:
86 
87 // TO DO:
88 
89 // EVAL_physical_position
90 // Need to solve x = m_geometry(u) for u
91 
92  // Return a point in the physical domain at parameter value u
104  gsMatrix<T> point(const gsMatrix<T>& u, int i = 0) const
105  {
106  return m_patches->piece(i).eval(u);
107  }
108 
109  // Return the value of the Field at parameter value u
110  // TO DO: rename to evalParam()
122  gsMatrix<T> value(const gsMatrix<T>& u, int i = 0) const
123  {
124  return m_parametric
125  ? m_fields->piece(i).eval(u)
126  : m_fields->piece(i).eval( point(u, i) );
127  }
128 
129  // Return the value of the Field at physical value u
130  // TO DO: rename to evalPhys()
131  gsMatrix<T> pvalue(const gsMatrix<T>& u, int i) const
132  {
133  GISMO_ASSERT(!m_parametric, "Cannot compute physical value");
134  return ( m_fields->piece(i).eval(u) );
135  }
136 
138  T distanceL2(gsField<T> const & field, int numEvals= 1000) const;
139 
141  T distanceL2(gsFunctionSet<T> const & func,
142  bool isFunc_param = false,
143  int numEvals=1000) const;
144 
147  T distanceL2(gsFunctionSet<T> const & func,
148  gsMultiBasis<T> const & B,
149  bool isFunc_param = false,
150  int numEvals=1000) const;
151 
154  T distanceH1(gsFunctionSet<T> const & func,
155  bool isFunc_param = false,
156  int = 1000) const;
157 
160  T distanceH1(gsFunctionSet<T> const & func,
161  gsMultiBasis<T> const & B,
162  bool isFunc_param = false,
163  int = 1000) const;
164 
167  T distanceH2(gsFunctionSet<T> const & func,
168  bool isFunc_param = false) const;
169 
172  T distanceDG(gsFunctionSet<T> const & func,
173  bool isFunc_param = false,
174  int = 1000) const;
175 
177  std::ostream &print(std::ostream &os) const
178  {
179  os << ( m_parametric ? "Parameterized f" : "F")
180  << "unction field.\n Defined on " << m_patches;
181  return os;
182  }
183 
186  short_t parDim() const { return m_patches->domainDim(); }
187 
190  short_t geoDim() const { return m_patches->targetDim(); }
191 
194  short_t dim() const { return m_fields->targetDim(); }
195 
197  GISMO_DEPRECATED index_t nPatches() const { return m_patches->nPieces(); }
198 
200  int nPieces() const { return m_patches->nPieces(); }
201 
202  const gsGeometry<T> & geometry() const
203  {
204  GISMO_ASSERT(dynamic_cast<const gsGeometry<T>*>(m_patches),
205  "No geometry in field. The domain is"<< *m_patches);
206  return *static_cast<const gsGeometry<T>*>(m_patches);
207  }
208 
210  const gsMultiPatch<T> & patches() const
211  {
212  GISMO_ASSERT(dynamic_cast<const gsMultiPatch<T>*>(m_patches),
213  "No patches in field. The field domain is "<< *m_patches);
214  return *static_cast<const gsMultiPatch<T>*>(m_patches);
215  }
216 
218  const gsFunctionSet<T> & fields() const { return *m_fields; }
219 
221  const gsGeometry<T> & patch(int i=0) const
222  {
223  GISMO_ASSERT( i<nPieces(),
224  "gsField: Invalid patch index.");
225  GISMO_ASSERT(dynamic_cast<const gsGeometry<T>*>(&m_patches->piece(i)),
226  "No geometry in field. The domain is"<< m_patches->piece(i));
227  return static_cast<const gsGeometry<T>&>(m_patches->piece(i));
228  }
229 
231  const gsFunction<T> & function(int i=0) const
232  {
233  GISMO_ASSERT(dynamic_cast<const gsFunction<T>*>(&m_fields->piece(i)),
234  "No function in field. The domain is"<< m_patches->piece(i));
235  return static_cast<const gsFunction<T>&>(m_fields->piece(i));
236  }
237 
239  const gsGeometry<T> & igaFunction(int i=0) const
240  {
241  GISMO_ASSERT(i<m_fields->nPieces(),
242  "gsField: Invalid patch index.");
244  "Cannot get an IGA function from non-parametric field.");
245  GISMO_ASSERT(dynamic_cast<const gsGeometry<T>*>(&m_fields->piece(i)),
246  "Cannot return an igaFunction from a function of type: "<< m_fields->piece(i) );
247  return static_cast<const gsGeometry<T> &>(m_fields->piece(i));
248  }
249 
252  bool isParametric() const { return m_parametric; }
253 
257  bool isParametrized() const
258  { return m_parametric && dynamic_cast<const gsGeometry<T>*>(&m_fields->piece(0));}
259 
268  const gsMatrix<T> & coefficientVector(int i=0) const
269  {
270  return igaFunction(i).coefs();
271  }
272 
273 // Data members
274 private:
275 
278 
279  // If there are many patches, one field per patch
280 
287 
297  bool m_parametric;// True iff this is an Isogeometric field, living on parameter domain
298 
299 }; // class gsField
300 
301 
303 template<class T>
304 std::ostream &operator<<(std::ostream &os, const gsField<T>& b)
305 {return b.print(os); }
306 
307 
308 } // namespace gismo
309 
310 #ifndef GISMO_BUILD_LIB
311 #include GISMO_HPP_HEADER(gsField.hpp)
312 #endif
bool m_parametric
True iff this is an isogeometric field.
Definition: gsField.h:297
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
shared_ptr< T > make_shared_not_owned(const T *x)
Creates a shared pointer which does not eventually delete the underlying raw pointer. Usefull to refer to objects which should not be destroyed.
Definition: gsMemory.h:189
gsFunctionSet< T >::Ptr m_fields
Vector containing &quot;local fields&quot; for each patch/subdomain.
Definition: gsField.h:286
const gsMatrix< T > & coefficientVector(int i=0) const
Returns the coefficient vector (if it exists) corresponding to the function field for patch i...
Definition: gsField.h:268
A scalar of vector field defined on a m_parametric geometry.
Definition: gsField.h:54
#define short_t
Definition: gsConfig.h:35
Provides declaration of MultiBasis class.
short_t parDim() const
Returns the dimension of the parameter domain (e.g., if the domain is a surface in three-dimensional ...
Definition: gsField.h:186
T distanceH2(gsFunctionSet< T > const &func, bool isFunc_param=false) const
Definition: gsField.hpp:66
Provides declaration of Geometry abstract interface.
#define index_t
Definition: gsConfig.h:32
A function from a n-dimensional domain to an m-dimensional image.
Definition: gsFunction.h:59
const gsFunctionSet< T > * m_patches
The isogeometric field is defined on this multipatch domain.
Definition: gsField.h:277
const gsMultiPatch< T > & patches() const
Returns gsMultiPatch containing the geometric information on the domain.
Definition: gsField.h:210
bool isParametrized() const
Definition: gsField.h:257
short_t geoDim() const
Returns the dimension of the physical domain (e.g., if the domain is a surface in three-dimensional s...
Definition: gsField.h:190
T distanceDG(gsFunctionSet< T > const &func, bool isFunc_param=false, int=1000) const
Definition: gsField.hpp:122
GISMO_DEPRECATED index_t nPatches() const
Returns the number of patches.
Definition: gsField.h:197
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
memory::shared_ptr< gsFunctionSet > Ptr
Shared pointer for gsFunctionSet.
Definition: gsFunctionSet.h:223
const gsFunctionSet< T > & fields() const
Returns the fields (defined per patch)
Definition: gsField.h:218
bool isParametric() const
Definition: gsField.h:252
gsMatrix< T > point(const gsMatrix< T > &u, int i=0) const
Maps points u from the parameter domain to the physical domain.
Definition: gsField.h:104
Provides declaration of the MultiPatch class.
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition: gsMultiPatch.h:33
T distanceH1(gsFunctionSet< T > const &func, bool isFunc_param=false, int=1000) const
Definition: gsField.hpp:111
T distanceL2(gsField< T > const &field, int numEvals=1000) const
Computes the L2-distance between the two fields, on the physical domain.
Definition: gsField.hpp:94
Provides functions to generate structured point data.
gsMatrix< T > value(const gsMatrix< T > &u, int i=0) const
Evaluation of the field at points u.
Definition: gsField.h:122
int nPieces() const
Returns the number of pieces.
Definition: gsField.h:200
short_t dim() const
Returns the dimension of the physical domain (e.g., if the domain is a surface in three-dimensional s...
Definition: gsField.h:194
This is the interface of all objects that computes functions on points like gsBasis, gsGeometry and gsFunctions.
const gsGeometry< T > & patch(int i=0) const
Returns the gsGeometry of patch i.
Definition: gsField.h:221
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsField.h:177
const gsGeometry< T > & igaFunction(int i=0) const
Attempts to return an Isogeometric function for patch i.
Definition: gsField.h:239