patternMinor
Gees - GPL Euler equation solver
Viewed 0 times
eulersolvergplequationgees
Problem
As a little helper I recently had to write a code that solves the 1-D Euler equations. As it serves my purpose well I though others could make use of it as well. The homepage of the code can be found here, including a download containing the Makefile.
This version of the code is in this Github repository.
File gees.f90:
```
program gees
use mod_fluxcalc
implicit none
real(8), dimension(:),allocatable :: p,v
real(8), dimension(:,:), allocatable :: u,f, utild, uold
real(8) :: temps, dt, tend, dx, odt, pi, c0
integer :: i, nt, it, nx, io, lout
character(len=13) :: fname
write(,) 'Welcome to GEES'
write(,) 'your friendly GPL Euler Equation solver'
write(,) 'written 2012 by Arno Mayrhofer (www.amconception.de)'
write(,)
write(,) 'Number of grid points:'
read(,) nx
write(,) nx
write(,) 'End time:'
read(,) tend
write(,) tend
write(,) 'Time-step size'
read(,) dt
write(,) dt
write(,) 'Output dt:'
read(,) odt
write(,) odt
write(,) 'Speed of sound:'
read(,) c0
write(,) c0
! number of time-steps
nt = int(tend/dt+1d-14)
! grid size
dx = 1D0/real(nx,8)
pi = acos(-1d0)
! list ouput index
lout = 1
allocate(p(-1:nx+1),v(-1:nx+1),f(nx,2),u(-1:nx+1,2), &
utild(-1:nx+1,2), uold(-1:nx+1,2))
! init
do i=1,nx-1
u(i,1) = 1d3+cos(2pireal(i,8)/real(nx,8))*10d0 !rho
u(i,2) = 0d0 !u(i,1)0.1d0sin(2pireal(i,8)/real(nx,8)) !rho*v
enddo
! set p,v from u and calcuate boundary values at bdry and ghost cells
call bcs(u,p,v,nx,c0)
! file output index
io = 0
! simulation time
temps = 0d0
! output
write(fname,'(i5.5,a8)') io,'.out.csv'
open(file=fname,unit=800)
write(800,*) 'xpos,p,rho,v'
do i=-1,nx+1
write(800,'(4(a1,e20.10))') ' ', real(i,8)/real(nx,8),',', p(i),',', u(i,1),',', v(i)
enddo
close(800)
io = io+1
! loop over all timesteps
do it=1,nt
! list output
if(real(ntlout)0.1d0.lt.real(it))then
write(,) 'Calcul
This version of the code is in this Github repository.
File gees.f90:
```
program gees
use mod_fluxcalc
implicit none
real(8), dimension(:),allocatable :: p,v
real(8), dimension(:,:), allocatable :: u,f, utild, uold
real(8) :: temps, dt, tend, dx, odt, pi, c0
integer :: i, nt, it, nx, io, lout
character(len=13) :: fname
write(,) 'Welcome to GEES'
write(,) 'your friendly GPL Euler Equation solver'
write(,) 'written 2012 by Arno Mayrhofer (www.amconception.de)'
write(,)
write(,) 'Number of grid points:'
read(,) nx
write(,) nx
write(,) 'End time:'
read(,) tend
write(,) tend
write(,) 'Time-step size'
read(,) dt
write(,) dt
write(,) 'Output dt:'
read(,) odt
write(,) odt
write(,) 'Speed of sound:'
read(,) c0
write(,) c0
! number of time-steps
nt = int(tend/dt+1d-14)
! grid size
dx = 1D0/real(nx,8)
pi = acos(-1d0)
! list ouput index
lout = 1
allocate(p(-1:nx+1),v(-1:nx+1),f(nx,2),u(-1:nx+1,2), &
utild(-1:nx+1,2), uold(-1:nx+1,2))
! init
do i=1,nx-1
u(i,1) = 1d3+cos(2pireal(i,8)/real(nx,8))*10d0 !rho
u(i,2) = 0d0 !u(i,1)0.1d0sin(2pireal(i,8)/real(nx,8)) !rho*v
enddo
! set p,v from u and calcuate boundary values at bdry and ghost cells
call bcs(u,p,v,nx,c0)
! file output index
io = 0
! simulation time
temps = 0d0
! output
write(fname,'(i5.5,a8)') io,'.out.csv'
open(file=fname,unit=800)
write(800,*) 'xpos,p,rho,v'
do i=-1,nx+1
write(800,'(4(a1,e20.10))') ' ', real(i,8)/real(nx,8),',', p(i),',', u(i,1),',', v(i)
enddo
close(800)
io = io+1
! loop over all timesteps
do it=1,nt
! list output
if(real(ntlout)0.1d0.lt.real(it))then
write(,) 'Calcul
Solution
A few points I'd do different:
- use the name of the procedures/modules also in their end statement
- not writing enddo and endif in a single word, but seperately. There are newer language constructs, where writing them together is not allowed, and separating them all is more consistent
- as mentioned in a comment above, use selected_real_kind instead of a hardwired 8
- use >,
- provide some explanation on routines arguments and the purpose of each routine
- indent module routines
- use spaces around the condition of if-clauses
- use the private statement in the module and explicitly mark visible entities with the public keyword
- turn the initialization and the time loop into subroutines each
Context
StackExchange Code Review Q#10326, answer score: 4
Revisions (0)
No revisions yet.