File: ODESolver.rst_t

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 (60 lines) | stat: -rw-r--r-- 1,511 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
{{ objname }}
{{ underline }}

.. plot::
    :include-source: False

    import openturns as ot
    from matplotlib import pyplot as plt
    import openturns.viewer as otv

    def flow(X):
        Y0 = X[0]
        Y1 = X[1]
        t = X[2]
        dY0 = Y0 * (2.0 - Y1)
        dY1 = Y1 * (Y0 - 1.0)
        return [dY0, dY1]

    f = ot.PythonFunction(3, 2, flow)
    phi = ot.ParametricFunction(f, [2], [0.0])
    solver = ot.{{ objname }}(phi)

    initialState = [2.0, 2.0]
    nt = 47
    dt = 0.1
    timeGrid = ot.RegularGrid(0.0, dt, nt)
    result = solver.solve(initialState, timeGrid)
    xMin = result.getMin()
    xMax = result.getMax()
    delta = 0.2 * (xMax - xMin)
    mesh = ot.IntervalMesher([12]*2).build(ot.Interval(xMin - delta, xMax + delta))
    field = ot.Field(mesh, phi(mesh.getVertices()))
    ot.ResourceMap.SetAsScalar("Field-ArrowScaling", 0.1)
    graph = field.draw()
    cloud = ot.Cloud(mesh.getVertices())
    cloud.setColor("black")
    graph.add(cloud)
    curve = ot.Curve(result)
    curve.setColor("red")
    curve.setLineWidth(2)
    graph.add(curve)
    graph.setTitle("Lotka-Volterra ODE system")

    fig = plt.figure()
    ax = fig.add_subplot(111)
    otv.View(graph, figure=fig)
    plt.xlabel(r'$y_0$')
    plt.ylabel(r'$y_1$')
    plt.grid()

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

   {% block methods %}
   .. automethod:: __init__
   {% endblock %}

.. minigallery:: {{module}}.{{objname}}
   :add-heading: Examples using the class