本文整理汇总了C++中NumericVector::first_local_index方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericVector::first_local_index方法的具体用法?C++ NumericVector::first_local_index怎么用?C++ NumericVector::first_local_index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NumericVector
的用法示例。
在下文中一共展示了NumericVector::first_local_index方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
int NumericVector<T>::global_relative_compare (const NumericVector<T> &other_vector,
const Real threshold) const
{
libmesh_assert (this->initialized());
libmesh_assert (other_vector.initialized());
libmesh_assert_equal_to (this->first_local_index(), other_vector.first_local_index());
libmesh_assert_equal_to (this->last_local_index(), other_vector.last_local_index());
int first_different_i = std::numeric_limits<int>::max();
numeric_index_type i = first_local_index();
const Real my_norm = this->linfty_norm();
const Real other_norm = other_vector.linfty_norm();
const Real abs_threshold = std::max(my_norm, other_norm) * threshold;
do
{
if ( std::abs( (*this)(i) - other_vector(i) ) > abs_threshold )
first_different_i = i;
else
i++;
}
while (first_different_i==std::numeric_limits<int>::max()
&& i<last_local_index());
// Find the correct first differing index in parallel
CommWorld.min(first_different_i);
if (first_different_i == std::numeric_limits<int>::max())
return -1;
return first_different_i;
}
示例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: compare
//--------------------------------------------------------------------------------------------
int NumericVector::compare (const NumericVector &other_vector,
const double threshold) const {
assert (this->initialized());
assert (other_vector.initialized());
assert (this->first_local_index() == other_vector.first_local_index());
assert (this->last_local_index() == other_vector.last_local_index());
int rvalue = -1;
int i = first_local_index();
do {
if ( std::abs( (*this)(i) - other_vector(i) ) > threshold )
rvalue = i;
else
i++;
} while (rvalue==-1 && i<last_local_index());
return rvalue;
}
示例4: 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]);
}