2
$\begingroup$

The following code runs with BC1 (Dirichlet Type). However, it fails for Dancwerts type BC1.

Remove["Global`*"]
\[Rho]b = 651.52; \[Epsilon] = 0.59; Dia = 0.025; u = (.5*10^-6/60)/(Pi/4*Dia^2); L = 0.15; 
kc = 0.3217*10^-4; DL = 4.0259*10^-6; KL = .078; qm = 9*10^-3; C0 = 100*10^-6/10^-3;

Eq1 = D[Conc[t, z], t] + u* D[Conc[t, z], z] - DL* D[Conc[t, z], z, z] + (\[Rho]b/\[Epsilon])D[q[t, z], t] == 0;
Eq2 = D[q[t, z], t] == kc*(Conc[t, z] - q[t, z]/(KL (qm - q[t, z])));
IC1 = Conc[0, z] == 0;
IC2 = q[0, z] == 0;
(*BC1=(Conc[t,0]-DL/u *D[Conc[t,z],z])/.z\[Rule]0.00*) (*DANCKWERTS BC1*)
BC1 = Conc[t, 0];
BC2 = D[Conc[t, z], z] /. z -> L;

Soln = NDSolve[{Eq1, Eq2, IC1, IC2, BC1 == C0, BC2 == 0}, {Conc, q}, {t, 0, 10000}, {z, 0, L},Method -> {"Shooting", "StartingInitialConditions" -> {BC1 == C0}}, Method -> {StiffnessSwitching, Method -> {ExplicitRungeKutta, Automatic}}] 

Plot3D[Evaluate[Conc[t, z] /. Soln], {t, 0, 10000}, {z, 0.00, L}, PlotRange -> All] 
Plot[Evaluate[Conc[t, L] /. Soln], {t, 0, 10000}, PlotRange -> {0, C0}] 
Table[Flatten[{t, Evaluate[Conc[t, L] /. Soln]}], {t, 0, 10000, 500}] // TableForm
$\endgroup$
4
  • 1
    $\begingroup$ You specify: Conc[0, z] == 0; and Conc[t, 0]== C0 what is not consistent at {x,y}=={0,0} $\endgroup$ Commented Apr 7, 2022 at 14:44
  • $\begingroup$ Yes, You are right: NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent. However, NDSolve still yields answer but with BC1 = Conc[t, 0] and it fails with Danckwerts BC1, i.e. BC1=(Conc[t,0]-DL/u *D[Conc[t,z],z])/.z[Rule]0.00. The main problem is Danckwerts BC1 and not the inconsistent IC/BC. $\endgroup$
    – user85941
    Commented Apr 7, 2022 at 15:23
  • 1
    $\begingroup$ You should upload a picture of the result for BC1=Conc[t,0] vs when BC1=danckwertz... to emphasize the desired result (certainly not identically 0). Also, I don't know BC specifications very well, but is it possible to solve an ODE to specify Conc in full a t=0? $\endgroup$
    – Adam
    Commented Apr 8, 2022 at 5:07
  • 1
    $\begingroup$ @user85941 This problem can be solved with using Mathematica FEM. See Help, ref/NeumannValue, Robin boundary conditions. $\endgroup$ Commented Apr 8, 2022 at 8:07

1 Answer 1

3
$\begingroup$

This problem can be solved with using Mathematica FEM. Let put u = -(.5*10^-6/60)/(Pi/4*Dia^2); and define Eq1 in accordance with Mathematica FEM as follows

Eq1 = D[Conc[t, z], t] - u*D[Conc[t, z], z] - 
   DL*D[Conc[t, z], z, z] + (\[Rho]b/\[Epsilon]) D[q[t, z], t];

Then Dancwerts type BC1 is

BC1 = (-u Conc[t, z] - DL*D[Conc[t, z], z]) /. z -> 0.00 

BC1 in FEM notation equals to BC1 = NeumannValue[-u (C0 - Conc[t, z]), z == 0]. From the other side BC2 = D[Conc[t, z], z] /. z -> L equals to BC2 = NeumannValue[0, z == L]. Therefore, code in FEM notation can be written as follows

Clear["Global`*"]
\[Rho]b = 651.52; \[Epsilon] = 0.59; Dia = 0.025; u = -(.5*10^-6/
      60)/(Pi/4*Dia^2); L = 0.15;
kc = 0.3217*10^-4; DL = 4.0259*10^-6; KL = .078; qm = 9*10^-3; C0 = 
 100*10^-6/10^-3;

Eq1 = D[Conc[t, z], t] - u*D[Conc[t, z], z] - 
   DL*D[Conc[t, z], z, z] + (\[Rho]b/\[Epsilon]) D[q[t, z], t];
Eq2 = D[q[t, z], t] == kc*(Conc[t, z] - q[t, z]/(KL (qm - q[t, z])));
IC1 = Conc[0, z] == 0;
IC2 = q[0, z] == 0;
(*BC1=Conc[t,0];*)
BC1 = NeumannValue[-u (C0 - Conc[t, z]), 
  z == 0];(*DANCKWERTS \
BC1=(Conc[t,0]-DL/u*D[Conc[t,z],z])/.z\[Rule]0.00*)

