Skip to content

Commit afa2612

Browse files
working on xdmf api
1 parent f2d2baf commit afa2612

File tree

7 files changed

+357
-295
lines changed

7 files changed

+357
-295
lines changed

src_main_pub/timestepping.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,7 @@ subroutine solver_run(this)
19881988
this%n=this%n+1 !sube de iteracion
19891989
end do ciclo_temporal ! End of the time-stepping loop
19901990

1991+
19911992
contains
19921993

19931994
subroutine request_flush_if_any_observation_is_done()

src_output/movieProbeOutput.F90

Lines changed: 125 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,63 @@ subroutine init_movie_probe_output(this, lowerBound, upperBound, field, domain,
4242
character(len=BUFSIZE), intent(in) :: outputTypeExtension
4343

4444
integer :: error
45-
character(len=BUFSIZE) :: pdvFileName
45+
character(len=BUFSIZE) :: filename
4646

4747
this%mainCoords = lowerBound
48-
this%auxCoords = upperBound
49-
this%component = field
50-
this%domain = domain
51-
this%path = get_output_path(this, outputTypeExtension, field, control%mpidir)
52-
53-
pdvFileName = add_extension(get_last_component(this%path), pvdExtension)
54-
this%pvdPath = join_path(this%path, pdvFileName)
55-
56-
call create_folder(this%path, error)
57-
call create_file_with_path(add_extension(this%path, binaryExtension), error)
48+
this%auxCoords = upperBound
49+
this%component = field
50+
this%domain = domain
5851

5952
call find_and_store_important_coords(this%mainCoords, this%auxCoords, this%component, problemInfo, this%nPoints, this%coords)
60-
call alloc_and_init(this%timeStep, BuffObse, 0.0_RKIND_tiempo)
53+
call alloc_and_init(this%timeStep, BUFSIZE, 0.0_RKIND_tiempo)
6154

6255
! Allocate value arrays based on component type
63-
call alloc_and_init(this%xValueForTime, BuffObse, this%nPoints, 0.0_RKIND)
64-
call alloc_and_init(this%yValueForTime, BuffObse, this%nPoints, 0.0_RKIND)
65-
call alloc_and_init(this%zValueForTime, BuffObse, this%nPoints, 0.0_RKIND)
56+
call alloc_and_init(this%xValueForTime, BUFSIZE, this%nPoints, 0.0_RKIND)
57+
call alloc_and_init(this%yValueForTime, BUFSIZE, this%nPoints, 0.0_RKIND)
58+
call alloc_and_init(this%zValueForTime, BUFSIZE, this%nPoints, 0.0_RKIND)
59+
60+
this%path = get_output_path(this, outputTypeExtension, field, control%mpidir)
61+
filename = get_last_component(this%path)
62+
this%filesPath = join_path(this%path, filename)
63+
64+
call create_folder(this%path, error)
65+
call create_bin_file(this%filesPath, error)
66+
call create_movie_files(this%filesPath, this%coords ,this%nPoints, error)
6667
end subroutine init_movie_probe_output
6768

69+
subroutine create_bin_file(filePath, error)
70+
character(len=*), intent(in) :: filePath
71+
integer, intent(out) :: error
72+
call create_file_with_path(add_extension(filePath, binaryExtension), error)
73+
end subroutine
74+
75+
subroutine create_movie_files(filePath, coords, nPoints, error)
76+
character(len=*), intent(in) :: filePath
77+
integer(kind=SINGLE), dimension(:, :), intent(in) :: coords
78+
integer, intent(in) :: nPoints
79+
integer, intent(out) :: error
80+
real(dp), allocatable, dimension(:, :) :: coordsReal
81+
82+
integer(HID_T) :: file_id
83+
character(len=BUFSIZE) :: h5_filename
84+
85+
h5_filename = add_extension(filePath, ".h5")
86+
87+
call H5open_f(error)
88+
call create_h5_file(trim(h5_filename), file_id)
89+
90+
allocate (coordsReal(3, nPoints))
91+
coordsReal = real(coords, dp)
92+
call write_dataset(file_id, "coords", coordsReal)
93+
deallocate(coordsReal)
94+
95+
call init_extendable_2d_dataset(file_id, 'xVal', nPoints, BUFSIZE)
96+
call init_extendable_2d_dataset(file_id, 'yVal', nPoints, BUFSIZE)
97+
call init_extendable_2d_dataset(file_id, 'zVal', nPoints, BUFSIZE)
98+
call H5Fclose_f(file_id, error)
99+
call H5close_f(error)
100+
end subroutine
101+
68102
subroutine update_movie_probe_output(this, step, fieldsReference, control, problemInfo)
69103
type(movie_probe_output_t), intent(inout) :: this
70104
real(kind=RKIND_tiempo), intent(in) :: step
@@ -129,7 +163,7 @@ subroutine flush_movie_probe_output(this)
129163
integer :: i
130164

131165
call write_bin_file(this)
132-
call write_to_xdmf(this)
166+
call write_to_xdmf_h5(this)
133167

134168
call clear_memory_data(this)
135169
end subroutine flush_movie_probe_output
@@ -143,16 +177,89 @@ subroutine write_bin_file(this)
143177
type(movie_probe_output_t), intent(inout) :: this
144178
integer :: i, t, unit
145179

146-
open (unit=unit, file=add_extension(this%path, binaryExtension), &
180+
open (unit=unit, file=add_extension(this%filesPath, binaryExtension), &
147181
status='old', form='unformatted', position='append', access='stream')
148182
do t = 1, this%nTime
149183
do i = 1, this%nPoints
150184
write(unit) this%timeStep(t), this%coords(1,i), this%coords(2,i), this%coords(3,i), this%xValueForTime(t,i), this%yValueForTime(t,i), this%zValueForTime(t,i)
151185
end do
152186
end do
187+
flush (unit)
153188
close (unit)
154189
end subroutine
155190

191+
subroutine write_to_xdmf_h5(this)
192+
193+
type(movie_probe_output_t), intent(inout) :: this
194+
195+
integer(HID_T) :: file_id
196+
integer :: t, error, xdmfunit
197+
real(dp), allocatable, dimension(:, :) :: coordsReal
198+
character(len=256) :: h5_filename, h5_filepath
199+
character(len=256) :: xdmf_filename
200+
character(len=10) :: dimension_string
201+
character(len=10) :: nCoordsString
202+
character(len=14) :: stepName
203+
h5_filepath = add_extension(this%filesPath, ".h5")
204+
h5_filename = get_last_component(h5_filepath)
205+
206+
call H5open_f(error)
207+
call H5Fopen_f(trim(h5_filepath), H5F_ACC_RDWR_F, file_id, error)
208+
209+
210+
write(dimension_string, '(I0,1X,I0)') this%nPoints, this%nTimesFlushed + this%nTime
211+
write(nCoordsString, '(I0, I0)') this%nPoints, 1
212+
do t = 1, this%nTime
213+
write(stepName, '((I5.5))') this%nTimesFlushed + t
214+
call append_rows_dataset(file_id, "xVal", reshape(this%xValueForTime(t, :), [1, this%nPoints]))
215+
call append_rows_dataset(file_id, "yVal", reshape(this%yValueForTime(t, :), [1, this%nPoints]))
216+
call append_rows_dataset(file_id, "zVal", reshape(this%zValueForTime(t, :), [1, this%nPoints]))
217+
if (mod(this%nTimesFlushed + t, 10) == 0) then
218+
219+
xdmf_filename = add_extension(add_extension(this%filesPath, ".ts_"//stepName), ".xdmf")
220+
open(newunit=xdmfunit, file=trim(xdmf_filename), status='replace', position='append', iostat=error)
221+
222+
call xdmf_write_header_file(xdmfunit)
223+
224+
call xdmf_create_grid_step_info(xdmfunit, stepName, real(this%timeStep(t)), trim(h5_filename), this%nPoints)
225+
226+
call xdmf_write_attribute(xdmfunit, 'xVal')
227+
call xdmf_write_hyperslab_data_item(xdmfunit, nCoordsString)
228+
call xdmf_write_h5_acces_data_item(xdmfunit, 0, this%nTimesFlushed + t - 1, this%nPoints, this%nTimesFlushed + this%nTime)
229+
call xdmf_close_data_item(xdmfunit)
230+
call xdmf_write_h5_data_item(xdmfunit, trim(h5_filename), '/xVal', dimension_string)
231+
call xdmf_close_data_item(xdmfunit)
232+
call xdmf_close_data_item(xdmfunit)
233+
call xdmf_close_attribute(xdmfunit)
234+
235+
call xdmf_write_attribute(xdmfunit, 'yVal')
236+
call xdmf_write_hyperslab_data_item(xdmfunit, nCoordsString)
237+
call xdmf_write_h5_acces_data_item(xdmfunit, 0, this%nTimesFlushed + t - 1, this%nPoints, this%nTimesFlushed + this%nTime)
238+
call xdmf_close_data_item(xdmfunit)
239+
call xdmf_write_h5_data_item(xdmfunit, trim(h5_filename), '/yVal', dimension_string)
240+
call xdmf_close_data_item(xdmfunit)
241+
call xdmf_close_data_item(xdmfunit)
242+
call xdmf_close_attribute(xdmfunit)
243+
244+
call xdmf_write_attribute(xdmfunit, 'zVal')
245+
call xdmf_write_hyperslab_data_item(xdmfunit, nCoordsString)
246+
call xdmf_write_h5_acces_data_item(xdmfunit, 0, this%nTimesFlushed + t - 1, this%nPoints, this%nTimesFlushed + this%nTime)
247+
call xdmf_close_data_item(xdmfunit)
248+
call xdmf_write_h5_data_item(xdmfunit, trim(h5_filename), '/zVal', dimension_string)
249+
call xdmf_close_data_item(xdmfunit)
250+
call xdmf_close_data_item(xdmfunit)
251+
call xdmf_close_attribute(xdmfunit)
252+
253+
call xdmf_close_grid(xdmfunit)
254+
255+
call xdmf_write_footer_file(xdmfunit)
256+
close(xdmfunit)
257+
endif
258+
end do
259+
260+
call H5Fclose_f(file_id, error)
261+
call H5close_f(error)
262+
end subroutine write_to_xdmf_h5
156263

157264
subroutine read_bin_file(this)
158265
! Check type definition for binary format
@@ -327,7 +434,7 @@ end subroutine update_pvd
327434

328435
subroutine clear_memory_data(this)
329436
type(movie_probe_output_t), intent(inout) :: this
330-
437+
this%nTimesFlushed = this%nTimesFlushed + this%nTime
331438
this%nTime = 0
332439
this%timeStep = 0.0_RKIND
333440
if (any(VOLUMIC_M_MEASURE == this%component)) then

src_output/output.F90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ subroutine close_outputs()
443443
case (BULK_PROBE_ID)
444444
case (VOLUMIC_CURRENT_PROBE_ID)
445445
case (MOVIE_PROBE_ID)
446-
447446
case (FREQUENCY_SLICE_PROBE_ID)
448447
call close_pvd(outputs(i)%frequencySliceProbe%pvdPath)
449448
end select

src_output/outputTypes.F90

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ module outputTypes
9696
type, extends(abstract_probe_t) :: abstract_time_probe_t
9797
character(len=BUFSIZE) :: filePathTime
9898
integer(kind=SINGLE) :: nTime = 0_SINGLE
99+
integer(kind=SINGLE) :: nTimesFlushed = 0_SINGLE !times alredy writen in disk
99100
real(kind=RKIND_tiempo), allocatable :: timeStep(:)
100101
end type abstract_time_probe_t
101102

@@ -171,7 +172,7 @@ module outputTypes
171172
real(kind=RKIND), allocatable :: xValueForTime(:, :) !(time, coordIdx)
172173
real(kind=RKIND), allocatable :: yValueForTime(:, :) !(time, coordIdx)
173174
real(kind=RKIND), allocatable :: zValueForTime(:, :) !(time, coordIdx)
174-
character(len=BUFSIZE) :: pvdPath
175+
character(len=BUFSIZE) :: filesPath
175176
end type movie_probe_output_t
176177

177178
type, extends(abstract_frequency_probe_t) :: frequency_slice_probe_output_t

0 commit comments

Comments
 (0)