Revision 1210cb0004d57b33cdf76364b40f1ddc8d4b7e8b authored by Wenqing Wang on 29 September 2021, 14:25:47 UTC, committed by Wenqing Wang on 02 November 2021, 08:06:25 UTC
1 parent 7ea6c2a
VectorUtils.h
/**
* \copyright
* Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include <random>
#include "MathLib/LinAlg/MatrixVectorTraits.h"
#include "MathLib/LinAlg/UnifiedMatrixSetters.h"
template <typename Vector>
void fillVectorRandomly(Vector& x)
{
std::random_device rd;
std::mt19937 random_number_generator(rd());
std::uniform_real_distribution<double> rnd;
using Index = typename MathLib::MatrixVectorTraits<Vector>::Index;
Index const size = x.size();
for (Index i = 0; i < size; ++i) {
MathLib::setVector(x, i, rnd(random_number_generator));
}
#ifdef USE_PETSC
finalizeVectorAssembly(x);
#endif
}
inline void fillVectorRandomly(std::vector<double>& x)
{
std::random_device rd;
std::mt19937 random_number_generator(rd());
std::uniform_real_distribution<double> rnd;
for (auto& value : x)
{
value = rnd(random_number_generator);
}
}
Computing file changes ...