Flow123d  release_3.0.0-1106-ga3b2e4c
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 
34 
35 
36 template <class Value>
38 {
39 public:
40  typedef typename Value::return_type return_type;
41 
42  /// Store value in one t stamp.
43  struct TableValue {
44  TableValue(double t, Value val)
45  : t_(t), value_(r_value_), r_value_(val) {}
46 
47  double t_;
49  return_type r_value_;
50  };
51 
52  /**
53  * Return record of one t stamp.
54  */
55  static const Input::Type::Tuple & get_input_type_val();
56 
57  /**
58  * Return Record for one t stamp series initialization of Fields. Allow to use interpolation
59  * of Field values defined in one field descriptor.
60  */
61  static const Input::Type::Record & get_input_type();
62 
63  /// Default constructor
64  TableFunction();
65 
66  /// Initialize actual values of the field given from the given Input::Record @p rec.
67  void init_from_input(const Input::Record &rec);
68 
69  /// Return true if TableFunction is initialized (method init_from_input was called).
70  bool initialized();
71 
72  /**
73  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
74  */
75  return_type const &value(double t);
76 
77 private:
78  // Compute the weighted average of table_values_[idx] and table_values_[idx+1]
79  void interpolated(double coef, unsigned int idx);
80 
81  /// Vector of values in all stamps.
83 
84  /// Last t stamp of computed value_ (to prevent repetitive calculation)
85  double last_t_;
86 
87  /// Last value, prevents passing large values (vectors) by value.
89  return_type r_value_;
90 };
91 
92 #endif /* TABLE_FUNCTION_HH_ */
return_type r_value_
Abstract linear system class.
Definition: balance.hh:35
Value value_
Last value, prevents passing large values (vectors) by value.
double last_t_
Last t stamp of computed value_ (to prevent repetitive calculation)
static constexpr bool value
Definition: json.hpp:87
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
TableValue(double t, Value val)
Tuple type proxy class.
Definition: type_tuple.hh:45
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:182
Store value in one t stamp.