Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
fields
field_base.hh
Go to the documentation of this file.
1
/*
2
* field_base.hh
3
*
4
* Created on: Aug 31, 2012
5
* Author: jb
6
*/
7
8
/**
9
* TODO:
10
* - better tests:
11
* - common set of quantities with different kind of values (scalar, vector, tensor, discrete, ..),
12
* common points and elements for evaluation
13
* - for individual Field implementations have:
14
* - different input
15
* - possibly different EPETCT_EQ tests, but rather have majority common
16
*
17
*
18
*/
19
20
21
#ifndef FIELD_BASE_HH_
22
#define FIELD_BASE_HH_
23
24
#include <string>
25
#include <memory>
26
27
#include <boost/type_traits.hpp>
28
29
#include "
input/input_type.hh
"
30
#include "
input/accessors.hh
"
31
32
#include "
mesh/accessors.hh
"
33
#include "
mesh/point.hh
"
34
#include "
fields/field_values.hh
"
35
36
37
38
/// Result type have sense only for larger Value types like vectors and tensors.
39
typedef
enum
{
40
result_none
,
// field not set
41
result_zero
,
// zero scalar, vector, or tensor
42
result_one
,
// unit scalar (1.0), identity tensor
43
result_other
44
}
FieldResult
;
45
46
47
48
49
/**
50
* Base class for space-time function classes.
51
*/
52
template
<
int
spacedim,
class
Value>
53
class
FieldBase
{
54
public
:
55
// expose template parameters
56
typedef
typename
Space<spacedim>::Point
Point
;
57
typedef
Value
ValueType
;
58
static
const
unsigned
int
spacedim_
=spacedim;
59
60
61
/**
62
* Kind of default constructor , with possible setting of the initial time.
63
* Fields that returns variable size vectors accepts number of components @p n_comp.
64
*/
65
FieldBase
(
unsigned
int
n_comp
=0);
66
67
/**
68
* Returns template parameters as string in order to distinguish name of AbstractRecords
69
* for initialization of different instances of the FieldBase template.
70
*/
71
static
std::string
template_name
();
72
73
/**
74
* Declaration of input type data member.
75
*/
76
static
Input::Type::AbstractRecord
input_type
;
77
78
/**
79
* Returns whole tree of input types for FieldBase with all descendants based on element input type (namely for FieldConstant)
80
* given by element_input_type pointer. USE ONLY IF YOU CAN NOT USE
81
* static member FieldBase<...>::input_type.
82
*/
83
static
Input::Type::AbstractRecord
get_input_type
(
const
typename
Value::ElementInputType *element_input_type=
nullptr
);
84
85
/**
86
* This static method gets accessor to abstract record with function input,
87
* dispatch to correct constructor and initialize appropriate function object from the input.
88
* Returns shared pointer to FunctionBase<>.
89
*/
90
static
std::shared_ptr< FieldBase<spacedim, Value> >
91
function_factory
(
const
Input::AbstractRecord
&rec,
unsigned
int
n_comp
=0);
92
93
/**
94
* Function can provide way to initialize itself from the input data.
95
*
96
* TODO: make protected, should be called through function factory
97
*/
98
virtual
void
init_from_input
(
const
Input::Record
&rec);
99
100
/**
101
* Set new time value. Some Fields may and some may not implement time dependent values and
102
* possibly various types of interpolation. There can not be unified approach to interpolation (at least not on this abstraction level)
103
* since some fields (FieldFormula, FieldPython) provides naturally time dependent functions other fields like (FieldConstant, ...), however,
104
* can be equipped by various time interpolation schemes. In future, we obviously need time interpolation of higher order so that
105
* we can use ODE integrators of higher order.
106
*
107
* The method returns true if the value of the field has changed in the new time step.
108
*/
109
virtual
bool
set_time
(
double
time);
110
111
/**
112
* Is used only by some Field implementations, but can be used to check validity of incoming ElementAccessor in value methods.
113
*
114
* Optional parameter @p boundary_domain can be used to specify, that the field will be evaluated only on the boundary part of the mesh.
115
* TODO: make separate mesh for the boundary, then we can drop this parameter.
116
*/
117
virtual
void
set_mesh
(
const
Mesh
*mesh,
bool
boundary_domain);
118
119
/**
120
* Returns number of rows, i.e. number of components for variable size vectors. For values of fixed size returns zero.
121
*/
122
unsigned
int
n_comp
()
const
;
123
124
/**
125
* Special field values spatially constant. Could allow optimization of tensor multiplication and
126
* tensor or vector addition. field_result_ should be set in constructor and in set_time method of particular Field implementation.
127
*/
128
FieldResult
field_result
()
const
129
{
return
field_result_
;}
130
131
/**
132
* Method for getting some information about next time where the function change its character.
133
* Used to add appropriate TimeMarks.
134
* TODO: think what kind of information we may need, is the next time value enough?
135
*/
136
virtual
double
next_change_time
()
137
{
ASSERT
(0,
"Not implemented yet."
);
return
0.0; }
138
139
/**
140
* Returns one value in one given point @p on an element given by ElementAccessor @p elm.
141
* It returns reference to he actual value in order to avoid temporaries for vector and tensor values.
142
*
143
* This method just call the later one @p value(Point, ElementAccessor, Value) and drops the FieldResult.
144
*
145
* Usual implementation of this method fills @p member r_value_ through unified envelope @p value_ as general tensor
146
* and then returns member @p r_value_. However, some particular Fields may have result stored elsewhere, in such a case
147
* the reference to the result can be returned directly without using the member @p value_. Keeping such wide space for optimization
148
* has drawback in slow generic implementation of the @p value_list method that fills whole vector of values for vector of points.
149
* Its generic implementation has to copy all values instead of directly store them into the vector of result values.
150
*
151
* So the best practice when implementing @p value and @value_list methods in particular FieldBase descendant is
152
* implement some thing like value(point, elm, Value::return_type &value) and using
153
* s having in part
154
*
155
*/
156
virtual
typename
Value::return_type
const
&
value
(
const
Point
&p,
const
ElementAccessor<spacedim>
&elm)=0;
157
158
/**
159
* Pure virtual method. At least this has to be implemented by descendants.
160
* Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
161
*/
162
//virtual FieldResult value(const Space<spacedim>::Point &p, ElementAccessor<spacedim> &elm, typename Value::return_type &value) =0;
163
164
/**
165
* Returns std::vector of scalar values in several points at once. The base class implements
166
* trivial implementation using the @p value(,,) method. This is not optimal as it involves lot of virtual calls,
167
* but this overhead can be negligible for more complex fields as Python of Formula.
168
*/
169
virtual
void
value_list
(
const
std::vector< Point >
&point_list,
const
ElementAccessor<spacedim>
&elm,
170
std::vector<typename Value::return_type>
&
value_list
)=0;
171
172
/**
173
* Virtual destructor.
174
*/
175
virtual
~FieldBase
() {}
176
177
178
protected
:
179
/// Actual time level; initial value is -infinity.
180
double
time_
;
181
/// Last value, prevents passing large values (vectors) by value.
182
Value
value_
;
183
typename
Value::return_type
r_value_
;
184
/// Indicator of particular values (zero, one) constant over space.
185
FieldResult
field_result_
;
186
};
187
188
189
#endif
/* FUNCTION_BASE_HH_ */
Generated on Thu May 29 2014 23:14:47 for Flow123d by
1.8.4