Flow123d  DF_patch_fe_data_tables-18aea81
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 
void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData &init_data) override
static const Input::Type::Record & get_input_type()
bool set_time(const TimeStep &time) override
FieldTimeFunction(unsigned int n_comp=0)
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
static Default obligatory()
The factory function to make an empty default value which is obligatory.
Definition: type_record.hh:110
Record type proxy class.
Definition: type_record.hh:182
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
virtual Record & derive_from(Abstract &parent)
Method to derive new Record from an AbstractRecord parent.
Definition: type_record.cc:196
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Record & copy_keys(const Record &other)
Copy keys from other record.
Definition: type_record.cc:216
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
return_type const & value(double t)
void init_from_input(const Input::Record &rec, const TimeStep &time)
Initialize actual values of the field given from the given Input::Record rec.
Representation of one time step..
double end() const
Class for representation SI units of Fields.
Definition: unit_si.hh:40
#define INSTANCE_ALL(field)
@ Value
#define FLOW123D_FORCE_LINK_IN_CHILD(x)
Definition: global_defs.h:104
#define WarningOut()
Macro defining 'warning' record of log.
Definition: logger.hh:278
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
const UnitSI & unit_si_
std::pair< double, double > limits_