0
$\begingroup$

I'm trying to address a mass diffusion problem, and I'm encountering two problems.

m1 = 2;
m2 = 36;
Z1 = 1;
Z2 = 6;
kT = 5;
D0 = 1;
g = 2.1;
n20[z_] := 
  Piecewise[{{1/(1 + Z2)*Exp[-m2*g*z/(1 + Z2)/kT], 
     z >= 0}, {1/(1 + Z2) + z*10, -1/(1 + Z2)/10 < z < 0}}, 0];
sol = NDSolve[{((1 + Z1)*D[n1[z], z] + (1 + Z2)*D[n20[z], z])*
     kT == -(m1*n1[z] + m2*n20[z])*g, n1[1] == 0}, n1[z], {z, -1, 1}]

The first comes from the NDSolve here, where it returns NDSolve::nlnum, however merely turning to DSolve will result in a correct solution.

The second problem appears when I tried to solve the time-dependent problem

sol = NDSolve[{((1 + Z1)*D[n1[z, t], z] + (1 + Z2)*D[n2[z, t], z])*
     kT == -(m1*n1[z, t] + m2*n2[z, t])*g, 
   D[n1[z, t], t] == D[D0*D[n1[z, t], z] + D0/kT*m1*n1[z, t]*g, z], 
   n2[z, 0] == n20[z], n1[1, 0] == 0}, n1, {z, -1, 1}, {t, 0, 1}]

And I get NDSolve::bcedge, which tells me the boundary condition n1[1, 0] == 0 'is not specified on a single edge of the boundary of the domain', which confuses me.

I'm not sure if the two problems are related. Any suggestions will help.

$\endgroup$
3
  • $\begingroup$ "I'm not sure if the two problems are related." They're not related at all. The first question is essentially the same as this previous question of yours: tieba.baidu.com/p/8984592306 , and has been discussed in this site quite a bit, the most recent one is this: mathematica.stackexchange.com/a/304563/1871 , so the simplest answer is, as mentioned in the posts above, use Simplify`PWToUnitStep. As to the second question, as pointed out by Nasser below, your ic and bc is a mess. I can spot at least 2 problems: 1. n1[1, 0] == 0 is not a well-posed constraint in 2D space: ... $\endgroup$
    – xzczd
    Commented Jul 1 at 14:04
  • $\begingroup$ ...: mathematica.stackexchange.com/a/71945/1871 2. The second PDE is just a variation of heat equation (n2 doesn't even involve in here), to determine a solution, boundary condition at z==1 and z==-1 is necessary. $\endgroup$
    – xzczd
    Commented Jul 1 at 14:08
  • $\begingroup$ @xzczd Thanks, I think I'm getting it. Now it seems the same problem as NDSolve needs to process with the derivative of some Piecewise function. $\endgroup$
    – Repentanze
    Commented Jul 2 at 3:17

1 Answer 1

1
$\begingroup$

The first comes from the NDSolve here, where it returns NDSolve::nlnum,

To remove NDSolve::nlnum add this method:

sol=NDSolve[{ode,ic},n1[z],{z,-1,1},Method->{"DiscontinuityProcessing"->None}]

enter image description here

And I get NDSolve::bcedge,

For second one problem, you had the wrong BC/IC. Try this

m1 = 2;
m2 = 36;
Z1 = 1;
Z2 = 6;
kT = 5;
D0 = 1;
g = 2.1;
n20[z_] := 
 Piecewise[{{1/(1 + Z2)*Exp[-m2*g*z/(1 + Z2)/kT], 
    z >= 0}, {1/(1 + Z2) + z*10, -1/(1 + Z2)/10 < z < 0}}, 0]
ode1 = ((1 + Z1)*D[n1[z, t], z] + (1 + Z2)*D[n2[z, t], z])*
   kT == -(m1*n1[z, t] + m2*n2[z, t])*g
ode2 = D[n1[z, t], t] == 
  D[D0*D[n1[z, t], z] + D0/kT*m1*n1[z, t]*g, z]
bc = {n2[z, 0] == n20[z], n1[1, t] == 0}

sol = NDSolve[{ode1, ode2, bc}, n1, {z, -1, 1}, {t, 0, 1}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you! Your modifications removed the warnings immediately. However, the result of the first NDSolve seems incorrect still(which is extremely small), although with a shape similar to the correct result. $\endgroup$
    – Repentanze
    Commented Jul 1 at 8:15
  • $\begingroup$ Now I addressed this problem with an NDSolve option MaxStepSize -> 0.001. $\endgroup$
    – Repentanze
    Commented Jul 1 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.