27 #include "grins_config.h"
35 #include "libmesh/getpot.h"
36 #include "libmesh/quadrature.h"
44 _stab_helper( physics_name+
"StabHelper", input )
57 context.get_element_fe(this->_press_var.p())->get_dphi();
59 context.get_element_fe(this->_flow_vars.u())->get_xyz();
60 context.get_element_fe(this->_flow_vars.u())->get_phi();
61 context.get_element_fe(this->_flow_vars.u())->get_dphi();
62 context.get_element_fe(this->_flow_vars.u())->get_d2phi();
72 #ifdef GRINS_USE_GRVY_TIMERS
73 this->_timer->BeginTimer(
"ParsedVelocitySourceAdjointStabilization::element_time_derivative");
77 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
80 const std::vector<libMesh::Real> &JxW =
81 context.get_element_fe(this->_flow_vars.u())->get_JxW();
83 const std::vector<libMesh::Point>& u_qpoint =
84 context.get_element_fe(this->_flow_vars.u())->get_xyz();
86 const std::vector<std::vector<libMesh::Real> >& u_phi =
87 context.get_element_fe(this->_flow_vars.u())->get_phi();
89 const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
90 context.get_element_fe(this->_flow_vars.u())->get_dphi();
92 const std::vector<std::vector<libMesh::RealTensor> >& u_hessphi =
93 context.get_element_fe(this->_flow_vars.u())->get_d2phi();
96 libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u());
97 libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v());
98 libMesh::DenseSubVector<libMesh::Number> *Fw = NULL;
100 libMesh::DenseSubMatrix<libMesh::Number> &Kuu =
101 context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.u());
102 libMesh::DenseSubMatrix<libMesh::Number> &Kuv =
103 context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.v());
104 libMesh::DenseSubMatrix<libMesh::Number> &Kvu =
105 context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.u());
106 libMesh::DenseSubMatrix<libMesh::Number> &Kvv =
107 context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.v());
109 libMesh::DenseSubMatrix<libMesh::Number> *Kuw = NULL;
110 libMesh::DenseSubMatrix<libMesh::Number> *Kvw = NULL;
111 libMesh::DenseSubMatrix<libMesh::Number> *Kwu = NULL;
112 libMesh::DenseSubMatrix<libMesh::Number> *Kwv = NULL;
113 libMesh::DenseSubMatrix<libMesh::Number> *Kww = NULL;
117 Fw = &context.get_elem_residual(this->_flow_vars.w());
118 Kuw = &context.get_elem_jacobian
119 (this->_flow_vars.u(), this->_flow_vars.w());
120 Kvw = &context.get_elem_jacobian
121 (this->_flow_vars.v(), this->_flow_vars.w());
122 Kwu = &context.get_elem_jacobian
123 (this->_flow_vars.w(), this->_flow_vars.u());
124 Kwv = &context.get_elem_jacobian
125 (this->_flow_vars.w(), this->_flow_vars.v());
126 Kww = &context.get_elem_jacobian
127 (this->_flow_vars.w(), this->_flow_vars.w());
136 unsigned int n_qpoints = context.get_element_qrule().n_points();
138 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
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(), qp ),
146 context.interior_value( this->_flow_vars.v(), qp ) );
147 if( this->_dim == 3 )
149 U(2) = context.interior_value( this->_flow_vars.w(), qp );
153 libMesh::Real mu_qp = this->_mu(context, qp);
156 libMesh::Real d_tau_M_d_rho;
157 libMesh::Gradient d_tau_M_dU;
159 if (compute_jacobian)
160 this->_stab_helper.compute_tau_momentum_and_derivs
161 ( context, qp, g, G, this->_rho, U, mu_qp,
162 tau_M, d_tau_M_d_rho, d_tau_M_dU,
165 tau_M = this->_stab_helper.compute_tau_momentum
166 ( context, qp, g, G, this->_rho, U, mu_qp,
169 libMesh::NumberVectorValue F;
170 libMesh::NumberTensorValue dFdU;
171 libMesh::NumberTensorValue* dFdU_ptr =
172 compute_jacobian ? &dFdU : NULL;
173 if (!this->compute_force(u_qpoint[qp], context.time, context, F, dFdU_ptr))
176 for (
unsigned int i=0; i != n_u_dofs; i++)
178 libMesh::Real test_func = this->_rho*U*u_gradphi[i][qp] +
179 mu_qp*( u_hessphi[i][qp](0,0) + u_hessphi[i][qp](1,1) + u_hessphi[i][qp](2,2) );
180 Fu(i) += tau_M*F(0)*test_func*JxW[qp];
182 Fv(i) += tau_M*F(1)*test_func*JxW[qp];
186 (*Fw)(i) += tau_M*F(2)*test_func*JxW[qp];
189 if (compute_jacobian)
191 libMesh::Gradient d_test_func_dU = this->_rho*u_gradphi[i][qp];
193 for (
unsigned int j=0; j != n_u_dofs; ++j)
195 Kuu(i,j) += tau_M*F(0)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
196 Kuu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(0)*test_func*JxW[qp]*context.get_elem_solution_derivative();
197 Kuu(i,j) += tau_M*dFdU(0,0)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
198 Kuv(i,j) += tau_M*F(0)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
199 Kuv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(0)*test_func*JxW[qp]*context.get_elem_solution_derivative();
200 Kuv(i,j) += tau_M*dFdU(0,1)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
201 Kvu(i,j) += tau_M*F(1)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
202 Kvu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(1)*test_func*JxW[qp]*context.get_elem_solution_derivative();
203 Kvu(i,j) += tau_M*dFdU(1,0)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
204 Kvv(i,j) += tau_M*F(1)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
205 Kvv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(1)*test_func*JxW[qp]*context.get_elem_solution_derivative();
206 Kvv(i,j) += tau_M*dFdU(1,1)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
211 for (
unsigned int j=0; j != n_u_dofs; ++j)
213 (*Kuw)(i,j) += tau_M*F(0)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
214 (*Kuw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(0)*test_func*JxW[qp]*context.get_elem_solution_derivative();
215 (*Kuw)(i,j) += tau_M*dFdU(0,2)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
216 (*Kvw)(i,j) += tau_M*F(1)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
217 (*Kvw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(1)*test_func*JxW[qp]*context.get_elem_solution_derivative();
218 (*Kvw)(i,j) += tau_M*dFdU(1,2)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
219 (*Kwu)(i,j) += tau_M*F(2)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
220 (*Kwu)(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*F(2)*test_func*JxW[qp]*context.get_elem_solution_derivative();
221 (*Kwu)(i,j) += tau_M*dFdU(2,0)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
222 (*Kwv)(i,j) += tau_M*F(2)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
223 (*Kwv)(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*F(2)*test_func*JxW[qp]*context.get_elem_solution_derivative();
224 (*Kwv)(i,j) += tau_M*dFdU(2,1)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
225 (*Kww)(i,j) += tau_M*F(2)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp]*context.get_elem_solution_derivative();
226 (*Kww)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*F(2)*test_func*JxW[qp]*context.get_elem_solution_derivative();
227 (*Kww)(i,j) += tau_M*dFdU(2,2)*u_phi[j][qp]*test_func*JxW[qp]*context.get_elem_solution_derivative();
236 #ifdef GRINS_USE_GRVY_TIMERS
237 this->_timer->EndTimer(
"BoussinesqBuoyancyAdjointStabilization::element_time_derivative");
248 #ifdef GRINS_USE_GRVY_TIMERS
249 this->_timer->BeginTimer(
"ParsedVelocitySourceAdjointStabilization::element_constraint");
253 const unsigned int n_p_dofs = context.get_dof_indices(this->_press_var.p()).size();
254 const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
257 const std::vector<libMesh::Real> &JxW =
258 context.get_element_fe(this->_flow_vars.u())->get_JxW();
260 const std::vector<libMesh::Point>& u_qpoint =
261 context.get_element_fe(this->_flow_vars.u())->get_xyz();
263 const std::vector<std::vector<libMesh::Real> >& u_phi =
264 context.get_element_fe(this->_flow_vars.u())->get_phi();
266 const std::vector<std::vector<libMesh::RealGradient> >& p_dphi =
267 context.get_element_fe(this->_press_var.p())->get_dphi();
269 libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_press_var.p());
271 libMesh::DenseSubMatrix<libMesh::Number> &Kpu =
272 context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.u());
273 libMesh::DenseSubMatrix<libMesh::Number> &Kpv =
274 context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.v());
275 libMesh::DenseSubMatrix<libMesh::Number> *Kpw = NULL;
279 Kpw = &context.get_elem_jacobian
280 (this->_press_var.p(), this->_flow_vars.w());
289 unsigned int n_qpoints = context.get_element_qrule().n_points();
291 libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u());
293 for (
unsigned int qp=0; qp != n_qpoints; qp++)
295 libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp );
296 libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp );
298 libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ),
299 context.interior_value( this->_flow_vars.v(), qp ) );
300 if( this->_dim == 3 )
302 U(2) = context.interior_value( this->_flow_vars.w(), qp );
306 libMesh::Real mu_qp = this->_mu(context, qp);
309 libMesh::Real d_tau_M_d_rho;
310 libMesh::Gradient d_tau_M_dU;
312 if (compute_jacobian)
313 this->_stab_helper.compute_tau_momentum_and_derivs
314 ( context, qp, g, G, this->_rho, U, mu_qp,
315 tau_M, d_tau_M_d_rho, d_tau_M_dU,
318 tau_M = this->_stab_helper.compute_tau_momentum
319 ( context, qp, g, G, this->_rho, U, mu_qp,
322 libMesh::NumberVectorValue F;
323 libMesh::NumberTensorValue dFdU;
324 libMesh::NumberTensorValue* dFdU_ptr =
325 compute_jacobian ? &dFdU : NULL;
326 if (!this->compute_force(u_qpoint[qp], context.time, context, F, dFdU_ptr))
332 for (
unsigned int i=0; i != n_p_dofs; i++)
334 Fp(i) += -tau_M*F*p_dphi[i][qp]*JxW[qp];
336 if (compute_jacobian)
338 for (
unsigned int j=0; j != n_u_dofs; ++j)
340 Kpu(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp]*context.get_elem_solution_derivative();
341 Kpv(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp]*context.get_elem_solution_derivative();
342 for (
unsigned int d=0; d != 3; ++d)
344 Kpu(i,j) += -tau_M*dFdU(d,0)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp]*context.get_elem_solution_derivative();
345 Kpv(i,j) += -tau_M*dFdU(d,1)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp]*context.get_elem_solution_derivative();
348 if( this->_dim == 3 )
349 for (
unsigned int j=0; j != n_u_dofs; ++j)
351 (*Kpw)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp]*context.get_elem_solution_derivative();
352 for (
unsigned int d=0; d != 3; ++d)
354 (*Kpw)(i,j) += -tau_M*dFdU(d,2)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp]*context.get_elem_solution_derivative();
361 #ifdef GRINS_USE_GRVY_TIMERS
362 this->_timer->EndTimer(
"ParsedVelocitySourceAdjointStabilization::element_constraint");
INSTANTIATE_INC_NS_SUBCLASS(ParsedVelocitySourceAdjointStabilization)
~ParsedVelocitySourceAdjointStabilization()
virtual void init_context(AssemblyContext &context)
Initialize context for added physics variables.
virtual void element_constraint(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Constraint part(s) of physics for element interiors.
ParsedVelocitySourceAdjointStabilization()
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context, CachedValues &cache)
Time dependent part(s) of physics for element interiors.