Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON subdictionary for setting initial conditions #1738

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/pages/user-guide/case-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ file documentation.
2. `uniform`, the value is a constant vector, looked up under the `value`
keyword.
3. `blasius`, a Blasius profile is prescribed. Its properties are looked up
in the `case.fluid.blasius` object, see below.
in the `case.fluid.initial_condition.blasius` object, see below.
4. `point_zone`, the values are set to a constant base value, supplied under the
`base_value` keyword, and then assigned a zone value inside a point zone. The
point zone is specified by the `name` keyword, and should be defined in the
Expand Down
12 changes: 6 additions & 6 deletions examples/hemi/hemi.case
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"scheme": "pnpn",
"Re": 1400,
"initial_condition": {
"type": "blasius"
},
"blasius": {
"approximation": "sin",
"delta": 0.6,
"freestream_velocity": [1.0, 0.0, 0.0]
"type": "blasius",
"blasius": {
"approximation": "sin",
"delta": 0.6,
"freestream_velocity": [1.0, 0.0, 0.0]
}
},
"velocity_solver": {
"type": "cg",
Expand Down
11 changes: 8 additions & 3 deletions src/case.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module case
use user_intf, only : user_t
use scalar_pnpn, only : scalar_pnpn_t
use json_module, only : json_file
use json_utils, only : json_get, json_get_or_default
use json_utils, only : json_get, json_get_or_default, json_extract_object
use scratch_registry, only : scratch_registry_t, neko_scratch_registry
use point_zone_registry, only: neko_point_zone_registry
implicit none
Expand Down Expand Up @@ -147,6 +147,7 @@ subroutine case_init_common(this)
character(len = :), allocatable :: string_val
integer :: output_dir_len
integer :: precision
type(json_file) :: json_subdict

!
! Load mesh
Expand Down Expand Up @@ -264,13 +265,15 @@ subroutine case_init_common(this)
!
call json_get(this%params, 'case.fluid.initial_condition.type',&
string_val)
call json_extract_object(this%params, 'case.fluid.initial_condition', &
json_subdict)

call neko_log%section("Fluid initial condition ")

if (trim(string_val) .ne. 'user') then
call set_flow_ic(this%fluid%u, this%fluid%v, this%fluid%w, &
this%fluid%p, this%fluid%c_Xh, this%fluid%gs_Xh, string_val, &
this%params)
json_subdict)
else
call json_get(this%params, 'case.fluid.scheme', string_val)
if (trim(string_val) .eq. 'compressible') then
Expand All @@ -291,12 +294,14 @@ subroutine case_init_common(this)

call json_get(this%params, 'case.scalar.initial_condition.type', &
string_val)
call json_extract_object(this%params, 'case.scalar.initial_condition', &
json_subdict)

call neko_log%section("Scalar initial condition ")

