IFEM 90A354
FieldFunctions.h
Go to the documentation of this file.
1// $Id$
2//==============================================================================
12//==============================================================================
13
14#ifndef _FIELD_FUNCTIONS_H
15#define _FIELD_FUNCTIONS_H
16
17#include "TensorFunction.h"
18#include <string>
19
20class Field;
21class Fields;
22class ASMbase;
23class HDF5Reader;
24class ProcessAdm;
25
26
32{
33public:
34 static constexpr int FIXED_LEVEL = 1 << 24;
35
36protected:
38 FieldFuncBase() : pidx(0), npch(0) {}
40 FieldFuncBase(const FieldFuncBase&) = delete;
42 virtual ~FieldFuncBase();
43
45 bool setPatch(size_t pIdx);
46
47protected:
48 std::vector<ASMbase*> patch;
49
50 size_t pidx;
51 size_t npch;
52};
53
54
60{
61protected:
64 hdf5(nullptr), pAdm(nullptr)
65 {}
68 explicit FieldFuncHDF5(const std::string& fileName);
70 FieldFuncHDF5(const FieldFuncHDF5&) = delete;
72 virtual ~FieldFuncHDF5();
73
79 bool load(const std::vector<std::string>& fieldNames,
80 const std::string& basisName, int level,
81 bool isScalar = false);
82
84 int findClosestLevel(double time) const;
85
91 virtual void addPatchField(ASMbase* pch,
92 const std::vector<Real>& coefs,
93 int nf, int basis) = 0;
95 virtual void clearField() = 0;
96
98 mutable int lastLevel;
99
100private:
103
104 mutable double lastTime;
105};
106
107
113{
114public:
120 FieldFuncScalarBase(const std::string& fileName,
121 const std::string& basisName,
122 const std::string& fieldName,
123 int level = 0);
125 virtual ~FieldFuncScalarBase() { this->clearFieldInt(); }
126
127protected:
130
134 virtual void addPatchField(ASMbase* pch,
135 const std::vector<Real>& coefs,
136 int, int);
138 virtual void clearField() { this->clearFieldInt(); }
139
141 void clearFieldInt();
142
143 mutable int currentLevel;
144
145 std::string fName;
146 std::string bName;
147
148 std::vector<Field*> field;
149};
150
151
157{
158public:
164 FieldFunction(const std::string& fileName,
165 const std::string& basisName,
166 const std::string& fieldName,
167 int level = 0);
172 FieldFunction(const std::vector<Field*>& fields);
174 virtual ~FieldFunction() {}
175
177 bool initPatch(size_t pIdx) override { return this->setPatch(pIdx); }
178
180 Vec3 gradient(const Vec3& X) const override;
181
183 SymmTensor hessian(const Vec3& X) const override;
184
185protected:
187 Real evaluate(const Vec3& X) const override;
188};
189
190
197{
198public:
202 FieldFuncStream(const std::vector<ASMbase*>& patches, std::istream& istr);
204 virtual ~FieldFuncStream();
205
207 virtual bool initPatch(size_t pIdx) { return this->setPatch(pIdx); }
208
209protected:
211 virtual Real evaluate(const Vec3& X) const;
212
213private:
214 std::vector<Field*> field;
215};
216
217
223{
224protected:
227 FieldsFuncBase(const std::vector<Fields*>& fields);
228
234 FieldsFuncBase(const std::string& fileName,
235 const std::string& basisName,
236 const std::string& fieldName,
237 int level);
239 virtual ~FieldsFuncBase() { this->clearField(); }
240
246 virtual void addPatchField(ASMbase* pch,
247 const std::vector<Real>& coefs,
248 int nf, int basis);
250 virtual void clearField();
251
253 std::vector<Real> getValues(const Vec3& X);
254
256 std::vector<Real> getGradient(const Vec3& X) const;
257
259 std::vector<Real> getHessian(const Vec3& X) const;
260
261private:
262 mutable int currentLevel;
263
264protected:
265 std::vector<std::string> fName;
266 std::string bName;
267
268 std::vector<Fields*> field;
269};
270
271
277{
278public:
284 VecFieldFunction(const std::string& fileName,
285 const std::string& basisName,
286 const std::string& fieldName,
287 int level = 0);
288
293 VecFieldFunction(const std::vector<Fields*>& fields);
294
296 virtual ~VecFieldFunction() {}
297
299 bool initPatch(size_t pIdx) override { return this->setPatch(pIdx); }
300
301protected:
303 Vec3 evaluate(const Vec3& X) const override;
304
306 std::vector<Real> evalGradient(const Vec3& X) const override
307 { return this->getGradient(X); }
309 std::vector<Real> evalHessian(const Vec3& X) const override
310 { return this->getHessian(X); }
311};
312
313
319{
320public:
326 TensorFieldFunction(const std::string& fileName,
327 const std::string& basisName,
328 const std::string& fieldName,
329 int level = 0);
332
334 virtual bool initPatch(size_t pIdx) { return this->setPatch(pIdx); }
335
336protected:
338 virtual Tensor evaluate(const Vec3& X) const;
339};
340
341
347{
348public:
354 ScalarGradFieldFunction(const std::string& fileName,
355 const std::string& basisName,
356 const std::string& fieldName,
357 int level = 0);
358
364 ScalarGradFieldFunction(const std::vector<Field*>& fields, int dim);
365
368
370 virtual bool initPatch(size_t pIdx) { return this->setPatch(pIdx); }
371
372protected:
374 virtual Vec3 evaluate(const Vec3& X) const;
375};
376
377
383{
384public:
390 ScalarLaplacianFieldFunction(const std::string& fileName,
391 const std::string& basisName,
392 const std::string& fieldName,
393 int level = 0);
396
398 virtual bool initPatch(size_t pIdx) { return this->setPatch(pIdx); }
399
400protected:
402 virtual Vec3 evaluate(const Vec3& X) const;
403};
404
405
411{
412public:
418 VecGradFieldFunction(const std::string& fileName,
419 const std::string& basisName,
420 const std::string& fieldName,
421 int level = 0);
424
426 virtual bool initPatch(size_t pIdx) { return this->setPatch(pIdx); }
427
428protected:
430 virtual Tensor evaluate(const Vec3& X) const;
431};
432
433
439{
440public:
446 VecLaplacianFieldFunction(const std::string& fileName,
447 const std::string& basisName,
448 const std::string& fieldName,
449 int level = 0);
452
454 virtual bool initPatch(size_t pIdx) { return this->setPatch(pIdx); }
455
456protected:
458 virtual Tensor evaluate(const Vec3& X) const;
459};
460
461
467{
468public:
474 STensorFieldFunction(const std::string& fileName,
475 const std::string& basisName,
476 const std::string& fieldName,
477 int level = 0);
480
482 virtual bool initPatch(size_t pIdx) { return this->setPatch(pIdx); }
483
484protected:
486 virtual SymmTensor evaluate(const Vec3& X) const;
487};
488
489#endif
#define Real
The floating point type to use.
Definition ImmersedBoundaries.h:18
Spatial tensor-valued functions.
Base class for spline-based finite element (FE) assembly drivers.
Definition ASMbase.h:72
Base class for spatial functions, defined through patch-wise fields.
Definition FieldFunctions.h:32
size_t npch
Number of patches in the field.
Definition FieldFunctions.h:51
FieldFuncBase()
Default constructor.
Definition FieldFunctions.h:38
std::vector< ASMbase * > patch
The patches on which the field is defined.
Definition FieldFunctions.h:48
FieldFuncBase(const FieldFuncBase &)=delete
No copying of this class.
virtual ~FieldFuncBase()
The destructor deletes the patches.
Definition FieldFunctions.C:33
static constexpr int FIXED_LEVEL
Bit flag in level for using fixed.
Definition FieldFunctions.h:34
bool setPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.C:39
size_t pidx
Current patch index.
Definition FieldFunctions.h:50
Base class for spatial functions, defined from a HDF5-file.
Definition FieldFunctions.h:60
virtual void clearField()=0
Clears the field container.
FieldFuncHDF5()
Default constructor.
Definition FieldFunctions.h:63
bool hasMultipleLevels
True if we have multiple time levels.
Definition FieldFunctions.h:97
FieldFuncHDF5(const FieldFuncHDF5 &)=delete
No copying of this class.
HDF5Reader * hdf5
The HDF5-file containing the field data.
Definition FieldFunctions.h:101
virtual void addPatchField(ASMbase *pch, const std::vector< Real > &coefs, int nf, int basis)=0
Adds a patch-wise field with the given coefficient values.
bool load(const std::vector< std::string > &fieldNames, const std::string &basisName, int level, bool isScalar=false)
Loads field values for the specified time level.
Definition FieldFunctions.C:102
virtual ~FieldFuncHDF5()
The destructor closes the HDF5-file.
Definition FieldFunctions.C:65
ProcessAdm * pAdm
Process administrator for the HDF5-file reader.
Definition FieldFunctions.h:102
int lastLevel
The last time level read from.
Definition FieldFunctions.h:98
double lastTime
The time of lastLevel.
Definition FieldFunctions.h:104
int findClosestLevel(double time) const
Finds the level whose time is closest to the specified time.
Definition FieldFunctions.C:72
Base class for field functions derived from a scalar field.
Definition FieldFunctions.h:113
std::string fName
Name of field.
Definition FieldFunctions.h:145
int currentLevel
Current time level to evaluate at.
Definition FieldFunctions.h:143
FieldFuncScalarBase()
Default constructor.
Definition FieldFunctions.h:129
virtual ~FieldFuncScalarBase()
The destructor deletes the scalar fields.
Definition FieldFunctions.h:125
virtual void clearField()
Clears the field container.
Definition FieldFunctions.h:138
void clearFieldInt()
Non-virtual actual implementation of clearField()
Definition FieldFunctions.C:263
std::vector< Field * > field
The scalar field to be evaluated.
Definition FieldFunctions.h:148
std::string bName
Name of basis.
Definition FieldFunctions.h:146
virtual void addPatchField(ASMbase *pch, const std::vector< Real > &coefs, int, int)
Adds a patch-wise field with the given coefficient values.
Definition FieldFunctions.C:271
A scalar-valued spatial function, defined through scalar fields.
Definition FieldFunctions.h:197
std::vector< Field * > field
The scalar field to be evaluated.
Definition FieldFunctions.h:214
virtual ~FieldFuncStream()
The destructor deletes the scalar fields.
Definition FieldFunctions.C:381
virtual Real evaluate(const Vec3 &X) const
Evaluates the scalar field function.
Definition FieldFunctions.C:387
virtual bool initPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.h:207
A scalar-valued spatial function, defined through scalar fields.
Definition FieldFunctions.h:157
virtual ~FieldFunction()
Empty destructor.
Definition FieldFunctions.h:174
SymmTensor hessian(const Vec3 &X) const override
Evaluates second derivatives of the function.
Definition FieldFunctions.C:342
bool initPatch(size_t pIdx) override
Sets the active patch.
Definition FieldFunctions.h:177
Real evaluate(const Vec3 &X) const override
Evaluates the scalar field function.
Definition FieldFunctions.C:298
Vec3 gradient(const Vec3 &X) const override
Evaluates first derivatives of the function.
Definition FieldFunctions.C:320
Interface class for scalar fields.
Definition Field.h:30
Base class for multi-valued spatial functions, defined through fields.
Definition FieldFunctions.h:223
int currentLevel
Current time level to evaluate at.
Definition FieldFunctions.h:262
std::vector< std::string > fName
Name of field components.
Definition FieldFunctions.h:265
std::vector< Real > getGradient(const Vec3 &X) const
Evaluates the field gradient at the givent point X.
Definition FieldFunctions.C:467
std::vector< Fields * > field
The vector field to be evaluated.
Definition FieldFunctions.h:268
virtual void clearField()
Clears the field container.
Definition FieldFunctions.C:425
virtual ~FieldsFuncBase()
The destructor deletes the vector fields.
Definition FieldFunctions.h:239
std::string bName
Name of basis.
Definition FieldFunctions.h:266
std::vector< Real > getHessian(const Vec3 &X) const
Evaluates the field gradient at the givent point X.
Definition FieldFunctions.C:482
virtual void addPatchField(ASMbase *pch, const std::vector< Real > &coefs, int nf, int basis)
Adds a patch-wise field with the given coefficient values.
Definition FieldFunctions.C:433
std::vector< Real > getValues(const Vec3 &X)
Evaluates the field at the givent point X.
Definition FieldFunctions.C:443
Base class for vector fields.
Definition Fields.h:35
size_t dim() const
Returns the number of components of the return value.
Definition Function.h:165
Read data from a HDF5 file.
Definition FieldFunctions.C:28
Class for administration of MPI processes in IFEM library.
Definition ProcessAdm.h:33
Scalar-valued unary function of a spatial point.
Definition Function.h:193
A symmtensor-valued spatial function, defined through a vector field.
Definition FieldFunctions.h:467
virtual ~STensorFieldFunction()
Empty destructor.
Definition FieldFunctions.h:479
virtual SymmTensor evaluate(const Vec3 &X) const
Evaluates the tensorial field function.
Definition FieldFunctions.C:698
virtual bool initPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.h:482
Symmetric tensor-valued unary function of a spatial point.
Definition TensorFunction.h:71
A vector-valued spatial function, defined through gradient of a scalar field.
Definition FieldFunctions.h:347
virtual bool initPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.h:370
virtual ~ScalarGradFieldFunction()
Empty destructor.
Definition FieldFunctions.h:367
virtual Vec3 evaluate(const Vec3 &X) const
Evaluates the vectorial field function.
Definition FieldFunctions.C:551
A vector-valued spatial function, defined through laplacian of a scalar field.
Definition FieldFunctions.h:383
virtual Vec3 evaluate(const Vec3 &X) const
Evaluates the vectorial field function.
Definition FieldFunctions.C:579
virtual bool initPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.h:398
virtual ~ScalarLaplacianFieldFunction()
Empty destructor.
Definition FieldFunctions.h:395
Simple class for representing a symmetric second-order tensor.
Definition Tensor.h:183
A tensor-valued spatial function, defined through a vector field.
Definition FieldFunctions.h:319
virtual Tensor evaluate(const Vec3 &X) const
Evaluates the tensorial field function.
Definition FieldFunctions.C:610
virtual bool initPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.h:334
virtual ~TensorFieldFunction()
Empty destructor.
Definition FieldFunctions.h:331
Tensor-valued unary function of a spatial point.
Definition TensorFunction.h:27
Simple class for representing a non-symmetric second-order tensor.
Definition Tensor.h:28
Simple class for representing a point in 3D space.
Definition Vec3.h:27
A vector-valued spatial function, defined through a vector field.
Definition FieldFunctions.h:277
bool initPatch(size_t pIdx) override
Sets the active patch.
Definition FieldFunctions.h:299
virtual ~VecFieldFunction()
Empty destructor.
Definition FieldFunctions.h:296
std::vector< Real > evalGradient(const Vec3 &X) const override
Returns the gradient of the function as a 1D array.
Definition FieldFunctions.h:306
std::vector< Real > evalHessian(const Vec3 &X) const override
Returns the hessian of the function as a 1D array.
Definition FieldFunctions.h:309
Vec3 evaluate(const Vec3 &X) const override
Evaluates the vectorial field function.
Definition FieldFunctions.C:519
Vector-valued unary function of a spatial point.
Definition Function.h:242
A tensor-valued spatial function, defined through gradient of a vector field.
Definition FieldFunctions.h:411
virtual bool initPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.h:426
virtual ~VecGradFieldFunction()
Empty destructor.
Definition FieldFunctions.h:423
virtual Tensor evaluate(const Vec3 &X) const
Evaluates the tensorial field function.
Definition FieldFunctions.C:631
A tensor-valued spatial function, defined through laplacian of a vector field.
Definition FieldFunctions.h:439
virtual ~VecLaplacianFieldFunction()
Empty destructor.
Definition FieldFunctions.h:451
virtual bool initPatch(size_t pIdx)
Sets the active patch.
Definition FieldFunctions.h:454
virtual Tensor evaluate(const Vec3 &X) const
Evaluates the tensorial field function.
Definition FieldFunctions.C:665