This problem, it seems, has to do with temporal integration, when the "MethodOfLines" is used concurrently with the FEM. When the coefficients are moved to the temporal partial derivative part of the equation the MethodOfLines includes the coefficients in the time integration scheme and not in the FEM spatial discretization, yet this yields the correct solution. The particulars are hard to figure out unless the details of how the "MethodOfLines" together with FEM works in Mathematica are known. The following verifies this. Using Piecewise instead of If below yields the same results (v.12.2).
The problem: the two solutions below yield different results simply because of the position of the coefficients:
sol 1, with coefficients on the spatial derivatives part (this yields incorrect results):
u = NDSolveValue[{D[T[t, x], t] - If[x < 0.4, 0.00093, 0.05405]*D[T[t, x],
x, x] == 0, T[0, x] == 300, T[t, 0] == 300, T[t, 1] == 400}, T, {t, 0,
100}, {x, 0, 1}, Method -> {"MethodOfLines", "SpatialDiscretization" ->
{"FiniteElement", "MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}];
sol 2, with coefficients on the temporal derivative part (this yields correct results):
u = NDSolveValue[{D[T[t, x], t]/If[x < 0.4, 0.00093, 0.05405] - D[T[t, x], x, x] == 0,
T[0, x] == 300, T[t, 0] == 300, T[t, 1] == 400}, T, {t, 0, 100}, {x, 0, 1},
Method -> {"MethodOfLines", "SpatialDiscretization" -> {"FiniteElement",
"MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}];
Solution like sol1 but without using the MethodOfLines (correct solution):
u = NDSolveValue[{D[T[t, x], t] - If[x < 0.4, 0.00093, 0.05405]*D[T[t, x], x, x] == 0,
T[0, x] == 300, T[t, 0] == 300, T[t, 1] == 400}, T, {t, 0, 100}, {x, 0, 1},
Method -> {"ExplicitEuler", "SpatialDiscretization" -> {"FiniteElement",
"MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}];
Solution with the MethodOfLines but without FEM (correct solution):
u = NDSolveValue[{D[T[t, x], t] - If[x < 0.4, 0.00093, 0.05405]*D[T[t, x], x, x] == 0,
T[0, x] == 300, T[t, 0] == 300, T[t, 1] == 400}, T, {t, 0, 100}, {x, 0, 1},
Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}];
Solution without MethodOfLines and without FEM (correct solution):
u = NDSolveValue[{D[T[t, x], t] - If[x < 0.4, 0.00093, 0.05405]*D[T[t, x], x, x] == 0,
T[0, x] == 300, T[t, 0] == 300, T[t, 1] == 400}, T, {t, 0, 100}, {x, 0, 1},
Method -> {"ExplicitEuler", "SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}];
Solution w/o MethodOfLines and without FEM with coefficients in the temporal derivative side (correct solution):
u = NDSolveValue[{D[T[t, x], t]/If[x < 0.4, 0.00093, 0.05405] - D[T[t, x], x, x] == 0,
T[0, x] == 300, T[t, 0] == 300, T[t, 1] == 400}, T, {t, 0, 100}, {x, 0, 1},
Method -> {"ExplicitEuler", "SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}];
All solutions can be plotted with:
Plot[u[2, x], {x, 0, 1}, PlotRange -> {{0., 1}, {300, 400}},
Frame -> True,GridLines -> Automatic, GridLinesStyle -> Directive[Thin,
Dashed],FrameLabel -> {"x", Row[{"T(", Style[t, Italic], ",",
"x)"}]},PlotStyle -> {Thick, Red},
ImageSize -> 1.1*{550, 350}]
Hope that helps
x[x,0]=Exp[x]
is not compatible with flux continuity. Same probleme here and here !! $\endgroup$