Flow123d  jenkins-Flow123d-windows32-release-multijob-28
field_constant.impl.hh
Go to the documentation of this file.
1 /*
2  * field_constant.impl.hh
3  *
4  * Created on: Dec 15, 2012
5  * Author: jb
6  */
7 
8 #ifndef FIELD_CONSTANT_IMPL_HH_
9 #define FIELD_CONSTANT_IMPL_HH_
10 
11 #include "fields/field_constant.hh"
12 #include "input/input_type.hh"
13 
14 
15 //#include <boost/type_traits.hpp>
16 
17 /// Implementation.
18 
19 namespace it = Input::Type;
20 
21 template <int spacedim, class Value>
24 
25 
26 template <int spacedim, class Value>
28  Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit
29  )
30 {
31  it::Record type=
32  it::Record("FieldConstant", FieldAlgorithmBase<spacedim,Value>::template_name()+" Field constant in space.")
33  .derive_from(a_type)
34  .declare_key("value", Value::get_input_type(eit), it::Default::obligatory(),
35  "Value of the constant field.\n"
36  "For vector values, you can use scalar value to enter constant vector.\n"
37  "For square NxN-matrix values, you can use:\n"
38  "* vector of size N to enter diagonal matrix\n"
39  "* vector of size (N+1)*N/2 to enter symmetric matrix (upper triangle, row by row)\n"
40  "* scalar to enter multiple of the unit matrix." )
41  .allow_auto_conversion("value");
42 
43  return type;
44 }
45 
46 
47 
48 template <int spacedim, class Value>
50 : FieldAlgorithmBase<spacedim, Value>(n_comp)
51 {}
52 
53 
54 template <int spacedim, class Value>
56 {
57  this->r_value_ = val;
58 
59  return *this;
60 }
61 
62 
63 template <int spacedim, class Value>
65  this->value_.init_from_input( rec.val<typename Value::AccessType>("value") );
66 }
67 
68 
69 
70 /**
71  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
72  */
73 template <int spacedim, class Value>
74 typename Value::return_type const & FieldConstant<spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
75 {
76  return this->r_value_;
77 }
78 
79 
80 
81 /**
82  * Returns std::vector of scalar values in several points at once.
83  */
84 template <int spacedim, class Value>
87 {
88  ASSERT_EQUAL( point_list.size(), value_list.size() );
89  for(unsigned int i=0; i< point_list.size(); i++)
90  value_list[i]=this->r_value_;
91 }
92 
93 
94 
95 template <int spacedim, class Value>
97 }
98 
99 
100 
101 #endif /* FIELD_CONSTANT_IMPL_HH_ */
FieldConstant< spacedim, Value > & set_value(const typename Value::return_type &val)
virtual void init_from_input(const Input::Record &rec)
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)
static Default obligatory()
Definition: type_record.hh:87
Record & derive_from(AbstractRecord &parent)
Definition: type_record.cc:172
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Record & allow_auto_conversion(const string &from_key)
Definition: type_record.cc:83
#define ASSERT_EQUAL(a, b)
Definition: global_defs.h:135
Accessor to the data with type Type::Record.
Definition: accessors.hh:308
const Ret val(const string &key) const
FieldConstant(unsigned int n_comp=0)
Class for declaration of polymorphic Record.
Definition: type_record.hh:467
Space< spacedim >::Point Point
virtual ~FieldConstant()
Record type proxy class.
Definition: type_record.hh:161
Record & declare_key(const string &key, const KeyType &type, const Default &default_value, const string &description)
Definition: type_record.cc:390