Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 {
19 auto const& diag = m_A->diagonalVector();
20 AlgVector<T> Axvec(xvec.partition());
21 xvec.setVal(0);
22 for (int iter = 0; iter < m_niters; ++iter) {
23 if (iter == 0) {
24 Axvec.setVal(0);
25 } else {
26 SpMV(Axvec, *m_A, xvec);
27 }
28 ForEach(xvec, Axvec, bvec, diag,
29 [=] AMREX_GPU_DEVICE (T& x, T const& ax, T const& b, T const& d)
30 {
31 if (d != T(0)) {
32 x += (b-ax)/d * T(2./3.); // weighted Jacobi
33 }
34 });
35 }
37 }
38
39private:
41 int m_niters = 4;
42};
43
44}
45
46#endif
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
Definition AMReX_AlgVector.H:19
void setVal(T val)
Definition AMReX_AlgVector.H:146
AlgPartition const & partition() const
Definition AMReX_AlgVector.H:43
Definition AMReX_Smoother_MV.H:11
JacobiSmoother(SpMatrix< T > const *a_A)
Definition AMReX_Smoother_MV.H:13
SpMatrix< T > const * m_A
Definition AMReX_Smoother_MV.H:40
int setNumIters(int a_niters)
Definition AMReX_Smoother_MV.H:15
void operator()(AlgVector< T > &xvec, AlgVector< T > const &bvec)
Definition AMReX_Smoother_MV.H:17
int m_niters
Definition AMReX_Smoother_MV.H:41
Definition AMReX_SpMatrix.H:19
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:237
Definition AMReX_Amr.cpp:49
void SpMV(AlgVector< T > &y, SpMatrix< T > const &A, AlgVector< T > const &x)
Definition AMReX_SpMV.H:20
constexpr void ForEach(TypeList< Ts... >, F &&f)
For each type t in TypeList, call f(t)
Definition AMReX_TypeList.H:78