view test/Grids/multiblockgrids_test.jl @ 2021:d6618d628515 feature/grids/multiblock_grids

Factor out functions for creating different types of multiblock grids in the tests
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 12 Mar 2025 10:54:47 +0100
parents 7f7207b9bd6c
children 7f04753ead30
line wrap: on
line source

using Diffinitive.Grids
using StaticArrays


function multiblockgrid1d()
    g₁ = equidistant_grid(0,1,5)
    g₂ = equidistant_grid(0,1,5)
    g₃ = equidistant_grid(0,1,5)

    C = connection.([
        (1, UpperBoundary(), 2, LowerBoundary()),
        (2, UpperBoundary(), 3, LowerBoundary()),
    ])

    return MultiBlockGrid([g₁,g₂,g₃], C)
end

function multiblockgrid2d()
    g₁₁ = equidistant_grid((0,0),(1,1),5,5)
    g₁₂ = equidistant_grid((0,0),(1,1),5,5)
    g₂₁ = equidistant_grid((0,0),(1,1),5,5)
    g₂₂ = equidistant_grid((0,0),(1,1),5,5)

    C = map(((i1,d1,b1,i2,d2,b2),)->connection(i1,CartesianBoundary{d1,b1}(), i2, CartesianBoundary{d2,b2}()),[
        (1, 1, UpperBoundary, 2, 1, LowerBoundary),
        (3, 1, UpperBoundary, 4, 1, LowerBoundary),
        (1, 2, UpperBoundary, 3, 2, LowerBoundary),
        (2, 2, UpperBoundary, 4, 2, LowerBoundary),
    ])

    return MultiBlockGrid([g₁₁, g₁₂, g₂₁, g₂₂], C)
end

function multiblockgrid_matrix()
    g₁₁ = equidistant_grid((0,0),(1,1),5,5)
    g₁₂ = equidistant_grid((0,0),(1,1),5,5)
    g₂₁ = equidistant_grid((0,0),(1,1),5,5)
    g₂₂ = equidistant_grid((0,0),(1,1),5,5)

    C = map(((i1,d1,b1,i2,d2,b2),)->connection(CartesianIndex(i1),CartesianBoundary{d1,b1}(), CartesianIndex(i2), CartesianBoundary{d2,b2}()),[
        ((1,1), 1, UpperBoundary, (1,2), 1, LowerBoundary),
        ((2,1), 1, UpperBoundary, (2,2), 1, LowerBoundary),
        ((1,1), 2, UpperBoundary, (1,2), 2, LowerBoundary),
        ((2,1), 2, UpperBoundary, (2,2), 2, LowerBoundary),
    ])

    return MultiBlockGrid([g₁₁ g₁₂; g₂₁ g₂₂], C)
end

function multiblockgrid_dict()
    g₁ = equidistant_grid(0,1,5)
    g₂ = equidistant_grid(0,1,5)

    C = [connection(:a, UpperBoundary(), :b, LowerBoundary())]
    MultiBlockGrid(Dict(:a=>g₁, :b=>g₂), C)
end

@testset "MultiBlockGrid" begin
    @test MultiBlockGrid <: Grid

    @testset "Constructors" begin
        @test multiblockgrid1d() isa Grid{Float64,1}
        @test multiblockgrid1d() isa MultiBlockGrid{Float64,1}
        @test multiblockgrid2d() isa MultiBlockGrid{SVector{2,Float64},2}
        @test multiblockgrid_matrix() isa MultiBlockGrid{SVector{2,Float64},2}
        @test multiblockgrid_dict() isa MultiBlockGrid{Float64,1}
    end

    @testset "Base.getindex" begin
        @test_broken false
    end

    @testset "boundary_identifiers" begin
        @test_broken false
    end

    @testset "boundary_grid" begin
        @test_broken false
    end

    @testset "min_spacing" begin
        @test_broken false
    end

    @testset "refine" begin
        @test_broken false
    end

    @testset "coarsen" begin
        @test_broken false
    end

    @testset "boundary_indices" begin
        @test_broken false
    end

    @testset "eval_on" begin
        @test_broken false
    end

    @testset "Base.map" begin
        @test_broken false
    end
end


@testset "MultiBlockBoundary" begin
    @test MultiBlockBoundary{1,UpperBoundary}() isa BoundaryIdentifier

    @test grid_id(MultiBlockBoundary{1,UpperBoundary}()) == 1

    @test boundary_id(MultiBlockBoundary{1,UpperBoundary}()) == UpperBoundary()
end

@testset "connection" begin
    @test connection(1, UpperBoundary(), 2, LowerBoundary()) == (MultiBlockBoundary{1,UpperBoundary}(), MultiBlockBoundary{2,LowerBoundary}())
    @test connection(:a, UpperBoundary(), :b, LowerBoundary()) == (MultiBlockBoundary{:a,UpperBoundary}(), MultiBlockBoundary{:b,LowerBoundary}())
    @test connection((1, UpperBoundary(), 2, LowerBoundary())) == (MultiBlockBoundary{1,UpperBoundary}(), MultiBlockBoundary{2,LowerBoundary}())

    @test_throws Exception connection(1, UpperBoundary, 2, LowerBoundary())
    @test_throws Exception connection(1, UpperBoundary(), 2, LowerBoundary)
end