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 <SensitivityAlgorithm.h>
00035 #include <LinearSOE.h>
00036 #include <Vector.h>
00037 #include <EquiSolnAlgo.h>
00038 #include <ReliabilityDomain.h>
00039 #include <RandomVariablePositioner.h>
00040
00041
00042 SensitivityAlgorithm::SensitivityAlgorithm(ReliabilityDomain *passedReliabilityDomain,
00043 EquiSolnAlgo *passedAlgorithm,
00044 SensitivityIntegrator *passedSensitivityIntegrator,
00045 int passedAnalysisTypeTag)
00046 {
00047
00048
00049 theReliabilityDomain = passedReliabilityDomain;
00050
00051
00052
00053 theAlgorithm = passedAlgorithm;
00054
00055
00056
00057 theSensitivityIntegrator = passedSensitivityIntegrator;
00058
00059
00060
00061 analysisTypeTag = passedAnalysisTypeTag;
00062
00063 }
00064
00065
00066
00067
00068 SensitivityAlgorithm::~SensitivityAlgorithm()
00069 {
00070 }
00071
00072
00073
00074 int
00075 SensitivityAlgorithm::computeSensitivities(void)
00076 {
00077
00078
00079
00080
00081
00082
00083
00084
00085 int numGrads, numPos, i, gradNumber, posNumber;
00086 RandomVariablePositioner *theRandomVariablePositioner;
00087 ParameterPositioner *theParameterPositioner;
00088
00089
00090
00091 LinearSOE *theSOE = theAlgorithm->getLinearSOEptr();
00092
00093
00094
00095 IncrementalIntegrator *theIncInt = theAlgorithm->getIncrementalIntegratorPtr();
00096
00097
00098
00099
00100
00101 if (theIncInt->formTangent(CURRENT_TANGENT) < 0){
00102 opserr << "WARNING SensitivityAlgorithm::computeGradients() -";
00103 opserr << "the Integrator failed in formTangent()\n";
00104 return -1;
00105 }
00106
00107
00108
00109 if (analysisTypeTag==1 || analysisTypeTag==3) {
00110 numGrads = theReliabilityDomain->getNumberOfRandomVariables();
00111 numPos = theReliabilityDomain->getNumberOfRandomVariablePositioners();
00112 }
00113 else {
00114 numPos = theReliabilityDomain->getNumberOfParameterPositioners();
00115 numGrads = numPos;
00116 }
00117
00118
00119
00120 theSOE->zeroB();
00121
00122
00123
00124 theSensitivityIntegrator->formIndependentSensitivityRHS();
00125
00126
00127
00128 for (gradNumber=1; gradNumber<=numGrads; gradNumber++ ) {
00129
00130
00131
00132 for (i=1; i<=numPos; i++ ) {
00133 if (analysisTypeTag==1 || analysisTypeTag==3) {
00134 theRandomVariablePositioner = theReliabilityDomain->getRandomVariablePositionerPtr(i);
00135 theRandomVariablePositioner->activate(false);
00136 }
00137 else {
00138 theParameterPositioner = theReliabilityDomain->getParameterPositionerPtr(i);
00139 theParameterPositioner->activate(false);
00140 }
00141 }
00142
00143
00144
00145
00146 for (posNumber=1; posNumber<=numPos; posNumber++ ) {
00147
00148 if (analysisTypeTag==1 || analysisTypeTag==3) {
00149
00150 theRandomVariablePositioner = theReliabilityDomain->getRandomVariablePositionerPtr(posNumber);
00151 int rvNumber = theRandomVariablePositioner->getRvNumber();
00152
00153
00154 if ( rvNumber==gradNumber ) {
00155
00156
00157 theRandomVariablePositioner->activate(true);
00158
00159 }
00160 }
00161 else {
00162 theParameterPositioner = theReliabilityDomain->getParameterPositionerPtr(posNumber);
00163 theParameterPositioner->activate(true);
00164 }
00165
00166 }
00167
00168
00169
00170 theSOE->zeroB();
00171
00172
00173
00174 theSensitivityIntegrator->formSensitivityRHS(gradNumber);
00175
00176
00177
00178 theSOE->solve();
00179
00180
00181
00182 theSensitivityIntegrator->saveSensitivity( theSOE->getX(), gradNumber, numGrads );
00183
00184
00185
00186 theSensitivityIntegrator->commitSensitivity(gradNumber, numGrads);
00187
00188 }
00189
00190 return 0;
00191 }
00192
00193 bool
00194 SensitivityAlgorithm::shouldComputeAtEachStep(void)
00195 {
00196 if (analysisTypeTag==1 || analysisTypeTag==2) {
00197 return true;
00198 }
00199 else {
00200 return false;
00201 }
00202 }