From 241d7809aa0df11ee484d5f3bc4cfcbecd6b2a19 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Wed, 13 Mar 2024 18:50:45 -0700 Subject: [PATCH 01/32] Deleting reliability objects, was leaking memory --- SRC/interpreter/OpenSeesReliabilityCommands.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index bf0b55159c..64e0b034c0 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -127,8 +127,10 @@ OpenSeesReliabilityCommands::OpenSeesReliabilityCommands( } OpenSeesReliabilityCommands::~OpenSeesReliabilityCommands() { - if (theDomain != 0) delete theDomain; - cmds = 0; + this->wipe(); + if (theDomain != 0) + delete theDomain; + cmds = 0; } ReliabilityDomain *OpenSeesReliabilityCommands::getDomain() { @@ -2565,6 +2567,8 @@ int OPS_runFOSMAnalysis() { return -1; } + delete theFOSMAnalysis; + return 0; } @@ -2655,6 +2659,8 @@ int OPS_runFORMAnalysis() { return -1; } + delete theFORMAnalysis; + return 0; } @@ -2840,5 +2846,7 @@ int OPS_runImportanceSamplingAnalysis() { return -1; } + delete theImportanceSamplingAnalysis; + return 0; } From 9ad243de19a8dd1c9ea2d8382fcaba1e4c011880 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Wed, 13 Mar 2024 18:51:20 -0700 Subject: [PATCH 02/32] Deleting paramIndex to prevent memory leak --- SRC/domain/domain/Domain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SRC/domain/domain/Domain.cpp b/SRC/domain/domain/Domain.cpp index 5b90eabf05..2133065844 100644 --- a/SRC/domain/domain/Domain.cpp +++ b/SRC/domain/domain/Domain.cpp @@ -358,6 +358,9 @@ Domain::~Domain() if (theParameters != 0) delete theParameters; + + if (paramIndex != 0) + delete [] paramIndex; if (theEleIter != 0) delete theEleIter; From e563de092771c7ef914fc974754df51ff09764bf Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Wed, 13 Mar 2024 19:06:33 -0700 Subject: [PATCH 03/32] Using objects instead of pointers --- .../OpenSeesReliabilityCommands.cpp | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 64e0b034c0..b26255bcd1 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -2552,23 +2552,16 @@ int OPS_runFOSMAnalysis() { return -1; } - FOSMAnalysis *theFOSMAnalysis = new FOSMAnalysis( + FOSMAnalysis theFOSMAnalysis( theReliabilityDomain, theStructuralDomain, theFunctionEvaluator, theGradientEvaluator, 0, filename); - if (theFOSMAnalysis == 0) { - opserr << "ERROR: could not create theFOSMAnalysis \n"; - return -1; - } - // Now run the analysis - if (theFOSMAnalysis->analyze() < 0) { + if (theFOSMAnalysis.analyze() < 0) { opserr << "WARNING: the FOSM analysis failed\n"; return -1; } - delete theFOSMAnalysis; - return 0; } @@ -2642,25 +2635,17 @@ int OPS_runFORMAnalysis() { } // Create the analysis object - FORMAnalysis *theFORMAnalysis = new FORMAnalysis( + FORMAnalysis theFORMAnalysis( theReliabilityDomain, theFindDesignPointAlgorithm, theFunctionEvaluator, theProbabilityTransformation, filename, relSensTag); - // Check that it really was created - if (theFORMAnalysis == 0) { - opserr << "ERROR: could not create theFORMAnalysis \n"; - return TCL_ERROR; - } - // Now run the analysis - if (theFORMAnalysis->analyze() < 0) { + if (theFORMAnalysis.analyze() < 0) { opserr << "WARNING: the FORM analysis failed\n"; return -1; } - delete theFORMAnalysis; - return 0; } @@ -2826,27 +2811,18 @@ int OPS_runImportanceSamplingAnalysis() { return -1; } - ImportanceSamplingAnalysis *theImportanceSamplingAnalysis = - new ImportanceSamplingAnalysis( + ImportanceSamplingAnalysis theImportanceSamplingAnalysis( theReliabilityDomain, theStructuralDomain, theProbabilityTransformation, theFunctionEvaluator, theRandomNumberGenerator, 0, numberOfSimulations, targetCOV, samplingVariance, printFlag, filename, analysisTypeTag); - if (theImportanceSamplingAnalysis == 0) { - opserr << "ERROR: could not create " - "theImportanceSamplingAnalysis \n"; - return -1; - } - - cmds->setImportanceSamplingAnalysis(theImportanceSamplingAnalysis); + cmds->setImportanceSamplingAnalysis(&theImportanceSamplingAnalysis); - if (theImportanceSamplingAnalysis->analyze() < 0) { + if (theImportanceSamplingAnalysis.analyze() < 0) { opserr << "WARNING: failed to run ImportanceSamplingAnalysis\n"; return -1; } - delete theImportanceSamplingAnalysis; - return 0; } From 4ed253fcaf692ffe7a93bf40f554cfcf6c65a02d Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 14 Mar 2024 07:17:48 -0700 Subject: [PATCH 04/32] Not setting importance sampling pointer --- SRC/interpreter/OpenSeesReliabilityCommands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index b26255bcd1..68426ecb21 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -2817,7 +2817,7 @@ int OPS_runImportanceSamplingAnalysis() { theRandomNumberGenerator, 0, numberOfSimulations, targetCOV, samplingVariance, printFlag, filename, analysisTypeTag); - cmds->setImportanceSamplingAnalysis(&theImportanceSamplingAnalysis); + //cmds->setImportanceSamplingAnalysis(&theImportanceSamplingAnalysis); if (theImportanceSamplingAnalysis.analyze() < 0) { opserr << "WARNING: failed to run ImportanceSamplingAnalysis\n"; From 1d62919d4bddd0bedfd3d3317ad56bf38ba682f4 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 14 Mar 2024 13:33:41 -0700 Subject: [PATCH 05/32] Using reasonable defaults for prob transf and random number generator instead of exiting analysis --- .../OpenSeesReliabilityCommands.cpp | 71 +++++++++++-------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 68426ecb21..4c194a9faa 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -2479,6 +2479,7 @@ int inputCheck() { // theCorrelationMatrix // set defaults + /* ProbabilityTransformation *theProbabilityTransformation = cmds->getProbabilityTransformation(); if (theProbabilityTransformation == 0) { @@ -2487,17 +2488,20 @@ int inputCheck() { << endln; theProbabilityTransformation = new AllIndependentTransformation(theReliabilityDomain, 0); + cmds->setProbabilityTransformation(theProbabilityTransformation); } - + */ + // reliabilityConvergenceCheck Standard -e1 1.0e-3 // -e2 1.0e-3 -print 1 functionEvaluator Tcl // gradientEvaluator FiniteDifference -pert 1000 SearchDirection *theSearchDirection = cmds->getSearchDirection(); if (theSearchDirection == 0) { - opserr << "No searchDirectin specified, assuming Standard" + opserr << "No searchDirection specified, assuming iHLRF" << endln; theSearchDirection = new HLRFSearchDirection(); + cmds->setSearchDirection(theSearchDirection); } // meritFunctionCheck AdkZhang -multi 2.0 @@ -2525,6 +2529,12 @@ int OPS_runFOSMAnalysis() { return -1; } + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain == 0) { + opserr << "FOSMAnalysis -- ReliabilityDomain is not defined\n"; + return -1; + } + // Check for essential ingredients FunctionEvaluator *theFunctionEvaluator = cmds->getFunctionEvaluator(); if (theFunctionEvaluator == 0) { @@ -2540,12 +2550,6 @@ int OPS_runFOSMAnalysis() { return -1; } - ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); - if (theReliabilityDomain == 0) { - opserr << "ReliabilityDomain is not defined\n"; - return -1; - } - Domain *theStructuralDomain = cmds->getStructuralDomain(); if (theStructuralDomain == 0) { opserr << "Structural Domain is not defined\n"; @@ -2580,6 +2584,12 @@ int OPS_runFORMAnalysis() { return -1; } + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain == 0) { + opserr << "FORMAnalysis -- ReliabilityDomain is not defined\n"; + return -1; + } + // Check for essential ingredients FunctionEvaluator *theFunctionEvaluator = cmds->getFunctionEvaluator(); if (theFunctionEvaluator == 0) { @@ -2600,16 +2610,11 @@ int OPS_runFORMAnalysis() { ProbabilityTransformation *theProbabilityTransformation = cmds->getProbabilityTransformation(); if (theProbabilityTransformation == 0) { - opserr << "Need theProbabilityTransformation before a " - "FORMAnalysis " - "can be created\n"; - return -1; - } - - ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); - if (theReliabilityDomain == 0) { - opserr << "ReliabilityDomain is not defined\n"; - return -1; + opserr << "FORMAnalysis - probability transformation not defined - "; + opserr << "assuming all independent transformation" << endln; + theProbabilityTransformation = + new AllIndependentTransformation(theReliabilityDomain, 0); + cmds->setProbabilityTransformation(theProbabilityTransformation); } Domain *theStructuralDomain = cmds->getStructuralDomain(); @@ -2666,13 +2671,22 @@ int OPS_runImportanceSamplingAnalysis() { } const char *filename = OPS_GetString(); + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain == 0) { + opserr << "Need theReliabilityDomain before a " + "ImportanceSamplingAnalysis can be created\n"; + return -1; + } + // Check for essential tools ProbabilityTransformation *theProbabilityTransformation = cmds->getProbabilityTransformation(); if (theProbabilityTransformation == 0) { - opserr << "Need theProbabilityTransformation before a " - "ImportanceSamplingAnalysis can be created\n"; - return -1; + opserr << "ImportanceSampingAnalysis - probability transformation not defined - "; + opserr << "assuming all independent transformation" << endln; + theProbabilityTransformation = + new AllIndependentTransformation(theReliabilityDomain, 0); + cmds->setProbabilityTransformation(theProbabilityTransformation); } FunctionEvaluator *theFunctionEvaluator = cmds->getFunctionEvaluator(); if (theFunctionEvaluator == 0) { @@ -2684,16 +2698,13 @@ int OPS_runImportanceSamplingAnalysis() { RandomNumberGenerator *theRandomNumberGenerator = cmds->getRandomNumberGenerator(); if (theRandomNumberGenerator == 0) { - opserr << "Need theRandomNumberGenerator before a " - "ImportanceSamplingAnalysis can be created\n"; - return -1; - } - ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); - if (theReliabilityDomain == 0) { - opserr << "Need theReliabilityDomain before a " - "ImportanceSamplingAnalysis can be created\n"; - return -1; + // Don't really need to say this - just do it - bc CStdLib is the only option -- MHS + //opserr << "ImportanceSampingAnalysis - random number generator not defined - "; + //opserr << "assuming CStdLib generator" << endln; + theRandomNumberGenerator = new CStdLibRandGenerator(); + cmds->setRandomNumberGenerator(theRandomNumberGenerator); } + Domain *theStructuralDomain = cmds->getStructuralDomain(); if (theReliabilityDomain == 0) { opserr << "Need theStructuralDomain before a " From 38d870d20c699d0e996f7a08e7276ba81ef5afcc Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 14 Mar 2024 13:42:32 -0700 Subject: [PATCH 06/32] Setting pointer and removing a check --- SRC/interpreter/OpenSeesReliabilityCommands.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 4c194a9faa..42dd94ad11 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -2036,6 +2036,7 @@ int OPS_findDesignPoint() { opserr << "Assume all RV's are independent" << endln; theProbabilityTransformation = new AllIndependentTransformation(theReliabilityDomain, 0); + cmds->setProbabilityTransformation(theProbabilityTransformation); } ReliabilityConvergenceCheck *theReliabilityConvergenceCheck = @@ -2496,6 +2497,7 @@ int inputCheck() { // -e2 1.0e-3 -print 1 functionEvaluator Tcl // gradientEvaluator FiniteDifference -pert 1000 + /* SearchDirection *theSearchDirection = cmds->getSearchDirection(); if (theSearchDirection == 0) { opserr << "No searchDirection specified, assuming iHLRF" @@ -2503,7 +2505,8 @@ int inputCheck() { theSearchDirection = new HLRFSearchDirection(); cmds->setSearchDirection(theSearchDirection); } - + */ + // meritFunctionCheck AdkZhang -multi 2.0 // -add 10.0 -factor 0.5 stepSizeRule Armijo // -maxNum 5 -base 0.5 -initial 1.0 2 -print 0 startPoint From 814a68ef1046da222ed0d60a79b726789991e6b9 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 14 Mar 2024 15:42:58 -0700 Subject: [PATCH 07/32] Adding framekwork for findCurvatures function --- SRC/interpreter/OpenSeesCommands.h | 1 + .../OpenSeesReliabilityCommands.cpp | 55 +++++++++++++++++++ SRC/interpreter/OpenSeesReliabilityCommands.h | 7 ++- SRC/interpreter/PythonWrapper.cpp | 12 ++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/SRC/interpreter/OpenSeesCommands.h b/SRC/interpreter/OpenSeesCommands.h index d14814d799..e8808e7775 100644 --- a/SRC/interpreter/OpenSeesCommands.h +++ b/SRC/interpreter/OpenSeesCommands.h @@ -397,6 +397,7 @@ int OPS_meritFunctionCheck(); int OPS_stepSizeRule(); int OPS_rootFinding(); int OPS_findDesignPoint(); +int OPS_findCurvatures(); int OPS_functionEvaluator(); int OPS_gradientEvaluator(); int OPS_wipeReliability(); diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 42dd94ad11..5a10d112a4 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -111,6 +111,7 @@ OpenSeesReliabilityCommands::OpenSeesReliabilityCommands( theStepSizeRule(0), theRootFinding(0), theFindDesignPointAlgorithm(0), + theFindCurvatures(0), theFunctionEvaluator(0), theGradientEvaluator(0), thePolakHeDualPurpose(0), @@ -179,6 +180,10 @@ void OpenSeesReliabilityCommands::wipe() { delete theFindDesignPointAlgorithm; theFindDesignPointAlgorithm = 0; } + if (theFindCurvatures != 0) { + delete theFindCurvatures; + theFindCurvatures = 0; + } if (theFunctionEvaluator != 0) { delete theFunctionEvaluator; theFunctionEvaluator = 0; @@ -1217,6 +1222,15 @@ void OpenSeesReliabilityCommands::setFindDesignPointAlgorithm( theFindDesignPointAlgorithm = algo; } +void OpenSeesReliabilityCommands::setFindCurvatures( + FindCurvatures *algo) { + if (theFindCurvatures != 0) { + delete theFindCurvatures; + theFindCurvatures = 0; + } + theFindCurvatures = algo; +} + void OpenSeesReliabilityCommands::setGradientEvaluator( GradientEvaluator *eval) { if (theGradientEvaluator != 0) { @@ -1970,6 +1984,47 @@ int OPS_rootFinding() { return 0; } +int OPS_findCurvatures() { + if (OPS_GetNumRemainingInputArgs() < 1) { + opserr << "ERROR: wrong number of arguments to findCurvatures" << endln; + return -1; + } + if (cmds == 0) { + opserr << "WARNING: reliability cmds not defined\n"; + return -1; + } + + // type + const char *type = OPS_GetString(); + + // Check that the necessary ingredients are present + + // + FindCurvatures *theFindCurvatures = 0; + if (strcmp(type, "firstPrincipal") == 0) { + + } + else if (strcmp(type, "bySearchAlgorithm") == 0) { + + } + else if (strcmp(type, "curvatureFitting") == 0) { + + } + else { + opserr << "ERROR: unrecognized type of FindCurvatures strategy" << endln; + return -1; + } + + if (theFindCurvatures == 0) { + opserr << "ERROR: could not create theFindCurvatures" << endln; + return -1; + } + + cmds->setFindCurvatures(theFindCurvatures); + + return 0; +} + int OPS_findDesignPoint() { if (OPS_GetNumRemainingInputArgs() < 1) { opserr << "ERROR: wrong number of arguments to " diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.h b/SRC/interpreter/OpenSeesReliabilityCommands.h index 48ecc0de8a..50ad3a44bb 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.h +++ b/SRC/interpreter/OpenSeesReliabilityCommands.h @@ -54,6 +54,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include #include +#include #include #include #include @@ -116,6 +117,9 @@ class OpenSeesReliabilityCommands { return theFindDesignPointAlgorithm; } + void setFindCurvatures(FindCurvatures *algo); + FindCurvatures *getFindCurvatures() { return theFindCurvatures; } + void setFunctionEvaluator(FunctionEvaluator *eval); FunctionEvaluator *getFunctionEvaluator() { return theFunctionEvaluator; @@ -175,7 +179,8 @@ class OpenSeesReliabilityCommands { StepSizeRule *theStepSizeRule; RootFinding *theRootFinding; FindDesignPointAlgorithm *theFindDesignPointAlgorithm; - + FindCurvatures *theFindCurvatures; + FunctionEvaluator *theFunctionEvaluator; GradientEvaluator *theGradientEvaluator; diff --git a/SRC/interpreter/PythonWrapper.cpp b/SRC/interpreter/PythonWrapper.cpp index 11006b6cab..714ac61a8f 100644 --- a/SRC/interpreter/PythonWrapper.cpp +++ b/SRC/interpreter/PythonWrapper.cpp @@ -2820,6 +2820,18 @@ static PyObject *Py_ops_findDesignPoint(PyObject *self, return wrapper->getResults(); } +static PyObject *Py_ops_findCurvatures(PyObject *self, + PyObject *args) { + wrapper->resetCommandLine(PyTuple_Size(args), 1, args); + + if (OPS_findCurvatures() < 0) { + opserr << (void *)0; + return NULL; + } + + return wrapper->getResults(); +} + static PyObject *Py_ops_runFORMAnalysis(PyObject *self, PyObject *args) { wrapper->resetCommandLine(PyTuple_Size(args), 1, args); From 137bdfb194631db2f8b68cffd84069955843b343 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 14 Mar 2024 16:48:37 -0700 Subject: [PATCH 08/32] Adding findCurvatures options --- .../OpenSeesReliabilityCommands.cpp | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 5a10d112a4..873aea1589 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -91,6 +91,8 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include #include +#include +#include // active object static OpenSeesReliabilityCommands *cmds = 0; @@ -1998,17 +2000,49 @@ int OPS_findCurvatures() { const char *type = OPS_GetString(); // Check that the necessary ingredients are present + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain == 0) { + opserr << "Need theReliabilityDomain before find curvatures" << endln; + return -1; + } + + FunctionEvaluator *theFunctionEvaluator = cmds->getFunctionEvaluator(); + if (theFunctionEvaluator == 0) { + opserr << "Need theFunctionEvaluator before find curvatures" << endln; + return -1; + } + FORMAnalysis *theFORMAnalysis = cmds->getFORMAnalysis(); + if (theFORMAnalysis == 0) { + opserr << "FORMAnalysis must be performed prior to find curvatures" << endln; + return -1; + } + // FindCurvatures *theFindCurvatures = 0; if (strcmp(type, "firstPrincipal") == 0) { - + theFindCurvatures = new FirstPrincipalCurvature(theReliabilityDomain, + theFunctionEvaluator, + theFORMAnalysis); } else if (strcmp(type, "bySearchAlgorithm") == 0) { + int numCurvatures = -1; + int numData = 1; + if (OPS_GetNumRemainingInputArgs() > 0) { + if (OPS_GetIntInput(&numData, &numCurvatures) < 0) { + opserr << "ERROR: unable to read numCurvatures for " << type + << " curvature finding" << endln; + return -1; + } + } + theFindCurvatures = new CurvaturesBySearchAlgorithm(theReliabilityDomain, + theFunctionEvaluator, + theFORMAnalysis, numCurvatures); } else if (strcmp(type, "curvatureFitting") == 0) { - + opserr << "curvatureFitting not in Python interpreter yet, also need to add Hessian" << endln; + return -1; } else { opserr << "ERROR: unrecognized type of FindCurvatures strategy" << endln; From 797525c924ac9ff021445ae8e30a829362e70846 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 14 Mar 2024 16:54:06 -0700 Subject: [PATCH 09/32] Changing analysis objects back to pointers --- .../OpenSeesReliabilityCommands.cpp | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 873aea1589..eb04f0b7df 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -2648,12 +2648,19 @@ int OPS_runFOSMAnalysis() { return -1; } - FOSMAnalysis theFOSMAnalysis( + FOSMAnalysis *theFOSMAnalysis = new FOSMAnalysis( theReliabilityDomain, theStructuralDomain, theFunctionEvaluator, theGradientEvaluator, 0, filename); + if (theFOSMAnalysis == 0) { + opserr << "Unable to create FOSM analysis" << endln; + return -1; + } + + cmds->setFOSMAnalysis(theFOSMAnalysis); + // Now run the analysis - if (theFOSMAnalysis.analyze() < 0) { + if (theFOSMAnalysis->analyze() < 0) { opserr << "WARNING: the FOSM analysis failed\n"; return -1; } @@ -2732,13 +2739,20 @@ int OPS_runFORMAnalysis() { } // Create the analysis object - FORMAnalysis theFORMAnalysis( + FORMAnalysis *theFORMAnalysis = new FORMAnalysis( theReliabilityDomain, theFindDesignPointAlgorithm, theFunctionEvaluator, theProbabilityTransformation, filename, relSensTag); + if (theFORMAnalysis == 0) { + opserr << "Unable to create FORM analysis" << endln; + return -1; + } + + cmds->setFORMAnalysis(theFORMAnalysis); + // Now run the analysis - if (theFORMAnalysis.analyze() < 0) { + if (theFORMAnalysis->analyze() < 0) { opserr << "WARNING: the FORM analysis failed\n"; return -1; } @@ -2914,15 +2928,21 @@ int OPS_runImportanceSamplingAnalysis() { return -1; } - ImportanceSamplingAnalysis theImportanceSamplingAnalysis( + ImportanceSamplingAnalysis *theImportanceSamplingAnalysis + = new ImportanceSamplingAnalysis( theReliabilityDomain, theStructuralDomain, theProbabilityTransformation, theFunctionEvaluator, theRandomNumberGenerator, 0, numberOfSimulations, targetCOV, samplingVariance, printFlag, filename, analysisTypeTag); - //cmds->setImportanceSamplingAnalysis(&theImportanceSamplingAnalysis); + if (theImportanceSamplingAnalysis == 0) { + opserr << "Unable to create ImportanceSampling analysis" << endln; + return -1; + } + + cmds->setImportanceSamplingAnalysis(theImportanceSamplingAnalysis); - if (theImportanceSamplingAnalysis.analyze() < 0) { + if (theImportanceSamplingAnalysis->analyze() < 0) { opserr << "WARNING: failed to run ImportanceSamplingAnalysis\n"; return -1; } From decac4eafc78ff82bb6ba827d51561b601c9a05b Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Fri, 15 Mar 2024 09:56:16 -0700 Subject: [PATCH 10/32] Adding SORM commands to Python --- SRC/interpreter/OpenSeesCommands.h | 1 + .../OpenSeesReliabilityCommands.cpp | 79 +++++++++++++++++++ SRC/interpreter/OpenSeesReliabilityCommands.h | 5 ++ SRC/interpreter/PythonWrapper.cpp | 13 +++ 4 files changed, 98 insertions(+) diff --git a/SRC/interpreter/OpenSeesCommands.h b/SRC/interpreter/OpenSeesCommands.h index e8808e7775..f1e8ca61ea 100644 --- a/SRC/interpreter/OpenSeesCommands.h +++ b/SRC/interpreter/OpenSeesCommands.h @@ -403,6 +403,7 @@ int OPS_gradientEvaluator(); int OPS_wipeReliability(); int OPS_runFOSMAnalysis(); int OPS_runFORMAnalysis(); +int OPS_runSORMAnalysis(); int OPS_runImportanceSamplingAnalysis(); ReliabilityDomain* OPS_GetReliabilityDomain(); diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index eb04f0b7df..9761940b5d 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -120,6 +120,7 @@ OpenSeesReliabilityCommands::OpenSeesReliabilityCommands( theSQPtriplePurpose(0), theFOSMAnalysis(0), theFORMAnalysis(0), + theSORMAnalysis(0), theImportanceSamplingAnalysis(0), theSensAlgo(0) { if (structuralDomain != 0) { @@ -202,6 +203,10 @@ void OpenSeesReliabilityCommands::wipe() { delete theFORMAnalysis; theFORMAnalysis = 0; } + if (theSORMAnalysis != 0) { + delete theSORMAnalysis; + theSORMAnalysis = 0; + } if (theImportanceSamplingAnalysis != 0) { delete theImportanceSamplingAnalysis; theImportanceSamplingAnalysis = 0; @@ -1273,6 +1278,14 @@ void OpenSeesReliabilityCommands::setFORMAnalysis(FORMAnalysis *analysis) { theFORMAnalysis = analysis; } +void OpenSeesReliabilityCommands::setSORMAnalysis(SORMAnalysis *analysis) { + if (theSORMAnalysis != 0) { + delete theSORMAnalysis; + theSORMAnalysis = 0; + } + theSORMAnalysis = analysis; +} + void OpenSeesReliabilityCommands::setImportanceSamplingAnalysis( ImportanceSamplingAnalysis *analysis) { if (theImportanceSamplingAnalysis != 0) { @@ -2760,6 +2773,72 @@ int OPS_runFORMAnalysis() { return 0; } +int OPS_runSORMAnalysis() { + if (OPS_GetNumRemainingInputArgs() < 1) { + opserr << "WARNING: Wrong number of input parameter to SORM " + << "analysis" << endln;; + return -1; + } + + // get file name + const char *filename = OPS_GetString(); + + // Do input check + if (inputCheck() < 0) { + return -1; + } + + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain == 0) { + opserr << "FORMAnalysis -- ReliabilityDomain is not defined" << endln; + return -1; + } + + // Check for essential ingredients + FindCurvatures *theFindCurvatures = cmds->getFindCurvatures(); + if (theFindCurvatures == 0) { + opserr << "Need FindCurvature approach before a SORMAnalysis can " + << "be created" << endln; + return -1; + } + + FORMAnalysis *theFORMAnalysis = + cmds->getFORMAnalysis(); + if (theFORMAnalysis == 0) { + opserr << "Need to run a FORM analysis before " + << "SORMAnalysis can be created" << endln; + return -1; + } + + // Check for essential ingredients + FunctionEvaluator *theFunctionEvaluator = cmds->getFunctionEvaluator(); + if (theFunctionEvaluator == 0) { + opserr << "Need theGFunEvaluator before a SORMAnalysis can " + << "be created" << endln; + return -1; + } + + // Create the analysis object + SORMAnalysis *theSORMAnalysis = new SORMAnalysis( + theReliabilityDomain, theFunctionEvaluator, + theFORMAnalysis, theFindCurvatures, filename); + + if (theSORMAnalysis == 0) { + opserr << "Unable to create SORM analysis" << endln; + return -1; + } + + cmds->setSORMAnalysis(theSORMAnalysis); + + // Now run the analysis + if (theSORMAnalysis->analyze() < 0) { + opserr << "WARNING: the SORM analysis failed\n"; + return -1; + } + + return 0; +} + int OPS_runImportanceSamplingAnalysis() { if (cmds == 0) { return -1; diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.h b/SRC/interpreter/OpenSeesReliabilityCommands.h index 50ad3a44bb..3283e40ebc 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.h +++ b/SRC/interpreter/OpenSeesReliabilityCommands.h @@ -52,6 +52,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include +#include #include #include #include @@ -154,6 +155,9 @@ class OpenSeesReliabilityCommands { void setFORMAnalysis(FORMAnalysis *analysis); FORMAnalysis *getFORMAnalysis() { return theFORMAnalysis; } + void setSORMAnalysis(SORMAnalysis *analysis); + SORMAnalysis *getSORMAnalysis() { return theSORMAnalysis; } + void setImportanceSamplingAnalysis( ImportanceSamplingAnalysis *analysis); ImportanceSamplingAnalysis *getImportanceSamplingAnalysis() { @@ -191,6 +195,7 @@ class OpenSeesReliabilityCommands { // analysis FOSMAnalysis *theFOSMAnalysis; FORMAnalysis *theFORMAnalysis; + SORMAnalysis *theSORMAnalysis; ImportanceSamplingAnalysis *theImportanceSamplingAnalysis; // sensitivity algorithm diff --git a/SRC/interpreter/PythonWrapper.cpp b/SRC/interpreter/PythonWrapper.cpp index 714ac61a8f..b2bd51c688 100644 --- a/SRC/interpreter/PythonWrapper.cpp +++ b/SRC/interpreter/PythonWrapper.cpp @@ -2843,6 +2843,17 @@ static PyObject *Py_ops_runFORMAnalysis(PyObject *self, PyObject *args) { return wrapper->getResults(); } +static PyObject *Py_ops_runSORMAnalysis(PyObject *self, PyObject *args) { + wrapper->resetCommandLine(PyTuple_Size(args), 1, args); + + if (OPS_runSORMAnalysis() < 0) { + opserr << (void *)0; + return NULL; + } + + return wrapper->getResults(); +} + static PyObject *Py_ops_getLSFTags(PyObject *self, PyObject *args) { wrapper->resetCommandLine(PyTuple_Size(args), 1, args); @@ -3111,7 +3122,9 @@ PythonWrapper::addOpenSeesCommands() addCommand("domainCommitTag", &Py_ops_domainCommitTag); addCommand("runFOSMAnalysis", &Py_ops_runFOSMAnalysis); addCommand("findDesignPoint", &Py_ops_findDesignPoint); + addCommand("findCurvatures", &Py_ops_findCurvatures); addCommand("runFORMAnalysis", &Py_ops_runFORMAnalysis); + addCommand("runSORMAnalysis", &Py_ops_runSORMAnalysis); addCommand("getLSFTags", &Py_ops_getLSFTags); addCommand("runImportanceSamplingAnalysis", &Py_ops_runImportanceSamplingAnalysis); addCommand("IGA", &Py_ops_IGA); From 467fe45743c2d2011f828a8321fff7c29421bb87 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Fri, 15 Mar 2024 11:34:18 -0700 Subject: [PATCH 11/32] Adding filter command to Python interpreter --- SRC/interpreter/OpenSeesCommands.h | 1 + .../OpenSeesReliabilityCommands.cpp | 68 +++++++++++++++++++ SRC/interpreter/PythonWrapper.cpp | 13 ++++ 3 files changed, 82 insertions(+) diff --git a/SRC/interpreter/OpenSeesCommands.h b/SRC/interpreter/OpenSeesCommands.h index f1e8ca61ea..f933ca934b 100644 --- a/SRC/interpreter/OpenSeesCommands.h +++ b/SRC/interpreter/OpenSeesCommands.h @@ -375,6 +375,7 @@ int OPS_partition(); // OpenSeesReliabilityCommands.cpp int OPS_randomVariable(); +int OPS_filter(); int OPS_getRVTags(); int OPS_getRVParamTag(); int OPS_getRVValue(); diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 9761940b5d..2de8aae2dd 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -74,6 +74,11 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #endif +#include +#include +#include +#include + #include #include #include @@ -338,6 +343,69 @@ int OPS_gradPerformanceFunction() { return 0; } +int OPS_filter() { + Filter *theFilter = 0; + int tag; + double period_Tn, damping, dtpulse; + + if (OPS_GetNumRemainingInputArgs() < 3) { + opserr << "ERROR: Invalid number of arguments to filter " + "command: filter tag type arg1 arg2 ..." << endln; + return -1; + } + + int numdata = 1; + if (OPS_GetIntInput(&numdata, &tag) < 0) { + opserr << "ERROR: invalid tag for filter commands" << endln; + return -1; + } + + const char *type = OPS_GetString(); + if (strcmp(type,"standard") == 0 || strcmp(type,"Koo") == 0 || + strcmp(type,"standardDisplacement") == 0 || + strcmp(type,"standardVelocity") == 0 || + strcmp(type,"standardAcceleration") == 0) { + + if (OPS_GetDoubleInput(&numdata, &period_Tn) < 0) { + opserr << "ERROR: invalid period for filter" << endln; + return -1; + } + if (OPS_GetDoubleInput(&numdata, &damping) < 0) { + opserr << "ERROR: invalid damping for filter" << endln; + return -1; + } + + if (strcmp(type,"standard") == 0 || strcmp(type,"standardDisplacement") == 0) + theFilter = new StandardLinearOscillatorDisplacementFilter(tag, period_Tn, damping); + if (strcmp(type,"standardVelocity") == 0) + theFilter = new StandardLinearOscillatorVelocityFilter(tag, period_Tn, damping); + if (strcmp(type,"standardAcceleration") == 0) + theFilter = new StandardLinearOscillatorAccelerationFilter(tag, period_Tn, damping); + if (strcmp(type,"Koo") == 0) + theFilter = new KooFilter(tag, period_Tn, damping); + } + else { + opserr << "Unknown filter type: " << type << endln; + return -1; + } + + if (theFilter == 0) { + opserr << "ERROR: ran out of memory creating filter \n"; + opserr << type << ' ' << tag << endln; + return -1; + } + + // ADD THE OBJECT TO THE DOMAIN + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain->addFilter(theFilter) == false) { + opserr << "ERROR: failed to add filter to the domain\n"; + opserr << type << ' ' << tag << endln; + delete theFilter; // otherwise memory leak + return -1; + } + + return 0; +} int OPS_randomVariable() { RandomVariable *theRandomVariable = 0; diff --git a/SRC/interpreter/PythonWrapper.cpp b/SRC/interpreter/PythonWrapper.cpp index b2bd51c688..c2b720d002 100644 --- a/SRC/interpreter/PythonWrapper.cpp +++ b/SRC/interpreter/PythonWrapper.cpp @@ -2381,6 +2381,18 @@ static PyObject *Py_ops_randomVariable(PyObject *self, PyObject *args) return wrapper->getResults(); } +static PyObject *Py_ops_filter(PyObject *self, PyObject *args) +{ + wrapper->resetCommandLine(PyTuple_Size(args), 1, args); + + if (OPS_filter() < 0) { + opserr<<(void*)0; + return NULL; + } + + return wrapper->getResults(); +} + static PyObject *Py_ops_getRVTags(PyObject *self, PyObject *args) { wrapper->resetCommandLine(PyTuple_Size(args), 1, args); @@ -3083,6 +3095,7 @@ PythonWrapper::addOpenSeesCommands() addCommand("getNodeLoadTags", &Py_ops_getNodeLoadTags); addCommand("getNodeLoadData", &Py_ops_getNodeLoadData); addCommand("randomVariable", &Py_ops_randomVariable); + addCommand("filter", &Py_ops_filter); addCommand("getRVTags", &Py_ops_getRVTags); addCommand("getRVParamTag", &Py_ops_getRVParamTag); addCommand("getRVValue", &Py_ops_getRVValue); From 181c62befc27f1632c8603af6d1eb56e0804be4c Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Fri, 15 Mar 2024 12:16:56 -0700 Subject: [PATCH 12/32] Adding modulating functions to Python interpreter --- SRC/interpreter/OpenSeesCommands.h | 1 + .../OpenSeesReliabilityCommands.cpp | 169 +++++++++++++++++- SRC/interpreter/PythonWrapper.cpp | 13 ++ 3 files changed, 181 insertions(+), 2 deletions(-) diff --git a/SRC/interpreter/OpenSeesCommands.h b/SRC/interpreter/OpenSeesCommands.h index f933ca934b..c9aedccfd6 100644 --- a/SRC/interpreter/OpenSeesCommands.h +++ b/SRC/interpreter/OpenSeesCommands.h @@ -376,6 +376,7 @@ int OPS_partition(); // OpenSeesReliabilityCommands.cpp int OPS_randomVariable(); int OPS_filter(); +int OPS_modulatingFunction(); int OPS_getRVTags(); int OPS_getRVParamTag(); int OPS_getRVValue(); diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 2de8aae2dd..a6c3eada8d 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -78,6 +78,10 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include #include +#include +#include +#include +#include #include #include @@ -343,10 +347,11 @@ int OPS_gradPerformanceFunction() { return 0; } + int OPS_filter() { Filter *theFilter = 0; int tag; - double period_Tn, damping, dtpulse; + double period_Tn, damping;//, dtpulse; if (OPS_GetNumRemainingInputArgs() < 3) { opserr << "ERROR: Invalid number of arguments to filter " @@ -356,7 +361,7 @@ int OPS_filter() { int numdata = 1; if (OPS_GetIntInput(&numdata, &tag) < 0) { - opserr << "ERROR: invalid tag for filter commands" << endln; + opserr << "ERROR: invalid tag for filter command" << endln; return -1; } @@ -407,6 +412,166 @@ int OPS_filter() { return 0; } +int OPS_modulatingFunction() { + ModulatingFunction *theModulatingFunction = 0; + int tag; + + if (OPS_GetNumRemainingInputArgs() < 3) { + opserr << "ERROR: Invalid number of arguments to modulating function " + "command: modulatingFunction tag type arg1 arg2 ..." << endln; + return -1; + } + + int numdata = 1; + if (OPS_GetIntInput(&numdata, &tag) < 0) { + opserr << "ERROR: invalid tag for modulatingFunction command" << endln; + return -1; + } + + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + + const char *type = OPS_GetString(); + if (strcmp(type,"gamma") == 0) { + + if (OPS_GetNumRemainingInputArgs() < 4) { + opserr << "ERROR: insufficient input for gamma modulatingFunction" << endln; + return -1; + } + + int filterTag; + double abc[3]; + if (OPS_GetIntInput(&numdata, &filterTag) < 0) { + opserr << "ERROR: invalid filter tag for modulating function" << endln; + return -1; + } + + Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + if (theFilter == 0) { + opserr << "ERROR: could not find filter with tag " << filterTag + << " for modulating function" << endln; + return -1; + } + + numdata = 3; + if (OPS_GetDoubleInput(&numdata, abc) < 0) { + opserr << "ERROR: invalid double data for modulating function" << endln; + return -1; + } + + theModulatingFunction = new GammaModulatingFunction(tag, theFilter, + abc[0], abc[1], abc[2]); + } + else if (strcmp(type,"constant") == 0) { + + if (OPS_GetNumRemainingInputArgs() < 2) { + opserr << "ERROR: insufficient input for constant modulatingFunction" << endln; + return -1; + } + + int filterTag; + double amplitude; + if (OPS_GetIntInput(&numdata, &filterTag) < 0) { + opserr << "ERROR: invalid filter tag for modulating function" << endln; + return -1; + } + + Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + if (theFilter == 0) { + opserr << "ERROR: could not find filter with tag " << filterTag + << " for modulating function" << endln; + return -1; + } + + numdata = 1; + if (OPS_GetDoubleInput(&numdata, &litude) < 0) { + opserr << "ERROR: invalid amplitude for modulating function" << endln; + return -1; + } + + theModulatingFunction = new ConstantModulatingFunction(tag, theFilter, amplitude); + } + else if (strcmp(type,"trapezoidal") == 0) { + + if (OPS_GetNumRemainingInputArgs() < 6) { + opserr << "ERROR: insufficient input for trapezoidal modulatingFunction" << endln; + return -1; + } + + int filterTag; + double ddata[5]; + if (OPS_GetIntInput(&numdata, &filterTag) < 0) { + opserr << "ERROR: invalid filter tag for modulating function" << endln; + return -1; + } + + Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + if (theFilter == 0) { + opserr << "ERROR: could not find filter with tag " << filterTag + << " for modulating function" << endln; + return -1; + } + + numdata = 5; + if (OPS_GetDoubleInput(&numdata, ddata) < 0) { + opserr << "ERROR: invalid double data for modulating function" << endln; + return -1; + } + + theModulatingFunction = new TrapezoidalModulatingFunction(tag, theFilter, + ddata[0], ddata[1], ddata[2], + ddata[3], ddata[4]); + } + else if (strcmp(type,"Koo") == 0) { + + if (OPS_GetNumRemainingInputArgs() < 3) { + opserr << "ERROR: insufficient input for Koo modulatingFunction" << endln; + return -1; + } + + int filterTag; + double ddata[2]; + if (OPS_GetIntInput(&numdata, &filterTag) < 0) { + opserr << "ERROR: invalid filter tag for modulating function" << endln; + return -1; + } + + Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + if (theFilter == 0) { + opserr << "ERROR: could not find filter with tag " << filterTag + << " for modulating function" << endln; + return -1; + } + + numdata = 2; + if (OPS_GetDoubleInput(&numdata, ddata) < 0) { + opserr << "ERROR: invalid double data for modulating function" << endln; + return -1; + } + + theModulatingFunction = new KooModulatingFunction(tag, theFilter, ddata[0], ddata[1]); + } + else { + opserr << "Unknown modulatingFunction type: " << type << endln; + return -1; + } + + if (theModulatingFunction == 0) { + opserr << "ERROR: ran out of memory creating modulating function \n"; + opserr << type << ' ' << tag << endln; + return -1; + } + + // ADD THE OBJECT TO THE DOMAIN + if (theReliabilityDomain->addModulatingFunction(theModulatingFunction) == false) { + opserr << "ERROR: failed to add modulating function to the domain\n"; + opserr << type << ' ' << tag << endln; + delete theModulatingFunction; // otherwise memory leak + return -1; + } + + return 0; +} + int OPS_randomVariable() { RandomVariable *theRandomVariable = 0; int tag; diff --git a/SRC/interpreter/PythonWrapper.cpp b/SRC/interpreter/PythonWrapper.cpp index c2b720d002..07d05356f7 100644 --- a/SRC/interpreter/PythonWrapper.cpp +++ b/SRC/interpreter/PythonWrapper.cpp @@ -2393,6 +2393,18 @@ static PyObject *Py_ops_filter(PyObject *self, PyObject *args) return wrapper->getResults(); } +static PyObject *Py_ops_modulatingFunction(PyObject *self, PyObject *args) +{ + wrapper->resetCommandLine(PyTuple_Size(args), 1, args); + + if (OPS_modulatingFunction() < 0) { + opserr<<(void*)0; + return NULL; + } + + return wrapper->getResults(); +} + static PyObject *Py_ops_getRVTags(PyObject *self, PyObject *args) { wrapper->resetCommandLine(PyTuple_Size(args), 1, args); @@ -3096,6 +3108,7 @@ PythonWrapper::addOpenSeesCommands() addCommand("getNodeLoadData", &Py_ops_getNodeLoadData); addCommand("randomVariable", &Py_ops_randomVariable); addCommand("filter", &Py_ops_filter); + addCommand("modulatingFunction", &Py_ops_modulatingFunction); addCommand("getRVTags", &Py_ops_getRVTags); addCommand("getRVParamTag", &Py_ops_getRVParamTag); addCommand("getRVValue", &Py_ops_getRVValue); From dea8076136944d4118a8ad75111a120ca9c7ad54 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Sat, 16 Mar 2024 07:06:40 -0700 Subject: [PATCH 13/32] Adding storage for filters with non-sequential tags --- .../domain/components/ReliabilityDomain.cpp | 106 +++++++++++++++++- .../domain/components/ReliabilityDomain.h | 11 ++ 2 files changed, 114 insertions(+), 3 deletions(-) diff --git a/SRC/reliability/domain/components/ReliabilityDomain.cpp b/SRC/reliability/domain/components/ReliabilityDomain.cpp index ca15bfbdd1..ed20a4bc06 100644 --- a/SRC/reliability/domain/components/ReliabilityDomain.cpp +++ b/SRC/reliability/domain/components/ReliabilityDomain.cpp @@ -90,6 +90,9 @@ ReliabilityDomain::ReliabilityDomain(Domain *passedDomain): cutsetIndex = new int[cutsetSize_init]; cutsetSize = cutsetSize_init; + + filterIndex = new int[filterSize_init]; + filterSize = filterSize_init; } void @@ -114,8 +117,10 @@ ReliabilityDomain::clearAll() theModulatingFunctionsPtr->clearAll(); if (theSpectraPtr != 0) theSpectraPtr->clearAll(); - if (theFiltersPtr != 0) + if (theFiltersPtr != 0) { theFiltersPtr->clearAll(); + numFilters = 0; + } if (theDesignVariablesPtr != 0) theDesignVariablesPtr->clearAll(); @@ -196,6 +201,8 @@ ReliabilityDomain::~ReliabilityDomain() delete [] lsfIndex; if (cutsetIndex != 0) delete [] cutsetIndex; + if (filterIndex != 0) + delete [] filterIndex; } @@ -323,8 +330,34 @@ ReliabilityDomain::addSpectrum(Spectrum *theSpectrum) bool ReliabilityDomain::addFilter(Filter *theFilter) { - bool result = theFiltersPtr->addComponent(theFilter); - return result; + bool result = theFiltersPtr->addComponent(theFilter); + + if (result == true) { + + // Array is full + if (numFilters == filterSize) { + + // Increase size and allocate new array + filterSize += filterSize_grow; + int *tmp_filterIndex = new int[filterSize]; + + // Copy values from old array to new + for (int i = 0; i < numFilters; i++) + tmp_filterIndex[i] = filterIndex[i]; + + // Get rid of old array + delete [] filterIndex; + + // Set pointer to new array + filterIndex = tmp_filterIndex; + } + + // Add to index + filterIndex[numFilters] = theFilter->getTag(); + numFilters++; + } + + return result; } @@ -600,6 +633,48 @@ ReliabilityDomain::getCutsetIndex(int tag) return index; } +Filter * +ReliabilityDomain::getFilterPtr(int tag) +{ + TaggedObject *theComponent = theFiltersPtr->getComponentPtr(tag); + if ( theComponent == 0 ) + return 0; + Filter *result = (Filter *) theComponent; + return result; +} + +Filter * +ReliabilityDomain::getFilterPtrFromIndex(int index) +{ + if (index >= 0 && index < numFilters) + return this->getFilterPtr(filterIndex[index]); + + else { + opserr << "ReliabilityDomain::getFilterPtrFromIndex -- index " << index << " out of bounds 0 ... " << numFilters-1 << endln; + return 0; + } + +} + +int +ReliabilityDomain::getFilterIndex(int tag) +{ + int index; + + // Find index of cutset with specified tag + for (index = 0; index < numFilters; index++) { + if (filterIndex[index] == tag) + break; + } + + if (index == numFilters) { + opserr << "ReliabilityDomain::getFilterIndex -- filter with tag " << tag << " not found" << endln; + return -1; + } + + return index; +} + ModulatingFunction * ReliabilityDomain::getModulatingFunction(int tag) @@ -762,6 +837,31 @@ ReliabilityDomain::removeCutset(int tag) return 0; } +int +ReliabilityDomain::removeFilter(int tag) +{ + Filter *theFilter = (Filter*) theFiltersPtr->getComponentPtr(tag); + + if (theFilter != 0) { + + // Find where filter is located + int index; + for (index = 0; index < numFilters; index++) { + if (filterIndex[index] == tag) + break; + } + + // Shift indices down by one + for (int i = index; i < numFilters-1; i++) + filterIndex[i] = filterIndex[i+1]; + + // Now remove the component + theFiltersPtr->removeComponent(tag); + numFilters--; + } + + return 0; +} //-Quan diff --git a/SRC/reliability/domain/components/ReliabilityDomain.h b/SRC/reliability/domain/components/ReliabilityDomain.h index 1336cc0aa5..e859341f21 100644 --- a/SRC/reliability/domain/components/ReliabilityDomain.h +++ b/SRC/reliability/domain/components/ReliabilityDomain.h @@ -105,6 +105,11 @@ class ReliabilityDomain Cutset *getCutsetPtrFromIndex(int index); int getCutsetIndex(int tag); + Filter *getFilterPtr(int tag); + // Following two methods to map index to tag and vice versa + Filter *getFilterPtrFromIndex(int index); + int getFilterIndex(int tag); + CorrelationCoefficient *getCorrelationCoefficientPtr(int tag); ModulatingFunction *getModulatingFunction(int tag); Filter *getFilter(int tag); @@ -209,6 +214,12 @@ class ReliabilityDomain enum {cutsetSize_grow = 2}; int cutsetSize; int numCutsets; + + int *filterIndex; + enum {filterSize_init = 10}; + enum {filterSize_grow = 2}; + int filterSize; + int numFilters; }; #endif From b628a4a96fa4be6a50213009727967e47c88afad Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Sat, 16 Mar 2024 07:32:02 -0700 Subject: [PATCH 14/32] Adding storage for non-sequential mod function tags --- .../domain/components/ReliabilityDomain.cpp | 114 +++++++++++++++++- .../domain/components/ReliabilityDomain.h | 13 +- 2 files changed, 120 insertions(+), 7 deletions(-) diff --git a/SRC/reliability/domain/components/ReliabilityDomain.cpp b/SRC/reliability/domain/components/ReliabilityDomain.cpp index ed20a4bc06..642bdf4a0d 100644 --- a/SRC/reliability/domain/components/ReliabilityDomain.cpp +++ b/SRC/reliability/domain/components/ReliabilityDomain.cpp @@ -56,7 +56,8 @@ ReliabilityDomain::ReliabilityDomain(Domain *passedDomain): theOpenSeesDomain(passedDomain), - numRandomVariables(0), numLimitStateFunctions(0), numCutsets(0) + numRandomVariables(0), numLimitStateFunctions(0), numCutsets(0), + numFilters(0), numModulatingFunctions(0) { theRandomVariablesPtr = new ArrayOfTaggedObjects (256); @@ -92,7 +93,10 @@ ReliabilityDomain::ReliabilityDomain(Domain *passedDomain): cutsetSize = cutsetSize_init; filterIndex = new int[filterSize_init]; - filterSize = filterSize_init; + filterSize = filterSize_init; + + modFcnIndex = new int[modFcnSize_init]; + modFcnSize = modFcnSize_init; } void @@ -113,8 +117,10 @@ ReliabilityDomain::clearAll() if (theCorrelationCoefficientsPtr != 0) theCorrelationCoefficientsPtr->clearAll(); - if (theModulatingFunctionsPtr != 0) + if (theModulatingFunctionsPtr != 0) { theModulatingFunctionsPtr->clearAll(); + numModulatingFunctions = 0; + } if (theSpectraPtr != 0) theSpectraPtr->clearAll(); if (theFiltersPtr != 0) { @@ -202,7 +208,9 @@ ReliabilityDomain::~ReliabilityDomain() if (cutsetIndex != 0) delete [] cutsetIndex; if (filterIndex != 0) - delete [] filterIndex; + delete [] filterIndex; + if (modFcnIndex != 0) + delete [] modFcnIndex; } @@ -316,8 +324,34 @@ ReliabilityDomain::addCutset(Cutset *theCutset) bool ReliabilityDomain::addModulatingFunction(ModulatingFunction *theModulatingFunction) { - bool result = theModulatingFunctionsPtr->addComponent(theModulatingFunction); - return result; + bool result = theModulatingFunctionsPtr->addComponent(theModulatingFunction); + + if (result == true) { + + // Array is full + if (numModulatingFunctions == modFcnSize) { + + // Increase size and allocate new array + modFcnSize += modFcnSize_grow; + int *tmp_modFcnIndex = new int[modFcnSize]; + + // Copy values from old array to new + for (int i = 0; i < numModulatingFunctions; i++) + tmp_modFcnIndex[i] = modFcnIndex[i]; + + // Get rid of old array + delete [] modFcnIndex; + + // Set pointer to new array + modFcnIndex = tmp_modFcnIndex; + } + + // Add to index + modFcnIndex[numModulatingFunctions] = theModulatingFunction->getTag(); + numModulatingFunctions++; + } + + return result; } bool @@ -675,6 +709,48 @@ ReliabilityDomain::getFilterIndex(int tag) return index; } +ModulatingFunction * +ReliabilityDomain::getModulatingFunctionPtr(int tag) +{ + TaggedObject *theComponent = theModulatingFunctionsPtr->getComponentPtr(tag); + if ( theComponent == 0 ) + return 0; + ModulatingFunction *result = (ModulatingFunction *) theComponent; + return result; +} + +ModulatingFunction * +ReliabilityDomain::getModulatingFunctionPtrFromIndex(int index) +{ + if (index >= 0 && index < numModulatingFunctions) + return this->getModulatingFunctionPtr(modFcnIndex[index]); + + else { + opserr << "ReliabilityDomain::getModulatintFunctionPtrFromIndex -- index " << index << " out of bounds 0 ... " << numModulatingFunctions-1 << endln; + return 0; + } + +} + +int +ReliabilityDomain::getModulatingFunctionIndex(int tag) +{ + int index; + + // Find index of cutset with specified tag + for (index = 0; index < numModulatingFunctions; index++) { + if (modFcnIndex[index] == tag) + break; + } + + if (index == numModulatingFunctions) { + opserr << "ReliabilityDomain::getModulatingFunctionIndex -- modulating function with tag " << tag << " not found" << endln; + return -1; + } + + return index; +} + ModulatingFunction * ReliabilityDomain::getModulatingFunction(int tag) @@ -863,6 +939,32 @@ ReliabilityDomain::removeFilter(int tag) return 0; } +int +ReliabilityDomain::removeModulatingFunction(int tag) +{ + ModulatingFunction *theModFcn = (ModulatingFunction*) theModulatingFunctionsPtr->getComponentPtr(tag); + + if (theModFcn != 0) { + + // Find where filter is located + int index; + for (index = 0; index < numModulatingFunctions; index++) { + if (modFcnIndex[index] == tag) + break; + } + + // Shift indices down by one + for (int i = index; i < numModulatingFunctions-1; i++) + modFcnIndex[i] = modFcnIndex[i+1]; + + // Now remove the component + theModulatingFunctionsPtr->removeComponent(tag); + numModulatingFunctions--; + } + + return 0; +} + //-Quan int diff --git a/SRC/reliability/domain/components/ReliabilityDomain.h b/SRC/reliability/domain/components/ReliabilityDomain.h index e859341f21..cea9915ee0 100644 --- a/SRC/reliability/domain/components/ReliabilityDomain.h +++ b/SRC/reliability/domain/components/ReliabilityDomain.h @@ -110,6 +110,11 @@ class ReliabilityDomain Filter *getFilterPtrFromIndex(int index); int getFilterIndex(int tag); + ModulatingFunction *getModulatingFunctionPtr(int tag); + // Following two methods to map index to tag and vice versa + ModulatingFunction *getModulatingFunctionPtrFromIndex(int index); + int getModulatingFunctionIndex(int tag); + CorrelationCoefficient *getCorrelationCoefficientPtr(int tag); ModulatingFunction *getModulatingFunction(int tag); Filter *getFilter(int tag); @@ -219,7 +224,13 @@ class ReliabilityDomain enum {filterSize_init = 10}; enum {filterSize_grow = 2}; int filterSize; - int numFilters; + int numFilters; + + int *modFcnIndex; + enum {modFcnSize_init = 10}; + enum {modFcnSize_grow = 2}; + int modFcnSize; + int numModulatingFunctions; }; #endif From 0412b14f003b49e66a2b49746a87197f9aca3fe8 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Sat, 16 Mar 2024 09:00:53 -0700 Subject: [PATCH 15/32] Adding storage for non-sequetial spectra tags --- .../domain/components/ReliabilityDomain.cpp | 88 +++++++++++++++++-- .../domain/components/ReliabilityDomain.h | 13 ++- 2 files changed, 93 insertions(+), 8 deletions(-) diff --git a/SRC/reliability/domain/components/ReliabilityDomain.cpp b/SRC/reliability/domain/components/ReliabilityDomain.cpp index 642bdf4a0d..fe33ab45c2 100644 --- a/SRC/reliability/domain/components/ReliabilityDomain.cpp +++ b/SRC/reliability/domain/components/ReliabilityDomain.cpp @@ -57,7 +57,7 @@ ReliabilityDomain::ReliabilityDomain(Domain *passedDomain): theOpenSeesDomain(passedDomain), numRandomVariables(0), numLimitStateFunctions(0), numCutsets(0), - numFilters(0), numModulatingFunctions(0) + numFilters(0), numModulatingFunctions(0), numSpectra(0) { theRandomVariablesPtr = new ArrayOfTaggedObjects (256); @@ -96,7 +96,10 @@ ReliabilityDomain::ReliabilityDomain(Domain *passedDomain): filterSize = filterSize_init; modFcnIndex = new int[modFcnSize_init]; - modFcnSize = modFcnSize_init; + modFcnSize = modFcnSize_init; + + spectraIndex = new int[spectraSize_init]; + spectraSize = spectraSize_init; } void @@ -121,8 +124,10 @@ ReliabilityDomain::clearAll() theModulatingFunctionsPtr->clearAll(); numModulatingFunctions = 0; } - if (theSpectraPtr != 0) + if (theSpectraPtr != 0) { theSpectraPtr->clearAll(); + numSpectra = 0; + } if (theFiltersPtr != 0) { theFiltersPtr->clearAll(); numFilters = 0; @@ -210,7 +215,9 @@ ReliabilityDomain::~ReliabilityDomain() if (filterIndex != 0) delete [] filterIndex; if (modFcnIndex != 0) - delete [] modFcnIndex; + delete [] modFcnIndex; + if (spectraIndex != 0) + delete [] spectraIndex; } @@ -357,8 +364,35 @@ ReliabilityDomain::addModulatingFunction(ModulatingFunction *theModulatingFuncti bool ReliabilityDomain::addSpectrum(Spectrum *theSpectrum) { - bool result = theSpectraPtr->addComponent(theSpectrum); - return result; + bool result = theSpectraPtr->addComponent(theSpectrum); + + if (result == true) { + + // Array is full + if (numSpectra == spectraSize) { + + // Increase size and allocate new array + spectraSize += spectraSize_grow; + int *tmp_spectraIndex = new int[spectraSize]; + + // Copy values from old array to new + for (int i = 0; i < numSpectra; i++) + tmp_spectraIndex[i] = spectraIndex[i]; + + // Get rid of old array + delete [] spectraIndex; + + // Set pointer to new array + spectraIndex = tmp_spectraIndex; + } + + // Add to index + spectraIndex[numSpectra] = theSpectrum->getTag(); + numSpectra++; + } + + + return result; } bool @@ -751,7 +785,6 @@ ReliabilityDomain::getModulatingFunctionIndex(int tag) return index; } - ModulatingFunction * ReliabilityDomain::getModulatingFunction(int tag) { @@ -762,6 +795,47 @@ ReliabilityDomain::getModulatingFunction(int tag) return result; } +Spectrum * +ReliabilityDomain::getSpectrumPtr(int tag) +{ + TaggedObject *theComponent = theSpectraPtr->getComponentPtr(tag); + if ( theComponent == 0 ) + return 0; + Spectrum *result = (Spectrum *) theComponent; + return result; +} + +Spectrum * +ReliabilityDomain::getSpectrumPtrFromIndex(int index) +{ + if (index >= 0 && index < numSpectra) + return this->getSpectrumPtr(spectraIndex[index]); + + else { + opserr << "ReliabilityDomain::getSpectrumPtrFromIndex -- index " << index << " out of bounds 0 ... " << numSpectra-1 << endln; + return 0; + } + +} + +int +ReliabilityDomain::getSpectrumIndex(int tag) +{ + int index; + + // Find index of cutset with specified tag + for (index = 0; index < numSpectra; index++) { + if (spectraIndex[index] == tag) + break; + } + + if (index == numSpectra) { + opserr << "ReliabilityDomain::getSpectrumIndex -- spectrum with tag " << tag << " not found" << endln; + return -1; + } + + return index; +} Spectrum * ReliabilityDomain::getSpectrum(int tag) diff --git a/SRC/reliability/domain/components/ReliabilityDomain.h b/SRC/reliability/domain/components/ReliabilityDomain.h index cea9915ee0..a012ffdb87 100644 --- a/SRC/reliability/domain/components/ReliabilityDomain.h +++ b/SRC/reliability/domain/components/ReliabilityDomain.h @@ -115,6 +115,11 @@ class ReliabilityDomain ModulatingFunction *getModulatingFunctionPtrFromIndex(int index); int getModulatingFunctionIndex(int tag); + Spectrum *getSpectrumPtr(int tag); + // Following two methods to map index to tag and vice versa + Spectrum *getSpectrumPtrFromIndex(int index); + int getSpectrumIndex(int tag); + CorrelationCoefficient *getCorrelationCoefficientPtr(int tag); ModulatingFunction *getModulatingFunction(int tag); Filter *getFilter(int tag); @@ -230,7 +235,13 @@ class ReliabilityDomain enum {modFcnSize_init = 10}; enum {modFcnSize_grow = 2}; int modFcnSize; - int numModulatingFunctions; + int numModulatingFunctions; + + int *spectraIndex; + enum {spectraSize_init = 10}; + enum {spectraSize_grow = 2}; + int spectraSize; + int numSpectra; }; #endif From 1918d2125d75d27c173972c09dec4d4608b57d21 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Sat, 16 Mar 2024 12:58:49 -0700 Subject: [PATCH 16/32] Adding spectrum command to Python interpreter --- SRC/interpreter/OpenSeesCommands.h | 1 + .../OpenSeesReliabilityCommands.cpp | 92 +++++++++++++++++-- SRC/interpreter/PythonWrapper.cpp | 13 +++ 3 files changed, 99 insertions(+), 7 deletions(-) diff --git a/SRC/interpreter/OpenSeesCommands.h b/SRC/interpreter/OpenSeesCommands.h index c9aedccfd6..237a2cd101 100644 --- a/SRC/interpreter/OpenSeesCommands.h +++ b/SRC/interpreter/OpenSeesCommands.h @@ -376,6 +376,7 @@ int OPS_partition(); // OpenSeesReliabilityCommands.cpp int OPS_randomVariable(); int OPS_filter(); +int OPS_spectrum(); int OPS_modulatingFunction(); int OPS_getRVTags(); int OPS_getRVParamTag(); diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index a6c3eada8d..2d20bab38d 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -82,6 +82,8 @@ MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include #include +#include +#include #include #include @@ -412,6 +414,78 @@ int OPS_filter() { return 0; } +int OPS_spectrum() { + Spectrum *theSpectrum = 0; + int tag; + + if (OPS_GetNumRemainingInputArgs() < 3) { + opserr << "ERROR: Invalid number of arguments to spectrum " + "command: spectrum tag type arg1 arg2 ..." << endln; + return -1; + } + + int numdata = 1; + if (OPS_GetIntInput(&numdata, &tag) < 0) { + opserr << "ERROR: invalid tag for spectrum command" << endln; + return -1; + } + + const char *type = OPS_GetString(); + if (strcmp(type,"jonswap") == 0) { + if (OPS_GetNumRemainingInputArgs() < 5) { + opserr << "ERROR: insufficient arguments for jonswap spectrum" << endln; + return -1; + } + double data[5]; + numdata = 5; + if (OPS_GetDoubleInput(&numdata,data) < 0) { + opserr << "ERROR: invalid double data for spectrum with tag " << tag << endln; + return -1; + } + + theSpectrum = new JonswapSpectrum(tag, data[0], data[1], data[2], data[3], data[4]); + } + else if (strcmp(type,"narrowband") == 0) { + if (OPS_GetNumRemainingInputArgs() < 3) { + opserr << "ERROR: insufficient arguments for narrowband spectrum" << endln; + return -1; + } + double data[3]; + numdata = 3; + if (OPS_GetDoubleInput(&numdata,data) < 0) { + opserr << "ERROR: invalid double data for spectrum with tag " << tag << endln; + return -1; + } + + theSpectrum = new NarrowBandSpectrum(tag, data[0], data[1], data[2]); + } + else if (strcmp(type,"points") == 0) { + opserr << "ERROR: points spectrum not yet added to Python interpreter" << endln; + return -1; + } + else { + opserr << "Unknown spectrum type: " << type << endln; + return -1; + } + + if (theSpectrum == 0) { + opserr << "ERROR: ran out of memory creating spectrum \n"; + opserr << type << ' ' << tag << endln; + return -1; + } + + // ADD THE OBJECT TO THE DOMAIN + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain->addSpectrum(theSpectrum) == false) { + opserr << "ERROR: failed to add spectrum to the domain\n"; + opserr << type << ' ' << tag << endln; + delete theSpectrum; // otherwise memory leak + return -1; + } + + return 0; +} + int OPS_modulatingFunction() { ModulatingFunction *theModulatingFunction = 0; int tag; @@ -445,7 +519,7 @@ int OPS_modulatingFunction() { return -1; } - Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + Filter *theFilter = theReliabilityDomain->getFilterPtr(filterTag); if (theFilter == 0) { opserr << "ERROR: could not find filter with tag " << filterTag << " for modulating function" << endln; @@ -475,7 +549,7 @@ int OPS_modulatingFunction() { return -1; } - Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + Filter *theFilter = theReliabilityDomain->getFilterPtr(filterTag); if (theFilter == 0) { opserr << "ERROR: could not find filter with tag " << filterTag << " for modulating function" << endln; @@ -504,7 +578,7 @@ int OPS_modulatingFunction() { return -1; } - Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + Filter *theFilter = theReliabilityDomain->getFilterPtr(filterTag); if (theFilter == 0) { opserr << "ERROR: could not find filter with tag " << filterTag << " for modulating function" << endln; @@ -535,7 +609,7 @@ int OPS_modulatingFunction() { return -1; } - Filter *theFilter = theReliabilityDomain->getFilter(filterTag); + Filter *theFilter = theReliabilityDomain->getFilterPtr(filterTag); if (theFilter == 0) { opserr << "ERROR: could not find filter with tag " << filterTag << " for modulating function" << endln; @@ -2783,6 +2857,8 @@ int inputCheck() { } */ ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + + /* num = theReliabilityDomain->getNumberOfFilters(); for (i = 1; i <= num; i++) { component = theReliabilityDomain->getFilter(i); @@ -2791,7 +2867,8 @@ int inputCheck() { return -1; } } - + */ + /* num = theReliabilityDomain->getNumberOfModulatingFunctions(); for (i = 1; i <= num; i++) { component = theReliabilityDomain->getModulatingFunction(i); @@ -2801,7 +2878,8 @@ int inputCheck() { return -1; } } - + */ + /* num = theReliabilityDomain->getNumberOfSpectra(); for (i = 1; i <= num; i++) { component = theReliabilityDomain->getSpectrum(i); @@ -2810,7 +2888,7 @@ int inputCheck() { return -1; } } - + */ // Check that the correlation matrix is positive definite // theCorrelationMatrix diff --git a/SRC/interpreter/PythonWrapper.cpp b/SRC/interpreter/PythonWrapper.cpp index 07d05356f7..0df33f6559 100644 --- a/SRC/interpreter/PythonWrapper.cpp +++ b/SRC/interpreter/PythonWrapper.cpp @@ -2393,6 +2393,18 @@ static PyObject *Py_ops_filter(PyObject *self, PyObject *args) return wrapper->getResults(); } +static PyObject *Py_ops_spectrum(PyObject *self, PyObject *args) +{ + wrapper->resetCommandLine(PyTuple_Size(args), 1, args); + + if (OPS_spectrum() < 0) { + opserr<<(void*)0; + return NULL; + } + + return wrapper->getResults(); +} + static PyObject *Py_ops_modulatingFunction(PyObject *self, PyObject *args) { wrapper->resetCommandLine(PyTuple_Size(args), 1, args); @@ -3109,6 +3121,7 @@ PythonWrapper::addOpenSeesCommands() addCommand("randomVariable", &Py_ops_randomVariable); addCommand("filter", &Py_ops_filter); addCommand("modulatingFunction", &Py_ops_modulatingFunction); + addCommand("spectrum", &Py_ops_spectrum); addCommand("getRVTags", &Py_ops_getRVTags); addCommand("getRVParamTag", &Py_ops_getRVParamTag); addCommand("getRVValue", &Py_ops_getRVValue); From 74b4daee39d5c9c6de032d0ab92e7e6b4b27b974 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Mon, 18 Mar 2024 06:30:40 -0700 Subject: [PATCH 17/32] Adding MonteCarlo command to Python --- .../OpenSeesReliabilityCommands.cpp | 134 +++++++++++++++++- SRC/interpreter/OpenSeesReliabilityCommands.h | 7 +- 2 files changed, 138 insertions(+), 3 deletions(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 2d20bab38d..7cc6d1f4f0 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -133,6 +133,7 @@ OpenSeesReliabilityCommands::OpenSeesReliabilityCommands( theFORMAnalysis(0), theSORMAnalysis(0), theImportanceSamplingAnalysis(0), + theMonteCarloAnalysis(0), theSensAlgo(0) { if (structuralDomain != 0) { theDomain = new ReliabilityDomain(structuralDomain); @@ -222,6 +223,10 @@ void OpenSeesReliabilityCommands::wipe() { delete theImportanceSamplingAnalysis; theImportanceSamplingAnalysis = 0; } + if (theMonteCarloAnalysis != 0) { + delete theMonteCarloAnalysis; + theMonteCarloAnalysis = 0; + } } int OPS_wipeReliability() { @@ -1602,6 +1607,15 @@ void OpenSeesReliabilityCommands::setImportanceSamplingAnalysis( theImportanceSamplingAnalysis = analysis; } +void OpenSeesReliabilityCommands::setMonteCarloAnalysis( + MonteCarloResponseAnalysis *analysis) { + if (theMonteCarloAnalysis != 0) { + delete theMonteCarloAnalysis; + theMonteCarloAnalysis = 0; + } + theMonteCarloAnalysis = analysis; +} + int OPS_startPoint() { if (OPS_GetNumRemainingInputArgs() < 1) { opserr << "ERROR: wrong number of arguments to startPoint" @@ -3202,7 +3216,7 @@ int OPS_runImportanceSamplingAnalysis() { } Domain *theStructuralDomain = cmds->getStructuralDomain(); - if (theReliabilityDomain == 0) { + if (theStructuralDomain == 0) { opserr << "Need theStructuralDomain before a " "ImportanceSamplingAnalysis can be created\n"; return -1; @@ -3284,7 +3298,7 @@ int OPS_runImportanceSamplingAnalysis() { int numdata = 1; double data = 0.0; if (OPS_GetDoubleInput(&numdata, &data) < 0) { - opserr << "ERROR: invalid input: samplingVariance \n"; + opserr << "ERROR: invalid input: maxNum \n"; return -1; } numberOfSimulations = long(data); @@ -3339,3 +3353,119 @@ int OPS_runImportanceSamplingAnalysis() { return 0; } + +int OPS_runMonteCarloAnalysis() { + if (cmds == 0) { + return -1; + } + + // do input check + if (inputCheck() < 0) { + return -1; + } + + // filename + if (OPS_GetNumRemainingInputArgs() < 1) { + opserr << "WARNING: need filename\n"; + return -1; + } + const char *filename = OPS_GetString(); + + ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); + if (theReliabilityDomain == 0) { + opserr << "Need theReliabilityDomain before a " + "ImportanceSamplingAnalysis can be created\n"; + return -1; + } + + // Check for essential tools + ProbabilityTransformation *theProbabilityTransformation = + cmds->getProbabilityTransformation(); + if (theProbabilityTransformation == 0) { + opserr << "ImportanceSampingAnalysis - probability transformation not defined - "; + opserr << "assuming all independent transformation" << endln; + theProbabilityTransformation = + new AllIndependentTransformation(theReliabilityDomain, 0); + cmds->setProbabilityTransformation(theProbabilityTransformation); + } + FunctionEvaluator *theFunctionEvaluator = cmds->getFunctionEvaluator(); + if (theFunctionEvaluator == 0) { + opserr << "Need theGFunEvaluator before a " + "ImportanceSamplingAnalysis " + "can be created\n"; + return -1; + } + RandomNumberGenerator *theRandomNumberGenerator = + cmds->getRandomNumberGenerator(); + if (theRandomNumberGenerator == 0) { + // Don't really need to say this - just do it - bc CStdLib is the only option -- MHS + //opserr << "ImportanceSampingAnalysis - random number generator not defined - "; + //opserr << "assuming CStdLib generator" << endln; + theRandomNumberGenerator = new CStdLibRandGenerator(); + cmds->setRandomNumberGenerator(theRandomNumberGenerator); + } + + // Declaration of input parameters + long int numberOfSimulations = 1000; + double targetCOV = 0.05; + int seed = 0; + int printFlag = 0; + char outputFile[80] = ""; + char *tclFileName = 0; + + while (OPS_GetNumRemainingInputArgs() > 1) { + const char *type = OPS_GetString(); + + if (strcmp(type, "-maxNum") == 0 || strcmp(type,"maxNum") == 0) { + int numdata = 1; + double data = 0.0; + if (OPS_GetDoubleInput(&numdata, &data) < 0) { + opserr << "ERROR: invalid input: numberOfSimulations \n"; + return -1; + } + numberOfSimulations = long(data); + + } else if (strcmp(type, "-seed") == 0) { + int numdata = 1; + if (OPS_GetIntInput(&numdata, &seed) < 0) { + opserr << "ERROR: invalid input: seed \n"; + return -1; + } + + } else if (strcmp(type, "-print") == 0 || strcmp(type, "-printFlag") == 0) { + int numdata = 1; + if (OPS_GetIntInput(&numdata, &printFlag) < 0) { + opserr << "ERROR: invalid input: printFlag \n"; + return -1; + } + + } else { + opserr << "ERROR: invalid input to Monte Carlo analysis. \n"; + return -1; + } + } + + + MonteCarloResponseAnalysis *theMonteCarloAnalysis = 0; + /* + theMonteCarloAnalysis + = new MonteCarloResponseAnalysis(theReliabilityDomain, 0, + theProbabilityTransformation, //theFunctionEvaluator, + theRandomNumberGenerator, numberOfSimulations, + printFlag, outputFile, tclFileName, seed); + + if (theMonteCarloAnalysis == 0) { + opserr << "Unable to create MonteCarlo analysis" << endln; + return -1; + } + + cmds->setMonteCarloAnalysis(theMonteCarloAnalysis); + + if (theMonteCarloAnalysis->analyze() < 0) { + opserr << "WARNING: failed to run MonteCarloAnalysis\n"; + return -1; + } +*/ + + return 0; +} diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.h b/SRC/interpreter/OpenSeesReliabilityCommands.h index 3283e40ebc..65cd4091c1 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.h +++ b/SRC/interpreter/OpenSeesReliabilityCommands.h @@ -59,6 +59,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include #include +#include #include #include #include @@ -164,6 +165,9 @@ class OpenSeesReliabilityCommands { return theImportanceSamplingAnalysis; } + void setMonteCarloAnalysis(MonteCarloResponseAnalysis *analysis); + MonteCarloResponseAnalysis *getMonteCarloAnalysis() { return theMonteCarloAnalysis; } + void setSensitivityAlgorithm(Integrator *inte) { theSensAlgo = inte; } @@ -197,7 +201,8 @@ class OpenSeesReliabilityCommands { FORMAnalysis *theFORMAnalysis; SORMAnalysis *theSORMAnalysis; ImportanceSamplingAnalysis *theImportanceSamplingAnalysis; - + MonteCarloResponseAnalysis *theMonteCarloAnalysis; + // sensitivity algorithm Integrator *theSensAlgo; }; From ee7b28ce10a54e8d95a0a4792e1eb0036f000f01 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Mon, 18 Mar 2024 06:34:12 -0700 Subject: [PATCH 18/32] Adding OPS function and using Vector objects instead of pointers --- .../pattern/SimulatedRandomProcessSeries.cpp | 113 ++++++++++++++---- .../pattern/SimulatedRandomProcessSeries.h | 7 +- 2 files changed, 97 insertions(+), 23 deletions(-) diff --git a/SRC/domain/pattern/SimulatedRandomProcessSeries.cpp b/SRC/domain/pattern/SimulatedRandomProcessSeries.cpp index 444c18fc54..4a32c2ee5d 100644 --- a/SRC/domain/pattern/SimulatedRandomProcessSeries.cpp +++ b/SRC/domain/pattern/SimulatedRandomProcessSeries.cpp @@ -41,52 +41,123 @@ //#include #include +#include +#include +#include + +CStdLibRandGenerator SimulatedRandomProcessSeries::randGenerator; + +void * +OPS_SimulatedRandomProcessSeries(void) +{ + // Pointer that will be returned + TimeSeries *theSeries = 0; + + int tag; + double mean; + int spectrumTag, NfreqIntervals; + + int numData = 1; + + int numRemainingArgs = OPS_GetNumRemainingInputArgs(); + if (numRemainingArgs < 4) { + opserr << "ERROR: Insufficient arguments for SimulatedRandomProcess series" << endln; + return 0; + } + + if (OPS_GetIntInput(&numData, &tag) != 0) { + opserr << "WARNING invalid tag for SimulatedRandomProcess" << endln; + return 0; + } + if (OPS_GetInt(&numData, &spectrumTag) != 0) { + opserr << "WARNING invalid spectrum tag for SimulatedRandomProcess with tag: " << tag << endln; + return 0; + } + if (OPS_GetDouble(&numData, &mean) != 0) { + opserr << "WARNING invalid mean for SimulatedRandomProcess with tag: " << tag << endln; + return 0; + } + if (OPS_GetInt(&numData, &NfreqIntervals) != 0) { + opserr << "WARNING invalid num frequency internvals for SimulatedRandomProcess with tag: " << tag << endln; + return 0; + } + + ReliabilityDomain *theReliabilityDomain = OPS_GetReliabilityDomain(); + if (theReliabilityDomain == 0) { + opserr << "ERROR SimulatedRandomProcess -- reliability domain not defined" << endln; + return 0; + } + + Spectrum *theSpectrum = theReliabilityDomain->getSpectrum(spectrumTag); + if (theSpectrum == 0) { + opserr << "ERROR SimulatedRandomProcess -- spectrum with tag " << spectrumTag + << " not found" << endln; + return 0; + } + + /* + RandomNumberGenerator *theRandNumGenerator = cmds->getRandomNumberGenerator(); + if (theRandNumGenerator == 0) { + opserr << "ERROR SimulatedRandomProcess -- random number generator not defined" << endln; + return 0; + } + */ + RandomNumberGenerator *theRandNumGenerator = 0; + + theSeries = new SimulatedRandomProcessSeries(tag, theRandNumGenerator, + theSpectrum, NfreqIntervals, mean); + + if (theSeries == 0) { + opserr << "WARNING ran out of memory creating DiscretizedRandomProcess series with tag: " << tag << endln; + return 0; + } + + return theSeries; +} + SimulatedRandomProcessSeries::SimulatedRandomProcessSeries(int tag, RandomNumberGenerator *theRandNumGenerator, Spectrum *theSpectr, int numFreqInt, double pmean) - :TimeSeries(tag, TSERIES_TAG_SimulatedRandomProcessSeries) + :TimeSeries(tag, TSERIES_TAG_SimulatedRandomProcessSeries), + theSpectrum(theSpectr), numFreqIntervals(numFreqInt), mean(pmean), + deltaW(0.0), theta(numFreqInt), A(numFreqInt) { - theRandomNumberGenerator = theRandNumGenerator; - theSpectrum = theSpectr; - numFreqIntervals = numFreqInt; - mean = pmean; - + //theRandomNumberGenerator = theRandNumGenerator; + theRandomNumberGenerator = &randGenerator; // Generate random numbers, uniformly distributed between 0 and 2pi double pi = 3.14159265358979; theRandomNumberGenerator->generate_nIndependentUniformNumbers(numFreqIntervals,0.0,(2*pi)); - Vector theta1 = theRandomNumberGenerator->getGeneratedNumbers(); - theta = new Vector(theta1); - + theta = theRandomNumberGenerator->getGeneratedNumbers(); // Generate standard normal random numbers theRandomNumberGenerator->generate_nIndependentStdNormalNumbers(numFreqIntervals); - Vector A1 = theRandomNumberGenerator->getGeneratedNumbers(); - A = new Vector(A1); - + A = theRandomNumberGenerator->getGeneratedNumbers(); // Length of each interval deltaW = (theSpectrum->getMaxFrequency()-theSpectrum->getMinFrequency())/numFreqIntervals; - - } TimeSeries * SimulatedRandomProcessSeries::getCopy(void) { - opserr << "SimulatedRandomProcessSeries::getCopy(void) - not yet implemented\n"; - return 0; + + SimulatedRandomProcessSeries *theCopy = + new SimulatedRandomProcessSeries(this->getTag(), + theRandomNumberGenerator, + theSpectrum, numFreqIntervals, mean); + theCopy->theta = theta; + theCopy->A = A; + + return theCopy; } SimulatedRandomProcessSeries::~SimulatedRandomProcessSeries() { - if (theta != 0) - delete theta; - if (A != 0) - delete A; + } @@ -106,7 +177,7 @@ SimulatedRandomProcessSeries::getFactor(double time) for (int i=0; igetMinFrequency(); S = theSpectrum->getAmplitude(W); - factor += sqrt(2.0*S*deltaW) * (*A)(i) * cos(W*time+(*theta)(i)); + factor += sqrt(2.0*S*deltaW) * A(i) * cos(W*time+theta(i)); } //outputFile << (mean+factor) << endl; diff --git a/SRC/domain/pattern/SimulatedRandomProcessSeries.h b/SRC/domain/pattern/SimulatedRandomProcessSeries.h index 3ff4eeb083..c47cecf2c0 100644 --- a/SRC/domain/pattern/SimulatedRandomProcessSeries.h +++ b/SRC/domain/pattern/SimulatedRandomProcessSeries.h @@ -38,6 +38,7 @@ #include #include #include +#include class SimulatedRandomProcessSeries : public TimeSeries { @@ -76,8 +77,10 @@ class SimulatedRandomProcessSeries : public TimeSeries int numFreqIntervals; double mean; double deltaW; - Vector *theta; - Vector *A; + Vector theta; + Vector A; + + static CStdLibRandGenerator randGenerator; }; #endif From 30fee22c4aae15dc24a2be98a26f43833af1b2e1 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Mon, 18 Mar 2024 06:34:30 -0700 Subject: [PATCH 19/32] Adding OPS function --- .../DiscretizedRandomProcessSeries.cpp | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp index e25850f864..5565818e0f 100644 --- a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp +++ b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp @@ -42,6 +42,80 @@ #include #include +#include +#include +#include + +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); + delete [] theModFcns; + + 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, From 6490e793897ce099050ce50fd6a56bd72c385183 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Mon, 18 Mar 2024 06:37:13 -0700 Subject: [PATCH 20/32] Adding random process series to Python interpreter --- SRC/interpreter/OpenSeesTimeSeriesCommands.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SRC/interpreter/OpenSeesTimeSeriesCommands.cpp b/SRC/interpreter/OpenSeesTimeSeriesCommands.cpp index 1bb096f96f..1ec70b0936 100644 --- a/SRC/interpreter/OpenSeesTimeSeriesCommands.cpp +++ b/SRC/interpreter/OpenSeesTimeSeriesCommands.cpp @@ -56,6 +56,8 @@ void* OPS_RampSeries(); void* OPS_RectangularSeries(); void* OPS_PulseSeries(); void* OPS_MPAccSeries(); //Tang.S +void* OPS_DiscretizedRandomProcessSeries(); +void* OPS_SimulatedRandomProcessSeries(); namespace { @@ -229,6 +231,8 @@ namespace { functionMap.insert(std::make_pair("Series", &OPS_PathSeries)); functionMap.insert(std::make_pair("MPAcc", &OPS_MPAccSeries)); //Tang.S functionMap.insert(std::make_pair("MPAccSeries", &OPS_MPAccSeries)); + functionMap.insert(std::make_pair("DiscretizedRandomProcess", &OPS_DiscretizedRandomProcessSeries)); + functionMap.insert(std::make_pair("SimulatedRandomProcess", &OPS_SimulatedRandomProcessSeries)); return 0; } From 17be170b71330632a9ce745da1195c6c74dc8a0f Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Mon, 18 Mar 2024 20:12:49 -0700 Subject: [PATCH 21/32] Using intialization list, implementing getCopy --- .../DiscretizedRandomProcessSeries.cpp | 27 ++++++++++++------- .../pattern/DiscretizedRandomProcessSeries.h | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp index 5565818e0f..bf200525a3 100644 --- a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp +++ b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp @@ -121,22 +121,29 @@ DiscretizedRandomProcessSeries::DiscretizedRandomProcessSeries(int tag, ModulatingFunction **theModFuncs, double p_mean, double p_maxStdv) - :TimeSeries(tag, TSERIES_TAG_DiscretizedRandomProcessSeries) + :TimeSeries(tag, TSERIES_TAG_DiscretizedRandomProcessSeries), + numModFuncs(num), c(0.0), 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"; + 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 0; } diff --git a/SRC/domain/pattern/DiscretizedRandomProcessSeries.h b/SRC/domain/pattern/DiscretizedRandomProcessSeries.h index fd099567a7..2abc68bea8 100644 --- a/SRC/domain/pattern/DiscretizedRandomProcessSeries.h +++ b/SRC/domain/pattern/DiscretizedRandomProcessSeries.h @@ -80,7 +80,7 @@ class DiscretizedRandomProcessSeries : public TimeSeries double c; double mean; double maxStdv; - double maxStdvTime; + //double maxStdvTime; ModulatingFunction **theModulatingFunctions; Vector *randomVariables; Vector *kickInTimes; From 7e91307b774fb81c319301b94f0569d1bc8df720 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Tue, 19 Mar 2024 05:58:34 -0700 Subject: [PATCH 22/32] Fixing getCopy --- SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp index bf200525a3..67125402a9 100644 --- a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp +++ b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp @@ -105,7 +105,6 @@ OPS_DiscretizedRandomProcessSeries(void) } theSeries = new DiscretizedRandomProcessSeries(tag, numModFcns, theModFcns, mean, maxStdv); - delete [] theModFcns; if (theSeries == 0) { opserr << "WARNING ran out of memory creating DiscretizedRandomProcess series with tag: " << tag << endln; @@ -144,7 +143,7 @@ DiscretizedRandomProcessSeries::getCopy(void) if (kickInTimes != 0) theCopy->kickInTimes = new Vector(*kickInTimes); - return 0; + return theCopy; } From a13b55eff78d79b35d54ab7580d5e4a61dddf188 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Tue, 19 Mar 2024 15:56:12 -0700 Subject: [PATCH 23/32] Initializaing c variable --- SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp index 67125402a9..e57f07f0dc 100644 --- a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp +++ b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp @@ -121,7 +121,7 @@ DiscretizedRandomProcessSeries::DiscretizedRandomProcessSeries(int tag, double p_mean, double p_maxStdv) :TimeSeries(tag, TSERIES_TAG_DiscretizedRandomProcessSeries), - numModFuncs(num), c(0.0), mean(p_mean), maxStdv(p_maxStdv), + numModFuncs(num), c(p_maxStdv), mean(p_mean), maxStdv(p_maxStdv), theModulatingFunctions(theModFuncs), randomVariables(0), kickInTimes(0), parameterID(0) { From 62c7f405e016ead28806a9fcff8dbe57f9fe287f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 26 Mar 2024 18:22:25 +0000 Subject: [PATCH 24/32] Fixing Ubuntu EC2 Makefile.def --- MAKES/Makefile.def.EC2-UBUNTU | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/MAKES/Makefile.def.EC2-UBUNTU b/MAKES/Makefile.def.EC2-UBUNTU index 2e8477de23..19c8f20707 100644 --- a/MAKES/Makefile.def.EC2-UBUNTU +++ b/MAKES/Makefile.def.EC2-UBUNTU @@ -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 | @@ -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 @@ -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 @@ -149,7 +150,8 @@ WIPE_LIBS = $(FE_LIBRARY) \ $(ARPACK_LIBRARY) \ $(UMFPACK_LIBRARY) \ $(CSPARSE_LIBRARY) \ - $(METIS_LIBRARY) + $(METIS_LIBRARY) \ + $(RELIABILITY_LIBRARY) # %---------------------------------------------------------% # | SECTION 4: COMPILERS | @@ -195,9 +197,9 @@ else C++FLAGS = -Wall -D_LINUX -D_UNIX -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++) @@ -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) \ @@ -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) From 906f38948a45da9a1de1360d707c8f729c03d30d Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Wed, 27 Mar 2024 13:37:04 -0700 Subject: [PATCH 25/32] Updating setParameter --- .../pattern/DiscretizedRandomProcessSeries.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp index e57f07f0dc..5b26562864 100644 --- a/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp +++ b/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp @@ -291,12 +291,12 @@ int DiscretizedRandomProcessSeries::setParameter(const char **argv, int argc, Parameter ¶m) { - 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". @@ -304,8 +304,7 @@ DiscretizedRandomProcessSeries::setParameter(const char **argv, int argc, // 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. } @@ -325,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 @@ -383,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 From 28a27a31650749774a6b8831cd5d1f5261981acf Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Thu, 4 Apr 2024 11:25:51 -0700 Subject: [PATCH 26/32] Adding PYTHON3 defintion --- MAKES/Makefile.def.EC2-UBUNTU | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MAKES/Makefile.def.EC2-UBUNTU b/MAKES/Makefile.def.EC2-UBUNTU index 19c8f20707..249632c0f5 100644 --- a/MAKES/Makefile.def.EC2-UBUNTU +++ b/MAKES/Makefile.def.EC2-UBUNTU @@ -183,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 @@ -195,7 +195,7 @@ 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 -fPIC CFLAGS = -Wall -O2 -fPIC From 3eb316b6bb0283b8eabbdc1d445621a464f613db Mon Sep 17 00:00:00 2001 From: Michael Scott Date: Thu, 11 Apr 2024 13:30:14 -0700 Subject: [PATCH 27/32] Removing inputCheck() --- .../OpenSeesReliabilityCommands.cpp | 138 ------------------ 1 file changed, 138 deletions(-) diff --git a/SRC/interpreter/OpenSeesReliabilityCommands.cpp b/SRC/interpreter/OpenSeesReliabilityCommands.cpp index 7cc6d1f4f0..d383c6910a 100644 --- a/SRC/interpreter/OpenSeesReliabilityCommands.cpp +++ b/SRC/interpreter/OpenSeesReliabilityCommands.cpp @@ -2831,119 +2831,6 @@ int OPS_transformUtoX() { return 0; } -int inputCheck() { - // Check that tagged objects are consecutive - int i, num; - ReliabilityDomainComponent *component; - if (cmds == 0) { - opserr << "WARNING: cmds is not defined\n"; - return -1; - } - - // Clear out old parameter positioners so we don't produce a - // memory leak - /* - theReliabilityDomain->removeAllParameterPositioners(); - - ParameterIter ¶mIter = theStructuralDomain->getParameters(); - Parameter *theParam; - i = 1; - while ((theParam = paramIter()) != 0) { - ParameterPositioner *theParamPos = - new ParameterPositioner(i, *theParam); - theParamPos->setGradNumber(i); - if (theReliabilityDomain->addParameterPositioner(theParamPos) == - false) { opserr << "ERROR: failed to add parameter positioner " - << i << endln; delete theParamPos; // otherwise memory leak - return TCL_ERROR; - } - i++; - } - */ - /* - num = - theReliabilityDomain->getNumberOfRandomVariablePositioners(); for - (i=1; i<=num; i++) { component = - theReliabilityDomain->getRandomVariablePositionerPtr(i); if - (component == 0) { opserr << "ERROR: Non-consecutive random - variable positioner list." << endln; return TCL_ERROR; - } - } - */ - ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); - - /* - num = theReliabilityDomain->getNumberOfFilters(); - for (i = 1; i <= num; i++) { - component = theReliabilityDomain->getFilter(i); - if (component == 0) { - opserr << "ERROR: Non-consecutive filter list." << endln; - return -1; - } - } - */ - /* - num = theReliabilityDomain->getNumberOfModulatingFunctions(); - for (i = 1; i <= num; i++) { - component = theReliabilityDomain->getModulatingFunction(i); - if (component == 0) { - opserr << "ERROR: Non-consecutive modulating function list." - << endln; - return -1; - } - } - */ - /* - num = theReliabilityDomain->getNumberOfSpectra(); - for (i = 1; i <= num; i++) { - component = theReliabilityDomain->getSpectrum(i); - if (component == 0) { - opserr << "ERROR: Non-consecutive spectrum list." << endln; - return -1; - } - } - */ - // Check that the correlation matrix is positive definite - // theCorrelationMatrix - - // set defaults - /* - ProbabilityTransformation *theProbabilityTransformation = - cmds->getProbabilityTransformation(); - if (theProbabilityTransformation == 0) { - opserr << "No probabilityTransformation specified, assuming " - "AllIndependent" - << endln; - theProbabilityTransformation = - new AllIndependentTransformation(theReliabilityDomain, 0); - cmds->setProbabilityTransformation(theProbabilityTransformation); - } - */ - - // reliabilityConvergenceCheck Standard -e1 1.0e-3 - // -e2 1.0e-3 -print 1 functionEvaluator Tcl - // gradientEvaluator FiniteDifference -pert 1000 - - /* - SearchDirection *theSearchDirection = cmds->getSearchDirection(); - if (theSearchDirection == 0) { - opserr << "No searchDirection specified, assuming iHLRF" - << endln; - theSearchDirection = new HLRFSearchDirection(); - cmds->setSearchDirection(theSearchDirection); - } - */ - - // meritFunctionCheck AdkZhang -multi 2.0 - // -add 10.0 -factor 0.5 stepSizeRule Armijo - // -maxNum 5 -base 0.5 -initial 1.0 2 -print 0 startPoint - // Mean findDesignPoint StepSearch -maxNumIter 30 - // -printDesignPointX CalRel_manual_1_output/1_designX.out - // randomNumberGenerator CStdLib - - return 0; -} - int OPS_runFOSMAnalysis() { if (OPS_GetNumRemainingInputArgs() < 1) { opserr << "WARNING: Wrong number of input parameter to FOSM " @@ -2954,11 +2841,6 @@ int OPS_runFOSMAnalysis() { // get file name const char *filename = OPS_GetString(); - // Do input check - if (inputCheck() < 0) { - return -1; - } - ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); if (theReliabilityDomain == 0) { opserr << "FOSMAnalysis -- ReliabilityDomain is not defined\n"; @@ -3016,11 +2898,6 @@ int OPS_runFORMAnalysis() { // get file name const char *filename = OPS_GetString(); - // Do input check - if (inputCheck() < 0) { - return -1; - } - ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); if (theReliabilityDomain == 0) { opserr << "FORMAnalysis -- ReliabilityDomain is not defined\n"; @@ -3108,11 +2985,6 @@ int OPS_runSORMAnalysis() { // get file name const char *filename = OPS_GetString(); - // Do input check - if (inputCheck() < 0) { - return -1; - } - ReliabilityDomain *theReliabilityDomain = cmds->getDomain(); if (theReliabilityDomain == 0) { opserr << "FORMAnalysis -- ReliabilityDomain is not defined" << endln; @@ -3169,11 +3041,6 @@ int OPS_runImportanceSamplingAnalysis() { return -1; } - // do input check - if (inputCheck() < 0) { - return -1; - } - // filename if (OPS_GetNumRemainingInputArgs() < 1) { opserr << "WARNING: need filename\n"; @@ -3359,11 +3226,6 @@ int OPS_runMonteCarloAnalysis() { return -1; } - // do input check - if (inputCheck() < 0) { - return -1; - } - // filename if (OPS_GetNumRemainingInputArgs() < 1) { opserr << "WARNING: need filename\n"; From 1f3d42acd4a4a9e5c23e2df14927c8f7e6031e60 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 25 Apr 2024 08:54:42 -0700 Subject: [PATCH 28/32] Removing ASD plastic from Makefiles -- DO NOT MERGE --- SRC/Makefile | 1 - SRC/interpreter/OpenSeesNDMaterialCommands.cpp | 4 ++-- SRC/material/nD/Makefile | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/SRC/Makefile b/SRC/Makefile index 8dc277bf08..55c12426e8 100644 --- a/SRC/Makefile +++ b/SRC/Makefile @@ -1057,7 +1057,6 @@ MATERIAL_LIBS = $(FE)/material/Material.o \ $(FE)/material/nD/PlateFromPlaneStressMaterial.o \ $(FE)/material/nD/PlateRebarMaterial.o \ $(FE)/material/nD/ASDConcrete3DMaterial.o \ - $(FE)/material/nD/ASDPlasticMaterial/OPS_AllASDPlasticMaterials.o \ $(FE)/material/nD/stressDensityModel/stressDensity.o \ $(FE)/material/nD/stressDensityModel/SDM-UC.o \ $(FE)/material/nD/OrthotropicRotatingAngleConcreteT2DMaterial01/OrthotropicRotatingAngleConcreteT2DMaterial01.o \ diff --git a/SRC/interpreter/OpenSeesNDMaterialCommands.cpp b/SRC/interpreter/OpenSeesNDMaterialCommands.cpp index 5bf8bcc7e2..ca4b1f593b 100644 --- a/SRC/interpreter/OpenSeesNDMaterialCommands.cpp +++ b/SRC/interpreter/OpenSeesNDMaterialCommands.cpp @@ -84,7 +84,7 @@ void* OPS_ConcreteMcftNonlinear7(); void* OPS_ASDConcrete3DMaterial(); void* OPS_OrthotropicRotatingAngleConcreteT2DMaterial01(); // M. J. Nunez - UChile void* OPS_SmearedSteelDoubleLayerT2DMaterial01(); // M. J. Nunez - UChile -void* OPS_AllASDPlasticMaterials(); +//void* OPS_AllASDPlasticMaterials(); namespace { @@ -207,7 +207,7 @@ namespace { nDMaterialsMap.insert(std::make_pair("ASDConcrete3D", &OPS_ASDConcrete3DMaterial)); nDMaterialsMap.insert(std::make_pair("OrthotropicRAConcrete", &OPS_OrthotropicRotatingAngleConcreteT2DMaterial01)); nDMaterialsMap.insert(std::make_pair("SmearedSteelDoubleLayer", &OPS_SmearedSteelDoubleLayerT2DMaterial01)); - nDMaterialsMap.insert(std::make_pair("ASDPlasticMaterial", &OPS_AllASDPlasticMaterials)); + //nDMaterialsMap.insert(std::make_pair("ASDPlasticMaterial", &OPS_AllASDPlasticMaterials)); return 0; } diff --git a/SRC/material/nD/Makefile b/SRC/material/nD/Makefile index b8c2e22c99..8e46345320 100644 --- a/SRC/material/nD/Makefile +++ b/SRC/material/nD/Makefile @@ -112,7 +112,7 @@ all: $(OBJS) @$(CD) $(FE)/material/nD/UANDESmaterials; $(MAKE); @$(CD) $(FE)/material/nD/OrthotropicRotatingAngleConcreteT2DMaterial01; $(MAKE); @$(CD) $(FE)/material/nD/SmearedSteelDoubleLayerT2DMaterial01; $(MAKE); - @$(CD) $(FE)/material/nD/ASDPlasticMaterial; $(MAKE); +# @$(CD) $(FE)/material/nD/ASDPlasticMaterial; $(MAKE); test: $(OBJS) main.o $(LINKER) $(LINKFLAGS) main.o ../../../SRC/api/elementAPI_Dummy.o $(FE_LIBRARY) \ From 9815802933e69deebf6768aed1526e158f7a7e28 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Wed, 31 Jul 2024 18:15:09 -0700 Subject: [PATCH 29/32] Reverting Makefile --- SRC/material/nD/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRC/material/nD/Makefile b/SRC/material/nD/Makefile index 8e46345320..b8c2e22c99 100644 --- a/SRC/material/nD/Makefile +++ b/SRC/material/nD/Makefile @@ -112,7 +112,7 @@ all: $(OBJS) @$(CD) $(FE)/material/nD/UANDESmaterials; $(MAKE); @$(CD) $(FE)/material/nD/OrthotropicRotatingAngleConcreteT2DMaterial01; $(MAKE); @$(CD) $(FE)/material/nD/SmearedSteelDoubleLayerT2DMaterial01; $(MAKE); -# @$(CD) $(FE)/material/nD/ASDPlasticMaterial; $(MAKE); + @$(CD) $(FE)/material/nD/ASDPlasticMaterial; $(MAKE); test: $(OBJS) main.o $(LINKER) $(LINKFLAGS) main.o ../../../SRC/api/elementAPI_Dummy.o $(FE_LIBRARY) \ From 39bc23355f6163426625f9364e216ea0d084d0e1 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Wed, 31 Jul 2024 18:16:05 -0700 Subject: [PATCH 30/32] Reverting Makefile --- SRC/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/SRC/Makefile b/SRC/Makefile index ee3155ab22..fe2595fa34 100644 --- a/SRC/Makefile +++ b/SRC/Makefile @@ -1065,6 +1065,7 @@ MATERIAL_LIBS = $(FE)/material/Material.o \ $(FE)/material/nD/PlateFromPlaneStressMaterial.o \ $(FE)/material/nD/PlateRebarMaterial.o \ $(FE)/material/nD/ASDConcrete3DMaterial.o \ + $(FE)/material/nD/ASDPlasticMaterial/OPS_AllASDPlasticMaterials.o \ $(FE)/material/nD/stressDensityModel/stressDensity.o \ $(FE)/material/nD/stressDensityModel/SDM-UC.o \ $(FE)/material/nD/OrthotropicRotatingAngleConcreteT2DMaterial01/OrthotropicRotatingAngleConcreteT2DMaterial01.o \ From a5cafb7671158b4a8f579a78cf076ec61d4fc7b8 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 1 Aug 2024 10:11:54 -0700 Subject: [PATCH 31/32] Adding OPS_GetReliabilityDomain to Tcl API --- SRC/api/elementAPI_TCL.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SRC/api/elementAPI_TCL.cpp b/SRC/api/elementAPI_TCL.cpp index 26df53e744..3cd4f6e05f 100644 --- a/SRC/api/elementAPI_TCL.cpp +++ b/SRC/api/elementAPI_TCL.cpp @@ -89,6 +89,7 @@ static LimitCurveFunction* theLimitCurveFunctions = NULL; static Tcl_Interp* theInterp = 0; static Domain* theDomain = 0; +static ReliabilityDomain* theReliabilityDomain = 0; static TclModelBuilder* theModelBuilder = 0; @@ -1290,6 +1291,12 @@ OPS_GetDomain(void) return theDomain; } +ReliabilityDomain* +OPS_GetReliabilityDomain(void) +{ + return theReliabilityDomain; +} + void TCL_OPS_setModelBuilder(TclModelBuilder* theNewBuilder) { From ffbd98925dcf7953041561d2cb8f00f4d551e183 Mon Sep 17 00:00:00 2001 From: "Michael H. Scott" Date: Thu, 1 Aug 2024 15:30:18 -0700 Subject: [PATCH 32/32] Adding set/get ReliabilityDomain pointer --- SRC/api/elementAPI_TCL.cpp | 7 +++++++ SRC/tcl/commands.cpp | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/SRC/api/elementAPI_TCL.cpp b/SRC/api/elementAPI_TCL.cpp index 3cd4f6e05f..a0c96a2069 100644 --- a/SRC/api/elementAPI_TCL.cpp +++ b/SRC/api/elementAPI_TCL.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -1297,6 +1298,12 @@ OPS_GetReliabilityDomain(void) return theReliabilityDomain; } +void +OPS_SetReliabilityDomain(ReliabilityDomain *theDomain) +{ + theReliabilityDomain = theDomain; +} + void TCL_OPS_setModelBuilder(TclModelBuilder* theNewBuilder) { diff --git a/SRC/tcl/commands.cpp b/SRC/tcl/commands.cpp index f3458b038e..84870f6d61 100644 --- a/SRC/tcl/commands.cpp +++ b/SRC/tcl/commands.cpp @@ -259,6 +259,8 @@ extern int OPS_DomainModalProperties(void); extern int OPS_ResponseSpectrumAnalysis(void); extern int OPS_sdfResponse(void); +extern void OPS_SetReliabilityDomain(ReliabilityDomain *); + #include #include #include @@ -1285,6 +1287,11 @@ reliability(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv if (theReliabilityBuilder == 0) { theReliabilityBuilder = new TclReliabilityBuilder(theDomain,interp); + if (theReliabilityBuilder == 0) { + opserr << "Failed to create reliability domain" << endln; + return TCL_ERROR; + } + OPS_SetReliabilityDomain(theReliabilityBuilder->getReliabilityDomain()); return TCL_OK; } else @@ -1297,6 +1304,7 @@ wipeReliability(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char ** { if (theReliabilityBuilder != 0) { delete theReliabilityBuilder; + OPS_SetReliabilityDomain(0); theReliabilityBuilder = 0; } return TCL_OK;