Skip to content

Commit dec9171

Browse files
authored
DRY m_checker (#592)
1 parent cf3ac9f commit dec9171

File tree

7 files changed

+541
-1010
lines changed

7 files changed

+541
-1010
lines changed

src/common/include/macros.fpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,17 @@
140140
#endif
141141
#:enddef
142142

143+
#:def PROHIBIT(*args)
144+
#:set condition = args[0]
145+
#:if len(args) == 1
146+
#:set message = '""'
147+
#:else
148+
#:set message = args[1]
149+
#:endif
150+
if (${condition}$) then
151+
call s_prohibit_abort("${condition}$", ${message}$)
152+
end if
153+
#:enddef
154+
143155
#define t_vec3 real(kind(0d0)), dimension(1:3)
144156
#define t_mat4x4 real(kind(0d0)), dimension(1:4,1:4)

src/common/m_checker_common.fpp

Lines changed: 120 additions & 271 deletions
Large diffs are not rendered by default.

src/common/m_helper.fpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ module m_helper
3636
f_create_bbox, &
3737
s_print_2D_array, &
3838
f_xor, &
39-
f_logical_to_int
39+
f_logical_to_int, &
40+
s_prohibit_abort
4041

4142
contains
4243

@@ -532,4 +533,20 @@ contains
532533
end if
533534
end function f_logical_to_int
534535

536+
subroutine s_prohibit_abort(condition, message)
537+
character(len=*), intent(in) :: condition, message
538+
539+
print *, ""
540+
print *, "===================================================================================================="
541+
print *, " CASE FILE ERROR "
542+
print *, "----------------------------------------------------------------------------------------------------"
543+
print *, "Prohibited condition: ", trim(condition)
544+
if (len_trim(message) > 0) then
545+
print *, "Note: ", trim(message)
546+
end if
547+
print *, "===================================================================================================="
548+
print *, ""
549+
call s_mpi_abort
550+
end subroutine s_prohibit_abort
551+
535552
end module m_helper

src/post_process/m_checker.f90

Lines changed: 0 additions & 180 deletions
This file was deleted.

src/post_process/m_checker.fpp

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
!>
2+
!!@file m_checker.f90
3+
!!@brief Contains module m_checker
4+
5+
#:include 'macros.fpp'
6+
7+
!> @brief The purpose of the module is to check for compatible input files
8+
module m_checker
9+
10+
use m_global_parameters !< Definitions of the global parameters
11+
12+
use m_mpi_proxy !< Message passing interface (MPI) module proxy
13+
14+
use m_helper_basic !< Functions to compare floating point numbers
15+
16+
use m_helper
17+
18+
implicit none
19+
20+
private; public :: s_check_inputs
21+
22+
contains
23+
24+
!> Checks compatibility of parameters in the input file.
25+
!! Used by the post_process stage
26+
subroutine s_check_inputs
27+
28+
call s_check_inputs_output_format
29+
call s_check_inputs_partial_density
30+
call s_check_inputs_velocity
31+
call s_check_inputs_flux_limiter
32+
call s_check_inputs_volume_fraction
33+
call s_check_inputs_vorticity
34+
call s_check_inputs_schlieren
35+
call s_check_inputs_surface_tension
36+
call s_check_inputs_no_flow_variables
37+
38+
end subroutine s_check_inputs
39+
40+
!> Checks constraints on output format parameters
41+
subroutine s_check_inputs_output_format
42+
@:PROHIBIT(format /= 1 .and. format /= 2)
43+
@:PROHIBIT(precision /= 1 .and. precision /= 2)
44+
end subroutine s_check_inputs_output_format
45+
46+
!> Checks constraints on partial density parameters
47+
subroutine s_check_inputs_partial_density
48+
character(len=5) :: iStr
49+
integer :: i
50+
51+
do i = 1, num_fluids
52+
call s_int_to_str(i, iStr)
53+
@:PROHIBIT(alpha_rho_wrt(i) .and. model_eqns == 1, "alpha_rho_wrt("//trim(iStr)//") is not supported for model_eqns = 1")
54+
@:PROHIBIT(alpha_rho_wrt(i) .and. i > num_fluids, "Index of alpha_rho_wrt("//trim(iStr)//") exceeds the total number of fluids")
55+
end do
56+
end subroutine s_check_inputs_partial_density
57+
58+
!> Checks constraints on momentum parameters
59+
subroutine s_check_inputs_momentum
60+
@:PROHIBIT(n == 0 .and. mom_wrt(2))
61+
@:PROHIBIT(p == 0 .and. mom_wrt(3))
62+
end subroutine s_check_inputs_momentum
63+
64+
!> Checks constraints on velocity parameters
65+
subroutine s_check_inputs_velocity
66+
@:PROHIBIT(n == 0 .and. vel_wrt(2))
67+
@:PROHIBIT(p == 0 .and. vel_wrt(3))
68+
end subroutine s_check_inputs_velocity
69+
70+
!> Checks constraints on flux limiter parameters
71+
subroutine s_check_inputs_flux_limiter
72+
@:PROHIBIT(n == 0 .and. flux_wrt(2))
73+
@:PROHIBIT(p == 0 .and. flux_wrt(3))
74+
@:PROHIBIT(all(flux_lim /= (/dflt_int, 1, 2, 3, 4, 5, 6, 7/)), "flux_lim must be between 1 and 7")
75+
end subroutine s_check_inputs_flux_limiter
76+
77+
!> Checks constraints on volume fraction parameters
78+
subroutine s_check_inputs_volume_fraction
79+
character(len=5) :: iStr
80+
integer :: i
81+
82+
do i = 1, num_fluids
83+
call s_int_to_str(i, iStr)
84+
@:PROHIBIT(alpha_wrt(i) .and. model_eqns == 1, "alpha_wrt("//trim(iStr)//") is not supported for model_eqns = 1")
85+
@:PROHIBIT(alpha_wrt(i) .and. i > num_fluids, "Index of alpha_wrt("//trim(iStr)//") exceeds the total number of fluids")
86+
end do
87+
end subroutine s_check_inputs_volume_fraction
88+
89+
!> Checks constraints on vorticity parameters
90+
subroutine s_check_inputs_vorticity
91+
@:PROHIBIT(n == 0 .and. any(omega_wrt))
92+
@:PROHIBIT(p == 0 .and. (omega_wrt(1) .or. omega_wrt(2)))
93+
@:PROHIBIT(any(omega_wrt) .and. fd_order == dflt_int, "fd_order must be set for omega_wrt")
94+
end subroutine s_check_inputs_vorticity
95+
96+
!> Checks constraints on numerical Schlieren parameters
97+
!! (schlieren_wrt and schlieren_alpha)
98+
subroutine s_check_inputs_schlieren
99+
character(len=5) :: iStr
100+
integer :: i
101+
102+
@:PROHIBIT(n == 0 .and. schlieren_wrt)
103+
@:PROHIBIT(schlieren_wrt .and. fd_order == dflt_int, "fd_order must be set for schlieren_wrt")
104+
105+
do i = 1, num_fluids
106+
call s_int_to_str(i, iStr)
107+
@:PROHIBIT(.not. f_is_default(schlieren_alpha(i)) .and. schlieren_alpha(i) <= 0d0, &
108+
"schlieren_alpha("//trim(iStr)//") must be greater than zero")
109+
@:PROHIBIT(.not. f_is_default(schlieren_alpha(i)) .and. i > num_fluids, &
110+
"Index of schlieren_alpha("//trim(iStr)//") exceeds the total number of fluids")
111+
@:PROHIBIT(.not. f_is_default(schlieren_alpha(i)) .and. (.not. schlieren_wrt), &
112+
"schlieren_alpha("//trim(iStr)//") should be set only with schlieren_wrt enabled")
113+
end do
114+
end subroutine s_check_inputs_schlieren
115+
116+
!> Checks constraints on surface tension parameters (cf_wrt and sigma)
117+
subroutine s_check_inputs_surface_tension
118+
@:PROHIBIT(cf_wrt .and. f_is_default(sigma), &
119+
"cf_wrt can only be enabled if the surface coefficient is set")
120+
end subroutine s_check_inputs_surface_tension
121+
122+
!> Checks constraints on the absence of flow variables
123+
subroutine s_check_inputs_no_flow_variables
124+
@:PROHIBIT(.not. any([ &
125+
(/rho_wrt, E_wrt, pres_wrt, gamma_wrt, heat_ratio_wrt, pi_inf_wrt, &
126+
pres_inf_wrt, cons_vars_wrt, prim_vars_wrt, c_wrt, schlieren_wrt/), &
127+
alpha_rho_wrt, mom_wrt, vel_wrt, flux_wrt, alpha_wrt, omega_wrt]), &
128+
"None of the flow variables have been selected for post-process. Exiting ...")
129+
end subroutine s_check_inputs_no_flow_variables
130+
131+
end module m_checker

0 commit comments

Comments
 (0)