I am solving a system of 3 steady state 1D ODEs, however the system consists of component that has sharp changes at x = 1, which is very hard to capture. Is there a way to specifically increase the mesh density around the region where sharp changes occur? Here is the line that I call to apply ParametricNDSolveValue.

solutions = ParametricNDSolveValue[{ODEs, BCs}, {a, b, phi}, {x, 0, 4}, {miumaxA, miumaxB}] ;

One way I think of is to define a mesh by making mesh points concentrated around x=1. Here is the code I used to create a list x-coordinates (named xlist) that represent the mesh points that are concentrated around x=1.

(*To create a list of x-coordinates for 1D mesh*)
k = 50;
m = 100;
f[x_] = k*(0.5*(1 - Tanh[m*(x - 1)]) + 0.5*m*Sech[0.1*m*(x - 1)]^2 + 
d[x_] = 1/f[x];
Plot[f[x], {x, 0, 4}, PlotRange -> {0, Full}]
xlist = {0};
xend = xlist[[Length[xlist]]];
coord = {{1}};
i = 1;
While[xend < 4,
 i = i + 1;
 coord = Join[coord, {{i}}];
 xend = xend + d[xend];
 xlist = Insert[xlist, xend, (Length[xlist] + 1)];
ReplacePart[xlist, Length[xlist] -> 4];

However, I am not sure of how to convert the list of x coordinates to a mesh and apply into ParametricNDSolveValue, as I am fairly new into mathematica modelling. Alternatively, is there other way to refine the mesh?

  • 2
    $\begingroup$ Look up ToGradedMesh. Also search for the ElementMesh generation tutorial. $\endgroup$
    – user21
    Commented Jul 8, 2022 at 19:21

2 Answers 2


If you know the discretization xlist of variable x you might create a mesh with

xmesh = ToElementMesh[Map[{#} &, xlist]] 

Unfortunatesly you didn't provide your ODEs and BCs, but next step would be

solutions = ParametricNDSolveValue[{ODEs, BCs}, {a, b, phi},Element[x, xmesh], {miumaxA, miumaxB}]

Hope it helps!


You can use ToGradedMesh for this.

mesh = ToGradedMesh[{
    {Line[{{0}, {1}}], <|"Alignment" -> "Right"|>},
    {Line[{{1}, {4}}], <|"Alignment" -> "Left"|>}

enter image description here

With the various options you can refine the mesh further.


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.