FiPy: Solving PDEs on irregular meshes

In this example we will revisit the basic problem of determining the potential between a grounded plate and a circle/sphere on an electrostatic potential. In [3] we had approximated the potential with a homogeneous charge on the ring and grounded the plate by putting a mirror charge behind the plate.

In more complex situations the position and shape of a mirror charge is not trivial. Therefore we use a numerical PDE solver.

Generating the mesh in gmsh

As we have seen on tha page "FiPy: Solving PDEs with Python" boundary conditions can only be defined on exterior faces of a mesh. Even in the simple case of a grounded plate and a circle on a defined potential one has to generate a mesh that fullfills the boundary conditions in gmsh.

Gmsh screenshot

Running the simulation

Before running the simulation one has to adapt the script from [1] to import a mesh instead of generating a regular one. Then one can successfully define a boundary condition on the inner exterior face of the mesh and run the simulation.

#!/usr/bin/env python

import fipy

mesh = fipy.GmshImporter2D('test0.msh')
X,Y =  mesh.getFaceCenters()

x0,y0 = 10,0
r = 5

potential = fipy.CellVariable(mesh=mesh, name='potential', value=0.)
permittivity = 1.
potential.equation = (fipy.DiffusionTerm(coeff = permittivity) == 0.)

allfaces = mesh.getExteriorFaces()
ring = allfaces & ( (X-x0)**2+(Y-y0)**2 < (r+1.5)**2) 

bcs = (
    fipy.FixedValue(value=5.,faces=ring),
    fipy.FixedValue(value=0.,faces=mesh.getFacesLeft()),
)

potential.equation.solve(var=potential, boundaryConditions=bcs)

viewer = fipy.viewers.Viewer(vars=(potential,))
viewer.plot("estat-example-3.png")

The result looks quite similar to the result from the previous example, but this time we can precisely extract physical quantities from the plot (, if the colorbar legend was in the plot).

Solution to Laplace Equation

References

  1. http://geuz.org/gmsh/