12#ifndef PECLET_CORE_SOLVER_CSR_BICGSTAB_HPP
13#define PECLET_CORE_SOLVER_CSR_BICGSTAB_HPP
50 std::function<
double(
double)> dotReduce,
Index nExt) {
51 haloFn_ = std::move(refresh);
52 dotReduce_ = std::move(dotReduce);
63 precFn_ = std::move(fn);
70 for (
int s = 0; s < sweeps; ++s) {
93 int maxIters = 200,
double tol = 1e-8) {
102 double rnorm = R.
res0;
104 for (; it < maxIters; ++it) {
105 applyPrec(op, r_, phat_);
110 if (rnorm <= tol * R.
res0) {
123 int maxIters = 500,
double tol = 1e-10) {
130 Kokkos::deep_copy(rhat_, r_);
134 double rho = 1, alpha = 1, omega = 1;
135 Kokkos::deep_copy(v_, 0.0);
136 Kokkos::deep_copy(p_, 0.0);
137 double rnorm = R.
res0;
139 for (; it < maxIters; ++it) {
143 double beta = (rhoNew / rho) * (alpha / omega);
146 applyPrec(op, p_, phat_);
150 alpha = rhoNew / rhatV;
152 Kokkos::deep_copy(s_, r_);
155 if (snorm <= tol * R.
res0) {
161 applyPrec(op, s_, shat_);
170 Kokkos::deep_copy(r_, s_);
173 if (rnorm <= tol * R.
res0) {
194 Kokkos::deep_copy(z, 0.0);
196 Kokkos::deep_copy(z, v);
199 for (
int s = 0; s < jacPre_; ++s) {
214 return dotReduce_ ? dotReduce_(s) : s;
216 void ensure(
Index n) {
219 if (r_.extent(0) ==
static_cast<std::size_t
>(n))
221 auto mk = [&](
const char* l) {
return View<double>(l,
static_cast<std::size_t
>(n)); };
223 rhat_ = mk(
"mom_rhat");
225 phat_ = mk(
"mom_phat");
228 shat_ = mk(
"mom_shat");
230 tmp_ = mk(
"mom_tmp");
233 View<double> r_, rhat_, p_, phat_, v_, s_, shat_, t_, tmp_;
238 std::function<double(
double)> dotReduce_;
void setDistributed(std::function< void(View< double >)> refresh, std::function< double(double)> dotReduce, Index nExt)
Distributed solve (docs/amr_distributed_flow.md, rung 2): refresh re-fills the ghost tail [op....
double solveJacobi(const MomentumOp &op, View< double > u, View< const double > b, int sweeps)
Plain weighted-Jacobi solve (the simple parallel mirror of the host GS smoother): sweeps damped-Jacob...
Result solveBiCGStab(const MomentumOp &op, View< double > u, View< const double > b, int maxIters=500, double tol=1e-10)
Jacobi-preconditioned BiCGStab solve of A u = b in place.
void setJacobi(int preSweeps, double omega)
void setPreconditioner(std::function< void(View< const double >, View< double >)> fn)
Set a generic preconditioner z = M⁻¹ r (a host callable that launches device kernels) — the multigrid...
Result solveDefectCorrection(const MomentumOp &op, View< double > u, View< const double > b, int maxIters=200, double tol=1e-8)
MG-preconditioned defect-correction (Richardson) solve of A u = b in place: u ← u + M⁻¹(b − A u),...
void bicgPUpdate(View< double > p, View< const double > r, View< const double > v, double beta, double omega, Index n)
BiCGStab direction update: p = r + β(p − ω v).
double dotPlain(View< const double > a, View< const double > b, Index n)
Plain (unweighted) dot product.
void applyMom(const MomentumOp &op, View< const double > u, View< double > Au)
Au = A u (cut-cell operator + optional implicit-FOU advection).
void axpy(View< double > y, double a, View< const double > x, Index n)
y += a·x
void residualMom(const MomentumOp &op, View< const double > u, View< const double > b, View< double > res)
res = b − A u.
void jacobiMom(const MomentumOp &op, View< double > u, View< const double > b, View< double > tmp, double omega)
One weighted-Jacobi sweep of A u = b (in place).
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
Kokkos::View< T *, MemSpace > View
1D device array.
Assembled momentum operator on the device: (A u)_i = diag_i u_i + Σ coef·u[nbr], with an optional imp...