Skip to content

Commit d07dda7

Browse files
adperezmtimofeymukhavbaconnet
authored andcommitted
Feature/write mesh control (#2281)
Added an option to print out the mesh every time. I am having problems on deciding how to do this. Generally I would like that one can control what is written when the write method is called, but that is not the way we do things in Neko, so for the moment it is just like this. I guess if one creates a file_t in the user file, it is possible to control if the mesh is written by directly modifying the attribute in the object, so at least that's something. This is based on what @arash-mp will also add in #2244. --------- Co-authored-by: Timofey Mukha <timofey.mukha@protonmail.com> Co-authored-by: Victor Baconnet <baconnet@kth.se>
1 parent a01540c commit d07dda7

File tree

6 files changed

+33
-6
lines changed

6 files changed

+33
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Develop
4+
- Added an option for writing the mesh in every output field file.
45
- *BREAKING* All simcomps now have a `name` keyword in the case file. A default
56
name is assigned, but all `name`s must be unique. If you have two or more
67
simcomps of the same `type`, you must manually provide each a unique `name`.

doc/pages/user-guide/case-file.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ concisely directly in the table.
11601160
| `nut_field` | The name of the turbulent viscosity field. | String | - |
11611161
| `output_control` | Defines the interpretation of `output_value` to define the frequency of writing checkpoint files. | `nsamples`, `simulationtime`, `tsteps`, `never` | - |
11621162
| `output_value` | The frequency of sampling in terms of `output_control`. | Positive real or integer | - |
1163+
| `output_mesh_in_all_files` | Indicates if the mesh should be written in every output fld file. | `true` or `false` | `false` |
11631164
| `output_filename` | The output filename. | String | `field` |
11641165
| `inflow_condition.type` | Velocity inflow condition type. | `user`, `uniform`, `blasius` | - |
11651166
| `inflow_condition.value` | Value of the inflow velocity. | Vector of 3 reals | - |

src/.depends

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ io/csv_file.lo : io/csv_file.f90 comm/comm.lo common/log.lo config/num_types.lo
146146
io/hdf5_file.lo : io/hdf5_file.F90 comm/comm.lo common/log.lo sem/dofmap.lo field/field_series.lo field/field_list.lo field/field.lo mesh/mesh.lo common/utils.lo common/checkpoint.lo io/generic_file.lo config/num_types.lo
147147
io/file.lo : io/file.f90 io/hdf5_file.lo io/csv_file.lo io/stl_file.lo io/vtk_file.lo io/fld_file_data.lo io/fld_file.lo io/bp_file.lo io/re2_file.lo io/rea_file.lo io/map_file.lo io/chkp_file.lo io/nmsh_file.lo io/generic_file.lo config/num_types.lo common/utils.lo
148148
io/output.lo : io/output.f90 io/file.lo config/num_types.lo
149-
io/fluid_output.lo : io/fluid_output.f90 field/field.lo registries/registry.lo scalar/scalars.lo io/output.lo device/device.lo config/neko_config.lo field/field_list.lo scalar/scalar_scheme.lo fluid/fluid_scheme_base.lo fluid/fluid_scheme_compressible.lo fluid/fluid_scheme_incompressible.lo config/num_types.lo
149+
io/fluid_output.lo : io/fluid_output.f90 io/fld_file.lo field/field.lo registries/registry.lo scalar/scalars.lo io/output.lo device/device.lo config/neko_config.lo field/field_list.lo scalar/scalar_scheme.lo fluid/fluid_scheme_base.lo fluid/fluid_scheme_compressible.lo fluid/fluid_scheme_incompressible.lo config/num_types.lo
150150
io/fld_file_output.lo : io/fld_file_output.f90 io/output.lo device/device.lo config/neko_config.lo field/field_list.lo config/num_types.lo
151151
io/chkp_output.lo : io/chkp_output.f90 config/num_types.lo io/output.lo common/checkpoint.lo
152152
io/fluid_stats_output.lo : io/fluid_stats_output.f90 math/matrix.lo io/output.lo device/device.lo io/fld_file_data.lo sem/map_2d.lo sem/map_1d.lo config/num_types.lo config/neko_config.lo fluid/fluid_stats.lo

src/case.f90

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,15 +494,20 @@ subroutine case_init_common(this)
494494
name, "field")
495495
call json_get_or_default(this%params, 'case.fluid.output_format', &
496496
file_format, 'fld')
497+
call json_get_or_default(this%params, &
498+
'case.fluid.output_mesh_in_all_files', &
499+
logical_val, .false.)
497500
call this%output_controller%init(this%time%end_time)
498501
if (scalar) then
499502
call this%f_out%init(precision, this%fluid, this%scalars, name = name, &
500503
path = trim(this%output_directory), &
501-
fmt = trim(file_format), layout = layout)
504+
fmt = trim(file_format), layout = layout, &
505+
always_write_mesh = logical_val)
502506
else
503507
call this%f_out%init(precision, this%fluid, name = name, &
504508
path = trim(this%output_directory), &
505-
fmt = trim(file_format), layout = layout)
509+
fmt = trim(file_format), layout = layout, &
510+
always_write_mesh = logical_val)
506511
end if
507512

