Rev 4801 | Rev 4805 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4801 | Rev 4803 | ||
|---|---|---|---|
| Line 63... | Line 63... | ||
| 63 | ProbabilityTransformation *passedProbabilityTransformation,
|
63 | ProbabilityTransformation *passedProbabilityTransformation,
|
| 64 | FunctionEvaluator *passedGFunEvaluator,
|
64 | FunctionEvaluator *passedGFunEvaluator,
|
| 65 | RandomNumberGenerator *passedRandomNumberGenerator,
|
65 | RandomNumberGenerator *passedRandomNumberGenerator,
|
| 66 | bool passedStartAtOrigin,
|
66 | bool passedStartAtOrigin,
|
| 67 | Tcl_Interp *passedInterp,
|
67 | Tcl_Interp *passedInterp,
|
| 68 |
|
68 | long int passedNumberOfSimulations, |
| 69 | double passedTargetCOV,
|
69 | double passedTargetCOV,
|
| 70 | double passedSamplingStdv,
|
70 | double passedSamplingStdv,
|
| 71 | int passedPrintFlag,
|
71 | int passedPrintFlag,
|
| 72 | TCL_Char *passedFileName,
|
72 | TCL_Char *passedFileName,
|
| 73 | int passedAnalysisTypeTag) |
73 | int passedAnalysisTypeTag) |
| Line 100... | Line 100... | ||
| 100 | int
|
100 | int
|
| 101 | ImportanceSamplingAnalysis::analyze(void) |
101 | ImportanceSamplingAnalysis::analyze(void) |
| 102 | {
|
102 | {
|
| 103 | 103 | ||
| 104 | // Alert the user that the simulation analysis has started
|
104 | // Alert the user that the simulation analysis has started
|
| 105 | opserr << " |
105 | opserr << "ImportanceSampling Analysis is running ... " << endln; |
| 106 | 106 | ||
| 107 | // Declaration of some of the data used in the algorithm
|
107 | // Declaration of some of the data used in the algorithm
|
| 108 | double gFunctionValue; |
108 | double gFunctionValue; |
| 109 | int result, I, |
109 | int result, I, seed = 1; |
| - | 110 | long int k = 1; |
|
| 110 | double det_covariance, phi, h, q; |
111 | double det_covariance, phi, h, q; |
| 111 | int numRV = theReliabilityDomain->getNumberOfRandomVariables(); |
112 | int numRV = theReliabilityDomain->getNumberOfRandomVariables(); |
| 112 | int numLsf = theReliabilityDomain->getNumberOfLimitStateFunctions(); |
113 | int numLsf = theReliabilityDomain->getNumberOfLimitStateFunctions(); |
| 113 | Vector x(numRV); |
114 | Vector x(numRV); |
| 114 | Vector z(numRV); |
115 | Vector z(numRV); |
| Line 161... | Line 162... | ||
| 161 | inputFile.close(); |
162 | inputFile.close(); |
| 162 | }
|
163 | }
|
| 163 | }
|
164 | }
|
| 164 | 165 | ||
| 165 | 166 | ||
| 166 | // Transform start point into standard normal space,
|
- | |
| 167 |
|
167 | // get starting x values from parameter directly
|
| 168 | Vector startPointY(numRV); |
- | |
| 169 | - | ||
| 170 | if (startAtOrigin) |
- | |
| 171 | startPointY.Zero(); |
- | |
| 172 | else { |
- | |
| 173 | //theReliabilityDomain->getStartPoint(x);
|
- | |
| 174 | for (int j = 0; j < numRV; j++) { |
168 | for (int j = 0; j < numRV; j++) { |
| 175 | RandomVariable *theParam = theReliabilityDomain->getRandomVariablePtrFromIndex(j); |
169 | RandomVariable *theParam = theReliabilityDomain->getRandomVariablePtrFromIndex(j); |
| 176 |
|
170 | double rvVal = theParam->getStartValue(); |
| - | 171 | x(j) = rvVal; |
|
| - | 172 | ||
| - | 173 | // now we should update the parameter value
|
|
| - | 174 | // KRM should this be a parameter reference now?
|
|
| - | 175 | theParam->setCurrentValue(rvVal); |
|
| 177 | }
|
176 | }
|
| - | 177 | ||
| - | 178 | // Transform start point into standard normal space
|
|
| - | 179 | Vector startPointY(numRV); |
|
| 178 | result = theProbabilityTransformation->transform_x_to_u(startPointY); |
180 | result = theProbabilityTransformation->transform_x_to_u(startPointY); |
| 179 | if (result < 0) { |
181 | if (result < 0) { |
| 180 | opserr << "ImportanceSamplingAnalysis::analyze() - could not " << endln |
182 | opserr << "ImportanceSamplingAnalysis::analyze() - could not " << endln |
| 181 | << " transform x to u. " << endln; |
183 | << " transform x to u. " << endln; |
| 182 | return -1; |
184 | return -1; |
| 183 | }
|
- | |
| 184 | }
|
185 | }
|
| 185 | 186 | ||
| 186 | // Initial declarations
|
187 | // Initial declarations
|
| 187 | Vector cov_of_q_bar(numLsf); |
188 | Vector cov_of_q_bar(numLsf); |
| 188 | Vector q_bar(numLsf); |
189 | Vector q_bar(numLsf); |
| Line 209... | Line 210... | ||
| 209 | bool isFirstSimulation = true; |
210 | bool isFirstSimulation = true; |
| 210 | while( (k<=numberOfSimulations && govCov>targetCOV || k<=2) ) { |
211 | while( (k<=numberOfSimulations && govCov>targetCOV || k<=2) ) { |
| 211 | 212 | ||
| 212 | // Keep the user posted
|
213 | // Keep the user posted
|
| 213 | if (printFlag == 1 || printFlag == 2) { |
214 | if (printFlag == 1 || printFlag == 2) { |
| - | 215 | sprintf(myString,"%li",k); |
|
| 214 | opserr << "Sample #" << |
216 | opserr << "Sample #" << myString << ":" << endln; |
| 215 | }
|
217 | }
|
| 216 | 218 | ||
| 217 | 219 | ||
| 218 | // Create array of standard normal random numbers
|
220 | // Create array of standard normal random numbers
|
| 219 | if (isFirstSimulation) { |
221 | if (isFirstSimulation) { |
| Line 252... | Line 254... | ||
| 252 | x = theProbabilityTransformation->get_x();
|
254 | x = theProbabilityTransformation->get_x();
|
| 253 | */
|
255 | */
|
| 254 | result = theProbabilityTransformation->transform_u_to_x(u, x); |
256 | result = theProbabilityTransformation->transform_u_to_x(u, x); |
| 255 | if (result < 0) { |
257 | if (result < 0) { |
| 256 | opserr << "ImportanceSamplingAnalysis::analyze() - could not transform u to x. " << endln; |
258 | opserr << "ImportanceSamplingAnalysis::analyze() - could not transform u to x. " << endln; |
| - | 259 | return -1; |
|
| - | 260 | }
|
|
| - | 261 | ||
| - | 262 | // set values in the variable namespace
|
|
| - | 263 | if (theGFunEvaluator->setVariables(x) < 0) { |
|
| - | 264 | opserr << "ImportanceSamplingAnalysis::analyze() - " << endln |
|
| - | 265 | << " could not set variables in namespace. " << endln; |
|
| 257 | return -1; |
266 | return -1; |
| 258 | }
|
267 | }
|
| 259 | 268 | ||
| 260 | // Evaluate limit-state function
|
269 | // Evaluate limit-state function
|
| 261 | FEconvergence = true; |
270 | FEconvergence = true; |
| 262 |
|
271 | if (theGFunEvaluator->runAnalysis(x) < 0) { |
| 263 | if (result < 0) { |
- | |
| 264 | // In this case a failure happened during the analysis
|
272 | // In this case a failure happened during the analysis
|
| 265 | // Hence, register this as failure
|
273 | // Hence, register this as failure
|
| 266 | FEconvergence = false; |
274 | FEconvergence = false; |
| 267 | }
|
275 | }
|
| 268 | 276 | ||
| Line 281... | Line 289... | ||
| 281 | theReliabilityDomain->setTagOfActiveLimitStateFunction(lsfTag); |
289 | theReliabilityDomain->setTagOfActiveLimitStateFunction(lsfTag); |
| 282 | 290 | ||
| 283 | // set namespace variable for tcl procedures
|
291 | // set namespace variable for tcl procedures
|
| 284 | Tcl_SetVar2Ex(interp,"RELIABILITY_lsf",NULL,Tcl_NewIntObj(lsfTag),TCL_NAMESPACE_ONLY); |
292 | Tcl_SetVar2Ex(interp,"RELIABILITY_lsf",NULL,Tcl_NewIntObj(lsfTag),TCL_NAMESPACE_ONLY); |
| 285 | 293 | ||
| 286 |
|
294 | // set and evaluate LSF
|
| - | 295 | const char *lsfExpression = theLimitStateFunction->getExpression(); |
|
| - | 296 | theGFunEvaluator->setExpression(lsfExpression); |
|
| - | 297 | ||
| 287 | gFunctionValue = theGFunEvaluator->evaluateExpression(); |
298 | gFunctionValue = theGFunEvaluator->evaluateExpression(); |
| 288 | if (!FEconvergence) { |
299 | if (!FEconvergence) { |
| 289 | gFunctionValue = -1.0; |
300 | gFunctionValue = -1.0; |
| 290 | }
|
301 | }
|
| 291 | 302 | ||
| Line 479... | Line 490... | ||
| 479 | int lsfTag = theLimitStateFunction->getTag(); |
490 | int lsfTag = theLimitStateFunction->getTag(); |
| 480 | int lsfIndex = theReliabilityDomain->getLimitStateFunctionIndex(lsfTag); |
491 | int lsfIndex = theReliabilityDomain->getLimitStateFunctionIndex(lsfTag); |
| 481 | if ( q_bar(lsfIndex) == 0.0 ) { |
492 | if ( q_bar(lsfIndex) == 0.0 ) { |
| 482 | 493 | ||
| 483 | resultsOutputFile << "#######################################################################" << endln; |
494 | resultsOutputFile << "#######################################################################" << endln; |
| 484 | resultsOutputFile << "# SAMPLING ANALYSIS RESULTS, LIMIT- |
495 | resultsOutputFile << "# SAMPLING ANALYSIS RESULTS, LIMIT-STATE FUNCTION NUMBER " |
| 485 | <<setiosflags(ios::left)<<setprecision(1)<<setw(4)<<lsfTag <<" #" << endln; |
496 | <<setiosflags(ios::left)<<setprecision(1)<<setw(4)<<lsfTag <<" #" << endln; |
| 486 | resultsOutputFile << "# #" << endln; |
497 | resultsOutputFile << "# #" << endln; |
| 487 | resultsOutputFile << "# Failure did not occur, or zero response! #" << endln; |
498 | resultsOutputFile << "# Failure did not occur, or zero response! #" << endln; |
| 488 | resultsOutputFile << "# #" << endln; |
499 | resultsOutputFile << "# #" << endln; |
| 489 | resultsOutputFile << "#######################################################################" << endln << endln << endln; |
500 | resultsOutputFile << "#######################################################################" << endln << endln << endln; |
| Line 592... | Line 603... | ||
| 592 | 603 | ||
| 593 | 604 | ||
| 594 | 605 | ||
| 595 | 606 | ||
| 596 | // Print summary of results to screen
|
607 | // Print summary of results to screen
|
| 597 | opserr << " |
608 | opserr << "ImportanceSampling Analysis completed." << endln; |
| 598 | 609 | ||
| 599 | // Clean up
|
610 | // Clean up
|
| 600 | resultsOutputFile.close(); |
611 | resultsOutputFile.close(); |
| 601 | 612 | ||
| 602 | return 0; |
613 | return 0; |