Subversion Repositories OpenSees

Rev

Rev 4695 | Rev 4891 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
291 mhscott 1
/* ****************************************************************** **
2
**    OpenSees - Open System for Earthquake Engineering Simulation    **
3
**          Pacific Earthquake Engineering Research Center            **
4
**                                                                    **
5
**                                                                    **
6
** (C) Copyright 2001, The Regents of the University of California    **
7
** All Rights Reserved.                                               **
8
**                                                                    **
9
** Commercial use of this program without express permission of the   **
10
** University of California, Berkeley, is strictly prohibited.  See   **
11
** file 'COPYRIGHT'  in main directory for information on usage and   **
12
** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
13
**                                                                    **
14
** Developed by:                                                      **
15
**   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
16
**   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
17
**   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
18
**                                                                    **
19
** Reliability module developed by:                                   **
20
**   Terje Haukaas (haukaas@ce.berkeley.edu)                          **
21
**   Armen Der Kiureghian (adk@ce.berkeley.edu)                       **
22
**                                                                    **
23
** ****************************************************************** */
24
 
3607 mhscott 25
// $Revision: 1.18 $
26
// $Date: 2008-08-27 17:12:23 $
291 mhscott 27
// $Source: /usr/local/cvs/OpenSees/SRC/reliability/analysis/analysis/FORMAnalysis.cpp,v $
28
 
29
 
30
//
1333 fmk 31
// Written by Terje Haukaas (haukaas@ce.berkeley.edu)
291 mhscott 32
//
33
 
34
#include <FORMAnalysis.h>
1333 fmk 35
#include <FindDesignPointAlgorithm.h>
291 mhscott 36
#include <ReliabilityDomain.h>
37
#include <ReliabilityAnalysis.h>
38
#include <Vector.h>
39
#include <Matrix.h>
40
#include <MatrixOperations.h>
41
#include <NormalRV.h>
42
#include <RandomVariable.h>
43
#include <math.h>
1333 fmk 44
#include <ProbabilityTransformation.h>
291 mhscott 45
 
3172 mhscott 46
#include <RandomVariableIter.h>
47
#include <LimitStateFunctionIter.h>
48
 
1333 fmk 49
#include <fstream>
50
#include <iomanip>
51
#include <iostream>
52
using std::ifstream;
53
using std::ios;
54
using std::setw;
55
using std::setprecision;
56
using std::setiosflags;
57
 
58
 
59
FORMAnalysis::FORMAnalysis(ReliabilityDomain *passedReliabilityDomain,
60
                                                   FindDesignPointAlgorithm *passedFindDesignPointAlgorithm,
61
                                                   ProbabilityTransformation *passedProbabilityTransformation,
3124 mhscott 62
                                                   Tcl_Interp *passedInterp, TCL_Char *passedFileName, int p_relSensTag)
291 mhscott 63
:ReliabilityAnalysis()
64
{
65
        theReliabilityDomain = passedReliabilityDomain;
1333 fmk 66
        theFindDesignPointAlgorithm = passedFindDesignPointAlgorithm;
67
        theProbabilityTransformation = passedProbabilityTransformation;
68
        strcpy(fileName,passedFileName);
69
        relSensTag = p_relSensTag;
3124 mhscott 70
        interp = passedInterp;
291 mhscott 71
}
72
 
73
 
74
FORMAnalysis::~FORMAnalysis()
75
{
2663 mhscott 76
 
291 mhscott 77
}
78
 
79
 
80
 
