GradGEvaluator.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.3 $
00026 // $Date: 2003/10/27 23:45:44 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/analysis/sensitivity/GradGEvaluator.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
00032 //
00033 
00034 #include <GradGEvaluator.h>
00035 #include <Matrix.h>
00036 #include <ReliabilityDomain.h>
00037 #include <tcl.h>
00038 
00039 GradGEvaluator::GradGEvaluator(ReliabilityDomain *passedReliabilityDomain,
00040                                                            Tcl_Interp *passedTclInterp)
00041 {
00042         theTclInterp = passedTclInterp;
00043         theReliabilityDomain = passedReliabilityDomain;
00044         DgDpar = 0;
00045 }
00046 
00047 GradGEvaluator::~GradGEvaluator()
00048 {
00049         if (DgDpar != 0)
00050                 delete DgDpar;
00051 }
00052 
00053 
00054 
00055 Matrix
00056 GradGEvaluator::getDgDdispl()
00057 {
00058         opserr << "GradGEvaluator::getDgDdispl() -- This method is not " << endln
00059                 << " implemented for the chosen type of GradGEvaluator." << endln;
00060         
00061         Matrix dummy(1,1);
00062         return dummy;
00063 }
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 int 
00072 GradGEvaluator::computeParameterDerivatives(double g)
00073 {
00074         // Zero out the previous result matrix
00075         if (DgDpar != 0) {
00076                 delete DgDpar;
00077                 DgDpar = 0;
00078         }
00079 
00080 
00081         // Initial declarations
00082         char separators[5] = "}{";
00083         char tclAssignment[500];
00084         double onedgdpar;
00085         int i;
00086 
00087 
00088         // "Download" limit-state function from reliability domain
00089         int lsf = theReliabilityDomain->getTagOfActiveLimitStateFunction();
00090         LimitStateFunction *theLimitStateFunction = 
00091                 theReliabilityDomain->getLimitStateFunctionPtr(lsf);
00092         char *theExpression = theLimitStateFunction->getExpression();
00093         char *lsf_copy = new char[500];
00094         strcpy(lsf_copy,theExpression);
00095         char *tokenPtr = strtok( lsf_copy, separators); 
00096 
00097         while ( tokenPtr != NULL ) {
00098 
00099                 if ( strncmp(tokenPtr, "par", 3) == 0) {
00100         
00101                         // Get parameter number
00102                         int parameterNumber;
00103                         sscanf(tokenPtr,"par_%i",&parameterNumber);
00104 
00105                         // Store the original parameter value
00106                         double originalValue;
00107                         sprintf(tclAssignment , "($par_%d)",parameterNumber);
00108                         Tcl_ExprDouble( theTclInterp, tclAssignment, &originalValue );
00109                         
00110                         // Assign a perturbed value
00111                         sprintf(tclAssignment,"set par_%d [ expr ($par_%d*1.001) ]",parameterNumber,parameterNumber);
00112                         Tcl_Eval( theTclInterp, tclAssignment);
00113 
00114                         // Evaluate limit-state function again
00115                         double g_perturbed;
00116                         char *theTokenizedExpression = theLimitStateFunction->getTokenizedExpression();
00117                         Tcl_ExprDouble( theTclInterp, theTokenizedExpression, &g_perturbed );
00118 
00119                         // Compute the gradient 'dgdpar' by finite difference
00120                         onedgdpar = (g_perturbed-g)/(originalValue*0.001);
00121 
00122                         // Make assignment back to its original value
00123                         sprintf(tclAssignment,"set par_%d %35.20f",parameterNumber,originalValue);
00124                         Tcl_Eval( theTclInterp, tclAssignment);
00125                         
00126                         // Store the DgDpar in a matrix (make it expand successively)
00127                         if (DgDpar == 0) {
00128                                 DgDpar = new Matrix(1, 2);
00129                                 (*DgDpar)(0,0) = (double)parameterNumber;
00130                                 (*DgDpar)(0,1) = onedgdpar;
00131                         }
00132                         else {
00133                                 int oldSize = DgDpar->noRows();
00134                                 Matrix tempMatrix = *DgDpar;
00135                                 delete DgDpar;
00136                                 DgDpar = new Matrix(oldSize+1, 2);
00137                                 for (i=0; i<oldSize; i++) {
00138                                         (*DgDpar)(i,0) = tempMatrix(i,0);
00139                                         (*DgDpar)(i,1) = tempMatrix(i,1);
00140                                 }
00141                                 (*DgDpar)(oldSize,0) = (double)parameterNumber;
00142                                 (*DgDpar)(oldSize,1) = onedgdpar;
00143                         }
00144                 }
00145 
00146                 tokenPtr = strtok( NULL, separators); 
00147         }
00148 
00149         delete [] lsf_copy;
00150 
00151         return 0;
00152 }
00153 
00154 
00155 
00156 Matrix 
00157 GradGEvaluator::getDgDpar()
00158 {
00159         return (*DgDpar);
00160 }

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