if (trim(string_val) .ne. 'user') then
call set_scalar_ic(this%scalar%s, &
this%scalar%c_Xh, this%scalar%gs_Xh, string_val, this%params)
this%scalar%c_Xh, this%scalar%gs_Xh, string_val, json_subdict)
else
call set_scalar_ic(this%scalar%s, &
this%scalar%c_Xh, this%scalar%gs_Xh, this%usr%scalar_user_ic, &
Expand Down
47 changes: 20 additions & 27 deletions src/fluid/flow_ic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ module flow_ic
private

interface set_flow_ic
module procedure set_flow_ic_int, set_flow_ic_usr, set_compressible_flow_ic_usr
module procedure set_flow_ic_int, set_flow_ic_usr, &
set_compressible_flow_ic_usr
end interface set_flow_ic

public :: set_flow_ic
Expand Down Expand Up @@ -90,18 +91,17 @@ subroutine set_flow_ic_int(u, v, w, p, coef, gs, type, params)
!
if (trim(type) .eq. 'uniform') then

call json_get(params, 'case.fluid.initial_condition.value', uinf)
call json_get(params, 'value', uinf)
call set_flow_ic_uniform(u, v, w, uinf)

!
! Blasius boundary layer
!
else if (trim(type) .eq. 'blasius') then

call json_get(params, 'case.fluid.blasius.delta', delta)
call json_get(params, 'case.fluid.blasius.approximation', &
read_str)
call json_get(params, 'case.fluid.blasius.freestream_velocity', uinf)
call json_get(params, 'blasius.delta', delta)
call json_get(params, 'blasius.approximation', read_str)
call json_get(params, 'blasius.freestream_velocity', uinf)

call set_flow_ic_blasius(u, v, w, delta, uinf, read_str)

Expand All @@ -110,11 +110,9 @@ subroutine set_flow_ic_int(u, v, w, p, coef, gs, type, params)
!
else if (trim(type) .eq. 'point_zone') then

call json_get(params, 'case.fluid.initial_condition.base_value', uinf)
call json_get(params, 'case.fluid.initial_condition.zone_name', &
read_str)
call json_get(params, 'case.fluid.initial_condition.zone_value', &
zone_value)
call json_get(params, 'base_value', uinf)
call json_get(params, 'zone_name', read_str)
call json_get(params, 'zone_value', zone_value)

call set_flow_ic_point_zone(u, v, w, uinf, read_str, zone_value)

Expand All @@ -123,17 +121,12 @@ subroutine set_flow_ic_int(u, v, w, p, coef, gs, type, params)
!
else if (trim(type) .eq. 'field') then

call json_get(params, 'case.fluid.initial_condition.file_name', &
read_str)
call json_get(params, 'file_name', read_str)
fname = trim(read_str)
call json_get_or_default(params, &
'case.fluid.initial_condition.interpolate', interpolate, &
call json_get_or_default(params, 'interpolate', interpolate, &
.false.)
call json_get_or_default(params, &
'case.fluid.initial_condition.tolerance', tol, 0.000001_rp)
call json_get_or_default(params, &
'case.fluid.initial_condition.mesh_file_name', read_str, &
"none")
call json_get_or_default(params, 'tolerance', tol, 0.000001_rp)
call json_get_or_default(params, 'mesh_file_name', read_str, "none")
mesh_fname = trim(read_str)

call set_flow_ic_fld(u, v, w, p, fname, interpolate, tol, mesh_fname)
Expand Down Expand Up @@ -422,7 +415,7 @@ subroutine set_flow_ic_fld(u, v, w, p, file_name, &

if (sample_idx .eq. -1) &
call neko_error("Invalid file name for the initial condition. The&
& file format must be e.g. 'mean0.f00001'")
& file format must be e.g. 'mean0.f00001'")

! Change from "field0.f000*" to "field0.fld" for the fld reader
call filename_chsuffix(file_name, file_name, 'fld')
Expand All @@ -443,7 +436,7 @@ subroutine set_flow_ic_fld(u, v, w, p, file_name, &

if (sample_mesh_idx .eq. -1) then
call neko_error("Invalid file name for the initial condition. &
&The file format must be e.g. 'mean0.f00001'")
&The file format must be e.g. 'mean0.f00001'")
end if

write (log_buf, '(A,ES12.6)') "Tolerance : ", tolerance
Expand Down Expand Up @@ -477,10 +470,10 @@ subroutine set_flow_ic_fld(u, v, w, p, file_name, &

if (mesh_mismatch .and. .not. interpolate) then
call neko_error("The fld file must match the current mesh! &
&Use 'interpolate': 'true' to enable interpolation.")
&Use 'interpolate': 'true' to enable interpolation.")
else if (.not. mesh_mismatch .and. interpolate) then
call neko_log%warning("You have activated interpolation but you might &
&still be using the same mesh.")
&still be using the same mesh.")
end if

! Mesh interpolation if specified
Expand All @@ -491,11 +484,11 @@ subroutine set_flow_ic_fld(u, v, w, p, file_name, &
type is (fld_file_t)
if (.not. ft%dp_precision) then
call neko_warning("The coordinates read from the field file are &
&in single precision.")
&in single precision.")
call neko_log%message("It is recommended to use a mesh in double &
&precision for better interpolation results.")
&precision for better interpolation results.")
call neko_log%message("If the interpolation does not work, you&
&can try to increase the tolerance.")
&can try to increase the tolerance.")
end if
class default
end select
Expand Down
39 changes: 16 additions & 23 deletions src/scalar/scalar_ic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,25 @@ subroutine set_scalar_ic_int(s, coef, gs, type, params)

if (trim(type) .eq. 'uniform') then

call json_get(params, 'case.scalar.initial_condition.value', ic_value)
call json_get(params, 'value', ic_value)
call set_scalar_ic_uniform(s, ic_value)

else if (trim(type) .eq. 'point_zone') then

call json_get(params, 'case.scalar.initial_condition.base_value', &
ic_value)
call json_get(params, 'case.scalar.initial_condition.zone_name', &
read_str)
call json_get(params, 'case.scalar.initial_condition.zone_value', &
zone_value)
call json_get(params, 'base_value', ic_value)
call json_get(params, 'zone_name', read_str)
call json_get(params, 'zone_value', zone_value)

call set_scalar_ic_point_zone(s, ic_value, read_str, zone_value)

else if (trim(type) .eq. 'field') then

call json_get(params, 'case.scalar.initial_condition.file_name', &
read_str)
call json_get(params, 'file_name', read_str)
fname = trim(read_str)
call json_get_or_default(params, &
'case.scalar.initial_condition.interpolate', interpolate, &
call json_get_or_default(params, 'interpolate', interpolate, &
.false.)
call json_get_or_default(params, &
'case.scalar.initial_condition.tolerance', tol, 0.000001_rp)
call json_get_or_default(params, &
'case.scalar.initial_condition.mesh_file_name', read_str, &
call json_get_or_default(params, 'tolerance', tol, 0.000001_rp)
call json_get_or_default(params, 'mesh_file_name', read_str, &
"none")
mesh_fname = trim(read_str)

Expand Down Expand Up @@ -288,7 +281,7 @@ subroutine set_scalar_ic_fld(s, file_name, &

if (sample_idx .eq. -1) &
call neko_error("Invalid file name for the initial condition. The&
& file format must be e.g. 'mean0.f00001'")
& file format must be e.g. 'mean0.f00001'")

! Change from "field0.f000*" to "field0.fld" for the fld reader
call filename_chsuffix(file_name, file_name, 'fld')
Expand All @@ -309,11 +302,11 @@ subroutine set_scalar_ic_fld(s, file_name, &

if (sample_mesh_idx .eq. -1) &
call neko_error("Invalid file name for the initial condition. &
&The file format must be e.g. 'mean0.f00001'")
&The file format must be e.g. 'mean0.f00001'")

write (log_buf, '(A,ES12.6)') "Tolerance : ", tolerance
call neko_log%message(log_buf)
write (log_buf, '(A,A)') "Mesh file : ", &
write (log_buf, '(A,A)') "Mesh file : ", &
trim(mesh_file_name)
call neko_log%message(log_buf)

Expand Down Expand Up @@ -342,10 +335,10 @@ subroutine set_scalar_ic_fld(s, file_name, &

if (mesh_mismatch .and. .not. interpolate) then
call neko_error("The fld file must match the current mesh! &
&Use 'interpolate': 'true' to enable interpolation.")
&Use 'interpolate': 'true' to enable interpolation.")
else if (.not. mesh_mismatch .and. interpolate) then
call neko_log%warning("You have activated interpolation but you might &
&still be using the same mesh.")
&still be using the same mesh.")
end if


Expand All @@ -356,11 +349,11 @@ subroutine set_scalar_ic_fld(s, file_name, &
type is (fld_file_t)
if (.not. ft%dp_precision) then
call neko_warning("The coordinates read from the field file are &
&in single precision.")
&in single precision.")
call neko_log%message("It is recommended to use a mesh in double &
&precision for better interpolation results.")
&precision for better interpolation results.")
call neko_log%message("If the interpolation does not work, you&
&can try to increase the tolerance.")
&can try to increase the tolerance.")
end if
class default
end select
Expand Down
Loading