Group Abstract Group Abstract

Message Boards Message Boards

Get numerical solution of PDE for diffusion at high diffusion rates?

I am trying to solve numerically the following PDE with IC and BCs as shown for u(t,x).

\[PartialD]u/\[PartialD]t = \[PartialD]^2u/\[PartialD]x^2 + p Subscript[(\[PartialD]u/\[PartialD]x), x=0]\[PartialD]u/\[PartialD]x
t = 0, u= 0
x= 0, u= 1
x = 1, u = 0

This equation arises in binary diffusion of a species where the diffusion rates are large as opposed to low rates where the second term on the RHS is very small and the PDE becomes identical to the heat conduction equation. This second term accounts for the convective flow induced by the diffusing species. The parameter p is related to the surface concentration of the diffusing species (at x = 0). A closed form solution is available for the case of a semi-infinite region where the last BC becomes x = [Infinity], u = 0. I tried to use NDSolve and NDSolveValue (code shown below) but I got an error message: NDSolveValue::delpde: Delay partial differential equations are not currently supported by NDSolve.

I am unsure if there is (1)a mistake in the code, (2) code is correct but NDSolve cannot provide a solution, or (3) there is a different approach that will work. Would appreciate any help. Thanks.

usolh = NDSolveValue[{D[u[t, x], t] == 
    D[u[t, x], x, x] + 0.5*(D[u[t, x], x] /. x -> 0)*D[u[t, x], x], 
   u[0, x] == 0, u[t, 0] == 1, u[t, 1] == 0}, 
  u, {t, 0, 5}, {x, 0, 1}](*we are assuming p=0.5 here*)
POSTED BY: Rutton Patel
23 Replies

It appears that you are trying to solve the unsteady-state version of the Stefan Tube problem like the figure below where species A is diffusing through stagnant species B.

Stefan Tube

$$\begin{array}{ccccc} N_{A z} & = & -c\mathcal{D}_{A B}\frac{\partial x_A}{\partial z} & + & x_A \left(N_{A z}+N_{B z}\right) \\ \end{array}$$ $$\left\{ {\begin{array}{*{20}{l}} {{\rm{Combined}}}\\ {{\rm{Flux}}} \end{array}} \right\} = \left\{ {\begin{array}{*{20}{l}} {{\rm{Diffusive}}}\\ {{\rm{Flux}}} \end{array}} \right\} + \left\{ {\begin{array}{*{20}{l}} {{\rm{Convective}}}\\ {{\rm{Flux}}} \end{array}} \right\}$$

Since $N_{Bz}$ is zero (stagnant), the equation reduces to

$$N_{A z}=-c\mathcal{D}_{A B}\frac{\partial x_A}{\partial z}+x_A N_{A z}$$

Which can be re-arranged to

$$N_{A z}=-\frac{c \mathcal{D}_{A B}}{1-x_A}\frac{\partial x_A}{\partial z}$$

If in the future you want to use Finite Element Method capabilities, it is conducive to express the equation in coefficient form as shown

$$m\frac{{{\partial ^2}}}{{\partial {t^2}}}u + d\frac{\partial }{{\partial t}}u + \nabla \cdot\left( { - c\nabla u - \alpha u + \gamma } \right) + \beta \cdot\nabla u + au - f = 0$$

The coefficients "c" and "d" are the only non-zero coefficients therefore, we can express your relation as

$$\frac{\partial }{{\partial t}}u + \nabla \cdot\left( { - \frac{1}{1-u}\nabla u } \right) = 0$$

Now, I do not think that you want your parameter $p=0.5$ in the equation, rather that you want to express it as a boundary condition. I added an exponential ramp to eliminate the inconsistent conditions warning.

Re-expressing your relation as Mathematica code, we obtain

usolh = NDSolveValue[{D[u[t, x], t] - 
      D[1/(1 - u[t, x])*(D[u[t, x], x]), x] == 0, u[0, x] == 0, 
    u[t, 0] == 0.5 (1 - Exp[-400 t]), u[t, 1] == 0}, 
   u, {t, 0, 5}, {x, 0, 1}, StartingStepSize -> 0.001];
