Flow123d  release_2.1.0-87-gfbc1563
field_formula.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 field_formula.hh
15  * @brief
16  */
17 
18 #ifndef FIELD_FORMULA_HH_
19 #define FIELD_FORMULA_HH_
20 
21 
22 #include "system/system.hh"
24 #include "mesh/point.hh"
25 #include "input/factory.hh"
26 #include "fields/field_values.hh"
27 
28 #include <string>
29 using namespace std;
30 
31 class FunctionParser;
32 
33 /**
34  * Class representing fields given by runtime parsed formulas.
35  *
36  * Using library:
37  * http://warp.povusers.org/FunctionParser/
38  *
39  * TODO:
40  * correct support for discrete functions (use integer parser), actually we just convert double to int
41  *
42  */
43 template <int spacedim, class Value>
44 class FieldFormula : public FieldAlgorithmBase<spacedim, Value>
45 {
46 public:
49 
50  FieldFormula(unsigned int n_comp=0);
51 
52 
53  static const Input::Type::Record & get_input_type();
54 
55  virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData& init_data);
56 
57  /**
58  * For time dependent formulas returns always true. For time independent formulas returns true only for the first time.
59  */
60  bool set_time(const TimeStep &time) override;
61 
62  /**
63  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
64  */
65  virtual typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm);
66 
67  /**
68  * Returns std::vector of scalar values in several points at once.
69  */
70  virtual void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
72 
73 
74  virtual ~FieldFormula();
75 
76 private:
78 
79  // StringValue::return_type == StringTensor, which behaves like arma::mat<string>
81 
82  // Matrix of parsers corresponding to the formula matrix returned by formula_matrix_helper_
84 
85  // Full address of the FiledFormula 'value' key.
86  // Necessary in the case of an error during parsing.
87  std::string value_input_address_;
88 
89  /// Registrar of class to factory
90  static const int registrar;
91 
92 
93 };
94 
95 
96 
97 #endif /* FIELD_FORMULA_HH_ */
std::string value_input_address_
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
StringTensorInput< Value::NRows_, Value::NCols_ > STI
FieldAlgorithmBase< spacedim, Value >::Point Point
StringTensor formula_matrix_
static constexpr bool value
Definition: json.hpp:87
Accessor to the data with type Type::Record.
Definition: accessors.hh:286
Space< spacedim >::Point Point
static const int registrar
Registrar of class to factory.
FieldAlgorithmBase< spacedim, Value > FactoryBaseType
std::vector< std::vector< FunctionParser > > parser_matrix_
Record type proxy class.
Definition: type_record.hh:177
Representation of one time step..