Skip to content

Commit

Permalink
Move time integrator inside solver to simplify the namelist.
Browse files Browse the repository at this point in the history
  • Loading branch information
semi-h committed Jul 10, 2024
1 parent bc4139b commit ff92c6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
20 changes: 13 additions & 7 deletions src/solver.f90
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module m_solver

class(base_backend_t), pointer :: backend
class(mesh_t), pointer :: mesh
class(time_intg_t), pointer :: time_integrator
type(time_intg_t) :: time_integrator
type(allocator_t), pointer :: host_allocator
type(dirps_t), pointer :: xdirps, ydirps, zdirps
procedure(poisson_solver), pointer :: poisson => null()
Expand Down Expand Up @@ -81,12 +81,11 @@ end subroutine poisson_solver

contains

function init(backend, mesh, time_integrator, host_allocator) result(solver)
function init(backend, mesh, host_allocator) result(solver)
implicit none

class(base_backend_t), target, intent(inout) :: backend
type(mesh_t), target, intent(inout) :: mesh
class(time_intg_t), target, intent(inout) :: time_integrator
type(allocator_t), target, intent(inout) :: host_allocator
type(solver_t) :: solver

Expand All @@ -95,11 +94,11 @@ function init(backend, mesh, time_integrator, host_allocator) result(solver)
character(len=200) :: input_file
real(dp) :: Re, dt
integer :: n_iters, n_output
character(3) :: poisson_solver_type
character(3) :: poisson_solver_type, time_intg
character(30) :: der1st_scheme, der2nd_scheme, &
interpl_scheme, stagder_scheme
namelist /solver_params/ Re, dt, n_iters, n_output, poisson_solver_type, &
der1st_scheme, der2nd_scheme, &
time_intg, der1st_scheme, der2nd_scheme, &
interpl_scheme, stagder_scheme

real(dp) :: x, y, z
Expand All @@ -109,7 +108,6 @@ function init(backend, mesh, time_integrator, host_allocator) result(solver)

solver%backend => backend
solver%mesh => mesh
solver%time_integrator => time_integrator
solver%host_allocator => host_allocator

allocate (solver%xdirps, solver%ydirps, solver%zdirps)
Expand All @@ -124,6 +122,7 @@ function init(backend, mesh, time_integrator, host_allocator) result(solver)
! set defaults
Re = 1600._dp; dt = 0.001_dp; n_iters = 20000; n_output = 100
poisson_solver_type = 'FFT'
time_intg = 'AB3'
der1st_scheme = 'compact6'; der2nd_scheme = 'compact6'
interpl_scheme = 'classic'; stagder_scheme = 'compact6'

Expand All @@ -134,6 +133,13 @@ function init(backend, mesh, time_integrator, host_allocator) result(solver)
close (100)
end if

solver%time_integrator = time_intg_t(solver%backend, &
solver%backend%allocator, &
time_intg)
if (solver%mesh%par%is_root()) then
print *, time_intg//' time integrator instantiated'
end if

solver%dt = dt
solver%backend%nu = 1._dp/Re
solver%n_iters = n_iters
Expand Down Expand Up @@ -666,7 +672,7 @@ end subroutine output
subroutine run(self)
implicit none

class(solver_t), intent(in) :: self
class(solver_t), intent(inout) :: self

class(field_t), pointer :: du, dv, dw, div_u, pressure, dpdx, dpdy, dpdz
class(field_t), pointer :: u_out, v_out, w_out
Expand Down
11 changes: 1 addition & 10 deletions src/xcompact.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ program xcompact
use m_base_backend
use m_common, only: pi
use m_solver, only: solver_t
use m_time_integrator, only: time_intg_t
use m_tdsops, only: tdsops_t
use m_mesh

Expand All @@ -26,7 +25,6 @@ program xcompact
type(mesh_t) :: mesh
type(allocator_t), pointer :: host_allocator
type(solver_t) :: solver
type(time_intg_t) :: time_integrator

#ifdef CUDA
type(cuda_backend_t), target :: cuda_backend
Expand All @@ -41,15 +39,13 @@ program xcompact
real(dp) :: t_start, t_end

character(len=200) :: input_file
character(len=3) :: method
character(len=20) :: BC_x(2), BC_y(2), BC_z(2)
integer, dimension(3) :: dims_global
integer, dimension(3) :: nproc_dir = 0
real(dp), dimension(3) :: L_global
integer :: nrank, nproc, ierr

namelist /domain_params/ L_global, dims_global, nproc_dir, BC_x, BC_y, BC_z
namelist /time_intg_params/ method

call MPI_Init(ierr)
call MPI_Comm_rank(MPI_COMM_WORLD, nrank, ierr)
Expand All @@ -70,13 +66,11 @@ program xcompact
BC_x = [character(len=20) :: 'periodic', 'periodic']
BC_y = [character(len=20) :: 'periodic', 'periodic']
BC_z = [character(len=20) :: 'periodic', 'periodic']
method = 'AB3'

if (command_argument_count() >= 1) then
call get_command_argument(1, input_file)
open (100, file=input_file)
read (100, nml=domain_params)
read (100, nml=time_intg_params)
close (100)
end if

Expand Down Expand Up @@ -111,10 +105,7 @@ program xcompact
if (nrank == 0) print *, 'OpenMP backend instantiated'
#endif

time_integrator = time_intg_t(allocator=allocator, backend=backend, &
method=method)
if (nrank == 0) print *, time_integrator%sname//' time intg instantiated'
solver = solver_t(backend, mesh, time_integrator, host_allocator)
solver = solver_t(backend, mesh, host_allocator)
if (nrank == 0) print *, 'solver instantiated'

call cpu_time(t_start)
Expand Down

0 comments on commit ff92c6e

Please sign in to comment.