KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
function_parser_utility.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ \.
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Riccardo Rossi
11 // Collaborator: Vicente Mataix Ferrandiz
12 //
13 
14 #pragma once
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "includes/define.h"
23 
24 // Forward declaration to avoid the include of tinyexpr in a header file
25 struct te_expr;
26 
27 namespace Kratos
28 {
31 
35 
39 
43 
47 
62 class KRATOS_API(KRATOS_CORE) BasicGenericFunctionUtility
63 {
64 public:
67 
69  typedef std::size_t IndexType;
70 
73 
77 
82  BasicGenericFunctionUtility(const std::string& rFunctionBody);
83 
86 
88  virtual ~BasicGenericFunctionUtility();
89 
93 
98  Pointer Clone()
99  {
100  return Kratos::make_shared<BasicGenericFunctionUtility>(*this);
101  }
102 
107  virtual bool UseLocalSystem()
108  {
109  return false;
110  }
111 
117  {
118  return mDependsOnSpace;
119  }
120 
125  std::string FunctionBody();
126 
137  virtual double RotateAndCallFunction(
138  const double x,
139  const double y,
140  const double z,
141  const double t,
142  const double X = 0.0,
143  const double Y = 0.0,
144  const double Z = 0.0
145  );
146 
157  double CallFunction(
158  const double x,
159  const double y,
160  const double z,
161  const double t,
162  const double X = 0.0,
163  const double Y = 0.0,
164  const double Z = 0.0
165  );
166 
168 
169 protected:
170 
173 
175  std::vector<te_expr*> mpTinyExpr = std::vector<te_expr*>(1, nullptr);
176  std::string mFunctionBody;
177 
178  bool mDependsOnSpace = true;
179 
183 
187  void InitializeParser();
188 
190 };
191 
206 class KRATOS_API(KRATOS_CORE) GenericFunctionUtility
208 {
209 public:
212 
214  typedef std::size_t IndexType;
215 
218 
222 
229  const std::string& rFunctionBody,
230  Parameters LocalSystem = Parameters{}
231  );
232 
235 
237  ~GenericFunctionUtility() override {};
238 
242 
247  Pointer Clone()
248  {
249  return Kratos::make_shared<GenericFunctionUtility>(*this);
250  }
251 
256  bool UseLocalSystem() override
257  {
258  return mUseLocalSystem;
259  }
260 
271  double RotateAndCallFunction(
272  const double x,
273  const double y,
274  const double z,
275  const double t,
276  const double X = 0.0,
277  const double Y = 0.0,
278  const double Z = 0.0
279  ) override;
280 
282 
283 private:
284 
287 
288  bool mUseLocalSystem = false;
289  BoundedMatrix<double, 3, 3> mRotationMatrix;
290  array_1d<double, 3> mCenterCoordinates;
291 
293 };
294 
302 {
303 public:
306 
311  FunctionParser(const std::string& rFunctionBody)
312  : mParser(rFunctionBody)
313  {
314  }
315 
319 
325  std::function<double(const double, const double, const double)> GetFunctionSpace()
326  {
327  return [&](const double x, const double y, const double z) -> double {return mParser.CallFunction(x,y,z,0.0);};
328  }
329 
335  std::function<double(const double, const double, const double, const double)> GetFunction()
336  {
337  return [&](const double x, const double y, const double z, const double t) -> double {return mParser.CallFunction(x,y,z,t);};
338  }
339 
345  std::function<double(const double, const double, const double, const double, const double, const double, const double)> GetFunctionInitialCoordinates()
346  {
347  return [&](const double x, const double y, const double z, const double t, const double X, const double Y, const double Z) -> double {return mParser.CallFunction(x,y,z,t,X,Y,Z);};;
348  }
349 
351 private:
354 
355  GenericFunctionUtility mParser;
356 
358 };
359 
360 }
This function allows to call a function method of type f(x, y, z, t) implemented in python style.
Definition: function_parser_utility.h:63
bool DependsOnSpace()
This method returns if it depends on space.
Definition: function_parser_utility.h:116
std::size_t IndexType
The index type definition.
Definition: function_parser_utility.h:69
std::string mFunctionBody
The function parser.
Definition: function_parser_utility.h:176
KRATOS_CLASS_POINTER_DEFINITION(BasicGenericFunctionUtility)
Counted pointer of BasicGenericFunctionUtility.
virtual bool UseLocalSystem()
This method returns if it depends on space.
Definition: function_parser_utility.h:107
Pointer Clone()
This method clones the current function instance.
Definition: function_parser_utility.h:98
GenericFunctionUtility.
Definition: function_parser_utility.h:302
std::function< double(const double, const double, const double, const double, const double, const double, const double)> GetFunctionInitialCoordinates()
This method parses a string into a std::function.
Definition: function_parser_utility.h:345
FunctionParser(const std::string &rFunctionBody)
Default constructor.
Definition: function_parser_utility.h:311
std::function< double(const double, const double, const double)> GetFunctionSpace()
This method parses a string into a std::function.
Definition: function_parser_utility.h:325
std::function< double(const double, const double, const double, const double)> GetFunction()
This method parses a string into a std::function.
Definition: function_parser_utility.h:335
GenericFunctionUtility.
Definition: function_parser_utility.h:208
std::size_t IndexType
The index type definition.
Definition: function_parser_utility.h:214
KRATOS_CLASS_POINTER_DEFINITION(GenericFunctionUtility)
Counted pointer of GenericFunctionUtility.
~GenericFunctionUtility() override
Destructor.
Definition: function_parser_utility.h:237
bool UseLocalSystem() override
This method returns if it depends on space.
Definition: function_parser_utility.h:256
Pointer Clone()
This method clones the current function instance.
Definition: function_parser_utility.h:247
Definition: amatrix_interface.h:41
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
z
Definition: GenerateWind.py:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
int t
Definition: ode_solve.py:392
x
Definition: sensitivityMatrix.py:49