-2

I'm trying to perform step by step simulation of a fmu in a for loop. The goal is to dynamically change the input of the model coming from python while keeping variables states between loops.

For now I am trying to simulate a battery fmu in a for loop using do_step() method.

fmu_path = "Battery_CS.fmu"
model = load_fmu(fmu_path)

start_time = 0.0
end_time = 60*60
step_size = 10

CAPACITY = 100 # Capacity in kWh
INIT_SOC = 50 # Initial state of charge in %
POWER = 100e3 # Power in W

time_sim = np.linspace(start_time, end_time, int((end_time - start_time) / step_size))

fmu_path = "Battery_CS.fmu"

model = load_fmu(fmu_path)
model.set("Capacity", CAPACITY)
model.set("Initial_SOC", INIT_SOC)
model.initialize(start_time, end_time)

for time in time_sim:
    model.set("Power", POWER)
    # Perform simulation for the current time step
    res = model.do_step(current_t = time, step_size = step_size)
    print(model.get(["SOC"]))

The output SOC stay the same.

[array([49.72222222])]
[array([49.72222222])]
[array([49.72222222])]
[array([49.72222222])]
[array([49.72222222])]
[array([49.72222222])]

The integrated state of charge is not memorized in the for loop. Any idea on how I could fix it ?

Magleno
  • 1
  • 1
  • Show code if you want answers. Speaking of answers, change the wording to ask a specific question. (side note i didn't downvote) – easleyfixed Aug 31 '23 at 16:08

0 Answers0