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

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/fvm/vorticity_mag.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
vorticity_mag.H
Go to the documentation of this file.
1#ifndef VORTICITYMAG_H
2#define VORTICITYMAG_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>
16{
17 VorticityMag(FTypeOut& vortmagphi, const FTypeIn& phi)
18 : m_vortmagphi(vortmagphi), m_phi(phi)
19 {
20 AMREX_ALWAYS_ASSERT(AMREX_SPACEDIM == m_phi.num_comp());
21 AMREX_ALWAYS_ASSERT(m_phi.num_grow() > amrex::IntVect(0));
22 }
23
24 template <typename Stencil>
25 void apply(const int lev) const
26 {
27 const auto& geom = m_phi.repo().mesh().Geom(lev);
28 const auto& idx = geom.InvCellSizeArray();
29 const auto dlo = geom.Domain().smallEnd();
30 const auto dhi = geom.Domain().bigEnd();
31
32 auto& out_mf = m_vortmagphi(lev);
33 auto const& in_arrs = m_phi(lev).const_arrays();
34 auto const& out_arrs = out_mf.arrays();
35
36 amrex::ParallelFor(
37 out_mf, amrex::IntVect(0),
38 [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) {
39 if (!Stencil::applies_to(i, j, k, dlo, dhi)) {
40 return;
41 }
42 auto const& phi = in_arrs[nbx];
43 auto const& vortmagphi = out_arrs[nbx];
44 const amrex::Real vx = (Stencil::c00 * phi(i + 1, j, k, 1) +
45 Stencil::c01 * phi(i, j, k, 1) +
46 Stencil::c02 * phi(i - 1, j, k, 1)) *
47 idx[0];
48 const amrex::Real wx = (Stencil::c00 * phi(i + 1, j, k, 2) +
49 Stencil::c01 * phi(i, j, k, 2) +
50 Stencil::c02 * phi(i - 1, j, k, 2)) *
51 idx[0];
52 const amrex::Real uy = (Stencil::c10 * phi(i, j + 1, k, 0) +
53 Stencil::c11 * phi(i, j, k, 0) +
54 Stencil::c12 * phi(i, j - 1, k, 0)) *
55 idx[1];
56 const amrex::Real wy = (Stencil::c10 * phi(i, j + 1, k, 2) +
57 Stencil::c11 * phi(i, j, k, 2) +
58 Stencil::c12 * phi(i, j - 1, k, 2)) *
59 idx[1];
60 const amrex::Real uz = (Stencil::c20 * phi(i, j, k + 1, 0) +
61 Stencil::c21 * phi(i, j, k, 0) +
62 Stencil::c22 * phi(i, j, k - 1, 0)) *
63 idx[2];
64 const amrex::Real vz = (Stencil::c20 * phi(i, j, k + 1, 1) +
65 Stencil::c21 * phi(i, j, k, 1) +
66 Stencil::c22 * phi(i, j, k - 1, 1)) *
67 idx[2];
68 vortmagphi(i, j, k) = std::sqrt(
69 utils::powi(uy - vx, 2) + utils::powi(vz - wy, 2) +
70 utils::powi(wx - uz, 2));
71 });
72 }
73
74 FTypeOut& m_vortmagphi;
75 const FTypeIn& m_phi;
76};
77
84template <typename FTypeIn, typename FTypeOut>
85void vorticity_mag(FTypeOut& vortmagphi, const FTypeIn& phi)
86{
87 BL_PROFILE("kynema-sgf::fvm::vorticity_mag");
88 VorticityMag<FTypeIn, FTypeOut> vortmag(vortmagphi, phi);
89 impl::apply(vortmag, phi);
90}
91
97template <typename FType>
98std::unique_ptr<ScratchField> vorticity_mag(const FType& phi)
99{
100 const std::string gname = phi.name() + "_vorticity_mag";
101 auto vortmagphi = phi.repo().create_scratch_field(gname, 1);
102 vorticity_mag(*vortmagphi, phi);
103 return vortmagphi;
104}
105
106} // namespace kynema_sgf::fvm
107
108#endif /* VORTICITYMAG_H */
void vorticity_mag(FTypeOut &vortmagphi, const FTypeIn &phi)
Definition vorticity_mag.H:85
AMREX_INLINE void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:20
Definition SchemeTraits.H:6
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real powi(const amrex::Real &x, const int &y)
Helper function to do pow() with integer exponents and output amrex::Real.
Definition math_ops.H:18
Definition vorticity_mag.H:16
const FTypeIn & m_phi
Definition vorticity_mag.H:75
void apply(const int lev) const
Definition vorticity_mag.H:25
FTypeOut & m_vortmagphi
Definition vorticity_mag.H:74
VorticityMag(FTypeOut &vortmagphi, const FTypeIn &phi)
Definition vorticity_mag.H:17