Flow123d  release_3.0.0-1191-g7740876
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 <stdio.h> // for sprintf
23 #include <boost/exception/info.hpp> // for operator<<, error_info::error...
24 #include <string> // for operator==, string
25 #include <vector> // for vector
26 #include <memory>
27 #include <armadillo>
28 #include "fields/field_algo_base.hh" // for FieldAlgorithmBase
29 #include "fields/field_values.hh" // for FieldValue<>::Enum, FieldValu...
30 #include "input/accessors.hh" // for ExcAccessorForNullStorage
31 #include "input/accessors_impl.hh" // for Record::val
32 #include "input/storage.hh" // for ExcStorageTypeMismatch
33 #include "input/type_record.hh" // for Record::ExcRecordKeyNotFound
34 #include "system/exceptions.hh" // for ExcAssertMsg::~ExcAssertMsg
35 #include "tools/time_governor.hh" // for TimeStep
36 
37 class FunctionParser;
38 template <int spacedim> class ElementAccessor;
39 class SurfaceDepth;
40 
41 using namespace std;
42 
43 /**
44  * Class representing fields given by runtime parsed formulas.
45  *
46  * Using library:
47  * http://warp.povusers.org/FunctionParser/
48  *
49  * TODO:
50  * correct support for discrete functions (use integer parser), actually we just convert double to int
51  *
52  */
53 template <int spacedim, class Value>
54 class FieldFormula : public FieldAlgorithmBase<spacedim, Value>
55 {
56 public:
59 
60  FieldFormula(unsigned int n_comp=0);
61 
62 
63  static const Input::Type::Record & get_input_type();
64 
65  virtual void init_from_input(const Input::Record &rec, const struct FieldAlgoBaseInitData& init_data);
66 
67  /**
68  * For time dependent formulas returns always true. For time independent formulas returns true only for the first time.
69  */
70  bool set_time(const TimeStep &time) override;
71 
72  /**
73  * Create SurfaceDepth object if surface region is set.
74  *
75  * See also description of the FieldBase<...>::set_mesh.
76  */
77  void set_mesh(const Mesh *mesh, bool boundary_domain) override;
78 
79  /**
80  * Returns one value in one given point. ResultType can be used to avoid some costly calculation if the result is trivial.
81  */
82  virtual typename Value::return_type const &value(const Point &p, const ElementAccessor<spacedim> &elm);
83 
84  /**
85  * Returns std::vector of scalar values in several points at once.
86  */
87  virtual void value_list (const std::vector< Point > &point_list, const ElementAccessor<spacedim> &elm,
89 
90 
91  virtual ~FieldFormula();
92 
93 private:
95 
96  /**
97  * Evaluate depth variable if it is contained in formula.
98  *
99  * Return arma vec of point coordinates extended by depth value (or zero if depth is not contained.
100  */
101  inline arma::vec eval_depth_var(const Point &p);
102 
103  // StringValue::return_type == StringTensor, which behaves like arma::mat<string>
105 
106  // Matrix of parsers corresponding to the formula matrix returned by formula_matrix_helper_
108 
109  /// Accessor to Input::Record
111 
112  /// Surface depth object calculate distance from surface.
113  std::shared_ptr<SurfaceDepth> surface_depth_;
114 
115  /// Flag indicates if depth variable 'd' is used in formula
117 
118  /// Flag indicates first call of set_time method, when FunctionParsers in parser_matrix_ must be initialized
120 
121  /// Registrar of class to factory
122  static const int registrar;
123 
124 
125 };
126 
127 
128 
129 #endif /* FIELD_FORMULA_HH_ */
Definition: mesh.h:76
std::shared_ptr< SurfaceDepth > surface_depth_
Surface depth object calculate distance from surface.
Helper struct stores data for initizalize descentants of FieldAlgorithmBase.
Mat< double, N, 1 > vec
Definition: armor.hh:211
StringTensorInput< Value::NRows_, Value::NCols_ > STI
FieldAlgorithmBase< spacedim, Value >::Point Point
bool first_time_set_
Flag indicates first call of set_time method, when FunctionParsers in parser_matrix_ must be initiali...
StringTensor formula_matrix_
Basic time management class.
static constexpr bool value
Definition: json.hpp:87
bool has_depth_var_
Flag indicates if depth variable &#39;d&#39; is used in formula.
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
Space< spacedim >::Point Point
static const int registrar
Registrar of class to factory.
Input::Record in_rec_
Accessor to Input::Record.
FieldAlgorithmBase< spacedim, Value > FactoryBaseType
std::vector< std::vector< FunctionParser > > parser_matrix_
Record type proxy class.
Definition: type_record.hh:182
Representation of one time step..