508513
call json_get_or_default(this%params, 'case.fluid.output_control',&

src/io/fld_file.f90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module fld_file
6363
!> Interface for NEKTON fld files
6464
type, public, extends(generic_file_t) :: fld_file_t
6565
logical :: dp_precision = .false. !< Precision of output data
66+
logical :: write_mesh = .false. !< Whether to write the mesh
6667
contains
6768
procedure :: read => fld_file_read
6869
procedure :: write => fld_file_write
@@ -281,7 +282,12 @@ subroutine fld_file_write(this, data, t)
281282
!
282283

283284
call this%increment_counter()
284-
write_mesh = (this%get_counter() .eq. this%get_start_counter())
285+
! Check if I should write the mesh. Always override at the start counters
286+
if (.not. this%write_mesh) then
287+
write_mesh = (this%get_counter() .eq. this%get_start_counter())
288+
else
289+
write_mesh = this%write_mesh
290+
end if
285291
call MPI_Allreduce(MPI_IN_PLACE, write_mesh, 1, &
286292
MPI_LOGICAL, MPI_LOR, NEKO_COMM)
287293
call MPI_Allreduce(MPI_IN_PLACE, write_velocity, 1, &

src/io/fluid_output.f90

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ module fluid_output
4444
use scalars, only : scalars_t
4545
use registry, only : neko_registry
4646
use field, only : field_t
47+
use fld_file, only : fld_file_t
4748
implicit none
4849
private
4950

5051
!> Fluid output
5152
type, public, extends(output_t) :: fluid_output_t
5253
type(field_list_t) :: fluid
54+
logical :: always_write_mesh = .false.
5355
contains
5456
procedure, pass(this) :: init => fluid_output_init
5557
procedure, pass(this) :: sample => fluid_output_sample
@@ -59,14 +61,15 @@ module fluid_output
5961
contains
6062

6163
subroutine fluid_output_init(this, precision, fluid, scalar_fields, name, &
62-
path, fmt, layout)
64+
path, fmt, layout, always_write_mesh)
6365
class(fluid_output_t), intent(inout) :: this
6466
integer, intent(inout) :: precision
6567
class(fluid_scheme_base_t), intent(in), target :: fluid
6668
class(scalars_t), intent(in), optional, target :: scalar_fields
6769
character(len=*), intent(in), optional :: name
6870
character(len=*), intent(in), optional :: path
6971
character(len=*), intent(in), optional :: fmt
72+
logical, intent(in), optional :: always_write_mesh
7073
integer, intent(in), optional :: layout
7174
character(len=1024) :: fname
7275
integer :: i, j, n_scalars
@@ -81,6 +84,10 @@ subroutine fluid_output_init(this, precision, fluid, scalar_fields, name, &
8184
end if
8285
end if
8386

87+
if (present(always_write_mesh)) then
88+
this%always_write_mesh = always_write_mesh
89+
end if
90+
8491
if (present(name) .and. present(path)) then
8592
fname = trim(path) // trim(name) // trim(suffix)
8693
else if (present(name)) then
@@ -188,7 +195,14 @@ subroutine fluid_output_sample(this, t)
188195

189196
end if
190197

191-
call this%file_%write(this%fluid, t)
198+
select type (ft => this%file_%file_type)
199+
! Only fld files have the option to write the mesh at command
200+
type is (fld_file_t)
201+
ft%write_mesh = this%always_write_mesh
202+
call ft%write(this%fluid, t)
203+
class default
204+
call ft%write(this%fluid, t)
205+
end select
192206

193207
end subroutine fluid_output_sample
194208

0 commit comments

Comments
 (0)