TclReliabilityBuilder.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 2001, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** Reliability module developed by:                                   **
00020 **   Terje Haukaas (haukaas@ce.berkeley.edu)                          **
00021 **   Armen Der Kiureghian (adk@ce.berkeley.edu)                       **
00022 **                                                                    **
00023 ** ****************************************************************** */
00024                                                                         
00025 // $Revision: 1.17 $
00026 // $Date: 2006/09/05 23:15:02 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/tcl/TclReliabilityBuilder.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu) 
00032 //
00033 
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <fstream>
00037 #include <iomanip>
00038 #include <iostream>
00039 using std::ifstream;
00040 using std::ios;
00041 using std::setw;
00042 using std::setprecision;
00043 using std::setiosflags;
00044 
00045 #include <Matrix.h>
00046 #include <Vector.h>
00047 #include <ID.h>
00048 #include <ArrayOfTaggedObjects.h>
00049 
00050 #include <Domain.h>
00051 
00052 #include <ReliabilityDomain.h>
00053 #include <RandomVariable.h>
00054 #include <CorrelationCoefficient.h>
00055 #include <LimitStateFunction.h>
00056 #include <RandomVariablePositioner.h>
00057 #include <ParameterPositioner.h>
00058 #include <NormalRV.h>
00059 #include <LognormalRV.h>
00060 #include <GammaRV.h>
00061 #include <ShiftedExponentialRV.h>
00062 #include <ShiftedRayleighRV.h>
00063 #include <ExponentialRV.h>
00064 #include <RayleighRV.h>
00065 #include <UniformRV.h>
00066 #include <BetaRV.h>
00067 #include <Type1LargestValueRV.h>
00068 #include <Type1SmallestValueRV.h>
00069 #include <Type2LargestValueRV.h>
00070 #include <Type3SmallestValueRV.h>
00071 #include <ChiSquareRV.h>
00072 #include <GumbelRV.h>
00073 #include <WeibullRV.h>
00074 #include <UserDefinedRV.h>
00075 #include <LaplaceRV.h>
00076 #include <ParetoRV.h>
00077 #include <GFunEvaluator.h>
00078 #include <GradGEvaluator.h>
00079 #include <StepSizeRule.h>
00080 #include <SearchDirection.h>
00081 #include <ProbabilityTransformation.h>
00082 #include <NatafProbabilityTransformation.h>
00083 #include <FindDesignPointAlgorithm.h>
00084 #include <ReliabilityAnalysis.h>
00085 #include <HLRFSearchDirection.h>
00086 #include <ArmijoStepSizeRule.h>
00087 #include <FixedStepSizeRule.h>
00088 #include <OpenSeesGFunEvaluator.h>
00089 #include <OpenSeesGradGEvaluator.h>
00090 #include <BasicGFunEvaluator.h>
00091 #include <TclGFunEvaluator.h>
00092 #include <FiniteDifferenceGradGEvaluator.h>
00093 #include <SearchWithStepSizeAndStepDirection.h>
00094 #include <FORMAnalysis.h>
00095 #include <FOSMAnalysis.h>
00096 #include <ParametricReliabilityAnalysis.h>
00097 #include <GFunVisualizationAnalysis.h>
00098 #include <OutCrossingAnalysis.h>
00099 #include <SamplingAnalysis.h>
00100 #include <RandomNumberGenerator.h>
00101 #include <CStdLibRandGenerator.h>
00102 #include <FindCurvatures.h>
00103 #include <FirstPrincipalCurvature.h>
00104 #include <CurvaturesBySearchAlgorithm.h>
00105 #include <SORMAnalysis.h>
00106 #include <SystemAnalysis.h>
00107 #include <Filter.h>
00108 #include <KooFilter.h>
00109 #include <StandardLinearOscillatorDisplacementFilter.h>
00110 #include <StandardLinearOscillatorVelocityFilter.h>
00111 #include <StandardLinearOscillatorAccelerationFilter.h>
00112 #include <ModulatingFunction.h>
00113 #include <GammaModulatingFunction.h>
00114 #include <ConstantModulatingFunction.h>
00115 #include <TrapezoidalModulatingFunction.h>
00116 #include <KooModulatingFunction.h>
00117 #include <Spectrum.h>
00118 #include <JonswapSpectrum.h>
00119 #include <NarrowBandSpectrum.h>
00120 #include <PointsSpectrum.h>
00121 #include <SensitivityAlgorithm.h>
00122 #include <ReliabilityConvergenceCheck.h>
00123 #include <StandardReliabilityConvergenceCheck.h>
00124 #include <OptimalityConditionReliabilityConvergenceCheck.h>
00125 #include <MeritFunctionCheck.h>
00126 #include <AdkZhangMeritFunctionCheck.h>
00127 #include <PolakHeSearchDirectionAndMeritFunction.h>
00128 #include <SQPsearchDirectionMeritFunctionAndHessian.h>
00129 #include <HessianApproximation.h>
00130 #include <GradientProjectionSearchDirection.h>
00131 #include <RootFinding.h>
00132 #include <SecantRootFinding.h>
00133 
00134 
00135 #include <TclReliabilityBuilder.h>
00136 extern SensitivityAlgorithm *theSensitivityAlgorithm;
00137 
00138 //
00139 // SOME STATIC POINTERS USED IN THE FUNCTIONS INVOKED BY THE INTERPRETER
00140 //
00141 ReliabilityDomain *theReliabilityDomain = 0;
00142 static Domain *theStructuralDomain = 0;
00143 
00144 static GFunEvaluator *theGFunEvaluator = 0;
00145 static GradGEvaluator *theGradGEvaluator = 0;
00146 static StepSizeRule *theStepSizeRule = 0;
00147 static SearchDirection *theSearchDirection = 0;
00148 static HessianApproximation *theHessianApproximation = 0;
00149 static MeritFunctionCheck *theMeritFunctionCheck = 0;
00150 static PolakHeSearchDirectionAndMeritFunction *thePolakHeDualPurpose = 0;
00151 static SQPsearchDirectionMeritFunctionAndHessian *theSQPtriplePurpose = 0;
00152 static ProbabilityTransformation *theProbabilityTransformation = 0;
00153 static ReliabilityConvergenceCheck *theReliabilityConvergenceCheck = 0;
00154 static Vector *theStartPoint = 0;
00155 static RootFinding *theRootFindingAlgorithm = 0;
00156 RandomNumberGenerator *theRandomNumberGenerator = 0;
00157 static FindDesignPointAlgorithm *theFindDesignPointAlgorithm = 0;
00158 static FindCurvatures *theFindCurvatures = 0;
00159 static GFunVisualizationAnalysis *theGFunVisualizationAnalysis = 0;
00160 static FORMAnalysis *theFORMAnalysis = 0;
00161 static FOSMAnalysis *theFOSMAnalysis = 0;
00162 static ParametricReliabilityAnalysis *theParametricReliabilityAnalysis = 0;
00163 static OutCrossingAnalysis *theOutCrossingAnalysis = 0;
00164 static SORMAnalysis *theSORMAnalysis = 0;
00165 static SamplingAnalysis *theSamplingAnalysis = 0;
00166 static SystemAnalysis *theSystemAnalysis = 0;
00167 
00168 // 
00169 // THE PROTOTYPES OF THE FUNCTIONS INVOKED BY THE INTERPRETER
00170 //
00171 int TclReliabilityModelBuilder_addRandomVariable(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00172 int TclReliabilityModelBuilder_addCorrelate(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00173 int TclReliabilityModelBuilder_correlateGroup(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00174 int TclReliabilityModelBuilder_correlationStructure(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00175 int TclReliabilityModelBuilder_addLimitState(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00176 int TclReliabilityModelBuilder_addRandomVariablePositioner(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00177 int TclReliabilityModelBuilder_addParameterPositioner(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00178 int TclReliabilityModelBuilder_addModulatingFunction(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00179 int TclReliabilityModelBuilder_addFilter(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00180 int TclReliabilityModelBuilder_addSpectrum(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00181 int TclReliabilityModelBuilder_addProbabilityTransformation(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00182 int TclReliabilityModelBuilder_addStartPoint(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00183 int TclReliabilityModelBuilder_addRootFinding(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00184 int TclReliabilityModelBuilder_addRandomNumberGenerator(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00185 int TclReliabilityModelBuilder_addSearchDirection(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00186 int TclReliabilityModelBuilder_addHessianApproximation(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00187 int TclReliabilityModelBuilder_addMeritFunctionCheck(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00188 int TclReliabilityModelBuilder_addReliabilityConvergenceCheck(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00189 int TclReliabilityModelBuilder_addStepSizeRule(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00190 int TclReliabilityModelBuilder_addgFunEvaluator(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00191 int TclReliabilityModelBuilder_addGradGEvaluator(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00192 int TclReliabilityModelBuilder_addFindDesignPointAlgorithm(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00193 int TclReliabilityModelBuilder_addFindCurvatures(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00194 int TclReliabilityModelBuilder_runFORMAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00195 int TclReliabilityModelBuilder_runFOSMAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00196 int TclReliabilityModelBuilder_runParametricReliabilityAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00197 int TclReliabilityModelBuilder_runGFunVisualizationAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00198 int TclReliabilityModelBuilder_runOutCrossingAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00199 int TclReliabilityModelBuilder_runSORMAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00200 int TclReliabilityModelBuilder_runSystemAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00201 int TclReliabilityModelBuilder_runSamplingAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00202 int TclReliabilityModelBuilder_tempCommand(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00203 int TclReliabilityModelBuilder_inputCheck(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00204 int TclReliabilityModelBuilder_getMean(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00205 int TclReliabilityModelBuilder_getStdv(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00206 int TclReliabilityModelBuilder_rvReduction(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv);
00207 
00208 
00209 
00210 //
00211 // CLASS CONSTRUCTOR & DESTRUCTOR
00212 //
00213 
00214 // constructor: the constructor will add certain commands to the interpreter
00215 TclReliabilityBuilder::TclReliabilityBuilder(Domain &passedDomain, Tcl_Interp *interp)
00216 {
00217   // Set the interpreter (the destructor needs it to delete commands)
00218   // Well... not any more. 
00219   theInterp = interp;
00220 
00221   // call Tcl_CreateCommand for class specific commands
00222   Tcl_CreateCommand(interp, "randomVariable",   TclReliabilityModelBuilder_addRandomVariable,(ClientData)NULL, NULL);
00223   Tcl_CreateCommand(interp, "correlate", TclReliabilityModelBuilder_addCorrelate,(ClientData)NULL, NULL); 
00224   Tcl_CreateCommand(interp, "correlateGroup", TclReliabilityModelBuilder_correlateGroup,(ClientData)NULL, NULL); 
00225   Tcl_CreateCommand(interp, "correlationStructure", TclReliabilityModelBuilder_correlationStructure,(ClientData)NULL, NULL); 
00226   Tcl_CreateCommand(interp, "performanceFunction", TclReliabilityModelBuilder_addLimitState,(ClientData)NULL, NULL);
00227   Tcl_CreateCommand(interp, "randomVariablePositioner",TclReliabilityModelBuilder_addRandomVariablePositioner,(ClientData)NULL, NULL);
00228   Tcl_CreateCommand(interp, "parameterPositioner",TclReliabilityModelBuilder_addParameterPositioner,(ClientData)NULL, NULL);
00229   Tcl_CreateCommand(interp, "modulatingFunction",TclReliabilityModelBuilder_addModulatingFunction,(ClientData)NULL, NULL);
00230   Tcl_CreateCommand(interp, "filter",TclReliabilityModelBuilder_addFilter,(ClientData)NULL, NULL);
00231   Tcl_CreateCommand(interp, "spectrum",TclReliabilityModelBuilder_addSpectrum,(ClientData)NULL, NULL);
00232   Tcl_CreateCommand(interp, "findDesignPoint",  TclReliabilityModelBuilder_addFindDesignPointAlgorithm,(ClientData)NULL, NULL);
00233   Tcl_CreateCommand(interp, "startPoint",       TclReliabilityModelBuilder_addStartPoint,(ClientData)NULL, NULL);
00234   Tcl_CreateCommand(interp, "rootFinding",      TclReliabilityModelBuilder_addRootFinding,(ClientData)NULL, NULL);
00235   Tcl_CreateCommand(interp, "gFunEvaluator",    TclReliabilityModelBuilder_addgFunEvaluator,(ClientData)NULL, NULL);
00236   Tcl_CreateCommand(interp, "gradGEvaluator",TclReliabilityModelBuilder_addGradGEvaluator,(ClientData)NULL, NULL);
00237   Tcl_CreateCommand(interp, "stepSizeRule",TclReliabilityModelBuilder_addStepSizeRule,(ClientData)NULL, NULL);
00238   Tcl_CreateCommand(interp, "searchDirection",  TclReliabilityModelBuilder_addSearchDirection,(ClientData)NULL, NULL);
00239   Tcl_CreateCommand(interp, "HessianApproximation",     TclReliabilityModelBuilder_addHessianApproximation,(ClientData)NULL, NULL);
00240   Tcl_CreateCommand(interp, "meritFunctionCheck",       TclReliabilityModelBuilder_addMeritFunctionCheck,(ClientData)NULL, NULL);
00241   Tcl_CreateCommand(interp, "reliabilityConvergenceCheck",      TclReliabilityModelBuilder_addReliabilityConvergenceCheck,(ClientData)NULL, NULL);
00242   Tcl_CreateCommand(interp, "probabilityTransformation",        TclReliabilityModelBuilder_addProbabilityTransformation,(ClientData)NULL, NULL);
00243   Tcl_CreateCommand(interp, "findCurvatures",   TclReliabilityModelBuilder_addFindCurvatures,(ClientData)NULL, NULL);
00244   Tcl_CreateCommand(interp, "randomNumberGenerator",TclReliabilityModelBuilder_addRandomNumberGenerator,(ClientData)NULL, NULL);
00245   Tcl_CreateCommand(interp, "runFORMAnalysis",TclReliabilityModelBuilder_runFORMAnalysis,(ClientData)NULL, NULL);
00246   Tcl_CreateCommand(interp, "runFOSMAnalysis",TclReliabilityModelBuilder_runFOSMAnalysis,(ClientData)NULL, NULL);
00247   Tcl_CreateCommand(interp, "runParametricReliabilityAnalysis",TclReliabilityModelBuilder_runParametricReliabilityAnalysis,(ClientData)NULL, NULL);
00248   Tcl_CreateCommand(interp, "runGFunVizAnalysis",TclReliabilityModelBuilder_runGFunVisualizationAnalysis,(ClientData)NULL, NULL);
00249   Tcl_CreateCommand(interp, "runOutCrossingAnalysis",TclReliabilityModelBuilder_runOutCrossingAnalysis,(ClientData)NULL, NULL);
00250   Tcl_CreateCommand(interp, "runSORMAnalysis",TclReliabilityModelBuilder_runSORMAnalysis,(ClientData)NULL, NULL);
00251   Tcl_CreateCommand(interp, "runSystemAnalysis",TclReliabilityModelBuilder_runSystemAnalysis,(ClientData)NULL, NULL);
00252   Tcl_CreateCommand(interp, "runSamplingAnalysis",TclReliabilityModelBuilder_runSamplingAnalysis,(ClientData)NULL, NULL);
00253   Tcl_CreateCommand(interp, "tempCommand",TclReliabilityModelBuilder_tempCommand,(ClientData)NULL, NULL);
00254   Tcl_CreateCommand(interp, "inputCheck",TclReliabilityModelBuilder_inputCheck,(ClientData)NULL, NULL);
00255   Tcl_CreateCommand(interp, "getMean",TclReliabilityModelBuilder_getMean,(ClientData)NULL, NULL);
00256   Tcl_CreateCommand(interp, "getStdv",TclReliabilityModelBuilder_getStdv,(ClientData)NULL, NULL);
00257   Tcl_CreateCommand(interp, "rvReduction",TclReliabilityModelBuilder_rvReduction,(ClientData)NULL, NULL);
00258 
00259 
00260   // set the static pointers in this file
00261   theStructuralDomain   = &passedDomain;
00262   theReliabilityDomain  = new ReliabilityDomain();
00263 
00264 
00265 }
00266 
00267 TclReliabilityBuilder::~TclReliabilityBuilder()
00268 {
00269   // Delete objects
00270   if (theReliabilityDomain != 0) 
00271     delete theReliabilityDomain;
00272   if (theGFunEvaluator != 0)
00273     delete theGFunEvaluator;
00274   if (theGradGEvaluator != 0)
00275     delete theGradGEvaluator;
00276   if (theStepSizeRule != 0)
00277     delete theStepSizeRule;
00278   if (theSearchDirection != 0)
00279     delete theSearchDirection;
00280   if (theHessianApproximation != 0)
00281     delete theHessianApproximation;
00282   if (thePolakHeDualPurpose != 0)
00283     delete thePolakHeDualPurpose;
00284   if (theSQPtriplePurpose != 0)
00285     delete theSQPtriplePurpose;
00286   if (theMeritFunctionCheck != 0)
00287     delete theMeritFunctionCheck;
00288   if (theReliabilityConvergenceCheck != 0)
00289     delete theReliabilityConvergenceCheck;
00290   if (theProbabilityTransformation != 0)
00291     delete theProbabilityTransformation;
00292   if (theStartPoint != 0)
00293     delete theStartPoint;
00294   if (theRootFindingAlgorithm != 0)
00295     delete theRootFindingAlgorithm;
00296   if (theRandomNumberGenerator != 0)
00297     delete theRandomNumberGenerator;
00298   if (theFindDesignPointAlgorithm != 0)
00299     delete theFindDesignPointAlgorithm;
00300   if (theFindCurvatures != 0)
00301     delete theFindCurvatures;
00302   if (theFORMAnalysis != 0)
00303     delete theFORMAnalysis;
00304   if (theFOSMAnalysis != 0)
00305     delete theFOSMAnalysis;
00306   if (theParametricReliabilityAnalysis != 0)
00307     delete theParametricReliabilityAnalysis;
00308   if (theSORMAnalysis != 0)
00309     delete theSORMAnalysis;
00310   if (theSamplingAnalysis != 0)
00311     delete theSamplingAnalysis;
00312   if (theSystemAnalysis != 0)
00313     delete theSystemAnalysis;
00314 
00315 
00316   theReliabilityDomain = 0;
00317   theReliabilityDomain =0;
00318   theGFunEvaluator =0;
00319   theGradGEvaluator =0;
00320   theStepSizeRule =0;
00321   theSearchDirection =0;
00322   theHessianApproximation =0;
00323   thePolakHeDualPurpose =0;
00324   theSQPtriplePurpose =0;
00325   theMeritFunctionCheck =0;
00326   theReliabilityConvergenceCheck =0;
00327   theProbabilityTransformation =0;
00328   theStartPoint =0;
00329   theRootFindingAlgorithm =0;
00330   theRandomNumberGenerator =0;
00331   theFindDesignPointAlgorithm =0;
00332   theFindCurvatures =0;
00333   theFORMAnalysis =0;
00334   theFOSMAnalysis =0;
00335   theParametricReliabilityAnalysis =0;
00336   theSORMAnalysis =0;
00337   theSamplingAnalysis =0;
00338   theSystemAnalysis =0;
00339 
00340 
00341         // Delete commands
00342         Tcl_DeleteCommand(theInterp, "randomVariable");
00343         Tcl_DeleteCommand(theInterp, "correlate");
00344         Tcl_DeleteCommand(theInterp, "correlateGroup");
00345         Tcl_DeleteCommand(theInterp, "correlationStructure");
00346         Tcl_DeleteCommand(theInterp, "limitState");
00347         Tcl_DeleteCommand(theInterp, "randomVariablePositioner");
00348         Tcl_DeleteCommand(theInterp, "positionerPositioner");
00349         Tcl_DeleteCommand(theInterp, "modulatingFunction");
00350         Tcl_DeleteCommand(theInterp, "filter");
00351         Tcl_DeleteCommand(theInterp, "spectrum");
00352         Tcl_DeleteCommand(theInterp, "findDesignPoint");
00353         Tcl_DeleteCommand(theInterp, "gFunEvaluator");
00354         Tcl_DeleteCommand(theInterp, "GradGEvaluator");
00355         Tcl_DeleteCommand(theInterp, "stepSizeRule");
00356         Tcl_DeleteCommand(theInterp, "searchDirection");
00357         Tcl_DeleteCommand(theInterp, "HessianApproximation");
00358         Tcl_DeleteCommand(theInterp, "meritFunctionCheck");
00359         Tcl_DeleteCommand(theInterp, "reliabilityConvergenceCheck");
00360         Tcl_DeleteCommand(theInterp, "ProbabilityTransformation");
00361         Tcl_DeleteCommand(theInterp, "startPoint");
00362         Tcl_DeleteCommand(theInterp, "rootFinding");
00363         Tcl_DeleteCommand(theInterp, "findCurvatures");
00364         Tcl_DeleteCommand(theInterp, "randomNumberGenerator");
00365         Tcl_DeleteCommand(theInterp, "runFORMAnalysis");
00366         Tcl_DeleteCommand(theInterp, "runFOSMAnalysis");
00367         Tcl_DeleteCommand(theInterp, "runParametricReliabilityAnalysis");
00368         Tcl_DeleteCommand(theInterp, "runGFunVizAnalysis");
00369         Tcl_DeleteCommand(theInterp, "runSORMAnalysis");
00370         Tcl_DeleteCommand(theInterp, "runSystemAnalysis");
00371         Tcl_DeleteCommand(theInterp, "runSamplingAnalysis");
00372         Tcl_DeleteCommand(theInterp, "tempCommand");
00373         Tcl_DeleteCommand(theInterp, "inputCheck");
00374         Tcl_DeleteCommand(theInterp, "getMean");
00375         Tcl_DeleteCommand(theInterp, "getStdv");
00376 }
00377 
00378 
00379 //
00380 // CLASS METHODS
00381 //
00382 
00383 
00384 ReliabilityDomain *
00385 TclReliabilityBuilder::getReliabilityDomain()
00386 {
00387         return theReliabilityDomain;
00388 }
00389 
00391 int 
00392 TclReliabilityModelBuilder_addRandomVariable(ClientData clientData,Tcl_Interp *interp,int argc,TCL_Char **argv)
00393 {
00394   RandomVariable *theRandomVariable = 0;
00395   int tag;
00396   double mean;
00397   double stdv;
00398   double startPt;
00399   double parameter1;
00400   double parameter2;
00401   double parameter3;
00402   double parameter4;
00403   int numberOfArguments = argc;
00404 
00405 
00406   // CHECK THAT AT LEAST ENOUGH ARGUMENTS ARE GIVEN
00407   if (numberOfArguments < 5) {
00408                 opserr << "ERROR: invalid number of arguments to randomVariable command \n";
00409                 return TCL_ERROR;
00410   }
00411 
00412 
00413   // CHECK THAT THE USER HAS PROVIDED A TYPE
00414   if ((strcmp(argv[2],"beta")                           == 0) ||
00415           (strcmp(argv[2],"chiSquare")                  == 0) ||
00416           (strcmp(argv[2],"exponential")                == 0) ||
00417           (strcmp(argv[2],"gamma")                              == 0) ||
00418           (strcmp(argv[2],"gumbel")                             == 0) ||
00419           (strcmp(argv[2],"laplace")                    == 0) ||
00420           (strcmp(argv[2],"lognormal")                  == 0) ||
00421           (strcmp(argv[2],"normal")                             == 0) ||
00422       (strcmp(argv[2],"pareto")                         == 0) || 
00423           (strcmp(argv[2],"rayleigh")                   == 0) ||          
00424           (strcmp(argv[2],"shiftedExponential") == 0) ||
00425           (strcmp(argv[2],"shiftedRayleigh")    == 0) ||
00426           (strcmp(argv[2],"type1LargestValue")  == 0) ||
00427           (strcmp(argv[2],"type1SmallestValue") == 0) ||
00428           (strcmp(argv[2],"type2LargestValue")  == 0) ||
00429           (strcmp(argv[2],"type3SmallestValue") == 0) ||
00430           (strcmp(argv[2],"uniform")                    == 0) ||
00431           (strcmp(argv[2],"userdefined")                == 0) ||
00432           (strcmp(argv[2],"weibull")                    == 0) 
00433          ) 
00434   {
00435   }
00436   else {
00437           opserr << "ERROR: A correct type has not been provided for a random variable." << endln
00438                   << " (Available types: normal, lognormal, uniform, etc.)" << endln
00439                   << " Syntax: randomVariable tag? type mean? stdv? <startPt?>" << endln
00440                   << "     or: randomVariable tag? type par1? par2? par3? par4? <startPt?>" << endln;
00441           return TCL_ERROR;
00442   }
00443 
00444 
00445   // GET TAG NUMBER
00446   if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
00447         opserr << "ERROR: invalid input: tag \n";
00448         return TCL_ERROR;
00449   }
00450 
00451 
00452   // TREAT THE USER-DEFINED RANDOM VARIABLE AS A SPECIAL CASE
00453   if (strcmp(argv[2],"userdefined") == 0) {
00454 
00455                 Vector xPoints;
00456                 Vector PDFpoints;
00457                 int numPoints;
00458                 int i;
00459 
00460                 if (strcmp(argv[3],"-list") == 0) {
00461 
00462                         numPoints = floor((argc-4)/2.0);
00463                         Vector temp_xPoints(numPoints);
00464                         Vector temp_PDFpoints(numPoints);
00465 
00466                         double x = 0.0;
00467                         double pdf = 0.0;
00468                         double x_old;
00469 
00470                         // Read the points
00471                         for (i=0; i<numPoints; i++) {
00472                           if (Tcl_GetDouble(interp, argv[4+2*i], &x) != TCL_OK) {
00473                                   opserr << "ERROR: Invalid x point to user-defined random variable." << endln;
00474                                   return TCL_ERROR;
00475                           }
00476                           if (Tcl_GetDouble(interp, argv[5+2*i], &pdf) != TCL_OK) {
00477                                   opserr << "ERROR: Invalid PDF value point to user-defined random variable." << endln;
00478                                   return TCL_ERROR;
00479                           }
00480                           if (i>0 && x<=x_old) {
00481                                   opserr << "ERROR: x-points to user-defined random variable must be consequtive!" << endln;
00482                                   return TCL_ERROR;
00483                           }
00484                           temp_xPoints(i) = x;
00485                           temp_PDFpoints(i) = pdf;
00486                           x_old = x;
00487                         }
00488 
00489                         xPoints = temp_xPoints;
00490                         PDFpoints = temp_PDFpoints;
00491                 
00492                 }
00493                 else if (strcmp(argv[3],"-file") == 0) {
00494 
00495                         // Open file where the vectors are given
00496                         ifstream inputFile( argv[4], ios::in );
00497                         if (inputFile.fail()) {
00498                                 opserr << "File " << *argv[4] << " could not be opened. " << endln;
00499                                 return TCL_ERROR;
00500                         }
00501 
00502                         // Loop through file to see how many entries there are
00503                         double dummy;
00504                         numPoints = 0;
00505                         while (inputFile >> dummy) {
00506                                 inputFile >> dummy;
00507                                 numPoints++;
00508                         }
00509                         if (numPoints == 0) {
00510                                 opserr << "ERROR: No entries in the direction file read by " << endln
00511                                         << "user-defined random variable, number " << tag << endln;
00512                                 return TCL_ERROR;
00513                         }
00514 
00515                         // Close the file
00516                         inputFile.close();
00517 
00518                         // Allocate vectors of correct size
00519                         Vector temp_xPoints(numPoints);
00520                         Vector temp_PDFpoints(numPoints);
00521 
00522                         // Open it again, now being ready to store the results in a matrix
00523                         ifstream inputFile2( argv[4], ios::in );
00524                         if (inputFile2.fail()) {
00525                                 opserr << "File " << *argv[4] << " could not be opened. " << endln;
00526                                 return TCL_ERROR;
00527                         }
00528 
00529                         // Store the vector
00530                         for (int i=0; i<numPoints; i++) {
00531                                         inputFile2 >> temp_xPoints(i);
00532                                         inputFile2 >> temp_PDFpoints(i);
00533                         }
00534                         inputFile2.close();
00535 
00536                         xPoints = temp_xPoints;
00537                         PDFpoints = temp_PDFpoints;
00538                 }
00539                 else {
00540                         opserr << "ERROR: Invalid argument to user-defined random variable, number " << tag << endln;
00541                         return TCL_ERROR;
00542                 }
00543           
00544         
00545           // Normalize the PDF
00546           double sum = 0.0;
00547           for ( i=1; i<numPoints; i++ ) {
00548                   sum += 0.5 * (PDFpoints(i)+PDFpoints(i-1)) * (xPoints(i)-xPoints(i-1));
00549           }
00550           double diff;
00551           if ( fabs(sum-1.0) < 1.0e-6) {
00552                   // It's normalized enough...!
00553           }
00554           else if (sum < 1.0) {
00555                   diff = (1.0-sum)/(xPoints(numPoints-1)-xPoints(0));
00556                   opserr << "WARNING: The PDF of random variable " << tag << " is normalized by " << endln
00557                              << "         uniformly increasing the PDF values by " << diff << endln;
00558                   for (int i=0; i<numPoints; i++) {
00559                           PDFpoints(i) = PDFpoints(i) + diff;
00560                   }
00561           }
00562           else {
00563                   diff = (sum-1.0)/(xPoints(numPoints-1)-xPoints(0));
00564                   opserr << "WARNING: The PDF of random variable " << tag << " is normalized by " << endln
00565                              << "         uniformly decreasing the PDF values by " << diff << endln;
00566                   for (int i=0; i<numPoints; i++) {
00567                           PDFpoints(i) = PDFpoints(i) - diff;
00568                   }
00569           }
00570 
00571           // Check if the PDF became negative somewhere
00572           for (i=0; i<numPoints; i++) {
00573                   if ( PDFpoints(i) < 0.0 ) {
00574                           opserr << "ERROR: Some PDF values of random variable " << tag << endln
00575                                   << "became negative after normalization. " << endln;
00576                           return TCL_ERROR;
00577                   }
00578           }
00579 
00580           // Check that it has been normalized
00581           sum = 0.0;
00582           for ( i=1; i<numPoints; i++ ) {
00583                   sum += 0.5 * (PDFpoints(i)+PDFpoints(i-1)) * (xPoints(i)-xPoints(i-1));
00584           }
00585       if ( fabs(1.0-sum) > 1.0e-6 ) {
00586                   opserr << "ERROR: Did not succeed in normalizing user-defined distribution." << endln;
00587                   return TCL_ERROR;
00588           }
00589 
00590 
00591 //        // Check if the user has given a start point too, and create the random variables
00592 //        if ( floor((argc-4)/2.0) != (argc-4)/2.0 ) {
00593 //        
00594 //                double startPt = 0.0;
00595 //                if (Tcl_GetDouble(interp, argv[5], &startPt) != TCL_OK) {
00596 //                        opserr << "ERROR: Invalid start point to user-defined random variable." << endln;
00597 //                        return TCL_ERROR;
00598 //                }
00599 //
00600 //                theRandomVariable = new UserDefinedRV(tag, xPoints, PDFpoints, startPt);
00601 //        }
00602 //        else {
00603 
00604                   theRandomVariable = new UserDefinedRV(tag, xPoints, PDFpoints);
00605 //        }
00606 
00607           // Add the random variable to the domain
00608           if (theReliabilityDomain->addRandomVariable(theRandomVariable) == false) {
00609                 opserr << "ERROR: failed to add random variable to the domain (wrong number of arguments?)\n";
00610                 opserr << "random variable: " << tag << endln;
00611                 delete theRandomVariable; // otherwise memory leak
00612                 return TCL_ERROR;
00613           }
00614           else {
00615                   return TCL_OK;
00616           }
00617 
00618   }
00619 
00620 
00621 
00622 
00623   // NOW START CREATING THE RANDOM VARIBLE OBJECT
00624   if (numberOfArguments==5)  {   // (Use mean/stdv WITHOUT startPt)
00625 
00626           // GET INPUT PARAMETER (double)
00627           if (Tcl_GetDouble(interp, argv[3], &mean) != TCL_OK) {
00628                 opserr << "ERROR: invalid input: mean \n";
00629                 return TCL_ERROR;
00630           }
00631 
00632           // GET INPUT PARAMETER (double)
00633           if (Tcl_GetDouble(interp, argv[4], &stdv) != TCL_OK) {
00634                 opserr << "ERROR: invalid input: stdv \n";
00635                 return TCL_ERROR;
00636           }
00637 
00638           // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
00639           if (strcmp(argv[2],"normal") == 0) {
00640                   if (stdv <= 0.0) {
00641                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00642                           return TCL_ERROR;
00643                   }
00644                   else {
00645                         theRandomVariable = new NormalRV(tag, mean, stdv);
00646                   }
00647           }
00648           else if (strcmp(argv[2],"lognormal") == 0) {
00649                   if (mean == 0.0 || stdv <= 0.0) {
00650                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00651                           return TCL_ERROR;
00652                   }
00653                   else {
00654                           theRandomVariable = new LognormalRV(tag, mean, stdv);
00655                   }
00656           }
00657           else if (strcmp(argv[2],"gamma") == 0) {
00658                   if ( stdv <= 0.0 ) {
00659                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00660                           return TCL_ERROR;
00661                   }
00662                   else {
00663                           theRandomVariable = new GammaRV(tag, mean, stdv);
00664                   }
00665           }
00666           else if (strcmp(argv[2],"shiftedExponential") == 0) {
00667                   if ( stdv <= 0.0 ) {
00668                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00669                           return TCL_ERROR;
00670                   }
00671                   else {
00672                         theRandomVariable = new ShiftedExponentialRV(tag, mean, stdv);
00673                   }
00674           }
00675           else if (strcmp(argv[2],"shiftedRayleigh") == 0) {
00676                   if ( stdv <= 0.0 ) {
00677                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00678                           return TCL_ERROR;
00679                   }
00680                   else {
00681                         theRandomVariable = new ShiftedRayleighRV(tag, mean, stdv);
00682                   }
00683           }
00684           else if (strcmp(argv[2],"exponential") == 0) {
00685                   if ( stdv <= 0.0 ) {
00686                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00687                           return TCL_ERROR;
00688                   }
00689                   else {
00690                         theRandomVariable = new ExponentialRV(tag, mean, stdv);
00691                   }
00692           }
00693           else if (strcmp(argv[2],"rayleigh") == 0) {
00694                   opserr << "Random variable with tag " << tag << "cannot be created with only mean/stdv." << endln;
00695                   return TCL_ERROR;
00696           }
00697           else if (strcmp(argv[2],"uniform") == 0) {
00698                   if ( stdv <= 0.0 ) {
00699                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00700                           return TCL_ERROR;
00701                   }
00702                   else {
00703                         theRandomVariable = new UniformRV(tag, mean, stdv);
00704                   }
00705           }
00706           else if (strcmp(argv[2],"beta") == 0) {
00707                   opserr << "ERROR:: 'Beta' type random variable: use parameters to create!\n";
00708                   return TCL_ERROR;
00709           }
00710           else if (strcmp(argv[2],"type1LargestValue") == 0) {
00711                   if ( stdv <= 0.0 ) {
00712                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00713                           return TCL_ERROR;
00714                   }
00715                   else {
00716                         theRandomVariable = new Type1LargestValueRV(tag, mean, stdv);
00717                   }
00718           }
00719           else if (strcmp(argv[2],"type1SmallestValue") == 0) {
00720                   if ( stdv <= 0.0 ) {
00721                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00722                           return TCL_ERROR;
00723                   }
00724                   else {
00725                         theRandomVariable = new Type1SmallestValueRV(tag, mean, stdv);
00726                   }
00727           }
00728           else if (strcmp(argv[2],"type2LargestValue") == 0) {
00729                   if ( stdv <= 0.0 ) {
00730                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00731                           return TCL_ERROR;
00732                   }
00733                   else {
00734                         theRandomVariable = new Type2LargestValueRV(tag, mean, stdv);
00735                   }
00736           }
00737           else if (strcmp(argv[2],"type3SmallestValue") == 0) {
00738                   if ( stdv <= 0.0 ) {
00739                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00740                           return TCL_ERROR;
00741                   }
00742                   else {
00743                         theRandomVariable = new Type3SmallestValueRV(tag, mean, stdv);
00744                   }
00745           }
00746           else if (strcmp(argv[2],"chiSquare") == 0) {
00747                   if ( stdv <= 0.0 ) {
00748                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00749                           return TCL_ERROR;
00750                   }
00751                   else {
00752                         theRandomVariable = new ChiSquareRV(tag, mean, stdv);
00753                   }
00754           }
00755           else if (strcmp(argv[2],"gumbel") == 0) {
00756                   if ( stdv <= 0.0 ) {
00757                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00758                           return TCL_ERROR;
00759                   }
00760                   else {
00761                         theRandomVariable = new GumbelRV(tag, mean, stdv);
00762                   }
00763           }
00764           else if (strcmp(argv[2],"weibull") == 0) {
00765                   if ( stdv <= 0.0 ) {
00766                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00767                           return TCL_ERROR;
00768                   }
00769                   else {
00770                         theRandomVariable = new WeibullRV(tag, mean, stdv);
00771                   }
00772           }
00773           else if (strcmp(argv[2],"laplace") == 0) {
00774                   if ( stdv <= 0.0 ) {
00775                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00776                           return TCL_ERROR;
00777                   }
00778                   else {
00779                         theRandomVariable = new LaplaceRV(tag, mean, stdv);
00780                   }
00781           }
00782           else if (strcmp(argv[2],"pareto") == 0) {
00783                   opserr << "Random variable with tag " << tag << "cannot be created with only mean/stdv." << endln;
00784                   return TCL_ERROR;
00785           }
00786           else {
00787                 opserr << "ERROR: unrecognized type of random variable number " << tag << endln;
00788                 return TCL_ERROR;
00789           }
00790 
00791           if (theRandomVariable == 0) {
00792                 opserr << "ERROR: could not create random variable number " << tag << endln;
00793                 return TCL_ERROR;
00794           }
00795   }
00796   else if (numberOfArguments==6)  {   // (Use mean/stdv AND startPt)
00797 
00798           // GET INPUT PARAMETER (double)
00799           if (Tcl_GetDouble(interp, argv[3], &mean) != TCL_OK) {
00800                 opserr << "ERROR: invalid input: mean \n";
00801                 return TCL_ERROR;
00802           }
00803 
00804           // GET INPUT PARAMETER (double)
00805           if (Tcl_GetDouble(interp, argv[4], &stdv) != TCL_OK) {
00806                 opserr << "ERROR: invalid input: stdv \n";
00807                 return TCL_ERROR;
00808           }
00809 
00810           // GET INPUT PARAMETER (double)
00811           if (Tcl_GetDouble(interp, argv[5], &startPt) != TCL_OK) {
00812                 opserr << "ERROR: invalid input: startPt \n";
00813                 return TCL_ERROR;
00814           }
00815 
00816           // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
00817           if (strcmp(argv[2],"normal") == 0) {
00818                   if (stdv <= 0.0) {
00819                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00820                           return TCL_ERROR;
00821                   }
00822                   else {
00823                         theRandomVariable = new NormalRV(tag, mean, stdv, startPt);
00824                   }
00825           }
00826           else if (strcmp(argv[2],"lognormal") == 0) {
00827                   if (mean == 0.0 || stdv <= 0.0) {
00828                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00829                           return TCL_ERROR;
00830                   }
00831                   else {
00832                           theRandomVariable = new LognormalRV(tag, mean, stdv, startPt);
00833                   }
00834           }
00835           else if (strcmp(argv[2],"gamma") == 0) {
00836                   if ( stdv <= 0.0 ) {
00837                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00838                           return TCL_ERROR;
00839                   }
00840                   else {
00841                           theRandomVariable = new GammaRV(tag, mean, stdv, startPt);
00842                   }
00843           }
00844           else if (strcmp(argv[2],"shiftedExponential") == 0) {
00845                   if ( stdv <= 0.0 ) {
00846                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00847                           return TCL_ERROR;
00848                   }
00849                   else {
00850                         theRandomVariable = new ShiftedExponentialRV(tag, mean, stdv, startPt);
00851                   }
00852           }
00853           else if (strcmp(argv[2],"shiftedRayleigh") == 0) {
00854                   if ( stdv <= 0.0 ) {
00855                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00856                           return TCL_ERROR;
00857                   }
00858                   else {
00859                         theRandomVariable = new ShiftedRayleighRV(tag, mean, stdv, startPt);
00860                   }
00861           }
00862           else if (strcmp(argv[2],"exponential") == 0) {
00863                   if ( stdv <= 0.0 ) {
00864                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00865                           return TCL_ERROR;
00866                   }
00867                   else {
00868                         theRandomVariable = new ExponentialRV(tag, mean, stdv, startPt);
00869                   }
00870           }
00871           else if (strcmp(argv[2],"rayleigh") == 0) {
00872                   opserr << "Random variable with tag " << tag << "cannot be created with only mean/stdv." << endln;
00873           }
00874           else if (strcmp(argv[2],"uniform") == 0) {
00875                   if ( stdv <= 0.0 ) {
00876                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00877                           return TCL_ERROR;
00878                   }
00879                   else {
00880                         theRandomVariable = new UniformRV(tag, mean, stdv, startPt);
00881                   }
00882           }
00883           else if (strcmp(argv[2],"beta") == 0) {
00884                   opserr << "ERROR:: 'Beta' type random variable: use parameters to create!\n";
00885                   return TCL_ERROR;
00886           }
00887           else if (strcmp(argv[2],"type1LargestValue") == 0) {
00888                   if ( stdv <= 0.0 ) {
00889                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00890                           return TCL_ERROR;
00891                   }
00892                   else {
00893                         theRandomVariable = new Type1LargestValueRV(tag, mean, stdv, startPt);
00894                   }
00895           }
00896           else if (strcmp(argv[2],"type1SmallestValue") == 0) {
00897                   if ( stdv <= 0.0 ) {
00898                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00899                           return TCL_ERROR;
00900                   }
00901                   else {
00902                         theRandomVariable = new Type1SmallestValueRV(tag, mean, stdv, startPt);
00903                   }
00904           }
00905           else if (strcmp(argv[2],"type2LargestValue") == 0) {
00906                   if ( stdv <= 0.0 ) {
00907                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00908                           return TCL_ERROR;
00909                   }
00910                   else {
00911                         theRandomVariable = new Type2LargestValueRV(tag, mean, stdv, startPt);
00912                   }
00913           }
00914           else if (strcmp(argv[2],"type3SmallestValue") == 0) {
00915                   if ( stdv <= 0.0 ) {
00916                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00917                           return TCL_ERROR;
00918                   }
00919                   else {
00920                         theRandomVariable = new Type3SmallestValueRV(tag, mean, stdv, startPt);
00921                   }
00922           }
00923           else if (strcmp(argv[2],"chiSquare") == 0) {
00924                   if ( stdv <= 0.0 ) {
00925                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00926                           return TCL_ERROR;
00927                   }
00928                   else {
00929                         theRandomVariable = new ChiSquareRV(tag, mean, stdv, startPt);
00930                   }
00931           }
00932           else if (strcmp(argv[2],"gumbel") == 0) {
00933                   if ( stdv <= 0.0 ) {
00934                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00935                           return TCL_ERROR;
00936                   }
00937                   else {
00938                         theRandomVariable = new GumbelRV(tag, mean, stdv, startPt);
00939                   }
00940           }
00941           else if (strcmp(argv[2],"weibull") == 0) {
00942                   if ( stdv <= 0.0 ) {
00943                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00944                           return TCL_ERROR;
00945                   }
00946                   else {
00947                         theRandomVariable = new WeibullRV(tag, mean, stdv, startPt);
00948                   }
00949           }
00950           else if (strcmp(argv[2],"laplace") == 0) {
00951                   if ( stdv <= 0.0 ) {
00952                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
00953                           return TCL_ERROR;
00954                   }
00955                   else {
00956                         theRandomVariable = new LaplaceRV(tag, mean, stdv, startPt);
00957                   }
00958           }
00959           else if (strcmp(argv[2],"pareto") == 0) {
00960                   opserr << "Random variable with tag " << tag << "cannot be created with only mean/stdv." << endln;
00961           }
00962           else {
00963                 opserr << "ERROR: unrecognized type of random variable number " << tag << endln;
00964                 return TCL_ERROR;
00965           }
00966 
00967           if (theRandomVariable == 0) {
00968                 opserr << "ERROR: could not create random variable number " << tag << endln;
00969                 return TCL_ERROR;
00970           }
00971   }
00972   else if (numberOfArguments==7)  {  // (Use parameters WITHOUT startPt)
00973 
00974           // GET INPUT PARAMETER (double)
00975           if (Tcl_GetDouble(interp, argv[3], &parameter1) != TCL_OK) {
00976                 opserr << "ERROR: invalid input: parameter1 \n";
00977                 return TCL_ERROR;
00978           }
00979 
00980           // GET INPUT PARAMETER (double)
00981           if (Tcl_GetDouble(interp, argv[4], &parameter2) != TCL_OK) {
00982                 opserr << "ERROR: invalid input: parameter2 \n";
00983                 return TCL_ERROR;
00984           }
00985 
00986           // GET INPUT PARAMETER (double)
00987           if (Tcl_GetDouble(interp, argv[5], &parameter3) != TCL_OK) {
00988                 opserr << "ERROR: invalid input: parameter3 \n";
00989                 return TCL_ERROR;
00990           }
00991 
00992           // GET INPUT PARAMETER (double)
00993           if (Tcl_GetDouble(interp, argv[6], &parameter4) != TCL_OK) {
00994                 opserr << "ERROR: invalid input: parameter4 \n";
00995                 return TCL_ERROR;
00996           }
00997 
00998           // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
00999           if (strcmp(argv[2],"normal") == 0) {
01000                   if ( parameter2 <= 0.0 ) {
01001                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01002                           return TCL_ERROR;
01003                   }
01004                   else  {
01005                         theRandomVariable = new NormalRV(tag, parameter1, parameter2, parameter3, parameter4);
01006                   }
01007           }
01008           else if (strcmp(argv[2],"lognormal") == 0) {
01009 //                if ( parameter2 <= 0.0 ) { Now assume that this indicates negative lognormal 
01010 //                        opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01011 //                        return TCL_ERROR;
01012 //                }
01013 //                else  {
01014                         theRandomVariable = new LognormalRV(tag, parameter1, parameter2, parameter3, parameter4);
01015 //                }
01016           }
01017           else if (strcmp(argv[2],"gamma") == 0) {
01018                   if ( parameter1 <= 0.0  || parameter2 <= 0.0 ) {
01019                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01020                           return TCL_ERROR;
01021                   }
01022                   else  {
01023                         theRandomVariable = new GammaRV(tag, parameter1, parameter2, parameter3, parameter4);
01024                   }
01025           }
01026           else if (strcmp(argv[2],"shiftedExponential") == 0) {
01027                   if ( parameter1 <= 0.0 ) {
01028                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01029                           return TCL_ERROR;
01030                   }
01031                   else  {
01032                         theRandomVariable = new ShiftedExponentialRV(tag, parameter1, parameter2, parameter3, parameter4);
01033                   }
01034           }
01035           else if (strcmp(argv[2],"shiftedRayleigh") == 0) {
01036                   if ( parameter1 <= 0.0 ) {
01037                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01038                           return TCL_ERROR;
01039                   }
01040                   else  {
01041                         theRandomVariable = new ShiftedRayleighRV(tag, parameter1, parameter2, parameter3, parameter4);
01042                   }
01043           }
01044           else if (strcmp(argv[2],"exponential") == 0) {
01045                   if ( parameter1 <= 0.0 ) {
01046                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01047                           return TCL_ERROR;
01048                   }
01049                   else  {
01050                         theRandomVariable = new ExponentialRV(tag, parameter1, parameter2, parameter3, parameter4);
01051                   }
01052           }
01053           else if (strcmp(argv[2],"rayleigh") == 0) {
01054                   if ( parameter1 <= 0.0 ) {
01055                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01056                           return TCL_ERROR;
01057                   }
01058                   else  {
01059                         theRandomVariable = new RayleighRV(tag, parameter1, parameter2, parameter3, parameter4);
01060                   }
01061           }
01062           else if (strcmp(argv[2],"uniform") == 0) {
01063                   if ( parameter1 >= parameter2 ) {
01064                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01065                           return TCL_ERROR;
01066                   }
01067                   else  {
01068                         theRandomVariable = new UniformRV(tag, parameter1, parameter2, parameter3, parameter4);
01069                   }
01070           }
01071           else if (strcmp(argv[2],"beta") == 0) {
01072                   if ( parameter1 >= parameter2  ||  parameter3 <= 0.0  || parameter4 <= 0.0  ) {
01073                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01074                           return TCL_ERROR;
01075                   }
01076                   else  {
01077                         theRandomVariable = new BetaRV(tag, parameter1, parameter2, parameter3, parameter4);
01078                   }
01079           }
01080           else if (strcmp(argv[2],"type1LargestValue") == 0) {
01081                   if ( parameter2 <= 0.0 ) {
01082                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01083                           return TCL_ERROR;
01084                   }
01085                   else  {
01086                         theRandomVariable = new Type1LargestValueRV(tag, parameter1, parameter2, parameter3, parameter4);
01087                   }
01088           }
01089           else if (strcmp(argv[2],"type1SmallestValue") == 0) {
01090                   if ( parameter2 <= 0.0 ) {
01091                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01092                           return TCL_ERROR;
01093                   }
01094                   else  {
01095                         theRandomVariable = new Type1SmallestValueRV(tag, parameter1, parameter2, parameter3, parameter4);
01096                   }
01097           }
01098           else if (strcmp(argv[2],"type2LargestValue") == 0) {
01099                   if ( parameter1 <= 0.0  || parameter2 <= 0.0 ) {
01100                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01101                           return TCL_ERROR;
01102                   }
01103                   else  {
01104                         theRandomVariable = new Type2LargestValueRV(tag, parameter1, parameter2, parameter3, parameter4);
01105                   }
01106           }
01107           else if (strcmp(argv[2],"type3SmallestValue") == 0) {
01108                   if ( parameter2 <= 0.0  ||  parameter3 <= 0.0 ) {
01109                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01110                           return TCL_ERROR;
01111                   }
01112                   else  {
01113                         theRandomVariable = new Type3SmallestValueRV(tag, parameter1, parameter2, parameter3, parameter4);
01114                   }
01115           }
01116           else if (strcmp(argv[2],"chiSquare") == 0) {
01117                   if ( parameter1 <= 0.0 ) {
01118                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01119                           return TCL_ERROR;
01120                   }
01121                   else  {
01122                         theRandomVariable = new ChiSquareRV(tag, parameter1, parameter2, parameter3, parameter4);
01123                   }
01124           }
01125           else if (strcmp(argv[2],"gumbel") == 0) {
01126                   if ( parameter2 <= 0.0 ) {
01127                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01128                           return TCL_ERROR;
01129                   }
01130                   else  {
01131                         theRandomVariable = new GumbelRV(tag, parameter1, parameter2, parameter3, parameter4);
01132                   }
01133           }
01134           else if (strcmp(argv[2],"weibull") == 0) {
01135                   if ( parameter1 <= 0.0  ||  parameter2 <= 0.0 ) {
01136                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01137                           return TCL_ERROR;
01138                   }
01139                   else  {
01140                         theRandomVariable = new WeibullRV(tag, parameter1, parameter2, parameter3, parameter4);
01141                   }
01142           }
01143           else if (strcmp(argv[2],"laplace") == 0) {
01144                   if ( parameter2 <= 0.0 ) {
01145                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01146                           return TCL_ERROR;
01147                   }
01148                   else  {
01149                         theRandomVariable = new LaplaceRV(tag, parameter1, parameter2, parameter3, parameter4);
01150                   }
01151           }
01152           else if (strcmp(argv[2],"pareto") == 0) {
01153                   if ( parameter1 <= 0.0  ||  parameter2 <= 0.0 ) {
01154                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01155                           return TCL_ERROR;
01156                   }
01157                   else  {
01158                         theRandomVariable = new ParetoRV(tag, parameter1, parameter2, parameter3, parameter4);
01159                   }
01160           }
01161           else {
01162                 opserr << "ERROR: unrecognized type of random variable \n";
01163                 opserr << "random variable: " << tag << endln;
01164                 return TCL_ERROR;
01165           }
01166 
01167           if (theRandomVariable == 0) {
01168                 opserr << "ERROR: unrecognized type of random variable number " << tag << endln;
01169                 return TCL_ERROR;
01170           }
01171   }
01172   else if (numberOfArguments==8)  {  // (Use parameters AND startPt)
01173 
01174           // GET INPUT PARAMETER (double)
01175           if (Tcl_GetDouble(interp, argv[3], &parameter1) != TCL_OK) {
01176                 opserr << "ERROR: invalid input: parameter1 \n";
01177                 return TCL_ERROR;
01178           }
01179 
01180           // GET INPUT PARAMETER (double)
01181           if (Tcl_GetDouble(interp, argv[4], &parameter2) != TCL_OK) {
01182                 opserr << "ERROR: invalid input: parameter2 \n";
01183                 return TCL_ERROR;
01184           }
01185 
01186           // GET INPUT PARAMETER (double)
01187           if (Tcl_GetDouble(interp, argv[5], &parameter3) != TCL_OK) {
01188                 opserr << "ERROR: invalid input: parameter3 \n";
01189                 return TCL_ERROR;
01190           }
01191 
01192           // GET INPUT PARAMETER (double)
01193           if (Tcl_GetDouble(interp, argv[6], &parameter4) != TCL_OK) {
01194                 opserr << "ERROR: invalid input: parameter4 \n";
01195                 return TCL_ERROR;
01196           }
01197 
01198           // GET INPUT PARAMETER (double)
01199           if (Tcl_GetDouble(interp, argv[7], &startPt) != TCL_OK) {
01200                 opserr << "ERROR: invalid input: startPt \n";
01201                 return TCL_ERROR;
01202           }
01203 
01204           // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
01205           if (strcmp(argv[2],"normal") == 0) {
01206                   if ( parameter2 <= 0.0 ) {
01207                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01208                           return TCL_ERROR;
01209                   }
01210                   else  {
01211                         theRandomVariable = new NormalRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01212                   }
01213           }
01214           else if (strcmp(argv[2],"lognormal") == 0) {
01215 //                if ( parameter2 <= 0.0 ) { Now assume that this indicates negative lognormal
01216 //                        opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01217 //                        return TCL_ERROR;
01218 //                }
01219 //                else  {
01220                         theRandomVariable = new LognormalRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01221 //                }
01222           }
01223           else if (strcmp(argv[2],"gamma") == 0) {
01224                   if ( parameter1 <= 0.0  || parameter2 <= 0.0 ) {
01225                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01226                           return TCL_ERROR;
01227                   }
01228                   else  {
01229                         theRandomVariable = new GammaRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01230                   }
01231           }
01232           else if (strcmp(argv[2],"shiftedExponential") == 0) {
01233                   if ( parameter1 <= 0.0 ) {
01234                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01235                           return TCL_ERROR;
01236                   }
01237                   else  {
01238                         theRandomVariable = new ShiftedExponentialRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01239                   }
01240           }
01241           else if (strcmp(argv[2],"shiftedRayleigh") == 0) {
01242                   if ( parameter1 <= 0.0 ) {
01243                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01244                           return TCL_ERROR;
01245                   }
01246                   else  {
01247                         theRandomVariable = new ShiftedRayleighRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01248                   }
01249           }
01250           else if (strcmp(argv[2],"exponential") == 0) {
01251                   if ( parameter1 <= 0.0 ) {
01252                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01253                           return TCL_ERROR;
01254                   }
01255                   else  {
01256                         theRandomVariable = new ExponentialRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01257                   }
01258           }
01259           else if (strcmp(argv[2],"rayleigh") == 0) {
01260                   if ( parameter1 <= 0.0 ) {
01261                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01262                           return TCL_ERROR;
01263                   }
01264                   else  {
01265                         theRandomVariable = new RayleighRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01266                   }
01267           }
01268           else if (strcmp(argv[2],"uniform") == 0) {
01269                   if ( parameter1 >= parameter2 ) {
01270                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01271                           return TCL_ERROR;
01272                   }
01273                   else  {
01274                         theRandomVariable = new UniformRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01275                   }
01276           }
01277           else if (strcmp(argv[2],"beta") == 0) {
01278                   if ( parameter1 >= parameter2  ||  parameter3 <= 0.0  || parameter4 <= 0.0  ) {
01279                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01280                           return TCL_ERROR;
01281                   }
01282                   else  {
01283                         theRandomVariable = new BetaRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01284                   }
01285           }
01286           else if (strcmp(argv[2],"type1LargestValue") == 0) {
01287                   if ( parameter2 <= 0.0 ) {
01288                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01289                           return TCL_ERROR;
01290                   }
01291                   else  {
01292                         theRandomVariable = new Type1LargestValueRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01293                   }
01294           }
01295           else if (strcmp(argv[2],"type1SmallestValue") == 0) {
01296                   if ( parameter2 <= 0.0 ) {
01297                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01298                           return TCL_ERROR;
01299                   }
01300                   else  {
01301                         theRandomVariable = new Type1SmallestValueRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01302                   }
01303           }
01304           else if (strcmp(argv[2],"type2LargestValue") == 0) {
01305                   if ( parameter1 <= 0.0  || parameter2 <= 0.0 ) {
01306                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01307                           return TCL_ERROR;
01308                   }
01309                   else  {
01310                         theRandomVariable = new Type2LargestValueRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01311                   }
01312           }
01313           else if (strcmp(argv[2],"type3SmallestValue") == 0) {
01314                   if ( parameter2 <= 0.0  ||  parameter3 <= 0.0 ) {
01315                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01316                           return TCL_ERROR;
01317                   }
01318                   else  {
01319                         theRandomVariable = new Type3SmallestValueRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01320                   }
01321           }
01322           else if (strcmp(argv[2],"chiSquare") == 0) {
01323                   if ( parameter1 <= 0.0 ) {
01324                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01325                           return TCL_ERROR;
01326                   }
01327                   else  {
01328                         theRandomVariable = new ChiSquareRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01329                   }
01330           }
01331           else if (strcmp(argv[2],"gumbel") == 0) {
01332                   if ( parameter2 <= 0.0 ) {
01333                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01334                           return TCL_ERROR;
01335                   }
01336                   else  {
01337                         theRandomVariable = new GumbelRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01338                   }
01339           }
01340           else if (strcmp(argv[2],"weibull") == 0) {
01341                   if ( parameter1 <= 0.0  ||  parameter2 <= 0.0 ) {
01342                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01343                           return TCL_ERROR;
01344                   }
01345                   else  {
01346                         theRandomVariable = new WeibullRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01347                   }
01348           }
01349           else if (strcmp(argv[2],"laplace") == 0) {
01350                   if ( parameter2 <= 0.0 ) {
01351                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01352                           return TCL_ERROR;
01353                   }
01354                   else  {
01355                         theRandomVariable = new LaplaceRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01356                   }
01357           }
01358           else if (strcmp(argv[2],"pareto") == 0) {
01359                   if ( parameter1 <= 0.0  ||  parameter2 <= 0.0 ) {
01360                           opserr << "ERROR: Invalid parameter input to random variable number " << tag << endln;
01361                           return TCL_ERROR;
01362                   }
01363                   else  {
01364                         theRandomVariable = new ParetoRV(tag, parameter1, parameter2, parameter3, parameter4, startPt);
01365                   }
01366           }
01367           else {
01368                 opserr << "ERROR: unrecognized type of random variable number " << tag << endln;
01369                 return TCL_ERROR;
01370           }
01371 
01372           if (theRandomVariable == 0) {
01373                 opserr << "ERROR: could not create random variable number " << tag << endln;
01374                 return TCL_ERROR;
01375           }
01376   }
01377 
01378 
01379   // ADD THE OBJECT TO THE DOMAIN
01380   if (theReliabilityDomain->addRandomVariable(theRandomVariable) == false) {
01381         opserr << "ERROR: failed to add random variable to the domain (wrong number of arguments?)\n";
01382         opserr << "random variable: " << tag << endln;
01383         delete theRandomVariable; // otherwise memory leak
01384         return TCL_ERROR;
01385   }
01386 
01387   return TCL_OK;
01388 }
01389                                            
01390 
01391 
01392 
01394 int 
01395 TclReliabilityModelBuilder_getMean(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
01396 {
01397         int tag;
01398         RandomVariable *rv;
01399         if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
01400                 opserr << "ERROR: Invalid random variable number tag to getMean command." << endln;
01401                 return TCL_ERROR;
01402         }
01403         rv = theReliabilityDomain->getRandomVariablePtr(tag);
01404         if (rv == 0) {
01405                 opserr << "ERROR: Invalid tag number to getMean command. " << endln;
01406                 return TCL_ERROR;
01407         }
01408         opserr << "Mean of random variable number " << tag << ": " << rv->getMean() << endln;
01409 
01410         return TCL_OK;
01411 }
01412 
01413 
01414 
01415 
01417 int 
01418 TclReliabilityModelBuilder_getStdv(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
01419 {
01420         int tag;
01421         RandomVariable *rv;
01422         if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
01423                 opserr << "ERROR: Invalid random variable number tag to getStdv command." << endln;
01424                 return TCL_ERROR;
01425         }
01426         rv = theReliabilityDomain->getRandomVariablePtr(tag);
01427         if (rv == 0) {
01428                 opserr << "ERROR: Invalid tag number to getStdv command. " << endln;
01429                 return TCL_ERROR;
01430         }
01431         opserr << "Standard deviation of random variable number " << tag << ": " << rv->getStdv() << endln;
01432         
01433         return TCL_OK;
01434 }
01435 
01436 
01437 
01438 
01440 int 
01441 TclReliabilityModelBuilder_addCorrelate(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
01442 {
01443         if (argc != 4) {
01444                 opserr << "ERROR: Wrong number of arguments to correlate command." << endln;
01445                 return TCL_ERROR;
01446         }
01447         
01448   CorrelationCoefficient *theCorrelationCoefficient = 0;
01449   int tag;
01450   int rv1;
01451   int rv2;
01452   double correlationValue;
01453 
01454 
01455   // GET INPUT PARAMETER (integer)
01456   if (Tcl_GetInt(interp, argv[1], &rv1) != TCL_OK) {
01457         opserr << "ERROR: invalid input: rv1 \n";
01458         return TCL_ERROR;
01459   }
01460 
01461   // GET INPUT PARAMETER (integer)
01462   if (Tcl_GetInt(interp, argv[2], &rv2) != TCL_OK) {
01463         opserr << "ERROR: invalid input: rv2 \n";
01464         return TCL_ERROR;
01465   }
01466 
01467   // GET INPUT PARAMETER (double)
01468   if (Tcl_GetDouble(interp, argv[3], &correlationValue) != TCL_OK) {
01469         opserr << "ERROR: invalid input: correlationValue \n";
01470         return TCL_ERROR;
01471   }
01472 
01473   // CREATE THE OBJECT
01474   tag = theReliabilityDomain->getNumberOfCorrelationCoefficients();
01475   theCorrelationCoefficient = new CorrelationCoefficient(tag+1, rv1, rv2, correlationValue);
01476 
01477   if (theCorrelationCoefficient == 0) {
01478         opserr << "ERROR: ran out of memory creating correlation coefficient \n";
01479         opserr << "correlation coefficient: " << tag << endln;
01480         return TCL_ERROR;
01481   }
01482 
01483   // ADD THE OBJECT TO THE DOMAIN
01484   if (theReliabilityDomain->addCorrelationCoefficient(theCorrelationCoefficient) == false) {
01485         opserr << "ERROR: failed to add correlation coefficient to the domain\n";
01486         opserr << "correlation coefficient: " << tag << endln;
01487         delete theCorrelationCoefficient; // otherwise memory leak
01488         return TCL_ERROR;
01489   }
01490 
01491   return TCL_OK;
01492 }
01493 
01494 
01495 
01496 
01498 int 
01499 TclReliabilityModelBuilder_correlateGroup(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
01500 {
01501         int firstRV, lastRV;
01502         double correlationValue;
01503 
01504         // GET INPUT PARAMETER (integer)
01505         if (Tcl_GetInt(interp, argv[1], &firstRV) != TCL_OK) {
01506                 opserr << "ERROR: invalid input: firstRV \n";
01507                 return TCL_ERROR;
01508         }
01509 
01510         // GET INPUT PARAMETER (integer)
01511         if (Tcl_GetInt(interp, argv[2], &lastRV) != TCL_OK) {
01512                 opserr << "ERROR: invalid input: lastRV \n";
01513                 return TCL_ERROR;
01514         }
01515 
01516         // GET INPUT PARAMETER (double)
01517         if (Tcl_GetDouble(interp, argv[3], &correlationValue) != TCL_OK) {
01518                 opserr << "ERROR: invalid input: correlationValue \n";
01519                 return TCL_ERROR;
01520         }
01521 
01522         // Assume that previos corr. coeffs. have been added in order
01523         char theCorrelateCommand[50];
01524         for (int i=firstRV; i<=lastRV; i++) {
01525                 for (int j=i+1; j<=lastRV; j++) {
01526                         sprintf(theCorrelateCommand,"correlate %d %d %10.5f",i,j,correlationValue);
01527                         Tcl_Eval(interp, theCorrelateCommand );
01528                 }
01529         }
01530 
01531         return TCL_OK;
01532 }
01533 
01534 
01535 
01537 int 
01538 TclReliabilityModelBuilder_correlationStructure(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
01539 {
01540         int firstRV, lastRV, i;
01541         double theta, correlationValue;
01542         char theCorrelateCommand[50];
01543 
01544         // GET INPUT PARAMETER (integer)
01545         if (Tcl_GetInt(interp, argv[2], &firstRV) != TCL_OK) {
01546                 opserr << "ERROR: invalid input: firstRV \n";
01547                 return TCL_ERROR;
01548         }
01549 
01550         // GET INPUT PARAMETER (integer)
01551         if (Tcl_GetInt(interp, argv[3], &lastRV) != TCL_OK) {
01552                 opserr << "ERROR: invalid input: lastRV \n";
01553                 return TCL_ERROR;
01554         }
01555 
01556         // GET INPUT PARAMETER (double)
01557         if (Tcl_GetDouble(interp, argv[4], &theta) != TCL_OK) {
01558                 opserr << "ERROR: invalid input: theta \n";
01559                 return TCL_ERROR;
01560         }
01561 
01562 
01563         // Create appropriate correlation coefficients
01564         if (strcmp(argv[1],"homogeneous1") == 0) {
01565                 for (int i=firstRV; i<=lastRV; i++) {
01566                         for (int j=i+1; j<=lastRV; j++) {
01567                                 correlationValue = exp(-abs(i-j)/theta);
01568                                 sprintf(theCorrelateCommand,"correlate %d %d %10.5f",i,j,correlationValue);
01569                                 Tcl_Eval(interp, theCorrelateCommand );
01570                         }
01571                 }
01572         }
01573         else if (strcmp(argv[1],"homogeneous2") == 0) {
01574                 for (int i=firstRV; i<=lastRV; i++) {
01575                         for (int j=i+1; j<=lastRV; j++) {
01576                                 correlationValue = exp(-pow((i-j)/theta,2.0));
01577                                 sprintf(theCorrelateCommand,"correlate %d %d %10.5f",i,j,correlationValue);
01578                                 Tcl_Eval(interp, theCorrelateCommand );
01579                         }
01580                 }
01581         }
01582         else if (strcmp(argv[1],"homogeneous3") == 0) {
01583                 for (int i=firstRV; i<=lastRV; i++) {
01584                         for (int j=i+1; j<=lastRV; j++) {
01585                                 correlationValue = 1.0/(theta*(i-j)*(i-j));
01586                                 sprintf(theCorrelateCommand,"correlate %d %d %10.5f",i,j,correlationValue);
01587                                 Tcl_Eval(interp, theCorrelateCommand );
01588                         }
01589                 }
01590         }
01591         else if (strcmp(argv[1],"homogeneous4") == 0) {
01592                 for (int i=firstRV; i<=lastRV; i++) {
01593                         for (int j=i+1; j<=lastRV; j++) {
01594                                 if (abs(i-j)<theta) {
01595                                         correlationValue = 1.0-(abs(i-j)/theta);
01596                                         sprintf(theCorrelateCommand,"correlate %d %d %10.5f",i,j,correlationValue);
01597                                         Tcl_Eval(interp, theCorrelateCommand );
01598                                 }
01599                         }
01600                 }
01601         }
01602         else if (strcmp(argv[1],"vectorProduct") == 0) {
01603 
01604                 // Open file where the vector is given
01605                 ifstream inputFile( "correlationVector.txt", ios::in );
01606                 if (inputFile.fail()) {
01607                         opserr << "File correlationVector.txt could not be opened. " << endln;
01608                         return TCL_ERROR;
01609                 }
01610 
01611                 // Loop through file to see how many entries there are
01612                 double dummy;
01613                 int numEntries = 0;
01614                 while (inputFile >> dummy) {
01615                         numEntries++;
01616                 }
01617                 if (numEntries == 0) {
01618                         opserr << "ERROR: No entries in the correlationVector.txt file!" << endln;
01619                         return TCL_ERROR;
01620                 }
01621 
01622                 // Give a warning if the number of elements of the vector is
01623                 // different from the number of random variables being correlated
01624                 if (numEntries != lastRV-firstRV+1) {
01625                         opserr << "WARNING: The number of entries in the correlationVector.txt file " << endln
01626                                 << " is not equal to the number of random variables that are being correlated." << endln;
01627                 }
01628 
01629                 // Close the file
01630                 inputFile.close();
01631 
01632                 // Open it again, now being ready to store the results in a vector
01633                 ifstream inputFile2( "correlationVector.txt", ios::in );
01634                 if (inputFile.fail()) {
01635                         opserr << "File correlationVector.txt could not be opened. " << endln;
01636                         return TCL_ERROR;
01637                 }
01638 
01639                 // Store the vector
01640                 Vector theVector(numEntries);
01641                 for (i=0; i<numEntries; i++) {
01642                         inputFile2 >> theVector(i);
01643                 }
01644                 inputFile2.close();
01645 
01646                 for (int i=firstRV; i<=lastRV; i++) {
01647                         for (int j=i+1; j<=lastRV; j++) {
01648                                 correlationValue = theta * theVector(i-firstRV+1) * theVector(j-firstRV+1);
01649                                 sprintf(theCorrelateCommand,"correlate %d %d %10.5f",i,j,correlationValue);
01650                                 Tcl_Eval(interp, theCorrelateCommand );
01651                         }
01652                 }
01653         }
01654         else {
01655                 opserr << "ERROR: Invalid type of correlation structure. " << endln;
01656                 return TCL_ERROR;
01657         }
01658 
01659         return TCL_OK;
01660 }
01661 
01663 int 
01664 TclReliabilityModelBuilder_addLimitState(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
01665 {
01666   LimitStateFunction *theLimitStateFunction = 0;
01667   int tag;
01668 
01669         if (theGFunEvaluator != 0 ) {
01670                 opserr << "ERROR: A limit-state function should not be created after the GFunEvaluator has been instantiated." << endln;
01671                 return TCL_ERROR;
01672         }
01673 
01674   // GET INPUT PARAMETER (integer)
01675   if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
01676         opserr << "ERROR: invalid input: tag \n";
01677         return TCL_ERROR;
01678   }
01679   
01680   // CREATE THE OBJECT (passing on argv[2])
01681   theLimitStateFunction = new LimitStateFunction(tag, argv[2]);
01682   if (theLimitStateFunction == 0) {
01683         opserr << "ERROR: ran out of memory creating limit-state function \n";
01684         opserr << "limit-state function: " << tag << endln;
01685         return TCL_ERROR;
01686   }
01687 
01688   // ADD THE OBJECT TO THE DOMAIN
01689   if (theReliabilityDomain->addLimitStateFunction(theLimitStateFunction) == false) {
01690         opserr << "ERROR: failed to add limit-state function to the domain\n";
01691         opserr << "limit-state function: " << tag << endln;
01692         delete theLimitStateFunction; // otherwise memory leak
01693         return TCL_ERROR;
01694   }
01695 
01696   return TCL_OK;
01697 
01698 
01699 
01700 
01701 /*
01702 
01703   LimitStateFunction *theLimitStateFunction = 0;
01704   int tag;
01705   int node;
01706   int dof;
01707   double displacementLimit;
01708 
01709   // GET INPUT PARAMETER (integer)
01710   if (Tcl_GetInt(interp, argv[2], &tag) != TCL_OK) {
01711         opserr << "ERROR: invalid input: tag \n";
01712         return TCL_ERROR;
01713   }
01714 
01715   // GET INPUT PARAMETER (integer)
01716   if (Tcl_GetInt(interp, argv[3], &node) != TCL_OK) {
01717         opserr << "ERROR: invalid input: node \n";
01718         return TCL_ERROR;
01719   }
01720 
01721   // GET INPUT PARAMETER (integer)
01722   if (Tcl_GetInt(interp, argv[4], &dof) != TCL_OK) {
01723         opserr << "ERROR: invalid input: dof \n";
01724         return TCL_ERROR;
01725   }
01726 
01727   // GET INPUT PARAMETER (double)
01728   if (Tcl_GetDouble(interp, argv[5], &displacementLimit) != TCL_OK) {
01729         opserr << "ERROR: invalid input: displacementLimit \n";
01730         return TCL_ERROR;
01731   }
01732 
01733   // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
01734   if (strcmp(argv[1],"disp") == 0) {
01735           theLimitStateFunction = new LimitStateFunction(tag, node, dof, displacementLimit);
01736   }
01737   else {
01738         opserr << "ERROR: unrecognized type of limit-state function \n";
01739         opserr << "limit-state function: " << tag << endln;
01740   }
01741 
01742   if (theLimitStateFunction == 0) {
01743         opserr << "ERROR: ran out of memory creating limit-state function \n";
01744         opserr << "limit-state function: " << tag << endln;
01745         return TCL_ERROR;
01746   }
01747 
01748   // ADD THE OBJECT TO THE DOMAIN
01749   if (theReliabilityDomain->addLimitStateFunction(theLimitStateFunction) == false) {
01750         opserr << "ERROR: failed to add limit-state function to the domain\n";
01751         opserr << "limit-state function: " << tag << endln;
01752         delete theLimitStateFunction; // otherwise memory leak
01753         return TCL_ERROR;
01754   }
01755 
01756   return TCL_OK;
01757 */
01758 }
01759 
01760 
01761 
01763 int 
01764 TclReliabilityModelBuilder_addRandomVariablePositioner(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
01765 {
01766         RandomVariablePositioner *theRandomVariablePositioner = 0;
01767         int tag;
01768         int rvNumber;
01769         int tagOfObject;
01770         DomainComponent *theObject;
01771         int argvCounter = 1;
01772 
01773 
01774         // READ THE TAG NUMBER
01775         if (Tcl_GetInt(interp, argv[argvCounter++], &tag) != TCL_OK) {
01776                 opserr << "ERROR: Invalid input tag to random variable positioner." << endln;
01777                 return TCL_ERROR;
01778         }
01779 
01780         // CHECK IF THE USER WANTS TO CREATE THE RANDOM VARIABLE HERE
01781         if (strcmp(argv[argvCounter],"-createRV3") == 0) {
01782                 argvCounter++;
01783 
01784                 if (strcmp(argv[argvCounter],"userdefined") == 0) {
01785                         opserr << "ERROR: Can't create a user-defined random variable like this." << endln;
01786                         return TCL_ERROR;
01787                 }
01788 
01789                 char theTclCommand[100];
01790                 TCL_Char *rvType;
01791                 double mean,stdv;
01792 
01793                 rvNumber = tag;
01794                 rvType = argv[argvCounter++];
01795 
01796                 // READ MEAN
01797                 if (Tcl_GetDouble(interp, argv[argvCounter], &mean) != TCL_OK) {
01798                         opserr << "ERROR: invalid input in positioner: rv mean \n";
01799                         return TCL_ERROR;
01800                 }
01801                 argvCounter++;
01802                 // READ STDV
01803                 if (Tcl_GetDouble(interp, argv[argvCounter], &stdv) != TCL_OK) {
01804                         opserr << "ERROR: invalid input in positioner: rv stdv \n";
01805                         return TCL_ERROR;
01806                 }
01807                 argvCounter++;
01808 
01809                 // LET TCL CREATE THE RANDOM VARIABLE
01810                 sprintf(theTclCommand,"randomVariable %d %s %15.10e %15.10e",rvNumber,rvType,mean,stdv);
01811                 Tcl_Eval( interp, theTclCommand );
01812 
01813         }
01814         else if (strcmp(argv[argvCounter],"-createRV4") == 0) {
01815                 argvCounter++;
01816 
01817                 if (strcmp(argv[argvCounter],"userdefined") == 0) {
01818                         opserr << "ERROR: Can't create a user-defined random variable like this." << endln;
01819                         return TCL_ERROR;
01820                 }
01821 
01822                 char theTclCommand[100];
01823                 TCL_Char *rvType;
01824                 double mean,stdv,startPt;
01825 
01826                 rvNumber = tag;
01827                 rvType = argv[argvCounter++];
01828 
01829                 // READ MEAN
01830                 if (Tcl_GetDouble(interp, argv[argvCounter], &mean) != TCL_OK) {
01831                         opserr << "ERROR: invalid input in positioner: rv mean \n";
01832                         return TCL_ERROR;
01833                 }
01834                 argvCounter++;
01835                 // READ STDV
01836                 if (Tcl_GetDouble(interp, argv[argvCounter], &stdv) != TCL_OK) {
01837                         opserr << "ERROR: invalid input in positioner: rv stdv \n";
01838                         return TCL_ERROR;
01839                 }
01840                 argvCounter++;
01841                 // READ STARTVALUE
01842                 if (Tcl_GetDouble(interp, argv[argvCounter], &startPt) != TCL_OK) {
01843                         opserr << "ERROR: invalid input in positioner: rv startPt \n";
01844                         return TCL_ERROR;
01845                 }
01846                 argvCounter++;
01847 
01848                 // LET TCL CREATE THE RANDOM VARIABLE
01849                 sprintf(theTclCommand,"randomVariable %d %s %15.10e %15.10e %15.10e",rvNumber,rvType,mean,stdv,startPt);
01850                 Tcl_Eval( interp, theTclCommand );
01851         }
01852         else if (strcmp(argv[argvCounter],"-createRV5") == 0) {
01853                 argvCounter++;
01854 
01855                 if (strcmp(argv[argvCounter],"userdefined") == 0) {
01856                         opserr << "ERROR: Can't create a user-defined random variable like this." << endln;
01857                         return TCL_ERROR;
01858                 }
01859 
01860                 char theTclCommand[100];
01861                 TCL_Char *rvType;
01862                 double par1, par2, par3, par4;
01863 
01864                 rvNumber = tag;
01865                 rvType = argv[argvCounter++];
01866 
01867                 // READ PARAMETER 1
01868                 if (Tcl_GetDouble(interp, argv[argvCounter], &par1) != TCL_OK) {
01869                         opserr << "ERROR: invalid input in positioner: rv parameter 1 \n";
01870                         return TCL_ERROR;
01871                 }
01872                 argvCounter++;
01873                 // READ PARAMETER 2
01874                 if (Tcl_GetDouble(interp, argv[argvCounter], &par2) != TCL_OK) {
01875                         opserr << "ERROR: invalid input in positioner: rv parameter 2 \n";
01876                         return TCL_ERROR;
01877                 }
01878                 argvCounter++;
01879                 // READ PARAMETER 3
01880                 if (Tcl_GetDouble(interp, argv[argvCounter], &par3) != TCL_OK) {
01881                         opserr << "ERROR: invalid input in positioner: rv parameter 3 \n";
01882                         return TCL_ERROR;
01883                 }
01884                 argvCounter++;
01885                 // READ PARAMETER 4
01886                 if (Tcl_GetDouble(interp, argv[argvCounter], &par4) != TCL_OK) {
01887                         opserr << "ERROR: invalid input in positioner: rv parameter 4 \n";
01888                         return TCL_ERROR;
01889                 }
01890                 argvCounter++;
01891 
01892                 // LET TCL CREATE THE RANDOM VARIABLE
01893                 sprintf(theTclCommand,"randomVariable %d %s %15.10e %15.10e %15.10e %15.10e",rvNumber,rvType,par1,par2,par3,par4);
01894                 Tcl_Eval( interp, theTclCommand );
01895         }
01896         else if (strcmp(argv[argvCounter],"-createRV6") == 0) {
01897                 argvCounter++;
01898 
01899                 if (strcmp(argv[argvCounter],"userdefined") == 0) {
01900                         opserr << "ERROR: Can't create a user-defined random variable like this." << endln;
01901                         return TCL_ERROR;
01902                 }
01903 
01904                 char theTclCommand[100];
01905                 TCL_Char *rvType;
01906                 double par1, par2, par3, par4, startPt;
01907 
01908                 rvNumber = tag;
01909                 rvType = argv[argvCounter++];
01910 
01911                 // READ PARAMETER 1
01912                 if (Tcl_GetDouble(interp, argv[argvCounter], &par1) != TCL_OK) {
01913                         opserr << "ERROR: invalid input in positioner: rv parameter 1 \n";
01914                         return TCL_ERROR;
01915                 }
01916                 argvCounter++;
01917                 // READ PARAMETER 2
01918                 if (Tcl_GetDouble(interp, argv[argvCounter], &par2) != TCL_OK) {
01919                         opserr << "ERROR: invalid input in positioner: rv parameter 2 \n";
01920                         return TCL_ERROR;
01921                 }
01922                 argvCounter++;
01923                 // READ PARAMETER 3
01924                 if (Tcl_GetDouble(interp, argv[argvCounter], &par3) != TCL_OK) {
01925                         opserr << "ERROR: invalid input in positioner: rv parameter 3 \n";
01926                         return TCL_ERROR;
01927                 }
01928                 argvCounter++;
01929                 // READ PARAMETER 4
01930                 if (Tcl_GetDouble(interp, argv[argvCounter], &par4) != TCL_OK) {
01931                         opserr << "ERROR: invalid input in positioner: rv parameter 4 \n";
01932                         return TCL_ERROR;
01933                 }
01934                 argvCounter++;
01935                 // READ START VALUE
01936                 if (Tcl_GetDouble(interp, argv[argvCounter], &startPt) != TCL_OK) {
01937                         opserr << "ERROR: invalid input in positioner: rv startPt \n";
01938                         return TCL_ERROR;
01939                 }
01940                 argvCounter++;
01941 
01942                 // LET TCL CREATE THE RANDOM VARIABLE
01943                 sprintf(theTclCommand,"randomVariable %d %s %15.10e %15.10e %15.10e %15.10e %15.10e",rvNumber,rvType,par1,par2,par3,par4,startPt);
01944                 Tcl_Eval( interp, theTclCommand );
01945         }
01946         else if (strcmp(argv[argvCounter],"-rvNum") == 0) {
01947                 argvCounter++;
01948                 
01949                 // READ THE RANDOM VARIABLE NUMBER
01950                 if (Tcl_GetInt(interp, argv[argvCounter++], &rvNumber) != TCL_OK) {
01951                         opserr << "ERROR: invalid input: rvNumber \n";
01952                         return TCL_ERROR;
01953                 }
01954 
01955                 // CHECK THAT THE RANDOM VARIABLE ACTUALLY EXISTS
01956                 RandomVariable *theRandomVariable = 0;
01957                 theRandomVariable = theReliabilityDomain->getRandomVariablePtr(rvNumber);
01958                 if (theRandomVariable == 0){
01959                         opserr << "ERROR:: A non-existing random variable number " << rvNumber << " is being positioned in the model " << endln;
01960                         return TCL_ERROR;
01961                 }
01962         }
01963         else {
01964                 opserr << "ERROR: Illegal random variable specification in random " << endln
01965                         << " variable positioner command. " << endln;
01966                 return TCL_ERROR;
01967         }
01968         
01969         if (strcmp(argv[argvCounter],"-parameter") == 0) {
01970           argvCounter++;
01971           int paramTag;
01972           if (Tcl_GetInt(interp, argv[argvCounter++], &paramTag) != TCL_OK) {
01973             opserr << "ERROR: invalid input in positioner: parameter tag \n";
01974             return TCL_ERROR;
01975           }
01976 
01977           Parameter *theParameter = theStructuralDomain->getParameter(paramTag);
01978 
01979           if (theParameter == 0) {
01980             opserr << "ERROR: parameter with tag " << paramTag 
01981                    << " not found in structural domain\n";
01982             return TCL_ERROR;
01983           }
01984           else {
01985             theRandomVariablePositioner =
01986               new RandomVariablePositioner(tag, rvNumber, *theParameter);
01987           }
01988         }
01989 
01990         // IF UNCERTAIN *ELEMENT* PROPERTY
01991         else if (strcmp(argv[argvCounter],"-element") == 0) {
01992                 argvCounter++;
01993 
01994                 if (Tcl_GetInt(interp, argv[argvCounter++], &tagOfObject) != TCL_OK) {
01995                         argvCounter++;
01996                         opserr << "ERROR: invalid input: tagOfObject \n";
01997                         return TCL_ERROR;
01998                 }
01999 
02000                 theObject = (DomainComponent *)theStructuralDomain->getElement(tagOfObject);
02001 
02002                 theRandomVariablePositioner =
02003                   new RandomVariablePositioner(tag,
02004                                                rvNumber,
02005                                                theObject,
02006                                                &argv[argvCounter],
02007                                                argc-argvCounter);
02008 
02009                 //int rvnumber = theRandomVariablePositioner->getRvNumber();
02010         }
02011 
02012         // IF UNCERTAIN *LOAD*
02013         else if (strcmp(argv[argvCounter],"-loadPattern") == 0) {
02014                 argvCounter++;
02015 
02016                 if (Tcl_GetInt(interp, argv[argvCounter++], &tagOfObject) != TCL_OK) {
02017                         opserr << "ERROR: invalid input: tagOfObject \n";
02018                         return TCL_ERROR;
02019                 }
02020                 theObject = (DomainComponent *)theStructuralDomain->getLoadPattern(tagOfObject);
02021 
02022 
02023 //              if (argc > 8) {
02024 //
02025 //                      // GET INPUT PARAMETER (double)
02026 //                      double factor = 1.0;
02027 //                      if (Tcl_GetDouble(interp, argv[8], &factor) != TCL_OK) {
02028 //                              opserr << "ERROR: invalid input: factor \n";
02029 //                              return TCL_ERROR;
02030 //                      }
02031 //                      theRandomVariablePositioner = new RandomVariablePositioner(tag,rvNumber,theObject,&argv[5],argc-5,factor);
02032 //              }
02033 //              else {
02034 //                      theRandomVariablePositioner = new RandomVariablePositioner(tag,rvNumber,theObject,&argv[5],argc-5);
02035 //              }
02036                 theRandomVariablePositioner =
02037                   new RandomVariablePositioner(tag,
02038                                                rvNumber,
02039                                                theObject,
02040                                                &argv[argvCounter],
02041                                                argc-argvCounter);
02042         }
02043 
02044         // IF UNCERTAIN *NODE* PROPERTY
02045         else if (strcmp(argv[argvCounter],"-node") == 0) {
02046                 argvCounter++;
02047 
02048                 if (Tcl_GetInt(interp, argv[argvCounter++], &tagOfObject) != TCL_OK) {
02049                         opserr << "ERROR: invalid input: tagOfObject \n";
02050                         return TCL_ERROR;
02051                 }
02052                 theObject = (DomainComponent *)theStructuralDomain->getNode(tagOfObject);
02053 
02054                 theRandomVariablePositioner =
02055                   new RandomVariablePositioner(tag,
02056                                                rvNumber,
02057                                                theObject,
02058                                                &argv[argvCounter],
02059                                                argc-argvCounter);
02060         }
02061         else {
02062                 opserr << "ERROR: Unknown parameter in randomVariablePositioner" << endln;
02063                 return TCL_ERROR;
02064         }
02065 
02066         // ADD THE RANDOMVARIABLEPOSITIONER TO THE DOMAIN
02067         if (theReliabilityDomain->addRandomVariablePositioner(theRandomVariablePositioner) == false) {
02068                 opserr << "ERROR: failed to add random variable positioner number " << tag << " to the domain." << endln;
02069                 delete theRandomVariablePositioner; // otherwise memory leak
02070                 return TCL_ERROR;
02071         }
02072 
02073         return TCL_OK;
02074 
02075 
02076 
02077 
02078 
02079 
02080 
02081 /*
02082 // THE OLD VERSION OF THIS FUNCTION:
02083 
02084   RandomVariablePositioner *theRandomVariablePositioner = 0;
02085   int tag;
02086   int rvNumber;
02087   int typeOfObject;
02088   int tagOfObject;
02089   int typeOfParameterInObject;
02090 
02091   // GET INPUT PARAMETER (integer)
02092   if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
02093         opserr << "ERROR: invalid input: tag \n";
02094         return TCL_ERROR;
02095   }
02096 
02097   // GET INPUT PARAMETER (integer)
02098   if (Tcl_GetInt(interp, argv[2], &rvNumber) != TCL_OK) {
02099         opserr << "ERROR: invalid input: rvNumber \n";
02100         return TCL_ERROR;
02101   }
02102 
02103   // GET INPUT PARAMETER (integer)
02104   if (Tcl_GetInt(interp, argv[3], &typeOfObject) != TCL_OK) {
02105         opserr << "ERROR: invalid input: typeOfObject \n";
02106         return TCL_ERROR;
02107   }
02108 
02109   // GET INPUT PARAMETER (integer)
02110   if (Tcl_GetInt(interp, argv[4], &tagOfObject) != TCL_OK) {
02111         opserr << "ERROR: invalid input: tagOfObject \n";
02112         return TCL_ERROR;
02113   }
02114 
02115   // GET INPUT PARAMETER (integer)
02116   if (Tcl_GetInt(interp, argv[5], &typeOfParameterInObject) != TCL_OK) {
02117         opserr << "ERROR: invalid input: typeOfParameterInObject \n";
02118         return TCL_ERROR;
02119   }
02120 
02121 
02122   // CREATE THE OBJECT
02123   theRandomVariablePositioner = new RandomVariablePositioner(tag, rvNumber, typeOfObject, tagOfObject, typeOfParameterInObject);
02124 
02125   if (theRandomVariablePositioner == 0) {
02126         opserr << "ERROR: ran out of memory creating random variable identificator \n";
02127         opserr << "randomVariableID: " << tag << endln;
02128         return TCL_ERROR;
02129   }
02130 
02131   // ADD THE OBJECT TO THE DOMAIN
02132   if (theReliabilityDomain->addRandomVariablePositioner(theRandomVariablePositioner) == false) {
02133         opserr << "ERROR: failed to add random variable identificator to the domain\n";
02134         opserr << "randomvariableID: " << tag << endln;
02135         delete theRandomVariablePositioner; // otherwise memory leak
02136         return TCL_ERROR;
02137   }
02138 
02139   return TCL_OK;
02140 */
02141 }
02142 
02143 
02144 
02145 
02146 
02148 int 
02149 TclReliabilityModelBuilder_addParameterPositioner(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02150 {
02151         ParameterPositioner *theParameterPositioner = 0;
02152         int tag;
02153         int tagOfObject;
02154         DomainComponent *theObject;
02155         int argvCounter = 1;
02156 
02157 
02158         // READ THE TAG NUMBER
02159         if (Tcl_GetInt(interp, argv[argvCounter++], &tag) != TCL_OK) {
02160                 opserr << "ERROR: Invalid tag given to parameterPositioner. " << endln;
02161                 return TCL_ERROR;
02162         }
02163 
02164         if (strcmp(argv[argvCounter],"-parameter") == 0) {
02165           argvCounter++;
02166           int paramTag;
02167           if (Tcl_GetInt(interp, argv[argvCounter++], &paramTag) != TCL_OK) {
02168             opserr << "ERROR: invalid input in positioner: parameter tag \n";
02169             return TCL_ERROR;
02170           }
02171 
02172           Parameter *theParameter = theStructuralDomain->getParameter(paramTag);
02173 
02174           if (theParameter == 0) {
02175             opserr << "ERROR: parameter with tag " << paramTag 
02176                    << " not found in structural domain\n";
02177             return TCL_ERROR;
02178           }
02179           else {
02180             theParameterPositioner =
02181               new ParameterPositioner(tag, *theParameter);
02182           }
02183         }
02184 
02185         // IF UNCERTAIN *LOAD*
02186         else if (strcmp(argv[argvCounter],"-loadPattern") == 0) {
02187                 argvCounter++;
02188                 
02189                 if (Tcl_GetInt(interp, argv[argvCounter++], &tagOfObject) != TCL_OK) {
02190                   opserr << "ERROR: invalid input: tagOfObject \n";
02191                   return TCL_ERROR;
02192                 }
02193                 theObject = (DomainComponent *)theStructuralDomain->getLoadPattern(tagOfObject);
02194 
02195                 theParameterPositioner =
02196                   new ParameterPositioner(tag,
02197                                           theObject,
02198                                           &argv[argvCounter],
02199                                           argc-argvCounter);
02200         }
02201 
02202         // IF UNCERTAIN element property
02203         else if (strcmp(argv[argvCounter],"-element") == 0) {
02204                 argvCounter++;
02205                 
02206                 if (Tcl_GetInt(interp, argv[argvCounter++], &tagOfObject) != TCL_OK) {
02207                   opserr << "ERROR: invalid input: tagOfObject \n";
02208                   return TCL_ERROR;
02209                 }
02210                 theObject = (DomainComponent *)theStructuralDomain->getElement(tagOfObject);
02211 
02212                 theParameterPositioner =
02213                   new ParameterPositioner(tag,
02214                                           theObject,
02215                                           &argv[argvCounter],
02216                                           argc-argvCounter);
02217         }
02218         // IF UNCERTAIN *NODE* PROPERTY
02219         else if (strcmp(argv[argvCounter],"-node") == 0) {
02220                 argvCounter++;
02221 
02222                 if (Tcl_GetInt(interp, argv[argvCounter++], &tagOfObject) != TCL_OK) {
02223                         opserr << "ERROR: invalid input: tagOfObject \n";
02224                         return TCL_ERROR;
02225                 }
02226                 theObject = (DomainComponent *)theStructuralDomain->getNode(tagOfObject);
02227 
02228                 theParameterPositioner =
02229                   new ParameterPositioner(tag,
02230                                           theObject,
02231                                           &argv[argvCounter],
02232                                           argc-argvCounter);
02233         }       else {
02234                 opserr << "ERROR: Unknown parameter in parameterPositioner" << endln;
02235                 return TCL_ERROR;
02236         }
02237 
02238         // ADD THE PARAMETERPOSITIONER TO THE DOMAIN
02239         if (theReliabilityDomain->addParameterPositioner(theParameterPositioner) == false) {
02240                 opserr << "ERROR: failed to add parameter positioner number " << tag << " to the domain." << endln;
02241                 delete theParameterPositioner; // otherwise memory leak
02242                 return TCL_ERROR;
02243         }
02244 
02245         return TCL_OK;
02246 
02247 }
02248 
02249 
02250 
02252 int 
02253 TclReliabilityModelBuilder_addModulatingFunction(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02254 {
02255         ModulatingFunction *theModulatingFunction = 0;
02256 
02257         if (strcmp(argv[2],"gamma") == 0) {
02258 
02259                 if (argc!=7) {
02260                         opserr << "ERROR: Incorrect number of arguments to gamma modulating function" << endln;
02261                         return TCL_ERROR;
02262                 }
02263 
02264                 int thisTag, filterTag;
02265                 double a,b,c;
02266 
02267                 // GET INPUT PARAMETER (integer)
02268                 if (Tcl_GetInt(interp, argv[1], &thisTag) != TCL_OK) {
02269                         opserr << "ERROR: invalid input: tag \n";
02270                         return TCL_ERROR;
02271                 }
02272 
02273                 // GET INPUT PARAMETER (integer)
02274                 if (Tcl_GetInt(interp, argv[3], &filterTag) != TCL_OK) {
02275                         opserr << "ERROR: invalid input: filterTag \n";
02276                         return TCL_ERROR;
02277                 }
02278 
02279                 // CHECK THAT THE FILTER EXISTS
02280                 Filter *theFilter = 0;
02281                 theFilter = theReliabilityDomain->getFilter(filterTag);
02282                 if (theFilter == 0) {
02283                         opserr << "ERROR: Could not find the filter with tag " << filterTag << endln;
02284                         return TCL_ERROR;
02285                 }
02286 
02287                 // GET INPUT PARAMETER (double)
02288                 if (Tcl_GetDouble(interp, argv[4], &a) != TCL_OK) {
02289                         opserr << "ERROR: invalid input: a \n";
02290                         return TCL_ERROR;
02291                 }
02292 
02293                 // GET INPUT PARAMETER (double)
02294                 if (Tcl_GetDouble(interp, argv[5], &b) != TCL_OK) {
02295                         opserr << "ERROR: invalid input: b \n";
02296                         return TCL_ERROR;
02297                 }
02298 
02299                 // GET INPUT PARAMETER (double)
02300                 if (Tcl_GetDouble(interp, argv[6], &c) != TCL_OK) {
02301                         opserr << "ERROR: invalid input: c \n";
02302                         return TCL_ERROR;
02303                 }
02304 
02305                 // CREATE THE OBJECT
02306                 theModulatingFunction = new GammaModulatingFunction(thisTag,theFilter,a,b,c);
02307 
02308                 if (theModulatingFunction == 0) {
02309                         opserr << "ERROR: ran out of memory creating modulating function \n";
02310                         opserr << "modulating function: " << thisTag << endln;
02311                         return TCL_ERROR;
02312                 }
02313 
02314                 // ADD THE OBJECT TO THE DOMAIN
02315                 if (theReliabilityDomain->addModulatingFunction(theModulatingFunction) == false) {
02316                         opserr << "ERROR: failed to add modulating function to the domain\n";
02317                         opserr << "modulating function: " << thisTag << endln;
02318                         delete theModulatingFunction; // otherwise memory leak
02319                         return TCL_ERROR;
02320                 }
02321         }
02322         else if (strcmp(argv[2],"constant") == 0) {
02323         
02324                 int thisTag, filterTag;
02325                 double amplitude=0.0;
02326 
02327                 // GET INPUT PARAMETER (integer)
02328                 if (Tcl_GetInt(interp, argv[1], &thisTag) != TCL_OK) {
02329                         opserr << "ERROR: invalid input: tag \n";
02330                         return TCL_ERROR;
02331                 }
02332 
02333                 // GET INPUT PARAMETER (integer)
02334                 if (Tcl_GetInt(interp, argv[3], &filterTag) != TCL_OK) {
02335                         opserr << "ERROR: invalid input: filterTag \n";
02336                         return TCL_ERROR;
02337                 }
02338 
02339                 // CHECK THAT THE FILTER EXISTS
02340                 Filter *theFilter = 0;
02341                 theFilter = theReliabilityDomain->getFilter(filterTag);
02342                 if (theFilter == 0) {
02343                         opserr << "ERROR: Could not find the filter with tag " << filterTag << endln;
02344                         return TCL_ERROR;
02345                 }
02346 
02347                 // GET INPUT PARAMETER (double)
02348                 if (Tcl_GetDouble(interp, argv[4], &amplitude) != TCL_OK) {
02349                         opserr << "ERROR: invalid input: amplitude \n";
02350                         return TCL_ERROR;
02351                 }
02352 
02353                 // CREATE THE OBJECT
02354                 theModulatingFunction = new ConstantModulatingFunction(thisTag,theFilter,amplitude);
02355 
02356                 if (theModulatingFunction == 0) {
02357                         opserr << "ERROR: ran out of memory creating modulating function \n";
02358                         opserr << "modulating function: " << thisTag << endln;
02359                         return TCL_ERROR;
02360                 }
02361 
02362                 // ADD THE OBJECT TO THE DOMAIN
02363                 if (theReliabilityDomain->addModulatingFunction(theModulatingFunction) == false) {
02364                         opserr << "ERROR: failed to add modulating function to the domain\n";
02365                         opserr << "modulating function: " << thisTag << endln;
02366                         delete theModulatingFunction; // otherwise memory leak
02367                         return TCL_ERROR;
02368                 }
02369         }
02370         else if (strcmp(argv[2],"trapezoidal") == 0) {
02371         
02372                 int thisTag, filterTag;
02373 
02374                 // GET INPUT PARAMETER (integer)
02375                 if (Tcl_GetInt(interp, argv[1], &thisTag) != TCL_OK) {
02376                         opserr << "ERROR: invalid input: tag \n";
02377                         return TCL_ERROR;
02378                 }
02379 
02380                 // GET INPUT PARAMETER (integer)
02381                 if (Tcl_GetInt(interp, argv[3], &filterTag) != TCL_OK) {
02382                         opserr << "ERROR: invalid input: filterTag \n";
02383                         return TCL_ERROR;
02384                 }
02385 
02386                 // CHECK THAT THE FILTER EXISTS
02387                 Filter *theFilter = 0;
02388                 theFilter = theReliabilityDomain->getFilter(filterTag);
02389                 if (theFilter == 0) {
02390                         opserr << "ERROR: Could not find the filter with tag " << filterTag << endln;
02391                         return TCL_ERROR;
02392                 }
02393 
02394                 double t1, t2, t3, t4, amplitude;
02395 
02396                 // GET INPUT PARAMETER (double)
02397                 if (Tcl_GetDouble(interp, argv[4], &t1) != TCL_OK) {
02398                         opserr << "ERROR: invalid input to modulating function: t1 \n";
02399                         return TCL_ERROR;
02400                 }
02401 
02402                 // GET INPUT PARAMETER (double)
02403                 if (Tcl_GetDouble(interp, argv[5], &t2) != TCL_OK) {
02404                         opserr << "ERROR: invalid input to modulating function: t2 \n";
02405                         return TCL_ERROR;
02406                 }
02407 
02408                 // GET INPUT PARAMETER (double)
02409                 if (Tcl_GetDouble(interp, argv[6], &t3) != TCL_OK) {
02410                         opserr << "ERROR: invalid input to modulating function: t3 \n";
02411                         return TCL_ERROR;
02412                 }
02413 
02414                 // GET INPUT PARAMETER (double)
02415                 if (Tcl_GetDouble(interp, argv[7], &t4) != TCL_OK) {
02416                         opserr << "ERROR: invalid input to modulating function: t4 \n";
02417                         return TCL_ERROR;
02418                 }
02419 
02420                 // GET INPUT PARAMETER (double)
02421                 if (Tcl_GetDouble(interp, argv[8], &amplitude) != TCL_OK) {
02422                         opserr << "ERROR: invalid input to modulating function: amplitude \n";
02423                         return TCL_ERROR;
02424                 }
02425 
02426                 // CREATE THE OBJECT
02427                 theModulatingFunction = new TrapezoidalModulatingFunction(thisTag,theFilter,t1,t2,t3,t4,amplitude);
02428 
02429                 if (theModulatingFunction == 0) {
02430                         opserr << "ERROR: ran out of memory creating modulating function \n";
02431                         opserr << "modulating function: " << thisTag << endln;
02432                         return TCL_ERROR;
02433                 }
02434 
02435                 // ADD THE OBJECT TO THE DOMAIN
02436                 if (theReliabilityDomain->addModulatingFunction(theModulatingFunction) == false) {
02437                         opserr << "ERROR: failed to add modulating function to the domain\n";
02438                         opserr << "modulating function: " << thisTag << endln;
02439                         delete theModulatingFunction; // otherwise memory leak
02440                         return TCL_ERROR;
02441                 }
02442         }       else if (strcmp(argv[2],"Koo") == 0) {
02443         
02444                 int thisTag, filterTag;
02445 
02446                 // GET INPUT PARAMETER (integer)
02447                 if (Tcl_GetInt(interp, argv[1], &thisTag) != TCL_OK) {
02448                         opserr << "ERROR: invalid input: tag \n";
02449                         return TCL_ERROR;
02450                 }
02451 
02452                 // GET INPUT PARAMETER (integer)
02453                 if (Tcl_GetInt(interp, argv[3], &filterTag) != TCL_OK) {
02454                         opserr << "ERROR: invalid input: filterTag \n";
02455                         return TCL_ERROR;
02456                 }
02457 
02458                 // CHECK THAT THE FILTER EXISTS
02459                 Filter *theFilter = 0;
02460                 theFilter = theReliabilityDomain->getFilter(filterTag);
02461                 if (theFilter == 0) {
02462                         opserr << "ERROR: Could not find the filter with tag " << filterTag << endln;
02463                         return TCL_ERROR;
02464                 }
02465 
02466                 double t1, t2;
02467 
02468                 // GET INPUT PARAMETER (double)
02469                 if (Tcl_GetDouble(interp, argv[4], &t1) != TCL_OK) {
02470                         opserr << "ERROR: invalid input to modulating function: t1 \n";
02471                         return TCL_ERROR;
02472                 }
02473 
02474                 // GET INPUT PARAMETER (double)
02475                 if (Tcl_GetDouble(interp, argv[5], &t2) != TCL_OK) {
02476                         opserr << "ERROR: invalid input to modulating function: t2 \n";
02477                         return TCL_ERROR;
02478                 }
02479 
02480 
02481                 // CREATE THE OBJECT
02482                 theModulatingFunction = new KooModulatingFunction(thisTag,theFilter,t1,t2);
02483 
02484                 if (theModulatingFunction == 0) {
02485                         opserr << "ERROR: ran out of memory creating modulating function \n";
02486                         opserr << "modulating function: " << thisTag << endln;
02487                         return TCL_ERROR;
02488                 }
02489 
02490                 // ADD THE OBJECT TO THE DOMAIN
02491                 if (theReliabilityDomain->addModulatingFunction(theModulatingFunction) == false) {
02492                         opserr << "ERROR: failed to add modulating function to the domain\n";
02493                         opserr << "modulating function: " << thisTag << endln;
02494                         delete theModulatingFunction; // otherwise memory leak
02495                         return TCL_ERROR;
02496                 }
02497         }
02498         else {
02499                 opserr << "ERROR:: Unknown type of modulating function. " << endln;
02500                 return TCL_ERROR;
02501         }
02502 
02503         return TCL_OK;
02504 }
02506 int 
02507 TclReliabilityModelBuilder_addFilter(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02508 {
02509         Filter *theFilter = 0;
02510 
02511         if (argc != 5) {
02512                 opserr << "ERROR: Wrong number of arguments to filter command." << endln;
02513                 return TCL_ERROR;
02514         }
02515 
02516 
02517         int tag;
02518         double period_Tn, damping;
02519 
02520         // GET INPUT PARAMETER (integer)
02521         if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
02522                 opserr << "ERROR: invalid input: tag \n";
02523                 return TCL_ERROR;
02524         }
02525 
02526         // GET INPUT PARAMETER (double)
02527         if (Tcl_GetDouble(interp, argv[3], &period_Tn) != TCL_OK) {
02528                 opserr << "ERROR: invalid input: freq_wn \n";
02529                 return TCL_ERROR;
02530         }
02531 
02532         // GET INPUT PARAMETER (double)
02533         if (Tcl_GetDouble(interp, argv[4], &damping) != TCL_OK) {
02534                 opserr << "ERROR: invalid input: damping \n";
02535                 return TCL_ERROR;
02536         }
02537 
02538 
02539 
02540         if ( (strcmp(argv[2],"standard") == 0) || (strcmp(argv[2],"standardDisplacement") == 0) ) {
02541 
02542                 theFilter = new StandardLinearOscillatorDisplacementFilter(tag,period_Tn,damping);
02543         }
02544         else if ( strcmp(argv[2],"Koo") == 0 ) {
02545 
02546                 theFilter = new KooFilter(tag,period_Tn,damping);
02547         }
02548         else if (strcmp(argv[2],"standardVelocity") == 0) {
02549 
02550                 theFilter = new StandardLinearOscillatorVelocityFilter(tag,period_Tn,damping);
02551         }
02552         else if (strcmp(argv[2],"standardAcceleration") == 0) {
02553 
02554                 theFilter = new StandardLinearOscillatorAccelerationFilter(tag,period_Tn,damping);
02555         }
02556         else {
02557                 opserr << "ERROR:: Unknown type of filter. " << endln;
02558                 return TCL_ERROR;
02559         }
02560 
02561 
02562         if (theFilter == 0) {
02563                 opserr << "ERROR: ran out of memory creating filter \n";
02564                 opserr << "filter: " << tag << endln;
02565                 return TCL_ERROR;
02566         }
02567 
02568         // ADD THE OBJECT TO THE DOMAIN
02569         if (theReliabilityDomain->addFilter(theFilter) == false) {
02570                 opserr << "ERROR: failed to add filter to the domain\n";
02571                 opserr << "filter: " << tag << endln;
02572                 delete theFilter; // otherwise memory leak
02573                 return TCL_ERROR;
02574         }
02575 
02576 
02577         return TCL_OK;
02578 }
02579 
02581 int 
02582 TclReliabilityModelBuilder_addSpectrum(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02583 {
02584         Spectrum *theSpectrum = 0;
02585 
02586         if (strcmp(argv[2],"jonswap") == 0) {
02587 
02588                 int tag;
02589                 double minFreq, maxFreq, alpha, wp, gamma;
02590 
02591                 // GET INPUT PARAMETER (integer)
02592                 if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
02593                         opserr << "ERROR: invalid input: tag \n";
02594                         return TCL_ERROR;
02595                 }
02596 
02597                 // GET INPUT PARAMETER (double)
02598                 if (Tcl_GetDouble(interp, argv[3], &minFreq) != TCL_OK) {
02599                         opserr << "ERROR: invalid input: minFreq \n";
02600                         return TCL_ERROR;
02601                 }
02602 
02603                 // GET INPUT PARAMETER (double)
02604                 if (Tcl_GetDouble(interp, argv[4], &maxFreq) != TCL_OK) {
02605                         opserr << "ERROR: invalid input: maxFreq \n";
02606                         return TCL_ERROR;
02607                 }
02608 
02609                 // GET INPUT PARAMETER (double)
02610                 if (Tcl_GetDouble(interp, argv[5], &alpha) != TCL_OK) {
02611                         opserr << "ERROR: invalid input: alpha \n";
02612                         return TCL_ERROR;
02613                 }
02614 
02615                 // GET INPUT PARAMETER (double)
02616                 if (Tcl_GetDouble(interp, argv[6], &wp) != TCL_OK) {
02617                         opserr << "ERROR: invalid input: wp \n";
02618                         return TCL_ERROR;
02619                 }
02620 
02621                 // GET INPUT PARAMETER (double)
02622                 if (Tcl_GetDouble(interp, argv[7], &gamma) != TCL_OK) {
02623                         opserr << "ERROR: invalid input: gamma \n";
02624                         return TCL_ERROR;
02625                 }
02626 
02627                 // CREATE THE OBJECT 
02628                 theSpectrum = new JonswapSpectrum(tag, minFreq, maxFreq, alpha, wp, gamma);
02629 
02630                 if (theSpectrum == 0) {
02631                         opserr << "ERROR: ran out of memory creating spectrum \n";
02632                         opserr << "spectrum: " << tag << endln;
02633                         return TCL_ERROR;
02634                 }
02635 
02636                 // ADD THE OBJECT TO THE DOMAIN
02637                 if (theReliabilityDomain->addSpectrum(theSpectrum) == false) {
02638                         opserr << "ERROR: failed to add spectrum to the domain\n";
02639                         opserr << "spectrum: " << tag << endln;
02640                         delete theSpectrum; // otherwise memory leak
02641                         return TCL_ERROR;
02642                 }
02643         }
02644         else if (strcmp(argv[2],"narrowband") == 0) {
02645 
02646                 int tag;
02647                 double minFreq, maxFreq, amplitude;
02648 
02649                 // GET INPUT PARAMETER (integer)
02650                 if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
02651                         opserr << "ERROR: invalid input: tag \n";
02652                         return TCL_ERROR;
02653                 }
02654 
02655                 // GET INPUT PARAMETER (double)
02656                 if (Tcl_GetDouble(interp, argv[3], &minFreq) != TCL_OK) {
02657                         opserr << "ERROR: invalid input: minFreq \n";
02658                         return TCL_ERROR;
02659                 }
02660 
02661                 // GET INPUT PARAMETER (double)
02662                 if (Tcl_GetDouble(interp, argv[4], &maxFreq) != TCL_OK) {
02663                         opserr << "ERROR: invalid input: maxFreq \n";
02664                         return TCL_ERROR;
02665                 }
02666 
02667                 // GET INPUT PARAMETER (double)
02668                 if (Tcl_GetDouble(interp, argv[5], &amplitude) != TCL_OK) {
02669                         opserr << "ERROR: invalid input: amplitude \n";
02670                         return TCL_ERROR;
02671                 }
02672 
02673 
02674                 // CREATE THE OBJECT 
02675                 theSpectrum = new NarrowBandSpectrum(tag, minFreq, maxFreq, amplitude);
02676 
02677                 if (theSpectrum == 0) {
02678                         opserr << "ERROR: ran out of memory creating spectrum \n";
02679                         opserr << "spectrum: " << tag << endln;
02680                         return TCL_ERROR;
02681                 }
02682 
02683                 // ADD THE OBJECT TO THE DOMAIN
02684                 if (theReliabilityDomain->addSpectrum(theSpectrum) == false) {
02685                         opserr << "ERROR: failed to add spectrum to the domain\n";
02686                         opserr << "spectrum: " << tag << endln;
02687                         delete theSpectrum; // otherwise memory leak
02688                         return TCL_ERROR;
02689                 }
02690         }
02691         else if (strcmp(argv[2],"points") == 0) {
02692 
02693                 int tag;
02694                 double frequency, amplitude;
02695 
02696                 // GET INPUT PARAMETER (integer)
02697                 if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
02698                         opserr << "ERROR: invalid input: tag \n";
02699                         return TCL_ERROR;
02700                 }
02701 
02702                 if ( fmod((argc-3),2.0) ) {
02703                         opserr << "ERROR: Inconsistent number of points given to spectrum " << tag << endln;
02704                         return TCL_ERROR;
02705                 }
02706 
02707                 
02708                 int numPoints = (int)((argc-3)/2.0);
02709 
02710                 Vector frequencies(numPoints);
02711                 Vector amplitudes(numPoints);
02712                 for (int iii=1; iii<=numPoints; iii++) {
02713 
02714                         // GET INPUT PARAMETER (double)
02715                         if (Tcl_GetDouble(interp, argv[(iii-1)*2+3], &frequency) != TCL_OK) {
02716                                 opserr << "ERROR: invalid input: frequency \n";
02717                                 return TCL_ERROR;
02718                         }
02719 
02720                         // GET INPUT PARAMETER (double)
02721                         if (Tcl_GetDouble(interp, argv[(iii-1)*2+4], &amplitude) != TCL_OK) {
02722                                 opserr << "ERROR: invalid input: amplitude \n";
02723                                 return TCL_ERROR;
02724                         }
02725 
02726                         frequencies(iii-1) = frequency;
02727                         amplitudes(iii-1) = amplitude;
02728                 }
02729 
02730 
02731 
02732                 // CREATE THE OBJECT 
02733                 theSpectrum = new PointsSpectrum(tag, frequencies, amplitudes);
02734 
02735                 if (theSpectrum == 0) {
02736                         opserr << "ERROR: ran out of memory creating spectrum \n";
02737                         opserr << "spectrum: " << tag << endln;
02738                         return TCL_ERROR;
02739                 }
02740 
02741                 // ADD THE OBJECT TO THE DOMAIN
02742                 if (theReliabilityDomain->addSpectrum(theSpectrum) == false) {
02743                         opserr << "ERROR: failed to add spectrum to the domain\n";
02744                         opserr << "spectrum: " << tag << endln;
02745                         delete theSpectrum; // otherwise memory leak
02746                         return TCL_ERROR;
02747                 }
02748         }
02749         else {
02750                 opserr << "ERROR:: Unknown type of spectrum. " << endln;
02751                 return TCL_ERROR;
02752         }
02753 
02754         return TCL_OK;
02755 }
02756 
02757 
02770 int 
02771 TclReliabilityModelBuilder_addRandomNumberGenerator(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02772 {
02773         // In case this is a replacement
02774         if (theRandomNumberGenerator != 0) {
02775                 delete theRandomNumberGenerator;
02776                 theRandomNumberGenerator = 0;
02777         }
02778 
02779 
02780   // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
02781   if (strcmp(argv[1],"CStdLib") == 0) {
02782           theRandomNumberGenerator = new CStdLibRandGenerator();
02783   }
02784   else {
02785         opserr << "ERROR: unrecognized type of RandomNumberGenerator \n";
02786         return TCL_ERROR;
02787   }
02788 
02789   if (theRandomNumberGenerator == 0) {
02790         opserr << "ERROR: could not create theRandomNumberGenerator \n";
02791         return TCL_ERROR;
02792   }
02793   return TCL_OK;
02794 }
02795 
02796 
02797 
02799 int 
02800 TclReliabilityModelBuilder_addProbabilityTransformation(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02801 {
02802         // In case this is a replacement
02803         if (theProbabilityTransformation != 0) {
02804                 delete theProbabilityTransformation;
02805                 theProbabilityTransformation = 0;
02806         }
02807 
02808 
02809         // Check number of arguments
02810         if (argc!= 2 && argc!= 4) {
02811                 opserr << "ERROR: Wrong number of arguments to probability transformation." << endln;
02812                 return TCL_ERROR;
02813         }
02814 
02815 
02816         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
02817         if (strcmp(argv[1],"Nataf") == 0) {
02818 
02819                 int printFlag = 0; 
02820                 
02821                 if (argc > 2) {
02822                         if (strcmp(argv[2],"-print") == 0) {
02823 
02824                                 if (Tcl_GetInt(interp, argv[3], &printFlag) != TCL_OK) {
02825                                         opserr << "ERROR: invalid input: printFlag to Nataf transformation \n";
02826                                         return TCL_ERROR;
02827                                 }
02828                         }
02829                 }
02830 
02831                 theProbabilityTransformation = new NatafProbabilityTransformation(theReliabilityDomain,printFlag);
02832   }
02833   else {
02834         opserr << "ERROR: unrecognized type of ProbabilityTransformation \n";
02835         return TCL_ERROR;
02836   }
02837 
02838   if (theProbabilityTransformation == 0) {
02839         opserr << "ERROR: could not create theProbabilityTransformation \n";
02840         return TCL_ERROR;
02841   }
02842   return TCL_OK;
02843 }
02844 
02845 
02846 
02847 
02849 int 
02850 TclReliabilityModelBuilder_addSearchDirection(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
02851 {
02852         // In case this is a replacement
02853         if (theSearchDirection != 0) {
02854                 delete theSearchDirection;
02855                 theSearchDirection = 0;
02856         }
02857 
02858 
02859         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
02860         if (strcmp(argv[1],"iHLRF") == 0) {
02861 
02862                 if (argc != 2) {
02863                         opserr << "ERROR: Wrong number of arguments to iHLRF search direction. " << endln;
02864                         return TCL_ERROR;
02865                 }
02866 
02867                 theSearchDirection = new HLRFSearchDirection();
02868 
02869                 if (theSearchDirection == 0) {
02870                         opserr << "ERROR: could not create theSearchDirection \n";
02871                         return TCL_ERROR;
02872                 }
02873 
02874 
02875         }
02876         else if (strcmp(argv[1],"PolakHe") == 0) {
02877 
02878                 double gamma = 1.0;
02879                 double delta = 1.0;
02880 
02881                 int argvCounter = 2;
02882                 while (argc > argvCounter) {
02883                         if (strcmp(argv[argvCounter],"-gamma") == 0) {
02884                                 argvCounter++;
02885 
02886                                 if (Tcl_GetDouble(interp, argv[argvCounter], &gamma) != TCL_OK) {
02887                                         opserr << "ERROR: invalid input: gamma for Polak-He algorithm" << endln;
02888                                         return TCL_ERROR;
02889                                 }
02890                                 argvCounter++;
02891 
02892                         }
02893                         else if (strcmp(argv[argvCounter],"-delta") == 0) {
02894                                 argvCounter++;
02895 
02896                                 if (Tcl_GetDouble(interp, argv[argvCounter], &delta) != TCL_OK) {
02897                                         opserr << "ERROR: invalid input: delta for Polak-He algorithm" << endln;
02898                                         return TCL_ERROR;
02899                                 }
02900                                 argvCounter++;
02901                         }
02902                         else {
02903                                 opserr << "ERROR: Invalid input to Polak-He algorithm." << endln;
02904                                 return TCL_ERROR;
02905                         }
02906                 }
02907 
02908 
02909                 thePolakHeDualPurpose = new PolakHeSearchDirectionAndMeritFunction(gamma,delta);
02910                 theSearchDirection = thePolakHeDualPurpose;
02911         }
02912         else if (strcmp(argv[1],"GradientProjection") == 0) {
02913 
02914                 if (argc != 2) {
02915                         opserr << "ERROR: Wrong number of arguments to GradientProjection search direction. " << endln;
02916                         return TCL_ERROR;
02917                 }
02918 
02919 
02920                 // Check that a step size rule has been created
02921                 if (theStepSizeRule == 0 ) {
02922                         opserr << "Need theStepSizeRule before a GradientProjectionSearchDirection can be created" << endln;
02923                         return TCL_ERROR;
02924                 }
02925 
02926                 // Check that a transformation has been created
02927                 if (theProbabilityTransformation == 0 ) {
02928                         opserr << "Need theProbabilityTransformation before a GradientProjectionSearchDirection can be created" << endln;
02929                         return TCL_ERROR;
02930                 }
02931 
02932                 // Check that a gfun evaluator has been created
02933                 if (theGFunEvaluator == 0 ) {
02934                         opserr << "Need theGFunEvaluator before a GradientProjectionSearchDirection can be created" << endln;
02935                         return TCL_ERROR;
02936                 }
02937 
02938                 // Check that a root-finding algorithm has been created
02939                 if (theRootFindingAlgorithm == 0 ) {
02940                         opserr << "Need theRootFindingAlgorithm before a GradientProjectionSearchDirection can be created" << endln;
02941                         return TCL_ERROR;
02942                 }
02943 
02944 
02945                 theSearchDirection = new GradientProjectionSearchDirection(theStepSizeRule,
02946                                                                                                                                    theProbabilityTransformation,
02947                                                                                                                                    theGFunEvaluator,
02948                                                                                                                                    theRootFindingAlgorithm);
02949         }
02950         else if (strcmp(argv[1],"SQP") == 0) {
02951 
02952                 double c_bar = 200.0;
02953                 double e_bar = 0.5;
02954 
02955                 int argvCounter = 2;
02956                 while (argc > argvCounter) {
02957                         if (strcmp(argv[argvCounter],"-c_bar") == 0) {
02958                                 argvCounter++;
02959 
02960                                 if (Tcl_GetDouble(interp, argv[argvCounter], &c_bar) != TCL_OK) {
02961                                         opserr << "ERROR: invalid input: c_bar for algorithm" << endln;
02962                                         return TCL_ERROR;
02963                                 }
02964                                 argvCounter++;
02965 
02966                         }
02967                         else if (strcmp(argv[argvCounter],"-e_bar") == 0) {
02968                                 argvCounter++;
02969 
02970                                 if (Tcl_GetDouble(interp, argv[argvCounter], &e_bar) != TCL_OK) {
02971                                         opserr << "ERROR: invalid input: e_bar for SQP algorithm" << endln;
02972                                         return TCL_ERROR;
02973                                 }
02974                                 argvCounter++;
02975                         }
02976                         else {
02977                                 opserr << "ERROR: Invalid input to SQP algorithm." << endln;
02978                                 return TCL_ERROR;
02979                         }
02980                 }
02981 
02982 
02983                 theSQPtriplePurpose = new SQPsearchDirectionMeritFunctionAndHessian(c_bar,e_bar);
02984                 theSearchDirection = theSQPtriplePurpose;
02985 
02986                 // Set default Hessian approximation in case user forgets
02987                 theHessianApproximation = theSQPtriplePurpose;
02988 
02989                 // Set the Hessian approximation in the search direction
02990                 theSQPtriplePurpose->setHessianApproximation(theHessianApproximation);
02991 
02992         
02993         }
02994         else {
02995                 opserr << "ERROR: unrecognized type of SearchDirection \n";
02996                 return TCL_ERROR;
02997         }
02998 
02999         if (theSearchDirection == 0) {
03000                 opserr << "ERROR: could not create theSearchDirection \n";
03001                 return TCL_ERROR;
03002         }
03003         return TCL_OK;
03004 }
03005 
03006 
03007 
03008 
03009 
03010 
03012 int 
03013 TclReliabilityModelBuilder_addHessianApproximation(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03014 {
03015         // In case this is a replacement
03016         if (theHessianApproximation != 0) {
03017                 delete theHessianApproximation;
03018                 theHessianApproximation = 0;
03019         }
03020 
03021 
03022         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
03023         if (strcmp(argv[1],"SQP_BFGS") == 0) {
03024 
03025                 // Check that the SQP search direction is already created
03026                 if (theSQPtriplePurpose == 0 ) {
03027                         opserr << "Need theSQPSearchDirection before a SQP Hessian Approximation can be created" << endln;
03028                         return TCL_ERROR;
03029                 }
03030 
03031                 theHessianApproximation = theSQPtriplePurpose;
03032 
03033                 // Set the Hessian approximation in the search direction
03034                 // (this needs to be changed for generatlity; new method of search direction)
03035                 theSQPtriplePurpose->setHessianApproximation(theHessianApproximation);
03036 
03037         }
03038         else {
03039                 opserr << "ERROR: unrecognized type of HessianApproximation \n";
03040                 return TCL_ERROR;
03041         }
03042 
03043         if (theHessianApproximation == 0) {
03044                 opserr << "ERROR: could not create theHessianApproximation \n";
03045                 return TCL_ERROR;
03046         }
03047         return TCL_OK;
03048 }
03049 
03050 
03051 
03052 
03053 
03055 int 
03056 TclReliabilityModelBuilder_addMeritFunctionCheck(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03057 {
03058         // In case this is a replacement
03059         if (theMeritFunctionCheck != 0) {
03060                 delete theMeritFunctionCheck;
03061                 theMeritFunctionCheck = 0;
03062         }
03063 
03064         int argvCounter = 1;
03065 
03066         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
03067         if (strcmp(argv[argvCounter],"AdkZhang") == 0) {
03068                 argvCounter++;
03069 
03070                 double multi = 2.0;
03071                 double add = 10.0;
03072                 double factor = 0.0;
03073                 
03074                 while (argvCounter < argc) {
03075 
03076                         if (strcmp(argv[argvCounter],"-multi") == 0) {
03077                                 argvCounter++;
03078 
03079                                 if (Tcl_GetDouble(interp, argv[argvCounter], &multi) != TCL_OK) {
03080                                         opserr << "ERROR: invalid input: multi \n";
03081                                         return TCL_ERROR;
03082                                 }
03083                                 argvCounter++;
03084                         }
03085                         else if (strcmp(argv[argvCounter],"-add") == 0) {
03086                                 argvCounter++;
03087 
03088                                 if (Tcl_GetDouble(interp, argv[argvCounter], &add) != TCL_OK) {
03089                                         opserr << "ERROR: invalid input: add \n";
03090                                         return TCL_ERROR;
03091                                 }
03092                                 argvCounter++;
03093                         }
03094                         else if (strcmp(argv[argvCounter],"-factor") == 0) {
03095                                 argvCounter++;
03096 
03097                                 if (Tcl_GetDouble(interp, argv[argvCounter], &factor) != TCL_OK) {
03098                                         opserr << "ERROR: invalid input: factor \n";
03099                                         return TCL_ERROR;
03100                                 }
03101                                 argvCounter++;
03102                         }
03103                         else {
03104                                 opserr << "ERROR: Invalid input to AdkZhang merit function check. " << endln;
03105                                 return TCL_ERROR;
03106                         }
03107                 }
03108 
03109                 // Do a quick input check
03110                 if (multi<1.0 || add<0.0) {
03111                         opserr << "ERROR: Invalid values of multi/add parameters to AdkZhang merit function check." << endln;
03112                         return TCL_ERROR;
03113                 }
03114 
03115                 theMeritFunctionCheck = new AdkZhangMeritFunctionCheck(multi,add,factor);
03116         }
03117         else if (strcmp(argv[argvCounter],"PolakHe") == 0) {
03118                 argvCounter++;
03119 
03120                 // Check that the PolakHe search direction is already created
03121                 if (thePolakHeDualPurpose == 0 ) {
03122                         opserr << "Need thePolakHeSearchDirection before a PolakHe merit function can be created" << endln;
03123                         return TCL_ERROR;
03124                 }
03125                 double factor = 0.5;
03126                 while (argvCounter < argc) {
03127 
03128                         if (strcmp(argv[argvCounter],"-factor") == 0) {
03129                                 argvCounter++;
03130 
03131                                 if (Tcl_GetDouble(interp, argv[argvCounter], &factor) != TCL_OK) {
03132                                         opserr << "ERROR: invalid input: factor \n";
03133                                         return TCL_ERROR;
03134                                 }
03135                                 argvCounter++;
03136                         }
03137                         else {
03138                                 opserr << "ERROR: Invalid input to Polak He merit function check. " << endln;
03139                                 return TCL_ERROR;
03140                         }
03141                 }
03142 
03143                 thePolakHeDualPurpose->setAlpha(factor);
03144                 theMeritFunctionCheck = thePolakHeDualPurpose;
03145 
03146         }
03147         else if (strcmp(argv[argvCounter],"SQP") == 0) {
03148                 argvCounter++;
03149 
03150                 // Check that the SQP search direction is already created
03151                 if (theSQPtriplePurpose == 0 ) {
03152                         opserr << "Need theSQPSearchDirection before a SQP merit function can be created" << endln;
03153                         return TCL_ERROR;
03154                 }
03155                 
03156                 double factor = 0.5;
03157                 while (argvCounter < argc) {
03158 
03159                         if (strcmp(argv[argvCounter],"-factor") == 0) {
03160                                 argvCounter++;
03161 
03162                                 if (Tcl_GetDouble(interp, argv[argvCounter], &factor) != TCL_OK) {
03163                                         opserr << "ERROR: invalid input: factor \n";
03164                                         return TCL_ERROR;
03165                                 }
03166                                 argvCounter++;
03167                         }
03168                         else {
03169                                 opserr << "ERROR: Invalid input to SQP merit function check. " << endln;
03170                                 return TCL_ERROR;
03171                         }
03172                 }
03173 
03174                 theSQPtriplePurpose->setAlpha(factor);
03175                 theMeritFunctionCheck = theSQPtriplePurpose;
03176 
03177         }
03178         else {
03179                 opserr << "ERROR: unrecognized type of MeritFunctionCheck \n";
03180                 return TCL_ERROR;
03181         }
03182 
03183         if (theMeritFunctionCheck == 0) {
03184                 opserr << "ERROR: could not create theMeritFunctionCheck \n";
03185                 return TCL_ERROR;
03186         }
03187         return TCL_OK;
03188 }
03189 
03190 
03191 
03192 
03193 
03194 
03195 
03196 
03198 int 
03199 TclReliabilityModelBuilder_addReliabilityConvergenceCheck(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03200 {
03201         // In case this is a replacement
03202         if (theReliabilityConvergenceCheck != 0) {
03203                 delete theReliabilityConvergenceCheck;
03204                 theReliabilityConvergenceCheck = 0;
03205         }
03206 
03207 
03208         if (argc < 2) {
03209                 opserr << "ERROR: Wrong number of arguments to reliability convergence check." << endln;
03210                 return TCL_ERROR;
03211         }
03212 
03213         // Initial declarations
03214         int argvCounter = 1;
03215 
03216 
03217         if (strcmp(argv[argvCounter],"Standard") == 0) {
03218                 argvCounter++;
03219 
03220                 double e1 = 1.0e-3;
03221                 double e2 = 1.0e-3;
03222                 double scaleValue = 0.0;
03223                 int print=1;
03224 
03225                 while (argvCounter < argc) {
03226 
03227                         if (strcmp(argv[argvCounter],"-e1") == 0) {
03228                                 argvCounter++;
03229 
03230                                 if (Tcl_GetDouble(interp, argv[argvCounter], &e1) != TCL_OK) {
03231                                         opserr << "ERROR: invalid input: e1 \n";
03232                                         return TCL_ERROR;
03233                                 }
03234                                 argvCounter++;
03235                         }
03236                         else if (strcmp(argv[argvCounter],"-e2") == 0) {
03237                                 argvCounter++;
03238 
03239                                 if (Tcl_GetDouble(interp, argv[argvCounter], &e2) != TCL_OK) {
03240                                         opserr << "ERROR: invalid input: e2 \n";
03241                                         return TCL_ERROR;
03242                                 }
03243                                 argvCounter++;
03244                         }
03245                         else if (strcmp(argv[argvCounter],"-print") == 0) {
03246                                 argvCounter++;
03247 
03248                                 if (Tcl_GetInt(interp, argv[argvCounter], &print) != TCL_OK) {
03249                                         opserr << "ERROR: invalid input: print \n";
03250                                         return TCL_ERROR;
03251                                 }
03252                                 argvCounter++;
03253                         }
03254                         else if (strcmp(argv[argvCounter],"-scaleValue") == 0) {
03255                                 argvCounter++;
03256 
03257                                 if (Tcl_GetDouble(interp, argv[argvCounter], &scaleValue) != TCL_OK) {
03258                                         opserr << "ERROR: invalid input: scaleValue \n";
03259                                         return TCL_ERROR;
03260                                 }
03261                                 argvCounter++;
03262                         }
03263                         else {
03264                                 opserr << "ERROR: Invalid input to standard reliability convergence check. " << endln;
03265                                 return TCL_ERROR;
03266                         }
03267                 }
03268                         theReliabilityConvergenceCheck = new StandardReliabilityConvergenceCheck(e1,e2,scaleValue,print);
03269         }
03270         else if (strcmp(argv[argvCounter],"OptimalityCondition") == 0) {
03271                 argvCounter++;
03272 
03273                 double e1 = 1.0e-3;
03274                 double e2 = 1.0e-3;
03275                 double scaleValue = 0.0;
03276                 int print = 1;
03277 
03278                 while (argvCounter < argc) {
03279 
03280                         if (strcmp(argv[argvCounter],"-e1") == 0) {
03281                                 argvCounter++;
03282 
03283                                 if (Tcl_GetDouble(interp, argv[argvCounter], &e1) != TCL_OK) {
03284                                         opserr << "ERROR: invalid input: e1 \n";
03285                                         return TCL_ERROR;
03286                                 }
03287                                 argvCounter++;
03288                         }
03289                         else if (strcmp(argv[argvCounter],"-e2") == 0) {
03290                                 argvCounter++;
03291 
03292                                 if (Tcl_GetDouble(interp, argv[argvCounter], &e2) != TCL_OK) {
03293                                         opserr << "ERROR: invalid input: e2 \n";
03294                                         return TCL_ERROR;
03295                                 }
03296                                 argvCounter++;
03297                         }
03298                         else if (strcmp(argv[argvCounter],"-print") == 0) {
03299                                 argvCounter++;
03300 
03301                                 if (Tcl_GetInt(interp, argv[argvCounter], &print) != TCL_OK) {
03302                                         opserr << "ERROR: invalid input: print \n";
03303                                         return TCL_ERROR;
03304                                 }
03305                                 argvCounter++;
03306                         }
03307                         else if (strcmp(argv[argvCounter],"-scaleValue") == 0) {
03308                                 argvCounter++;
03309 
03310                                 if (Tcl_GetDouble(interp, argv[argvCounter], &scaleValue) != TCL_OK) {
03311                                         opserr << "ERROR: invalid input: scaleValue \n";
03312                                         return TCL_ERROR;
03313                                 }
03314                                 argvCounter++;
03315                         }
03316                         else {
03317                                 opserr << "ERROR: Invalid input to standard reliability convergence check. " << endln;
03318                                 return TCL_ERROR;
03319                         }
03320                 }
03321                 theReliabilityConvergenceCheck = new OptimalityConditionReliabilityConvergenceCheck(e1,e2,scaleValue,print);
03322         }
03323         else {
03324                 opserr << "ERROR: unrecognized type of ReliabilityConvergenceCheck \n";
03325                 return TCL_ERROR;
03326         }
03327 
03328         if (theReliabilityConvergenceCheck == 0) {
03329                 opserr << "ERROR: could not create theReliabilityConvergenceCheck \n";
03330                 return TCL_ERROR;
03331         }
03332         return TCL_OK;
03333 }
03334 
03335 
03336 
03338 int 
03339 TclReliabilityModelBuilder_addStepSizeRule(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03340 {
03341         // In case this is a replacement
03342         if (theStepSizeRule != 0) {
03343                 delete theStepSizeRule;
03344                 theStepSizeRule = 0;
03345         }
03346 
03347 
03348         // Initial declarations
03349         int argvCounter = 1;
03350 
03351 
03352         if (strcmp(argv[argvCounter],"Armijo") == 0) {
03353                 argvCounter++;
03354 
03355                 // Check that the necessary ingredients are present
03356                 if (theGFunEvaluator == 0 ) {
03357                         opserr << "Need theGFunEvaluator before an ArmijoStepSizeRule can be created" << endln;
03358                         return TCL_ERROR;
03359                 }
03360                 if (theProbabilityTransformation == 0 ) {
03361                         opserr << "Need theProbabilityTransformation before a ArmijoStepSizeRule can be created" << endln;
03362                         return TCL_ERROR;
03363                 }
03364                 if (theMeritFunctionCheck == 0 ) {
03365                         opserr << "Need theMeritFunctionCheck before a ArmijoStepSizeRule can be created" << endln;
03366                         return TCL_ERROR;
03367                 }
03368 
03369                 // Get input parameters
03370                 double base = 0.5;
03371                 int maxNumReductions = 10;
03372 
03373                 double b0 = 1.0;
03374                 int numberOfShortSteps = 2;
03375                 
03376                 double radius = 50.0;
03377                 double surfaceDistance = 0.1;
03378                 double evolution = 0.5;
03379 
03380                 int printFlag = 0;
03381                 
03382                 while (argvCounter < argc) {
03383 
03384 
03385                         if (strcmp(argv[argvCounter],"-print") == 0) {
03386                                 argvCounter++;
03387 
03388                                 if (Tcl_GetInt(interp, argv[argvCounter], &printFlag) != TCL_OK) {
03389                                         opserr << "ERROR: invalid input: printFlag \n";
03390                                         return TCL_ERROR;
03391                                 }
03392                                 argvCounter++;
03393                         }
03394                         else if (strcmp(argv[argvCounter],"-maxNum") == 0) {
03395                                 argvCounter++;
03396 
03397                                 if (Tcl_GetInt(interp, argv[argvCounter], &maxNumReductions) != TCL_OK) {
03398                                         opserr << "ERROR: invalid input: maxNumReductions \n";
03399                                         return TCL_ERROR;
03400                                 }
03401                                 argvCounter++;
03402                         }
03403                         else if (strcmp(argv[argvCounter],"-base") == 0) {
03404                                 argvCounter++;
03405 
03406                                 if (Tcl_GetDouble(interp, argv[argvCounter], &base) != TCL_OK) {
03407                                         opserr << "ERROR: invalid input: base \n";
03408                                         return TCL_ERROR;
03409                                 }
03410                                 argvCounter++;
03411                         }
03412                         else if (strcmp(argv[argvCounter],"-initial") == 0) {
03413                                 argvCounter++;
03414 
03415                                 if (Tcl_GetDouble(interp, argv[argvCounter], &b0) != TCL_OK) {
03416                                         opserr << "ERROR: invalid input: b0 \n";
03417                                         return TCL_ERROR;
03418                                 }
03419                                 argvCounter++;
03420 
03421                                 if (Tcl_GetInt(interp, argv[argvCounter], &numberOfShortSteps) != TCL_OK) {
03422                                         opserr << "ERROR: invalid input: numberOfShortSteps \n";
03423                                         return TCL_ERROR;
03424                                 }
03425                                 argvCounter++;
03426                         }
03427                         else if (strcmp(argv[argvCounter],"-sphere") == 0) {
03428                                 argvCounter++;
03429 
03430                                 if (Tcl_GetDouble(interp, argv[argvCounter], &radius) != TCL_OK) {
03431                                         opserr << "ERROR: invalid input: radius \n";
03432                                         return TCL_ERROR;
03433                                 }
03434                                 argvCounter++;
03435 
03436                                 if (Tcl_GetDouble(interp, argv[argvCounter], &surfaceDistance) != TCL_OK) {
03437                                         opserr << "ERROR: invalid input: surfaceDistance \n";
03438                                         return TCL_ERROR;
03439                                 }
03440                                 argvCounter++;
03441 
03442                                 if (Tcl_GetDouble(interp, argv[argvCounter], &evolution) != TCL_OK) {
03443                                         opserr << "ERROR: invalid input: evolution \n";
03444                                         return TCL_ERROR;
03445                                 }
03446                                 argvCounter++;
03447                         }
03448                         else {
03449                                 opserr << "ERROR: Invalid input to Armijo rule. " << endln;
03450                                 return TCL_ERROR;
03451                         }
03452                 }
03453 
03454                 theStepSizeRule = new ArmijoStepSizeRule(theGFunEvaluator,
03455                                                                                                  theProbabilityTransformation,
03456                                                                                                  theMeritFunctionCheck,
03457                                                                                                  theRootFindingAlgorithm, 
03458                                                                                                  base,
03459                                                                                                  maxNumReductions,
03460                                                                                                  b0,
03461                                                                                                  numberOfShortSteps,
03462                                                                                                  radius,
03463                                                                                                  surfaceDistance,
03464                                                                                                  evolution,
03465                                                                                                  printFlag);
03466 
03467 
03468         }
03469         else if (strcmp(argv[argvCounter],"Fixed") == 0) {
03470                 argvCounter++;
03471 
03472                 double stepSize = 1.0;
03473 
03474                 while (argvCounter < argc) {
03475 
03476                         if (strcmp(argv[argvCounter],"-stepSize") == 0) {
03477                                 argvCounter++;
03478 
03479                                 if (Tcl_GetDouble(interp, argv[argvCounter], &stepSize) != TCL_OK) {
03480                                         opserr << "ERROR: Invalid step size input to Fixed step size rule." << endln;
03481                                         return TCL_ERROR;
03482                                 }
03483                                 argvCounter++;
03484                         }
03485                         else {
03486                                 opserr << "ERROR: Invalid input to Fixed step size rule. " << endln;
03487                                 return TCL_ERROR;
03488                         }
03489 
03490                 }
03491 
03492 
03493                 theStepSizeRule = new FixedStepSizeRule(stepSize);
03494         }
03495         else {
03496                 opserr << "ERROR: unrecognized type of StepSizeRule \n";
03497                 return TCL_ERROR;
03498         }
03499 
03500         if (theStepSizeRule == 0) {
03501                 opserr << "ERROR: could not create theStepSizeRule \n";
03502                 return TCL_ERROR;
03503         }
03504         return TCL_OK;
03505 }
03506 
03507 
03508 
03510 int 
03511 TclReliabilityModelBuilder_addgFunEvaluator(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03512 {
03513         // In case this is a replacement
03514         if (theGFunEvaluator != 0) {
03515                 delete theGFunEvaluator;
03516                 theGFunEvaluator = 0;
03517         }
03518 
03519 
03520         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
03521         if (strcmp(argv[1],"Matlab") == 0) {
03522                 opserr << "ERROR: The Matlab g-function evaluator is not implemented in this " << endln
03523                         << " version of your OpenSees executable file. Please contact the " << endln
03524                         << " developer for more information." << endln;
03525                 return TCL_ERROR;
03526         }
03527         else if (strcmp(argv[1],"Tcl") == 0) {
03528 
03529                 if (argc != 4) {
03530                         opserr << "ERROR: Wrong number of arguments to Tcl g-function evaluator." << endln;
03531                         return TCL_ERROR;
03532                 }
03533 
03534                 if (strcmp(argv[2],"-file") != 0) {
03535                         opserr << "ERROR: Wrong input to Tcl g-function evaluator." << endln;
03536                         return TCL_ERROR;
03537                 }
03538                 theGFunEvaluator = new TclGFunEvaluator(interp, theReliabilityDomain, argv[3]);
03539 
03540         }
03541         else if (strcmp(argv[1],"OpenSees") == 0) {
03542 
03543                 // There are several alternatives for this command:
03544                 // gFunEvaluator  OpenSees  -file <filename>
03545                 // gFunEvaluator  OpenSees  -runToMaxTimeInGFun
03546                 // gFunEvaluator  OpenSees  -analyze <numSteps> <dt(optional)>
03547 
03548                 if (argc < 3) {
03549                         opserr << "ERROR: Too few arguments to gFunEvaluator" << endln;
03550                         return TCL_ERROR;
03551                 }
03552 
03553                 if (strcmp(argv[2],"-file") == 0) {
03554 
03555                         // Try to open the file to make sure it exists
03556                         ifstream inputFile( argv[3], ios::in );
03557                         if (inputFile.fail()) {
03558                                 opserr << "File " << *argv[3] << " could not be opened. " << endln;
03559                                 return TCL_ERROR;
03560                         }
03561                         inputFile.close();
03562 
03563                         theGFunEvaluator = new OpenSeesGFunEvaluator(
03564                                 interp, theReliabilityDomain, argv[3]);
03565                 }
03566                 else if (strcmp(argv[2],"-analyze") == 0) {
03567 
03568                         // Get number of steps
03569                         int nsteps;
03570                         if (Tcl_GetInt(interp, argv[3], &nsteps) != TCL_OK) {
03571                                 opserr << "ERROR: invalid input: numSteps for OpenSees GFunEvaluator \n";
03572                                 return TCL_ERROR;
03573                         }
03574                         // Get optional time increment
03575                         double dt = 0.0;
03576                         if (argc == 5) {
03577                                 if (Tcl_GetDouble(interp, argv[4], &dt) != TCL_OK) {
03578                                         opserr << "ERROR: invalid input: dt for OpenSees GFunEvaluator \n";
03579                                         return TCL_ERROR;
03580                                 }
03581                         }
03582                         theGFunEvaluator = new OpenSeesGFunEvaluator(interp, theReliabilityDomain, nsteps, dt);
03583 
03584                 }
03585                 else {
03586                         opserr << "ERROR: unrecognized parameter in OpenSees GFunEvaluator \n";
03587                         return TCL_ERROR;
03588                 }
03589         
03590         }
03591         else if (strcmp(argv[1],"Basic") == 0) {
03592                 theGFunEvaluator = new BasicGFunEvaluator(interp, theReliabilityDomain);
03593         }
03594         else {
03595                 opserr << "ERROR: unrecognized type of GFunEvaluator \n";
03596                 return TCL_ERROR;
03597         }
03598         
03599         if (theGFunEvaluator == 0) {
03600                 opserr << "ERROR: could not create the theGFunEvaluator \n";
03601                 return TCL_ERROR;
03602         }
03603         return TCL_OK;
03604 }
03605 
03606 
03607 
03608 
03609 
03611 int 
03612 TclReliabilityModelBuilder_addGradGEvaluator(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03613 {
03614         // In case this is a replacement
03615         if (theGradGEvaluator != 0) {
03616                 delete theGradGEvaluator;
03617                 theGradGEvaluator = 0;
03618         }
03619 
03620 
03621         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
03622         if (strcmp(argv[1],"FiniteDifference") == 0) {
03623 
03624                 double perturbationFactor = 1000.0;
03625                 bool doGradientCheck = false;
03626 
03627                 // Check that the necessary ingredients are present
03628                 if (theGFunEvaluator == 0 ) {
03629                         opserr << "Need theGFunEvaluator before a FiniteDifferenceGradGEvaluator can be created" << endln;
03630                         return TCL_ERROR;
03631                 }
03632 
03633                 // Possibly read perturbation factor
03634                 if (argc>2) {
03635                         int numExtras;
03636                         if (argc==3 || argc==4) {
03637                                 numExtras = 1;
03638                         }
03639                         else if (argc==5) {
03640                                 numExtras = 2;
03641                         }
03642                         else {
03643                                 opserr << "ERROR: Wrong number of arguments to gradGEvaluator. " << endln;
03644                                 return TCL_ERROR;
03645                         }
03646 
03647                         int counter = 2;
03648 
03649                         for (int i=1; i<=numExtras; i++) {
03650 
03651                                 if (strcmp(argv[counter],"-pert") == 0) {
03652                                         counter ++;
03653 
03654                                         if (Tcl_GetDouble(interp, argv[counter], &perturbationFactor) != TCL_OK) {
03655                                                 opserr << "ERROR: invalid input: perturbationFactor \n";
03656                                                 return TCL_ERROR;
03657                                         }
03658                                         counter++;
03659                                 }
03660                                 else if (strcmp(argv[counter],"-check") == 0) {
03661                                         counter++;
03662                                         doGradientCheck = true;
03663                                 }
03664                                 else {
03665                                         opserr << "ERROR: Error in input to gradGEvaluator. " << endln;
03666                                         return TCL_ERROR;
03667                                 }
03668                         }
03669                 }
03670 
03671                 theGradGEvaluator = new FiniteDifferenceGradGEvaluator(theGFunEvaluator, theReliabilityDomain,interp, perturbationFactor,doGradientCheck, false);
03672         }
03673         else if (strcmp(argv[1],"OpenSees") == 0) {
03674 
03675                 bool doGradientCheck = false;
03676 
03677                 if (theSensitivityAlgorithm == 0) {
03678                         opserr << "Need a DDM sensitivity algorithm before a OpenSees sensitivity evaluator can be created" << endln;
03679                         return TCL_ERROR;
03680                 }
03681 
03682                 if (argc==2) {
03683                         // Do nothing
03684                 }
03685                 else if (argc==3) {
03686                         if (strcmp(argv[2],"-check") == 0) {
03687                                 doGradientCheck = true;
03688                         }
03689                 }
03690                 else {
03691                         opserr << "ERROR: Wrong number of arguments to gradGEvaluator. " << endln;
03692                         return TCL_ERROR;
03693                 }
03694 
03695                 theGradGEvaluator = new OpenSeesGradGEvaluator(interp, theReliabilityDomain,doGradientCheck);
03696         }
03697         else {
03698                 opserr << "ERROR: unrecognized type of GradGEvaluator \n";
03699                 return TCL_ERROR;
03700         }
03701 
03702         if (theGradGEvaluator == 0) {
03703                 opserr << "ERROR: could not create theGradGEvaluator \n";
03704                 return TCL_ERROR;
03705         }
03706         return TCL_OK;
03707 }
03708 
03709 
03711 int 
03712 TclReliabilityModelBuilder_addFindCurvatures(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03713 {
03714         // In case this is a replacement
03715         if (theFindCurvatures != 0) {
03716                 delete theFindCurvatures;
03717                 theFindCurvatures = 0;
03718         }
03719 
03720 
03721         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
03722         if (strcmp(argv[1],"firstPrincipal") == 0) {
03723 
03724                 theFindCurvatures = new FirstPrincipalCurvature();
03725         }
03726         else if (strcmp(argv[1],"bySearchAlgorithm") == 0) {
03727 
03728                 // Check that the necessary ingredients are present
03729                 if (theFindDesignPointAlgorithm == 0 ) {
03730                         opserr << "Need theFindDesignPointAlgorithm before a CurvaturesBySearchAlgorithm can be created" << endln;
03731                         return TCL_ERROR;
03732                 }
03733 
03734                 int numberOfCurvatures;
03735 
03736                 // GET INPUT PARAMETER (integer)
03737                 if (Tcl_GetInt(interp, argv[2], &numberOfCurvatures) != TCL_OK) {
03738                         opserr << "ERROR: invalid input: numberOfCurvatures \n";
03739                         return TCL_ERROR;
03740                 }
03741 
03742                 theFindCurvatures = new CurvaturesBySearchAlgorithm(numberOfCurvatures,theFindDesignPointAlgorithm);
03743         }
03744         else {
03745                 opserr << "ERROR: unrecognized type of FindCurvatures \n";
03746                 return TCL_ERROR;
03747         }
03748 
03749         if (theFindCurvatures == 0) {
03750                 opserr << "ERROR: could not create theFindCurvatures \n";
03751                 return TCL_ERROR;
03752         }
03753         return TCL_OK;
03754 }
03755 
03756 
03757 
03759 int 
03760 TclReliabilityModelBuilder_addFindDesignPointAlgorithm(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03761 {
03762         // In case this is a replacement
03763         if (theFindDesignPointAlgorithm != 0) {
03764                 delete theFindDesignPointAlgorithm;
03765                 theFindDesignPointAlgorithm = 0;
03766         }
03767 
03768         if (argc < 2) {
03769                 opserr << "ERROR: Wrong number of arguments to find design point algorithm." << endln;
03770                 return TCL_ERROR;
03771         }
03772 
03773         int argvCounter = 1;
03774 
03775         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
03776         if (strcmp(argv[argvCounter],"StepSearch") == 0) {
03777                 argvCounter++;
03778 
03779                 // Check that the necessary ingredients are present
03780                 if (theGFunEvaluator == 0 ) {
03781                         opserr << "Need theGFunEvaluator before a FindDesignPointAlgorithm can be created" << endln;
03782                         return TCL_ERROR;
03783                 }
03784                 if (theGradGEvaluator == 0 ) {
03785                         opserr << "Need theGradGEvaluator before a FindDesignPointAlgorithm can be created" << endln;
03786                         return TCL_ERROR;
03787                 }
03788                 if (theStepSizeRule == 0 ) {
03789                         opserr << "Need theStepSizeRule before a FindDesignPointAlgorithm can be created" << endln;
03790                         return TCL_ERROR;
03791                 }
03792                 if (theSearchDirection == 0 ) {
03793                         opserr << "Need theSearchDirection before a FindDesignPointAlgorithm can be created" << endln;
03794                         return TCL_ERROR;
03795                 }
03796                 if (theProbabilityTransformation == 0 ) {
03797                         opserr << "Need theProbabilityTransformation before a FindDesignPointAlgorithm can be created" << endln;
03798                         return TCL_ERROR;
03799                 }
03800 //              if (theStartPoint == 0 ) {
03801 //                      opserr << "Need theStartPoint before a FindDesignPointAlgorithm can be created" << endln;
03802 //                      return TCL_ERROR;
03803 //              }
03804                 if (theReliabilityConvergenceCheck == 0 ) {
03805                         opserr << "Need theReliabilityConvergenceCheck before a FindDesignPointAlgorithm can be created" << endln;
03806                         return TCL_ERROR;
03807                 }
03808 
03809                 int printFlag=0;
03810                 char fileNamePrint[256];
03811                 strcpy(fileNamePrint,"initialized");
03812 
03813 
03814                 int maxNumIter = 100;
03815                 while (argvCounter < argc) {
03816 
03817                         if (strcmp(argv[argvCounter],"-maxNumIter") == 0) {
03818                                 argvCounter++;
03819 
03820                                 if (Tcl_GetInt(interp, argv[argvCounter], &maxNumIter) != TCL_OK) {
03821                                         opserr << "ERROR: invalid input: maxNumIter \n";
03822                                         return TCL_ERROR;
03823                                 }
03824                                 argvCounter++;
03825                         }
03826                         else if (strcmp(argv[argvCounter],"-printAllPointsX") == 0) {
03827                                 argvCounter++;
03828                                 printFlag = 1;
03829                                 strcpy(fileNamePrint,argv[argvCounter]);
03830                                 argvCounter++;
03831                         }
03832                         else if (strcmp(argv[argvCounter],"-printAllPointsY") == 0) {
03833                                 argvCounter++;
03834                                 printFlag = 2;
03835                                 strcpy(fileNamePrint,argv[argvCounter]);
03836                                 argvCounter++;
03837                         }
03838                         else if (strcmp(argv[argvCounter],"-printDesignPointX") == 0) {
03839                                 argvCounter++;
03840                                 printFlag = 3;
03841                                 strcpy(fileNamePrint,argv[argvCounter]);
03842                                 argvCounter++;
03843                         }
03844                         else if (strcmp(argv[argvCounter],"-printDesignPointY") == 0) {
03845                                 argvCounter++;
03846                                 printFlag = 4;
03847                                 strcpy(fileNamePrint,argv[argvCounter]);
03848                                 argvCounter++;
03849                         }
03850                         else if (strcmp(argv[argvCounter],"-printCurrentPointX") == 0) {
03851                                 argvCounter++;
03852                                 printFlag = 5;
03853                                 strcpy(fileNamePrint,argv[argvCounter]);
03854                                 argvCounter++;
03855                         }
03856                         else if (strcmp(argv[argvCounter],"-printCurrentPointY") == 0) {
03857                                 argvCounter++;
03858                                 printFlag = 6;
03859                                 strcpy(fileNamePrint,argv[argvCounter]);
03860                                 argvCounter++;
03861                         }
03862                         else {
03863                                 opserr << "ERROR: Invalid input to SearchWithStepSizeAndStepDirection. " << endln;
03864                                 return TCL_ERROR;
03865                         }
03866                 }
03867                 
03868                 theFindDesignPointAlgorithm = new SearchWithStepSizeAndStepDirection(
03869                                         maxNumIter, 
03870                                         theGFunEvaluator,
03871                                         theGradGEvaluator,
03872                                         theStepSizeRule,
03873                                         theSearchDirection,
03874                                         theProbabilityTransformation,
03875                                         theHessianApproximation,
03876                                         theReliabilityConvergenceCheck,
03877                                         printFlag,
03878                                         fileNamePrint,
03879                                         theStartPoint);
03880 
03881         }
03882         else {
03883                 opserr << "ERROR: unrecognized type of FindDesignPointAlgorithm Algorithm \n";
03884                 return TCL_ERROR;
03885         }
03886 
03887         if (theFindDesignPointAlgorithm == 0) {
03888                 opserr << "ERROR: could not create theFindDesignPointAlgorithm \n";
03889                 return TCL_ERROR;
03890         }
03891         return TCL_OK;
03892 }
03893 
03894 
03895 
03896 
03898 int 
03899 TclReliabilityModelBuilder_addStartPoint(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
03900 {
03901         // In case this is a replacement
03902         if (theStartPoint != 0) {
03903                 delete theStartPoint;
03904                 theStartPoint = 0;
03905         }
03906 
03907 
03908         // Check that there are enough arguments
03909         if (argc<2) {
03910                 opserr << "ERROR: Not enough arguments to theStartPoint. " << endln;
03911                 return TCL_ERROR;
03912         }
03913 
03914         int nrv = theReliabilityDomain->getNumberOfRandomVariables();
03915         RandomVariable *aRandomVariable;
03916 
03917 
03918         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
03919         if (strcmp(argv[1],"Mean") == 0) {
03920 
03921                 theStartPoint = new Vector(nrv);
03922 
03923                 for ( int i=1; i<=nrv; i++ )
03924                 {
03925                         aRandomVariable = theReliabilityDomain->getRandomVariablePtr(i);
03926                         if (aRandomVariable == 0) {
03927                                 opserr << "ERROR: when creating theStartPoint - could not find" << endln
03928                                         << " random variable with tag #" << i << "." << endln;
03929                                 return TCL_ERROR;
03930                         }
03931                         (*theStartPoint)(i-1) = aRandomVariable->getMean();
03932                 }
03933         }
03934         else if (strcmp(argv[1],"Origin") == 0) {
03935                 // This is the default option (at least from now on...)
03936                 // Do nothing; theStartPoint==0 is the indication of this case
03937         }
03938         else if (strcmp(argv[1],"Given") == 0) {
03939 
03940                 theStartPoint = new Vector(nrv);
03941 
03942                 for ( int i=1; i<=nrv; i++ )
03943                 {
03944                         aRandomVariable = theReliabilityDomain->getRandomVariablePtr(i);
03945                         if (aRandomVariable == 0) {
03946                                 opserr << "ERROR: when creating theStartPoint - could not find" << endln
03947                                         << " random variable with tag #" << i << "." << endln;
03948                                 return TCL_ERROR;
03949                         }
03950                         (*theStartPoint)(i-1) = aRandomVariable->getStartValue();
03951                 }
03952         }
03953         else if (strcmp(argv[1],"-file") == 0) {
03954 
03955                 theStartPoint = new Vector(nrv);
03956 
03957                 ifstream inputFile( argv[2], ios::in );
03958                 if (inputFile.fail()) {
03959                         opserr << "File " << *argv[2] << " could not be opened. " << endln;
03960                         return TCL_ERROR;
03961                 }
03962 
03963                 // Loop through file to see how many entries there are
03964                 int numRVs = theReliabilityDomain->getNumberOfRandomVariables();
03965                 double dummy;
03966                 int numEntries = 0;
03967                 while (inputFile >> dummy) {
03968                         numEntries++;
03969                 }
03970                 if (numEntries == 0) {
03971                         opserr << "ERROR: No entries in the file read by startPoint!" << endln;
03972                         return TCL_ERROR;
03973                 }
03974                 if (numEntries != numRVs) {
03975                         opserr << "ERROR: Wrong number of entries in the file read by startPoint." << endln;
03976                         return TCL_ERROR;
03977                 }
03978 
03979                 // Close the file
03980                 inputFile.close();
03981 
03982                 // Open it again, now being ready to store the results
03983                 ifstream inputFile2( argv[2], ios::in );
03984                 for (int i=0; i<nrv; i++){
03985                         inputFile2 >> (*theStartPoint)(i);
03986                 }
03987                 inputFile2.close();
03988 
03989         }
03990         else {
03991                 opserr << "ERROR: Invalid type of start point is given. " << endln;
03992                 return TCL_ERROR;
03993         }
03994 
03995         // Check that the vector is of correct size
03996         if (theStartPoint==0) {
03997 //              opserr << "ERROR: Could not create the start point. " << endln;
03998 //              return TCL_ERROR;
03999         }
04000         else {
04001                 if (theStartPoint->Size() != nrv) {
04002                         opserr << "ERROR: The size of the start point vector is NOT equal " << endln
04003                                 << " to the number of random variables in the model! " << endln;
04004                         return TCL_ERROR;
04005                 }
04006         }
04007 
04008         return TCL_OK;
04009 }
04010 
04011 
04012 
04013 
04014 
04015 
04016 
04018 int 
04019 TclReliabilityModelBuilder_addRootFinding(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04020 {
04021         // In case this is a replacement
04022         if (theRootFindingAlgorithm != 0) {
04023                 delete theRootFindingAlgorithm;
04024                 theRootFindingAlgorithm = 0;
04025         }
04026 
04027 
04028         if (theGFunEvaluator == 0 ) {
04029                 opserr << "Need theGFunEvaluator before a root-finding algorithm can be created" << endln;
04030                 return TCL_ERROR;
04031         }
04032 
04033         if (theProbabilityTransformation == 0 ) {
04034                 opserr << "Need theProbabilityTransformation before a root-finding algorithm can be created" << endln;
04035                 return TCL_ERROR;
04036         }
04037 
04038 
04039         int maxIter = 50;
04040         double tol = 1.0e-3;
04041         double maxStepLength = 1.0;
04042 
04043         int argvCounter = 2;
04044         while (argc > argvCounter) {
04045                 if (strcmp(argv[argvCounter],"-maxIter") == 0) {
04046                         argvCounter++;
04047 
04048                         if (Tcl_GetInt(interp, argv[argvCounter], &maxIter) != TCL_OK) {
04049                                 opserr << "ERROR: invalid input: maxIter for projection" << endln;
04050                                 return TCL_ERROR;
04051                         }
04052                         argvCounter++;
04053 
04054                 }
04055                 else if (strcmp(argv[argvCounter],"-tol") == 0) {
04056                         argvCounter++;
04057 
04058                         if (Tcl_GetDouble(interp, argv[argvCounter], &tol) != TCL_OK) {
04059                                 opserr << "ERROR: invalid input: tol factor \n";
04060                                 return TCL_ERROR;
04061                         }               
04062                         argvCounter++;
04063 
04064                 }
04065                 else if (strcmp(argv[argvCounter],"-maxStepLength") == 0) {
04066                         argvCounter++;
04067 
04068 
04069                         if (Tcl_GetDouble(interp, argv[argvCounter], &maxStepLength) != TCL_OK) {
04070                                 opserr << "ERROR: invalid input: maxStepLength factor \n";
04071                                 return TCL_ERROR;
04072                         }               
04073                         argvCounter++;
04074                 }
04075                 else {
04076                         opserr << "ERROR: Invalid input to projection algorithm. " << endln;
04077                         return TCL_ERROR;
04078                 }
04079 
04080         }
04081 
04082 
04083         if (strcmp(argv[1],"Secant") == 0) {
04084 
04085                 theRootFindingAlgorithm = new SecantRootFinding(
04086                         theReliabilityDomain,
04087                         theProbabilityTransformation,
04088                         theGFunEvaluator,
04089                         maxIter,
04090                         tol,
04091                         maxStepLength);
04092                 
04093         }
04094         else {
04095                 opserr << "ERROR: unrecognized type of root-finding algorithm \n";
04096                 return TCL_ERROR;
04097         }
04098 
04099         if (theRootFindingAlgorithm == 0) {
04100                 opserr << "ERROR: could not create root-finding algorithm \n";
04101                 return TCL_ERROR;
04102         }
04103 
04104 
04105         return TCL_OK;
04106 }
04107 
04108 
04109 
04110 
04112 int 
04113 TclReliabilityModelBuilder_runFORMAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04114 {
04115         // In case this is a replacement
04116         if (theFORMAnalysis != 0) {
04117                 delete theFORMAnalysis;
04118                 theFORMAnalysis = 0;
04119         }
04120 
04121 
04122         // Do input check
04123         char theCommand[15] = "inputCheck";
04124         Tcl_Eval( interp, theCommand );
04125 
04126 
04127         // Check number of arguments
04128         if ( (argc!=2) && (argc!=4))  {
04129                 opserr << "ERROR: Wrong number of input parameter to FORM analysis" << endln;
04130                 return TCL_ERROR;
04131         }
04132 
04133 
04134         // Check for essential tools
04135         if (theFindDesignPointAlgorithm == 0 ) {
04136                 opserr << "Need theFindDesignPointAlgorithm before a FORMAnalysis can be created" << endln;
04137                 return TCL_ERROR;
04138         }
04139         if (theProbabilityTransformation == 0 ) {
04140                 opserr << "Need theProbabilityTransformation before a FORMAnalysis can be created" << endln;
04141                 return TCL_ERROR;
04142         }
04143 
04144 
04145         // Read input parameter(s)
04146         int relSensTag = 0;
04147         if (argc == 4) {
04148                 if (strcmp(argv[2],"-relSens") == 0) {
04149                         if (Tcl_GetInt(interp, argv[3], &relSensTag) != TCL_OK) {
04150                                 opserr << "ERROR: invalid input: relSensTag \n";
04151                                 return TCL_ERROR;
04152                         }
04153                 }
04154                 else {
04155                         opserr << "ERROR: Invalid input to FORMAnalysis." << endln;
04156                         return TCL_ERROR;
04157                 }
04158         }
04159 
04160 
04161         // Create the analysis object
04162         theFORMAnalysis 
04163                 = new FORMAnalysis( theReliabilityDomain, 
04164                                                         theFindDesignPointAlgorithm, 
04165                                                         theProbabilityTransformation, 
04166                                                         argv[1] , 
04167                                                         relSensTag);
04168 
04169 
04170         // Check that it really was created
04171         if (theFORMAnalysis == 0) {
04172                 opserr << "ERROR: could not create theFORMAnalysis \n";
04173                 return TCL_ERROR;
04174         }
04175 
04176 
04177         // Now run the analysis
04178         theFORMAnalysis->analyze();
04179 
04180         return TCL_OK;
04181 }
04182 
04183 
04184 
04185 
04186 
04188 int 
04189 TclReliabilityModelBuilder_runFOSMAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04190 {
04191         // In case this is a replacement
04192         if (theFOSMAnalysis != 0) {
04193                 delete theFOSMAnalysis;
04194                 theFOSMAnalysis = 0;
04195         }
04196 
04197 
04198         // Do input check
04199         char theCommand[15] = "inputCheck";
04200         Tcl_Eval( interp, theCommand );
04201 
04202 
04203         // Check number of arguments
04204         if (argc != 2)  {
04205                 opserr << "ERROR: Wrong number of input parameter to FOSM analysis" << endln;
04206                 return TCL_ERROR;
04207         }
04208 
04209 
04210         // Check for essential ingredients
04211         if (theGFunEvaluator == 0 ) {
04212                 opserr << "Need theGFunEvaluator before a FOSMAnalysis can be created" << endln;
04213                 return TCL_ERROR;
04214         }
04215         if (theGradGEvaluator == 0 ) {
04216                 opserr << "Need theGradGEvaluator before a FOSMAnalysis can be created" << endln;
04217                 return TCL_ERROR;
04218         }
04219 
04220 
04221         theFOSMAnalysis = new FOSMAnalysis( theReliabilityDomain,
04222                                                                                         theGFunEvaluator,
04223                                                                                         theGradGEvaluator,
04224                                                                                         interp,
04225                                                                                         argv[1]);
04226 
04227         if (theFOSMAnalysis == 0) {
04228                 opserr << "ERROR: could not create theFOSMAnalysis \n";
04229                 return TCL_ERROR;
04230         }
04231 
04232         // Now run the analysis
04233         theFOSMAnalysis->analyze();
04234 
04235         return TCL_OK;
04236 }
04237 
04238 
04239 
04240 
04241 
04242 
04244 int 
04245 TclReliabilityModelBuilder_runParametricReliabilityAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04246 {
04247         // In case this is a replacement
04248         if (theParametricReliabilityAnalysis != 0) {
04249                 delete theParametricReliabilityAnalysis;
04250                 theParametricReliabilityAnalysis = 0;
04251         }
04252 
04253 
04254         // Do input check
04255         char theCommand[15] = "inputCheck";
04256         Tcl_Eval( interp, theCommand );
04257 
04258 
04259         // Check number of arguments
04260         if (argc != 9)  {
04261                 opserr << "ERROR: Wrong number of input parameter to Fragility analysis" << endln;
04262                 return TCL_ERROR;
04263         }
04264 
04265 
04266         // Check for essential ingredients
04267         if (theFindDesignPointAlgorithm == 0 ) {
04268                 opserr << "Need theFindDesignPointAlgorithm before a ParametricReliabilityAnalysis can be created" << endln;
04269                 return TCL_ERROR;
04270         }
04271         if (theGradGEvaluator == 0 ) {
04272                 opserr << "Need theGradGEvaluator before a ParametricReliabilityAnalysis can be created" << endln;
04273                 return TCL_ERROR;
04274         }
04275 
04276 
04277         // Read input
04278         bool parGiven = false;
04279         bool rangeGiven = false; 
04280         bool numIntGiven = false;
04281         int parameterNumber;
04282         double first;
04283         double last;
04284         int numIntervals;
04285         int counter = 3;
04286         for (int i=1; i<=3; i++) {
04287 
04288                 if (strcmp(argv[counter-1],"-par") == 0) {
04289                         // GET INPUT PARAMETER (int)
04290                         if (Tcl_GetInt(interp, argv[counter], &parameterNumber) != TCL_OK) {
04291                                 opserr << "ERROR: invalid input: parameterNumber \n";
04292                                 return TCL_ERROR;
04293                         }
04294                         counter++; counter++;
04295                         parGiven = true;
04296                 }
04297                 else if (strcmp(argv[counter-1],"-range") == 0) {
04298                         // GET INPUT PARAMETER (double)
04299                         if (Tcl_GetDouble(interp, argv[counter], &first) != TCL_OK) {
04300                                 opserr << "ERROR: invalid input: first bound to range \n";
04301                                 return TCL_ERROR;
04302                         }
04303                         counter++; 
04304                         // GET INPUT PARAMETER (double)
04305                         if (Tcl_GetDouble(interp, argv[counter], &last) != TCL_OK) {
04306                                 opserr << "ERROR: invalid input: last bound to range \n";
04307                                 return TCL_ERROR;
04308                         }
04309                         counter++; counter++;
04310                         rangeGiven = true;
04311                 }
04312                 else if (strcmp(argv[counter-1],"-numInt") == 0) {
04313                         // GET INPUT PARAMETER (int)
04314                         if (Tcl_GetInt(interp, argv[counter], &numIntervals) != TCL_OK) {
04315                                 opserr << "ERROR: invalid input: number of intervals \n";
04316                                 return TCL_ERROR;
04317                         }
04318                         counter++; counter++;
04319                         numIntGiven = true;
04320                 }
04321                 else {
04322                         opserr << "ERROR: invalid input to Fragility analysis " << endln;
04323                         return TCL_ERROR;
04324                 }
04325 
04326         }
04327 
04328         if (parGiven && rangeGiven && numIntGiven) {
04329                 theParametricReliabilityAnalysis = new ParametricReliabilityAnalysis( theReliabilityDomain,
04330                                                                                                   theFindDesignPointAlgorithm,
04331                                                                                                   theGradGEvaluator,
04332                                                                                                   parameterNumber,
04333                                                                                                   first,
04334                                                                                                   last,
04335                                                                                                   numIntervals,
04336                                                                                                   argv[1],
04337                                                                                                   interp);
04338         }
04339         else {
04340                 opserr << "ERROR:: some input to theParametricReliabilityAnalysis was not provided" << endln;
04341                 return TCL_ERROR;
04342         }
04343 
04344         if (theParametricReliabilityAnalysis == 0) {
04345                 opserr << "ERROR: could not create theParametricReliabilityAnalysis \n";
04346                 return TCL_ERROR;
04347         }
04348 
04349         // Now run the analysis
04350         theParametricReliabilityAnalysis->analyze();
04351 
04352         return TCL_OK;
04353 }
04354 
04356 int 
04357 TclReliabilityModelBuilder_runSORMAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04358 {
04359         // In case this is a replacement
04360         if (theSORMAnalysis != 0) {
04361                 delete theSORMAnalysis;
04362                 theSORMAnalysis = 0;
04363         }
04364 
04365 
04366         // Do input check
04367         char theCommand[15] = "inputCheck";
04368         Tcl_Eval( interp, theCommand );
04369 
04370 
04371         if (theFindCurvatures == 0 ) {
04372                 opserr << "Need theFindCurvatures before a SORMAnalysis can be created" << endln;
04373                 return TCL_ERROR;
04374         }
04375         if (theFORMAnalysis == 0 ) {
04376                 opserr << "ERROR: The current SORM implementation requires a FORM analysis" << endln
04377                         << " to have been executed previously in the same session." << endln;
04378                 return TCL_ERROR;
04379         }
04380 
04381         if (argc != 2)  {
04382                 opserr << "ERROR: Wrong number of arguments to SORM analysis" << endln;
04383                 return TCL_ERROR;
04384         }
04385 
04386         theSORMAnalysis 
04387                 = new SORMAnalysis(theReliabilityDomain, theFindCurvatures , argv[1]);
04388 
04389         if (theSORMAnalysis == 0) {
04390                 opserr << "ERROR: could not create theSORMAnalysis \n";
04391                 return TCL_ERROR;
04392         }
04393 
04394         // Now run the analysis
04395         theSORMAnalysis->analyze();
04396 
04397         return TCL_OK;
04398 }
04399 
04401 int 
04402 TclReliabilityModelBuilder_runSystemAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04403 {
04404         // In case this is a replacement
04405         if (theSystemAnalysis != 0) {
04406                 delete theSystemAnalysis;
04407                 theSystemAnalysis = 0;
04408         }
04409 
04410 
04411         // Do input check
04412         char theCommand[15] = "inputCheck";
04413         Tcl_Eval( interp, theCommand );
04414 
04415 
04416         if (argc != 3)  {
04417                 opserr << "ERROR: Wrong number of arguments to System Reliability analysis" << endln;
04418                 return TCL_ERROR;
04419         }
04420 
04421 
04422         // GET INPUT PARAMETER (string) AND CREATE THE OBJECT
04423         if (strcmp(argv[2],"allInSeries") == 0) {
04424 
04425                 theSystemAnalysis = new SystemAnalysis(theReliabilityDomain, argv[1]);
04426 
04427         }
04428         else {
04429                 opserr << "ERROR: Invalid input to system reliability analysis" << endln;
04430                 return TCL_ERROR;
04431         }
04432 
04433 
04434         if (theSystemAnalysis == 0) {
04435                 opserr << "ERROR: Could not create theSystemAnalysis. " << endln;
04436                 return TCL_ERROR;
04437         }
04438 
04439 
04440         // Now run the analysis
04441         theSystemAnalysis->analyze();
04442 
04443         return TCL_OK;
04444 }
04445 
04447 int 
04448 TclReliabilityModelBuilder_runSamplingAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04449 {
04450         // In case this is a replacement
04451         if (theSamplingAnalysis != 0) {
04452                 delete theSamplingAnalysis;
04453                 theSamplingAnalysis = 0;
04454         }
04455 
04456 
04457         // Do input check
04458         char theCommand[15] = "inputCheck";
04459         Tcl_Eval( interp, theCommand );
04460 
04461 
04462         // Check for essential tools
04463         if (theProbabilityTransformation == 0 ) {
04464                 opserr << "Need theProbabilityTransformation before a SimulationAnalyis can be created" << endln;
04465                 return TCL_ERROR;
04466         }
04467         if (theGFunEvaluator == 0 ) {
04468                 opserr << "Need theGFunEvaluator before a SimulationAnalyis can be created" << endln;
04469                 return TCL_ERROR;
04470         }
04471         if (theRandomNumberGenerator == 0 ) {
04472                 opserr << "Need theRandomNumberGenerator before a SimulationAnalyis can be created" << endln;
04473                 return TCL_ERROR;
04474         }
04475 
04476         
04477         // The following switches are available (default values are provided)
04478         // (The sampling is performed around theStartPoint, except 
04479         // for response statistics sampling; then the mean is used together
04480         // with unit sampling variance.)
04481         //
04482         //     -type  failureProbability (1)......... this is the default
04483         //     -type  responseStatistics (2)
04484         //     -type  saveGvalues (3)
04485         //
04486         //     -variance 1.0  ....................... this is the default
04487         //
04488         //     -maxNum 1000  ........................ this is the default
04489         //
04490         //     -targetCOV 0.05  ..................... this is the default
04491         //
04492         //     -print 0   (print nothing) ........... this is the default
04493         //     -print 1   (print to screen)
04494         //     -print 2   (print to restart file)
04495         //
04496 
04497         if (argc!=2 && argc!=4 && argc!=6 && argc!=8 && argc!=10 && argc!=12) {
04498                 opserr << "ERROR: Wrong number of arguments to Sampling analysis" << endln;
04499                 return TCL_ERROR;
04500         }
04501 
04502 
04503         // Declaration of input parameters
04504         int numberOfSimulations = 1000;
04505         double targetCOV                = 0.05;
04506         double samplingVariance = 1.0;
04507         int printFlag                   = 0;
04508         int analysisTypeTag             = 1;
04509 
04510 
04511         for (int i=2; i<argc; i=i+2) {
04512 
04513                 if (strcmp(argv[i],"-type") == 0) {
04514 
04515                         if (strcmp(argv[i+1],"failureProbability") == 0) {
04516 
04517                                 analysisTypeTag = 1;
04518 
04519 //                              if (theStartPoint == 0 ) {
04520 //                                      opserr << "Need theStartPoint before a SimulationAnalyis can be created" << endln;
04521 //                                      return TCL_ERROR;
04522 //                              }
04523                         }
04524                         else if ( (strcmp(argv[i+1],"responseStatistics") == 0) || (strcmp(argv[i+1],"saveGvalues") == 0) ) {
04525 
04526                                 if (strcmp(argv[i+1],"responseStatistics") == 0) {
04527                                         analysisTypeTag = 2;
04528                                 }
04529                                 else {
04530                                         analysisTypeTag = 3;
04531                                 }
04532                                 if (samplingVariance != 1.0) {
04533                                         opserr << "ERROR:: sampling variance must be 1.0 for " << endln
04534                                                 << " response statistics sampling." << endln;
04535                                         return TCL_ERROR;
04536                                 }
04537                                 // Make sure that the mean point is the sampling center
04538                                 int nrv = theReliabilityDomain->getNumberOfRandomVariables();
04539                                 RandomVariable *aRandomVariable;
04540                                 if (theStartPoint == 0) {
04541                                         theStartPoint = new Vector(nrv);
04542                                 }
04543                                 for ( int i=1; i<=nrv; i++ )
04544                                 {
04545                                         aRandomVariable = theReliabilityDomain->getRandomVariablePtr(i);
04546                                         if (aRandomVariable == 0) {
04547                                                 opserr << "ERROR: when creating theStartPoint - could not find" << endln
04548                                                         << " random variable with tag #" << i << "." << endln;
04549                                                 return TCL_ERROR;
04550                                         }
04551                                         (*theStartPoint)(i-1) = aRandomVariable->getMean();
04552                                 }
04553                                 opserr << "NOTE: The startPoint is set to the Mean due to the selected sampling analysis type." << endln;
04554                         }
04555                         else {
04556                                 opserr << "ERROR: invalid input: type \n";
04557                                 return TCL_ERROR;
04558                         }
04559                 }
04560                 else if (strcmp(argv[i],"-variance") == 0) {
04561                         // GET INPUT PARAMETER (double)
04562                         if (Tcl_GetDouble(interp, argv[i+1], &samplingVariance) != TCL_OK) {
04563                                 opserr << "ERROR: invalid input: samplingVariance \n";
04564                                 return TCL_ERROR;
04565                         }
04566                         if (analysisTypeTag == 2 && samplingVariance != 1.0) {
04567                                 opserr << "ERROR:: sampling variance must be 1.0 for " << endln
04568                                         << " response statistics sampling." << endln;
04569                                 return TCL_ERROR;
04570                         }
04571                 }
04572                 else if (strcmp(argv[i],"-maxNum") == 0) {
04573                         // GET INPUT PARAMETER (integer)
04574                         if (Tcl_GetInt(interp, argv[i+1], &numberOfSimulations) != TCL_OK) {
04575                                 opserr << "ERROR: invalid input: numberOfSimulations \n";
04576                                 return TCL_ERROR;
04577                         }
04578                 }
04579                 else if (strcmp(argv[i],"-targetCOV") == 0) {
04580                         // GET INPUT PARAMETER (double)
04581                         if (Tcl_GetDouble(interp, argv[i+1], &targetCOV) != TCL_OK) {
04582                                 opserr << "ERROR: invalid input: targetCOV \n";
04583                                 return TCL_ERROR;
04584                         }
04585                 }
04586                 else if (strcmp(argv[i],"-print") == 0) {
04587                         // GET INPUT PARAMETER (integer)
04588                         if (Tcl_GetInt(interp, argv[i+1], &printFlag) != TCL_OK) {
04589                                 opserr << "ERROR: invalid input: printFlag \n";
04590                                 return TCL_ERROR;
04591                         }
04592                 }
04593                 else {
04594                         opserr << "ERROR: invalid input to sampling analysis. " << endln;
04595                         return TCL_ERROR;
04596                 }
04597         }
04598 
04599         // Warn about illegal combinations
04600         if (analysisTypeTag==2 && printFlag==2) {
04601                 opserr << "ERROR:: The restart option of the sampling analysis cannot be " << endln
04602                         << " used together with the response statistics option. " << endln;
04603                 return TCL_ERROR;
04604         }
04605         
04606         
04607         theSamplingAnalysis 
04608                         = new SamplingAnalysis(theReliabilityDomain, 
04609                                                                         theProbabilityTransformation, 
04610                                                                         theGFunEvaluator, 
04611                                                                         theRandomNumberGenerator, 
04612                                                                         numberOfSimulations, 
04613                                                                         targetCOV,
04614                                                                         samplingVariance,
04615                                                                         printFlag,
04616                                                                         argv[1],
04617                                                                         theStartPoint,
04618                                                                         analysisTypeTag);
04619 
04620         if (theSamplingAnalysis == 0) {
04621                 opserr << "ERROR: could not create theSamplingAnalysis \n";
04622                 return TCL_ERROR;
04623         }
04624 
04625         // Now run analysis
04626         theSamplingAnalysis->analyze();
04627 
04628         return TCL_OK;
04629 
04630 }
04631 
04633 int 
04634 TclReliabilityModelBuilder_runOutCrossingAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04635 {
04636         // In case this is a replacement
04637         if (theOutCrossingAnalysis != 0) {
04638                 delete theOutCrossingAnalysis;
04639                 theOutCrossingAnalysis = 0;
04640         }
04641 
04642 
04643         // Do input check
04644         char theCommand[15] = "inputCheck";
04645         Tcl_Eval( interp, theCommand );
04646 
04647 
04648         if (theFindDesignPointAlgorithm == 0 ) {
04649                 opserr << "Need theFindDesignPointAlgorithm before an OutCrossingAnalysis can be created" << endln;
04650                 return TCL_ERROR;
04651         }
04652         if (theGFunEvaluator == 0 ) {
04653                 opserr << "Need theGFunEvaluator before an OutCrossingAnalysis can be created" << endln;
04654                 return TCL_ERROR;
04655         }
04656         if (theGradGEvaluator == 0 ) {
04657                 opserr << "Need theGradGEvaluator before an OutCrossingAnalysis can be created" << endln;
04658                 return TCL_ERROR;
04659         }
04660 
04661         int stepsToStart = 0;
04662         int stepsToEnd = 0;
04663         int sampleFreq = 1;
04664         double littleDt = 0.01;
04665         int analysisType = 1;
04666 
04667         // Loop through arguments
04668         int argvCounter = 2;
04669         while (argc > argvCounter) {
04670                 if (strcmp(argv[argvCounter],"-results") == 0) {
04671                         argvCounter++;
04672 
04673                         // GET INPUT PARAMETER (integer)
04674                         if (Tcl_GetInt(interp, argv[argvCounter], &stepsToStart) != TCL_OK) {
04675                                 opserr << "ERROR: invalid input stepsToStart to theOutCrossingAnalysis \n";
04676                                 return TCL_ERROR;
04677                         }
04678                         argvCounter++;
04679 
04680                         // GET INPUT PARAMETER (integer)
04681                         if (Tcl_GetInt(interp, argv[argvCounter], &stepsToEnd) != TCL_OK) {
04682                                 opserr << "ERROR: invalid input stepsToEnd to theOutCrossingAnalysis \n";
04683                                 return TCL_ERROR;
04684                         }
04685                         argvCounter++;
04686 
04687                         // GET INPUT PARAMETER (integer)
04688                         if (Tcl_GetInt(interp, argv[argvCounter], &sampleFreq) != TCL_OK) {
04689                                 opserr << "ERROR: invalid input sampleFreq to theOutCrossingAnalysis \n";
04690                                 return TCL_ERROR;
04691                         }
04692                         argvCounter++;
04693                 }
04694                 else if (strcmp(argv[argvCounter],"-littleDt") == 0) {
04695                         argvCounter++;
04696 
04697                           // GET INPUT PARAMETER (double)
04698                         if (Tcl_GetDouble(interp, argv[argvCounter], &littleDt) != TCL_OK) {
04699                                 opserr << "ERROR: invalid input littleDt to theOutCrossingAnalysis \n";
04700                                 return TCL_ERROR;
04701                         }
04702                         argvCounter++;
04703                 }
04704                 else if (strcmp(argv[argvCounter],"-Koo") == 0) {
04705                         argvCounter++;
04706                         analysisType = 2;
04707                 }
04708                 else if (strcmp(argv[argvCounter],"-twoSearches") == 0) {
04709                         argvCounter++;
04710                         analysisType = 1;
04711                 }
04712                 else {
04713                         opserr << "ERROR: Invalid input to theOutCrossingAnalysis." << endln;
04714                         return TCL_ERROR;
04715                         argvCounter++;
04716                 }
04717         }
04718 
04719         theOutCrossingAnalysis 
04720                         = new OutCrossingAnalysis(
04721                                 theReliabilityDomain,
04722                                 theGFunEvaluator,
04723                                 theGradGEvaluator,
04724                                 theFindDesignPointAlgorithm,
04725                                 analysisType,
04726                                 stepsToStart,
04727                                 stepsToEnd,
04728                                 sampleFreq,
04729                                 littleDt,
04730                                 argv[1]);
04731 
04732         if (theOutCrossingAnalysis == 0) {
04733                 opserr << "ERROR: could not create theOutCrossingAnalysis \n";
04734                 return TCL_ERROR;
04735         }
04736 
04737         // Now run analysis
04738         theOutCrossingAnalysis->analyze();
04739 
04740         return TCL_OK;
04741 
04742 }
04743 
04744 
04746 int 
04747 TclReliabilityModelBuilder_runGFunVisualizationAnalysis(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
04748 {
04749         // In case this is a replacement
04750         if (theGFunVisualizationAnalysis != 0) {
04751                 delete theGFunVisualizationAnalysis;
04752                 theGFunVisualizationAnalysis = 0;
04753         }
04754 
04755 
04756         // Do input check
04757         char theCommand[15] = "inputCheck";
04758         Tcl_Eval( interp, theCommand );
04759 
04760 
04761         if (theGFunEvaluator == 0 ) {
04762                 opserr << "Need theGFunEvaluator before a GFunVisualizationAnalysis can be created" << endln;
04763                 return TCL_ERROR;
04764         }
04765 
04766         if (theProbabilityTransformation == 0 ) {
04767                 opserr << "Need theProbabilityTransformation before a GFunVisualizationAnalysis can be created" << endln;
04768                 return TCL_ERROR;
04769         }
04770 
04771 
04772         // Initial declarations
04773         int rv1 = 0;
04774         int rv2 = 0;
04775         int numPts1 = 0;
04776         int numPts2 = 0;
04777         double from1 = 0.0;
04778         double to1 = 0.0;
04779         double from2 = 0.0;
04780         double to2 = 0.0;
04781 
04782         int rvDir;
04783         Matrix theMatrix;
04784         int numLinePts;
04785         Vector theDirectionVector;
04786         Vector axesVector;
04787         int convFileArgv = 0;
04788 
04789         // Tags to keep track of which options the users chooses
04790         // (and to check which ones have been given)
04791         int convResults = 0;
04792         int space = 0;
04793         int funSurf = 0;
04794         int dir = 0;
04795         int axes = 0;
04796 
04797 
04798         // Loop through arguments
04799         int argvCounter = 2;
04800         while (argc > argvCounter) {
04801                 if (strcmp(argv[argvCounter],"-convResults") == 0) {
04802                         argvCounter++;
04803 
04804                         convFileArgv = argvCounter;
04805                         if ((argc-1)<argvCounter) {
04806                                 opserr << "ERROR: No file name found for visualization of convergence results. " << endln;
04807                                 return TCL_ERROR;
04808                         }
04809                         argvCounter++;
04810 
04811                         convResults = 1;                
04812                 }
04813                 else if (strcmp(argv[argvCounter],"-space") == 0) {
04814                         argvCounter++;
04815 
04816                         if (strcmp(argv[argvCounter],"X") == 0 || strcmp(argv[argvCounter],"x") == 0) {
04817                                 space = 1;
04818                         }
04819                         else if (strcmp(argv[argvCounter],"Y") == 0 || strcmp(argv[argvCounter],"y") == 0) {
04820                                 space = 2;
04821                         }
04822                         else {
04823                                 opserr << "ERROR: Invalid input to visualization analysis. " << endln;
04824                                 return TCL_ERROR;
04825                         }
04826                         argvCounter++;
04827                 }
04828                 else if (strcmp(argv[argvCounter],"-funSurf") == 0) {
04829                         argvCounter++;
04830 
04831                         if (strcmp(argv[argvCounter],"function") == 0 ) {
04832                                 funSurf = 1;
04833                         }
04834                         else if (strcmp(argv[argvCounter],"surface") == 0 ) {
04835                                 funSurf = 2;
04836                         }
04837                         else {
04838                                 opserr << "ERROR: Invalid input to visualization analysis. " << endln;
04839                                 return TCL_ERROR;
04840                         }
04841                         argvCounter++;
04842                 }
04843                 else if (strcmp(argv[argvCounter],"-dir") == 0) {
04844                         argvCounter++;
04845 
04846                         if (strcmp(argv[argvCounter],"rv") == 0 ) {
04847                                 argvCounter++;
04848 
04849                                 dir = 1;
04850 
04851                                 // GET INPUT PARAMETER (integer)
04852                                 if (Tcl_GetInt(interp, argv[argvCounter], &rvDir) != TCL_OK) {
04853                                         opserr << "ERROR: invalid input: rvDir  in theGFunVisualizationAnalysis \n";
04854                                         return TCL_ERROR;
04855                                 }
04856                                 argvCounter++;
04857 
04858                         }
04859                         else if (strcmp(argv[argvCounter],"file") == 0 ) {
04860                                 argvCounter++;
04861 
04862                                 dir = 2;
04863 
04864                                 // Open file where the vectors are given
04865                                 ifstream inputFile( argv[argvCounter], ios::in );
04866                                 if (inputFile.fail()) {
04867                                         opserr << "File " << *argv[argvCounter] << " could not be opened. " << endln;
04868                                         return TCL_ERROR;
04869                                 }
04870 
04871                                 // Loop through file to see how many entries there are
04872                                 int numRVs = theReliabilityDomain->getNumberOfRandomVariables();
04873                                 double dummy;
04874                                 int numEntries = 0;
04875                                 while (inputFile >> dummy) {
04876                                         numEntries++;
04877                                 }
04878                                 if (numEntries == 0) {
04879                                         opserr << "ERROR: No entries in the direction file read by visualization analysis!" << endln;
04880                                         return TCL_ERROR;
04881                                 }
04882 
04883                                 // Check that the number of points are ok
04884                                 if (numEntries != numRVs) {
04885                                         opserr << "ERROR: Wrong number of entries in the the file " << argv[argvCounter] << endln;
04886                                         return TCL_ERROR;
04887                                 }
04888 
04889                                 // Close the file
04890                                 inputFile.close();
04891 
04892                                 // Open it again, now being ready to store the results in a matrix
04893                                 ifstream inputFile2( argv[argvCounter], ios::in );
04894                                 if (inputFile2.fail()) {
04895                                         opserr << "File " << *argv[argvCounter] << " could not be opened. " << endln;
04896                                         return TCL_ERROR;
04897                                 }
04898                                 argvCounter++;
04899 
04900                                 // Store the vector
04901                                 Vector dummyDirectionVector(numRVs);
04902                                 for (int i=0; i<numRVs; i++) {
04903                                                 inputFile2 >> dummyDirectionVector(i);
04904                                 }
04905                                 inputFile2.close();
04906 
04907                                 theDirectionVector = dummyDirectionVector;
04908 
04909                                 argvCounter++;
04910                         }
04911                         else {
04912                                 opserr << "ERROR: Invalid input to visualization analysis. " << endln;
04913                                 return TCL_ERROR;
04914                         }
04915                 }
04916                 else if (strcmp(argv[argvCounter],"-coords1") == 0) {
04917 
04918                         axes = 1;
04919                         argvCounter++;
04920 
04921                         // GET INPUT PARAMETER (integer)
04922                         if (Tcl_GetInt(interp, argv[argvCounter], &rv1) != TCL_OK) {
04923                                 opserr << "ERROR: invalid input: rv1  in theGFunVisualizationAnalysis \n";
04924                                 return TCL_ERROR;
04925                         }
04926                         argvCounter++;
04927 
04928                           // GET INPUT PARAMETER (double)
04929                         if (Tcl_GetDouble(interp, argv[argvCounter], &from1) != TCL_OK) {
04930                                 opserr << "ERROR: invalid input: from1 in theGFunVisualizationAnalysis \n";
04931                                 return TCL_ERROR;
04932                         }
04933                         argvCounter++;
04934 
04935                         // GET INPUT PARAMETER (double)
04936                         if (Tcl_GetDouble(interp, argv[argvCounter], &to1) != TCL_OK) {
04937                                 opserr << "ERROR: invalid input: to1 in theGFunVisualizationAnalysis \n";
04938                                 return TCL_ERROR;
04939                         }
04940                         argvCounter++;
04941 
04942                         // GET INPUT PARAMETER (double)
04943                         if (Tcl_GetInt(interp, argv[argvCounter], &numPts1) != TCL_OK) {
04944                                 opserr << "ERROR: invalid input: numPts1 in theGFunVisualizationAnalysis \n";
04945                                 return TCL_ERROR;
04946                         }
04947                         argvCounter++;
04948 
04949                         Vector dummy(4);
04950                         dummy(0) = (double)rv1;
04951                         dummy(1) = from1;
04952                         dummy(2) = to1;
04953                         dummy(3) = (double)numPts1;
04954                         axesVector = dummy;
04955 
04956                 }
04957                 else if (strcmp(argv[argvCounter],"-coords2") == 0) {
04958 
04959                         axes = 2;
04960                         argvCounter++;
04961 
04962                         // GET INPUT PARAMETER (integer)
04963                         if (Tcl_GetInt(interp, argv[argvCounter], &rv1) != TCL_OK) {
04964                                 opserr << "ERROR: invalid input: rv1  in theGFunVisualizationAnalysis \n";
04965                                 return TCL_ERROR;
04966                         }
04967                         argvCounter++;
04968 
04969                           // GET INPUT PARAMETER (double)
04970                         if (Tcl_GetDouble(interp, argv[argvCounter], &from1) != TCL_OK) {
04971                                 opserr << "ERROR: invalid input: from1 in theGFunVisualizationAnalysis \n";
04972                                 return TCL_ERROR;
04973                         }
04974                         argvCounter++;
04975 
04976                         // GET INPUT PARAMETER (double)
04977                         if (Tcl_GetDouble(interp, argv[argvCounter], &to1) != TCL_OK) {
04978                                 opserr << "ERROR: invalid input: to1 in theGFunVisualizationAnalysis \n";
04979                                 return TCL_ERROR;
04980                         }
04981                         argvCounter++;
04982 
04983                         // GET INPUT PARAMETER (double)
04984                         if (Tcl_GetInt(interp, argv[argvCounter], &numPts1) != TCL_OK) {
04985                                 opserr << "ERROR: invalid input: numPts1 in theGFunVisualizationAnalysis \n";
04986                                 return TCL_ERROR;
04987                         }
04988                         argvCounter++;
04989 
04990                         // GET INPUT PARAMETER (integer)
04991                         if (Tcl_GetInt(interp, argv[argvCounter], &rv2) != TCL_OK) {
04992                                 opserr << "ERROR: invalid input: rv2  in theGFunVisualizationAnalysis \n";
04993                                 return TCL_ERROR;
04994                         }
04995                         argvCounter++;
04996 
04997                           // GET INPUT PARAMETER (double)
04998                         if (Tcl_GetDouble(interp, argv[argvCounter], &from2) != TCL_OK) {
04999                                 opserr << "ERROR: invalid input: from2 in theGFunVisualizationAnalysis \n";
05000                                 return TCL_ERROR;
05001                         }
05002                         argvCounter++;
05003 
05004                         // GET INPUT PARAMETER (double)
05005                         if (Tcl_GetDouble(interp, argv[argvCounter], &to2) != TCL_OK) {
05006                                 opserr << "ERROR: invalid input: to2 in theGFunVisualizationAnalysis \n";
05007                                 return TCL_ERROR;
05008                         }
05009                         argvCounter++;
05010 
05011                         // GET INPUT PARAMETER (double)
05012                         if (Tcl_GetInt(interp, argv[argvCounter], &numPts2) != TCL_OK) {
05013                                 opserr << "ERROR: invalid input: numPts2 in theGFunVisualizationAnalysis \n";
05014                                 return TCL_ERROR;
05015                         }
05016                         argvCounter++;
05017 
05018                         Vector dummy(8);
05019                         dummy(0) = (double)rv1;
05020                         dummy(1) = from1;
05021                         dummy(2) = to1;
05022                         dummy(3) = (double)numPts1;
05023                         dummy(4) = (double)rv2;
05024                         dummy(5) = from2;
05025                         dummy(6) = to2;
05026                         dummy(7) = (double)numPts2;
05027                         axesVector = dummy;
05028 
05029                 }
05030                 else if (strcmp(argv[argvCounter],"-file") == 0) {
05031 
05032                         axes = 3;
05033                         argvCounter++;
05034 
05035                         // Open file where the vectors are given
05036                         ifstream inputFile( argv[argvCounter], ios::in );
05037                         if (inputFile.fail()) {
05038                                 opserr << "File " << *argv[argvCounter] << " could not be opened. " << endln;
05039                                 return TCL_ERROR;
05040                         }
05041 
05042                         // Loop through file to see how many entries there are
05043                         int numRVs = theReliabilityDomain->getNumberOfRandomVariables();
05044                         int numVectors;
05045                         double dummy;
05046                         int numEntries = 0;
05047                         while (inputFile >> dummy) {
05048                                 numEntries++;
05049                         }
05050                         if (numEntries == 0) {
05051                                 opserr << "ERROR: No entries in the file read by visualization analysis!" << endln;
05052                                 return TCL_ERROR;
05053                         }
05054 
05055                         // Check that the number of points are ok
05056                         if ((numEntries % numRVs) !=0.0) {
05057                                 opserr << "ERROR: Wrong number of entries in the the file " << argv[argvCounter] << endln;
05058                                 return TCL_ERROR;
05059                         }
05060                         numVectors = (int)(numEntries/numRVs);
05061 
05062                         // Close the file
05063                         inputFile.close();
05064 
05065                         // Open it again, now being ready to store the results in a matrix
05066                         ifstream inputFile2( argv[argvCounter], ios::in );
05067                         if (inputFile2.fail()) {
05068                                 opserr << "File " << *argv[argvCounter] << " could not be opened. " << endln;
05069                                 return TCL_ERROR;
05070                         }
05071                         argvCounter++;
05072 
05073                         // Store the vectors in a matrix
05074                         Matrix dummyMatrix(numRVs,numVectors);
05075                         for (int i=0; i<numVectors; i++) {
05076                                 for (int j=0; j<numRVs; j++ ) {
05077                                         inputFile2 >> dummyMatrix(j,i);
05078                                 }
05079                         }
05080                         inputFile2.close();
05081 
05082                         theMatrix = dummyMatrix;
05083 
05084                         // GET INPUT PARAMETER (integer)
05085                         if (Tcl_GetInt(interp, argv[argvCounter], &numLinePts) != TCL_OK) {
05086                                 opserr << "ERROR: invalid input: numPts  in theGFunVisualizationAnalysis \n";
05087                                 return TCL_ERROR;
05088                         }
05089                         argvCounter++;
05090                 }
05091                 else {
05092                         opserr << "ERROR: invalid input to theGFunVisualizationAnalysis." << endln;
05093                         return TCL_ERROR;
05094                 }
05095         }
05096 
05097 
05098         // Check that the input was more or less reasonable
05099         // convResults [ 0:no,                   1:yes                 ]
05100         // space       [ 0:error,                1:X,        2:Y       ]
05101         // funSurf     [ 0:error,                1:function, 2:surface ]
05102         // dir         [ 0:(needed for surface), 1:rv,       2:file    ] (pass rvDir or theDirectionVector)
05103         // axes        [ 0:error,   1:coords1,   2:coords2,  3:file    ] (pass axesVector... or theMatrix+numLinePts)
05104 
05105         if (space==0 || funSurf==0 || axes==0) {
05106                 opserr << "ERROR: Some input is missing to the visualization analysis." << endln;
05107                 return TCL_ERROR;
05108         }
05109         if (dir==0 && funSurf==2) {
05110                 opserr << "A direction is needed for visualization of the limit-state surface." << endln;
05111                 return TCL_ERROR;
05112         }
05113 
05114         theGFunVisualizationAnalysis = new GFunVisualizationAnalysis(
05115                                                                                         theReliabilityDomain, 
05116                                                                                         theGFunEvaluator, 
05117                                                                                         theProbabilityTransformation, 
05118                                                                                         argv[1],
05119                                                                                         argv[convFileArgv],
05120                                                                                         convResults,
05121                                                                                         space,
05122                                                                                         funSurf,
05123                                                                                         axes,
05124                                                                                         dir);
05125 
05126 
05127         // Pass stuff to the analysis object
05128         if (dir == 1) {
05129                 theGFunVisualizationAnalysis->setDirection(rvDir);
05130         }
05131         else if (dir == 2) {
05132                 theGFunVisualizationAnalysis->setDirection(theDirectionVector);
05133         }
05134 
05135         if (axes == 1 || axes == 2) {
05136                 theGFunVisualizationAnalysis->setAxes(axesVector);
05137         }
05138         else if (axes == 3) {
05139                 theGFunVisualizationAnalysis->setAxes(theMatrix);
05140                 theGFunVisualizationAnalysis->setNumLinePts(numLinePts) ;       
05141         }
05142         
05143         if (axes == 1 || axes == 2) {
05144 
05145 //              if (theStartPoint == 0 ) {
05146 //                      opserr << "Need theStartPoint before this GFunVisualizationAnalysis can be created" << endln;
05147 //                      return TCL_ERROR;
05148 //              }
05149                 
05150                 theGFunVisualizationAnalysis->setStartPoint(theStartPoint);
05151         }
05152 
05153         if (convResults == 1) {
05154 
05155                 if (theGradGEvaluator == 0 ) {
05156                         opserr << "Need theGradGEvaluator before this GFunVisualizationAnalysis can be created" << endln;
05157                         return TCL_ERROR;
05158                 }
05159 
05160                 if (theMeritFunctionCheck == 0 ) {
05161                         opserr << "Need theMeritFunctionCheck before this GFunVisualizationAnalysis can be created" << endln;
05162                         return TCL_ERROR;
05163                 }
05164 
05165                 if (theReliabilityConvergenceCheck == 0 ) {
05166                         opserr << "Need theReliabilityConvergenceCheck before this GFunVisualizationAnalysis can be created" << endln;
05167                         return TCL_ERROR;
05168                 }
05169 
05170                 theGFunVisualizationAnalysis->setGradGEvaluator(theGradGEvaluator);
05171                 theGFunVisualizationAnalysis->setMeritFunctionCheck(theMeritFunctionCheck);
05172                 theGFunVisualizationAnalysis->setReliabilityConvergenceCheck(theReliabilityConvergenceCheck);
05173         }
05174 
05175         if (funSurf == 2) {
05176 
05177                 if (theRootFindingAlgorithm == 0 ) {
05178                         opserr << "Need theRootFindingAlgorithm before this GFunVisualizationAnalysis can be created" << endln;
05179                         return TCL_ERROR;
05180                 }
05181 
05182                 theGFunVisualizationAnalysis->setRootFindingAlgorithm(theRootFindingAlgorithm);
05183         }
05184 
05185 
05186         // It is chosen to have only one constructor. 
05187         // Hence, pass some stuff via methods, depending on analysis options. 
05188 
05189 
05190         if (theGFunVisualizationAnalysis == 0) {
05191                 opserr << "ERROR: could not create theGFunVisualizationAnalysis \n";
05192                 return TCL_ERROR;
05193         }
05194 
05195         // Now run the analysis
05196         theGFunVisualizationAnalysis->analyze();
05197 
05198         return TCL_OK;
05199 }
05200 
05201 
05202 
05203 
05204 
05206 int 
05207 TclReliabilityModelBuilder_rvReduction(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
05208 {
05209 
05210         // Check that this is not done after transformation etc has been created
05211         if (theProbabilityTransformation != 0 ) {
05212                 opserr << "ERROR: R.v. reduction cannot be performed after the " << endln
05213                         << " probability transformation has been created." << endln;
05214                 return TCL_ERROR;
05215         }
05216 
05217 
05218         // Initial declarations
05219         int i, j;
05220         int rvNum;
05221         bool result;
05222         bool isInList, rv1isInList, rv2isInList;
05223         Vector keepRvs;
05224 
05225 
05226 
05227 
05228 
05229 
05230         // Read user-given numbers of random variables to keep
05231         int numInList;
05232         if (strcmp(argv[1],"-list") == 0) {
05233                 numInList = argc-2;
05234                 Vector tempKeepRvs(numInList);
05235                 for (i=1; i<=numInList; i++) {
05236                         if (Tcl_GetInt(interp, argv[i+1], &rvNum) != TCL_OK) {
05237                                 opserr << "ERROR: Invalid input to r.v. reduction command." << endln;
05238                                 return TCL_ERROR;
05239                         }
05240                         tempKeepRvs(i-1) = rvNum;
05241                 }
05242                 keepRvs = tempKeepRvs;
05243         }
05244         else if (strcmp(argv[1],"-file") == 0) {
05245 
05246                 // Check how many entries we should read
05247                 if (Tcl_GetInt(interp, argv[3], &numInList) != TCL_OK) {
05248                         opserr << "ERROR: Invalid input to r.v. reduction command." << endln;
05249                         return TCL_ERROR;
05250                 }
05251 
05252                 // Read entries
05253                 Vector tempKeepRvs(numInList);
05254                 ifstream inputFile( argv[2], ios::in );
05255                 if (inputFile.fail()) {
05256                         opserr << "File " << *argv[2] << " could not be opened. " << endln;
05257                         return TCL_ERROR;
05258                 }
05259                 for (int i=0; i<numInList; i++) {
05260                                 inputFile >> tempKeepRvs(i);
05261                 }
05262                 inputFile.close();
05263                 keepRvs = tempKeepRvs;
05264         }
05265         else {
05266                 opserr << "ERROR: Invalid argument to r.v. reduction. " << endln;
05267                 return TCL_ERROR;
05268         }
05269 
05270 
05271 
05272         // Handle re-creation of random variables
05273         ArrayOfTaggedObjects aListOfRandomVariables(256);
05274         int nrv = theReliabilityDomain->getNumberOfRandomVariables();
05275         RandomVariable *aRandomVariable;
05276         int newTag;
05277         for (i=1; i<=nrv; i++) {
05278                 isInList = false;
05279                 for (j=1; j<=numInList; j++) {
05280                         if (keepRvs(j-1)==i) {
05281                                 isInList = true;
05282                                 newTag = j;
05283                                 break;
05284                         }
05285                 }
05286                 aRandomVariable = theReliabilityDomain->getRandomVariablePtr(i);
05287                 if (!isInList) {
05288                         delete aRandomVariable;
05289                 }
05290                 else {
05291                         aRandomVariable->setNewTag(newTag);
05292                         result = aListOfRandomVariables.addComponent(aRandomVariable);
05293                 }
05294                 theReliabilityDomain->removeRandomVariable(i);
05295         }
05296         // Add the new random variables to the reliability domain
05297         for (i=1; i<=numInList; i++) {
05298                 theReliabilityDomain->addRandomVariable((RandomVariable*)aListOfRandomVariables.getComponentPtr(i));
05299         }
05300 
05301 
05302 
05303 
05304 
05305 
05306 
05307 
05308         // Handle the re-creation of correlation coefficients
05309         int nCorr = theReliabilityDomain->getNumberOfCorrelationCoefficients();
05310         int count = 1;
05311         ArrayOfTaggedObjects aListOfCorrelationCoefficients(256);
05312         CorrelationCoefficient *aCorrelationCoefficient;
05313         CorrelationCoefficient *aNewCorrelationCoefficient;
05314         int rv1, rv2, newRv1, newRv2;
05315         double rho;
05316         for (i=1; i<=nCorr; i++) {
05317 
05318                 // Get correlation data
05319                 aCorrelationCoefficient = theReliabilityDomain->getCorrelationCoefficientPtr(i);
05320                 rv1 = aCorrelationCoefficient->getRv1();
05321                 rv2 = aCorrelationCoefficient->getRv2();
05322                 rho = aCorrelationCoefficient->getCorrelation();
05323 
05324                 // Get random variable numbers and possibly create a new correlation coefficient
05325                 rv1isInList = false;
05326                 rv2isInList = false;
05327                 for (j=1; j<=numInList; j++) {
05328                         if (keepRvs(j-1)==rv1) {
05329                                 rv1isInList = true;
05330                                 newRv1 = j;
05331                         }
05332                         if (keepRvs(j-1)==rv2) {
05333                                 rv2isInList = true;
05334                                 newRv2 = j;
05335                         }
05336                 }
05337                 if (rv1isInList && rv2isInList) {
05338                         aNewCorrelationCoefficient = new CorrelationCoefficient(count,newRv1,newRv2,rho);
05339                         aListOfCorrelationCoefficients.addComponent(aNewCorrelationCoefficient);
05340                         count++;
05341                 }
05342                 delete aCorrelationCoefficient;
05343                 theReliabilityDomain->removeCorrelationCoefficient(i);
05344         }
05345         // Add the new correlation coefficients to the reliability domain
05346         for (i=1; i<=(count-1); i++) {
05347                 theReliabilityDomain->addCorrelationCoefficient((CorrelationCoefficient*)aListOfCorrelationCoefficients.getComponentPtr(i));
05348         }
05349 
05350 
05351 
05352 
05353 
05354 
05355         // Handle the re-creation of random variable positioners
05356         int nPos = theReliabilityDomain->getNumberOfRandomVariablePositioners();
05357         RandomVariablePositioner *aRvPositioner;
05358         ArrayOfTaggedObjects aListOfPositioners(256);
05359         count =1;
05360         int newRvNum;
05361         for (i=1; i<=nPos; i++) {
05362                 aRvPositioner = theReliabilityDomain->getRandomVariablePositionerPtr(i);
05363                 rvNum = aRvPositioner->getRvNumber();
05364                 isInList = false;
05365                 for (j=1; j<=numInList; j++) {
05366                         if (keepRvs(j-1)==rvNum) {
05367                                 isInList = true;
05368                                 newRvNum = j;
05369                                 break;
05370                         }
05371                 }
05372                 if (!isInList) {
05373                         delete aRvPositioner;
05374                 }
05375                 else {
05376                         aRvPositioner->setNewTag(count);
05377                         aRvPositioner->setRvNumber(newRvNum);
05378                         aListOfPositioners.addComponent(aRvPositioner);
05379                         count++;
05380                 }
05381                 theReliabilityDomain->removeRandomVariablePositioner(i);
05382         }
05383         // Add the new random variable positioners to the reliability domain
05384         for (i=1; i<=numInList; i++) {
05385                 theReliabilityDomain->addRandomVariablePositioner((RandomVariablePositioner*)aListOfPositioners.getComponentPtr(i));
05386         }
05387 
05388 
05389 
05390 
05391 
05392 /*
05393 nrv = theReliabilityDomain->getNumberOfRandomVariables();
05394 RandomVariable *aRV;
05395 for (i=1; i<=nrv; i++) {
05396         aRV = theReliabilityDomain->getRandomVariablePtr(i);
05397         opserr << "Mean of rv# " << i << ": " << aRV->getMean() << endln;
05398 
05399 }
05400 nrv = theReliabilityDomain->getNumberOfCorrelationCoefficients();
05401 CorrelationCoefficient *aaRV;
05402 for (i=1; i<=nrv; i++) {
05403         aaRV = theReliabilityDomain->getCorrelationCoefficientPtr(i);
05404         opserr << "Rv1: " << aaRV->getRv1() << endln;
05405         opserr << "Rv2: " << aaRV->getRv2() << endln;
05406         opserr << "Corr: " << aaRV->getCorrelation() << endln;
05407 }
05408 nrv = theReliabilityDomain->getNumberOfRandomVariablePositioners();
05409 RandomVariablePositioner *aaaRV;
05410 for (i=1; i<=nrv; i++) {
05411         aaaRV = theReliabilityDomain->getRandomVariablePositionerPtr(i);
05412         opserr << "Rv in pos: " << aaaRV->getRvNumber() << endln;
05413 }
05414 
05415 while(true) {
05416 }
05417 */
05418 
05419 
05420         return TCL_OK;
05421 }
05422 
05423 
05424 
05425 
05426 
05428 int 
05429 TclReliabilityModelBuilder_inputCheck(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
05430 {
05431         // Check that tagged objects are consequtive
05432         int i, num;
05433 
05434         num = theReliabilityDomain->getNumberOfRandomVariables();
05435         ReliabilityDomainComponent *component;
05436         for (i=1; i<=num; i++) {
05437                 component = theReliabilityDomain->getRandomVariablePtr(i);
05438                 if (component == 0) {
05439                         opserr << "ERROR: Non-consequtive random variable list." << endln;
05440                         return TCL_ERROR;
05441                 }
05442         }
05443         
05444         num = theReliabilityDomain->getNumberOfRandomVariablePositioners();
05445         for (i=1; i<=num; i++) {
05446                 component = theReliabilityDomain->getRandomVariablePositionerPtr(i);
05447                 if (component == 0) {
05448                         opserr << "ERROR: Non-consequtive random variable positioner list." << endln;
05449                         return TCL_ERROR;
05450                 }
05451         }
05452         
05453         num = theReliabilityDomain->getNumberOfCorrelationCoefficients();
05454         for (i=1; i<=num; i++) {
05455                 component = theReliabilityDomain->getCorrelationCoefficientPtr(i);
05456                 if (component == 0) {
05457                         opserr << "ERROR: Non-consequtive correlation coefficient list." << endln;
05458                         return TCL_ERROR;
05459                 }
05460         }
05461         
05462         num = theReliabilityDomain->getNumberOfFilters();
05463         for (i=1; i<=num; i++) {
05464                 component = theReliabilityDomain->getFilter(i);
05465                 if (component == 0) {
05466                         opserr << "ERROR: Non-consequtive filter list." << endln;
05467                         return TCL_ERROR;
05468                 }
05469         }
05470         
05471         num = theReliabilityDomain->getNumberOfLimitStateFunctions();
05472         for (i=1; i<=num; i++) {
05473                 component = theReliabilityDomain->getLimitStateFunctionPtr(i);
05474                 if (component == 0) {
05475                         opserr << "ERROR: Non-consequtive limit-state (performance) function list." << endln;
05476                         return TCL_ERROR;
05477                 }
05478         }
05479         
05480         num = theReliabilityDomain->getNumberOfModulatingFunctions();
05481         for (i=1; i<=num; i++) {
05482                 component = theReliabilityDomain->getModulatingFunction(i);
05483                 if (component == 0) {
05484                         opserr << "ERROR: Non-consequtive modulating function list." << endln;
05485                         return TCL_ERROR;
05486                 }
05487         }
05488         
05489         num = theReliabilityDomain->getNumberOfSpectra();
05490         for (i=1; i<=num; i++) {
05491                 component = theReliabilityDomain->getSpectrum(i);
05492                 if (component == 0) {
05493                         opserr << "ERROR: Non-consequtive spectrum list." << endln;
05494                         return TCL_ERROR;
05495                 }
05496         }
05497 
05498 
05499 
05500         // Check that the correlation matrix is positive definite
05501         // theCorrelationMatrix
05502 
05503 
05504         return TCL_OK;
05505 }
05506 
05507 
05508 
05510 int 
05511 TclReliabilityModelBuilder_tempCommand(ClientData clientData, Tcl_Interp *interp, int argc, TCL_Char **argv)
05512 {
05513 //      opserr << "The temp command does nothing now!" << endln;
05514 //      return TCL_OK;
05515 
05516 
05517         int tag;
05518         RandomVariable *rv;
05519         if (Tcl_GetInt(interp, argv[1], &tag) != TCL_OK) {
05520                 opserr << "ERROR: Invalid random variable number tag to inverse CDF command." << endln;
05521                 return TCL_ERROR;
05522         }
05523         rv = theReliabilityDomain->getRandomVariablePtr(tag);
05524         if (rv == 0) {
05525                 opserr << "ERROR: Invalid tag number to inverse CDF command. " << endln;
05526                 return TCL_ERROR;
05527         }
05528 
05529         double x = 0.25;
05530         double p = 0.25;
05531 
05532         opserr << "PDF:    " << rv->getPDFvalue(x)        << endln;
05533         opserr << "CDF:    " << rv->getCDFvalue(x)        << endln;
05534         opserr << "invCDF: " << rv->getInverseCDFvalue(p) << endln;
05535         
05536         return TCL_OK;
05537 
05538 
05539 
05540 }
05541 
05542 

Generated on Mon Oct 23 15:05:27 2006 for OpenSees by doxygen 1.5.0