DiscretizedRandomProcessSeries.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.5 $
00026 // $Date: 2006/09/05 20:53:29 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/domain/pattern/DiscretizedRandomProcessSeries.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu), February 2002
00032 // Revised: 
00033 //
00034 
00035 #include <DiscretizedRandomProcessSeries.h>
00036 #include <Vector.h>
00037 #include <Channel.h>
00038 #include <ModulatingFunction.h>
00039 #include <Filter.h>
00040 #include <classTags.h>
00041 #include <Parameter.h>
00042 
00043 DiscretizedRandomProcessSeries::DiscretizedRandomProcessSeries(int num, 
00044                                                                ModulatingFunction **theModFuncs,
00045                                                                double p_mean,
00046                                                                double p_maxStdv)
00047 :TimeSeries(TSERIES_TAG_DiscretizedRandomProcessSeries)
00048 {
00049         randomVariables = 0;
00050         kickInTimes = 0;
00051     theModulatingFunctions = theModFuncs;
00052         numModFuncs = num;
00053         mean = p_mean;
00054         maxStdv = p_maxStdv;
00055 
00056         c = 0.0;
00057 }
00058 
00059 
00060 DiscretizedRandomProcessSeries::~DiscretizedRandomProcessSeries()
00061 {
00062         if (randomVariables != 0) 
00063                 delete randomVariables;
00064 
00065         if (kickInTimes != 0) 
00066                 delete kickInTimes;
00067 }
00068 
00069 
00070 double
00071 DiscretizedRandomProcessSeries::getFactor(double time)
00072 {
00073         if (time == 0.0) {
00074                 return 0.0;
00075         }
00076         else if (randomVariables == 0 || kickInTimes == 0) {
00077                 opserr << "ERROR in DiscretizedRandomProcessSeries::getFactor(): " << endln
00078                         << " random variables or kick-in times vector(s) do not exist. " << endln;
00079                 return 0.0;
00080         }
00081         else if (kickInTimes->Size() != randomVariables->Size() ) {
00082                 opserr << "ERROR in DiscretizedRandomProcessSeries::getFactor(): " << endln
00083                         << " number of random variables is not the same as kick-in times. " << endln;
00084                 return 0.0;
00085         }
00086         else {
00087                 double sum1;
00088                 double sum2;
00089                 int nrv = 0;
00090                 double modFuncAmplitude, filterAmplitude;
00091                 Filter *theFilter;
00092 
00093                 // Loop over all modulating functions
00094                 sum1 = 0.0;
00095                 for (int k=0; k<numModFuncs; k++) {
00096 
00097                         // Get value of modulating function number k at time t
00098                         modFuncAmplitude = theModulatingFunctions[k]->getAmplitude(time);
00099                         theFilter = theModulatingFunctions[k]->getFilter();
00100 
00101                         // Number of discretizing random variables
00102                         nrv = randomVariables->Size();
00103 
00104                         // Loop over all active rv's 
00105                         sum2 = 0.0;
00106                         for (int i=0; i<nrv; i++) {
00107 
00108                                 // Get value of filter for argument (t-ti)
00109                                 filterAmplitude = theFilter->getAmplitude(time-(*kickInTimes)(i));
00110                                 
00111                                 // Add contribution 'ui * hi'
00112                                 sum2 += (*randomVariables)(i) * filterAmplitude;
00113 
00114                                 // Break when we get to inactive rv's
00115                                 if (time-(*kickInTimes)(i) < 0.0) {
00116                                         break;
00117                                 }
00118                         }
00119 
00120                         sum1 += sum2*modFuncAmplitude;
00121                 }
00122 
00123                 double result = mean + c*sum1;
00124                 return result;
00125         }
00126 }
00127 
00128 
00129 double
00130 DiscretizedRandomProcessSeries::getFactorSensitivity(double time)
00131 {
00132         // The parameterID has been set to the number of 
00133         // the random variable in question
00134 
00135         // So, do the same thing as above, just set x(i-1) equal to 1.0
00136         // for i==parameterID
00137 
00138         if (time == 0.0) {
00139                 return 0.0;
00140         }
00141         else if (randomVariables == 0 || kickInTimes == 0) {
00142                 opserr << "ERROR in DiscretizedRandomProcessSeries::getFactorSensitivity(): " << endln
00143                         << " random variables or kick-in times vector(s) do not exist. " << endln;
00144                 return 0.0;
00145         }
00146         else if (kickInTimes->Size() != randomVariables->Size() ) {
00147                 opserr << "ERROR in DiscretizedRandomProcessSeries::getFactorSensitivity(): " << endln
00148                         << " number of random variables is not the same as kick-in times. " << endln;
00149                 return 0.0;
00150         }
00151         else {
00152 
00153                 double sum1;
00154                 double sum2;
00155                 int nrv = 0;
00156                 double modFuncAmplitude;
00157                 Filter *theFilter;
00158 
00159                 // Loop over all modulating functions
00160                 sum1 = 0.0;
00161                 for (int k=0; k<numModFuncs; k++) {
00162 
00163                         // Get value of modulating function number k at time t
00164                         modFuncAmplitude = theModulatingFunctions[k]->getAmplitude(time);
00165                         theFilter = theModulatingFunctions[k]->getFilter();
00166 
00167                         // Number of discretizing random variables
00168                         nrv = randomVariables->Size();
00169 
00170                         // Loop over all rv's (even though some may be zero at this time)
00171                         sum2 = theFilter->getAmplitude(time-(*kickInTimes)(parameterID-1));
00172                         sum1 += sum2*modFuncAmplitude;
00173                 }
00174 
00175                 double result = mean + c*sum1;
00176                 return result;
00177         }
00178 }
00179 
00180 
00181 int
00182 DiscretizedRandomProcessSeries::sendSelf(int commitTag, Channel &theChannel)
00183 {
00184         return 0;
00185 }
00186 
00187 
00188 int 
00189 DiscretizedRandomProcessSeries::recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker)
00190 {
00191         return 0;    
00192 }
00193 
00194 
00195 void
00196 DiscretizedRandomProcessSeries::Print(OPS_Stream &s, int flag)
00197 {
00198 }
00199 
00200 int
00201 DiscretizedRandomProcessSeries::setParameter(const char **argv, int argc,
00202                                              Parameter &param)
00203 {
00204   if (argc < 1)
00205     return -1;
00206 
00207   // **** MHS needs to fix this!!
00208   //int rvNumber = info.theInt;
00209   int rvNumber = 1;  // to get it to compile for now
00210   // **********************
00211 
00212         // The second argument tells when the random variable "kicks in".
00213         // Store this in a table...
00214         // In case the vector doesn't exist
00215         if (kickInTimes == 0) {
00216                 kickInTimes = new Vector(rvNumber);
00217                 (*kickInTimes)(rvNumber-1) = (double)atof(argv[0]);
00218 
00219                 // Assume more than one random variable, so don't 
00220                 // update factor 'c' here.
00221         }
00222         // In case the vector isn't big enough
00223         else if (kickInTimes->Size() < rvNumber) {
00224 
00225                 // Store old values in a temporary vector
00226                 Vector temp(*kickInTimes);
00227 
00228                 // Create a large enough vector
00229                 delete kickInTimes;
00230                 kickInTimes = new Vector(rvNumber);
00231 
00232                 // Put in old values
00233                 for (int i=0; i<temp.Size(); i++) {
00234                         (*kickInTimes)(i) = temp(i);
00235                 }
00236 
00237                 // Put in new value
00238                 (*kickInTimes)(rvNumber-1) = (double)atof(argv[0]);
00239 
00240 
00242 
00243                 // Number of discretizing random variables
00244                 int nrv = kickInTimes->Size();
00245 
00246                 double new_c;
00247                 double denominator;
00248 
00249                 // Loop over all time instances
00250                 for (int t=1; t<=nrv; t++) {
00251 
00252                         denominator = 0.0;
00253 
00254                         // Loop over modulating functions
00255                         for (int k=0; k<numModFuncs; k++) {
00256 
00257                                 // Get value of modulating function number k at time t
00258                                 Filter *theFilter_k = theModulatingFunctions[k]->getFilter();
00259                                 double modFuncAmplitude_k = theModulatingFunctions[k]->getAmplitude((*kickInTimes)(t-1));
00260                 
00261                                 
00262                                 // Loop over modulating functions
00263                                 for (int l=0; l<numModFuncs; l++) {
00264 
00265 
00266                                         // Get value of modulating function number l at time t
00267                                         Filter *theFilter_l = theModulatingFunctions[l]->getFilter();
00268                                         double modFuncAmplitude_l = theModulatingFunctions[l]->getAmplitude((*kickInTimes)(t-1));
00269 
00270 
00271                                         // Loop over all rv's (even though some may be zero at this time)
00272                                         for (int i=0; i<nrv; i++) {
00273 
00274                                                 // Get value of filters for argument (t-ti)
00275                                                 double filterAmplitude_k = theFilter_k->getAmplitude(((*kickInTimes)(t-1))-(*kickInTimes)(i));
00276                                                 double filterAmplitude_l = theFilter_l->getAmplitude(((*kickInTimes)(t-1))-(*kickInTimes)(i));
00277                                                 
00278                                                 // Add contribution 'ui * hi'
00279                                                 denominator += filterAmplitude_k*filterAmplitude_l
00280                                                                          * modFuncAmplitude_k*modFuncAmplitude_l;
00281                                         }
00282                                 }
00283                         }
00284                 }
00285 
00286                 new_c = sqrt(maxStdv*maxStdv/denominator);
00287 
00288                 if (c==0.0) {
00289                         c = new_c;
00290                 }
00291                 else if (new_c < c) {
00292                         c = new_c;
00293                 }
00294 
00295 c = maxStdv;
00296 opserr << "c: " << c << endln;
00297 
00299         }
00300         else {
00301                 (*kickInTimes)(rvNumber-1) = (double)atof(argv[0]);
00302         }
00303 
00304         // The random variable number is returned as a parameter ID
00305         return param.addObject(rvNumber, this);
00306 }
00307 
00308 int
00309 DiscretizedRandomProcessSeries::updateParameter(int parameterID, Information &info)
00310 {
00311         // In case the vector doesn't exist
00312         if (randomVariables == 0) {
00313                 randomVariables = new Vector(parameterID);
00314                 (*randomVariables)(parameterID-1) = info.theDouble;
00315         }
00316         // In case the vector isn't big enough
00317         else if (randomVariables->Size() < parameterID) {
00318 
00319                 // Store old values in a temporary vector
00320                 Vector temp(*randomVariables);
00321 
00322                 // Create a large enough vector
00323                 delete randomVariables;
00324                 randomVariables = new Vector(parameterID);
00325 
00326                 // Put in old values
00327                 for (int i=0; i<temp.Size(); i++) {
00328                         (*randomVariables)(i) = temp(i);
00329                 }
00330 
00331                 // Put in new value
00332                 (*randomVariables)(parameterID-1) = info.theDouble;
00333         }
00334         else {
00335                 (*randomVariables)(parameterID-1) = info.theDouble;
00336         }
00337 
00338         return 0;
00339 }
00340 
00341 int
00342 DiscretizedRandomProcessSeries::activateParameter(int passedParameterID)
00343 {
00344         parameterID = passedParameterID;
00345 
00346         return 0;
00347 }

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