Flow123d  3.9.0-960b954f9
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>
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",
74  in_rec_.address_string());
75  }
76  table_function.init_from_input( in_rec_.val<Input::Record>("time_function"), time );
77  this->r_value_ = table_function.value( time.end() );
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 
FieldTimeFunction::FieldTimeFunction
FieldTimeFunction(unsigned int n_comp=0)
Definition: field_time_function.cc:50
FieldTimeFunction::get_input_type
static const Input::Type::Record & get_input_type()
Definition: field_time_function.cc:28
FieldAlgoBaseInitData::field_name_
std::string field_name_
Definition: field_algo_base.hh:91
FieldTimeFunction::set_time
bool set_time(const TimeStep &time) override
Definition: field_time_function.cc:67
field_time_function.hh
FieldTimeFunction::init_from_input
void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data) override
Definition: field_time_function.cc:56
FieldAlgoBaseInitData::unit_si_
const UnitSI & unit_si_
Definition: field_algo_base.hh:93
FieldConstant
Definition: field_constant.hh:43
FLOW123D_FORCE_LINK_IN_CHILD
#define FLOW123D_FORCE_LINK_IN_CHILD(x)
Definition: global_defs.h:104
FieldFlag
Definition: field_flag.hh:23
table_function.hh
TableFunction
Definition: table_function.hh:38
Input::Type::Record::derive_from
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:196
TimeStep::end
double end() const
Definition: time_governor.hh:161
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FieldAlgoBaseInitData::limits_
std::pair< double, double > limits_
Definition: field_algo_base.hh:94
FieldAlgoBaseInitData
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
Definition: field_algo_base.hh:81
Input::Type::Record::allow_auto_conversion
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:133
TimeStep
Representation of one time step..
Definition: time_governor.hh:123
Input::Type::Default::obligatory
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
UnitSI
Class for representation SI units of Fields.
Definition: unit_si.hh:40
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
Input::Type::Record::close
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
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
Input::Type::Record::copy_keys
Record & copy_keys(const Record &other)
Copy keys from other record.
Definition: type_record.cc:216
FieldAlgorithmBase
Definition: field_algo_base.hh:112
WarningOut
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:278
INSTANCE_ALL
#define INSTANCE_ALL(field)
Definition: field_instances.hh:43
TableFunction::value
const return_type & value(double t)
Definition: table_function.cc:92
TableFunction::init_from_input
void init_from_input(const Input::Record &rec, const TimeStep &time)
Initialize actual values of the field given from the given Input::Record rec.
Definition: table_function.cc:63
field_instances.hh
FieldTimeFunction
Definition: field_time_function.hh:42