Flow123d  3.9.0-d39db4f
table_function.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 table_function.hh
15  * @brief
16  */
17 
18 #ifndef TABLE_FUNCTION_HH_
19 #define TABLE_FUNCTION_HH_
20 
21 #include <string.h> // for memcpy
22 #include <vector> // for vector
23 #include <armadillo>
24 #include "fields/field_values.hh" // for FieldValue<>::TensorFixed
25 
26 namespace Input {
27  class Record;
28  namespace Type {
29  class Record;
30  class Tuple;
31  }
32 }
33 class TimeStep;
34 
35 
36 
37 template <class Value>
39 {
40 public:
41  typedef typename Value::return_type return_type;
42 
43  /// Store value in one t stamp.
44  struct TableValue {
45  TableValue(double t, Value val)
46  : t_(t), value_(r_value_), r_value_(val) {}
47 
48  double t_;
51  };
52 
53  /**
54  * Return record of one t stamp.
55  */
56  static const Input::Type::Tuple & get_input_type_val();
57 
58  /**
59  * Return Record for one t stamp series initialization of Fields. Allow to use interpolation
60  * of Field values defined in one field descriptor.
61  */
62  static const Input::Type::Record & get_input_type();
63 
64  /// Default constructor
65  TableFunction();
66 
67  /// Initialize actual values of the field given from the given Input::Record @p rec.
68  void init_from_input(const Input::Record &rec, const TimeStep &time);
69 
70  /// Return true if TableFunction is initialized (method init_from_input was called).
71  bool initialized();
72 
73  /**
74  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
75  */
76  return_type const &value(double t);
77 
78 private:
79  // Compute the weighted average of table_values_[idx] and table_values_[idx+1]
80  void interpolated(double coef, unsigned int idx);
81 
82  /// Vector of values in all stamps.
84 
85  /// Last t stamp of computed value_ (to prevent repetitive calculation)
86  double last_t_;
87 
88  /// Last value, prevents passing large values (vectors) by value.
91 };
92 
93 #endif /* TABLE_FUNCTION_HH_ */
TableFunction::initialized
bool initialized()
Return true if TableFunction is initialized (method init_from_input was called).
Definition: table_function.cc:86
Input
Abstract linear system class.
Definition: balance.hh:40
string.h
TableFunction::TableValue::TableValue
TableValue(double t, Value val)
Definition: table_function.hh:45
std::vector
Definition: doxy_dummy_defs.hh:7
Input::Type::Tuple
Tuple type proxy class.
Definition: type_tuple.hh:45
TableFunction::interpolated
void interpolated(double coef, unsigned int idx)
Definition: table_function.cc:121
TableFunction::last_t_
double last_t_
Last t stamp of computed value_ (to prevent repetitive calculation)
Definition: table_function.hh:86
TableFunction
Definition: table_function.hh:38
TableFunction::table_values_
std::vector< struct TableValue > table_values_
Vector of values in all stamps.
Definition: table_function.hh:83
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
TableFunction::TableValue
Store value in one t stamp.
Definition: table_function.hh:44
TimeStep
Representation of one time step..
Definition: time_governor.hh:123
field_values.hh
TableFunction::TableValue::r_value_
return_type r_value_
Definition: table_function.hh:50
TableFunction::return_type
Value::return_type return_type
Definition: table_function.hh:41
TableFunction::TableValue::value_
Value value_
Definition: table_function.hh:49
TableFunction::TableValue::t_
double t_
Definition: table_function.hh:48
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
Value
@ Value
Definition: finite_element.hh:43
TableFunction::get_input_type
static const Input::Type::Record & get_input_type()
Definition: table_function.cc:44
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
TableFunction::TableFunction
TableFunction()
Default constructor.
Definition: table_function.cc:56
TableFunction::r_value_
return_type r_value_
Definition: table_function.hh:90
TableFunction::value_
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: table_function.hh:89
TableFunction::get_input_type_val
static const Input::Type::Tuple & get_input_type_val()
Definition: table_function.cc:26