GFunEvaluator.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.4 $
00026 // $Date: 2003/10/27 23:45:43 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/analysis/gFunction/GFunEvaluator.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
00032 //
00033 
00034 #include <GFunEvaluator.h>
00035 #include <ReliabilityDomain.h>
00036 #include <tcl.h>
00037 
00038 #include <fstream>
00039 #include <iomanip>
00040 #include <iostream>
00041 using std::ifstream;
00042 using std::ios;
00043 using std::setw;
00044 using std::setprecision;
00045 
00046 GFunEvaluator::GFunEvaluator(Tcl_Interp *passedTclInterp, ReliabilityDomain *passedReliabilityDomain)
00047 {
00048         theTclInterp = passedTclInterp;
00049         theReliabilityDomain = passedReliabilityDomain;
00050         numberOfEvaluations = 0;
00051 }
00052 
00053 GFunEvaluator::~GFunEvaluator()
00054 {
00055 }
00056 
00057 
00058 double
00059 GFunEvaluator::getG()
00060 {
00061         return g;
00062 }
00063 
00064 int
00065 GFunEvaluator::initializeNumberOfEvaluations()
00066 {
00067         numberOfEvaluations = 0;
00068         return 0;
00069 }
00070 
00071 int
00072 GFunEvaluator::getNumberOfEvaluations()
00073 {
00074         return numberOfEvaluations;
00075 }
00076 
00077 
00078 int 
00079 GFunEvaluator::evaluateG(Vector x)
00080 {
00081         numberOfEvaluations++;
00082 
00083 
00084         // "Download" limit-state function from reliability domain
00085         int lsf = theReliabilityDomain->getTagOfActiveLimitStateFunction();
00086         LimitStateFunction *theLimitStateFunction = theReliabilityDomain->getLimitStateFunctionPtr(lsf);
00087 
00088 
00089         // Get the limit-state function expression
00090         char *theExpression = theLimitStateFunction->getExpression();
00091 
00092 
00093         // Set value of GFun-specific parameters in the limit-state function
00094         int result = this->tokenizeSpecials(theExpression);
00095 
00096 
00097         // Initial declarations
00098         int i;
00099         double fileValue = 0.0;
00100 
00101         char buf[500]="";
00102         char tclAssignment[500]="";
00103         char tempchar[100]="";
00104         char temp[120];
00105 
00106         char separators[5] = "}{";
00107         char *dollarSign = "$";
00108         char *underscore = "_";
00109 
00110         char lsf_forTokenizing[500];
00111         strcpy(lsf_forTokenizing,theExpression);
00112 
00113 
00114         // Set values of basic random variables and file quantities
00115         // (Other quantities will have to be set by specific implementations of this class)
00116         char *tokenPtr = strtok( lsf_forTokenizing, separators);
00117         while ( tokenPtr != NULL ) {
00118 
00119                 // Copy the token pointer over to a temporary storage
00120                 strcpy(tempchar,tokenPtr);
00121 
00122                 if ( strncmp(tokenPtr, "x",1) == 0) {
00123                         int rvNum;
00124                         sscanf(tempchar,"x_%i",&rvNum);
00125                         sprintf(tclAssignment , "set x_%d  %15.5f", rvNum, x(rvNum-1) );
00126                         Tcl_Eval( theTclInterp, tclAssignment);
00127                 }
00128                 else if ( strncmp(tokenPtr, "file",4) == 0) {
00129                         int rowNum = 0;
00130                         int colNum = 0;
00131                         char fileName[256];
00132                         sscanf(tempchar,"file_%s",fileName);
00133                         int rowloc = strcspn(fileName,"_");
00134                         char rowstr[10] = "";
00135                         int rowcnt = 0;
00136                         for (i=rowloc+1; fileName[i]!='\0'; i++) {
00137                                 rowstr[rowcnt] = fileName[i];
00138                                 rowcnt++;
00139                         }
00140                         rowstr[rowcnt] = '\0';
00141                         sscanf(rowstr,"%i_%i",&rowNum,&colNum);
00142                         fileName[rowloc] = '\0';
00143 
00144                         ifstream inputFile(fileName,ios::in);
00145                         if (!inputFile) {
00146                                 opserr << "Could not open file with quantities for limit-state function." << endln;
00147                         }
00148                         for (i=1; i<rowNum; i++) {
00149                                 inputFile.getline(buf,120);
00150                         }
00151                         for (i=1; i<=colNum; i++) {
00152                                 inputFile >> temp;
00153                         }
00154                         fileValue = (double)atof(temp);
00155                         if (fileValue == 0.0) {
00156                                 opserr << "ERROR: Could not find quantity in performance function file." << endln;
00157                                 return -1;
00158                         }
00159                         inputFile.close();
00160                         sprintf(tclAssignment , "set file_%s_%d_%d  %15.5f",fileName,rowNum,colNum,fileValue);
00161 
00162                         Tcl_Eval( theTclInterp, tclAssignment);
00163                 }
00164                 
00165                 tokenPtr = strtok( NULL, separators);
00166         }
00167 
00168         // Compute value of g-function
00169         char *theTokenizedExpression = theLimitStateFunction->getTokenizedExpression();
00170         g = 0.0;
00171         Tcl_ExprDouble( theTclInterp, theTokenizedExpression, &g );
00172 
00173 
00174         return 0;
00175 }
00176 
00177 
00178 
00179 
00180 
00181 
00182 void
00183 GFunEvaluator::setNsteps(int nsteps)
00184 {
00185         opserr << "GFunEvaluator::set_nsteps() -- This method is not " << endln
00186                 << " implemented for the chosen type of GFunEvaluator." << endln;
00187 }
00188 
00189 
00190 double
00191 GFunEvaluator::getDt()
00192 {
00193         opserr << "GFunEvaluator::getDt() -- This method is not " << endln
00194                 << " implemented for the chosen type of GFunEvaluator." << endln;
00195         return 0;
00196 }
00197 
00198 
00199 
00200 
00201 

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