\doxysection{pgm.\+hpp}
\hypertarget{pgm_8hpp_source}{}\label{pgm_8hpp_source}\index{ginkgo/core/multigrid/pgm.hpp@{ginkgo/core/multigrid/pgm.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{//\ SPDX-\/FileCopyrightText:\ 2017\ -\/\ 2025\ The\ Ginkgo\ authors}}
\DoxyCodeLine{00002\ \textcolor{comment}{//}}
\DoxyCodeLine{00003\ \textcolor{comment}{//\ SPDX-\/License-\/Identifier:\ BSD-\/3-\/Clause}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#ifndef\ GKO\_PUBLIC\_CORE\_MULTIGRID\_PGM\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_MULTIGRID\_PGM\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <vector>}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/composition.hpp>}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/exception\_helpers.hpp>}}
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/lin\_op.hpp>}}
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/types.hpp>}}
\DoxyCodeLine{00015\ \textcolor{preprocessor}{\#include\ <ginkgo/core/config/config.hpp>}}
\DoxyCodeLine{00016\ \textcolor{preprocessor}{\#include\ <ginkgo/core/config/registry.hpp>}}
\DoxyCodeLine{00017\ \textcolor{preprocessor}{\#include\ <ginkgo/core/config/type\_descriptor.hpp>}}
\DoxyCodeLine{00018\ \textcolor{preprocessor}{\#include\ <ginkgo/core/distributed/matrix.hpp>}}
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#include\ <ginkgo/core/matrix/csr.hpp>}}
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#include\ <ginkgo/core/matrix/dense.hpp>}}
\DoxyCodeLine{00021\ \textcolor{preprocessor}{\#include\ <ginkgo/core/multigrid/multigrid\_level.hpp>}}
\DoxyCodeLine{00022\ }
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00025\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko_1_1multigrid}{multigrid}}\ \{}
\DoxyCodeLine{00026\ }
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00050\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision,\ \textcolor{keyword}{typename}\ IndexType\ =\ \textcolor{keywordtype}{int}32>}
\DoxyCodeLine{00051\ \textcolor{keyword}{class\ }Pgm\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1EnableLinOp}{EnableLinOp}}<Pgm<ValueType,\ IndexType>>,}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{public}\ EnableMultigridLevel<ValueType>\ \{}
\DoxyCodeLine{00053\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnableLinOp}{EnableLinOp}}<Pgm>;}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnablePolymorphicObject}{EnablePolymorphicObject}}<Pgm,\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}>;}
\DoxyCodeLine{00055\ \ \ \ \ GKO\_ASSERT\_SUPPORTED\_VALUE\_AND\_INDEX\_TYPE;}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00058\ \ \ \ \ \textcolor{keyword}{using\ }value\_type\ =\ ValueType;}
\DoxyCodeLine{00059\ \ \ \ \ \textcolor{keyword}{using\ }index\_type\ =\ IndexType;}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00066\ \ \ \ \ std::shared\_ptr<const\ LinOp>\ \doxymbox{\hyperlink{classgko_1_1multigrid_1_1Pgm_af4256a2ba571d8fe579e7b092b426561}{get\_system\_matrix}}()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00067\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ system\_matrix\_;}
\DoxyCodeLine{00069\ \ \ \ \ \}}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00080\ \ \ \ \ IndexType*\ \doxymbox{\hyperlink{classgko_1_1multigrid_1_1Pgm_a410a9f34612fbbbc7492beadb6944bc9}{get\_agg}}()\ noexcept\ \{\ \textcolor{keywordflow}{return}\ agg\_.get\_data();\ \}}
\DoxyCodeLine{00081\ }
\DoxyCodeLine{00089\ \ \ \ \ \textcolor{keyword}{const}\ IndexType*\ \doxymbox{\hyperlink{classgko_1_1multigrid_1_1Pgm_a18df85e700558f8b57d6013744c24a15}{get\_const\_agg}}()\ const\ noexcept}
\DoxyCodeLine{00090\ \ \ \ \ \{}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ agg\_.get\_const\_data();}
\DoxyCodeLine{00092\ \ \ \ \ \}}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00094\ \ \ \ \ \doxymbox{\hyperlink{group__LinOp_ga1fc8e9d8be0c9ad2d72bc1ddfc6d8358}{GKO\_CREATE\_FACTORY\_PARAMETERS}}(parameters,\ \doxymbox{\hyperlink{classgko_1_1multigrid_1_1Pgm_1_1Factory}{Factory}})}
\DoxyCodeLine{00095\ \ \ \ \ \{}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \doxymbox{\hyperlink{group__LinOp_ga49d4c09c39f06b22bebbbfd1d8bfe450}{GKO\_FACTORY\_PARAMETER\_SCALAR}}(\doxymbox{\hyperlink{structgko_1_1multigrid_1_1Pgm_1_1parameters__type_afc511fbee9d2ea44e611275d8b287a82}{max\_iterations}},\ 15u);}
\DoxyCodeLine{00102\ }
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{double}\ \doxymbox{\hyperlink{group__LinOp_ga49d4c09c39f06b22bebbbfd1d8bfe450}{GKO\_FACTORY\_PARAMETER\_SCALAR}}(\doxymbox{\hyperlink{structgko_1_1multigrid_1_1Pgm_1_1parameters__type_a84f566c53173ae409ff6916f052ddcf4}{max\_unassigned\_ratio}},\ 0.05);}
\DoxyCodeLine{00110\ }
\DoxyCodeLine{00118\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{group__LinOp_ga49d4c09c39f06b22bebbbfd1d8bfe450}{GKO\_FACTORY\_PARAMETER\_SCALAR}}(\doxymbox{\hyperlink{structgko_1_1multigrid_1_1Pgm_1_1parameters__type_a3c2ddfd2af200acc414f0e2af404e431}{deterministic}},\ \textcolor{keyword}{false});}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{group__LinOp_ga49d4c09c39f06b22bebbbfd1d8bfe450}{GKO\_FACTORY\_PARAMETER\_SCALAR}}(\doxymbox{\hyperlink{structgko_1_1multigrid_1_1Pgm_1_1parameters__type_aadc7dc67f45b1dc93967b935143627f1}{skip\_sorting}},\ \textcolor{keyword}{false});}
\DoxyCodeLine{00131\ \ \ \ \ \};}
\DoxyCodeLine{00132\ \ \ \ \ \doxymbox{\hyperlink{group__LinOp_ga8e0af90ec2414b768266f77cedffc309}{GKO\_ENABLE\_LIN\_OP\_FACTORY}}(Pgm,\ parameters,\ Factory);}
\DoxyCodeLine{00133\ \ \ \ \ \doxymbox{\hyperlink{group__LinOp_ga521f65604cc4cf427dcb2ecfa49b757c}{GKO\_ENABLE\_BUILD\_METHOD}}(Factory);}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00148\ \ \ \ \ \textcolor{keyword}{static}\ \doxymbox{\hyperlink{structgko_1_1multigrid_1_1Pgm_1_1parameters__type}{parameters\_type}}\ \doxymbox{\hyperlink{classgko_1_1multigrid_1_1Pgm_a0bef9b63524f0040cca27976cb086816}{parse}}(}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1config_1_1pnode}{config::pnode}}\&\ config,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1config_1_1registry}{config::registry}}\&\ context,}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1config_1_1type__descriptor}{config::type\_descriptor}}\&\ td\_for\_child\ =}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ config::make\_type\_descriptor<ValueType,\ IndexType>());}
\DoxyCodeLine{00152\ }
\DoxyCodeLine{00153\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ b,\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ x)\textcolor{keyword}{\ const\ override}}
\DoxyCodeLine{00155\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ this-\/>\doxymbox{\hyperlink{classgko_1_1UseComposition_a81d7f1c982c43df853ed9b9074e45409}{get\_composition}}()-\/>apply(b,\ x);}
\DoxyCodeLine{00157\ \ \ \ \ \}}
\DoxyCodeLine{00158\ }
\DoxyCodeLine{00159\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ alpha,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ b,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ beta,}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ x)\textcolor{keyword}{\ const\ override}}
\DoxyCodeLine{00161\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ this-\/>\doxymbox{\hyperlink{classgko_1_1UseComposition_a81d7f1c982c43df853ed9b9074e45409}{get\_composition}}()-\/>apply(alpha,\ b,\ beta,\ x);}
\DoxyCodeLine{00163\ \ \ \ \ \}}
\DoxyCodeLine{00164\ }
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{keyword}{explicit}\ Pgm(std::shared\_ptr<const\ Executor>\ exec)}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ :\ \doxymbox{\hyperlink{classgko_1_1EnableLinOp}{EnableLinOp}}<Pgm>(\doxymbox{\hyperlink{namespacestd}{std}}::move(exec))}
\DoxyCodeLine{00167\ \ \ \ \ \{\}}
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00169\ \ \ \ \ \textcolor{keyword}{explicit}\ Pgm(\textcolor{keyword}{const}\ Factory*\ factory,}
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ system\_matrix)}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ :\ EnableLinOp<Pgm>(factory-\/>get\_executor(),\ system\_matrix-\/>get\_size()),}
\DoxyCodeLine{00172\ \ \ \ \ \ \ \ \ \ \ EnableMultigridLevel<ValueType>(system\_matrix),}
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ \ \ parameters\_\{factory-\/>get\_parameters()\},}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ \ \ system\_matrix\_\{system\_matrix\},}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ \ \ agg\_(factory-\/>get\_executor(),\ system\_matrix\_-\/>get\_size()[0])}
\DoxyCodeLine{00176\ \ \ \ \ \{}
\DoxyCodeLine{00177\ \ \ \ \ \ \ \ \ GKO\_ASSERT(parameters\_.\doxymbox{\hyperlink{structgko_1_1multigrid_1_1Pgm_1_1parameters__type_a84f566c53173ae409ff6916f052ddcf4}{max\_unassigned\_ratio}}\ <=\ 1.0);}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ GKO\_ASSERT(parameters\_.\doxymbox{\hyperlink{structgko_1_1multigrid_1_1Pgm_1_1parameters__type_a84f566c53173ae409ff6916f052ddcf4}{max\_unassigned\_ratio}}\ >=\ 0.0);}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (system\_matrix\_-\/>get\_size()[0]\ !=\ 0)\ \{}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ generate\ on\ the\ existed\ matrix}}
\DoxyCodeLine{00181\ \ \ \ \ \ \ \ \ \ \ \ \ this-\/>generate();}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00183\ \ \ \ \ \}}
\DoxyCodeLine{00184\ }
\DoxyCodeLine{00185\ \ \ \ \ \textcolor{keywordtype}{void}\ generate();}
\DoxyCodeLine{00186\ }
\DoxyCodeLine{00192\ \ \ \ \ std::tuple<std::shared\_ptr<LinOp>,\ std::shared\_ptr<LinOp>,}
\DoxyCodeLine{00193\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::shared\_ptr<LinOp>>}
\DoxyCodeLine{00194\ \ \ \ \ generate\_local(}
\DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ std::shared\_ptr<\textcolor{keyword}{const}\ matrix::Csr<ValueType,\ IndexType>>\ local\_matrix);}
\DoxyCodeLine{00196\ }
\DoxyCodeLine{00197\ \textcolor{preprocessor}{\#if\ GINKGO\_BUILD\_MPI}\textcolor{preprocessor}{}}
\DoxyCodeLine{00211\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ GlobalIndexType>}
\DoxyCodeLine{00212\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{array<GlobalIndexType>}}\ communicate\_non\_local\_agg(}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ std::shared\_ptr<\textcolor{keyword}{const}\ experimental::distributed::Matrix<}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \ \ \ \ ValueType,\ IndexType,\ GlobalIndexType>>}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \ \ \ \ matrix,}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ std::shared\_ptr<}
\DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \ \ \ \ experimental::distributed::Partition<IndexType,\ GlobalIndexType>>}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \ \ \ \ coarse\_partition,}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ array<IndexType>\&\ local\_agg);}
\DoxyCodeLine{00220\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00221\ }
\DoxyCodeLine{00222\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00223\ \ \ \ \ std::shared\_ptr<const\ LinOp>\ system\_matrix\_\{\};}
\DoxyCodeLine{00224\ \ \ \ \ array<IndexType>\ agg\_;}
\DoxyCodeLine{00225\ \};}
\DoxyCodeLine{00226\ }
\DoxyCodeLine{00227\ }
\DoxyCodeLine{00228\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision,\ \textcolor{keyword}{typename}\ IndexType\ =\ \textcolor{keywordtype}{int}32>}
\DoxyCodeLine{00229\ \textcolor{keyword}{using\ }AmgxPgm\ GKO\_DEPRECATED(}
\DoxyCodeLine{00230\ \ \ \ \ \textcolor{stringliteral}{"{}This\ class\ is\ deprecated\ and\ will\ be\ removed\ in\ the\ next\ "{}}}
\DoxyCodeLine{00231\ \ \ \ \ \textcolor{stringliteral}{"{}major\ release.\ Please\ use\ Pgm\ instead."{}})\ =\ \doxymbox{\hyperlink{classgko_1_1multigrid_1_1Pgm}{Pgm<ValueType,\ IndexType>}};}
\DoxyCodeLine{00232\ }
\DoxyCodeLine{00233\ }
\DoxyCodeLine{00234\ \}\ \ \textcolor{comment}{//\ namespace\ multigrid}}
\DoxyCodeLine{00235\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00236\ }
\DoxyCodeLine{00237\ }
\DoxyCodeLine{00238\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_MULTIGRID\_PGM\_HPP\_}}

\end{DoxyCode}
