Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/pyfmi/fmi_algorithm_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ class AssimuloFMIAlgOptions(OptionBase):
Default: "Default" (rtol*0.01*(nominal values of the continuous states))

maxh --
The maximum step-size allowed to be used by the solver.
The maximum step-size allowed to be used by the solver. The
default caps the step at the communication-point spacing, which
forces at least 'ncp' steps; None or 0.0 removes the cap and
lets the solver's error control alone choose the step (also the
default when ncp = 0).
Default: "Default" (max step-size computed based on (final_time-start_time)/ncp)

discr --
Expand Down Expand Up @@ -623,11 +627,13 @@ def _set_solver_options(self):
if "usejac" in solver_options and fnbr == 0:
solver_options["usejac"] = False

if "maxh" in solver_options and solver_options["maxh"] == "Default":
if "maxh" in solver_options and isinstance(solver_options["maxh"], str) and solver_options["maxh"] == "Default":
if self.options["ncp"] == 0:
solver_options["maxh"] = 0.0
else:
solver_options["maxh"] = abs(float(self.final_time - self.start_time)) / float(self.options["ncp"])
elif "maxh" in solver_options and solver_options["maxh"] is None:
solver_options["maxh"] = 0.0 # no maximum step, for every Assimulo solver

if "rtol" in solver_options:
rtol_is_vector = (isinstance(self.solver_options["rtol"], np.ndarray) or isinstance(self.solver_options["rtol"], list))
Expand Down
21 changes: 21 additions & 0 deletions tests/test_fmi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,27 @@ def run_case(expected, default="Default"):
opts["with_jacobian"] = True
run_case(True, True)

def test_maxh_option(self):
"""'maxh': "Default" caps at (tf-t0)/ncp, None and 0.0 remove the cap, a value is passed through."""
model = Dummy_FMUModelME2([], os.path.join(file_path, "files", "FMUs", "XML", "ME2.0", "NoState.Example1.fmu"), _connect_dll=False)
opts = model.simulate_options()
opts["result_handling"] = None

def run_case(expected, solver, maxh="Default", ncp=500):
model.reset()
opts["solver"] = solver
opts["ncp"] = ncp
opts[solver + "_options"]["maxh"] = maxh
alg = NoSolveAlg(0.0, 2.0, (), model, opts)
assert alg.simulator.maxh == pytest.approx(expected), alg.simulator.maxh

for solver in ("CVode", "Radau5ODE"):
run_case(2.0 / 500, solver)
run_case(0.0, solver, ncp=0)
run_case(0.0, solver, maxh=None)
run_case(0.0, solver, maxh=0.0)
run_case(0.25, solver, maxh=0.25)

def test_sparse_option(self):

def run_case(expected_jacobian, expected_sparse, fnbr=0, nnz={}, set_sparse=False):
Expand Down