Flow123d  last_with_con_2.0.0-4-g42e6930
field_algo_base.impl.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file field_algo_base.impl.hh
15  * @brief
16  */
17 
18 #ifndef field_algo_base_IMPL_HH_
19 #define field_algo_base_IMPL_HH_
20 
21 #include <string>
22 #include <limits>
23 #include <memory>
24 using namespace std;
25 
28 #include "fields/field_python.hh"
29 #include "fields/field_constant.hh"
30 #include "fields/field_formula.hh"
32 
33 #include "fields/field_values.hh"
34 
35 #include "tools/time_governor.hh"
36 #include "input/factory.hh"
37 #include "input/accessors.hh"
39 
40 namespace it = Input::Type;
41 
42 
43 
44 
45 /******************************************************************************************
46  * Implementation of FieldBase<...>
47  */
48 
49 template <int spacedim, class Value>
51 : value_(r_value_),
52  field_result_(result_other),
53  component_idx_(std::numeric_limits<unsigned int>::max())
54 {
55  value_.set_n_comp(n_comp);
56 }
57 
58 
59 
60 template <int spacedim, class Value>
62  return boost::str(boost::format("R%i -> %s") % spacedim % Value::type_name() );
63 }
64 
65 
66 
67 template <int spacedim, class Value>
69  stringstream ss;
70  ss << "[" << Value::NRows_ << ", " << Value::NCols_ << "]";
71  return it::Abstract("Field:"+template_name(), "Abstract for all time-space functions.")
72  .allow_auto_conversion("FieldConstant")
75  .close();
76 }
77 
78 
79 template <int spacedim, class Value>
82  if (is_enum_valued) {
83  ASSERT( !(value_selection==Input::Type::Selection()) ).error("Not defined 'value_selection' for enum element type.\n");
84  param_vec.push_back( std::make_pair("element_input_type", std::make_shared<it::Selection>(value_selection)) );
85  } else {
86  param_vec.push_back( std::make_pair("element_input_type", std::make_shared<typename Value::ElementInputType>()) );
87  }
88 
89  return it::Instance(get_input_type(), param_vec).close();
90 }
91 
92 
93 
94 template <int spacedim, class Value>
95 shared_ptr< FieldAlgorithmBase<spacedim, Value> >
97 {
98  shared_ptr< FieldAlgorithmBase<spacedim, Value> > func;
100  func->init_from_input(rec);
101  return func;
102 }
103 
104 
105 
106 template <int spacedim, class Value>
108  xprintf(PrgErr, "The field '%s' do not support initialization from input.\n",
109  typeid(this).name());
110 }
111 
112 
113 
114 template <int spacedim, class Value>
116  time_ = time;
117  return false; // no change
118 }
119 
120 
121 
122 template <int spacedim, class Value>
123 void FieldAlgorithmBase<spacedim, Value>::set_mesh(const Mesh *mesh, bool boundary_domain) {
124 }
125 
126 
127 
128 template<int spacedim, class Value>
130  return (Value::NRows_ ? 0 : value_.n_rows());
131 }
132 
133 
134 
135 template<int spacedim, class Value>
137  const std::vector< Point > &point_list,
138  const ElementAccessor<spacedim> &elm,
140 {
141  ASSERT_EQ( point_list.size(), value_list.size() ).error();
142  for(unsigned int i=0; i< point_list.size(); i++) {
143  ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows() )(i)(Value(value_list[i]).n_rows())(this->value_.n_rows())
144  .error("value_list has wrong number of rows");
145  value_list[i]=this->value(point_list[i], elm);
146  }
147 
148 }
149 
150 
151 
152 /****************************************************************************
153  * Macros for explicit instantiation of particular field class template.
154  */
155 
156 
157 // Instantiation of fields with values dependent of the dimension of range space
158 #define INSTANCE_DIM_DEP_VALUES( field, dim_from, dim_to) \
159 template class field<dim_from, FieldValue<dim_to>::VectorFixed >; \
160 template class field<dim_from, FieldValue<dim_to>::TensorFixed >; \
161 
162 // Instantiation of fields with domain in the ambient space of dimension @p dim_from
163 #define INSTANCE_TO_ALL(field, dim_from) \
164 template class field<dim_from, FieldValue<0>::Enum >; \
165 template class field<dim_from, FieldValue<0>::Integer >; \
166 template class field<dim_from, FieldValue<0>::Scalar >; \
167 \
168 INSTANCE_DIM_DEP_VALUES( field, dim_from, dim_from) \
169 
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_
TimeStep time_
Actual time level; initial value is -infinity.
Abstract & allow_auto_conversion(const string &type_default)
Allows shorter input of the Abstract providing the default value to the "TYPE" key.
static const Input::Type::Instance & get_input_type_instance(Input::Type::Selection value_selection=Input::Type::Selection())
virtual bool set_time(const TimeStep &time)
const Instance & close() const
Used for set Instance to TypeRepository.
virtual void value_list(const std::vector< Point > &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)=0
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
Definition: mesh.h:95
Helper class that stores data of generic types.
Definition: type_generic.hh:88
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
Definition: asserts.hh:347
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)=0
Abstract & add_attribute(std::string key, TypeBase::json_string value)
Frontend to TypeBase::add_attribute_.
Basic time management class.
static constexpr bool is_enum_valued
Accessor to the data with type Type::Record.
Definition: accessors.hh:277
#define xprintf(...)
Definition: system.hh:87
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, unsigned int n_comp=0)
static string field_value_shape()
Class for declaration of polymorphic Record.
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:444
Abstract & root_of_generic_subtree()
FieldAlgorithmBase(unsigned int n_comp=0)
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: system.hh:59
static Input::Type::Abstract & get_input_type()
virtual void set_mesh(const Mesh *mesh, bool boundary_domain)
const std::shared_ptr< Type > factory(Arguments...arguments) const
static std::string template_name()
Representation of one time step..
Template for classes storing finite set of named values.
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328
unsigned int n_comp() const
virtual void init_from_input(const Input::Record &rec)