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

Preview of scalar as a simcomp #1129

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
45 changes: 28 additions & 17 deletions examples/scalar_mms/scalar_mms.case
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,30 @@
"absolute_tolerance": 1e-7,
"max_iterations": 800
},
"output_control": "nsamples",
"output_value": 1
"output_control": "never"
},
"scalar": {
"enabled": true,
"simulation_components": [
{
"type": "probes",
"compute_control": "simulationtime",
"compute_value": 1,
"points_file": "probes.csv",
"output_file": "output.csv",
"fields": [
"s"
],
"order" : 2
},
{
"type" : "scalar",
"lambda": 0.01,
"cp": 1,
"initial_condition": {
"type": "user"
},
"output_filename" : "scalar",
"output_control" : "nsamples",
"output_value" : 1,
"source_terms": [
{
"type": "user_vector"
Expand All @@ -54,19 +68,16 @@
"1.0"
]
}
]
},
"simulation_components": [
{
"type": "probes",
"compute_control": "nsamples",
"compute_value": 1,
"points_file": "probes.csv",
"output_file": "output.csv",
"fields": [
"s"
]
],
"order": 1,
"solver": {
"type": "cg",
"preconditioner": "jacobi",
"projection_space_size": 0,
"absolute_tolerance": 1e-7,
"max_iterations": 800
}
}
]
}
}
}
7 changes: 4 additions & 3 deletions src/.depends
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ common/bcknd/sx/rhs_maker_sx.o : common/bcknd/sx/rhs_maker_sx.f90 field/scratch_
common/bcknd/device/rhs_maker_device.o : common/bcknd/device/rhs_maker_device.F90 config/num_types.o field/field.o field/field_series.o common/utils.o device/device.o common/rhs_maker.o
common/material_properties.o : common/material_properties.f90 comm/comm.o common/utils.o common/user_intf.o common/log.o common/json_utils.o config/num_types.o
config/neko_config.o : config/neko_config.f90
case.o : case.f90 common/material_properties.o mesh/point_zone_registry.o field/scratch_registry.o common/json_utils.o scalar/scalar_pnpn.o common/user_intf.o common/jobctrl.o common/log.o time_schemes/time_scheme_controller.o comm/comm.o mesh/mesh.o common/utils.o io/file.o common/statistics.o scalar/scalar_ic.o fluid/flow_ic.o common/sampler.o comm/redist.o comm/parmetis.o field/mesh_field.o io/fluid_stats_output.o io/mean_flow_output.o io/mean_sqr_flow_output.o io/chkp_output.o io/fluid_output.o fluid/fluid_fctry.o config/num_types.o
case.o : case.f90 common/material_properties.o mesh/point_zone_registry.o field/scratch_registry.o common/json_utils.o common/user_intf.o common/jobctrl.o common/log.o time_schemes/time_scheme_controller.o comm/comm.o mesh/mesh.o common/utils.o io/file.o common/statistics.o fluid/flow_ic.o common/sampler.o comm/redist.o comm/parmetis.o field/mesh_field.o io/fluid_stats_output.o io/mean_flow_output.o io/mean_sqr_flow_output.o io/chkp_output.o io/fluid_output.o fluid/fluid_fctry.o config/num_types.o
common/user_intf.o : common/user_intf.f90 common/utils.o config/num_types.o bc/usr_scalar.o bc/usr_inflow.o mesh/mesh.o sem/coef.o scalar/scalar_user_source_term.o fluid/fluid_user_source_term.o field/field.o
fluid/fluid_scheme.o : fluid/fluid_scheme.f90 common/material_properties.o common/utils.o common/user_intf.o field/scratch_registry.o common/json_utils.o field/field_registry.o common/log.o math/operators.o math/mathops.o time_schemes/time_scheme_controller.o math/math.o mesh/mesh.o bc/bc.o fluid/fluid_stats.o krylov/precon_fctry.o krylov/krylov_fctry.o bc/non_normal.o bc/symmetry.o bc/dong_outflow.o bc/dirichlet.o bc/blasius.o bc/usr_inflow.o bc/inflow.o bc/wall.o sem/coef.o krylov/krylov.o sem/dofmap.o sem/space.o field/field.o field/field_list.o fluid/fluid_source_term.o fluid/fluid_user_source_term.o config/num_types.o fluid/mean_flow.o common/checkpoint.o config/neko_config.o fluid/mean_sqr_flow.o gs/gather_scatter.o
fluid/fluid_aux.o : fluid/fluid_aux.f90 krylov/krylov.o config/num_types.o common/log.o
Expand Down Expand Up @@ -235,8 +235,9 @@ simulation_components/simulation_component.o : simulation_components/simulation_
simulation_components/simcomp_executor.o : simulation_components/simcomp_executor.f90 case.o common/json_utils.o simulation_components/simulation_component_factory.o simulation_components/simulation_component.o config/num_types.o
simulation_components/vorticity.o : simulation_components/vorticity.f90 common/json_utils.o io/fld_file_output.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/lambda2.o : simulation_components/lambda2.f90 device/device.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/scalar.o : simulation_components/scalar.f90 common/json_utils.o scalar/scalar_ic.o common/log.o scalar/scalar_pnpn.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/les_simcomp.o : simulation_components/les_simcomp.f90 common/json_utils.o les/les_model_fctry.o les/les_model.o case.o math/operators.o field/field.o field/field_registry.o simulation_components/simulation_component.o config/num_types.o
simulation_components/simulation_component_factory.o : simulation_components/simulation_component_factory.f90 common/log.o common/json_utils.o case.o simulation_components/les_simcomp.o simulation_components/probes.o simulation_components/lambda2.o simulation_components/vorticity.o simulation_components/simulation_component.o
simulation_components/simulation_component_factory.o : simulation_components/simulation_component_factory.f90 common/log.o common/json_utils.o case.o simulation_components/les_simcomp.o simulation_components/probes.o simulation_components/scalar.o simulation_components/lambda2.o simulation_components/vorticity.o simulation_components/simulation_component.o
source_terms/source_term.o : source_terms/source_term.f90 field/field_list.o sem/coef.o config/num_types.o config/neko_config.o
source_terms/const_source_term.o : source_terms/const_source_term.f90 source_terms/bcknd/device/const_source_term_device.o source_terms/bcknd/cpu/const_source_term_cpu.o common/utils.o config/neko_config.o sem/coef.o source_terms/source_term.o common/json_utils.o field/field_list.o config/num_types.o
source_terms/bcknd/cpu/const_source_term_cpu.o : source_terms/bcknd/cpu/const_source_term_cpu.f90 math/math.o field/field_list.o config/num_types.o
Expand All @@ -246,5 +247,5 @@ les/les_model.o : les/les_model.f90 device/device.o config/neko_config.o gs/gs_o
les/les_model_fctry.o : les/les_model_fctry.f90 sem/coef.o sem/dofmap.o les/vreman.o les/les_model.o
les/vreman.o : les/vreman.f90 sem/coef.o les/bcknd/cpu/vreman_cpu.o config/neko_config.o common/utils.o common/json_utils.o sem/dofmap.o les/les_model.o field/field.o config/num_types.o
les/bcknd/cpu/vreman_cpu.o : les/bcknd/cpu/vreman_cpu.f90 sem/coef.o math/operators.o field/field.o field/field_registry.o field/scratch_registry.o math/math.o field/field_list.o config/num_types.o
neko.o : neko.f90 mesh/point_zone_registry.o mesh/point_zones/sphere_point_zone.o mesh/point_zones/box_point_zone.o mesh/point_zone.o sem/point_interpolator.o common/time_interpolator.o io/data_streamer.o simulation_components/simcomp_executor.o field/scratch_registry.o field/field_registry.o common/system.o sem/spectral_error_indicator.o simulation_components/probes.o simulation_components/simulation_component.o math/tensor.o math/vector.o fluid/fluid_user_source_term.o field/field_list.o fluid/fluid_stats.o sem/cpr.o math/bcknd/device/device_math.o device/device.o common/jobctrl.o common/signal.o comm/parmetis.o common/user_intf.o common/projection.o math/mathops.o math/operators.o simulation.o io/output.o common/sampler.o case.o config/neko_config.o math/ax.o math/ax_helm_fctry.o krylov/precon_fctry.o krylov/krylov_fctry.o bc/dirichlet.o bc/wall.o bc/bc.o sem/coef.o gs/gather_scatter.o comm/mpi_types.o field/field.o io/file.o common/global_interpolation.o math/mxm_wrapper.o io/format/map.o field/mesh_field.o mesh/point.o mesh/mesh.o adt/tuple.o adt/stack.o adt/uset.o adt/htable.o sem/space.o sem/dofmap.o sem/speclib.o math/math.o common/log.o common/utils.o comm/comm.o config/num_types.o
neko.o : neko.f90 mesh/point_zone_registry.o mesh/point_zones/sphere_point_zone.o mesh/point_zones/box_point_zone.o mesh/point_zone.o sem/point_interpolator.o common/time_interpolator.o io/data_streamer.o simulation_components/simcomp_executor.o field/scratch_registry.o field/field_registry.o common/system.o sem/spectral_error_indicator.o simulation_components/probes.o simulation_components/simulation_component.o math/tensor.o math/vector.o scalar/scalar_user_source_term.o fluid/fluid_user_source_term.o field/field_list.o fluid/fluid_stats.o sem/cpr.o math/bcknd/device/device_math.o device/device.o common/jobctrl.o common/signal.o comm/parmetis.o common/user_intf.o common/projection.o math/mathops.o math/operators.o simulation.o io/output.o common/sampler.o case.o config/neko_config.o math/ax.o math/ax_helm_fctry.o krylov/precon_fctry.o krylov/krylov_fctry.o bc/dirichlet.o bc/wall.o bc/bc.o sem/coef.o gs/gather_scatter.o comm/mpi_types.o field/field.o io/file.o common/global_interpolation.o math/mxm_wrapper.o io/format/map.o field/mesh_field.o mesh/point.o mesh/mesh.o adt/tuple.o adt/stack.o adt/uset.o adt/htable.o sem/space.o sem/dofmap.o sem/speclib.o math/math.o common/log.o common/utils.o comm/comm.o config/num_types.o
driver.o : driver.f90 neko.o
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ neko_fortran_SOURCES = \
simulation_components/simcomp_executor.f90\
simulation_components/vorticity.f90\
simulation_components/lambda2.f90\
simulation_components/scalar.f90\
simulation_components/les_simcomp.f90\
simulation_components/simulation_component_factory.f90\
source_terms/source_term.f90\
Expand Down
59 changes: 2 additions & 57 deletions src/case.f90
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module case
use redist
use sampler
use flow_ic
use scalar_ic, only : set_scalar_ic
use stats
use file
use utils
Expand All @@ -55,7 +54,6 @@ module case
use logger
use jobctrl
use user_intf
use scalar_pnpn ! todo directly load the pnpn? can we have other
use json_module, only : json_file, json_core, json_value
use json_utils, only : json_get, json_get_or_default
use scratch_registry, only : scratch_registry_t, neko_scratch_registry
Expand All @@ -80,7 +78,6 @@ module case
type(stats_t) :: q
type(user_t) :: usr
class(fluid_scheme_t), allocatable :: fluid
type(scalar_pnpn_t), allocatable :: scalar
type(material_properties_t):: material_properties
end type case_t

