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 <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
00085 int lsf = theReliabilityDomain->getTagOfActiveLimitStateFunction();
00086 LimitStateFunction *theLimitStateFunction = theReliabilityDomain->getLimitStateFunctionPtr(lsf);
00087
00088
00089
00090 char *theExpression = theLimitStateFunction->getExpression();
00091
00092
00093
00094 int result = this->tokenizeSpecials(theExpression);
00095
00096
00097
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
00115
00116 char *tokenPtr = strtok( lsf_forTokenizing, separators);
00117 while ( tokenPtr != NULL ) {
00118
00119
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
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