-
Notifications
You must be signed in to change notification settings - Fork 279
[Core][Future] Add linear operators #14110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rubenzorrilla
wants to merge
14
commits into
master
Choose a base branch
from
core/future-add-linear-operators
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+704
−0
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
39d5e0f
Add linear algebra defines
rubenzorrilla 94fc666
Test
rubenzorrilla e4f1d55
Matrix-free and CSR linear operators
rubenzorrilla 7e6f002
Merge branch 'core/future-add-linear-algebra-defines' into core/futur…
rubenzorrilla f84198f
Replace linear operators
rubenzorrilla 44fae39
Minors and Python exposure
rubenzorrilla 48fcd7c
@matekelemen's suggestions
rubenzorrilla 0b517da
@matekelemen's suggestion
rubenzorrilla 4a94fbb
Merge branch 'core/future-add-linear-algebra-defines' into core/futur…
rubenzorrilla 7aa2d3f
Rename to traits
rubenzorrilla b897a37
Minor
rubenzorrilla c838f4f
Merging w/ main branch
rubenzorrilla ab386f5
Merge branch 'core/future-add-linear-algebra-defines' into core/futur…
rubenzorrilla 63dc39c
Removing leftover include
rubenzorrilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,49 @@ | ||
| // | / | | ||
| // ' / __| _` | __| _ \ __| | ||
| // . \ | ( | | ( |\__ ` | ||
| // _|\_\_| \__,_|\__|\___/ ____/ | ||
| // Multi-Physics | ||
| // | ||
| // License: BSD License | ||
| // Kratos default license: kratos/license.txt | ||
| // | ||
| // Main authors: Ruben Zorrilla | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| // System includes | ||
|
|
||
| // External includes | ||
|
|
||
| // Project includes | ||
| #include "containers/distributed_csr_matrix.h" | ||
| #include "containers/distributed_sparse_graph.h" | ||
| #include "containers/distributed_system_vector.h" | ||
|
|
||
| namespace Kratos::Future | ||
| { | ||
|
|
||
| ///@addtogroup KratosCore | ||
| ///@{ | ||
|
|
||
| ///@name Kratos Classes | ||
| ///@{ | ||
|
|
||
| struct DistributedLinearAlgebraTraits | ||
| { | ||
| using DataType = double; | ||
|
|
||
| using IndexType = std::size_t; | ||
|
|
||
| using MatrixType = DistributedCsrMatrix<DataType, IndexType>; | ||
|
|
||
| using VectorType = DistributedSystemVector<DataType, IndexType>; | ||
|
|
||
| using SparseGraphType = DistributedSparseGraph<IndexType>; | ||
| }; | ||
|
|
||
| ///@} | ||
| ///@} addtogroup block | ||
|
|
||
| } // namespace Kratos::Future |
This file contains hidden or 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,51 @@ | ||
| // | / | | ||
| // ' / __| _` | __| _ \ __| | ||
| // . \ | ( | | ( |\__ ` | ||
| // _|\_\_| \__,_|\__|\___/ ____/ | ||
| // Multi-Physics | ||
| // | ||
| // License: BSD License | ||
| // Kratos default license: kratos/license.txt | ||
| // | ||
| // Main authors: Ruben Zorrilla | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| // System includes | ||
|
|
||
| // External includes | ||
|
|
||
| // Project includes | ||
| #include "containers/csr_matrix.h" | ||
| #include "containers/sparse_contiguous_row_graph.h" | ||
| #include "containers/system_vector.h" | ||
|
|
||
| namespace Kratos::Future | ||
| { | ||
|
|
||
| ///@addtogroup KratosCore | ||
| ///@{ | ||
|
|
||
| ///@name Kratos Classes | ||
| ///@{ | ||
|
|
||
| struct SerialLinearAlgebraTraits | ||
| { | ||
| using DataType = double; | ||
|
|
||
| using IndexType = std::size_t; | ||
|
|
||
| using MatrixType = CsrMatrix<DataType, IndexType>; | ||
|
|
||
| using VectorType = SystemVector<DataType, IndexType>; | ||
|
|
||
| using DenseMatrixType = DenseMatrix<DataType>; //TODO: think about this one | ||
|
|
||
| using SparseGraphType = SparseContiguousRowGraph<IndexType>; | ||
| }; | ||
|
|
||
| ///@} | ||
| ///@} addtogroup block | ||
|
|
||
| } // namespace Kratos::Future |
This file contains hidden or 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,227 @@ | ||
| // | / | | ||
| // ' / __| _` | __| _ \ __| | ||
| // . \ | ( | | ( |\__ ` | ||
| // _|\_\_| \__,_|\__|\___/ ____/ | ||
| // Multi-Physics | ||
| // | ||
| // License: BSD License | ||
| // Kratos default license: kratos/license.txt | ||
| // | ||
| // Main authors: Ruben Zorrilla | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| // System includes | ||
|
|
||
| // External includes | ||
|
|
||
| // Project includes | ||
| #include "includes/model_part.h" | ||
|
|
||
| namespace Kratos::Future | ||
| { | ||
|
|
||
| ///@addtogroup KratosCore | ||
| ///@{ | ||
|
|
||
| ///@name Kratos Classes | ||
| ///@{ | ||
|
|
||
| /** | ||
| * @brief | ||
| * @class LinearOperator | ||
| * @ingroup KratosCore | ||
| * @brief Auxiliary container to store a linear operator | ||
| * @details | ||
| * This class implements a generic linear operator interface to be used | ||
| * in matrix-free algorithms. Being a generic interface, it can be derived | ||
| * to wrap different types of linear operators, including maxtrix-based ones. | ||
| * @tparam TLinearAlgebra The struct containing the linear algebra types | ||
| */ | ||
| template <class TLinearAlgebra> | ||
| class LinearOperator | ||
| { | ||
|
|
||
| public: | ||
| ///@name Type Definitions | ||
| ///@{ | ||
|
|
||
| /// Pointer definition of LinearOperator | ||
| KRATOS_CLASS_POINTER_DEFINITION(LinearOperator); | ||
|
|
||
| /// Vector type definition from template parameter | ||
| using VectorType = typename TLinearAlgebra::VectorType; | ||
|
|
||
| /// Matrix type definition from template parameter | ||
| using MatrixType = typename TLinearAlgebra::MatrixType; | ||
|
|
||
| /// Data type stored in the system vector | ||
| using DataType = typename VectorType::DataType; | ||
|
|
||
| /// Index type used in the system vector | ||
| using IndexType = typename VectorType::IndexType; | ||
|
|
||
| ///@} | ||
| ///@name Life Cycle | ||
| ///@{ | ||
|
|
||
| /** | ||
| * @brief Default constructor. | ||
| * @details Creates an empty LinearOperator with uninitialized function objects. | ||
| */ | ||
| LinearOperator() = default; | ||
|
|
||
| /** | ||
| * @brief Constructor from parameters. | ||
| * @param ThisParameters Parameters containing the linear operator settings | ||
| */ | ||
| LinearOperator(Parameters ThisParameters) | ||
| { | ||
| mNumRows = ThisParameters["num_rows"].GetInt(); | ||
| mNumCols = ThisParameters["num_cols"].GetInt(); | ||
| } | ||
|
|
||
| /// Deleted copy constructor (non-copyable) | ||
| LinearOperator(const LinearOperator& rOther) = delete; | ||
|
|
||
| /// Defaulted move constructor | ||
| LinearOperator(LinearOperator&& rOther) = default; | ||
|
|
||
| /// Default destructor | ||
| virtual ~LinearOperator() = default; | ||
|
|
||
| ///@} | ||
| ///@name Operators | ||
| ///@{ | ||
|
|
||
| /// Deleted copy assignment operator (non-copyable) | ||
| LinearOperator& operator=(const LinearOperator& rOther) = delete; | ||
|
|
||
| /// Defaulted move assignment operator | ||
| LinearOperator& operator=(LinearOperator&& rOther) = default; | ||
|
|
||
| ///@} | ||
| ///@name Operations | ||
| ///@{ | ||
|
|
||
| /** | ||
| * @brief Performs the matrix-vector product y = A * x. | ||
| * @param rX Input vector x | ||
| * @param rY Output vector y | ||
| */ | ||
| virtual void SpMV( | ||
| const VectorType& rX, | ||
| VectorType& rY) const | ||
| { | ||
| KRATOS_ERROR << "SpMV() is not implemented in base LinearOperator class." << std::endl; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Performs the transposed matrix-vector product y = A^T * x. | ||
| * @param rX Input vector x | ||
| * @param rY Output vector y | ||
| */ | ||
| virtual void TransposeSpMV( | ||
| const VectorType& rX, | ||
| VectorType& rY) const | ||
| { | ||
| KRATOS_ERROR << "TransposeSpMV() is not implemented in base LinearOperator class." << std::endl; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Clear the operator data. | ||
| * @details Resets the sizes and function objects to null. | ||
| */ | ||
| virtual void Clear() | ||
| { | ||
| mNumRows = 0; | ||
| mNumCols = 0; | ||
| } | ||
|
|
||
| ///@} | ||
| ///@name Access | ||
| ///@{ | ||
|
|
||
| virtual MatrixType& GetMatrix() | ||
| { | ||
| KRATOS_ERROR << "GetMatrix() is not implemented in base LinearOperator class." << std::endl; | ||
| } | ||
|
|
||
| virtual const MatrixType& GetMatrix() const | ||
| { | ||
| KRATOS_ERROR << "GetMatrix() is not implemented in base LinearOperator class." << std::endl; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Set the number of rows. | ||
| * @param NumRows Number of rows | ||
| */ | ||
| void SetNumRows(std::size_t NumRows) | ||
| { | ||
| mNumRows = NumRows; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Set the number of columns. | ||
| * @param NumCols Number of columns | ||
| */ | ||
| void SetNumCols(std::size_t NumCols) | ||
| { | ||
| mNumCols = NumCols; | ||
| } | ||
|
|
||
| ///@} | ||
| ///@name Inquiry | ||
| ///@{ | ||
|
|
||
| /** | ||
| * @brief Get the number of rows. | ||
| * @return Number of rows of the operator | ||
| */ | ||
| std::size_t NumRows() const | ||
| { | ||
| return mNumRows; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Get the number of columns. | ||
| * @return Number of columns of the operator | ||
| */ | ||
| std::size_t NumCols() const | ||
| { | ||
| return mNumCols; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Check if the operator is matrix-free. | ||
| * @return True if the operator is matrix-free, false otherwise | ||
| */ | ||
| virtual bool IsMatrixFree() const | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| ///@} | ||
| private: | ||
|
|
||
| ///@name Member Variables | ||
| ///@{ | ||
|
|
||
| /// Number of rows of the operator | ||
| std::size_t mNumRows = 0; | ||
|
|
||
| /// Number of columns of the operator | ||
| std::size_t mNumCols = 0; | ||
|
|
||
| ///@} | ||
| }; // class LinearOperator | ||
|
|
||
| ///@} | ||
| ///@name Input and output | ||
| ///@{ | ||
|
|
||
| ///@} | ||
| ///@} addtogroup block | ||
|
|
||
| } // namespace Kratos::Future | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.