本文整理汇总了C++中NumericVector::localize方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericVector::localize方法的具体用法?C++ NumericVector::localize怎么用?C++ NumericVector::localize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumericVector
的用法示例。
在下文中一共展示了NumericVector::localize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inequality_constraints_jacobian
void AssembleOptimization::inequality_constraints_jacobian (const NumericVector<Number> & X,
SparseMatrix<Number> & C_ineq_jac,
OptimizationSystem & sys)
{
C_ineq_jac.zero();
std::unique_ptr<NumericVector<Number>> X_localized =
NumericVector<Number>::build(X.comm());
X_localized->init(X.size(), false, SERIAL);
X.localize(*X_localized);
std::vector<std::vector<Number>> constraint_jac_values(1);
std::vector<std::vector<dof_id_type>> constraint_jac_indices(1);
constraint_jac_values[0].resize(2);
constraint_jac_indices[0].resize(2);
constraint_jac_values[0][0] = 2.* (*X_localized)(200);
constraint_jac_values[0][1] = 1.;
constraint_jac_indices[0][0] = 200;
constraint_jac_indices[0][1] = 201;
for (std::size_t i=0; i<constraint_jac_values.size(); i++)
for (std::size_t j=0; j<constraint_jac_values[i].size(); j++)
if ((sys.C_ineq->first_local_index() <= i) &&
(i < sys.C_ineq->last_local_index()))
{
dof_id_type col_index = constraint_jac_indices[i][j];
Number value = constraint_jac_values[i][j];
C_ineq_jac.set(i, col_index, value);
}
}
示例2: inequality_constraints
void AssembleOptimization::inequality_constraints (const NumericVector<Number> & X,
NumericVector<Number> & C_ineq,
OptimizationSystem & /*sys*/)
{
C_ineq.zero();
std::unique_ptr<NumericVector<Number>> X_localized =
NumericVector<Number>::build(X.comm());
X_localized->init(X.size(), false, SERIAL);
X.localize(*X_localized);
std::vector<Number> constraint_values(1);
constraint_values[0] = (*X_localized)(200)*(*X_localized)(200) + (*X_localized)(201) - 5.;
for (std::size_t i=0; i<constraint_values.size(); i++)
if ((C_ineq.first_local_index() <= i) && (i < C_ineq.last_local_index()))
C_ineq.set(i, constraint_values[i]);
}
示例3: equality_constraints
void AssembleOptimization::equality_constraints (const NumericVector<Number> & X,
NumericVector<Number> & C_eq,
OptimizationSystem & /*sys*/)
{
C_eq.zero();
UniquePtr<NumericVector<Number> > X_localized =
NumericVector<Number>::build(X.comm());
X_localized->init(X.size(), false, SERIAL);
X.localize(*X_localized);
std::vector<Number> constraint_values(3);
constraint_values[0] = (*X_localized)(17);
constraint_values[1] = (*X_localized)(23);
constraint_values[2] = (*X_localized)(98) + (*X_localized)(185);
for (unsigned int i=0; i<constraint_values.size(); i++)
if ((C_eq.first_local_index() <= i) &&
(i < C_eq.last_local_index()))
C_eq.set(i, constraint_values[i]);
}
示例4: historyControl
void
AdamsPredictor::apply(NumericVector<Number> & sln)
{
// At the moment, I don't believe there is a function in Predictor
// that gets called on time step begin.
// That means that history control must go here.
historyControl();
// AB2 can only be applied if there are enough old solutions
// AB1 could potentially be used for the time step prior?
// It would be possible to do VSVO Adams, Kevin has the info
// Doing so requires a time stack of some sort....
if (_dt == 0 || _dt_old == 0 || _dt_older == 0 || _t_step < 2)
return;
// localize current solution to working vec
sln.localize(_solution_predictor);
// NumericVector<Number> & vector1 = _tmp_previous_solution;
NumericVector<Number> & vector2 = _tmp_residual_old;
NumericVector<Number> & vector3 = _tmp_third_vector;
Real commonpart = _dt / _dt_old;
Real firstpart = (1 + .5 * commonpart);
Real secondpart = .5 * _dt / _dt_older;
_older_solution.localize(vector2);
_oldest_solution.localize(vector3);
_solution_predictor *= 1 + commonpart * firstpart;
vector2 *= -1. * commonpart * (firstpart + secondpart);
vector3 *= commonpart * secondpart;
_solution_predictor += vector2;
_solution_predictor += vector3;
_solution_predictor.localize(sln);
}
示例5: move_mesh
void LinearElasticityWithContact::move_mesh (MeshBase & input_mesh,
const NumericVector<Number> & input_solution)
{
// Maintain a set of node ids that we've encountered.
LIBMESH_BEST_UNORDERED_SET<dof_id_type> encountered_node_ids;
// Localize input_solution so that we have the data to move all
// elements (not just elements local to this processor).
UniquePtr< NumericVector<Number> > localized_input_solution =
NumericVector<Number>::build(input_solution.comm());
localized_input_solution->init (input_solution.size(), false, SERIAL);
input_solution.localize(*localized_input_solution);
MeshBase::const_element_iterator el = input_mesh.active_elements_begin();
const MeshBase::const_element_iterator end_el = input_mesh.active_elements_end();
for ( ; el != end_el; ++el)
{
Elem * elem = *el;
Elem * orig_elem = _sys.get_mesh().elem_ptr(elem->id());
for (unsigned int node_id=0; node_id<elem->n_nodes(); node_id++)
{
Node & node = elem->node_ref(node_id);
if (encountered_node_ids.find(node.id()) != encountered_node_ids.end())
continue;
encountered_node_ids.insert(node.id());
std::vector<std::string> uvw_names(3);
uvw_names[0] = "u";
uvw_names[1] = "v";
uvw_names[2] = "w";
{
const Point master_point = elem->master_point(node_id);
Point uvw;
for (unsigned int index=0; index<uvw_names.size(); index++)
{
const unsigned int var = _sys.variable_number(uvw_names[index]);
const FEType & fe_type = _sys.get_dof_map().variable_type(var);
FEComputeData data (_sys.get_equation_systems(), master_point);
FEInterface::compute_data(elem->dim(),
fe_type,
elem,
data);
std::vector<dof_id_type> dof_indices_var;
_sys.get_dof_map().dof_indices (orig_elem, dof_indices_var, var);
for (unsigned int i=0; i<dof_indices_var.size(); i++)
{
Number value = (*localized_input_solution)(dof_indices_var[i]) * data.shape[i];
#ifdef LIBMESH_USE_COMPLEX_NUMBERS
// We explicitly store the real part in uvw
uvw(index) += value.real();
#else
uvw(index) += value;
#endif
}
}
// Update the node's location
node += uvw;
}
}
}
}