Skip to content

Commit 721d085

Browse files
committed
examples
1 parent c97c31c commit 721d085

8 files changed

Lines changed: 590 additions & 93 deletions

File tree

doc/_static/beam.svg

Lines changed: 499 additions & 0 deletions
Loading

doc/examples/application/plot_metamodel.py

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,14 @@
33
=====================================
44
"""
55
# %%
6-
# We are interested in the evolution of an epidemic through a
7-
# population (for instance, Covid!). We have an epidemiologic model describing
8-
# the epidemic dynamics. More precisely, we focus on the evolution of the number
9-
# of people infected by the disease.
10-
#
11-
# .. image:: /_static/epid.png
12-
# :scale: 80 %
13-
# :alt: alternate text
14-
# :align: center
15-
#
16-
# --------
17-
#
18-
# See the epidemiological model :doc:`here<../../fmus/epid>`.
19-
#
20-
# --------
21-
#
6+
# This example shows how to create a metamodel of the
7+
# :doc:`epidemiological model<../../examples/model_description>`.
228
#
239
# **To decrease the model simulation costs, let's create a metamodel.**
2410
#
25-
# Metamodeling a model which output depends on time is a difficult problem. We
26-
# will combine two methods: Karhunen-Loeve dimension reduction should precede the Kriging metamodeling.
11+
# Metamodeling a model with time-dependent output is a difficult problem. We
12+
# will combine two methods: Karhunen-Loeve dimension reduction should precede
13+
# the Kriging metamodeling.
2714
#
2815
# We will proceed the following way:
2916
#
@@ -61,20 +48,21 @@
6148
)
6249

6350
# %%
64-
# We create a Monte-Carlo design of experiment, on which we
65-
# simulate the FMU.
51+
# We create a Monte-Carlo design of experiment, on which we simulate the FMU.
6652
# The simulation inputs and outputs will be used to train the metamodel.
6753

6854
inputLaw = ot.Uniform(1.5, 2.5)
69-
inputSample = inputLaw.getSample(30)
55+
inputSample = inputLaw.getSample(10)
7056
outputFMUSample = function(inputSample)
7157

7258
graph = outputFMUSample.draw().getGraph(0, 0)
7359
graph.setTitle("FMU simulations")
7460
graph.setXTitle("Time")
7561
graph.setYTitle("Number of infected")
76-
graph.setLegends([f"{line[0]:.3f}" for line in inputSample[:15]] + ["_"] * 15)
77-
view = otv.View(graph, legend_kw={"title": "infection rate", "loc": "upper left"})
62+
graph.setLegendFontSize(6.)
63+
graph.setLegends([f"{line[0]:.2f}" for line in inputSample[:10]])
64+
view = otv.View(graph,
65+
legend_kw={"title": "infection rate", "loc": "upper left"})
7866

7967
# %%
8068
# We define a function to visualize the upcoming Karhunen-Loeve modes.
@@ -133,7 +121,9 @@ def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"):
133121
# We metamodel the Karhunen-Loeve coefficients using ordinary Kriging.
134122
dim = inputSample.getDimension() # only 1 input dimension
135123
univb = ot.ConstantBasisFactory(dim).build() # univariate basis
136-
coll = [ot.AggregatedFunction([univb.build(i)] * n_mode) for i in range(univb.getSize())]
124+
coll = [ot.AggregatedFunction(
125+
[univb.build(i)] * n_mode) for i in range(univb.getSize())]
126+
137127
basis = ot.Basis(coll) # multivariate basis
138128
covarianceModel = ot.SquaredExponential(dim)
139129
covarianceModel = ot.TensorizedCovarianceModel([covarianceModel] * n_mode)
@@ -145,8 +135,8 @@ def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"):
145135
metamodel = result.getMetaModel()
146136

147137
# %%
148-
# We have created all pieces for a "PointToField" metamodel. Let put these
149-
# pieces together:
138+
# We have created all pieces for a "PointToField" metamodel.
139+
# Let put these pieces together:
150140

151141

152142
def globalMetamodel(sample):
@@ -225,12 +215,11 @@ def globalMetamodel(sample):
225215
# ----------------------
226216
#
227217
# The ``globalMetamodel`` (computationnally faster than the FMU) created with
228-
# the above script can now be used as a computationnally much cheaper
229-
# substitute to the FMU for
218+
# the above script can now be used as a faster substitute to the FMU for
230219
#
231-
# - `sensitivity analysis <openturns.github.io/openturns/latest/auto_reliability_sensitivity/index.html#sensitivity-analysis>`_,
232-
# - `parameter inference <openturns.github.io/openturns/latest/auto_calibration/index.html#bayesian-calibration>`_,
233-
# - `estimate a failure probability <openturns.github.io/openturns/latest/auto_reliability_sensitivity/index.html#reliability>`_,
220+
# - `sensitivity analysis <https://openturns.github.io/openturns/latest/auto_sensitivity_analysis/index.html>`_,
221+
# - `parameter inference <https://openturns.github.io/openturns/latest/auto_calibration/index.html>`_,
222+
# - `estimate a failure probability <https://openturns.github.io/openturns/latest/auto_reliability/index.html>`_,
234223
#
235224
# etc.
236225

doc/examples/application/plot_reliability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
==================================================
44
"""
55
# %%
6-
# A load is applied to a :doc:`cantilever beam<../model_description>`.
6+
# A load is applied to a :doc:`cantilever beam<../../examples/model_description>`.
77
# The beam must not exceed a bending of 30 cm. The load (F), beam
88
# Young's modulus (E), length (L) and section modulus (I) are uncertain.
99
#

