Skip to content

Commit

Permalink
Merge pull request OpenSees#1476 from mhscott/reliability
Browse files Browse the repository at this point in the history
Adding more reliability commands to Python interpreter
  • Loading branch information
mhscott authored Aug 1, 2024
2 parents 7361cb2 + ffbd989 commit 7389fa7
Show file tree
Hide file tree
Showing 15 changed files with 1,286 additions and 222 deletions.
22 changes: 12 additions & 10 deletions MAKES/Makefile.def.EC2-UBUNTU
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ GRAPHIC_FLAG = -D_NOGRAPHICS
PROGRAMMING_MODE = SEQUENTIAL
DEBUG_MODE = NO_DEBUG
RELIABILITY = NO_RELIABILITY

RELIABILITY = YES_RELIABILITY
RELIABILITY_FLAG = -D_RELIABILITY

# %---------------------------------%
# | SECTION 2: PATHS |
Expand All @@ -88,7 +89,6 @@ RELIABILITY = NO_RELIABILITY
# remove the directory from DIRS.

BASE = ./usr/local
HOME = ./home
FE = $(HOME)/OpenSees/SRC

AMDdir = $(HOME)/OpenSees/OTHER/AMD
Expand Down Expand Up @@ -134,6 +134,7 @@ AMD_LIBRARY = $(HOME)/lib/libAMD.a
UMFPACK_LIBRARY = $(HOME)/lib/libUmfpack.a
METIS_LIBRARY = $(HOME)/lib/libMetis.a
CSPARSE_LIBRARY = $(HOME)/lib/libCSparse.a
RELIABILITY_LIBRARY = $(HOME)/lib/libReliability.a

TCL_LIBRARY = /usr/lib/x86_64-linux-gnu/libtcl8.6.so

Expand All @@ -149,7 +150,8 @@ WIPE_LIBS = $(FE_LIBRARY) \
$(ARPACK_LIBRARY) \
$(UMFPACK_LIBRARY) \
$(CSPARSE_LIBRARY) \
$(METIS_LIBRARY)
$(METIS_LIBRARY) \
$(RELIABILITY_LIBRARY)

# %---------------------------------------------------------%
# | SECTION 4: COMPILERS |
Expand Down Expand Up @@ -181,7 +183,7 @@ RANLIBFLAGS =
ifeq ($(INTERPRETER_LANGUAGE), PYTHON)


C++FLAGS = -Wall -D_LINUX -D_UNIX -D_TCL85 \
C++FLAGS = -Wall -D_LINUX -D_UNIX -D_PYTHON3 -D_TCL85 \
$(GRAPHIC_FLAG) $(RELIABILITY_FLAG) $(DEBUG_FLAG) \
$(PROGRAMMING_FLAG) -fPIC -ffloat-store
CFLAGS = -Wall -fPIC
Expand All @@ -193,11 +195,11 @@ LINKFLAGS = -g -pg

else

C++FLAGS = -Wall -D_LINUX -D_UNIX -D_TCL85 \
C++FLAGS = -Wall -D_LINUX -D_UNIX -D_PYTHON3 -D_TCL85 \
$(GRAPHIC_FLAG) $(RELIABILITY_FLAG) $(DEBUG_FLAG) \
$(PROGRAMMING_FLAG) -O3 -ffloat-store
CFLAGS = -Wall -O2
FFLAGS = -Wall -O -fallow-argument-mismatch
$(PROGRAMMING_FLAG) -O3 -ffloat-store -fPIC
CFLAGS = -Wall -O2 -fPIC
FFLAGS = -Wall -O -fallow-argument-mismatch -fPIC

# Linker
LINKER = $(CC++)
Expand Down Expand Up @@ -261,7 +263,7 @@ SHELL = /bin/sh
MACHINE_LINKLIBS = -L$(BASE)/lib \
-L$(HOME)/lib

MACHINE_NUMERICAL_LIBS = -lm \
MACHINE_NUMERICAL_LIBS = $(RELIABILITY_LIBRARY) -lm \
$(ARPACK_LIBRARY) \
$(SUPERLU_LIBRARY) \
$(UMFPACK_LIBRARY) $(CSPARSE_LIBRARY) \
Expand Down Expand Up @@ -289,7 +291,7 @@ include $(FE)/Makefile.incl

