0

I've got this equation from mathematical model to know the thermal behavior of a battery.

dTsdt = Ts * a+ Ta * b + dTadt * c + d

However, i can't get to solve it due to the nested derivatives.

I need to solve the equation for Ts and Ta. I tried to define it as follows, but python does not like it and several eŕrors show up. Im using scipy.integrate and the solver ODEint

Since the model takes data from vectors, it has to be solved for every time step and record the output accordingly. I also tried assinging the derivatives to a variable v1,v2, and then put everything in an equation without derivatives like the second approach shown as follows.

def Tmodel(z,t,a,b,c,d):
    Ts,Ta= z
    dTsdt = Ts*a+ Ta*b + dTadt*c+ d
    dzdt=[dTsdt]
    return dzdt

z0=[0,0]
# solve ODE
for i in range(0,n-1):
   
    tspan = [t[i],t[i+1]]
    # solve for next step
    z = odeint(Tmodel,z0,tspan,arg=(a[i],b[i],c[i],d[i],))
    # store solution for plotting
    Ts[i] = z[1][0]
    Ta[i] = z[1][1]
    # next initial condition
    z0 = z[1]

def Tmodel(z,t,a,b,c,d):
    Ts,v1,Ta,v2= z
# v1= dTsdt
# v2= dTadt
    v1 = Ts*a+ Ta*b + v2*c+ d
    dzdt=[v1,v2]
    return dzdt


That did not work either.I believe there might be a solver capable of solving that equation or the equation must be decouple in a way and solve accordingly.

Any advice on how to solve such eqtn with python would be appreciate it.

Best regards,

MM

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • You need two equations if there are two unknowns Ta and Ts. That's your problem. Where does the 2nd equation come from? – duffymo Nov 16 '22 at 18:19
  • There is no second equation. I understand your point,however, while solving the model, those variables were the only ones dependant on time. – Mauricio Mejia Nov 16 '22 at 18:22
  • You may not know what the 2nd equation is, but there is one. Ts(t) and Ta(t) are two functions of time. You need both to solve this: two ODEs. This reference looks different from yours: https://www.sciencedirect.com/science/article/pii/S1388248121000953 – duffymo Nov 16 '22 at 18:29
  • The formulation starts similarly from the following approach : Cp x d [Ax(Ts-Ta)/B + Ts ]/ dt = a+ C x[(Ts-Ta)/B + Ts] - Ta x D since Ts and Ta are taken as variables over time: we get dTsdt and dTadt. That's basically the core of the model which throws only one equation. – Mauricio Mejia Nov 16 '22 at 18:51
  • What are Ta and Ts? Perhaps a discussion of the physics would help. – duffymo Nov 16 '22 at 18:56
  • Ta = Ambient temperature Ts = Surface temperature of the component. – Mauricio Mejia Nov 16 '22 at 19:00
  • Ah! Ambient temperature could be a known function. You would plug that into the equation for surface temperature and solve for dTs/dt. That's why you only have one equation. You can assume something sensible for Ta as a function of time - constant or sinusoid with (min, max) ambient temperatures. – duffymo Nov 16 '22 at 19:21
  • Well, I actually assumed Ta to be a constant in the mathematical model, and I was able to solve dTsdt, because there was no other derivative but dTsdt. However, Ta does vary over the time, there is a Ta value for every time step, which I have in a vector and used to feed the solver in every iteration. But as mentioned, it looks like Ta has to be taken as function of time. – Mauricio Mejia Nov 16 '22 at 21:54
  • If I understood correctly, you suggest to define Ta(t) as constant (which would update according to the vector), and define the function like : def Tmodel(z,t,a,b,c,d): Ts,Ta= z dTsdt = Ts*a+ Ta*b + dTadt*c+ d dTadt = 2*Ta ?? dzdt=[dTsdt,dTadt] return dzdt – Mauricio Mejia Nov 16 '22 at 22:07
  • Right, if you assume the ambient temperature is constant, the derivative dTa/dt = 0 and you're left with a single linear ODE that you can integrate in closed form. – duffymo Nov 17 '22 at 00:29
  • Yes, in fact, I did that approach already. But the model needs more precision so now I'm trying with Ta as a function of time. – Mauricio Mejia Nov 17 '22 at 14:40
  • Here I have the whole approach of the equation, perhaps It can be understood a little bit better. https://docs.google.com/presentation/d/1jv0JIRRxjmIDvcOKupzWxn3-D8rhiRWODhFkaKeeooE/edit?usp=sharing – Mauricio Mejia Nov 17 '22 at 14:41
  • sorry, i forgot to mentioned that I added a new variable which is Rv. – Mauricio Mejia Nov 17 '22 at 14:44

