Documentation 6b54b78464
Loading...
Searching...
No Matches
CMatrixVectorProduct.hpp
Go to the documentation of this file.
1/*!
2 * \file CMatrixVectorProduct.hpp
3 * \brief Headers for the classes related to sparse matrix-vector product wrappers.
4 * The actual operations are currently implemented mostly by CSysMatrix.
5 * \author F. Palacios, J. Hicken, T. Economon
6 * \version 8.5.0 "Harrier"
7 *
8 * SU2 Project Website: https://su2code.github.io
9 *
10 * The SU2 Project is maintained by the SU2 Foundation
11 * (http://su2foundation.org)
12 *
13 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
14 *
15 * SU2 is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * SU2 is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29#pragma once
30
31#include "../CConfig.hpp"
32#include "../geometry/CGeometry.hpp"
33#include "CSysVector.hpp"
34#include "CSysMatrix.hpp"
35
36/*!
37 * \class CMatrixVectorProduct
38 * \ingroup SpLinSys
39 * \brief Abstract base class for defining matrix-vector products
40 * \author J. Hicken.
41 *
42 * The Krylov-subspace solvers require only matrix-vector products and
43 * not the actual matrix/Jacobian. We need some way to indicate which
44 * function will perform the product. However, sometimes the
45 * functions that define the product will require different numbers
46 * and types of inputs. For example, the forward-difference
47 * approximation to a Jacobian-vector product requires the vector that
48 * defines the Jacobian and a perturbation parameter. The
49 * CMatrixVectorProduct class is used to derive child classes that can
50 * handle the different types of matrix-vector products and still be
51 * passed to a single implementation of the Krylov solvers.
52 * This abstraction may also be used to define matrix-free products.
53 */
54
55template <class ScalarType>
57 public:
58 virtual ~CMatrixVectorProduct() = 0;
59 virtual void operator()(const CSysVector<ScalarType>& u, CSysVector<ScalarType>& v) const = 0;
60};
61template <class ScalarType>
63
64/*!
65 * \class CSysMatrixVectorProduct
66 * \ingroup SpLinSys
67 * \brief Specialization of matrix-vector product that uses CSysMatrix class
68 */
69template <class ScalarType>
70class CSysMatrixVectorProduct final : public CMatrixVectorProduct<ScalarType> {
71 private:
72 const CSysMatrix<ScalarType>& matrix; /*!< \brief pointer to matrix that defines the product. */
73 CGeometry* geometry; /*!< \brief geometry associated with the matrix. */
74 const CConfig* config; /*!< \brief config of the problem. */
75
76 public:
77 /*!
78 * \brief constructor of the class
79 * \param[in] matrix_ref - matrix reference that will be used to define the products
80 * \param[in] geometry_ref - geometry associated with the problem
81 * \param[in] config_ref - config of the problem
82 */
83 inline CSysMatrixVectorProduct(const CSysMatrix<ScalarType>& matrix_ref, CGeometry* geometry_ref,
84 const CConfig* config_ref)
85 : matrix(matrix_ref), geometry(geometry_ref), config(config_ref) {
86 /*--- The matrix does not change while this object lives, so it crosses the bus once,
87 * here. The vectors are uploaded by CSysSolve, see HandleTemporariesIn. ---*/
88#ifdef SU2_ENABLE_CUDA_KERNELS
89 if constexpr (su2_gpu_capable_v<ScalarType>) {
90 if (config->GetCUDA()) {
92 }
93 }
94#endif
95 }
96
97 /*!
98 * \note This class cannot be default constructed as that would leave us with invalid pointers.
99 */
101
102 /*!
103 * \brief operator that defines the CSysMatrix-CSysVector product
104 * \param[in] u - CSysVector that is being multiplied by the sparse matrix
105 * \param[out] v - CSysVector that is the result of the product
106 */
107 inline void operator()(const CSysVector<ScalarType>& u, CSysVector<ScalarType>& v) const override {
108 matrix.MatrixVectorProduct(u, v, geometry, config);
109 }
110};
Declaration of the block-sparse matrix class. The implemtation is in CSysMatrix.cpp.
Declararion and inlines of the vector class used in the solution of large, distributed,...
#define SU2_DEVICE_REGION(...)
Brackets device work so that it is issued by a single thread with the whole team synchronized before ...
Definition CSysVector.hpp:100
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
bool GetCUDA(void) const
Get information about GPU support.
Definition CConfig.hpp:6698
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
Abstract base class for defining matrix-vector products.
Definition CMatrixVectorProduct.hpp:56
virtual ~CMatrixVectorProduct()=0
Definition CMatrixVectorProduct.hpp:62
virtual void operator()(const CSysVector< ScalarType > &u, CSysVector< ScalarType > &v) const =0
Specialization of matrix-vector product that uses CSysMatrix class.
Definition CMatrixVectorProduct.hpp:70
CSysMatrixVectorProduct(const CSysMatrix< ScalarType > &matrix_ref, CGeometry *geometry_ref, const CConfig *config_ref)
constructor of the class
Definition CMatrixVectorProduct.hpp:83
void operator()(const CSysVector< ScalarType > &u, CSysVector< ScalarType > &v) const override
operator that defines the CSysMatrix-CSysVector product
Definition CMatrixVectorProduct.hpp:107
CSysMatrixVectorProduct()=delete
Main class for defining block-compressed-row-storage sparse matrices.
Definition CSysMatrix.hpp:256
void HtDTransfer(bool trigger=true) const
Performs the memory copy from host to device.
Definition CSysMatrixGPU.cu:1016
Class for holding and manipulating vectors needed by linear solvers.
Definition CSysVector.hpp:195