#TCL_INCLUDES = -I/usr/includes/tcl-private/generic
TCL_INCLUDES = -I/usr/include/tcl8.6
PYTHON_INCLUDES = -I/usr/include/python3.5
PYTHON_INCLUDES = -I/usr/include/python3.10

INCLUDES = $(TCL_INCLUDES) $(FE_INCLUDES) $(MACHINE_INCLUDES) $(PYTHON_INCLUDES)

Expand Down
14 changes: 14 additions & 0 deletions SRC/api/elementAPI_TCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <WrapperNDMaterial.h>
#include <LimitCurve.h>
#include <WrapperLimitCurve.h>
#include <ReliabilityDomain.h>

#include <OPS_Globals.h>

Expand Down Expand Up @@ -89,6 +90,7 @@ static LimitCurveFunction* theLimitCurveFunctions = NULL;

static Tcl_Interp* theInterp = 0;
static Domain* theDomain = 0;
static ReliabilityDomain* theReliabilityDomain = 0;

static TclModelBuilder* theModelBuilder = 0;

Expand Down Expand Up @@ -1290,6 +1292,18 @@ OPS_GetDomain(void)
return theDomain;
}

ReliabilityDomain*
OPS_GetReliabilityDomain(void)
{
return theReliabilityDomain;
}

void
OPS_SetReliabilityDomain(ReliabilityDomain *theDomain)
{
theReliabilityDomain = theDomain;
}

