Flow123d  jenkins-Flow123d-windows32-release-multijob-51
field_algo_base.impl.hh
Go to the documentation of this file.
1 /*
2  * function_base_impl.hh
3  *
4  * Created on: Oct 1, 2012
5  * Author: jb
6  */
7 
8 
9 #ifndef field_algo_base_IMPL_HH_
10 #define field_algo_base_IMPL_HH_
11 
12 #include <string>
13 #include <limits>
14 #include <memory>
15 using namespace std;
16 
19 #include "fields/field_python.hh"
20 #include "fields/field_constant.hh"
21 #include "fields/field_formula.hh"
23 
24 #include "fields/field_values.hh"
25 
26 
27 namespace it = Input::Type;
28 
29 
30 /******************************************************************************************
31  * Implementation of FieldBase<...>
32  */
33 
34 template <int spacedim, class Value>
36 : time_( -numeric_limits<double>::infinity() ),
37  value_(r_value_)
38 {
39  value_.set_n_comp(n_comp);
40 }
41 
42 
43 
44 template <int spacedim, class Value>
46  return boost::str(boost::format("R%i -> %s") % spacedim % Value::type_name() );
47 }
48 
49 
50 
51 template <int spacedim, class Value>
53  = it::AbstractRecord("Field:"+template_name(), "Abstract record for all time-space functions.")
54  .allow_auto_conversion("FieldConstant");
55 
56 
57 
58 template <int spacedim, class Value>
59 Input::Type::AbstractRecord FieldAlgorithmBase<spacedim, Value>::get_input_type(const typename Value::ElementInputType *element_input_type) {
60  it::AbstractRecord type= it::AbstractRecord("Field:"+template_name(), "Abstract record for all time-space functions.");
61  type.allow_auto_conversion("FieldConstant");
62 
63  FieldConstant<spacedim,Value>::get_input_type(type, element_input_type);
64  FieldFormula<spacedim,Value>::get_input_type(type, element_input_type);
65 #ifdef HAVE_PYTHON
66  FieldPython<spacedim,Value>::get_input_type(type, element_input_type);
67 #endif
69  FieldElementwise<spacedim,Value>::get_input_type(type, element_input_type);
70 
71  return type;
72 }
73 
74 
75 
76 template <int spacedim, class Value>
77 shared_ptr< FieldAlgorithmBase<spacedim, Value> >
79 {
80  shared_ptr< FieldAlgorithmBase<spacedim, Value> > func;
81 
83  func=make_shared< FieldInterpolatedP0<spacedim,Value> >(n_comp);
84 #ifdef HAVE_PYTHON
85  } else if (rec.type() == FieldPython<spacedim,Value>::input_type ) {
86  func=make_shared< FieldPython<spacedim, Value> >(n_comp);
87 #endif
88  } else if (rec.type() == FieldConstant<spacedim, Value>::input_type ) {
89  func=make_shared< FieldConstant<spacedim,Value> >(n_comp);
90  } else if (rec.type() == FieldFormula<spacedim,Value>::input_type ) {
91  func=make_shared< FieldFormula<spacedim,Value> >(n_comp);
93  func=make_shared< FieldElementwise<spacedim,Value> >(n_comp);
94  } else {
95  xprintf(PrgErr,"TYPE of Field is out of set of descendants. SHOULD NOT HAPPEN.\n");
96  }
97  func->init_from_input(rec);
98  return func;
99 }
100 
101 
102 
103 template <int spacedim, class Value>
105  xprintf(PrgErr, "The field '%s' do not support initialization from input.\n",
106  typeid(this).name());
107 }
108 
109 
110 
111 template <int spacedim, class Value>
113  time_ = time;
114  return false; // no change
115 }
116 
117 
118 
119 template <int spacedim, class Value>
120 void FieldAlgorithmBase<spacedim, Value>::set_mesh(const Mesh *mesh, bool boundary_domain) {
121 }
122 
123 
124 
125 template<int spacedim, class Value>
127  return (Value::NRows_ ? 0 : value_.n_rows());
128 }
129 
130 
131 
132 template<int spacedim, class Value>
134  const std::vector< Point > &point_list,
135  const ElementAccessor<spacedim> &elm,
137 {
138  ASSERT_EQUAL( point_list.size(), value_list.size() );
139  for(unsigned int i=0; i< point_list.size(); i++) {
140  ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows(),
141  "value_list[%d] has wrong number of rows: %d; should match number of components: %d\n",
142  i, Value(value_list[i]).n_rows(),this->value_.n_rows());
143  value_list[i]=this->value(point_list[i], elm);
144  }
145 
146 }
147 
148 
149 
150 /****************************************************************************
151  * Macros for explicit instantiation of particular field class template.
152  */
153 
154 
155 // Instantiation of fields with values dependent of the dimension of range space
156 #define INSTANCE_DIM_DEP_VALUES( field, dim_from, dim_to) \
157 template class field<dim_from, FieldValue<dim_to>::VectorFixed >; \
158 template class field<dim_from, FieldValue<dim_to>::TensorFixed >; \
159 
160 // Instantiation of fields with domain in the ambient space of dimension @p dim_from
161 #define INSTANCE_TO_ALL(field, dim_from) \
162 template class field<dim_from, FieldValue<0>::Enum >; \
163 template class field<dim_from, FieldValue<0>::EnumVector >; \
164 template class field<dim_from, FieldValue<0>::Integer >; \
165 template class field<dim_from, FieldValue<0>::Scalar >; \
166 template class field<dim_from, FieldValue<0>::Vector >; \
167 \
168 INSTANCE_DIM_DEP_VALUES( field, dim_from, 2) \
169 INSTANCE_DIM_DEP_VALUES( field, dim_from, 3) \
170 
171 // All instances of one field class template @p field.
172 // currently we need only fields on 3D ambient space (and 2D for some tests)
173 // so this is to save compilation time and avoid memory problems on the test server
174 #define INSTANCE_ALL(field) \
175 INSTANCE_TO_ALL( field, 3) \
176 INSTANCE_TO_ALL( field, 2)
177 // currently we use only 3D ambient space
178 
179 
180 
181 
182 #endif //FUNCTION_BASE_IMPL_HH_
static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit)
static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit)
static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit)
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)=0
Definition: mesh.h:108
AbstractRecord & allow_auto_conversion(const string &type_default)
Definition: type_record.cc:503
static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit)
#define ASSERT(...)
Definition: global_defs.h:121
static Input::Type::AbstractRecord get_input_type(const typename Value::ElementInputType *element_input_type=nullptr)
#define ASSERT_EQUAL(a, b)
Definition: global_defs.h:136
Input::Type::Record type() const
Definition: accessors.cc:228
Accessor to the data with type Type::Record.
Definition: accessors.hh:308
static Input::Type::Record get_input_type(Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit)
#define xprintf(...)
Definition: system.hh:100
Class for declaration of polymorphic Record.
Definition: type_record.hh:463
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, unsigned int n_comp=0)
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:423
virtual bool set_time(double time)
FieldAlgorithmBase(unsigned int n_comp=0)
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: system.hh:72
virtual void set_mesh(const Mesh *mesh, bool boundary_domain)
static std::string template_name()
unsigned int n_comp() const
virtual void init_from_input(const Input::Record &rec)