diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index b67459678..9c2ce22ba 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -414,6 +414,7 @@ $(primitiveMesh)/primitiveMeshFaceCentresAndAreas.C $(primitiveMesh)/primitiveMeshFindCell.C $(primitiveMesh)/primitiveMeshPointCells.C $(primitiveMesh)/primitiveMeshPointFaces.C +$(primitiveMesh)/primitiveMeshPointEdges.C $(primitiveMesh)/primitiveMeshPointPoints.C $(primitiveMesh)/primitiveMeshCellPoints.C $(primitiveMesh)/primitiveMeshCalcCellShapes.C diff --git a/src/OpenFOAM/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C b/src/OpenFOAM/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C index 76ca321ae..99037d65b 100644 --- a/src/OpenFOAM/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C +++ b/src/OpenFOAM/coordinateSystems/coordinateRotation/EulerCoordinateRotation.C @@ -28,6 +28,7 @@ License #include "Switch.H" #include "mathematicalConstants.H" +#include "dictionary.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C b/src/OpenFOAM/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C index 8a6d42914..524eb18c5 100644 --- a/src/OpenFOAM/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C +++ b/src/OpenFOAM/coordinateSystems/coordinateRotation/STARCDCoordinateRotation.C @@ -28,6 +28,7 @@ License #include "Switch.H" #include "mathematicalConstants.H" +#include "dictionary.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/coordinateSystems/coordinateRotation/axisCoordinateRotation.C b/src/OpenFOAM/coordinateSystems/coordinateRotation/axisCoordinateRotation.C index 9932acaa6..01ed4bdcb 100644 --- a/src/OpenFOAM/coordinateSystems/coordinateRotation/axisCoordinateRotation.C +++ b/src/OpenFOAM/coordinateSystems/coordinateRotation/axisCoordinateRotation.C @@ -28,6 +28,7 @@ License #include "Switch.H" #include "mathematicalConstants.H" +#include "dictionary.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/coordinateSystems/cylindricalCS.C b/src/OpenFOAM/coordinateSystems/cylindricalCS.C index 82c4989ff..468bca0a9 100644 --- a/src/OpenFOAM/coordinateSystems/cylindricalCS.C +++ b/src/OpenFOAM/coordinateSystems/cylindricalCS.C @@ -26,7 +26,6 @@ License #include "cylindricalCS.H" -#include "one.H" #include "Switch.H" #include "mathematicalConstants.H" #include "addToRunTimeSelectionTable.H" @@ -133,7 +132,7 @@ Foam::vector Foam::cylindricalCS::localToGlobal { scalar theta ( - local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 ) + local.y() * ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 ) ); return coordinateSystem::localToGlobal diff --git a/src/OpenFOAM/coordinateSystems/cylindricalCS.H b/src/OpenFOAM/coordinateSystems/cylindricalCS.H index b84acd093..d8e2eda9f 100644 --- a/src/OpenFOAM/coordinateSystems/cylindricalCS.H +++ b/src/OpenFOAM/coordinateSystems/cylindricalCS.H @@ -95,13 +95,13 @@ public: // Constructors //- Construct null - cylindricalCS(const bool inDegrees=true); + cylindricalCS(const bool inDegrees = true); //- Construct copy cylindricalCS ( const coordinateSystem&, - const bool inDegrees=true + const bool inDegrees = true ); //- Construct copy with a different name @@ -109,7 +109,7 @@ public: ( const word& name, const coordinateSystem&, - const bool inDegrees=true + const bool inDegrees = true ); //- Construct from origin and rotation @@ -118,7 +118,7 @@ public: const word& name, const point& origin, const coordinateRotation&, - const bool inDegrees=true + const bool inDegrees = true ); //- Construct from origin and 2 axes @@ -128,7 +128,7 @@ public: const point& origin, const vector& axis, const vector& dirn, - const bool inDegrees=true + const bool inDegrees = true ); //- Construct from dictionary diff --git a/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.C b/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.C index 16d531c8c..d5a668184 100644 --- a/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.C +++ b/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.C @@ -25,8 +25,10 @@ License \*---------------------------------------------------------------------------*/ #include "ellipticCylindricalCS.H" -#include "addToRunTimeSelectionTable.H" + +#include "Switch.H" #include "mathematicalConstants.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -59,6 +61,7 @@ Foam::ellipticCylindricalCS::ellipticCylindricalCS ) : coordinateSystem(cs), + a_(0), inDegrees_(inDegrees) {} @@ -71,6 +74,22 @@ Foam::ellipticCylindricalCS::ellipticCylindricalCS ) : coordinateSystem(name, cs), + a_(0), + inDegrees_(inDegrees) +{} + + +Foam::ellipticCylindricalCS::ellipticCylindricalCS +( + const word& name, + const point& origin, + const coordinateRotation& cr, + const scalar a, + const bool inDegrees +) +: + coordinateSystem(name, origin, cr), + a_(a), inDegrees_(inDegrees) {} @@ -91,21 +110,6 @@ Foam::ellipticCylindricalCS::ellipticCylindricalCS {} -Foam::ellipticCylindricalCS::ellipticCylindricalCS -( - const word& name, - const point& origin, - const coordinateRotation& cr, - const scalar a, - const bool inDegrees -) -: - coordinateSystem(name, origin, cr), - a_(a), - inDegrees_(inDegrees) -{} - - Foam::ellipticCylindricalCS::ellipticCylindricalCS ( const word& name, @@ -128,8 +132,7 @@ Foam::vector Foam::ellipticCylindricalCS::localToGlobal { // Notation: u = local.x() v = local.y() z = local.z(); scalar theta = - local.y() - *( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 ) + local.y()*( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 ); return coordinateSystem::localToGlobal ( @@ -150,8 +153,8 @@ Foam::tmp Foam::ellipticCylindricalCS::localToGlobal ) const { scalarField theta = - local.component(vector::Y) - *( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 ) + local.component(vector::Y)* + ( inDegrees_ ? mathematicalConstant::pi/180.0 : 1.0 ); vectorField lc(local.size()); lc.replace diff --git a/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.H b/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.H index 8b4c673fa..4fc4fea2d 100644 --- a/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.H +++ b/src/OpenFOAM/coordinateSystems/ellipticCylindricalCS.H @@ -108,14 +108,14 @@ public: ellipticCylindricalCS(const bool inDegrees = true); //- Construct copy - sphericalCS + ellipticCylindricalCS ( const coordinateSystem&, const bool inDegrees = true ); //- Construct copy with a different name - sphericalCS + ellipticCylindricalCS ( const word& name, const coordinateSystem&, @@ -132,6 +132,17 @@ public: const bool inDegrees = true ); + //- Construct from origin and 2 axes + ellipticCylindricalCS + ( + const word& name, + const point& origin, + const vector& axis, + const vector& dirn, + const scalar a, + const bool inDegrees = true + ); + //- Construct from dictionary ellipticCylindricalCS ( diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H index f1de065c7..a8e3cb822 100644 --- a/src/OpenFOAM/db/IOobject/IOobjectI.H +++ b/src/OpenFOAM/db/IOobject/IOobjectI.H @@ -33,16 +33,20 @@ inline Stream& Foam::IOobject::writeBanner(Stream& os, bool noHint) { static bool spacesSet = false; static char spaces[40]; - static char spacesRev[40]; if (!spacesSet) { memset(spaces, ' ', 40); - spaces[38 - strlen(Foam::FOAMversion)] = '\0'; - - memset(spacesRev, ' ', 40); - spacesRev[38 - strlen(Foam::FOAMDevRevisionNumber)] = '\0'; + size_t len = strlen(Foam::FOAMversion); + if (len < 38) + { + spaces[38 - len] = '\0'; + } + else + { + spaces[0] = '\0'; + } spacesSet = true; } @@ -59,10 +63,10 @@ inline Stream& Foam::IOobject::writeBanner(Stream& os, bool noHint) os << "| ========= | |\n" - "| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |\n" - "| \\\\ / O peration | Version: " << FOAMversion << spaces << "|\n" - "| \\\\ / A nd | Revision: " << FOAMDevRevisionNumber << spacesRev << "|\n" - "| \\\\/ M anipulation | Web: www.OpenFOAM.org |\n" + "| \\\\ / F ield | OpenFOAM Extend Project: Open source CFD |\n" + "| \\\\ / O peration | Version: " << FOAMversion << spaces << "|\n" + "| \\\\ / A nd | Web: www.extend-project.de |\n" + "| \\\\/ M anipulation | |\n" "\\*---------------------------------------------------------------------------*/\n"; return os; diff --git a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H index 4ddc223af..47f33c866 100644 --- a/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H +++ b/src/OpenFOAM/db/dlLibraryTable/dlLibraryTable.H @@ -49,28 +49,6 @@ namespace Foam Class dlLibraryTable Declaration \*---------------------------------------------------------------------------*/ -//- A means of hashing pointer addresses -template<> -class Hash -{ - -public: - - Hash() - {} - - long operator()(const void* const& p) const - { - return long(p); - } - - label operator()(const void* const& p, const label tableSize) const - { - return abs(operator()(p)) % tableSize; - } -}; - - class dlLibraryTable : public HashTable > diff --git a/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C b/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C index 5c6f1e16d..e803481f4 100644 --- a/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C +++ b/src/OpenFOAM/db/regIOobject/regIOobjectWrite.C @@ -84,7 +84,15 @@ bool Foam::regIOobject::writeObject { // Try opening an OFstream for object - OFstream os(objectPath(), fmt, ver, cmp); + // Stream open for over-write. HJ, 17/Aug/2010 + OFstream os + ( + objectPath(), + ios_base::out|ios_base::trunc, + fmt, + ver, + cmp + ); // If any of these fail, return (leave error handling to Ostream class) if (!os.good()) diff --git a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H index 9992ded59..07d57a15b 100644 --- a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H +++ b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H @@ -42,7 +42,7 @@ inline Foam::SubField::SubField const UList& list ) : -q SubList(list, list.size()) + SubList(list, list.size()) {} diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.C b/src/OpenFOAM/matrices/Matrix/Matrix.C index 231862557..c45dd2cbb 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.C +++ b/src/OpenFOAM/matrices/Matrix/Matrix.C @@ -28,13 +28,13 @@ License // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // -template -void Foam::Matrix::allocate() +template +void Foam::Matrix::allocate() { if (n_ && m_) { - v_ = new T*[n_]; - v_[0] = new T[n_*m_]; + v_ = new Type*[n_]; + v_[0] = new Type[n_*m_]; for (register label i=1; i::allocate() // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * // -template -Foam::Matrix::~Matrix() +template +Foam::Matrix::~Matrix() { if (v_) { @@ -59,34 +59,8 @@ Foam::Matrix::~Matrix() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -const Foam::Matrix& Foam::Matrix::null() -{ - Matrix* nullPtr = reinterpret_cast*>(NULL); - return *nullPtr; -} - - -template -Foam::Matrix::Matrix(const label n, const label m) -: - v_(NULL), - n_(n), - m_(m) -{ - if (n_ < 0 || m_ < 0) - { - FatalErrorIn("Matrix::Matrix(const label n, const label m)") - << "bad n, m " << n_ << ", " << m_ - << abort(FatalError); - } - - allocate(); -} - - -template -Foam::Matrix::Matrix(const label n, const label m, const T& a) +template +Foam::Matrix::Matrix(const label n, const label m) : v_(NULL), n_(n), @@ -96,7 +70,28 @@ Foam::Matrix::Matrix(const label n, const label m, const T& a) { FatalErrorIn ( - "Matrix::Matrix(const label n, const label m, const T&)" + "Matrix::Matrix(const label n, const label m)" + ) << "bad n, m " << n_ << ", " << m_ + << abort(FatalError); + } + + allocate(); +} + + +template +Foam::Matrix::Matrix(const label n, const label m, const Type& a) +: + v_(NULL), + n_(n), + m_(m) +{ + if (n_ < 0 || m_ < 0) + { + FatalErrorIn + ( + "Matrix::Matrix" + "(const label n, const label m, const T&)" ) << "bad n, m " << n_ << ", " << m_ << abort(FatalError); } @@ -105,7 +100,7 @@ Foam::Matrix::Matrix(const label n, const label m, const T& a) if (v_) { - T* v = v_[0]; + Type* v = v_[0]; label nm = n_*m_; @@ -117,8 +112,8 @@ Foam::Matrix::Matrix(const label n, const label m, const T& a) } -template -Foam::Matrix::Matrix(const Matrix& a) +template +Foam::Matrix::Matrix(const Matrix& a) : v_(NULL), n_(a.n_), @@ -127,8 +122,8 @@ Foam::Matrix::Matrix(const Matrix& a) if (a.v_) { allocate(); - T* v = v_[0]; - const T* av = a.v_[0]; + Type* v = v_[0]; + const Type* av = a.v_[0]; label nm = n_*m_; for (register label i=0; i::Matrix(const Matrix& a) } } - -template -void Foam::Matrix::clear() + +template +void Foam::Matrix::clear() { if (v_) { @@ -153,8 +148,8 @@ void Foam::Matrix::clear() } -template -void Foam::Matrix::transfer(Matrix& a) +template +void Foam::Matrix::transfer(Matrix& a) { clear(); @@ -169,14 +164,32 @@ void Foam::Matrix::transfer(Matrix& a) } +template +Form Foam::Matrix::T() const +{ + const Matrix& A = *this; + Form At(m(), n()); + + for (register label i=0; i -void Foam::Matrix::operator=(const T& t) +template +void Foam::Matrix::operator=(const Type& t) { if (v_) { - T* v = v_[0]; + Type* v = v_[0]; label nm = n_*m_; for (register label i=0; i::operator=(const T& t) // Assignment operator. Takes linear time. -template -void Foam::Matrix::operator=(const Matrix& a) +template +void Foam::Matrix::operator=(const Matrix& a) { if (this == &a) { - FatalErrorIn("Matrix::operator=(const Matrix&)") + FatalErrorIn("Matrix::operator=(const Matrix&)") << "attempted assignment to self" << abort(FatalError); } @@ -204,12 +217,12 @@ void Foam::Matrix::operator=(const Matrix& a) n_ = a.n_; m_ = a.m_; allocate(); - } + } if (v_) { - T* v = v_[0]; - const T* av = a.v_[0]; + Type* v = v_[0]; + const Type* av = a.v_[0]; label nm = n_*m_; for (register label i=0; i::operator=(const Matrix& a) // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // -template -const T& Foam::max(const Matrix& a) +template +const Type& Foam::max(const Matrix& a) { - label nm = a.n_*a.m_; + label nm = a.n()*a.m(); if (nm) { label curMaxI = 0; - const T* v = a.v_[0]; + const Type* v = a[0]; for (register label i=1; i& a) } else { - FatalErrorIn("max(const Matrix&)") + FatalErrorIn("max(const Matrix&)") << "matrix is empty" << abort(FatalError); @@ -254,15 +267,15 @@ const T& Foam::max(const Matrix& a) } -template -const T& Foam::min(const Matrix& a) +template +const Type& Foam::min(const Matrix& a) { - label nm = a.n_*a.m_; + label nm = a.n()*a.m(); if (nm) { label curMinI = 0; - const T* v = a.v_[0]; + const Type* v = a[0]; for (register label i=1; i& a) } else { - FatalErrorIn("min(const Matrix&)") + FatalErrorIn("min(const Matrix&)") << "matrix is empty" << abort(FatalError); @@ -288,17 +301,17 @@ const T& Foam::min(const Matrix& a) // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // -template -Foam::Matrix Foam::operator-(const Matrix& a) +template +Form Foam::operator-(const Matrix& a) { - Matrix na(a.n_, a.m_); + Form na(a.n(), a.m()); - if (a.n_ && a.m_) + if (a.n() && a.m()) { - T* nav = na.v_[0]; - const T* av = a.v_[0]; + Type* nav = na[0]; + const Type* av = a[0]; - label nm = a.n_*a.m_; + label nm = a.n()*a.m(); for (register label i=0; i Foam::operator-(const Matrix& a) } -template -Foam::Matrix Foam::operator+(const Matrix& a, const Matrix& b) +template +Form Foam::operator+(const Matrix& a, const Matrix& b) { - if (a.n_ != b.n_) + if (a.n() != b.n()) { - FatalErrorIn("Matrix::operator+(const Matrix&, const Matrix&)") - << "attempted add matrices with different number of rows: " - << a.n_ << ", " << b.n_ + FatalErrorIn + ( + "Matrix::operator+(const Matrix&, const Matrix&)" + ) << "attempted add matrices with different number of rows: " + << a.n() << ", " << b.n() << abort(FatalError); } - if (a.m_ != b.m_) + if (a.m() != b.m()) { - FatalErrorIn("Matrix::operator+(const Matrix&, const Matrix&)") - << "attempted add matrices with different number of columns: " - << a.m_ << ", " << b.m_ + FatalErrorIn + ( + "Matrix::operator+(const Matrix&, const Matrix&)" + ) << "attempted add matrices with different number of columns: " + << a.m() << ", " << b.m() << abort(FatalError); } - Matrix ab(a.n_, a.m_); + Form ab(a.n(), a.m()); - T* abv = ab.v_[0]; - const T* av = a.v_[0]; - const T* bv = b.v_[0]; + Type* abv = ab[0]; + const Type* av = a[0]; + const Type* bv = b[0]; - label nm = a.n_*a.m_;; + label nm = a.n()*a.m(); for (register label i=0; i Foam::operator+(const Matrix& a, const Matrix& b) } -template -Foam::Matrix Foam::operator-(const Matrix& a, const Matrix& b) +template +Form Foam::operator-(const Matrix& a, const Matrix& b) { - if (a.n_ != b.n_) + if (a.n() != b.n()) { - FatalErrorIn("Matrix::operator-(const Matrix&, const Matrix&)") - << "attempted add matrices with different number of rows: " - << a.n_ << ", " << b.n_ + FatalErrorIn + ( + "Matrix::operator-(const Matrix&, const Matrix&)" + ) << "attempted add matrices with different number of rows: " + << a.n() << ", " << b.n() << abort(FatalError); } - if (a.m_ != b.m_) + if (a.m() != b.m()) { - FatalErrorIn("Matrix::operator-(const Matrix&, const Matrix&)") - << "attempted add matrices with different number of columns: " - << a.m_ << ", " << b.m_ + FatalErrorIn + ( + "Matrix::operator-(const Matrix&, const Matrix&)" + ) << "attempted add matrices with different number of columns: " + << a.m() << ", " << b.m() << abort(FatalError); } - Matrix ab(a.n_, a.m_); + Form ab(a.n(), a.m()); - T* abv = ab.v_[0]; - const T* av = a.v_[0]; - const T* bv = b.v_[0]; + Type* abv = ab[0]; + const Type* av = a[0]; + const Type* bv = b[0]; - label nm = a.n_*a.m_;; + label nm = a.n()*a.m(); for (register label i=0; i Foam::operator-(const Matrix& a, const Matrix& b) } -template -Foam::Matrix Foam::operator*(const scalar s, const Matrix& a) +template +Form Foam::operator*(const scalar s, const Matrix& a) { - Matrix sa(a.n_, a.m_); + Form sa(a.n(), a.m()); - if (a.n_ && a.m_) + if (a.n() && a.m()) { - T* sav = sa.v_[0]; - const T* av = a.v_[0]; + Type* sav = sa[0]; + const Type* av = a[0]; - label nm = a.n_*a.m_;; + label nm = a.n()*a.m(); for (register label i=0; i class Matrix; +template class Matrix; -template const T& max(const Matrix&); -template const T& min(const Matrix&); +template Istream& operator>> +( + Istream&, + Matrix& +); -template Matrix operator-(const Matrix&); -template Matrix operator+(const Matrix&, const Matrix&); -template Matrix operator-(const Matrix&, const Matrix&); -template Matrix operator*(const scalar, const Matrix&); - -template Istream& operator>>(Istream&, Matrix&); -template Ostream& operator<<(Ostream&, const Matrix&); +template Ostream& operator<< +( + Ostream&, + const Matrix& +); /*---------------------------------------------------------------------------*\ Class Matrix Declaration \*---------------------------------------------------------------------------*/ -template +template class Matrix { // Private data //- Row pointers - T** __restrict__ v_; + Type** __restrict__ v_; //- Number of rows and columns in Matrix. label n_, m_; @@ -87,6 +88,12 @@ class Matrix public: + // Static Member Functions + + //- Return a null Matrix + inline static const Matrix& null(); + + // Constructors //- Null constructor. @@ -97,16 +104,16 @@ public: //- Construct with given number of rows and columns // and value for all elements. - Matrix(const label n, const label m, const T&); + Matrix(const label n, const label m, const Type&); //- Copy constructor. - Matrix(const Matrix&); + Matrix(const Matrix&); //- Construct from Istream. Matrix(Istream&); //- Clone - inline autoPtr > clone() const; + inline autoPtr > clone() const; // Destructor @@ -116,10 +123,6 @@ public: // Member functions - //- Return a null Matrix - static const Matrix& null(); - - // Access //- Return the number of rows @@ -148,48 +151,72 @@ public: //- Transfer the contents of the argument Matrix into this Matrix // and annull the argument Matrix. - void transfer(Matrix&); + void transfer(Matrix&); + + + //- Return the transpose of the matrix + Form T() const; // Member operators //- Return subscript-checked element of Matrix. - inline T* operator[](const label); + inline Type* operator[](const label); //- Return subscript-checked element of constant Matrix. - inline const T* operator[](const label) const; + inline const Type* operator[](const label) const; //- Assignment operator. Takes linear time. - void operator=(const Matrix&); + void operator=(const Matrix&); //- Assignment of all entries to the given value - void operator=(const T&); - - - // Friend functions - - friend const T& max(const Matrix&); - friend const T& min(const Matrix&); - - - // Friend operators - - friend Matrix operator-(const Matrix&); - friend Matrix operator+(const Matrix&, const Matrix&); - friend Matrix operator-(const Matrix&, const Matrix&); - friend Matrix operator*(const scalar, const Matrix&); + void operator=(const Type&); // IOstream operators //- Read Matrix from Istream, discarding contents of existing Matrix. - friend Istream& operator>> (Istream&, Matrix&); + friend Istream& operator>> + ( + Istream&, + Matrix& + ); // Write Matrix to Ostream. - friend Ostream& operator<< (Ostream&, const Matrix&); + friend Ostream& operator<< + ( + Ostream&, + const Matrix& + ); }; +// Global functions and operators + +template const Type& max(const Matrix&); +template const Type& min(const Matrix&); + +template Form operator-(const Matrix&); + +template Form operator+ +( + const Matrix&, + const Matrix& +); + +template Form operator- +( + const Matrix&, + const Matrix& +); + +template Form operator* +( + const scalar, + const Matrix& +); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/matrices/Matrix/MatrixI.H b/src/OpenFOAM/matrices/Matrix/MatrixI.H index acb2d8928..4273a8d24 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixI.H +++ b/src/OpenFOAM/matrices/Matrix/MatrixI.H @@ -26,8 +26,8 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -template -inline Foam::Matrix::Matrix() +template +inline Foam::Matrix::Matrix() : v_(NULL), n_(0), @@ -35,71 +35,75 @@ inline Foam::Matrix::Matrix() {} -template -inline Foam::autoPtr > Foam::Matrix::clone() const +template +inline Foam::autoPtr > +Foam::Matrix::clone() const { - return autoPtr >(new Matrix(*this)); + return autoPtr >(new Matrix(*this)); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +template +inline const Foam::Matrix& Foam::Matrix::null() +{ + return *reinterpret_cast< Matrix* >(0); +} + + //- Return the number of rows -template -inline Foam::label Foam::Matrix::n() const +template +inline Foam::label Foam::Matrix::n() const { return n_; } -//- Return the number of columns -template -inline Foam::label Foam::Matrix::m() const +template +inline Foam::label Foam::Matrix::m() const { return m_; } -//- Return the number of columns -template -inline Foam::label Foam::Matrix::size() const +template +inline Foam::label Foam::Matrix::size() const { return n_*m_; } -// Check index i is within valid range (0 ... n-1). -template -inline void Foam::Matrix::checki(const label i) const +template +inline void Foam::Matrix::checki(const label i) const { if (!n_) { - FatalErrorIn("Matrix::checki(const label)") + FatalErrorIn("Matrix::checki(const label)") << "attempt to access element from zero sized row" << abort(FatalError); } else if (i<0 || i>=n_) { - FatalErrorIn("Matrix::checki(const label)") + FatalErrorIn("Matrix::checki(const label)") << "index " << i << " out of range 0 ... " << n_-1 << abort(FatalError); } } -// Check index j is within valid range (0 ... n-1). -template -inline void Foam::Matrix::checkj(const label j) const +template +inline void Foam::Matrix::checkj(const label j) const { if (!m_) { - FatalErrorIn("Matrix::checkj(const label)") + FatalErrorIn("Matrix::checkj(const label)") << "attempt to access element from zero sized column" << abort(FatalError); } else if (j<0 || j>=m_) { - FatalErrorIn("Matrix::checkj(const label)") + FatalErrorIn("Matrix::checkj(const label)") << "index " << j << " out of range 0 ... " << m_-1 << abort(FatalError); } @@ -108,9 +112,8 @@ inline void Foam::Matrix::checkj(const label j) const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -// Return subscript-checked element access -template -inline T* Foam::Matrix::operator[](const label i) +template +inline Type* Foam::Matrix::operator[](const label i) { # ifdef FULLDEBUG checki(i); @@ -119,9 +122,8 @@ inline T* Foam::Matrix::operator[](const label i) } -// Return subscript-checked const element access -template -inline const T* Foam::Matrix::operator[](const label i) const +template +inline const Type* Foam::Matrix::operator[](const label i) const { # ifdef FULLDEBUG checki(i); diff --git a/src/OpenFOAM/matrices/Matrix/MatrixIO.C b/src/OpenFOAM/matrices/Matrix/MatrixIO.C index 99a3df9da..d97ae8803 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixIO.C +++ b/src/OpenFOAM/matrices/Matrix/MatrixIO.C @@ -32,8 +32,8 @@ License // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // -template -Foam::Matrix::Matrix(Istream& is) +template +Foam::Matrix::Matrix(Istream& is) : v_(NULL), n_(0), @@ -43,17 +43,17 @@ Foam::Matrix::Matrix(Istream& is) } -template -Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) +template +Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) { // Anull matrix M.clear(); - is.fatalCheck("operator>>(Istream&, Matrix&)"); + is.fatalCheck("operator>>(Istream&, Matrix&)"); token firstToken(is); - is.fatalCheck("operator>>(Istream&, Matrix&) : reading first token"); + is.fatalCheck("operator>>(Istream&, Matrix&) : reading first token"); if (firstToken.isLabel()) { @@ -63,7 +63,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) label nm = M.n_*M.m_; // Read list contents depending on data format - if (is.format() == IOstream::ASCII || !contiguous()) + if (is.format() == IOstream::ASCII || !contiguous()) { // Read beginning of contents char listDelimiter = is.readBeginList("Matrix"); @@ -71,7 +71,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) if (nm) { M.allocate(); - T* v = M.v_[0]; + Type* v = M.v_[0]; if (listDelimiter == token::BEGIN_LIST) { @@ -88,7 +88,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) is.fatalCheck ( - "operator>>(Istream&, Matrix&) : " + "operator>>(Istream&, Matrix&) : " "reading entry" ); } @@ -98,12 +98,12 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) } else { - T element; + Type element; is >> element; is.fatalCheck ( - "operator>>(Istream&, Matrix&) : " + "operator>>(Istream&, Matrix&) : " "reading the single entry" ); @@ -122,13 +122,13 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) if (nm) { M.allocate(); - T* v = M.v_[0]; + Type* v = M.v_[0]; - is.read(reinterpret_cast(v), nm*sizeof(T)); + is.read(reinterpret_cast(v), nm*sizeof(Type)); is.fatalCheck ( - "operator>>(Istream&, Matrix&) : " + "operator>>(Istream&, Matrix&) : " "reading the binary block" ); } @@ -136,7 +136,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) } else { - FatalIOErrorIn("operator>>(Istream&, Matrix&)", is) + FatalIOErrorIn("operator>>(Istream&, Matrix&)", is) << "incorrect first token, expected , found " << firstToken.info() << exit(FatalIOError); @@ -146,23 +146,23 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix& M) } -template -Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) +template +Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) { label nm = M.n_*M.m_; os << M.n() << token::SPACE << M.m(); // Write list contents depending on data format - if (os.format() == IOstream::ASCII || !contiguous()) + if (os.format() == IOstream::ASCII || !contiguous()) { if (nm) { bool uniform = false; - const T* v = M.v_[0]; + const Type* v = M.v_[0]; - if (nm > 1 && contiguous()) + if (nm > 1 && contiguous()) { uniform = true; @@ -189,7 +189,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) } // Fix: matrices smaller than 20x20 will be written square. // HJ, 22/Jan/2009 - else if (nm < 400 && contiguous()) + else if (nm < 400 && contiguous()) { // Write size of list and start contents delimiter os << token::BEGIN_LIST; @@ -248,7 +248,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix& M) { if (nm) { - os.write(reinterpret_cast(M.v_[0]), nm*sizeof(T)); + os.write(reinterpret_cast(M.v_[0]), nm*sizeof(Type)); } } diff --git a/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.C b/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.C index e8797a1ab..28333e6e6 100644 --- a/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.C +++ b/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.C @@ -25,7 +25,7 @@ License Class DenseMatrixTools -\*----------------------------------------------------------------------------*/ +\*---------------------------------------------------------------------------*/ #include "DenseMatrixTools.H" #include "Swap.H" @@ -36,7 +36,7 @@ Class template static void Foam::DenseMatrixTools::solve ( - Matrix& A, + SquareMatrix& A, List& x, List& b ) @@ -107,12 +107,12 @@ static void Foam::DenseMatrixTools::solve } -template +template static void Foam::DenseMatrixTools::qrDecompose ( const label nCols, - FieldField& A, - Matrix& R + FieldField& A, + Matrix& R ) { // Note: consider Arnoldi algorithm for speed-up. HJ, 14/Sep/2006 @@ -128,9 +128,9 @@ static void Foam::DenseMatrixTools::qrDecompose for (label k = j + 1; k < nCols; k++) { - const Field& Aj = A[j]; - Field& Ak = A[k]; - T& Rjk = R[j][k]; + const Field& Aj = A[j]; + Field& Ak = A[k]; + Type& Rjk = R[j][k]; Rjk = gSumProd(Aj, Ak); diff --git a/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.H b/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.H index 9545a6b99..178f330d5 100644 --- a/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.H +++ b/src/OpenFOAM/matrices/Matrix/tools/DenseMatrixTools.H @@ -33,7 +33,7 @@ SourceFiles #ifndef DenseMatrixTools_H #define DenseMatrixTools_H -#include "Matrix.H" +#include "SquareMatrix.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,16 +47,16 @@ namespace Foam namespace DenseMatrixTools { //- Solve using Gauss Elimination with pivoting. Destroys matrix and b - template - static void solve(Matrix& A, List& x, List& b); + template + static void solve(SquareMatrix& A, List& x, List& b); //- Q-R decomposition - template + template static void qrDecompose ( const label nCols, FieldField& A, - Matrix& R + Matrix& R ); }; diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H index f6dd24e9b..f41cbc56e 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrix.H @@ -250,6 +250,11 @@ public: //- Maximum number of iterations label maxIter_; + + protected: + + // Protected data + //- Matrix reference const lduMatrix& matrix_; @@ -451,7 +456,9 @@ public: //- Abstract base-class for lduMatrix smoothers class smoother { - // Private data + protected: + + // Protected data //- Matrix reference const lduMatrix& matrix_; @@ -585,7 +592,9 @@ public: //- Abstract base-class for lduMatrix preconditioners class preconditioner { - // Private data + protected: + + // Protected data //- Matrix reference const lduMatrix& matrix_; diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C index 627c4e1d3..6e006291b 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixPreconditioner.C @@ -84,7 +84,7 @@ Foam::lduPreconditioner::New const dictionary& controls = e.isDict() ? e.dict() : dictionary::null; - if (sol.matrix().symmetric()) + if (matrix.symmetric()) { symMatrixConstructorTable::iterator constructorIter = symMatrixConstructorTablePtr_->find(preconName); @@ -121,7 +121,7 @@ Foam::lduPreconditioner::New ) ); } - else if (sol.matrix().asymmetric()) + else if (matrix.asymmetric()) { asymMatrixConstructorTable::iterator constructorIter = asymMatrixConstructorTablePtr_->find(preconName); diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C index c5a919aea..b2ecabe12 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSmoother.C @@ -172,6 +172,8 @@ Foam::autoPtr Foam::lduMatrix::smoother::New ) << "cannot solve incomplete matrix, " "no diagonal or off-diagonal coefficient" << exit(FatalIOError); + + return autoPtr(NULL); } } diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C index 37b0537fe..7e48e1fc3 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixSolver.C @@ -48,7 +48,7 @@ Foam::autoPtr Foam::lduMatrix::solver::New const dictionary& dict ) { - word name(dict.lookup("solver")); + word solverName(dict.lookup("solver")); if (matrix.diagonal()) { @@ -243,10 +243,11 @@ Foam::lduMatrix::solver::solver void Foam::lduMatrix::solver::readControls() { - minIter_ = dict_.lookupOrDefault