WeibullRV.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/03/04 00:44:37 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/domain/distributions/WeibullRV.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
00032 //
00033 
00034 #include <WeibullRV.h>
00035 #include <math.h>
00036 #include <string.h>
00037 #include <GammaRV.h>
00038 #include <classTags.h>
00039 #include <OPS_Globals.h>
00040 
00041 WeibullRV::WeibullRV(int passedTag, 
00042                  double passedMean,
00043                  double passedStdv,
00044                  double passedStartValue)
00045 :RandomVariable(passedTag, RANDOM_VARIABLE_weibull)
00046 {
00047         tag = passedTag;
00048         setParameters(passedMean,passedStdv);
00049         startValue = passedStartValue;
00050 }
00051 WeibullRV::WeibullRV(int passedTag, 
00052                  double passedParameter1,
00053                  double passedParameter2,
00054                  double passedParameter3,
00055                  double passedParameter4,
00056                  double passedStartValue)
00057 :RandomVariable(passedTag, RANDOM_VARIABLE_weibull)
00058 {
00059         tag = passedTag ;
00060         u = passedParameter1;
00061         k = passedParameter2;
00062         startValue = passedStartValue;
00063 }
00064 WeibullRV::WeibullRV(int passedTag, 
00065                  double passedMean,
00066                  double passedStdv)
00067 :RandomVariable(passedTag, RANDOM_VARIABLE_weibull)
00068 {
00069         tag = passedTag;
00070         setParameters(passedMean,passedStdv);
00071         startValue = getMean();
00072 }
00073 WeibullRV::WeibullRV(int passedTag, 
00074                  double passedParameter1,
00075                  double passedParameter2,
00076                  double passedParameter3,
00077                  double passedParameter4)
00078 :RandomVariable(passedTag, RANDOM_VARIABLE_weibull)
00079 {
00080         tag = passedTag ;
00081         u = passedParameter1;
00082         k = passedParameter2;
00083         startValue = getMean();
00084 }
00085 
00086 
00087 WeibullRV::~WeibullRV()
00088 {
00089 }
00090 
00091 
00092 void
00093 WeibullRV::Print(OPS_Stream &s, int flag)
00094 {
00095 }
00096 
00097 
00098 double
00099 WeibullRV::getPDFvalue(double rvValue)
00100 {
00101         double result;
00102         if ( 0.0 < rvValue) {
00103                 result = k/u * pow(rvValue/u,k-1) * exp(-pow(rvValue/u,k));
00104         }
00105         else {
00106                 result = 0.0;
00107         }
00108         return result;
00109 }
00110 
00111 
00112 double
00113 WeibullRV::getCDFvalue(double rvValue)
00114 {
00115         double result;
00116         if ( 0.0 < rvValue) {
00117                 result = 1 - exp(-pow(rvValue/u,k));
00118         }
00119         else {
00120                 result = 0.0;
00121         }
00122         return result;
00123 }
00124 
00125 
00126 double
00127 WeibullRV::getInverseCDFvalue(double probValue)
00128 {
00129         return u * pow((-log(1-probValue)),(1/k));
00130 }
00131 
00132 
00133 const char *
00134 WeibullRV::getType()
00135 {
00136         return "WEIBULL";
00137 }
00138 
00139 
00140 double 
00141 WeibullRV::getMean()
00142 {
00143         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00144         double result = u * aGammaRV->gammaFunction(1.0+1.0/k);
00145         delete aGammaRV;
00146         return result;
00147 }
00148 
00149 
00150 
00151 double 
00152 WeibullRV::getStdv()
00153 {
00154         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00155         double a = aGammaRV->gammaFunction(1.0+2.0/k);
00156         double b = aGammaRV->gammaFunction(1.0+1.0/k);
00157         delete aGammaRV;
00158         double result = u*sqrt(a-b*b);
00159         return result;
00160 }
00161 
00162 
00163 double 
00164 WeibullRV::getStartValue()
00165 {
00166         return startValue;
00167 }
00168 
00169 double WeibullRV::getParameter1()  {return u;}
00170 double WeibullRV::getParameter2()  {return k;}
00171 double WeibullRV::getParameter3()  {opserr<<"No such parameter in r.v. #"<<tag<<endln; return 0.0;}
00172 double WeibullRV::getParameter4()  {opserr<<"No such parameter in r.v. #"<<tag<<endln; return 0.0;}
00173 
00174 void
00175 WeibullRV::setParameters(double mean, double stdv)
00176 {
00177         double cov = stdv/mean;
00178         double xk = 0.0;
00179         function141(xk, cov,mean);
00180 }
00181 
00182 
00183 void
00184 WeibullRV::function141(double xk, double cov, double mean)
00185 {
00186         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00187         xk = xk + 1.0;
00188         double x1 = 1.0 + 1.0/xk;
00189         double x2 = 1.0 + 2.0/xk;
00190         double gm1 = aGammaRV->gammaFunction(x1);
00191         double gm2 = aGammaRV->gammaFunction(x2);
00192         delete aGammaRV;
00193         double vy = sqrt(gm2/gm1/gm1 - 1.0);
00194         if (cov-vy < 0.0) 
00195                 function141(xk,cov,mean);
00196         else if (cov-vy == 0.0) 
00197                 function144(xk,cov,mean);
00198         else 
00199                 function142(xk,cov,mean);
00200 }
00201 void
00202 WeibullRV::function142(double xk, double cov, double mean)
00203 {
00204         xk = xk - 0.1;
00205         double x1 = 1.0 + 1.0/xk;
00206         double x2 = 1.0 + 2.0/xk;
00207         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00208         double gm1 = aGammaRV->gammaFunction(x1);
00209         double gm2 = aGammaRV->gammaFunction(x2);
00210         delete aGammaRV;
00211         double vy = sqrt(gm2/gm1/gm1 - 1.0);
00212         if (cov-vy < 0.0) 
00213                 function143(xk,cov,mean);
00214         else if (cov-vy == 0.0) 
00215                 function144(xk,cov,mean);
00216         else 
00217                 function142(xk,cov,mean);
00218 }
00219 void
00220 WeibullRV::function143(double xk, double cov, double mean)
00221 {
00222         xk = xk + 0.01;
00223         double x1 = 1.0 + 1.0/xk;
00224         double x2 = 1.0 + 2.0/xk;
00225         GammaRV *aGammaRV = new GammaRV(1, 0.0, 1.0, 0.0);
00226         double gm1 = aGammaRV->gammaFunction(x1);
00227         double gm2 = aGammaRV->gammaFunction(x2);
00228         delete aGammaRV;
00229         double vy = sqrt(gm2/gm1/gm1 - 1.0);
00230         if (cov-vy < 0.0) 
00231                 function143(xk,cov,mean);
00232         else if (cov-vy == 0.0) 
00233                 function144(xk,cov,mean);
00234         else 
00235                 function144(xk,cov,mean);
00236 
00237 
00238 }
00239 void
00240 WeibullRV::function144(double xk, double gm1, double mean)
00241 {
00242         u = mean/gm1;
00243         k = xk;
00244 }

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