Flow123d
field_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_BASE_IMPL_HH_
10 #define FIELD_BASE_IMPL_HH_
11 
12 #include <string>
13 #include <limits>
14 #include <memory>
15 using namespace std;
16 
17 #include "fields/field_base.hh"
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 FieldBase<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< FieldBase<spacedim, Value> >
79 {
80  shared_ptr< FieldBase<spacedim, Value> > func;
81 
83  //xprintf(PrgErr,"TYPE of Field currently not functional.\n");
84  func=make_shared< FieldInterpolatedP0<spacedim,Value> >(n_comp);
85 #ifdef HAVE_PYTHON
86  } else if (rec.type() == FieldPython<spacedim,Value>::input_type ) {
87  func=make_shared< FieldPython<spacedim, Value> >(n_comp);
88 #endif
89  } else if (rec.type() == FieldConstant<spacedim, Value>::input_type ) {
90  func=make_shared< FieldConstant<spacedim,Value> >(n_comp);
91  } else if (rec.type() == FieldFormula<spacedim,Value>::input_type ) {
92  func=make_shared< FieldFormula<spacedim,Value> >(n_comp);
94  func=make_shared< FieldElementwise<spacedim,Value> >(n_comp);
95  } else {
96  xprintf(PrgErr,"TYPE of Field is out of set of descendants. SHOULD NOT HAPPEN.\n");
97  }
98  func->init_from_input(rec);
99  return func;
100 }
101 
102 
103 
104 template <int spacedim, class Value>
106  xprintf(PrgErr, "The field '%s' do not support initialization from input.\n",
107  typeid(this).name());
108 }
109 
110 
111 
112 template <int spacedim, class Value>
114  time_ = time;
115  return false; // no change
116 }
117 
118 
119 
120 template <int spacedim, class Value>
121 void FieldBase<spacedim, Value>::set_mesh(const Mesh *mesh, bool boundary_domain) {
122 }
123 
124 
125 
126 template<int spacedim, class Value>
128  return (Value::NRows_ ? 0 : value_.n_rows());
129 }
130 
131 
132 
133 
134 
135 /****************************************************************************
136  * Macros for explicit instantiation of particular field class template.
137  */
138 
139 
140 // Instantiation of fields with values dependent of the dimension of range space
141 #define INSTANCE_DIM_DEP_VALUES( field, dim_from, dim_to) \
142 template class field<dim_from, FieldValue<dim_to>::VectorFixed >; \
143 template class field<dim_from, FieldValue<dim_to>::TensorFixed >; \
144 
145 // Instantiation of fields with domain in the ambient space of dimension @p dim_from
146 #define INSTANCE_TO_ALL(field, dim_from) \
147 template class field<dim_from, FieldValue<0>::Enum >; \
148 template class field<dim_from, FieldValue<0>::EnumVector >; \
149 template class field<dim_from, FieldValue<0>::Integer >; \
150 template class field<dim_from, FieldValue<0>::Scalar >; \
151 template class field<dim_from, FieldValue<0>::Vector >; \
152 \
153 INSTANCE_DIM_DEP_VALUES( field, dim_from, 2) \
154 INSTANCE_DIM_DEP_VALUES( field, dim_from, 3) \
155 
156 /*#define INSTANCE_ALL(field) \
157 INSTANCE_TO_ALL(field, 0) \
158 INSTANCE_TO_ALL( field, 1) \
159 INSTANCE_TO_ALL( field, 2) \
160 INSTANCE_TO_ALL( field, 3) */
161 
162 // All instances of one field class template @p field.
163 // currently we need only fields on 3D ambient space (and 2D for some tests)
164 // so this is to save compilation time and avoid memory problems on the test server
165 #define INSTANCE_ALL(field) \
166 INSTANCE_TO_ALL( field, 3) \
167 INSTANCE_TO_ALL( field, 2)
168 // currently we use only 3D ambient space
169 // INSTANCE_TO_ALL( field, 2)
170 
171 
172 
173 
174 #endif //FUNCTION_BASE_IMPL_HH_