/home/runner/work/kynema-sgf/kynema-sgf/src/fvm/filter.H Source File

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/fvm/filter.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
filter.H
Go to the documentation of this file.
1#ifndef FILTER_H
2#define FILTER_H
3
4#include "src/fvm/fvm_utils.H"
5#include "AMReX_REAL.H"
6
7using namespace amrex::literals;
8
9namespace kynema_sgf::fvm {
10
14template <typename FTypeIn, typename FTypeOut>
15struct Filter
16{
21 Filter(FTypeOut& filterphi, const FTypeIn& phi)
22 : m_filterphi(filterphi), m_phi(phi)
23 {
24 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
25 filterphi.num_comp() == phi.num_comp(),
26 "filterphi.num_comp() = " + std::to_string(filterphi.num_comp()) +
27 ", phi.num_comp() = " + std::to_string(phi.num_comp()));
28 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
29 m_phi.num_grow() > amrex::IntVect(0),
30 "m_phi.num_grow() = (" + std::to_string(m_phi.num_grow()[0]) +
31 ", " + std::to_string(m_phi.num_grow()[1]) + ", " +
32 std::to_string(m_phi.num_grow()[2]) + ")");
33 }
34
35 template <typename Stencil>
36 void apply(const int lev) const
37 {
38 const int ncomp = m_phi.num_comp();
39 const auto& geom = m_phi.repo().mesh().Geom(lev);
40 const auto dlo = geom.Domain().smallEnd();
41 const auto dhi = geom.Domain().bigEnd();
42
43 auto& out_mf = m_filterphi(lev);
44 auto const& in_arrs = m_phi(lev).const_arrays();
45 auto const& out_arrs = out_mf.arrays();
46
47 amrex::ParallelFor(
48 out_mf, amrex::IntVect(0),
49 [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) {
50 if (!Stencil::applies_to(i, j, k, dlo, dhi)) {
51 return;
52 }
53 auto const& phi_arr = in_arrs[nbx];
54 auto const& filterphi_arr = out_arrs[nbx];
55 for (int icomp = 0; icomp < ncomp; icomp++) {
56 const amrex::Real filx =
57 (Stencil::f00 * phi_arr(i + 1, j, k, icomp)) +
58 (Stencil::f01 * phi_arr(i, j, k, icomp)) +
59 (Stencil::f02 * phi_arr(i - 1, j, k, icomp));
60 const amrex::Real fily =
61 (Stencil::f10 * phi_arr(i, j + 1, k, icomp)) +
62 (Stencil::f11 * phi_arr(i, j, k, icomp)) +
63 (Stencil::f12 * phi_arr(i, j - 1, k, icomp));
64 const amrex::Real filz =
65 (Stencil::f20 * phi_arr(i, j, k + 1, icomp)) +
66 (Stencil::f21 * phi_arr(i, j, k, icomp)) +
67 (Stencil::f22 * phi_arr(i, j, k - 1, icomp));
68 filterphi_arr(i, j, k, icomp) =
69 1.0_rt / 3.0_rt * (filx + fily + filz);
70 }
71 });
72 }
73
74 FTypeOut& m_filterphi;
75 const FTypeIn& m_phi;
76};
77
84template <typename FTypeIn, typename FTypeOut>
85void filter(FTypeOut& filterphi, const FTypeIn& phi)
86{
87 BL_PROFILE("kynema-sgf::fvm::filter");
88 Filter<FTypeIn, FTypeOut> filtering(filterphi, phi);
89 impl::apply(filtering, phi);
90}
91
97template <typename FType>
98std::unique_ptr<ScratchField> filter(const FType& phi)
99{
100 const std::string gname = phi.name() + "_filter";
101 auto filterphi = phi.repo().create_scratch_field(gname, phi.num_comp());
102 filter(*filterphi, phi);
103 return filterphi;
104}
105
106} // namespace kynema_sgf::fvm
107
108#endif /* FILTER_H */
void filter(FTypeOut &filterphi, const FTypeIn &phi)
Definition filter.H:85
AMREX_INLINE void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:20
Definition SchemeTraits.H:6
Definition filter.H:16
const FTypeIn & m_phi
Definition filter.H:75
FTypeOut & m_filterphi
Definition filter.H:74
void apply(const int lev) const
Definition filter.H:36
Filter(FTypeOut &filterphi, const FTypeIn &phi)
Definition filter.H:21