Flow123d  release_3.0.0-680-gbed5aba
field_time_function.cc
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_time_function.cc
15  * @brief
16  */
17 
19 #include "fields/field_instances.hh" // for instantiation macros
20 #include "fields/table_function.hh"
21 
22 namespace it = Input::Type;
23 
24 FLOW123D_FORCE_LINK_IN_CHILD(field_time_function)
25 
26 
27 template <int spacedim, class Value>
28 const Input::Type::Record & FieldTimeFunction<spacedim, Value>::get_input_type()
29 {
30  return it::Record("FieldTimeFunction", FieldAlgorithmBase<spacedim,Value>::template_name()+" Field time-dependent function in space.")
34  "Values of time series initialization of Field.")
35  //.declare_key("unit", FieldAlgorithmBase<spacedim, Value>::get_field_algo_common_keys(), it::Default::optional(),
36  // "Definition of unit.")
37  .declare_key("time_unit", it::String(), it::Default::read_time("Common unit of TimeGovernor."),
38  "Definition of unit of all times defined in FieldTimeFunction.")
39  .allow_auto_conversion("time_function")
40  .close();
41 }
42 
43 template <int spacedim, class Value>
45  Input::register_class< FieldTimeFunction<spacedim, Value>, unsigned int >("FieldTimeFunction") +
47 
48 
49 template <int spacedim, class Value>
51 : FieldConstant<spacedim, Value>(n_comp), unit_si_( UnitSI::dimensionless() )
52 {}
53 
54 
55 template <int spacedim, class Value>
57 {
58  this->init_unit_conversion_coefficient(rec, init_data);
59  this->field_name_ = init_data.field_name_;
60  this->in_rec_ = rec;
61  this->unit_si_ = init_data.unit_si_;
62  this->limits_ = init_data.limits_;
63 }
64 
65 
66 template <int spacedim, class Value>
68 {
69  // Possible optimization: If we need set value_ repeatedly, we introduce TableFunction as class member and retrive it only once.
70  TableFunction<Value> table_function;
71 
72  if (!Value::is_scalable()) {
73  WarningOut().fmt("Setting key 'time_function' of non-floating point field at address {}\nValues will be skipped.\n",
75  }
76  table_function.init_from_input( in_rec_.val<Input::Record>("time_function") );
77  this->r_value_ = table_function.value( time.end() / time.read_coef(in_rec_.find<string>("time_unit")) );
78  this->value_.scale(this->unit_conversion_coefficient_);
79  struct FieldAlgoBaseInitData init_data(this->field_name_, 0, this->unit_si_, this->limits_, FieldFlag::Flags() );
80  this->check_field_limits(this->in_rec_, init_data);
81 
82  return true;
83 }
84 
85 
86 // Instantion of Fields
87 INSTANCE_ALL(FieldTimeFunction)
88 
void init_unit_conversion_coefficient(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data)
Init value of unit_conversion_coefficient_ from input.
void check_field_limits(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data)
Compare field value with given minimal and maximal limits.
FieldTimeFunction(unsigned int n_comp=0)
double read_coef(Input::Iterator< std::string > unit_it) const
Abstract linear system class.
Definition: balance.hh:35
bool set_time(const TimeStep &time) override
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
#define INSTANCE_ALL(field)
Iterator< Ret > find(const string &key) const
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
void init_from_input(const Input::Record &rec)
Initialize actual values of the field given from the given Input::Record rec.
Value::return_type r_value_
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:303
double unit_conversion_coefficient_
Coeficient of conversion of user-defined unit.
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:195
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
void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data)
std::pair< double, double > limits_
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
const Ret val(const string &key) const
Input::Record in_rec_
Accessor to Input::Record.
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:501
double end() const
Record & copy_keys(const Record &other)
Copy keys from other record.
Definition: type_record.cc:215
static Default read_time(const std::string &description)
The factory function to make an default value that will be specified at the time when a key will be r...
Definition: type_record.hh:97
const UnitSI & unit_si_
Value value_
Last value, prevents passing large values (vectors) by value.
return_type const & value(double t)
#define WarningOut()
Macro defining &#39;warning&#39; record of log.
Definition: logger.hh:246
std::pair< double, double > limits_
Record type proxy class.
Definition: type_record.hh:182
Class for representation SI units of Fields.
Definition: unit_si.hh:40
Class for declaration of the input data that are in string format.
Definition: type_base.hh:589
Representation of one time step..
#define FLOW123D_FORCE_LINK_IN_CHILD(x)
Definition: global_defs.h:180
string address_string() const
Definition: accessors.cc:184