FE-Project
Loading...
Searching...
No Matches
scale_file_restart_meshfield.F90
Go to the documentation of this file.
1!-------------------------------------------------------------------------------
10!-------------------------------------------------------------------------------
11#include "scaleFElib.h"
13 !-----------------------------------------------------------------------------
14 !
15 !++ Used modules
16 !
17 use scale_precision
18 use scale_io
19 use scale_prc, only: &
20 prc_myrank, &
21 prc_abort
22 use scale_file_h, only: &
23 file_file_max
26
38
41
42 use scale_file_base_meshfield, only: &
44
45 use scale_mesh_base1d, only: &
46 mf1d_dimtype_x => meshbase1d_dimtypeid_x, &
47 mf1d_dtype_num => meshbase1d_dimtype_num
48 use scale_mesh_base2d, only: &
49 mf2d_dimtype_x => meshbase2d_dimtypeid_x, &
50 mf2d_dimtype_y => meshbase2d_dimtypeid_y, &
51 mf2d_dtype_num => meshbase2d_dimtype_num
52 use scale_mesh_base3d, only: &
53 mf3d_dimtype_x => meshbase3d_dimtypeid_x, &
54 mf3d_dimtype_y => meshbase3d_dimtypeid_y, &
55 mf3d_dimtype_z => meshbase3d_dimtypeid_z, &
56 mf3d_dtype_num => meshbase3d_dimtype_num
57
58 !-----------------------------------------------------------------------------
59 implicit none
60 private
61 !-----------------------------------------------------------------------------
62 !
63 !++ Public type & procedures
64 !
65 type :: file_restart_meshfield
66 type(FILE_base_meshfield) :: base
67
68 logical :: flag_output
69 character(len=H_LONG) :: in_basename
70 logical :: in_postfix_timelabel
71
72 character(len=H_LONG) :: out_basename
73 logical :: out_postfix_timelabel
74 character(len=H_MID) :: out_title
75 character(len=H_SHORT) :: out_dtype
76 end type file_restart_meshfield
77 type(file_restart_meshfield), public :: restart_file
78
80
81
82 type, extends(file_restart_meshfield), public :: file_restart_meshfield_component
83 character(len=H_SHORT) :: comp_name
84 contains
85 procedure :: init1 => file_restart_meshfield_component_init1
86 procedure :: init2 => file_restart_meshfield_component_init2
87 generic :: init => init1, init2
88 procedure :: open => file_restart_meshfield_component_open
89 procedure :: file_restart_meshfield_component_create
90 generic :: create => file_restart_meshfield_component_create
91 procedure :: file_restart_meshfield_component_def_var
92 generic :: def_var => file_restart_meshfield_component_def_var
93 procedure :: end_def => file_restart_meshfield_component_enddef
94 procedure :: file_restart_meshfield_component_write_var2d
95 procedure :: file_restart_meshfield_component_write_var3d
96 generic :: write_var => &
97 file_restart_meshfield_component_write_var2d, &
98 file_restart_meshfield_component_write_var3d
99 procedure :: close => file_restart_meshfield_component_close
100 procedure :: file_restart_meshfield_component_read_var2d
101 procedure :: file_restart_meshfield_component_read_var3d
102 generic :: read_var => &
103 file_restart_meshfield_component_read_var2d, &
104 file_restart_meshfield_component_read_var3d
105 procedure :: final => file_restart_meshfield_component_final
106 end type
107
108 !-----------------------------------------------------------------------------
109 !
110 !++ Public parameters & variables
111 !
112 !-----------------------------------------------------------------------------
113 !
114 !++ Private procedures
115 !
116 !-------------------
117
118contains
119
120!----------------
121!OCL SERIAL
123 implicit none
124
125 logical :: output_flag = .false.
126 character(len=H_LONG) :: in_basename = ''
127 logical :: in_postfix_timelabel = .false.
128 character(len=H_LONG) :: out_basename = ''
129 logical :: out_postfix_timelabel = .true.
130 character(len=H_MID) :: out_title = ''
131 character(len=H_SHORT) :: out_dtype = 'DEFAULT'
132
133 namelist / param_restart / &
134 output_flag, &
135 in_basename, &
136 in_postfix_timelabel, &
137 out_basename, &
138 out_postfix_timelabel, &
139 out_title, &
140 out_dtype
141
142 integer :: ierr
143 !----------------------------------------
144
145 log_newline
146
147 !--- read namelist
148 rewind(io_fid_conf)
149 read(io_fid_conf,nml=param_restart,iostat=ierr)
150 if( ierr < 0 ) then !--- missing
151 log_info("FILE_restart_meshfield_setup",*) 'Not found namelist. Default used.'
152 elseif( ierr > 0 ) then !--- fatal error
153 log_error("FILE_restart_meshfield_setup",*) 'Not appropriate names in namelist PARAM_RESTART. Check!'
154 call prc_abort
155 endif
156 log_nml(param_restart)
157
158 restart_file%flag_output = output_flag
159
160 restart_file%in_basename = in_basename
161 restart_file%in_postfix_timelabel = in_postfix_timelabel
162
163 restart_file%out_basename = out_basename
164 restart_file%out_postfix_timelabel = out_postfix_timelabel
165 restart_file%out_title = out_title
166 restart_file%out_dtype = out_dtype
167
168 restart_file%base%fid = -1
169
170 return
171 end subroutine file_restart_meshfield_setup
172
173!OCL SERIAL
174 subroutine file_restart_meshfield_component_init1( this, &
175 comp_name, &
176 var_num, mesh1D, mesh2D, meshCubedSphere2D, &
177 mesh3D, meshCubedSphere3D )
178
179 use scale_file_common_meshfield, only: &
181
182 implicit none
183
184 class(file_restart_meshfield_component), intent(inout) :: this
185 character(*), intent(in) :: comp_name
186 integer, intent(in) :: var_num
187 class(meshbase1d), target, optional, intent(in) :: mesh1d
188 class(meshrectdom2d), target, optional, intent(in) :: mesh2d
189 class(meshcubedspheredom2d), target, optional, intent(in) :: meshcubedsphere2d
190 class(meshcubedom3d), target, optional, intent(in) :: mesh3d
191 class(meshcubedspheredom3d), target, optional, intent(in) :: meshcubedsphere3d
192
193 !--------------------------------------------------
194
195 call this%Init2( &
196 comp_name, &
197 restart_file%in_basename, restart_file%in_postfix_timelabel, &
198 restart_file%out_basename, restart_file%out_postfix_timelabel, &
199 restart_file%out_dtype, restart_file%out_title, &
200 var_num, mesh1d, mesh2d, meshcubedsphere2d, mesh3d, meshcubedsphere3d )
201
202 return
203 end subroutine file_restart_meshfield_component_init1
204
205!OCL SERIAL
206 subroutine file_restart_meshfield_component_init2( this, &
207 comp_name, &
208 in_basename, in_postfix_timelabel, &
209 out_basename, out_postfix_timelabel, &
210 out_dtype, out_title, &
211 var_num, &
212 mesh1D, &
213 mesh2D, meshCubedSphere2D, &
214 mesh3D, meshCubedSphere3D )
215
216 implicit none
217
218 class(file_restart_meshfield_component), intent(inout) :: this
219 character(*), intent(in) :: comp_name
220 character(*), intent(in) :: in_basename
221 logical, intent(in) :: in_postfix_timelabel
222 character(*), intent(in) :: out_basename
223 logical, intent(in) :: out_postfix_timelabel
224 character(*), intent(in) :: out_title
225 character(*), intent(in) :: out_dtype
226 integer, intent(in) :: var_num
227 class(meshbase1d), target, optional, intent(in) :: mesh1d
228 class(meshrectdom2d), target, optional, intent(in) :: mesh2d
229 class(meshcubedspheredom2d), target, optional, intent(in) :: meshcubedsphere2d
230 class(meshcubedom3d), target, optional, intent(in) :: mesh3d
231 class(meshcubedspheredom3d), target, optional, intent(in) :: meshcubedsphere3d
232 !--------------------------------------------------
233 this%comp_name = comp_name
234
235 this%in_basename = in_basename
236 this%in_postfix_timelabel = in_postfix_timelabel
237
238 this%out_basename = out_basename
239 this%out_postfix_timelabel = out_postfix_timelabel
240 this%out_title = out_title
241 this%out_dtype = out_dtype
242
243 !-
244 call this%base%Init( var_num, mesh1d, mesh2d, meshcubedsphere2d, mesh3d, meshcubedsphere3d )
245
246 return
247 end subroutine file_restart_meshfield_component_init2
248
249!OCL SERIAL
250 subroutine file_restart_meshfield_component_open( &
251 this )
252
253 use scale_time, only: &
254 time_gettimelabel
255 implicit none
256
257 class(file_restart_meshfield_component), intent(inout) :: this
258
259 character(len=19) :: timelabel
260 character(len=H_LONG) :: basename
261 !--------------------------------------------------------------
262
263 if ( this%in_basename == '' ) then
264 log_info(trim(this%comp_name)//"_vars_restart_open",*) 'restart file is not specified. Check!'
265 call prc_abort
266 return
267 end if
268
269 if ( this%in_postfix_timelabel ) then
270 call time_gettimelabel( timelabel )
271 basename = trim(this%in_basename)//'_'//trim(timelabel)
272 else
273 basename = trim(this%in_basename)
274 endif
275
276 !--------------------------------
277
278 log_newline
279 log_info(trim(this%comp_name)//"_vars_restart_open",*) 'Open restart file'
280 call this%base%open( basename, myrank=prc_myrank )
281
282 return
283 end subroutine file_restart_meshfield_component_open
284
285!OCL SERIAL
286 subroutine file_restart_meshfield_component_create( &
287 this )
288
289 use scale_time, only: &
290 time_gettimelabel, &
291 nowdate => time_nowdate, &
292 nowsubsec => time_nowsubsec
293 implicit none
294
295 class(file_restart_meshfield_component), intent(inout) :: this
296
297 character(len=19) :: timelabel
298 character(len=H_LONG) :: basename
299 character(len=34) :: tunits
300 character(len=H_SHORT) :: calendar
301 logical :: fileexisted
302 !--------------------------------------------------------------
303
304 if ( this%out_basename == '' ) return
305
306 !--------------------------------
307
308 log_newline
309 log_info(trim(this%comp_name)//"_vars_restart_create",*) 'Create restart file'
310
311 if ( this%out_postfix_timelabel ) then
312 call time_gettimelabel( timelabel )
313 basename = trim(this%out_basename)//'_'//trim(timelabel)
314 else
315 basename = trim(this%out_basename)
316 endif
317
318 log_info(trim(this%comp_name)//"_vars_restart_create",*) 'basename: ', trim(basename)
319
320
321 call this%base%Create( basename, this%out_title, this%out_dtype, & ! (in)
322 fileexisted, & ! (out)
323 myrank=prc_myrank, tunits=tunits, calendar=calendar ) ! (in)
324
325 if ( .not. fileexisted ) then
326 call this%base%Put_GlobalAttribute_time( nowdate, nowsubsec )
327 end if
328
329 return
330 end subroutine file_restart_meshfield_component_create
331
332!OCL SERIAL
333 subroutine file_restart_meshfield_component_def_var( this, &
334 field, desc, vid, dim_type_id )
335
336 implicit none
337
338 class(file_restart_meshfield_component), intent(inout) :: this
339 class(meshfieldbase), intent(in) :: field
340 character(len=*), intent(in) :: desc
341 integer, intent(in) :: vid
342 integer, intent(in) :: dim_type_id
343 !------------------------------------------------------------------
344
345 call this%base%Def_var( &
346 field, desc, vid, dim_type_id, this%out_dtype )
347
348 return
349 end subroutine file_restart_meshfield_component_def_var
350
351!OCL SERIAL
352 subroutine file_restart_meshfield_component_enddef( this )
353
354 implicit none
355 class(file_restart_meshfield_component), intent(inout) :: this
356 !--------------------------------------------------------------
357
358 call this%base%End_def()
359 return
360 end subroutine file_restart_meshfield_component_enddef
361
362!OCL SERIAL
363 subroutine file_restart_meshfield_component_write_var2d( this, &
364 vid, field2d )
365
366 use scale_time, only: time_nowdaysec
367 implicit none
368
369 class(file_restart_meshfield_component), intent(inout) :: this
370 integer, intent(in) :: vid
371 class(meshfield2d), intent(in) :: field2d
372 !--------------------------------------------------
373
374 call this%base%Write_var2D( vid, field2d, time_nowdaysec, time_nowdaysec )
375
376 return
377 end subroutine file_restart_meshfield_component_write_var2d
378
379!OCL SERIAL
380 subroutine file_restart_meshfield_component_write_var3d( this, &
381 vid, field3d )
382
383 use scale_time, only: time_nowdaysec
384 implicit none
385
386 class(file_restart_meshfield_component), intent(inout) :: this
387 integer, intent(in) :: vid
388 class(meshfield3d), intent(in) :: field3d
389 !--------------------------------------------------
390
391 call this%base%Write_var3D( vid, field3d, time_nowdaysec, time_nowdaysec )
392
393 return
394 end subroutine file_restart_meshfield_component_write_var3d
395
396!OCL SERIAL
397 subroutine file_restart_meshfield_component_read_var2d( this, &
398 dim_typeid, varname, field2d, step, allow_missing )
399
400
401 implicit none
402
403 class(file_restart_meshfield_component), intent(inout) :: this
404 integer, intent(in) :: dim_typeid
405 character(*), intent(in) :: varname
406 class(meshfield2d), intent(inout) :: field2d
407 integer, intent(in), optional :: step
408 logical, intent(in), optional :: allow_missing
409 !------------------------------------------------------
410
411 call this%base%Read_Var( &
412 dim_typeid, varname, field2d, step, allow_missing )
413
414 return
415 end subroutine file_restart_meshfield_component_read_var2d
416
417!OCL SERIAL
418 subroutine file_restart_meshfield_component_read_var3d( this, &
419 dim_typeid, varname, field3d, step, allow_missing )
420
421
422 implicit none
423
424 class(file_restart_meshfield_component), intent(inout) :: this
425 integer, intent(in) :: dim_typeid
426 character(*), intent(in) :: varname
427 class(meshfield3d), intent(inout) :: field3d
428 integer, intent(in), optional :: step
429 logical, intent(in), optional :: allow_missing
430 !------------------------------------------------------
431
432 call this%base%Read_Var( &
433 dim_typeid, varname, field3d, step, allow_missing )
434
435 return
436 end subroutine file_restart_meshfield_component_read_var3d
437
438!OCL SERIAL
439 subroutine file_restart_meshfield_component_close( this )
440 implicit none
441
442 class(file_restart_meshfield_component), intent(inout) :: this
443 !--------------------------------------------------
444
445 if ( this%base%fid /= -1 ) then
446 log_newline
447 log_info(trim(this%comp_name)//"_vars_restart_close",*) 'Close restart file'
448 call this%base%Close()
449 end if
450
451 return
452 end subroutine file_restart_meshfield_component_close
453
454!OCL SERIAL
455 subroutine file_restart_meshfield_component_final( this )
456 implicit none
457 class(file_restart_meshfield_component), intent(inout) :: this
458 !--------------------------------------------------
459
460 call this%base%Final()
461
462 return
463 end subroutine file_restart_meshfield_component_final
464
465 !------------
466
module FElib / Element / Base
type(file_restart_meshfield), public restart_file
module FElib / Mesh / Local 1D
module FElib / Mesh / Local 2D
module FElib / Mesh / Local 3D
module FElib / Mesh / Base 1D
integer, public meshbase1d_dimtype_num
integer, public meshbase1d_dimtypeid_x
module FElib / Mesh / Base 2D
integer, public meshbase2d_dimtypeid_x
integer, public meshbase2d_dimtype_num
integer, public meshbase2d_dimtypeid_y
module FElib / Mesh / Base 3D
integer, public meshbase3d_dimtypeid_y
integer, public meshbase3d_dimtypeid_z
integer, public meshbase3d_dimtype_num
integer, public meshbase3d_dimtypeid_x
module FElib / Mesh / Cubic 3D domain
module FElib / Mesh / Cubed-sphere 2D domain
module FElib / Mesh / Cubed-sphere 3D domain
module FElib / Mesh / Rectangle 2D domain
module FElib / Data / base
module FElib / Data / base