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,
70 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
73 const std::vector<libMesh::Real> &JxW = fe->get_JxW();
76 const std::vector<std::vector<libMesh::Real> >& u_phi = fe->get_phi();
78 const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
79 context.get_element_fe(this->_flow_vars.u())->get_dphi();
81 const std::vector<std::vector<libMesh::RealTensor> >& u_hessphi =
82 context.get_element_fe(this->_flow_vars.u())->get_d2phi();
84 const std::vector<libMesh::Point>& u_qpoint = fe->get_xyz();
87 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
90 libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.u());
91 libMesh::DenseSubMatrix<libMesh::Number> &Kuv = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.v());
92 libMesh::DenseSubMatrix<libMesh::Number> &Kvu = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.u());
93 libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.v());
95 libMesh::DenseSubMatrix<libMesh::Number> &Kus =
96 context.get_elem_jacobian(this->_flow_vars.u(),
97 this->fan_speed_var());
98 libMesh::DenseSubMatrix<libMesh::Number> &Kvs =
99 context.get_elem_jacobian(this->_flow_vars.v(),
100 this->fan_speed_var());
102 libMesh::DenseSubMatrix<libMesh::Number>* Kwu = NULL;
103 libMesh::DenseSubMatrix<libMesh::Number>* Kwv = NULL;
104 libMesh::DenseSubMatrix<libMesh::Number>* Kww = NULL;
105 libMesh::DenseSubMatrix<libMesh::Number>* Kuw = NULL;
106 libMesh::DenseSubMatrix<libMesh::Number>* Kvw = NULL;
108 libMesh::DenseSubMatrix<libMesh::Number>* Kws = NULL;
110 libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u());
111 libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v());
112 libMesh::DenseSubVector<libMesh::Number>* Fw = NULL;
114 if( this->_flow_vars.dim() == 3 )
116 Kuw = &context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.w());
117 Kvw = &context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.w());
119 Kwu = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.u());
120 Kwv = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.v());
121 Kww = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.w());
123 Kws = &context.get_elem_jacobian(this->_flow_vars.w(), this->fan_speed_var());
125 Fw = &context.get_elem_residual(this->_flow_vars.w());
128 unsigned int n_qpoints = context.get_element_qrule().n_points();
130 for (
unsigned int qp=0; qp != n_qpoints; qp++)
132 libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
133 libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );
135 libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ),
136 context.interior_value( this->_flow_vars.v(), qp ) );
138 if( this->_flow_vars.dim() == 3 )
140 U(2) = context.interior_value( this->_flow_vars.w(), qp );
143 libMesh::Number s = context.interior_value(this->fan_speed_var(), qp);
146 libMesh::Real mu_qp = this->_mu(context, qp);
149 libMesh::Real d_tau_M_d_rho;
150 libMesh::Gradient d_tau_M_dU;
152 if (compute_jacobian)
153 this->_stab_helper.compute_tau_momentum_and_derivs
154 ( context, qp, g, G, this->_rho, U, mu_qp,
155 tau_M, d_tau_M_d_rho, d_tau_M_dU,
158 tau_M = this->_stab_helper.compute_tau_momentum
159 ( context, qp, g, G, this->_rho, U, mu_qp,
162 libMesh::NumberVectorValue U_B_1;
163 libMesh::NumberVectorValue F;
164 libMesh::NumberTensorValue dFdU;
165 libMesh::NumberTensorValue* dFdU_ptr =
166 compute_jacobian ? &dFdU : NULL;
167 libMesh::NumberVectorValue dFds;
168 libMesh::NumberVectorValue* dFds_ptr =
169 compute_jacobian ? &dFds : NULL;
170 if (!this->compute_force(u_qpoint[qp], context.time, U, s,
171 U_B_1, F, dFdU_ptr, dFds_ptr))
174 for (
unsigned int i=0; i != n_u_dofs; i++)
176 libMesh::Real test_func = this->_rho*U*u_gradphi[i][qp] +
177 mu_qp*( u_hessphi[i][qp](0,0) + u_hessphi[i][qp](1,1) + u_hessphi[i][qp](2,2) );
178 Fu(i) += tau_M*F(0)*test_func*JxW[qp];
180 Fv(i) += tau_M*F(1)*test_func*JxW[qp];
182 if (this->_flow_vars.dim() == 3)
184 (*Fw)(i) += tau_M*F(2)*test_func*JxW[qp];
187 if (compute_jacobian)
189 libMesh::Gradient d_test_func_dU = this->_rho*u_gradphi[i][qp];
191 for (
unsigned int j=0; j != n_u_dofs; ++j)
193 Kuu(i,j) += tau_M*F(0)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
194 Kuu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
195 Kuu(i,j) += tau_M*dFdU(0,0)*u_phi[j][qp]*test_func*JxW[qp];
196 Kuv(i,j) += tau_M*F(0)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
197 Kuv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
198 Kuv(i,j) += tau_M*dFdU(0,1)*u_phi[j][qp]*test_func*JxW[qp];
199 Kvu(i,j) += tau_M*F(1)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
200 Kvu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
201 Kvu(i,j) += tau_M*dFdU(1,0)*u_phi[j][qp]*test_func*JxW[qp];
202 Kvv(i,j) += tau_M*F(1)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
203 Kvv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
204 Kvv(i,j) += tau_M*dFdU(1,1)*u_phi[j][qp]*test_func*JxW[qp];
206 Kus(i,0) += tau_M*dFds(0)*test_func*JxW[qp];
207 Kvs(i,0) += tau_M*dFds(1)*test_func*JxW[qp];
210 if (this->_flow_vars.dim() == 3)
212 for (
unsigned int j=0; j != n_u_dofs; ++j)
214 (*Kuw)(i,j) += tau_M*F(0)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
215 (*Kuw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(0)*test_func*JxW[qp];
216 (*Kuw)(i,j) += tau_M*dFdU(0,2)*u_phi[j][qp]*test_func*JxW[qp];
217 (*Kvw)(i,j) += tau_M*F(1)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
218 (*Kvw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(1)*test_func*JxW[qp];
219 (*Kvw)(i,j) += tau_M*dFdU(1,2)*u_phi[j][qp]*test_func*JxW[qp];
220 (*Kwu)(i,j) += tau_M*F(2)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp];
221 (*Kwu)(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
222 (*Kwu)(i,j) += tau_M*dFdU(2,0)*u_phi[j][qp]*test_func*JxW[qp];
223 (*Kwv)(i,j) += tau_M*F(2)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp];
224 (*Kwv)(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
225 (*Kwv)(i,j) += tau_M*dFdU(2,1)*u_phi[j][qp]*test_func*JxW[qp];
226 (*Kww)(i,j) += tau_M*F(2)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp];
227 (*Kww)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(2)*test_func*JxW[qp];
228 (*Kww)(i,j) += tau_M*dFdU(2,2)*u_phi[j][qp]*test_func*JxW[qp];
230 (*Kws)(i,0) += tau_M*dFds(2)*test_func*JxW[qp];
245 const unsigned int n_p_dofs = context.get_dof_indices(this->_press_var.p()).size();
246 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
249 const std::vector<libMesh::Real> &JxW =
250 context.get_element_fe(this->_flow_vars.u())->get_JxW();
252 const std::vector<libMesh::Point>& u_qpoint =
253 context.get_element_fe(this->_flow_vars.u())->get_xyz();
255 const std::vector<std::vector<libMesh::Real> >& u_phi =
256 context.get_element_fe(this->_flow_vars.u())->get_phi();
258 const std::vector<std::vector<libMesh::RealGradient> >& p_dphi =
259 context.get_element_fe(this->_press_var.p())->get_dphi();
261 libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_press_var.p());
263 libMesh::DenseSubMatrix<libMesh::Number> &Kpu =
264 context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.u());
265 libMesh::DenseSubMatrix<libMesh::Number> &Kpv =
266 context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.v());
267 libMesh::DenseSubMatrix<libMesh::Number> &Kps =
268 context.get_elem_jacobian(this->_press_var.p(), this->fan_speed_var());
270 libMesh::DenseSubMatrix<libMesh::Number> *Kpw = NULL;
272 if(this->_flow_vars.dim() == 3)
274 Kpw = &context.get_elem_jacobian
275 (this->_press_var.p(), this->_flow_vars.w());
284 unsigned int n_qpoints = context.get_element_qrule().n_points();
286 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
288 for (
unsigned int qp=0; qp != n_qpoints; qp++)
290 libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
291 libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );
293 libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ),
294 context.interior_value( this->_flow_vars.v(), qp ) );
296 if( this->_flow_vars.dim() == 3 )
298 U(2) = context.interior_value( this->_flow_vars.w(), qp );
301 libMesh::Number s = context.interior_value(this->fan_speed_var(), qp);
304 libMesh::Real mu_qp = this->_mu(context, qp);
307 libMesh::Real d_tau_M_d_rho;
308 libMesh::Gradient d_tau_M_dU;
310 if (compute_jacobian)
311 this->_stab_helper.compute_tau_momentum_and_derivs
312 ( context, qp, g, G, this->_rho, U, mu_qp,
313 tau_M, d_tau_M_d_rho, d_tau_M_dU,
316 tau_M = this->_stab_helper.compute_tau_momentum
317 ( context, qp, g, G, this->_rho, U, mu_qp,
320 libMesh::NumberVectorValue U_B_1;
321 libMesh::NumberVectorValue F;
322 libMesh::NumberTensorValue dFdU;
323 libMesh::NumberTensorValue* dFdU_ptr =
324 compute_jacobian ? &dFdU : NULL;
325 libMesh::NumberVectorValue dFds;
326 libMesh::NumberVectorValue* dFds_ptr =
327 compute_jacobian ? &dFds : NULL;
328 if (!this->compute_force(u_qpoint[qp], context.time, U, s,
329 U_B_1, F, dFdU_ptr, dFds_ptr))
335 for (
unsigned int i=0; i != n_p_dofs; i++)
337 Fp(i) += -tau_M*(F*p_dphi[i][qp])*JxW[qp];
339 if (compute_jacobian)
341 Kps(i,0) += -tau_M*(dFds*p_dphi[i][qp])*JxW[qp];
343 for (
unsigned int j=0; j != n_u_dofs; ++j)
345 Kpu(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*(F*p_dphi[i][qp])*JxW[qp];
346 Kpv(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*(F*p_dphi[i][qp])*JxW[qp];
347 for (
unsigned int d=0; d != 3; ++d)
349 Kpu(i,j) += -tau_M*dFdU(d,0)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
350 Kpv(i,j) += -tau_M*dFdU(d,1)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
353 if( this->_flow_vars.dim() == 3 )
354 for (
unsigned int j=0; j != n_u_dofs; ++j)
356 (*Kpw)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp];
357 for (
unsigned int d=0; d != 3; ++d)
359 (*Kpw)(i,j) += -tau_M*dFdU(d,2)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp];
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context)
Time dependent part(s) of physics for element interiors.
AveragedTurbineAdjointStabilization()
virtual void element_constraint(bool compute_jacobian, AssemblyContext &context)
Constraint part(s) of physics for element interiors.
virtual void init_context(AssemblyContext &context)
Initialize context for added physics variables.
INSTANTIATE_INC_NS_SUBCLASS(AveragedTurbineAdjointStabilization)
~AveragedTurbineAdjointStabilization()