From 3ba1d1766081a3302d64e55ad57d176c2021dacc Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sat, 12 Mar 2016 10:41:18 +0000 Subject: [PATCH] MatrixSpace: 2D (i-j) specialization of VectorSpace Provides '(i, j)' element access and general forms of inner and outer products, transpose etc. for square and rectangular VectorSpaces. VectorSpaces default to be column-vectors as before whereas row-vectors may be represented as 1xn MatrixSpaces. In the future it may be preferable to create a specializations of VectorSpace for column- and maybe row-vectors but it would add complexity to MatrixSpace to handle all the type combinations. Tensor is now a 3x3 specialization of MatrixSpace. Sub-block const and non-const access is provided via the '.block()' member functions. Consistent sub-block access is also provide for VectorSpace so that columns of MatrixSpaces may be accessed and substituted. These new classes will be used to create a more extensive set of primitive vector and tensor types over the next few weeks. Henry G. Weller CFD Direct --- .../primitives/MatrixSpace/MatrixSpace.H | 322 +++++++++ .../primitives/MatrixSpace/MatrixSpaceI.H | 609 ++++++++++++++++++ src/OpenFOAM/primitives/Tensor/Tensor.H | 47 +- src/OpenFOAM/primitives/Tensor/TensorI.H | 133 ++-- .../primitives/VectorSpace/VectorSpace.H | 48 +- .../primitives/VectorSpace/VectorSpaceI.H | 77 +++ .../primitives/VectorSpace/products.H | 18 + 7 files changed, 1202 insertions(+), 52 deletions(-) create mode 100644 src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H create mode 100644 src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H new file mode 100644 index 000000000..1d7bcec20 --- /dev/null +++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpace.H @@ -0,0 +1,322 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +Class + Foam::MatrixSpace + +Description + Templated matrix space. + + Template arguments are the Form the matrix space will be used to create, + the type of the elements and the number of rows and columns of the matrix. + +SourceFiles + MatrixSpaceI.H + +SeeAlso + Foam::VectorSpace + +\*---------------------------------------------------------------------------*/ + +#ifndef MatrixSpace_H +#define MatrixSpace_H + +#include "VectorSpace.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class MatrixSpace Declaration +\*---------------------------------------------------------------------------*/ + +template +class MatrixSpace +: + public VectorSpace +{ + +public: + + //- MatrixSpace type + typedef MatrixSpace msType; + + + // Member constants + + static const direction nRows = Nrows; + static const direction nCols = Ncols; + + + // Static member functions + + //- Return the number of rows + static direction m() + { + return Nrows; + } + + //- Return the number of columns + static direction n() + { + return Ncols; + } + + //- Return the identity matrix for square matrix spaces + inline static msType identity(); + + + // Sub-Block Classes + + //- Const sub-block type + template + class ConstBlock + { + //- Reference to parent matrix + const msType& matrix_; + + public: + + static const direction nRows = SubTensor::nRows; + static const direction nCols = SubTensor::nCols; + + //- Return the number of rows in the block + static direction m() + { + return nRows; + } + + //- Return the number of columns in the block + static direction n() + { + return nCols; + } + + //- Construct for the given matrix + inline ConstBlock(const msType& matrix); + + //- (i, j) const element access operator + inline const Cmpt& operator() + ( + const direction i, + const direction j + ) const; + }; + + + //- Sub-block type + template + < + class SubTensor, + direction BRowStart, + direction BColStart + > + class Block + { + //- Reference to parent matrix + msType& matrix_; + + public: + + static const direction nRows = SubTensor::nRows; + static const direction nCols = SubTensor::nCols; + + //- Return the number of rows in the block + static direction m() + { + return nRows; + } + + //- Return the number of columns in the block + static direction n() + { + return nCols; + } + + //- Construct for the given matrix + inline Block(msType& matrix); + + //- Assignment to a matrix + template + inline void operator= + ( + const MatrixSpace + < + Form2, + Cmpt, + SubTensor::nRows, + SubTensor::nCols + >& matrix + ); + + //- Assignment to a column vector + template + inline void operator= + ( + const VectorSpace& v + ); + + //- (i, j) const element access operator + inline const Cmpt& operator() + ( + const direction i, + const direction j + ) const; + + //- (i, j) element access operator + inline Cmpt& operator()(const direction i, const direction j); + }; + + + // Constructors + + //- Construct null + inline MatrixSpace(); + + //- Construct initialized to zero + inline explicit MatrixSpace(const Foam::zero); + + //- Construct as copy of a VectorSpace with the same size + template + inline explicit MatrixSpace + ( + const VectorSpace& + ); + + //- Construct from a block of another matrix space + template + < + template class Block2, + direction BRowStart, + direction BColStart + > + inline MatrixSpace + ( + const Block2& block + ); + + //- Construct from Istream + MatrixSpace(Istream&); + + + // Member Functions + + //- Fast const element access using compile-time addressing + template + inline const Cmpt& elmt() const; + + //- Fast element access using compile-time addressing + template + inline Cmpt& elmt(); + + // Const element access functions for a 3x3 + // Compile-time errors are generated for inappropriate use + + inline const Cmpt& xx() const; + inline const Cmpt& xy() const; + inline const Cmpt& xz() const; + inline const Cmpt& yx() const; + inline const Cmpt& yy() const; + inline const Cmpt& yz() const; + inline const Cmpt& zx() const; + inline const Cmpt& zy() const; + inline const Cmpt& zz() const; + + // Element access functions for a 3x3 + // Compile-time errors are generated for inappropriate use + + inline Cmpt& xx(); + inline Cmpt& xy(); + inline Cmpt& xz(); + inline Cmpt& yx(); + inline Cmpt& yy(); + inline Cmpt& yz(); + inline Cmpt& zx(); + inline Cmpt& zy(); + inline Cmpt& zz(); + + //- Return the transpose of the matrix + inline typename typeOfTranspose::type T() const; + + //- Return a const sub-block corresponding to the specified type + // starting at the specified row and column + template + inline ConstBlock block() const; + + //- Return a sub-block corresponding to the specified type + // starting at the specified row and column + template + inline Block block(); + + //- (i, j) const element access operator + inline const Cmpt& operator() + ( + const direction& row, + const direction& col + ) const; + + //- (i, j) element access operator + inline Cmpt& operator()(const direction& row, const direction& col); + + + // Member Operators + + //- Assignment to zero + inline void operator=(const Foam::zero); + + //- Assignment to a block of another matrix space + template + < + template class Block2, + direction BRowStart, + direction BColStart + > + inline void operator= + ( + const Block2& block + ); + + //- Inner product with a compatible square matrix + template + inline void operator&= + ( + const MatrixSpace& matrix + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "MatrixSpaceI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H new file mode 100644 index 000000000..e8df098a9 --- /dev/null +++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H @@ -0,0 +1,609 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +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 . + +\*---------------------------------------------------------------------------*/ + +#include "StaticAssert.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +inline Foam::MatrixSpace::MatrixSpace() +{} + + +template +inline Foam::MatrixSpace::MatrixSpace +( + const Foam::zero z +) +: + MatrixSpace::vsType(z) +{} + + +template +template +inline Foam::MatrixSpace::MatrixSpace +( + const VectorSpace& vs +) +: + MatrixSpace::vsType(vs) +{} + + +template +template +< + template class Block2, + Foam::direction BRowStart, + Foam::direction BColStart +> +inline Foam::MatrixSpace::MatrixSpace +( + const Block2& block +) +{ + for (direction i=0; i +inline Foam::MatrixSpace::MatrixSpace(Istream& is) +: + MatrixSpace::vsType(is) +{} + + +template +template +inline Foam::MatrixSpace:: +ConstBlock:: +ConstBlock(const msType& matrix) +: + matrix_(matrix) +{ + StaticAssert(msType::nRows >= BRowStart + nRows); + StaticAssert(msType::nCols >= BColStart + nCols); +} + + +template +template +inline Foam::MatrixSpace:: +Block:: +Block(msType& matrix) +: + matrix_(matrix) +{ + StaticAssert(msType::nRows >= BRowStart + nRows); + StaticAssert(msType::nCols >= BColStart + nCols); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +template +inline const Cmpt& Foam::MatrixSpace::elmt() const +{ + StaticAssert(Row < Nrows && Col < Ncols); + return this->v_[Row*Ncols + Col]; +} + + +template +template +inline Cmpt& Foam::MatrixSpace::elmt() +{ + StaticAssert(Row < Nrows && Col < Ncols); + return this->v_[Row*Ncols + Col]; +} + + +template +inline const Cmpt& Foam::MatrixSpace::xx() const +{ + return elmt<0, 0>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::xx() +{ + return elmt<0, 0>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::xy() const +{ + return elmt<0,1>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::xy() +{ + return elmt<0,1>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::xz() const +{ + return elmt<0,2>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::xz() +{ + return elmt<0,2>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::yx() const +{ + return elmt<1,0>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::yx() +{ + return elmt<1,0>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::yy() const +{ + return elmt<1,1>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::yy() +{ + return elmt<1,1>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::yz() const +{ + return elmt<1,2>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::yz() +{ + return elmt<1,2>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::zx() const +{ + return elmt<2,0>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::zx() +{ + return elmt<2,0>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::zy() const +{ + return elmt<2,1>(); +} + + +template +inline Cmpt& Foam::MatrixSpace::zy() +{ + return elmt<2,1>(); +} + + +template +inline const Cmpt& Foam::MatrixSpace::zz() const +{ + return elmt<2,2>(); +} + +template +inline Cmpt& Foam::MatrixSpace::zz() +{ + return elmt<2,2>(); +} + +template +inline Foam::MatrixSpace +Foam::MatrixSpace::identity() +{ + StaticAssert(Nrows == Ncols); + msType result((Foam::zero())); + + for (direction i=0; i +inline typename Foam::typeOfTranspose::type +Foam::MatrixSpace::T() const +{ + typename typeOfTranspose::type result; + + for (direction i=0; i +template +< + class SubTensor, + Foam::direction BRowStart, + Foam::direction BColStart +> +inline typename Foam::MatrixSpace::template + ConstBlock +Foam::MatrixSpace::block() const +{ + return *this; +} + + +template +template +< + class SubTensor, + Foam::direction BRowStart, + Foam::direction BColStart +> +inline +typename Foam::MatrixSpace::template + Block +Foam::MatrixSpace::block() +{ + return *this; +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template +inline const Cmpt& Foam::MatrixSpace::operator() +( + const direction& row, + const direction& col +) const +{ + #ifdef FULLDEBUG + if (row < 0 || row > Nrows-1 || col < 0 || col > Ncols-1) + { + FatalErrorInFunction + << "indices out of range" + << abort(FatalError); + } + #endif + + return this->v_[row*Ncols + col]; +} + + +template +inline Cmpt& Foam::MatrixSpace::operator() +( + const direction& row, + const direction& col +) +{ + #ifdef FULLDEBUG + if (row < 0 || row > Nrows-1 || col < 0 || col > Ncols-1) + { + FatalErrorInFunction + << "indices out of range" + << abort(FatalError); + } + #endif + + return this->v_[row*Ncols + col]; +} + + +template +template +inline const Cmpt& +Foam::MatrixSpace:: +ConstBlock:: +operator()(const direction i, const direction j) const +{ + return matrix_(BRowStart + i, BColStart + j); +} + + +template +template +inline const Cmpt& +Foam::MatrixSpace:: +Block:: +operator()(const direction i, const direction j) const +{ + return matrix_(BRowStart + i, BColStart + j); +} + + +template +template +inline Cmpt& +Foam::MatrixSpace:: +Block:: +operator()(const direction i, const direction j) +{ + return matrix_(BRowStart + i, BColStart + j); +} + + +template +inline void Foam::MatrixSpace::operator= +( + const Foam::zero z +) +{ + MatrixSpace::vsType::operator=(z); +} + + +template +template +inline void Foam::MatrixSpace::operator&= +( + const MatrixSpace& matrix +) +{ + *this = *this & matrix; +} + + +template +template +< + template class Block2, + Foam::direction BRowStart, + Foam::direction BColStart +> +inline void Foam::MatrixSpace::operator= +( + const Block2& block +) +{ + for (direction i = 0; i < Nrows; ++i) + { + for (direction j = 0; j < Ncols; ++j) + { + operator()(i, j) = block(i, j); + } + } +} + + +template +template +template +inline void +Foam::MatrixSpace:: +Block:: +operator= +( + const MatrixSpace& matrix +) +{ + for (direction i=0; i +template +template +inline void +Foam::MatrixSpace:: +Block:: +operator= +( + const VectorSpace& v +) +{ + StaticAssert(nCols == 1); + + for (direction i=0; i +inline typename typeOfTranspose::type T +( + const MatrixSpace& matrix +) +{ + return matrix.T(); +} + + +template +inline typename typeOfTranspose::type T +( + const VectorSpace& v +) +{ + typename typeOfTranspose::type result; + + for (direction i=0; i +inline typename typeOfInnerProduct::type operator& +( + const MatrixSpace& matrix1, + const MatrixSpace& matrix2 +) +{ + StaticAssert(Ncols1 == Nrows2); + + typename typeOfInnerProduct::type result + ( + (Foam::zero()) + ); + + for (direction i=0; i +inline typename typeOfInnerProduct::type operator& +( + const MatrixSpace& matrix, + const VectorSpace& v +) +{ + typename typeOfInnerProduct::type result + ( + (Foam::zero()) + ); + + for (direction i=0; i +inline typename typeOfOuterProduct::type operator* +( + const VectorSpace& v1, + const VectorSpace& v2 +) +{ + typename typeOfOuterProduct::type result; + + for (direction i=0; i class Tensor : - public VectorSpace, Cmpt, 9> + public MatrixSpace, Cmpt, 3, 3> { public: @@ -85,6 +90,13 @@ public: //- Construct null inline Tensor(); + //- Construct initialized to zero + inline explicit Tensor(const Foam::zero); + + //- Construct given MatrixSpace of the same rank + template + inline Tensor(const MatrixSpace, Cmpt2, 3, 3>&); + //- Construct given VectorSpace of the same rank template inline Tensor(const VectorSpace, Cmpt2, 9>&); @@ -114,13 +126,25 @@ public: const Cmpt tzx, const Cmpt tzy, const Cmpt tzz ); + //- Construct from a block of another matrix space + template + < + template class Block2, + direction BRowStart, + direction BColStart + > + Tensor + ( + const Block2, BRowStart, BColStart>& block + ); + //- Construct from Istream - Tensor(Istream&); + inline Tensor(Istream&); // Member Functions - // Access + // Component access inline const Cmpt& xx() const; inline const Cmpt& xy() const; @@ -142,7 +166,7 @@ public: inline Cmpt& zy(); inline Cmpt& zz(); - // Access vector components. + // Row-vector access. inline Vector x() const; inline Vector y() const; @@ -161,6 +185,10 @@ public: //- Inner-product with a Tensor inline void operator&=(const Tensor&); + //- Assign to an equivalent vector space + template + inline void operator=(const VectorSpace, Cmpt2, 9>&); + //- Assign to a SphericalTensor inline void operator=(const SphericalTensor&); @@ -181,6 +209,15 @@ public: }; +template +class typeOfTranspose> +{ +public: + + typedef Tensor type; +}; + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/Tensor/TensorI.H b/src/OpenFOAM/primitives/Tensor/TensorI.H index 35bfdef0c..567370328 100644 --- a/src/OpenFOAM/primitives/Tensor/TensorI.H +++ b/src/OpenFOAM/primitives/Tensor/TensorI.H @@ -32,6 +32,24 @@ inline Foam::Tensor::Tensor() {} +template +inline Foam::Tensor::Tensor(const Foam::zero z) +: + Tensor::msType(z) +{} + + +template +template +inline Foam::Tensor::Tensor +( + const MatrixSpace, Cmpt2, 3, 3>& vs +) +: + Tensor::msType(vs) +{} + + template template inline Foam::Tensor::Tensor @@ -39,7 +57,7 @@ inline Foam::Tensor::Tensor const VectorSpace, Cmpt2, 9>& vs ) : - VectorSpace, Cmpt, 9>(vs) + Tensor::msType(vs) {} @@ -106,57 +124,31 @@ inline Foam::Tensor::Tensor } +template +template +< + template class Block2, + Foam::direction BRowStart, + Foam::direction BColStart +> +inline Foam::Tensor::Tensor +( + const Block2, BRowStart, BColStart>& block +) +: + Tensor::msType(block) +{} + + template inline Foam::Tensor::Tensor(Istream& is) : - VectorSpace, Cmpt, 9>(is) + Tensor::msType(is) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -inline Foam::Vector Foam::Tensor::x() const -{ - return Vector(this->v_[XX], this->v_[XY], this->v_[XZ]); -} - - -template -inline Foam::Vector Foam::Tensor::y() const -{ - return Vector(this->v_[YX], this->v_[YY], this->v_[YZ]); -} - - -template -inline Foam::Vector Foam::Tensor::z() const -{ - return Vector(this->v_[ZX], this->v_[ZY], this->v_[ZZ]); -} - - -template -inline Foam::Vector Foam::Tensor::vectorComponent -( - const direction cmpt -) const -{ - switch (cmpt) - { - case 0: - return x(); - break; - case 1: - return y(); - break; - case 2: - return z(); - break; - } -} - - template inline const Cmpt& Foam::Tensor::xx() const { @@ -283,6 +275,48 @@ inline Cmpt& Foam::Tensor::zz() } +template +inline Foam::Vector Foam::Tensor::x() const +{ + return Vector(this->v_[XX], this->v_[XY], this->v_[XZ]); +} + + +template +inline Foam::Vector Foam::Tensor::y() const +{ + return Vector(this->v_[YX], this->v_[YY], this->v_[YZ]); +} + + +template +inline Foam::Vector Foam::Tensor::z() const +{ + return Vector(this->v_[ZX], this->v_[ZY], this->v_[ZZ]); +} + + +template +inline Foam::Vector Foam::Tensor::vectorComponent +( + const direction cmpt +) const +{ + switch (cmpt) + { + case 0: + return x(); + break; + case 1: + return y(); + break; + case 2: + return z(); + break; + } +} + + template inline Foam::Tensor Foam::Tensor::T() const { @@ -320,6 +354,17 @@ inline void Foam::Tensor::operator&=(const Tensor& t) } +template +template +inline void Foam::Tensor::operator= +( + const VectorSpace, Cmpt2, 9>& vs +) +{ + VectorSpace, Cmpt, 9>::operator=(vs); +} + + template inline void Foam::Tensor::operator=(const SphericalTensor& st) { diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H index 27c1bff3c..1d47ae3a0 100644 --- a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H +++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H @@ -88,7 +88,7 @@ public: typedef Cmpt cmptType; - // Member constants + // Static constants //- Dimensionality of space static const direction dim = 3; @@ -97,6 +97,13 @@ public: static const direction nComponents = Ncmpts; + // VectorSpace currently defaults to a column-vector + // This will be removed when column-vector is introduced + // as a specialization + static const direction nRows = Ncmpts; + static const direction nCols = 1; + + // Static data members static const char* const typeName; @@ -109,6 +116,38 @@ public: static const Form rootMin; + // Sub-Block Classes + + //- Const sub-block type + template + < + class SubVector, + direction BStart + > + class ConstBlock + { + const vsType& vs_; + + public: + + //- Number of components in this vector space + static const direction nComponents = SubVector::nComponents; + + //- Construct for a given vector + inline ConstBlock(const vsType& vs); + + //- [i] const element access operator + inline const Cmpt& operator[](const direction i) const; + + //- (i, 0) const element access operator + inline const Cmpt& operator() + ( + const direction i, + const direction + ) const; + }; + + // Constructors //- Construct null @@ -123,9 +162,9 @@ public: //- Construct as copy inline VectorSpace(const VectorSpace&); - //- Construct as copy of another VectorSpace type of the same rank + //- Construct as copy of a VectorSpace with the same size template - inline VectorSpace(const VectorSpace&); + inline explicit VectorSpace(const VectorSpace&); // Member Functions @@ -142,6 +181,9 @@ public: //- Return a VectorSpace with all elements = s inline static Form uniform(const Cmpt& s); + template + inline const ConstBlock block() const; + // Member Operators diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H index fe4a47be4..10f6964e7 100644 --- a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H +++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H @@ -27,6 +27,7 @@ License #include "products.H" #include "VectorSpaceOps.H" #include "ops.H" +#include "StaticAssert.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -68,6 +69,20 @@ inline VectorSpace::VectorSpace } +template +template +inline +VectorSpace::ConstBlock::ConstBlock +( + const vsType& vs +) +: + vs_(vs) +{ + StaticAssert(vsType::nComponents >= BStart + nComponents); +} + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template @@ -164,6 +179,16 @@ inline Form VectorSpace::uniform(const Cmpt& s) } +template +template +inline const typename VectorSpace::template + ConstBlock +VectorSpace::block() const +{ + return *this; +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template @@ -204,6 +229,58 @@ inline Cmpt& VectorSpace::operator[] } +template +template +inline const Cmpt& +VectorSpace:: +ConstBlock::operator[] +( + const direction i +) const +{ + #ifdef FULLDEBUG + if (i >= Ncmpts) + { + FatalErrorInFunction + << "index out of range" + << abort(FatalError); + } + #endif + + return vs_[BStart + i]; +} + + +template +template +inline const Cmpt& +VectorSpace:: +ConstBlock::operator() +( + const direction i, + const direction j +) const +{ + #ifdef FULLDEBUG + if (i >= Ncmpts) + { + FatalErrorInFunction + << "index out of range" + << abort(FatalError); + } + + if (j != 0) + { + FatalErrorInFunction + << "j != 0" + << abort(FatalError); + } + #endif + + return vs_[BStart + i]; +} + + template inline void VectorSpace::operator= ( diff --git a/src/OpenFOAM/primitives/VectorSpace/products.H b/src/OpenFOAM/primitives/VectorSpace/products.H index 4214f32f0..5992444b8 100644 --- a/src/OpenFOAM/primitives/VectorSpace/products.H +++ b/src/OpenFOAM/primitives/VectorSpace/products.H @@ -41,6 +41,24 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +//- Abstract template class to provide the form resulting from +// the inner-product of two forms +template +class typeOfInnerProduct +{}; + +//- Abstract template class to provide the form resulting from +// the outer-product of two forms +template +class typeOfOuterProduct +{}; + +//- Abstract template class to provide the transpose form of a form +template +class typeOfTranspose +{}; + + template class typeOfRank {};