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
9template <typename T>
11{
12public:
13 explicit JacobiSmoother (SpMatrix<T> const* a_A) : m_A(a_A) {}
14
15 int setNumIters (int a_niters) { return std::exchange(m_niters, a_niters); }
16
17 void operator() (AlgVector<T>& xvec, AlgVector<T> const& bvec,
18 bool with_initial_guess = false)
19 {
20 auto const& diag = m_A->diagonalVector();
21 AlgVector<T> Axvec(xvec.partition());
22 if ( ! with_initial_guess) {
23 xvec.setVal(0);
24 }
25 for (int iter = 0; iter < m_niters; ++iter) {
26 if ((iter == 0) && ! with_initial_guess) {
27 Axvec.setVal(0);
28 } else {
29 SpMV(Axvec, *m_A, xvec);
30 }
31 ForEach(xvec, Axvec, bvec, diag,
32 [=] AMREX_GPU_DEVICE (T& x, T const& ax, T const& b, T const& d)
33 {
34 if (d != T(0)) {
35 x += (b-ax)/d * T(2./3.); // weighted Jacobi
36 }
37 });
38 }
40 }
41
42private:
43 SpMatrix<T> const* m_A;
44 int m_niters = 4;
45};
46
47}
48
49#endif
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
Definition AMReX_AlgVector.H:20
void setVal(T val)
Definition AMReX_AlgVector.H:246
AlgPartition const & partition() const
Definition AMReX_AlgVector.H:44
Definition AMReX_Smoother_MV.H:11
JacobiSmoother(SpMatrix< T > const *a_A)
Definition AMReX_Smoother_MV.H:13
int setNumIters(int a_niters)
Definition AMReX_Smoother_MV.H:15
void operator()(AlgVector< T > &xvec, AlgVector< T > const &bvec, bool with_initial_guess=false)
Definition AMReX_Smoother_MV.H:17
Definition AMReX_SpMatrix.H:52
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:263
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:82
void SpMV(Long nrows, Long ncols, T *__restrict__ py, CsrView< T const > const &A, T const *__restrict__ px)
Definition AMReX_SpMV.H:13