OOFEM 3.0
Loading...
Searching...
No Matches
oofem::PythonExpression Class Reference

#include <pythonexpression.h>

Inheritance diagram for oofem::PythonExpression:
Collaboration diagram for oofem::PythonExpression:

Public Member Functions

 PythonExpression (int n, Domain *d)
virtual ~PythonExpression ()
 Destructor.
void initializeFrom (InputRecord &ir) override
void giveInputRecord (DynamicInputRecord &ir) override
void evaluate (FloatArray &answer, const std ::map< std ::string, FunctionArgument > &valDict, GaussPoint *gp=nullptr, double param=0.) override
void evaluateVelocity (FloatArray &answer, const std ::map< std ::string, FunctionArgument > &valDict)
void evaluateAcceleration (FloatArray &answer, const std ::map< std ::string, FunctionArgument > &valDict)
double evaluateAtTime (double t) override
double evaluateVelocityAtTime (double t) override
double evaluateAccelerationAtTime (double t) override
const char * giveClassName () const override
const char * giveInputRecordName () const override
Public Member Functions inherited from oofem::Function
 Function (int n, Domain *d)
virtual ~Function ()
 Destructor.
virtual double evaluate (TimeStep *tStep, ValueModeType mode)
virtual double evaluate (const std ::map< std ::string, FunctionArgument > &valDict)
double giveFunctionParameter (int paramID)
void saveContext (DataStream &stream, ContextMode mode) override
void restoreContext (DataStream &stream, ContextMode mode) override
Public Member Functions inherited from oofem::FEMComponent
 FEMComponent (int n, Domain *d)
virtual ~FEMComponent ()=default
 Virtual destructor.
DomaingiveDomain () const
virtual void setDomain (Domain *d)
int giveNumber () const
void setNumber (int num)
virtual void updateLocalNumbering (EntityRenumberingFunctor &f)
virtual void initializeFrom (InputRecord &ir, int priority)
virtual void initializeFinish ()
virtual void postInitialize ()
 Performs post initialization steps. Called after all components are created and initialized.
virtual int checkConsistency ()
virtual void printOutputAt (FILE *file, TimeStep *tStep)
virtual void printYourself ()
 Prints receiver state on stdout. Useful for debugging.
virtual InterfacegiveInterface (InterfaceType t)
std::string errorInfo (const char *func) const
 Returns string for prepending output (used by error reporting macros).

Private Member Functions

