/home/runner/work/amr-wind/amr-wind/amr-wind/fvm/filter.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/fvm/filter.H Source File
AMR-Wind 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
5#include "AMReX_Array4.H"
6#include "AMReX_Geometry.H"
7#include "AMReX_MFIter.H"
8
9namespace amr_wind::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(filterphi.num_comp() == phi.num_comp());
25 AMREX_ALWAYS_ASSERT(m_phi.num_grow() > amrex::IntVect(0));
26 }
27
28 template <typename Stencil>
29 void apply(const int lev, const amrex::MFIter& mfi) const
30 {
31 const int ncomp = m_phi.num_comp();
32 const auto& geom = m_phi.repo().mesh().Geom(lev);
33 const auto& filterphi_arr = m_filterphi(lev).array(mfi);
34 const auto& phi_arr = m_phi(lev).const_array(mfi);
35
36 const auto& bx_in = mfi.tilebox();
37 const auto& bx = Stencil::box(bx_in, geom);
38 if (bx.isEmpty()) {
39 return;
40 }
41
42 amrex::ParallelFor(
43 bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
44 for (int icomp = 0; icomp < ncomp; icomp++) {
45 amrex::Real fp1 = Stencil::f00;
46 amrex::Real f = Stencil::f01;
47 amrex::Real fm1 = Stencil::f02;
48 const amrex::Real filx =
49 (fp1 * phi_arr(i + 1, j, k, icomp) +
50 f * phi_arr(i, j, k, icomp) +
51 fm1 * phi_arr(i - 1, j, k, icomp));
52
53 fp1 = Stencil::f10;
54 f = Stencil::f11;
55 fm1 = Stencil::f12;
56 const amrex::Real fily =
57 (fp1 * phi_arr(i, j + 1, k, icomp) +
58 f * phi_arr(i, j, k, icomp) +
59 fm1 * phi_arr(i, j - 1, k, icomp));
60
61 fp1 = Stencil::f20;
62 f = Stencil::f21;
63 fm1 = Stencil::f22;
64 const amrex::Real filz =
65 (fp1 * phi_arr(i, j, k + 1, icomp) +
66 f * phi_arr(i, j, k, icomp) +
67 fm1 * phi_arr(i, j, k - 1, icomp));
68 filterphi_arr(i, j, k, icomp) =
69 1. / 3. * (filx + fily + filz);
70 }
71 });
72 }
73
74 FTypeOut& m_filterphi;
75 const FTypeIn& m_phi;
76};
77
84template <typename FTypeIn, typename FTypeOut>
85inline void filter(FTypeOut& filterphi, const FTypeIn& phi)
86{
87 BL_PROFILE("amr-wind::fvm::filter");
88 Filter<FTypeIn, FTypeOut> filtering(filterphi, phi);
89 impl::apply(filtering, phi);
90}
91
97template <typename FType>
98inline std::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 amr_wind::fvm
107
108#endif /* FILTER_H */
void filter(FTypeOut &filterphi, const FTypeIn &phi)
Definition filter.H:85
void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:14
Definition SchemeTraits.H:6
Definition filter.H:16
FTypeOut & m_filterphi
Definition filter.H:74
Filter(FTypeOut &filterphi, const FTypeIn &phi)
Definition filter.H:21
void apply(const int lev, const amrex::MFIter &mfi) const
Definition filter.H:29
const FTypeIn & m_phi
Definition filter.H:75