146 type(
case_t),
target,
intent(inout) :: this
148 logical :: scalar = .false.
149 type(
file_t) :: msh_file, bdry_file, part_file
151 logical :: found, logical_val, load_balance
152 logical :: temperature_found = .false.
153 integer :: integer_val, var_type
154 real(kind=
rp) :: real_val
155 real(kind=
dp) :: double_val
156 real(kind=
rp),
allocatable :: real_vals(:)
158 character(len=:),
allocatable :: string_val, name, file_format
159 character(len=NEKO_FNAME_LEN) :: lb_file, lb_name, lb_path, lb_ext
160 integer :: output_dir_len
161 integer :: precision, layout
162 type(json_file) :: scalar_params, numerics_params
163 type(json_file) :: json_subdict
164 integer :: n_scalars, i
165 logical :: tmp_feature
170 call this%user%init()
173 call this%user%startup(this%params)
176 if (this%params%valid_path(
'case.no_defaults'))
then
184 if (this%params%valid_path(
'case.constants'))
then
185 call this%params%info(
'case.constants', &
186 n_children = integer_val)
187 do i = 1, integer_val
189 'case.constants', i, json_subdict)
190 call json_get(json_subdict,
'name', string_val)
192 call json_subdict%info(
'value', found = found, var_type = var_type)
194 select case (var_type)
196 call json_get(json_subdict,
'value', integer_val)
200 call json_get(json_subdict,
'value', real_val)
204 call json_get(json_subdict,
'value', real_vals)
210 call neko_error(
'case_init_common: Unsupported constant ' // &
211 'type in case.constants for entry '//trim(string_val)//
'.')
224 if (trim(string_val) .eq.
'no mesh')
then
225 call neko_error(
'The mesh_file keyword could not be found in the .' // &
226 'case file. Often caused by incorrectly formatted json.')
230 inquire(
file = trim(string_val), exist = found)
232 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
234 if (.not. found)
then
235 call neko_error(
'The mesh file ' // trim(string_val) // &
239 if (.not. load_balance .or.
pe_size .eq. 1)
then
240 if (load_balance)
then
241 call neko_log%message(
'Load balancing requested but only one ' // &
242 'MPI rank found, ignoring.')
245 call msh_file%init(string_val)
246 call msh_file%read(this%msh)
248 else if (load_balance)
then
249 call neko_log%section(
'Load Balancing')
252 write(lb_file,
'(A,A,A,I0,A)') &
253 trim(lb_path), trim(lb_name),
"_lb_",
pe_size, trim(lb_ext)
256 inquire(
file = trim(lb_file), exist = found)
258 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
261 call neko_log%message(
'Reading balanced mesh')
262 call msh_file%init(lb_file)
263 call msh_file%read(this%msh)
265 call msh_file%init(string_val)
266 call msh_file%read(this%msh)
268 call neko_log%message(
'Performing load balancing with ParMETIS')
273 call msh_file%init(lb_file)
274 call msh_file%write(this%msh)
281 call this%user%mesh_setup(this%msh, this%time)
286 call json_get(this%params,
'case.time', json_subdict)
287 call this%time%init(json_subdict)
297 call json_get(this%params,
'case.fluid.scheme', string_val)
298 call fluid_scheme_base_factory(this%fluid, trim(string_val))
303 call this%chkp%init()
304 this%chkp%tlag => this%time%tlag
305 this%chkp%dtlag => this%time%dtlag
306 call this%fluid%init(this%msh, lx, this%params, this%user, this%chkp)
320 if (this%params%valid_path(
'case.scalar'))
then
324 else if (this%params%valid_path(
'case.scalars'))
then
325 call this%params%info(
'case.scalars', n_children = n_scalars)
326 if (n_scalars > 0)
then
332 allocate(this%scalars)
333 call json_get(this%params,
'case.numerics', numerics_params)
334 if (this%params%valid_path(
'case.scalar'))
then
336 call json_get(this%params,
'case.scalar', scalar_params)
337 call this%scalars%init(this%msh, this%fluid%c_Xh, this%fluid%gs_Xh, &
338 scalar_params, numerics_params, this%user, this%chkp, &
339 this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
340 this%fluid%ext_bdf, this%fluid%rho)
343 call json_get(this%params,
'case.scalars', json_subdict)
344 call this%scalars%init(n_scalars, this%msh, this%fluid%c_Xh, &
345 this%fluid%gs_Xh, json_subdict, numerics_params, this%user, &
346 this%chkp, this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
347 this%fluid%ext_bdf, this%fluid%rho)
354 call json_get(this%params,
'case.fluid.initial_condition.type', &
356 call json_get(this%params,
'case.fluid.initial_condition', &
359 call neko_log%section(
"Fluid initial condition ")
361 if (this%params%valid_path(
'case.restart_file'))
then
362 call neko_log%message(
"Restart file specified, " // &
363 "initial conditions ignored")
364 else if (trim(string_val) .ne.
'user')
then
365 call set_flow_ic(this%fluid%u, this%fluid%v, this%fluid%w, &
366 this%fluid%p, this%fluid%c_Xh, this%fluid%gs_Xh, string_val, &
369 call json_get(this%params,
'case.fluid.scheme', string_val)
370 if (trim(string_val) .eq.
'compressible')
then
372 this%fluid%u, this%fluid%v, this%fluid%w, this%fluid%p, &
373 this%fluid%c_Xh, this%fluid%gs_Xh, &
374 this%user%initial_conditions, this%fluid%name)
376 call set_flow_ic(this%fluid%u, this%fluid%v, this%fluid%w, &
377 this%fluid%p, this%fluid%c_Xh, this%fluid%gs_Xh, &
378 this%user%initial_conditions, this%fluid%name)
385 call neko_log%section(
"Scalar initial condition ")
387 if (this%params%valid_path(
'case.restart_file'))
then
388 call neko_log%message(
"Restart file specified, " // &
389 "initial conditions ignored")
390 else if (this%params%valid_path(
'case.scalar'))
then
392 call json_get(this%params,
'case.scalar.initial_condition.type', &
395 'case.scalar.initial_condition', json_subdict)
397 if (trim(string_val) .ne.
'user')
then
398 if (trim(this%scalars%scalar_fields(1)%scalar%name) .eq. &
401 this%scalars%scalar_fields(1)%scalar%c_Xh, &
402 this%scalars%scalar_fields(1)%scalar%gs_Xh, &
403 string_val, json_subdict, 0)
406 this%scalars%scalar_fields(1)%scalar%c_Xh, &
407 this%scalars%scalar_fields(1)%scalar%gs_Xh, &
408 string_val, json_subdict, 1)
411 call set_scalar_ic(this%scalars%scalar_fields(1)%scalar%name, &
412 this%scalars%scalar_fields(1)%scalar%s, &
413 this%scalars%scalar_fields(1)%scalar%c_Xh, &
414 this%scalars%scalar_fields(1)%scalar%gs_Xh, &
415 this%user%initial_conditions)
423 call json_get(scalar_params,
'initial_condition.type', string_val)
424 call json_get(scalar_params,
'initial_condition', &
427 if (trim(string_val) .ne.
'user')
then
428 if (trim(this%scalars%scalar_fields(i)%scalar%name) .eq. &
431 this%scalars%scalar_fields(i)%scalar%s, &
432 this%scalars%scalar_fields(i)%scalar%c_Xh, &
433 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
434 string_val, json_subdict, 0)
435 temperature_found = .true.
437 if (temperature_found)
then
441 this%scalars%scalar_fields(i)%scalar%s, &
442 this%scalars%scalar_fields(i)%scalar%c_Xh, &
443 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
444 string_val, json_subdict, i - 1)
449 this%scalars%scalar_fields(i)%scalar%s, &
450 this%scalars%scalar_fields(i)%scalar%c_Xh, &
451 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
452 string_val, json_subdict, i)
456 call set_scalar_ic(this%scalars%scalar_fields(i)%scalar%name,&
457 this%scalars%scalar_fields(i)%scalar%s, &
458 this%scalars%scalar_fields(i)%scalar%c_Xh, &
459 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
460 this%user%initial_conditions)
469 select type (f => this%fluid)
479 call this%fluid%validate
482 call this%scalars%validate()
489 this%output_directory,
'')
491 output_dir_len = len(trim(this%output_directory))
492 if (output_dir_len .gt. 0)
then
493 if (this%output_directory(output_dir_len:output_dir_len) .ne.
"/")
then
494 this%output_directory = trim(this%output_directory)//
"/"
497 call mkdir(trim(this%output_directory))
505 logical_val, .false.)
506 if (logical_val)
then
507 call msh_part%init(this%msh,
'MPI_Rank')
509 call part_file%init(trim(this%output_directory)//
'partitions.vtk')
510 call part_file%write(msh_part)
520 if (trim(string_val) .eq.
'double')
then
540 'case.fluid.output_mesh_in_all_files', &
541 logical_val, .false.)
545 tmp_feature, .false.)
546 if (tmp_feature) logical_val = .true.
548 call this%output_controller%init(this%time%end_time)
550 call this%f_out%init(precision, this%fluid, this%scalars, name = name, &
551 path = trim(this%output_directory), &
552 fmt = trim(file_format), layout = layout, &
553 always_write_mesh = logical_val)
555 call this%f_out%init(precision, this%fluid, name = name, &
556 path = trim(this%output_directory), &
557 fmt = trim(file_format), layout = layout, &
558 always_write_mesh = logical_val)
562 logical_val, .false.)
563 call this%f_out%file_%set_subdivide(logical_val)
565 call json_get(this%params,
'case.fluid.output_control', string_val)
567 if (trim(string_val) .eq.
'org')
then
570 double_val =
real(integer_val, kind=
dp)
571 call this%output_controller%add(this%f_out, double_val,
'nsamples')
572 else if (trim(string_val) .eq.
'never')
then
573 call this%output_controller%add(this%f_out, 0.0_dp,
'never')
574 else if (trim(string_val) .eq.
'tsteps' .or. &
575 trim(string_val) .eq.
'nsamples')
then
578 double_val =
real(integer_val, kind=
dp)
579 call this%output_controller%add(this%f_out, double_val, string_val)
580 else if (trim(string_val) .eq.
'simulationtime')
then
583 call this%output_controller%add(this%f_out, double_val, string_val)
585 call neko_log%error(
'Unknown output control type for the fluid: ' // &
592 call json_get(this%params,
'case.output_checkpoints', logical_val)
593 if (logical_val)
then
598 call this%chkp_out%init(this%chkp, name = name,&
599 path = this%output_directory, fmt = trim(string_val))
600 call json_get(this%params,
'case.checkpoint_control', &
602 if (trim(string_val) .eq.
'tsteps' .or. &
603 trim(string_val) .eq.
'nsamples')
then
606 double_val =
real(integer_val, kind=
dp)
607 else if (trim(string_val) .eq.
'simulationtime')
then
610 else if (trim(string_val) .eq.
'never')
then
614 call this%output_controller%add(this%chkp_out, double_val, string_val, &
621 if (this%params%valid_path(
'case.job_timelimit'))
then
622 call json_get(this%params,
'case.job_timelimit', string_val)
628 call scalar_params%destroy()
629 call numerics_params%destroy()
630 call json_subdict%destroy()