本文整理汇总了C++中Gradient::add_scaled方法的典型用法代码示例。如果您正苦于以下问题:C++ Gradient::add_scaled方法的具体用法?C++ Gradient::add_scaled怎么用?C++ Gradient::add_scaled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gradient
的用法示例。
在下文中一共展示了Gradient::add_scaled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_projection
void HPCoarsenTest::add_projection(const System & system,
const Elem * elem,
unsigned int var)
{
// If we have children, we need to add their projections instead
if (!elem->active())
{
libmesh_assert(!elem->subactive());
for (unsigned int c = 0; c != elem->n_children(); ++c)
this->add_projection(system, elem->child(c), var);
return;
}
// The DofMap for this system
const DofMap & dof_map = system.get_dof_map();
// The type of finite element to use for this variable
const FEType & fe_type = dof_map.variable_type (var);
const FEContinuity cont = fe->get_continuity();
fe->reinit(elem);
dof_map.dof_indices(elem, dof_indices, var);
const unsigned int n_dofs =
cast_int<unsigned int>(dof_indices.size());
FEInterface::inverse_map (system.get_mesh().mesh_dimension(),
fe_type, coarse, *xyz_values, coarse_qpoints);
fe_coarse->reinit(coarse, &coarse_qpoints);
const unsigned int n_coarse_dofs =
cast_int<unsigned int>(phi_coarse->size());
if (Uc.size() == 0)
{
Ke.resize(n_coarse_dofs, n_coarse_dofs);
Ke.zero();
Fe.resize(n_coarse_dofs);
Fe.zero();
Uc.resize(n_coarse_dofs);
Uc.zero();
}
libmesh_assert_equal_to (Uc.size(), phi_coarse->size());
// Loop over the quadrature points
for (unsigned int qp=0; qp<qrule->n_points(); qp++)
{
// The solution value at the quadrature point
Number val = libMesh::zero;
Gradient grad;
Tensor hess;
for (unsigned int i=0; i != n_dofs; i++)
{
dof_id_type dof_num = dof_indices[i];
val += (*phi)[i][qp] *
system.current_solution(dof_num);
if (cont == C_ZERO || cont == C_ONE)
grad.add_scaled((*dphi)[i][qp],system.current_solution(dof_num));
// grad += (*dphi)[i][qp] *
// system.current_solution(dof_num);
if (cont == C_ONE)
hess.add_scaled((*d2phi)[i][qp], system.current_solution(dof_num));
// hess += (*d2phi)[i][qp] *
// system.current_solution(dof_num);
}
// The projection matrix and vector
for (unsigned int i=0; i != Fe.size(); ++i)
{
Fe(i) += (*JxW)[qp] *
(*phi_coarse)[i][qp]*val;
if (cont == C_ZERO || cont == C_ONE)
Fe(i) += (*JxW)[qp] *
(grad*(*dphi_coarse)[i][qp]);
if (cont == C_ONE)
Fe(i) += (*JxW)[qp] *
hess.contract((*d2phi_coarse)[i][qp]);
// Fe(i) += (*JxW)[qp] *
// (*d2phi_coarse)[i][qp].contract(hess);
for (unsigned int j=0; j != Fe.size(); ++j)
{
Ke(i,j) += (*JxW)[qp] *
(*phi_coarse)[i][qp]*(*phi_coarse)[j][qp];
if (cont == C_ZERO || cont == C_ONE)
Ke(i,j) += (*JxW)[qp] *
(*dphi_coarse)[i][qp]*(*dphi_coarse)[j][qp];
if (cont == C_ONE)
Ke(i,j) += (*JxW)[qp] *
((*d2phi_coarse)[i][qp].contract((*d2phi_coarse)[j][qp]));
}
}
}
}
示例2: select_refinement
//.........这里部分代码省略.........
average_val /= n_vertices;
}
else
{
unsigned int old_elem_level = elem->p_level();
(const_cast<Elem *>(elem))->hack_p_level(old_elem_level - 1);
fe_coarse->reinit(elem, &(qrule->get_points()));
const unsigned int n_coarse_dofs =
cast_int<unsigned int>(phi_coarse->size());
(const_cast<Elem *>(elem))->hack_p_level(old_elem_level);
Ke.resize(n_coarse_dofs, n_coarse_dofs);
Ke.zero();
Fe.resize(n_coarse_dofs);
Fe.zero();
// Loop over the quadrature points
for (unsigned int qp=0; qp<qrule->n_points(); qp++)
{
// The solution value at the quadrature point
Number val = libMesh::zero;
Gradient grad;
Tensor hess;
for (unsigned int i=0; i != n_dofs; i++)
{
dof_id_type dof_num = dof_indices[i];
val += (*phi)[i][qp] *
system.current_solution(dof_num);
if (cont == C_ZERO || cont == C_ONE)
grad.add_scaled((*dphi)[i][qp], system.current_solution(dof_num));
// grad += (*dphi)[i][qp] *
// system.current_solution(dof_num);
if (cont == C_ONE)
hess.add_scaled((*d2phi)[i][qp], system.current_solution(dof_num));
// hess += (*d2phi)[i][qp] *
// system.current_solution(dof_num);
}
// The projection matrix and vector
for (unsigned int i=0; i != Fe.size(); ++i)
{
Fe(i) += (*JxW)[qp] *
(*phi_coarse)[i][qp]*val;
if (cont == C_ZERO || cont == C_ONE)
Fe(i) += (*JxW)[qp] *
grad * (*dphi_coarse)[i][qp];
if (cont == C_ONE)
Fe(i) += (*JxW)[qp] *
hess.contract((*d2phi_coarse)[i][qp]);
for (unsigned int j=0; j != Fe.size(); ++j)
{
Ke(i,j) += (*JxW)[qp] *
(*phi_coarse)[i][qp]*(*phi_coarse)[j][qp];
if (cont == C_ZERO || cont == C_ONE)
Ke(i,j) += (*JxW)[qp] *
(*dphi_coarse)[i][qp]*(*dphi_coarse)[j][qp];
if (cont == C_ONE)
Ke(i,j) += (*JxW)[qp] *
((*d2phi_coarse)[i][qp].contract((*d2phi_coarse)[j][qp]));
}
}