I am trying to solve the following Fokker-Planck equation using NDSolveValue: $$\partial_t P(x,t) = -\partial_xJ$$ where $$J = -D\partial_x P(x,t) - (D/k_BT)\partial_xW(x)$$ where we assume D,T constant and W being a time independent potential, which in my case is a step function connected with a cosine to make it continuous in the 0th and 1th derivative: $$W(x) = h_1 \quad for \quad x<x_1$$ $$W(x) = ((h_2 - h_1)/2 )cos(\pi x/(x_2 - x1)) + (h_2 + h_1)/2 \quad for \quad x_1 \leq x < x_2$$ $$h2 \quad for \quad x \geq x_2$$
However, in this differential equation there is a second derivative in x of W, in which case there will be a discontinuity at x1 and x2 (I think the same also holds for mathematicas smoothstep function.)
I have tried solving this via the following code (with arbitrary values for h1,h2,x1,x2):
M2[x_] =
Piecewise[{{h1,x < x1}, {((h2 - h1)/2)*Cos[(Pi/(x2 - x1))*x] + (h1 + h2)/2,x1 <= x <x2},{h2, x >= x2}}] /. {x1 -> 10, x2 -> 12, h1 -> 5,h2 -> 15};
pde = D[P[x, t], t] == -D[(-D[P[x, t], x] - P[x, t]* D[M2[x], x]), x];
delt[x_] = PDF[NormalDistribution[12.5, 0.0015]];
molfem[measure_ : Automatic] := {"MethodOfLines",
"SpatialDiscretization" -> {"FiniteElement",
"MeshOptions" -> MaxCellMeasure -> measure}};
testfp =
NDSolveValue[{pde, P[x, 0] == delt[x], P[0, t] == 0,
P[15, t] == 0}, P[x, t], {x, 0, 15}, {t, 0, 100},
Method -> molfem[0.01]];
where I have used some code from here. However, it doesnt work for me, and produces the following error:
CompiledFunction: Compiled Expression should be a machine sized real number.
I am sadly relatively out of my depth with this one and any help would be appreciated.