The program solves Poisson's equation, in two dimensions through either a parallelization or serial verison of the code. For the former, we accomplish parallelization via OpenMP.
In this project you will solve Poisson's equation, ,where is the electrostatic potential and is the source charge density. Towards the end of the course we will learn how to solve this via a "relaxation" method, but here we will transform the differential equation into a matrix problem in a given basis. The main numerical work will be Fourier integrals.
We will work in two dimensions, so that the full equation becomes
We will place this in a metal rectangular box with sides of length and . This means the gradient of the potential at the surfaces must be zero, that is, if we place the walls at and , and at and , then
This is easily accomplished by expanding the potential in basis functions which automatically satisfy these conditions, that is cosines:
These basis functions have been chosen so as to be already normalized.In this basis, the problem becomes almost trivial:
to be solved for and where the source term is now
This two dimensional integral is the main computational work. For this you can
and should use your quadrature
module from assignment two. The number
of sample points for the quadrature does not need to be the same as the
number of samples for the Fourier coefficients. You may hard code the number
of quadrature sample points. If your quadrature subroutines are general enough
you just need to copy the quadrature.f90
file into this repository and you
wont even need to make changes to the source code. However you will need to
modify the makefile
in this repository to include the correct dependencies.
For the source term, we will use the function
Your code should receive, via a namelist
file given as an argument, the
following:
- The dimensions of the box, and (which may be different)
- The total charge .
- The center of the charge distribution and
- The widths and
- The max index , which is the maximum value for both indices and .
You may add additional namelists
to the input file (e.g. name of the output
file, number of sample points for the quadrature, step size in each direction
when writing results for plots), just be sure to give default values to all
variables in all namelists
.
Create a jupyter notebook to show your resulting potential in a two
dimensional plot. Either through iso-potential curves (plt.contour()
) or by a
color plot (plt.imshow()
). I'll leave up to you to decide how to better
present your results and to look at the necessary documentation.
We selected the Boole's algorithm
To utilize the efficiency of OpenMp, the program puts the parallel codes in the data file generating part of read_write.f90
, them the task of generating data file is available to break into n (determined by how many threshold) parallel processes to save time.
The n_max can be chosen in different ways depending on what you are looking for:
If your goal is just to get an understanding of what the structure of the potential in the box is, an n_max
between 20 - 40 would suffice.
In the case you are looking for precision, an n_max no greater than 70 should be useful in getting a good approximation.
-
The program contributes a simpiler way to show the process of solving Poisson's equation with codes instead of equations or methods, which allows the user to understand where and how those values are used and contributed to the results. In the meantime, the program is a convenient tool for analyzing the difference from 2D and 3D potential graphs by slightly switching the initial conditions in the
.namelist
file. -
2D and 3D graphs in
.ipynb
are able to exhibit a clear view of distribution of potential. -
Be familiar with the power ot OpenMP that the efficiency and time the program takes for computation by changing the number of threshold.
The program relies on fortran language to code the formula and system required to run the program which returns a output of database including positions and potentials into the code in jupyter notebook which is already prepared to draw the graph we expect.
The program includes:
box_parameters.namelist
file for convenient to change initial conditions.graoup_project_analysis.ipynb
shows the results and graphs in jupyter notebook.main.f90
, the overview of program with calling all necessary subroutines and functions from other files in order to generating data files for graphing.makefile
, a shortcut code for executing the program.potential.f90
is responsible solving Poisson's equation for a charge distribution held within a 2D conducting box. Ultimately, this file finds the electrostatic potential as a function of x and y.quadrature.f90
includes 2 functions used to evaluate a volume integral with the methods of Booles' quadrature.read_write.f90
is the file used to read initial values for computing the potential and generate data files for graphing in the '.ipynb' file.
Determine the initial condition inside .namelist
file (or the program will take initial values from the read_write.f90
file). Due to the integration algorithm of Boole's rule, the value of n_max
has to be 4n+1. And 0 value in center
or width
would cause invalid output values.
Once the initial conditions are setting, open the terminal and go to the direction where the program is, write make
and ./poisson box_parameters.namelist
(or ./poisson
to use default initial condition) in order to compiling and executing the program. In generally it will takes around 15 seconds of executing and the time will be showd on the screen of terminal.
When the .dat
file is generated, the jupyter notebook file .ipynb
is available to graph the distribution of potential with both 2D and 3D graphs. And the jupyter notebook requires the numpy
and matplotlib
library for graphing.
Note: write make clear
in the terminal is available to clear all unecessary files which used to generating the execution file.