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
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) :: 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))
298 call this%chkp%init()
299 call this%chkp%add_time_state(this%time)
300 call this%fluid%init(this%msh, lx, this%params, this%user, this%chkp)
314 if (this%params%valid_path(
'case.scalar'))
then
318 else if (this%params%valid_path(
'case.scalars'))
then
319 call this%params%info(
'case.scalars', n_children = n_scalars)
320 if (n_scalars > 0)
then
326 allocate(this%scalars)
327 call json_get(this%params,
'case.numerics', numerics_params)
328 if (this%params%valid_path(
'case.scalar'))
then
330 call json_get(this%params,
'case.scalar', scalar_params)
331 call this%scalars%init(this%msh, this%fluid%c_Xh, this%fluid%gs_Xh, &
332 scalar_params, numerics_params, this%user, this%chkp, &
333 this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
334 this%fluid%ext_bdf, this%fluid%rho)
337 call json_get(this%params,
'case.scalars', json_subdict)
338 call this%scalars%init(n_scalars, this%msh, this%fluid%c_Xh, &
339 this%fluid%gs_Xh, json_subdict, numerics_params, this%user, &
340 this%chkp, this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
341 this%fluid%ext_bdf, this%fluid%rho)
348 call this%fluid%set_initial_condition(this%user, &
349 this%params%valid_path(
'case.restart_file'))
352 call this%scalars%set_initial_conditions(this%user, &
353 this%params%valid_path(
'case.restart_file'))
359 call this%fluid%validate
362 call this%scalars%validate()
369 this%output_directory,
'')
371 output_dir_len = len(trim(this%output_directory))
372 if (output_dir_len .gt. 0)
then
373 if (this%output_directory(output_dir_len:output_dir_len) .ne.
"/")
then
374 this%output_directory = trim(this%output_directory)//
"/"
377 call mkdir(trim(this%output_directory))
385 logical_val, .false.)
386 if (logical_val)
then
387 call msh_part%init(this%msh,
'MPI_Rank')
389 call part_file%init(trim(this%output_directory)//
'partitions.vtk')
390 call part_file%write(msh_part)
400 if (trim(string_val) .eq.
'double')
then
420 'case.fluid.output_mesh_in_all_files', &
421 logical_val, .false.)
425 tmp_feature, .false.)
426 if (tmp_feature) logical_val = .true.
430 write_at_start, .true.)
432 call this%output_controller%init(this%time%end_time, &
433 time_start = this%time%start_time, write_at_start = write_at_start)
435 call this%f_out%init(precision, this%fluid, this%scalars, name = name, &
436 path = trim(this%output_directory), &
437 fmt = trim(file_format), layout = layout, &
438 always_write_mesh = logical_val)
440 call this%f_out%init(precision, this%fluid, name = name, &
441 path = trim(this%output_directory), &
442 fmt = trim(file_format), layout = layout, &
443 always_write_mesh = logical_val)
447 logical_val, .false.)
448 call this%f_out%file_%set_subdivide(logical_val)
450 call json_get(this%params,
'case.fluid.output_control', string_val)
452 if (trim(string_val) .eq.
'org')
then
455 double_val =
real(integer_val, kind=
dp)
456 call this%output_controller%add(this%f_out, double_val,
'nsamples')
457 else if (trim(string_val) .eq.
'never')
then
458 call this%output_controller%add(this%f_out, 0.0_dp,
'never')
459 else if (trim(string_val) .eq.
'tsteps' .or. &
460 trim(string_val) .eq.
'nsamples')
then
463 double_val =
real(integer_val, kind=
dp)
464 call this%output_controller%add(this%f_out, double_val, string_val)
465 else if (trim(string_val) .eq.
'simulationtime')
then
468 call this%output_controller%add(this%f_out, double_val, string_val)
470 call neko_log%error(
'Unknown output control type for the fluid: ' // &
477 call json_get(this%params,
'case.output_checkpoints', logical_val)
478 if (logical_val)
then
483 call this%chkp_out%init(this%chkp, name = name,&
484 path = this%output_directory, fmt = trim(string_val))
485 call json_get(this%params,
'case.checkpoint_control', &
487 if (trim(string_val) .eq.
'tsteps' .or. &
488 trim(string_val) .eq.
'nsamples')
then
491 double_val =
real(integer_val, kind=
dp)
492 else if (trim(string_val) .eq.
'simulationtime')
then
495 else if (trim(string_val) .eq.
'never')
then
501 call this%output_controller%add(this%chkp_out, double_val, string_val, &
502 write_at_start = .false.)
508 if (this%params%valid_path(
'case.job_timelimit'))
then
509 call json_get(this%params,
'case.job_timelimit', string_val)
515 call scalar_params%destroy()
516 call numerics_params%destroy()
517 call json_subdict%destroy()