ExampleAxialStressedBeam: AxialStressedBeam.py

File AxialStressedBeam.py, 5.7 kB (added by regis.lebrun@eads.net, 1 year ago)
Line 
1 # Main OpenTURNS module
2 from openturns import *
3 # OpenTURNS viewer capability (since release 0.9.2)
4 from openturns_viewer import ViewImage
5
6 # Constant definition:
7 stochasticDimension = 2
8
9 # Random generator initialization:
10 RandomGenerator().SetSeed(0)
11
12 #Analytical model definition:
13
14 # Analytical construction : Input
15 inputFunction = Description(stochasticDimension)
16 inputFunction[0] = "R"
17 inputFunction[1] = "F"
18
19 # Analytical construction : Output
20 outputFunction = Description(1)
21 outputFunction[0] = "G"
22
23 formulas = Description(outputFunction.getSize())
24 # Here, _pi is the built-in constant _pi=3.14159265....
25 formulas[0] = "R-F/(_pi*100.0)"
26
27 LimitState = NumericalMathFunction(inputFunction, outputFunction, formulas)
28
29 # Test of the limit state function:
30 x = NumericalPoint(stochasticDimension, 0)
31 x[0]=300.0
32 x[1]=75000.0
33 print "x=" , x
34 print "G(x)=" , LimitState(x)
35
36 # Stochastic model definition:
37
38 # Mean
39 mean = NumericalPoint(stochasticDimension, 0.0)
40 mean[0] = 300.0
41 mean[1] = 75000.0
42
43 # Standard deviation
44 sigma = NumericalPoint(stochasticDimension, 0.0)
45 sigma[0] = 30.0
46 sigma[1] = 5000.0
47
48 # Additional parameters for the lognormal distribution:
49 component = Description(1)
50 BorneInf = 0.0
51
52 # Initialization of the distribution collection:
53 aCollection = DistributionCollection()
54
55 # Create a first marginal : LogNormal distribution 1D, parameterized by its mean and standard deviation
56 marginal = LogNormal(mean[0], sigma[0], BorneInf, LogNormal.MUSIGMA)
57 marginal.setName("Yield strength")
58 component[0] = "R"
59 marginal.setDescription(component)
60 # Graphical output of the PDF
61 pdfgraph1=marginal.drawPDF()
62 # If the directory name is omitted, the graph will be produced in the current directory.
63 # If the dimensions are omitted, the default is 400x300 up to release 0.10.0, and 640x480 for the later releases
64 pdfgraph1.draw("/tmp", "pdf_R", 640, 480)
65 # Visualize the graph
66 ViewImage(pdfgraph1.getBitmap())
67 # Fill the first marginal of aCollection
68 aCollection.add( Distribution(marginal, "Yield strength") )
69
70 # Create a second marginal : Normal distribution 1D
71 marginal = Normal(mean[1], sigma[1])
72 marginal.setName("Traction_load")
73 component[0] = "F"
74 marginal.setDescription(component)
75 # Graphical output of the PDF
76 pdfgraph2=marginal.drawPDF()
77 pdfgraph2.draw("/tmp", "pdf_F", 640, 480)
78 ViewImage(pdfgraph2.getBitmap())
79 # Fill the second marginal of aCollection
80 aCollection.add( Distribution(marginal, "Traction_load") )
81
82 # Create a copula : IndependentCopula (no correlation)
83 aCopula = IndependentCopula(aCollection.getSize())
84 aCopula.setName("Independent copula")
85
86 # Instanciate one distribution object
87 myDistribution = ComposedDistribution(aCollection, Copula(aCopula))
88 myDistribution.setName("myDist")
89
90 # We create a 'usual' RandomVector from the Distribution
91 vect = RandomVector(Distribution(myDistribution))
92
93 # We create a composite random vector
94 G = RandomVector(LimitState, vect)
95
96 # We create an Event from this RandomVector
97 myEvent = Event(G, ComparisonOperator(Less()), 0.0, "Event 1")
98
99 # Using Monte Carlo simulations
100
101 # Resolution options:
102 cv = 0.05
103 NbSim = 100000
104
105 algoMC = MonteCarlo(myEvent)
106 algoMC.setMaximumOuterSampling(NbSim)
107 algoMC.setBlockSize(1)
108 algoMC.setMaximumCoefficientOfVariation(cv)
109 # For statistics about the algorithm
110 initialNumberOfCall = LimitState.getEvaluationCallsNumber()
111
112 # Perform the analysis:
113 algoMC.run()
114
115 # Results:
116 result = algoMC.getResult()
117 probability = result.getProbabilityEstimate()
118 print "MonteCarlo result=" , result.str()
119 print "Number of executed iterations =" , result.getOuterSampling()
120 print "Number of calls to the limit state =" , LimitState.getEvaluationCallsNumber() - initialNumberOfCall
121 print "Pf = " , probability
122 print "CV =" , result.getCoefficientOfVariation()
123 MCcvgraph = algoMC.drawProbabilityConvergence()
124 MCcvgraph.draw("/tmp", "montecarlo_convergence", 640, 480)
125 ViewImage(MCcvgraph.getBitmap())
126
127 # Using FORM analysis
128
129 # Resolution options:
130 eps=1E-3
131
132 # We create a NearestPoint algorithm
133 myCobyla = Cobyla()
134 myCobyla.setSpecificParameters(CobylaSpecificParameters())
135 myCobyla.setMaximumIterationsNumber(100)
136 myCobyla.setMaximumAbsoluteError(eps)
137 myCobyla.setMaximumRelativeError(eps)
138 myCobyla.setMaximumResidualError(eps)
139 myCobyla.setMaximumConstraintError(eps)
140
141 # For statistics about the algorithm
142 initialNumberOfCall = LimitState.getEvaluationCallsNumber()
143
144 # We create a FORM algorithm
145 # The first parameter is a NearestPointAlgorithm
146 # The second parameter is an event
147 # The third parameter is a starting point for the design point research
148
149 algoFORM = FORM(NearestPointAlgorithm(myCobyla), myEvent, mean)
150
151 # Perform the analysis:
152 algoFORM.run()
153
154 # Results:
155 result = algoFORM.getResult()
156 print "Number of calls to the limit state =" , LimitState.getEvaluationCallsNumber() - initialNumberOfCall
157 print "Pf =" , result.getEventProbability()
158
159 # Graphical result output
160 importanceFactorsGraph = result.drawImportanceFactors()
161 importanceFactorsGraph.draw("/tmp", "importance_factors", 640, 480)
162 ViewImage(importanceFactorsGraph.getBitmap())
163
164 # Using Directional sampling
165
166 # Resolution options:
167 cv = 0.05
168 NbSim = 100000
169
170 algoDS = DirectionalSampling(myEvent)
171 algoDS.setMaximumOuterSampling(NbSim)
172 algoDS.setBlockSize(1)
173 algoDS.setMaximumCoefficientOfVariation(cv)
174 # For statistics about the algorithm
175 initialNumberOfCall = LimitState.getEvaluationCallsNumber()
176
177 # Perform the analysis:
178 algoDS.run()
179
180 # Results:
181 result = algoDS.getResult()
182 probability = result.getProbabilityEstimate()
183 print "Number of executed iterations =" , result.getOuterSampling()
184 print "Number of calls to the limit state =" , LimitState.getEvaluationCallsNumber() - initialNumberOfCall
185 print "Pf = " , probability
186 print "CV =" , result.getCoefficientOfVariation()
187 DScvgraph = algoDS.drawProbabilityConvergence()
188 DScvgraph.draw("/tmp", "directionalsampling_convergence", 640, 480)
189 ViewImage(DScvgraph.getBitmap())
190