Expand Down Expand Up @@ -139,7 +136,6 @@ subroutine case_init_common(C)
type(case_t), target, intent(inout) :: C
character(len=:), allocatable :: output_directory
integer :: lx = 0
logical :: scalar = .false.
type(file_t) :: msh_file, bdry_file, part_file
type(mesh_fld_t) :: msh_part, parts
logical :: found, logical_val
Expand Down Expand Up @@ -227,25 +223,6 @@ subroutine case_init_common(C)
!
call neko_point_zone_registry%init(C%params, C%fluid%u%dof)

!
! Setup scalar scheme
!
! @todo no scalar factory for now, probably not needed
if (C%params%valid_path('case.scalar')) then
call json_get_or_default(C%params, 'case.scalar.enabled', scalar,&
.true.)
end if

if (scalar) then
allocate(C%scalar)
call C%scalar%init(C%msh, C%fluid%c_Xh, C%fluid%gs_Xh, C%params, C%usr,&
C%material_properties)
call C%fluid%chkp%add_scalar(C%scalar%s)
C%fluid%chkp%abs1 => C%scalar%abx1
C%fluid%chkp%abs2 => C%scalar%abx2
C%fluid%chkp%slag => C%scalar%slag
end if

!
! Setup user defined conditions
!
Expand All @@ -257,11 +234,6 @@ subroutine case_init_common(C)
end if
end if

