OOFEM 3.0
Loading...
Searching...
No Matches
pythonexpression.h
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35#ifndef pythonexpression_h
36#define pythonexpression_h
37
38#include "function.h"
39
40#ifndef PyObject_HEAD
41struct _object;
42typedef _object PyObject;
43#endif
44
46
47#define _IFT_PythonExpression_Name "pythonexpression"
48#define _IFT_PythonExpression_f "f"
49#define _IFT_PythonExpression_dfdt "dfdt"
50#define _IFT_PythonExpression_d2fdt2 "d2fdt2"
51#define _IFT_PythonExpression_ffile "fpath"
52#define _IFT_PythonExpression_dfdtfile "dfdtpath"
53#define _IFT_PythonExpression_d2fdt2file "d2fdt2path"
55
56
57namespace oofem {
62{
63private:
65 std :: string fExpression;
67 std :: string dfdtExpression = "0";
69 std :: string d2fdt2Expression = "0";
70
71
75
76 PyObject *main_dict = nullptr;
77
79 PyObject *getDict(const std :: map< std :: string, FunctionArgument > &valDict);
81 void getArray(FloatArray &answer, PyObject **func, const std :: map< std :: string, FunctionArgument > &valDict);
83 double getScalar(PyObject *func, double time);
84 // helper method to convert a PyObject to a double
85 double pyObj2double(PyObject *obj) ;
86
87public:
93 PythonExpression(int n, Domain * d);
95 virtual ~PythonExpression();
96
103 void initializeFrom(InputRecord &ir) override;
104 void giveInputRecord(DynamicInputRecord &ir) override;
105
106 void evaluate(FloatArray &answer, const std :: map< std :: string, FunctionArgument > &valDict, GaussPoint *gp=nullptr, double param=0.) override;
107 void evaluateVelocity(FloatArray &answer, const std :: map< std :: string, FunctionArgument > &valDict);
108 void evaluateAcceleration(FloatArray &answer, const std :: map< std :: string, FunctionArgument > &valDict);
109
110 double evaluateAtTime(double t) override;
111 double evaluateVelocityAtTime(double t) override;
112 double evaluateAccelerationAtTime(double t) override;
113
114 const char *giveClassName() const override { return "PythonExpression"; }
115 const char *giveInputRecordName() const override { return _IFT_PythonExpression_Name; }
116private:
117 void readFile2String(const std :: string &path, std :: string &content);
118};
119} // end namespace oofem
120#endif // pythonexpression_h
Function(int n, Domain *d)
Definition function.C:44
double getScalar(PyObject *func, double time)
Helper function to run given function for given time.
void evaluate(FloatArray &answer, const std ::map< std ::string, FunctionArgument > &valDict, GaussPoint *gp=nullptr, double param=0.) override
std::string d2fdt2Expression
Expression for second time derivative or path to python script.
void initializeFrom(InputRecord &ir) override
const char * giveInputRecordName() const override
void giveInputRecord(DynamicInputRecord &ir) override
void evaluateAcceleration(FloatArray &answer, const std ::map< std ::string, FunctionArgument > &valDict)
double pyObj2double(PyObject *obj)
void evaluateVelocity(FloatArray &answer, const std ::map< std ::string, FunctionArgument > &valDict)
std::string dfdtExpression
Expression for first time derivative or path to python script.
PythonExpression(int n, Domain *d)
double evaluateAtTime(double t) override
PyObject * getDict(const std ::map< std ::string, FunctionArgument > &valDict)
Helper function to convert the std::map to a Python dictionary.
void getArray(FloatArray &answer, PyObject **func, const std ::map< std ::string, FunctionArgument > &valDict)
Helper function to run given function for given value dictionary.
const char * giveClassName() const override
double evaluateVelocityAtTime(double t) override
std::string fExpression
Expression for the function value or path to python script.
double evaluateAccelerationAtTime(double t) override
#define OOFEM_EXPORT
Definition oofemcfg.h:7
#define _IFT_PythonExpression_Name
_object PyObject

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011