NeoFOAM
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
utilities.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2024-2025 NeoFOAM authors
3
4#pragma once
5
6#include <ginkgo/ginkgo.hpp>
7#include <ginkgo/extensions/kokkos.hpp>
8
12
13
14namespace NeoFOAM::la
15{
16
17std::shared_ptr<gko::Executor> getGkoExecutor(Executor exec);
18
19namespace detail
20{
21template<typename ValueType, typename IndexType>
22std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
23createGkoMtx(std::shared_ptr<const gko::Executor> exec, LinearSystem<ValueType, IndexType>& sys)
24{
25 auto& mtx = sys.matrix();
26 size_t nrows = sys.rhs().size();
27
28 auto valuesView = gko::array<scalar>::view(exec, mtx.values().size(), mtx.values().data());
29 auto colIdxView = gko::array<int>::view(exec, mtx.colIdxs().size(), mtx.colIdxs().data());
30 auto rowPtrView = gko::array<int>::view(exec, mtx.rowPtrs().size(), mtx.rowPtrs().data());
31
32 return gko::share(gko::matrix::Csr<scalar, int>::create(
33 exec, gko::dim<2> {nrows, nrows}, valuesView, colIdxView, rowPtrView
34 ));
35}
36
37template<typename ValueType>
38std::shared_ptr<gko::matrix::Dense<ValueType>>
39createGkoDense(std::shared_ptr<const gko::Executor> exec, ValueType* ptr, size_t size)
40{
41 return gko::share(gko::matrix::Dense<ValueType>::create(
42 exec, gko::dim<2> {size, 1}, gko::array<scalar>::view(exec, size, ptr), 1
43 ));
44}
45}
46
47}
A class representing a linear system of equations.
Field< ValueType > & rhs()
CSRMatrix< ValueType, IndexType > & matrix()
std::shared_ptr< gko::matrix::Dense< ValueType > > createGkoDense(std::shared_ptr< const gko::Executor > exec, ValueType *ptr, size_t size)
Definition utilities.hpp:39
std::shared_ptr< gko::matrix::Csr< ValueType, IndexType > > createGkoMtx(std::shared_ptr< const gko::Executor > exec, LinearSystem< ValueType, IndexType > &sys)
Definition utilities.hpp:23
std::shared_ptr< gko::Executor > getGkoExecutor(Executor exec)
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:16