! Setup user boundary conditions for the scalar.
if (scalar) then
call C%scalar%set_user_bc(C%usr%scalar_user_bc)
end if

!
! Setup initial conditions
!
Expand All @@ -275,17 +247,6 @@ subroutine case_init_common(C)
C%fluid%c_Xh, C%fluid%gs_Xh, C%usr%fluid_user_ic, C%params)
end if

if (scalar) then
call json_get(C%params, 'case.scalar.initial_condition.type', string_val)
if (trim(string_val) .ne. 'user') then
call set_scalar_ic(C%scalar%s, &
C%scalar%c_Xh, C%scalar%gs_Xh, string_val, C%params)
else
call set_scalar_ic(C%scalar%s, &
C%scalar%c_Xh, C%scalar%gs_Xh, C%usr%scalar_user_ic, C%params)
end if
end if

! Add initial conditions to BDF scheme (if present)
select type(f => C%fluid)
type is(fluid_pnpn_t)
Expand All @@ -300,11 +261,6 @@ subroutine case_init_common(C)
!
call C%fluid%validate

if (scalar) then
call C%scalar%slag%set(C%scalar%s)
call C%scalar%validate
end if

!
! Set order of timestepper
!
Expand Down Expand Up @@ -363,16 +319,10 @@ subroutine case_init_common(C)
end if

