Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory #111

Merged
merged 3 commits into from
Jul 1, 2024
Merged
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
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
wip - release 0.16.4
- Dont write result file to disk

2024-05-13 - release 0.16.3
- Check omc presence
- Fix packages list
Expand Down
2 changes: 1 addition & 1 deletion otfmi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.16.3"
__version__ = "0.16.4"

from .otfmi import (
FMUFunction,
Expand Down
47 changes: 22 additions & 25 deletions otfmi/fmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Phimeca Engineering (Sylvain Girard, girard@phimeca.com).
"""Utility functions for common FMU manipulations."""

import io
import pyfmi
import numpy as np
import os
import tempfile
import warnings
import otfmi

Expand All @@ -28,22 +27,16 @@ def load_fmu(path_fmu, kind=None, **kwargs):

"""

# pyfmi writes a log in current folder even with log_level=0
log_file_name = (
""
if os.access(".", os.W_OK)
else os.path.join(
tempfile.gettempdir(), os.path.basename(path_fmu) + "_log.txt"
)
)
# pyfmi writes a log file in current folder even with log_level=0
kwargs.setdefault("log_file_name", io.StringIO())

if kind is None:
try:
return pyfmi.load_fmu(path_fmu, kind="CS", log_file_name=log_file_name)
return pyfmi.load_fmu(path_fmu, kind="CS", **kwargs)
except pyfmi.fmi.FMUException:
return pyfmi.load_fmu(path_fmu, kind="auto", log_file_name=log_file_name)
return pyfmi.load_fmu(path_fmu, kind="auto", **kwargs)
else:
return pyfmi.load_fmu(path_fmu, kind=kind, log_file_name=log_file_name)
return pyfmi.load_fmu(path_fmu, kind=kind, **kwargs)


def simulate(
Expand Down Expand Up @@ -99,22 +92,32 @@ def parse_kwargs_simulate(
----------
value_input : Vector or array-like with time steps as rows.

name_input : Sequence of string, input names.
name_input : Sequence of string
input names.

name_output : Sequence of string, output names.
name_output : Sequence of string
output names

model : fmu model.
model : pyfmi.FMUModel*
fmu model.
"""

value_input_array = reshape_input(value_input, len(name_input))
time, kwargs = guess_time(value_input_array, **kwargs)

kwargs.setdefault("options", kwargs.pop("dict_option", dict())) # alias.
kwargs["options"]["filter"] = name_output
options = kwargs.pop("dict_option", dict())

# store only interest variables
options.setdefault("filter", name_output)

# store results in memory instead of binary file, cleaner and a bit faster
options.setdefault("result_handling", "memory")

# only available for CS model
if "FMUModelCS" in model.__class__.__name__:
kwargs["options"]["silent_mode"] = True
options.setdefault("silent_mode", True)

kwargs["options"] = options

if len(time) > 1:
kwargs.setdefault("start_time", time[0])
Expand Down Expand Up @@ -157,12 +160,6 @@ def parse_kwargs_simulate(
if len(name_input_fmi) > 0:
kwargs["input"] = (name_input_fmi, np.column_stack((time, value_input_fmi)))

# pyfmi writes a result file in current folder
if not os.access(".", os.W_OK):
kwargs["options"]["result_file_name"] = os.path.join(
tempfile.gettempdir(), model.get_identifier() + "_result.mat"
)

return kwargs


Expand Down