/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
Description
Various tools for test applications.
\*---------------------------------------------------------------------------*/
#include "scalar.H"
#include "complex.H"
#include "Matrix.H"
#include "Random.H"
#include
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Total number of unit tests
unsigned nTest_ = 0;
// Total number of failed unit tests
unsigned nFail_ = 0;
// Return the absolute tolerance value for bitwise comparisons of floatScalars
floatScalar getTol(floatScalar)
{
return 1e-2;
}
// Return the absolute tolerance value for bitwise comparisons of doubleScalars
doubleScalar getTol(doubleScalar)
{
return 1e-10;
}
// Return the absolute tolerance value for bitwise comparisons of doubleScalars
doubleScalar getTol(complex)
{
return 1e-10;
}
// Create a non-complex random Matrix.
template
typename std::enable_if
<
!std::is_same:: value,
MatrixType
>::type makeRandomMatrix
(
const labelPair& dims,
Random& rndGen
)
{
MatrixType mat(dims);
std::generate
(
mat.begin(),
mat.end(),
[&]{return rndGen.GaussNormal();}
);
return mat;
}
// Create a complex random Matrix.
template
typename std::enable_if
<
std::is_same:: value,
MatrixType
>::type makeRandomMatrix
(
const labelPair& dims,
Random& rndGen
)
{
MatrixType mat(dims);
for (auto& x : mat)
{
x = complex(rndGen.GaussNormal(), rndGen.GaussNormal());
}
return mat;
}
// Copy an initializer list into a DiagonalMatrix
template
void assignMatrix
(
UList& A,
std::initializer_list list
)
{
std::copy(list.begin(), list.end(), A.begin());
}
// Copy an initializer list into a SymmetricSquareMatrix.
template
void assignMatrix
(
Matrix