Skip to content

Commit fd0b261

Browse files
Recover mapvtk funcionality from old observation module
1 parent 4f39216 commit fd0b261

File tree

4 files changed

+60
-33
lines changed

4 files changed

+60
-33
lines changed

src_output/mapVTKOutput.F90

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ subroutine store_relevant_coordinates(this, problemInfo)
7272
this%nPoints = counter
7373
call alloc_and_init(this%coords, 3, this%nPoints, -99)
7474
call alloc_and_init(this%materialTag, this%nPoints, -1)
75+
call alloc_and_init(this%currentType, this%nPoints, -1)
7576

7677
counter = 0
7778
do k = this%mainCoords%Z, this%auxCoords%Z
@@ -81,13 +82,13 @@ subroutine store_relevant_coordinates(this, problemInfo)
8182
if (isWithinBounds(Hfield, i, j, k, problemInfo)) then
8283
if (isMaterialExceptPML(Hfield, i, j, k, problemInfo)) then
8384
counter = counter + 1
84-
call writeFaceTagInfo(this, counter, i, j, k, problemInfo%materialTag%getFaceTag(Hfield, i, j, k))
85+
call writeFaceTagInfo(this, counter, i, j, k, Hfield, problemInfo%materialTag%getFaceTag(Hfield, i, j, k))
8586
end if
8687
if (problemInfo%materialTag%getFaceTag(Hfield, i, j, k) < 0 &
8788
.and. (btest(iabs(problemInfo%materialTag%getFaceTag(Hfield, i, j, k)), Hfield - 1)) &
8889
.and. .not. isPML(Hfield, i, j, k, problemInfo)) then
8990
counter = counter + 1
90-
call writeFaceTagInfo(this, counter, i, j, k, problemInfo%materialTag%getFaceTag(Hfield, i, j, k))
91+
call writeFaceTagInfo(this, counter, i, j, k, Hfield, problemInfo%materialTag%getFaceTag(Hfield, i, j, k))
9192
end if
9293
end if
9394
end do
@@ -103,12 +104,13 @@ logical function isMaterialExceptPML(field, i, j, k, problemInfo)
103104
isMaterialExceptPML = isMaterialExceptPML .and. (.not. isPML(field, i, j, k, problemInfo))
104105
end function isMaterialExceptPML
105106

106-
subroutine writeFaceTagInfo(this, counter, i, j, k, tag)
107+
subroutine writeFaceTagInfo(this, counter, i, j, k, field, tag)
107108
type(mapvtk_output_t), intent(inout) :: this
108-
integer, intent(in) :: i, j, k, counter, tag
109+
integer, intent(in) :: i, j, k, counter, tag, field
109110
this%coords(1, counter) = i
110111
this%coords(2, counter) = j
111112
this%coords(3, counter) = k
113+
this%currentType(counter) = currentType(field)
112114
this%materialTag(counter) = tag
113115
end subroutine
114116

@@ -135,29 +137,44 @@ subroutine create_geometry_simulation_vtu(this, control)
135137
vtuPath = join_path(this%path, get_last_component(this%path))//vtuFileExtension
136138

137139
call createUnstructuredDataForVTU(this%nPoints, this%coords, this%currentType, nodes, edges, quads, numNodes, numEdges, numQuads)
138-
call ugrid%add_points(nodes)
140+
call ugrid%add_points(real(nodes, 4))
139141

140142
allocate (conn(2*numEdges + 4*numQuads))
141143
conn(1:2*numEdges) = reshape(edges, [2*numEdges])
142144
conn(2*numEdges + 1:2*numEdges + 4*numQuads) = reshape(quads, [4*numQuads])
143145

144146
allocate (offsets(numEdges + numQuads))
145-
do i = 1, numEdges
146-
if (i == 1) then
147-
offsets(i) = 2
147+
do i = 1, numEdges + numQuads
148+
if (i <= numEdges) then
149+
if (i == 1) then
150+
offsets(i) = 2
151+
else
152+
offsets(i) = offsets(i-1) + 2
153+
end if
148154
else
149-
offsets(i) = offsets(i - 1) + 2
155+
if (i == 1) then
156+
offsets(i) = 4
157+
else
158+
offsets(i) = offsets(i-1) + 4
159+
end if
150160
end if
151161
end do
152-
do i = 1, numQuads
153-
offsets(numEdges + i) = offsets(numEdges + i - 1) + 4
154-
end do
155162

156163
allocate(types(numEdges+numQuads))
157164
types(1:numEdges) = 3
158165
types(numEdges+1:numEdges+numQuads) = 9
159166

160167
call ugrid%add_cell_connectivity(conn, offsets, types)
168+
if (size(offsets) /= numQuads) then
169+
print *, "Problema con offsets"
170+
end if
171+
if (size(types) /= numQuads) then
172+
print *, "Problema con types"
173+
end if
174+
if (offsets(numQuads) /= size(conn)) then
175+
print *, "Tenemos un problema con conn y offset"
176+
end if
177+
161178
call ugrid%write_file(vtuPath)
162179

