Hi there. I would like to use the BatteryStateful model through PySAM. I've managed to set it up, but the results don't seem to be correct.
I have created a minimum working example to show this:
I set up a model with the parameters shown in the attached JSON file (
). In my Python code, I set the input power of the battery as 10 kW, and the simulation timestep as 1 minute. Then I executed the model. The energy that is supposed to be absorbed by the battery is 10*1/60 = 0.167 kWh. However, the energy that actually gets absorbed into the battery is 2.89 kWh.
I have attached my python code (
). I also show the code here below, with the output of the script.
The code:
# Import libraries:
from PySAM import BatteryStateful
import json
# Initialize the model:
model = BatteryStateful.new()
with open("mwe.json.txt", 'r') as parameter_file:
data = json.load(parameter_file)
for key, val in data.items():
model.value(key, val)
model.value('dt_hr', 1 / 60) # Run the simulation for a one-minute timestep.
model.value('input_power', -10) # Let the power input be 10 kW.
model.setup()
# Run the model for one timestep, with an input power of 10kW:
model.execute() # Execute the model.
# View the result:
print("Power provided to battery: \n\t10 kW")
print("Power absorbed by battery: \n\t" + str(abs(model.StatePack.P)) + " kW")
print("Energy expected to be absorbed by battery: \n\t" +
str(abs(model.StatePack.P * 1 / 60)) + " kWh")
print("Energy actually absorbed by the battery: \n\t" +
str(model.StatePack.SOC / 100 * model.ParamsPack.nominal_energy) + " kWh")
The output:
Power provided to battery:
10 kW
Power absorbed by battery:
10.000000000000014 kW
Energy expected to be absorbed by battery:
0.1666666666666669 kWh
Energy actually absorbed by the battery:
2.8879938952723645 kWh
I hope you can help me figure out what the reason is for this issue. I hope I am not using the model incorrectly...
Chris