void LowMachNavierStokesSPGSMStabilization<Mu,SH,TC>::assemble_energy_time_deriv( 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.interior_value(this->_flow_vars.u(), qp); v = context.interior_value(this->_flow_vars.v(), qp); libMesh::Gradient grad_T = context.interior_gradient(this->_temp_vars.T(), qp); libMesh::NumberVectorValue U(u,v); if (this->mesh_dim(context) == 3) U(2) = context.interior_value(this->_flow_vars.w(), qp); // w libMesh::Real T = context.interior_value( this->_temp_vars.T(), qp ); libMesh::Real rho = this->rho( T, this->get_p0_steady( 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, this->_is_steady ); libMesh::Real RE_s = this->compute_res_energy_steady( context, qp ); for (unsigned int i=0; i != n_T_dofs; i++) { FT(i) -= rho_cp*tau_E*RE_s*U*T_gradphi[i][qp]*JxW[qp]; } } return; }
void ReactingLowMachNavierStokesStabilizationBase<Mixture,Evaluator>::compute_res_transient( AssemblyContext& context, unsigned int qp, libMesh::Real& RP_t, libMesh::RealGradient& RM_t, libMesh::Real& RE_t, std::vector<libMesh::Real>& Rs_t ) { libMesh::Real T = context.interior_value( this->_temp_vars.T(), qp ); std::vector<libMesh::Real> ws(this->n_species()); for(unsigned int s=0; s < this->_n_species; s++ ) { ws[s] = context.interior_value(this->_species_vars.species(s), qp); } Evaluator gas_evaluator( this->_gas_mixture ); const libMesh::Real R_mix = gas_evaluator.R_mix(ws); const libMesh::Real p0 = this->get_p0_transient(context,qp); const libMesh::Real rho = this->rho(T, p0, R_mix); const libMesh::Real cp = gas_evaluator.cp(T,p0,ws); const libMesh::Real M = gas_evaluator.M_mix( ws ); // M_dot = -M^2 \sum_s w_dot[s]/Ms libMesh::Real M_dot = 0.0; std::vector<libMesh::Real> ws_dot(this->n_species()); for(unsigned int s=0; s < this->n_species(); s++) { context.interior_rate(this->_species_vars.species(s), qp, ws_dot[s]); // Start accumulating M_dot M_dot += ws_dot[s]/this->_gas_mixture.M(s); } libMesh::Real M_dot_over_M = M_dot*(-M); libMesh::RealGradient u_dot; context.interior_rate(this->_flow_vars.u(), qp, u_dot(0)); context.interior_rate(this->_flow_vars.v(), qp, u_dot(1)); if(this->mesh_dim(context) == 3) context.interior_rate(this->_flow_vars.w(), qp, u_dot(2)); libMesh::Real T_dot; context.interior_rate(this->_temp_vars.T(), qp, T_dot); RP_t = -T_dot/T + M_dot_over_M; RM_t = rho*u_dot; RE_t = rho*cp*T_dot; for(unsigned int s=0; s < this->n_species(); s++) { Rs_t[s] = rho*ws_dot[s]; } return; }
void LowMachNavierStokesSPGSMStabilization<Mu,SH,TC>::assemble_continuity_time_deriv( 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.interior_value( this->_temp_vars.T(), qp ); libMesh::Real mu = this->_mu(T); libMesh::Real rho = this->rho( T, this->get_p0_steady( context, qp ) ); libMesh::RealGradient U( context.interior_value( this->_flow_vars.u(), qp ), context.interior_value( this->_flow_vars.v(), qp ) ); if( this->mesh_dim(context) == 3 ) U(2) = context.interior_value( this->_flow_vars.w(), qp ); libMesh::Real tau_M = this->_stab_helper.compute_tau_momentum( context, qp, g, G, rho, U, mu, this->_is_steady ); libMesh::RealGradient RM_s = this->compute_res_momentum_steady( 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_s*p_dphi[i][qp]*JxW[qp]; } } return; }
void HeatTransferSPGSMStabilization<K>::element_time_derivative ( 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(); 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.interior_value( this->_flow_vars.u(), qp ), context.interior_value( this->_flow_vars.v(), qp ) ); if( this->_flow_vars.dim() == 3 ) { U(2) = context.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, this->_is_steady ); libMesh::Real RE_s = this->_stab_helper.compute_res_energy_steady( context, qp, this->_rho, this->_Cp, _k_qp ); for (unsigned int i=0; i != n_T_dofs; i++) { FT(i) += -tau_E*RE_s*this->_rho*this->_Cp*U*T_gradphi[i][qp]*JxW[qp]; } if( compute_jacobian ) { libmesh_not_implemented(); } } }
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 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 LowMachNavierStokes<Mu,SH,TC>::assemble_thermo_press_elem_time_deriv( 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 number of local degrees of freedom in each variable const unsigned int n_p0_dofs = context.get_dof_indices(this->_p0_var).size(); // The subvectors and submatrices we need to fill: libMesh::DenseSubVector<libMesh::Real> &F_p0 = context.get_elem_residual(this->_p0_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.interior_value(this->_T_var, qp); libMesh::Gradient grad_u, grad_v, grad_w; grad_u = context.interior_gradient(this->_u_var, qp); grad_v = context.interior_gradient(this->_v_var, qp); if (this->_dim == 3) grad_w = context.interior_gradient(this->_w_var, qp); libMesh::Number divU = grad_u(0) + grad_v(1); if(this->_dim==3) divU += grad_w(2); //libMesh::Number cp = this->_cp(T); //libMesh::Number cv = cp + this->_R; //libMesh::Number gamma = cp/cv; //libMesh::Number gamma_ratio = gamma/(gamma-1.0); libMesh::Number p0 = context.interior_value( this->_p0_var, qp ); for (unsigned int i = 0; i != n_p0_dofs; ++i) { F_p0(i) += (p0/T - this->_p0/this->_T0)*JxW[qp]; //F_p0(i) -= p0*gamma_ratio*divU*JxW[qp]; } // End DoF loop i } return; }
libMesh::Real HeatTransferStabilizationHelper::compute_res_energy_transient( AssemblyContext& context, unsigned int qp, const libMesh::Real rho, const libMesh::Real Cp ) const { libMesh::Real T_dot = context.interior_value(this->_temp_vars.T_var(), qp); return rho*Cp*T_dot; }
void HeatTransferStabilizationHelper::compute_res_energy_transient_and_derivs ( AssemblyContext& context, unsigned int qp, const libMesh::Real rho, const libMesh::Real Cp, libMesh::Real &res, libMesh::Real &d_res_dTdot ) const { libMesh::Real T_dot = context.interior_value(this->_temp_vars.T_var(), qp); res = rho*Cp*T_dot; d_res_dTdot = rho*Cp; }
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; }
libMesh::Real SpalartAllmarasStabilizationHelper::compute_res_spalart_transient( AssemblyContext& context, unsigned int qp, const libMesh::Real rho ) const { libMesh::Number nu_dot = context.interior_value(this->_turbulence_vars.nu_var(), qp); return rho*nu_dot; }
void HeatTransfer::element_time_derivative( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("HeatTransfer::element_time_derivative"); #endif // The number of local degrees of freedom in each variable. const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size(); const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u_var()).size(); //TODO: check n_T_dofs is same as n_u_dofs, n_v_dofs, n_w_dofs // We get some references to cell-specific data that // will be used to assemble the linear system. // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(_temp_vars.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(_temp_vars.T_var())->get_phi(); // The velocity shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& vel_phi = context.get_element_fe(_flow_vars.u_var())->get_phi(); // The temperature shape function gradients (in global coords.) // at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi = context.get_element_fe(_temp_vars.T_var())->get_dphi(); const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(this->_flow_vars.u_var())->get_xyz(); libMesh::DenseSubMatrix<libMesh::Number> &KTT = context.get_elem_jacobian(_temp_vars.T_var(), _temp_vars.T_var()); // R_{T},{T} libMesh::DenseSubMatrix<libMesh::Number> &KTu = context.get_elem_jacobian(_temp_vars.T_var(), _flow_vars.u_var()); // R_{T},{u} libMesh::DenseSubMatrix<libMesh::Number> &KTv = context.get_elem_jacobian(_temp_vars.T_var(), _flow_vars.v_var()); // R_{T},{v} libMesh::DenseSubMatrix<libMesh::Number>* KTw = NULL; libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(_temp_vars.T_var()); // R_{T} if( this->_dim == 3 ) { KTw = &context.get_elem_jacobian(_temp_vars.T_var(), _flow_vars.w_var()); // R_{T},{w} } // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { // Compute the solution & its gradient at the old Newton iterate. libMesh::Number u, v; u = context.interior_value(_flow_vars.u_var(), qp); v = context.interior_value(_flow_vars.v_var(), qp); libMesh::Gradient grad_T; grad_T = context.interior_gradient(_temp_vars.T_var(), qp); libMesh::NumberVectorValue U (u,v); if (_dim == 3) U(2) = context.interior_value(_flow_vars.w_var(), qp); const libMesh::Number r = u_qpoint[qp](0); libMesh::Real jac = JxW[qp]; if( _is_axisymmetric ) { jac *= r; } // First, an i-loop over the degrees of freedom. for (unsigned int i=0; i != n_T_dofs; i++) { FT(i) += jac * (-_rho*_Cp*T_phi[i][qp]*(U*grad_T) // convection term -_k*(T_gradphi[i][qp]*grad_T) ); // diffusion term if (compute_jacobian) { for (unsigned int j=0; j != n_T_dofs; j++) { // TODO: precompute some terms like: // _rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*T_grad_phi[j][qp]) KTT(i,j) += jac * (-_rho*_Cp*T_phi[i][qp]*(U*T_gradphi[j][qp]) // convection term -_k*(T_gradphi[i][qp]*T_gradphi[j][qp])); // diffusion term } // end of the inner dof (j) loop // Matrix contributions for the Tu, Tv and Tw couplings (n_T_dofs same as n_u_dofs, n_v_dofs and n_w_dofs) for (unsigned int j=0; j != n_u_dofs; j++) { KTu(i,j) += jac*(-_rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(0))); KTv(i,j) += jac*(-_rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(1))); if (_dim == 3) (*KTw)(i,j) += jac*(-_rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(2))); } // end of the inner dof (j) loop } // end - if (compute_jacobian && context.get_elem_solution_derivative()) } // end of the outer dof (i) loop } // end of the quadrature point (qp) loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("HeatTransfer::element_time_derivative"); #endif return; }
void AveragedTurbine<Mu>::element_time_derivative( bool compute_jacobian, AssemblyContext& context, CachedValues& /* cache */ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("AveragedTurbine::element_time_derivative"); #endif // Element Jacobian * quadrature weights for interior integration const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_flow_vars.u())->get_JxW(); // The shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& u_phi = context.get_element_fe(this->_flow_vars.u())->get_phi(); const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(this->_flow_vars.u())->get_xyz(); // 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(); // The subvectors and submatrices we need to fill: libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.u()); // R_{u},{u} libMesh::DenseSubMatrix<libMesh::Number> &Kuv = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.v()); // R_{u},{v} libMesh::DenseSubMatrix<libMesh::Number> &Kvu = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.u()); // R_{v},{u} libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.v()); // R_{v},{v} libMesh::DenseSubMatrix<libMesh::Number> &Kus = context.get_elem_jacobian(this->_flow_vars.u(), this->fan_speed_var()); // R_{u},{s} libMesh::DenseSubMatrix<libMesh::Number> &Ksu = context.get_elem_jacobian(this->fan_speed_var(), this->_flow_vars.u()); // R_{s},{u} libMesh::DenseSubMatrix<libMesh::Number> &Kvs = context.get_elem_jacobian(this->_flow_vars.v(), this->fan_speed_var()); // R_{v},{s} libMesh::DenseSubMatrix<libMesh::Number> &Ksv = context.get_elem_jacobian(this->fan_speed_var(), this->_flow_vars.v()); // R_{s},{v} libMesh::DenseSubMatrix<libMesh::Number> &Kss = context.get_elem_jacobian(this->fan_speed_var(), this->fan_speed_var()); // R_{s},{s} libMesh::DenseSubMatrix<libMesh::Number>* Kwu = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kwv = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kww = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kuw = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kvw = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Ksw = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kws = NULL; 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::Number>* Fw = NULL; libMesh::DenseSubVector<libMesh::Number> &Fs = context.get_elem_residual(this->fan_speed_var()); // R_{s} if( this->mesh_dim(context) == 3 ) { Kuw = &context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.w()); // R_{u},{w} Kvw = &context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.w()); // R_{v},{w} Kwu = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.u()); // R_{w},{u} Kwv = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.v()); // R_{w},{v} Kww = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.w()); // R_{w},{w} Fw = &context.get_elem_residual(this->_flow_vars.w()); // R_{w} Ksw = &context.get_elem_jacobian(this->fan_speed_var(), this->_flow_vars.w()); // R_{s},{w} Kws = &context.get_elem_jacobian(this->_flow_vars.w(), this->fan_speed_var()); // R_{w},{s} 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++) { // Compute the solution at the old Newton iterate. libMesh::Number u, v, s; u = context.interior_value(this->_flow_vars.u(), qp); v = context.interior_value(this->_flow_vars.v(), qp); s = context.interior_value(this->fan_speed_var(), qp); libMesh::NumberVectorValue U(u,v); if (this->mesh_dim(context) == 3) U(2) = context.interior_value(this->_flow_vars.w(), qp); // w libMesh::NumberVectorValue U_B_1; libMesh::NumberVectorValue F; libMesh::NumberTensorValue dFdU; libMesh::NumberTensorValue* dFdU_ptr = compute_jacobian ? &dFdU : NULL; libMesh::NumberVectorValue dFds; libMesh::NumberVectorValue* dFds_ptr = compute_jacobian ? &dFds : NULL; if (!this->compute_force(u_qpoint[qp], context.time, U, s, U_B_1, F, dFdU_ptr, dFds_ptr)) continue; libMesh::Real jac = JxW[qp]; // Using this dot product to derive torque *depends* on s=1 // and U_B_1 corresponding to 1 rad/sec base velocity; this // means that the length of U_B_1 is equal to radius. // F is the force on the air, so *negative* F is the force on // the turbine. Fs(0) -= U_B_1 * F * jac; if (compute_jacobian) { Kss(0,0) -= U_B_1 * dFds * jac; for (unsigned int j=0; j != n_u_dofs; j++) { libMesh::Real jac_j = JxW[qp] * u_phi[j][qp]; for (unsigned int d=0; d != 3; ++d) { Ksu(0,j) -= jac_j * U_B_1(d) * dFdU(d,0); Ksv(0,j) -= jac_j * U_B_1(d) * dFdU(d,1); } if (this->mesh_dim(context) == 3) { for (unsigned int d=0; d != 3; ++d) (*Ksw)(0,j) -= jac_j * U_B_1(d) * dFdU(d,2); } } // End j dof loop } for (unsigned int i=0; i != n_u_dofs; i++) { const libMesh::Number jac_i = jac * u_phi[i][qp]; Fu(i) += F(0)*jac_i; Fv(i) += F(1)*jac_i; if( this->mesh_dim(context) == 3 ) (*Fw)(i) += F(2)*jac_i; if( compute_jacobian ) { Kus(i,0) += dFds(0) * jac_i; Kvs(i,0) += dFds(1) * jac_i; if( this->mesh_dim(context) == 3 ) (*Kws)(i,0) += dFds(2) * jac_i; for (unsigned int j=0; j != n_u_dofs; j++) { const libMesh::Number jac_ij = jac_i * u_phi[j][qp]; Kuu(i,j) += jac_ij * dFdU(0,0); Kuv(i,j) += jac_ij * dFdU(0,1); Kvu(i,j) += jac_ij * dFdU(1,0); Kvv(i,j) += jac_ij * dFdU(1,1); if( this->mesh_dim(context) == 3 ) { (*Kuw)(i,j) += jac_ij * dFdU(0,2); (*Kvw)(i,j) += jac_ij * dFdU(1,2); (*Kwu)(i,j) += jac_ij * dFdU(2,0); (*Kwv)(i,j) += jac_ij * dFdU(2,1); (*Kww)(i,j) += jac_ij * dFdU(2,2); } } } } } #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("AveragedTurbine::element_time_derivative"); #endif return; }
void VelocityPenalty<Mu>::element_time_derivative( bool compute_jacobian, AssemblyContext& context, CachedValues& /* cache */ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("VelocityPenalty::element_time_derivative"); #endif // Element Jacobian * quadrature weights for interior integration const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_flow_vars.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->_flow_vars.u_var())->get_phi(); const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(this->_flow_vars.u_var())->get_xyz(); // The number of local degrees of freedom in each variable const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u_var()).size(); // The subvectors and submatrices we need to fill: libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(this->_flow_vars.u_var(), this->_flow_vars.u_var()); // R_{u},{u} libMesh::DenseSubMatrix<libMesh::Number> &Kuv = context.get_elem_jacobian(this->_flow_vars.u_var(), this->_flow_vars.v_var()); // R_{u},{v} libMesh::DenseSubMatrix<libMesh::Number> &Kvu = context.get_elem_jacobian(this->_flow_vars.v_var(), this->_flow_vars.u_var()); // R_{v},{u} libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(this->_flow_vars.v_var(), this->_flow_vars.v_var()); // R_{v},{v} libMesh::DenseSubMatrix<libMesh::Number>* Kwu = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kwv = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kww = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kuw = NULL; libMesh::DenseSubMatrix<libMesh::Number>* Kvw = NULL; libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u_var()); // R_{u} libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v_var()); // R_{v} libMesh::DenseSubVector<libMesh::Number>* Fw = NULL; if( this->_dim == 3 ) { Kuw = &context.get_elem_jacobian(this->_flow_vars.u_var(), this->_flow_vars.w_var()); // R_{u},{w} Kvw = &context.get_elem_jacobian(this->_flow_vars.v_var(), this->_flow_vars.w_var()); // R_{v},{w} Kwu = &context.get_elem_jacobian(this->_flow_vars.w_var(), this->_flow_vars.u_var()); // R_{w},{u} Kwv = &context.get_elem_jacobian(this->_flow_vars.w_var(), this->_flow_vars.v_var()); // R_{w},{v} Kww = &context.get_elem_jacobian(this->_flow_vars.w_var(), this->_flow_vars.w_var()); // R_{w},{w} Fw = &context.get_elem_residual(this->_flow_vars.w_var()); // R_{w} } unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { // Compute the solution at the old Newton iterate. libMesh::Number u, v; u = context.interior_value(this->_flow_vars.u_var(), qp); v = context.interior_value(this->_flow_vars.v_var(), qp); libMesh::NumberVectorValue U(u,v); if (this->_dim == 3) U(2) = context.interior_value(this->_flow_vars.w_var(), qp); // w libMesh::NumberVectorValue F; libMesh::NumberTensorValue dFdU; libMesh::NumberTensorValue* dFdU_ptr = compute_jacobian ? &dFdU : NULL; if (!this->compute_force(u_qpoint[qp], context, U, F, dFdU_ptr)) continue; const libMesh::Real jac = JxW[qp]; for (unsigned int i=0; i != n_u_dofs; i++) { const libMesh::Number jac_i = jac * u_phi[i][qp]; Fu(i) += F(0)*jac_i; Fv(i) += F(1)*jac_i; if( this->_dim == 3 ) { (*Fw)(i) += F(2)*jac_i; } if( compute_jacobian ) { for (unsigned int j=0; j != n_u_dofs; j++) { const libMesh::Number jac_ij = context.get_elem_solution_derivative() * jac_i * u_phi[j][qp]; Kuu(i,j) += jac_ij * dFdU(0,0); Kuv(i,j) += jac_ij * dFdU(0,1); Kvu(i,j) += jac_ij * dFdU(1,0); Kvv(i,j) += jac_ij * dFdU(1,1); if( this->_dim == 3 ) { (*Kuw)(i,j) += jac_ij * dFdU(0,2); (*Kvw)(i,j) += jac_ij * dFdU(1,2); (*Kwu)(i,j) += jac_ij * dFdU(2,0); (*Kwv)(i,j) += jac_ij * dFdU(2,1); (*Kww)(i,j) += jac_ij * dFdU(2,2); } } } } } #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("VelocityPenalty::element_time_derivative"); #endif return; }
void BoussinesqBuoyancyAdjointStabilization<Mu>::element_time_derivative( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("BoussinesqBuoyancyAdjointStabilization::element_time_derivative"); #endif // The number of local degrees of freedom in each variable. const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u_var()).size(); const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size(); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(_flow_vars.u_var())->get_JxW(); const std::vector<std::vector<libMesh::Real> >& T_phi = context.get_element_fe(this->_temp_vars.T_var())->get_phi(); const std::vector<std::vector<libMesh::Real> >& u_phi = context.get_element_fe(this->_flow_vars.u_var())->get_phi(); const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi = context.get_element_fe(this->_flow_vars.u_var())->get_dphi(); const std::vector<std::vector<libMesh::RealTensor> >& u_hessphi = context.get_element_fe(this->_flow_vars.u_var())->get_d2phi(); // Get residuals and jacobians libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(_flow_vars.u_var()); // R_{u} libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(_flow_vars.v_var()); // R_{v} libMesh::DenseSubVector<libMesh::Number> *Fw = NULL; libMesh::DenseSubMatrix<libMesh::Number> &KuT = context.get_elem_jacobian(_flow_vars.u_var(), _temp_vars.T_var()); // J_{uT} libMesh::DenseSubMatrix<libMesh::Number> &KvT = context.get_elem_jacobian(_flow_vars.v_var(), _temp_vars.T_var()); // J_{vT} libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(_flow_vars.u_var(), _flow_vars.u_var()); // J_{uu} libMesh::DenseSubMatrix<libMesh::Number> &Kuv = context.get_elem_jacobian(_flow_vars.u_var(), _flow_vars.v_var()); // J_{uv} libMesh::DenseSubMatrix<libMesh::Number> &Kvu = context.get_elem_jacobian(_flow_vars.v_var(), _flow_vars.u_var()); // J_{vu} libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(_flow_vars.v_var(), _flow_vars.v_var()); // J_{vv} libMesh::DenseSubMatrix<libMesh::Number> *KwT = NULL; libMesh::DenseSubMatrix<libMesh::Number> *Kuw = NULL; libMesh::DenseSubMatrix<libMesh::Number> *Kvw = NULL; libMesh::DenseSubMatrix<libMesh::Number> *Kwu = NULL; libMesh::DenseSubMatrix<libMesh::Number> *Kwv = NULL; libMesh::DenseSubMatrix<libMesh::Number> *Kww = NULL; if(this->_dim == 3) { Fw = &context.get_elem_residual(this->_flow_vars.w_var()); // R_{w} KwT = &context.get_elem_jacobian (_flow_vars.w_var(), _temp_vars.T_var()); // J_{wT} Kuw = &context.get_elem_jacobian (_flow_vars.u_var(), _flow_vars.w_var()); // J_{uw} Kvw = &context.get_elem_jacobian (_flow_vars.v_var(), _flow_vars.w_var()); // J_{vw} Kwu = &context.get_elem_jacobian (_flow_vars.w_var(), _flow_vars.u_var()); // J_{wu} Kwv = &context.get_elem_jacobian (_flow_vars.w_var(), _flow_vars.v_var()); // J_{wv} Kww = &context.get_elem_jacobian (_flow_vars.w_var(), _flow_vars.w_var()); // J_{ww} } // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u_var()); 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.interior_value( this->_flow_vars.u_var(), qp ), context.interior_value( this->_flow_vars.v_var(), qp ) ); if( this->_dim == 3 ) { U(2) = context.interior_value( this->_flow_vars.w_var(), qp ); } // Compute the viscosity at this qp libMesh::Real mu_qp = this->_mu(context, qp); libMesh::Real tau_M; libMesh::Real d_tau_M_d_rho; libMesh::Gradient d_tau_M_dU; if (compute_jacobian) this->_stab_helper.compute_tau_momentum_and_derivs ( context, qp, g, G, this->_rho, U, mu_qp, tau_M, d_tau_M_d_rho, d_tau_M_dU, this->_is_steady ); else tau_M = this->_stab_helper.compute_tau_momentum ( context, qp, g, G, this->_rho, U, mu_qp, this->_is_steady ); // Compute the solution & its gradient at the old Newton iterate. libMesh::Number T; T = context.interior_value(_temp_vars.T_var(), qp); libMesh::RealGradient d_residual_dT = _rho_ref*_beta_T*_g; // d_residual_dU = 0 libMesh::RealGradient residual = (T-_T_ref)*d_residual_dT; for (unsigned int i=0; i != n_u_dofs; i++) { libMesh::Real test_func = this->_rho*U*u_gradphi[i][qp] + mu_qp*( u_hessphi[i][qp](0,0) + u_hessphi[i][qp](1,1) + u_hessphi[i][qp](2,2) ); Fu(i) += -tau_M*residual(0)*test_func*JxW[qp]; Fv(i) += -tau_M*residual(1)*test_func*JxW[qp]; if (_dim == 3) { (*Fw)(i) += -tau_M*residual(2)*test_func*JxW[qp]; } if (compute_jacobian) { libMesh::Gradient d_test_func_dU = this->_rho*u_gradphi[i][qp]; // d_test_func_dT = 0 for (unsigned int j=0; j != n_u_dofs; ++j) { Kuu(i,j) += -tau_M*residual(0)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); Kuu(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*residual(0)*test_func*JxW[qp] * context.get_elem_solution_derivative(); Kuv(i,j) += -tau_M*residual(0)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); Kuv(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*residual(0)*test_func*JxW[qp] * context.get_elem_solution_derivative(); Kvu(i,j) += -tau_M*residual(1)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); Kvu(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*residual(1)*test_func*JxW[qp] * context.get_elem_solution_derivative(); Kvv(i,j) += -tau_M*residual(1)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); Kvv(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*residual(1)*test_func*JxW[qp] * context.get_elem_solution_derivative(); } for (unsigned int j=0; j != n_T_dofs; ++j) { // KuT(i,j) += -tau_M*residual(0)*dtest_func_dT[j]*JxW[qp] * context.get_elem_solution_derivative(); KuT(i,j) += -tau_M*d_residual_dT(0)*T_phi[j][qp]*test_func*JxW[qp] * context.get_elem_solution_derivative(); // KvT(i,j) += -tau_M*residual(1)*dtest_func_dT[j]*JxW[qp] * context.get_elem_solution_derivative(); KvT(i,j) += -tau_M*d_residual_dT(1)*T_phi[j][qp]*test_func*JxW[qp] * context.get_elem_solution_derivative(); } if (_dim == 3) { for (unsigned int j=0; j != n_T_dofs; ++j) { // KwT(i,j) += -tau_M*residual(2)*dtest_func_dT[j]*JxW[qp] * context.get_elem_solution_derivative(); (*KwT)(i,j) += -tau_M*d_residual_dT(2)*T_phi[j][qp]*test_func*JxW[qp] * context.get_elem_solution_derivative(); } for (unsigned int j=0; j != n_u_dofs; ++j) { (*Kuw)(i,j) += -tau_M*residual(0)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); (*Kuw)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*residual(0)*test_func*JxW[qp] * context.get_elem_solution_derivative(); (*Kvw)(i,j) += -tau_M*residual(1)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); (*Kvw)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*residual(1)*test_func*JxW[qp] * context.get_elem_solution_derivative(); (*Kwu)(i,j) += -tau_M*residual(2)*d_test_func_dU(0)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); (*Kwu)(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*residual(2)*test_func*JxW[qp] * context.get_elem_solution_derivative(); (*Kwv)(i,j) += -tau_M*residual(2)*d_test_func_dU(1)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); (*Kwv)(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*residual(2)*test_func*JxW[qp] * context.get_elem_solution_derivative(); (*Kww)(i,j) += -tau_M*residual(2)*d_test_func_dU(2)*u_phi[j][qp]*JxW[qp] * context.get_elem_solution_derivative(); (*Kww)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*residual(2)*test_func*JxW[qp] * context.get_elem_solution_derivative(); } } } // End compute_jacobian check } // End i dof loop } // End quadrature loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("BoussinesqBuoyancyAdjointStabilization::element_time_derivative"); #endif return; }
void BoussinesqBuoyancyAdjointStabilization<Mu>::element_constraint( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("BoussinesqBuoyancyAdjointStabilization::element_constraint"); #endif // The number of local degrees of freedom in each variable. const unsigned int n_p_dofs = context.get_dof_indices(_flow_vars.p_var()).size(); const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u_var()).size(); const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size(); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(_flow_vars.u_var())->get_JxW(); const std::vector<std::vector<libMesh::Real> >& T_phi = context.get_element_fe(this->_temp_vars.T_var())->get_phi(); const std::vector<std::vector<libMesh::Real> >& u_phi = context.get_element_fe(this->_flow_vars.u_var())->get_phi(); const std::vector<std::vector<libMesh::RealGradient> >& p_dphi = context.get_element_fe(this->_flow_vars.p_var())->get_dphi(); libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_flow_vars.p_var()); // R_{p} libMesh::DenseSubMatrix<libMesh::Number> &KpT = context.get_elem_jacobian(_flow_vars.p_var(), _temp_vars.T_var()); // J_{pT} libMesh::DenseSubMatrix<libMesh::Number> &Kpu = context.get_elem_jacobian(_flow_vars.p_var(), _flow_vars.u_var()); // J_{pu} libMesh::DenseSubMatrix<libMesh::Number> &Kpv = context.get_elem_jacobian(_flow_vars.p_var(), _flow_vars.v_var()); // J_{pv} libMesh::DenseSubMatrix<libMesh::Number> *Kpw = NULL; if(this->_dim == 3) { Kpw = &context.get_elem_jacobian (_flow_vars.p_var(), _flow_vars.w_var()); // J_{pw} } // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u_var()); 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.interior_value( this->_flow_vars.u_var(), qp ), context.interior_value( this->_flow_vars.v_var(), qp ) ); if( this->_dim == 3 ) { U(2) = context.interior_value( this->_flow_vars.w_var(), qp ); } // Compute the viscosity at this qp libMesh::Real mu_qp = this->_mu(context, qp); libMesh::Real tau_M; libMesh::Real d_tau_M_d_rho; libMesh::Gradient d_tau_M_dU; if (compute_jacobian) this->_stab_helper.compute_tau_momentum_and_derivs ( context, qp, g, G, this->_rho, U, mu_qp, tau_M, d_tau_M_d_rho, d_tau_M_dU, this->_is_steady ); else tau_M = this->_stab_helper.compute_tau_momentum ( context, qp, g, G, this->_rho, U, mu_qp, this->_is_steady ); // Compute the solution & its gradient at the old Newton iterate. libMesh::Number T; T = context.interior_value(_temp_vars.T_var(), qp); libMesh::RealGradient d_residual_dT = _rho_ref*_beta_T*_g; // d_residual_dU = 0 libMesh::RealGradient residual = (T-_T_ref)*d_residual_dT; // First, an i-loop over the velocity degrees of freedom. // We know that n_u_dofs == n_v_dofs so we can compute contributions // for both at the same time. for (unsigned int i=0; i != n_p_dofs; i++) { Fp(i) += tau_M*residual*p_dphi[i][qp]*JxW[qp]; if (compute_jacobian) { for (unsigned int j=0; j != n_T_dofs; ++j) { KpT(i,j) += tau_M*d_residual_dT*T_phi[j][qp]*p_dphi[i][qp]*JxW[qp] * context.get_elem_solution_derivative(); } for (unsigned int j=0; j != n_u_dofs; ++j) { Kpu(i,j) += d_tau_M_dU(0)*u_phi[j][qp]*residual*p_dphi[i][qp]*JxW[qp] * context.get_elem_solution_derivative(); Kpv(i,j) += d_tau_M_dU(1)*u_phi[j][qp]*residual*p_dphi[i][qp]*JxW[qp] * context.get_elem_solution_derivative(); } if( this->_dim == 3 ) for (unsigned int j=0; j != n_u_dofs; ++j) { (*Kpw)(i,j) += d_tau_M_dU(2)*u_phi[j][qp]*residual*p_dphi[i][qp]*JxW[qp] * context.get_elem_solution_derivative(); } } } } // End quadrature loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("BoussinesqBuoyancyAdjointStabilization::element_constraint"); #endif return; }
void PracticeCDRinv::element_time_derivative( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ){ // The number of local degrees of freedom in each variable. const unsigned int n_c_dofs = context.get_dof_indices(_c_var).size(); // We get some references to cell-specific data that // will be used to assemble the linear system. // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(_c_var)->get_JxW(); // The temperature shape function gradients (in global coords.) // at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& dphi = context.get_element_fe(_c_var)->get_dphi(); const std::vector<std::vector<libMesh::Real> >& phi = context.get_element_fe(_c_var)->get_phi(); const std::vector<libMesh::Point>& q_points = context.get_element_fe(_c_var)->get_xyz(); libMesh::DenseSubMatrix<libMesh::Number> &J_c_zc = context.get_elem_jacobian(_c_var, _zc_var); libMesh::DenseSubMatrix<libMesh::Number> &J_c_c = context.get_elem_jacobian(_c_var, _c_var); libMesh::DenseSubMatrix<libMesh::Number> &J_zc_c = context.get_elem_jacobian(_zc_var, _c_var); libMesh::DenseSubMatrix<libMesh::Number> &J_zc_fc = context.get_elem_jacobian(_zc_var, _fc_var); libMesh::DenseSubMatrix<libMesh::Number> &J_fc_zc = context.get_elem_jacobian(_fc_var, _zc_var); libMesh::DenseSubMatrix<libMesh::Number> &J_fc_fc = context.get_elem_jacobian(_fc_var, _fc_var); libMesh::DenseSubVector<libMesh::Number> &Rc = context.get_elem_residual( _c_var );; libMesh::DenseSubVector<libMesh::Number> &Rzc = context.get_elem_residual( _zc_var ); libMesh::DenseSubVector<libMesh::Number> &Rfc = context.get_elem_residual( _fc_var ); // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++){ libMesh::Number c = context.interior_value(_c_var, qp), zc = context.interior_value(_zc_var, qp), fc = context.interior_value(_fc_var, qp); libMesh::Gradient grad_c = context.interior_gradient(_c_var, qp), grad_zc = context.interior_gradient(_zc_var, qp), grad_fc = context.interior_gradient(_fc_var, qp); //location of quadrature point const libMesh::Real ptx = q_points[qp](0); const libMesh::Real pty = q_points[qp](1); int xind, yind; libMesh::Real xdist = 1.e10; libMesh::Real ydist = 1.e10; for(int ii=0; ii<x_pts.size(); ii++){ libMesh::Real tmp = std::abs(ptx - x_pts[ii]); if(xdist > tmp){ xdist = tmp; xind = ii; } else break; } for(int jj=0; jj<y_pts[xind].size(); jj++){ libMesh::Real tmp = std::abs(pty - y_pts[xind][jj]); if(ydist > tmp){ ydist = tmp; yind = jj; } else break; } libMesh::Real u = vel_field[xind][yind](0); libMesh::Real v = vel_field[xind][yind](1); libMesh::NumberVectorValue U (u, v); // First, an i-loop over the degrees of freedom. for (unsigned int i=0; i != n_c_dofs; i++){ Rc(i) += JxW[qp]*(-_k*grad_zc*dphi[i][qp] + U*grad_zc*phi[i][qp] + 2*_R*zc*c*phi[i][qp]); Rzc(i) += JxW[qp]*(-_k*grad_c*dphi[i][qp] - U*grad_c*phi[i][qp] + _R*c*c*phi[i][qp] + fc*phi[i][qp]); Rfc(i) += JxW[qp]*(_beta*grad_fc*dphi[i][qp] + zc*phi[i][qp]); if (compute_jacobian){ for (unsigned int j=0; j != n_c_dofs; j++){ J_c_zc(i,j) += JxW[qp]*(-_k*dphi[j][qp]*dphi[i][qp] + U*dphi[j][qp]*phi[i][qp] + 2*_R*phi[j][qp]*c*phi[i][qp]); J_c_c(i,j) += JxW[qp]*(2*_R*zc*phi[j][qp]*phi[i][qp]); J_zc_c(i,j) += JxW[qp]*(-_k*dphi[j][qp]*dphi[i][qp] - U*dphi[j][qp]*phi[i][qp] + 2*_R*c*phi[j][qp]*phi[i][qp]); J_zc_fc(i,j) += JxW[qp]*(phi[j][qp]*phi[i][qp]); J_fc_zc(i,j) += JxW[qp]*(phi[j][qp]*phi[i][qp]); J_fc_fc(i,j) += JxW[qp]*(_beta*dphi[j][qp]*dphi[i][qp]); } // end of the inner dof (j) loop } // end - if (compute_jacobian && context.get_elem_solution_derivative()) } // end of the outer dof (i) loop } // end of the quadrature point (qp) loop for(unsigned int dnum=0; dnum<datavals.size(); dnum++){ libMesh::Point data_point = datapts[dnum]; if(context.get_elem().contains_point(data_point)){ libMesh::Number cpred = context.point_value(_c_var, data_point); libMesh::Number cstar = datavals[dnum]; unsigned int dim = context.get_system().get_mesh().mesh_dimension(); libMesh::FEType fe_type = context.get_element_fe(_c_var)->get_fe_type(); //go between physical and reference element libMesh::Point c_master = libMesh::FEInterface::inverse_map(dim, fe_type, &context.get_elem(), data_point); std::vector<libMesh::Real> point_phi(n_c_dofs); for (unsigned int i=0; i != n_c_dofs; i++){ //get value of basis function at mapped point in reference (master) element point_phi[i] = libMesh::FEInterface::shape(dim, fe_type, &context.get_elem(), i, c_master); } for (unsigned int i=0; i != n_c_dofs; i++){ Rc(i) += (cpred - cstar)*point_phi[i]; if (compute_jacobian){ for (unsigned int j=0; j != n_c_dofs; j++) J_c_c(i,j) += point_phi[j]*point_phi[i] ; } } } } return; }
void LowMachNavierStokesSPGSMStabilization<Mu,SH,TC>::assemble_momentum_time_deriv( 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.interior_value( this->_temp_vars.T(), qp ); libMesh::Real rho = this->rho( T, this->get_p0_steady( context, qp ) ); libMesh::RealGradient U( context.interior_value(this->_flow_vars.u(), qp), context.interior_value(this->_flow_vars.v(), qp) ); libMesh::RealGradient grad_u = context.interior_gradient(this->_flow_vars.u(), qp); libMesh::RealGradient grad_v = context.interior_gradient(this->_flow_vars.v(), qp); libMesh::RealGradient grad_w; if( this->mesh_dim(context) == 3 ) { U(2) = context.interior_value(this->_flow_vars.w(), qp); grad_w = context.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 mu = this->_mu(T); libMesh::Real tau_M = this->_stab_helper.compute_tau_momentum( context, qp, g, G, rho, U, mu, this->_is_steady ); libMesh::Real tau_C = this->_stab_helper.compute_tau_continuity( tau_M, g ); libMesh::Real RC_s = this->compute_res_continuity_steady( context, qp ); libMesh::RealGradient RM_s = this->compute_res_momentum_steady( context, qp ); for (unsigned int i=0; i != n_u_dofs; i++) { Fu(i) += ( - tau_C*RC_s*u_gradphi[i][qp](0) - tau_M*RM_s(0)*rho*U*u_gradphi[i][qp] )*JxW[qp]; Fv(i) += ( - tau_C*RC_s*u_gradphi[i][qp](1) - tau_M*RM_s(1)*rho*U*u_gradphi[i][qp] )*JxW[qp]; if( this->mesh_dim(context) == 3 ) { (*Fw)(i) += ( - tau_C*RC_s*u_gradphi[i][qp](2) - tau_M*RM_s(2)*rho*U*u_gradphi[i][qp] )*JxW[qp]; } } } return; }
void AxisymmetricHeatTransfer<Conductivity>::element_time_derivative( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("AxisymmetricHeatTransfer::element_time_derivative"); #endif // The number of local degrees of freedom in each variable. const unsigned int n_T_dofs = context.get_dof_indices(_T_var).size(); const unsigned int n_u_dofs = context.get_dof_indices(_u_r_var).size(); //TODO: check n_T_dofs is same as n_u_dofs, n_v_dofs, n_w_dofs // We get some references to cell-specific data that // will be used to assemble the linear system. // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(_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(_T_var)->get_phi(); // The velocity shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& vel_phi = context.get_element_fe(_u_r_var)->get_phi(); // The temperature shape function gradients (in global coords.) // at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& T_gradphi = context.get_element_fe(_T_var)->get_dphi(); // Physical location of the quadrature points const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(_u_r_var)->get_xyz(); // The subvectors and submatrices we need to fill: libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(_T_var); // R_{T} libMesh::DenseSubMatrix<libMesh::Number> &KTT = context.get_elem_jacobian(_T_var, _T_var); // R_{T},{T} libMesh::DenseSubMatrix<libMesh::Number> &KTr = context.get_elem_jacobian(_T_var, _u_r_var); // R_{T},{r} libMesh::DenseSubMatrix<libMesh::Number> &KTz = context.get_elem_jacobian(_T_var, _u_z_var); // R_{T},{z} // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { const libMesh::Number r = u_qpoint[qp](0); // Compute the solution & its gradient at the old Newton iterate. libMesh::Number u_r, u_z; u_r = context.interior_value(_u_r_var, qp); u_z = context.interior_value(_u_z_var, qp); libMesh::Gradient grad_T; grad_T = context.interior_gradient(_T_var, qp); libMesh::NumberVectorValue U (u_r,u_z); libMesh::Number k = this->_k( context, qp ); // FIXME - once we have T-dependent k, we'll need its // derivatives in Jacobians // libMesh::Number dk_dT = this->_k.deriv( T ); // First, an i-loop over the degrees of freedom. for (unsigned int i=0; i != n_T_dofs; i++) { FT(i) += JxW[qp]*r* (-_rho*_Cp*T_phi[i][qp]*(U*grad_T) // convection term -k*(T_gradphi[i][qp]*grad_T) ); // diffusion term if (compute_jacobian) { libmesh_assert (context.get_elem_solution_derivative() == 1.0); for (unsigned int j=0; j != n_T_dofs; j++) { // TODO: precompute some terms like: // _rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*T_grad_phi[j][qp]) KTT(i,j) += JxW[qp] * context.get_elem_solution_derivative() *r* (-_rho*_Cp*T_phi[i][qp]*(U*T_gradphi[j][qp]) // convection term -k*(T_gradphi[i][qp]*T_gradphi[j][qp])); // diffusion term } // end of the inner dof (j) loop #if 0 if( dk_dT != 0.0 ) { for (unsigned int j=0; j != n_T_dofs; j++) { // TODO: precompute some terms like: KTT(i,j) -= JxW[qp] * context.get_elem_solution_derivative() *r*( dk_dT*T_phi[j][qp]*T_gradphi[i][qp]*grad_T ); } } #endif // Matrix contributions for the Tu, Tv and Tw couplings (n_T_dofs same as n_u_dofs, n_v_dofs and n_w_dofs) for (unsigned int j=0; j != n_u_dofs; j++) { KTr(i,j) += JxW[qp] * context.get_elem_solution_derivative() *r*(-_rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(0))); KTz(i,j) += JxW[qp] * context.get_elem_solution_derivative() *r*(-_rho*_Cp*T_phi[i][qp]*(vel_phi[j][qp]*grad_T(1))); } // end of the inner dof (j) loop } // end - if (compute_jacobian && context.get_elem_solution_derivative()) } // end of the outer dof (i) loop } // end of the quadrature point (qp) loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("AxisymmetricHeatTransfer::element_time_derivative"); #endif 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 AxisymmetricBoussinesqBuoyancy::element_time_derivative( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("AxisymmetricBoussinesqBuoyancy::element_time_derivative"); #endif // The number of local degrees of freedom in each variable. const unsigned int n_u_dofs = context.get_dof_indices(_flow_vars.u_var()).size(); const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size(); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(_flow_vars.u_var())->get_JxW(); // The velocity shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& vel_phi = context.get_element_fe(_flow_vars.u_var())->get_phi(); // The temperature shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& T_phi = context.get_element_fe(_temp_vars.T_var())->get_phi(); // Physical location of the quadrature points const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(_flow_vars.u_var())->get_xyz(); // Get residuals libMesh::DenseSubVector<libMesh::Number> &Fr = context.get_elem_residual(_flow_vars.u_var()); // R_{r} libMesh::DenseSubVector<libMesh::Number> &Fz = context.get_elem_residual(_flow_vars.v_var()); // R_{z} // Get Jacobians libMesh::DenseSubMatrix<libMesh::Number> &KrT = context.get_elem_jacobian(_flow_vars.u_var(), _temp_vars.T_var()); // R_{r},{T} libMesh::DenseSubMatrix<libMesh::Number> &KzT = context.get_elem_jacobian(_flow_vars.v_var(), _temp_vars.T_var()); // R_{z},{T} // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { const libMesh::Number r = u_qpoint[qp](0); // Compute the solution & its gradient at the old Newton iterate. libMesh::Number T; T = context.interior_value(_temp_vars.T_var(), qp); // First, an i-loop over the velocity degrees of freedom. // We know that n_u_dofs == n_v_dofs so we can compute contributions // for both at the same time. for (unsigned int i=0; i != n_u_dofs; i++) { Fr(i) += -_rho*_beta_T*(T - _T_ref)*_g(0)*vel_phi[i][qp]*r*JxW[qp]; Fz(i) += -_rho*_beta_T*(T - _T_ref)*_g(1)*vel_phi[i][qp]*r*JxW[qp]; if (compute_jacobian && context.get_elem_solution_derivative()) { for (unsigned int j=0; j != n_T_dofs; j++) { const libMesh::Number val = -_rho*_beta_T*vel_phi[i][qp]*T_phi[j][qp]*r*JxW[qp] * context.get_elem_solution_derivative(); KrT(i,j) += val*_g(0); KzT(i,j) += val*_g(1); } // End j dof loop } // End compute_jacobian check } // End i dof loop } // End quadrature loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("AxisymmetricBoussinesqBuoyancy::element_time_derivative"); #endif return; }
void VelocityPenaltyAdjointStabilization<Mu>::element_constraint( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("VelocityPenaltyAdjointStabilization::element_constraint"); #endif // 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(); const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size(); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(this->_flow_vars.u())->get_JxW(); const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(this->_flow_vars.u())->get_xyz(); const std::vector<std::vector<libMesh::Real> >& u_phi = context.get_element_fe(this->_flow_vars.u())->get_phi(); 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} libMesh::DenseSubMatrix<libMesh::Number> &Kpu = context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.u()); // J_{pu} libMesh::DenseSubMatrix<libMesh::Number> &Kpv = context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.v()); // J_{pv} libMesh::DenseSubMatrix<libMesh::Number> *Kpw = NULL; if(this->mesh_dim(context) == 3) { Kpw = &context.get_elem_jacobian (this->_press_var.p(), this->_flow_vars.w()); // J_{pw} } // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); libMesh::FEBase* fe = context.get_element_fe(this->_flow_vars.u()); 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.interior_value( this->_flow_vars.u(), qp ), context.interior_value( this->_flow_vars.v(), qp ) ); if( this->mesh_dim(context) == 3 ) { U(2) = context.interior_value( this->_flow_vars.w(), qp ); } // Compute the viscosity at this qp libMesh::Real mu_qp = this->_mu(context, qp); libMesh::Real tau_M; libMesh::Real d_tau_M_d_rho; libMesh::Gradient d_tau_M_dU; if (compute_jacobian) this->_stab_helper.compute_tau_momentum_and_derivs ( context, qp, g, G, this->_rho, U, mu_qp, tau_M, d_tau_M_d_rho, d_tau_M_dU, this->_is_steady ); else tau_M = this->_stab_helper.compute_tau_momentum ( context, qp, g, G, this->_rho, U, mu_qp, this->_is_steady ); libMesh::NumberVectorValue F; libMesh::NumberTensorValue dFdU; libMesh::NumberTensorValue* dFdU_ptr = compute_jacobian ? &dFdU : NULL; if (!this->compute_force(u_qpoint[qp], context, U, F, dFdU_ptr)) continue; // First, an i-loop over the velocity degrees of freedom. // We know that n_u_dofs == n_v_dofs so we can compute contributions // for both at the same time. for (unsigned int i=0; i != n_p_dofs; i++) { Fp(i) += -tau_M*F*p_dphi[i][qp]*JxW[qp]; if (compute_jacobian) { for (unsigned int j=0; j != n_u_dofs; ++j) { Kpu(i,j) += -d_tau_M_dU(0)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp]*context.get_elem_solution_derivative(); Kpv(i,j) += -d_tau_M_dU(1)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp]*context.get_elem_solution_derivative(); for (unsigned int d=0; d != 3; ++d) { Kpu(i,j) += -tau_M*dFdU(d,0)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp]*context.get_elem_solution_derivative(); Kpv(i,j) += -tau_M*dFdU(d,1)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp]*context.get_elem_solution_derivative(); } } if( this->mesh_dim(context) == 3 ) for (unsigned int j=0; j != n_u_dofs; ++j) { (*Kpw)(i,j) += -d_tau_M_dU(2)*u_phi[j][qp]*F*p_dphi[i][qp]*JxW[qp]*context.get_elem_solution_derivative(); for (unsigned int d=0; d != 3; ++d) { (*Kpw)(i,j) += -tau_M*dFdU(d,2)*u_phi[j][qp]*p_dphi[i][qp](d)*JxW[qp]*context.get_elem_solution_derivative(); } } } } } // End quadrature loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("VelocityPenaltyAdjointStabilization::element_constraint"); #endif return; }
void ReactingLowMachNavierStokesStabilizationBase<Mixture,Evaluator>::compute_res_steady( AssemblyContext& context, unsigned int qp, libMesh::Real& RP_s, libMesh::RealGradient& RM_s, libMesh::Real& RE_s, std::vector<libMesh::Real>& Rs_s ) { Rs_s.resize(this->n_species(),0.0); // Grab r-coordinate for axisymmetric terms // We're assuming all variables are using the same quadrature rule libMesh::Real r = (context.get_element_fe(this->_flow_vars.u())->get_xyz())[qp](0); libMesh::RealGradient grad_p = context.interior_gradient(this->_press_var.p(), qp); libMesh::RealGradient grad_u = context.interior_gradient(this->_flow_vars.u(), qp); libMesh::RealGradient grad_v = context.interior_gradient(this->_flow_vars.v(), qp); libMesh::RealGradient U( context.interior_value(this->_flow_vars.u(), qp), context.interior_value(this->_flow_vars.v(), qp) ); libMesh::Real divU = grad_u(0) + grad_v(1); if( this->_is_axisymmetric ) divU += U(0)/r; if(this->mesh_dim(context) == 3) { U(2) = context.interior_value(this->_flow_vars.w(), qp); divU += (context.interior_gradient(this->_flow_vars.w(), qp))(2); } // We don't add axisymmetric terms here since we don't directly use hess_{u,v} // axisymmetric terms are built into divGradU, etc. functions below libMesh::RealTensor hess_u = context.interior_hessian(this->_flow_vars.u(), qp); libMesh::RealTensor hess_v = context.interior_hessian(this->_flow_vars.v(), qp); libMesh::Real T = context.interior_value(this->_temp_vars.T(), qp); libMesh::Gradient grad_T = context.interior_gradient(this->_temp_vars.T(), qp); libMesh::Tensor hess_T = context.interior_hessian(this->_temp_vars.T(), qp); libMesh::Real hess_T_term = hess_T(0,0) + hess_T(1,1); #if LIBMESH_DIM > 2 hess_T_term += hess_T(2,2); #endif // Add axisymmetric terms, if needed if( this->_is_axisymmetric ) hess_T_term += grad_T(0)/r; std::vector<libMesh::Real> ws(this->n_species()); std::vector<libMesh::RealGradient> grad_ws(this->n_species()); std::vector<libMesh::RealTensor> hess_ws(this->n_species()); for(unsigned int s=0; s < this->_n_species; s++ ) { ws[s] = context.interior_value(this->_species_vars.species(s), qp); grad_ws[s] = context.interior_gradient(this->_species_vars.species(s), qp); hess_ws[s] = context.interior_hessian(this->_species_vars.species(s), qp); } Evaluator gas_evaluator( this->_gas_mixture ); const libMesh::Real R_mix = gas_evaluator.R_mix(ws); const libMesh::Real p0 = this->get_p0_steady(context,qp); libMesh::Real rho = this->rho(T, p0, R_mix ); libMesh::Real cp = gas_evaluator.cp(T,p0,ws); libMesh::Real M = gas_evaluator.M_mix( ws ); std::vector<libMesh::Real> D( this->n_species() ); libMesh::Real mu, k; gas_evaluator.mu_and_k_and_D( T, rho, cp, ws, mu, k, D ); // grad_rho = drho_dT*gradT + \sum_s drho_dws*grad_ws const libMesh::Real drho_dT = -p0/(R_mix*T*T); libMesh::RealGradient grad_rho = drho_dT*grad_T; for(unsigned int s=0; s < this->_n_species; s++ ) { libMesh::Real Ms = gas_evaluator.M(s); libMesh::Real R_uni = Constants::R_universal/1000.0; /* J/kmol-K --> J/mol-K */ // drho_dws = -p0/(T*R_mix*R_mix)*dR_dws // dR_dws = R_uni*d_dws(1/M) // d_dws(1/M) = d_dws(\sum_s w_s/Ms) = 1/Ms const libMesh::Real drho_dws = -p0/(R_mix*R_mix*T)*R_uni/Ms; grad_rho += drho_dws*grad_ws[s]; } libMesh::RealGradient rhoUdotGradU; libMesh::RealGradient divGradU; libMesh::RealGradient divGradUT; libMesh::RealGradient divdivU; if( this->mesh_dim(context) < 3 ) { rhoUdotGradU = rho*_stab_helper.UdotGradU( U, grad_u, grad_v ); // Call axisymmetric versions if we are doing an axisymmetric run if( this->_is_axisymmetric ) { divGradU = _stab_helper.div_GradU_axi( r, U, grad_u, grad_v, hess_u, hess_v ); divGradUT = _stab_helper.div_GradU_T_axi( r, U, grad_u, hess_u, hess_v ); divdivU = _stab_helper.div_divU_I_axi( r, U, grad_u, hess_u, hess_v ); } else { divGradU = _stab_helper.div_GradU( hess_u, hess_v ); divGradUT = _stab_helper.div_GradU_T( hess_u, hess_v ); divdivU = _stab_helper.div_divU_I( hess_u, hess_v ); } } else { libMesh::RealGradient grad_w = context.interior_gradient(this->_flow_vars.w(), qp); libMesh::RealTensor hess_w = context.interior_hessian(this->_flow_vars.w(), qp); rhoUdotGradU = rho*_stab_helper.UdotGradU( U, grad_u, grad_v, grad_w ); divGradU = _stab_helper.div_GradU( hess_u, hess_v, hess_w ); divGradUT = _stab_helper.div_GradU_T( hess_u, hess_v, hess_w ); divdivU = _stab_helper.div_divU_I( hess_u, hess_v, hess_w ); } // Terms if we have vicosity derivatives w.r.t. temp. /* if( this->_mu.deriv(T) != 0.0 ) { libMesh::Gradient gradTgradu( grad_T*grad_u, grad_T*grad_v ); libMesh::Gradient gradTgraduT( grad_T(0)*grad_u(0) + grad_T(1)*grad_u(1), grad_T(0)*grad_v(0) + grad_T(1)*grad_v(1) ); libMesh::Real divU = grad_u(0) + grad_v(1); libMesh::Gradient gradTdivU( grad_T(0)*divU, grad_T(1)*divU ); if(this->mesh_dim(context) == 3) { libMesh::Gradient grad_w = context.interior_gradient(this->_flow_vars.w(), qp); gradTgradu(2) = grad_T*grad_w; gradTgraduT(0) += grad_T(2)*grad_u(2); gradTgraduT(1) += grad_T(2)*grad_v(2); gradTgraduT(2) = grad_T(0)*grad_w(0) + grad_T(1)*grad_w(1) + grad_T(2)*grad_w(2); divU += grad_w(2); gradTdivU(0) += grad_T(0)*grad_w(2); gradTdivU(1) += grad_T(1)*grad_w(2); gradTdivU(2) += grad_T(2)*divU; } divT += this->_mu.deriv(T)*( gradTgradu + gradTgraduT - 2.0/3.0*gradTdivU ); } */ // Axisymmetric terms already built in libMesh::RealGradient div_stress = mu*(divGradU + divGradUT - 2.0/3.0*divdivU); std::vector<libMesh::Real> omega_dot(this->n_species()); gas_evaluator.omega_dot(T,rho,ws,omega_dot); libMesh::Real chem_term = 0.0; libMesh::Gradient mass_term(0.0,0.0,0.0); for(unsigned int s=0; s < this->_n_species; s++ ) { // Start accumulating chemistry term for energy residual libMesh::Real h_s=gas_evaluator.h_s(T,s); chem_term += h_s*omega_dot[s]; /* Accumulate mass term for continuity residual mass_term = grad_M/M */ mass_term += grad_ws[s]/this->_gas_mixture.M(s); libMesh::Real hess_s_term = hess_ws[s](0,0) + hess_ws[s](1,1); #if LIBMESH_DIM > 2 hess_s_term += hess_ws[s](2,2); #endif // Add axisymmetric terms, if needed if( this->_is_axisymmetric ) hess_s_term += grad_ws[s](0)/r; // Species residual /*! \todo Still missing derivative of species diffusion coefficient. rho*grad_D[s]*grad_ws[s] */ Rs_s[s] = rho*U*grad_ws[s] - rho*D[s]*hess_s_term - grad_rho*D[s]*grad_ws[s] - omega_dot[s]; } mass_term *= M; // Continuity residual RP_s = divU - (U*grad_T)/T - U*mass_term; // Momentum residual RM_s = rhoUdotGradU + grad_p - div_stress - rho*(this->_g); // Energy residual // - this->_k.deriv(T)*(grad_T*grad_T) RE_s = rho*U*cp*grad_T - k*(hess_T_term) + chem_term; return; }
void LowMachNavierStokes<Mu,SH,TC>::compute_element_time_derivative_cache( const AssemblyContext& context, CachedValues& cache ) { const unsigned int n_qpoints = context.get_element_qrule().n_points(); std::vector<libMesh::Real> u, v, w, T, p, p0; u.resize(n_qpoints); v.resize(n_qpoints); if( this->_dim > 2 ) w.resize(n_qpoints); T.resize(n_qpoints); p.resize(n_qpoints); p0.resize(n_qpoints); std::vector<libMesh::Gradient> grad_u, grad_v, grad_w, grad_T; grad_u.resize(n_qpoints); grad_v.resize(n_qpoints); if( this->_dim > 2 ) grad_w.resize(n_qpoints); grad_T.resize(n_qpoints); for (unsigned int qp = 0; qp != n_qpoints; ++qp) { u[qp] = context.interior_value(this->_u_var, qp); v[qp] = context.interior_value(this->_v_var, qp); grad_u[qp] = context.interior_gradient(this->_u_var, qp); grad_v[qp] = context.interior_gradient(this->_v_var, qp); if( this->_dim > 2 ) { w[qp] = context.interior_value(this->_w_var, qp); grad_w[qp] = context.interior_gradient(this->_w_var, qp); } T[qp] = context.interior_value(this->_T_var, qp); grad_T[qp] = context.interior_gradient(this->_T_var, qp); p[qp] = context.interior_value(this->_p_var, qp); p0[qp] = this->get_p0_steady(context, qp); } cache.set_values(Cache::X_VELOCITY, u); cache.set_values(Cache::Y_VELOCITY, v); cache.set_gradient_values(Cache::X_VELOCITY_GRAD, grad_u); cache.set_gradient_values(Cache::Y_VELOCITY_GRAD, grad_v); if(this->_dim > 2) { cache.set_values(Cache::Z_VELOCITY, w); cache.set_gradient_values(Cache::Z_VELOCITY_GRAD, grad_w); } cache.set_values(Cache::TEMPERATURE, T); cache.set_gradient_values(Cache::TEMPERATURE_GRAD, grad_T); cache.set_values(Cache::PRESSURE, p); cache.set_values(Cache::THERMO_PRESSURE, p0); return; }
void SpalartAllmarasSPGSMStabilization<Mu>::element_time_derivative ( 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 viscosity shape function gradients (in global coords.) // at interior quadrature points. const std::vector<std::vector<libMesh::RealGradient> >& nu_gradphi = context.get_element_fe(this->_turbulence_vars.nu())->get_dphi(); // Quadrature point locations //const std::vector<libMesh::Point>& nu_qpoint = //context.get_element_fe(this->_turbulence_vars.nu())->get_xyz(); //libMesh::DenseSubMatrix<libMesh::Number> &Knunu = context.get_elem_jacobian(this->_turbulence_vars.nu(), this->_turbulence_vars.nu()); // R_{nu},{nu} 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::Gradient grad_nu; grad_nu = context.interior_gradient(this->_turbulence_vars.nu(), qp); libMesh::Real jac = JxW[qp]; // The physical viscosity libMesh::Real _mu_qp = this->_mu(context, qp); // To be fixed // For the channel flow we will just set the distance function analytically //(*distance_qp)(qp) = std::min(fabs(y),fabs(1 - y)); // 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); // Stabilization terms 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_spalart = this->_stab_helper.compute_tau_spalart( context, qp, g, G, this->_rho, U, _mu_qp, this->_is_steady ); libMesh::Number RM_spalart = this->_stab_helper.compute_res_spalart_steady( context, qp, this->_rho, _mu_qp, (*distance_qp)(qp), this->_infinite_distance ); for (unsigned int i=0; i != n_nu_dofs; i++) { Fnu(i) += jac*( -tau_spalart*RM_spalart*this->_rho*(U*nu_gradphi[i][qp]) ); } if( compute_jacobian ) { libmesh_not_implemented(); } } }
void BoussinesqBuoyancy::element_time_derivative ( 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(_flow_vars.u()).size(); const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T()).size(); // Element Jacobian * quadrature weights for interior integration. const std::vector<libMesh::Real> &JxW = context.get_element_fe(_flow_vars.u())->get_JxW(); // The velocity shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& vel_phi = context.get_element_fe(_flow_vars.u())->get_phi(); // The temperature shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& T_phi = context.get_element_fe(_temp_vars.T())->get_phi(); // Get residuals libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(_flow_vars.u()); // R_{u} libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(_flow_vars.v()); // R_{v} libMesh::DenseSubVector<libMesh::Number>* Fw = NULL; // Get Jacobians libMesh::DenseSubMatrix<libMesh::Number> &KuT = context.get_elem_jacobian(_flow_vars.u(), _temp_vars.T()); // R_{u},{T} libMesh::DenseSubMatrix<libMesh::Number> &KvT = context.get_elem_jacobian(_flow_vars.v(), _temp_vars.T()); // R_{v},{T} libMesh::DenseSubMatrix<libMesh::Number>* KwT = NULL; if( this->_flow_vars.dim() == 3 ) { Fw = &context.get_elem_residual(_flow_vars.w()); // R_{w} KwT = &context.get_elem_jacobian(_flow_vars.w(), _temp_vars.T()); // R_{w},{T} } // Now we will build the element Jacobian and residual. // Constructing the residual requires the solution and its // gradient from the previous timestep. This must be // calculated at each quadrature point by summing the // solution degree-of-freedom values by the appropriate // weight functions. unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp=0; qp != n_qpoints; qp++) { // Compute the solution & its gradient at the old Newton iterate. libMesh::Number T; T = context.interior_value(_temp_vars.T(), qp); // First, an i-loop over the velocity degrees of freedom. // We know that n_u_dofs == n_v_dofs so we can compute contributions // for both at the same time. for (unsigned int i=0; i != n_u_dofs; i++) { Fu(i) += -_rho*_beta_T*(T - _T_ref)*_g(0)*vel_phi[i][qp]*JxW[qp]; Fv(i) += -_rho*_beta_T*(T - _T_ref)*_g(1)*vel_phi[i][qp]*JxW[qp]; if (this->_flow_vars.dim() == 3) (*Fw)(i) += -_rho*_beta_T*(T - _T_ref)*_g(2)*vel_phi[i][qp]*JxW[qp]; if (compute_jacobian) { for (unsigned int j=0; j != n_T_dofs; j++) { KuT(i,j) += context.get_elem_solution_derivative() * -_rho*_beta_T*_g(0)*vel_phi[i][qp]*T_phi[j][qp]*JxW[qp]; KvT(i,j) += context.get_elem_solution_derivative() * -_rho*_beta_T*_g(1)*vel_phi[i][qp]*T_phi[j][qp]*JxW[qp]; if (this->_flow_vars.dim() == 3) (*KwT)(i,j) += context.get_elem_solution_derivative() * -_rho*_beta_T*_g(2)*vel_phi[i][qp]*T_phi[j][qp]*JxW[qp]; } // End j dof loop } // End compute_jacobian check } // End i dof loop } // End quadrature loop }
void HeatTransfer::mass_residual( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("HeatTransfer::mass_residual"); #endif // First we get some references to cell-specific data that // will be used to assemble the linear system. // Element Jacobian * quadrature weights for interior integration const std::vector<libMesh::Real> &JxW = context.get_element_fe(_temp_vars.T_var())->get_JxW(); // The shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& phi = context.get_element_fe(_temp_vars.T_var())->get_phi(); const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(this->_flow_vars.u_var())->get_xyz(); // The number of local degrees of freedom in each variable const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size(); // The subvectors and submatrices we need to fill: libMesh::DenseSubVector<libMesh::Real> &F = context.get_elem_residual(_temp_vars.T_var()); libMesh::DenseSubMatrix<libMesh::Real> &M = context.get_elem_jacobian(_temp_vars.T_var(), _temp_vars.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(_temp_vars.T_var(), qp); const libMesh::Number r = u_qpoint[qp](0); libMesh::Real jac = JxW[qp]; if( _is_axisymmetric ) { jac *= r; } for (unsigned int i = 0; i != n_T_dofs; ++i) { F(i) += _rho*_Cp*T_dot*phi[i][qp]*jac; if( compute_jacobian ) { for (unsigned int j=0; j != n_T_dofs; j++) { // We're assuming rho, cp are constant w.r.t. T here. M(i,j) += _rho*_Cp*phi[j][qp]*phi[i][qp]*jac; } }// End of check on Jacobian } // End of element dof loop } // End of the quadrature point loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("HeatTransfer::mass_residual"); #endif return; }