Clear Filters
Clear Filters

Pdepe solver be run in loop for designing a control scheme.

2 views (last 30 days)
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
maria atiq on 13 Feb 2024
The control part i have tested on a simple thermal equation and it works fine.
clc;clear;close all
T_desired = 180; % desired output, or reference point
R=108.6830;
alpha = 3.927*10^-3;
Tref=293.15;
V=0.5;
Kp = 1; % proportional term Kp
Ki = 0.5; % Integral term Ki
Kd = 0.01; % derivative term Kd
dt = 0.01; % sampling time
Time = 10; % total simulation time in seconds
n = round(Time/dt); % number of samples
% pre-assign all the arrays to optimize simulation time
Prop(1:n+1) = 0; Der(1:n+1) = 0; Int(1:n+1) = 0; I(1:n+1) = 0;
PID(1:n+1) = 0;
Temp(1:n+1) = 0;
Output(1:n+1) = 0;
Error(1:n+1) = 0;
state1(1:n+1) = 0; STATE1(1:n+1) = 0;
state2(1:n+1) = 0; STATE2(1:n+1) = 0;
for i = 1:n
Error(i+1) = T_desired - Temp(i); % error entering the PID controller
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
STATE1(i+1) = sum(PID); % sum PID term to calculate the first integration
Output(i+1) = (STATE1(i+1) + STATE1(i))*dt/2; % output after the first integrator
%
Temp(i+1) = ((Output(i+1).^2)/R)*(1-alpha*(Temp(i)-Tref));
end
% plot results
T = 0:dt:Time;
Reference = T_desired*ones(1,i+1);
plot(T,Reference,'r',T,Temp,'b')
xlabel('Time (sec)')
legend('Desired','Simulated')
Torsten
Torsten on 14 Feb 2024
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

Sign in to comment.

Answers (0)

Categories

Find more on Heat and Mass Transfer 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!