The following piece of code
(* DEFINITIONS *)
mol[n_Integer, o_: "Pseudospectral"] := {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> n,
"MinPoints" -> n, "DifferenceOrder" -> o}}
f[t_] := Exp[t]/(1 + Exp[t])
step[t_] := f[(t - 1/2)*(100)] - f[(0 - 1/2)*(100)]
(* I tried to make sure that step[t] is exactly zero at t=0 to avoid initial violation of the BC's*)
(* PARAMETERS *)
k = 1/3;
A = 1/40;
yo = 3/10;
(* INTEGRATION*)
s = NDSolve[{
D[v[t, x], t] + v[t, x]*D[v[t, x], x] + k*D[y[t, x], x] ==
0,
D[y[t, x], t] + v[t, x]*D[y[t, x], x] + D[v[t, x], x] == 0,
y[0, x] == yo,
y[t, 0] == yo,
v[0, x] == 0,
v[t, 1] == A*step[t]
}, {v, y}, {x, 0, 1}, {t, 0, 1}, Method -> mol[81]];
(* VISUALIZATION *)
Plot[(v[t, 1] - A*step[t]) /. s, {t, 0, 1}, WorkingPrecision -> 100,
PlotPoints -> 400, PlotRange -> All, PlotLabel -> "BC violation"]
results in a plot that shows that BC are violated on their 3rd decimal digit.
Is there any typo or spelling mistake in my code? How can I fix it?
APPENDIX: Another example of violation that gets close to the second decimal digit
(* DEFINITIONS *)
mol[n_Integer, o_: "Pseudospectral"] := {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> n,
"MinPoints" -> n, "DifferenceOrder" -> o}}
f[t_] := Exp[t]/(1 + Exp[t])
step[t_] := f[(t - 1/2)*(100)] - f[(0 - 1/2)*(100)]
(* PARAMETERS *)
λ = 1/3;
A = 1/6;
yo = 2/10;
(* INTEGRATION*)
s = NDSolve[{
D[v[t, x], t] + v[t, x]*D[v[t, x], x] + λ*D[y[t, x], x] ==
0,
D[y[t, x], t] + v[t, x]*D[y[t, x], x] + D[v[t, x], x] == 0,
y[0, x] == yo,
y[t, 0] == yo + A*step[t],
v[0, x] == 0,
v[t, 1] == 0
}, {v, y}, {x, 0, 1}, {t, 0, 1}(*,Method\[Rule]mol[81]*),
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MaxPoints" -> 2001, "MinPoints" -> 2001,
"DifferenceOrder" -> Automatic}} ];
(* VISUALIZATION *)
Plot[(y[t, 0] - yo - A*step[t]) /. s, {t, 0, 1},
WorkingPrecision -> 100, PlotPoints -> 400, PlotRange -> All,
PlotLabel -> "BC violation"]
Plot[(v[t, 1]) /. s, {t, 0, 1}, WorkingPrecision -> 100,
PlotPoints -> 400, PlotRange -> All, PlotLabel -> "BC violation"]


