1
$\begingroup$

I'm trying to solve a system of one PDE and one ODE that are dependent on time and distance (H[x,t] and P[x,t]) with the distance varying between x = 0 and x = xmax. The value for function P is 0 at x >= xmax/100. H takes positive values between x=0 and x=xmax. The solution I'm expecting is something like this

enter image description here

The solution I'm getting is this

enter image description here

With blue being the solution for H and yellow for P. The problem is that P doesn't drop back to zero at x=xmax/100 as I'm expecting.

I used the following Dirichlet condition for P

DirichletCondition[P[x, t] == 0, x == xmax/100]

but I get the same answer. Maybe I should use a piecewise function but maybe I'm missing something very simple. The full code I'm using is this

(* Function definitions *)

Cxt[name_, xx_,tt_] := (Evaluate[name[x, t] /. x -> xx /. t -> tt] /. sol )*1000

(*Constants*)
f = 38.94; logL = -2;
Ls = 10^logL; a = 0.5;
C1 = 1*^-5; dH = 1*^-6;
Ea = 0.5;
tmax = 40;(*Time in seconds*)
xmax = 10 Sqrt[dH] Sqrt[tmax];(*Maximum distance to simulate.cm*)

(*PDE system*)
eqsH = {D[H[x, t], t] - dH D[H[x, t], x, x] == NeumannValue[Ls Exp[a f Ea] P[x, t] - LsExp[-a f Ea] H[x, t], 
    x == 0], H[x, 0] == 0};

eqsP = {D[P[x, t], t] == NeumannValue[-Ls Exp[a f Ea] P[x, t] + Ls Exp[-a f Ea] H[x, t], 
     x == 0], DirichletCondition[P[x, t] == 0, x == xmax/100],P[x, 0] == 1};

(*Solution of the differential equations*)
prec = 7; msf = 0.001;

sol = NDSolve[{eqsH, eqsP}, {H, P}, {x, 0, xmax}, {t, 0, tmax},AccuracyGoal -> prec, PrecisionGoal -> prec, Method -> {"MethodOfLines","SpatialDiscretization" -> {"FiniteElement"}}] // First // 
   Quiet;
(* Plot *)
Plot[{Cxt[H, x, 10], Cxt[P, x, 10]/15}, {x, 0, xmax}, 
  PlotRange -> All];

Any help or advice in how to get the answer I'm expecting is more than welcome! Thanks!

$\endgroup$
4
  • 1
    $\begingroup$ Boundary condition DirichletCondition[P[x, t] == 0, x == xmax/100] generates error NDSolve::bcnop: No places were found on the boundary where x==1/(500 Sqrt[10]) was True, so DirichletCondition[P==0,x==1/(500 Sqrt[10])] will effectively be ignored. $\endgroup$ Dec 12, 2020 at 0:20
  • 1
    $\begingroup$ Your expectations like "The value for function P is 0 at x >= xmax/100" contradict to the initial condition P[x, 0] == 1 $\endgroup$ Dec 12, 2020 at 12:23
  • $\begingroup$ Thanks for the feedback Alex. $\endgroup$
    – Afmo
    Dec 13, 2020 at 9:21
  • $\begingroup$ Thanks @AlexTrounev you were right the initial conditions wasn't properly written. I solved it by adding a piecewise initial condition. $\endgroup$
    – Afmo
    Dec 17, 2020 at 8:28

1 Answer 1

1
$\begingroup$

The problem was solved by adding a piecewise boundary condition

Initial condition equal to a new function "a"

P[x, 0] == a[x]

Function "a" is a piecewise function

a[x_] := Piecewise[{{Value1, x < xmax/100}, {0, x >= xmax/100}}];

$\endgroup$

Your Answer

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

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