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

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/fvm/strainrate.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
strainrate.H
Go to the documentation of this file.
1#ifndef STRAINRATE_H
2#define STRAINRATE_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 StrainRate(FTypeOut& strphi, const FTypeIn& phi)
18 : m_strphi(strphi), 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_strphi(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& strphi = out_arrs[nbx];
44 const amrex::Real ux = (Stencil::c00 * phi(i + 1, j, k, 0) +
45 Stencil::c01 * phi(i, j, k, 0) +
46 Stencil::c02 * phi(i - 1, j, k, 0)) *
47 idx[0];
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 vy = (Stencil::c10 * phi(i, j + 1, k, 1) +
61 Stencil::c11 * phi(i, j, k, 1) +
62 Stencil::c12 * phi(i, j - 1, k, 1)) *
63 idx[1];
64 const amrex::Real wy = (Stencil::c10 * phi(i, j + 1, k, 2) +
65 Stencil::c11 * phi(i, j, k, 2) +
66 Stencil::c12 * phi(i, j - 1, k, 2)) *
67 idx[1];
68 const amrex::Real uz = (Stencil::c20 * phi(i, j, k + 1, 0) +
69 Stencil::c21 * phi(i, j, k, 0) +
70 Stencil::c22 * phi(i, j, k - 1, 0)) *
71 idx[2];
72 const amrex::Real vz = (Stencil::c20 * phi(i, j, k + 1, 1) +
73 Stencil::c21 * phi(i, j, k, 1) +
74 Stencil::c22 * phi(i, j, k - 1, 1)) *
75 idx[2];
76 const amrex::Real wz = (Stencil::c20 * phi(i, j, k + 1, 2) +
77 Stencil::c21 * phi(i, j, k, 2) +
78 Stencil::c22 * phi(i, j, k - 1, 2)) *
79 idx[2];
80 strphi(i, j, k) = std::sqrt(
81 (2.0_rt * utils::powi(ux, 2)) +
82 (2.0_rt * utils::powi(vy, 2)) +
83 (2.0_rt * utils::powi(wz, 2)) + utils::powi(uy + vx, 2) +
84 utils::powi(vz + wy, 2) + utils::powi(wx + uz, 2));
85 });
86 }
87
88 FTypeOut& m_strphi;
89 const FTypeIn& m_phi;
90};
91
98template <typename FTypeIn, typename FTypeOut>
99void strainrate(FTypeOut& strphi, const FTypeIn& phi)
100{
101 BL_PROFILE("kynema-sgf::fvm::strainrate");
102 StrainRate<FTypeIn, FTypeOut> str(strphi, phi);
103 impl::apply(str, phi);
104}
105
111template <typename FType>
112std::unique_ptr<ScratchField> strainrate(const FType& phi)
113{
114 const std::string gname = phi.name() + "_strainrate";
115 auto strphi = phi.repo().create_scratch_field(gname, 1);
116 strainrate(*strphi, phi);
117 return strphi;
118}
119
120} // namespace kynema_sgf::fvm
121
122#endif /* STRAINRATE_H */
void strainrate(FTypeOut &strphi, const FTypeIn &phi)
Definition strainrate.H:99
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 strainrate.H:16
void apply(const int lev) const
Definition strainrate.H:25
const FTypeIn & m_phi
Definition strainrate.H:89
FTypeOut & m_strphi
Definition strainrate.H:88
StrainRate(FTypeOut &strphi, const FTypeIn &phi)
Definition strainrate.H:17