本文整理汇总了C++中AssemblyContext::get_elem_residual方法的典型用法代码示例。如果您正苦于以下问题:C++ AssemblyContext::get_elem_residual方法的具体用法?C++ AssemblyContext::get_elem_residual怎么用?C++ AssemblyContext::get_elem_residual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssemblyContext
的用法示例。
在下文中一共展示了AssemblyContext::get_elem_residual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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;
}
示例2: apply_neumann_normal
void BoundaryConditions::apply_neumann_normal( AssemblyContext& context,
const VariableIndex var,
const libMesh::Real sign,
const FEShape& value ) const
{
libMesh::FEGenericBase<FEShape>* side_fe = NULL;
context.get_side_fe( var, side_fe );
// The number of local degrees of freedom in each variable.
const unsigned int n_var_dofs = context.get_dof_indices(var).size();
// Element Jacobian * quadrature weight for side integration.
const std::vector<libMesh::Real> &JxW_side = side_fe->get_JxW();
// The var shape functions at side quadrature points.
const std::vector<std::vector<FEShape> >& var_phi_side = side_fe->get_phi();
libMesh::DenseSubVector<libMesh::Number> &F_var = context.get_elem_residual(var); // residual
unsigned int n_qpoints = context.get_side_qrule().n_points();
for (unsigned int qp=0; qp != n_qpoints; qp++)
{
for (unsigned int i=0; i != n_var_dofs; i++)
{
F_var(i) += sign*value*var_phi_side[i][qp]*JxW_side[qp];
}
}
return;
}
示例3: Fs
void AveragedTurbine<Mu>::nonlocal_time_derivative(bool compute_jacobian,
AssemblyContext& context,
CachedValues& /* cache */ )
{
libMesh::DenseSubMatrix<libMesh::Number> &Kss =
context.get_elem_jacobian(this->fan_speed_var(), this->fan_speed_var()); // R_{s},{s}
libMesh::DenseSubVector<libMesh::Number> &Fs =
context.get_elem_residual(this->fan_speed_var()); // R_{s}
const std::vector<libMesh::dof_id_type>& dof_indices =
context.get_dof_indices(this->fan_speed_var());
const libMesh::Number fan_speed =
context.get_system().current_solution(dof_indices[0]);
const libMesh::Number output_torque =
this->torque_function(libMesh::Point(0), fan_speed);
Fs(0) += output_torque;
if (compute_jacobian)
{
// FIXME: we should replace this FEM with a hook to the AD fparser stuff
const libMesh::Number epsilon = 1e-6;
const libMesh::Number output_torque_deriv =
(this->torque_function(libMesh::Point(0), fan_speed+epsilon) -
this->torque_function(libMesh::Point(0), fan_speed-epsilon)) / (2*epsilon);
Kss(0,0) += output_torque_deriv * context.get_elem_solution_derivative();
}
return;
}
示例4: F
void HeatConduction<K>::mass_residual( bool compute_jacobian,
AssemblyContext& context,
CachedValues& /*cache*/ )
{
// 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();
// 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_value function
// while u' will be given by the interior_rate function.
libMesh::Real T_dot;
context.interior_rate(_temp_vars.T_var(), qp, T_dot);
for (unsigned int i = 0; i != n_T_dofs; ++i)
{
F(i) -= JxW[qp]*(_rho*_Cp*T_dot*phi[i][qp] );
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) -=
context.get_elem_solution_rate_derivative()
* JxW[qp]*_rho*_Cp*phi[j][qp]*phi[i][qp] ;
}
}// End of check on Jacobian
} // End of element dof loop
} // End of the quadrature point loop
return;
}
示例5: U
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;
}
示例6: U
void LowMachNavierStokes<Mu,SH,TC>::assemble_mass_time_deriv( bool /*compute_jacobian*/,
AssemblyContext& context,
CachedValues& cache )
{
// The number of local degrees of freedom in each variable.
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->_u_var)->get_JxW();
// The pressure shape functions at interior quadrature points.
const std::vector<std::vector<libMesh::Real> >& p_phi =
context.get_element_fe(this->_p_var)->get_phi();
libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_p_var); // R_{p}
unsigned int n_qpoints = context.get_element_qrule().n_points();
for (unsigned int qp=0; qp != n_qpoints; qp++)
{
libMesh::Number u, v, T;
u = cache.get_cached_values(Cache::X_VELOCITY)[qp];
v = cache.get_cached_values(Cache::Y_VELOCITY)[qp];
T = cache.get_cached_values(Cache::TEMPERATURE)[qp];
libMesh::Gradient grad_u = cache.get_cached_gradient_values(Cache::X_VELOCITY_GRAD)[qp];
libMesh::Gradient grad_v = cache.get_cached_gradient_values(Cache::Y_VELOCITY_GRAD)[qp];
libMesh::Gradient grad_T = cache.get_cached_gradient_values(Cache::TEMPERATURE_GRAD)[qp];
libMesh::NumberVectorValue U(u,v);
if (this->_dim == 3)
U(2) = cache.get_cached_values(Cache::Z_VELOCITY)[qp]; // w
libMesh::Number divU = grad_u(0) + grad_v(1);
if (this->_dim == 3)
{
libMesh::Gradient grad_w = cache.get_cached_gradient_values(Cache::Z_VELOCITY_GRAD)[qp];
divU += grad_w(2);
}
// 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) += (-U*grad_T/T + divU)*p_phi[i][qp]*JxW[qp];
}
}
return;
}
示例7: pin_value
void BoundaryConditions::pin_value( AssemblyContext& context,
const CachedValues& /*cache*/,
const bool request_jacobian,
const VariableIndex var,
const double pin_value,
const libMesh::Point& pin_location,
const double penalty )
{
if (context.get_elem().contains_point(pin_location))
{
libMesh::FEGenericBase<libMesh::Real>* elem_fe = NULL;
context.get_element_fe( var, elem_fe );
libMesh::DenseSubVector<libMesh::Number> &F_var = context.get_elem_residual(var); // residual
libMesh::DenseSubMatrix<libMesh::Number> &K_var = context.get_elem_jacobian(var,var); // jacobian
// The number of local degrees of freedom in p variable.
const unsigned int n_var_dofs = context.get_dof_indices(var).size();
libMesh::Number var_value = context.point_value(var, pin_location);
libMesh::FEType fe_type = elem_fe->get_fe_type();
libMesh::Point point_loc_in_masterelem =
libMesh::FEInterface::inverse_map(context.get_dim(), fe_type, &context.get_elem(), pin_location);
std::vector<libMesh::Real> phi(n_var_dofs);
for (unsigned int i=0; i != n_var_dofs; i++)
{
phi[i] = libMesh::FEInterface::shape( context.get_dim(), fe_type, &context.get_elem(), i,
point_loc_in_masterelem );
}
for (unsigned int i=0; i != n_var_dofs; i++)
{
F_var(i) += penalty*(var_value - pin_value)*phi[i];
/** \todo What the hell is the context.get_elem_solution_derivative() all about? */
if (request_jacobian && context.get_elem_solution_derivative())
{
libmesh_assert (context.get_elem_solution_derivative() == 1.0);
for (unsigned int j=0; j != n_var_dofs; j++)
K_var(i,j) += penalty*phi[i]*phi[j];
} // End if request_jacobian
} // End i loop
} // End if pin_location
return;
}
示例8: U
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();
}
}
}
示例9: FT
void HeatTransferSource<SourceFunction>::element_time_derivative( bool /*compute_jacobian*/,
AssemblyContext& context,
CachedValues& /*cache*/ )
{
#ifdef GRINS_USE_GRVY_TIMERS
this->_timer->BeginTimer("HeatTransferSource::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();
// 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();
// Locations of quadrature points
const std::vector<libMesh::Point>& x_qp = context.get_element_fe(_temp_vars.T_var())->get_xyz();
// Get residuals
libMesh::DenseSubVector<libMesh::Number> &FT = context.get_elem_residual(_temp_vars.T_var()); // R_{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++)
{
libMesh::Real q = _source( x_qp[qp] );
for (unsigned int i=0; i != n_T_dofs; i++)
{
FT(i) += q*T_phi[i][qp]*JxW[qp];
}
}
#ifdef GRINS_USE_GRVY_TIMERS
this->_timer->EndTimer("HeatTransferSource::element_time_derivative");
#endif
return;
}
示例10: nonlocal_constraint
void ScalarODE::nonlocal_constraint(bool compute_jacobian,
AssemblyContext& context,
CachedValues& /* cache */ )
{
libMesh::DenseSubMatrix<libMesh::Number> &Kss =
context.get_elem_jacobian(_scalar_ode_var, _scalar_ode_var); // R_{s},{s}
libMesh::DenseSubVector<libMesh::Number> &Fs =
context.get_elem_residual(_scalar_ode_var); // R_{s}
const libMesh::Number constraint =
(*constraint_function)(context, libMesh::Point(0),
context.get_time());
Fs(0) += constraint;
if (compute_jacobian)
{
// FIXME: we should replace this hacky FDM with a hook to the
// AD fparser stuff
libMesh::DenseSubVector<libMesh::Number> &Us =
const_cast<libMesh::DenseSubVector<libMesh::Number>&>
(context.get_elem_solution(_scalar_ode_var)); // U_{s}
const libMesh::Number s = Us(0);
Us(0) = s + this->_epsilon;
libMesh::Number constraint_jacobian =
(*constraint_function)(context, libMesh::Point(0),
context.get_time());
Us(0) = s - this->_epsilon;
constraint_jacobian -=
(*constraint_function)(context, libMesh::Point(0),
context.get_time());
Us(0) = s;
constraint_jacobian /= (2*this->_epsilon);
Kss(0,0) += constraint_jacobian *
context.get_elem_solution_derivative();
}
return;
}
示例11:
void ConstantSourceTerm::element_time_derivative
( bool /*compute_jacobian*/, AssemblyContext & context )
{
for( std::vector<VariableIndex>::const_iterator v_it = _vars.begin();
v_it != _vars.end(); ++v_it )
{
VariableIndex var = *v_it;
// The number of local degrees of freedom in each variable.
const unsigned int n_dofs = context.get_dof_indices(var).size();
// Element Jacobian * quadrature weights for interior integration.
const std::vector<libMesh::Real> &JxW =
context.get_element_fe(var)->get_JxW();
// The temperature shape functions at interior quadrature points.
const std::vector<std::vector<libMesh::Real> >& phi =
context.get_element_fe(var)->get_phi();
// Get residuals
libMesh::DenseSubVector<libMesh::Number> &F_var = context.get_elem_residual(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++)
{
for (unsigned int i=0; i != n_dofs; i++)
{
F_var(i) += (this->_value)*phi[i][qp]*JxW[qp];
}
}
} // Variable loop
return;
}
示例12: Us
void AveragedTurbine<Mu>::nonlocal_mass_residual( bool compute_jacobian,
AssemblyContext& context,
CachedValues& /* cache */ )
{
libMesh::DenseSubMatrix<libMesh::Number> &Kss =
context.get_elem_jacobian(this->fan_speed_var(), this->fan_speed_var()); // R_{s},{s}
libMesh::DenseSubVector<libMesh::Number> &Fs =
context.get_elem_residual(this->fan_speed_var()); // R_{s}
const libMesh::DenseSubVector<libMesh::Number> &Us =
context.get_elem_solution_rate(this->fan_speed_var());
const libMesh::Number& fan_speed = Us(0);
Fs(0) -= this->moment_of_inertia * fan_speed;
if (compute_jacobian)
{
Kss(0,0) -= this->moment_of_inertia * context.get_elem_solution_rate_derivative();
}
return;
}
示例13: U
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;
//.........这里部分代码省略.........
示例14: U
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)
//.........这里部分代码省略.........
示例15: U
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();
}
}
}