3434
3535/* !
3636 * \brief Blended difference for U-MUSCL reconstruction.
37- * \param[in] grad_proj - Gradient projection at point i: dot(grad_i, vector_ij)
38- * \param[in] delta - Centered difference: V_j - V_i
39- * \param[in] kappa - Blending parameter
40- * \return Blended difference for reconstruction
37+ * \param[in] grad_proj - Gradient projection at point i: dot(grad_i, vector_ij).
38+ * \param[in] delta - Centered difference: V_j - V_i.
39+ * \param[in] kappa - Blending parameter.
40+ * \return Blended difference for reconstruction from point i.
4141 */
4242FORCEINLINE Double umusclProjection (Double grad_proj,
4343 Double delta,
4444 Double kappa) {
4545 /* -------------------------------------------------------------------*/
4646 /* --- Reconstruction will be V_L = V_i + 0.25 * dV_ij^kappa. ---*/
47- /* --- Scale dV_ij^cent by 0.5 here and return 0.5 * dV_ij^kappa ---*/
47+ /* --- Scale dV_ij^cent by 0.5 here and return 0.5 * dV_ij^kappa ---*/
4848 /* --- for backward compatibility (i.e. when kappa==0 and this ---*/
4949 /* --- function isn't called, the reconstruction will be ---*/
5050 /* --- V_L = V_i + 0.5 * proj, otherwise V_L = V_i + 0.5 * blend). ---*/
@@ -58,6 +58,36 @@ FORCEINLINE Double umusclProjection(Double grad_proj,
5858 return (1.0 - kappa) * upw + (1.0 + kappa) * cent;
5959}
6060
61+ /* !
62+ * \brief MUSCL reconstruction of the specified variable.
63+ * \param[in] grad_i - Gradient vector at point i.
64+ * \param[in] delta - Centered difference: V_j - V_i.
65+ * \param[in] vector_ij - Distance vector from i to j.
66+ * \param[in] iVar - Variable index.
67+ * \param[in] umuscl - If true, use U-MUSCL blended difference.
68+ * \param[in] kappa - Blending coefficient.
69+ * \param[in] relax - Newton-Krylov relaxation.
70+ * \return Variable reconstructed from point i.
71+ */
72+ template <class GradType , size_t nDim>
73+ FORCEINLINE Double musclReconstruction (const GradType& grad,
74+ const Double delta,
75+ const VectorDbl<nDim>& vector_ij,
76+ size_t iVar,
77+ bool umuscl,
78+ Double kappa,
79+ Double relax) {
80+ /* --- Gradient projection ---*/
81+ Double proj = dot (grad[iVar], vector_ij);
82+
83+ if (umuscl) {
84+ /* --- Blended difference: dV_ij^kappa = (1-kappa)dV_ij^upw + (1+kappa)dV_ij^cent ---*/
85+ proj = umusclProjection (proj, delta, kappa);
86+ }
87+
88+ return relax * proj;
89+ }
90+
6191/* !
6292 * \brief Unlimited reconstruction.
6393 */
@@ -72,28 +102,22 @@ FORCEINLINE void musclUnlimited(Int iPoint,
72102 Double relax) {
73103 constexpr auto nVarGrad = nVarGrad_ > 0 ? nVarGrad_ : VarType::nVar;
74104
75- const auto scale = 0.5 * relax;
76-
77105 auto grad_i = gatherVariables<nVarGrad,nDim>(iPoint, gradient);
78106 auto grad_j = gatherVariables<nVarGrad,nDim>(jPoint, gradient);
79107
80108 for (size_t iVar = 0 ; iVar < nVarGrad; ++iVar) {
81- /* --- Gradient projections ---*/
82- Double proj_i = dot (grad_i[iVar], vector_ij);
83- Double proj_j = dot (grad_j[iVar], vector_ij);
109+ /* --- Centered difference, only needed for U-MUSCL projection ---*/
110+ Double delta_ij = 0.0 ;
111+ if (umuscl)
112+ delta_ij = V.j .all (iVar) - V.i .all (iVar);
84113
85- if (umuscl) {
86- /* --- Centered difference: dV_ij^cent = V_j - V_i ---*/
87- const Double cent = V.j .all (iVar) - V.i .all (iVar);
88-
89- /* --- Blended difference: dV_ij^kappa = (1-kappa)dV_ij^upw + (1+kappa)dV_ij^cent ---*/
90- proj_i = umusclProjection (proj_i, cent, kappa);
91- proj_j = umusclProjection (proj_j, cent, kappa);
92- }
114+ /* --- U-MUSCL reconstructed variables ---*/
115+ const Double proj_i = musclReconstruction (grad_i, delta_ij, vector_ij, iVar, umuscl, kappa, relax);
116+ const Double proj_j = musclReconstruction (grad_j, delta_ij, vector_ij, iVar, umuscl, kappa, relax);
93117
94118 /* --- Apply reconstruction: V_L = V_i + 0.25 * dV_ij^kappa ---*/
95- V.i .all (iVar) += scale * proj_i;
96- V.j .all (iVar) -= scale * proj_j;
119+ V.i .all (iVar) += 0.5 * proj_i;
120+ V.j .all (iVar) -= 0.5 * proj_j;
97121 }
98122}
99123
@@ -112,31 +136,25 @@ FORCEINLINE void musclPointLimited(Int iPoint,
112136 Double relax) {
113137 constexpr auto nVarGrad = nVarGrad_ > 0 ? nVarGrad_ : VarType::nVar;
114138
115- const auto scale = 0.5 * relax;
116-
117139 auto lim_i = gatherVariables<nVarGrad>(iPoint, limiter);
118140 auto lim_j = gatherVariables<nVarGrad>(jPoint, limiter);
119141
120142 auto grad_i = gatherVariables<nVarGrad,nDim>(iPoint, gradient);
121143 auto grad_j = gatherVariables<nVarGrad,nDim>(jPoint, gradient);
122144
123145 for (size_t iVar = 0 ; iVar < nVarGrad; ++iVar) {
124- /* --- Gradient projections ---*/
125- Double proj_i = dot (grad_i[iVar], vector_ij);
126- Double proj_j = dot (grad_j[iVar], vector_ij);
146+ /* --- Centered difference, only needed for U-MUSCL projection ---*/
147+ Double delta_ij = 0.0 ;
148+ if (umuscl)
149+ delta_ij = V.j .all (iVar) - V.i .all (iVar);
127150
128- if (umuscl) {
129- /* --- Centered difference: dV_ij^cent = Vj - Vi ---*/
130- const Double cent = V.j .all (iVar) - V.i .all (iVar);
131-
132- /* --- Blended difference: dV_ij^kappa = (1-kappa)dV_ij^upw + (1+kappa)dV_ij^cent ---*/
133- proj_i = umusclProjection (proj_i, cent, kappa);
134- proj_j = umusclProjection (proj_j, cent, kappa);
135- }
151+ /* --- U-MUSCL reconstructed variables ---*/
152+ const Double proj_i = musclReconstruction (grad_i, delta_ij, vector_ij, iVar, umuscl, kappa, relax);
153+ const Double proj_j = musclReconstruction (grad_j, delta_ij, vector_ij, iVar, umuscl, kappa, relax);
136154
137155 /* --- Apply reconstruction: V_L = V_i + 0.25 * lim * dV_ij^kappa ---*/
138- V.i .all (iVar) += scale * lim_i (iVar) * proj_i;
139- V.j .all (iVar) -= scale * lim_j (iVar) * proj_j;
156+ V.i .all (iVar) += 0.5 * lim_i (iVar) * proj_i;
157+ V.j .all (iVar) -= 0.5 * lim_j (iVar) * proj_j;
140158 }
141159}
142160
@@ -154,31 +172,24 @@ FORCEINLINE void musclEdgeLimited(Int iPoint,
154172 Double relax) {
155173 constexpr auto nVarGrad = nVarGrad_ > 0 ? nVarGrad_ : VarType::nVar;
156174
157- const auto scale = 0.5 * relax;
158-
159175 auto grad_i = gatherVariables<nVarGrad,nDim>(iPoint, gradient);
160176 auto grad_j = gatherVariables<nVarGrad,nDim>(jPoint, gradient);
161177
162178 for (size_t iVar = 0 ; iVar < nVarGrad; ++iVar) {
163- Double proj_i = dot (grad_i[iVar], vector_ij);
164- Double proj_j = dot (grad_j[iVar], vector_ij);
179+ /* --- Centered difference, needed for U-MUSCL projection and limiter ---*/
165180 const Double delta_ij = V.j .all (iVar) - V.i .all (iVar);
166181 const Double delta_ij_2 = pow (delta_ij, 2 ) + 1e-6 ;
167182
168- if (umuscl) {
169- /* --- Centered difference: dV_ij^cent = V_j - V_i ---*/
170- const Double cent = V.j .all (iVar) - V.i .all (iVar);
171-
172- /* --- Blended difference: dV_ij^kappa = (1-kappa)dV_ij^upw + (1+kappa)dV_ij^cent ---*/
173- proj_i = umusclProjection (proj_i, cent, kappa);
174- proj_j = umusclProjection (proj_j, cent, kappa);
175- }
183+ /* --- U-MUSCL reconstructed variables ---*/
184+ const Double proj_i = musclReconstruction (grad_i, delta_ij, vector_ij, iVar, umuscl, kappa, relax);
185+ const Double proj_j = musclReconstruction (grad_j, delta_ij, vector_ij, iVar, umuscl, kappa, relax);
176186
177187 // / TODO: Customize the limiter function.
178188 const Double lim_i = (delta_ij_2 + proj_i*delta_ij) / (pow (proj_i,2 ) + delta_ij_2);
179189 const Double lim_j = (delta_ij_2 + proj_j*delta_ij) / (pow (proj_j,2 ) + delta_ij_2);
180- V.i .all (iVar) += scale * lim_i * proj_i;
181- V.j .all (iVar) -= scale * lim_j * proj_j;
190+
191+ V.i .all (iVar) += 0.5 * lim_i * proj_i;
192+ V.j .all (iVar) -= 0.5 * lim_j * proj_j;
182193 }
183194}
184195
0 commit comments