Skip to content

Commit 1b76bc8

Browse files
Refactor output handling and enhance geometry simulation for VTK integration
1 parent fd0b261 commit 1b76bc8

File tree

5 files changed

+96
-33
lines changed

5 files changed

+96
-33
lines changed

src_main_pub/timestepping.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,6 @@ subroutine solver_run(this)
18681868
if (this%thereAre%Observation) call flush_outputs(this%sgg%tiempo, this%n, this%control, fieldReference, this%bounds, flushFF)
18691869
#else
18701870
if (this%thereAre%Observation) call FlushObservationFiles(this%sgg,this%ini_save, this%n,this%control%layoutnumber, this%control%size, dxe, dye, dze, dxh, dyh, dzh,this%bounds,this%control%singlefilewrite,this%control%facesNF2FF,flushFF)
1871-
#endif
18721871
#ifdef CompileWithMPI
18731872
call MPI_Barrier(SUBCOMM_MPI,ierr)
18741873
#endif
@@ -1941,6 +1940,7 @@ subroutine solver_run(this)
19411940

19421941
#ifdef CompileWithMPI
19431942
call MPI_Barrier(SUBCOMM_MPI,ierr)
1943+
#endif
19441944
#endif
19451945
endif !del if (this%performflushDATA.or....
19461946
if (this%control%singlefilewrite.and.this%perform%Unpack) call singleUnpack()

src_output/mapVTKOutput.F90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ subroutine writeFaceTagInfo(this, counter, i, j, k, field, tag)
114114
this%materialTag(counter) = tag
115115
end subroutine
116116

117-
subroutine create_geometry_simulation_vtu(this, control)
117+
subroutine create_geometry_simulation_vtu(this, control, realXGrid, realYGrid, realZGrid)
118118
implicit none
119119

120120
type(mapvtk_output_t), intent(in) :: this
121121
type(sim_control_t), intent(in) :: control
122+
real(KIND=RKIND), pointer, dimension(:), intent(in) :: realXGrid, realYGrid, realZGrid
123+
122124
type(vtk_file) :: vtkOutput
123125
type(vtk_unstructured_grid), target :: ugrid
124126

@@ -136,7 +138,7 @@ subroutine create_geometry_simulation_vtu(this, control)
136138
call create_folder(this%path, ierr)
137139
vtuPath = join_path(this%path, get_last_component(this%path))//vtuFileExtension
138140

139-
call createUnstructuredDataForVTU(this%nPoints, this%coords, this%currentType, nodes, edges, quads, numNodes, numEdges, numQuads)
141+
call createUnstructuredDataForVTU(this%nPoints, this%coords, this%currentType, nodes, edges, quads, numNodes, numEdges, numQuads, control%vtkindex, realXGrid, realYGrid, realZGrid)
140142
call ugrid%add_points(real(nodes, 4))
141143

142144
allocate (conn(2*numEdges + 4*numQuads))

src_output/movieProbeOutput.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ end subroutine flush_movie_probe_output
141141
!===========================
142142

143143
subroutine write_bin_file(this)
144+
! Check type definition for binary format
144145
type(movie_probe_output_t), intent(inout) :: this
145146
integer :: i, t, unit
146147

@@ -152,10 +153,10 @@ subroutine write_bin_file(this)
152153
end do
153154
end do
154155
close(unit)
155-
call read_bin_file(this)
156156
end subroutine
157157

158158
subroutine read_bin_file(this)
159+
! Check type definition for binary format
159160
type(movie_probe_output_t), intent(inout) :: this
160161
integer :: unit
161162
integer :: iostat
@@ -164,7 +165,6 @@ subroutine read_bin_file(this)
164165
real(kind=RKIND) :: xVal, yVal, zVal
165166
integer(kind=4) :: dataSize
166167

167-
! Open the file for reading
168168
open(unit=unit, file=add_extension(this%path, binaryExtension), &
169169
status='old', form='unformatted', access='stream', iostat=iostat)
170170
if (iostat /= 0) then

src_output/output.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ subroutine init_outputs(sgg, media, sinpml_fullsize, materialTags, bounds, contr
188188

189189
allocate (outputs(outputCount)%mapvtkOutput)
190190
call init_solver_output(outputs(outputCount)%mapvtkOutput, lowerBound, upperBound, outputRequestType, outputTypeExtension, control%mpidir, problemInfo)
191-
call create_geometry_simulation_vtu(outputs(outputCount)%mapvtkOutput, control)
191+
call create_geometry_simulation_vtu(outputs(outputCount)%mapvtkOutput, control, sgg%LineX, sgg%LineY, sgg%LineZ)
192192
!! call adjust_computation_range --- Required due to issues in mpi region edges
193193

194194
case (iEx, iEy, iEz, iHx, iHy, iHz)

src_output/volumicProbeUtils.F90

Lines changed: 88 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ logical function logical_func(component, i, j, k, problemInfo)
2020
end function logical_func
2121
end interface
2222

23+
interface registerNode
24+
module procedure &
25+
registerNodeByIndex, &
26+
registerNodeByCoordinate
27+
end interface
28+
2329
contains
2430

2531
subroutine find_and_store_important_coords(lowerBound, upperBound, component, problemInfo, nPoints, coords)
@@ -83,9 +89,11 @@ subroutine store_required_coords(lowerBound, upperBound, requestComponent, probl
8389
end do
8490
end subroutine store_required_coords
8591

86-
subroutine createUnstructuredDataForVTU(counter, coords, currentType, Nodes, Edges, Quads, numNodes, numEdges, numQuads)
92+
subroutine createUnstructuredDataForVTU(counter, coords, currentType, Nodes, Edges, Quads, numNodes, numEdges, numQuads, usevtkindex, realXGrid, realYGrid, realZGrid)
8793
integer, intent(in) :: counter
8894
integer(kind=SINGLE), intent(in) :: coords(:, :), currentType(:)
95+
logical, intent(in) :: usevtkindex
96+
real(KIND=RKIND), pointer, dimension(:), intent(in) :: realXGrid, realYGrid, realZGrid
8997

9098
integer(kind=4), intent(out):: numNodes, numQuads, numEdges
9199
real(kind=RKIND), allocatable, dimension(:, :), intent(out) :: Nodes
@@ -99,17 +107,27 @@ subroutine createUnstructuredDataForVTU(counter, coords, currentType, Nodes, Edg
99107
allocate (Quads(4, numQuads))
100108
allocate (Nodes(3, 2*numEdges + 4*numQuads))
101109

102-
call registerElements(counter, coords, currentType, Nodes, Edges, Quads)
110+
call registerElements(counter, coords, currentType, Nodes, Edges, Quads, usevtkindex, realXGrid, realYGrid, realZGrid)
103111
return
104112
end subroutine
105113

106-
subroutine registerNode(nodes, nodeIx, x, y, z)
114+
subroutine registerNodeByIndex(nodes, nodeIdx, x, y, z)
115+
real(kind=RKIND), dimension(:, :), intent(inout) :: nodes
116+
integer(kind=SINGLE), intent(in) :: nodeIdx, x, y, z
117+
!We need to avoid using idx 0
118+
nodes(1, nodeIdx + 1) = x*1.0_RKIND
119+
nodes(2, nodeIdx + 1) = y*1.0_RKIND
120+
nodes(3, nodeIdx + 1) = z*1.0_RKIND
121+
end subroutine
122+
123+
subroutine registerNodeByCoordinate(nodes, nodeIdx, x, y, z)
107124
real(kind=RKIND), dimension(:, :), intent(inout) :: nodes
108-
integer(kind=SINGLE), intent(in) :: nodeIx, x, y, z
125+
integer(kind=SINGLE), intent(in) :: nodeIdx
126+
real(kind=RKIND), intent(in) :: x, y, z
109127
!We need to avoid using idx 0
110-
nodes(1, nodeIx + 1) = x*1.0_RKIND
111-
nodes(2, nodeIx + 1) = y*1.0_RKIND
112-
nodes(3, nodeIx + 1) = z*1.0_RKIND
128+
nodes(1, nodeIdx + 1) = x
129+
nodes(2, nodeIdx + 1) = y
130+
nodes(3, nodeIdx + 1) = z
113131
end subroutine
114132

115133
subroutine registerEdge(edges, edgeIdx, startNodeIdx, endNodeIdx)
@@ -145,66 +163,109 @@ subroutine countElements(counter, currentType, numEdges, numQuads)
145163
end do
146164
end subroutine
147165

148-
subroutine registerElements(counter, coords, currentType, Nodes, Edges, Quads)
166+
subroutine registerElements(counter, coords, currentType, Nodes, Edges, Quads, usevtkindex, realXGrid, realYGrid, realZGrid)
149167
integer, intent(in) :: counter
150168
integer(kind=SINGLE), intent(in) :: coords(:, :), currentType(:)
151169
real(kind=RKIND), intent(inout) :: Nodes(:, :)
152170
integer(kind=4), intent(inout) :: Edges(:, :), Quads(:, :)
171+
logical :: usevtkindex
172+
real(KIND=RKIND), pointer, dimension(:), intent(in) :: realXGrid, realYGrid, realZGrid
153173

154174
integer :: nodeIdx, quadIdx, edgeIdx
175+
integer :: xCoord, yCoord, zCoord
155176
integer :: i
156177

157178
nodeIdx = -1
158179
quadIdx = -1
159180
edgeIdx = -1
160-
181+
161182
do i = 1, counter
183+
xCoord = coords(1, i)
184+
yCoord = coords(2, i)
185+
zCoord = coords(3, i)
186+
162187
select case (currentType(i))
163188
case (iJx)
164189
nodeIdx = nodeIdx + 2
165-
call registerNode(Nodes, nodeIdx - 1, coords(1, i) , coords(2, i), coords(3, i) )
166-
call registerNode(Nodes, nodeIdx , coords(1, i) + 1, coords(2, i), coords(3, i) )
190+
if (usevtkindex) then
191+
call registerNode(Nodes, nodeIdx - 1, xCoord , yCoord, zCoord )
192+
call registerNode(Nodes, nodeIdx , xCoord + 1, yCoord, zCoord )
193+
else
194+
call registerNode(Nodes, nodeIdx - 1, realXGrid(xCoord) , realYGrid(yCoord), realZGrid(zCoord) )
195+
call registerNode(Nodes, nodeIdx , realXGrid(xCoord + 1), realYGrid(yCoord), realZGrid(zCoord) )
196+
endif
167197
edgeIdx = edgeIdx + 1
168198
call registerEdge(Edges, edgeIdx, nodeIdx - 1, nodeIdx)
169199

170200
case (iJy)
171201
nodeIdx = nodeIdx + 2
172-
call registerNode(Nodes, nodeIdx - 1, coords(1, i), coords(2, i) , coords(3, i) )
173-
call registerNode(Nodes, nodeIdx , coords(1, i), coords(2, i) + 1, coords(3, i) )
202+
if (usevtkindex) then
203+
call registerNode(Nodes, nodeIdx - 1, xCoord , yCoord , zCoord )
204+
call registerNode(Nodes, nodeIdx , xCoord , yCoord + 1, zCoord )
205+
else
206+
call registerNode(Nodes, nodeIdx - 1, realXGrid(xCoord) , realYGrid(yCoord) , realZGrid(zCoord) )
207+
call registerNode(Nodes, nodeIdx , realXGrid(xCoord) , realYGrid(yCoord + 1), realZGrid(zCoord) )
208+
endif
174209
edgeIdx = edgeIdx + 1
175210
call registerEdge(Edges, edgeIdx, nodeIdx - 1, nodeIdx)
176211

177212
case (iJz)
178213
nodeIdx = nodeIdx + 2
179-
call registerNode(Nodes, nodeIdx - 1, coords(1, i), coords(2, i) , coords(3, i) )
180-
call registerNode(Nodes, nodeIdx , coords(1, i), coords(2, i) , coords(3, i) + 1)
214+
if (usevtkindex) then
215+
call registerNode(Nodes, nodeIdx - 1, xCoord, yCoord , zCoord )
216+
call registerNode(Nodes, nodeIdx , xCoord, yCoord , zCoord + 1)
217+
else
218+
call registerNode(Nodes, nodeIdx - 1, realXGrid(xCoord) , realYGrid(yCoord) , realZGrid(zCoord) )
219+
call registerNode(Nodes, nodeIdx , realXGrid(xCoord) , realYGrid(yCoord) , realZGrid(zCoord + 1))
220+
endif
181221
edgeIdx = edgeIdx + 1
182222
call registerEdge(Edges, edgeIdx, nodeIdx - 1, nodeIdx)
183223

184224
case (iBloqueJx)
185225
nodeIdx = nodeIdx + 4
186-
call registerNode(Nodes, nodeIdx - 3, coords(1, i), coords(2, i) , coords(3, i) )
187-
call registerNode(Nodes, nodeIdx - 2, coords(1, i), coords(2, i) + 1, coords(3, i) )
188-
call registerNode(Nodes, nodeIdx - 1, coords(1, i), coords(2, i) + 1, coords(3, i) + 1)
189-
call registerNode(Nodes, nodeIdx , coords(1, i), coords(2, i) , coords(3, i) + 1)
226+
if (usevtkindex) then
227+
call registerNode(Nodes, nodeIdx - 3, xCoord, yCoord , zCoord )
228+
call registerNode(Nodes, nodeIdx - 2, xCoord, yCoord + 1, zCoord )
229+
call registerNode(Nodes, nodeIdx - 1, xCoord, yCoord + 1, zCoord + 1)
230+
call registerNode(Nodes, nodeIdx , xCoord, yCoord , zCoord + 1)
231+
else
232+
call registerNode(Nodes, nodeIdx - 3, realXGrid(xCoord), realYGrid(yCoord) , realZGrid(zCoord) )
233+
call registerNode(Nodes, nodeIdx - 2, realXGrid(xCoord), realYGrid(yCoord + 1), realZGrid(zCoord) )
234+
call registerNode(Nodes, nodeIdx - 1, realXGrid(xCoord), realYGrid(yCoord + 1), realZGrid(zCoord + 1))
235+
call registerNode(Nodes, nodeIdx , realXGrid(xCoord), realYGrid(yCoord) , realZGrid(zCoord + 1))
236+
endif
190237
quadIdx = quadIdx + 1
191238
call registerQuad(Quads, quadIdx, nodeIdx - 3, nodeIdx - 2, nodeIdx - 1, nodeIdx)
192239

193240
case (iBloqueJy)
194241
nodeIdx = nodeIdx + 4
195-
call registerNode(Nodes, nodeIdx - 3, coords(1, i) , coords(2, i), coords(3, i) )
196-
call registerNode(Nodes, nodeIdx - 2, coords(1, i) + 1, coords(2, i), coords(3, i) )
197-
call registerNode(Nodes, nodeIdx - 1, coords(1, i) + 1, coords(2, i), coords(3, i) + 1)
198-
call registerNode(Nodes, nodeIdx , coords(1, i) , coords(2, i), coords(3, i) + 1)
242+
if (usevtkindex) then
243+
call registerNode(Nodes, nodeIdx - 3, xCoord , yCoord, zCoord )
244+
call registerNode(Nodes, nodeIdx - 2, xCoord + 1, yCoord, zCoord )
245+
call registerNode(Nodes, nodeIdx - 1, xCoord + 1, yCoord, zCoord + 1)
246+
call registerNode(Nodes, nodeIdx , xCoord , yCoord, zCoord + 1)
247+
else
248+
call registerNode(Nodes, nodeIdx - 3, realXGrid(xCoord) , realYGrid(yCoord), realZGrid(zCoord) )
249+
call registerNode(Nodes, nodeIdx - 2, realXGrid(xCoord + 1), realYGrid(yCoord), realZGrid(zCoord) )
250+
call registerNode(Nodes, nodeIdx - 1, realXGrid(xCoord + 1), realYGrid(yCoord), realZGrid(zCoord + 1))
251+
call registerNode(Nodes, nodeIdx , realXGrid(xCoord) , realYGrid(yCoord), realZGrid(zCoord + 1))
252+
endif
199253
quadIdx = quadIdx + 1
200254
call registerQuad(Quads, quadIdx, nodeIdx - 3, nodeIdx - 2, nodeIdx - 1, nodeIdx)
201255

202256
case (iBloqueJz)
203257
nodeIdx = nodeIdx + 4
204-
call registerNode(Nodes, nodeIdx - 3, coords(1, i) , coords(2, i) , coords(3, i))
205-
call registerNode(Nodes, nodeIdx - 2, coords(1, i) + 1, coords(2, i) , coords(3, i))
206-
call registerNode(Nodes, nodeIdx - 1, coords(1, i) + 1, coords(2, i) + 1, coords(3, i))
207-
call registerNode(Nodes, nodeIdx , coords(1, i) , coords(2, i) + 1, coords(3, i))
258+
if (usevtkindex) then
259+
call registerNode(Nodes, nodeIdx - 3, xCoord , yCoord , zCoord)
260+
call registerNode(Nodes, nodeIdx - 2, xCoord + 1, yCoord , zCoord)
261+
call registerNode(Nodes, nodeIdx - 1, xCoord + 1, yCoord + 1, zCoord)
262+
call registerNode(Nodes, nodeIdx , xCoord , yCoord + 1, zCoord)
263+
else
264+
call registerNode(Nodes, nodeIdx - 3, realXGrid(xCoord) , realYGrid(yCoord) , realZGrid(zCoord))
265+
call registerNode(Nodes, nodeIdx - 2, realXGrid(xCoord + 1), realYGrid(yCoord) , realZGrid(zCoord))
266+
call registerNode(Nodes, nodeIdx - 1, realXGrid(xCoord + 1), realYGrid(yCoord + 1), realZGrid(zCoord))
267+
call registerNode(Nodes, nodeIdx , realXGrid(xCoord) , realYGrid(yCoord + 1), realZGrid(zCoord))
268+
endif
208269
quadIdx = quadIdx + 1
209270
call registerQuad(Quads, quadIdx, nodeIdx - 3, nodeIdx - 2, nodeIdx - 1, nodeIdx)
210271
end select

0 commit comments

Comments
 (0)