Skip to content

Commit

Permalink
Merge pull request #703 from sewkokot/addNdfAndNdmToPython
Browse files Browse the repository at this point in the history
Adding getNDM and getNDF output commands to OpenSeesPy
  • Loading branch information
mhscott committed Nov 2, 2021
2 parents 505dc03 + e041113 commit 395c576
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
2 changes: 2 additions & 0 deletions SRC/interpreter/OpenSeesCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ int OPS_nodeCoord();
int OPS_setNodeCoord();
int OPS_updateElementDomain();
int OPS_eleNodes();
int OPS_getNDMM();
int OPS_getNDFF();
int OPS_eleType();
int OPS_nodeDOFs();
int OPS_nodeMass();
Expand Down
85 changes: 85 additions & 0 deletions SRC/interpreter/OpenSeesOutputCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,91 @@ int OPS_updateElementDomain()
return 0;
}

int OPS_getNDMM()
{

int ndm;
int numdata = 1;

if (OPS_GetNumRemainingInputArgs() > 0) {

int tag;

if (OPS_GetIntInput(&numdata, &tag) < 0) {
opserr << "WARNING getNDM nodeTag? \n";
return -1;
}

Domain* theDomain = OPS_GetDomain();
if (theDomain == 0) return -1;
Node *theNode = theDomain->getNode(tag);

if (theNode == 0) {
opserr << "WARNING node "<< tag <<" does not exist\n";
return -1;
}

const Vector& crds = theNode->getCrds();
ndm = crds.Size();

} else {

ndm = OPS_GetNDM();

}

int size = 1;

if (OPS_SetIntOutput(&size, &ndm, false) < 0) {
opserr << "WARNING failed to set output\n";
return -1;
}

return 0;
}

int OPS_getNDFF()
{

int ndf;
int numdata = 1;

if (OPS_GetNumRemainingInputArgs() > 0) {

int tag;

if (OPS_GetIntInput(&numdata, &tag) < 0) {
opserr << "WARNING getNDF nodeTag? \n";
return -1;
}

Domain* theDomain = OPS_GetDomain();
if (theDomain == 0) return -1;
Node *theNode = theDomain->getNode(tag);

if (theNode == 0) {
opserr << "WARNING node "<< tag <<" does not exist\n";
return -1;
}

ndf = theNode->getNumberDOF();

} else {

ndf = OPS_GetNDF();

}

int size = 1;

if (OPS_SetIntOutput(&size, &ndf, false) < 0) {
opserr << "WARNING failed to set output\n";
return -1;
}

return 0;
}

int OPS_eleType()
{
if (OPS_GetNumRemainingInputArgs() < 1) {
Expand Down
26 changes: 26 additions & 0 deletions SRC/interpreter/PythonWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,30 @@ static PyObject *Py_ops_updateElementDomain(PyObject *self, PyObject *args)
return wrapper->getResults();
}

static PyObject *Py_ops_getNDMM(PyObject *self, PyObject *args)
{
wrapper->resetCommandLine(PyTuple_Size(args), 1, args);

if (OPS_getNDMM() < 0) {
opserr<<(void*)0;
return NULL;
}

return wrapper->getResults();
}

static PyObject *Py_ops_getNDFF(PyObject *self, PyObject *args)
{
wrapper->resetCommandLine(PyTuple_Size(args), 1, args);

if (OPS_getNDFF() < 0) {
opserr<<(void*)0;
return NULL;
}

return wrapper->getResults();
}

static PyObject *Py_ops_eleNodes(PyObject *self, PyObject *args)
{
wrapper->resetCommandLine(PyTuple_Size(args), 1, args);
Expand Down Expand Up @@ -2448,6 +2472,8 @@ PythonWrapper::addOpenSeesCommands()
addCommand("nodeCoord", &Py_ops_nodeCoord);
addCommand("setNodeCoord", &Py_ops_setNodeCoord);
addCommand("updateElementDomain", &Py_ops_updateElementDomain);
addCommand("getNDM", &Py_ops_getNDMM);
addCommand("getNDF", &Py_ops_getNDFF);
addCommand("eleNodes", &Py_ops_eleNodes);
addCommand("eleType", &Py_ops_eleType);
addCommand("nodeDOFs", &Py_ops_nodeDOFs);
Expand Down
4 changes: 2 additions & 2 deletions SRC/tcl/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7062,7 +7062,7 @@ getNDM(ClientData clientData, Tcl_Interp* interp, int argc, TCL_Char** argv)
if (argc > 1) {
int tag;
if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
opserr << "WARNING ndm nodeTag? \n";
opserr << "WARNING getNDM nodeTag? \n";
return TCL_ERROR;
}
Node* theNode = theDomain.getNode(tag);
Expand Down Expand Up @@ -7096,7 +7096,7 @@ getNDF(ClientData clientData, Tcl_Interp* interp, int argc, TCL_Char** argv)
if (argc > 1) {
int tag;
if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
opserr << "WARNING ndf nodeTag? \n";
opserr << "WARNING getNDF nodeTag? \n";
return TCL_ERROR;
}
Node* theNode = theDomain.getNode(tag);
Expand Down

0 comments on commit 395c576

Please sign in to comment.