144 type(
case_t),
target,
intent(inout) :: this
146 logical :: scalar = .false.
147 type(
file_t) :: msh_file, bdry_file, part_file
149 logical :: found, logical_val, load_balance
150 logical :: write_at_start
151 integer :: integer_val, var_type
152 real(kind=
rp) :: real_val
153 real(kind=
dp) :: double_val
154 real(kind=
rp),
allocatable :: real_vals(:)
156 character(len=:),
allocatable :: string_val, name, file_format
157 character(len=NEKO_FNAME_LEN) :: lb_file, lb_name, lb_path, lb_ext
158 integer :: output_dir_len
159 integer :: precision, layout
160 type(json_file) :: scalar_params, numerics_params
161 type(json_file) :: json_subdict
162 integer :: n_scalars, i
163 logical :: tmp_feature
168 call this%user%init()
171 call this%user%startup(this%params)
174 if (this%params%valid_path(
'case.no_defaults'))
then
182 if (this%params%valid_path(
'case.constants'))
then
183 call this%params%info(
'case.constants', &
184 n_children = integer_val)
185 do i = 1, integer_val
187 'case.constants', i, json_subdict)
188 call json_get(json_subdict,
'name', string_val)
190 call json_subdict%info(
'value', found = found, var_type = var_type)
192 select case (var_type)
194 call json_get(json_subdict,
'value', integer_val)
198 call json_get(json_subdict,
'value', real_val)
202 call json_get(json_subdict,
'value', real_vals)
208 call neko_error(
'case_init_common: Unsupported constant ' // &
209 'type in case.constants for entry '//trim(string_val)//
'.')
222 if (trim(string_val) .eq.
'no mesh')
then
223 call neko_error(
'The mesh_file keyword could not be found in the .' // &
224 'case file. Often caused by incorrectly formatted json.')
228 inquire(
file = trim(string_val), exist = found)
230 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
232 if (.not. found)
then
233 call neko_error(
'The mesh file ' // trim(string_val) // &
237 if (.not. load_balance .or.
pe_size .eq. 1)
then
238 if (load_balance)
then
239 call neko_log%message(
'Load balancing requested but only one ' // &
240 'MPI rank found, ignoring.')
243 call msh_file%init(string_val)
244 call msh_file%read(this%msh)
246 else if (load_balance)
then
247 call neko_log%section(
'Load Balancing')
250 write(lb_file,
'(A,A,A,I0,A)') &
251 trim(lb_path), trim(lb_name),
"_lb_",
pe_size, trim(lb_ext)
254 inquire(
file = trim(lb_file), exist = found)
256 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
259 call neko_log%message(
'Reading balanced mesh')
260 call msh_file%init(lb_file)
261 call msh_file%read(this%msh)
263 call msh_file%init(string_val)
264 call msh_file%read(this%msh)
266 call neko_log%message(
'Performing load balancing with ParMETIS')
271 call msh_file%init(lb_file)
272 call msh_file%write(this%msh)
279 call this%user%mesh_setup(this%msh, this%time)
284 call json_get(this%params,
'case.time', json_subdict)
285 call this%time%init(json_subdict)
295 call json_get(this%params,
'case.fluid.scheme', string_val)
296 call fluid_scheme_base_factory(this%fluid, trim(string_val))
301 call this%chkp%init()
302 call this%chkp%add_time_state(this%time)
303 call this%fluid%init(this%msh, lx, this%params, this%user, this%chkp)
317 if (this%params%valid_path(
'case.scalar'))
then
321 else if (this%params%valid_path(
'case.scalars'))
then
322 call this%params%info(
'case.scalars', n_children = n_scalars)
323 if (n_scalars > 0)
then
329 allocate(this%scalars)
330 call json_get(this%params,
'case.numerics', numerics_params)
331 if (this%params%valid_path(
'case.scalar'))
then
333 call json_get(this%params,
'case.scalar', scalar_params)
334 call this%scalars%init(this%msh, this%fluid%c_Xh, this%fluid%gs_Xh, &
335 scalar_params, numerics_params, this%user, this%chkp, &
336 this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
337 this%fluid%ext_bdf, this%fluid%rho)
340 call json_get(this%params,
'case.scalars', json_subdict)
341 call this%scalars%init(n_scalars, this%msh, this%fluid%c_Xh, &
342 this%fluid%gs_Xh, json_subdict, numerics_params, this%user, &
343 this%chkp, this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
344 this%fluid%ext_bdf, this%fluid%rho)
351 call json_get(this%params,
'case.fluid.initial_condition.type', &
353 call json_get(this%params,
'case.fluid.initial_condition', &
356 call neko_log%section(
"Fluid initial condition ")
358 if (this%params%valid_path(
'case.restart_file'))
then
359 call neko_log%message(
"Restart file specified, " // &
360 "initial conditions ignored")
361 else if (trim(string_val) .ne.
'user')
then
362 call set_flow_ic(this%fluid%u, this%fluid%v, this%fluid%w, &
363 this%fluid%p, this%fluid%c_Xh, this%fluid%gs_Xh, string_val, &
366 call json_get(this%params,
'case.fluid.scheme', string_val)
367 if (trim(string_val) .eq.
'compressible')
then
369 this%fluid%u, this%fluid%v, this%fluid%w, this%fluid%p, &
370 this%fluid%c_Xh, this%fluid%gs_Xh, &
371 this%user%initial_conditions, this%fluid%name)
373 call set_flow_ic(this%fluid%u, this%fluid%v, this%fluid%w, &
374 this%fluid%p, this%fluid%c_Xh, this%fluid%gs_Xh, &
375 this%user%initial_conditions, this%fluid%name)
382 call this%scalars%set_initial_conditions(this%user, &
383 this%params%valid_path(
'case.restart_file'))
387 select type (f => this%fluid)
397 call this%fluid%validate
400 call this%scalars%validate()
407 this%output_directory,
'')
409 output_dir_len = len(trim(this%output_directory))
410 if (output_dir_len .gt. 0)
then
411 if (this%output_directory(output_dir_len:output_dir_len) .ne.
"/")
then
412 this%output_directory = trim(this%output_directory)//
"/"
415 call mkdir(trim(this%output_directory))
423 logical_val, .false.)
424 if (logical_val)
then
425 call msh_part%init(this%msh,
'MPI_Rank')
427 call part_file%init(trim(this%output_directory)//
'partitions.vtk')
428 call part_file%write(msh_part)
438 if (trim(string_val) .eq.
'double')
then
458 'case.fluid.output_mesh_in_all_files', &
459 logical_val, .false.)
463 tmp_feature, .false.)
464 if (tmp_feature) logical_val = .true.
468 write_at_start, .true.)
470 call this%output_controller%init(this%time%end_time, &
471 time_start = this%time%start_time, write_at_start = write_at_start)
473 call this%f_out%init(precision, this%fluid, this%scalars, name = name, &
474 path = trim(this%output_directory), &
475 fmt = trim(file_format), layout = layout, &
476 always_write_mesh = logical_val)
478 call this%f_out%init(precision, this%fluid, name = name, &
479 path = trim(this%output_directory), &
480 fmt = trim(file_format), layout = layout, &
481 always_write_mesh = logical_val)
485 logical_val, .false.)
486 call this%f_out%file_%set_subdivide(logical_val)
488 call json_get(this%params,
'case.fluid.output_control', string_val)
490 if (trim(string_val) .eq.
'org')
then
493 double_val =
real(integer_val, kind=
dp)
494 call this%output_controller%add(this%f_out, double_val,
'nsamples')
495 else if (trim(string_val) .eq.
'never')
then
496 call this%output_controller%add(this%f_out, 0.0_dp,
'never')
497 else if (trim(string_val) .eq.
'tsteps' .or. &
498 trim(string_val) .eq.
'nsamples')
then
501 double_val =
real(integer_val, kind=
dp)
502 call this%output_controller%add(this%f_out, double_val, string_val)
503 else if (trim(string_val) .eq.
'simulationtime')
then
506 call this%output_controller%add(this%f_out, double_val, string_val)
508 call neko_log%error(
'Unknown output control type for the fluid: ' // &
515 call json_get(this%params,
'case.output_checkpoints', logical_val)
516 if (logical_val)
then
521 call this%chkp_out%init(this%chkp, name = name,&
522 path = this%output_directory, fmt = trim(string_val))
523 call json_get(this%params,
'case.checkpoint_control', &
525 if (trim(string_val) .eq.
'tsteps' .or. &
526 trim(string_val) .eq.
'nsamples')
then
529 double_val =
real(integer_val, kind=
dp)
530 else if (trim(string_val) .eq.
'simulationtime')
then
533 else if (trim(string_val) .eq.
'never')
then
539 call this%output_controller%add(this%chkp_out, double_val, string_val, &
540 write_at_start = .false.)
546 if (this%params%valid_path(
'case.job_timelimit'))
then
547 call json_get(this%params,
'case.job_timelimit', string_val)
553 call scalar_params%destroy()
554 call numerics_params%destroy()
555 call json_subdict%destroy()