141 type(
case_t),
target,
intent(inout) :: this
143 logical :: scalar = .false.
144 type(
file_t) :: msh_file, bdry_file, part_file
146 logical :: found, logical_val, load_balance
147 logical :: write_at_start, output_boundary
148 integer :: integer_val, var_type
149 real(kind=
rp) :: real_val
150 real(kind=
dp) :: double_val
151 real(kind=
rp),
allocatable :: real_vals(:)
153 character(len=:),
allocatable :: string_val, name, file_format
154 character(len=NEKO_FNAME_LEN) :: lb_file, lb_name, lb_path, lb_ext
155 integer :: output_dir_len
156 integer :: precision, layout
157 type(json_file) :: fluid_params, scalar_params, numerics_params
158 type(json_file) :: json_subdict
159 integer :: n_scalars, i
160 logical :: tmp_feature
165 call this%user%init()
168 call this%user%startup(this%params)
171 if (this%params%valid_path(
'case.no_defaults'))
then
179 if (this%params%valid_path(
'case.constants'))
then
180 call this%params%info(
'case.constants', &
181 n_children = integer_val)
182 do i = 1, integer_val
184 'case.constants', i, json_subdict)
185 call json_get(json_subdict,
'name', string_val)
187 call json_subdict%info(
'value', found = found, var_type = var_type)
189 select case (var_type)
191 call json_get(json_subdict,
'value', integer_val)
195 call json_get(json_subdict,
'value', real_val)
199 call json_get(json_subdict,
'value', real_vals)
205 call neko_error(
'case_init_common: Unsupported constant ' // &
206 'type in case.constants for entry '//trim(string_val)//
'.')
219 if (trim(string_val) .eq.
'no mesh')
then
220 call neko_error(
'The mesh_file keyword could not be found in the .' // &
221 'case file. Often caused by incorrectly formatted json.')
225 inquire(
file = trim(string_val), exist = found)
227 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
229 if (.not. found)
then
230 call neko_error(
'The mesh file ' // trim(string_val) // &
234 if (.not. load_balance .or.
pe_size .eq. 1)
then
235 if (load_balance)
then
236 call neko_log%message(
'Load balancing requested but only one ' // &
237 'MPI rank found, ignoring.')
240 call msh_file%init(string_val)
241 call msh_file%read(this%msh)
243 else if (load_balance)
then
244 call neko_log%section(
'Load Balancing')
247 write(lb_file,
'(A,A,A,I0,A)') &
248 trim(lb_path), trim(lb_name),
"_lb_",
pe_size, trim(lb_ext)
251 inquire(
file = trim(lb_file), exist = found)
253 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
256 call neko_log%message(
'Reading balanced mesh')
257 call msh_file%init(lb_file)
258 call msh_file%read(this%msh)
260 call msh_file%init(string_val)
261 call msh_file%read(this%msh)
263 call neko_log%message(
'Performing load balancing with ParMETIS')
268 call msh_file%init(lb_file)
269 call msh_file%write(this%msh)
276 call this%user%mesh_setup(this%msh, this%time)
281 call json_get(this%params,
'case.time', json_subdict)
282 call this%time%init(json_subdict)
292 call json_get(this%params,
'case.fluid.scheme', string_val)
293 call fluid_scheme_base_factory(this%fluid, trim(string_val))
297 call json_get(this%params,
'case.fluid', fluid_params)
298 call json_get(this%params,
'case.numerics', numerics_params)
300 output_boundary, .false.)
302 call this%chkp%init()
303 call this%chkp%add_time_state(this%time)
304 call this%fluid%init(this%msh, lx, fluid_params, numerics_params, &
305 this%user, this%chkp, output_boundary)
319 if (this%params%valid_path(
'case.scalar'))
then
323 else if (this%params%valid_path(
'case.scalars'))
then
324 call this%params%info(
'case.scalars', n_children = n_scalars)
325 if (n_scalars > 0)
then
331 allocate(this%scalars)
332 if (this%params%valid_path(
'case.scalar'))
then
334 call json_get(this%params,
'case.scalar', scalar_params)
335 call this%scalars%init(this%msh, this%fluid%c_Xh, this%fluid%gs_Xh, &
336 scalar_params, numerics_params, this%user, this%chkp, &
337 this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
338 this%fluid%ext_bdf, this%fluid%rho)
341 call json_get(this%params,
'case.scalars', json_subdict)
342 call this%scalars%init(n_scalars, this%msh, this%fluid%c_Xh, &
343 this%fluid%gs_Xh, json_subdict, numerics_params, this%user, &
344 this%chkp, this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
345 this%fluid%ext_bdf, this%fluid%rho)
352 call this%fluid%set_initial_condition(fluid_params, this%user, &
353 this%params%valid_path(
'case.restart_file'))
356 if (this%params%valid_path(
'case.scalar'))
then
357 call this%scalars%set_initial_conditions(scalar_params, this%user, &
358 this%params%valid_path(
'case.restart_file'))
360 call this%scalars%set_initial_conditions(json_subdict, this%user, &
361 this%params%valid_path(
'case.restart_file'))
368 call this%fluid%validate
371 call this%scalars%validate()
378 this%output_directory,
'')
380 output_dir_len = len(trim(this%output_directory))
381 if (output_dir_len .gt. 0)
then
382 if (this%output_directory(output_dir_len:output_dir_len) .ne.
"/")
then
383 this%output_directory = trim(this%output_directory)//
"/"
386 call mkdir(trim(this%output_directory))
394 logical_val, .false.)
395 if (logical_val)
then
396 call msh_part%init(this%msh,
'MPI_Rank')
398 call part_file%init(trim(this%output_directory)//
'partitions.vtk')
399 call part_file%write(msh_part)
409 if (trim(string_val) .eq.
'double')
then
429 'case.fluid.output_mesh_in_all_files', &
430 logical_val, .false.)
434 tmp_feature, .false.)
435 if (tmp_feature) logical_val = .true.
439 write_at_start, .true.)
441 call this%output_controller%init(this%time%end_time, &
442 time_start = this%time%start_time, write_at_start = write_at_start)
444 call this%f_out%init(precision, this%fluid, this%scalars, name = name, &
445 path = trim(this%output_directory), &
446 fmt = trim(file_format), layout = layout, &
447 always_write_mesh = logical_val)
449 call this%f_out%init(precision, this%fluid, name = name, &
450 path = trim(this%output_directory), &
451 fmt = trim(file_format), layout = layout, &
452 always_write_mesh = logical_val)
456 logical_val, .false.)
457 call this%f_out%file_%set_subdivide(logical_val)
459 call json_get(this%params,
'case.fluid.output_control', string_val)
461 if (trim(string_val) .eq.
'org')
then
464 double_val =
real(integer_val, kind=
dp)
465 call this%output_controller%add(this%f_out, double_val,
'nsamples')
466 else if (trim(string_val) .eq.
'never')
then
467 call this%output_controller%add(this%f_out, 0.0_dp,
'never')
468 else if (trim(string_val) .eq.
'tsteps' .or. &
469 trim(string_val) .eq.
'nsamples')
then
472 double_val =
real(integer_val, kind=
dp)
473 call this%output_controller%add(this%f_out, double_val, string_val)
474 else if (trim(string_val) .eq.
'simulationtime')
then
477 call this%output_controller%add(this%f_out, double_val, string_val)
479 call neko_log%error(
'Unknown output control type for the fluid: ' // &
486 call json_get(this%params,
'case.output_checkpoints', logical_val)
487 if (logical_val)
then
492 call this%chkp_out%init(this%chkp, name = name,&
493 path = this%output_directory, fmt = trim(string_val))
494 call json_get(this%params,
'case.checkpoint_control', &
496 if (trim(string_val) .eq.
'tsteps' .or. &
497 trim(string_val) .eq.
'nsamples')
then
500 double_val =
real(integer_val, kind=
dp)
501 else if (trim(string_val) .eq.
'simulationtime')
then
504 else if (trim(string_val) .eq.
'never')
then
510 call this%output_controller%add(this%chkp_out, double_val, string_val, &
511 write_at_start = .false.)
517 if (this%params%valid_path(
'case.job_timelimit'))
then
518 call json_get(this%params,
'case.job_timelimit', string_val)
524 call scalar_params%destroy()
525 call numerics_params%destroy()
526 call json_subdict%destroy()