Skip to content

Repository files navigation

LSPC (Laplace Solver in Polar Coodinates)

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.


Basic information

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.

First step

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 function

In this example, the Dirichlet boundary condition being used is the function $\sin(x)$. To use another function, comment out the current line and uncomment (or write) the function to be applied. Once the function is set, save the file.


Compilation

After defining the boundary condition, the program must be compiled. This is done by executing the file dcompi in the terminal as follows:

$ ./dcompi

At the end of the execution, the executable file LSPC is created.


Running the LSPC program

Once the new file LSPC is generated, it can be executed.

The execution can be carried out in two ways:

  1. Running only the file LSPC, which generates the files containing the numerical solution.
  2. Running the file dexe, which in addition to executing LSPC, also runs the file 5_graphic.py to visualize the heat map of the solution.

1. First method

Run the file LSPC in the terminal:

$ ./LSPC

The program then starts showing the following:

---------------------------------------------
--------------- PROGRAMA LSPC ---------------
---------------------------------------------

Ingrese el valor de n_r:

At this point, the value of the parameter $n_r$ must be entered, for example 3. The program then displays:

---------------------------------------------
--------------- PROGRAMA LSPC ---------------
---------------------------------------------

Ingrese el valor de n_r:
3
Ingrese el valor de m_max:

Finally, the value of the parameter $m_{max}$ must be entered, for example 10, and then wait for the program to finish its execution:

---------------------------------------------
--------------- PROGRAMA LSPC ---------------
---------------------------------------------

Ingrese el valor de n_r:
3
Ingrese el valor de m_max:
10

When 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$).

2. Second method

Run the file dexe in the terminal:

$ ./dexe

The 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 $n_r=3$ and $m_{max}=10$, the following image would be shown: image


Output files

Below is an explanation of how to interpret the output files of the LSPC program. As an example, the output files for the parameters $n_r=3$ and $m_{max}=10$ are used.

1. file1.dat

This set of values should be considered as a python list, since the indices for each value are useful.

Value Index $r_i$
0.00 0 $r_0$
0.25 1 $r_1$
0.50 2 $r_2$
0.75 3 $r_3$
1.00 4 $r_4$

2. file2.dat

For this set of values, the same consideration as in file1.dat applies.

Value Index $\theta_j$
0.0000 0 $\theta_0$
0.0628 1 $\theta_1$
0.1257 2 $\theta_2$
$\vdots$ $\vdots$ $\vdots$
6.2832 100 $\theta_4$

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 $\cdots$ 6.2832
Index 0 1 2 $\cdots$ 100
$\theta_j$ $\theta_0$ $\theta_1$ $\theta_2$ $\cdots$ $\theta_{100}$

3. file3.dat

This set of values is represented as the following matrix:

0.0000 0.0000 0.0000 0.0000 $\cdots$ 0.0000 0.0000
0.0000 0.0157 0.0313 0.0468 $\cdots$ -0.0157 0.0000
0.0000 0.0314 0.0627 0.0937 $\cdots$ -0.0314 0.0000
0.0000 0.0471 0.0940 0.1405 $\cdots$ -0.0471 0.0000
0.0000 0.0628 0.1253 0.1874 $\cdots$ -0.0628 0.0000

Each value corresponds to the values from the files file1.dat ($r_i$) and file2.dat ($\theta_j$):

$T(r_0,\theta_0)$ $T(r_0,\theta_1)$ $T(r_0,\theta_2)$ $T(r_0,\theta_3)$ $\cdots$ $T(r_0,\theta_{99})$ $T(r_0,\theta_{100})$
$T(r_1,\theta_0)$ $T(r_1,\theta_1)$ $T(r_1,\theta_2)$ $T(r_1,\theta_3)$ $\cdots$ $T(r_1,\theta_{99})$ $T(r_1,\theta_{100})$
$T(r_2,\theta_0)$ $T(r_2,\theta_1)$ $T(r_2,\theta_2)$ $T(r_2,\theta_3)$ $\cdots$ $T(r_2,\theta_{99})$ $T(r_2,\theta_{100})$
$T(r_3,\theta_0)$ $T(r_3,\theta_1)$ $T(r_3,\theta_2)$ $T(r_3,\theta_3)$ $\cdots$ $T(r_3,\theta_{99})$ $T(r_3,\theta_{100})$
$T(r_4,\theta_0)$ $T(r_4,\theta_1)$ $T(r_4,\theta_2)$ $T(r_4,\theta_3)$ $\cdots$ $T(r_4,\theta_{99})$ $T(r_4,\theta_{100})$

Note

The files used for the previous example can be found in the example folder.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages