Skip to content

Commit

Permalink
Merge pull request #1366 from ExtremeFLOW/feature/field-initial-condi…
Browse files Browse the repository at this point in the history
…tion

Initial condition from fld or chkp
  • Loading branch information
MartinKarp authored Oct 4, 2024
2 parents 1118210 + f511098 commit c31fc84
Show file tree
Hide file tree
Showing 9 changed files with 857 additions and 187 deletions.
41 changes: 39 additions & 2 deletions doc/pages/user-guide/case-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ file documentation.
`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
`case.point_zones` object. See more about point zones @ref point-zones.md.
5. `field`, where the initial condition is retrieved from a field file.
The following keywords can be used:

| Name | Description | Admissible values | Default value |
| ---------------- | -------------------------------------------------------------------------------------------------- | ---------------------------- | ------------- |
| `file_name` | Name of the field file to use (e.g. `myfield0.f00034`). | Strings ending with `f*****` | - |
| `interpolate` | Whether to interpolate the velocity and pressure fields from the field file onto the current mesh. | `true` or `false` | `false` |
| `tolerance` | Tolerance for the point search. | Positive real. | `1e-6` |
| `mesh_file_name` | If interpolation is enabled, the name of the field file that contains the mesh coordinates. | Strings ending with `f*****` | `file_name` |

@attention Interpolating a field from the same mesh but different
polynomial order is performed implicitly and does not require to enable
interpolation.

@note It is recommended to interpolate from `fld` files that were
written in double precision.
To check if your `fld` file was written in double precision, run
the command:
~~~~~~~~~~~~~~~{.sh}
head -1 field0.f00000
~~~~~~~~~~~~~~~
The output `#std 4 ...` indicates single precision,
whereas `#std 8 ...` indicates double precision.
Neko write single precision `fld` files by default. To write your
files in double precision, set `case.output_precision` to
`"double"`.

@attention Neko does not detect wether interpolation is needed or not.
Interpolation will always be performed if `"interpolate"` is set
to `true` even if the field file matches with the current simulation.

