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=
rp),
allocatable :: real_vals(:)
157 character(len=:),
allocatable :: string_val, name, file_format
158 character(len=NEKO_FNAME_LEN) :: lb_file, lb_name, lb_path, lb_ext
159 integer :: output_dir_len
160 integer :: precision, layout
161 type(json_file) :: scalar_params, numerics_params
162 type(json_file) :: json_subdict
163 integer :: n_scalars, i
164 logical :: tmp_feature
169 call this%user%init()
172 call this%user%startup(this%params)
175 if (this%params%valid_path(
'case.no_defaults'))
then
183 if (this%params%valid_path(
'case.constants'))
then
184 call this%params%info(
'case.constants', &
185 n_children = integer_val)
186 do i = 1, integer_val
188 'case.constants', i, json_subdict)
189 call json_get(json_subdict,
'name', string_val)
191 call json_subdict%info(
'value', found = found, var_type = var_type)
193 select case (var_type)
195 call json_get(json_subdict,
'value', integer_val)
199 call json_get(json_subdict,
'value', real_val)
203 call json_get(json_subdict,
'value', real_vals)
209 call neko_error(
'case_init_common: Unsupported constant ' // &
210 'type in case.constants for entry '//trim(string_val)//
'.')
223 if (trim(string_val) .eq.
'no mesh')
then
224 call neko_error(
'The mesh_file keyword could not be found in the .' // &
225 'case file. Often caused by incorrectly formatted json.')
229 inquire(
file = trim(string_val), exist = found)
231 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
233 if (.not. found)
then
234 call neko_error(
'The mesh file ' // trim(string_val) // &
238 if (.not. load_balance .or.
pe_size .eq. 1)
then
239 if (load_balance)
then
240 call neko_log%message(
'Load balancing requested but only one ' // &
241 'MPI rank found, ignoring.')
244 call msh_file%init(string_val)
245 call msh_file%read(this%msh)
247 else if (load_balance)
then
248 call neko_log%section(
'Load Balancing')
251 write(lb_file,
'(A,A,A,I0,A)') &
252 trim(lb_path), trim(lb_name),
"_lb_",
pe_size, trim(lb_ext)
255 inquire(
file = trim(lb_file), exist = found)
257 call mpi_bcast(found, 1, mpi_logical, 0,
neko_comm)
260 call neko_log%message(
'Reading balanced mesh')
261 call msh_file%init(lb_file)
262 call msh_file%read(this%msh)
264 call msh_file%init(string_val)
265 call msh_file%read(this%msh)
267 call neko_log%message(
'Performing load balancing with ParMETIS')
272 call msh_file%init(lb_file)
273 call msh_file%write(this%msh)
280 call this%user%mesh_setup(this%msh, this%time)
285 call json_get(this%params,
'case.time', json_subdict)
286 call this%time%init(json_subdict)
296 call json_get(this%params,
'case.fluid.scheme', string_val)
297 call fluid_scheme_base_factory(this%fluid, trim(string_val))
302 call this%chkp%init()
303 this%chkp%tlag => this%time%tlag
304 this%chkp%dtlag => this%time%dtlag
305 call this%fluid%init(this%msh, lx, this%params, this%user, this%chkp)
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 call json_get(this%params,
'case.numerics', numerics_params)
333 if (this%params%valid_path(
'case.scalar'))
then
335 call json_get(this%params,
'case.scalar', scalar_params)
336 call this%scalars%init(this%msh, this%fluid%c_Xh, this%fluid%gs_Xh, &
337 scalar_params, numerics_params, this%user, this%chkp, &
338 this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
339 this%fluid%ext_bdf, this%fluid%rho)
342 call json_get(this%params,
'case.scalars', json_subdict)
343 call this%scalars%init(n_scalars, this%msh, this%fluid%c_Xh, &
344 this%fluid%gs_Xh, json_subdict, numerics_params, this%user, &
345 this%chkp, this%fluid%ulag, this%fluid%vlag, this%fluid%wlag, &
346 this%fluid%ext_bdf, this%fluid%rho)
353 call json_get(this%params,
'case.fluid.initial_condition.type', &
355 call json_get(this%params,
'case.fluid.initial_condition', &
358 call neko_log%section(
"Fluid initial condition ")
360 if (this%params%valid_path(
'case.restart_file'))
then
361 call neko_log%message(
"Restart file specified, " // &
362 "initial conditions ignored")
363 else if (trim(string_val) .ne.
'user')
then
364 call set_flow_ic(this%fluid%u, this%fluid%v, this%fluid%w, &
365 this%fluid%p, this%fluid%c_Xh, this%fluid%gs_Xh, string_val, &
368 call json_get(this%params,
'case.fluid.scheme', string_val)
369 if (trim(string_val) .eq.
'compressible')
then
371 this%fluid%u, this%fluid%v, this%fluid%w, this%fluid%p, &
372 this%fluid%c_Xh, this%fluid%gs_Xh, &
373 this%user%initial_conditions, this%fluid%name)
375 call set_flow_ic(this%fluid%u, this%fluid%v, this%fluid%w, &
376 this%fluid%p, this%fluid%c_Xh, this%fluid%gs_Xh, &
377 this%user%initial_conditions, this%fluid%name)
384 call neko_log%section(
"Scalar initial condition ")
386 if (this%params%valid_path(
'case.restart_file'))
then
387 call neko_log%message(
"Restart file specified, " // &
388 "initial conditions ignored")
389 else if (this%params%valid_path(
'case.scalar'))
then
391 call json_get(this%params,
'case.scalar.initial_condition.type', &
394 'case.scalar.initial_condition', json_subdict)
396 if (trim(string_val) .ne.
'user')
then
397 if (trim(this%scalars%scalar_fields(1)%scalar%name) .eq. &
400 this%scalars%scalar_fields(1)%scalar%c_Xh, &
401 this%scalars%scalar_fields(1)%scalar%gs_Xh, &
402 string_val, json_subdict, 0)
405 this%scalars%scalar_fields(1)%scalar%c_Xh, &
406 this%scalars%scalar_fields(1)%scalar%gs_Xh, &
407 string_val, json_subdict, 1)
410 call set_scalar_ic(this%scalars%scalar_fields(1)%scalar%name, &
411 this%scalars%scalar_fields(1)%scalar%s, &
412 this%scalars%scalar_fields(1)%scalar%c_Xh, &
413 this%scalars%scalar_fields(1)%scalar%gs_Xh, &
414 this%user%initial_conditions)
422 call json_get(scalar_params,
'initial_condition.type', string_val)
423 call json_get(scalar_params,
'initial_condition', &
426 if (trim(string_val) .ne.
'user')
then
427 if (trim(this%scalars%scalar_fields(i)%scalar%name) .eq. &
430 this%scalars%scalar_fields(i)%scalar%c_Xh, &
431 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
432 string_val, json_subdict, 0)
433 temperature_found = .true.
435 if (temperature_found)
then
438 this%scalars%scalar_fields(i)%scalar%c_Xh, &
439 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
440 string_val, json_subdict, i - 1)
444 this%scalars%scalar_fields(i)%scalar%c_Xh, &
445 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
446 string_val, json_subdict, i)
450 call set_scalar_ic(this%scalars%scalar_fields(i)%scalar%name,&
451 this%scalars%scalar_fields(i)%scalar%s, &
452 this%scalars%scalar_fields(i)%scalar%c_Xh, &
453 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
454 this%user%initial_conditions)
463 select type (f => this%fluid)
473 call this%fluid%validate
476 call this%scalars%validate()
483 this%output_directory,
'')
485 output_dir_len = len(trim(this%output_directory))
486 if (output_dir_len .gt. 0)
then
487 if (this%output_directory(output_dir_len:output_dir_len) .ne.
"/")
then
488 this%output_directory = trim(this%output_directory)//
"/"
491 call mkdir(trim(this%output_directory))
499 logical_val, .false.)
500 if (logical_val)
then
501 call msh_part%init(this%msh,
'MPI_Rank')
503 call part_file%init(trim(this%output_directory)//
'partitions.vtk')
504 call part_file%write(msh_part)
514 if (trim(string_val) .eq.
'double')
then
534 'case.fluid.output_mesh_in_all_files', &
535 logical_val, .false.)
540 tmp_feature, .false.)
541 if (tmp_feature) logical_val = .true.
543 call this%output_controller%init(this%time%end_time)
545 call this%f_out%init(precision, this%fluid, this%scalars, name = name, &
546 path = trim(this%output_directory), &
547 fmt = trim(file_format), layout = layout, &
548 always_write_mesh = logical_val)
550 call this%f_out%init(precision, this%fluid, name = name, &
551 path = trim(this%output_directory), &
552 fmt = trim(file_format), layout = layout, &
553 always_write_mesh = logical_val)
557 logical_val, .false.)
558 call this%f_out%file_%set_subdivide(logical_val)
560 call json_get(this%params,
'case.fluid.output_control', string_val)
562 if (trim(string_val) .eq.
'org')
then
565 real_val =
real(integer_val, kind=
rp)
566 call this%output_controller%add(this%f_out, real_val,
'nsamples')
567 else if (trim(string_val) .eq.
'never')
then
568 call this%output_controller%add(this%f_out, 0.0_rp,
'never')
569 else if (trim(string_val) .eq.
'tsteps' .or. &
570 trim(string_val) .eq.
'nsamples')
then
573 real_val =
real(integer_val, kind=
rp)
574 call this%output_controller%add(this%f_out, real_val, string_val)
575 else if (trim(string_val) .eq.
'simulationtime')
then
577 call this%output_controller%add(this%f_out, real_val, string_val)
579 call neko_log%error(
'Unknown output control type for the fluid: ' // &
586 call json_get(this%params,
'case.output_checkpoints', logical_val)
587 if (logical_val)
then
592 call this%chkp_out%init(this%chkp, name = name,&
593 path = this%output_directory, fmt = trim(string_val))
594 call json_get(this%params,
'case.checkpoint_control', &
596 if (trim(string_val) .eq.
'tsteps' .or. &
597 trim(string_val) .eq.
'nsamples')
then
600 real_val =
real(integer_val, kind=
rp)
601 else if (trim(string_val) .eq.
'simulationtime')
then
604 else if (trim(string_val) .eq.
'never')
then
608 call this%output_controller%add(this%chkp_out, real_val, string_val, &
615 if (this%params%valid_path(
'case.job_timelimit'))
then
616 call json_get(this%params,
'case.job_timelimit', string_val)
622 call scalar_params%destroy()
623 call numerics_params%destroy()
624 call json_subdict%destroy()