00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00092 opserr << "Fragility Analysis is running ... " << endln;
00093
00094
00095
00096
00097
00098
00099
00100
00101 ofstream outputFile( fileName, ios::out );
00102
00103
00104
00105 int numLsf = theReliabilityDomain->getNumberOfLimitStateFunctions();
00106
00107
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
00124 for (int lsf=1; lsf<=numLsf; lsf++ ) {
00125
00126
00127
00128 opserr << "Limit-state function number: " << lsf << endln;
00129
00130
00131
00132 theReliabilityDomain->setTagOfActiveLimitStateFunction(lsf);
00133
00134
00135
00136
00137
00138
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
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
00162 currentValue = first;
00163 for (int counter=0; counter<(numIntervals+1); counter++) {
00164
00165 currentValues(counter) = currentValue;
00166
00167
00168
00169
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
00206 if (theParameterPositioner != 0) {
00207 theParameterPositioner->update(currentValue);
00208 }
00209
00210
00211
00212 if (theFindDesignPointAlgorithm->findDesignPoint(theReliabilityDomain) < 0){
00213
00214
00215 pf(counter) = -1.0;
00216 pdf(counter) = -1.0;
00217 }
00218 else {
00219
00220
00221 uStar = theFindDesignPointAlgorithm->get_u();
00222 alpha = theFindDesignPointAlgorithm->get_alpha();
00223 beta = alpha ^ uStar;
00224 pf(counter) = 1.0 - aStdNormRV.getCDFvalue(beta);
00225
00226
00227 dGdPar = theGradGEvaluator->getDgDpar();
00228
00229
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
00238 gradient = theFindDesignPointAlgorithm->getGradientInStandardNormalSpace();
00239
00240
00241 pdf(counter) = fabs( aStdNormRV.getPDFvalue(-beta) / gradient.Norm() * thedGdPar );
00242
00243 }
00244
00245 currentValue = currentValue + (last-first)/numIntervals;
00246
00247
00248
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 }
00261
00262
00263 outputFile << "# #" << endln;
00264 outputFile << "#######################################################################" << endln << endln << endln;
00265
00266 }
00267
00268
00269
00270 opserr << "Fragility Analysis completed." << endln;
00271
00272
00273
00274 outputFile.close();
00275
00276 return 0;
00277 }
00278