Neko  0.8.99
A portable framework for high-order spectral element flow simulations
file.f90
Go to the documentation of this file.
1 ! Copyright (c) 2019-2024, The Neko Authors
2 ! All rights reserved.
3 !
4 ! Redistribution and use in source and binary forms, with or without
5 ! modification, are permitted provided that the following conditions
6 ! are met:
7 !
8 ! * Redistributions of source code must retain the above copyright
9 ! notice, this list of conditions and the following disclaimer.
10 !
11 ! * Redistributions in binary form must reproduce the above
12 ! copyright notice, this list of conditions and the following
13 ! disclaimer in the documentation and/or other materials provided
14 ! with the distribution.
15 !
16 ! * Neither the name of the authors nor the names of its
17 ! contributors may be used to endorse or promote products derived
18 ! from this software without specific prior written permission.
19 !
20 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 ! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 ! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 ! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 ! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 ! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 ! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 ! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 ! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 ! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 ! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 ! POSSIBILITY OF SUCH DAMAGE.
32 !
34 module file
36  use num_types, only : rp
37  use generic_file, only : generic_file_t
38  use nmsh_file, only : nmsh_file_t
39  use chkp_file, only : chkp_file_t
40  use map_file, only : map_file_t
41  use rea_file, only : rea_file_t
42  use re2_file, only : re2_file_t
43  use fld_file, only : fld_file_t
44  use fld_file_data, only : fld_file_data_t
45  use vtk_file, only : vtk_file_t
46  use stl_file, only : stl_file_t
47  use csv_file, only : csv_file_t
48  use hdf5_file, only : hdf5_file_t
49  implicit none
50 
54  type file_t
55  class(generic_file_t), allocatable :: file_type
56  contains
58  procedure :: write => file_write
60  procedure :: read => file_read
62  procedure :: set_counter => file_set_counter
64  procedure :: set_start_counter => file_set_start_counter
66  procedure :: set_header => file_set_header
68  procedure :: set_precision => file_set_precision
70  final :: file_free
71  end type file_t
72 
73  interface file_t
74  module procedure file_init
75  end interface file_t
76 
77 contains
78 
81  function file_init(fname, header, precision) result(this)
82  character(len=*) :: fname
83  character(len=*), optional :: header
84  integer, optional :: precision
85  type(file_t), target :: this
86  character(len=80) :: suffix
87  class(generic_file_t), pointer :: q
88 
89  call filename_suffix(fname, suffix)
90 
91  if (allocated(this%file_type)) then
92  deallocate(this%file_type)
93  end if
94 
95  if (suffix .eq. "rea") then
96  allocate(rea_file_t::this%file_type)
97  else if (suffix .eq. "re2") then
98  allocate(re2_file_t::this%file_type)
99  else if (suffix .eq. "map") then
100  allocate(map_file_t::this%file_type)
101  else if (suffix .eq. "vtk") then
102  allocate(vtk_file_t::this%file_type)
103  else if (suffix .eq. "nmsh") then
104  allocate(nmsh_file_t::this%file_type)
105  else if (suffix .eq. "fld") then
106  allocate(fld_file_t::this%file_type)
107  else if (suffix .eq. "chkp") then
108  allocate(chkp_file_t::this%file_type)
109  else if (suffix .eq. "stl") then
110  allocate(stl_file_t::this%file_type)
111  else if (suffix .eq. "csv") then
112  allocate(csv_file_t::this%file_type)
113  this%file_type%serial = .true.
114  else if ((suffix .eq. "hdf5") .or. (suffix .eq. "h5")) then
115  allocate(hdf5_file_t::this%file_type)
116  else
117  call neko_error('Unknown file format')
118  end if
119 
120  call this%file_type%init(fname)
121 
122  if (present(header)) then
123  call this%set_header(header)
124  end if
125 
126  if (present(precision)) then
127  call this%set_precision(precision)
128  end if
129 
130  end function file_init
131 
133  subroutine file_free(this)
134  type(file_t), intent(inout) :: this
135 
136  if (allocated(this%file_type)) then
137  deallocate(this%file_type)
138  end if
139 
140  end subroutine file_free
141 
144  subroutine file_write(this, data, t)
145  class(file_t), intent(inout) :: this
146  class(*), intent(inout) :: data
147  real(kind=rp), intent(in), optional :: t
148 
149  if (present(t)) then
150  call this%file_type%write(data, t)
151  else
152  call this%file_type%write(data)
153  end if
154 
155  end subroutine file_write
156 
159  subroutine file_read(this, data)
160  class(file_t), intent(in) :: this
161  class(*), intent(inout) :: data
162 
163  call this%file_type%read(data)
164 
165  end subroutine file_read
166 
168  subroutine file_set_counter(this, n)
169  class(file_t), intent(inout) :: this
170  integer, intent(in) :: n
171 
172  select type(ft => this%file_type)
173  class is (generic_file_t)
174  call ft%set_counter(n)
175  end select
176 
177  end subroutine file_set_counter
178 
180  subroutine file_set_start_counter(this, n)
181  class(file_t), intent(inout) :: this
182  integer, intent(in) :: n
183 
184  select type(ft => this%file_type)
185  class is (generic_file_t)
186  call ft%set_start_counter(n)
187  end select
188 
189  end subroutine file_set_start_counter
190 
192  subroutine file_set_header(this, hd)
193  class(file_t), intent(inout) :: this
194  character(len=*), intent(in) :: hd
195 
196  character(len=80) :: suffix
197 
198  select type(ft => this%file_type)
199  class is (csv_file_t)
200  call ft%set_header(hd)
201  class default
202  call filename_suffix(this%file_type%fname, suffix)
203  call neko_warning("No set_header defined for " // trim(suffix) // " yet!")
204  end select
205 
206  end subroutine file_set_header
207 
210  subroutine file_set_precision(this, precision)
211  class(file_t), intent(inout) :: this
212  integer, intent(in) :: precision
213 
214  character(len=80) :: suffix
215 
216  select type(ft => this%file_type)
217  type is (fld_file_t)
218  call ft%set_precision(precision)
219  class default
220  call filename_suffix(this%file_type%fname, suffix)
221  call neko_warning("No precision strategy defined for " // trim(suffix) //&
222  " files!")
223  end select
224 
225  end subroutine file_set_precision
226 
227 end module file
Neko checkpoint file format.
Definition: chkp_file.f90:35
File format for .csv files, used for any read/write operations involving floating point data.
Definition: csv_file.f90:35
Module for file I/O operations.
Definition: file.f90:34
subroutine file_set_header(this, hd)
Set a file's header.
Definition: file.f90:193
subroutine file_set_start_counter(this, n)
Set a file's start counter.
Definition: file.f90:181
subroutine file_set_counter(this, n)
Set a file's counter.
Definition: file.f90:169
type(file_t) function, target file_init(fname, header, precision)
File reader/writer constructor.
Definition: file.f90:82
subroutine file_read(this, data)
Read data from a file.
Definition: file.f90:160
subroutine file_set_precision(this, precision)
Set a file's output precision.
Definition: file.f90:211
subroutine file_free(this)
File operation destructor.
Definition: file.f90:134
subroutine file_write(this, data, t)
Writes data to a file.
Definition: file.f90:145
Simple module to handle fld file series. Provides an interface to the different fields sotred in a fl...
NEKTON fld file format.
Definition: fld_file.f90:35
HDF5 file format.
Definition: hdf5_file.F90:34
NEKTON map file.
Definition: map_file.f90:35
Neko binary mesh data.
Definition: nmsh_file.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
NEKTON mesh data in re2 format.
Definition: re2_file.f90:35
NEKTON session data reader.
Definition: rea_file.f90:35
Stereolithography (STL) file.
Definition: stl_file.f90:34
Utilities.
Definition: utils.f90:35
subroutine, public neko_warning(warning_msg)
Definition: utils.f90:198
subroutine, public filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition: utils.f90:69
Legacy VTK file format.
Definition: vtk_file.f90:35
Interface for Neko checkpoint files.
Definition: chkp_file.f90:55
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Definition: file.f90:54
Interface for NEKTON fld files.
Definition: fld_file.f90:64
A generic file handler.
Interface for HDF5 files.
Definition: hdf5_file.F90:54
Interface for NEKTON map files.
Definition: map_file.f90:44
Interface for Neko nmsh files.
Definition: nmsh_file.f90:60
Interface for NEKTON re2 files.
Definition: re2_file.f90:62
Interface for NEKTON ascii files.
Definition: rea_file.f90:61
Interface for STL files.
Definition: stl_file.f90:49
Interface for legacy VTK files.
Definition: vtk_file.f90:51