Flow123d  release_3.0.0-1263-g7cf53c1
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_;
50  return_type r_value_;
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.
90  return_type r_value_;
91 };
92 
93 #endif /* TABLE_FUNCTION_HH_ */
return_type r_value_
Abstract linear system class.
Definition: balance.hh:37
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
Representation of one time step..
Store value in one t stamp.