Flow123d  last_with_con_2.0.0-4-g42e6930
field_constant.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_constant.impl.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_CONSTANT_IMPL_HH_
19 #define FIELD_CONSTANT_IMPL_HH_
20 
21 #include "fields/field_constant.hh"
22 #include "input/input_type.hh"
23 
24 
25 /// Implementation.
26 
27 namespace it = Input::Type;
28 
29 FLOW123D_FORCE_LINK_IN_CHILD(field_constant)
30 
31 
32 template <int spacedim, class Value>
33 const Input::Type::Record & FieldConstant<spacedim, Value>::get_input_type()
34 {
35  return it::Record("FieldConstant", FieldAlgorithmBase<spacedim,Value>::template_name()+" Field constant in space.")
37  .declare_key("value", Value::get_input_type(), it::Default::obligatory(),
38  "Value of the constant field.\n"
39  "For vector values, you can use scalar value to enter constant vector.\n"
40  "For square (($N\\times N$))-matrix values, you can use:\n"
41  " - vector of size (($N$)) to enter diagonal matrix\n\n"
42  " - vector of size (($\\frac12N(N+1)$)) to enter symmetric matrix (upper triangle, row by row)\n"
43  " - scalar to enter multiple of the unit matrix." )
44  .allow_auto_conversion("value")
45  .close();
46 }
47 
48 template <int spacedim, class Value>
50  Input::register_class< FieldConstant<spacedim, Value>, unsigned int >("FieldConstant") +
52 
53 
54 template <int spacedim, class Value>
56 : FieldAlgorithmBase<spacedim, Value>(n_comp)
57 {}
58 
59 
60 template <int spacedim, class Value>
62 {
63  this->r_value_ = val;
64 
65  return *this;
66 }
67 
68 
69 template <int spacedim, class Value>
71  this->value_.init_from_input( rec.val<typename Value::AccessType>("value") );
72 
73  typename Value::return_type tmp_value;
74  Value tmp_field_value(tmp_value);
75  tmp_field_value.set_n_comp(this->n_comp());
76 
77  tmp_field_value.zeros();
78  if ( this->value_.equal_to(tmp_value) ) {
80  return;
81  }
82 
83 
84  tmp_field_value.ones();
85  if ( this->value_.equal_to(tmp_value) ) {
86  this->field_result_ = result_ones;
87  return;
88  }
89 
90  // This check must be the last one, since for scalar and vector values ones() == eye().
91  // For vector, eye() does nothing. So, the value of tmp_value remains equal to ones().
92  tmp_field_value.eye();
93  if ( this->value_.equal_to(tmp_value) ) {
94  this->field_result_ = result_eye;
95  return;
96  }
97 
98 
100 }
101 
102 
103 
104 /**
105  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
106  */
107 template <int spacedim, class Value>
108 typename Value::return_type const & FieldConstant<spacedim, Value>::value(const Point &p, const ElementAccessor<spacedim> &elm)
109 {
110  return this->r_value_;
111 }
112 
113 
114 
115 /**
116  * Returns std::vector of scalar values in several points at once.
117  */
118 template <int spacedim, class Value>
121 {
122  OLD_ASSERT_EQUAL( point_list.size(), value_list.size() );
123 
124  for(unsigned int i=0; i< point_list.size(); i++) {
125  OLD_ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows(),
126  "value_list[%d] has wrong number of rows: %d; should match number of components: %d\n",
127  i, Value(value_list[i]).n_rows(),this->value_.n_rows());
128 
129 
130  value_list[i]=this->r_value_;
131  }
132 }
133 
134 
135 
136 template <int spacedim, class Value>
138 }
139 
140 
141 
142 #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)
FieldResult field_result_
Indicator of particular values (zero, one) constant over space.
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()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:99
virtual Value::return_type const & value(const Point &p, const ElementAccessor< spacedim > &elm)
Value::return_type r_value_
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:286
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:195
#define OLD_ASSERT(...)
Definition: global_defs.h:131
virtual Record & allow_auto_conversion(const string &from_key)
Allows shorter input of the Record providing only value of the from_key given as the parameter...
Definition: type_record.cc:132
Accessor to the data with type Type::Record.
Definition: accessors.hh:277
const Ret val(const string &key) const
FieldConstant(unsigned int n_comp=0)
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:468
Space< spacedim >::Point Point
Value value_
Last value, prevents passing large values (vectors) by value.
#define OLD_ASSERT_EQUAL(a, b)
Definition: global_defs.h:133
Record type proxy class.
Definition: type_record.hh:171
#define FLOW123D_FORCE_LINK_IN_CHILD(x)
Definition: global_defs.h:180
unsigned int n_comp() const