Soln = NDSolve[{Eq1 == BC1, Eq2, IC1, IC2}, {Conc, q}, {t, 0, 
   10000}, {z, 0, L}];

Visualization

{Plot3D[Evaluate[Conc[t, z] /. Soln], {t, 0, 10000}, {z, 0.00, L}, 
  PlotRange -> All, AxesLabel -> Automatic, PlotTheme -> "Marketing", 
  ColorFunction -> "Rainbow", MeshStyle -> White],
 Plot[Evaluate[{Conc[t, L], Conc[t, 0]} /. Soln], {t, 0, 10000}, 
  PlotRange -> {0, C0}, AxesLabel -> Automatic], 
 Plot[Evaluate[Table[Conc[t, z] /. Soln, {t, 1000, 10000, 1000}]], {z,
    0, L}, PlotRange -> {0, C0}, AxesLabel -> Automatic],
 Table[Flatten[{t, Evaluate[Conc[t, 0] /. Soln]}], {t, 0, 10000, 
    500}] // TableForm}

Figure 1

Note, that this solution computed on the mesh with 20 elements only,

Conc["ElementMesh"] /. Soln

Out[]= {NDSolve`FEM`ElementMesh[{{0., 
    0.15}}, {NDSolve`FEM`LineElement["<" 20 ">"]}]}  

Boundary conditions at z=0and z=L

{Show[Plot[(-u Conc[t, 0] - DL Derivative[0, 1][Conc][t, 0]) /. 
    Soln, {t, 0, 10000}, PlotRange -> All], 
  ListPlot[Table[{t, -u C0}, {t, 1000, 10000, 1000}], 
   PlotStyle -> Red]], 
 Plot[Derivative[0, 1][Conc][t, L] /. Soln, {t, 0, 10000}, 
  PlotRange -> All]}

Figure 2

We can also compute solution with DirichletCondition[] as follows

BC1 = Conc[t, 0];
BC2 = D[Conc[t, z], z] /. z -> L;

Sol0 = NDSolve[{Eq1 == 0, Eq2, IC1, IC2, 
    DirichletCondition[Conc[t, z] == C0, z == 0]}, {Conc, q}, {t, 0, 
    10000}, {z, 0, L}];


{Plot3D[Evaluate[Conc[t, z] /. Sol0], {t, 0, 10000}, {z, 0.00, L}, 
  PlotRange -> All],
 Plot[Evaluate[{Conc[t, L], Conc[t, 0]} /. Sol0], {t, 0, 10000}, 
  PlotRange -> {0, C0}, AxesLabel -> Automatic], 
 Plot[Derivative[0, 1][Conc][t, L] /. Sol0, {t, 0, 10000}],
 Table[Flatten[{t, Evaluate[Conc[t, L] /. Sol0]}], {t, 0, 10000, 
    500}] // TableForm}

Figure 3

$\endgroup$
4
  • $\begingroup$ Thanks Mr. Alex for your excellent code no. 2 for Dirichlet BC. I pasted it and it ran successfully, matching with my previous code for same Dirichlet BC (same numerical values, curves etc). Albeit your code was SMARTER!!! Also, I learnt something about FEM. $\endgroup$
    – user85941
    Commented Apr 8, 2022 at 16:23
  • $\begingroup$ Thanks Mr. Alex for your Excellent code no. 2 for Dirichlet BC. I pasted and run successfully (matching with my previous results for Dirichlet BC i.e. same values, 2D/3D curves etc). Albeit your code was SMARTER one!!! Also, I learnt a new part ie MathematicaFEM. However, when i pasted your code no. 1 for Neumann BC (actually an intelligent way of Danckwerts BC1), I am getting two errors: (1) NDSolve::bcart: Warning: an insufficient number of boundary conditions .... Artificial boundary effects ..... (2) NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.`. Plz help... $\endgroup$
    – user85941
    Commented Apr 8, 2022 at 16:35
  • $\begingroup$ Thanks Mr Alex. got my answer! actually we dont have to use IC2 in your code. BTW thanks again. Will ask u more about similar problems. also, pl tell a book good and easy one for getting used to apply FEM/FDM/FVM in Mathematica....a Good one and and EASY one. REGARDS. $\endgroup$
    – user85941
    Commented Apr 8, 2022 at 22:59
  • 2
    $\begingroup$ @user85941 First, see tutorial/NDSolveOverview about numerical methods to solve PDE implemented in Mathematica. There are nice explanation about FEM application on FEMDocumentation/tutorial/FiniteElementOverview , See also second popular method tutorial/NDSolveMethodOfLines. On this Forum we have very nice collection with FEM and FDM numerical examples. See also some topics about numerical methods on community.wolfram.com/dashboard $\endgroup$ Commented Apr 9, 2022 at 2: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.