-
Notifications
You must be signed in to change notification settings - Fork 13
Ginkgo config solver #272
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
Ginkgo config solver #272
Changes from 11 commits
92d7f8e
b22c097
f7d3792
0c6cbe1
8c80fb6
b121691
deb5c23
370264e
a8905db
afe2ac6
3b2005f
51e6978
c418c49
643447a
60e7c05
007c83f
9743a4b
65a51a3
f7ca345
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,7 @@ | |
| [[maybe_unused]] const Dictionary& fvSolution | ||
| ) | ||
| { | ||
| // FIXME: | ||
| if (exp.temporalOperators().size() == 0 && exp.spatialOperators().size() == 0) | ||
| { | ||
| NF_ERROR_EXIT("No temporal or implicit terms to solve."); | ||
|
|
@@ -132,8 +132,7 @@ | |
| using ValueType = typename FieldType::ElementType; | ||
| auto ls = ginkgoMatrix(exp, solution); | ||
|
|
||
|
|
||
| NeoFOAM::la::ginkgo::BiCGStab<ValueType> solver(solution.exec(), fvSolution); | ||
| NeoFOAM::la::ginkgo::Solver<ValueType> solver(solution.exec(), fvSolution); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line 116-119 format seems to be incorrect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clang format seems to be fine with it. |
||
| solver.solve(ls, solution.internalField()); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,19 +18,33 @@ std::shared_ptr<gko::Executor> getGkoExecutor(Executor exec); | |
|
|
||
| namespace detail | ||
| { | ||
|
|
||
| template<typename T> | ||
| gko::array<T> createGkoArray(std::shared_ptr<const gko::Executor> exec, std::span<T> values) | ||
| { | ||
| return gko::make_array_view(exec, values.size(), values.data()); | ||
| } | ||
|
|
||
| template<typename T> | ||
| gko::detail::const_array_view<T> | ||
| createGkoArray(std::shared_ptr<const gko::Executor> exec, std::span<const T> values) | ||
| { | ||
| return gko::make_const_array_view(exec, values.size(), values.data()); | ||
| } | ||
|
|
||
| template<typename ValueType, typename IndexType> | ||
| std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>> | ||
| createGkoMtx(std::shared_ptr<const gko::Executor> exec, LinearSystem<ValueType, IndexType>& sys) | ||
| { | ||
| auto& mtx = sys.matrix(); | ||
| size_t nrows = sys.rhs().size(); | ||
|
|
||
| auto valuesView = gko::array<scalar>::view(exec, mtx.values().size(), mtx.values().data()); | ||
| auto colIdxView = gko::array<int>::view(exec, mtx.colIdxs().size(), mtx.colIdxs().data()); | ||
| auto rowPtrView = gko::array<int>::view(exec, mtx.rowPtrs().size(), mtx.rowPtrs().data()); | ||
|
|
||
| return gko::share(gko::matrix::Csr<scalar, int>::create( | ||
| exec, gko::dim<2> {nrows, nrows}, valuesView, colIdxView, rowPtrView | ||
| return gko::share(gko::matrix::Csr<ValueType, IndexType>::create( | ||
| exec, | ||
| gko::dim<2> {nrows, nrows}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: nrows from mtx.nRows() not from rhs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now the matrices are assumed to be square. I think this will also stay like this for quite a while. |
||
| createGkoArray(exec, mtx.values()), | ||
| createGkoArray(exec, mtx.colIdxs()), | ||
| createGkoArray(exec, mtx.rowPtrs()) | ||
| )); | ||
| } | ||
|
|
||
|
|
@@ -39,7 +53,7 @@ std::shared_ptr<gko::matrix::Dense<ValueType>> | |
| createGkoDense(std::shared_ptr<const gko::Executor> exec, ValueType* ptr, size_t size) | ||
| { | ||
| return gko::share(gko::matrix::Dense<ValueType>::create( | ||
| exec, gko::dim<2> {size, 1}, gko::array<scalar>::view(exec, size, ptr), 1 | ||
| exec, gko::dim<2> {size, 1}, createGkoArray(exec, std::span {ptr, size}), 1 | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // SPDX-FileCopyrightText: 2025 NeoFOAM authors | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include "NeoFOAM/linearAlgebra/ginkgo.hpp" | ||
|
|
||
| gko::config::pnode NeoFOAM::la::ginkgo::parse(const Dictionary& dict) | ||
| { | ||
| auto parseData = [&](auto key) | ||
| { | ||
| auto parseAny = [&](auto blueprint) | ||
| { | ||
| using value_type = decltype(blueprint); | ||
| if (dict[key].type() == typeid(value_type)) | ||
| { | ||
| return gko::config::pnode(dict.get<value_type>(key)); | ||
| } | ||
| else | ||
| { | ||
| return gko::config::pnode(); | ||
| } | ||
| }; | ||
|
|
||
| if (auto node = parseAny(std::string())) | ||
| { | ||
| return node; | ||
| } | ||
| if (auto node = parseAny(static_cast<const char*>(nullptr))) | ||
| { | ||
| return node; | ||
| } | ||
| if (auto node = parseAny(int {})) | ||
| { | ||
| return node; | ||
| } | ||
| if (auto node = parseAny(static_cast<unsigned int>(0))) | ||
| { | ||
| return node; | ||
| } | ||
| if (auto node = parseAny(double {})) | ||
| { | ||
| return node; | ||
| } | ||
| if (auto node = parseAny(float {})) | ||
| { | ||
| return node; | ||
| } | ||
|
|
||
| NF_THROW("Dictionary key " + key + " has unsupported type: " + dict[key].type().name()); | ||
| }; | ||
| gko::config::pnode::map_type result; | ||
| for (const auto& key : dict.keys()) | ||
| { | ||
| gko::config::pnode node; | ||
| if (dict.isDict(key)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't Dictionary support Array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear ATM. Since the dictionary just stores an |
||
| { | ||
| node = parse(dict.subDict(key)); | ||
| } | ||
| else | ||
| { | ||
| node = parseData(key); | ||
| } | ||
| result.emplace(key, node); | ||
| } | ||
| return gko::config::pnode {result}; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| # SPDX-License-Identifier: Unlicense | ||
| # SPDX-FileCopyrightText: 2024 NeoFOAM authors | ||
|
|
||
| neofoam_unit_test(ginkgo) | ||
| neofoam_unit_test(CSRMatrix) | ||
| neofoam_unit_test(linearSystem) | ||
| neofoam_unit_test(linearAlgebra) |
Uh oh!
There was an error while loading. Please reload this page.