void
TCL_OPS_setModelBuilder(TclModelBuilder* theNewBuilder)
{
Expand Down
3 changes: 3 additions & 0 deletions SRC/domain/domain/Domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ Domain::~Domain()

if (theParameters != 0)
delete theParameters;

if (paramIndex != 0)
delete [] paramIndex;

if (theEleIter != 0)
delete theEleIter;
Expand Down
117 changes: 97 additions & 20 deletions SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,108 @@
#include <math.h>
#include <stdlib.h>

#include <elementAPI.h>
#include <ModulatingFunction.h>
#include <OpenSeesReliabilityCommands.h>

void *
OPS_DiscretizedRandomProcessSeries(void)
{
// Pointer that will be returned
TimeSeries *theSeries = 0;

int tag;
double mean,maxStdv;

int numData = 1;

int numRemainingArgs = OPS_GetNumRemainingInputArgs();
if (numRemainingArgs < 4) {
opserr << "ERROR: Insufficient arguments for DiscretizedRandomProcess series" << endln;
return 0;
}

if (OPS_GetIntInput(&numData, &tag) != 0) {
opserr << "WARNING invalid tag for DiscretizedRandomProcess" << endln;
return 0;
}
if (OPS_GetDouble(&numData, &mean) != 0) {
opserr << "WARNING invalid mean for DicretizedRandomProcess with tag: " << tag << endln;
return 0;
}
if (OPS_GetDouble(&numData, &maxStdv) != 0) {
opserr << "WARNING invalid maxStdv for DicretizedRandomProcess with tag: " << tag << endln;
return 0;
}

ReliabilityDomain *theReliabilityDomain = OPS_GetReliabilityDomain();
if (theReliabilityDomain == 0) {
opserr << "ERROR DiscretizedRandomProcess -- reliability domain not defined" << endln;
return 0;
}

int numModFcns = numRemainingArgs - 3;
ModulatingFunction **theModFcns = new ModulatingFunction*[numModFcns];
for (int i = 0; i < numModFcns; i++) {
numData = 1;
int modTag;
if (OPS_GetInt(&numData, &modTag) != 0) {
opserr << "WARNING invalid modulating function tag in DiscretizedRandomProcess with tag: " << tag << endln;
delete [] theModFcns; // So no memory leak
return 0;
}
//
// Get pointer from reliability domain
//
theModFcns[i] = theReliabilityDomain->getModulatingFunctionPtr(modTag);
if (theModFcns[i] == 0) {
opserr << "ERROR DiscretizedRandomProcess -- modulating function with tag "
<< modTag << " not found" << endln;
delete [] theModFcns; // So no memory leak
return 0;
}
}

theSeries = new DiscretizedRandomProcessSeries(tag, numModFcns, theModFcns, mean, maxStdv);

if (theSeries == 0) {
opserr << "WARNING ran out of memory creating DiscretizedRandomProcess series with tag: " << tag << endln;
delete [] theModFcns; // So no memory leak
return 0;
}

return theSeries;
}

DiscretizedRandomProcessSeries::DiscretizedRandomProcessSeries(int tag,
int num,
ModulatingFunction **theModFuncs,
double p_mean,
double p_maxStdv)
:TimeSeries(tag, TSERIES_TAG_DiscretizedRandomProcessSeries)
:TimeSeries(tag, TSERIES_TAG_DiscretizedRandomProcessSeries),
numModFuncs(num), c(p_maxStdv), mean(p_mean), maxStdv(p_maxStdv),
theModulatingFunctions(theModFuncs), randomVariables(0), kickInTimes(0), parameterID(0)
{
randomVariables = 0;
kickInTimes = 0;
theModulatingFunctions = theModFuncs;
numModFuncs = num;
mean = p_mean;
maxStdv = p_maxStdv;

c = 0.0;

}

TimeSeries *
DiscretizedRandomProcessSeries::getCopy(void)
{
opserr << "DiscretizedRandomProcessSeries::getCopy() - not yet implemented\n";
return 0;
DiscretizedRandomProcessSeries *theCopy =
new DiscretizedRandomProcessSeries(this->getTag(), numModFuncs, theModulatingFunctions,
mean, maxStdv);

theCopy->c = c;
theCopy->parameterID = parameterID;

if (randomVariables != 0)
theCopy->randomVariables = new Vector(*randomVariables);

if (kickInTimes != 0)
theCopy->kickInTimes = new Vector(*kickInTimes);

return theCopy;
}


Expand Down Expand Up @@ -211,21 +291,20 @@ int
DiscretizedRandomProcessSeries::setParameter(const char **argv, int argc,
Parameter &param)
{
if (argc < 1)
if (argc < 3)
return -1;

// **** MHS needs to fix this!!
//int rvNumber = info.theInt;
int rvNumber = 1; // to get it to compile for now
int rvNumber = atoi(argv[2]); // to get it to compile for now
// **********************

// The second argument tells when the random variable "kicks in".
// Store this in a table...
// In case the vector doesn't exist
if (kickInTimes == 0) {
kickInTimes = new Vector(rvNumber);
(*kickInTimes)(rvNumber-1) = (double)atof(argv[0]);

(*kickInTimes)(rvNumber-1) = (double)atof(argv[1]);
// Assume more than one random variable, so don't
// update factor 'c' here.
}
Expand All @@ -245,9 +324,7 @@ DiscretizedRandomProcessSeries::setParameter(const char **argv, int argc,
}

// Put in new value
(*kickInTimes)(rvNumber-1) = (double)atof(argv[0]);


(*kickInTimes)(rvNumber-1) = (double)atof(argv[1]);
/////// Update factor 'c' /////////

// Number of discretizing random variables
Expand Down Expand Up @@ -303,12 +380,12 @@ DiscretizedRandomProcessSeries::setParameter(const char **argv, int argc,
}

c = maxStdv;
opserr << "c: " << c << endln;
//opserr << "c: " << c << endln;

//////////////////////////////////////
}
else {
(*kickInTimes)(rvNumber-1) = (double)atof(argv[0]);
(*kickInTimes)(rvNumber-1) = (double)atof(argv[1]);
}

// The random variable number is returned as a parameter ID
Expand Down
2 changes: 1 addition & 1 deletion SRC/domain/pattern/DiscretizedRandomProcessSeries.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DiscretizedRandomProcessSeries : public TimeSeries
double c;
double mean;
double maxStdv;
double maxStdvTime;
//double maxStdvTime;
ModulatingFunction **theModulatingFunctions;
Vector *randomVariables;
Vector *kickInTimes;
Expand Down
Loading

0 comments on commit 7389fa7

Please sign in to comment.