https://gitlab.opengeosys.org/ogs/ogs.git
Revision 03d2c78f3cf834a6915d5fee28afe1199013cd11 authored by Lars Bilke on 29 April 2021, 10:25:51 UTC, committed by Dmitry Yu. Naumov on 01 May 2021, 11:47:52 UTC
1 parent 9ba5f04
Raw File
Tip revision: 03d2c78f3cf834a6915d5fee28afe1199013cd11 authored by Lars Bilke on 29 April 2021, 10:25:51 UTC
[T] Disable snakemake tests when tee tool is not available.
Tip revision: 03d2c78
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