0

I modified the examples.convection.exponential1D.mesh1D example and it gives an error when I run it.

from fipy import CellVariable, Grid1D, DiffusionTerm, PowerLawConvectionTerm
from fipy.tools import numerix

diffCoeff = 1.
convCoeff = (10.,)
L = 10.
nx = 100
mesh = Grid1D(dx=L / nx, nx=nx)

valueLeft = (0.,)
valueRight = 0.    
var = CellVariable(mesh=mesh, name="variable")    
var.faceGrad.constrain(valueLeft, where=mesh.facesLeft)
var.constrain(valueRight, mesh.facesRight)

eq = (DiffusionTerm(coeff=diffCoeff)
      + PowerLawConvectionTerm(coeff=convCoeff))
eq.solve(var=var)

When I run it I get the following error:

...\fipy\solvers\scipy\linearLUSolver.py:41: RuntimeWarning: invalid value encountered in double_scalars
if (numerix.sqrt(numerix.sum(errorVector**2)) / error0)  <= self.tolerance:

Did I implement the zero gradient boundary condition right? I only found 2D examples. In this 1D problem does valueLeft even have to be a vector? I tried with scalar but still got the same error.

I'm new to FiPy and I'm aware that this PDE in this form may not make any sense but I wanted to start from a simpler example and in the end I want to solve a PDE with these boundary conditions and a source. Would adding a source solve my problem?

Any help would be appreciated.

2 Answers2

0

That's a warning, not an error. It just means we're not being very smart about normalizing an equation with zero error.

The PDE still solves (although the solution isn't very interesting).

jeguyer
  • 2,379
  • 1
  • 11
  • 15
0

That's a warning not an error. On printing the values of var they are all zero, which is the correct answer given the boundary conditions.

The warning is caused by a divide by zero warning caused by this line of code, which should be fixed to deal with the case when the residual starts at zero. However, the long and the short is for users to just ignore that warning as the solver still returns the correct result.

wd15
  • 1,068
  • 5
  • 8
  • Thank you! So that means I used the faceGrad.constrain() method properly? – Ferenc Lengyel Feb 11 '21 at 22:42
  • Using zero constraints on both boundaries won't give you much feedback on whether you're solving what you're interested in correctly. Try a problem with a non-trivial outcome to check. Also, convection terms should really be used in conjunction with transient terms as there are accuracy and stability issues with convection. – wd15 Feb 12 '21 at 03:19