本文整理汇总了C++中NumericVector::add_vector方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericVector::add_vector方法的具体用法?C++ NumericVector::add_vector怎么用?C++ NumericVector::add_vector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumericVector
的用法示例。
在下文中一共展示了NumericVector::add_vector方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
MooseVariable::add(NumericVector<Number> & residual)
{
if (_has_nodal_value)
residual.add_vector(&_nodal_u[0], _dof_indices);
if (_has_nodal_value_neighbor)
residual.add_vector(&_nodal_u_neighbor[0], _dof_indices_neighbor);
}
示例2: assemble_A_and_F
void AssembleOptimization::assemble_A_and_F()
{
A_matrix->zero();
F_vector->zero();
const MeshBase & mesh = _sys.get_mesh();
const unsigned int dim = mesh.mesh_dimension();
const unsigned int u_var = _sys.variable_number ("u");
const DofMap & dof_map = _sys.get_dof_map();
FEType fe_type = dof_map.variable_type(u_var);
UniquePtr<FEBase> fe (FEBase::build(dim, fe_type));
QGauss qrule (dim, fe_type.default_quadrature_order());
fe->attach_quadrature_rule (&qrule);
const std::vector<Real> & JxW = fe->get_JxW();
const std::vector<std::vector<Real> > & phi = fe->get_phi();
const std::vector<std::vector<RealGradient> > & dphi = fe->get_dphi();
std::vector<dof_id_type> dof_indices;
DenseMatrix<Number> Ke;
DenseVector<Number> Fe;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el; ++el)
{
const Elem * elem = *el;
dof_map.dof_indices (elem, dof_indices);
const unsigned int n_dofs = dof_indices.size();
fe->reinit (elem);
Ke.resize (n_dofs, n_dofs);
Fe.resize (n_dofs);
for (unsigned int qp=0; qp<qrule.n_points(); qp++)
{
for (unsigned int dof_i=0; dof_i<n_dofs; dof_i++)
{
for (unsigned int dof_j=0; dof_j<n_dofs; dof_j++)
{
Ke(dof_i, dof_j) += JxW[qp] * (dphi[dof_j][qp]* dphi[dof_i][qp]);
}
Fe(dof_i) += JxW[qp] * phi[dof_i][qp];
}
}
A_matrix->add_matrix (Ke, dof_indices);
F_vector->add_vector (Fe, dof_indices);
}
A_matrix->close();
F_vector->close();
}
示例3:
void SparseMatrix<T>::vector_mult_add (NumericVector<T>& dest,
const NumericVector<T>& arg) const
{
/* This functionality is actually implemented in the \p
NumericVector class. */
dest.add_vector(arg,*this);
}
示例4:
void
Assembly::addResidualBlock(NumericVector<Number> & residual, DenseVector<Number> & res_block, const std::vector<dof_id_type> & dof_indices, Real scaling_factor)
{
if (dof_indices.size() > 0 && res_block.size())
{
_temp_dof_indices = dof_indices;
_dof_map.constrain_element_vector(res_block, _temp_dof_indices, false);
if (scaling_factor != 1.0)
{
_tmp_Re = res_block;
_tmp_Re *= scaling_factor;
residual.add_vector(_tmp_Re, _temp_dof_indices);
}
else
{
residual.add_vector(res_block, _temp_dof_indices);
}
}
}
示例5: mooseAssert
void
Assembly::addCachedResidual(NumericVector<Number> & residual, Moose::KernelType type)
{
std::vector<Real> & cached_residual_values = _cached_residual_values[type];
std::vector<unsigned int> & cached_residual_rows = _cached_residual_rows[type];
mooseAssert(cached_residual_values.size() == cached_residual_rows.size(), "Number of cached residuals and number of rows must match!");
residual.add_vector(cached_residual_values, cached_residual_rows);
if (_max_cached_residuals < cached_residual_values.size())
_max_cached_residuals = cached_residual_values.size();
// Try to be more efficient from now on
// The 2 is just a fudge factor to keep us from having to grow the vector during assembly
cached_residual_values.clear();
cached_residual_values.reserve(_max_cached_residuals*2);
cached_residual_rows.clear();
cached_residual_rows.reserve(_max_cached_residuals*2);
}
示例6: compute_residual
//.........这里部分代码省略.........
std::vector<unsigned int> dof_indices;
// Now we will loop over all the active elements in the mesh which
// are local to this processor.
// We will compute the element residual.
residual.zero();
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el; ++el)
{
// Store a pointer to the element we are currently
// working on. This allows for nicer syntax later.
const Elem* elem = *el;
// Get the degree of freedom indices for the
// current element. These define where in the global
// matrix and right-hand-side this element will
// contribute to.
dof_map.dof_indices (elem, dof_indices);
// Compute the element-specific data for the current
// element. This involves computing the location of the
// quadrature points (q_point) and the shape functions
// (phi, dphi) for the current element.
fe->reinit (elem);
// We use the resize member here because
// the number of degrees of freedom might have changed from
// the last element. Note that this will be the case if the
// element type is different (i.e. the last element was a
// triangle, now we are on a quadrilateral).
Re.resize (dof_indices.size());
// Now we will build the residual. This involves
// the construction of the matrix K and multiplication of it
// with the current solution x. We rearrange this into two loops:
// In the first, we calculate only the contribution of
// K_ij*x_j which is independent of the row i. In the second loops,
// we multiply with the row-dependent part and add it to the element
// residual.
for (unsigned int qp=0; qp<qrule.n_points(); qp++)
{
Number u = 0;
Gradient grad_u;
for (unsigned int j=0; j<phi.size(); j++)
{
u += phi[j][qp]*soln(dof_indices[j]);
grad_u += dphi[j][qp]*soln(dof_indices[j]);
}
const Number K = 1./std::sqrt(1. + grad_u*grad_u);
for (unsigned int i=0; i<phi.size(); i++)
Re(i) += JxW[qp]*(
K*(dphi[i][qp]*grad_u) +
kappa*phi[i][qp]*u
);
}
// At this point the interior element integration has
// been completed. However, we have not yet addressed
// boundary conditions.
// The following loops over the sides of the element.
// If the element has no neighbor on a side then that
// side MUST live on a boundary of the domain.
for (unsigned int side=0; side<elem->n_sides(); side++)
if (elem->neighbor(side) == NULL)
{
// The value of the shape functions at the quadrature
// points.
const std::vector<std::vector<Real> >& phi_face = fe_face->get_phi();
// The Jacobian * Quadrature Weight at the quadrature
// points on the face.
const std::vector<Real>& JxW_face = fe_face->get_JxW();
// Compute the shape function values on the element face.
fe_face->reinit(elem, side);
// Loop over the face quadrature points for integration.
for (unsigned int qp=0; qp<qface.n_points(); qp++)
{
// This is the right-hand-side contribution (f),
// which has to be subtracted from the current residual
for (unsigned int i=0; i<phi_face.size(); i++)
Re(i) -= JxW_face[qp]*sigma*phi_face[i][qp];
}
}
dof_map.constrain_element_vector (Re, dof_indices);
residual.add_vector (Re, dof_indices);
}
// That's it.
}
示例7: assemble_A_and_F
void AssembleOptimization::assemble_A_and_F()
{
A_matrix->zero();
F_vector->zero();
const MeshBase & mesh = _sys.get_mesh();
const unsigned int dim = mesh.mesh_dimension();
const unsigned int u_var = _sys.variable_number ("u");
const DofMap & dof_map = _sys.get_dof_map();
FEType fe_type = dof_map.variable_type(u_var);
UniquePtr<FEBase> fe (FEBase::build(dim, fe_type));
QGauss qrule (dim, fe_type.default_quadrature_order());
fe->attach_quadrature_rule (&qrule);
const std::vector<Real> & JxW = fe->get_JxW();
const std::vector<std::vector<Real> > & phi = fe->get_phi();
const std::vector<std::vector<RealGradient> > & dphi = fe->get_dphi();
std::vector<dof_id_type> dof_indices;
DenseMatrix<Number> Ke;
DenseVector<Number> Fe;
MeshBase::const_element_iterator el = mesh.active_local_elements_begin();
const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();
for ( ; el != end_el; ++el)
{
const Elem * elem = *el;
dof_map.dof_indices (elem, dof_indices);
const unsigned int n_dofs = dof_indices.size();
fe->reinit (elem);
Ke.resize (n_dofs, n_dofs);
Fe.resize (n_dofs);
for (unsigned int qp=0; qp<qrule.n_points(); qp++)
{
for (unsigned int dof_i=0; dof_i<n_dofs; dof_i++)
{
for (unsigned int dof_j=0; dof_j<n_dofs; dof_j++)
{
Ke(dof_i, dof_j) += JxW[qp] * (dphi[dof_j][qp]* dphi[dof_i][qp]);
}
Fe(dof_i) += JxW[qp] * phi[dof_i][qp];
}
}
// This will zero off-diagonal entries of Ke corresponding to
// Dirichlet dofs.
dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
// We want the diagonal of constrained dofs to be zero too
for (unsigned int local_dof_index=0; local_dof_index<n_dofs; local_dof_index++)
{
dof_id_type global_dof_index = dof_indices[local_dof_index];
if (dof_map.is_constrained_dof(global_dof_index))
{
Ke(local_dof_index, local_dof_index) = 0.;
}
}
A_matrix->add_matrix (Ke, dof_indices);
F_vector->add_vector (Fe, dof_indices);
}
A_matrix->close();
F_vector->close();
}
示例8: residual
//.........这里部分代码省略.........
std::unique_ptr<FEBase> fe_face (FEBase::build(dim, fe_type));
QGauss qface (dim-1, fe_type.default_quadrature_order());
fe_face->attach_quadrature_rule (&qface);
const std::vector<Real> & JxW = fe->get_JxW();
const std::vector<std::vector<Real>> & phi = fe->get_phi();
const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
DenseVector<Number> Re;
DenseSubVector<Number> Re_var[3] =
{DenseSubVector<Number>(Re),
DenseSubVector<Number>(Re),
DenseSubVector<Number>(Re)};
std::vector<dof_id_type> dof_indices;
std::vector<std::vector<dof_id_type>> dof_indices_var(3);
residual.zero();
for (const auto & elem : mesh.active_local_element_ptr_range())
{
dof_map.dof_indices (elem, dof_indices);
for (unsigned int var=0; var<3; var++)
dof_map.dof_indices (elem, dof_indices_var[var], var);
const unsigned int n_dofs = dof_indices.size();
const unsigned int n_var_dofs = dof_indices_var[0].size();
fe->reinit (elem);
Re.resize (n_dofs);
for (unsigned int var=0; var<3; var++)
Re_var[var].reposition (var*n_var_dofs, n_var_dofs);
for (unsigned int qp=0; qp<qrule.n_points(); qp++)
{
DenseVector<Number> u_vec(3);
DenseMatrix<Number> grad_u(3, 3);
for (unsigned int var_i=0; var_i<3; var_i++)
{
for (unsigned int j=0; j<n_var_dofs; j++)
u_vec(var_i) += phi[j][qp]*soln(dof_indices_var[var_i][j]);
// Row is variable u, v, or w column is x, y, or z
for (unsigned int var_j=0; var_j<3; var_j++)
for (unsigned int j=0; j<n_var_dofs; j++)
grad_u(var_i,var_j) += dphi[j][qp](var_j)*soln(dof_indices_var[var_i][j]);
}
DenseMatrix<Number> strain_tensor(3, 3);
for (unsigned int i=0; i<3; i++)
for (unsigned int j=0; j<3; j++)
{
strain_tensor(i,j) += 0.5 * (grad_u(i,j) + grad_u(j,i));
for (unsigned int k=0; k<3; k++)
strain_tensor(i,j) += 0.5 * grad_u(k,i)*grad_u(k,j);
}
// Define the deformation gradient
DenseMatrix<Number> F(3, 3);
F = grad_u;
for (unsigned int var=0; var<3; var++)
F(var, var) += 1.;
DenseMatrix<Number> stress_tensor(3, 3);
for (unsigned int i=0; i<3; i++)
for (unsigned int j=0; j<3; j++)
for (unsigned int k=0; k<3; k++)
for (unsigned int l=0; l<3; l++)
stress_tensor(i,j) +=
elasticity_tensor(young_modulus, poisson_ratio, i, j, k, l) * strain_tensor(k,l);
DenseVector<Number> f_vec(3);
f_vec(0) = 0.;
f_vec(1) = 0.;
f_vec(2) = -forcing_magnitude;
for (unsigned int dof_i=0; dof_i<n_var_dofs; dof_i++)
for (unsigned int i=0; i<3; i++)
{
for (unsigned int j=0; j<3; j++)
{
Number FxStress_ij = 0.;
for (unsigned int m=0; m<3; m++)
FxStress_ij += F(i,m) * stress_tensor(m,j);
Re_var[i](dof_i) += JxW[qp] * (-FxStress_ij * dphi[dof_i][qp](j));
}
Re_var[i](dof_i) += JxW[qp] * (f_vec(i) * phi[dof_i][qp]);
}
}
dof_map.constrain_element_vector (Re, dof_indices);
residual.add_vector (Re, dof_indices);
}
}