Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_Smoother_MV.H
Go to the documentation of this file.
1#ifndef AMREX_SMOOTHER_MV_H_
2#define AMREX_SMOOTHER_MV_H_
3
4#include <AMReX_Algebra.H>
5#include <utility>
6
7namespace amrex {
8
21template <typename T>
23{
24public:
30 explicit JacobiSmoother (SpMatrix<T> const* a_A) : m_A(a_A) {}
31
38 int setNumIters (int a_niters) { return std::exchange(m_niters, a_niters); }
39
47 void operator() (AlgVector<T>& xvec, AlgVector<T> const& bvec,
48 bool with_initial_guess = false)
49 {
50 auto const& diag = m_A->diagonalVector();
51 AlgVector<T> Axvec(xvec.partition());
52 if ( ! with_initial_guess) {
53 xvec.setVal(0);
54 }
55 for (int iter = 0; iter < m_niters; ++iter) {
56 if ((iter == 0) && ! with_initial_guess) {
57 Axvec.setVal(0);
58 } else {
59 SpMV(Axvec, *m_A, xvec);
60 }
61 ForEach(xvec, Axvec, bvec, diag,
62 [=] AMREX_GPU_DEVICE (T& x, T const& ax, T const& b, T const& d)
63 {
64 if (d != T(0)) {
65 x += (b-ax)/d * T(2./3.); // weighted Jacobi
66 }
67 });
68 }
70 }
71
72private:
73 SpMatrix<T> const* m_A;
74 int m_niters = 4;
75};
76
77}
78
79#endif
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
Distributed dense vector that mirrors the layout of an AlgPartition.
Definition AMReX_AlgVector.H:29
void setVal(T val)
Definition AMReX_AlgVector.H:275
AlgPartition const & partition() const
Partition describing the global layout of the vector.
Definition AMReX_AlgVector.H:71
Weighted-Jacobi smoother for AlgVector/SpMatrix linear systems.
Definition AMReX_Smoother_MV.H:23
JacobiSmoother(SpMatrix< T > const *a_A)
Construct a weighted-Jacobi smoother that operates on a_A.
Definition AMReX_Smoother_MV.H:30
int setNumIters(int a_niters)
Update how many Jacobi sweeps to perform per apply.
Definition AMReX_Smoother_MV.H:38
void operator()(AlgVector< T > &xvec, AlgVector< T > const &bvec, bool with_initial_guess=false)
Apply the smoother to solve approximately for xvec.
Definition AMReX_Smoother_MV.H:47
Distributed CSR matrix that manages storage and GPU-friendly partitions.
Definition AMReX_SpMatrix.H:61
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
Definition AMReX_Amr.cpp:49
constexpr void ForEach(TypeList< Ts... >, F &&f)
For each type t in TypeList, call f(t)
Definition AMReX_TypeList.H:83
void SpMV(Long nrows, Long ncols, T *__restrict__ py, CsrView< T const > const &A, T const *__restrict__ px)
Perform y = A * x using CSR data (GPU/CPU aware).
Definition AMReX_SpMV.H:28