| 1 | #! /usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | from openturns import * |
|---|
| 4 | |
|---|
| 5 | from math import * |
|---|
| 6 | |
|---|
| 7 | from openturns_viewer import ViewImage |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | # This function enables a pretty print of a NumericalPoint |
|---|
| 11 | def printNumericalPoint(point, digits) : |
|---|
| 12 | oss = "[" |
|---|
| 13 | eps = pow(0.1, digits) |
|---|
| 14 | for i in range(point.getDimension()) : |
|---|
| 15 | if i == 0 : |
|---|
| 16 | sep = "" |
|---|
| 17 | else : |
|---|
| 18 | sep = "," |
|---|
| 19 | if fabs(point[i]) < eps : |
|---|
| 20 | oss += sep + str(fabs(point[i])) |
|---|
| 21 | else : |
|---|
| 22 | oss += sep + str(point[i]) |
|---|
| 23 | sep = "," |
|---|
| 24 | oss += "]" |
|---|
| 25 | return oss |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | ########################################### |
|---|
| 29 | ### Fonction 'poutre' |
|---|
| 30 | ########################################### |
|---|
| 31 | |
|---|
| 32 | # We create a numerical math function |
|---|
| 33 | stochasticDimension = 4 |
|---|
| 34 | |
|---|
| 35 | # Analytical construction : Input |
|---|
| 36 | inputFunction = Description(stochasticDimension) |
|---|
| 37 | inputFunction[0] = "E" |
|---|
| 38 | inputFunction[1] = "F" |
|---|
| 39 | inputFunction[2] = "L" |
|---|
| 40 | inputFunction[3] = "I" |
|---|
| 41 | |
|---|
| 42 | # Analytical construction : Output |
|---|
| 43 | outputFunction = Description(1) |
|---|
| 44 | outputFunction[0] = "y" |
|---|
| 45 | |
|---|
| 46 | formulas = Description(outputFunction.getSize()) |
|---|
| 47 | formulas[0] = "F*(L^3)/(3*E*I)" |
|---|
| 48 | |
|---|
| 49 | myFunction = NumericalMathFunction(inputFunction, outputFunction, formulas) |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | ########################################### |
|---|
| 54 | ### Random input vector |
|---|
| 55 | ########################################### |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | dim = myFunction.getInputNumericalPointDimension() |
|---|
| 59 | |
|---|
| 60 | # We create a normal distribution point of dimension 4 |
|---|
| 61 | mean = NumericalPoint(dim, 0.0) |
|---|
| 62 | # E : steel : 210000 MPa |
|---|
| 63 | mean[0] = 2.1e11 |
|---|
| 64 | # F : 1kg : 10N |
|---|
| 65 | mean[1] = 10.0 |
|---|
| 66 | # L : 1 m |
|---|
| 67 | mean[2] = 1.0 |
|---|
| 68 | # I : square hollow section of width 2 cm and thickness 1mm : 2.47325 e-9 |
|---|
| 69 | mean[3] = 2.47325e-9 |
|---|
| 70 | sigma = NumericalPoint(dim, 1.0) |
|---|
| 71 | # E : 5% * mean |
|---|
| 72 | sigma[0] = 0.05 * mean[0] |
|---|
| 73 | # F : 10% * mean |
|---|
| 74 | sigma[1] = 0.1 * mean[1] |
|---|
| 75 | # L : 1% * mean |
|---|
| 76 | sigma[2] = 0.01 * mean[2] |
|---|
| 77 | # I : 1% * mean |
|---|
| 78 | sigma[3] = 0.01 * mean[3] |
|---|
| 79 | |
|---|
| 80 | R = IdentityMatrix(dim) |
|---|
| 81 | myDistribution = Normal(mean, sigma, R) |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | input = RandomVector(myDistribution) |
|---|
| 85 | |
|---|
| 86 | output = RandomVector(myFunction, input) |
|---|
| 87 | |
|---|
| 88 | # Custom gradient |
|---|
| 89 | eps = NumericalPoint(4, 1.0) |
|---|
| 90 | for i in range(4): |
|---|
| 91 | eps[i] = mean[i]*0.001 |
|---|
| 92 | myGradient = NonCenteredFiniteDifferenceGradient(eps, myFunction.getEvaluationImplementation()) |
|---|
| 93 | myFunction.setGradientImplementation(NonCenteredFiniteDifferenceGradient(myGradient)) |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | ################################################################# |
|---|
| 97 | ### Probabilistic Study : threshold exceedance: deviation <-1cm |
|---|
| 98 | ################################################################# |
|---|
| 99 | |
|---|
| 100 | # We create an Event from this RandomVector |
|---|
| 101 | threshold = 0.01 |
|---|
| 102 | myEvent = Event(output, ComparisonOperator(GreaterOrEqual()), threshold) |
|---|
| 103 | |
|---|
| 104 | ###### |
|---|
| 105 | # FORM |
|---|
| 106 | ###### |
|---|
| 107 | |
|---|
| 108 | print "#####" |
|---|
| 109 | print "FORM" |
|---|
| 110 | print "#####" |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | # We create a NearestPoint algorithm |
|---|
| 114 | mySQP = SQP() |
|---|
| 115 | specific = SQPSpecificParameters(0.5,1.0e-03,1.2) |
|---|
| 116 | mySQP.setSpecificParameters(SQPSpecificParameters()) |
|---|
| 117 | mySQP.setMaximumIterationsNumber(1000) |
|---|
| 118 | mySQP.setMaximumAbsoluteError(1.0e-3) # |(ui+1)-ui| |
|---|
| 119 | mySQP.setMaximumRelativeError(1.0e-3) # |norm(u)| |
|---|
| 120 | mySQP.setMaximumResidualError(1.0e-3) # crit FERUM |
|---|
| 121 | mySQP.setMaximumConstraintError(1.0e-3) |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | # We create a FORM algorithm |
|---|
| 125 | myAlgoFORM = FORM(NearestPointAlgorithm(mySQP), myEvent, mean) |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | # Perform the simulation |
|---|
| 129 | myAlgoFORM.run() |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | # Stream out the result |
|---|
| 133 | resultFORM = myAlgoFORM.getResult() |
|---|
| 134 | digits = 5 |
|---|
| 135 | print "FORM event probability=" , resultFORM.getEventProbability() |
|---|
| 136 | print "generalized reliability index=" , resultFORM.getGeneralisedReliabilityIndex() |
|---|
| 137 | |
|---|
| 138 | |
|---|