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%s, &
431 this%scalars%scalar_fields(i)%scalar%c_Xh, &
432 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
433 string_val, json_subdict, 0)
434 temperature_found = .true.
436 if (temperature_found)
then
440 this%scalars%scalar_fields(i)%scalar%s, &
441 this%scalars%scalar_fields(i)%scalar%c_Xh, &
442 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
443 string_val, json_subdict, i - 1)
448 this%scalars%scalar_fields(i)%scalar%s, &
449 this%scalars%scalar_fields(i)%scalar%c_Xh, &
450 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
451 string_val, json_subdict, i)
455 call set_scalar_ic(this%scalars%scalar_fields(i)%scalar%name,&
456 this%scalars%scalar_fields(i)%scalar%s, &
457 this%scalars%scalar_fields(i)%scalar%c_Xh, &
458 this%scalars%scalar_fields(i)%scalar%gs_Xh, &
459 this%user%initial_conditions)
468 select type (f => this%fluid)
478 call this%fluid%validate
481 call this%scalars%validate()
488 this%output_directory,
'')
490 output_dir_len = len(trim(this%output_directory))
491 if (output_dir_len .gt. 0)
then
492 if (this%output_directory(output_dir_len:output_dir_len) .ne.
"/")
then
493 this%output_directory = trim(this%output_directory)//
"/"
496 call mkdir(trim(this%output_directory))
504 logical_val, .false.)
505 if (logical_val)
then
506 call msh_part%init(this%msh,
'MPI_Rank')
508 call part_file%init(trim(this%output_directory)//
'partitions.vtk')
509 call part_file%write(msh_part)
519 if (trim(string_val) .eq.
'double')
then
539 'case.fluid.output_mesh_in_all_files', &
540 logical_val, .false.)
544 tmp_feature, .false.)
545 if (tmp_feature) logical_val = .true.
547 call this%output_controller%init(this%time%end_time)
549 call this%f_out%init(precision, this%fluid, this%scalars, name = name, &
550 path = trim(this%output_directory), &
551 fmt = trim(file_format), layout = layout, &
552 always_write_mesh = logical_val)
554 call this%f_out%init(precision, this%fluid, name = name, &
555 path = trim(this%output_directory), &
556 fmt = trim(file_format), layout = layout, &
557 always_write_mesh = logical_val)
561 logical_val, .false.)
562 call this%f_out%file_%set_subdivide(logical_val)
564 call json_get(this%params,
'case.fluid.output_control', string_val)
566 if (trim(string_val) .eq.
'org')
then
569 real_val =
real(integer_val, kind=
rp)
570 call this%output_controller%add(this%f_out, real_val,
'nsamples')
571 else if (trim(string_val) .eq.
'never')
then
572 call this%output_controller%add(this%f_out, 0.0_rp,
'never')
573 else if (trim(string_val) .eq.
'tsteps' .or. &
574 trim(string_val) .eq.
'nsamples')
then
577 real_val =
real(integer_val, kind=
rp)
578 call this%output_controller%add(this%f_out, real_val, string_val)
579 else if (trim(string_val) .eq.
'simulationtime')
then
581 call this%output_controller%add(this%f_out, real_val, string_val)
583 call neko_log%error(
'Unknown output control type for the fluid: ' // &
590 call json_get(this%params,
'case.output_checkpoints', logical_val)
591 if (logical_val)
then
596 call this%chkp_out%init(this%chkp, name = name,&
597 path = this%output_directory, fmt = trim(string_val))
598 call json_get(this%params,
'case.checkpoint_control', &
600 if (trim(string_val) .eq.
'tsteps' .or. &
601 trim(string_val) .eq.
'nsamples')
then
604 real_val =
real(integer_val, kind=
rp)
605 else if (trim(string_val) .eq.
'simulationtime')
then
608 else if (trim(string_val) .eq.
'never')
then
612 call this%output_controller%add(this%chkp_out, real_val, string_val, &
619 if (this%params%valid_path(
'case.job_timelimit'))
then
620 call json_get(this%params,
'case.job_timelimit', string_val)
626 call scalar_params%destroy()
627 call numerics_params%destroy()
628 call json_subdict%destroy()