Rev 3212 | Rev 3498 | 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 | |||
| 3358 | fmk | 25 | // $Revision: 1.15 $ |
| 26 | // $Date: 2008-03-13 22:30:16 $ |
||
| 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> |
| 291 | mhscott | 36 | #include <StepSizeRule.h> |
| 37 | #include <SearchDirection.h> |
||
| 1334 | fmk | 38 | #include <ProbabilityTransformation.h> |
| 39 | #include <NatafProbabilityTransformation.h> |
||
| 291 | mhscott | 40 | #include <GFunEvaluator.h> |
| 1334 | fmk | 41 | #include <GradGEvaluator.h> |
| 291 | mhscott | 42 | #include <RandomVariable.h> |
| 43 | #include <CorrelationCoefficient.h> |
||
| 44 | #include <MatrixOperations.h> |
||
| 1334 | fmk | 45 | #include <HessianApproximation.h> |
| 46 | #include <ReliabilityConvergenceCheck.h> |
||
| 291 | mhscott | 47 | #include <Matrix.h> |
| 48 | #include <Vector.h> |
||
| 49 | #include <GammaRV.h> |
||
| 50 | |||
| 1334 | fmk | 51 | #include <fstream> |
| 52 | #include <iomanip> |
||
| 53 | #include <iostream> |
||
| 291 | mhscott | 54 | |
| 1334 | fmk | 55 | using std::ifstream; |
| 56 | using std::ios; |
||
| 291 | mhscott | 57 | |
| 1334 | fmk | 58 | using std::setw; |
| 59 | using std::setprecision; |
||
| 60 | |||
| 61 | |||
| 62 | |||
| 291 | mhscott | 63 | SearchWithStepSizeAndStepDirection::SearchWithStepSizeAndStepDirection( |
| 64 | int passedMaxNumberOfIterations, |
||
| 65 | GFunEvaluator *passedGFunEvaluator, |
||
| 1334 | fmk | 66 | GradGEvaluator *passedGradGEvaluator, |
| 291 | mhscott | 67 | StepSizeRule *passedStepSizeRule, |
| 68 | SearchDirection *passedSearchDirection, |
||
| 1334 | fmk | 69 | ProbabilityTransformation *passedProbabilityTransformation, |
| 70 | HessianApproximation *passedHessianApproximation, |
||
| 71 | ReliabilityConvergenceCheck *passedReliabilityConvergenceCheck, |
||
| 72 | int pprintFlag, |
||
| 73 | char *pFileNamePrint, |
||
| 74 | Vector *pStartPoint) |
||
| 75 | :FindDesignPointAlgorithm() |
||
| 291 | mhscott | 76 | { |
| 77 | maxNumberOfIterations = passedMaxNumberOfIterations; |
||
| 78 | theGFunEvaluator = passedGFunEvaluator; |
||
| 1334 | fmk | 79 | theGradGEvaluator = passedGradGEvaluator; |
| 291 | mhscott | 80 | theStepSizeRule = passedStepSizeRule; |
| 81 | theSearchDirection = passedSearchDirection; |
||
| 1334 | fmk | 82 | theProbabilityTransformation = passedProbabilityTransformation; |
| 83 | theHessianApproximation = passedHessianApproximation; |
||
| 84 | theReliabilityConvergenceCheck = passedReliabilityConvergenceCheck; |
||
| 85 | startPoint = pStartPoint; |
||
| 86 | printFlag = pprintFlag; |
||
| 1592 | mhscott | 87 | numberOfEvaluations =0; |
| 1334 | fmk | 88 | if (printFlag != 0) { |
| 89 | strcpy(fileNamePrint,pFileNamePrint); |
||
| 90 | } |
||
| 91 | else { |
||
| 92 | strcpy(fileNamePrint,"searchpoints.out"); |
||
| 93 | } |
||
| 291 | mhscott | 94 | } |
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | SearchWithStepSizeAndStepDirection::~SearchWithStepSizeAndStepDirection() |
||
| 99 | { |
||
| 2665 | mhscott | 100 | |
| 291 | mhscott | 101 | } |
| 102 | |||
| 103 | |||
| 104 | int |
||
| 1334 | fmk | 105 | SearchWithStepSizeAndStepDirection::findDesignPoint(ReliabilityDomain *passedReliabilityDomain) |
| 291 | mhscott | 106 | { |
| 107 | |||
| 108 | // Set the reliability domain (a data member of this class) |
||
| 109 | theReliabilityDomain = passedReliabilityDomain; |
||
| 110 | |||
| 1334 | fmk | 111 | // Declaration of data used in the algorithm |
| 291 | mhscott | 112 | int numberOfRandomVariables = theReliabilityDomain->getNumberOfRandomVariables(); |
| 405 | mhscott | 113 | int j; |
| 291 | mhscott | 114 | int zeroFlag; |
| 1334 | fmk | 115 | Vector dummy(numberOfRandomVariables); |
| 116 | x = dummy; |
||
| 117 | u = dummy; |
||
| 118 | Vector u_old(numberOfRandomVariables); |
||
| 2787 | mhscott | 119 | uSecondLast = dummy; |
| 291 | mhscott | 120 | Vector uNew(numberOfRandomVariables); |
| 2787 | mhscott | 121 | alpha = dummy; |
| 122 | gamma = dummy; |
||
| 123 | alphaSecondLast = dummy; |
||
| 1334 | fmk | 124 | double gFunctionValue = 1.0; |
| 125 | double gFunctionValue_old = 1.0; |
||
| 291 | mhscott | 126 | Vector gradientOfgFunction(numberOfRandomVariables); |
| 2787 | mhscott | 127 | gradientInStandardNormalSpace = dummy; |
| 1334 | fmk | 128 | Vector gradientInStandardNormalSpace_old(numberOfRandomVariables); |
| 291 | mhscott | 129 | double normOfGradient =0; |
| 130 | double stepSize; |
||
| 2987 | mhscott | 131 | //Matrix jacobian_x_u(numberOfRandomVariables,numberOfRandomVariables); |
| 1334 | fmk | 132 | int evaluationInStepSize = 0; |
| 133 | int result; |
||
| 1592 | mhscott | 134 | theGFunEvaluator->initializeNumberOfEvaluations(); |
| 291 | mhscott | 135 | |
| 1334 | fmk | 136 | |
| 137 | // Prepare output file to store the search points |
||
| 138 | ofstream outputFile2( fileNamePrint, ios::out ); |
||
| 139 | if (printFlag == 0) { |
||
| 140 | outputFile2 << "The user has not specified to store any search points." << endln; |
||
| 141 | outputFile2 << "This is just a dummy file. " << endln; |
||
| 142 | } |
||
| 291 | mhscott | 143 | |
| 144 | |||
| 1334 | fmk | 145 | if (startPoint == 0) { |
| 146 | // Here we want to start at the origin in the standard normal space. |
||
| 147 | // Hence, just leave 'u' as being initialized to zero. |
||
| 148 | // (Note; this is slightly different from the mean point, as done earlier) |
||
| 291 | mhscott | 149 | } |
| 1334 | fmk | 150 | else { |
| 291 | mhscott | 151 | |
| 1334 | fmk | 152 | // Get starting point |
| 153 | x = (*startPoint); |
||
| 291 | mhscott | 154 | |
| 3212 | mhscott | 155 | /* |
| 1334 | fmk | 156 | // Transform starting point into standard normal space |
| 157 | result = theProbabilityTransformation->set_x(x); |
||
| 158 | if (result < 0) { |
||
| 159 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 160 | << " could not set x in the xu-transformation." << endln; |
||
| 161 | return -1; |
||
| 162 | } |
||
| 163 | |||
| 164 | |||
| 165 | result = theProbabilityTransformation->transform_x_to_u(); |
||
| 166 | if (result < 0) { |
||
| 167 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 168 | << " could not transform from x to u." << endln; |
||
| 169 | return -1; |
||
| 170 | } |
||
| 171 | u = theProbabilityTransformation->get_u(); |
||
| 3212 | mhscott | 172 | */ |
| 173 | |||
| 174 | // Transform starting point into standard normal space |
||
| 175 | result = theProbabilityTransformation->transform_x_to_u(x, u); |
||
| 176 | if (result < 0) { |
||
| 177 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 178 | << " could not transform from x to u." << endln; |
||
| 179 | return -1; |
||
| 180 | } |
||
| 291 | mhscott | 181 | } |
| 182 | |||
| 3212 | mhscott | 183 | Matrix Jxu(numberOfRandomVariables, numberOfRandomVariables); |
| 184 | Matrix Jux(numberOfRandomVariables, numberOfRandomVariables); |
||
| 185 | |||
| 291 | mhscott | 186 | // Loop to find design point |
| 187 | i = 1; |
||
| 188 | while ( i <= maxNumberOfIterations ) |
||
| 189 | { |
||
| 3212 | mhscott | 190 | /* |
| 291 | mhscott | 191 | // Transform from u to x space |
| 1334 | fmk | 192 | result = theProbabilityTransformation->set_u(u); |
| 291 | mhscott | 193 | if (result < 0) { |
| 1271 | fmk | 194 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 195 | << " could not set u in the xu-transformation." << endln; |
||
| 291 | mhscott | 196 | return -1; |
| 197 | } |
||
| 198 | |||
| 1334 | fmk | 199 | result = theProbabilityTransformation->transform_u_to_x_andComputeJacobian(); |
| 291 | mhscott | 200 | if (result < 0) { |
| 1271 | fmk | 201 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 202 | << " could not transform from u to x and compute Jacobian." << endln; |
||
| 291 | mhscott | 203 | return -1; |
| 204 | } |
||
| 1334 | fmk | 205 | x = theProbabilityTransformation->get_x(); |
| 2987 | mhscott | 206 | const Matrix &jacobian_x_u = theProbabilityTransformation->getJacobian_x_u(); |
| 3212 | mhscott | 207 | */ |
| 208 | // Transform to x-space |
||
| 209 | result = theProbabilityTransformation->transform_u_to_x(u, x); |
||
| 210 | if (result < 0) { |
||
| 211 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 212 | << " could not transform from u to x." << endln; |
||
| 213 | return -1; |
||
| 214 | } |
||
| 215 | // Get Jacobian x-space to u-space |
||
| 216 | result = theProbabilityTransformation->getJacobian_x_to_u(x, Jxu); |
||
| 217 | if (result < 0) { |
||
| 218 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 219 | << " could not transform from u to x." << endln; |
||
| 220 | return -1; |
||
| 221 | } |
||
| 291 | mhscott | 222 | |
| 223 | |||
| 3212 | mhscott | 224 | |
| 1334 | fmk | 225 | // Possibly print the point to output file |
| 226 | int iii; |
||
| 227 | if (printFlag != 0) { |
||
| 228 | |||
| 229 | if (printFlag == 1) { |
||
| 230 | outputFile2.setf(ios::scientific, ios::floatfield); |
||
| 231 | for (iii=0; iii<x.Size(); iii++) { |
||
| 232 | outputFile2<<setprecision(5)<<setw(15)<<x(iii)<<endln; |
||
| 233 | } |
||
| 234 | } |
||
| 235 | else if (printFlag == 2) { |
||
| 236 | outputFile2.setf(ios::scientific, ios::floatfield); |
||
| 237 | for (iii=0; iii<u.Size(); iii++) { |
||
| 238 | outputFile2<<setprecision(5)<<setw(15)<<u(iii)<<endln; |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | |||
| 510 | mhscott | 244 | // Evaluate limit-state function unless it has been done in |
| 245 | // a trial step by the "stepSizeAlgorithm" |
||
| 1334 | fmk | 246 | if (evaluationInStepSize == 0) { |
| 247 | result = theGFunEvaluator->runGFunAnalysis(x); |
||
| 510 | mhscott | 248 | if (result < 0) { |
| 1271 | fmk | 249 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 1334 | fmk | 250 | << " could not run analysis to evaluate limit-state function. " << endln; |
| 510 | mhscott | 251 | return -1; |
| 252 | } |
||
| 1334 | fmk | 253 | result = theGFunEvaluator->evaluateG(x); |
| 254 | if (result < 0) { |
||
| 255 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 256 | << " could not tokenize limit-state function. " << endln; |
||
| 257 | return -1; |
||
| 258 | } |
||
| 259 | gFunctionValue_old = gFunctionValue; |
||
| 260 | gFunctionValue = theGFunEvaluator->getG(); |
||
| 291 | mhscott | 261 | } |
| 262 | |||
| 263 | |||
| 1334 | fmk | 264 | // Set scale parameter |
| 265 | if (i == 1) { |
||
| 266 | Gfirst = gFunctionValue; |
||
| 267 | opserr << " Limit-state function value at start point, g=" << gFunctionValue << endln; |
||
| 268 | opserr << " STEP #0: "; |
||
| 1592 | mhscott | 269 | theReliabilityConvergenceCheck->setScaleValue(gFunctionValue); |
| 510 | mhscott | 270 | } |
| 271 | |||
| 272 | |||
| 291 | mhscott | 273 | // Gradient in original space |
| 1592 | mhscott | 274 | result = theGradGEvaluator->computeGradG(gFunctionValue,x); |
| 275 | if (result < 0) { |
||
| 276 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 277 | << " could not compute gradients of the limit-state function. " << endln; |
||
| 278 | return -1; |
||
| 279 | } |
||
| 280 | gradientOfgFunction = theGradGEvaluator->getGradG(); |
||
| 291 | mhscott | 281 | |
| 282 | |||
| 1592 | mhscott | 283 | // Check if all components of the vector is zero |
| 284 | zeroFlag = 0; |
||
| 285 | for (j=0; j<gradientOfgFunction.Size(); j++) { |
||
| 286 | if (gradientOfgFunction[j] != 0.0) { |
||
| 287 | zeroFlag = 1; |
||
| 291 | mhscott | 288 | } |
| 1592 | mhscott | 289 | } |
| 290 | if (zeroFlag == 0) { |
||
| 291 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 292 | << " all components of the gradient vector is zero. " << endln; |
||
| 293 | return -1; |
||
| 294 | } |
||
| 291 | mhscott | 295 | |
| 296 | |||
| 1592 | mhscott | 297 | // Gradient in standard normal space |
| 298 | gradientInStandardNormalSpace_old = gradientInStandardNormalSpace; |
||
| 2787 | mhscott | 299 | //gradientInStandardNormalSpace = jacobian_x_u ^ gradientOfgFunction; |
| 3212 | mhscott | 300 | //gradientInStandardNormalSpace.addMatrixTransposeVector(0.0, jacobian_x_u, gradientOfgFunction, 1.0); |
| 301 | gradientInStandardNormalSpace.addMatrixTransposeVector(0.0, Jxu, gradientOfgFunction, 1.0); |
||
| 291 | mhscott | 302 | |
| 303 | |||
| 304 | // Compute the norm of the gradient in standard normal space |
||
| 305 | normOfGradient = gradientInStandardNormalSpace.Norm(); |
||
| 306 | |||
| 307 | |||
| 308 | // Check that the norm is not zero |
||
| 309 | if (normOfGradient == 0.0) { |
||
| 1271 | fmk | 310 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 311 | << " the norm of the gradient is zero. " << endln; |
||
| 291 | mhscott | 312 | return -1; |
| 313 | } |
||
| 314 | |||
| 1334 | fmk | 315 | |
| 291 | mhscott | 316 | // Compute alpha-vector |
| 1334 | fmk | 317 | alpha = gradientInStandardNormalSpace * ( (-1.0) / normOfGradient ); |
| 291 | mhscott | 318 | |
| 319 | |||
| 320 | // Check convergence |
||
| 1334 | fmk | 321 | result = theReliabilityConvergenceCheck->check(u,gFunctionValue,gradientInStandardNormalSpace); |
| 3133 | mhscott | 322 | if (result > 0 || i == maxNumberOfIterations) { |
| 1334 | fmk | 323 | |
| 510 | mhscott | 324 | |
| 1334 | fmk | 325 | // Inform the user of the happy news! |
| 1592 | mhscott | 326 | opserr << "Design point found!" << endln; |
| 510 | mhscott | 327 | |
| 328 | |||
| 1334 | fmk | 329 | // Print the design point to file, if desired |
| 330 | int iii; |
||
| 331 | if (printFlag != 0) { |
||
| 332 | if (printFlag == 3) { |
||
| 3212 | mhscott | 333 | /* |
| 1334 | fmk | 334 | result = theProbabilityTransformation->set_u(u); |
| 335 | if (result < 0) { |
||
| 336 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 337 | << " could not set u in the xu-transformation." << endln; |
||
| 338 | return -1; |
||
| 339 | } |
||
| 340 | |||
| 341 | result = theProbabilityTransformation->transform_u_to_x(); |
||
| 342 | if (result < 0) { |
||
| 343 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 344 | << " could not transform from u to x." << endln; |
||
| 345 | return -1; |
||
| 346 | } |
||
| 347 | x = theProbabilityTransformation->get_x(); |
||
| 3212 | mhscott | 348 | */ |
| 349 | result = theProbabilityTransformation->transform_u_to_x(u, x); |
||
| 350 | if (result < 0) { |
||
| 351 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 352 | << " could not transform from u to x." << endln; |
||
| 353 | return -1; |
||
| 354 | } |
||
| 1334 | fmk | 355 | |
| 356 | outputFile2.setf(ios::scientific, ios::floatfield); |
||
| 357 | for (iii=0; iii<x.Size(); iii++) { |
||
| 358 | outputFile2<<setprecision(5)<<setw(15)<<x(iii)<<endln; |
||
| 359 | } |
||
| 360 | } |
||
| 361 | else if (printFlag == 4) { |
||
| 362 | static ofstream outputFile2( fileNamePrint, ios::out ); |
||
| 363 | outputFile2.setf(ios::scientific, ios::floatfield); |
||
| 364 | for (iii=0; iii<u.Size(); iii++) { |
||
| 365 | outputFile2<<setprecision(5)<<setw(15)<<u(iii)<<endln; |
||
| 366 | } |
||
| 367 | } |
||
| 368 | } |
||
| 369 | |||
| 370 | |||
| 510 | mhscott | 371 | // Compute the gamma vector |
| 3212 | mhscott | 372 | //const Matrix &jacobian_u_x = theProbabilityTransformation->getJacobian_u_x(); |
| 373 | // Get Jacobian u-space to x-space |
||
| 374 | result = theProbabilityTransformation->getJacobian_u_to_x(u, Jux); |
||
| 375 | if (result < 0) { |
||
| 376 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
||
| 377 | << " could not transform from u to x." << endln; |
||
| 378 | return -1; |
||
| 379 | } |
||
| 291 | mhscott | 380 | |
| 2787 | mhscott | 381 | //Vector tempProduct = jacobian_u_x ^ alpha; |
| 382 | Vector tempProduct(numberOfRandomVariables); |
||
| 3212 | mhscott | 383 | //tempProduct.addMatrixTransposeVector(0.0, jacobian_u_x, alpha, 1.0); |
| 384 | tempProduct.addMatrixTransposeVector(0.0, Jux, alpha, 1.0); |
||
| 291 | mhscott | 385 | |
| 2987 | mhscott | 386 | // Only diagonal elements of (J_xu*J_xu^T) are used |
| 387 | for (j = 0; j < numberOfRandomVariables; j++) { |
||
| 388 | double sum = 0.0; |
||
| 389 | double jk; |
||
| 390 | for (int k = 0; k < numberOfRandomVariables; k++) { |
||
| 3212 | mhscott | 391 | //jk = jacobian_x_u(j,k); |
| 392 | jk = Jxu(j,k); |
||
| 2987 | mhscott | 393 | sum += jk*jk; |
| 394 | } |
||
| 395 | gamma(j) = sqrt(sum) * tempProduct(j); |
||
| 396 | } |
||
| 1334 | fmk | 397 | |
| 398 | Glast = gFunctionValue; |
||
| 291 | mhscott | 399 | |
| 1592 | mhscott | 400 | numberOfEvaluations = theGFunEvaluator->getNumberOfEvaluations(); |
| 401 | |||
| 291 | mhscott | 402 | return 1; |
| 403 | } |
||
| 404 | |||
| 405 | |||
| 406 | // Store 'u' and 'alpha' at the second last iteration point |
||
| 407 | uSecondLast = u; |
||
| 408 | alphaSecondLast = alpha; |
||
| 409 | |||
| 410 | |||
| 1334 | fmk | 411 | // Let user know that we have to take a new step |
| 412 | opserr << " STEP #" << i <<": "; |
||
| 413 | |||
| 414 | |||
| 415 | // Update Hessian approximation, if any |
||
| 416 | if ( (theHessianApproximation!=0) && (i!=1) ) { |
||
| 417 | theHessianApproximation->updateHessianApproximation(u_old, |
||
| 418 | gFunctionValue_old, |
||
| 419 | gradientInStandardNormalSpace_old, |
||
| 420 | stepSize, |
||
| 421 | searchDirection, |
||
| 422 | gFunctionValue, |
||
| 423 | gradientInStandardNormalSpace); |
||
| 424 | } |
||
| 425 | |||
| 426 | |||
| 291 | mhscott | 427 | // Determine search direction |
| 1334 | fmk | 428 | result = theSearchDirection->computeSearchDirection(i, |
| 291 | mhscott | 429 | u, gFunctionValue, gradientInStandardNormalSpace ); |
| 430 | if (result < 0) { |
||
| 1271 | fmk | 431 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 432 | << " could not compute search direction. " << endln; |
||
| 291 | mhscott | 433 | return -1; |
| 434 | } |
||
| 435 | searchDirection = theSearchDirection->getSearchDirection(); |
||
| 436 | |||
| 437 | |||
| 438 | // Determine step size |
||
| 439 | result = theStepSizeRule->computeStepSize( |
||
| 1334 | fmk | 440 | u, gradientInStandardNormalSpace, gFunctionValue, searchDirection, i); |
| 441 | if (result < 0) { // (something went wrong) |
||
| 1271 | fmk | 442 | opserr << "SearchWithStepSizeAndStepDirection::doTheActualSearch() - " << endln |
| 443 | << " could not compute step size. " << endln; |
||
| 291 | mhscott | 444 | return -1; |
| 445 | } |
||
| 1334 | fmk | 446 | else if (result == 0) { // (nothing was evaluated in step size) |
| 447 | evaluationInStepSize = 0; |
||
| 448 | } |
||
| 1592 | mhscott | 449 | else if (result == 1) { // (the gfun was evaluated) |
| 1334 | fmk | 450 | evaluationInStepSize = 1; |
| 451 | gFunctionValue_old = gFunctionValue; |
||
| 452 | gFunctionValue = theStepSizeRule->getGFunValue(); |
||
| 453 | } |
||
| 291 | mhscott | 454 | stepSize = theStepSizeRule->getStepSize(); |
| 455 | |||
| 456 | |||
| 1334 | fmk | 457 | // Determine new iteration point (take the step) |
| 458 | u_old = u; |
||
| 2787 | mhscott | 459 | //u = u_old + (searchDirection * stepSize); |
| 460 | u = u_old; |
||
| 461 | u.addVector(1.0, searchDirection, stepSize); |
||
| 510 | mhscott | 462 | |
| 463 | |||
| 291 | mhscott | 464 | // Increment the loop parameter |
| 465 | i++; |
||
| 466 | |||
| 467 | } |
||
| 468 | |||
| 469 | |||
| 470 | // Print a message if max number of iterations was reached |
||
| 1334 | fmk | 471 | // (Note: in this case the last trial point was never transformed/printed) |
| 1271 | fmk | 472 | opserr << "Maximum number of iterations was reached before convergence." << endln; |
| 291 | mhscott | 473 | |
| 1334 | fmk | 474 | |
| 475 | return -1; |
||
| 291 | mhscott | 476 | } |
| 477 | |||
| 478 | |||
| 479 | |||
| 2736 | mhscott | 480 | const Vector& |
| 291 | mhscott | 481 | SearchWithStepSizeAndStepDirection::get_x() |
| 482 | { |
||
| 483 | return x; |
||
| 484 | } |
||
| 485 | |||
| 2736 | mhscott | 486 | const Vector & |
| 291 | mhscott | 487 | SearchWithStepSizeAndStepDirection::get_u() |
| 488 | { |
||
| 489 | return u; |
||
| 490 | } |
||
| 491 | |||
| 2736 | mhscott | 492 | const Vector& |
| 291 | mhscott | 493 | SearchWithStepSizeAndStepDirection::get_alpha() |
| 494 | { |
||
| 495 | return alpha; |
||
| 496 | } |
||
| 497 | |||
| 2736 | mhscott | 498 | const Vector& |
| 291 | mhscott | 499 | SearchWithStepSizeAndStepDirection::get_gamma() |
| 500 | { |
||
| 2736 | mhscott | 501 | if (gamma.Norm() > 1.0) |
| 502 | gamma = gamma / gamma.Norm(); |
||
| 503 | |||
| 504 | return gamma; |
||
| 291 | mhscott | 505 | } |
| 506 | |||
| 507 | int |
||
| 1334 | fmk | 508 | SearchWithStepSizeAndStepDirection::getNumberOfSteps() |
| 291 | mhscott | 509 | { |
| 1334 | fmk | 510 | return (i-1); |
| 291 | mhscott | 511 | } |
| 512 | |||
| 2736 | mhscott | 513 | const Vector& |
| 291 | mhscott | 514 | SearchWithStepSizeAndStepDirection::getSecondLast_u() |
| 515 | { |
||
| 516 | return uSecondLast; |
||
| 517 | } |
||
| 518 | |||
| 2736 | mhscott | 519 | const Vector& |
| 291 | mhscott | 520 | SearchWithStepSizeAndStepDirection::getSecondLast_alpha() |
| 521 | { |
||
| 522 | return alphaSecondLast; |
||
| 523 | } |
||
| 524 | |||
| 2736 | mhscott | 525 | const Vector& |
| 291 | mhscott | 526 | SearchWithStepSizeAndStepDirection::getLastSearchDirection() |
| 527 | { |
||
| 528 | return searchDirection; |
||
| 529 | } |
||
| 530 | |||
| 531 | double |
||
| 532 | SearchWithStepSizeAndStepDirection::getFirstGFunValue() |
||
| 533 | { |
||
| 1334 | fmk | 534 | return Gfirst; |
| 291 | mhscott | 535 | } |
| 536 | |||
| 1334 | fmk | 537 | double |
| 538 | SearchWithStepSizeAndStepDirection::getLastGFunValue() |
||
| 539 | { |
||
| 540 | return Glast; |
||
| 541 | } |
||
| 291 | mhscott | 542 | |
| 543 | |||
| 2736 | mhscott | 544 | const Vector& |
| 1334 | fmk | 545 | SearchWithStepSizeAndStepDirection::getGradientInStandardNormalSpace() |
| 546 | { |
||
| 547 | return gradientInStandardNormalSpace; |
||
| 548 | } |
||
| 291 | mhscott | 549 | |
| 550 | |||
| 551 | |||
| 1592 | mhscott | 552 | int |
| 553 | SearchWithStepSizeAndStepDirection::getNumberOfEvaluations() |
||
| 554 | { |
||
| 555 | return numberOfEvaluations; |
||
| 556 | } |
||
| 1334 | fmk | 557 | |
| 558 | |||
| 3358 | fmk | 559 | // Quan and Michele |
| 1334 | fmk | 560 | |
| 3358 | fmk | 561 | int SearchWithStepSizeAndStepDirection::setStartPt(Vector * pStartPt) |
| 562 | { |
||
| 563 | startPoint->addVector(0.0,(*pStartPt),1.0); |
||
| 564 | return 0; |
||
| 565 | } |
||
| 1592 | mhscott | 566 | |
| 567 | |||
| 568 |