/home/runner/work/amr-wind/amr-wind/amr-wind/fvm/qcriterion.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/fvm/qcriterion.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
qcriterion.H
Go to the documentation of this file.
1#ifndef QCRITERION_H
2#define QCRITERION_H
3
5#include "AMReX_REAL.H"
6
7using namespace amrex::literals;
8
9namespace amr_wind::fvm {
10
14template <typename FTypeIn, typename FTypeOut>
16{
18 FTypeOut& qcritphi, const FTypeIn& phi, const bool nondim = false)
19 : m_qcritphi(qcritphi), m_phi(phi), m_nondim(nondim)
20 {
21 AMREX_ALWAYS_ASSERT(AMREX_SPACEDIM == m_phi.num_comp());
22 AMREX_ALWAYS_ASSERT(m_phi.num_grow() > amrex::IntVect(0));
23 }
24
25 template <typename Stencil>
26 void apply(const int lev, const amrex::MFIter& mfi) const
27 {
28 const auto& geom = m_phi.repo().mesh().Geom(lev);
29 const auto& idx = geom.InvCellSizeArray();
30 const auto& qcritphi = m_qcritphi(lev).array(mfi);
31 const auto& phi = m_phi(lev).const_array(mfi);
32 const bool nondim = m_nondim;
33
34 const auto& bx_in = mfi.tilebox();
35 const auto& bx = Stencil::box(bx_in, geom);
36 if (bx.isEmpty()) {
37 return;
38 }
39 amrex::ParallelFor(
40 bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
41 amrex::Real cp1, c, cm1, ux, uy, uz, vx, vy, vz, wx, wy, wz;
42 cp1 = Stencil::c00;
43 c = Stencil::c01;
44 cm1 = Stencil::c02;
45
46 ux = (cp1 * phi(i + 1, j, k, 0) + c * phi(i, j, k, 0) +
47 cm1 * phi(i - 1, j, k, 0)) *
48 idx[0];
49 vx = (cp1 * phi(i + 1, j, k, 1) + c * phi(i, j, k, 1) +
50 cm1 * phi(i - 1, j, k, 1)) *
51 idx[0];
52 wx = (cp1 * phi(i + 1, j, k, 2) + c * phi(i, j, k, 2) +
53 cm1 * phi(i - 1, j, k, 2)) *
54 idx[0];
55
56 cp1 = Stencil::c10;
57 c = Stencil::c11;
58 cm1 = Stencil::c12;
59
60 uy = (cp1 * phi(i, j + 1, k, 0) + c * phi(i, j, k, 0) +
61 cm1 * phi(i, j - 1, k, 0)) *
62 idx[1];
63 vy = (cp1 * phi(i, j + 1, k, 1) + c * phi(i, j, k, 1) +
64 cm1 * phi(i, j - 1, k, 1)) *
65 idx[1];
66 wy = (cp1 * phi(i, j + 1, k, 2) + c * phi(i, j, k, 2) +
67 cm1 * phi(i, j - 1, k, 2)) *
68 idx[1];
69
70 cp1 = Stencil::c20;
71 c = Stencil::c21;
72 cm1 = Stencil::c22;
73
74 uz = (cp1 * phi(i, j, k + 1, 0) + c * phi(i, j, k, 0) +
75 cm1 * phi(i, j, k - 1, 0)) *
76 idx[2];
77 vz = (cp1 * phi(i, j, k + 1, 1) + c * phi(i, j, k, 1) +
78 cm1 * phi(i, j, k - 1, 1)) *
79 idx[2];
80 wz = (cp1 * phi(i, j, k + 1, 2) + c * phi(i, j, k, 2) +
81 cm1 * phi(i, j, k - 1, 2)) *
82 idx[2];
83
84 const amrex::Real S2 =
85 std::pow(ux, 2.0_rt) + std::pow(vy, 2.0_rt) +
86 std::pow(wz, 2.0_rt) + 0.5_rt * std::pow(uy + vx, 2.0_rt) +
87 0.5_rt * std::pow(vz + wy, 2.0_rt) +
88 0.5_rt * std::pow(wx + uz, 2.0_rt);
89
90 const amrex::Real W2 = 0.5_rt * std::pow(uy - vx, 2.0_rt) +
91 0.5_rt * std::pow(vz - wy, 2.0_rt) +
92 0.5_rt * std::pow(wx - uz, 2.0_rt);
93 if (nondim) {
94 qcritphi(i, j, k) =
95 0.5_rt *
96 (W2 / amrex::max<amrex::Real>(
97 std::numeric_limits<amrex::Real>::epsilon() *
98 1.0e2_rt,
99 S2) -
100 1.0_rt);
101 } else {
102 qcritphi(i, j, k) = 0.5_rt * (W2 - S2);
103 }
104 });
105 }
106
107 FTypeOut& m_qcritphi;
108 const FTypeIn& m_phi;
110};
111
119template <typename FTypeIn, typename FTypeOut>
120inline void
121q_criterion(FTypeOut& qcritphi, const FTypeIn& phi, const bool nondim = false)
122{
123 BL_PROFILE("amr-wind::fvm::q_criterion");
124 Qcriterion<FTypeIn, FTypeOut> qcriterion(qcritphi, phi, nondim);
125 impl::apply(qcriterion, phi);
126}
127
133template <typename FType>
134inline std::unique_ptr<ScratchField> q_criterion(const FType& phi)
135{
136 const std::string gname = phi.name() + "_q_criterion";
137 auto qcritphi = phi.repo().create_scratch_field(gname, 1);
138 q_criterion(*qcritphi, phi);
139 return qcritphi;
140}
141
142} // namespace amr_wind::fvm
143
144#endif /* QCRITERION_H */
void q_criterion(FTypeOut &qcritphi, const FTypeIn &phi, const bool nondim=false)
Definition qcriterion.H:121
void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:14
Definition SchemeTraits.H:6
Definition qcriterion.H:16
FTypeOut & m_qcritphi
Definition qcriterion.H:107
bool m_nondim
Definition qcriterion.H:109
const FTypeIn & m_phi
Definition qcriterion.H:108
Qcriterion(FTypeOut &qcritphi, const FTypeIn &phi, const bool nondim=false)
Definition qcriterion.H:17
void apply(const int lev, const amrex::MFIter &mfi) const
Definition qcriterion.H:26