1 Answers1

0

Your difficulty seems to be that you are given Ta in a form with no easy derivative, so you do not know where to take it from. One solution is to avoid this derivative completely and solve the system for y=Ts-c*Ta. Substitute Ts=y+c*Ta in the right side to get

dy/dt = y*a + Ta*(b+c*a) + d

Of course, this requires then a post-processing step Ts=y+c*Ta to get to the requested variable.

If Ta is given as function table, use an interpolation function to get values at any odd time t that is demanded by the ODE solver.

Ta_func = interp1d(Ta_times,Ta_values)

def Tmodel(y,t,a,b,c,d):
    Ta= Ta_func(t)
    dydt = y*a+ Ta*(b+c*a) + d
    return dydt

y[0] = Ts0-c*Ta_func(t[0])

for i in range(len(t)-1):
    y[i+1] = odeint(Tmodel,y[i],t[i:i+2],arg=(a[i],b[i],c[i],d[i],))[-1,0]

Ts = y + c*Ta_func(t)
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • I think I understood partially what you did in your approach. So, at the moment, I have vector of Ta of the same size as the time vector. Based on your suggestion, I can create a function with interp1d() and call it up every time the model is to be solved (which will be for every time step with the respective values). with this function, Im assuming dTadt = Ta, then I solve for dydt. I still do not understand the rest of the approach with the initial condition and the time step increased by 2. :S I would appreaciate more details if possible. – Mauricio Mejia Nov 17 '22 at 15:06
  • I have created a slide with the whole mathematical model approach, in this case, I have also included a new variable Rv which is updated everytime the model solves Ts, since Rv depends on that varaible too. https://docs.google.com/presentation/d/1jv0JIRRxjmIDvcOKupzWxn3-D8rhiRWODhFkaKeeooE/edit?usp=sharing – Mauricio Mejia Nov 17 '22 at 15:08
  • Very nice slide. It makes what you're doing much clearer to me. I'm a mechanical engineer. A good first approximation would be that the convection coefficient on the surface is constant. The dependence of Nusselt number on surface temperature isn't that significant. I would say Ta is a constant as the first approximation, too. There's no way your battery is pumping out so much energy that the ambient far-field temperature will change. – duffymo Nov 17 '22 at 15:28
  • I would not eliminate `Ti` but `Ts` from that equation using the proportionality equation. Then you also will not get additional derivatives. This is in principle the same as above, only that `y` is a different linear combination. // Of course, if `Ta` is a constant, then the problem does not arise from the start. – Lutz Lehmann Nov 17 '22 at 15:28
  • The slide makes it clear to me that you have to have two equations: one for Ti and another for Ts. – duffymo Nov 17 '22 at 15:33
  • I can only think of this additional equations : Qbattery = Qgen - Qdiss Q = h*Area(Ts-Ta) Q = (Ti-Ts)*Kth*Area / L Q = heat h= heat transfer coeff Kth= thermal coeff of the material L= thickness – Mauricio Mejia Nov 17 '22 at 18:23
  • The reason I replaced Ti in the equation is because it is not given. I have Ta as a vector, and the rest of the constants but not Ti (Internal temperature). – Mauricio Mejia Nov 17 '22 at 18:24
  • Of the 3 variables `Ti, Ts, Ta` you can always reconstruct one if the two others are given. `Ta` is given externally, thus it is freely interchangeable what the "active" variable between `Ts` and `Ti` is. – Lutz Lehmann Nov 17 '22 at 18:33
  • Ts is to be found, and is ideally the variable I would like to get as the main output of the model. – Mauricio Mejia Nov 17 '22 at 20:33
  • I only have Ta, Rc and Rv at t=0. Since Rv is calculated from the diference between Ta and Ts(updated as the output of the model at every timestep) – Mauricio Mejia Nov 17 '22 at 20:34