1. The associated geometry and mesh for my problem is given below:
2. The PDE is as follows:
General form accepted by PDE Toolbox (as detailed in documentation):
where
such that the PDE reduces to the heat diffusion equation with no generation: where
are the density, specific heat capacity and thermal conductivity respectively (and all are constant). Of course in this scenario, the dependent variable u represents the temperature. Example main function code for solving this in the PDE toolbox is given below (please excuse its length, and the fact that I have it as a function):
function [model,results,transition,tlist] = lumpedmain()
clc;clear;close all;clear global;
format LONGG
global m
global n
global tlist
global transition
global packX
global packY
global packZ
global qsolar
global qalbedo
global qplanetary
global e
global a
global sigma
global results
model = createpde;
packX = 80;
packY = 40;
packZ = 65;
R1 = [3;4;0;packX;packX;0;0;0;packY;packY];
gd = [R1];
ns = char('R1');
ns = ns';
sf = 'R1';
g = decsg(gd,sf,ns);
geometryFromEdges(model,g);
mesh = generateMesh(model,'Hmin',5,'Hmax',20);
figure
pdegplot(g,'EdgeLabels','on','FaceLabels','on')
xlabel('x (mm)')
ylabel('y (mm)')
grid on
xlim([0 packX])
ylim([0 packY])
figure
pdemesh(mesh)
xlabel('x (mm)')
ylabel('y (mm)')
xlim([0 packX])
ylim([0 packY])
c = struct2cell(importdata('200113 - Drive Cycle Test 1_CB1.txt'));
c = c(1,1);
fm = cell2mat(c);
m = fm(11633:24177,:);
x = m(1,2);
for i = 1:length(m)
m(i,2) = m (i,2) - x;
end
m = m(1:11577,:);
m(end,3) = m(1,3);
n = 200;
orbit = m(:,2);
tlistrough = orbit;
if n > 1
for i = 2:n
tlistrough = [tlistrough;(orbit+(i-1)*orbit(end))];
end
end
tlist = zeros(length(tlistrough),1);
dt = 0.500000023739631;
tlist = linspace(tlistrough(1),tlistrough(end),length(tlist));
tlist = tlist';
mlong = m;
if n > 1
for i = 2:n
mlong = [mlong;m];
end
end
j = 1;
for i = 2:(length(mlong)-1)
dI = mlong(i,4)-mlong(i-1,4);
if abs(dI) > 143
transitionrough(j,1) = i-1;
j = j + 1;
end
end
transitionrough(1) = 1;
transitionrough(length(transitionrough)+1) = length(tlist);
dx = 0;
j = 1;
for i = 1:(length(transitionrough)-1)
dx = transitionrough(i+1)-transitionrough(i);
if abs(dx) > 10
transition(j) = transitionrough(i);
j = j + 1;
end
transition(j) = transitionrough(end);
end
transition = transition';
albedo = 0.35;
F = 0.7;
Js = 1371;
Ja = Js*albedo*F;
z = 550000;
Rrad = 6371000;
Rorbit = Rrad+z;
Jp = 237*(Rrad/Rorbit)^2;
sigma = 5.67*(10^(-8));
e = 0.63;
a = 0.40;
qsolar = a*Js*(packZ/1000);
qalbedo = a*Ja*(packZ/1000);
qplanetary = e*Jp*(packZ/1000);
k = 9;
rho = 1792.5;
cp = 1395;
specifyCoefficients(model,'m',0,...
'd',rho*cp*(packZ/1000),...
'c',k*(packZ/1000),...
'a',0,...
'f',0,...
'Face',1);
applyBoundaryCondition(model,'neumann','Edge',1,'q',0,...
'g',0);
applyBoundaryCondition(model,'neumann','Edge',3,'q',0,...
'g',0);
applyBoundaryCondition(model,'neumann','Edge',2,'q',0,...
'g',@gcoef_sun);
applyBoundaryCondition(model,'neumann','Edge',4,'q',0,...
'g',@gcoef_planet);
T0 = 318;
setInitialConditions(model,T0);
results = solvepde(model,tlist);
nodes_right = findNodes(results.Mesh,'region','Edge',2);
nodes_left = findNodes(results.Mesh,'region','Edge',4);
for i = 1:length(nodes_right)
T_right(i,:) = results.NodalSolution(nodes_right(i),:);
end
for i = 1:length(nodes_left)
T_left(i,:) = results.NodalSolution(nodes_left(i),:);
end
numorb = tlist/5787.47027489007;
figure
plot(numorb,mean(results.NodalSolution)-273.15,'r')
ylabel('Mean pack temperature (\circC)')
xlabel('Number of Orbits')
xlim([0,numorb(end)]);
grid on
grid minor
figure
plot(numorb,mean(T_right)-273.15)
ylabel('Mean Temperature (\circC)')
xlabel('Number of Orbits')
xlim([0,numorb(end)]);
grid on
grid minor
hold on
plot(numorb,mean(T_left)-273.15)
lgd2 = legend('Sun-facing','Earth-facing','location','best');
end
NOTE: I have attached the data '200113 - Drive Cycle Test 1_CB1.txt' needed when setting up tlist to this thread.
3. The boundary conditions are as follows:
E1 - Isolated, heat flux = 0
E2 - Neumann condition
where E3 - Isolated, heat flux = 0
E4 - Neumann condition
where where
are the emmisivity and Stefan-Boltzmann constant, respectively.
is the depth into the page, applied throughout to convert into W/m. These boundary conditions are supposed to simulate a body in orbit around the Earth, such that the inward radiation flux from the sun on E2, and the inward planetary and albedo radiation flux on E4 vary with position (and thus time). The outward radiation from the body is always present.
Example code for the functions gcoef_sun and gcoef_planet that (attempt) to implement the Neumann conditions are below:
function [g_sun] = gcoef_sun(location,state)
global n
global tlist
global transition
global qsolar
global e
global sigma
global packZ
g_sun = zeros(1,length(location.y));
if(isnan(state.time))
g_sun = NaN;
else
if state.time == 0
g_sun(1,:) = (-1)*(e)*(sigma)*((state.u)^4)*(packZ/1000);
else
for i = 2:2:2*n
if state.time > tlist(transition(i-1,1),1) && state.time <= tlist(transition(i,1),1)
g_sun(1,:) = (-1)*(e)*(sigma)*((state.u)^4)*(packZ/1000);
elseif state.time > tlist(transition(i,1),1) && state.time <= tlist(transition(i+1,1),1)
g_sun(1,:) = qsolar + (-1)*(e)*(sigma)*((state.u)^4)*(packZ/1000);
end
end
end
end
end
function [g_planet] = gcoef_planet(location,state)
global n
global tlist
global transition
global qalbedo
global qplanetary
global e
global sigma
global packZ
g_planet = zeros(1,length(location.y));
if(isnan(state.time))
g_planet = NaN;
else
if state.time == 0
g_planet(1,:) = qplanetary + (-1)*(e)*(sigma)*((state.u)^4)*(packZ/1000);
else
for i = 2:2:2*n
if state.time > tlist(transition(i-1,1),1) && state.time <= tlist(transition(i,1),1)
g_planet(1,:) = qplanetary + (-1)*(e)*(sigma)*((state.u)^4)*(packZ/1000);
elseif state.time > tlist(transition(i,1),1) && state.time <= tlist(transition(i+1,1),1)
g_planet(1,:) = qplanetary + qalbedo + (-1)*(e)*(sigma)*((state.u)^4)*(packZ/1000);
end
end
end
end
end
4. The results are as follows:
For n=100 and n=200 orbits (Note - for n=100 the simulation takes ~30 minutes, for n=200 it takes in excess of 3 hours. The exact number of orbits is specified within the %% Specify time domain by number of orbits section of the main function, set this accordingly to run the simulation for as long as desired):
I should note that each orbit corresponds to around 5790 s (just under 100 minutes), and here I am solving in steps of ~0.5 s (due to the frequency at which data was sampled - see main function above).
5. Issue
Clearly these two results are not consistent. In the top two plots it seems as if the system is approaching steady-state, but in the bottom two plots there is this strange behaviour that begins around the 70th orbit that is not there for the simulation with n=100. The only thing I have changed between running these two simualtions was the variable n, nothing else. For whatever reason MATLAB is misbehaving.
What could be the cause of this misbehaviour?
I suspect that my boundary conditions may be the issue, but if somebody could please shed some light on this I would greatly appreciate the help. Apologies for the long thread.