forked from lesgo-jhu/lesgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfl_util.f90
113 lines (90 loc) · 2.89 KB
/
cfl_util.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
!!
!! Copyright (C) 2010-2017 Johns Hopkins University
!!
!! This file is part of lesgo.
!!
!! lesgo is free software: you can redistribute it and/or modify
!! it under the terms of the GNU General Public License as published by
!! the Free Software Foundation, either version 3 of the License, or
!! (at your option) any later version.
!!
!! lesgo is distributed in the hope that it will be useful,
!! but WITHOUT ANY WARRANTY; without even the implied warranty of
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!! GNU General Public License for more details.
!!
!! You should have received a copy of the GNU General Public License
!! along with lesgo. If not, see <http://www.gnu.org/licenses/>.
!!
!*******************************************************************************
module cfl_util
!*******************************************************************************
!
! This module provides the subroutines/functions for getting CFL related
! quantities
!
save
private
public get_max_cfl, get_cfl_dt
contains
!*******************************************************************************
function get_max_cfl() result(cfl)
!*******************************************************************************
!
! This function provides the value of the maximum CFL in the entire
! domain
!
use types, only : rprec
use param, only : dt, dx, dy, dz, nx, ny, nz
use sim_param, only : u,v,w
#ifdef PPMPI
use mpi
use param, only : ierr, MPI_RPREC
#endif
implicit none
real(rprec) :: cfl
real(rprec) :: cfl_u, cfl_v, cfl_w
#ifdef PPMPI
real(rprec) :: cfl_buf
#endif
cfl_u = maxval( abs(u(1:nx,1:ny,1:nz-1)) ) / dx
cfl_v = maxval( abs(v(1:nx,1:ny,1:nz-1)) ) / dy
cfl_w = maxval( abs(w(1:nx,1:ny,1:nz-1)) ) / dz
cfl = dt * maxval( (/ cfl_u, cfl_v, cfl_w /) )
#ifdef PPMPI
call mpi_allreduce(cfl, cfl_buf, 1, MPI_RPREC, MPI_MAX, MPI_COMM_WORLD, ierr)
cfl = cfl_buf
#endif
end function get_max_cfl
!*******************************************************************************
function get_cfl_dt() result(dt)
!*******************************************************************************
!
! This functions determines the maximum allowable time step based on the CFL
! value specified in the param module
!
use types, only : rprec
use param, only : cfl, dx, dy, dz, nx, ny, nz
use sim_param, only : u,v,w
#ifdef PPMPI
use mpi
use param, only : ierr, MPI_RPREC
#endif
implicit none
real(rprec) :: dt
! dt inverse
real(rprec) :: dt_inv_u, dt_inv_v, dt_inv_w
#ifdef PPMPI
real(rprec) :: dt_buf
#endif
! Avoid division by computing max dt^-1
dt_inv_u = maxval( abs(u(1:nx,1:ny,1:nz-1)) ) / dx
dt_inv_v = maxval( abs(v(1:nx,1:ny,1:nz-1)) ) / dy
dt_inv_w = maxval( abs(w(1:nx,1:ny,1:nz-1)) ) / dz
dt = cfl / maxval( (/ dt_inv_u, dt_inv_v, dt_inv_w /) )
#ifdef PPMPI
call mpi_allreduce(dt, dt_buf, 1, MPI_RPREC, MPI_MIN, MPI_COMM_WORLD, ierr)
dt = dt_buf
#endif
end function get_cfl_dt
end module cfl_util