# How to solve a Poisson equation using the finite difference method when there is an object inside a domain?

I'm interested in solving an electrostatics problem in 2d case in some domain with a conductor placed inside the domain. From a mathematical point of view, I have to solve a Poisson equation with user-defined boundary conditions (let us consider a rectangular domain for simplicity) and a certain region in the domain with a constant user-defined potential (see the figure).

I use a finite difference method to solve the Poisson equation numerically, which means I have to construct a grid in the domain and then attempt to find values of the potential at the nodes of the grid. Recall that in the finite difference method, we write an equation for the unknown potential at each node of the grid. Combined together, these equations form a system of linear equations. Solution of this system is an approximate solution to the Poisson equation in the domain.

I know how to construct and solve the system of linear equations for the unknow potential in a rectangular domain without any "inner objects". My question is: how should I approach the problem, when there are some "inner objects"?

My current idea is to record each node the object occupies (orange on the figure) and then cross out the corresponding equations from the linear system. I would also have to modify the equations corresponding to the nodes that happen to lie near the boundary of the object. Having done that, it should be possible solve the system. Then, using this solution and the user-defined value of the potential on the conductor, it is possible to restore the potential in the full domain.

Is it the only possible strategy or are there any simpler ways to do this? I'm interested in the approach, most reasonable from a programming point of view.

BTW: I use PETSc to solve linear system. Could it possibly have a certain feature for such case?

## 2 Answers

If you have simple, grid-aligned interior objects or accuracy is not crucial then stick with the method you have described. If you need to accurately represent arbitrary boundary shapes then you're probably best off moving to a (more complicated) finite element approach on an unstructured grid.

You have described the simplest approach to solving this problem. If the interior objects can only be exactly aligned with your grid (e.g. rectangles in a rectangular grid) this approach will work very well. However, you are discretizing the boundary onto the chosen grid which results in low (first?) order accuracy at the interior boundary regardless of the order of accuracy of the finite difference discretization you use. Depending on your goals, this might be ok. As is often the case in solving PDEs, more complex boundary shapes (interior or exterior) create significant difficulties. The most common solution for the Poisson equation would be the use of a body-fitted grid or unstructured mesh. Most typical would be using finite elements on an unstructured triangular mesh (e.g. pdf link). This requires dealing with grid generation and typically requires more complex data structures for managing the relationships between elements and the other challenges of dealing with the unstructured mesh.

• Yes, I know, the accuracy of the finite difference method leaves much to be desired. However, there are other factors to consider, such as ease of implementation and speed of computation. Previously I've tried to employ finite elements method ( using excellent deal.ii library ), but for complex geometries it is also very cumbersom to implement. So, it was decided to start from something more simple. Jul 9, 2015 at 3:45

I found a specific approach for dirichlet BCs here in lecture 4. It shows one possible way to solve problems with complex boundaries. Because of the linear interpolation, I think up to second order accuracy is possible. Relevant page shown below: