pdepe function maximum value
显示 更早的评论
Hello,
I want to solve Fick's second law of diffusion using the pdepe function, where w is the concentration of a species in a solid and D is the diffusion coefficient
- ∂w/∂t=∂/∂x(D ∂w/∂x)
I defined the following parameters
- c=1 m=0 s=0 and f=D ∂w(x,t)/∂x
I made a function to define D
My boundary conditions are (at x=0 and x=L)
- -D ∂w(0,t)/∂x=beta
- -D ∂w(L,t)/∂x=0
Since boundaries are defined as p+qf=0 I've set
- pl=beta
- ql=1
- pr=0
- qr=1
My code seems to work just fine. The concentration w at point x=0 grows with time and numerically, the way I’ve written the code, it has no limit but physically it cannot surpass a saturation concentration Cp. Is there a way to set a maximum to the function? I do not know how to translate this to the code or even where I can add this condition.I would like a code that sets w(0,t)=Cp whenever, w(0,t) ≥Cp
Thanks
12 个评论
Torsten
2018-3-7
Usual boundary condition at x=0:
D*dw/dx = k*(w-Cp)
Best wishes
Torsten.
FM
2018-3-8
Torsten
2018-3-8
Then you could make several computations for different k-values ...
FM
2018-3-8
ql = 1.0;
if ul <= Cp
pl = beta;
else
pl = 0.0;
end
FM
2018-3-8
if ul <= Cp
ql = 1.0;
pl = beta;
else
ql = 0.0;
pl = ul - Cp;
end
If this does not work, stop the solver when ul reaches Cp and restart it with the new boundary condition.
Best wishes
Torsten.
FM
2018-3-8
Torsten
2018-3-8
sol = pdepe(m,pdefun,icfun,@(xl,ul,xr,ur,t)bcfun(xl,ul,xr,ur,t,ichoice),xmesh,tspan)
...
[pl, ql, pr, qr] = bcfun(xl,ul,xr,ur,t,ichoice)
...
FM
2018-3-8
FM
2018-3-9
Torsten
2018-3-9
Please show your code.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!