Flow123d  release_2.1.0-84-g6a13a75
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 
22 #include "input/accessors.hh"
23 #include "input/input_exception.hh"
24 #include "fields/field_values.hh"
25 #include <vector>
26 
27 
28 
29 template <class Value>
31 {
32 public:
33  typedef typename Value::return_type return_type;
34 
35  /// Store value in one t stamp.
36  struct TableValue {
37  TableValue(double t, Value val)
38  : t_(t), value_(r_value_), r_value_(val) {}
39 
40  double t_;
41  Value value_;
42  return_type r_value_;
43  };
44 
45  /**
46  * Return record of one t stamp.
47  */
48  static const Input::Type::Tuple & get_input_type_val();
49 
50  /**
51  * Return Record for one t stamp series initialization of Fields. Allow to use interpolation
52  * of Field values defined in one field descriptor.
53  */
54  static const Input::Type::Record & get_input_type();
55 
56  /// Default constructor
57  TableFunction();
58 
59  /// Initialize actual values of the field given from the given Input::Record @p rec.
60  void init_from_input(const Input::Record &rec);
61 
62  /// Return true if TableFunction is initialized (method init_from_input was called).
63  bool initialized();
64 
65  /**
66  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
67  */
68  return_type const &value(double t);
69 
70 private:
71  // Compute the weighted average of table_values_[idx] and table_values_[idx+1]
72  void interpolated(double coef, unsigned int idx);
73 
74  /// Vector of values in all stamps.
76 
77  /// Last t stamp of computed value_ (to prevent repetitive calculation)
78  double last_t_;
79 
80  /// Last value, prevents passing large values (vectors) by value.
81  Value value_;
82  return_type r_value_;
83 };
84 
85 #endif /* TABLE_FUNCTION_HH_ */
return_type r_value_
bool initialized()
Return true if TableFunction is initialized (method init_from_input was called).
static const Input::Type::Record & get_input_type()
Value value_
Last value, prevents passing large values (vectors) by value.
double last_t_
Last t stamp of computed value_ (to prevent repetitive calculation)
void init_from_input(const Input::Record &rec)
Initialize actual values of the field given from the given Input::Record rec.
void interpolated(double coef, unsigned int idx)
Accessor to the data with type Type::Record.
Definition: accessors.hh:286
TableFunction()
Default constructor.
TableValue(double t, Value val)
Tuple type proxy class.
Definition: type_tuple.hh:45
static const Input::Type::Tuple & get_input_type_val()
return_type const & value(double t)
Value::return_type return_type
std::vector< struct TableValue > table_values_
Vector of values in all stamps.
Record type proxy class.
Definition: type_record.hh:177
Store value in one t stamp.