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 LowMachNavierStokes<Mu,SH,TC>::assemble_thermo_press_mass_residual( bool /*compute_jacobian*/, AssemblyContext& context ) { // The number of local degrees of freedom in each variable. const unsigned int n_p0_dofs = context.get_dof_indices(this->_p0_var).size(); const unsigned int n_T_dofs = context.get_dof_indices(this->_T_var).size(); const unsigned int n_p_dofs = context.get_dof_indices(this->_p_var).size(); // Element Jacobian * quadrature weights for interior integration const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_T_var)->get_JxW(); // The temperature shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& T_phi = context.get_element_fe(this->_T_var)->get_phi(); // The temperature shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& p_phi = context.get_element_fe(this->_p_var)->get_phi(); // The subvectors and submatrices we need to fill: libMesh::DenseSubVector<libMesh::Real> &F_p0 = context.get_elem_residual(this->_p0_var); libMesh::DenseSubVector<libMesh::Real> &F_T = context.get_elem_residual(this->_T_var); libMesh::DenseSubVector<libMesh::Real> &F_p = context.get_elem_residual(this->_p_var); unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp = 0; qp != n_qpoints; ++qp) { libMesh::Number T; T = context.fixed_interior_value(this->_T_var, qp); libMesh::Number cp = this->_cp(T); libMesh::Number cv = cp + this->_R; libMesh::Number gamma = cp/cv; libMesh::Number one_over_gamma = 1.0/(gamma-1.0); libMesh::Number p0_dot = context.interior_value(this->_p0_var, qp ); libMesh::Number p0 = context.fixed_interior_value(this->_p0_var, qp ); for (unsigned int i=0; i != n_p0_dofs; i++) { F_p0(i) += p0_dot*one_over_gamma*JxW[qp]; } for (unsigned int i=0; i != n_T_dofs; i++) { F_T(i) -= p0_dot*T_phi[i][qp]*JxW[qp]; } for (unsigned int i=0; i != n_p_dofs; i++) { F_p(i) -= p0_dot/p0*p_phi[i][qp]*JxW[qp]; } } return; }
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; }
void LowMachNavierStokesSPGSMStabilization<Mu,SH,TC>::assemble_continuity_mass_residual( bool /*compute_jacobian*/, AssemblyContext& context) { // The number of local degrees of freedom in each variable. const unsigned int n_p_dofs = context.get_dof_indices(this->_press_var.p()).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 pressure shape functions at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& p_dphi = context.get_element_fe(this->_press_var.p())->get_dphi(); libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_press_var.p()); // R_{p} unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; 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 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 ) ); if( this->mesh_dim(context) == 3 ) U(2) = context.fixed_interior_value( this->_flow_vars.w(), qp ); libMesh::Real tau_M = this->_stab_helper.compute_tau_momentum( context, qp, g, G, rho, U, mu, false ); libMesh::RealGradient RM_t = this->compute_res_momentum_transient( context, qp ); // Now a loop over the pressure degrees of freedom. This // computes the contributions of the continuity equation. for (unsigned int i=0; i != n_p_dofs; i++) { Fp(i) += tau_M*RM_t*p_dphi[i][qp]*JxW[qp]; } } return; }
void HeatTransferSPGSMStabilization<K>::mass_residual( bool compute_jacobian, AssemblyContext & context ) { if( compute_jacobian ) libmesh_not_implemented(); // 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(); 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} libMesh::FEBase* fe = context.get_element_fe(this->_temp_vars.T()); unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp ); libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp ); libMesh::RealGradient U( context.fixed_interior_value( this->_flow_vars.u(), qp ), context.fixed_interior_value( this->_flow_vars.v(), qp ) ); if( this->_flow_vars.dim() == 3 ) { U(2) = context.fixed_interior_value( this->_flow_vars.w(), qp ); } // Compute Conductivity at this qp libMesh::Real _k_qp = this->_k(context, qp); libMesh::Real tau_E = this->_stab_helper.compute_tau_energy( context, G, this->_rho, this->_Cp, _k_qp, U, false ); libMesh::Real RE_t = this->_stab_helper.compute_res_energy_transient( context, qp, this->_rho, this->_Cp ); for (unsigned int i=0; i != n_T_dofs; i++) { FT(i) -= tau_E*RE_t*this->_rho*this->_Cp*U*T_gradphi[i][qp]*JxW[qp]; } } }
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 LowMachNavierStokes<Mu,SH,TC>::assemble_energy_mass_residual( bool /*compute_jacobian*/, AssemblyContext& context ) { // Element Jacobian * quadrature weights for interior integration const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_T_var)->get_JxW(); // The shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& T_phi = context.get_element_fe(this->_T_var)->get_phi(); // The number of local degrees of freedom in each variable const unsigned int n_T_dofs = context.get_dof_indices(this->_T_var).size(); // The subvectors and submatrices we need to fill: libMesh::DenseSubVector<libMesh::Real> &F_T = context.get_elem_residual(this->_T_var); unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp = 0; qp != n_qpoints; ++qp) { // For the mass residual, we need to be a little careful. // The time integrator is handling the time-discretization // for us so we need to supply M(u_fixed)*u for the residual. // u_fixed will be given by the fixed_interior_* functions // while u will be given by the interior_* functions. libMesh::Real T_dot = context.interior_value(this->_T_var, qp); libMesh::Real T = context.fixed_interior_value(this->_T_var, qp); libMesh::Real cp = this->_cp(T); libMesh::Number rho = this->rho(T, this->get_p0_transient(context, qp)); for (unsigned int i = 0; i != n_T_dofs; ++i) { F_T(i) += rho*cp*T_dot*T_phi[i][qp]*JxW[qp]; } // End DoF loop i } // End quadrature loop qp return; }
void LowMachNavierStokes<Mu,SH,TC>::assemble_momentum_mass_residual( bool /*compute_jacobian*/, AssemblyContext& context ) { // Element Jacobian * quadrature weights for interior integration const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_u_var)->get_JxW(); // The shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& u_phi = context.get_element_fe(this->_u_var)->get_phi(); // The number of local degrees of freedom in each variable const unsigned int n_u_dofs = context.get_dof_indices(this->_u_var).size(); // for convenience if (this->_dim != 3) this->_w_var = this->_u_var; // The subvectors and submatrices we need to fill: libMesh::DenseSubVector<libMesh::Real> &F_u = context.get_elem_residual(this->_u_var); libMesh::DenseSubVector<libMesh::Real> &F_v = context.get_elem_residual(this->_v_var); libMesh::DenseSubVector<libMesh::Real> &F_w = context.get_elem_residual(this->_w_var); unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp = 0; qp != n_qpoints; ++qp) { // For the mass residual, we need to be a little careful. // The time integrator is handling the time-discretization // for us so we need to supply M(u_fixed)*u for the residual. // u_fixed will be given by the fixed_interior_* functions // while u will be given by the interior_* functions. libMesh::Real u_dot = context.interior_value(this->_u_var, qp); libMesh::Real v_dot = context.interior_value(this->_v_var, qp); libMesh::Real w_dot = 0.0; if( this->_dim == 3 ) w_dot = context.interior_value(this->_w_var, qp); libMesh::Real T = context.fixed_interior_value(this->_T_var, qp); libMesh::Number rho = this->rho(T, this->get_p0_transient(context, qp)); for (unsigned int i = 0; i != n_u_dofs; ++i) { F_u(i) += rho*u_dot*u_phi[i][qp]*JxW[qp]; F_v(i) += rho*v_dot*u_phi[i][qp]*JxW[qp]; if( this->_dim == 3 ) F_w(i) += rho*w_dot*u_phi[i][qp]*JxW[qp]; /* if( compute_jacobian ) { for (unsigned int j=0; j != n_u_dofs; j++) { // Assuming rho is constant w.r.t. u, v, w // and T (if Boussinesq added). libMesh::Real value = JxW[qp]*_rho*u_phi[i][qp]*u_phi[j][qp]; M_uu(i,j) += value; M_vv(i,j) += value; if( _dim == 3) { M_ww(i,j) += value; } } // End DoF loop j } // End Jacobian check */ } // End DoF loop i } // End quadrature loop qp return; }
void SpalartAllmarasSPGSMStabilization<Mu>::mass_residual ( bool compute_jacobian, AssemblyContext & context ) { // Get a pointer to the current element, we need this for computing the distance to wall for the // quadrature points libMesh::Elem &elem_pointer = context.get_elem(); // The number of local degrees of freedom in each variable. const unsigned int n_nu_dofs = context.get_dof_indices(this->_turbulence_vars.nu()).size(); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_turbulence_vars.nu())->get_JxW(); // The pressure shape functions at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& nu_gradphi = context.get_element_fe(this->_turbulence_vars.nu())->get_dphi(); libMesh::DenseSubVector<libMesh::Number> &Fnu = context.get_elem_residual(this->_turbulence_vars.nu()); // R_{nu} libMesh::FEBase* fe = context.get_element_fe(this->_turbulence_vars.nu()); unsigned int n_qpoints = context.get_element_qrule().n_points(); // Auto pointer to distance fcn evaluated at quad points std::unique_ptr< libMesh::DenseVector<libMesh::Real> > distance_qp; // Fill the vector of distances to quadrature points distance_qp = this->distance_function->interpolate(&elem_pointer, context.get_element_qrule().get_points()); for (unsigned int qp=0; qp != n_qpoints; qp++) { libMesh::RealGradient g = this->_stab_helper.compute_g( fe, context, qp ); libMesh::RealTensor G = this->_stab_helper.compute_G( fe, context, qp ); libMesh::RealGradient U( context.fixed_interior_value( this->_flow_vars.u(), qp ), context.fixed_interior_value( this->_flow_vars.v(), qp ) ); // Compute the viscosity at this qp libMesh::Real _mu_qp = this->_mu(context, qp); if( this->_flow_vars.dim() == 3 ) { U(2) = context.fixed_interior_value( this->_flow_vars.w(), qp ); } libMesh::Real tau_spalart = this->_stab_helper.compute_tau_spalart( context, qp, g, G, this->_rho, U, _mu_qp, this->_is_steady ); libMesh::Real RM_spalart = this->_stab_helper.compute_res_spalart_transient( context, qp, this->_rho ); for (unsigned int i=0; i != n_nu_dofs; i++) { Fnu(i) += -JxW[qp]*tau_spalart*RM_spalart*this->_rho*(U*nu_gradphi[i][qp]); } if( compute_jacobian ) { libmesh_not_implemented(); } } }
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; }