163180
!---------------------------------------------

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_vtk(outputs(outputCount)%mapvtkOutput, problemInfo, control)
191+
call create_geometry_simulation_vtu(outputs(outputCount)%mapvtkOutput, control)
192192
!! call adjust_computation_range --- Required due to issues in mpi region edges
193193

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

src_output/outputUtils.F90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module mod_outputUtils
3131
public :: computeJ2
3232
public :: fieldo
3333
public :: create_data_file
34+
public :: currentType
3435
!===========================
3536

3637
!===========================
@@ -575,6 +576,19 @@ integer function u(field1, field2)
575576
end if
576577
end function
577578

579+
integer function currentType(field)
580+
integer(kind=4) :: field
581+
select case (field)
582+
case (iEx); currentType = iJx
583+
case (iEy); currentType = iJy
584+
case (iEz); currentType = iJz
585+
case (iHx); currentType = iBloqueJx
586+
case (iHy); currentType = iBloqueJy
587+
case (iHz); currentType = iBloqueJz
588+
case default; call StopOnError(0, 0, 'field is not a E or H field')
589+
end select
590+
end function
591+
578592
function get_field(field, i, j, k, fields_reference) result(res)
579593
implicit none
580594
real(kind=rkind) :: res

src_output/volumicProbeUtils.F90

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,47 +91,43 @@ subroutine createUnstructuredDataForVTU(counter, coords, currentType, Nodes, Edg
9191
real(kind=RKIND), allocatable, dimension(:, :), intent(out) :: Nodes
9292
integer(kind=4), allocatable, dimension(:, :), intent(out) :: Edges, Quads
9393

94-
if (counter /= 0) then
95-
Allocate (Nodes(3, counter))
96-
else
97-
return
98-
end if
94+
if (counter == 0) return
9995

10096
call countElements(counter, currentType, numEdges, numQuads)
10197

10298
allocate (Edges(2, numEdges))
10399
allocate (Quads(4, numQuads))
104-
allocate (Nodes(3, counter*(numEdges + numQuads)))
100+
allocate (Nodes(3, 2*numEdges + 4*numQuads))
105101

106102
call registerElements(counter, coords, currentType, Nodes, Edges, Quads)
107-
103+
return
108104
end subroutine
109105

110106
subroutine registerNode(nodes, nodeIx, x, y, z)
111107
real(kind=RKIND), dimension(:, :), intent(inout) :: nodes
112108
integer(kind=SINGLE), intent(in) :: nodeIx, x, y, z
113-
114-
nodes(1, nodeIx) = x*1.0_RKIND
115-
nodes(2, nodeIx) = y*1.0_RKIND
116-
nodes(3, nodeIx) = z*1.0_RKIND
109+
!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
117113
end subroutine
118114

119115
subroutine registerEdge(edges, edgeIdx, startNodeIdx, endNodeIdx)
120116
integer(kind=SINGLE), dimension(:, :), intent(inout) :: edges
121117
integer(kind=SINGLE), intent(in) :: edgeIdx, startNodeIdx, endNodeIdx
122118

123-
edges(1, edgeIdx) = startNodeIdx
124-
edges(2, edgeIdx) = endNodeIdx
119+
edges(1, edgeIdx + 1) = startNodeIdx
120+
edges(2, edgeIdx + 1) = endNodeIdx
125121
end subroutine
126122

127123
subroutine registerQuad(quads, quadIdx, firstNodeIdx, secondNodeIdx, thirdNodeIdx, fourthNodeIdx)
128124
integer(kind=SINGLE), dimension(:, :), intent(inout) :: quads
129125
integer(kind=SINGLE), intent(in) :: quadIdx, firstNodeIdx, secondNodeIdx, thirdNodeIdx, fourthNodeIdx
130126

131-
quads(1, quadIdx) = firstNodeIdx
132-
quads(2, quadIdx) = secondNodeIdx
133-
quads(2, quadIdx) = thirdNodeIdx
134-
quads(2, quadIdx) = fourthNodeIdx
127+
quads(1, quadIdx + 1) = firstNodeIdx
128+
quads(2, quadIdx + 1) = secondNodeIdx
129+
quads(3, quadIdx + 1) = thirdNodeIdx
130+
quads(4, quadIdx + 1) = fourthNodeIdx
135131
end subroutine
136132

137133
subroutine countElements(counter, currentType, numEdges, numQuads)
@@ -158,9 +154,9 @@ subroutine registerElements(counter, coords, currentType, Nodes, Edges, Quads)
158154
integer :: nodeIdx, quadIdx, edgeIdx
159155
integer :: i
160156

161-
nodeIdx = 0
162-
quadIdx = 0
163-
edgeIdx = 0
157+
nodeIdx = -1
158+
quadIdx = -1
159+
edgeIdx = -1
164160

165161
do i = 1, counter
166162
select case (currentType(i))

0 commit comments

Comments
 (0)