File: t_FMIPhysicalModel_std.py

package info (click to toggle)
persalys 13.1.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 71,916 kB
  • sloc: xml: 496,859; cpp: 53,848; python: 3,435; sh: 332; makefile: 131; ansic: 14
file content (69 lines) | stat: -rw-r--r-- 1,864 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
#!/usr/bin/env python

import openturns as ot
import openturns.testing as ott
import persalys
import os
import platform

myStudy = persalys.Study("myStudy")

key_platform = (platform.system(), platform.architecture()[0])
# Call to either 'platform.system' or 'platform.architecture' *after*
# importing pyfmi causes a segfault.
dict_platform = {("Linux", "64bit"): "linux64", ("Windows", "32bit"): "win32"}

path_here = os.path.dirname(os.path.abspath(__file__))
try:
    directory_platform = dict_platform[key_platform]
except KeyError:
    raise RuntimeError("Not available")

path_fmu = os.path.join(path_here, "fmu", directory_platform, "deviation.fmu")

E = persalys.Input("E", 1.0, ot.Normal(), "E description")
F = persalys.Input("F", 1.0)
II = persalys.Input("I", 1.0)
L = persalys.Input("L", 1.0)
y = persalys.Output("y", "deviation")

inputs = [E, F, II, L]
outputs = [y]
model = persalys.FMIPhysicalModel("myPhysicalModel", inputs, outputs, path_fmu)
myStudy.add(model)

# print(model.getCode())

E_d = ot.Beta(0.93, 3.2 - 0.93, 28000000.0, 48000000.0)
F_d = ot.LogNormalMuSigma(30000.0, 9000.0, 15000.0).getDistribution()
L_d = ot.Uniform(250.0, 260.0)
I_d = ot.Beta(2.5, 4.0 - 2.5, 310.0, 450.0)
distribution = ot.ComposedDistribution([E_d, F_d, I_d, L_d])
x = distribution.getMean()


f = model.getFunction()
y = f(x)
ott.assert_almost_equal(y, [12.3369])

# script
script = myStudy.getPythonScript()
print("script=", script)
exec(script)


# compare with pyfmi directly
if 0:
    import pyfmi
    import otfmi

    # print(path_fmu)
    model_fmu = model_fmu = otfmi.FMUFunction(
        path_fmu, inputs_fmu=["E", "F", "I", "L"], outputs_fmu="y"
    )

    ml = pyfmi.load_fmu(path_fmu)
    vars = ml.get_model_variables()
    for var in vars.values():
        print(var.name, var.value_reference)
        # print(ml.get_real(var.value_reference))