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

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/fvm/curvature.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
curvature.H
Go to the documentation of this file.
1#ifndef CURVATURE_H
2#define CURVATURE_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 Curvature(FTypeOut& curphi, const FTypeIn& phi)
18 : m_curphi(curphi), m_phi(phi)
19 {
20 AMREX_ALWAYS_ASSERT(m_phi.num_comp() == m_curphi.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 const int ncomp = m_phi.num_comp();
32
33 auto& out_mf = m_curphi(lev);
34 auto const& in_arrs = m_phi(lev).const_arrays();
35 auto const& out_arrs = out_mf.arrays();
36
37 amrex::ParallelFor(
38 out_mf, amrex::IntVect(0),
39 [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) {
40 if (!Stencil::applies_to(i, j, k, dlo, dhi)) {
41 return;
42 }
43 auto const& phi = in_arrs[nbx];
44 auto const& curphi = out_arrs[nbx];
45 for (int n = 0; n < ncomp; ++n) {
46 const amrex::Real phixx =
47 (Stencil::s00 * phi(i + 1, j, k, n) +
48 Stencil::s01 * phi(i, j, k, n) +
49 Stencil::s02 * phi(i - 1, j, k, n)) *
50 idx[0] * idx[0];
51 const amrex::Real phiyy =
52 (Stencil::s10 * phi(i, j + 1, k, n) +
53 Stencil::s11 * phi(i, j, k, n) +
54 Stencil::s12 * phi(i, j - 1, k, n)) *
55 idx[1] * idx[1];
56 const amrex::Real phizz =
57 (Stencil::s20 * phi(i, j, k + 1, n) +
58 Stencil::s21 * phi(i, j, k, n) +
59 Stencil::s22 * phi(i, j, k - 1, n)) *
60 idx[2] * idx[2];
61 const amrex::Real phiz =
62 (Stencil::c20 * phi(i, j, k + 1, n) +
63 Stencil::c21 * phi(i, j, k, n) +
64 Stencil::c22 * phi(i, j, k - 1, n)) *
65 idx[2];
66 const amrex::Real phiz_ip1 =
67 (Stencil::c20 * phi(i + 1, j, k + 1, n) +
68 Stencil::c21 * phi(i + 1, j, k, n) +
69 Stencil::c22 * phi(i + 1, j, k - 1, n)) *
70 idx[2];
71 const amrex::Real phiz_im1 =
72 (Stencil::c20 * phi(i - 1, j, k + 1, n) +
73 Stencil::c21 * phi(i - 1, j, k, n) +
74 Stencil::c22 * phi(i - 1, j, k - 1, n)) *
75 idx[2];
76 const amrex::Real phiz_jp1 =
77 (Stencil::c20 * phi(i, j + 1, k + 1, n) +
78 Stencil::c21 * phi(i, j + 1, k, n) +
79 Stencil::c22 * phi(i, j + 1, k - 1, n)) *
80 idx[2];
81 const amrex::Real phiz_jm1 =
82 (Stencil::c20 * phi(i, j - 1, k + 1, n) +
83 Stencil::c21 * phi(i, j - 1, k, n) +
84 Stencil::c22 * phi(i, j - 1, k - 1, n)) *
85 idx[2];
86 const amrex::Real phiy =
87 (Stencil::c10 * phi(i, j + 1, k, n) +
88 Stencil::c11 * phi(i, j, k, n) +
89 Stencil::c12 * phi(i, j - 1, k, n)) *
90 idx[1];
91 const amrex::Real phiy_ip1 =
92 (Stencil::c10 * phi(i + 1, j + 1, k, n) +
93 Stencil::c11 * phi(i + 1, j, k, n) +
94 Stencil::c12 * phi(i + 1, j - 1, k, n)) *
95 idx[1];
96 const amrex::Real phiy_im1 =
97 (Stencil::c10 * phi(i - 1, j + 1, k, n) +
98 Stencil::c11 * phi(i - 1, j, k, n) +
99 Stencil::c12 * phi(i - 1, j - 1, k, n)) *
100 idx[1];
101 const amrex::Real phiyz =
102 (Stencil::c10 * phiz_jp1 + Stencil::c11 * phiz +
103 Stencil::c12 * phiz_jm1) *
104 idx[1];
105 const amrex::Real phix =
106 (Stencil::c00 * phi(i + 1, j, k, n) +
107 Stencil::c01 * phi(i, j, k, n) +
108 Stencil::c02 * phi(i - 1, j, k, n)) *
109 idx[0];
110 const amrex::Real phixy =
111 (Stencil::c00 * phiy_ip1 + Stencil::c01 * phiy +
112 Stencil::c02 * phiy_im1) *
113 idx[0];
114 const amrex::Real phixz =
115 (Stencil::c00 * phiz_ip1 + Stencil::c01 * phiz +
116 Stencil::c02 * phiz_im1) *
117 idx[0];
118 curphi(i, j, k, n) =
119 -((phix * phix * phiyy) -
120 (2.0_rt * phix * phiy * phixy) +
121 (phiy * phiy * phixx) + (phix * phix * phizz) -
122 (2.0_rt * phix * phiz * phixz) +
123 (phiz * phiz * phixx) + (phiy * phiy * phizz) -
124 (2.0_rt * phiy * phiz * phiyz) +
125 (phiz * phiz * phiyy)) /
126 std::pow(
127 (phix * phix) + (phiy * phiy) + (phiz * phiz),
128 1.5_rt);
129 }
130 });
131 }
132
133 FTypeOut& m_curphi;
134 const FTypeIn& m_phi;
135};
136
140template <typename FTypeIn, typename FTypeOut>
141void curvature(FTypeOut& curphi, const FTypeIn& phi)
142{
143 BL_PROFILE("kynema-sgf::fvm::curvature");
144 Curvature<FTypeIn, FTypeOut> cur(curphi, phi);
145 impl::apply(cur, phi);
146}
147
151template <typename FType>
152std::unique_ptr<ScratchField> curvature(const FType& phi)
153{
154 const std::string gname = phi.name() + "_curvature";
155 auto curphi = phi.repo().create_scratch_field(gname, phi.num_comp());
156 curvature(*curphi, phi);
157 return curphi;
158}
159
160} // namespace kynema_sgf::fvm
161
162#endif /* CURVATURE_H */
void curvature(FTypeOut &curphi, const FTypeIn &phi)
Definition curvature.H:141
AMREX_INLINE void apply(const FvmOp &fvmop, const FType &fld)
Definition fvm_utils.H:20
Definition SchemeTraits.H:6
Definition curvature.H:16
void apply(const int lev) const
Definition curvature.H:25
Curvature(FTypeOut &curphi, const FTypeIn &phi)
Definition curvature.H:17
const FTypeIn & m_phi
Definition curvature.H:134
FTypeOut & m_curphi
Definition curvature.H:133