plt = Plot3D[usolh[t, x], {t, 0., 5.}, {x, 0., 1.}, PlotRange -> All, 
   PlotPoints -> {200, 200}, MaxRecursion -> 4, 
   ColorFunction -> (ColorData["DarkBands"][#3] &), 
   MeshFunctions -> {#2 &}, Mesh -> 20, AxesLabel -> Automatic, 
   MeshStyle -> {Black, Thick}, ImageSize -> Large];
sz = 300;
Grid[{{Show[{plt}, ViewProjection -> "Orthographic", 
    ViewPoint -> Front, ImageSize -> sz, 
    Background -> RGBColor[0.84, 0.92, 1.], Boxed -> False], 
   Show[{plt}, ViewProjection -> "Orthographic", ViewPoint -> Right, 
    ImageSize -> sz, Background -> RGBColor[0.84, 0.92, 1.], 
    Boxed -> False]}, {Show[{plt}, ViewProjection -> "Orthographic", 
    ViewPoint -> Top, ImageSize -> sz, 
    Background -> RGBColor[0.84, 0.92, 1.], Boxed -> False], 
   Show[{plt}, ViewProjection -> "Perspective", 
    ViewPoint -> {Above, Left, Front}, ImageSize -> sz, 
    Background -> RGBColor[0.84, 0.92, 1.], Boxed -> False]}}, 
 Dividers -> Center]

PDE results

After the initial transient, the system achieves steady-state quickly as indicated by the nearly parallel contour lines seen in the lower left image.

POSTED BY: Tim Laska
POSTED BY: Tim Laska
POSTED BY: Tim Laska
POSTED BY: Rutton Patel

Thanks very much for your suggestion. I appreciate the time you have taken to analyze the question I posed. I do not fully understand your code but it appears that you do 10 iterations starting from a linear relation between $u$ and $x$. The first plot shows nice convergence for $u$ vs. $x$ as does the second $u$ vs. $t$. I am puzzled as to why the $u$ vs. $t$ plots for the two methods are quite different. Similarly the 3D plots for the two methods look different.

POSTED BY: Rutton Patel
Anonymous User
Anonymous User
Posted 7 years ago

Also I see Rutton D Patel, Self. got an excellent solution and had to revert it.

Is this a book problem others can refer to a page number of so future work does not end up stale with yet more conditions?

POSTED BY: Anonymous User
Anonymous User
Anonymous User
Posted 7 years ago

I'm too much an amateur to post a sol'n.

But my book says it's often the case measurements are made (with sensors) and later (if found useful) looked back upon in retrospect with pde. The example given was temperature of curing concrete in a dam - that sensors are used.

POSTED BY: Anonymous User
Posted 7 years ago

Very encouraging results, Tim. Really neat and nice!

POSTED BY: Updating Name

Thank you Rutton!

Since $Z$ is a combined variable of z and t, I think you need to multiply the $\phi$ expression by $\sqrt{t}$ to make it equivalent to dimensionless $\mathbf{v}^*$. If we choose the $t=\frac{1}{256}$ again, then we can plot the numerically derived result versus the analytical solution using:

Plot[phiinv[x], {x, 0.01, 0.99}, ImageSize -> Large, Frame -> True, 
 FrameLabel -> {Style["xa0", 18], Style["\[Phi]", 18], 
   Style[StringForm["Dimensionless Interface Flux"], 18]}, 
 Epilog -> {PointSize[0.02], 
   Point[{0.25, ((-Sqrt[t] D[f25[t, x], x])/(1 - 0.25))}] /. {t -> 
      1/256, x -> 0}, 
   Point[{0.5, ((-Sqrt[t] D[f50[t, x], x])/(1 - 0.5))}] /. {t -> 
      1/256, x -> 0}, 
   Point[{0.75, ((-Sqrt[t] D[f75[t, x], x])/(1 - 0.75))}] /. {t -> 
      1/256, x -> 0}}]

Phi comparison

You can see very tight agreement between the analytical our numerical solution for the evaluated points.

POSTED BY: Tim Laska

Thanks very much for the clarification of your code and method. If as you say "vstar" is evaluated only at the interface my objection is inapplicable. I misunderstood in thinking that you were still solving the PDE in your first post which is valid only when $B$ is stagnant for all $z$. I find your code very ingeneous particularly in comparing your results with the semi-infinite case!

In comparing your solution to the semi-infinite solution from BSL, I wonder if you compared your values of vstar to the BSL $\phi$ (which is the same as vstar) for various $x_{\text{A0}}$? That would be very interesting.

Thanks again for your help and interest in this problem.

POSTED BY: Rutton Patel

By rolling your own Method Of Lines (MOL), you get more flexibility on what you can do with the derivatives. If you look at "vstar", then you see it was only evaluated at the interface $u_0$ (note that part 1 of delconc is also at the interface).

vstar = -1/(1 - Subscript[u, 0][t]) delconc[[1]];

So, vstar is evaluated at the interface only where the flux of B is zero and it is only a function of $t$ because its divergence is zero. Therefore, it should satisfy your conditions of only being evaluated at the interface and not throughout the domain.

Regarding the figure 20.1-1, if the characteristic length scale is, $L$, and the characteristic time scale is $\frac{L^2}{D_{AB}}$, then Z using dimensionless units becomes

$$Z=\frac{z}{\sqrt{4t}}$$

Given that figure 20.1-1 has a Z value that goes from 0 to 2 and we know that z is between 0 and 1, we can solve for t in terms of z.

Solve[z/(2*Sqrt[t]) == 2, t]
(* {{t -> z^2/16}} *)

So, I chose $z=\frac{1}{4}<1$ and that meant the time when $Z=2$ was $t=\frac{1}{256}$. Then, I solved for $z$ in terms of $Z$ using.

Solve[bigZ == z/(2*Sqrt[t]), z]
(* {{z -> 2*bigZ*Sqrt[t]}} *)

Taken together, that means the following is the numerically derived $X$ for $x_{A0}=0.5$ @ $z=\frac{1}{4}$ (note that z in the Mathematica implementation is actually $Z$ to avoid beginning with capitals).

f50[1/256, 2 Sqrt[1/256] z]/0.5

If we want to look at the case where $z=1$, then $t=\frac{1}{16}$. Now, instead of following the infinite tube, we expect the numerical result to satisfy the $x_{A0}=0$ boundary condition.

Plot[{bigX[z, 0.75], 
  Callout[f75[1/16, 2 Sqrt[1/16] z]/0.75, "3/4", 1, 
   CalloutMarker -> "CirclePoint"], bigX[z, 0.5], 
  Callout[f50[1/16, 2 Sqrt[1/16] z]/0.5, "1/2", 0.9, 
   CalloutMarker -> "CirclePoint"], bigX[z, 0.25], 
  Callout[f25[1/16, 2 Sqrt[1/16] z]/0.25, "1/4", 0.8, 
   CalloutMarker -> "CirclePoint"], bigX[z, 0]}, {z, 0, 2}, 
 PlotRange -> {0, 1}, GridLines -> Automatic, 
 Filling -> {{1 -> {2}}, {3 -> {4}}, {5 -> {6}}}, 
 PlotStyle -> {Dashed, Thick, Dashed, Thick, Dashed, Thick, Dashed}, 
 ImageSize -> Large, Frame -> True, 
 FrameLabel -> {Style["Z", 18], Style["X", 18], 
   Style[StringForm["Dimensionless Concentration Profiles"], 18]}, 
 PlotLegends -> Placed[legend, {Right, Center}]]

z equal 1 case

It appears that the BC is satisfied.

Now, we can test your assertion that my model does not allow for mass conservation by simply evaluating $N_{Bz}$ at $z=1$. You can use the relations stated previously to derive an expression for the molar flux of B. Start with the dimensionless molar velocity.

$$\mathbf{v}^*=N_A+N_B$$

Use the expression for $N_{B z}$ in terms of $x_A$. $$N_{B z} = \left (1-x_A \right ) \left(N_{A z}+N_{B z}\right)+\frac{\partial x_A}{\partial z} $$

Substitute $\mathbf{v}^*$ for $N_A+N_B$ $$N_{B z} = \left (1-x_A \right ) \mathbf{v}^*+\frac{\partial x_A}{\partial z}$$

Evaluate at the exit ( $z=1$).

$${N_{Bz}} = {\left. {\left( {1 - {x_A}} \right){{\mathbf{v}}^*} + \frac{{\partial {x_A}}}{{\partial z}}} \right|_{z = 1}}$$

Evaluate $\mathbf{v}^*$ at the interface $${N_{Bz}} = {\left. {\left( {\left( {1 - {x_A}} \right)\left( {{{\left. {\frac{1}{{1 - {x_{A,sat}}}}\frac{{\partial {x_A}}}{{\partial z}}} \right|}_{z = 0}}} \right) + \frac{{\partial {x_A}}}{{\partial z}}} \right)} \right|_{z = 1}}$$

We can implement and plot the last equation in Mathematica code for the $x_{A,sat}=0.5$ case.

Plot[((1 - f50[t, 1]) (-D[f50[t, x], x]/(1 - 0.5)) /. {t -> tp, 
     x -> 0}) + ((D[f50[t, x], x]) /. {t -> tp, x -> 1}), {tp, 0.0002,
   0.1}, PlotRange -> {-1, 40}, ImageSize -> Large, Frame -> True, 
 FrameLabel -> {Style["Dimensionless Time", 18], 
   Style["\!\(\*SubscriptBox[\(N\), \(Bz\)]\)", 18], 
   Style[StringForm["Flux of B at z=1"], 18]}]

enter image description here

Now, we did not achieve infinite flux because this is a numerical model, but the flux of B at the exit starts out very high and asymptotically approaches 0 at large t. So, the assertion of the model having zero B flux along the axis is false.

POSTED BY: Tim Laska
Posted 7 years ago
POSTED BY: Updating Name

Neil,

Thanks very much for your suggestion. I have been away, hence the delayed response. I will look at Yi-Lin Chiu's NB.

Regards,

Rutton

POSTED BY: Rutton Patel

@Rutton D Patel, welcome to Wolfram Community! Please make sure you know the rules:

https://wolfr.am/READ-1ST

The rules explain how to format your posts properly. We believe if you read this short guide you will have no problems with posting, as all other members of Community have no trouble with it. We do not except text and code as images in most of the cases. Please in future follow the rules for the proper formatting of your posts.

POSTED BY: EDITORIAL BOARD

Rutton,

At this year's Wolfram Conference, Wolfram developer, Yi-Lin Chiu demonstrated how to handle PDE's for acoustics. While your PDE's will be a bit different, I think this talk will be helpful for generally solving PDE's relating space and time with various boundary conditions in Mathematica.

On this page- search for Modeling Acoustics with Differential Equations

You can use his notebook as a tutorial. I did not compare it to your example, I'd be curious if you find it helpful.

Regards,

Neil

POSTED BY: Neil Singer

Dear Tim,

Your point is well taken and I will think more about it. The MMA tutorial on DDE does not cover PDEs and the examples for ODEs do not contain terms involving the gradient at 0. I guess it is a question to pose to MMA developers.

Thanks, best regards and HAPPY NEW YEAR!

Rutton

POSTED BY: Rutton Patel
POSTED BY: Tim Laska

enter image description here

POSTED BY: Rutton Patel
POSTED BY: Rutton Patel
Posted 7 years ago
POSTED BY: Updating Name

enter image description here

POSTED BY: Rutton Patel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard