Rev 4802 | Rev 4806 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 291 | mhscott | 1 | /* ****************************************************************** ** |
| 2 | ** OpenSees - Open System for Earthquake Engineering Simulation ** |
||
| 3 | ** Pacific Earthquake Engineering Research Center ** |
||
| 4 | ** ** |
||
| 5 | ** ** |
||
| 6 | ** (C) Copyright 2001, The Regents of the University of California ** |
||
| 7 | ** All Rights Reserved. ** |
||
| 8 | ** ** |
||
| 9 | ** Commercial use of this program without express permission of the ** |
||
| 10 | ** University of California, Berkeley, is strictly prohibited. See ** |
||
| 11 | ** file 'COPYRIGHT' in main directory for information on usage and ** |
||
| 12 | ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. ** |
||
| 13 | ** ** |
||
| 14 | ** Developed by: ** |
||
| 15 | ** Frank McKenna (fmckenna@ce.berkeley.edu) ** |
||
| 16 | ** Gregory L. Fenves (fenves@ce.berkeley.edu) ** |
||
| 17 | ** Filip C. Filippou (filippou@ce.berkeley.edu) ** |
||
| 18 | ** ** |
||
| 19 | ** Reliability module developed by: ** |
||
| 20 | ** Terje Haukaas (haukaas@ce.berkeley.edu) ** |
||
| 21 | ** Armen Der Kiureghian (adk@ce.berkeley.edu) ** |
||
| 22 | ** ** |
||
| 23 | ** ****************************************************************** */ |
||
| 24 | |||
| 4323 | mhscott | 25 | // $Revision: 1.20 $ |
| 26 | // $Date: 2010-09-13 21:34:43 $ |
||
| 291 | mhscott | 27 | // $Source: /usr/local/cvs/OpenSees/SRC/reliability/analysis/designPoint/SearchWithStepSizeAndStepDirection.cpp,v $ |
| 28 | |||
| 29 | |||
| 30 | // |
||
| 1334 | fmk | 31 | // Written by Terje Haukaas (haukaas@ce.berkeley.edu) |
| 291 | mhscott | 32 | // |
| 33 | |||
| 34 | #include <SearchWithStepSizeAndStepDirection.h> |
||
| 1334 | fmk | 35 | #include <FindDesignPointAlgorithm.h> |
| 3498 | mhscott | 36 | #include <ReliabilityDomain.h> |
| 291 | mhscott | 37 | #include <StepSizeRule.h> |
| 38 | #include <SearchDirection.h> |
||
| 1334 | fmk | 39 | #include <ProbabilityTransformation.h> |
| 40 | #include <NatafProbabilityTransformation.h> |
||
| 4721 | mhscott | 41 | #include <LimitStateFunction.h> |
| 42 | #include <FunctionEvaluator.h> |
||
| 43 | #include <GradientEvaluator.h> |
||
| 291 | mhscott | 44 | #include <RandomVariable.h> |
| 4782 | mackie | 45 | #include <RandomVariableIter.h> |
| 291 | mhscott | 46 | #include <CorrelationCoefficient.h> |
| 47 | #include <MatrixOperations.h> |
||
| 1334 | fmk | 48 | #include <HessianApproximation.h> |
| 49 | #include <ReliabilityConvergenceCheck.h> |
||
| 291 | mhscott | 50 | #include <Matrix.h> |
| 51 | #include <Vector.h> |
||
| 52 | |||
| 1334 | fmk | 53 | #include <fstream> |
| 54 | #include <iomanip> |
||
| 55 | #include <iostream> |
||
| 4638 | fmk | 56 | #include <math.h> |
| 291 | mhscott | 57 | |
| 1334 | fmk | 58 | using std::ifstream; |
| 59 | using std::ios; |
||
| 60 | using std::setw; |
||
| 61 | using std::setprecision; |
||
| 62 | |||
| 63 | |||
| 291 | mhscott | 64 | SearchWithStepSizeAndStepDirection::SearchWithStepSizeAndStepDirection( |
| 3498 | mhscott | 65 | int passedMaxNumberOfIterations, |
| 66 | ReliabilityDomain *passedReliabilityDomain, |
||
| 4782 | mackie | 67 | Domain *passedOpenSeesDomain, |
| 4721 | mhscott | 68 | FunctionEvaluator *passedFunctionEvaluator, |
| 69 | GradientEvaluator *passedGradientEvaluator, |
||
| 291 | mhscott | 70 | StepSizeRule *passedStepSizeRule, |
| 71 | SearchDirection *passedSearchDirection, |
||
| 1334 | fmk | 72 | ProbabilityTransformation *passedProbabilityTransformation, |
| 73 | HessianApproximation *passedHessianApproximation, |
||
| 74 | ReliabilityConvergenceCheck *passedReliabilityConvergenceCheck, |
||
| 3659 | mhscott | 75 | bool pStartAtOrigin, |
| 1334 | fmk | 76 | int pprintFlag, |
| 3659 | mhscott | 77 | char *pFileNamePrint) |
| 4782 | mackie | 78 | :FindDesignPointAlgorithm(), theReliabilityDomain(passedReliabilityDomain), |
| 79 | theOpenSeesDomain(passedOpenSeesDomain) |
||
| 291 | mhscott | 80 | { |
| 81 | maxNumberOfIterations = passedMaxNumberOfIterations; |
||
| 4721 | mhscott | 82 | theFunctionEvaluator = passedFunctionEvaluator; |
| 83 | theGradientEvaluator = passedGradientEvaluator; |
||
| 291 | mhscott | 84 | theStepSizeRule = passedStepSizeRule; |
| 85 | theSearchDirection = passedSearchDirection; |
||
| 1334 | fmk | 86 | theProbabilityTransformation = passedProbabilityTransformation; |
| 87 | theHessianApproximation = passedHessianApproximation; |
||
| 88 | theReliabilityConvergenceCheck = passedReliabilityConvergenceCheck; |
||
| 3659 | mhscott | 89 | //startPoint = pStartPoint; |
| 90 | startAtOrigin = pStartAtOrigin; |
||
| 1334 | fmk | 91 | printFlag = pprintFlag; |
| 4802 | mackie | 92 | numberOfEvaluations = 0; |
| 1334 | fmk | 93 | if (printFlag != 0) { |
| 94 | strcpy(fileNamePrint,pFileNamePrint); |
||
| 95 | } |
||
| 3498 | mhscott | 96 | |
| 4721 | mhscott | 97 | int nrv = theReliabilityDomain->getNumberOfRandomVariables(); |
| 3498 | mhscott | 98 | x = new Vector(nrv); |
| 99 | u = new Vector(nrv); |
||
| 100 | alpha = new Vector(nrv); |
||
| 101 | gamma = new Vector(nrv); |
||
| 102 | gradientInStandardNormalSpace = new Vector(nrv); |
||
| 103 | uSecondLast = new Vector(nrv); |
||
| 104 | alphaSecondLast = new Vector(nrv); |
||
| 105 | searchDirection = new Vector(nrv); |
||
| 291 | mhscott | 106 | } |
| 107 | |||
| 108 | |||
| 109 | |||
| 110 | SearchWithStepSizeAndStepDirection::~SearchWithStepSizeAndStepDirection() |
||
| 111 | { |
||
| 3498 | mhscott | 112 | if (x != 0) |
| 113 | delete x; |
||
| 114 | if (u != 0) |
||
| 115 | delete u; |
||
| 116 | if (alpha != 0) |
||
| 117 | delete alpha; |
||
| 118 | if (gamma != 0) |
||
| 119 | delete gamma; |
||
| 120 | if (gradientInStandardNormalSpace != 0) |
||
| 121 | delete gradientInStandardNormalSpace; |
||
| 122 | if (uSecondLast != 0) |
||
| 123 | delete uSecondLast; |
||
| 124 | if (alphaSecondLast != 0) |
||
| 125 | delete alphaSecondLast; |
||
| 126 | if (searchDirection != 0) |
||
| 127 | delete searchDirection; |
||
| 128 | |||
| 291 | mhscott | 129 | } |
| 130 | |||
| 131 | |||
| 132 | int |
||
| 3498 | mhscott | 133 | SearchWithStepSizeAndStepDirection::findDesignPoint() |
| 291 | mhscott | 134 | { |
| 135 | |||
| 1334 | fmk | 136 | // Declaration of data used in the algorithm |
| 291 | mhscott | 137 | int numberOfRandomVariables = theReliabilityDomain->getNumberOfRandomVariables(); |
| 4784 | mackie | 138 | int numberOfParameters = theOpenSeesDomain->getNumParameters(); |
| 139 | int zeroFlag, result; |
||
| 3498 | mhscott | 140 | int evaluationInStepSize = 0; |
| 141 | |||
| 1334 | fmk | 142 | double gFunctionValue = 1.0; |
| 143 | double gFunctionValue_old = 1.0; |
||
| 3498 | mhscott | 144 | double normOfGradient = 0.0; |
| 145 | double stepSize = 1.0; |
||
| 146 | |||
| 147 | Vector u_old(numberOfRandomVariables); |
||
| 148 | Vector uNew(numberOfRandomVariables); |
||
| 291 | mhscott | 149 | Vector gradientOfgFunction(numberOfRandomVariables); |
| 1334 | fmk | 150 | Vector gradientInStandardNormalSpace_old(numberOfRandomVariables); |
| 3498 | mhscott | 151 | |
| 4782 | mackie | 152 | Matrix Jxu(numberOfRandomVariables, numberOfRandomVariables); |
| 153 | Matrix Jux(numberOfRandomVariables, numberOfRandomVariables); |
||
| 3498 | mhscott | 154 | |
| 4721 | mhscott | 155 | theFunctionEvaluator->initializeNumberOfEvaluations(); |
| 291 | mhscott | 156 | |
| 1334 | fmk | 157 | // Prepare output file to store the search points |
| 4721 | mhscott | 158 | /* |
| 159 | if (printFlag != 0) |
||
| 160 | ofstream outputFile2( fileNamePrint, ios::out ); |
||
| 161 | */ |
||
| 291 | mhscott | 162 | |
| 4782 | mackie | 163 | |
| 164 | // get starting x values from parameter directly |
||
| 165 | for (int j = 0; j < numberOfRandomVariables; j++) { |
||
| 166 | RandomVariable *theParam = theReliabilityDomain->getRandomVariablePtrFromIndex(j); |
||
| 4784 | mackie | 167 | double rvVal = theParam->getStartValue(); |
| 168 | (*x)(j) = rvVal; |
||
| 169 | |||
| 170 | // now we should update the parameter value |
||
| 171 | // KRM should this be a parameter reference now? |
||
| 172 | theParam->setCurrentValue(rvVal); |
||
| 4782 | mackie | 173 | } |
| 4792 | mhscott | 174 | |
| 4782 | mackie | 175 | // Transform starting point into standard normal space to initialize u vector |
| 176 | result = theProbabilityTransformation->transform_x_to_u(*u); |
||
| 177 | if (result < 0) { |
||
| 178 | opserr << "SearchWithStepSizeAndStepDirection::findDesignPoint() - " << endln |
||
| 179 | << " could not transform from x to u." << endln; |
||
| 180 | return -1; |
||
| 181 | } |
||
| 291 | mhscott | 182 | |
| 183 | // Loop to find design point |
||
| 3498 | mhscott | 184 | steps = 1; |
| 185 | while ( steps <= maxNumberOfIterations ) |
||
| 291 | mhscott | 186 | { |
| 187 | |||
| 510 | mhscott | 188 | // Evaluate limit-state function unless it has been done in |
| 189 | // a trial step by the "stepSizeAlgorithm" |
||
| 1334 | fmk | 190 | if (evaluationInStepSize == 0) { |
| 4721 | mhscott | 191 | // set perturbed values in the variable namespace |
| 192 | if (theFunctionEvaluator->setVariables(*x) < 0) { |
||
| 193 | opserr << "ERROR SearchWithStepSizeAndStepDirection -- error setting variables in namespace" << endln; |
||
| 510 | mhscott | 194 | return -1; |
| 195 | } |
||
| 4721 | mhscott | 196 | |
| 197 | // run analysis |
||
| 198 | if (theFunctionEvaluator->runAnalysis(*x) < 0) { |
||
| 199 | opserr << "ERROR SearchWithStepSizeAndStepDirection -- error running analysis" << endln; |
||
| 1334 | fmk | 200 | return -1; |
| 201 | } |
||
| 4721 | mhscott | 202 | |
| 203 | // evaluate LSF and obtain result |
||
| 204 | int lsfTag = theReliabilityDomain->getTagOfActiveLimitStateFunction(); |
||
| 205 | LimitStateFunction *theLimitStateFunction = theReliabilityDomain->getLimitStateFunctionPtr(lsfTag); |
||
| 206 | const char *lsfExpression = theLimitStateFunction->getExpression(); |
||
| 207 | theFunctionEvaluator->setExpression(lsfExpression); |
||
| 208 | |||
| 1334 | fmk | 209 | gFunctionValue_old = gFunctionValue; |
| 4801 | mackie | 210 | gFunctionValue = theFunctionEvaluator->evaluateExpression(); |
| 4721 | mhscott | 211 | |
| 291 | mhscott | 212 | } |
| 213 | |||
| 1334 | fmk | 214 | // Set scale parameter |
| 3498 | mhscott | 215 | if (steps == 1) { |
| 1334 | fmk | 216 | Gfirst = gFunctionValue; |
| 4323 | mhscott | 217 | if (printFlag != 0) { |
| 218 | opserr << " Limit-state function value at start point, g=" << gFunctionValue << endln; |
||
| 219 | opserr << " STEP #0: "; |
||
| 220 | } |
||
| 1592 | mhscott | 221 | theReliabilityConvergenceCheck->setScaleValue(gFunctionValue); |
| 510 | mhscott | 222 | } |
| 223 | |||
| 224 | |||
| 291 | mhscott | 225 | // Gradient in original space |
| 4782 | mackie | 226 | result = theGradientEvaluator->computeGradient(gFunctionValue); |
| 1592 | mhscott | 227 | if (result < 0) { |
| 228 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 229 | << " could not compute gradients of the limit-state function. " << endln; |
||
| 230 | return -1; |
||
| 231 | } |
||
| 4721 | mhscott | 232 | gradientOfgFunction = theGradientEvaluator->getGradient(); |
| 291 | mhscott | 233 | |
| 4782 | mackie | 234 | // Check if all components of the vector are zero |
| 4721 | mhscott | 235 | if (gradientOfgFunction.Norm() == 0.0) { |
| 1592 | mhscott | 236 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 237 | << " all components of the gradient vector is zero. " << endln; |
||
| 238 | return -1; |
||
| 239 | } |
||
| 4782 | mackie | 240 | |
| 241 | // Get Jacobian x-space to u-space |
||
| 242 | result = theProbabilityTransformation->getJacobian_x_to_u(Jxu); |
||
| 243 | if (result < 0) { |
||
| 244 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 245 | << " could not transform Jacobian from x to u." << endln; |
||
| 246 | return -1; |
||
| 247 | } |
||
| 291 | mhscott | 248 | |
| 1592 | mhscott | 249 | // Gradient in standard normal space |
| 3498 | mhscott | 250 | gradientInStandardNormalSpace_old = *gradientInStandardNormalSpace; |
| 2787 | mhscott | 251 | //gradientInStandardNormalSpace = jacobian_x_u ^ gradientOfgFunction; |
| 3212 | mhscott | 252 | //gradientInStandardNormalSpace.addMatrixTransposeVector(0.0, jacobian_x_u, gradientOfgFunction, 1.0); |
| 3498 | mhscott | 253 | gradientInStandardNormalSpace->addMatrixTransposeVector(0.0, Jxu, gradientOfgFunction, 1.0); |
| 291 | mhscott | 254 | |
| 255 | |||
| 256 | // Compute the norm of the gradient in standard normal space |
||
| 3498 | mhscott | 257 | normOfGradient = gradientInStandardNormalSpace->Norm(); |
| 291 | mhscott | 258 | |
| 259 | |||
| 260 | // Check that the norm is not zero |
||
| 261 | if (normOfGradient == 0.0) { |
||
| 1271 | fmk | 262 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 263 | << " the norm of the gradient is zero. " << endln; |
||
| 291 | mhscott | 264 | return -1; |
| 265 | } |
||
| 266 | |||
| 3606 | mhscott | 267 | // check there are no sucessive large betas |
| 268 | int earlyexit = 0; |
||
| 269 | if ( u->Norm() > uSecondLast->Norm() > 10 ) |
||
| 270 | earlyexit = 1; |
||
| 1334 | fmk | 271 | |
| 291 | mhscott | 272 | // Compute alpha-vector |
| 3498 | mhscott | 273 | alpha->addVector(0.0, *gradientInStandardNormalSpace, -1.0/normOfGradient ); |
| 291 | mhscott | 274 | |
| 275 | |||
| 276 | // Check convergence |
||
| 3498 | mhscott | 277 | result = theReliabilityConvergenceCheck->check(*u,gFunctionValue,*gradientInStandardNormalSpace); |
| 4782 | mackie | 278 | |
| 3498 | mhscott | 279 | if (result > 0 || steps == maxNumberOfIterations) { |
| 1334 | fmk | 280 | |
| 281 | // Inform the user of the happy news! |
||
| 1592 | mhscott | 282 | opserr << "Design point found!" << endln; |
| 510 | mhscott | 283 | |
| 4721 | mhscott | 284 | /* |
| 1334 | fmk | 285 | // Print the design point to file, if desired |
| 286 | int iii; |
||
| 287 | if (printFlag != 0) { |
||
| 288 | if (printFlag == 3) { |
||
| 289 | result = theProbabilityTransformation->set_u(u); |
||
| 290 | if (result < 0) { |
||
| 291 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 292 | << " could not set u in the xu-transformation." << endln; |
||
| 293 | return -1; |
||
| 294 | } |
||
| 295 | |||
| 296 | result = theProbabilityTransformation->transform_u_to_x(); |
||
| 297 | if (result < 0) { |
||
| 298 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 299 | << " could not transform from u to x." << endln; |
||
| 300 | return -1; |
||
| 301 | } |
||
| 302 | x = theProbabilityTransformation->get_x(); |
||
| 4721 | mhscott | 303 | |
| 3498 | mhscott | 304 | result = theProbabilityTransformation->transform_u_to_x(*u, *x); |
| 3212 | mhscott | 305 | if (result < 0) { |
| 306 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 307 | << " could not transform from u to x." << endln; |
||
| 308 | return -1; |
||
| 309 | } |
||
| 1334 | fmk | 310 | |
| 311 | outputFile2.setf(ios::scientific, ios::floatfield); |
||
| 3498 | mhscott | 312 | for (iii=0; iii<x->Size(); iii++) { |
| 313 | outputFile2<<setprecision(5)<<setw(15)<<(*x)(iii)<<endln; |
||
| 1334 | fmk | 314 | } |
| 315 | } |
||
| 316 | else if (printFlag == 4) { |
||
| 317 | static ofstream outputFile2( fileNamePrint, ios::out ); |
||
| 318 | outputFile2.setf(ios::scientific, ios::floatfield); |
||
| 3498 | mhscott | 319 | for (iii=0; iii<u->Size(); iii++) { |
| 320 | outputFile2<<setprecision(5)<<setw(15)<<(*u)(iii)<<endln; |
||
| 1334 | fmk | 321 | } |
| 322 | } |
||
| 323 | } |
||
| 4721 | mhscott | 324 | */ |
| 1334 | fmk | 325 | |
| 326 | |||
| 510 | mhscott | 327 | // Compute the gamma vector |
| 3212 | mhscott | 328 | // Get Jacobian u-space to x-space |
| 3498 | mhscott | 329 | result = theProbabilityTransformation->getJacobian_u_to_x(*u, Jux); |
| 3212 | mhscott | 330 | if (result < 0) { |
| 331 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 332 | << " could not transform from u to x." << endln; |
||
| 333 | return -1; |
||
| 334 | } |
||
| 291 | mhscott | 335 | |
| 2787 | mhscott | 336 | //Vector tempProduct = jacobian_u_x ^ alpha; |
| 337 | Vector tempProduct(numberOfRandomVariables); |
||
| 3212 | mhscott | 338 | //tempProduct.addMatrixTransposeVector(0.0, jacobian_u_x, alpha, 1.0); |
| 3498 | mhscott | 339 | tempProduct.addMatrixTransposeVector(0.0, Jux, *alpha, 1.0); |
| 291 | mhscott | 340 | |
| 2987 | mhscott | 341 | // Only diagonal elements of (J_xu*J_xu^T) are used |
| 4784 | mackie | 342 | for (int j = 0; j < numberOfRandomVariables; j++) { |
| 2987 | mhscott | 343 | double sum = 0.0; |
| 344 | double jk; |
||
| 345 | for (int k = 0; k < numberOfRandomVariables; k++) { |
||
| 3212 | mhscott | 346 | //jk = jacobian_x_u(j,k); |
| 347 | jk = Jxu(j,k); |
||
| 2987 | mhscott | 348 | sum += jk*jk; |
| 349 | } |
||
| 3498 | mhscott | 350 | (*gamma)(j) = sqrt(sum) * tempProduct(j); |
| 2987 | mhscott | 351 | } |
| 1334 | fmk | 352 | |
| 353 | Glast = gFunctionValue; |
||
| 291 | mhscott | 354 | |
| 4721 | mhscott | 355 | numberOfEvaluations = theFunctionEvaluator->getNumberOfEvaluations(); |
| 3521 | mhscott | 356 | |
| 357 | // compute sensitivity pf beta wrt to LSF parameters (if they exist) |
||
| 4721 | mhscott | 358 | // Note this will need to change because now parameters have multiple derived classes |
| 359 | /* |
||
| 360 | const Matrix &dGdPar = theGradientEvaluator->getDgDpar(); |
||
| 3521 | mhscott | 361 | int numPars = dGdPar.noRows(); |
| 362 | if (numPars > 0 && dGdPar.noCols() > 1) { |
||
| 363 | opserr << "Sensitivity of beta wrt LSF parameters: "; |
||
| 364 | Vector dBetadPar(numPars); |
||
| 365 | |||
| 366 | for (int ib=0; ib<numPars; ib++) |
||
| 367 | dBetadPar(ib) = dGdPar(ib,1) / gradientInStandardNormalSpace->Norm(); |
||
| 368 | |||
| 369 | opserr << dBetadPar; |
||
| 370 | } |
||
| 4721 | mhscott | 371 | */ |
| 291 | mhscott | 372 | return 1; |
| 373 | } |
||
| 374 | |||
| 375 | |||
| 376 | // Store 'u' and 'alpha' at the second last iteration point |
||
| 3498 | mhscott | 377 | *uSecondLast = *u; |
| 378 | *alphaSecondLast = *alpha; |
||
| 291 | mhscott | 379 | |
| 380 | |||
| 1334 | fmk | 381 | // Let user know that we have to take a new step |
| 4323 | mhscott | 382 | if (printFlag != 0) |
| 383 | opserr << " STEP #" << steps <<": "; |
||
| 1334 | fmk | 384 | |
| 385 | |||
| 4792 | mhscott | 386 | |
| 1334 | fmk | 387 | // Update Hessian approximation, if any |
| 3498 | mhscott | 388 | if ( (theHessianApproximation!=0) && (steps!=1) ) { |
| 1334 | fmk | 389 | theHessianApproximation->updateHessianApproximation(u_old, |
| 390 | gFunctionValue_old, |
||
| 391 | gradientInStandardNormalSpace_old, |
||
| 392 | stepSize, |
||
| 3498 | mhscott | 393 | *searchDirection, |
| 1334 | fmk | 394 | gFunctionValue, |
| 3498 | mhscott | 395 | *gradientInStandardNormalSpace); |
| 1334 | fmk | 396 | } |
| 397 | |||
| 398 | |||
| 291 | mhscott | 399 | // Determine search direction |
| 3498 | mhscott | 400 | result = theSearchDirection->computeSearchDirection(steps, |
| 401 | *u, gFunctionValue, *gradientInStandardNormalSpace ); |
||
| 291 | mhscott | 402 | if (result < 0) { |
| 1271 | fmk | 403 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 404 | << " could not compute search direction. " << endln; |
||
| 291 | mhscott | 405 | return -1; |
| 406 | } |
||
| 3498 | mhscott | 407 | *searchDirection = theSearchDirection->getSearchDirection(); |
| 291 | mhscott | 408 | |
| 409 | |||
| 4792 | mhscott | 410 | |
| 291 | mhscott | 411 | // Determine step size |
| 412 | result = theStepSizeRule->computeStepSize( |
||
| 3498 | mhscott | 413 | *u, *gradientInStandardNormalSpace, gFunctionValue, *searchDirection, steps); |
| 4802 | mackie | 414 | if (result < 0) { |
| 415 | // something went wrong |
||
| 1271 | fmk | 416 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 417 | << " could not compute step size. " << endln; |
||
| 291 | mhscott | 418 | return -1; |
| 419 | } |
||
| 4802 | mackie | 420 | else if (result == 0) { |
| 421 | // nothing was evaluated in step size |
||
| 1334 | fmk | 422 | evaluationInStepSize = 0; |
| 423 | } |
||
| 4802 | mackie | 424 | else if (result == 1) { |
| 425 | // the gfun was evaluated |
||
| 1334 | fmk | 426 | evaluationInStepSize = 1; |
| 427 | gFunctionValue_old = gFunctionValue; |
||
| 428 | gFunctionValue = theStepSizeRule->getGFunValue(); |
||
| 429 | } |
||
| 291 | mhscott | 430 | stepSize = theStepSizeRule->getStepSize(); |
| 431 | |||
| 432 | |||
| 3606 | mhscott | 433 | // save the previous displacement before modifying |
| 3498 | mhscott | 434 | u_old = *u; |
| 3606 | mhscott | 435 | double udiff = 20.0; |
| 436 | double stepSizeMod = 1.0; |
||
| 437 | |||
| 438 | // Determine new iteration point (take the step), BUT limit the maximum jump that can occur |
||
| 439 | while ( fabs(udiff) > 15 ) { |
||
| 440 | *u = u_old; |
||
| 441 | |||
| 4323 | mhscott | 442 | if (stepSizeMod < 1 && printFlag != 0) |
| 443 | opserr << "SearchWithStepSizeAndStepDirection:: reducing stepSize using modification factor of " << stepSizeMod << endln; |
||
| 510 | mhscott | 444 | |
| 3606 | mhscott | 445 | //u = u_old + (searchDirection * stepSize); |
| 446 | u->addVector(1.0, *searchDirection, stepSize*stepSizeMod); |
||
| 510 | mhscott | 447 | |
| 3606 | mhscott | 448 | udiff = u->Norm() - u_old.Norm(); |
| 449 | stepSizeMod *= 0.75; |
||
| 450 | } |
||
| 4782 | mackie | 451 | |
| 452 | // Transform to x-space |
||
| 453 | result = theProbabilityTransformation->transform_u_to_x(*u, *x); |
||
| 454 | if (result < 0) { |
||
| 455 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 456 | << " could not transform from u to x." << endln; |
||
| 457 | return -1; |
||
| 458 | } |
||
| 459 | |||
| 460 | // update domain with new x values |
||
| 461 | RandomVariable *theRV; |
||
| 462 | RandomVariableIter &rvIter = theReliabilityDomain->getRandomVariables(); |
||
| 463 | //for ( int i=0 ; i<nrv ; i++ ) { |
||
| 464 | while ((theRV = rvIter()) != 0) { |
||
| 465 | int rvTag = theRV->getTag(); |
||
| 466 | //int i = theRV->getIndex(); |
||
| 467 | int i = theReliabilityDomain->getRandomVariableIndex(rvTag); |
||
| 468 | theRV->setCurrentValue( (*x)(i) ); |
||
| 469 | } |
||
| 3606 | mhscott | 470 | |
| 291 | mhscott | 471 | // Increment the loop parameter |
| 3498 | mhscott | 472 | steps++; |
| 291 | mhscott | 473 | |
| 474 | } |
||
| 475 | |||
| 476 | |||
| 477 | // Print a message if max number of iterations was reached |
||
| 1334 | fmk | 478 | // (Note: in this case the last trial point was never transformed/printed) |
| 1271 | fmk | 479 | opserr << "Maximum number of iterations was reached before convergence." << endln; |
| 1334 | fmk | 480 | |
| 4721 | mhscott | 481 | /* |
| 482 | if (printFlag != 0) |
||
| 483 | outputFile2.close(); |
||
| 484 | */ |
||
| 485 | |||
| 1334 | fmk | 486 | return -1; |
| 291 | mhscott | 487 | } |
| 488 | |||
| 489 | |||
| 490 | |||
| 2736 | mhscott | 491 | const Vector& |
| 291 | mhscott | 492 | SearchWithStepSizeAndStepDirection::get_x() |
| 493 | { |
||
| 3498 | mhscott | 494 | return *x; |
| 291 | mhscott | 495 | } |
| 496 | |||
| 2736 | mhscott | 497 | const Vector & |
| 291 | mhscott | 498 | SearchWithStepSizeAndStepDirection::get_u() |
| 499 | { |
||
| 3498 | mhscott | 500 | return *u; |
| 291 | mhscott | 501 | } |
| 502 | |||
| 2736 | mhscott | 503 | const Vector& |
| 291 | mhscott | 504 | SearchWithStepSizeAndStepDirection::get_alpha() |
| 505 | { |
||
| 3498 | mhscott | 506 | return *alpha; |
| 291 | mhscott | 507 | } |
| 508 | |||
| 2736 | mhscott | 509 | const Vector& |
| 291 | mhscott | 510 | SearchWithStepSizeAndStepDirection::get_gamma() |
| 511 | { |
||
| 3498 | mhscott | 512 | if (gamma->Norm() > 1.0) |
| 513 | gamma->Normalize(); |
||
| 2736 | mhscott | 514 | |
| 3498 | mhscott | 515 | return *gamma; |
| 291 | mhscott | 516 | } |
| 517 | |||
| 518 | int |
||
| 1334 | fmk | 519 | SearchWithStepSizeAndStepDirection::getNumberOfSteps() |
| 291 | mhscott | 520 | { |
| 3498 | mhscott | 521 | return (steps-1); |
| 291 | mhscott | 522 | } |
| 523 | |||
| 2736 | mhscott | 524 | const Vector& |
| 291 | mhscott | 525 | SearchWithStepSizeAndStepDirection::getSecondLast_u() |
| 526 | { |
||
| 3498 | mhscott | 527 | return *uSecondLast; |
| 291 | mhscott | 528 | } |
| 529 | |||
| 2736 | mhscott | 530 | const Vector& |
| 291 | mhscott | 531 | SearchWithStepSizeAndStepDirection::getSecondLast_alpha() |
| 532 | { |
||
| 3498 | mhscott | 533 | return *alphaSecondLast; |
| 291 | mhscott | 534 | } |
| 535 | |||
| 2736 | mhscott | 536 | const Vector& |
| 291 | mhscott | 537 | SearchWithStepSizeAndStepDirection::getLastSearchDirection() |
| 538 | { |
||
| 3498 | mhscott | 539 | return *searchDirection; |
| 291 | mhscott | 540 | } |
| 541 | |||
| 542 | double |
||
| 543 | SearchWithStepSizeAndStepDirection::getFirstGFunValue() |
||
| 544 | { |
||
| 1334 | fmk | 545 | return Gfirst; |
| 291 | mhscott | 546 | } |
| 547 | |||
| 1334 | fmk | 548 | double |
| 549 | SearchWithStepSizeAndStepDirection::getLastGFunValue() |
||
| 550 | { |
||
| 551 | return Glast; |
||
| 552 | } |
||
| 291 | mhscott | 553 | |
| 554 | |||
| 2736 | mhscott | 555 | const Vector& |
| 1334 | fmk | 556 | SearchWithStepSizeAndStepDirection::getGradientInStandardNormalSpace() |
| 557 | { |
||
| 3498 | mhscott | 558 | return *gradientInStandardNormalSpace; |
| 1334 | fmk | 559 | } |
| 291 | mhscott | 560 | |
| 561 | |||
| 562 | |||
| 1592 | mhscott | 563 | int |
| 564 | SearchWithStepSizeAndStepDirection::getNumberOfEvaluations() |
||
| 565 | { |
||
| 566 | return numberOfEvaluations; |
||
| 567 | } |
||
| 1334 | fmk | 568 | |
| 569 | |||
| 3358 | fmk | 570 | // Quan and Michele |
| 571 | int SearchWithStepSizeAndStepDirection::setStartPt(Vector * pStartPt) |
||
| 572 | { |
||
| 3659 | mhscott | 573 | //startPoint->addVector(0.0,(*pStartPt),1.0); |
| 3358 | fmk | 574 | return 0; |
| 575 | } |
||
| 1592 | mhscott | 576 | |
| 577 |