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?
OpenSees Dynamic API in OpenSeesPy
Moderators: silvia, selimgunay, Moderators
Re: OpenSees Dynamic API in OpenSeesPy
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.
Either way, you are better off not dynamically linking. Just compile and link from source code.
Re: OpenSees Dynamic API in OpenSeesPy
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;
}
}
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;
}
}