Lack of Boundary Conditions to solve PDE (using pdepe function)
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I'm simulating the internal thermal and chemical dynamics of a fuel cell, using pdepe function (which is new to me). There are plenty of variables ( u1, u2, ..., un ) to be solved. However, I find that for each variable ui added, pdepe asks for boundary conditions (left and right) of ui, which I don't have sometimes.
For a simplified example, I don't know how to give boundary conditions of u2 for the following problem:
Its code is here (modified from MATLAB's example of pdepe):
function pde_example
m = 0;
x = linspace(0,1,20);
t = linspace(0,2,20);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u1, u2.
u1 = sol(:,:,1);
u2 = sol(:,:,2);
% A surface plot of u1.
figure(1)
surf(x,t,u1)
title('Solution of u1')
xlabel('Distance x')
ylabel('Time t')
% A solution profile of u1 at t=2.
figure(2)
plot(x,u1(end,:))
title('Solution of u1 at t = 2')
xlabel('Distance x')
ylabel('u1(x,2)')
% A surface plot of u2.
figure(3)
surf(x,t,u2)
title('Solution of u2.')
xlabel('Distance x')
ylabel('Time t')
% A solution profile of u2 at t=2.
figure(4)
plot(x,u2(end,:))
title('Solution of u2 at t = 2')
xlabel('Distance x')
ylabel('u2(x,2)')
% ----------------------------*PDE part*----------------------------------
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = [pi^2;0];
f = [DuDx(1);0];
s = [0;u(2)-DuDx(1)];
% -----------------------------*IC part*---------------------------------
function u0 = pdex1ic(x)
u0 = [sin(pi*x);pi*cos(pi*x)];
% ----------------------------*BC part*----------------------------------
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = [ul(1); ul(2)-pi*exp(-t)];
ql = [0;0];
pr = [pi*exp(-t); ur(2)+pi*exp(-t)];
qr = [1;0];
It seems that this code can get the appropriate solution of u2 only if boundary conditions of u2 is given (i.e. ul(2)-pi*exp(-t) and ur(2)+pi*exp(-t)), which is obtained manually. If it's true, it will be a disaster for my simulation. Or am I wrong? How to get the appropriate solutions without manual pre-calculation? Thanks a lot!
2 comentarios
Torsten
el 19 de Jun. de 2017
No way to solve this system using "pdepe".
Discretize the first and second equation in space and use ODE15S to solve for T.
The profile for I can be obtained directly in each time step:
dU/dx = 0 gives U=constant. To solve U = f2(dI/dx,T) for I, you will need one boundary condition for I (either at x=0 or x=1). Now if T is given, you can use forward or backward differencing (depending on where the boundary condition for I is given) to solve for I.
Best wishes
Torsten.
Respuestas (1)
Bill Greene
el 19 de Jun. de 2017
In your original code, set your boundary condition function to this:
pl = [ul(1); 0];
ql = [0;1];
pr = [pi*exp(-t); 0];
qr = [1;1];
Since f in your second PDE is zero, this boundary condition doesn't affect the solution but it does satisfy pdepe's requirement for a BC at both ends. This "trick" can often be used to get good solutions from pdepe when one or more of the PDE is only first order.
0 comentarios
Ver también
Categorías
Más información sobre Boundary Conditions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!