/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_WITH_MESSAGE(
17 m_lapphi.num_comp() == 1,
18 "m_lapphi.num_comp() = " + std::to_string(m_lapphi.num_comp()));
19 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
20 m_phi.num_comp() == AMREX_SPACEDIM,
21 "m_phi.num_comp() = " + std::to_string(m_phi.num_comp()) +
22 ", AMREX_SPACEDIM = " + std::to_string(AMREX_SPACEDIM));
23 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
24 m_phi.num_grow() > amrex::IntVect(0),
25 "m_phi.num_grow() = (" + std::to_string(m_phi.num_grow()[0]) +
26 ", " + std::to_string(m_phi.num_grow()[1]) + ", " +
27 std::to_string(m_phi.num_grow()[2]) + ")");
28 }
29
30 template <typename Stencil>
31 void apply(const int lev) const
32 {
33 const auto& geom = m_phi.repo().mesh().Geom(lev);
34 const auto& idx = geom.InvCellSizeArray();
35 const auto dlo = geom.Domain().smallEnd();
36 const auto dhi = geom.Domain().bigEnd();
37
38 auto& out_mf = m_lapphi(lev);
39 auto const& in_arrs = m_phi(lev).const_arrays();
40 auto const& out_arrs = out_mf.arrays();
41
42 amrex::ParallelFor(
43 out_mf, amrex::IntVect(0),
44 [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) {
45 if (!Stencil::applies_to(i, j, k, dlo, dhi)) {
46 return;
47 }
48 auto const& phi = in_arrs[nbx];
49 auto const& lapphi = out_arrs[nbx];
50 const amrex::Real d2phidx2 =
51 ((Stencil::s00 * phi(i + 1, j, k, 0)) +
52 (Stencil::s01 * phi(i, j, k, 0)) +
53 (Stencil::s02 * phi(i - 1, j, k, 0))) *
54 idx[0] * idx[0];
55 const amrex::Real d2phidy2 =
56 ((Stencil::s10 * phi(i, j + 1, k, 1)) +
57 (Stencil::s11 * phi(i, j, k, 1)) +
58 (Stencil::s12 * phi(i, j - 1, k, 1))) *
59 idx[1] * idx[1];
60 const amrex::Real d2phidz2 =
61 ((Stencil::s20 * phi(i, j, k + 1, 2)) +
62 (Stencil::s21 * phi(i, j, k, 2)) +
63 (Stencil::s22 * phi(i, j, k - 1, 2))) *
64 idx[2] * idx[2];
65 lapphi(i, j, k) = d2phidx2 + d2phidy2 + d2phidz2;
66 });
67 }
68
69 FTypeOut& m_lapphi;
70 const FTypeIn& m_phi;
71};
72
79template <typename FTypeIn, typename FTypeOut>
80void laplacian(FTypeOut& lapphi, const FTypeIn& phi)
81{
82 BL_PROFILE("kynema-sgf::fvm::laplacian");
83 Laplacian<FTypeIn, FTypeOut> lap(lapphi, phi);
84 impl::apply(lap, phi);
85}
86
92template <typename FType>
93std::unique_ptr<ScratchField> laplacian(const FType& phi)
94{
95 const std::string gname = phi.name() + "_laplacian";
96 auto lapphi = phi.repo().create_scratch_field(gname, 1);
97 laplacian(*lapphi, phi);
98 return lapphi;
99}
100
101} // namespace kynema_sgf::fvm
102
103#endif /* LAPLACIAN_H */
void laplacian(FTypeOut &lapphi, const FTypeIn &phi)
Definition laplacian.H:80
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:69
Laplacian(FTypeOut &lphi, const FTypeIn &phi)
Definition laplacian.H:14
void apply(const int lev) const
Definition laplacian.H:31
const FTypeIn & m_phi
Definition laplacian.H:70