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 this->comm().min(first_different_i); if (first_different_i == std::numeric_limits<int>::max()) return -1; return first_different_i; }
int NumericVector<T>::local_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(); do { if ( std::abs( (*this)(i) - other_vector(i) ) > threshold * std::max(std::abs((*this)(i)), std::abs(other_vector(i)))) 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; }
int NumericVector<T>::compare (const NumericVector<T> &other_vector, const Real threshold) const { libmesh_assert (this->initialized()); libmesh_assert (other_vector.initialized()); libmesh_assert (this->first_local_index() == other_vector.first_local_index()); libmesh_assert (this->last_local_index() == other_vector.last_local_index()); int first_different_i = std::numeric_limits<int>::max(); unsigned int i = first_local_index(); do { if ( std::abs( (*this)(i) - other_vector(i) ) > 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 Parallel::min(first_different_i); if (first_different_i == std::numeric_limits<int>::max()) return -1; return first_different_i; }
NumericVector<T>& DistributedVector<T>::operator = (const std::vector<T>& v) { libmesh_assert (this->initialized()); libmesh_assert_equal_to (_values.size(), _local_size); libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size); if (v.size() == local_size()) _values = v; else if (v.size() == size()) for (std::size_t i=first_local_index(); i<last_local_index(); i++) _values[i-first_local_index()] = v[i]; else libmesh_error_msg("Incompatible sizes in DistributedVector::operator="); return *this; }
//-------------------------------------------------------------------------------------------- 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; }