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 <GFunVisualizationAnalysis.h>
00035 #include <GFunEvaluator.h>
00036 #include <ReliabilityDomain.h>
00037 #include <ReliabilityAnalysis.h>
00038 #include <GradGEvaluator.h>
00039 #include <MeritFunctionCheck.h>
00040 #include <Vector.h>
00041 #include <Matrix.h>
00042 #include <MatrixOperations.h>
00043 #include <NormalRV.h>
00044 #include <RandomVariable.h>
00045 #include <math.h>
00046
00047 #include <iomanip>
00048 using std::ios;
00049 #include <ProbabilityTransformation.h>
00050 #include <ReliabilityConvergenceCheck.h>
00051 #include <RootFinding.h>
00052
00053 GFunVisualizationAnalysis::GFunVisualizationAnalysis(
00054 ReliabilityDomain *passedReliabilityDomain,
00055 GFunEvaluator *passedGFunEvaluator,
00056 ProbabilityTransformation *passedProbabilityTransformation,
00057 TCL_Char *passedOutputFileName,
00058 TCL_Char *passedConvFileName,
00059 int passedConvResults,
00060 int passedSpace,
00061 int passedFunSurf,
00062 int passedAxes,
00063 int passedDir)
00064 :ReliabilityAnalysis()
00065 {
00066 theReliabilityDomain = passedReliabilityDomain;
00067 theGFunEvaluator = passedGFunEvaluator;
00068 theProbabilityTransformation = passedProbabilityTransformation;
00069 theMeritFunctionCheck = 0;
00070 theGradGEvaluator = 0;
00071 theReliabilityConvergenceCheck = 0;
00072 theStartPoint = 0;
00073
00074 outputFileName = new char[256];
00075 strcpy(outputFileName,passedOutputFileName);
00076
00077 convFileName = new char[256];
00078 strcpy(convFileName,passedConvFileName);
00079
00080 convResults = passedConvResults;
00081 space = passedSpace;
00082 funSurf = passedFunSurf;
00083 axes = passedAxes;
00084 dir = passedDir;
00085
00086 nrv = theReliabilityDomain->getNumberOfRandomVariables();
00087
00088 scaleValue = 1.0;
00089
00090 if (convResults==1) {
00091 static ofstream convFile( convFileName, ios::out );
00092 }
00093
00094
00095 }
00096
00097 GFunVisualizationAnalysis::~GFunVisualizationAnalysis()
00098 {
00099 if (outputFileName != 0)
00100 delete [] outputFileName;
00101 if (convFileName != 0)
00102 delete [] convFileName;
00103 }
00104
00105
00106 int
00107 GFunVisualizationAnalysis::analyze(void)
00108 {
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 opserr << "Visualization Analysis is running ... " << endln;;
00119
00120
00121
00122 ofstream outputFile( outputFileName, ios::out );
00123
00124
00125
00126 int i,j;
00127 Vector thePoint;
00128 double result;
00129
00130
00131
00132 int numPoints1, numPoints2;
00133 if (axes==1) {
00134 numPoints1 = numPts1;
00135 numPoints2 = 1;
00136 }
00137 else if (axes==2) {
00138 numPoints1 = numPts1;
00139 numPoints2 = numPts2;
00140 }
00141 else if (axes==3) {
00142
00143 numPoints1 = theMatrix.noCols()-1;
00144 numPoints2 = numLinePts;
00145 }
00146
00147 int counter = 0;
00148 for (i=1; i<=numPoints1; i++) {
00149 for (j=1; j<=numPoints2; j++) {
00150
00151 counter++;
00152 opserr << counter << " ";
00153
00154
00155 if (axes==1 || axes==2) {
00156 thePoint = this->getCurrentAxes12Point(i,j);
00157 }
00158 else if (axes==3) {
00159 thePoint = this->getCurrentAxes3Point(i,j);
00160 }
00161
00162
00163 if (funSurf==1) {
00164
00165
00166 if (space==2) {
00167 result = theProbabilityTransformation->set_u(thePoint);
00168 if (result < 0) {
00169 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00170 << " could not set u in the xu-transformation." << endln;
00171 return -1;
00172 }
00173
00174 result = theProbabilityTransformation->transform_u_to_x();
00175 if (result < 0) {
00176 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00177 << " could not transform from u to x and compute Jacobian." << endln;
00178 return -1;
00179 }
00180 thePoint = theProbabilityTransformation->get_x();
00181 }
00182
00183
00184 if (j==1) {
00185 result = this->evaluateGFunction(thePoint,true);
00186 }
00187 else {
00188 result = this->evaluateGFunction(thePoint,false);
00189 }
00190 }
00191 else if (funSurf==2) {
00192
00193
00194 result = this->findGSurface(thePoint);
00195 }
00196
00197
00198 outputFile << result << " ";
00199 }
00200 outputFile << endln;
00201 }
00202
00203
00204 outputFile.close();
00205
00206
00207 opserr << endln << "GFunVisualizationAnalysis completed." << endln;
00208
00209 return 0;
00210 }
00211
00212
00213 Vector
00214 GFunVisualizationAnalysis::getCurrentAxes12Point(int i, int j)
00215 {
00216
00217 Vector thePoint;
00218 int result;
00219
00220
00221
00222 if (theStartPoint == 0) {
00223
00224
00225
00226 Vector dummy(nrv);
00227 dummy.Zero();
00228 thePoint = dummy;
00229
00230
00231
00232 if (space==1) {
00233 result = theProbabilityTransformation->set_u(thePoint);
00234 if (result < 0) {
00235 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00236 << " could not set u in the xu-transformation." << endln;
00237 return -1;
00238 }
00239
00240 result = theProbabilityTransformation->transform_u_to_x();
00241 if (result < 0) {
00242 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00243 << " could not transform from u to x and compute Jacobian." << endln;
00244 return -1;
00245 }
00246 thePoint = theProbabilityTransformation->get_x();
00247 }
00248 }
00249 else {
00250
00251
00252
00253 thePoint = (*theStartPoint);
00254
00255
00256 if (space==2) {
00257 result = theProbabilityTransformation->set_x(thePoint);
00258 if (result < 0) {
00259 opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln
00260 << " could not set x in the xu-transformation." << endln;
00261 return -1;
00262 }
00263
00264 result = theProbabilityTransformation->transform_x_to_u();
00265 if (result < 0) {
00266 opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln
00267 << " could not transform from x to u." << endln;
00268 return -1;
00269 }
00270 thePoint = theProbabilityTransformation->get_u();
00271 }
00272 }
00273
00274
00275
00276 thePoint(rv1-1) = from1+(i-1)*interval1;
00277 if (axes==2) {
00278 thePoint(rv2-1) = from2+(j-1)*interval2;
00279 }
00280
00281 return thePoint;
00282 }
00283
00284
00285 Vector
00286 GFunVisualizationAnalysis::getCurrentAxes3Point(int i, int j)
00287 {
00288
00289
00290
00291
00292
00293 Vector vector1(nrv);
00294 Vector vector2(nrv);
00295
00296
00297
00298 for (int k=0; k<nrv; k++) {
00299 vector1(k) = theMatrix(k,i-1);
00300 vector2(k) = theMatrix(k,i);
00301 }
00302
00303
00304
00305 Vector vector = vector2-vector1;
00306
00307
00308
00309 Vector thePoint;
00310 double vectorFactor = ((double)(j-1))/((double)(numLinePts-1));
00311 thePoint = ( vector1 + vector*vectorFactor );
00312
00313
00314 return thePoint;
00315 }
00316
00317
00318 int
00319 GFunVisualizationAnalysis::setDirection(int prvDir)
00320 {
00321 rvDir = prvDir;
00322
00323 return 0;
00324 }
00325
00326 int
00327 GFunVisualizationAnalysis::setDirection(Vector pDirectionVector)
00328 {
00329 theDirectionVector = pDirectionVector;
00330
00331 return 0;
00332 }
00333
00334 int
00335 GFunVisualizationAnalysis::setAxes(Vector axesVector)
00336 {
00337
00338 rv1 = (int)axesVector(0);
00339 from1 = axesVector(1);
00340 double to1 = axesVector(2);
00341 numPts1 = (int)axesVector(3);
00342
00343 double to2;
00344 if (axesVector.Size() > 4 ) {
00345 rv2 = (int)axesVector(4);
00346 from2 = axesVector(5);
00347 to2 = axesVector(6);
00348 numPts2 = (int)axesVector(7);
00349 }
00350
00351 interval1 = (to1-from1)/(numPts1-1);
00352 interval2 = (to2-from2)/(numPts2-1);
00353
00354 return 0;
00355 }
00356
00357 int
00358 GFunVisualizationAnalysis::setAxes(Matrix pMatrix)
00359 {
00360 theMatrix = pMatrix;
00361
00362 return 0;
00363 }
00364
00365 int
00366 GFunVisualizationAnalysis::setNumLinePts(int pNumLinePts)
00367 {
00368 numLinePts = pNumLinePts;
00369
00370 return 0;
00371 }
00372
00373 int
00374 GFunVisualizationAnalysis::setRootFindingAlgorithm(RootFinding *pRootFinder)
00375 {
00376 theRootFindingAlgorithm = pRootFinder;
00377
00378 return 0;
00379 }
00380
00381
00382 int
00383 GFunVisualizationAnalysis::setStartPoint(Vector *pStartPoint)
00384 {
00385 theStartPoint = pStartPoint;
00386
00387 return 0;
00388 }
00389
00390 int
00391 GFunVisualizationAnalysis::setGradGEvaluator(GradGEvaluator *pGradGEvaluator)
00392 {
00393 theGradGEvaluator = pGradGEvaluator;
00394
00395 return 0;
00396 }
00397
00398 int
00399 GFunVisualizationAnalysis::setMeritFunctionCheck(MeritFunctionCheck *pMeritFunctionCheck)
00400 {
00401 theMeritFunctionCheck = pMeritFunctionCheck;
00402
00403 return 0;
00404 }
00405
00406 int
00407 GFunVisualizationAnalysis::setReliabilityConvergenceCheck(ReliabilityConvergenceCheck *pReliabilityConvergenceCheck)
00408 {
00409 theReliabilityConvergenceCheck = pReliabilityConvergenceCheck;
00410
00411 return 0;
00412 }
00413
00414
00415
00416 double
00417 GFunVisualizationAnalysis::findGSurface(Vector thePoint)
00418 {
00419
00420
00421 int result;
00422 double g;
00423 Vector surfacePoint(nrv);
00424 Vector Direction(nrv);
00425 Vector theTempPoint(nrv);
00426 int i;
00427 Vector distance;
00428 double scalarDist;
00429 double a;
00430
00431
00432
00433 Direction.Zero();
00434 if (dir==1) {
00435 Direction(rvDir-1) = 1.0;
00436 }
00437 else if (dir==2) {
00438 if (nrv != theDirectionVector.Size()) {
00439 opserr << "ERROR: There is something wrong with the size of the direction" << endln
00440 << " vector of the visualization analysis object." << endln;
00441 }
00442 Direction = theDirectionVector;
00443 }
00444
00445
00446 if (space==2) {
00447 result = theProbabilityTransformation->set_u(thePoint);
00448 if (result < 0) {
00449 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00450 << " could not set u in the xu-transformation." << endln;
00451 return -1;
00452 }
00453
00454 result = theProbabilityTransformation->transform_u_to_x();
00455 if (result < 0) {
00456 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00457 << " could not transform from u to x and compute Jacobian." << endln;
00458 return -1;
00459 }
00460 theTempPoint = theProbabilityTransformation->get_x();
00461 }
00462 else {
00463 theTempPoint = thePoint;
00464 }
00465
00466
00467
00468 result = theGFunEvaluator->runGFunAnalysis(theTempPoint);
00469 if (result < 0) {
00470 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00471 << " could not run analysis to evaluate limit-state function. " << endln;
00472 return -1;
00473 }
00474 result = theGFunEvaluator->evaluateG(theTempPoint);
00475 if (result < 0) {
00476 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00477 << " could not tokenize limit-state function. " << endln;
00478 return -1;
00479 }
00480 g = theGFunEvaluator->getG();
00481
00482
00483
00484 surfacePoint = theRootFindingAlgorithm->findLimitStateSurface(space,g,Direction,thePoint);
00485
00486
00487
00488
00489
00490 i=0;
00491 while (Direction(i)==0.0) {
00492 i++;
00493 }
00494 a = ( surfacePoint(i) - thePoint(i) ) / Direction(i);
00495 distance = surfacePoint-thePoint;
00496
00497
00498 scalarDist = (a/fabs(a)*distance.Norm());
00499
00500
00501 return scalarDist;
00502 }
00503
00504 double
00505 GFunVisualizationAnalysis::evaluateGFunction(Vector thePoint, bool isFirstPoint)
00506 {
00507
00508 double g;
00509 int result;
00510
00511
00512
00513 result = theGFunEvaluator->runGFunAnalysis(thePoint);
00514 if (result < 0) {
00515 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00516 << " could not run analysis to evaluate limit-state function. " << endln;
00517 return -1;
00518 }
00519 result = theGFunEvaluator->evaluateG(thePoint);
00520 if (result < 0) {
00521 opserr << "GFunVisualizationAnalysis::analyze() - " << endln
00522 << " could not tokenize limit-state function. " << endln;
00523 return -1;
00524 }
00525 g = theGFunEvaluator->getG();
00526
00527
00528
00529
00530 if (convResults==1) {
00531
00532
00533 static ofstream convFile( convFileName, ios::out );
00534
00535
00536
00537 char myString[300];
00538 Vector u;
00539 double meritFunctionValue;
00540 int numCrit = theReliabilityConvergenceCheck->getNumberOfCriteria();
00541 double criteriumValue;
00542
00543
00544
00545 if (isFirstPoint) {
00546 double dummy = 0.0;
00547 sprintf(myString,"%20.14e %20.14e ", dummy,dummy);
00548 convFile << myString;
00549 sprintf(myString,"%20.14e ", dummy);
00550 convFile << myString;
00551 for (int crit=1; crit<=numCrit; crit++) {
00552 sprintf(myString,"%20.14e ", dummy);
00553 convFile << myString;
00554 }
00555 convFile << endln;
00556 }
00557
00558
00559 if (scaleValue == 1.0 && convResults == 1) {
00560 scaleValue = g;
00561 theReliabilityConvergenceCheck->setScaleValue(g);
00562 }
00563
00564
00565
00566 result = theProbabilityTransformation->set_x(thePoint);
00567 if (result < 0) {
00568 opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln
00569 << " could not set x in the xu-transformation." << endln;
00570 return -1;
00571 }
00572
00573 result = theProbabilityTransformation->transform_x_to_u();
00574 if (result < 0) {
00575 opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln
00576 << " could not transform from x to u." << endln;
00577 return -1;
00578 }
00579 u = theProbabilityTransformation->get_u();
00580
00581
00582
00583 result = theProbabilityTransformation->set_u(u);
00584 if (result < 0) {
00585 opserr << "ArmijoStepSizeRule::computeStepSize() - could not set " << endln
00586 << " vector u in the xu-transformation. " << endln;
00587 return -1;
00588 }
00589 result = theProbabilityTransformation->transform_u_to_x_andComputeJacobian();
00590 if (result < 0) {
00591 opserr << "ArmijoStepSizeRule::computeStepSize() - could not " << endln
00592 << " transform u to x. " << endln;
00593 return -1;
00594 }
00595 theProbabilityTransformation->get_x();
00596 Matrix jacobian_x_u = theProbabilityTransformation->getJacobian_x_u();
00597
00598
00599
00600 sprintf(myString,"%20.14e %20.14e ", g,u.Norm());
00601 convFile << myString;
00602
00603
00604 result = theGradGEvaluator->computeGradG(g,thePoint);
00605 if (result < 0) {
00606 opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln
00607 << " could not compute gradients of the limit-state function. " << endln;
00608 return -1;
00609 }
00610 Vector gradientOfgFunction = theGradGEvaluator->getGradG();
00611 gradientOfgFunction = jacobian_x_u ^ gradientOfgFunction;
00612
00613
00614
00615 if (isFirstPoint) {
00616 meritFunctionValue = theMeritFunctionCheck->updateMeritParameters(u, g, gradientOfgFunction);
00617 }
00618 meritFunctionValue = theMeritFunctionCheck->getMeritFunctionValue(u, g, gradientOfgFunction);
00619 sprintf(myString,"%20.14e ", meritFunctionValue);
00620 convFile << myString;
00621
00622
00623 theReliabilityConvergenceCheck->check(u,g,gradientOfgFunction);
00624 for (int crit=1; crit<=numCrit; crit++) {
00625 criteriumValue = theReliabilityConvergenceCheck->getCriteriaValue(crit);
00626 sprintf(myString,"%20.14e ", criteriumValue);
00627 convFile << myString;
00628 }
00629
00630 convFile << endln;
00631
00632 }
00633
00634
00635 return g;
00636 }
00637