ParametricReliabilityAnalysis.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.2 $
00026 // $Date: 2004/08/27 17:55:37 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/analysis/analysis/ParametricReliabilityAnalysis.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
00032 //
00033 
00034 #include <ParametricReliabilityAnalysis.h>
00035 #include <ReliabilityAnalysis.h>
00036 #include <ReliabilityDomain.h>
00037 #include <FindDesignPointAlgorithm.h>
00038 #include <GradGEvaluator.h>
00039 #include <ParameterPositioner.h>
00040 #include <NormalRV.h>
00041 #include <tcl.h>
00042 
00043 #include <fstream>
00044 #include <iomanip>
00045 #include <iostream>
00046 using std::ifstream;
00047 using std::ios;
00048 using std::setw;
00049 using std::setprecision;
00050 using std::setiosflags;
00051 
00052 ParametricReliabilityAnalysis::ParametricReliabilityAnalysis(ReliabilityDomain *passedReliabilityDomain,
00053                                                                          FindDesignPointAlgorithm *passedFindDesignPointAlgorithm,
00054                                                                          GradGEvaluator *passedGradGEvaluator,
00055                                                                          int pParameterNumber,
00056                                                                          double pFirst,
00057                                                                          double pLast,
00058                                                                          int pNumIntervals,
00059                                                                          TCL_Char *passedFileName,
00060                                                                          Tcl_Interp *passedTclInterp)
00061 :ReliabilityAnalysis()
00062 {
00063         parameterNumber = pParameterNumber;
00064         first = pFirst;
00065         last = pLast;
00066         numIntervals = pNumIntervals;
00067 
00068         theReliabilityDomain = passedReliabilityDomain;
00069         theFindDesignPointAlgorithm = passedFindDesignPointAlgorithm;
00070         theGradGEvaluator = passedGradGEvaluator;
00071 
00072         fileName = new char[256];
00073         strcpy(fileName,passedFileName);
00074 
00075         theTclInterp = passedTclInterp;
00076 }
00077 
00078 
00079 ParametricReliabilityAnalysis::~ParametricReliabilityAnalysis()
00080 {
00081         if (fileName != 0)
00082         delete [] fileName;
00083 }
00084 
00085 
00086 
00087 int 
00088 ParametricReliabilityAnalysis::analyze(void)
00089 {
00090         
00091         // Alert the user that the FORM analysis has started
00092         opserr << "Fragility Analysis is running ... " << endln;
00093 
00094 
00095         // The relevant commands are now, for instance, given like this
00096         // performanceFunction 1 "{par_1}-{u_7_1}"
00097         // runParametricReliabilityAnalysis output.out -par 1 -range 14.0 16.0 -num 10
00098 
00099 
00100         // Open output file
00101         ofstream outputFile( fileName, ios::out );
00102 
00103 
00104         // Get number of limit-state functions
00105         int numLsf = theReliabilityDomain->getNumberOfLimitStateFunctions();
00106 
00107         // Initial declarations
00108         Vector pf(numIntervals+1);
00109         Vector pdf(numIntervals+1);
00110         Vector uStar, alpha;
00111         double beta;
00112         NormalRV aStdNormRV(1,0.0,1.0,0.0);
00113         Matrix dGdPar;
00114         int numPars;
00115         double thedGdPar;
00116         Vector gradient;
00117         double currentValue;
00118         Vector currentValues(numIntervals+1);
00119         int numPos;
00120         ParameterPositioner *theParameterPositioner = 0;
00121 
00122 
00123         // Loop over number of limit-state functions and perform FORM analysis
00124         for (int lsf=1; lsf<=numLsf; lsf++ ) {
00125 
00126 
00127                 // Inform the user which limit-state function is being evaluated
00128                 opserr << "Limit-state function number: " << lsf << endln;
00129 
00130 
00131                 // Set tag of "active" limit-state function
00132                 theReliabilityDomain->setTagOfActiveLimitStateFunction(lsf);
00133 
00134 
00135                 // "Download" limit-state function from reliability domain
00136                 // fmk to Terje: you just set it so why do you need the tag again
00137                 //     also you can't do a redef inside a loop with the same def as loop variable!!!!
00138                 // => changing int lst to int newLsf in line below
00139                 int newLsf = theReliabilityDomain->getTagOfActiveLimitStateFunction();
00140                 LimitStateFunction *theLimitStateFunction = theReliabilityDomain->getLimitStateFunctionPtr(lsf);
00141                 if (theLimitStateFunction == 0) {
00142                         opserr << "ParametricReliabilityAnalysis::analyze() - could not find" << endln
00143                                 << " limit-state function with tag #" << lsf << "." << endln;
00144                         return -1;
00145                 }
00146 
00147 
00148                 // Print results to output file
00149                 outputFile << "#######################################################################" << endln;
00150                 outputFile << "#  FORM ANALYSIS RESULTS, LIMIT-STATE FUNCTION NUMBER "
00151                         <<setiosflags(ios::left)<<setprecision(1)<<setw(4)<<lsf <<"            #" << endln;
00152                 outputFile << "#                                                                     #" << endln;
00153                 outputFile << "#                                                                     #" << endln;
00154                 outputFile << "#                    Failure probability     Estimated probability    #" << endln;
00155                 outputFile << "#    Parameter       estimate (fragility)     densitity function      #" << endln;
00156                 outputFile << "#     value               (CDF)                    (PDF)              #" << endln;
00157                 outputFile.setf(ios::scientific, ios::floatfield);
00158                 outputFile.flush();
00159 
00160 
00161                 // Range over parameter values
00162                 currentValue = first;
00163                 for (int counter=0; counter<(numIntervals+1); counter++) {
00164 
00165                         currentValues(counter) = currentValue;
00166 
00167                         // Detect parameter and set value, first the 
00168                         // case where the parameter is represented by a 
00169                         // parameterPositioner
00170                         numPos = theReliabilityDomain->getNumberOfParameterPositioners();
00171                         if (numPos != 0) {
00172                                 theParameterPositioner = theReliabilityDomain->getParameterPositionerPtr(parameterNumber);
00173                                 if (theParameterPositioner == 0) {
00174                                         opserr << "ParametricReliabilityAnalysis::analyze() -- The parameter number in the " << endln
00175                                                 << " fragility analysis object does not match the parameter number " << endln
00176                                                 << " being set by the parameter positioner." << endln;
00177                                 }
00178                         }
00179                         else {
00180                                 char separators[5] = "_}{";
00181                                 char *theExpression = theLimitStateFunction->getExpression();
00182                                 char *lsf_forTokenizing = new char[1000];
00183                                 strcpy(lsf_forTokenizing,theExpression);
00184                                 char *tokenPtr = strtok( lsf_forTokenizing, separators);
00185                                 while ( tokenPtr != NULL ) {
00186                                         if ( strcmp(tokenPtr, "par") == 0) {
00187                                                 tokenPtr = strtok( NULL, separators);
00188                                                 int par = atoi( tokenPtr );
00189                                                 if (par==parameterNumber) {
00190                                                         char tclAssignment[100];
00191                                                         sprintf(tclAssignment , "set par_%d  %15.5f", parameterNumber, currentValue);
00192                                                         Tcl_Eval( theTclInterp, tclAssignment);
00193                                                 }
00194                                                 else {
00195                                                         opserr << "ParametricReliabilityAnalysis::analyze() -- The parameter number " << endln
00196                                                                 << " in the limit-state function does not match the parameter " << endln
00197                                                                 << " number in the fragility analysis object." << endln;
00198                                                 }
00199                                         }
00200                                         tokenPtr = strtok( NULL, separators);
00201                                 }
00202                         }
00203 
00204 
00205                         // Possibly set the parameter value in the FE domain
00206                         if (theParameterPositioner != 0) {
00207                                 theParameterPositioner->update(currentValue);
00208                         }
00209 
00210 
00211                         // Find the design point
00212                         if (theFindDesignPointAlgorithm->findDesignPoint(theReliabilityDomain) < 0){
00213 
00214                                 // Set detectable 'crazy' values when the design point wasn't found
00215                                 pf(counter) = -1.0;
00216                                 pdf(counter) = -1.0;
00217                         }
00218                         else {
00219 
00220                                 // Store probability of failure
00221                                 uStar                           = theFindDesignPointAlgorithm->get_u();
00222                                 alpha                           = theFindDesignPointAlgorithm->get_alpha();
00223                                 beta = alpha ^ uStar;
00224                                 pf(counter) = 1.0 - aStdNormRV.getCDFvalue(beta);
00225 
00226                                 // Compute PDF, first; derivative of lsf wrt. parameter
00227                                 dGdPar = theGradGEvaluator->getDgDpar();
00228 
00229                                 // Find the right element
00230                                 numPars = dGdPar.noRows();
00231                                 for (int i=0; i<numPars; i++) {
00232                                         if (((int)(dGdPar(i,0))) == parameterNumber) {
00233                                                 thedGdPar = dGdPar(i,1);
00234                                         }
00235                                 }
00236 
00237                                 // Gradient of limit-state function
00238                                 gradient = theFindDesignPointAlgorithm->getGradientInStandardNormalSpace();
00239 
00240                                 // Compute PDF value
00241                                 pdf(counter) = fabs( aStdNormRV.getPDFvalue(-beta) / gradient.Norm() * thedGdPar );
00242 
00243                         }
00244 
00245                         currentValue = currentValue + (last-first)/numIntervals;
00246 
00247 
00248                         // Print results to output file
00249                         outputFile << "#   " << setprecision(3)<<setw(11)<<currentValues(counter)<<"         ";
00250                         if (pf(counter)==-1.0) {
00251                                 outputFile << "--failed--              ";
00252                                 outputFile << "--failed--            #" << endln;
00253                         }
00254                         else {
00255                                 outputFile <<setprecision(3)<<setw(11)<<pf(counter)<<"             ";
00256                                 outputFile <<setprecision(3)<<setw(11)<<pdf(counter)<<"           #" << endln;
00257                         }
00258                         outputFile.flush();
00259 
00260                 } // Done looping over parameter range
00261 
00262 
00263                 outputFile << "#                                                                     #" << endln;
00264                 outputFile << "#######################################################################" << endln << endln << endln;
00265 
00266         } // Done looping over limit-state functions
00267                 
00268 
00269         // Print summary of results to screen (more here!!!)
00270         opserr << "Fragility Analysis completed." << endln;
00271 
00272 
00273         // Clean up
00274         outputFile.close();
00275 
00276         return 0;
00277 }
00278 

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