SensitivityAlgorithm.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 2001, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** Reliability module developed by:                                   **
00020 **   Terje Haukaas (haukaas@ce.berkeley.edu)                          **
00021 **   Armen Der Kiureghian (adk@ce.berkeley.edu)                       **
00022 **                                                                    **
00023 ** ****************************************************************** */
00024                                                                         
00025 // $Revision: 1.6 $
00026 // $Date: 2003/10/27 23:05:30 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/FEsensitivity/SensitivityAlgorithm.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
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         // The reliability domain is needed to get hold 
00048         // of the random variable positioners:
00049         theReliabilityDomain = passedReliabilityDomain;
00050 
00051         // The finite element equation solution algorithm is 
00052         // needed to get hold of the system of equations (SOE):
00053         theAlgorithm = passedAlgorithm;
00054 
00055         // The sensitivity integrator is needed to assemble the 
00056         // new right-hand side of the system of equations:
00057         theSensitivityIntegrator = passedSensitivityIntegrator;
00058 
00059         // Tag to tell whether grads should be computed at each step
00060         // and whether they should be computed wrt. random variables
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         // Meaning of analysisTypeTag:
00078         // 1: compute at each step wrt. random variables
00079         // 2: compute at each step wrt. parameters
00080         // 3: compute by command wrt. random variables
00081         // 4: compute by command wrt. parameters
00082 
00083         
00084         // Initial declarations
00085         int numGrads, numPos, i, gradNumber, posNumber;
00086         RandomVariablePositioner *theRandomVariablePositioner;
00087         ParameterPositioner *theParameterPositioner;
00088 
00089 
00090         // Get pointer to the system of equations (SOE)
00091         LinearSOE *theSOE = theAlgorithm->getLinearSOEptr();
00092 
00093 
00094         // Get pointer to incremental integrator
00095         IncrementalIntegrator *theIncInt = theAlgorithm->getIncrementalIntegratorPtr();
00096 
00097 
00098         // Form current tangent at converged state
00099         // (would be nice with an if-statement here in case
00100         // the current tangent is already formed)
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         // Get number of random variables and random variable positioners
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         // Zero out the old right-hand side of the SOE
00120         theSOE->zeroB();
00121                 
00122 
00123         // Form the part of the RHS which are indepent of parameter
00124         theSensitivityIntegrator->formIndependentSensitivityRHS();
00125 
00126 
00127         // Loop where one gradient vector is computed per iteration
00128         for (gradNumber=1; gradNumber<=numGrads; gradNumber++ )  {
00129 
00130 
00131                 // Clear sensitivity flags
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                 // Loop over positioners to check which are "active" this time
00145                 // and set flag for phase 1
00146                 for (posNumber=1; posNumber<=numPos; posNumber++ ) {
00147 
00148                         if (analysisTypeTag==1 || analysisTypeTag==3) {
00149                                 // Get the random positioner and its rv#
00150                                 theRandomVariablePositioner = theReliabilityDomain->getRandomVariablePositionerPtr(posNumber);
00151                                 int rvNumber = theRandomVariablePositioner->getRvNumber();
00152 
00153                                 // Check if rv# of this rv positioner is the same as the gradient#
00154                                 if ( rvNumber==gradNumber ) {
00155 
00156                                         // Set sensitivity flag so that this one contributes to the RHS
00157                                         theRandomVariablePositioner->activate(true);
00158 
00159                                 } // End if rv# == gradient#
00160                         }
00161                         else {
00162                                 theParameterPositioner = theReliabilityDomain->getParameterPositionerPtr(posNumber);
00163                                 theParameterPositioner->activate(true);
00164                         }
00165 
00166                 } // End loop over r.v. positioners to check if it contributes
00167 
00168 
00169                 // Zero out the old right-hand side
00170                 theSOE->zeroB();
00171 
00172                 
00173                 // Form new right-hand side
00174                 theSensitivityIntegrator->formSensitivityRHS(gradNumber);
00175 
00176 
00177                 // Solve the system of equation with the new right-hand side
00178                 theSOE->solve();
00179 
00180 
00181                 // Save 'v' to the nodes for a "sensNodeDisp node? dof?" command
00182                 theSensitivityIntegrator->saveSensitivity( theSOE->getX(), gradNumber, numGrads );
00183 
00184 
00185                 // Commit unconditional history variables (also for elastic problems; strain sens may be needed anyway)
00186                 theSensitivityIntegrator->commitSensitivity(gradNumber, numGrads);
00187 
00188         } // End loop for each gradient
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 }

Generated on Mon Oct 23 15:05:26 2006 for OpenSees by doxygen 1.5.0