Skip to content

Commit

Permalink
add specific methods for boundary_index to prevent breaks in the code…
Browse files Browse the repository at this point in the history
…. To-do simplify this whole API thing!
  • Loading branch information
mberto79 committed Aug 30, 2024
1 parent d8161e8 commit 3302922
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
19 changes: 0 additions & 19 deletions src/Discretise/Discretise_4_assign_boundaries.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
export boundary_info, boundary_map
export assign, @assign!

struct boundary_info{I<:Integer, S<:Symbol}
ID::I
Name::S
end
Adapt.@adapt_structure boundary_info

# Create LUT to map boudnary names to indices
function boundary_map(mesh)
I = Integer; S = Symbol
boundary_map = boundary_info{I,S}[]

mesh_temp = adapt(CPU(), mesh) # WARNING: Temp solution

for (i, boundary) in enumerate(mesh_temp.boundaries)
push!(boundary_map, boundary_info{I,S}(i, boundary.name))
end

return boundary_map
end

# Assign function definition for vector field
assign(vec::VectorField, args...) = begin
Expand Down
10 changes: 0 additions & 10 deletions src/Mesh/BlockMesher2D/Mesh2D_5_access_functions.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
export x, y, z # access cell centres
export xf, yf, zf # access face centres
export boundary_index

function boundary_index(boundaries::Vector{Boundary{TI}}, name::Symbol) where {TI}
bci = zero(TI)
for i eachindex(boundaries)
bci += 1
if boundaries[i].name == name
return bci
end
end
end

function x(mesh::Mesh2{I,F}) where {I,F}
cells = mesh.cells
Expand Down
37 changes: 34 additions & 3 deletions src/Mesh/Mesh_1_functions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export _get_float, _get_int, _get_backend, _convert_array!
export boundary_info, boundary_map
export total_boundary_faces, boundary_index
export norm_static
export x, y, z # access cell centres
Expand Down Expand Up @@ -29,12 +30,42 @@ function total_boundary_faces(mesh::AbstractMesh)
end

# Extract bundary index based on set name
struct boundary_info{I<:Integer, S<:Symbol}
ID::I
Name::S
end
Adapt.@adapt_structure boundary_info

# Create LUT to map boudnary names to indices
function boundary_map(mesh)
I = Integer; S = Symbol
boundary_map = boundary_info{I,S}[]

mesh_temp = adapt(CPU(), mesh) # WARNING: Temp solution

for (i, boundary) in enumerate(mesh_temp.boundaries)
push!(boundary_map, boundary_info{I,S}(i, boundary.name))
end

return boundary_map
end

function boundary_index(
boundaries, name
)
boundaries::Vector{boundary_info{TI, S}}, name::S
) where{TI<:Integer,S<:Symbol}
for index in eachindex(boundaries)
if boundaries[index].Name == name
return boundaries[index].ID
end
end
end

function boundary_index(boundaries::Vector{Boundary{S, UR}}, name::S) where {S<:Symbol,UR}
# bci = zero(TI)
for index eachindex(boundaries)
# bci += 1
if boundaries[index].name == name
return index
return index
end
end
end
Expand Down

0 comments on commit 3302922

Please sign in to comment.