4
$\begingroup$

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

Try:

testfp = 
  NDSolveValue[{pde, P[x, 0] == delt[x][x], P[0, t] == 0, 
    P[15, t] == 0}, P[x, t], {x, 0, 15}, {t, 0, 100}, 
   Method -> molfem[0.01]];

this used delt[x][x] to get rid if the formal x in the function of delt[x]

$\endgroup$
6
  • $\begingroup$ Eyyy, that fixed it for me. Can I ask, why a second x is necessary? $\endgroup$
    – IronicOwl
    Commented Apr 8 at 12:02
  • $\begingroup$ You specified a function, but want an open expression. Look at the output of PDF[NormalDistribution[12.5, 0.0015]] $\endgroup$
    – user21
    Commented Apr 9 at 7:28
  • $\begingroup$ Hmmm I see what you mean. However, I am afraid I still dont understand. I tried to replace the delt with a HeavisideTheta and it gives the same error depite being what I believe to be an open expression... $\endgroup$
    – IronicOwl
    Commented Apr 9 at 10:51
  • $\begingroup$ @IronicOwl, that's not something I can not answer, without seeing it and probably should be a new question. $\endgroup$
    – user21
    Commented Apr 9 at 14:52
  • $\begingroup$ Also, sorry for the typo. There is no such thing as an 'open' expression. I don't recall why or how the word 'open' slipped into this. Not what I meant. $\endgroup$
    – user21
    Commented Apr 9 at 14:55

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.