|
| 1 | + |
| 2 | +function update_new_edges!(geo::Post2D, new_ablation_point_idx::Vector{Int}) |
| 3 | + |
| 4 | + new_ablation_elements = Vector{Vector{Int}}() |
| 5 | + for i in new_ablation_point_idx |
| 6 | + mesh_id = geo.pd_id_to_surface[i] |
| 7 | + push!(new_ablation_elements, geo.surface_elements[mesh_id]) |
| 8 | + end |
| 9 | + |
| 10 | + for (i, elem) in enumerate(new_ablation_elements) |
| 11 | + pd_id = new_ablation_point_idx[i] |
| 12 | + cell_type = geo.element_type[geo.pd_id_to_surface[pd_id]] |
| 13 | + remove_element!(geo.bc_counter, elem, cell_type, pd_id) |
| 14 | + end |
| 15 | + |
| 16 | + boundary_keys = get_boundary(geo.bc_counter) |
| 17 | + |
| 18 | + new_bc_edges = Dict{Int, Vector{Vector{Vector{Float64}}}}() |
| 19 | + |
| 20 | + for (face, pd_id) in boundary_keys |
| 21 | + coords = [geo.mesh_nodes[n] for n in face] |
| 22 | + if haskey(new_bc_edges, pd_id) |
| 23 | + push!(new_bc_edges[pd_id], coords) |
| 24 | + else |
| 25 | + new_bc_edges[pd_id] = [coords] |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + geo.bc_edge = new_bc_edges |
| 30 | +end |
| 31 | + |
| 32 | +function update_new_edges!(geo::Post3D, new_ablation_point_idx::Vector{Int}) |
| 33 | + |
| 34 | + new_ablation_elements = Vector{Vector{Int}}() |
| 35 | + for i in new_ablation_point_idx |
| 36 | + mesh_id = geo.pd_id_to_volume[i] |
| 37 | + push!(new_ablation_elements, geo.volume_elements[mesh_id]) |
| 38 | + end |
| 39 | + |
| 40 | + for (i, elem) in enumerate(new_ablation_elements) |
| 41 | + pd_id = new_ablation_point_idx[i] |
| 42 | + cell_type = geo.element_type[geo.pd_id_to_volume[pd_id]] |
| 43 | + remove_element!(geo.bc_counter, elem, cell_type, pd_id) |
| 44 | + end |
| 45 | + |
| 46 | + boundary_keys = get_boundary(geo.bc_counter) |
| 47 | + |
| 48 | + new_bc_surfaces = Dict{Int, Vector{Vector{Vector{Float64}}}}() |
| 49 | + |
| 50 | + for (face, pd_id) in boundary_keys |
| 51 | + coords = [geo.mesh_nodes[n] for n in face] |
| 52 | + if haskey(new_bc_surfaces, pd_id) |
| 53 | + push!(new_bc_surfaces[pd_id], coords) |
| 54 | + else |
| 55 | + new_bc_surfaces[pd_id] = [coords] |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + geo.bc_surface = new_bc_surfaces |
| 60 | +end |
| 61 | + |
| 62 | +function save_bc_edges_vtk(geo::Post2D, root::String, step::Int, Δt::Float64; pvd_name="bc_edges.pvd") |
| 63 | + |
| 64 | + mkpath(root) |
| 65 | + new_bc_edges = geo.bc_edge |
| 66 | + vtkfile = joinpath(root, "bc_edges_" * lpad(string(step), 4, '0') * ".vtk") |
| 67 | + |
| 68 | + all_points = Vector{Vector{Float64}}() |
| 69 | + polylines = Vector{Vector{Int}}() |
| 70 | + polyline_bc_ids = Vector{Int}() |
| 71 | + |
| 72 | + point_count = 0 |
| 73 | + for (bc_id, edges) in new_bc_edges |
| 74 | + for edge_points in edges |
| 75 | + if length(edge_points) >= 2 |
| 76 | + edge_indices = Vector{Int}() |
| 77 | + for point in edge_points |
| 78 | + push!(all_points, point) |
| 79 | + push!(edge_indices, point_count) |
| 80 | + point_count += 1 |
| 81 | + end |
| 82 | + push!(polylines, edge_indices) |
| 83 | + push!(polyline_bc_ids, bc_id) |
| 84 | + end |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + open(vtkfile, "w") do io |
| 89 | + println(io, "# vtk DataFile Version 3.0") |
| 90 | + println(io, "BC Edges step=$step, time=$(step*Δt)") |
| 91 | + println(io, "ASCII") |
| 92 | + println(io, "DATASET POLYDATA") |
| 93 | + |
| 94 | + # Points |
| 95 | + println(io, "POINTS $(length(all_points)) float") |
| 96 | + for point in all_points |
| 97 | + if length(point) == 2 |
| 98 | + println(io, "$(point[1]) $(point[2]) 0.0") |
| 99 | + else |
| 100 | + println(io, "$(point[1]) $(point[2]) $(point[3])") |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + # Lines |
| 105 | + total_size = sum(length(poly) + 1 for poly in polylines) |
| 106 | + println(io, "LINES $(length(polylines)) $total_size") |
| 107 | + for poly in polylines |
| 108 | + print(io, "$(length(poly))") |
| 109 | + for idx in poly |
| 110 | + print(io, " $idx") |
| 111 | + end |
| 112 | + println(io) |
| 113 | + end |
| 114 | + |
| 115 | + # Cell data |
| 116 | + println(io, "CELL_DATA $(length(polylines))") |
| 117 | + println(io, "SCALARS bc_id int 1") |
| 118 | + println(io, "LOOKUP_TABLE default") |
| 119 | + for bc_id in polyline_bc_ids |
| 120 | + println(io, bc_id) |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + pvdfile = joinpath(root, pvd_name) |
| 125 | + current_time = step * Δt |
| 126 | + |
| 127 | + if step == 0 || !isfile(pvdfile) |
| 128 | + open(pvdfile, "w") do io |
| 129 | + println(io, """<VTKFile type="Collection" version="0.1" byte_order="LittleEndian">""") |
| 130 | + println(io, " <Collection>") |
| 131 | + println(io, " <DataSet timestep=\"" * |
| 132 | + string(round(current_time, digits=6)) * |
| 133 | + "\" group=\"\" part=\"0\" file=\"" * |
| 134 | + basename(vtkfile) * "\"/>") |
| 135 | + println(io, " </Collection>") |
| 136 | + println(io, "</VTKFile>") |
| 137 | + end |
| 138 | + else |
| 139 | + lines = readlines(pvdfile) |
| 140 | + insert!(lines, length(lines)-1, |
| 141 | + " <DataSet timestep=\"" * |
| 142 | + string(round(current_time, digits=6)) * |
| 143 | + "\" group=\"\" part=\"0\" file=\"" * |
| 144 | + basename(vtkfile) * "\"/>") |
| 145 | + open(pvdfile, "w") do io |
| 146 | + for l in lines |
| 147 | + println(io, l) |
| 148 | + end |
| 149 | + end |
| 150 | + end |
| 151 | + |
| 152 | + return vtkfile |
| 153 | +end |
| 154 | + |
| 155 | +function save_bc_edges_vtk(geo::Post3D, root::String, step::Int, Δt::Float64; pvd_name="bc_surfaces.pvd") |
| 156 | + |
| 157 | + mkpath(root) |
| 158 | + new_bc_edges = geo.bc_surface |
| 159 | + vtkfile = joinpath(root, "bc_surfaces_" * lpad(string(step), 4, '0') * ".vtk") |
| 160 | + |
| 161 | + all_points = Vector{Vector{Float64}}() |
| 162 | + polylines = Vector{Vector{Int}}() |
| 163 | + polyline_bc_ids = Vector{Int}() |
| 164 | + |
| 165 | + point_count = 0 |
| 166 | + for (bc_id, edges) in new_bc_edges |
| 167 | + for edge_points in edges |
| 168 | + if length(edge_points) >= 2 |
| 169 | + edge_indices = Vector{Int}() |
| 170 | + for point in edge_points |
| 171 | + push!(all_points, point) |
| 172 | + push!(edge_indices, point_count) |
| 173 | + point_count += 1 |
| 174 | + end |
| 175 | + push!(polylines, edge_indices) |
| 176 | + push!(polyline_bc_ids, bc_id) |
| 177 | + end |
| 178 | + end |
| 179 | + end |
| 180 | + |
| 181 | + open(vtkfile, "w") do io |
| 182 | + println(io, "# vtk DataFile Version 3.0") |
| 183 | + println(io, "BC Edges step=$step, time=$(step*Δt)") |
| 184 | + println(io, "ASCII") |
| 185 | + println(io, "DATASET POLYDATA") |
| 186 | + |
| 187 | + # Points |
| 188 | + println(io, "POINTS $(length(all_points)) float") |
| 189 | + for point in all_points |
| 190 | + if length(point) == 2 |
| 191 | + println(io, "$(point[1]) $(point[2]) 0.0") |
| 192 | + else |
| 193 | + println(io, "$(point[1]) $(point[2]) $(point[3])") |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + # Lines |
| 198 | + total_size = sum(length(poly) + 1 for poly in polylines) |
| 199 | + println(io, "LINES $(length(polylines)) $total_size") |
| 200 | + for poly in polylines |
| 201 | + print(io, "$(length(poly))") |
| 202 | + for idx in poly |
| 203 | + print(io, " $idx") |
| 204 | + end |
| 205 | + println(io) |
| 206 | + end |
| 207 | + |
| 208 | + # Cell data |
| 209 | + println(io, "CELL_DATA $(length(polylines))") |
| 210 | + println(io, "SCALARS bc_id int 1") |
| 211 | + println(io, "LOOKUP_TABLE default") |
| 212 | + for bc_id in polyline_bc_ids |
| 213 | + println(io, bc_id) |
| 214 | + end |
| 215 | + end |
| 216 | + |
| 217 | + pvdfile = joinpath(root, pvd_name) |
| 218 | + current_time = step * Δt |
| 219 | + |
| 220 | + if step == 0 || !isfile(pvdfile) |
| 221 | + open(pvdfile, "w") do io |
| 222 | + println(io, """<VTKFile type="Collection" version="0.1" byte_order="LittleEndian">""") |
| 223 | + println(io, " <Collection>") |
| 224 | + println(io, " <DataSet timestep=\"" * |
| 225 | + string(round(current_time, digits=6)) * |
| 226 | + "\" group=\"\" part=\"0\" file=\"" * |
| 227 | + basename(vtkfile) * "\"/>") |
| 228 | + println(io, " </Collection>") |
| 229 | + println(io, "</VTKFile>") |
| 230 | + end |
| 231 | + else |
| 232 | + lines = readlines(pvdfile) |
| 233 | + insert!(lines, length(lines)-1, |
| 234 | + " <DataSet timestep=\"" * |
| 235 | + string(round(current_time, digits=6)) * |
| 236 | + "\" group=\"\" part=\"0\" file=\"" * |
| 237 | + basename(vtkfile) * "\"/>") |
| 238 | + open(pvdfile, "w") do io |
| 239 | + for l in lines |
| 240 | + println(io, l) |
| 241 | + end |
| 242 | + end |
| 243 | + end |
| 244 | + |
| 245 | + return vtkfile |
| 246 | +end |
| 247 | + |
0 commit comments