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

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/fvm/laplacian.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
laplacian.H
Go to the documentation of this file.
1#ifndef LAPLACIAN_H
2#define LAPLACIAN_H
3
4#include "src/fvm/fvm_utils.H"
5
6namespace kynema_sgf::fvm {
7
11template <typename FTypeIn, typename FTypeOut>
13{
14 Laplacian(FTypeOut& lphi, const FTypeIn& phi) : m_lapphi(lphi), m_phi(phi)
15 {
16 AMREX_ALWAYS_ASSERT(m_lapphi.num_comp() == 1);
17 AMREX_ALWAYS_ASSERT(m_phi.num_comp() == AMREX_SPACEDIM);
18 AMREX_ALWAYS_ASSERT(m_phi.num_grow() > amrex::IntVect(0));
19 }
20
21 template <typename Stencil>
22 void apply(const int lev) const
23 {
24 const auto& geom = m_phi.repo().mesh().Geom(lev);
25 const auto& idx = geom.InvCellSizeArray();
26 const auto dlo = geom.Domain().smallEnd();
27 const auto dhi = geom.Domain().bigEnd();
28
29 auto& out_mf = m_lapphi(lev);
30 auto const& in_arrs = m_phi(lev).const_arrays();
31 auto const& out_arrs = out_mf.arrays();
32
33 amrex::ParallelFor(
34 out_mf, amrex::IntVect(0),
35 [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) {
36 if (!Stencil::applies_to(i, j, k, dlo, dhi)) {
37 return;
38 }
39 auto const& phi = in_arrs[nbx];
40 auto const& lapphi = out_arrs[nbx];
41 const amrex::Real d2phidx2 =
42 (Stencil::s00 * phi(i + 1, j, k, 0) +
43 Stencil::s01 * phi(i, j, k, 0) +
44 Stencil::s02 * phi(i - 1, j, k, 0)) *
45 idx[0] * idx[0];
46 const amrex::Real d2phidy2 =
47 (Stencil::s10 * phi(i, j + 1, k, 1) +
48 Stencil::s11 * phi(i, j, k, 1) +
49 Stencil::s12 * phi(i, j - 1, k, 1)) *
50 idx[1] * idx[1];
51 const amrex::Real d2phidz2 =
52 (Stencil::s20 * phi(i, j, k + 1, 2) +
53 Stencil::s21 * phi(i, j, k, 2) +
54 Stencil::s22 * phi(i, j, k - 1, 2)) *
55 idx[2] * idx[2];
56 lapphi(i, j, k) = d2phidx2 + d2phidy2 + d2phidz2;
57 });
58 }
59
60 FTypeOut& m_lapphi;
61 const FTypeIn& m_phi;
62};
63
70template <typename FTypeIn, typename FTypeOut>
71void laplacian(FTypeOut& lapphi, const FTypeIn& phi)
72{
73 BL_PROFILE("kynema-sgf::fvm::laplacian");
74 Laplacian<FTypeIn, FTypeOut> lap(lapphi, phi);
75 impl::apply(lap, phi);
76}
77
83template <typename FType>
84std::unique_ptr<ScratchField> laplacian(const FType& phi)
85{
86 const std::string gname = phi.name() + "_laplacian";
87 auto lapphi = phi.repo().create_scratch_field(gname, 1);
88 laplacian(*lapphi, phi);
89 return lapphi;
90}
91
92} // namespace kynema_sgf::fvm
93
94#endif /* LAPLACIAN_H */
void laplacian(FTypeOut &lapphi, const FTypeIn &phi)
Definition laplacian.H:71
AMREX_INLINE void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:20
Definition SchemeTraits.H:6
Definition laplacian.H:13
FTypeOut & m_lapphi
Definition laplacian.H:60
Laplacian(FTypeOut &lphi, const FTypeIn &phi)
Definition laplacian.H:14
void apply(const int lev) const
Definition laplacian.H:22
const FTypeIn & m_phi
Definition laplacian.H:61