/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_WITH_MESSAGE(
21 AMREX_SPACEDIM == m_phi.num_comp(),
22 "AMREX_SPACEDIM = " + std::to_string(AMREX_SPACEDIM) +
23 ", m_phi.num_comp() = " + std::to_string(m_phi.num_comp()));
24 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
25 m_phi.num_grow() > amrex::IntVect(0),
26 "m_phi.num_grow() = (" + std::to_string(m_phi.num_grow()[0]) +
27 ", " + std::to_string(m_phi.num_grow()[1]) + ", " +
28 std::to_string(m_phi.num_grow()[2]) + ")");
29 }
30
31 template <typename Stencil>
32 void apply(const int lev) const
33 {
34 const auto& geom = m_phi.repo().mesh().Geom(lev);
35 const auto& idx = geom.InvCellSizeArray();
36 const auto dlo = geom.Domain().smallEnd();
37 const auto dhi = geom.Domain().bigEnd();
38
39 auto& out_mf = m_strphi(lev);
40 auto const& in_arrs = m_phi(lev).const_arrays();
41 auto const& out_arrs = out_mf.arrays();
42
43 amrex::ParallelFor(
44 out_mf, amrex::IntVect(0),
45 [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) {
46 if (!Stencil::applies_to(i, j, k, dlo, dhi)) {
47 return;
48 }
49 auto const& phi = in_arrs[nbx];
50 auto const& strphi = out_arrs[nbx];
51 const amrex::Real ux = ((Stencil::c00 * phi(i + 1, j, k, 0)) +
52 (Stencil::c01 * phi(i, j, k, 0)) +
53 (Stencil::c02 * phi(i - 1, j, k, 0))) *
54 idx[0];
55 const amrex::Real vx = ((Stencil::c00 * phi(i + 1, j, k, 1)) +
56 (Stencil::c01 * phi(i, j, k, 1)) +
57 (Stencil::c02 * phi(i - 1, j, k, 1))) *
58 idx[0];
59 const amrex::Real wx = ((Stencil::c00 * phi(i + 1, j, k, 2)) +
60 (Stencil::c01 * phi(i, j, k, 2)) +
61 (Stencil::c02 * phi(i - 1, j, k, 2))) *
62 idx[0];
63 const amrex::Real uy = ((Stencil::c10 * phi(i, j + 1, k, 0)) +
64 (Stencil::c11 * phi(i, j, k, 0)) +
65 (Stencil::c12 * phi(i, j - 1, k, 0))) *
66 idx[1];
67 const amrex::Real vy = ((Stencil::c10 * phi(i, j + 1, k, 1)) +
68 (Stencil::c11 * phi(i, j, k, 1)) +
69 (Stencil::c12 * phi(i, j - 1, k, 1))) *
70 idx[1];
71 const amrex::Real wy = ((Stencil::c10 * phi(i, j + 1, k, 2)) +
72 (Stencil::c11 * phi(i, j, k, 2)) +
73 (Stencil::c12 * phi(i, j - 1, k, 2))) *
74 idx[1];
75 const amrex::Real uz = ((Stencil::c20 * phi(i, j, k + 1, 0)) +
76 (Stencil::c21 * phi(i, j, k, 0)) +
77 (Stencil::c22 * phi(i, j, k - 1, 0))) *
78 idx[2];
79 const amrex::Real vz = ((Stencil::c20 * phi(i, j, k + 1, 1)) +
80 (Stencil::c21 * phi(i, j, k, 1)) +
81 (Stencil::c22 * phi(i, j, k - 1, 1))) *
82 idx[2];
83 const amrex::Real wz = ((Stencil::c20 * phi(i, j, k + 1, 2)) +
84 (Stencil::c21 * phi(i, j, k, 2)) +
85 (Stencil::c22 * phi(i, j, k - 1, 2))) *
86 idx[2];
87 strphi(i, j, k) = std::sqrt(
88 (2.0_rt * utils::powi(ux, 2)) +
89 (2.0_rt * utils::powi(vy, 2)) +
90 (2.0_rt * utils::powi(wz, 2)) + utils::powi(uy + vx, 2) +
91 utils::powi(vz + wy, 2) + utils::powi(wx + uz, 2));
92 });
93 }
94
95 FTypeOut& m_strphi;
96 const FTypeIn& m_phi;
97};
98
105template <typename FTypeIn, typename FTypeOut>
106void strainrate(FTypeOut& strphi, const FTypeIn& phi)
107{
108 BL_PROFILE("kynema-sgf::fvm::strainrate");
109 StrainRate<FTypeIn, FTypeOut> str(strphi, phi);
110 impl::apply(str, phi);
111}
112
118template <typename FType>
119std::unique_ptr<ScratchField> strainrate(const FType& phi)
120{
121 const std::string gname = phi.name() + "_strainrate";
122 auto strphi = phi.repo().create_scratch_field(gname, 1);
123 strainrate(*strphi, phi);
124 return strphi;
125}
126
127} // namespace kynema_sgf::fvm
128
129#endif /* STRAINRATE_H */
void strainrate(FTypeOut &strphi, const FTypeIn &phi)
Definition strainrate.H:106
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:32
const FTypeIn & m_phi
Definition strainrate.H:96
FTypeOut & m_strphi
Definition strainrate.H:95
StrainRate(FTypeOut &strphi, const FTypeIn &phi)
Definition strainrate.H:17