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 <MVFOSMAnalysis.h>
00035 #include <ReliabilityAnalysis.h>
00036 #include <ReliabilityDomain.h>
00037 #include <RandomVariablePositioner.h>
00038 #include <GFunEvaluator.h>
00039 #include <GradGEvaluator.h>
00040 #include <Matrix.h>
00041 #include <Vector.h>
00042 #include <tcl.h>
00043
00044 #include <fstream>
00045 #include <iomanip>
00046 #include <iostream>
00047 using std::ifstream;
00048 using std::ios;
00049 using std::setw;
00050 using std::setprecision;
00051 using std::setiosflags;
00052
00053
00054 MVFOSMAnalysis::MVFOSMAnalysis(ReliabilityDomain *passedReliabilityDomain,
00055 GFunEvaluator *passedGFunEvaluator,
00056 GradGEvaluator *passedGradGEvaluator,
00057 Tcl_Interp *passedTclInterp,
00058 const char *passedFileName)
00059 :ReliabilityAnalysis()
00060 {
00061 theReliabilityDomain = passedReliabilityDomain;
00062 theGFunEvaluator = passedGFunEvaluator;
00063 theGradGEvaluator = passedGradGEvaluator;
00064 theTclInterp = passedTclInterp;
00065 fileName = new char[256];
00066 strcpy(fileName,passedFileName);
00067 }
00068
00069
00070 MVFOSMAnalysis::~MVFOSMAnalysis()
00071 {
00072 if (fileName != 0)
00073 delete [] fileName;
00074 }
00075
00076
00077
00078 int
00079 MVFOSMAnalysis::analyze(void)
00080 {
00081
00082
00083 opserr << "MVFOSM Analysis is running ... " << endln;
00084
00085
00086
00087 int i,j,k;
00088
00089
00090
00091 ofstream outputFile( fileName, ios::out );
00092
00093
00094
00095 int nrv = theReliabilityDomain->getNumberOfRandomVariables();
00096
00097
00098
00099 RandomVariable *aRandomVariable;
00100 Vector meanVector(nrv);
00101 for (i=1; i<=nrv; i++)
00102 {
00103 aRandomVariable = theReliabilityDomain->getRandomVariablePtr(i);
00104 if (aRandomVariable == 0) {
00105 opserr << "MVFOSMAnalysis::analyze() -- Could not find" << endln
00106 << " random variable with tag #" << i << "." << endln;
00107 return -1;
00108 }
00109 meanVector(i-1) = aRandomVariable->getMean();
00110 }
00111
00112
00113
00114 Vector stdvVector(nrv);
00115 for (i=1; i<=nrv; i++)
00116 {
00117 aRandomVariable = theReliabilityDomain->getRandomVariablePtr(i);
00118 stdvVector(i-1) = aRandomVariable->getStdv();
00119 }
00120
00121
00122
00123 int result;
00124 result = theGFunEvaluator->runGFunAnalysis(meanVector);
00125 if (result < 0) {
00126 opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln
00127 << " could not run analysis to evaluate limit-state function. " << endln;
00128 return -1;
00129 }
00130
00131
00132
00133 Matrix covMatrix(nrv,nrv);
00134 for (i=1; i<=nrv; i++) {
00135 covMatrix(i-1,i-1) = stdvVector(i-1)*stdvVector(i-1);
00136 }
00137 int ncorr = theReliabilityDomain->getNumberOfCorrelationCoefficients();
00138 CorrelationCoefficient *theCorrelationCoefficient;
00139 double covariance, correlation;
00140 int rv1, rv2;
00141 for (i=1 ; i<=ncorr ; i++) {
00142 theCorrelationCoefficient = theReliabilityDomain->getCorrelationCoefficientPtr(i);
00143 correlation = theCorrelationCoefficient->getCorrelation();
00144 rv1 = theCorrelationCoefficient->getRv1();
00145 rv2 = theCorrelationCoefficient->getRv2();
00146 covariance = correlation*stdvVector(rv1-1)*stdvVector(rv2-1);
00147 covMatrix(rv1-1,rv2-1) = covariance;
00148 covMatrix(rv2-1,rv1-1) = covariance;
00149 }
00150
00151
00152
00153 int numLsf = theReliabilityDomain->getNumberOfLimitStateFunctions();
00154 Vector gradient(nrv);
00155 Matrix matrixOfGradientVectors(nrv,numLsf);
00156 Vector meanEstimates(numLsf);
00157 Vector responseStdv(numLsf);
00158 double responseVariance;
00159
00160
00161
00162 for (int lsf=1; lsf<=numLsf; lsf++ ) {
00163
00164
00165 opserr << "Limit-state function number: " << lsf << endln;
00166
00167
00168
00169 theReliabilityDomain->setTagOfActiveLimitStateFunction(lsf);
00170
00171
00172
00173 result = theGFunEvaluator->evaluateG(meanVector);
00174 if (result < 0) {
00175 opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln
00176 << " could not tokenize limit-state function. " << endln;
00177 return -1;
00178 }
00179 meanEstimates(lsf-1) = theGFunEvaluator->getG();
00180
00181
00182
00183 result = theGradGEvaluator->evaluateGradG(meanEstimates(lsf-1),meanVector);
00184 if (result < 0) {
00185 opserr << "MVFOSMAnalysis::analyze() -- could not" << endln
00186 << " compute gradients of the limit-state function. " << endln;
00187 return -1;
00188 }
00189 gradient = theGradGEvaluator->getGradG();
00190 for (i=1 ; i<=nrv ; i++) {
00191 matrixOfGradientVectors(i-1,lsf-1) = gradient(i-1);
00192 }
00193
00194
00195
00196 responseVariance = (covMatrix^gradient)^gradient;
00197 if (responseVariance <= 0.0) {
00198 opserr << "ERROR: Response variance of limit-state function number "<< lsf << endln
00199 << " is zero! " << endln;
00200 }
00201 else {
00202 responseStdv(lsf-1) = sqrt(responseVariance);
00203 }
00204
00205
00206
00207 outputFile << "#######################################################################" << endln;
00208 outputFile << "# MVFOSM ANALYSIS RESULTS, LIMIT-STATE FUNCTION NUMBER "
00209 <<setiosflags(ios::left)<<setprecision(1)<<setw(4)<<lsf <<" #" << endln;
00210 outputFile << "# #" << endln;
00211
00212 outputFile << "# Estimated mean: .................................... "
00213 <<setiosflags(ios::left)<<setprecision(5)<<setw(12)<<meanEstimates(lsf-1)
00214 << " #" << endln;
00215 outputFile << "# Estimated standard deviation: ...................... "
00216 <<setiosflags(ios::left)<<setprecision(5)<<setw(12)<<responseStdv(lsf-1)
00217 << " #" << endln;
00218 outputFile << "# #" << endln;
00219 outputFile << "#######################################################################" << endln << endln << endln;
00220
00221
00222
00223 opserr << "Done analyzing limit-state function " << lsf << endln;
00224 }
00225
00226
00227
00228 Matrix responseCovMatrix(numLsf,numLsf);
00229 double responseCovariance;
00230 Vector gradientVector1(nrv), gradientVector2(nrv);
00231 for (i=1; i<=numLsf; i++) {
00232 for (k=0; k<nrv; k++) {
00233 gradientVector1(k) = matrixOfGradientVectors(k,i-1);
00234 }
00235 for (j=i+1; j<=numLsf; j++) {
00236 for (k=0; k<nrv; k++) {
00237 gradientVector2(k) = matrixOfGradientVectors(k,j-1);
00238 }
00239 responseCovariance = (covMatrix^gradientVector1)^gradientVector2;
00240 responseCovMatrix(i-1,j-1) = responseCovariance;
00241 }
00242 }
00243 for (i=1; i<=numLsf; i++) {
00244 for (j=1; j<i; j++) {
00245 responseCovMatrix(i-1,j-1) = responseCovMatrix(j-1,i-1);
00246 }
00247 }
00248
00249
00250
00251 Matrix correlationMatrix(numLsf,numLsf);
00252 for (i=1; i<=numLsf; i++) {
00253 for (j=i+1; j<=numLsf; j++) {
00254 correlationMatrix(i-1,j-1) = responseCovMatrix(i-1,j-1)/(responseStdv(i-1)*responseStdv(j-1));
00255 }
00256 }
00257 for (i=1; i<=numLsf; i++) {
00258 for (j=1; j<i; j++) {
00259 correlationMatrix(i-1,j-1) = correlationMatrix(j-1,i-1);
00260 }
00261 }
00262
00263
00264
00265 outputFile << "#######################################################################" << endln;
00266 outputFile << "# RESPONSE CORRELATION COEFFICIENTS #" << endln;
00267 outputFile << "# #" << endln;
00268 if (numLsf <=1) {
00269 outputFile << "# Only one limit-state function! #" << endln;
00270 }
00271 else {
00272 outputFile << "# gFun gFun Correlation #" << endln;
00273 outputFile.setf(ios::fixed, ios::floatfield);
00274 for (i=0; i<numLsf; i++) {
00275 for (j=i+1; j<numLsf; j++) {
00276
00277 outputFile << "# " <<setw(3)<<(i+1)<<" "<<setw(3)<<(j+1)<<" ";
00278 if (correlationMatrix(i,j)<0.0) { outputFile << "-"; }
00279 else { outputFile << " "; }
00280
00281 outputFile <<setprecision(7)<<setw(11)<<fabs(correlationMatrix(i,j));
00282 outputFile << " #" << endln;
00283 }
00284 }
00285 }
00286 outputFile << "# #" << endln;
00287 outputFile << "#######################################################################" << endln << endln << endln;
00288
00289
00290
00291
00292 opserr << "MVFOSMAnalysis completed." << endln;
00293
00294
00295 return 0;
00296 }
00297