doc/examples/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ Heat exchanger example
5555
:maxdepth: 1
5656

5757
../auto_example/f2f/index.rst
58+
59+
Model descriptions
60+
------------------
61+
62+
.. toctree::
63+
:maxdepth: 1
64+
65+
model_description
Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
1+
Models description
2+
==================
3+
4+
Examples used in this documentation rely on several models.
5+
6+
Following sections show how they works.
7+
8+
The cantilever beam model
9+
-------------------------
10+
11+
.. image:: /_static/beam.svg
12+
:scale: 100 %
13+
:alt: alternate text
14+
:align: center
15+
16+
We consider a cantilever beam defined by its Young’s modulus ``E``, its length ``L`` and its section modulus ``I``.
17+
One end of the cantilever beam is fixed in a wall and we apply a concentrated
18+
bending load ``F`` at the other end of the beam, resulting in a deviation ``Y``.
19+
The mechanical equation ruling the deviation is
20+
21+
22+
.. raw:: html
23+
24+
<div style="margin-left:20px;width:300px;height:120px;">
25+
.. math::
26+
27+
Y = \frac{FL^3}{3EI}
28+
29+
.. raw:: html
30+
31+
</div>
32+
33+
34+
This model is implemented in Modelica language:
35+
36+
.. code::
37+
38+
model deviation
39+
output Real y;
40+
input Real E (start=3.0e7);
41+
input Real F (start=3.0e4);
42+
input Real L (start=250);
43+
input Real I (start=400);
44+
equation
45+
y=(F*L^3)/(3*E*I);
46+
end deviation;
47+
48+
49+
50+
151
The epidemiological model
2-
=========================
52+
--------------------------
353

4-
The epidemiological model describes epidemics which propagate through human contact.
54+
This model describes epidemics which propagate through human contact.
555
An isolated population is considered, whose total number is constant.
656
The people are divided in three categories:
757

@@ -10,17 +60,20 @@ The people are divided in three categories:
1060
* the Removed (who are either dead or immune).
1161

1262
The disease can only be propagated from Infected to Susceptibles.
13-
This happens at a rate called ``infection rate`` (:math:`\beta`).
14-
An Infected becomes Removed after an infection duration (:math:`\gamma`) corresponding to the inverse of the ``healing_rate``.
63+
This happens at a rate called ``infection rate`` :math:`\beta`.
64+
An Infected becomes Removed after an infection duration :math:`\gamma` corresponding to the inverse of the ``healing_rate``.
1565

16-
.. image:: ../_static/epid.png
17-
:scale: 80 %
66+
.. image:: /_static/epid.png
67+
:scale: 50 %
1868
:alt: alternate text
1969
:align: center
2070

2171
The evolution of the number of Susceptibles, Infected and Removed over
2272
time writes:
2373

74+
75+
76+
2477
.. math::
2578
2679
\begin{aligned}
@@ -29,6 +82,9 @@ time writes:
2982
\frac{\partial R}{\partial t}(t) &= \gamma I(t)
3083
\end{aligned}
3184
85+
86+
87+
3288
This model is implemented in Modelica language. The default simulation time is 50 units of time (days for instance).
3389

3490
.. code::

doc/fmus/deviation.rst

Lines changed: 0 additions & 42 deletions
This file was deleted.

doc/fmus/index.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

doc/index.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ The core features of `otfmi <https://github.com/openturns/otfmi>`__ are:
4545

4646
application/application
4747

48-
.. toctree::
49-
:maxdepth: 1
50-
51-
fmus/index
52-
5348
.. toctree::
5449
:maxdepth: 1
5550

0 commit comments

Comments
 (0)