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

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/fvm/vorticity.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
vorticity.H
Go to the documentation of this file.
1#ifndef VORTICITY_H
2#define VORTICITY_H
3
4#include "src/fvm/fvm_utils.H"
5
6namespace kynema_sgf::fvm {
7
11template <typename FTypeIn, typename FTypeOut>
13{
14 Vorticity(FTypeOut& vortphi, const FTypeIn& phi)
15 : m_vort(vortphi), m_phi(phi)
16 {
17 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
18 AMREX_SPACEDIM == m_phi.num_comp(),
19 "AMREX_SPACEDIM = " + std::to_string(AMREX_SPACEDIM) +
20 ", m_phi.num_comp() = " + std::to_string(m_phi.num_comp()));
21 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
22 m_phi.num_grow() > amrex::IntVect(0),
23 "m_phi.num_grow() = (" + std::to_string(m_phi.num_grow()[0]) +
24 ", " + std::to_string(m_phi.num_grow()[1]) + ", " +
25 std::to_string(m_phi.num_grow()[2]) + ")");
26 }
27
28 template <typename Stencil>
29 void apply(const int lev) const
30 {
31 const auto& geom = m_phi.repo().mesh().Geom(lev);
32 const auto& idx = geom.InvCellSizeArray();
33 const auto dlo = geom.Domain().smallEnd();
34 const auto dhi = geom.Domain().bigEnd();
35
36 auto& out_mf = m_vort(lev);
37 auto const& in_arrs = m_phi(lev).const_arrays();
38 auto const& out_arrs = out_mf.arrays();
39
40 amrex::ParallelFor(
41 out_mf, amrex::IntVect(0),
42 [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) {
43 if (!Stencil::applies_to(i, j, k, dlo, dhi)) {
44 return;
45 }
46 auto const& phi = in_arrs[nbx];
47 auto const& vort = out_arrs[nbx];
48 const amrex::Real vx = ((Stencil::c00 * phi(i + 1, j, k, 1)) +
49 (Stencil::c01 * phi(i, j, k, 1)) +
50 (Stencil::c02 * phi(i - 1, j, k, 1))) *
51 idx[0];
52 const amrex::Real wx = ((Stencil::c00 * phi(i + 1, j, k, 2)) +
53 (Stencil::c01 * phi(i, j, k, 2)) +
54 (Stencil::c02 * phi(i - 1, j, k, 2))) *
55 idx[0];
56 const amrex::Real uy = ((Stencil::c10 * phi(i, j + 1, k, 0)) +
57 (Stencil::c11 * phi(i, j, k, 0)) +
58 (Stencil::c12 * phi(i, j - 1, k, 0))) *
59 idx[1];
60 const amrex::Real wy = ((Stencil::c10 * phi(i, j + 1, k, 2)) +
61 (Stencil::c11 * phi(i, j, k, 2)) +
62 (Stencil::c12 * phi(i, j - 1, k, 2))) *
63 idx[1];
64 const amrex::Real uz = ((Stencil::c20 * phi(i, j, k + 1, 0)) +
65 (Stencil::c21 * phi(i, j, k, 0)) +
66 (Stencil::c22 * phi(i, j, k - 1, 0))) *
67 idx[2];
68 const amrex::Real vz = ((Stencil::c20 * phi(i, j, k + 1, 1)) +
69 (Stencil::c21 * phi(i, j, k, 1)) +
70 (Stencil::c22 * phi(i, j, k - 1, 1))) *
71 idx[2];
72 vort(i, j, k, 0) = wy - vz;
73 vort(i, j, k, 1) = uz - wx;
74 vort(i, j, k, 2) = vx - uy;
75 });
76 }
77
78 FTypeOut& m_vort;
79 const FTypeIn& m_phi;
80};
81
88template <typename FTypeIn, typename FTypeOut>
89void vorticity(FTypeOut& vortphi, const FTypeIn& phi)
90{
91 BL_PROFILE("kynema-sgf::fvm::vorticity");
92 Vorticity<FTypeIn, FTypeOut> vort(vortphi, phi);
93 impl::apply(vort, phi);
94}
95
101template <typename FType>
102std::unique_ptr<ScratchField> vorticity(const FType& phi)
103{
104 const std::string gname = phi.name() + "_vorticity";
105 auto vortphi = phi.repo().create_scratch_field(gname, AMREX_SPACEDIM);
106 vorticity(*vortphi, phi);
107 return vortphi;
108}
109
110} // namespace kynema_sgf::fvm
111
112#endif /* VORTICITY_H */
void vorticity(FTypeOut &vortphi, const FTypeIn &phi)
Definition vorticity.H:89
AMREX_INLINE void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:20
Definition SchemeTraits.H:6
Definition vorticity.H:13
void apply(const int lev) const
Definition vorticity.H:29
FTypeOut & m_vort
Definition vorticity.H:78
const FTypeIn & m_phi
Definition vorticity.H:79
Vorticity(FTypeOut &vortphi, const FTypeIn &phi)
Definition vorticity.H:14