Initial Equations in Simscape Custom Models

7 views (last 30 days)
Hello,
I am using a custom component to model a battery in Simscape. The model allows me to enter a lookup table for voltage in terms of the capacity, current and state of charge of the battery and simulate the battery's voltage, current and thermal response. The equations section of my Simscape component are shown below:
equations
assert(SOC >= 0, 'State of charge cannot be less than 0');
assert(SOC <= 1, 'State of charge cannot be greater than 1');
let
% Open circuit voltage
voc = tablelookup(IData, SOCData, VData, {0, 'A'}, SOC, interpolation = smooth, extrapolation = smooth);
in
% State of charge
SOC.der == -i/C;
% Nodal voltage definition
v == p.v - n.v;
% Nodal voltage lookup
v == tablelookup(IData, SOCData, VData, abs(i), SOC, interpolation = smooth, extrapolation = smooth);
% Current dependent capacity
C == tablelookup(IData, CData, abs(i), interpolation = smooth, extrapolation = smooth);
% Temperature
T == H.T;
% Heat generated
qg == abs(i)*(voc - v);
% Heat flow
0 == Q + qg;
end
end
Testing of this model has worked quite well and has been able to match my test data but the initialization of the model is always an issue that I am trying to circumvent.
The model is unable to initialize appropriately when I apply a constant current to the model. For example if I attempt to draw a constant 2 A from the model, the solver will complain of being unable to initialize stating that the initial conditions fail to converge. I believe the issue behind this is because if I begin with a fully charged battery such that State of Charge is 100%, this would be technically when the battery has a 0 A current draw. However when I apply the current of 2 A to the battery, this coupled with the State of Charge initial condition forces the solver to be unable to converge on a solution because it doesn't exist.
I think my guess at this is valid because if I replace the constant current draw with a Step response with a final value of 2 A, the model appropriately initializes and can move forward. This is true, even if I set the Step Time of the Step block to eps = 2.2204e-16 which forces the solver to accept 0 A as the initial condition and then applies the proper 2 A current.
The problem with this is that I don't want to have to constantly utilize a Step block to drive the model at a constant current. I thought that I could bring this behavior inside the model code by using
equations(Initial=true)
i == 0;
end
But this always causes the model to fail regardless of the driving input.
Is there another way to accomplish this beahvior and get what I need or am I stuck with doing a step response for all of my driving inputs?

Answers (2)

Javier Gazzarri
Javier Gazzarri on 14 Mar 2020
Hello Christpher,
Thank you for your inquiry.
I am not sure if I understand your approach, so I have a couple of clarification questions:
  1. You define VOC as a function of current in the first tablelookup function. Can you please explain why an open circuit voltage would depend on current?
  2. Voltage is an across variable per your nodal definition. Is this consistent with also defining it as a look up table right after?
Would it be possible for you to share the block itself so I can try to run it and see if I can spot the issue?
There is a battery cell block in Simscape Electrical that you may want to also consider for this model, which includes SOC and T dependence, as well as aging effects.
Best regards,
Javier
jgazzarr@mathworks.com
  1 Comment
Christopher McNamara
Christopher McNamara on 16 Mar 2020
Hey Javier,
Thanks for the reply.
  1. For the VOC, I am not actually defining it as a function of current. My voltage lookup tables are as a function of current and state of charge and for the VOC I am using the same table but using zero current as the current value by using {0, 'A'} for the current.
  2. I think the across variable and definition as a lookup table is correct. Normally this equation defintion defining the across variable behavior is inherited from the "foundation.electrical.branch" b ut I have only used the nodal definitions from the domain "foundation.electrical.electrical". So the first line defines the across behavior and the second line defines its relationship to the current and state of charge.
I can see if I can share the block itself to get more feedback but I think that is probably done best via email. I am aware of the battery cell block in Simscape Electrical but we do not utilize this package and in general do not need the majority of its features.

Sign in to comment.


Javier Gazzarri
Javier Gazzarri on 16 Mar 2020
Thank you Christopher. I see your point.
The issue with initialization may be the result of this way of defining VOC. There is a very simple alternative to this, that is defining is as a function of SOC and T only, not curent. There is no problem in the look up tables haveing different dimensionalities. Please let me know if you need assistance with this.
If you can indeed share the block please feel free to do so and I'll investigate the issue on my side.
Best regards,
Javier

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!