Flow123d  release_2.2.0-33-g759111d
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  .allow_auto_conversion("time_function")
38  .close();
39 }
40 
41 template <int spacedim, class Value>
43  Input::register_class< FieldTimeFunction<spacedim, Value>, unsigned int >("FieldTimeFunction") +
45 
46 
47 template <int spacedim, class Value>
49 : FieldConstant<spacedim, Value>(n_comp), unit_si_( UnitSI::dimensionless() )
50 {}
51 
52 
53 template <int spacedim, class Value>
55 {
56  this->init_unit_conversion_coefficient(rec, init_data);
57  this->field_name_ = init_data.field_name_;
58  this->in_rec_ = rec;
59  this->unit_si_ = init_data.unit_si_;
60  this->limits_ = init_data.limits_;
61 }
62 
63 
64 template <int spacedim, class Value>
66 {
67  // Possible optimization: If we need set value_ repeatedly, we introduce TableFunction as class member and retrive it only once.
68  TableFunction<Value> table_function;
69 
70  if (!Value::is_scalable()) {
71  WarningOut().fmt("Setting key 'time_function' of non-floating point field at address {}\nValues will be skipped.\n",
73  }
74  table_function.init_from_input( in_rec_.val<Input::Record>("time_function") );
75  this->r_value_ = table_function.value( time.end() );
76  this->value_.scale(this->unit_conversion_coefficient_);
77  struct FieldAlgoBaseInitData init_data(this->field_name_, 0, this->unit_si_, this->limits_);
78  this->check_field_limits(this->in_rec_, init_data);
79 
80  return true;
81 }
82 
83 
84 // Instantion of Fields
86 
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)
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)
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:490
double end() const
Record & copy_keys(const Record &other)
Copy keys from other record.
Definition: type_record.cc:215
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:236
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
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