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

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/fvm/vorticity.H Source File
AMR-Wind 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
5
6namespace amr_wind::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(AMREX_SPACEDIM == m_phi.num_comp());
18 AMREX_ALWAYS_ASSERT(m_phi.num_grow() > amrex::IntVect(0));
19 }
20
21 template <typename Stencil>
22 void apply(const int lev, const amrex::MFIter& mfi) const
23 {
24 const auto& geom = m_phi.repo().mesh().Geom(lev);
25 const auto& idx = geom.InvCellSizeArray();
26 const auto& vort = m_vort(lev).array(mfi);
27 const auto& phi = m_phi(lev).const_array(mfi);
28
29 const auto& bx_in = mfi.tilebox();
30 const auto& bx = Stencil::box(bx_in, geom);
31 if (bx.isEmpty()) {
32 return;
33 }
34
35 amrex::ParallelFor(
36 bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
37 amrex::Real cp1, c, cm1, uy, uz, vx, vz, wx, wy;
38 cp1 = Stencil::c00;
39 c = Stencil::c01;
40 cm1 = Stencil::c02;
41
42 vx = (cp1 * phi(i + 1, j, k, 1) + c * phi(i, j, k, 1) +
43 cm1 * phi(i - 1, j, k, 1)) *
44 idx[0];
45 wx = (cp1 * phi(i + 1, j, k, 2) + c * phi(i, j, k, 2) +
46 cm1 * phi(i - 1, j, k, 2)) *
47 idx[0];
48
49 cp1 = Stencil::c10;
50 c = Stencil::c11;
51 cm1 = Stencil::c12;
52
53 uy = (cp1 * phi(i, j + 1, k, 0) + c * phi(i, j, k, 0) +
54 cm1 * phi(i, j - 1, k, 0)) *
55 idx[1];
56 wy = (cp1 * phi(i, j + 1, k, 2) + c * phi(i, j, k, 2) +
57 cm1 * phi(i, j - 1, k, 2)) *
58 idx[1];
59
60 cp1 = Stencil::c20;
61 c = Stencil::c21;
62 cm1 = Stencil::c22;
63
64 uz = (cp1 * phi(i, j, k + 1, 0) + c * phi(i, j, k, 0) +
65 cm1 * phi(i, j, k - 1, 0)) *
66 idx[2];
67 vz = (cp1 * phi(i, j, k + 1, 1) + c * phi(i, j, k, 1) +
68 cm1 * phi(i, j, k - 1, 1)) *
69 idx[2];
70
71 vort(i, j, k, 0) = wy - vz;
72 vort(i, j, k, 1) = uz - wx;
73 vort(i, j, k, 2) = vx - uy;
74 });
75 }
76
77 FTypeOut& m_vort;
78 const FTypeIn& m_phi;
79};
80
87template <typename FTypeIn, typename FTypeOut>
88inline void vorticity(FTypeOut& vortphi, const FTypeIn& phi)
89{
90 BL_PROFILE("amr-wind::fvm::vorticity");
91 Vorticity<FTypeIn, FTypeOut> vort(vortphi, phi);
92 impl::apply(vort, phi);
93}
94
100template <typename FType>
101inline std::unique_ptr<ScratchField> vorticity(const FType& phi)
102{
103 const std::string gname = phi.name() + "_vorticity";
104 auto vortphi = phi.repo().create_scratch_field(gname, AMREX_SPACEDIM);
105 vorticity(*vortphi, phi);
106 return vortphi;
107}
108
109} // namespace amr_wind::fvm
110
111#endif /* VORTICITY_H */
void vorticity(FTypeOut &vortphi, const FTypeIn &phi)
Definition vorticity.H:88
void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:14
Definition SchemeTraits.H:6
Definition vorticity.H:13
const FTypeIn & m_phi
Definition vorticity.H:78
Vorticity(FTypeOut &vortphi, const FTypeIn &phi)
Definition vorticity.H:14
void apply(const int lev, const amrex::MFIter &mfi) const
Definition vorticity.H:22
FTypeOut & m_vort
Definition vorticity.H:77