### Blasius profile
The `blasius` object is used to specify the Blasius profile that can be used for the
Expand Down Expand Up @@ -467,8 +497,12 @@ that can be described concisely directly in the table.
| `output_value` | The frequency of sampling in terms of `output_control`. | Positive real or integer | - |
| `inflow_condition.type` | Velocity inflow condition type. | `user`, `uniform`, `blasius` | - |
| `inflow_condition.value` | Value of the inflow velocity. | Vector of 3 reals | - |
| `initial_condition.type` | Initial condition type. | `user`, `uniform`, `blasius` | - |
| `initial_condition.type` | Initial condition type. | `user`, `uniform`, `blasius`, `field` | - |
| `initial_condition.value` | Value of the velocity initial condition. | Vector of 3 reals | - |
| `initial_condition.file_name` | If `"type" = "field"`, the path to the field file to read from. | String ending with `.fld`, `.chkp`, `.nek5000` or `f*****`. | - |
| `initial_condition.sample_index` | If `"type" = "field"`, and file type is `fld` or `nek5000`, the index of the file to sampled. | Positive integer. | -1 |
| `initial_condition.previous_mesh` | If `"type" = "field"`, and file type is `chkp`, the previous mesh from which to interpolate. | String ending with `.nmsh`. | - |
| `initial_condition.tolerance` | If `"type" = "field"`, and file type is `chkp`, tolerance to use for mesh interpolation. | Positive real. | 1e-6 |
| `blasius.delta` | Boundary layer thickness in the Blasius profile. | Positive real | - |
| `blasius.freestream_velocity` | Free-stream velocity in the Blasius profile. | Vector of 3 reals | - |
| `blasius.approximation` | Numerical approximation of the Blasius profile. | `linear`, `quadratic`, `cubic`, `quartic`, `sin` | - |
Expand Down Expand Up @@ -544,7 +578,10 @@ file documentation.
`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
`case.point_zones` object. See more about point zones @ref point-zones.md.

4. `field`, where the initial condition is retrieved from a field file. Works
in the same way as for the fluid. See the
[fluid section](@ref case-file_fluid-ic) for detailed explanations.

### Source terms

The configuration of source terms is the same as for the fluid. A demonstration
Expand Down
8 changes: 4 additions & 4 deletions src/.depends
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ io/map_file.o : io/map_file.f90 io/format/map.o comm/comm.o common/utils.o io/ge
io/re2_file.o : io/re2_file.f90 common/log.o adt/htable.o io/map_file.o io/format/map.o io/format/re2.o common/datadist.o comm/mpi_types.o comm/comm.o mesh/point.o mesh/mesh.o common/utils.o config/num_types.o io/generic_file.o
io/rea_file.o : io/rea_file.f90 common/log.o adt/htable.o common/datadist.o comm/comm.o io/map_file.o io/re2_file.o io/format/rea.o io/format/map.o mesh/point.o mesh/mesh.o common/utils.o config/num_types.o io/generic_file.o
io/fld_file.o : io/fld_file.f90 comm/mpi_types.o math/math.o common/datadist.o comm/comm.o common/utils.o mesh/mesh.o fluid/mean_sqr_flow.o fluid/mean_flow.o io/fld_file_data.o math/vector.o common/structs.o sem/space.o sem/dofmap.o field/field_list.o field/field.o io/generic_file.o config/num_types.o
io/fld_file_data.o : io/fld_file_data.f90 math/vector.o math/math.o config/num_types.o
io/fld_file_data.o : io/fld_file_data.f90 mesh/mesh.o common/utils.o common/global_interpolation.o sem/space.o sem/dofmap.o field/field.o math/vector.o math/math.o config/num_types.o
io/vtk_file.o : io/vtk_file.f90 comm/comm.o common/log.o mesh/tri_mesh.o mesh/tet_mesh.o field/mesh_field.o sem/dofmap.o field/field.o mesh/mesh.o common/utils.o io/generic_file.o config/num_types.o
io/stl_file.o : io/stl_file.f90 io/format/stl.o comm/comm.o common/utils.o comm/mpi_types.o mesh/point.o common/log.o mesh/tri_mesh.o io/generic_file.o config/num_types.o
io/nmsh_file.o : io/nmsh_file.f90 common/log.o comm/mpi_types.o common/datadist.o mesh/element.o io/format/nmsh.o adt/tuple.o mesh/point.o common/utils.o mesh/mesh.o config/num_types.o comm/comm.o io/generic_file.o
Expand All @@ -130,7 +130,7 @@ io/fluid_stats_output.o : io/fluid_stats_output.f90 math/matrix.o io/output.o de
io/mean_sqr_flow_output.o : io/mean_sqr_flow_output.f90 io/output.o config/num_types.o fluid/mean_sqr_flow.o
io/data_streamer.o : io/data_streamer.F90 config/neko_config.o comm/mpi_types.o comm/comm.o device/device.o common/utils.o sem/coef.o field/field.o config/num_types.o
common/sampler.o : common/sampler.f90 common/time_based_controller.o config/num_types.o common/profiler.o common/utils.o common/log.o comm/comm.o io/fld_file.o io/output.o
common/global_interpolation.o : common/global_interpolation.F90 comm/mpi_types.o math/math.o comm/comm.o sem/local_interpolation.o common/utils.o common/log.o mesh/mesh.o sem/dofmap.o sem/space.o config/num_types.o
common/global_interpolation.o : common/global_interpolation.F90 common/structs.o comm/mpi_types.o math/math.o comm/comm.o sem/local_interpolation.o common/utils.o common/log.o mesh/mesh.o sem/dofmap.o sem/space.o config/num_types.o
common/profiler.o : common/profiler.F90 common/runtime_statistics.o common/craypat.o device/hip/roctx.o device/cuda/nvtx.o device/device.o config/neko_config.o
common/craypat.o : common/craypat.F90
bc/bc.o : bc/bc.f90 common/utils.o adt/tuple.o adt/stack.o mesh/facet_zone.o mesh/mesh.o sem/space.o sem/coef.o sem/dofmap.o device/device.o config/num_types.o config/neko_config.o
Expand Down Expand Up @@ -208,7 +208,7 @@ fluid/mean_flow.o : fluid/mean_flow.f90 field/field.o field/mean_field.o
fluid/fluid_stats.o : fluid/fluid_stats.f90 common/utils.o config/neko_config.o device/device.o common/stats_quant.o field/field_list.o field/field.o sem/coef.o math/operators.o math/math.o config/num_types.o math/bcknd/device/device_math.o field/mean_field.o
fluid/mean_sqr_flow.o : fluid/mean_sqr_flow.f90 field/field.o field/mean_sqr_field.o
fluid/flow_profile.o : fluid/flow_profile.f90 config/num_types.o
fluid/flow_ic.o : fluid/flow_ic.f90 mesh/point_zone_registry.o mesh/point_zone.o common/json_utils.o common/user_intf.o math/bcknd/device/device_math.o math/math.o sem/coef.o common/utils.o field/field.o device/device.o fluid/flow_profile.o config/neko_config.o gs/gather_scatter.o config/num_types.o
fluid/flow_ic.o : fluid/flow_ic.f90 sem/space.o sem/interpolation.o common/global_interpolation.o io/file.o io/fld_file.o io/fld_file_data.o mesh/point_zone_registry.o mesh/point_zone.o common/json_utils.o common/user_intf.o math/bcknd/device/device_math.o math/math.o sem/coef.o common/utils.o field/field.o device/device.o fluid/flow_profile.o config/neko_config.o gs/gather_scatter.o common/log.o config/num_types.o
fluid/advection.o : fluid/advection.f90 time_schemes/time_scheme_controller.o field/field_series.o sem/coef.o field/field.o sem/space.o config/num_types.o
fluid/advection_fctry.o : fluid/advection_fctry.f90 fluid/bcknd/advection/adv_oifs.o fluid/bcknd/advection/adv_no_dealias.o fluid/bcknd/advection/adv_dealias.o common/json_utils.o fluid/advection.o
fluid/bcknd/advection/adv_dealias.o : fluid/bcknd/advection/adv_dealias.f90 device/device.o sem/interpolation.o math/operators.o config/neko_config.o math/bcknd/device/device_math.o sem/coef.o field/field.o sem/space.o math/math.o config/num_types.o fluid/advection.o
Expand Down Expand Up @@ -268,7 +268,7 @@ scalar/scalar_pnpn.o : scalar/scalar_pnpn.f90 field/scratch_registry.o common/ti
scalar/scalar_aux.o : scalar/scalar_aux.f90 krylov/krylov.o config/num_types.o common/log.o
scalar/scalar_residual.o : scalar/scalar_residual.f90 config/num_types.o mesh/mesh.o sem/space.o bc/facet_normal.o scalar/source_scalar.o sem/coef.o field/field.o math/ax.o gs/gather_scatter.o
scalar/scalar_residual_fctry.o : scalar/scalar_residual_fctry.f90 scalar/bcknd/sx/scalar_residual_sx.o scalar/bcknd/cpu/scalar_residual_cpu.o scalar/bcknd/device/scalar_residual_device.o config/neko_config.o scalar/scalar_residual.o
scalar/scalar_ic.o : scalar/scalar_ic.f90 mesh/point_zone_registry.o mesh/point_zone.o common/json_utils.o common/user_intf.o math/math.o sem/coef.o common/utils.o field/field.o device/device.o math/bcknd/device/device_math.o config/num_types.o config/neko_config.o gs/gather_scatter.o
scalar/scalar_ic.o : scalar/scalar_ic.f90 sem/space.o sem/interpolation.o common/global_interpolation.o io/file.o common/checkpoint.o io/fld_file.o io/fld_file_data.o common/log.o field/field_registry.o mesh/point_zone_registry.o mesh/point_zone.o common/json_utils.o common/user_intf.o math/math.o sem/coef.o common/utils.o field/field.o device/device.o math/bcknd/device/device_math.o config/num_types.o config/neko_config.o gs/gather_scatter.o
scalar/scalar_source_term.o : scalar/scalar_source_term.f90 common/user_intf.o sem/coef.o field/field_list.o field/field.o source_terms/source_term_handler.o source_terms/source_term.o scalar/scalar_user_source_term.o
scalar/scalar_user_source_term.o : scalar/scalar_user_source_term.f90 sem/dofmap.o math/math.o math/bcknd/device/device_math.o device/device.o sem/coef.o field/field_list.o source_terms/source_term.o common/utils.o config/num_types.o config/neko_config.o
scalar/bcknd/cpu/scalar_residual_cpu.o : scalar/bcknd/cpu/scalar_residual_cpu.f90 math/math.o config/num_types.o mesh/mesh.o sem/space.o sem/coef.o field/field.o math/ax.o scalar/scalar_residual.o
Expand Down
16 changes: 14 additions & 2 deletions src/case.f90
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ subroutine case_init_from_file(C, case_file)
end if

call MPI_Bcast(integer_val, 1, MPI_INTEGER, 0, NEKO_COMM, ierr)
if (pe_rank .ne. 0) allocate(character(len=integer_val)::json_buffer)
if (pe_rank .ne. 0) allocate(character(len = integer_val) :: json_buffer)
call MPI_Bcast(json_buffer, integer_val, MPI_CHARACTER, 0, NEKO_COMM, ierr)
call C%params%load_from_string(json_buffer)

Expand Down Expand Up @@ -137,7 +137,7 @@ subroutine case_init_common(C)
logical :: found, logical_val
integer :: integer_val
real(kind=rp) :: real_val
character(len=:), allocatable :: string_val
character(len = :), allocatable :: string_val
real(kind=rp) :: stats_start_time, stats_output_val
integer :: stats_sampling_interval
integer :: output_dir_len
Expand Down Expand Up @@ -270,6 +270,9 @@ subroutine case_init_common(C)
!
call json_get(C%params, 'case.fluid.initial_condition.type',&
string_val)

call neko_log%section("Fluid initial condition ")

if (trim(string_val) .ne. 'user') then
call set_flow_ic(C%fluid%u, C%fluid%v, C%fluid%w, C%fluid%p, &
C%fluid%c_Xh, C%fluid%gs_Xh, string_val, C%params)
Expand All @@ -278,15 +281,24 @@ subroutine case_init_common(C)
C%fluid%c_Xh, C%fluid%gs_Xh, C%usr%fluid_user_ic, C%params)
end if

call neko_log%end_section()

if (scalar) then

call json_get(C%params, 'case.scalar.initial_condition.type', string_val)

call neko_log%section("Scalar initial condition ")

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

call neko_log%end_section()

end if

! Add initial conditions to BDF scheme (if present)
Expand Down
Loading

0 comments on commit c31fc84

Please sign in to comment.