49 smallDefTangent(NULL),
65 if ( result !=
IRRT_OK )
return result;
74 auto tryDef=[&](
const std::string& attr, bp::object& callable)->
bool{
75 if(PyObject_HasAttrString(
module.ptr(),attr.c_str())){
76 callable=
module.attr(attr.c_str());
77 if(!PyCallable_Check(callable.ptr())){
OOFEM_WARNING(
"Object %s is not callable",attr.c_str());
return false; }
78 }
else callable=bp::object();
93 this->mpModule = PyImport_Import(mpName);
96 if ( mpModule != NULL ) {
98 smallDef = PyObject_GetAttrString(mpModule,
"computeStress");
99 largeDef = PyObject_GetAttrString(mpModule,
"computePK1Stress");
100 smallDefTangent = PyObject_GetAttrString(mpModule,
"computeStressTangent");
101 largeDefTangent = PyObject_GetAttrString(mpModule,
"computePK1StressTangent");
103 OOFEM_WARNING(
"Using numerical tangent for small deformations");
106 OOFEM_WARNING(
"Using numerical tangent for large deformations");
109 OOFEM_WARNING(
"No functions for either small or large deformations supplied. Are you sure the functions are named correctly?");
138 func(oldStrain,oldStress,strain,stress,stateDict,tempStateDict,tStep->
giveTargetTime());
141 if ( !PyCallable_Check(func) ) {
149 PyObject *pArgOldStrain = PyList_New(size);
150 PyObject *pArgOldStress = PyList_New(size);
151 PyObject *pArgStrain = PyList_New(size);
153 for (
int i = 0; i < size; i++ ) {
154 PyList_SET_ITEM( pArgOldStrain, i, PyFloat_FromDouble( oldStrain[i] ) );
155 PyList_SET_ITEM( pArgOldStress, i, PyFloat_FromDouble( oldStress[i] ) );
156 PyList_SET_ITEM( pArgStrain, i, PyFloat_FromDouble( strain[i] ) );
160 PyTuple_SetItem(pArgs, 0, pArgOldStrain);
161 PyTuple_SetItem(pArgs, 1, pArgOldStress);
162 PyTuple_SetItem(pArgs, 2, pArgStrain);
164 Py_INCREF(stateDict);
165 PyTuple_SetItem(pArgs, 3, stateDict);
166 Py_INCREF(tempStateDict);
167 PyTuple_SetItem(pArgs, 4, tempStateDict);
169 PyTuple_SetItem(pArgs, 5, PyFloat_FromDouble( tStep->
giveTargetTime() ));
171 PyObject *retVal = PyObject_CallObject(func, pArgs);
175 for (
int i = 0; i < size; i++ ) {
176 PyObject *val = PyList_GET_ITEM(retVal, i);
177 stress[i] = PyFloat_AS_DOUBLE(val);
188 answer=bp::extract<FloatMatrix>(func(strain,stress,stateDict,tempStateDict,tStep->
giveTargetTime()));
190 if ( !PyCallable_Check(func) ) {
198 PyObject *pArgStrain = PyList_New(size);
199 PyObject *pArgStress = PyList_New(size);
201 for (
int i = 0; i < size; i++ ) {
202 PyList_SET_ITEM( pArgStrain, i, PyFloat_FromDouble( strain[i] ) );
203 PyList_SET_ITEM( pArgStress, i, PyFloat_FromDouble( stress[i] ) );
206 PyTuple_SetItem(pArgs, 0, pArgStrain);
207 PyTuple_SetItem(pArgs, 1, pArgStress);
209 Py_INCREF(stateDict);
210 PyTuple_SetItem(pArgs, 2, stateDict);
211 Py_INCREF(tempStateDict);
212 PyTuple_SetItem(pArgs, 3, tempStateDict);
214 PyTuple_SetItem(pArgs, 4, PyFloat_FromDouble( tStep->
giveTargetTime() ));
216 PyObject *retVal = PyObject_CallObject(func, pArgs);
218 if ( retVal == NULL ) {
219 OOFEM_ERROR(
"bad return value (null) from PyObject_CallObject");
222 answer.
resize(size, size);
223 for (
int i = 0; i < size; i++ ) {
224 PyObject *row = PyList_GET_ITEM(retVal, i);
225 for (
int j = 0; j < size; j++ ) {
226 PyObject *val = PyList_GET_ITEM(row, j);
227 answer(i, j) = PyFloat_AS_DOUBLE(val);
247 for (
int i = 1; i <= 6; ++i ) {
273 for (
int i = 1; i <= 9; ++i ) {
327 vE.beSymVectorFormOfStrain(E);
330 vS.beSymVectorForm(S);
345 bp::extract<double> exNum(val);
346 bp::extract<FloatArray> exMat(val);
347 if(exNum.check()){ answer=
FloatArray{exNum()};
return 1; }
348 else if(exMat.check()){ answer=exMat();
return 1;}
349 OOFEM_WARNING(
"Dictionary entry of material state not float or something convertible to FloatArray");
352 std :: string s = std :: to_string( type );
356 if ( PyFloat_Check(val) != 0 ) {
358 }
else if ( PyList_Check(val) != 0 ) {
360 int size = PyList_Size(val);
362 for (
int i = 0; i < size; i++ ) {
363 PyObject *val = PyList_GET_ITEM(val, i);
364 answer[i] = PyFloat_AS_DOUBLE(val);
369 OOFEM_WARNING(
"Dictionary entry of material state is not a list (only lists supported for now)");
virtual void initTempStatus()
Initializes the temporary internal variables, describing the current state according to previously re...
virtual void updateYourself(TimeStep *tStep)
Update equilibrium history variables according to temp-variables.
InternalStateType
Type representing the physical meaning of element or constitutive model internal variable.
void subtract(const FloatArray &src)
Subtracts array src to receiver.
void letTempStrainVectorBe(const FloatArray &v)
Assigns tempStrainVector to given vector v.
virtual MaterialStatus * giveStatus(GaussPoint *gp) const
Returns material status of receiver in given integration point.
void letTempFVectorBe(const FloatArray &v)
Assigns tempFVector to given vector v.
virtual void giveFirstPKStressVector_3d(FloatArray &answer, GaussPoint *gp, const FloatArray &reducedF, TimeStep *tStep)
Default implementation relies on giveRealStressVector for second Piola-Kirchoff stress.
const FloatArray & givePVector() const
Returns the const pointer to receiver's first Piola-Kirchhoff stress vector.
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
virtual int giveIPValue(FloatArray &answer, GaussPoint *gp, InternalStateType type, TimeStep *tStep)
Returns the integration point corresponding value in Reduced form.
double & at(int i)
Coefficient access function.
This class implements a structural material status information.
bp::object smallDefTangent
bp::object module
module containing functions (created from moduleName)
bp::dict stateDict
Internal state variables.
double giveTargetTime()
Returns target time.
bp::object smallDef
callable for small deformations
MatResponseMode
Describes the character of characteristic material matrix.
StructuralPythonMaterial(int n, Domain *d)
Constructor.
void callTangentFunction(FloatMatrix &answer, bp::object func, const FloatArray &strain, const FloatArray &stress, bp::object stateDict, bp::object tempStateDict, TimeStep *tStep) const
virtual ~StructuralPythonMaterialStatus()
Destructor.
void beMatrixForm(const FloatArray &aArray)
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
bp::object giveTempStateDictionary()
const FloatArray & giveTempPVector() const
Returns the const pointer to receiver's temporary first Piola-Kirchhoff stress vector.
void times(double f)
Multiplies receiver by factor f.
const FloatArray & giveTempStrainVector() const
Returns the const pointer to receiver's temporary strain vector.
#define _IFT_StructuralPythonMaterial_moduleName
double at(int i, int j) const
Coefficient access function.
virtual ~StructuralPythonMaterial()
Destructor.
void reinitTempStateDictionary()
virtual void give3dMaterialStiffnessMatrix_dPdF(FloatMatrix &answer, MatResponseMode mode, GaussPoint *gp, TimeStep *tStep)
Abstract base class representing a material status information.
virtual MaterialStatus * CreateStatus(GaussPoint *gp) const
Creates new copy of associated status and inserts it into given integration point.
void callStressFunction(bp::object func, const FloatArray &oldStrain, const FloatArray &oldStress, const FloatArray &strain, FloatArray &stress, bp::object stateDict, bp::object tempStateDict, TimeStep *tStep) const
Class representing vector of real numbers.
Implementation of matrix containing floating point numbers.
IRResultType
Type defining the return values of InputRecord reading operations.
virtual void giveRealStressVector_3d(FloatArray &answer, GaussPoint *gp, const FloatArray &reducedStrain, TimeStep *tStep)
Default implementation relies on giveRealStressVector for second Piola-Kirchoff stress.
void letTempStressVectorBe(const FloatArray &v)
Assigns tempStressVector to given vector v.
const FloatArray & giveStressVector() const
Returns the const pointer to receiver's stress vector.
IntegrationPointStatus * giveMaterialStatus()
Returns reference to associated material status (NULL if not defined).
const FloatArray & giveFVector() const
Returns the const pointer to receiver's deformation gradient vector.
void resize(int rows, int cols)
Checks size of receiver towards requested bounds.
void beTProductOf(const FloatMatrix &a, const FloatMatrix &b)
Assigns to the receiver product of .
const FloatArray & giveTempFVector() const
Returns the const pointer to receiver's temporary deformation gradient vector.
void setColumn(const FloatArray &src, int c)
Sets the values of the matrix in specified column.
void times(double s)
Multiplies receiver with scalar.
Abstract base class for all "structural" constitutive models.
virtual void initTempStatus()
Initializes the temporary internal variables, describing the current state according to previously re...
Domain * giveDomain() const
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
bp::object giveStateDictionary()
REGISTER_Material(DummyMaterial)
void beProductOf(const FloatMatrix &a, const FloatMatrix &b)
Assigns to the receiver product of .
const FloatArray & giveTempStressVector() const
Returns the const pointer to receiver's temporary stress vector.
int giveSize() const
Returns the size of receiver.
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
std::string moduleName
Name of the file that contains the python function.
void beInverseOf(const FloatMatrix &src)
Modifies receiver to become inverse of given parameter.
const FloatArray & giveStrainVector() const
Returns the const pointer to receiver's strain vector.
Class representing integration point in finite element program.
#define OOFEM_WARNING(...)
bp::object largeDefTangent
Class representing solution step.
StructuralPythonMaterialStatus(Domain *d, GaussPoint *gp)
Constructor.
double pert
Numerical pertubation for numerical tangents.
virtual void give3dMaterialStiffnessMatrix(FloatMatrix &answer, MatResponseMode mode, GaussPoint *gp, TimeStep *tStep)
Computes full 3d material stiffness matrix at given integration point, time, respecting load history ...
virtual int giveIPValue(FloatArray &answer, GaussPoint *gp, InternalStateType type, TimeStep *tStep)
Returns the integration point corresponding value in Reduced form.
virtual void updateYourself(TimeStep *tStep)
Update equilibrium history variables according to temp-variables.
void letTempPVectorBe(const FloatArray &v)
Assigns tempPVector to given vector v.
void resize(int s)
Resizes receiver towards requested size.