!
! Setup sampler
! Setup sampler and add fluid output
!
call C%s%init(C%end_time)
if (scalar) then
C%f_out = fluid_output_t(precision, C%fluid, C%scalar, &
path=trim(output_directory))
else
C%f_out = fluid_output_t(precision, C%fluid, &
path=trim(output_directory))
end if
C%f_out = fluid_output_t(precision, C%fluid, path=trim(output_directory))

call json_get_or_default(C%params, 'case.fluid.output_control',&
string_val, 'org')
Expand Down Expand Up @@ -485,11 +435,6 @@ subroutine case_free(C)
deallocate(C%fluid)
end if

if (allocated(C%scalar)) then
call C%scalar%free()
deallocate(C%scalar)
end if

call C%msh%free()

call C%s%free()
Expand Down
22 changes: 21 additions & 1 deletion src/common/json_utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module json_utils
implicit none
private

public :: json_get, json_get_or_default
public :: json_get, json_get_or_default, json_extract_subdict

!> Retrieves a parameter by name or throws an error
interface json_get
Expand Down Expand Up @@ -296,4 +296,24 @@ subroutine json_get_or_default_string(json, name, value, default)
end if
end subroutine json_get_or_default_string

!> Extract `i`th json object from a json array.
!! @param core JSON core object.
!! @param parent The parent JSON object with the array.
!! @param i The index of the object to extract.
!! @param subdict JSON object object to be filled with the subdict.
subroutine json_extract_subdict(core, parent, i, subdict)
type(json_core), intent(inout) :: core
type(json_value), pointer, intent(in) :: parent
integer, intent(in) :: i
type(json_file), intent(inout) :: subdict
type(json_value), pointer :: ptr
logical :: found
character(len=:), allocatable :: buffer

call core%get_child(parent, i, ptr, found)
call core%print_to_string(ptr, buffer)
call subdict%load_from_string(buffer)

end subroutine json_extract_subdict

end module json_utils
53 changes: 5 additions & 48 deletions src/common/material_properties.f90
Original file line number Diff line number Diff line change
Expand Up @@ -126,56 +126,13 @@ subroutine material_properties_init(this, params, user)
end if

!
! Scalar
! Scalar dummy values
!
if (.not. params%valid_path('case.scalar')) then
! Set dummy values
this%cp = 1.0_rp
this%lambda = 1.0_rp
call this%write_to_log(.false.)
return
end if

! Incorrect user input
if (nondimensional .and. &
(params%valid_path('case.scalar.lambda') .or. &
params%valid_path('case.scalar.cp'))) then
call neko_error("For non-dimensional setup set the Pe number for&
& the scalar")
else if (.not. nondimensional .and. &
params%valid_path('case.scalar.Pe')) then
call neko_error("Dimensional material properties input detected,&
& because you set rho and mu for the fluid. &
& Please set cp and lambda for the scalar.")

! Non-dimensional case
else if (nondimensional) then
write(log_buf, '(A)') 'Non-dimensional scalar material properties &
& input.'
call neko_log%message(log_buf, lvl=NEKO_LOG_VERBOSE)
write(log_buf, '(A)') 'Specific heat capacity will be set to 1, &
& conductivity to 1/Pe.'
call neko_log%message(log_buf, lvl=NEKO_LOG_VERBOSE)

! Read Pe into lambda for further manipulation.
call json_get(params, 'case.scalar.Pe', this%lambda)
write(log_buf, '(A,ES13.6)') 'Pe :', this%lambda
call neko_log%message(log_buf)

! Set cp and rho to 1 since the setup is non-dimensional.
this%cp = 1.0_rp
this%rho = 1.0_rp
! Invert the Pe to get conductivity
this%lambda = 1.0_rp/this%lambda
! Dimensional case
else
call json_get(params, 'case.scalar.lambda', this%lambda)
call json_get(params, 'case.scalar.cp', this%cp)
end if
this%cp = 1.0_rp
this%lambda = 1.0_rp
call this%write_to_log(.false.)
return
end if

call this%write_to_log(.true.)

end subroutine material_properties_init

!> Write final dimensional values to the log.
Expand Down
2 changes: 1 addition & 1 deletion src/io/fld_file_output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ subroutine fld_file_output_init(this, precision, name, nfields, path)
deallocate(this%fields%fields)
end if

allocate(this%fields%fields(3))
allocate(this%fields%fields(nfields))

end subroutine fld_file_output_init

Expand Down
Loading
Loading