Flow123d  JS_before_hm-1818-ge572947f9
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 
27 
28 #include "fields/field_values.hh"
29 
30 #include "tools/unit_converter.hh"
31 
32 #include "tools/time_governor.hh"
33 #include "input/factory.hh"
34 #include "input/accessors.hh"
36 
37 namespace it = Input::Type;
38 
39 
40 
41 
42 /******************************************************************************************
43  * Implementation of FieldBase<...>
44  */
45 
46 template <int spacedim, class Value>
48 : value_(r_value_),
49  field_result_(result_other),
50  component_idx_(std::numeric_limits<unsigned int>::max()),
51  unit_conversion_coefficient_(1.0)
52 {
53  value_.set_n_comp(n_comp);
54 }
55 
56 
57 
58 template <int spacedim, class Value>
60  return fmt::format("R{:d}_to_{}", spacedim, Value::type_name() );
61 }
62 
63 
64 
65 template <int spacedim, class Value>
67  stringstream ss;
68  ss << "[" << Value::NRows_ << ", " << Value::NCols_ << "]";
69  return it::Abstract("Field_"+template_name(), "Abstract for all time-space functions.")
70  .allow_auto_conversion("FieldConstant")
73  .close();
74 }
75 
76 
77 template <int spacedim, class Value>
80  if (is_enum_valued) {
81  ASSERT( !(value_selection==Input::Type::Selection()) ).error("Not defined 'value_selection' for enum element type.\n");
82  param_vec.push_back( std::make_pair("element_input_type", std::make_shared<it::Selection>(value_selection)) );
83  } else {
84  param_vec.push_back( std::make_pair("element_input_type", std::make_shared<typename Value::ElementInputType>()) );
85  }
86 
87  return it::Instance(get_input_type(), param_vec).close();
88 }
89 
90 template <int spacedim, class Value>
92  return it::Record("FieldAlgorithmBase_common_aux", "")
94  "Unit of the field values provided in the main input file, in the external file, or "
95  "by a function (FieldPython).")
96  .close();
97 }
98 
99 template <int spacedim, class Value>
100 shared_ptr< FieldAlgorithmBase<spacedim, Value> >
102 {
103  shared_ptr< FieldAlgorithmBase<spacedim, Value> > func;
104  func = rec.factory< FieldAlgorithmBase<spacedim, Value> >(init_data.n_comp_);
105  func->init_from_input(rec, init_data);
106  return func;
107 }
108 
109 
110 
111 template <int spacedim, class Value>
113  THROW( ExcInputInitUnsupported() << EI_Field(typeid(this).name()) );
114 }
115 
116 
117 
118 template <int spacedim, class Value>
120  time_ = time;
121  return false; // no change
122 }
123 
124 
125 
126 template <int spacedim, class Value>
128 }
129 
130 
131 
132 template<int spacedim, class Value>
134  return (Value::NRows_ ? 0 : value_.n_rows());
135 }
136 
137 
138 template<int spacedim, class Value>
141  FMT_UNUSED ElementCacheMap &cache_map,
142  FMT_UNUSED unsigned int region_patch_idx)
143 {
144  ASSERT_DBG(false).error("Must be implemented in descendants!\n");
145 }
146 
147 
148 template<int spacedim, class Value>
150 {}
151 
152 
153 template<int spacedim, class Value>
155  const Armor::array &point_list,
156  const ElementAccessor<spacedim> &elm,
158 {
159  ASSERT_EQ( point_list.size(), value_list.size() ).error();
160  ASSERT_DBG(point_list.n_rows() == spacedim && point_list.n_cols() == 1).error("Invalid point size.\n");
161  for(unsigned int i=0; i< point_list.size(); i++) {
162  ASSERT( Value(value_list[i]).n_rows()==this->value_.n_rows() )(i)(Value(value_list[i]).n_rows())(this->value_.n_rows())
163  .error("value_list has wrong number of rows");
164  value_list[i]=this->value(point_list.vec<spacedim>(i), elm);
165  }
166 
167 }
168 
169 template<int spacedim, class Value>
171  const struct FieldAlgoBaseInitData& init_data)
172 {
173  Input::Record unit_record;
174  if ( rec.opt_val("unit", unit_record) ) {
175  if (!Value::is_scalable()) {
176  WarningOut().fmt("Setting unit conversion coefficient of non-floating point field at address {}\nCoefficient will be skipped.\n",
177  rec.address_string());
178  }
179  std::string unit_str = unit_record.val<std::string>("unit_formula");
180  try {
181  this->unit_conversion_coefficient_ = init_data.unit_si_.convert_unit_from(unit_str);
182  } catch (ExcInvalidUnit &e) {
183  e << rec.ei_address();
184  throw;
185  } catch (ExcNoncorrespondingUnit &e) {
186  e << rec.ei_address();
187  throw;
188  }
189  }
190 }
191 
192 
193 
194 
195 #endif //FUNCTION_BASE_IMPL_HH_
Input::AbstractRecord::factory
const std::shared_ptr< Type > factory(Arguments... arguments) const
Definition: accessors_impl.hh:135
FieldAlgorithmBase::n_comp
unsigned int n_comp() const
Definition: field_algo_base.impl.hh:133
factory.hh
time_governor.hh
Basic time management class.
field_algo_base.hh
Input::Type::Instance::close
const Instance & close() const
Used for set Instance to TypeRepository.
Definition: type_generic.cc:108
ASSERT
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
Definition: asserts.hh:347
FieldAlgorithmBase::value_list
virtual void value_list(const Armor::array &point_list, const ElementAccessor< spacedim > &elm, std::vector< typename Value::return_type > &value_list)=0
Definition: field_algo_base.impl.hh:154
FieldAlgorithmBase::get_field_algo_common_keys
static const Input::Type::Record & get_field_algo_common_keys()
Definition: field_algo_base.impl.hh:91
ElementCacheMap
Directing class of FieldValueCache.
Definition: field_value_cache.hh:151
FieldAlgorithmBase::cache_reinit
virtual void cache_reinit(const ElementCacheMap &cache_map)
Allows reinit data members or structures in descendants during reinit of FieldValueCache of 'parental...
Definition: field_algo_base.impl.hh:149
Input::Record::val
const Ret val(const string &key) const
Definition: accessors_impl.hh:31
FieldAlgorithmBase::get_input_type_instance
static const Input::Type::Instance & get_input_type_instance(Input::Type::Selection value_selection=Input::Type::Selection())
Definition: field_algo_base.impl.hh:78
Armor::Array::vec
ArmaVec< Type, nr > vec(uint mat_index) const
Definition: armor.hh:821
value
static constexpr bool value
Definition: json.hpp:87
ASSERT_DBG
#define ASSERT_DBG(expr)
Definition: include_fadbad.hh:28
result_other
@ result_other
Definition: field_algo_base.hh:72
FieldAlgoBaseInitData::unit_si_
const UnitSI & unit_si_
Definition: field_algo_base.hh:93
THROW
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
std::vector
Definition: doxy_dummy_defs.hh:7
ElementAccessor
Definition: dh_cell_accessor.hh:32
UnitSI::convert_unit_from
double convert_unit_from(std::string actual_unit) const
Convert and check user-defined unit.
Definition: unit_si.cc:217
FieldAlgorithmBase::get_input_type
static Input::Type::Abstract & get_input_type()
Definition: field_algo_base.impl.hh:66
fmt::format
std::string format(CStringRef format_str, ArgList args)
Definition: format.h:3141
FlowAttribute::field_value_shape
static string field_value_shape()
Definition: flow_attribute_lib.hh:47
Input::Record::address_string
string address_string() const
Definition: accessors.cc:184
Armor::Array::n_rows
uint n_rows() const
Definition: armor.hh:715
FieldAlgoBaseInitData::n_comp_
unsigned int n_comp_
Definition: field_algo_base.hh:92
Input::Type::Abstract::root_of_generic_subtree
Abstract & root_of_generic_subtree()
Definition: type_abstract.cc:278
FieldAlgorithmBase::FieldAlgorithmBase
FieldAlgorithmBase(unsigned int n_comp=0)
Definition: field_algo_base.impl.hh:47
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FieldAlgorithmBase::cache_update
virtual void cache_update(FieldValueCache< typename Value::element_type > &data_cache, ElementCacheMap &cache_map, unsigned int region_patch_idx)
Definition: field_algo_base.impl.hh:139
FieldAlgoBaseInitData
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
Definition: field_algo_base.hh:81
FieldAlgorithmBase::init_from_input
virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data)
Definition: field_algo_base.impl.hh:112
accessors.hh
flow_attribute_lib.hh
TimeStep
Representation of one time step..
Definition: time_governor.hh:123
FieldAlgorithmBase::value_
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: field_algo_base.hh:280
FieldAlgorithmBase::init_unit_conversion_coefficient
void init_unit_conversion_coefficient(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data)
Init value of unit_conversion_coefficient_ from input.
Definition: field_algo_base.impl.hh:170
field_values.hh
Input::AbstractRecord
Accessor to the polymorphic input data of a type given by an AbstracRecord object.
Definition: accessors.hh:458
Input::Type::Abstract::add_attribute
Abstract & add_attribute(std::string key, TypeBase::json_string value)
Frontend to TypeBase::add_attribute_.
Definition: type_abstract.cc:284
Input::Type::Abstract
Class for declaration of polymorphic Record.
Definition: type_abstract.hh:62
Input::Record::ei_address
EI_Address ei_address() const
Definition: accessors.cc:178
ASSERT_EQ
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual)
Definition: asserts.hh:328
Input::Record::opt_val
bool opt_val(const string &key, Ret &value) const
Definition: accessors_impl.hh:107
Input::Type::Instance
Helper class that stores data of generic types.
Definition: type_generic.hh:89
Input::Type::Record::declare_key
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:503
FieldAlgorithmBase::set_mesh
virtual void set_mesh(const Mesh *mesh, bool boundary_domain)
Definition: field_algo_base.impl.hh:127
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
Armor::Array::n_cols
uint n_cols() const
Definition: armor.hh:720
UnitConverter::get_input_type
static const Input::Type::Record & get_input_type()
Definition: unit_converter.cc:100
Input::Type::Record::close
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Armor::Array::size
unsigned int size() const
Definition: armor.hh:728
FieldAlgorithmBase::template_name
static std::string template_name()
Definition: field_algo_base.impl.hh:59
Input::Type
Definition: balance.hh:41
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
Value
@ Value
Definition: finite_element.hh:43
Mesh
Definition: mesh.h:98
FieldAlgorithmBase
Definition: field_algo_base.hh:112
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:278
unit_converter.hh
std
Definition: doxy_dummy_defs.hh:5
Armor::Array
Definition: armor.hh:597
Input::Type::Default::optional
static Default optional()
The factory function to make an empty default value which is optional.
Definition: type_record.hh:124
Input::Type::Abstract::allow_auto_conversion
Abstract & allow_auto_conversion(const string &type_default)
Allows shorter input of the Abstract providing the default value to the "TYPE" key.
Definition: type_abstract.cc:97
Input::Type::Abstract::close
Abstract & close()
Close the Abstract and add its to type repository (see TypeRepository::add_type).
Definition: type_abstract.cc:190
FieldAlgorithmBase::set_time
virtual bool set_time(const TimeStep &time)
Definition: field_algo_base.impl.hh:119
FieldAlgorithmBase::function_factory
static std::shared_ptr< FieldAlgorithmBase< spacedim, Value > > function_factory(const Input::AbstractRecord &rec, const struct FieldAlgoBaseInitData &init_data)
Definition: field_algo_base.impl.hh:101
FMT_UNUSED
#define FMT_UNUSED
Definition: posix.h:75