https://gitlab.opengeosys.org/ogs/ogs.git
Raw File
Tip revision: c418ff867cdf23d55150706457f82ce6e0b1f7a7 authored by KeitaYoshioka on 26 October 2021, 20:16:46 UTC
Merge branch 'PhaseField' into 'master'
Tip revision: c418ff8
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);
    }
}
back to top