-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
197 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Test | ||
using IntervalSets | ||
import Random: seed! | ||
import LinearAlgebra: Tridiagonal, norm | ||
import ClimaComms | ||
import ClimaCore: | ||
Geometry, Domains, Meshes, Topologies, Spaces, Fields, Operators | ||
|
||
include("schur_complement_W.jl") | ||
|
||
function test_thomas_algorithm(::Type{FT}) where {FT} | ||
comms_ctx = ClimaComms.SingletonCommsContext() | ||
@info "Testing Thomas Algorithm on a $(comms_ctx.device) with \ | ||
$(ClimaComms.nprocs(comms_ctx)) processes and eltype $FT" | ||
|
||
domain_z = Domains.IntervalDomain( | ||
Geometry.ZPoint(FT(1)) .. Geometry.ZPoint(FT(2)), | ||
periodic = true, | ||
) | ||
mesh_z = Meshes.IntervalMesh(domain_z; nelems = 10) | ||
topology_z = Topologies.IntervalTopology(comms_ctx, mesh_z) | ||
|
||
domain_xy = Domains.RectangleDomain( | ||
Geometry.XPoint(FT(1)) .. Geometry.XPoint(FT(2)), | ||
Geometry.YPoint(FT(1)) .. Geometry.YPoint(FT(2)), | ||
x1periodic = true, | ||
x2periodic = true, | ||
) | ||
mesh_xy = Meshes.RectilinearMesh(domain_xy, 10, 10) | ||
topology_xy = Topologies.Topology2D(comms_ctx, mesh_xy) | ||
|
||
quad = Spaces.Quadratures.GLL{4}() | ||
|
||
space_vf = Spaces.CenterFiniteDifferenceSpace(topology_z) | ||
space_ijfh = Spaces.SpectralElementSpace2D(topology_xy, quad) | ||
space_vijfh = Spaces.ExtrudedFiniteDifferenceSpace(space_ijfh, space_vf) | ||
|
||
coords = Fields.coordinate_field(space_vijfh) | ||
|
||
seed!(1) # ensure reproducibility | ||
A = map(coords) do _ | ||
diagonal_coef = FT(4) + rand(FT) / 10 | ||
off_diagonal_coef = FT(1) + rand(FT) / 10 | ||
Operators.StencilCoefs{-1, 1}(( | ||
off_diagonal_coef, | ||
diagonal_coef, | ||
off_diagonal_coef, | ||
),) | ||
end | ||
b = map(_ -> rand(FT), coords) | ||
b ./= norm(b) | ||
|
||
A_copy = copy(A) | ||
b_copy = copy(b) | ||
|
||
column_thomas_solve!(comms_ctx.device, A, b) | ||
|
||
Ni, Nj, _, _, Nh = size(Spaces.local_geometry_data(space_vijfh)) | ||
for h in 1:Nh, j in 1:Nj, i in 1:Ni | ||
A_array_data = Array(parent(Spaces.column(A_copy, i, j, h))) | ||
A_array = Tridiagonal( | ||
@view(A_array_data[2:end, 1]), | ||
@view(A_array_data[1:end, 2]), | ||
@view(A_array_data[1:(end - 1), 3]), | ||
) | ||
b_array = Array(vec(parent(Spaces.column(b_copy, i, j, h)))) | ||
x_array_exact = A_array \ b_array | ||
x_array_computed = Array(vec(parent(Spaces.column(b, i, j, h)))) | ||
|
||
@test norm(x_array_computed .- x_array_exact) / norm(x_array_exact) < | ||
2 * eps(FT) | ||
end | ||
end | ||
|
||
@testset "Thomas algorithm tests for Float32 and Float64" begin | ||
FT = Float64 | ||
for FT in (Float32, Float64) | ||
test_thomas_algorithm(FT) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters