view test/Grids/multiblockgrids_test.jl @ 2020:7f7207b9bd6c feature/grids/multiblock_grids

Add constructor tests for 2d grids and using matrix for the grid collection
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 12 Mar 2025 10:48:58 +0100
parents fb2dc185c197
children d6618d628515
line wrap: on
line source

using Diffinitive.Grids
using StaticArrays

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

    @testset "Constructors" begin
        # Vector
        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()),
        ])

        @test MultiBlockGrid([g₁,g₂,g₃], C) isa Grid{Float64,1}
        @test MultiBlockGrid([g₁,g₂,g₃], C) isa MultiBlockGrid{Float64,1}


        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),
        ])

        @test MultiBlockGrid([g₁₁, g₁₂, g₂₁, g₂₂], C) isa MultiBlockGrid{SVector{2,Float64},2}

        # 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),
        ])

        @test MultiBlockGrid([g₁₁ g₁₂; g₂₁ g₂₂], C) isa MultiBlockGrid{SVector{2,Float64},2}

        # Dictionary
        @test MultiBlockGrid(Dict(:a=>g₁, :b=>g₂), [connection(:a, UpperBoundary(), :b, LowerBoundary())]) 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