Commit 4ecc6ccf authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: declare generated methods for vector-space, primitives

- make read construct from Istream explicit

BUG: sph(const SymmTensor2D<Cmpt>&)

- had incorrect constant, but the 2D routines still need more attention
 (#1575)
parent 69537604
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -73,7 +74,7 @@ class pTraits<List<T>>
public:
typedef label cmptType;
pTraits(Istream& is)
explicit pTraits(Istream& is)
:
List<T>(is)
{}
......@@ -87,7 +88,7 @@ class pTraits<UList<T>>
public:
typedef label cmptType;
pTraits(Istream& is)
explicit pTraits(Istream& is)
:
UList<T>(is)
{}
......@@ -101,7 +102,7 @@ class pTraits<Field<T>>
public:
typedef label cmptType;
pTraits(Istream& is)
explicit pTraits(Istream& is)
:
Field<T>(is)
{}
......@@ -115,7 +116,7 @@ class pTraits<face>
public:
typedef label cmptType;
pTraits(Istream& is)
explicit pTraits(Istream& is)
:
face(is)
{}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -58,11 +58,13 @@ class Barycentric
{
public:
//- Equivalent type of labels used for valid component indexing
typedef Barycentric<label> labelType;
// Typedefs
//- Equivalent type of labels used for valid component indexing
typedef Barycentric<label> labelType;
// Member constants
// Member Constants
//- Rank of Barycentric is 1
static constexpr direction rank = 1;
......@@ -72,15 +74,18 @@ public:
enum components { A, B, C, D };
// Constructors
// Generated Methods
//- Default construct
Barycentric() = default;
//- Construct null
inline Barycentric();
// Constructors
//- Construct initialized to zero
inline Barycentric(const Foam::zero);
//- Construct given four components
//- Construct from components
inline Barycentric
(
const Cmpt& va,
......
......@@ -27,11 +27,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Cmpt>
inline Foam::Barycentric<Cmpt>::Barycentric()
{}
template<class Cmpt>
inline Foam::Barycentric<Cmpt>::Barycentric(const Foam::zero)
:
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -61,11 +61,13 @@ class BarycentricTensor
{
public:
//- Equivalent type of labels used for valid component indexing
typedef Tensor<label> labelType;
// Typedefs
//- Equivalent type of labels used for valid component indexing
typedef Tensor<label> labelType;
// Member constants
// Member Constants
//- Rank of BarycentricTensor is 2
static constexpr direction rank = 2;
......@@ -75,16 +77,19 @@ public:
enum components { XA, XB, XC, XD, YA, YB, YC, YD, ZA, ZB, ZC, ZD };
// Constructors
// Generated Methods
//- Default construct
BarycentricTensor() = default;
//- Construct null
BarycentricTensor();
// Constructors
//- Construct initialised to zero
BarycentricTensor(const Foam::zero);
inline BarycentricTensor(const Foam::zero);
//- Construct given three barycentric components (rows)
BarycentricTensor
inline BarycentricTensor
(
const Barycentric<Cmpt>& x,
const Barycentric<Cmpt>& y,
......@@ -92,7 +97,7 @@ public:
);
//- Construct given four vector components (columns)
BarycentricTensor
inline BarycentricTensor
(
const Vector<Cmpt>& a,
const Vector<Cmpt>& b,
......
......@@ -27,11 +27,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Cmpt>
inline Foam::BarycentricTensor<Cmpt>::BarycentricTensor()
{}
template<class Cmpt>
inline Foam::BarycentricTensor<Cmpt>::BarycentricTensor(const Foam::zero)
:
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,7 +31,7 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::barycentric barycentric01
static inline Foam::barycentric barycentric01Impl
(
Foam::scalar s,
Foam::scalar t,
......@@ -71,13 +72,11 @@ Foam::barycentric barycentric01
Foam::barycentric Foam::barycentric01(Random& rndGen)
{
return
::barycentric01
(
rndGen.sample01<scalar>(),
rndGen.sample01<scalar>(),
rndGen.sample01<scalar>()
);
const scalar s(rndGen.sample01<scalar>());
const scalar t(rndGen.sample01<scalar>());
const scalar u(rndGen.sample01<scalar>());
return barycentric01Impl(s, t, u);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -58,11 +58,13 @@ class Barycentric2D
{
public:
//- Equivalent type of labels used for valid component indexing
typedef Barycentric2D<label> labelType;
// Typedefs
//- Equivalent type of labels used for valid component indexing
typedef Barycentric2D<label> labelType;
// Member constants
// Member Constants
//- Rank of Barycentric2D is 1
static constexpr direction rank = 1;
......@@ -72,15 +74,18 @@ public:
enum components { A, B, C };
// Constructors
// Generated Methods: copy construct/assignment
//- Default construct
Barycentric2D() = default;
//- Construct null
inline Barycentric2D();
// Constructors
//- Construct initialized to zero
inline Barycentric2D(const Foam::zero);
//- Construct given four components
//- Construct from components
inline Barycentric2D
(
const Cmpt& va,
......@@ -109,7 +114,6 @@ public:
//- True if any coordinates are negative
inline bool outside() const;
};
......
......@@ -28,11 +28,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Cmpt>
inline Foam::Barycentric2D<Cmpt>::Barycentric2D()
{}
template<class Cmpt>
inline Foam::Barycentric2D<Cmpt>::Barycentric2D(const Foam::zero)
:
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,7 +31,7 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::barycentric2D barycentric2D01
static inline Foam::barycentric2D barycentric2D01Impl
(
Foam::scalar s,
Foam::scalar t
......@@ -53,12 +54,10 @@ Foam::barycentric2D barycentric2D01
Foam::barycentric2D Foam::barycentric2D01(Random& rndGen)
{
return
::barycentric2D01
(
rndGen.sample01<scalar>(),
rndGen.sample01<scalar>()
);
const scalar s(rndGen.sample01<scalar>());
const scalar t(rndGen.sample01<scalar>());
return barycentric2D01Impl(s, t);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -58,14 +58,15 @@ class DiagTensor
:
public VectorSpace<DiagTensor<Cmpt>, Cmpt, 3>
{
public:
//- Equivalent type of labels used for valid component indexing
typedef DiagTensor<label> labelType;
// Typedefs
//- Equivalent type of labels used for valid component indexing
typedef DiagTensor<label> labelType;
// Member constants
// Member Constants
//- Rank of DiagTensor is 2
static constexpr direction rank = 2;
......@@ -75,10 +76,19 @@ public:
enum components { XX, YY, ZZ };
// Constructors
// Generated Methods
//- Default construct
DiagTensor() = default;
//- Construct null
inline DiagTensor();
//- Copy construct
DiagTensor(const DiagTensor&) = default;
//- Copy assignment
DiagTensor& operator=(const DiagTensor&) = default;
// Constructors
//- Construct initialized to zero
inline DiagTensor(const Foam::zero);
......@@ -91,7 +101,7 @@ public:
inline DiagTensor(const Cmpt& txx, const Cmpt& tyy, const Cmpt& tzz);
//- Construct from Istream
inline DiagTensor(Istream&);
inline explicit DiagTensor(Istream& is);
// Member Functions
......
......@@ -30,11 +30,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Cmpt>
inline Foam::DiagTensor<Cmpt>::DiagTensor()
{}
template<class Cmpt>
inline Foam::DiagTensor<Cmpt>::DiagTensor(const Foam::zero)
:
......@@ -289,7 +284,10 @@ inline Cmpt tr(const DiagTensor<Cmpt>& dt)
template<class Cmpt>
inline SphericalTensor<Cmpt> sph(const DiagTensor<Cmpt>& dt)
{
return 0.5*tr(dt);
return SphericalTensor<Cmpt>
(
1.0/3.0*tr(dt)
);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -60,34 +60,35 @@ class MatrixSpace
:
public VectorSpace<Form, Cmpt, Mrows*Ncols>
{
public:
//- MatrixSpace type
typedef MatrixSpace<Form, Cmpt, Mrows, Ncols> msType;
// Typedefs
//- MatrixSpace type
typedef MatrixSpace<Form, Cmpt, Mrows, Ncols> msType;
// Member constants
// Member Constants
static constexpr direction mRows = Mrows;
static constexpr direction nCols = Ncols;
// Static member functions
// Static Member Functions
//- Return the number of rows
//- The number of rows
static direction m() noexcept
{
return Mrows;
}
//- Return the number of columns
//- The number of columns
static direction n() noexcept
{
return Ncols;
}
//- Return the identity matrix for square matrix spaces
//- An identity matrix for square matrix-spaces
inline static msType identity();
......@@ -149,13 +150,13 @@ public:
static const direction mRows = SubTensor::mRows;
static const direction nCols = SubTensor::nCols;
//- Return the number of rows in the block
//- The number of rows in the block
static direction m()
{
return mRows;
}
//- Return the number of columns in the block
//- The number of columns in the block
static direction n()
{
return nCols;
......@@ -199,10 +200,13 @@ public:
};
// Constructors
// Generated Methods
//- Default construct
MatrixSpace() = default;
//- Construct null
inline MatrixSpace();
// Constructors
//- Construct initialized to zero
inline MatrixSpace(const Foam::zero);
......@@ -227,7 +231,7 @@ public:
);
//- Construct from Istream
MatrixSpace(Istream&);
explicit MatrixSpace(Istream& is);
// Member Functions
......
......@@ -29,11 +29,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
inline Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::MatrixSpace()
{}
template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
inline Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::MatrixSpace
(
......
......@@ -70,18 +70,19 @@ class pTraits<Scalar>
public:
//- Component type
typedef Scalar cmptType;
// Typedefs
//- Magnitude type
typedef Scalar magType;
//- Component type
typedef Scalar cmptType;
//- Equivalent type of labels used for valid component indexing
typedef label labelType;
//- Magnitude type
typedef Scalar magType;
//- Equivalent type of labels used for valid component indexing
typedef label labelType;
// Member constants
// Member Constants
//- Dimensionality of space
static constexpr direction dim = 3;
......@@ -93,7 +94,7 @@ public:
static constexpr direction nComponents = 1;
// Static data members
// Static Data Members
static const char* const typeName;
static const char* const componentNames[];
......@@ -108,11 +109,11 @@ public:
// Constructors
//- Construct from primitive
//- Copy construct from primitive
explicit pTraits(const Scalar& val);
//- Construct from Istream
pTraits(Istream& is);
//- Read construct from Istream
explicit pTraits(Istream& is);
// Member Functions
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -57,20 +57,21 @@ class SphericalTensor
:
public VectorSpace<SphericalTensor<Cmpt>, Cmpt, 1>
{
public:
//- Equivalent type of labels used for valid component indexing
typedef SphericalTensor<label> labelType;
// Typedefs
//- Equivalent type of labels used for valid component indexing
typedef SphericalTensor<label> labelType;
// Member constants
// Member Constants
//- Rank of SphericalTensor is 2
static constexpr direction rank = 2;
// Static data members
// Static Data Members
static const SphericalTensor I;
static const SphericalTensor oneThirdI;
......@@ -81,10 +82,19 @@ public:
enum components { II };
// Constructors
// Generated Methods
//- Default construct
SphericalTensor() = default;
//- Construct null
inline SphericalTensor();
//- Copy construct
SphericalTensor(const SphericalTensor&) = default;
//- Copy assignment
SphericalTensor& operator=(const SphericalTensor&) = default;
// Constructors
//- Construct initialized to zero
inline SphericalTensor(const Foam::zero);
......@@ -97,10 +107,10 @@ public:
);
//- Construct given the component
inline SphericalTensor(const Cmpt& tii);
inline explicit SphericalTensor(const Cmpt& tii);
//- Construct from Istream
inline SphericalTensor(Istream&);
inline explicit SphericalTensor(Istream<