27 #include "grins_config.h"
35 #include "libmesh/quadrature.h"
43 _stab_helper( physics_name+
"StabHelper", input )
55 context.get_element_fe(this->_press_var.p())->get_dphi();
57 context.get_element_fe(this->_flow_vars.u())->get_xyz();
58 context.get_element_fe(this->_flow_vars.u())->get_phi();
59 context.get_element_fe(this->_flow_vars.u())->get_dphi();
60 context.get_element_fe(this->_flow_vars.u())->get_d2phi();
67 (
bool compute_jacobian,
71 #ifdef GRINS_USE_GRVY_TIMERS
72 this->_timer->BeginTimer(
"AveragedTurbineAdjointStabilization::element_time_derivative");
75 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
78 const std::vector<libMesh::Real> &JxW = fe->get_JxW();
81 const std::vector<std::vector<libMesh::Real> >& u_phi = fe->get_phi();
83 const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
84 context.get_element_fe(this->_flow_vars.u())->get_dphi();
86 const std::vector<std::vector<libMesh::RealTensor> >& u_hessphi =
87 context.get_element_fe(this->_flow_vars.u())->get_d2phi();
89 const std::vector<libMesh::Point>& u_qpoint = fe->get_xyz();
92 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
95 libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.u());
96 libMesh::DenseSubMatrix<libMesh::Number> &Kuv = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.v());
97 libMesh::DenseSubMatrix<libMesh::Number> &Kvu = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.u());
98 libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.v());
100 libMesh::DenseSubMatrix<libMesh::Number> &Kus =
101 context.get_elem_jacobian(this->_flow_vars.u(),
102 this->fan_speed_var());
103 libMesh::DenseSubMatrix<libMesh::Number> &Kvs =
104 context.get_elem_jacobian(this->_flow_vars.v(),
105 this->fan_speed_var());
107 libMesh::DenseSubMatrix<libMesh::Number>* Kwu = NULL;
108 libMesh::DenseSubMatrix<libMesh::Number>* Kwv = NULL;
109 libMesh::DenseSubMatrix<libMesh::Number>* Kww = NULL;
110 libMesh::DenseSubMatrix<libMesh::Number>* Kuw = NULL;
111 libMesh::DenseSubMatrix<libMesh::Number>* Kvw = NULL;
113 libMesh::DenseSubMatrix<libMesh::Number>* Kws = NULL;
115 libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u());
116 libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v());
117 libMesh::DenseSubVector<libMesh::Number>* Fw = NULL;
119 if( this->_dim == 3 )
121 Kuw = &context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.w());
122 Kvw = &context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.w());
124 Kwu = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.u());
125 Kwv = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.v());
126 Kww = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.w());
128 Kws = &context.get_elem_jacobian(this->_flow_vars.w(), this->fan_speed_var());
130 Fw = &context.get_elem_residual(this->_flow_vars.w());
133 unsigned int n_qpoints = context.get_element_qrule().n_points();
135 for (
unsigned int qp=0; qp != n_qpoints; qp++)
137 libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
138 libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );
140 libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ),
141 context.interior_value( this->_flow_vars.v(), qp ) );
143 if( this->_dim == 3 )
145 U(2) = context.interior_value( this->_flow_vars.w(), qp );
148 libMesh::Number s = context.interior_value(this->fan_speed_var(), qp);
151 libMesh::Real mu_qp = this->_mu(context, qp);
154 libMesh::Real d_tau_M_d_rho;
155 libMesh::Gradient d_tau_M_dU;
157 if (compute_jacobian)
158 this->_stab_helper.compute_tau_momentum_and_derivs
159 ( context, qp, g, G, this->_rho, U, mu_qp,
160 tau_M, d_tau_M_d_rho, d_tau_M_dU,
163 tau_M = this->_stab_helper.compute_tau_momentum
164 ( context, qp, g, G, this->_rho, U, mu_qp,
167 libMesh::NumberVectorValue U_B_1;
168 libMesh::NumberVectorValue F;
169 libMesh::NumberTensorValue dFdU;
170 libMesh::NumberTensorValue* dFdU_ptr =
171 compute_jacobian ? &dFdU : NULL;
172 libMesh::NumberVectorValue dFds;
173 libMesh::NumberVectorValue* dFds_ptr =
174 compute_jacobian ? &dFds : NULL;
175 if (!this->compute_force(u_qpoint[qp], context.time, U, s,
176 U_B_1, F, dFdU_ptr, dFds_ptr))
179 for (
unsigned int i=0; i != n_u_dofs; i++)
181 libMesh::Real test_func = this->_rho*U*u_gradphi[i][qp] +
182 mu_qp*( u_hessphi[i][qp](0,0) + u_hessphi[i][qp](1,1) + u_hessphi[i][qp](2,2) );
183 Fu(i) += tau_M*F(0)*test_func*JxW[qp];
185 Fv(i) += tau_M*F(1)*test_func*JxW[qp];
189 (*Fw)(i) += tau_M*F(2)*test_func*JxW[qp];
192 if (compute_jacobian)
194 libMesh::Gradient d_test_func_dU = this->_rho*u_gradphi[i][qp];
196 for (
unsigned int j=0; j != n_u_dofs; ++j)
198 Kuu(i,j) += tau_M*F(0)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
199 Kuu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
200 Kuu(i,j) += tau_M*dFdU(0,0)*u_phi[j][qp]*test_func*JxW[qp];
201 Kuv(i,j) += tau_M*F(0)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
202 Kuv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
203 Kuv(i,j) += tau_M*dFdU(0,1)*u_phi[j][qp]*test_func*JxW[qp];
204 Kvu(i,j) += tau_M*F(1)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
205 Kvu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
206 Kvu(i,j) += tau_M*dFdU(1,0)*u_phi[j][qp]*test_func*JxW[qp];
207 Kvv(i,j) += tau_M*F(1)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
208 Kvv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
209 Kvv(i,j) += tau_M*dFdU(1,1)*u_phi[j][qp]*test_func*JxW[qp];
211 Kus(i,0) += tau_M*dFds(0)*test_func*JxW[qp];
212 Kvs(i,0) += tau_M*dFds(1)*test_func*JxW[qp];
217 for (
unsigned int j=0; j != n_u_dofs; ++j)
219 (*Kuw)(i,j) += tau_M*F(0)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
220 (*Kuw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
221 (*Kuw)(i,j) += tau_M*dFdU(0,2)*u_phi[j][qp]*test_func*JxW[qp];
222 (*Kvw)(i,j) += tau_M*F(1)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
223 (*Kvw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
224 (*Kvw)(i,j) += tau_M*dFdU(1,2)*u_phi[j][qp]*test_func*JxW[qp];
225 (*Kwu)(i,j) += tau_M*F(2)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
226 (*Kwu)(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
227 (*Kwu)(i,j) += tau_M*dFdU(2,0)*u_phi[j][qp]*test_func*JxW[qp];
228 (*Kwv)(i,j) += tau_M*F(2)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
229 (*Kwv)(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
230 (*Kwv)(i,j) += tau_M*dFdU(2,1)*u_phi[j][qp]*test_func*JxW[qp];
231 (*Kww)(i,j) += tau_M*F(2)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
232 (*Kww)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
233 (*Kww)(i,j) += tau_M*dFdU(2,2)*u_phi[j][qp]*test_func*JxW[qp];
235 (*Kws)(i,0) += tau_M*dFds(2)*test_func*JxW[qp];
244 #ifdef GRINS_USE_GRVY_TIMERS
245 this->_timer->EndTimer(
"AveragedTurbineAdjointStabilization::element_time_derivative");
256 #ifdef GRINS_USE_GRVY_TIMERS
257 this->_timer->BeginTimer(
"AveragedTurbineAdjointStabilization::element_constraint");
261 const unsigned int n_p_dofs = context.get_dof_indices(this->_press_var.p()).size();
262 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
265 const std::vector<libMesh::Real> &JxW =
266 context.get_element_fe(this->_flow_vars.u())->get_JxW();
268 const std::vector<libMesh::Point>& u_qpoint =
269 context.get_element_fe(this->_flow_vars.u())->get_xyz();
271 const std::vector<std::vector<libMesh::Real> >& u_phi =
272 context.get_element_fe(this->_flow_vars.u())->get_phi();
274 const std::vector<std::vector<libMesh::RealGradient> >& p_dphi =
275 context.get_element_fe(this->_press_var.p())->get_dphi();
277 libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_press_var.p());
279 libMesh::DenseSubMatrix<libMesh::Number> &Kpu =
280 context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.u());
281 libMesh::DenseSubMatrix<libMesh::Number> &Kpv =
282 context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.v());
283 libMesh::DenseSubMatrix<libMesh::Number> &Kps =
284 context.get_elem_jacobian(this->_press_var.p(), this->fan_speed_var());
286 libMesh::DenseSubMatrix<libMesh::Number> *Kpw = NULL;
290 Kpw = &context.get_elem_jacobian
291 (this->_press_var.p(), this->_flow_vars.w());
300 unsigned int n_qpoints = context.get_element_qrule().n_points();
302 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
304 for (
unsigned int qp=0; qp != n_qpoints; qp++)
306 libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
307 libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );
309 libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ),
310 context.interior_value( this->_flow_vars.v(), qp ) );
312 if( this->_dim == 3 )
314 U(2) = context.interior_value( this->_flow_vars.w(), qp );
317 libMesh::Number s = context.interior_value(this->fan_speed_var(), qp);
320 libMesh::Real mu_qp = this->_mu(context, qp);
323 libMesh::Real d_tau_M_d_rho;
324 libMesh::Gradient d_tau_M_dU;
326 if (compute_jacobian)
327 this->_stab_helper.compute_tau_momentum_and_derivs
328 ( context, qp, g, G, this->_rho, U, mu_qp,
329 tau_M, d_tau_M_d_rho, d_tau_M_dU,
332 tau_M = this->_stab_helper.compute_tau_momentum
333 ( context, qp, g, G, this->_rho, U, mu_qp,
336 libMesh::NumberVectorValue U_B_1;
337 libMesh::NumberVectorValue F;
338 libMesh::NumberTensorValue dFdU;
339 libMesh::NumberTensorValue* dFdU_ptr =
340 compute_jacobian ? &dFdU : NULL;
341 libMesh::NumberVectorValue dFds;
342 libMesh::NumberVectorValue* dFds_ptr =
343 compute_jacobian ? &dFds : NULL;
344 if (!this->compute_force(u_qpoint[qp], context.time, U, s,
345 U_B_1, F, dFdU_ptr, dFds_ptr))
351 for (
unsigned int i=0; i != n_p_dofs; i++)
353 Fp(i) += -tau_M*(F*p_dphi[i][qp])*JxW[qp];
355 if (compute_jacobian)
357 Kps(i,0) += -tau_M*(dFds*p_dphi[i][qp])*JxW[qp];
359 for (
unsigned int j=0; j != n_u_dofs; ++j)
361 Kpu(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*(F*p_dphi[i][qp])*JxW[qp];
362 Kpv(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*(F*p_dphi[i][qp])*JxW[qp];
363 for (
unsigned int d=0; d != 3; ++d)
365 Kpu(i,j) += -tau_M*dFdU(d,0)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
366 Kpv(i,j) += -tau_M*dFdU(d,1)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
369 if( this->_dim == 3 )
370 for (
unsigned int j=0; j != n_u_dofs; ++j)
372 (*Kpw)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp];
373 for (
unsigned int d=0; d != 3; ++d)
375 (*Kpw)(i,j) += -tau_M*dFdU(d,2)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
382 #ifdef GRINS_USE_GRVY_TIMERS
383 this->_timer->EndTimer(
"AveragedTurbineAdjointStabilization::element_constraint");
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()