4
$\begingroup$

When applying NDSolve to a 1-D transient heat equation, the following code appears to set MaxStepSize for the temporal variable t.

t0 = 0;
t1 = 10;
x0 = 0;
x1 = 1;
nx = 100;
dx = (x1-x0)/nx;
eqs1 = {D[u[x,t],x,x] - D[u[x,t],t] == NeumannValue[1, x==x0 || x == x1], DirichletCondition[u[x,t]==0, t== t0]};
sol1 = NDSolve[eqs1, u, {x, x0, x1}, {t, t0, t1}, Method-> {"MethodOfLines", "TemporalVariable" -> t}, MaxStepSize -> dx]
f = u /. First[sol1];
Dimensions[f["Grid"]]

I would like to apply MaxStepSize to the spatial variable x, rather than to the temporal variable t.

I've tried without success variations involving SpatialDiscretization, such as

NDSolve[eqs1, u, {x, x0, x1}, {t, t0, t1}, Method-> {"MethodOfLines", "TemporalVariable" -> t, "SpatialDiscretization"-> {"TensorProductGrid","MaxStepSize" -> dx}}]

which yields the following error:

NDSolve::moptx: Method option MaxStepSize in {NDSolve`FiniteElement,MaxStepSize->1/100} is not one of {ConstraintMethod,BoundaryTolerance,InterpolationOrder,IntegrationOrder,LinearSolveMethod,MeshOptions,PrecomputeGeometryData}. >>

What is the correct approach?

$\endgroup$

1 Answer 1

5
$\begingroup$

I think you are looking for MaxCellMeasure in case of the finite element method.

t0 = 0;
t1 = 10;
x0 = 0;
x1 = 1;
nx = 100;
dx = (x1 - x0)/nx;
eqs1 = {D[u[x, t], x, x] - D[u[x, t], t] == 
    NeumannValue[1, x == x0 || x == x1], 
   DirichletCondition[u[x, t] == 0, t == t0]};
sol1 = NDSolveValue[eqs1, u, {x, x0, x1}, {t, t0, t1}, 
  Method -> {"MethodOfLines", "TemporalVariable" -> t, 
    "SpatialDiscretization" -> {"FiniteElement", 
      "MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}, MaxStepSize -> dx]
Dimensions[sol1["Grid"]]

In case of the "SpatialDiscretization" "TensorProductGrid" you are looking for a "MaxPoints" and/or "MinPoints" option. You'd also need to adjust your equation a bit like so:

t0 = 0;
t1 = 10;
x0 = 0;
x1 = 1;
nx = 100;
dx = (x1 - x0)/nx;
eqs1 = {D[u[x, t], x, x] - D[u[x, t], t] == 0, u[x, 0] == 0
   , Derivative[1, 0][u][0, t] == 1
   , Derivative[1, 0][u][1, t] == 1
   };
sol1 = NDSolveValue[eqs1, u, {x, x0, x1}, {t, t0, t1}, 
  Method -> {"MethodOfLines", "TemporalVariable" -> t, 
    "SpatialDiscretization" -> {"TensorProductGrid", 
      "MaxPoints" -> 125, "MinPoints" -> 125}}, MaxStepSize -> dx]
Dimensions[sol1["Grid"]]

This is not quite correct as the initial condition does not match the boundary condition; but that's only possible with more knowledge of what you would like to solve.

$\endgroup$
4
  • $\begingroup$ Thanks. The FiniteElement approach worked, and solved my immediate problem. However, Method -> {"MethodOfLines", "TemporalVariable" -> t, "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> 2000}} yielded the error NDSolveValue::moptx: Method option MaxPoints in {NDSolve`FiniteElement,MaxPoints->2000} is not one of {ConstraintMethod,BoundaryTolerance,InterpolationOrder,IntegrationOrder,LinearSolveMethod,MeshOptions,PrecomputeGeometryData}. >> Can you advise the correct syntax for the latter approach? $\endgroup$ May 17, 2016 at 7:25
  • $\begingroup$ @RonnenLevinson, see update. $\endgroup$
    – user21
    May 17, 2016 at 9:34
  • $\begingroup$ The sample system models heat conduction following the sudden application of constant surface heat flux to a body at initial temperature zero. As originally written, it defines the BCs by adding a NeumannValue[] term to the PDE, rather than by providing separate BC equations, to avoid the warning from NDSolve[] about inconsistent boundary and initial conditions. I have been unable get the TensorProductGrid flavor of SpatialDiscretization to work with a NeumannValue[]-specified BC. That, coupled with the need to control grid spacing, prompted my original question. $\endgroup$ May 17, 2016 at 17:20
  • 2
    $\begingroup$ @RonnenLevinson, NeumannValue will always trigger FEM - as NeumannValue is FEM specific. If you want TensorProductGrid you need to express the derivatives with Derivative or D. $\endgroup$
    – user21
    May 17, 2016 at 19:54

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.