Pdepe solver be run in loop for designing a control scheme.
Show older comments
Hi, i am designing a control scheme for a thermal system defined by a 2nd order pde. I used pdepe solver to get the solution but driven by input voltage. But in-order-to design a control scehme i need to run the pdepe solver in iterations .please guide.
35 Comments
maria atiq
on 30 Jan 2024
You can save "sol" as a cell array in each iteration as "sol{i}".
But why do you want to save intermediate sol terms if you iterate and get a new "sol" in the next iteration ? Do you want to have a kind of convergence monitor after exiting the iteration loop ?
maria atiq
on 30 Jan 2024
Edited: maria atiq
on 30 Jan 2024
Torsten
on 30 Jan 2024
I think we are unable to help you without some code that clarifies your problem.
maria atiq
on 30 Jan 2024
Edited: maria atiq
on 30 Jan 2024
maria atiq
on 30 Jan 2024
Torsten
on 30 Jan 2024
What does the index i stand for ? The average solution for T over all x-values at time (i*dt) ?
maria atiq
on 30 Jan 2024
maria atiq
on 30 Jan 2024
maria atiq
on 30 Jan 2024
Again my question: What does the index i stand for ? If you solve the heat equation with "pdepe", you get a matrix T as solution where the rows of T stand for the time points t and the columns stand for grid points x. You only use a single scalar T(i+1). I cannot make sense of it.
maria atiq
on 30 Jan 2024
maria atiq
on 7 Feb 2024
Edited: maria atiq
on 7 Feb 2024
maria atiq
on 7 Feb 2024
maria atiq
on 7 Feb 2024
Torsten
on 7 Feb 2024
Ok, I see that your PDE depends somehow on the input C, and you say you want to change C in the loop. But how ?
maria atiq
on 7 Feb 2024
maria atiq
on 7 Feb 2024
Torsten
on 7 Feb 2024
So, the updated voltage value is saved as C.V and it is callled in equation function.
But you don't update C.V depending on sol, do you ?
maria atiq
on 7 Feb 2024
Edited: maria atiq
on 7 Feb 2024
I think this is somehow what you want.
I tried to keep "voltage" of size k, but the PID control as I interpreted it from your code gives me an array of size k-2 in the end which leads to a size dimension mismatch in function "heateqfull1".
Hope you can solve the problem.
dt = 0.000168; % sampling time
Time = 0.01; % total simulation time in seconds
k = round(Time/dt);
T_desired = 200; % desired output, or reference point
Kp = 1; % proportional term Kp
Ki = 0.5005; % Integral term Ki
Kd = 0.001; % derivative term Kd
% pre-assign all the arrays to optimize simulation time
Prop(1:k+1) = 0; Der(1:k+1) = 0; Int(1:k+1) = 0; I(1:k+1) = 0;
PID(1:k+1) = 0;
Temp_avg(1:k+1) = 0;
voltage (1:k) = 0;
Error(1:k+1) = Inf;
state1(1:k+1) = 0; STATE1(1:k+1) = 0;
state2(1:k+1) = 0; STATE2(1:k+1) = 0;
Times = linspace(0,Time,k+1);
m = 1;
x1 = linspace(0,55,10);
x2 = linspace(55.01,59,100);
x3 = linspace(59.01,589,100);
x = cat(2,x1,x2,x3);
ic = @(x) incondfull1(x);
size(Times)
size(voltage)
while max(abs(Error))>1e-2
eqn = @(x,t,T,dTdx) heateqfull1(x,t,T,dTdx,Times,voltage);
m = 1;
sol = pdepe(m,eqn,ic,@boundarycondfull1,x,Times);
for i = 1:k+1
Temp_avg(i) = 2/589^2*trapz(sol(i,:,1).*x);
end
Error = T_desired - Temp_avg;
Prop = Error(2:end);
Der = (Error(2:end)-Error(1:end-1))/dt;
Int = (Error(2:end)-Error(1:end-1))*dt/2;
I = cumsum(Int);
PID = Kp*Prop + Ki*I + Kd*Der;
STATE1 = cumsum(PID);
state2 = (STATE1(2:end)+STATE1(1:end-1))*dt/2;
STATE2 = cumsum(state2);
voltage = (STATE2(2:end) + STATE2(1:end-1))*dt/2;
size(voltage)
end
function [c,f,s] = heateqfull1(x,t,T,dTdx,t_inter,voltage_inter)
%%---------- universal parametrs -------------
tm= 1.7; % thickness of membrane in micrometer
th= 0.3; % thickness of heater in micrometer
rh= 55; % radius of heater in micrometer
rm= 589; % radius of membrane in micrometer
wh= 4; % width of heater in micrometer
r1= 55; % radius of region 1 in micrometer
r2= 59; % radius of region 2 in micrometer
r3= 589; % radius of region 3 in micrometers
k= 1.61*10^-5; % effective thermal conductivity of Si3N4 and SiO2 in W/µmK
ka= 2.623 * 10^-8; % thermal conductivity of air in W/µmK
kw= 0.598 * 10^-6; % thermal conductivity of air in W/µmK
hc= 2*10^-10; % effective heat trasnfer co-efficent in W/µm2K
rho= 2.76*10^-12; % denisty of membrane g/um3
shc= 0.68812; % specific heat capacity of membrane in J/(g*K)
Ta= 293.15; % room temperature in K
kpt= 2.95*10^-5; % effective thermal conductivity of platinum in W/µmK
%%__ resistance of heater depending upon thickness and resistivity ___
rrho= 0.105; % resistivity of platinum in ohm um ; 1.05*10*-7 ohm m 2014 paper
St=1; %2013
Sc=1; %2013
Wc=24; % extrernal wide width contact (nc-ext *wti=12*2=24 )2013
Sj=20; % length of external wide width contact (ns-ext *wti=10*2=20)2013
Sa=6; % 2015 paper supporting documnet as this parameter is not in 2013 paper
Lc=503; % 2015 paper supporting documnet as this parameter is not in 2013 paper
th=0.3; % thickness of heater in um from 2015 paper
Ro=rrho*([(pi*((5*rh)+(6*St)+((25/4)*wh)-(4*Sc)+(2*Sj))/(wh*th))]+[(2*Lc)/(Wc*th)]);
alpha = 3.927*10^-3; % temperature coefficient of resistivity in 1/K
%V =C.V; % voltage for input in Volts
%%-------- specific user defined parameters-----------
ci= (rho*shc)/k;
si=(2*hc)/(k*tm);
sii=1/(2*kpt*pi*r1*wh*tm*Ro);
c = ci;
if x>=0 & x<=55
s=-si *(T-293.15);
f = dTdx;
else if x>=55 & x<=59
for j = 1:numel(t_inter)-1
if t >= t_inter(j) & t <= t_inter(j+1)
V = voltage_inter(j);
break
end
end
s = -(si*(T-293.15))+ [V^2 *(1-(alpha*(T-293.15)))]/sii ;
f = dTdx;
else if x>=59
s=-si *(T-293.15);
f = dTdx;
end
end
end
end
function [pl,ql,pr,qr] = boundarycondfull1(xl,Tl,xr,Tr,t)
pl = 0;
ql = 1;
pr = Tr-293.15 ;
qr = 0;
end
function T0 = incondfull1(x)
T0 = 293.15;
end
I can't understand why you changed
Times = linspace(0,Time,k+1);
to
t = linspace(0,0.01,60);
It makes no sense at all for me.
Given time points t0,...,tk and average temperatures T0,...,Tk over the domain at these time points, you need to compute voltages V1,...,Vk for the time intervals (V1 applied in [t0 t1], V2 applied in [t1 t2],...,Vk applied in [t(k-1) tk]) by your optimal control equations. I made an attempt to get k voltages from your equations, but only got k-2. So you will need to check the commands in the while-loop.
maria atiq
on 10 Feb 2024
maria atiq
on 10 Feb 2024
Torsten
on 10 Feb 2024
You must think about what you want to achieve in your voltage control: You want to find a time-dependent voltage applied for 55<=x<=59 such that nearly from the first time instant on, the average temperature over the length is constantly at T_desired = 100. For me it sounds that this is impossible to achieve.
Bill Greene
on 10 Feb 2024
I know I'm late to this conversation but I was curious so ran the code.
When I print
max(abs(Error))
at the bottom of the while loop, it equals 100 for all iterations.
PS: Is there an introductory reference that describes the controller you are trying to implement?
maria atiq
on 10 Feb 2024
I made an error in the code. It must read
Temp_avg(i) = 2/589^2*trapz(x,sol(i,:,1).*x);
instead of
Temp_avg(i) = 2/589^2*trapz(sol(i,:,1).*x);
I don't have an idea about control theory - so I don't know what's wrong about your PID control scheme.
Maybe you know why the control does not converge.
k = 20;
Times = linspace(0,0.25,k+1);
dt = 0.25/k;
T_desired = 300.0; % desired output, or reference point
Kp = 1; % proportional term Kp
Ki = 0.5005; % Integral term Ki
Kd = 0.001; % derivative term Kd
% pre-assign all the arrays to optimize simulation time
Prop(1:k+1) = 0; Der(1:k+1) = 0; Int(1:k+1) = 0; I(1:k+1) = 0;
PID(1:k+1) = 0;
Temp_avg(1:k+1) = 0;
Temp_avg(1) = 293.15;
voltage (1:k+1) = 0;
Error(1:k+1) = 0;
Error(1) = T_desired - 293.15;
state1(1:k+1) = 0; STATE1(1:k+1) = 0;
state2(1:k+1) = 0; STATE2(1:k+1) = 0;
x1=linspace(0,55,100);
x2=linspace(55.01,59,100);
x3=linspace(59.01,589,100);
x=cat(2,x1,x2,x3);
ic = @(x) incondfull1(x);
m = 1;
%Times = linspace(0,Time,k+1);
for i=1:k
C.V=voltage(i);
eqn = @(x,t,T,dTdx) heateqfull1(x,t,T,dTdx,C);
sol = pdepe(m,eqn,ic,@boundarycondfull1,x,[Times(i),(Times(i)+Times(i+1))/2,Times(i+1)]);
Temp_avg(i+1) = 2/(x(110)^2-x(10)^2)*trapz(x(10:110),sol(end,10:110,1).*x(10:110));
Error(i+1)= T_desired - Temp_avg(i+1);
Prop(i+1) = Error(i+1);% error of proportional term
Der(i+1) = (Error(i+1) - Error(i))/dt; % derivative of the error
Int(i+1) = (Error(i+1) + Error(i))*dt/2; % integration of the error
I(i+1) = sum(Int); % the sum of the integration of the error
PID(i+1) = Kp*Prop(i) + Ki*I(i+1)+ Kd*Der(i); % the three PID terms
%% You can replace the follwoing five lines with your system/hardware/model
STATE1(i+1) = sum(PID); % sum PID term to calculate the first integration
state2(i+1) = (STATE1(i+1) + STATE1(i))*dt/2; % output after the first integrator
STATE2(i+1) = sum(state2); % sum output of first integrator to calculate the second integration
voltage(i+1) = (STATE2(i+1) + STATE2(i))*dt/2;
end
Reference = T_desired*ones(1,numel(Times));
plot(Times,Reference,'r',Times,Temp_avg,'b');
xlabel('Time (sec)')
legend('Desired','Simulated')
function [c,f,s] = heateqfull1(x,t,T,dTdx,C)
%%---------- universal parametrs -------------
tm= 1.7; % thickness of membrane in micrometer
th= 0.3; % thickness of heater in micrometer
rh= 55; % radius of heater in micrometer
rm= 589; % radius of membrane in micrometer
wh= 4; % width of heater in micrometer
r1= 55; % radius of region 1 in micrometer
r2= 59; % radius of region 2 in micrometer
r3= 589; % radius of region 3 in micrometers
k= 1.61*10^-5; % effective thermal conductivity of Si3N4 and SiO2 in W/µmK
ka= 2.623 * 10^-8; % thermal conductivity of air in W/µmK
kw= 0.598 * 10^-6; % thermal conductivity of air in W/µmK
hc= 2*10^-10; % effective heat trasnfer co-efficent in W/µm2K
rho= 2.76*10^-12; % denisty of membrane g/um3
shc= 0.68812; % specific heat capacity of membrane in J/(g*K)
Ta= 293.15; % room temperature in K
kpt= 2.95*10^-5; % effective thermal conductivity of platinum in W/µmK
%%__ resistance of heater depending upon thickness and resistivity ___
rrho= 0.105; % resistivity of platinum in ohm um ; 1.05*10*-7 ohm m 2014 paper
St=1; %2013
Sc=1; %2013
Wc=24; % extrernal wide width contact (nc-ext *wti=12*2=24 )2013
Sj=20; % length of external wide width contact (ns-ext *wti=10*2=20)2013
Sa=6; % 2015 paper supporting documnet as this parameter is not in 2013 paper
Lc=503; % 2015 paper supporting documnet as this parameter is not in 2013 paper
th=0.3; % thickness of heater in um from 2015 paper
Ro=rrho*([(pi*((5*rh)+(6*St)+((25/4)*wh)-(4*Sc)+(2*Sj))/(wh*th))]+[(2*Lc)/(Wc*th)]);
alpha = 3.927*10^-3; % temperature coefficient of resistivity in 1/K
V =C.V; % voltage for input in Volts
%%-------- specific user defined parameters-----------
ci= (rho*shc)/k;
si=(2*hc)/(k*tm);
sii=1/(2*kpt*pi*r1*wh*tm*Ro);
c = ci;
if x>=0 & x<=55
s=-si *(T-293.15);
f = dTdx;
elseif x>55 & x<=59
s = -(si*(T-293.15))+ [V^2 *(1-(alpha*(T-293.15)))]/sii ;
f = dTdx;
else
s=-si *(T-293.15);
f = dTdx;
end
end
function [pl,ql,pr,qr] = boundarycondfull1(xl,Tl,xr,Tr,t)
pl = 0;
ql = 1;
pr = Tr-293.15 ;
qr = 0;
end
function T0 = incondfull1(x)
T0 = 293.15;
end
Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

