Numerical solution of Laplace's equation on a circular plate with Dirichlet boundary conditions.
Program developed in Fortran 90, using the compiler
GNU Fortran 9.4.0
Program developed in Python for graphics,
Python 3.11.4
Important
The program was run on the Ubuntu operating system.
This repository contains the following files:
- 1_constant.f90 : Fortran file containing constants necessary for the program.
- 2_function.f90 : Fortran file containing functions necessary for the program.
- 3_subroutines.f90 : Fortran file containing subroutines used in the main program.
- 4_main.f90 : Fortran file containing the main code of the program.
- 5_graphic.py : Python file for plotting the heat map of the numerical solution.
- dcompi : File with bash instructions that compiles the Fortran files and generates the LSPC executable.
- dexe : File with bash instructions that runs the generated executable and then the Python script.
- requirements.txt : File listing the packages needed to run the Python script.
Before running the program, the first thing that must be defined is the boundary condition to be used.
To do this, open the file 2_function.f90 and look for the following section:
!
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!++++++++++++++ Condicion de Contorno de Dirichlet ++++++++++++++
!++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
! Necesario para obtener una solucion.
!
function funcion_contorno(x) result(aux)
use constants
implicit none
real(dp),intent(in) :: x
real(dp) :: aux
aux = sin(x)
!aux = (1.0_dp+(x**2_dp))*sin(x)
!aux = 20.0_dp + (0.0_dp*x)
return
end functionIn this example, the Dirichlet boundary condition being used is the function
After defining the boundary condition, the program must be compiled.
This is done by executing the file dcompi in the terminal as follows:
$ ./dcompiAt the end of the execution, the executable file LSPC is created.
Once the new file LSPC is generated, it can be executed.
The execution can be carried out in two ways:
- Running only the file
LSPC, which generates the files containing the numerical solution. - Running the file
dexe, which in addition to executingLSPC, also runs the file5_graphic.pyto visualize the heat map of the solution.
Run the file LSPC in the terminal:
$ ./LSPCThe program then starts showing the following:
---------------------------------------------
--------------- PROGRAMA LSPC ---------------
---------------------------------------------
Ingrese el valor de n_r:
At this point, the value of the parameter
---------------------------------------------
--------------- PROGRAMA LSPC ---------------
---------------------------------------------
Ingrese el valor de n_r:
3
Ingrese el valor de m_max:
Finally, the value of the parameter
---------------------------------------------
--------------- PROGRAMA LSPC ---------------
---------------------------------------------
Ingrese el valor de n_r:
3
Ingrese el valor de m_max:
10When the program finishes, three files are created:
-
file1.dat : Contains the values of
$r$ considered to obtain the results of the numerical solution. -
file2.dat : Contains the values of
$\theta$ considered for plotting. -
file3.dat : Contains the temperature values at the points (
$r,\theta$ ).
Run the file dexe in the terminal:
$ ./dexeThe program executes in the same way as the first method, with the difference that at the end it displays the heat map of the numerical solution.
For the given example, with 
Below is an explanation of how to interpret the output files of the LSPC program. As an example, the output files for the parameters
This set of values should be considered as a python list, since the indices for each value are useful.
| Value | Index | |
|---|---|---|
| 0.00 | 0 | |
| 0.25 | 1 | |
| 0.50 | 2 | |
| 0.75 | 3 | |
| 1.00 | 4 |
For this set of values, the same consideration as in file1.dat applies.
| Value | Index | |
|---|---|---|
| 0.0000 | 0 | |
| 0.0628 | 1 | |
| 0.1257 | 2 | |
| 6.2832 | 100 |
In this case, for better visualization and understanding of the final file, it can be represented as follows:
| Value | 0.0000 | 0.0628 | 0.1257 | 6.2832 | |
| Index | 0 | 1 | 2 | 100 | |
This set of values is represented as the following matrix:
| 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | |
| 0.0000 | 0.0157 | 0.0313 | 0.0468 | -0.0157 | 0.0000 | |
| 0.0000 | 0.0314 | 0.0627 | 0.0937 | -0.0314 | 0.0000 | |
| 0.0000 | 0.0471 | 0.0940 | 0.1405 | -0.0471 | 0.0000 | |
| 0.0000 | 0.0628 | 0.1253 | 0.1874 | -0.0628 | 0.0000 |
Each value corresponds to the values from the files file1.dat (file2.dat (
Note
The files used for the previous example can be found in the example folder.