NatafProbabilityTransformation.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: 2004/01/22 01:56:47 $
00027 // $Source: /usr/local/cvs/OpenSees/SRC/reliability/analysis/transformation/NatafProbabilityTransformation.cpp,v $
00028 
00029 
00030 //
00031 // Written by Terje Haukaas (haukaas@ce.berkeley.edu)
00032 //
00033 
00034 #include <ProbabilityTransformation.h>
00035 #include <NatafProbabilityTransformation.h>
00036 #include <RandomVariable.h>
00037 #include <CorrelationCoefficient.h>
00038 #include <NormalRV.h>
00039 #include <Vector.h>
00040 #include <Matrix.h>
00041 #include <MatrixOperations.h>
00042 #include <math.h>
00043 #include <string.h>
00044 
00045 
00046 NatafProbabilityTransformation::NatafProbabilityTransformation(ReliabilityDomain *passedReliabilityDomain,
00047                                                                                          int passedPrintFlag)
00048 :ProbabilityTransformation()
00049 {
00050         theReliabilityDomain = passedReliabilityDomain;
00051         printFlag = passedPrintFlag;
00052 
00053 
00054         // Find and set problem size (number of random variables)
00055         nrv = theReliabilityDomain->getNumberOfRandomVariables();
00056 
00057 
00058         // Create/initialize vectors and matrices
00059         x = new Vector(nrv);
00060         u = new Vector(nrv);
00061         jacobian_x_u = new Matrix(nrv,nrv);
00062         jacobian_u_x = new Matrix(nrv,nrv);
00063         lowerCholesky = new Matrix(nrv,nrv);
00064         inverseLowerCholesky = new Matrix(nrv,nrv);
00065         correlationMatrix = new Matrix(nrv,nrv);
00066 
00067 
00068         // Establish correlation matrix according to the Nataf assumption
00069         setCorrelationMatrix(0, 0, 0.0);
00070 
00071 
00072         // Create object to do matrix operations on the correlation matrix
00073         theMatrixOperations = 0;
00074         theMatrixOperations = new MatrixOperations(*correlationMatrix);
00075         if (theMatrixOperations == 0) {
00076                 opserr << "NatafProbabilityTransformation::NatafProbabilityTransformation() - could " << endln
00077                         << " not create the object to perform matrix operations." << endln;
00078         }
00079 
00080 
00081         // Cholesky decomposition of correlation matrix
00082         int result = theMatrixOperations->computeCholeskyAndItsInverse();
00083         if (result < 0) {
00084                 opserr << "NatafProbabilityTransformation::NatafProbabilityTransformation() - could not" << endln
00085                         << " compute the Cholesky decomposition and its inverse " << endln
00086                         << " for the correlation matrix." << endln;
00087         }
00088         (*lowerCholesky) = theMatrixOperations->getLowerCholesky();
00089         (*inverseLowerCholesky) = theMatrixOperations->getInverseLowerCholesky();
00090 }
00091 
00092 NatafProbabilityTransformation::~NatafProbabilityTransformation()
00093 {
00094         if (correlationMatrix != 0) 
00095                 delete correlationMatrix;
00096         if (lowerCholesky != 0) 
00097                 delete lowerCholesky;
00098         if (inverseLowerCholesky != 0) 
00099                 delete inverseLowerCholesky;
00100         if (jacobian_x_u != 0) 
00101                 delete jacobian_x_u;
00102         if (jacobian_u_x != 0) 
00103                 delete jacobian_u_x;
00104         if (x != 0) 
00105                 delete x;
00106         if (u != 0) 
00107                 delete u;
00108         if (theMatrixOperations != 0) 
00109                 delete theMatrixOperations;
00110 }
00111 
00112 
00113 
00114 int 
00115 NatafProbabilityTransformation::set_x(Vector passedx)
00116 {
00117         (*x) = passedx; // (later: check size of vector, etc.)
00118         return 0;
00119 }
00120 
00121 int 
00122 NatafProbabilityTransformation::set_u(Vector passedu)
00123 {
00124         (*u) = passedu; // (later: check size of vector, etc.)
00125         return 0;
00126 }
00127 
00128 int 
00129 NatafProbabilityTransformation::transform_x_to_u()
00130 {
00131         Vector z = x_to_z(*x);
00132         (*u) = (*inverseLowerCholesky) * z;
00133         
00134         return 0;
00135 }
00136 
00137 
00138 Vector 
00139 NatafProbabilityTransformation::meanSensitivityOf_x_to_u(Vector &x, int rvNumber)
00140 {
00141         // Returns the sensitivity of 'u' with respect to [mean, stdv]
00142         // for the given random variable number (rvNumber)
00143 
00144         // Need four factors:
00145 
00146         // 1) (*inverseLowerCholesky)    DONE
00147 
00148         // 2) Vector z = x_to_z(x); 
00149         Vector z = x_to_z(x);
00150 
00151         // 3) DzDmean and DzDstdv = a vector of zeros and then:
00152         Vector DzDmean(x.Size());
00153         NormalRV aStandardNormalRV(1,0.0,1.0,0.0); 
00154         RandomVariable *theRV = theReliabilityDomain->getRandomVariablePtr(rvNumber);
00155         if (strcmp(theRV->getType(),"NORMAL")==0) {
00156                 double mu = theRV->getParameter1();
00157                 double sigma = theRV->getParameter2();
00158                 DzDmean(rvNumber-1) = -1.0 / sigma;
00159         }
00160         else if (strcmp(theRV->getType(),"LOGNORMAL")==0) {
00161                 double lambda = theRV->getParameter1();
00162                 double zeta = fabs(theRV->getParameter2()); // more here for negative lognormal?
00163                 double mean = fabs(theRV->getMean()); // more here for negative lognormal?
00164                 double stdv = theRV->getStdv();
00165 
00166                 double a = mean*mean+stdv*stdv;
00167                 DzDmean(rvNumber-1) = 0.5*(-2.0*mean*mean*log(a)+4.0*mean*mean*log(mean)-3.0*stdv*stdv*log(a)+4.0*stdv*stdv*log(mean)+2.0*stdv*stdv*log(fabs(x(rvNumber-1))))
00168                         /(pow(log(a)-2.0*log(mean),1.5)*mean*a);
00169                 
00170 //              double z = ( log ( fabs(x(rvNumber-1)) ) - lambda ) / zeta; // more here for negative lognormal?
00171 //              double e = (stdv/mean)*(stdv/mean);
00172 //              double d = 1 + e;
00173 //              double f = 1.0 / (mean*d*zeta);
00174 //              DzDmean(rvNumber-1) = f*(-d-e+e*z/zeta);
00175         }
00176         else if (strcmp(theRV->getType(),"UNIFORM")==0) {
00177                 double pz = 0.39894228048*exp(-z(rvNumber-1)*z(rvNumber-1)/2.0);
00178                 double a = theRV->getParameter1();
00179                 double b = theRV->getParameter2();
00180                 DzDmean(rvNumber-1) = -1.0/(pz*(b-a));
00181         }
00182         else {
00183                 opserr << "WARNING: Cannot compute reliability sensitivity results for " << endln
00184                         << " type of random variable number " << rvNumber << endln;
00185                 DzDmean(rvNumber-1) = 0.0; //aStandardNormalRV.getInverseCDFvalue(theRV->getCDFMeanSensitivity(x(rvNumber-1)));
00186         }
00187 
00188         // 4) The hardest part: DinverseLowerCholeskyDmean
00189         //                                              DinverseLowerCholeskyDstdv
00190         //    This is possible, but a bit tedious
00191         //    The procedure would be:
00192         //             R = L * L^T
00193         //            dR = dL* L^T + L * dL^T
00194         //            dR = dL* L^T + dL* L^T
00195         //            dR = 2 * dL* L^T
00196         //            dL = 0.5 * dR * L^(-T)
00197         //
00198         //    For now: do this by finite difference
00199         Matrix OrigInverseLowerCholesky = (*inverseLowerCholesky);
00200         RandomVariable *aRandomVariable;
00201         aRandomVariable = theReliabilityDomain->getRandomVariablePtr(rvNumber);
00202         double stdv = aRandomVariable->getStdv();
00203         double h = stdv/200.0;
00204         setCorrelationMatrix(rvNumber, 0, h);
00205 
00206         MatrixOperations someMatrixOperations(*correlationMatrix);
00207 
00208         int result = someMatrixOperations.computeCholeskyAndItsInverse();
00209         if (result < 0) {
00210                 opserr << "NatafProbabilityTransformation::NatafProbabilityTransformation() - could not" << endln
00211                         << " compute the Cholesky decomposition and its inverse " << endln
00212                         << " for the correlation matrix." << endln;
00213         }
00214         Matrix PerturbedInverseLowerCholesky = someMatrixOperations.getInverseLowerCholesky();
00215         Matrix DinverseLowerCholeskyDmean = (OrigInverseLowerCholesky - PerturbedInverseLowerCholesky) * (1/h);
00216         setCorrelationMatrix(0, 0, 0.0);
00217 
00218         // Return the final result (the four factors)
00219         return ( DinverseLowerCholeskyDmean * z + (*inverseLowerCholesky) * DzDmean );
00220 }
00221 
00222 
00223 
00224 Vector 
00225 NatafProbabilityTransformation::stdvSensitivityOf_x_to_u(Vector &x, int rvNumber)
00226 {
00227         // Returns the sensitivity of 'u' with respect to [mean, stdv]
00228         // for the given random variable number (rvNumber)
00229 
00230         // Need four factors:
00231 
00232         // 1) (*inverseLowerCholesky)    DONE
00233 
00234         // 2) Vector z = x_to_z(x); 
00235         Vector z = x_to_z(x);
00236 
00237         // 3) DzDmean and DzDstdv = a vector of zeros and then:
00238         Vector DzDstdv(x.Size());
00239         NormalRV aStandardNormalRV(1,0.0,1.0,0.0); 
00240         RandomVariable *theRV = theReliabilityDomain->getRandomVariablePtr(rvNumber);
00241         if (strcmp(theRV->getType(),"NORMAL")==0) {
00242                 double mu = theRV->getParameter1();
00243                 double sigma = theRV->getParameter2();
00244                 DzDstdv(rvNumber-1) = - (x(rvNumber-1)-mu) / (sigma*sigma);
00245         }
00246         else if (strcmp(theRV->getType(),"LOGNORMAL")==0) {
00247                 double lambda = theRV->getParameter1();
00248                 double zeta = fabs(theRV->getParameter2()); // more here for negative lognormal?
00249                 double mean = fabs(theRV->getMean()); // more here for negative lognormal?
00250                 double stdv = theRV->getStdv();
00251 
00252                 double a = mean*mean+stdv*stdv;
00253                 DzDstdv(rvNumber-1) = 0.5*stdv*(log(a)-2.0*log(fabs(x(rvNumber-1))))/(pow(log(a)-2.0*log(mean),1.5)*a);
00254                 
00255 //              double z = ( log ( fabs(x(rvNumber-1)) ) - lambda ) / zeta; // more here for negative lognormal?
00256 //              double e = (stdv/mean)*(stdv/mean);
00257 //              double d = 1 + e;
00258 //              double f = 1.0 / (mean*d*zeta);
00259 //              DzDstdv(rvNumber-1) = stdv*((1.0-z/zeta)*f/mean);
00260         }
00261         else if (strcmp(theRV->getType(),"UNIFORM")==0) {
00262                 double pz = 0.39894228048*exp(-z(rvNumber-1)*z(rvNumber-1)/2.0);
00263                 double a = theRV->getParameter1();
00264                 double b = theRV->getParameter2();
00265                 double DzDmean = -1.0/(pz*(b-a));
00266                 double e = -DzDmean/(b-a);
00267                 DzDstdv(rvNumber-1) = 1.732050807*(a+b-2.0*x(rvNumber-1))*e;
00268         }
00269         else {
00270                 opserr << "WARNING: Cannot compute reliability sensitivity results for " << endln
00271                         << " type of random variable number " << rvNumber << endln;
00272                 DzDstdv(rvNumber-1) = 0.0; //aStandardNormalRV.getInverseCDFvalue(theRV->getCDFStdvSensitivity(x(rvNumber-1)));
00273         }
00274 
00275         // 4) The hardest part: DinverseLowerCholeskyDmean
00276         //                                              DinverseLowerCholeskyDstdv
00277         //    This is possible, but a bit tedious
00278         //    The procedure would be:
00279         //             R = L * L^T
00280         //            dR = dL* L^T + L * dL^T
00281         //            dR = dL* L^T + dL* L^T
00282         //            dR = 2 * dL* L^T
00283         //            dL = 0.5 * dR * L^(-T)
00284         //
00285         //    For now: do this by finite difference
00286         Matrix OrigInverseLowerCholesky = (*inverseLowerCholesky);
00287         RandomVariable *aRandomVariable;
00288         aRandomVariable = theReliabilityDomain->getRandomVariablePtr(rvNumber);
00289         double stdv = aRandomVariable->getStdv();
00290         double h = stdv/200.0;
00291         setCorrelationMatrix(0, rvNumber, h);
00292 
00293         MatrixOperations someMatrixOperations(*correlationMatrix);
00294 
00295         int result = someMatrixOperations.computeCholeskyAndItsInverse();
00296         if (result < 0) {
00297                 opserr << "NatafProbabilityTransformation::NatafProbabilityTransformation() - could not" << endln
00298                         << " compute the Cholesky decomposition and its inverse " << endln
00299                         << " for the correlation matrix." << endln;
00300         }
00301         Matrix PerturbedInverseLowerCholesky = someMatrixOperations.getInverseLowerCholesky();
00302         Matrix DinverseLowerCholeskyDstdv = (OrigInverseLowerCholesky - PerturbedInverseLowerCholesky) * (1/h);
00303         setCorrelationMatrix(0, 0, 0.0);
00304 
00305         // Return the final result (the four factors)
00306         return ( DinverseLowerCholeskyDstdv * z + (*inverseLowerCholesky) * DzDstdv );
00307 }
00308 
00309 
00310 
00311 
00312 int 
00313 NatafProbabilityTransformation::transform_u_to_x()
00314 {
00315 
00316         Vector z = (*lowerCholesky) * (*u);
00317         (*x) = z_to_x(z);
00318 
00319 
00320         // If user has set print flag to '1' then print realization 
00321         if (printFlag == 1) {
00322                 RandomVariable *theRV;
00323                 double mean, stdv, dist; 
00324                 char theString[80];
00325                 sprintf(theString," CURRENT REALIZATION OF RANDOM VARIABLES:");
00326                 opserr << theString << endln;
00327                 for ( int i=0 ; i<nrv ; i++ )
00328                 {
00329                         theRV = theReliabilityDomain->getRandomVariablePtr(i+1);
00330                         mean = theRV->getMean();
00331                         stdv = theRV->getStdv();
00332                         dist = ((*x)(i)-mean)/stdv; 
00333                         sprintf(theString," x_%d: %5.2e (%5.2f standard deviations away from the mean)",(i+1),(*x)(i),dist);
00334                         opserr << theString << endln;
00335                 }
00336         }
00337 
00338         return 0;
00339 }
00340 
00341 
00342 int 
00343 NatafProbabilityTransformation::transform_u_to_x_andComputeJacobian()
00344 {
00345         Vector z = (*lowerCholesky) * (*u);
00346         (*x) = z_to_x(z);
00347 
00348 
00349         Matrix Jzx = getJacobian_z_x((*x),z);
00350         (*jacobian_u_x) = (*inverseLowerCholesky) * Jzx;
00351 
00352 
00353         int result = theMatrixOperations->setMatrix((*jacobian_u_x));
00354         if (result < 0) {
00355                 opserr << "NatafProbabilityTransformation::transform_u_to_x() - could not set " << endln
00356                         << " the matrix in the object to perform matrix operations." << endln;
00357                 return -1;
00358         }
00359         
00360         result = theMatrixOperations->computeInverse();
00361         if (result < 0) {
00362                 opserr << "NatafProbabilityTransformation::transform_u_to_x() - could not " << endln
00363                         << " invert Jacobian_u_x." << endln;
00364                 return -1;
00365         }
00366         (*jacobian_x_u) = theMatrixOperations->getInverse();
00367 
00368 
00369         // If user has set print flag to '1' then print realization 
00370         if (printFlag == 1) {
00371                 RandomVariable *theRV;
00372                 double mean, stdv, dist; 
00373                 char theString[80];
00374                 sprintf(theString," CURRENT REALIZATION OF RANDOM VARIABLES:");
00375                 opserr << theString << endln;
00376                 for ( int i=0 ; i<nrv ; i++ )
00377                 {
00378                         theRV = theReliabilityDomain->getRandomVariablePtr(i+1);
00379                         mean = theRV->getMean();
00380                         stdv = theRV->getStdv();
00381                         dist = ((*x)(i)-mean)/stdv; 
00382                         sprintf(theString," x_%d: %5.2e (%5.2f standard deviations away from the mean)",(i+1),(*x)(i),dist);
00383                         opserr << theString << endln;
00384                 }
00385         }
00386 
00387         return 0;
00388 }
00389 
00390 
00391 
00392 
00393 
00394 
00395 
00396 Vector 
00397 NatafProbabilityTransformation::get_x()
00398 {
00399         return (*x);
00400 }
00401 
00402 
00403 
00404 Vector 
00405 NatafProbabilityTransformation::get_u()
00406 {
00407         return (*u);
00408 }
00409 
00410 
00411 
00412 Matrix 
00413 NatafProbabilityTransformation::getJacobian_x_u()
00414 {
00415         return (*jacobian_x_u);
00416 }
00417 
00418 
00419 
00420 Matrix 
00421 NatafProbabilityTransformation::getJacobian_u_x()
00422 {
00423         return (*jacobian_u_x);
00424 }
00425 
00426 
00427 
00428 
00429 
00430 
00431 
00432 Matrix
00433 NatafProbabilityTransformation::getJacobian_z_x(Vector x, Vector z)
00434 {       
00435         RandomVariable *theRV;
00436         NormalRV aStandardNormalRV(1, 0.0, 1.0, 0.0);
00437         Matrix jacobianMatrix_z_x(nrv,nrv);
00438         for ( int i=0 ; i<nrv ; i++ )
00439         {
00440                 theRV = theReliabilityDomain->getRandomVariablePtr(i+1);
00441                 if (strcmp(theRV->getType(),"NORMAL")==0) {
00442                         double sigma = theRV->getParameter2();
00443                         jacobianMatrix_z_x(i,i) = 1.0 / sigma;
00444                 }
00445                 else if (strcmp(theRV->getType(),"LOGNORMAL")==0) {
00446                         double zeta = fabs(theRV->getParameter2());
00447                         if (x(i) == 0.0) {
00448                                 opserr << "NatafProbabilityTransformation::getJacobian_z_x() -- Error: value " << endln
00449                                     << "of lognormal random variable is zero in original space. " << endln;
00450                         }
00451                         jacobianMatrix_z_x(i,i) = 1.0 / ( zeta * x(i)  );
00452                 }
00453                 else {
00454                         double pdf = aStandardNormalRV.getPDFvalue(z(i));
00455                         if (pdf == 0.0) {
00456                                 opserr << "ERROR: NatafProbabilityTransformation::getJacobian_z_x() -- " << endln
00457                                         << " the PDF value is zero, probably due to too large step. " << endln;
00458                         }
00459                         jacobianMatrix_z_x(i,i) = theRV->getPDFvalue(x(i)) / pdf;
00460                         if (jacobianMatrix_z_x(i,i)==0.0) {
00461                         }
00462                 }
00463         }
00464 
00465         return jacobianMatrix_z_x;
00466 }
00467 
00468 
00469 
00470 
00471 Vector
00472 NatafProbabilityTransformation::z_to_x(Vector z)
00473 {
00474         RandomVariable *theRV;
00475         NormalRV aStandardNormalRV(1, 0.0, 1.0, 0.0);
00476         Vector x(nrv);
00477         for ( int i=0 ; i<nrv ; i++ )
00478         {
00479                 theRV = theReliabilityDomain->getRandomVariablePtr(i+1);
00480                 if (strcmp(theRV->getType(),"NORMAL")==0) {
00481                         double mju = theRV->getParameter1();
00482                         double sigma = theRV->getParameter2();
00483                         x(i) = z(i) * sigma + mju;
00484                 }
00485                 else if (strcmp(theRV->getType(),"LOGNORMAL")==0) {
00486                         double lambda = theRV->getParameter1();
00487                         double zeta = theRV->getParameter2();
00488                         if (zeta < 0.0) { // interpret this as negative lognormal random variable
00489                                 x(i) = -exp ( -z(i) * zeta + lambda );
00490                         }
00491                         else {
00492                                 x(i) = exp ( z(i) * zeta + lambda );
00493                         }
00494                 }
00495                 else {
00496                         x(i) = theRV->getInverseCDFvalue(  aStandardNormalRV.getCDFvalue(z(i))  );
00497                 }
00498         }
00499         return x;
00500 }
00501 
00502 
00503 
00504 
00505 
00506 Vector
00507 NatafProbabilityTransformation::x_to_z(Vector x)
00508 {
00509         RandomVariable *theRV;
00510         NormalRV aStandardNormalRV(1, 0.0, 1.0, 0.0);
00511         Vector z(nrv);
00512         for ( int i=0 ; i<nrv ; i++ )
00513         {
00514                 theRV = theReliabilityDomain->getRandomVariablePtr(i+1);
00515                 if (strcmp(theRV->getType(),"NORMAL")==0) {
00516                         double mju = theRV->getParameter1();
00517                         double sigma = theRV->getParameter2();
00518                         z(i) =   ( x(i) - mju ) / sigma;
00519                 }
00520                 else if (strcmp(theRV->getType(),"LOGNORMAL")==0) {
00521                         double lambda = theRV->getParameter1();
00522                         double zeta = theRV->getParameter2();
00523                         if (zeta < 0.0) { 
00524                                 z(i) = -( log ( fabs(x(i)) ) - lambda ) / zeta;
00525                         }
00526                         else {
00527                                 z(i) = ( log ( x(i) ) - lambda ) / zeta;
00528                         }
00529                 }
00530                 else {
00531                         z(i) = aStandardNormalRV.getInverseCDFvalue(theRV->getCDFvalue(x(i)));
00532                 }
00533         }
00534         return z;
00535 }
00536 
00537 
00538 
00539 
00540 
00541 
00542 
00543 
00544 
00545 
00546 
00547 
00548 
00549 void
00550 NatafProbabilityTransformation::setCorrelationMatrix(int pertMeanOfThisRV, int pertStdvOfThisRV, double h)
00551 {
00552         // Initial declarations
00553         int rv1;
00554         int rv2;
00555         RandomVariable *rv1Ptr;
00556         RandomVariable *rv2Ptr;
00557         double correlation;
00558         double newCorrelation;
00559 
00560         // Initialize correlation matrix
00561         correlationMatrix->Zero();
00562 
00563         // Put 'ones' on the diagonal
00564         for ( int i=0 ; i<nrv ; i++ )
00565         {
00566                 (*correlationMatrix)(i,i) = 1.0;
00567         }
00568 
00569         // Get number of correlation coefficients
00570         int numberOfCorrelationCoefficients = 
00571                 theReliabilityDomain->getNumberOfCorrelationCoefficients();
00572 
00573         // Modify each coefficient at a time and put it into the correlation matrix
00574         for ( int j=1 ; j<=numberOfCorrelationCoefficients ; j++ )
00575         {
00576                 // Get a pointer to the correlation coefficient with tag 'j'
00577                 CorrelationCoefficient *theCorrelationCoefficient = 
00578                         theReliabilityDomain->getCorrelationCoefficientPtr(j);
00579 
00580                 // Get tags for the two involved random variables
00581                 rv1 = theCorrelationCoefficient->getRv1();
00582                 rv2 = theCorrelationCoefficient->getRv2();
00583 
00584                 // Get value of the correlation
00585                 correlation = theCorrelationCoefficient->getCorrelation();
00586 
00587                 // Get pointers to the two random variables
00588                 rv1Ptr = theReliabilityDomain->getRandomVariablePtr(rv1);
00589                 rv2Ptr = theReliabilityDomain->getRandomVariablePtr(rv2);
00590 
00591                 // Get the types of the two random variables
00592                 const char *typeRv1 = rv1Ptr->getType();
00593                 const char *typeRv2 = rv2Ptr->getType();
00594 
00595                 // Compute the coefficient of variation of the random variables
00596                 if (rv1Ptr->getMean() == 0.0  ||  rv2Ptr->getMean() == 0.0 ) {
00597                         opserr << "WARNING: The Nataf-transformation is currently implemented " << endln
00598                                 << " with the assumption of non-zero mean. " << endln;
00599                 }
00600                 double cov1 = rv1Ptr->getStdv() / rv1Ptr->getMean();
00601                 double cov2 = rv2Ptr->getStdv() / rv2Ptr->getMean();
00602 
00603 
00604                 // Handle negative lognormal random variables
00605                 // (is the closed form expressions correct for these?)
00606                 if ( strcmp(typeRv1,"LOGNORMAL") == 0 ) {
00607                         if (cov1 < 0.0) {
00608                                 cov1 = cov1;
00609                         }
00610                 }
00611                 if ( strcmp(typeRv2,"LOGNORMAL") == 0 ) {
00612                         if (cov2 < 0.0) {
00613                                 cov2 = cov2;
00614                         }
00615                 }
00616 
00617                 // Handle mean/stdv reliability sensitivities
00618                 // (used in finite difference schemes to obtain derivative
00619                 //  of Cholesky decomposition)
00620                 if (pertMeanOfThisRV !=0) {
00621                         if (pertMeanOfThisRV == rv1) {
00622                                 cov1 = rv1Ptr->getStdv() / (rv1Ptr->getMean()+h);
00623                         }
00624                         else if (pertMeanOfThisRV == rv2) {
00625                                 cov2 = rv2Ptr->getStdv() / (rv2Ptr->getMean()+h);
00626                         }
00627                 }
00628                 else if (pertStdvOfThisRV !=0) {
00629                         if (pertStdvOfThisRV == rv1) {
00630                                 cov1 = (rv1Ptr->getStdv()+h) / rv1Ptr->getMean();
00631                         }
00632                         else if (pertStdvOfThisRV == rv2) {
00633                                 cov2 = (rv2Ptr->getStdv()+h) / rv2Ptr->getMean();
00634                         }
00635                 }
00636 
00637                 // Modify the correlation coefficient according to 
00638                 // the type of the the two involved random variables
00639 
00641                 if ( strcmp(typeRv1,"USERDEFINED") == 0  ||  strcmp(typeRv2,"USERDEFINED") == 0  ) {
00642                         opserr << " ... modifying correlation rho("<<rv1<<","<<rv2<<") for user-defined random variable..." << endln;
00643                         newCorrelation = solveForCorrelation(rv1, rv2, correlation);
00644                         opserr << " ... computed correlation for Nataf standard normal variates: " << newCorrelation << endln;
00645                 }
00646                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
00647                         newCorrelation = correlation;
00648                 }
00649                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
00650                         double zeta2 = sqrt ( log ( 1.0 + cov2 * cov2 ) );
00651                         newCorrelation = correlation * cov2 / zeta2;
00652                 }
00653                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
00654                         newCorrelation = (1.001 - 0.007 * cov2 + 0.118 * cov2 * cov2) * correlation;
00655                 }
00656                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
00657                         newCorrelation = 1.107 * correlation;
00658                 }
00659                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
00660                         newCorrelation = 1.014 * correlation;
00661                 }
00662                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
00663                         newCorrelation = 1.023 * correlation;
00664                 }
00665                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  strcmp(typeRv2,"BETA") == 0  ) {
00666                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
00667                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
00668                         double s2 = rv2Ptr->getStdv() / ba;
00669                         newCorrelation = (1.026 + 0.001*correlation - 0.178*u2
00670                                 + 0.268*s2 - 0.001*correlation*correlation
00671                                 + 0.178*u2*u2 - 0.679*s2*s2 - 0.003*s2*correlation)  *  correlation;
00672                 }
00673                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
00674                         newCorrelation = 1.031 * correlation;
00675                 }
00676                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
00677                         newCorrelation = 1.031 * correlation;
00678                 }
00679                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
00680                         newCorrelation = (1.030 + 0.238*cov2 + 0.364*cov2*cov2) * correlation;
00681                 }
00682                 else if ( strcmp(typeRv1,"NORMAL") == 0  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
00683                         newCorrelation = (1.031 - 0.195*cov2 + 0.328*cov2*cov2) * correlation;
00684                 }
00686                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
00687                         double zeta1 = sqrt ( log ( 1 + pow ( cov1 , 2 ) ) );
00688                         newCorrelation = correlation * cov1 / zeta1;
00689                 }
00690                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
00691                         double zeta1 = sqrt ( log ( 1.0 + cov1*cov1 ) );
00692                         double zeta2 = sqrt ( log ( 1.0 + cov2*cov2 ) );
00693                         newCorrelation = 1.0 / ( zeta1 * zeta2 ) * log ( 1 + correlation * cov1 * cov2 );
00694                 }
00695                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
00696                         double temp = 1.001 + 0.033*correlation + 0.004*cov1 - 0.016*cov2 
00697                                 + 0.002*correlation*correlation + 0.223*cov1*cov1 + 0.0130*cov2*cov2;
00698                         newCorrelation = correlation * (temp - 0.104*correlation*cov1 + 0.029*cov1*cov2 - 0.119*correlation*cov2);
00699                 }
00700                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
00701                         newCorrelation = (1.098 + 0.003*correlation + 0.019*cov1 + 0.025*correlation*correlation
00702                                 + 0.303*cov1*cov1 - 0.437*correlation*cov1) * correlation;
00703                 }
00704                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
00705                         newCorrelation = (1.011 + 0.001*correlation + 0.014*cov1 + 0.004*correlation*correlation 
00706                                 + 0.231*cov1*cov1 - 0.130*correlation*cov1) * correlation;
00707                 }
00708                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
00709                         newCorrelation = (1.019 + 0.014*cov1 + 0.010*correlation*correlation + 0.249*cov1*cov1)*correlation;
00710                 }
00711                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  strcmp(typeRv2,"BETA") == 0  ) {
00712                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
00713                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
00714                         double s2 = rv2Ptr->getStdv() / ba;
00715                         double uu = u2*u2;
00716                         double ss = s2*s2;
00717                         double xu = correlation * u2;
00718                         double xs = correlation * s2;
00719                         double us = u2*s2;
00720                         double up = u2*cov1;
00721                         double sp = s2 * cov1;
00722                         double temp = 0.979 + 0.053*correlation + 0.181*u2 + 0.293*s2 + 0.002*cov1
00723                                 - 0.004*correlation*correlation - 0.181*uu + 5.796*ss + 0.277*cov1*cov1 - 0.107*xu
00724                                 - 0.619*xs - 0.190*correlation*cov1 - 3.976*us - 0.097*up + 0.133*sp
00725                                 - 14.402*ss*s2 - 0.069*cov1*cov1*cov1
00726                                 + 0.031*correlation*xs + 0.015*correlation*correlation*cov1
00727                                 + 3.976*uu*s2 + 0.097*uu*cov1 - 0.430*ss*cov1
00728                                 + 0.113*sp*cov1 + 1.239*correlation*us + 0.380*correlation*up;
00729                         newCorrelation = temp * correlation;
00730                 }
00731                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
00732                         newCorrelation = (1.029 + 0.001*correlation + 0.014*cov1 + 0.004*correlation*correlation
00733                                 + 0.233*cov1*cov1 - 0.197*correlation*cov1)*correlation;
00734                 }
00735                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
00736                         newCorrelation = (1.029 - 0.001*correlation + 0.014*cov1 + 0.004*correlation*correlation
00737                                 + 0.233*cov1*cov1 + 0.197*correlation*cov1) * correlation;
00738                 }
00739                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
00740                         double temp = 1.026 + 0.082*correlation - 0.019*cov1 + 0.222*cov2 + 0.018*correlation*correlation
00741                                 + 0.288*cov1*cov1 + 0.379*cov2*cov2;
00742                         newCorrelation = (temp - 0.441*correlation*cov1 + 0.126*cov1*cov2 - 0.277*correlation*cov2);
00743                 }
00744                 else if ( strcmp(typeRv1,"LOGNORMAL") == 0  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
00745                         double temp = 1.031+0.052*correlation+0.011*cov1-0.210*cov2+0.002*correlation*correlation+0.220*cov1*cov1+0.350*cov2*cov2;
00746                         newCorrelation = (temp+0.005*correlation*cov1+0.009*cov1*cov2-0.174*correlation*cov2)*correlation;
00747                 }
00749                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
00750                         newCorrelation = (1.001 - 0.007 * cov1 + 0.118 * cov1 * cov1) * correlation;
00751                 }
00752                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
00753                         double temp = 1.001 + 0.033*correlation + 0.004*cov2 - 0.016*cov1 
00754                                 + 0.002*correlation*correlation + 0.223*cov2*cov2 + 0.0130*cov1*cov1;
00755                         newCorrelation = correlation * (temp - 0.104*correlation*cov2 + 0.029*cov2*cov1 - 0.119*correlation*cov1);
00756                 }
00757                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
00758                         double temp = 1.002+0.022*correlation-0.012*(cov1+cov2)+0.001*correlation*correlation+0.125*(cov1*cov1+cov2*cov2);
00759                         newCorrelation = (temp-0.077*(correlation*cov1+correlation*cov2)+0.014*cov1*cov2)*correlation;
00760                 }
00761                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
00762                         newCorrelation = (1.104+0.003*correlation-0.008*cov1+0.014*correlation*correlation+0.173*cov1*cov1-0.296*correlation*cov1)*correlation;
00763                 }
00764                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
00765                         newCorrelation = (1.014+0.001*correlation-0.007*cov1+0.002*correlation*correlation+0.126*cov1*cov1-0.090*correlation*cov1)*correlation;
00766                 }
00767                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
00768                         newCorrelation = (1.023+0.000*correlation-0.007*cov1+0.002*correlation*correlation+0.127*cov1*cov1-0.000*correlation*cov1)*correlation;
00769                 }
00770                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  strcmp(typeRv2,"BETA") == 0  ) {
00771                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
00772                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
00773                         double s2 = rv2Ptr->getStdv() / ba;
00774                         double uu=u2*u2;
00775                         double ss=s2*s2;
00776                         double xu=correlation*u2;
00777                         double xs=correlation*s2;
00778                         double us=u2*s2;
00779                         double up=u2*cov1;
00780                         double sp=s2*cov1;
00781                         double temp;
00782                         double xp=correlation*cov1;
00783                         if(correlation > 0.0) {
00784                                 temp = 0.931+0.050*correlation+0.366*u2+0.549*s2+0.181*cov1
00785                                 -0.055*correlation*correlation-0.515*uu+4.804*ss-0.484*cov1*cov1-0.064*xu
00786                                 -0.637*xs+0.032*xp-4.059*us-0.319*up-0.211*sp
00787                                 +0.052*correlation*correlation*correlation+0.227*uu*u2-10.220*ss*s2+0.559*cov1*cov1*cov1-0.042*correlation*xu
00788                                 +0.223*correlation*xs-0.172*correlation*xp+0.028*correlation*uu+0.695*correlation*ss+0.126*correlation*cov1*cov1
00789                                 +3.845*uu*s2+0.019*uu*cov1-1.244*us*s2+0.008*up*cov1-2.075*ss*cov1
00790                                 +0.167*sp*cov1+0.666*correlation*us+0.386*correlation*up-0.517*correlation*sp+2.125*us*cov1;
00791                         }
00792                         else {
00793                                 temp = 1.025+0.050*correlation-0.029*u2+0.047*s2-0.136*cov1
00794                                 +0.069*correlation*correlation+0.178*uu+6.281*ss+0.548*cov1*cov1-0.027*xu
00795                                 -0.686*xs+0.046*xp-3.513*us+0.231*up+0.299*sp
00796                                 +0.063*correlation*correlation*correlation-0.226*uu*u2-17.507*ss*s2-0.366*cov1*cov1*cov1+0.051*correlation*xu
00797                                 -0.246*correlation*xs+0.186*correlation*xp-0.001*correlation*uu+0.984*correlation*ss+0.121*correlation*cov1*cov1
00798                                 +3.700*uu*s2+0.081*uu*cov1+1.356*us*s2+0.002*up*cov1+1.654*ss*cov1
00799                                 -0.135*sp*cov1+0.619*correlation*us+0.410*correlation*up-0.686*correlation*sp-2.205*us*cov1;
00800                         }
00801                         newCorrelation = temp*correlation;
00802                 }
00803                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
00804                         newCorrelation = (1.031+0.001*correlation-0.007*cov1+0.003*correlation*correlation+0.131*cov1*cov1-0.132*correlation*cov1)*correlation;
00805                 }
00806                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
00807                         newCorrelation = (1.031-0.001*correlation-0.007*cov1+0.003*correlation*correlation+0.131*cov1*cov1+0.132*correlation*cov1)*correlation;
00808                 }
00809                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
00810                         double temp = 1.029+0.056*correlation-0.030*cov1+0.225*cov2+0.012*correlation*correlation+0.174*cov1*cov1+0.379*cov2*cov2;
00811                         newCorrelation = (temp-0.313*correlation*cov1+0.075*cov1*cov2-0.182*correlation*cov2)*correlation;
00812                 }
00813                 else if ( strcmp(typeRv1,"GAMMA") == 0  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
00814                         double temp = 1.032+0.034*correlation-0.007*cov1-0.202*cov2+0.000*correlation*correlation+0.121*cov1*cov1+0.339*cov2*cov2;
00815                         newCorrelation = (temp-0.006*correlation*cov1+0.003*cov1*cov2-0.111*correlation*cov2)*correlation;
00816                 }
00818                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
00819                         newCorrelation = 1.107 * correlation;
00820                 }
00821                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
00822                         newCorrelation = (1.098 + 0.003*correlation + 0.019*cov2 + 0.025*correlation*correlation
00823                                 + 0.303*cov2*cov2 - 0.437*correlation*cov2) * correlation;
00824                 }
00825                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
00826                         newCorrelation = (1.104+0.003*correlation-0.008*cov2+0.014*correlation*correlation+0.173*cov2*cov2-0.296*correlation*cov2)*correlation;
00827                 }
00828                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
00829                         newCorrelation = (1.229-0.367*correlation+0.153*correlation*correlation)*correlation;
00830                 }
00831                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
00832                         newCorrelation = (1.123-0.100*correlation+0.021*correlation*correlation)*correlation;
00833                 }
00834                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
00835                         newCorrelation = (1.133+0.029*correlation*correlation)*correlation;
00836                 }
00837                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  strcmp(typeRv2,"BETA") == 0  ) {
00838                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
00839                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
00840                         double s2 = rv2Ptr->getStdv() / ba;
00841                         double uu=u2*u2;
00842                         double ss=s2*s2;
00843                         double xu=correlation*u2;
00844                         double xs=correlation*s2;
00845                         double us=u2*s2;
00846                         double temp = 1.082-0.004*correlation+0.204*u2+0.432*s2-0.001*correlation*correlation
00847                                 - 0.204*uu+7.728*ss+0.008*xu-1.699*xs-5.338*us
00848                                 - 19.741*ss*s2+0.135*correlation*xs+5.338*uu*s2+3.397*correlation*us;
00849                         newCorrelation = temp*correlation;
00850                 }
00851                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
00852                         newCorrelation = (1.142-0.154*correlation+0.031*correlation*correlation)*correlation;
00853                 }
00854                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
00855                         newCorrelation = (1.142+0.154*correlation+0.031*correlation*correlation)*correlation;
00856                 }
00857                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
00858                         newCorrelation = (1.109-0.152*correlation+0.361*cov2+0.130*correlation*correlation+0.455*cov2*cov2-0.728*correlation*cov2)*correlation;
00859                 }
00860                 else if ( (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 )  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
00861                         newCorrelation = (1.147+0.145*correlation-0.271*cov2+0.010*correlation*correlation+0.459*cov2*cov2-0.467*correlation*cov2)*correlation;
00862                 }
00864                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
00865                         newCorrelation = 1.014 * correlation;
00866                 }
00867                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
00868                         newCorrelation = (1.011 + 0.001*correlation + 0.014*cov2 + 0.004*correlation*correlation 
00869                                 + 0.231*cov2*cov2 - 0.130*correlation*cov2) * correlation;
00870                 }
00871                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
00872                         newCorrelation = (1.014+0.001*correlation-0.007*cov2+0.002*correlation*correlation+0.126*cov2*cov2-0.090*correlation*cov2)*correlation;
00873                 }
00874                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
00875                         newCorrelation = (1.123-0.100*correlation+0.021*correlation*correlation)*correlation;
00876                 }
00877                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
00878                         newCorrelation = (1.028-0.029*correlation)*correlation;
00879                 }
00880                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
00881                         newCorrelation = (1.038-0.008*correlation*correlation)*correlation;
00882                 }
00883                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  strcmp(typeRv2,"BETA") == 0  ) {
00884                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
00885                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
00886                         double s2 = rv2Ptr->getStdv() / ba;
00887                         double temp = 1.037-0.042*correlation-0.182*u2+0.369*s2-0.001*correlation*correlation
00888                                 +0.182*u2*u2-1.150*s2*s2+0.084*correlation*u2;
00889                         newCorrelation = temp*correlation;
00890                 }
00891                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
00892                         newCorrelation = (1.046-0.045*correlation+0.006*correlation*correlation)*correlation;
00893                 }
00894                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
00895                         newCorrelation = (1.046+0.045*correlation+0.006*correlation*correlation)*correlation;
00896                 }
00897                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
00898                         newCorrelation = (1.036-0.038*correlation+0.266*cov2+0.028*correlation*correlation+0.383*cov2*cov2-0.229*correlation*cov2)*correlation;
00899                 }
00900                 else if ( (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 )  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
00901                         newCorrelation = (1.047+0.042*correlation-0.212*cov2+0.353*cov2*cov2-0.136*correlation*cov2)*correlation;
00902                 }
00904                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
00905                         newCorrelation = 1.023 * correlation;
00906                 }
00907                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
00908                         newCorrelation = (1.019 + 0.014*cov2 + 0.010*correlation*correlation + 0.249*cov2*cov2)*correlation;
00909                 }
00910                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
00911                         newCorrelation = (1.023+0.000*correlation-0.007*cov2+0.002*correlation*correlation+0.127*cov2*cov2-0.000*correlation*cov2)*correlation;
00912                 }
00913                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
00914                         newCorrelation = (1.133+0.029*correlation*correlation)*correlation;
00915                 }
00916                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
00917                         newCorrelation = (1.038-0.008*correlation*correlation)*correlation;
00918                 }
00919                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
00920                         newCorrelation = (1.047-0.047*correlation*correlation)*correlation;
00921                 }
00922                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  strcmp(typeRv2,"BETA") == 0  ) {
00923                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
00924                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
00925                         double s2 = rv2Ptr->getStdv() / ba;
00926                         double temp = 1.040+0.015*correlation-0.176*u2+0.432*s2-0.008*correlation*correlation
00927                                 +0.176*u2*u2-1.286*s2*s2-0.137*correlation*s2;
00928                         newCorrelation = temp * correlation;
00929                 }
00930                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
00931                         newCorrelation = (1.055+0.015*correlation*correlation)*correlation;
00932                 }
00933                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
00934                         newCorrelation = (1.055+0.015*correlation*correlation)*correlation;
00935                 }
00936                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
00937                         newCorrelation = (1.033+0.305*cov2+0.074*correlation*correlation+0.405*cov2*cov2)*correlation;
00938                 }
00939                 else if ( strcmp(typeRv1,"UNIFORM") == 0  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
00940                         newCorrelation = (1.061-0.237*cov2-0.005*correlation*correlation+0.379*cov2*cov2)*correlation;
00941                 }
00943                 else if ( strcmp(typeRv1,"BETA") == 0  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
00944                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
00945                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
00946                         double s1 = rv1Ptr->getStdv() / ba;
00947                         newCorrelation = (1.026 + 0.001*correlation - 0.178*u1
00948                                 + 0.268*s1 - 0.001*correlation*correlation
00949                                 + 0.178*u1*u1 - 0.679*s1*s1 - 0.003*s1*correlation)  *  correlation;
00950 
00951                 }
00952                 else if ( strcmp(typeRv1,"BETA") == 0  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
00953                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
00954                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
00955                         double s1 = rv1Ptr->getStdv() / ba;
00956                         double uu = u1*u1;
00957                         double ss = s1*s1;
00958                         double xu = correlation * u1;
00959                         double xs = correlation * s1;
00960                         double us = u1*s1;
00961                         double up = u1*cov2;
00962                         double sp = s1 * cov2;
00963                         double temp = 0.979 + 0.053*correlation + 0.181*u1 + 0.293*s1 + 0.002*cov2
00964                                 - 0.004*correlation*correlation - 0.181*uu + 5.796*ss + 0.277*cov2*cov2 - 0.107*xu
00965                                 - 0.619*xs - 0.190*correlation*cov2 - 3.976*us - 0.097*up + 0.133*sp
00966                                 - 14.402*ss*s1 - 0.069*cov2*cov2*cov2
00967                                 + 0.031*correlation*xs + 0.015*correlation*correlation*cov2
00968                                 + 3.976*uu*s1 + 0.097*uu*cov2 - 0.430*ss*cov2
00969                                 + 0.113*sp*cov2 + 1.239*correlation*us + 0.380*correlation*up;
00970                         newCorrelation = temp * correlation;
00971 
00972                 }
00973                 else if ( strcmp(typeRv1,"BETA") == 0  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
00974                         double ba2 = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
00975                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba2; 
00976                         double s2 = rv2Ptr->getStdv() / ba2;
00977                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
00978                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
00979                         double s1 = rv1Ptr->getStdv() / ba;
00980                         double uu=u1*u1;
00981                         double ss=s1*s1;
00982                         double xu=correlation*u1;
00983                         double xs=correlation*s1;
00984                         double us=u1*s1;
00985                         double up=u1*cov2;
00986                         double sp=s1*cov2;
00987                         double temp;
00988                         double xp=correlation*cov2;
00989                         if(correlation > 0.0) {
00990                                 temp = 0.931+0.050*correlation+0.366*u1+0.549*s1+0.181*cov2
00991                                 -0.055*correlation*correlation-0.515*uu+4.804*ss-0.484*cov2*cov2-0.064*xu
00992                                 -0.637*xs+0.032*xp-4.059*us-0.319*up-0.211*sp
00993                                 +0.052*correlation*correlation*correlation+0.227*uu*u2-10.220*ss*s2+0.559*cov2*cov2*cov2-0.042*correlation*xu
00994                                 +0.223*correlation*xs-0.172*correlation*xp+0.028*correlation*uu+0.695*correlation*ss+0.126*correlation*cov2*cov2
00995                                 +3.845*uu*s2+0.019*uu*cov2-1.244*us*s1+0.008*up*cov2-2.075*ss*cov2
00996                                 +0.167*sp*cov2+0.666*correlation*us+0.386*correlation*up-0.517*correlation*sp+2.125*us*cov2;
00997                         }
00998                         else {
00999                                 temp = 1.025+0.050*correlation-0.029*u1+0.047*s1-0.136*cov2
01000                                 +0.069*correlation*correlation+0.178*uu+6.281*ss+0.548*cov2*cov2-0.027*xu
01001                                 -0.686*xs+0.046*xp-3.513*us+0.231*up+0.299*sp
01002                                 +0.063*correlation*correlation*correlation-0.226*uu*u1-17.507*ss*s2-0.366*cov2*cov2*cov2+0.051*correlation*xu
01003                                 -0.246*correlation*xs+0.186*correlation*xp-0.001*correlation*uu+0.984*correlation*ss+0.121*correlation*cov2*cov2
01004                                 +3.700*uu*s1+0.081*uu*cov2+1.356*us*s1+0.002*up*cov2+1.654*ss*cov2
01005                                 -0.135*sp*cov2+0.619*correlation*us+0.410*correlation*up-0.686*correlation*sp-2.205*us*cov2;
01006                         }
01007                         newCorrelation = temp*correlation;
01008 
01009                 }
01010                 else if ( strcmp(typeRv1,"BETA") == 0  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
01011                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01012                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
01013                         double s1 = rv1Ptr->getStdv() / ba;
01014                         double ba2 = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
01015                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba2; 
01016                         double s2 = rv2Ptr->getStdv() / ba2;
01017                         double uu=u1*u1;
01018                         double ss=s1*s1;
01019                         double xu=correlation*u1;
01020                         double xs=correlation*s1;
01021                         double us=u1*s1;
01022                         double temp = 1.082-0.004*correlation+0.204*u1+0.432*s1-0.001*correlation*correlation
01023                                 - 0.204*uu+7.728*ss+0.008*xu-1.699*xs-5.338*us
01024                                 - 19.741*ss*s2+0.135*correlation*xs+5.338*uu*s1+3.397*correlation*us;
01025                         newCorrelation = temp*correlation;
01026 
01027                 }
01028                 else if ( strcmp(typeRv1,"BETA") == 0  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
01029                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01030                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
01031                         double s1 = rv1Ptr->getStdv() / ba;
01032                         double temp = 1.037-0.042*correlation-0.182*u1+0.369*s1-0.001*correlation*correlation
01033                                 +0.182*u1*u1-1.150*s1*s1+0.084*correlation*u1;
01034                         newCorrelation = temp*correlation;
01035                 }
01036                 else if ( strcmp(typeRv1,"BETA") == 0  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
01037                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01038                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
01039                         double s1 = rv1Ptr->getStdv() / ba;
01040                         double temp = 1.040+0.015*correlation-0.176*u1+0.432*s1-0.008*correlation*correlation
01041                                 +0.176*u1*u1-1.286*s1*s1-0.137*correlation*s1;
01042                         newCorrelation = temp * correlation;
01043                 }
01044                 else if ( strcmp(typeRv1,"BETA") == 0  &&  strcmp(typeRv2,"BETA") == 0  ) {
01045                         double ba1 = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01046                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba1; 
01047                         double s1 = rv1Ptr->getStdv() / ba1;
01048                         double ba2 = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
01049                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba2; 
01050                         double s2 = rv2Ptr->getStdv() / ba2;
01051                         double o=u1;
01052                         double p=s1;
01053                         double q=u2;
01054                         double r=s2;
01055                         double u=o+q;
01056                         double s=p+r;
01057                         double oo=o*o;
01058                         double pp=p*cov1;
01059                         double qq=q*q;
01060                         double rr=r*r;
01061                         double oq=o*q;
01062                         double pr=p*r;
01063                         double us=oo+cov2*cov2;
01064                         double ss=cov1*cov1+rr;
01065                         double uc=oo*o+cov2*cov2*q;
01066                         double sc=cov1*cov1*cov1+rr*r;
01067                         double x=correlation;
01068                         double xx=correlation*correlation;
01069                         double temp;
01070                         if(correlation > 0.0) {
01071                                 temp =1.030-0.050*x-0.056*u+0.094*s+0.009*xx-0.084*us+2.583*ss
01072                                         +0.100*x*u+0.010*x*s-0.485*u*s+0.270*oq-0.688*pr-0.011*xx*x
01073                                         +0.024*uc-10.786*sc+0.013*xx*u-0.035*xx*s+0.001*x*us-0.069*x*ss
01074                                         +1.174*us*s+0.004*oq*u+0.227*ss*u+2.783*pr*s+0.058*x*s*u
01075                                         -0.260*x*oq-0.352*x*pr-1.609*oq*s+0.194*pr*u;
01076                         }
01077                         else {
01078                                 temp=0.939-0.023*x+0.147*u+0.668*s+0.035*xx-0.008*us+3.146*ss
01079                                         +0.103*x*u-0.126*x*s-1.866*u*s-0.268*oq-0.304*pr+0.011*xx*x
01080                                         -0.024*uc-10.836*sc-0.013*xx*u-0.035*xx*s-0.001*x*us+0.069*x*ss
01081                                         +1.175*us*s-0.005*oq*u-0.270*ss*u+2.781*pr*s+0.058*x*u*s
01082                                         -0.259*x*oq+0.352*x*pr+1.608*oq*s-0.189*pr*u;
01083                         }
01084                         newCorrelation = temp * correlation;
01085                 }
01086                 else if ( strcmp(typeRv1,"BETA") == 0  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
01087                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01088                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
01089                         double s1 = rv1Ptr->getStdv() / ba;
01090                         double temp = 1.055-0.066*correlation-0.194*u1+0.391*s1+0.003*correlation*correlation
01091                                 +0.194*u1*u1-1.134*s1*s1+0.130*correlation*u1+0.003*correlation*s1;
01092                         newCorrelation = temp * correlation;
01093                 }
01094                 else if ( strcmp(typeRv1,"BETA") == 0  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
01095                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01096                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
01097                         double s1 = rv1Ptr->getStdv() / ba;
01098                         double temp = 1.055+0.066*correlation-0.194*u1+0.391*s1+0.003*correlation*correlation
01099                                 +0.194*u1*u1-1.134*s1*s1-0.130*correlation*u1-0.003*correlation*s1;
01100                         newCorrelation = temp * correlation;
01101                 }
01102                 else if ( strcmp(typeRv1,"BETA") == 0  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
01103                         double ba1 = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01104                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba1; 
01105                         double s1 = rv1Ptr->getStdv() / ba1;
01106                         double uu=u1*u1;
01107                         double ss=s1*s1;
01108                         double xu=correlation*u1;
01109                         double xs=correlation*s1;
01110                         double us=u1*s1;
01111                         double uq=u1*cov2;
01112                         double sq=s1*cov2;
01113                         double xq=correlation*cov2;
01114                         double temp=1.005 + 0.091*correlation + 0.285*u1+ 0.260*s1+ 0.199*cov2
01115                                 - 0.023*correlation*correlation - 0.285*uu + 8.180*ss + 0.543*cov2*cov2 - 0.181*xu
01116                                 - 1.744*xs - 0.336*xq - 5.450*us - 0.265*uq + 0.514*sq
01117                                 -19.661*ss*s1- 0.178*cov2*cov2*cov2
01118                                 + 0.244*correlation*xs + 0.066*correlation*correlation*cov2 - 0.001*correlation*ss
01119                                 + 5.450*uu*s1+ 0.265*uu*cov2 - 0.986*ss*cov2
01120                                 + 0.133*sq*cov2 + 3.488*correlation*us + 0.671*correlation*uq;
01121                         newCorrelation = temp * correlation;
01122                 }
01123                 else if ( strcmp(typeRv1,"BETA") == 0  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
01124                         double ba = rv1Ptr->getParameter4() - rv1Ptr->getParameter3();
01125                         double u1 = ( rv1Ptr->getMean() - rv1Ptr->getParameter3() ) / ba; 
01126                         double s1 = rv1Ptr->getStdv() / ba;
01127                         double temp = 1.054+0.002*correlation-0.176*u1+0.366*s1-0.201*cov2
01128                                 -0.002*correlation*correlation+0.176*u1*u1-1.098*s1*s1+0.340*cov2*cov2
01129                                 -0.004*correlation*u1-0.029*s1*cov2;
01130                         newCorrelation = temp * correlation;
01131                 }
01133                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
01134                         newCorrelation = 1.031 * correlation;
01135                 }
01136                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
01137                         newCorrelation = (1.029 + 0.001*correlation + 0.014*cov2 + 0.004*correlation*correlation
01138                                 + 0.233*cov2*cov2 - 0.197*correlation*cov2)*correlation;
01139                 }
01140                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
01141                         newCorrelation = (1.031+0.001*correlation-0.007*cov2+0.003*correlation*correlation+0.131*cov2*cov2-0.132*correlation*cov2)*correlation;
01142                 }
01143                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
01144                         newCorrelation = (1.142-0.154*correlation+0.031*correlation*correlation)*correlation;
01145                 }
01146                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
01147                         newCorrelation = (1.046-0.045*correlation+0.006*correlation*correlation)*correlation;
01148                 }
01149                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
01150                         newCorrelation = (1.055+0.015*correlation*correlation)*correlation;
01151                 }
01152                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  strcmp(typeRv2,"BETA") == 0  ) {
01153                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
01154                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
01155                         double s2 = rv2Ptr->getStdv() / ba;
01156                         double temp = 1.055-0.066*correlation-0.194*u2+0.391*s2+0.003*correlation*correlation
01157                                 +0.194*u2*u2-1.134*s2*s2+0.130*correlation*u2+0.003*correlation*s2;
01158                         newCorrelation = temp * correlation;
01159                 }
01160                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
01161                         newCorrelation = (1.064-0.069*correlation+0.005*correlation*correlation)*correlation;
01162                 }
01163                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
01164                         newCorrelation = (1.064+0.069*correlation+0.005*correlation*correlation)*correlation;
01165                 }
01166                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
01167                         newCorrelation = (1.056-0.060*correlation+0.263*cov2+0.020*correlation*correlation+0.383*cov2*cov2-0.332*correlation*cov1)*correlation;
01168                 }
01169                 else if ( (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
01170                         newCorrelation = (1.064+0.065*correlation-0.210*cov2+0.003*correlation*correlation+0.356*cov2*cov2-0.211*correlation*cov2)*correlation;
01171                 }
01173                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
01174                         newCorrelation = 1.031 * correlation;
01175                 }
01176                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
01177                         newCorrelation = (1.029 - 0.001*correlation + 0.014*cov2 + 0.004*correlation*correlation
01178                                 + 0.233*cov2*cov2 + 0.197*correlation*cov2) * correlation;
01179                 }
01180                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
01181                         newCorrelation = (1.031-0.001*correlation-0.007*cov2+0.003*correlation*correlation+0.131*cov2*cov2+0.132*correlation*cov2)*correlation;
01182                 }
01183                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
01184                         newCorrelation = (1.142+0.154*correlation+0.031*correlation*correlation)*correlation;
01185                 }
01186                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
01187                         newCorrelation = (1.046+0.045*correlation+0.006*correlation*correlation)*correlation;
01188                 }
01189                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
01190                         newCorrelation = (1.055+0.015*correlation*correlation)*correlation;
01191                 }
01192                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  strcmp(typeRv2,"BETA") == 0  ) {
01193                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
01194                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
01195                         double s2 = rv2Ptr->getStdv() / ba;
01196                         double temp = 1.055+0.066*correlation-0.194*u2+0.391*s2+0.003*correlation*correlation
01197                                 +0.194*u2*u2-1.134*s2*s2-0.130*correlation*u2-0.003*correlation*s2;
01198                         newCorrelation = temp * correlation;
01199                 }
01200                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
01201                         newCorrelation = (1.064+0.069*correlation+0.005*correlation*correlation)*correlation;
01202                 }
01203                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
01204                         newCorrelation = (1.064-0.069*correlation+0.005*correlation*correlation)*correlation;
01205                 }
01206                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
01207                         newCorrelation = (1.056+0.060*correlation+0.263*cov2+0.020*correlation*correlation+0.383*cov2*cov2+0.332*correlation*cov2)*correlation;
01208                 }
01209                 else if ( strcmp(typeRv1,"TYPE1SMALLESTVALAUE") == 0  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
01210                         newCorrelation = (1.064-0.065*correlation-0.210*cov2+0.003*correlation*correlation+0.356*cov2*cov2+0.211*correlation*cov2)*correlation;
01211                 }
01213                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
01214                         newCorrelation = (1.030 + 0.238*cov1 + 0.364*cov1*cov1) * correlation;
01215                 }
01216                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
01217                         double temp = 1.026 + 0.082*correlation - 0.019*cov2 + 0.222*cov1 + 0.018*correlation*correlation
01218                                 + 0.288*cov2*cov2 + 0.379*cov1*cov1;
01219                         newCorrelation = (temp - 0.441*correlation*cov2 + 0.126*cov2*cov1 - 0.277*correlation*cov1);            
01220                 }
01221                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
01222                         double temp = 1.029+0.056*correlation-0.030*cov2+0.225*cov1+0.012*correlation*correlation+0.174*cov2*cov2+0.379*cov1*cov1;
01223                         newCorrelation = (temp-0.313*correlation*cov2+0.075*cov1*cov2-0.182*correlation*cov1)*correlation;
01224                 }
01225                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
01226                         newCorrelation = (1.109-0.152*correlation+0.361*cov1+0.130*correlation*correlation+0.455*cov1*cov1-0.728*correlation*cov1)*correlation;
01227                 }
01228                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
01229                         newCorrelation = (1.036-0.038*correlation+0.266*cov1+0.028*correlation*correlation+0.383*cov1*cov1-0.229*correlation*cov1)*correlation;
01230                 }
01231                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
01232                         newCorrelation = (1.033+0.305*cov1+0.074*correlation*correlation+0.405*cov1*cov1)*correlation;
01233                 }
01234                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  strcmp(typeRv2,"BETA") == 0  ) {
01235                         double ba2 = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
01236                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba2; 
01237                         double s2 = rv2Ptr->getStdv() / ba2;
01238                         double uu=u2*u2;
01239                         double ss=s2*s2;
01240                         double xu=correlation*u2;
01241                         double xs=correlation*s2;
01242                         double us=u2*s2;
01243                         double uq=u2*cov1;
01244                         double sq=s2*cov1;
01245                         double xq=correlation*cov1;
01246                         double temp=1.005 + 0.091*correlation + 0.285*u2+ 0.260*s2+ 0.199*cov1
01247                                 - 0.023*correlation*correlation - 0.285*uu + 8.180*ss + 0.543*cov1*cov1 - 0.181*xu
01248                                 - 1.744*xs - 0.336*xq - 5.450*us - 0.265*uq + 0.514*sq
01249                                 -19.661*ss*s2- 0.178*cov1*cov1*cov1
01250                                 + 0.244*correlation*xs + 0.066*correlation*correlation*cov1 - 0.001*correlation*ss
01251                                 + 5.450*uu*s2+ 0.265*uu*cov1 - 0.986*ss*cov1
01252                                 + 0.133*sq*cov1 + 3.488*correlation*us + 0.671*correlation*uq;
01253                         newCorrelation = temp * correlation;
01254                 }
01255                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
01256                         newCorrelation = (1.056-0.060*correlation+0.263*cov1+0.020*correlation*correlation+0.383*cov1*cov1-0.332*correlation*cov1)*correlation;
01257                 }
01258                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
01259                         newCorrelation = (1.056+0.060*correlation+0.263*cov1+0.020*correlation*correlation+0.383*cov1*cov1+0.332*correlation*cov1)*correlation;
01260                 }
01261                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
01262                         double rs=cov1*cov1+cov2*cov2;
01263                         double rc=cov1*cov1*cov1+cov2*cov2*cov2;
01264                         double r=cov1+cov2;
01265                         double pq=cov1*cov2;
01266                         double temp=1.086+0.054*correlation+0.104*r-0.055*correlation*correlation+0.662*rs-0.570*correlation*r+0.203*pq;
01267                         newCorrelation = (temp-0.020*correlation*correlation*correlation-0.218*rc-0.371*correlation*rs+0.257*correlation*correlation*r+0.141*pq*r)*correlation;
01268                 }
01269                 else if ( strcmp(typeRv1,"TYPE2LARGESTVALUE") == 0  &&  (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0) ) {
01270                         double temp = 1.065+0.146*correlation+0.241*cov1-0.259*cov2+0.013*correlation*correlation+0.372*cov1*cov1+0.435*cov2*cov2;
01271                         newCorrelation = (temp+0.005*correlation*cov1+0.034*cov1*cov2-0.481*correlation*cov2)*correlation;
01272                 }
01274                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  strcmp(typeRv2,"NORMAL") == 0  ) {
01275                         newCorrelation = (1.031 - 0.195*cov1 + 0.328*cov1*cov1) * correlation;
01276                 }
01277                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  strcmp(typeRv2,"LOGNORMAL") == 0  ) {
01278                         double temp = 1.031+0.052*correlation+0.011*cov2-0.210*cov1+0.002*correlation*correlation+0.220*cov2*cov2+0.350*cov1*cov1;
01279                         newCorrelation = (temp+0.005*correlation*cov2+0.009*cov2*cov1-0.174*correlation*cov1)*correlation;
01280                 }
01281                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  strcmp(typeRv2,"GAMMA") == 0  ) {
01282                         double temp = 1.032+0.034*correlation-0.007*cov2-0.202*cov1+0.000*correlation*correlation+0.121*cov2*cov2+0.339*cov1*cov1;
01283                         newCorrelation = (temp-0.006*correlation*cov2+0.003*cov2*cov1-0.111*correlation*cov1)*correlation;
01284                 }
01285                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  (strcmp(typeRv2,"EXPONENTIAL") == 0 || strcmp(typeRv2,"SHIFTEDEXPONENTIAL") == 0 ) ) {
01286                         newCorrelation = (1.147+0.145*correlation-0.271*cov1+0.010*correlation*correlation+0.459*cov1*cov1-0.467*correlation*cov1)*correlation;
01287                 }
01288                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  (strcmp(typeRv2,"RAYLEIGH") == 0 || strcmp(typeRv2,"SHIFTEDRAYLEIGH") == 0 ) ) {
01289                         newCorrelation = (1.047+0.042*correlation-0.212*cov1+0.353*cov1*cov1-0.136*correlation*cov1)*correlation;
01290                 }
01291                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  strcmp(typeRv2,"UNIFORM") == 0  ) {
01292                         newCorrelation = (1.061-0.237*cov1-0.005*correlation*correlation+0.379*cov1*cov1)*correlation;
01293                 }
01294                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  strcmp(typeRv2,"BETA") == 0  ) {
01295                         double ba = rv2Ptr->getParameter4() - rv2Ptr->getParameter3();
01296                         double u2 = ( rv2Ptr->getMean() - rv2Ptr->getParameter3() ) / ba; 
01297                         double s2 = rv2Ptr->getStdv() / ba;
01298                         double temp = 1.054+0.002*correlation-0.176*u2+0.366*s2-0.201*cov1
01299                                 -0.002*correlation*correlation+0.176*u2*u2-1.098*s2*s2+0.340*cov1*cov1
01300                                 -0.004*correlation*u2-0.029*s2*cov1;
01301                         newCorrelation = temp * correlation;
01302                 }
01303                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  (strcmp(typeRv2,"TYPE1LARGESTVALUE") == 0 || strcmp(typeRv2,"GUMBEL") == 0)  ) {
01304                         newCorrelation = (1.064+0.065*correlation-0.210*cov1+0.003*correlation*correlation+0.356*cov1*cov1-0.211*correlation*cov1)*correlation;
01305                 }
01306                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  strcmp(typeRv2,"TYPE1SMALLESTVALAUE") == 0  ) {
01307                         newCorrelation = (1.064-0.065*correlation-0.210*cov1+0.003*correlation*correlation+0.356*cov1*cov1+0.211*correlation*cov1)*correlation;
01308                 }
01309                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  strcmp(typeRv2,"TYPE2LARGESTVALUE") == 0  ) {
01310                         double temp = 1.065+0.146*correlation+0.241*cov2-0.259*cov1+0.013*correlation*correlation+0.372*cov2*cov2+0.435*cov1*cov1;
01311                         newCorrelation = (temp+0.005*correlation*cov2+0.034*cov1*cov2-0.481*correlation*cov1)*correlation;
01312                 }
01313 #ifndef _WIN32
01314                 // VC++.net has a limit of 128 on number of nested conditionals!!!!!!!!
01315                 else if ( (strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0 || strcmp(typeRv2,"WEIBULL") == 0)  &&  ( strcmp(typeRv2,"TYPE3SMALLESTVALUE") == 0  || strcmp(typeRv2,"WEIBULL") == 0 ) ) {
01316                         double temp = 1.063-0.004*correlation-0.200*(cov1+cov2)-0.001*correlation*correlation+0.337*(cov1*cov1+cov2*cov2);
01317                         newCorrelation = (temp+0.007*(correlation*cov1+correlation*cov2)-0.007*cov1*cov2)*correlation;
01318                 }
01319 #endif
01321                 else {
01322                         opserr << "Did not find the given combination of distributions in CorrelationModifier" << endln;
01323                 }
01324 
01325                 if(newCorrelation > 1.0) {
01326                         newCorrelation = 0.999999999;
01327                 }
01328                 if(newCorrelation < -1.0) {
01329                         newCorrelation = -0.999999999;
01330                 }
01331                 
01332                 
01333                 // Put the coefficient into the correlation matrix
01334                 (*correlationMatrix)( ( rv1-1 ) , ( rv2-1 ) ) = newCorrelation;
01335                 (*correlationMatrix)( ( rv2-1 ) , ( rv1-1 ) ) = newCorrelation;
01336         }
01337 
01338         // Here the correlation matrix should be checked for validity
01339         // (Whether it is close to singular or not)
01340         
01341 
01342 }
01343 
01344 
01345 
01346 
01347 
01348 
01349 double
01350 NatafProbabilityTransformation::phi2(double z_i, 
01351                                                                          double z_j,
01352                                                                          double rho)
01353 {
01354         double par = z_i*z_i + z_j*z_j - 2.0*rho*z_i*z_j;
01355 
01356         double theExp = exp(-par/(2.0*(1.0-rho*rho)));
01357 
01358         double pi = 3.14159265358979;
01359 
01360         double result = theExp/(2.0*pi*sqrt(1.0-rho*rho));
01361 
01362         return result;
01363 }
01364 
01365 
01366 
01367 double
01368 NatafProbabilityTransformation::integrand(int rv_i,
01369                                                                                   double z_i, 
01370                                                                                   double mean_i,
01371                                                                                   double stdv_i, 
01372                                                                                   int rv_j,
01373                                                                                   double z_j,
01374                                                                                   double mean_j, 
01375                                                                                   double stdv_j,
01376                                                                                   double rho)
01377 {
01378         RandomVariable *theRv_i = theReliabilityDomain->getRandomVariablePtr(rv_i);
01379         RandomVariable *theRv_j = theReliabilityDomain->getRandomVariablePtr(rv_j);
01380         NormalRV aStandardNormalRV(1,0.0,1.0,0.0); 
01381 
01382         double x_i = theRv_i->getInverseCDFvalue(aStandardNormalRV.getCDFvalue(z_i));
01383         double x_j = theRv_j->getInverseCDFvalue(aStandardNormalRV.getCDFvalue(z_j));
01384 
01385         double thePhi2 = phi2(z_i, z_j, rho);
01386 
01387         return ( (x_i-mean_i)/stdv_i 
01388                    * (x_j-mean_j)/stdv_j 
01389                    * thePhi2 );
01390 }
01391 
01392 
01393 double
01394 NatafProbabilityTransformation::doubleIntegral(int rv_i,
01395                                                                                   double mean_i,
01396                                                                                   double stdv_i, 
01397                                                                                   int rv_j,
01398                                                                                   double mean_j, 
01399                                                                                   double stdv_j,
01400                                                                                   double rho)
01401 {
01402         // The grid of integration points:
01403         // 1, 2, ..., i, ..., 2*n  in x-direction with intervals h
01404         // 1, 2, ..., j, ..., 2*m  in y-direction with intervals k
01405         int i, j;
01406         
01407 
01408         // Selected integration boundaries
01409         double z_i0 = -5.0;
01410         double z_in =  5.0;
01411         double z_j0 = -5.0;
01412         double z_jm =  5.0;
01413 
01414         // Half the number of integration points
01415         int n = 100;
01416         int m = 100;
01417         
01418         // Integration point intervals
01419         double h = (z_in-z_i0)/(2.0*n);
01420         double k = (z_jm-z_j0)/(2.0*m);
01421 
01422         // Grid of integration points
01423         Vector z_i(2.0*n);
01424         Vector z_j(2.0*m);
01425         for (i=1; i<=2*n; i++) {
01426                 z_i(i-1) = z_i0 + (i-1)*h;
01427         }
01428         for (j=1; j<=2*m; j++) {
01429                 z_j(j-1) = z_j0 + (j-1)*k;
01430         }
01431 
01432         // Computing sums (naming terms according to p. 126 in "Numerical Methods" by Faires & Burden)
01433         double term1 = 0.0;
01434         double term2 = 0.0;
01435         double term3 = 0.0;
01436         double term4 = 0.0;
01437         double term5 = 0.0;
01438         double term6 = 0.0;
01439         double term7 = 0.0;
01440         double term8 = 0.0;
01441         double term9 = 0.0;
01442         double term10 = 0.0;
01443         double term11 = 0.0;
01444         double term12 = 0.0;
01445         double term13 = 0.0;
01446         double term14 = 0.0;
01447         double term15 = 0.0;
01448         double term16 = 0.0;
01449 
01450         // No sum terms
01451         term1 = integrand( rv_i, z_i( 0        ) , mean_i, stdv_i, 
01452                                    rv_j, z_j( 0        ) , mean_j, stdv_j, rho);
01453         term4 = integrand( rv_i, z_i( 2*n    -1) , mean_i, stdv_i, 
01454                                    rv_j, z_j( 0        ) , mean_j, stdv_j, rho);
01455         term13 = integrand(rv_i, z_i( 0        ) , mean_i, stdv_i, 
01456                                    rv_j, z_j( 2*m    -1) , mean_j, stdv_j, rho);
01457         term16 = integrand(rv_i, z_i( 2*n    -1) , mean_i, stdv_i, 
01458                                    rv_j, z_j( 2*m    -1) , mean_j, stdv_j, rho);
01459 
01460         // Single sum over n terms
01461         for (i=1; i<=n; i++) {
01462                 term2 += integrand(rv_i, z_i( 2*i    -1) , mean_i, stdv_i, 
01463                                        rv_j, z_j( 0        ) , mean_j, stdv_j, rho);
01464                 term3 += integrand(rv_i, z_i( 2*i-1  -1) , mean_i, stdv_i, 
01465                                        rv_j, z_j( 0        ) , mean_j, stdv_j, rho);
01466                 term14 += integrand(rv_i, z_i( 2*i    -1) , mean_i, stdv_i, 
01467                                         rv_j, z_j( 2*m    -1) , mean_j, stdv_j, rho);
01468                 term15 += integrand(rv_i, z_i( 2*i-1    -1) , mean_i, stdv_i, 
01469                                         rv_j, z_j( 2*m      -1) , mean_j, stdv_j, rho);
01470         }
01471         term2 -= integrand(rv_i, z_i( 2*n  -1) , mean_i, stdv_i, 
01472                                    rv_j, z_j( 0      ) , mean_j, stdv_j, rho);
01473         term14 -= integrand(rv_i, z_i( 2*n    -1) , mean_i, stdv_i, 
01474                                 rv_j, z_j( 2*m    -1) , mean_j, stdv_j, rho);
01475 
01476         // Single sum over m terms
01477         for (j=1; j<=m; j++) {
01478                 term5 += integrand(rv_i, z_i( 0        ) , mean_i, stdv_i, 
01479                                        rv_j, z_j( 2*j    -1) , mean_j, stdv_j, rho);
01480                 term8 += integrand(rv_i, z_i( 2*n    -1) , mean_i, stdv_i, 
01481                                        rv_j, z_j( 2*j    -1) , mean_j, stdv_j, rho);
01482                 term9 += integrand(rv_i, z_i( 0          ) , mean_i, stdv_i, 
01483                                        rv_j, z_j( 2*j-1    -1) , mean_j, stdv_j, rho);
01484                 term12 += integrand(rv_i, z_i( 2*n     -1) , mean_i, stdv_i, 
01485                                         rv_j, z_j( 2*j-1   -1) , mean_j, stdv_j, rho);
01486         }
01487         term8 -= integrand(rv_i, z_i( 2*n    -1) , mean_i, stdv_i, 
01488                                rv_j, z_j( 2*m    -1) , mean_j, stdv_j, rho);
01489         
01490         // Double sum terms
01491         for (j=1; j<=(m-1); j++) {
01492                 for (i=1; i<=(n-1); i++) {
01493                         term6 += integrand(rv_i, z_i( 2*i    -1) , mean_i, stdv_i, 
01494                                                            rv_j, z_j( 2*j    -1) , mean_j, stdv_j, rho);
01495                 }
01496         }
01497         for (j=1; j<=(m-1); j++) {
01498                 for (i=1; i<=(n); i++) {
01499                         term7 += integrand(rv_i, z_i( 2*i-1    -1) , mean_i, stdv_i, 
01500                                                            rv_j, z_j( 2*j      -1) , mean_j, stdv_j, rho);
01501                 }
01502         }
01503         for (j=1; j<=(m); j++) {
01504                 for (i=1; i<=(n-1); i++) {
01505                         term10 += integrand(rv_i, z_i( 2*i       -1) , mean_i, stdv_i, 
01506                                                             rv_j, z_j( 2*j-1     -1) , mean_j, stdv_j, rho);
01507                 }
01508         }
01509         for (j=1; j<=(m); j++) {
01510                 for (i=1; i<=(n); i++) {
01511                         term11 += integrand(rv_i, z_i( 2*i-1     -1) , mean_i, stdv_i, 
01512                                                             rv_j, z_j( 2*j-1     -1) , mean_j, stdv_j, rho);
01513                 }
01514         }
01515 
01516 
01517         double par1 = term1 + 2.0*term2 + 4.0*term3 + term4;
01518         
01519         double par2 = term5 + 2.0*term6 + 4.0*term7 + term8;
01520 
01521         double par3 = term9 + 2.0*term10 + 4.0*term11 + term12;
01522 
01523         double par4 = term13 + 2.0*term14 + 4.0*term15 + term16;
01524 
01525         double result = h*k/9.0 * (par1 + 2.0*par2 + 4.0*par3 + par4);
01526 
01527         return result;
01528 }
01529 
01530 
01531 
01532 double
01533 NatafProbabilityTransformation::residualFunction(double rho_original, 
01534                                                                                                  double rho,
01535                                                                                                  double rv_i, 
01536                                                                                                  double mean_i, 
01537                                                                                                  double stdv_i, 
01538                                                                                                  double rv_j, 
01539                                                                                                  double mean_j, 
01540                                                                                                  double stdv_j)
01541 {
01542         double result = rho_original - doubleIntegral(rv_i, mean_i, stdv_i, rv_j, mean_j, stdv_j, rho);
01543 
01544         return result;
01545 }
01546 
01547 
01548 
01549 
01550 double
01551 NatafProbabilityTransformation::solveForCorrelation(int rv_i, int rv_j, double rho_original)
01552 {
01553         RandomVariable *theRv_i = theReliabilityDomain->getRandomVariablePtr(rv_i);
01554         RandomVariable *theRv_j = theReliabilityDomain->getRandomVariablePtr(rv_j);
01555 
01556         double mean_i = theRv_i->getMean();
01557         double mean_j = theRv_j->getMean();
01558 
01559         double stdv_i = theRv_i->getStdv();
01560         double stdv_j = theRv_j->getStdv();
01561 
01562         double result = 0.0;
01563 
01564         double tol = 1.0e-6;
01565         double pert = 1.0e-4;
01566 
01567         double rho_old = rho_original;
01568         double rho_new;
01569         double f;
01570         double df;
01571         double perturbed_f;
01572 
01573         for (int i=1;  i<=100;  i++ )  {
01574 
01575                 // Evaluate function
01576                 f = residualFunction(rho_original,
01577                                          rho_old,
01578                                                          rv_i, mean_i, stdv_i, 
01579                                                          rv_j, mean_j, stdv_j);
01580 
01581                 // Evaluate perturbed function
01582                 perturbed_f = residualFunction(rho_original,
01583                                                                            (rho_old+pert),
01584                                                                            rv_i, mean_i, stdv_i, 
01585                                                                            rv_j, mean_j, stdv_j);
01586 
01587                 // Evaluate derivative of function
01588                 df = ( perturbed_f - f ) / pert;
01589 
01590                 if ( fabs(df) < 1.0e-15) {
01591                         opserr << "WARNING: NatafProbabilityTransformation::solveForCorrelation() -- " << endln
01592                                 << " zero derivative in Newton algorithm. " << endln;
01593                 }
01594                 else {
01595 
01596                         // Take a Newton step
01597                         rho_new = rho_old - f/df;
01598                         
01599                         // Check convergence; quit or continue
01600                         if (fabs(1.0-fabs(rho_old/rho_new)) < tol) {
01601                                 result = rho_new;
01602                                 return result;
01603                         }
01604                         else {
01605                                 if (i==100) {
01606                                         opserr << "WARNING: NatafProbabilityTransformation::solveForCorrelation() -- " << endln
01607                                                 << " Newton scheme did not converge. " << endln;
01608                                         result = 0.0;
01609                                         return result;
01610                                 }
01611                                 else {
01612                                         rho_old = rho_new;
01613                                 }
01614                         
01615                         }
01616                 }
01617         }
01618 
01619         return result;
01620 
01621 }
01622 
01623 
01624 
01625 
01626 
01627 
01628 
01629 
01630 
01631 
01632 
01633 
01634 

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