-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1788 from CliMA/dy/field_matrix_wrapper
Add wrapper for FieldMatrix and FieldMatrixSolver
- Loading branch information
Showing
6 changed files
with
75 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "ClimaCore" | ||
uuid = "d414da3d-4745-48bb-8d80-42e94e092884" | ||
authors = ["CliMA Contributors <[email protected]>"] | ||
version = "0.14.7" | ||
version = "0.14.8" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
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,48 @@ | ||
""" | ||
FieldMatrixWithSolver(A, b, [alg]) | ||
A wrapper that combines a `FieldMatrix` `A` with a `FieldMatrixSolver` that can | ||
be used to solve the equation `A * x = b` for `x`, where `x` and `b` are both | ||
`FieldVector`s. Similar to a `LinearAlgebra.Factorization`, this wrapper can be | ||
passed to `ldiv!`, whereas a regular `FieldMatrix` cannot be passed to `ldiv!`. | ||
By default, the `FieldMatrixSolverAlgorithm` `alg` is set to a | ||
[`BlockDiagonalSolve`](@ref), so a custom `alg` must be specified when `A` is | ||
not a block diagonal matrix. | ||
""" | ||
struct FieldMatrixWithSolver{M, S} <: AbstractDict{FieldNamePair, Any} | ||
matrix::M | ||
solver::S | ||
end | ||
FieldMatrixWithSolver( | ||
A::FieldMatrix, | ||
b::Fields.FieldVector, | ||
alg::FieldMatrixSolverAlgorithm = BlockDiagonalSolve(), | ||
) = FieldMatrixWithSolver(A, FieldMatrixSolver(alg, A, b)) | ||
|
||
# TODO: Find a simple way to make b an optional argument and add a method for | ||
# Base.one(::FieldMatrixWithSolver). | ||
|
||
Base.keys(A::FieldMatrixWithSolver) = keys(A.matrix) | ||
|
||
Base.values(A::FieldMatrixWithSolver) = values(A.matrix) | ||
|
||
Base.pairs(A::FieldMatrixWithSolver) = pairs(A.matrix) | ||
|
||
Base.length(A::FieldMatrixWithSolver) = length(A.matrix) | ||
|
||
Base.iterate(A::FieldMatrixWithSolver, index = 1) = iterate(A.matrix, index) | ||
|
||
Base.getindex(A::FieldMatrixWithSolver, key) = getindex(A.matrix, key) | ||
|
||
Base.:(==)(A1::FieldMatrixWithSolver, A2::FieldMatrixWithSolver) = | ||
A1.matrix == A2.matrix && A1.solver.alg == A2.solver.alg | ||
|
||
Base.similar(A::FieldMatrixWithSolver) = | ||
FieldMatrixWithSolver(similar(A.matrix), A.solver) | ||
|
||
ldiv!(x::Fields.FieldVector, A::FieldMatrixWithSolver, b::Fields.FieldVector) = | ||
field_matrix_solve!(A.solver, x, A.matrix, b) | ||
|
||
mul!(b::Fields.FieldVector, A::FieldMatrixWithSolver, x::Fields.FieldVector) = | ||
@. b = A.matrix * x |
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
9bb1a73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
9bb1a73
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/108688
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: