This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [hypre]: Introduce HypreDirectBuilder * [move]: refactor DirectMatrixBuilder Use composition instead of inheritance. * [ref]: refactor DirectMatrixBuilder Use composition instead of inheritance. * [all]: clang-format * [core]: some cleaning * [all]: IDirectMatrixBuilder and factory Should be able to use hypre directly, without SimpleCSR. * [hypre]: clang-format * [all]: real factory for DirectMatrixBuilder * [all]: change default DirectMatrixBuilder * [move]: add method to choose DirectMatrixBuilder backend * [dok]: make DokBuilder implements IDirectMatrixBuilder * [all]: add contribute method to IDirectMatrixBuilder This method returns whether or not the non zero was added. * [move]: Remove DoKDirectMatrixBuilder The functionality can be accessed with new DirectMatrixBuilder. * [core]: Add missing header for IDirectMatrixBuilder * [hypre]: Correct reset for DirectMatrixBuilder * [dok]: reset flag for DirectMatrixBuilder * [hypre] directbuilder works with reset flags * [hypre] Call ClearAllErrors before major operations * [dok] fix format
- Loading branch information
1 parent
fea96bd
commit 95b25f2
Showing
32 changed files
with
1,137 additions
and
396 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
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,86 @@ | ||
/* | ||
* Copyright 2023 IFPEN-CEA | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// | ||
// Created by chevalierc on 17/05/23. | ||
// | ||
|
||
#include "hypre_direct_matrix_builder.h" | ||
#include "alien/hypre/export.h" | ||
|
||
#include <alien/core/impl/MultiMatrixImpl.h> | ||
#include <alien/handlers/scalar/MatrixBuilderFactory.h> | ||
|
||
#include <alien/hypre/backend.h> | ||
|
||
namespace Alien::Hypre | ||
{ | ||
HypreDirectMatrixBuilder::HypreDirectMatrixBuilder(Alien::IMatrix& matrix, | ||
Hypre::HypreDirectMatrixBuilder::ResetFlag reset_flag, | ||
[[maybe_unused]] Hypre::HypreDirectMatrixBuilder::SymmetricFlag symmetric_flag) | ||
: m_matrix(matrix) | ||
{ | ||
|
||
m_matrix.impl()->lock(); | ||
m_matrix_impl = &m_matrix.impl()->get<BackEnd::tag::hypre>(true); | ||
|
||
m_matrix_impl->init(reset_flag); | ||
} | ||
|
||
void HypreDirectMatrixBuilder::finalize() | ||
{ | ||
m_matrix_impl->assemble(); | ||
m_matrix.impl()->unlock(); | ||
} | ||
|
||
void HypreDirectMatrixBuilder::setData(Arccore::Integer iIndex, Arccore::Integer jIndex, Arccore::Real value) | ||
{ | ||
m_matrix_impl->setRowValues(iIndex, ConstArrayView<Integer>(1, &jIndex), ConstArrayView<Real>(1, &value)); | ||
} | ||
|
||
void HypreDirectMatrixBuilder::setData(Arccore::Integer iIndex, Arccore::Real factor, | ||
Arccore::ConstArrayView<Arccore::Integer> jIndexes, | ||
Arccore::ConstArrayView<Arccore::Real> jValues) | ||
{ | ||
if (factor != 1.0) { | ||
throw FatalErrorException("Scaling is not supported"); | ||
} | ||
|
||
m_matrix_impl->setRowValues(iIndex, jIndexes, jValues); | ||
} | ||
|
||
void HypreDirectMatrixBuilder::addData(Arccore::Integer iIndex, Arccore::Integer jIndex, Arccore::Real value) | ||
{ | ||
m_matrix_impl->addRowValues(iIndex, ConstArrayView<Integer>(1, &jIndex), ConstArrayView<Real>(1, &value)); | ||
} | ||
|
||
void HypreDirectMatrixBuilder::addData(Arccore::Integer iIndex, Arccore::Real factor, | ||
Arccore::ConstArrayView<Arccore::Integer> jIndexes, | ||
Arccore::ConstArrayView<Arccore::Real> jValues) | ||
{ | ||
if (factor != 1.0) { | ||
throw FatalErrorException("Scaling is not supported"); | ||
} | ||
|
||
m_matrix_impl->addRowValues(iIndex, jIndexes, jValues); | ||
} | ||
|
||
const ALIEN_HYPRE_EXPORT Alien::Common::MatrixBuilderFactory hypre_builder_register( | ||
AlgebraTraits<BackEnd::tag::hypre>::name(), [](IMatrix& matrix, DirectMatrixOptions::ResetFlag reset, DirectMatrixOptions::SymmetricFlag symmetry) { return std::make_unique<HypreDirectMatrixBuilder>(matrix, reset, symmetry); }); | ||
|
||
}; // namespace Alien::Hypre |
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,143 @@ | ||
/* | ||
* Copyright 2023 IFPEN-CEA | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// | ||
// Created by chevalierc on 17/05/23. | ||
// | ||
|
||
#ifndef ALIEN_HYPREDIRECTMATRIXBUILDER_H | ||
#define ALIEN_HYPREDIRECTMATRIXBUILDER_H | ||
|
||
#include <alien/data/IMatrix.h> | ||
#include <alien/data/utils/MatrixElement.h> | ||
|
||
#include <arccore/trace/ITraceMng.h> | ||
#include <arccore/message_passing/IMessagePassingMng.h> | ||
|
||
#include <alien/handlers/scalar/IDirectMatrixBuilder.h> | ||
#include "hypre_matrix.h" | ||
|
||
namespace Alien | ||
{ | ||
|
||
/*---------------------------------------------------------------------------*/ | ||
/*---------------------------------------------------------------------------*/ | ||
|
||
namespace Hypre | ||
{ | ||
|
||
/*---------------------------------------------------------------------------*/ | ||
/*---------------------------------------------------------------------------*/ | ||
|
||
class ALIEN_EXPORT HypreDirectMatrixBuilder final : public Alien::Common::IDirectMatrixBuilder | ||
{ | ||
public: | ||
using ResetFlag = DirectMatrixOptions::ResetFlag; | ||
using ReserveFlag = DirectMatrixOptions::ReserveFlag; | ||
using SymmetricFlag = DirectMatrixOptions::SymmetricFlag; | ||
|
||
using MatrixElement = MatrixElementT<HypreDirectMatrixBuilder>; | ||
|
||
HypreDirectMatrixBuilder(IMatrix& matrix, [[maybe_unused]] ResetFlag reset_flag, | ||
[[maybe_unused]] SymmetricFlag symmetric_flag = SymmetricFlag::eSymmetric); | ||
|
||
~HypreDirectMatrixBuilder() override | ||
{ | ||
finalize(); | ||
} | ||
|
||
HypreDirectMatrixBuilder(HypreDirectMatrixBuilder&) = delete; | ||
|
||
HypreDirectMatrixBuilder(HypreDirectMatrixBuilder&&) = delete; | ||
|
||
HypreDirectMatrixBuilder& operator=(const HypreDirectMatrixBuilder&) = delete; | ||
|
||
HypreDirectMatrixBuilder& operator=(HypreDirectMatrixBuilder&&) = delete; | ||
|
||
void reserve(Arccore::Integer n, ReserveFlag flag = ReserveFlag::eResetReservation) override | ||
{ | ||
// Nothing yet | ||
} | ||
|
||
void reserve(Arccore::ConstArrayView<Arccore::Integer> indices, Arccore::Integer n, | ||
ReserveFlag flag = ReserveFlag::eResetReservation) override | ||
{ | ||
// Nothing yet | ||
} | ||
|
||
void allocate() override | ||
{ | ||
// Nothing yet | ||
} | ||
|
||
void addData(Arccore::Integer iIndex, Arccore::Integer jIndex, Arccore::Real value) override; | ||
|
||
void addData(Arccore::Integer iIndex, Arccore::Real factor, | ||
Arccore::ConstArrayView<Arccore::Integer> jIndexes, | ||
Arccore::ConstArrayView<Arccore::Real> jValues) override; | ||
|
||
void setData(Arccore::Integer iIndex, Arccore::Integer jIndex, Arccore::Real value) override; | ||
|
||
void setData(Arccore::Integer iIndex, Arccore::Real factor, | ||
Arccore::ConstArrayView<Arccore::Integer> jIndexes, | ||
Arccore::ConstArrayView<Arccore::Real> jValues) override; | ||
|
||
void finalize() override; | ||
|
||
void squeeze() override | ||
{ | ||
// do nothing | ||
} | ||
|
||
[[nodiscard]] Arccore::String stats() const override | ||
{ | ||
// Do nothing | ||
return { "" }; | ||
} | ||
|
||
[[nodiscard]] Arccore::String stats(Arccore::IntegerConstArrayView ids) const override | ||
{ | ||
// Do nothing | ||
return { "" }; | ||
} | ||
std::optional<Arccore::Real> contribute(Arccore::Integer row, Arccore::Integer col, Arccore::Real value) override | ||
{ | ||
addData(row, col, value); | ||
return { value }; | ||
} | ||
|
||
private: | ||
IMatrix& m_matrix; | ||
|
||
Matrix* m_matrix_impl; | ||
}; | ||
|
||
/*---------------------------------------------------------------------------*/ | ||
/*---------------------------------------------------------------------------*/ | ||
|
||
} // namespace Hypre | ||
|
||
/*---------------------------------------------------------------------------*/ | ||
/*---------------------------------------------------------------------------*/ | ||
|
||
} // namespace Alien | ||
|
||
/*---------------------------------------------------------------------------*/ | ||
/*---------------------------------------------------------------------------*/ | ||
|
||
#endif //ALIEN_HYPREDIRECTMATRIXBUILDER_H |
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
Oops, something went wrong.