Repository: CATIA-Systems/FMPy (language: python)

Issue:
add a default experiment stepsize to container fmu
for instance the minium value of all included fmus
(not very high priority as it is easy to fix, but for the sake of consistency)


Discussion / hints:
Actually the second smallest timestep would be best. As an alternative, it would also be ok to just take the stepsize as an additional entry in the configuration dictionary.
I take "second smallest timestep" back. Both have their usecases. So I guess my request would be an additional attribute of the Container class. Could you please implement this? 
@t-sommer Could you add a attribute for the container class that creates a default experiment stepsize?

Fix patch:
diff --git a/fmpy/fmucontainer/__init__.py b/fmpy/fmucontainer/__init__.py
index df7a4118..13996f56 100644
--- a/fmpy/fmucontainer/__init__.py
+++ b/fmpy/fmucontainer/__init__.py
@@ -40,16 +40,26 @@ class Connection(object):
     endConnector: str
 
 
+@attrs(eq=False, auto_attribs=True)
+class DefaultExperiment(object):
+
+    startTime: str = None
+    stopTime: str = None
+    tolerance: str = None
+    stepSize: str = None
+
+
 @attrs(eq=False)
 class Configuration(object):
 
     fmiVersion = attrib(type=str, default=None, repr=False)
-
-    parallelDoStep = attrib(type=bool, default=False, repr=False)
-
     description = attrib(type=str, default=None, repr=False)
     variableNamingConvention = attrib(type=str, default='flat', repr=False)
 
+    defaultExperiment = attrib(type=DefaultExperiment, default=None, repr=False)
+
+    parallelDoStep = attrib(type=bool, default=False, repr=False)
+
     unitDefinitions = attrib(type=List[Unit], default=Factory(list), repr=False)
     typeDefinitions = attrib(type=List[SimpleType], default=Factory(list), repr=False)
 
diff --git a/fmpy/fmucontainer/templates/FMI2.xml b/fmpy/fmucontainer/templates/FMI2.xml
index be10f105..2eedf928 100644
--- a/fmpy/fmucontainer/templates/FMI2.xml
+++ b/fmpy/fmucontainer/templates/FMI2.xml
@@ -72,6 +72,13 @@
 {% endfor %}
   </TypeDefinitions>
 
+{% endif %}
+{% if system.defaultExperiment %}
+  <DefaultExperiment{% if system.defaultExperiment.startTime %} startTime="{{system.defaultExperiment.startTime}}"{% endif %}
+{% if system.defaultExperiment.stopTime %} stopTime="{{system.defaultExperiment.stopTime}}"{% endif %}
+{% if system.defaultExperiment.tolerance %} tolerance="{{system.defaultExperiment.tolerance}}"{% endif %}
+{% if system.defaultExperiment.stepSize %} stepSize="{{system.defaultExperiment.stepSize}}"{% endif %}/>
+
 {% endif %}
   <ModelVariables>
     <ScalarVariable name="time" valueReference="0" causality="independent" variability="continuous">
diff --git a/fmpy/fmucontainer/templates/FMI3.xml b/fmpy/fmucontainer/templates/FMI3.xml
index c198d1d1..95a17bdc 100644
--- a/fmpy/fmucontainer/templates/FMI3.xml
+++ b/fmpy/fmucontainer/templates/FMI3.xml
@@ -57,6 +57,13 @@
 {% endfor %}
   </TypeDefinitions>
 
+{% endif %}
+{% if system.defaultExperiment %}
+  <DefaultExperiment{% if system.defaultExperiment.startTime %} startTime="{{system.defaultExperiment.startTime}}"{% endif %}
+{% if system.defaultExperiment.stopTime %} stopTime="{{system.defaultExperiment.stopTime}}"{% endif %}
+{% if system.defaultExperiment.tolerance %} tolerance="{{system.defaultExperiment.tolerance}}"{% endif %}
+{% if system.defaultExperiment.stepSize %} stepSize="{{system.defaultExperiment.stepSize}}"{% endif %}/>
+
 {% endif %}
   <ModelVariables>
     <Float64 name="time" valueReference="0" causality="independent" variability="continuous"/>


Test patch:
diff --git a/tests/test_fmu_container.py b/tests/test_fmu_container.py
index 9ab3e2ed..45fff8af 100644
--- a/tests/test_fmu_container.py
+++ b/tests/test_fmu_container.py
@@ -1,7 +1,7 @@
 import pytest
 from itertools import product
 from fmpy import simulate_fmu, plot_result
-from fmpy.fmucontainer import create_fmu_container, Variable, Connection, Configuration, Component
+from fmpy.fmucontainer import create_fmu_container, Variable, Connection, Configuration, Component, DefaultExperiment
 from fmpy.util import compile_platform_binary
 from fmpy.validation import validate_fmu
 from fmpy.model_description import Unit, BaseUnit, SimpleType, DisplayUnit, Item
@@ -31,6 +31,12 @@ def test_create_fmu_container(reference_fmus_dist_dir, fmi_version, parallelDoSt
                 Item(name='Option 2', value=2, description="Second option")
             ])
         ],
+        defaultExperiment=DefaultExperiment(
+            startTime='0',
+            stopTime='10',
+            tolerance='1e-5',
+            stepSize='1e-2'
+        ),
         variables=[
             Variable(
                 type=real_type,