# Recent Posts - What I've been saying

## Writing a Tensor class in Modern C++

As promised in my article about the mathematics of solving the multidimensional Poisson equation, I am beginning writing about the process of writing a parallelized solution to the Poisson Equation by successive over-relaxation. This article will be about writing a tensor class in modern C++, as we will need a multidimensional grid for our Poisson solver.

Mathematically speaking, a Tensor is a multidimensional object over some appropriate field. In this case we will be considering simple fields, real numbers (to floating-point precision), integers (modulo some appropriate power of 2) and complex numbers. Tensors are mathematically-rich objects, with their own notation and algebras embedded in Ricci calculus, but here we will only be writing a basic Tensor class equipped with a few useful operators, however, it is an easily extendable object, so can easily be modified for most general purposes. Read more »

## Multidimensional Poisson Equation Numerical Methods

Further to my posts on solving the Laplace Equation and Poisson Equation in $R \subset \mathbb{R}^{2}$ this post is describing mathematical extensions to these methods allowing us to consider numerical solvers for regions $R \subset \mathbb{R}^{n}$, for arbitrary $n \in \mathbb{N}$.

We begin by once again considering the multidimensional Poisson equation in $\mathbb{R}^{n}$, where $\psi,f : \mathbb{R}^{n} \to \mathbb{R}$:

$$\nabla^{2} \psi = \sum_{k=1}^{n}\frac{\partial^{2} \psi}{\partial x_{k}^{2}}=f(\vec{r})$$

Recalling the central difference method from before: $f^{\prime \prime}(x) \approx \frac{f(x+h) – 2f(x) + f(x-h)}{h^{2}}$, we can write:

$$\nabla^{2} \psi \approx \sum_{k=1}^{n}\frac{\psi(\dots,x_{k}+\delta x_{k},\dots) – 2\psi(\dots,x_{k},\dots) + \psi(\dots,x_{k}-\delta x_{k},\dots)}{(\delta x_{k})^{2}}=f(x_{1},\dots,x_{n})$$

Or in a more readable vector notation, where $\vec{r} = \left(\begin{smallmatrix}x_{1} & \dots & x_{n}\end{smallmatrix}\right)^{T}$ and $\delta \vec{x}_{k} = \delta x_{k} \boldsymbol{\hat{e}}_{k}$, and $\boldsymbol{\hat{e}}_{k}$ is the $k$th unit vector: Read more »

## Solution to the Poisson Equation in C++ using Successive Over-relaxation

Note: The first section of this blog post is mathematical and useful to understand, however, if you are just looking for an implementation you can skip through to the first code block.

Due to the interest in my previous blog post: Solution to the Laplace Equation in C++ using successive over-relaxation, I have decided to write a follow-up post on how to extend the method to allow for solutions to the Poisson Equation.

The Poisson Equation is the general case of the Laplace Equation and takes the following form:

$$\nabla^{2} \phi = f(\vec{r})$$

## Solution to the Laplace Equation in C++ using successive over-relaxation

Note: The first section of this blog post is mathematical and useful to understand, however, if you are just looking for an implementation you can skip through to the first code block.

Partial Differential Equations are notoriously difficult to solve analytically; in all but the simplest cases, there often does not exist a solution in elementary form. This would be acceptable, but for the ubiquity of partial differential equations in physical models. So Mathematicians and Computer Scientists had to develop methods of solving PDEs numerically.

In this blog post, I will show one such method of solving Laplace’s equation (a type of PDE) in $\mathbb{R}^{2}$ using the method of successive over-relaxation, an iterative technique which involves splitting the relevant domain into a grid and sampling each point in a fixed order. For those who don’t know, or have forgotten, Laplace’s equation is written as follows:

$$\nabla^{2} \psi = 0$$

Designed and Produced by Thomas Russell © 2014-2017