| 65 | const Vector &ImplicitGradient::getGradient() { return *grad_g; } |
| 66 | |
| 67 | int ImplicitGradient::computeGradient(double g) { |
| 68 | // Initialize gradient vector |
| 69 | grad_g->Zero(); |
| 70 | |
| 71 | // get limit-state function from reliability domain |
| 72 | int lsf = theReliabilityDomain->getTagOfActiveLimitStateFunction(); |
| 73 | LimitStateFunction *theLimitStateFunction = |
| 74 | theReliabilityDomain->getLimitStateFunctionPtr(lsf); |
| 75 | const char *lsfExpression = theLimitStateFunction->getExpression(); |
| 76 | |
| 77 | // get RVs created in the reliability domain |
| 78 | int nrv = this->theReliabilityDomain->getNumberOfRandomVariables(); |
| 79 | |
| 80 | // first check for dg/dimplicit partials |
| 81 | for (int i = 0; i < nrv; i++) { |
| 82 | // get RV |
| 83 | auto *theRV = |
| 84 | this->theReliabilityDomain->getRandomVariablePtrFromIndex(i); |
| 85 | if (theRV == 0) { |
| 86 | opserr << "ERROR: can't get RV " << i |
| 87 | << " -- ImplictGradient::computeGradient\n"; |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | // get RV tag |
| 92 | int rvTag = theRV->getTag(); |
| 93 | |
| 94 | // get grad expression |
| 95 | const char *gradExpression = |
| 96 | theLimitStateFunction->getGradientExpression(rvTag); |
| 97 | |
| 98 | // not provided means zero |
| 99 | if (gradExpression == 0) { |
| 100 | opserr |
| 101 | << "WARNING: lsf " << lsf |
| 102 | << ": gradient expression for " |
| 103 | "random variable " |
| 104 | << rvTag |
| 105 | << " is not defined -- ImplicitGradient::computeGradient"; |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | // set expression |
| 110 | theFunctionEvaluator->setExpression(gradExpression); |
| 111 | |
| 112 | // update variables |
| 113 | if (theFunctionEvaluator->setVariables() < 0) { |
| 114 | opserr << "ERROR ImplicitGradient -- error setting " |
| 115 | "variables in namespace" |
| 116 | << endln; |
| 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | // evaluate grad expression |
| 121 | (*grad_g)(i) = theFunctionEvaluator->evaluateExpression(); |
| 122 | |
| 123 | // Reset limit state function in evaluator |
| 124 | theFunctionEvaluator->setExpression(lsfExpression); |
no test coverage detected