view src/Grids/multiblockgrids.jl @ 2028:06f4b2ab43e8 feature/grids/multiblock_grids

Implement boundary_grid
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 11 Apr 2025 15:58:17 +0200
parents 1b6f150d95c5
children
line wrap: on
line source

struct MultiBlockGrid{T,D,GT, CT} <: Grid{T,D}
    grids::GT
    connections::CT
end

function MultiBlockGrid(grids, connections)
    T = eltype(valtype(grids))
    D = ndims(valtype(grids))

    MultiBlockGrid{T,D,typeof(grids), typeof(connections)}(grids,connections)
end

grids(g::MultiBlockGrid) = g.grids
connections(g::MultiBlockGrid) = g.connections

Base.getindex(g::MultiBlockGrid, I...) = g.grids[I...]

min_spacing(g::MultiBlockGrid) = minimum(min_spacing, grids(g))

function refine(g::MultiBlockGrid, n)
    gs = map(grids(g)) do gᵢ
        refine(gᵢ,n)
    end

    return MultiBlockGrid(gs, connections(g))
end

function coarsen(g::MultiBlockGrid, n)
    gs = map(grids(g)) do gᵢ
        coarsen(gᵢ,n)
    end

    return MultiBlockGrid(gs, connections(g))
end


"""
    MultiBlockBoundary{N, BID} <: BoundaryIdentifier

A boundary identifier for a multiblock grids. `N` Specifies which grid and
`BID` which boundary on that grid.
"""
struct MultiBlockBoundary{N, BID} <: BoundaryIdentifier end
grid_id(::MultiBlockBoundary{N, BID}) where {N, BID} = N
boundary_id(::MultiBlockBoundary{N, BID}) where {N, BID} = BID()


function connection(k1, b1::BoundaryIdentifier, k2, b2::BoundaryIdentifier)
    return (
        MultiBlockBoundary{k1,typeof(b1)}(),
        MultiBlockBoundary{k2,typeof(b2)}(),
    )
end

connection(t::Tuple) = connection(t...)

# function boundary_identifiers end # Requires function from manifolds?

function boundary_grid(g::MultiBlockGrid, bId::MultiBlockBoundary)
    return boundary_grid(grids(g)[grid_id(bId)], boundary_id(bId))
end

# function boundary_indices end # Need to figure out the grid functions first?
# function eval_on end # Need to figure out the grid functions first?
# function Base.map end # Need to figure out the grid functions first? Should only have to implement the iterator interface

# Plotting recipes


# Nested indices??
# motsvarande eachindex
# Kolla notebooks med experiment
# IteratorSize
# nogot slags shape?