81
int
3124 mhscott 82
FORMAnalysis::analyze()
291 mhscott 83
{
84
 
85
        // Alert the user that the FORM analysis has started
1271 fmk 86
        opserr << "FORM Analysis is running ... " << endln;
291 mhscott 87
 
88
        // Declare variables used in this method
3124 mhscott 89
        double stdv, mean, Go, Glast, beta, pf1;
3172 mhscott 90
        int numberOfSteps, numberOfEvaluations;
4695 mhscott 91
        static NormalRV aStdNormRV(1,0.0,1.0);
3521 mhscott 92
 
93
        // reliability domain info
291 mhscott 94
        int numRV = theReliabilityDomain->getNumberOfRandomVariables();
3521 mhscott 95
        int numLsf = theReliabilityDomain->getNumberOfLimitStateFunctions();
96
        LimitStateFunction *theLimitStateFunction;
97
 
98
        Vector delta(numRV);
1333 fmk 99
        Vector eta(numRV);
1592 mhscott 100
        Vector kappa(numRV);
3521 mhscott 101
 
1333 fmk 102
        // Open output file
103
        ofstream outputFile( fileName, ios::out );
291 mhscott 104
 
105
        // Loop over number of limit-state functions and perform FORM analysis
3521 mhscott 106
        //LimitStateFunctionIter lsfIter = theReliabilityDomain->getLimitStateFunctions();
107
        //while ((theLimitStateFunction = lsfIter()) != 0) {
108
        for (int lsf = 0; lsf < numLsf; lsf++ ) {
109
                theLimitStateFunction = theReliabilityDomain->getLimitStateFunctionPtrFromIndex(lsf);
110
                int lsfTag = theLimitStateFunction->getTag();
291 mhscott 111
 
3521 mhscott 112
                // Inform the user which limit-state function is being evaluated
113
                opserr << "Limit-state function number: " << lsfTag << endln;
114
                Tcl_SetVar2Ex(interp,"RELIABILITY_lsf",NULL,Tcl_NewIntObj(lsfTag),TCL_NAMESPACE_ONLY);
291 mhscott 115
 
3521 mhscott 116
                // Set tag of "active" limit-state function
117
                theReliabilityDomain->setTagOfActiveLimitStateFunction(lsfTag);
118
 
119
                outputFile << "#######################################################################" << endln;
120
                outputFile << "#  FORM ANALYSIS RESULTS, LIMIT-STATE FUNCTION NUMBER "
121
                                   << setiosflags(ios::left)<<setprecision(1)<<setw(4)<<lsfTag <<"            #" << endln;
122
                outputFile << "#                                                                     #" << endln;
291 mhscott 123
 
3521 mhscott 124
                // Find the design point
125
                if (theFindDesignPointAlgorithm->findDesignPoint() < 0) {
126
                opserr << "FORMAnalysis::analyze() - failed while finding the" << endln
127
                   << " design point for limit-state function number " << lsfTag << "." << endln;
128
 
3172 mhscott 129
 
1333 fmk 130
                        outputFile << "#  No convergence!                                                    #" << endln;
3172 mhscott 131
                        outputFile << "#  Results shown for last iteration of analysis                       #" << endln;
3521 mhscott 132
                }
2784 mhscott 133
 
3521 mhscott 134
                // Get results from the "find desingn point algorithm"
135
                const Vector &xStar = theFindDesignPointAlgorithm->get_x();
136
                const Vector &uStar = theFindDesignPointAlgorithm->get_u();
137
                const Vector &alpha = theFindDesignPointAlgorithm->get_alpha();
138
                const Vector &gamma = theFindDesignPointAlgorithm->get_gamma();
139
                numberOfSteps           = theFindDesignPointAlgorithm->getNumberOfSteps();
140
                Go                                      = theFindDesignPointAlgorithm->getFirstGFunValue();
141
                Glast                           = theFindDesignPointAlgorithm->getLastGFunValue();
142
                const Vector &uSecondLast = theFindDesignPointAlgorithm->getSecondLast_u();
143
                const Vector &alphaSecondLast = theFindDesignPointAlgorithm->getSecondLast_alpha();
144
                const Vector &lastSearchDirection = theFindDesignPointAlgorithm->getLastSearchDirection();
145
                numberOfEvaluations     = theFindDesignPointAlgorithm->getNumberOfEvaluations();
3172 mhscott 146
 
3521 mhscott 147
                // Postprocessing
148
                beta = alpha ^ uStar;
149
                pf1 = 1.0 - aStdNormRV.getCDFvalue(beta);
3172 mhscott 150
 
151
 
3521 mhscott 152
                // Reliability sensitivity analysis wrt. mean/stdv
153
                if (relSensTag == 1) {
154
                        double dBetaDmean;
155
                        double dBetaDstdv;
156
                        Vector DuStarDmean(numRV);
157
                        Vector DuStarDstdv(numRV);
2784 mhscott 158
 
3521 mhscott 159
                        RandomVariableIter rvIter = theReliabilityDomain->getRandomVariables();
160
                        RandomVariable *theRV;
4878 mackie 161
                        for (int j = 0; j < numRV; j++) {
162
                theRV = theReliabilityDomain->getRandomVariablePtrFromIndex(j);
163
                        //while ((theRV = rvIter()) != 0) {
3521 mhscott 164
                                //int j = theRV->getIndex();
165
                                int rvTag = theRV->getTag();
4878 mackie 166
                                //int j = theReliabilityDomain->getRandomVariableIndex(rvTag);
3521 mhscott 167
 
168
                                DuStarDmean = theProbabilityTransformation->meanSensitivityOf_x_to_u(xStar,rvTag);
169
                                DuStarDstdv = theProbabilityTransformation->stdvSensitivityOf_x_to_u(xStar,rvTag);
170
                                dBetaDmean = alpha^DuStarDmean;
171
                                dBetaDstdv = alpha^DuStarDstdv;
172
                                stdv = theRV->getStdv();
173
                                mean = theRV->getMean();
174
 
175
                                delta(j) = stdv * dBetaDmean;
176
                                eta(j) = stdv * dBetaDstdv;
177
                                // (Kappa is the sensitivity wrt. the coefficient of variation)
178
                                if (mean != 0.0)
179
                                        kappa(j) = -dBetaDmean*stdv/((stdv/mean)*(stdv/mean))+dBetaDstdv*mean;
180
                                else
181
                                        kappa(j) = 0.0;
182
                        }
183
 
184
                        // Don't scale them: WHY????? the output is gibberish otherwise
4878 mackie 185
                        //delta /= delta.Norm();
186
                        //eta /= eta.Norm();
187
                        //kappa /= kappa.Norm();
3521 mhscott 188
                }
189
 
4695 mhscott 190
 
191
                // One day, we will use recorders -- MHS 19/7/2011
192
                /*
3521 mhscott 193
                // Store key results in the limit-state functions
194
                theLimitStateFunction->setFORM_beta(beta);
195
                theLimitStateFunction->setFORM_pf1(pf1);
196
                theLimitStateFunction->setFORM_x(xStar);
197
                theLimitStateFunction->setFORM_u(uStar);
198
                theLimitStateFunction->setFORM_alpha(alpha);
199
                theLimitStateFunction->setFORM_gamma(gamma);
200
                theLimitStateFunction->setFORM_numSteps(numberOfSteps);
201
                theLimitStateFunction->setFORM_startGFun(Go);
202
                theLimitStateFunction->setFORM_endGFun(Glast);
203
                theLimitStateFunction->setSecondLast_u(uSecondLast);
204
                theLimitStateFunction->setSecondLast_alpha(alphaSecondLast);
205
                theLimitStateFunction->setLastSearchDirection(lastSearchDirection);
4695 mhscott 206
                */
2784 mhscott 207
 
291 mhscott 208
 
3172 mhscott 209
          outputFile << "#  Limit-state function value at start point: ......... "
210
                     <<setiosflags(ios::left)<<setprecision(5)<<setw(12)<<Go
211
                     << "  #" << endln;
212
          outputFile << "#  Limit-state function value at end point: ........... "
213
                     <<setiosflags(ios::left)<<setprecision(5)<<setw(12)<<Glast
214
                     << "  #" << endln;
215
          outputFile << "#  Number of steps: ................................... "
216
                     <<setiosflags(ios::left)<<setw(12)<<numberOfSteps
217
                     << "  #" << endln;
218
          outputFile << "#  Number of g-function evaluations: .................. "
219
                     <<setiosflags(ios::left)<<setw(12)<<numberOfEvaluations
220
                     << "  #" << endln;
221
          outputFile << "#  Reliability index beta: ............................ "
222
                     <<setiosflags(ios::left)<<setprecision(5)<<setw(12)<<beta
223
                     << "  #" << endln;
224
          outputFile << "#  FO approx. probability of failure, pf1: ............ "
3607 mhscott 225
                     <<setiosflags(ios::left)<<setiosflags(ios::scientific)<<setprecision(5)<<setw(12)<<pf1
3172 mhscott 226
                     << "  #" << endln;
227
          outputFile << "#                                                                     #" << endln;
228
          outputFile << "# rvtag   x*          u*         alpha    gamma    delta    eta       #" << endln;
229
          outputFile.setf( ios::scientific, ios::floatfield );
230
 
231
          RandomVariableIter rvIter = theReliabilityDomain->getRandomVariables();
232
          RandomVariable *theRV;
233
          //for (int i=0;  i<xStar.Size(); i++) {
234
          while ((theRV = rvIter()) != 0) {
3395 mhscott 235
            //int i = theRV->getIndex();
236
            int tag = theRV->getTag();
237
            int i = theReliabilityDomain->getRandomVariableIndex(tag);
238
            outputFile << "#  " <<setw(3)<<tag<<" ";
3172 mhscott 239
            outputFile.setf(ios::scientific, ios::floatfield);
240
            if (xStar(i)<0.0) { outputFile << "-"; }
241
            else { outputFile << " "; }
242
            outputFile <<setprecision(3)<<setw(11)<<fabs(xStar(i));
243
            if (uStar(i)<0.0) { outputFile << "-"; }
244
            else { outputFile << " "; }
245
            outputFile <<setprecision(3)<<setw(11)<<fabs(uStar(i));
246
            outputFile.unsetf( ios::scientific );
247
            outputFile.setf(ios::fixed, ios::floatfield);
248
 
249
            if (alpha(i)<0.0) { outputFile << "-"; }
250
            else { outputFile << " "; }
251
            outputFile<<setprecision(5)<<setw(8)<<fabs(alpha(i));
252
 
253
            if (gamma(i)<0.0) { outputFile << "-"; }
254
            else { outputFile << " "; }
255
            outputFile<<setprecision(5)<<setw(8)<<fabs(gamma(i));              
256
 
257
            if (relSensTag == 1) {
258
              if (delta(i)<0.0) { outputFile << "-"; }
259
              else { outputFile << " "; }
260
              outputFile<<setprecision(5)<<setw(8)<<fabs(delta(i));            
261
 
262
              if (eta(i)<0.0) { outputFile << "-"; }
263
              else { outputFile << " "; }
264
              outputFile<<setprecision(5)<<setw(8)<<fabs(eta(i));              
265
 
1592 mhscott 266
//              Printing reliability sensitivity wrt. coefficient of variation
267
//                              aRandomVariable = theReliabilityDomain->getRandomVariablePtr(i+1);
268
//                              mean = aRandomVariable->getMean();
269
//                              if (mean==0.0) { outputFile << "    -    "; }
270
//                              else {
271
//                                      if (kappa(i)<0.0) { outputFile << "-"; }
272
//                                      else { outputFile << " "; }
273
//                                      outputFile<<setprecision(5)<<setw(8)<<fabs(kappa(i));           
274
//                              }
3172 mhscott 275
            }
276
            else {
277
              outputFile << "    -        -    ";
278
            }
279
 
280
            outputFile<<"   #" << endln;
281
          }
282
          outputFile << "#                                                                     #" << endln;
283
          outputFile << "#######################################################################" << endln << endln << endln;
284
 
285
 
286
          // Inform the user that we're done with this limit-state function
3521 mhscott 287
          opserr << "Done analyzing limit-state function " << lsfTag << ", beta=" << beta << endln;
291 mhscott 288
        }
3172 mhscott 289
 
1333 fmk 290
        // Clean up
291
        outputFile.close();
291 mhscott 292
 
1333 fmk 293
        // Print summary of results to screen (more here!!!)
294
        opserr << "FORMAnalysis completed." << endln;
295
 
291 mhscott 296
        return 0;
297
}
298