Skip to content

Using the latest fmpy to calculate fmu3.0, using matrix input, why always get an error? Someone help me!! #641

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

Open
Redlargeforest opened this issue Mar 30, 2025 · 0 comments

Comments

@Redlargeforest
Copy link

Redlargeforest commented Mar 30, 2025

fmu version 3.0 has been uploaded

fmu_vector(2).zip
My python code is as follows:

import fmpy
import numpy as np
from fmpy.simulation import Input

fmu_path = 'fmu_vector(2).fmu'
model_description = fmpy.read_model_description(fmu_path)


u_var = next(var for var in model_description.modelVariables if var.name == 'u' and var.causality == 'input')
print(f"Input variable 'u' type: {u_var.type}, shape: {u_var.shape}")

start_values = {
    'm': 3,
    'n': 3,
    'k': 3,
    'u': [1, 2, 3, 4, 5, 6, 7, 8, 9]
}


dtype = [('time', np.float64), ('u', np.float64, 9)]
input_signals = np.array([
    (0.0, [1, 2, 3, 4, 5, 6, 7, 8, 9]),
    (1.0, [2, 2, 3, 4, 5, 6, 7, 8, 9]),
], dtype=dtype)


result = fmpy.simulate_fmu(
    fmu_path,
    start_time=0.0,
    stop_time=2.0,
    start_values=start_values,
    output_interval=2,
    input=input_signals,
    output=['y']
)


print("Simulation results:", result.dtype.names)
print(result)

Error reported as follows:

Traceback (most recent call last):
File "F:\python\PythonProject\udf\FMPYceshi\ceshi.py", line 28, in
result = fmpy.simulate_fmu(
File "F:\python\PythonProject\udf.venv\lib\site-packages\fmpy\simulation.py", line 761, in simulate_fmu
result = simulateCS(model_description, fmu, start_time, stop_time, relative_tolerance, start_values, apply_default_start_values, input, output, output_interval, timeout, step_finished, set_input_derivatives, use_event_mode, early_return_allowed, validate, initialize, terminate, set_stop_time)
File "F:\python\PythonProject\udf.venv\lib\site-packages\fmpy\simulation.py", line 1209, in simulateCS
input.apply(time)
File "F:\python\PythonProject\udf.venv\lib\site-packages\fmpy\simulation.py", line 319, in apply
values[:], derivatives[:] = self.interpolate(time=time, t=self.t, table=table, discrete=False, after_event=after_event)
TypeError: only length-1 arrays can be converted to Python scalars
Kneeling and pleading for assistance!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant