File: plot_parametric_function.py

package info (click to toggle)
openturns 1.26-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,708 kB
  • sloc: cpp: 261,605; python: 67,030; ansic: 4,378; javascript: 406; sh: 185; xml: 164; makefile: 101
file content (133 lines) | stat: -rw-r--r-- 3,383 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""
Create a parametric function
============================
"""

# %%
# In this example, we show how to use the :class:`~openturns.ParametricFunction` class.
# This is a tool which is very convenient when we perform
# calibration, e.g. with :class:`~openturns.NonLinearLeastSquaresCalibration`
# or :class:`~openturns.RandomWalkMetropolisHastings`.

# %%
# In this example we create a parametric function:
#
# .. math::
#    d_{L,I}(E, F):  \Rset^2  \rightarrow \Rset
#
# function from an existing "full" function:
#
# .. math::
#  d(E, F, L, I):  \Rset^4  \rightarrow \Rset.
#

# %%
import openturns as ot


# %%
# Define the function
# ~~~~~~~~~~~~~~~~~~~

# %%
# Create the function with all parameters d(E, F, L, I)


def d_func(X):
    E, F, L, II = X
    d = -F * L**3 / (3.0 * E * II)
    return [d]


beam = ot.PythonFunction(4, 1, d_func)
beam.setInputDescription(["E", "F", "L", "I"])

# %%
# Evaluate d
x = [50.0, 1.0, 10.0, 5.0]
beam(x)

# %%
# In the physical model, the inputs and parameters are ordered as
# presented in the next table.
# Notice that there are no parameters in the physical model.
#
# +-------+----------------+
# | Index | Input variable |
# +=======+================+
# | 0     | E              |
# +-------+----------------+
# | 1     | F              |
# +-------+----------------+
# | 2     | L              |
# +-------+----------------+
# | 3     | I              |
# +-------+----------------+
#
# +-------+-----------+
# | Index | Parameter |
# +=======+===========+
# | ∅     | ∅         |
# +-------+-----------+
#
# **Table 1.** Indices and names of the inputs and parameters of the physical model.
#

# %%
# The next cell presents the description of the input variables
# and the description of the parameters of the physical model.
# We see that there is no parameter at this stage in this function.
print("Physical Model Inputs:", beam.getInputDescription())
print("Physical Model Parameters:", beam.getParameterDescription())


# %%
# Define the parametric function
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# %%
# We create a :class:`~openturns.ParametricFunction`
# where the parameters are `L` and `I` which have the indices 2 and
# and 3 in the physical model.
#
# +-------+----------------+
# | Index | Input variable |
# +=======+================+
# | 0     | E              |
# +-------+----------------+
# | 1     | F              |
# +-------+----------------+
#
# +-------+-----------+
# | Index | Parameter |
# +=======+===========+
# | 0     | L         |
# +-------+-----------+
# | 1     | I         |
# +-------+-----------+
#
# **Table 2.** Indices and names of the inputs and parameters of the parametric model.
#

# %%
# Create the indices of the frozen parameters (L,I) from the full parameter list
indices = [2, 3]

# %%
# Create the values of the frozen parameters (L,I)
referencePoint = [10.0, 5.0]

# %%
# Create the parametric function
beam_LI = ot.ParametricFunction(beam, indices, referencePoint)

# %%
# The next cell presents the description of the input variables
# and the description of the parameters of the parametric function.
# We see that the parametric function has 2 parameters: L and I.
print("Physical Model Inputs:", beam_LI.getInputDescription())
print("Physical Model Parameters:", beam_LI.getParameterDescription())

# %%
# Evaluate d on (E,F) with fixed parameters (L,I)
beam_LI([50.0, 1.0])