OpenSees Dynamic API in OpenSeesPy

Forum for asking and answering questions related to use of the OpenSeesPy module

Moderators: silvia, selimgunay, Moderators

Post Reply
tomossk
Posts: 2
Joined: Fri Jan 07, 2022 9:01 am

OpenSees Dynamic API in OpenSeesPy

Post by tomossk » Sat Jan 08, 2022 11:29 pm

I'm trying to add new material in OpenSees using OpenSees Dynamic API described in
https://opensees.berkeley.edu/wiki/inde ... al_C%2B%2B

Now I'm checking the example source saved in DEVELOPER/material/cpp/ElasticPPcpp.cpp.
Original OpenSees works well as expected.

However, OpenSeesPy does not work and I got error message "WARNING material type ElasticPPcpp is unknown."
Here is material definition in input script.
ops.uniaxialMaterial("ElasticPPcpp", 1, 3000,0.001)

OpenSeesPy supports OpenSees Dynamic API?
Do I need additional commands to add new material dynamically?

mhscott
Posts: 872
Joined: Tue Jul 06, 2004 3:38 pm
Location: Corvallis, Oregon USA
Contact:

Re: OpenSees Dynamic API in OpenSeesPy

Post by mhscott » Sun Jan 09, 2022 5:43 am

OpenSeesPy is a dll itself, so I don't think the dll instructions will work.

Either way, you are better off not dynamically linking. Just compile and link from source code.

tomossk
Posts: 2
Joined: Fri Jan 07, 2022 9:01 am

Re: OpenSees Dynamic API in OpenSeesPy

Post by tomossk » Sun Jan 09, 2022 3:14 pm

Dear Prof. Scott.

Thank you for your quick reply.
I think dll can call another dll.
I check current OpenSees source code and add new code in SRC/interpreter/OpenSeesUniaxialMaterialCommands.cpp.
(The code of dynamic loading was copied from SRC/material/uniaxial/TclModelBuilderUniaxialMaterialCommand.cpp and modified.)
It seems to work as expected in Windows. (I'm not checking in Linux.) Do you have any comments about this modification?
If you agree, could you add this kind of code not only in material but also in all Dynamic API like element, solver, integrator, solution algorithm and recorder?

---add include at the top---
#include <package.h>

---original code from line 438---
OPS_ParsingFunctionMap::const_iterator iter = uniaxialMaterialsMap.find(matType);
if (iter == uniaxialMaterialsMap.end()) {
opserr<<"WARNING material type " << matType << " is unknown\n";
return -1;
}

UniaxialMaterial* theMaterial = (UniaxialMaterial*) (*iter->second)();

---replace to new code---
OPS_ParsingFunctionMap::const_iterator iter = uniaxialMaterialsMap.find(matType);
UniaxialMaterial* theMaterial = 0;
if (iter != uniaxialMaterialsMap.end()) {
theMaterial = (UniaxialMaterial*)(*iter->second)();
}
else {
void* libHandle;
void* (*funcPtr)();

char* matFuncName = new char[strlen(matType) + 5];
strcpy(matFuncName, "OPS_");
strcpy(matFuncName + 4, matType);
int res = getLibraryFunction(matType, matFuncName, &libHandle, (void**)&funcPtr);

if (res == 0) {
char* matName = new char[strlen(matType) + 1];
strcpy(matName, matType);
uniaxialMaterialsMap.insert(std::make_pair(matName, funcPtr));

theMaterial = (UniaxialMaterial*)(*funcPtr)();
}
else {
opserr << "WARNING material type " << matType << " is unknown\n";
return -1;
}
}

Post Reply