libMesh::Real SpalartAllmarasStabilizationHelper::compute_res_spalart_steady( AssemblyContext& context, unsigned int qp, const libMesh::Real rho, const libMesh::Real mu, const libMesh::Real distance_qp, const bool infinite_distance) const { // The flow velocity libMesh::Number u,v; u = context.interior_value(this->_flow_vars.u(), qp); v = context.interior_value(this->_flow_vars.v(), qp); libMesh::NumberVectorValue U(u,v); if ( this->_flow_vars.dim() == 3 ) U(2) = context.interior_value(this->_flow_vars.w(), qp); libMesh::RealGradient grad_u = context.fixed_interior_gradient(this->_flow_vars.u(), qp); libMesh::RealGradient grad_v = context.fixed_interior_gradient(this->_flow_vars.v(), qp); libMesh::Number nu_value = context.interior_value(this->_turbulence_vars.nu(), qp); libMesh::RealGradient grad_nu = context.fixed_interior_gradient(this->_turbulence_vars.nu(), qp); libMesh::RealTensor hess_nu = context.fixed_interior_hessian(this->_turbulence_vars.nu(), qp); // The convection term libMesh::Number rhoUdotGradnu = rho*(U*grad_nu); // The diffusion term libMesh::Number inv_sigmadivnuplusnuphysicalGradnu = (1./this->_sa_params.get_sigma())*(grad_nu*grad_nu + ((nu_value + mu)*(hess_nu(0,0) + hess_nu(1,1) + (this->_flow_vars.dim() == 3)?hess_nu(2,2):0)) + this->_sa_params.get_cb2()*grad_nu*grad_nu); // The source term libMesh::Real vorticity_value_qp = this->_spalart_allmaras_helper.vorticity(context, qp); libMesh::Real S_tilde = this->_sa_params.source_fn(nu_value, mu, distance_qp, vorticity_value_qp, infinite_distance); libMesh::Real source_term = this->_sa_params.get_cb1()*S_tilde*nu_value; libMesh::Real kappa2 = (this->_sa_params.get_kappa())*(this->_sa_params.get_kappa()); libMesh::Real cw1 = this->_sa_params.get_cb1()/kappa2 + (1.0 + this->_sa_params.get_cb2())/this->_sa_params.get_sigma(); // The destruction term libMesh::Real fw = this->_sa_params.destruction_fn(nu_value, distance_qp, S_tilde, infinite_distance); libMesh::Real destruction_term = 0.0; if(infinite_distance) { destruction_term = 0.0; } else { destruction_term = cw1*fw*pow(nu_value/distance_qp, 2.); } return rhoUdotGradnu + source_term + inv_sigmadivnuplusnuphysicalGradnu - destruction_term; }
void HeatTransferStabilizationHelper::compute_res_energy_steady_and_derivs ( AssemblyContext& context, unsigned int qp, const libMesh::Real rho, const libMesh::Real Cp, const libMesh::Real k, libMesh::Real &res, libMesh::Real &d_res_dT, libMesh::Gradient &d_res_dgradT, libMesh::Tensor &d_res_dhessT, libMesh::Gradient &d_res_dU ) const { libMesh::Gradient grad_T = context.fixed_interior_gradient(this->_temp_vars.T(), qp); libMesh::Tensor hess_T = context.fixed_interior_hessian(this->_temp_vars.T(), qp); libMesh::RealGradient rhocpU( rho*Cp*context.fixed_interior_value(this->_flow_vars.u(), qp), rho*Cp*context.fixed_interior_value(this->_flow_vars.v(), qp) ); if(this->_flow_vars.dim() == 3) rhocpU(2) = rho*Cp*context.fixed_interior_value(this->_flow_vars.w(), qp); res = rhocpU*grad_T - k*(hess_T(0,0) + hess_T(1,1) + hess_T(2,2)); d_res_dT = 0; d_res_dgradT = rhocpU; d_res_dhessT = 0; d_res_dhessT(0,0) = -k; d_res_dhessT(1,1) = -k; d_res_dhessT(2,2) = -k; d_res_dU = rho * Cp * grad_T; }
void LowMachNavierStokesSPGSMStabilization<Mu,SH,TC>::assemble_energy_mass_residual( bool /*compute_jacobian*/, AssemblyContext& context ) { // The number of local degrees of freedom in each variable. const unsigned int n_T_dofs = context.get_dof_indices(this->_temp_vars.T()).size(); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_temp_vars.T())->get_JxW(); // The temperature shape functions gradients at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi = context.get_element_fe(this->_temp_vars.T())->get_dphi(); libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(this->_temp_vars.T()); // R_{T} unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { libMesh::Number u, v; u = context.fixed_interior_value(this->_flow_vars.u(), qp); v = context.fixed_interior_value(this->_flow_vars.v(), qp); libMesh::Gradient grad_T = context.fixed_interior_gradient(this->_temp_vars.T(), qp); libMesh::NumberVectorValue U(u,v); if (this->mesh_dim(context) == 3) U(2) = context.fixed_interior_value(this->_flow_vars.w(), qp); // w libMesh::Real T = context.fixed_interior_value( this->_temp_vars.T(), qp ); libMesh::Real rho = this->rho( T, this->get_p0_transient( context, qp ) ); libMesh::Real k = this->_k(T); libMesh::Real cp = this->_cp(T); libMesh::Number rho_cp = rho*this->_cp(T); libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u()); libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp ); libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp ); libMesh::Real tau_E = this->_stab_helper.compute_tau_energy( context, qp, g, G, rho, U, k, cp, false ); libMesh::Real RE_t = this->compute_res_energy_transient( context, qp ); for (unsigned int i=0; i != n_T_dofs; i++) { FT(i) -= rho_cp*tau_E*RE_t*U*T_gradphi[i][qp]*JxW[qp]; } } return; }
libMesh::Real HeatTransferStabilizationHelper::compute_res_energy_steady( AssemblyContext& context, unsigned int qp, const libMesh::Real rho, const libMesh::Real Cp, const libMesh::Real k ) const { libMesh::Gradient grad_T = context.fixed_interior_gradient(this->_temp_vars.T(), qp); libMesh::Tensor hess_T = context.fixed_interior_hessian(this->_temp_vars.T(), qp); libMesh::RealGradient rhocpU( rho*Cp*context.fixed_interior_value(this->_flow_vars.u(), qp), rho*Cp*context.fixed_interior_value(this->_flow_vars.v(), qp) ); if(this->_flow_vars.dim() == 3) rhocpU(2) = rho*Cp*context.fixed_interior_value(this->_flow_vars.w(), qp); return rhocpU*grad_T - k*(hess_T(0,0) + hess_T(1,1) + hess_T(2,2)); }
void LowMachNavierStokesSPGSMStabilization<Mu,SH,TC>::assemble_momentum_mass_residual( bool /*compute_jacobian*/, AssemblyContext& context ) { // The number of local degrees of freedom in each variable. const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size(); // Check number of dofs is same for _flow_vars.u(), v_var and w_var. libmesh_assert (n_u_dofs == context.get_dof_indices(this->_flow_vars.v()).size()); if (this->mesh_dim(context) == 3) libmesh_assert (n_u_dofs == context.get_dof_indices(this->_flow_vars.w()).size()); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_flow_vars.u())->get_JxW(); // The velocity shape function gradients at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi = context.get_element_fe(this->_flow_vars.u())->get_dphi(); libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u()); // R_{u} libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v()); // R_{v} libMesh::DenseSubVector<libMesh::Real>* Fw = NULL; if( this->mesh_dim(context) == 3 ) { Fw = &context.get_elem_residual(this->_flow_vars.w()); // R_{w} } unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { libMesh::Real T = context.fixed_interior_value( this->_temp_vars.T(), qp ); libMesh::Real rho = this->rho( T, this->get_p0_transient( context, qp ) ); libMesh::Real mu = this->_mu(T); libMesh::RealGradient U( context.fixed_interior_value(this->_flow_vars.u(), qp), context.fixed_interior_value(this->_flow_vars.v(), qp) ); libMesh::RealGradient grad_u = context.fixed_interior_gradient(this->_flow_vars.u(), qp); libMesh::RealGradient grad_v = context.fixed_interior_gradient(this->_flow_vars.v(), qp); libMesh::RealGradient grad_w; if( this->mesh_dim(context) == 3 ) { U(2) = context.fixed_interior_value(this->_flow_vars.w(), qp); grad_w = context.fixed_interior_gradient(this->_flow_vars.w(), qp); } libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u()); libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp ); libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp ); libMesh::Real tau_M = this->_stab_helper.compute_tau_momentum( context, qp, g, G, rho, U, mu, false ); libMesh::Real tau_C = this->_stab_helper.compute_tau_continuity( tau_M, g ); libMesh::Real RC_t = this->compute_res_continuity_transient( context, qp ); libMesh::RealGradient RM_s = this->compute_res_momentum_steady( context, qp ); libMesh::RealGradient RM_t = this->compute_res_momentum_transient( context, qp ); for (unsigned int i=0; i != n_u_dofs; i++) { Fu(i) -= ( tau_C*RC_t*u_gradphi[i][qp](0) + tau_M*RM_t(0)*rho*U*u_gradphi[i][qp] )*JxW[qp]; Fv(i) -= ( tau_C*RC_t*u_gradphi[i][qp](1) + tau_M*RM_t(1)*rho*U*u_gradphi[i][qp] )*JxW[qp]; if( this->mesh_dim(context) == 3 ) { (*Fw)(i) -= ( tau_C*RC_t*u_gradphi[i][qp](2) + tau_M*RM_t(2)*rho*U*u_gradphi[i][qp] )*JxW[qp]; } } } return; }