Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Nov 22, 2023
1 parent 48d0bcd commit f01ec73
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 51 deletions.
4 changes: 2 additions & 2 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ The submodule **otfmi.fmi** gathers a set of useful functions, employed by the (
fmi.get_start_value
fmi.set_dict_value

From OpenTURNS to FMU
From OpenTURNS to FMI
---------------------

Otfmi can also embed an OpenTURNS function in a Modelica model and/or FMU.
OTFMI can also export an OpenTURNS function in a Modelica source model (.mo) or Functional Mock-up Unit (.fmu).

.. autosummary::
:toctree: _generated/
Expand Down
43 changes: 13 additions & 30 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import sys
import os
import subprocess
from distutils.version import LooseVersion
import sphinx
# import sphinx_gallery


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -43,10 +41,7 @@
}


if LooseVersion(sphinx.__version__) >= "1.8":
autodoc_default_options = {"members": None, "inherited-members": None}
else:
autodoc_default_flags = ["members", "inherited-members"]
autodoc_default_options = {"members": None, "inherited-members": None}

intersphinx_mapping = {
"openturns": ("http://openturns.github.io/openturns/latest", None)
Expand All @@ -56,30 +51,18 @@
numpydoc_show_class_members = True
numpydoc_class_members_toctree = False

try:
import sphinx.ext.imgmath

extensions.append("sphinx.ext.imgmath")
imgmath_latex_preamble = r"\usepackage{{{0}math_notations}}".format(
os.path.dirname(__file__) + os.sep
)
imgmath_use_preview = True
if (
subprocess.call(
"dvisvgm -V", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
== 0
):
imgmath_image_format = "svg"
except ImportError:
extensions.append("sphinx.ext.pngmath")
pngmath_latex_preamble = r"\usepackage{{{0}math_notations}}".format(
os.path.dirname(__file__) + os.sep
extensions.append("sphinx.ext.imgmath")
imgmath_latex_preamble = r"\usepackage{{{0}math_notations}}".format(
os.path.dirname(__file__) + os.sep
)
imgmath_use_preview = True
if (
subprocess.call(
"dvisvgm -V", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
# The next option is used for smart-alignment of math images on the text.
# It only works when the preview-latex package is installed.
# See http://sphinx-doc.org/latest/ext/math.html#confval-pngmath_use_preview
pngmath_use_preview = True
== 0
):
imgmath_image_format = "svg"

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
2 changes: 1 addition & 1 deletion doc/example/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Common low-level functions
../auto_example/low_level/plot_simulate
../auto_example/low_level/plot_initialize

From OpenTURNS to FMU
From OpenTURNS to FMI
---------------------

.. warning::
Expand Down
16 changes: 7 additions & 9 deletions doc/example/ot_to_fmu/plot_fmu_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
# ``otfmi.FunctionExporter`` enables to export OpenTURNS functions as FMUs. The
# main interest of this class is to use OpenTURNS metamodels in a simulation environment.
#
# .. warning::
# **This functionality is experimental**.
#
# Currently, the inclusion of a metamodel in
# `OpenModelica GUI <https://openmodelica.org/?id=78:omconnectioneditoromedit&catid=10:main-category>`_
# has been performed once (see
Expand All @@ -23,15 +20,15 @@
#
# First, we create the OpenTURNS function to export as FMU.
# This example being solely a demonstrator, we consider a very simple
# exponentiel function.
# exponential function.

import openturns as ot
import otfmi
import tempfile
from os.path import join

func = ot.SymbolicFunction("x", "exp(x)")
inputPoint = ot.Point([2])
func = ot.SymbolicFunction(["x"], ["exp(x)"])
inputPoint = [2.0]
print(func(inputPoint))

# %%
Expand All @@ -41,9 +38,10 @@
print(fmu_path)

# %%
# We export the OpenTURNS function as a Model Exchange FMU. Another export
# possiblity is the CoSimulation FMU (embeds a solver).

# We export the OpenTURNS function as a Model Exchange FMU.
# The counterpart is to export as CoSimulation FMU (embeds a solver).
# Another option would be to export the function via pythonfmu (see the "mode" keyword)
# allowing export of temporal functions (not a concern here for our function).
fmuExporter.export_fmu(fmu_path, fmuType="me")

# %%
Expand Down
9 changes: 4 additions & 5 deletions doc/example/ot_to_fmu/plot_model_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
# ``otfmi.FunctionExporter`` enables to export OpenTURNS functions as Modelica model.
# The main interest is to use OpenTURNS metamodels in a simulation environment.
#
# .. warning::
# **This functionality is experimental**.
#
# Currently, the inclusion of a metamodel in
# `OpenModelica GUI <https://openmodelica.org/?id=78:omconnectioneditoromedit&catid=10:main-category>`_
# has been performed once (see
Expand All @@ -29,7 +26,7 @@


func = ot.SymbolicFunction("x", "exp(x)")
inputPoint = ot.Point([2])
inputPoint = [2.0]
print(func(inputPoint))

# %%
Expand All @@ -47,7 +44,7 @@
modelExporter.export_model(model_path, gui=True)

# %%
# Simple as it looks, this function actually does the following :
# Simple as it looks, this function actually does the following:
#
# - write a C-wrapper for the OpenTURNS function,
# - write a Modelica model calling the C-wrapper as `External <shorturl.at/fhCU2>`_ function.
Expand Down Expand Up @@ -107,3 +104,5 @@
# ⚠️ Compared to native Modelica functions, the included OpenTURNS function is
# slow. In this case, 11 seconds of simulation were required for 50 time
# steps (i.e. 50 function calls).
#
# Note that faster export modes are available with the "mode" keyword, depending on your setup.
13 changes: 9 additions & 4 deletions otfmi/function_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,17 @@ def export_model(self, model_path, gui=False, verbose=False, binary=True, mode="
Verbose output (default=False).
binary : bool
Whether to generate binaries or source (default=True)
mode : 'pyprocess', 'cpython' or 'cxx'
Use either a Python process, the Python C API to evaluate the model or the OpenTURNS C++ API.
If cxx mode is selected the OpenTURNS development headers and libraries need
to be installed (not just the Python module that is installed by pip for example).
mode : str, either 'pyprocess', 'cpython' or 'cxx'
- pyprocess: the function is run via a Python process by file I/O;
slow but should work almost everywhere.
- cpython: the function is run via the Python C API; quite fast (no file I/O)
but requires Python development headers/libs
- cxx: the function is directly evaluated trough the OpenTURNS C++ API;
even faster but requires the OpenTURNS development headers and libraries
(not just the Python module that would be installed by pip for example).
move : bool
Move the model from temporary folder to user folder (default=True)
For internal use.
"""

assert isinstance(model_path, str), "model_path must be str"
Expand Down

0 comments on commit f01ec73

Please sign in to comment.