Flow123d  release_3.0.0-973-g92f55e826
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_;
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.
90 };
91 
92 #endif /* TABLE_FUNCTION_HH_ */
TableFunction::initialized
bool initialized()
Return true if TableFunction is initialized (method init_from_input was called).
Definition: table_function.cc:78
Input
Abstract linear system class.
Definition: balance.hh:37
string.h
TableFunction::TableValue::TableValue
TableValue(double t, Value val)
Definition: table_function.hh:44
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:113
TableFunction::last_t_
double last_t_
Last t stamp of computed value_ (to prevent repetitive calculation)
Definition: table_function.hh:85
TableFunction
Definition: table_function.hh:37
TableFunction::table_values_
std::vector< struct TableValue > table_values_
Vector of values in all stamps.
Definition: table_function.hh:82
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:43
field_values.hh
TableFunction::TableValue::r_value_
return_type r_value_
Definition: table_function.hh:49
TableFunction::return_type
Value::return_type return_type
Definition: table_function.hh:40
TableFunction::TableValue::value_
Value value_
Definition: table_function.hh:48
TableFunction::TableValue::t_
double t_
Definition: table_function.hh:47
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
Value
@ Value
Definition: finite_element.hh:47
TableFunction::get_input_type
static const Input::Type::Record & get_input_type()
Definition: table_function.cc:36
TableFunction::init_from_input
void init_from_input(const Input::Record &rec)
Initialize actual values of the field given from the given Input::Record rec.
Definition: table_function.cc:55
TableFunction::value
const return_type & value(double t)
Definition: table_function.cc:84
TableFunction::TableFunction
TableFunction()
Default constructor.
Definition: table_function.cc:48
TableFunction::r_value_
return_type r_value_
Definition: table_function.hh:89
TableFunction::value_
Value value_
Last value, prevents passing large values (vectors) by value.
Definition: table_function.hh:88
TableFunction::get_input_type_val
static const Input::Type::Tuple & get_input_type_val()
Definition: table_function.cc:25