27 #include "grins_config.h"
35 #include "libmesh/quadrature.h"
45 _stab_helper( physics_name+
"StabHelper", input )
60 context.get_element_fe(this->_flow_vars.p_var())->get_dphi();
62 context.get_element_fe(this->_flow_vars.u_var())->get_xyz();
63 context.get_element_fe(this->_flow_vars.u_var())->get_phi();
64 context.get_element_fe(this->_flow_vars.u_var())->get_dphi();
65 context.get_element_fe(this->_flow_vars.u_var())->get_d2phi();
72 (
bool compute_jacobian,
76 #ifdef GRINS_USE_GRVY_TIMERS
77 this->_timer->BeginTimer(
"AveragedTurbineAdjointStabilization::element_time_derivative");
80 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u_var());
83 const std::vector<libMesh::Real> &JxW = fe->get_JxW();
86 const std::vector<std::vector<libMesh::Real> >& u_phi = fe->get_phi();
88 const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
89 context.get_element_fe(this->_flow_vars.u_var())->get_dphi();
91 const std::vector<std::vector<libMesh::RealTensor> >& u_hessphi =
92 context.get_element_fe(this->_flow_vars.u_var())->get_d2phi();
94 const std::vector<libMesh::Point>& u_qpoint = fe->get_xyz();
97 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u_var()).size();
100 libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(this->_flow_vars.u_var(), this->_flow_vars.u_var());
101 libMesh::DenseSubMatrix<libMesh::Number> &Kuv = context.get_elem_jacobian(this->_flow_vars.u_var(), this->_flow_vars.v_var());
102 libMesh::DenseSubMatrix<libMesh::Number> &Kvu = context.get_elem_jacobian(this->_flow_vars.v_var(), this->_flow_vars.u_var());
103 libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(this->_flow_vars.v_var(), this->_flow_vars.v_var());
105 libMesh::DenseSubMatrix<libMesh::Number> &Kus =
106 context.get_elem_jacobian(this->_flow_vars.u_var(),
107 this->fan_speed_var());
108 libMesh::DenseSubMatrix<libMesh::Number> &Kvs =
109 context.get_elem_jacobian(this->_flow_vars.v_var(),
110 this->fan_speed_var());
112 libMesh::DenseSubMatrix<libMesh::Number>* Kwu = NULL;
113 libMesh::DenseSubMatrix<libMesh::Number>* Kwv = NULL;
114 libMesh::DenseSubMatrix<libMesh::Number>* Kww = NULL;
115 libMesh::DenseSubMatrix<libMesh::Number>* Kuw = NULL;
116 libMesh::DenseSubMatrix<libMesh::Number>* Kvw = NULL;
118 libMesh::DenseSubMatrix<libMesh::Number>* Kws = NULL;
120 libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u_var());
121 libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v_var());
122 libMesh::DenseSubVector<libMesh::Number>* Fw = NULL;
124 if( this->_dim == 3 )
126 Kuw = &context.get_elem_jacobian(this->_flow_vars.u_var(), this->_flow_vars.w_var());
127 Kvw = &context.get_elem_jacobian(this->_flow_vars.v_var(), this->_flow_vars.w_var());
129 Kwu = &context.get_elem_jacobian(this->_flow_vars.w_var(), this->_flow_vars.u_var());
130 Kwv = &context.get_elem_jacobian(this->_flow_vars.w_var(), this->_flow_vars.v_var());
131 Kww = &context.get_elem_jacobian(this->_flow_vars.w_var(), this->_flow_vars.w_var());
133 Kws = &context.get_elem_jacobian(this->_flow_vars.w_var(), this->fan_speed_var());
135 Fw = &context.get_elem_residual(this->_flow_vars.w_var());
138 unsigned int n_qpoints = context.get_element_qrule().n_points();
140 for (
unsigned int qp=0; qp != n_qpoints; qp++)
142 libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
143 libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );
145 libMesh::RealGradient U( context.interior_value( this->_flow_vars.u_var(), qp ),
146 context.interior_value( this->_flow_vars.v_var(), qp ) );
148 if( this->_dim == 3 )
150 U(2) = context.interior_value( this->_flow_vars.w_var(), qp );
153 libMesh::Number s = context.interior_value(this->fan_speed_var(), qp);
156 libMesh::Real mu_qp = this->_mu(context, qp);
159 libMesh::Real d_tau_M_d_rho;
160 libMesh::Gradient d_tau_M_dU;
162 if (compute_jacobian)
163 this->_stab_helper.compute_tau_momentum_and_derivs
164 ( context, qp, g, G, this->_rho, U, mu_qp,
165 tau_M, d_tau_M_d_rho, d_tau_M_dU,
168 tau_M = this->_stab_helper.compute_tau_momentum
169 ( context, qp, g, G, this->_rho, U, mu_qp,
172 libMesh::NumberVectorValue U_B_1;
173 libMesh::NumberVectorValue F;
174 libMesh::NumberTensorValue dFdU;
175 libMesh::NumberTensorValue* dFdU_ptr =
176 compute_jacobian ? &dFdU : NULL;
177 libMesh::NumberVectorValue dFds;
178 libMesh::NumberVectorValue* dFds_ptr =
179 compute_jacobian ? &dFds : NULL;
180 if (!this->compute_force(u_qpoint[qp], context.time, U, s,
181 U_B_1, F, dFdU_ptr, dFds_ptr))
184 for (
unsigned int i=0; i != n_u_dofs; i++)
186 libMesh::Real test_func = this->_rho*U*u_gradphi[i][qp] +
187 mu_qp*( u_hessphi[i][qp](0,0) + u_hessphi[i][qp](1,1) + u_hessphi[i][qp](2,2) );
188 Fu(i) += tau_M*F(0)*test_func*JxW[qp];
190 Fv(i) += tau_M*F(1)*test_func*JxW[qp];
194 (*Fw)(i) += tau_M*F(2)*test_func*JxW[qp];
197 if (compute_jacobian)
199 libMesh::Gradient d_test_func_dU = this->_rho*u_gradphi[i][qp];
201 for (
unsigned int j=0; j != n_u_dofs; ++j)
203 Kuu(i,j) += tau_M*F(0)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
204 Kuu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
205 Kuu(i,j) += tau_M*dFdU(0,0)*u_phi[j][qp]*test_func*JxW[qp];
206 Kuv(i,j) += tau_M*F(0)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
207 Kuv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
208 Kuv(i,j) += tau_M*dFdU(0,1)*u_phi[j][qp]*test_func*JxW[qp];
209 Kvu(i,j) += tau_M*F(1)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
210 Kvu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
211 Kvu(i,j) += tau_M*dFdU(1,0)*u_phi[j][qp]*test_func*JxW[qp];
212 Kvv(i,j) += tau_M*F(1)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
213 Kvv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
214 Kvv(i,j) += tau_M*dFdU(1,1)*u_phi[j][qp]*test_func*JxW[qp];
216 Kus(i,0) += tau_M*dFds(0)*test_func*JxW[qp];
217 Kvs(i,0) += tau_M*dFds(1)*test_func*JxW[qp];
222 for (
unsigned int j=0; j != n_u_dofs; ++j)
224 (*Kuw)(i,j) += tau_M*F(0)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
225 (*Kuw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
226 (*Kuw)(i,j) += tau_M*dFdU(0,2)*u_phi[j][qp]*test_func*JxW[qp];
227 (*Kvw)(i,j) += tau_M*F(1)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
228 (*Kvw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
229 (*Kvw)(i,j) += tau_M*dFdU(1,2)*u_phi[j][qp]*test_func*JxW[qp];
230 (*Kwu)(i,j) += tau_M*F(2)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
231 (*Kwu)(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
232 (*Kwu)(i,j) += tau_M*dFdU(2,0)*u_phi[j][qp]*test_func*JxW[qp];
233 (*Kwv)(i,j) += tau_M*F(2)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
234 (*Kwv)(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
235 (*Kwv)(i,j) += tau_M*dFdU(2,1)*u_phi[j][qp]*test_func*JxW[qp];
236 (*Kww)(i,j) += tau_M*F(2)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
237 (*Kww)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
238 (*Kww)(i,j) += tau_M*dFdU(2,2)*u_phi[j][qp]*test_func*JxW[qp];
240 (*Kws)(i,0) += tau_M*dFds(2)*test_func*JxW[qp];
249 #ifdef GRINS_USE_GRVY_TIMERS
250 this->_timer->EndTimer(
"AveragedTurbineAdjointStabilization::element_time_derivative");
261 #ifdef GRINS_USE_GRVY_TIMERS
262 this->_timer->BeginTimer(
"AveragedTurbineAdjointStabilization::element_constraint");
266 const unsigned int n_p_dofs = context.get_dof_indices(this->_flow_vars.p_var()).size();
267 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u_var()).size();
270 const std::vector<libMesh::Real> &JxW =
271 context.get_element_fe(this->_flow_vars.u_var())->get_JxW();
273 const std::vector<libMesh::Point>& u_qpoint =
274 context.get_element_fe(this->_flow_vars.u_var())->get_xyz();
276 const std::vector<std::vector<libMesh::Real> >& u_phi =
277 context.get_element_fe(this->_flow_vars.u_var())->get_phi();
279 const std::vector<std::vector<libMesh::RealGradient> >& p_dphi =
280 context.get_element_fe(this->_flow_vars.p_var())->get_dphi();
282 libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_flow_vars.p_var());
284 libMesh::DenseSubMatrix<libMesh::Number> &Kpu =
285 context.get_elem_jacobian(this->_flow_vars.p_var(), this->_flow_vars.u_var());
286 libMesh::DenseSubMatrix<libMesh::Number> &Kpv =
287 context.get_elem_jacobian(this->_flow_vars.p_var(), this->_flow_vars.v_var());
288 libMesh::DenseSubMatrix<libMesh::Number> &Kps =
289 context.get_elem_jacobian(this->_flow_vars.p_var(), this->fan_speed_var());
291 libMesh::DenseSubMatrix<libMesh::Number> *Kpw = NULL;
295 Kpw = &context.get_elem_jacobian
296 (this->_flow_vars.p_var(), this->_flow_vars.w_var());
305 unsigned int n_qpoints = context.get_element_qrule().n_points();
307 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u_var());
309 for (
unsigned int qp=0; qp != n_qpoints; qp++)
311 libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
312 libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );
314 libMesh::RealGradient U( context.interior_value( this->_flow_vars.u_var(), qp ),
315 context.interior_value( this->_flow_vars.v_var(), qp ) );
317 if( this->_dim == 3 )
319 U(2) = context.interior_value( this->_flow_vars.w_var(), qp );
322 libMesh::Number s = context.interior_value(this->fan_speed_var(), qp);
325 libMesh::Real mu_qp = this->_mu(context, qp);
328 libMesh::Real d_tau_M_d_rho;
329 libMesh::Gradient d_tau_M_dU;
331 if (compute_jacobian)
332 this->_stab_helper.compute_tau_momentum_and_derivs
333 ( context, qp, g, G, this->_rho, U, mu_qp,
334 tau_M, d_tau_M_d_rho, d_tau_M_dU,
337 tau_M = this->_stab_helper.compute_tau_momentum
338 ( context, qp, g, G, this->_rho, U, mu_qp,
341 libMesh::NumberVectorValue U_B_1;
342 libMesh::NumberVectorValue F;
343 libMesh::NumberTensorValue dFdU;
344 libMesh::NumberTensorValue* dFdU_ptr =
345 compute_jacobian ? &dFdU : NULL;
346 libMesh::NumberVectorValue dFds;
347 libMesh::NumberVectorValue* dFds_ptr =
348 compute_jacobian ? &dFds : NULL;
349 if (!this->compute_force(u_qpoint[qp], context.time, U, s,
350 U_B_1, F, dFdU_ptr, dFds_ptr))
356 for (
unsigned int i=0; i != n_p_dofs; i++)
358 Fp(i) += -tau_M*(F*p_dphi[i][qp])*JxW[qp];
360 if (compute_jacobian)
362 Kps(i,0) += -tau_M*(dFds*p_dphi[i][qp])*JxW[qp];
364 for (
unsigned int j=0; j != n_u_dofs; ++j)
366 Kpu(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*(F*p_dphi[i][qp])*JxW[qp];
367 Kpv(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*(F*p_dphi[i][qp])*JxW[qp];
368 for (
unsigned int d=0; d != 3; ++d)
370 Kpu(i,j) += -tau_M*dFdU(d,0)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
371 Kpv(i,j) += -tau_M*dFdU(d,1)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
374 if( this->_dim == 3 )
375 for (
unsigned int j=0; j != n_u_dofs; ++j)
377 (*Kpw)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp];
378 for (
unsigned int d=0; d != 3; ++d)
380 (*Kpw)(i,j) += -tau_M*dFdU(d,2)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
387 #ifdef GRINS_USE_GRVY_TIMERS
388 this->_timer->EndTimer(
"AveragedTurbineAdjointStabilization::element_constraint");
virtual void set_parameter(libMesh::Number ¶m_variable, const GetPot &input, const std::string ¶m_name, libMesh::Number param_default)
Each subclass can simultaneously read a parameter value from.
const PhysicsName incompressible_navier_stokes
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for element interiors.
virtual void element_constraint(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Constraint part(s) of physics for element interiors.
AveragedTurbineAdjointStabilization()
virtual void init_context(AssemblyContext &context)
Initialize context for added physics variables.
INSTANTIATE_INC_NS_SUBCLASS(AveragedTurbineAdjointStabilization)
~AveragedTurbineAdjointStabilization()