Flow123d  jenkins-Flow123d-windows-release-multijob-285
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 /// Implementation.
16 
17 namespace it = Input::Type;
18 
19 template <int spacedim, class Value>
22 
23 
24 template <int spacedim, class Value>
26  Input::Type::AbstractRecord &a_type, const typename Value::ElementInputType *eit
27  )
28 {
29  it::Record type=
30  it::Record("FieldConstant", FieldAlgorithmBase<spacedim,Value>::template_name()+" Field constant in space.")
31  .derive_from(a_type)
32  .declare_key("value", Value::get_input_type(eit), it::Default::obligatory(),
33  "Value of the constant field.\n"
34  "For vector values, you can use scalar value to enter constant vector.\n"
35  "For square NxN-matrix values, you can use:\n"
36  "* vector of size N to enter diagonal matrix\n"
37  "* vector of size (N+1)*N/2 to enter symmetric matrix (upper triangle, row by row)\n"
38  "* scalar to enter multiple of the unit matrix." )
39  .allow_auto_conversion("value");
40 
41  return type;
42 }
43 
44 
45 
46 template <int spacedim, class Value>
48 : FieldAlgorithmBase<spacedim, Value>(n_comp)
49 {}
50 
51 
52 template <int spacedim, class Value>
54 {
55  this->r_value_ = val;
56 
57  return *this;
58 }
59 
60 
61 template <int spacedim, class Value>
63  this->value_.init_from_input( rec.val<typename Value::AccessType>("value") );
64 }
65 
66 
67 
68 /**
69  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
70  */
71 template <int spacedim, class Value>
72 typename Value::return_type const & FieldConstant<spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
73 {
74  return this->r_value_;
75 }
76 
77 
78 
79 /**
80  * Returns std::vector of scalar values in several points at once.
81  */
82 template <int spacedim, class Value>
85 {
86  ASSERT_EQUAL( point_list.size(), value_list.size() );
87 
88  for(unsigned int i=0; i< point_list.size(); i++) {
89  ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows(),
90  "value_list[%d] has wrong number of rows: %d; should match number of components: %d\n",
91  i, Value(value_list[i]).n_rows(),this->value_.n_rows());
92 
93 
94  value_list[i]=this->r_value_;
95  }
96 }
97 
98 
99 
100 template <int spacedim, class Value>
102 }
103 
104 
105 
106 #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:89
Record & derive_from(AbstractRecord &parent)
Definition: type_record.cc:197
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:111
#define ASSERT(...)
Definition: global_defs.h:121
#define ASSERT_EQUAL(a, b)
Definition: global_defs.h:136
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
const Ret val(const string &key) const
FieldConstant(unsigned int n_comp=0)
Class for declaration of polymorphic Record.
Definition: type_record.hh:487
Space< spacedim >::Point Point
Record type proxy class.
Definition: type_record.hh:169
Record & declare_key(const string &key, const KeyType &type, const Default &default_value, const string &description)
Definition: type_record.cc:430