PyObjectgetDict (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.
double getScalar (PyObject *func, double time)
 Helper function to run given function for given time.
double pyObj2double (PyObject *obj)
void readFile2String (const std ::string &path, std ::string &content)

Private Attributes

std::string fExpression
 Expression for the function value or path to python script.
std::string dfdtExpression = "0"
 Expression for first time derivative or path to python script.
std::string d2fdt2Expression = "0"
 Expression for second time derivative or path to python script.
PyObjectf
PyObjectdfdt
PyObjectd2fdt2
PyObjectmain_dict = nullptr

Additional Inherited Members

Public Attributes inherited from oofem::Function
DomainfuncDomain
int parameterType
Protected Attributes inherited from oofem::FEMComponent
int number
 Component number.
Domaindomain
 Link to domain object, useful for communicating with other FEM components.

Detailed Description

Class representing user defined functions as Python expressions

Definition at line 61 of file pythonexpression.h.

Constructor & Destructor Documentation

◆ PythonExpression()

oofem::PythonExpression::PythonExpression ( int n,
Domain * d )

Constructor. Creates load time function with given number, belonging to given domain.

Parameters
nLoad time function number.
dDomain to which new object will belongs..

Definition at line 52 of file pythonexpression.C.

References oofem::Function::Function().

◆ ~PythonExpression()

oofem::PythonExpression::~PythonExpression ( )
virtual

Destructor.

Todo
Is this right?

Definition at line 54 of file pythonexpression.C.

Member Function Documentation

◆ evaluate()

void oofem::PythonExpression::evaluate ( FloatArray & answer,
const std ::map< std ::string, FunctionArgument > & valDict,
GaussPoint * gp = nullptr,
double param = 0. )
overridevirtual

Returns the value of the function for given input.

Parameters
valDictMap with inputs.
answerFunction value.

Reimplemented from oofem::Function.

Definition at line 192 of file pythonexpression.C.

References f, and getArray().

◆ evaluateAcceleration()

void oofem::PythonExpression::evaluateAcceleration ( FloatArray & answer,
const std ::map< std ::string, FunctionArgument > & valDict )

Definition at line 206 of file pythonexpression.C.

References d2fdt2, and getArray().

◆ evaluateAccelerationAtTime()

double oofem::PythonExpression::evaluateAccelerationAtTime ( double t)
overridevirtual

Returns the second time derivative of the function at given time.

Parameters
tTime.
Returns
\( f''(t) \).

Implements oofem::Function.

Definition at line 250 of file pythonexpression.C.

References d2fdt2, and getScalar().

◆ evaluateAtTime()

double oofem::PythonExpression::evaluateAtTime ( double t)
overridevirtual

Returns the value of the function at given time.

Parameters
tTime.
Returns
\( f(t) \).

Reimplemented from oofem::Function.

Definition at line 239 of file pythonexpression.C.

References f, and getScalar().

◆ evaluateVelocity()

void oofem::PythonExpression::evaluateVelocity ( FloatArray & answer,
const std ::map< std ::string, FunctionArgument > & valDict )

Definition at line 199 of file pythonexpression.C.

References dfdt, and getArray().

◆ evaluateVelocityAtTime()

double oofem::PythonExpression::evaluateVelocityAtTime ( double t)
overridevirtual

Returns the first time derivative of the function at given time.

Parameters
tTime.
Returns
\( f'(t) \).

Implements oofem::Function.

Definition at line 244 of file pythonexpression.C.

References dfdt, and getScalar().

◆ getArray()

void oofem::PythonExpression::getArray ( FloatArray & answer,
PyObject ** func,
const std ::map< std ::string, FunctionArgument > & valDict )
private

Helper function to run given function for given value dictionary.

Definition at line 161 of file pythonexpression.C.

References getDict(), main_dict, pyObj2double(), oofem::FloatArray::resize(), and RETURN_VARIABLE.

Referenced by evaluate(), evaluateAcceleration(), and evaluateVelocity().

◆ getDict()

PyObject * oofem::PythonExpression::getDict ( const std ::map< std ::string, FunctionArgument > & valDict)
private

◆ getScalar()

double oofem::PythonExpression::getScalar ( PyObject * func,
double time )
private

Helper function to run given function for given time.

Definition at line 213 of file pythonexpression.C.

References main_dict, OOFEM_ERROR, pyObj2double(), and RETURN_VARIABLE.

Referenced by evaluateAccelerationAtTime(), evaluateAtTime(), and evaluateVelocityAtTime().

◆ giveClassName()

const char * oofem::PythonExpression::giveClassName ( ) const
inlineoverridevirtual
Returns
Class name of the receiver.

Implements oofem::FEMComponent.

Definition at line 114 of file pythonexpression.h.

◆ giveInputRecord()

void oofem::PythonExpression::giveInputRecord ( DynamicInputRecord & input)
overridevirtual

Setups the input record string of receiver.

Parameters
inputDynamic input record to be filled by receiver.

Reimplemented from oofem::FEMComponent.

Definition at line 120 of file pythonexpression.C.

References _IFT_PythonExpression_d2fdt2, _IFT_PythonExpression_dfdt, _IFT_PythonExpression_f, d2fdt2Expression, dfdtExpression, fExpression, and oofem::DynamicInputRecord::setField().

◆ giveInputRecordName()

const char * oofem::PythonExpression::giveInputRecordName ( ) const
inlineoverridevirtual
Returns
Input record name of the receiver.

Implements oofem::FEMComponent.

Definition at line 115 of file pythonexpression.h.

References _IFT_PythonExpression_Name.

◆ initializeFrom()

void oofem::PythonExpression::initializeFrom ( InputRecord & ir)
overridevirtual

◆ pyObj2double()

double oofem::PythonExpression::pyObj2double ( PyObject * obj)
private

Definition at line 256 of file pythonexpression.C.

Referenced by getArray(), and getScalar().

◆ readFile2String()

void oofem::PythonExpression::readFile2String ( const std ::string & path,
std ::string & content )
private

Definition at line 270 of file pythonexpression.C.

References OOFEM_ERROR.

Referenced by initializeFrom().

Member Data Documentation

◆ d2fdt2

PyObject* oofem::PythonExpression::d2fdt2
private

◆ d2fdt2Expression

std::string oofem::PythonExpression::d2fdt2Expression = "0"
private

Expression for second time derivative or path to python script.

Definition at line 69 of file pythonexpression.h.

Referenced by giveInputRecord(), and initializeFrom().

◆ dfdt

PyObject* oofem::PythonExpression::dfdt
private

Definition at line 73 of file pythonexpression.h.

Referenced by evaluateVelocity(), evaluateVelocityAtTime(), and initializeFrom().

◆ dfdtExpression

std::string oofem::PythonExpression::dfdtExpression = "0"
private

Expression for first time derivative or path to python script.

Definition at line 67 of file pythonexpression.h.

Referenced by giveInputRecord(), and initializeFrom().

◆ f

PyObject* oofem::PythonExpression::f
private

Definition at line 72 of file pythonexpression.h.

Referenced by evaluate(), evaluateAtTime(), and initializeFrom().

◆ fExpression

std::string oofem::PythonExpression::fExpression
private

Expression for the function value or path to python script.

Definition at line 65 of file pythonexpression.h.

Referenced by giveInputRecord(), and initializeFrom().

◆ main_dict

PyObject* oofem::PythonExpression::main_dict = nullptr
private

Definition at line 76 of file pythonexpression.h.

Referenced by getArray(), getScalar(), and initializeFrom().


The documentation for this class was generated from the following files:

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