From 86fc3380465d7f8158892773fcb390b1861f00d5 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 28 Oct 2015 10:08:07 +0000 Subject: [PATCH] Feature ILUCp and BlockILUCp preconditioning, extended addr update and clean-up --- .../expandContract/ExpandTensorNField.C | 6 +- .../expandContract/ExpandTensorNField.H | 5 +- .../fields/expandContract/expandTensorField.C | 19 ++ .../fields/expandContract/expandTensorField.H | 3 + .../BlockAmg/coarseBlockAmgLevel.C | 9 +- .../BlockAmg/fineBlockAmgLevel.C | 9 +- .../BlockLduMatrix/BlockLduMatrix.H | 5 +- .../BlockLduMatrix/BlockLduMatrixOperations.C | 207 +++++++++++++----- .../extendedBlockLduMatrix.C | 42 ++-- .../extendedBlockLduMatrix.H | 6 +- .../sphericalTensorExtendedBlockLduMatrix.C | 27 ++- .../symmTensorExtendedBlockLduMatrix.C | 32 ++- .../tensorExtendedBlockLduMatrix.C | 36 ++- .../BlockGaussSeidelPrecon.C | 3 +- .../BlockILUCpPrecon/BlockILUCpPrecon.C | 20 +- .../BlockILUCpPrecon/BlockILUCpPrecon.H | 9 +- .../extendedLduAddressing.C | 79 ++++--- .../extendedLduAddressing.H | 50 ++--- .../lduMatrix/lduAddressing/lduAddressing.C | 36 +++ .../lduMatrix/lduAddressing/lduAddressing.H | 24 +- .../extendedLduMatrix/extendedLduMatrix.C | 21 +- .../extendedLduMatrix/extendedLduMatrix.H | 14 +- src/foam/primitives/VectorN/TensorNI.H | 42 +++- src/foam/primitives/VectorN/VectorN.H | 2 + src/foam/primitives/VectorN/VectorNI.H | 6 + .../VectorN/expandContract/ExpandTensorN.H | 3 + .../VectorN/expandContract/ExpandTensorNI.H | 86 +++++++- .../primitives/expandContract/expandTensor.H | 48 ++++ src/lduSolvers/lduPrecon/ILUCp/ILUCp.C | 26 +-- src/lduSolvers/lduPrecon/ILUCp/ILUCp.H | 11 +- 30 files changed, 632 insertions(+), 254 deletions(-) diff --git a/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.C b/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.C index 51ba1d848..248a87247 100644 --- a/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.C +++ b/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.C @@ -77,7 +77,11 @@ UNARY_FUNCTION(sphericalTensorType, cmptType, expandScalar) \ \ UNARY_FUNCTION(tensorType, vectorType, expandLinear) \ UNARY_FUNCTION(diagTensorType, vectorType, expandLinear) \ -UNARY_FUNCTION(sphericalTensorType, vectorType, expandLinear) +UNARY_FUNCTION(sphericalTensorType, vectorType, expandLinear) \ + \ +UNARY_FUNCTION(vectorType, tensorType, sumToDiag) \ +UNARY_FUNCTION(vectorType, tensorType, sumMagToDiag) + namespace Foam { diff --git a/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.H b/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.H index 2c4b7da2e..71b123cae 100644 --- a/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.H +++ b/src/foam/fields/Fields/VectorNFields/expandContract/ExpandTensorNField.H @@ -65,7 +65,10 @@ UNARY_FUNCTION(sphericalTensorType, cmptType, expandScalar) \ \ UNARY_FUNCTION(tensorType, vectorType, expandLinear) \ UNARY_FUNCTION(diagTensorType, vectorType, expandLinear) \ -UNARY_FUNCTION(sphericalTensorType, vectorType, expandLinear) +UNARY_FUNCTION(sphericalTensorType, vectorType, expandLinear) \ + \ +UNARY_FUNCTION(vectorType, tensorType, sumToDiag) \ +UNARY_FUNCTION(vectorType, tensorType, sumMagToDiag) // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // diff --git a/src/foam/fields/expandContract/expandTensorField.C b/src/foam/fields/expandContract/expandTensorField.C index 7f4d9f946..fb0698104 100644 --- a/src/foam/fields/expandContract/expandTensorField.C +++ b/src/foam/fields/expandContract/expandTensorField.C @@ -85,6 +85,25 @@ void expandLinear(Field& res, const UList& f) } } + +void sumToDiag(Field& res, const UList& f) +{ + forAll (res, i) + { + sumToDiag(res[i], f[i]); + } +} + + +void sumMagToDiag(Field& res, const UList& f) +{ + forAll (res, i) + { + sumMagToDiag(res[i], f[i]); + } +} + + } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/foam/fields/expandContract/expandTensorField.H b/src/foam/fields/expandContract/expandTensorField.H index 1ae41828f..2cfc568b8 100644 --- a/src/foam/fields/expandContract/expandTensorField.H +++ b/src/foam/fields/expandContract/expandTensorField.H @@ -54,6 +54,9 @@ void expandScalar(Field& res, const UList& f); void expandScalar(Field& res, const UList& f); void expandLinear(Field& res, const UList& f); +void sumToDiag(Field& res, const UList& f); +void sumMagToDiag(Field& res, const UList& f); + } // End namespace Foam #endif diff --git a/src/foam/matrices/blockLduMatrix/BlockAmg/coarseBlockAmgLevel.C b/src/foam/matrices/blockLduMatrix/BlockAmg/coarseBlockAmgLevel.C index 2f7cd9d72..5ea4a85c8 100644 --- a/src/foam/matrices/blockLduMatrix/BlockAmg/coarseBlockAmgLevel.C +++ b/src/foam/matrices/blockLduMatrix/BlockAmg/coarseBlockAmgLevel.C @@ -76,12 +76,15 @@ Foam::coarseBlockAmgLevel::coarseBlockAmgLevel BlockLduSmoother::New ( matrixPtr_, - dict, - "coarseSmoother" + dict +// ,"coarseSmoother" ) ), Ax_() -{} +{ + Info<< "Coarse AMG level check" << endl; + matrixPtr_->check(); +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/src/foam/matrices/blockLduMatrix/BlockAmg/fineBlockAmgLevel.C b/src/foam/matrices/blockLduMatrix/BlockAmg/fineBlockAmgLevel.C index 14bfbc773..691649a37 100644 --- a/src/foam/matrices/blockLduMatrix/BlockAmg/fineBlockAmgLevel.C +++ b/src/foam/matrices/blockLduMatrix/BlockAmg/fineBlockAmgLevel.C @@ -71,12 +71,15 @@ Foam::fineBlockAmgLevel::fineBlockAmgLevel BlockLduSmoother::New ( matrix, - dict, - "fineSmoother" + dict +// ,"fineSmoother" ) ), Ax_() -{} +{ + Info<< "Fine AMG level check" << endl; + matrix_.check(); +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrix.H b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrix.H index ec91d6e89..9a1722593 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrix.H +++ b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrix.H @@ -227,9 +227,8 @@ public: BlockLduMatrix(BlockLduMatrix&, bool reUse); - // Destructor - - virtual ~BlockLduMatrix(); + //- Destructor + virtual ~BlockLduMatrix(); // Member functions diff --git a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrixOperations.C b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrixOperations.C index dcdd3b3df..be8033239 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrixOperations.C +++ b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/BlockLduMatrixOperations.C @@ -307,9 +307,14 @@ void Foam::BlockLduMatrix::check() const typedef typename TypeCoeffField::linearTypeField linearTypeField; typedef typename TypeCoeffField::squareTypeField squareTypeField; - // Copy the diagonal - TypeCoeffField DiagCopy(this->diag().size()); -// TypeCoeffField DiagCopy = this->diag(); + // TODO: Account for coupled boundary patch coeffs + // HJ, 29/Oct/2015 + + // Get original diag + const TypeCoeffField& d = this->diag(); + + // Copy the diagonal. It is initialised to zero + TypeCoeffField SumOffDiag(d.size()); const unallocLabelList& l = lduAddr().lowerAddr(); const unallocLabelList& u = lduAddr().upperAddr(); @@ -323,67 +328,110 @@ void Foam::BlockLduMatrix::check() const if ( Upper.activeType() == blockCoeffBase::SQUARE - || DiagCopy.activeType() == blockCoeffBase::SQUARE + || d.activeType() == blockCoeffBase::SQUARE ) { + // Note: For a square coefficient, the matrix needs to be analysed + // row-by-row, including the contribution of the off-diagonal + // elements in the diagonal matrix + + // Get result as linear + linearTypeField& activeSumOffDiag = SumOffDiag.asLinear(); + + // Do diagonal elements + + // Create the diagonal matrix element without the diagonal + const squareTypeField& activeDiag = d.asSquare(); + + linearTypeField diagDiag(activeDiag.size()); + squareTypeField luDiag(activeDiag.size()); + + // Take out the diagonal from the diag as a linear type + contractLinear(diagDiag, activeDiag); + + // Expand diagonal only to full square type and store into luDiag + expandLinear(luDiag, diagDiag); + + // Keep only off-diagonal in luDiag + luDiag = activeDiag - luDiag; + + sumMagToDiag(activeSumOffDiag, luDiag); + + // Do the off-diagonal elements by collapsing each row + // into the linear form + const squareTypeField& activeUpper = Upper.asSquare(); - squareTypeField& activeDiagCopy = DiagCopy.asSquare(); for (register label coeffI = 0; coeffI < l.size(); coeffI++) { - activeDiagCopy[l[coeffI]] += activeUpper[coeffI].T(); - activeDiagCopy[u[coeffI]] += activeUpper[coeffI]; + activeSumOffDiag[l[coeffI]] += + sumMagToDiag(activeUpper[coeffI].T()); + + activeSumOffDiag[u[coeffI]] += + sumMagToDiag(activeUpper[coeffI]); } - Info<< "void BlockLduMatrix::check() const : " - << "Symmetric matrix: raw matrix difference: " - << sum(mag(activeDiagCopy)) - << " scaled: " - << sum(mag(activeDiagCopy))/sum(mag(this->diag().asSquare())) + // Check diagonal dominance + + diagDiag = cmptMag(diagDiag); + + // Divide diagonal with sum of off-diagonals + cmptDivide(diagDiag, diagDiag, activeSumOffDiag); + + InfoIn("void BlockLduMatrix::check() const)") + << "Symmetric matrix: " << activeDiag.size() + << " diagonal dominance sym square: " + << Foam::min(diagDiag) << endl; } else if ( Upper.activeType() == blockCoeffBase::LINEAR - || DiagCopy.activeType() == blockCoeffBase::LINEAR + || d.activeType() == blockCoeffBase::LINEAR ) { + const linearTypeField& activeDiag = d.asLinear(); + const linearTypeField& activeUpper = Upper.asLinear(); - linearTypeField& activeDiagCopy = DiagCopy.asLinear(); + linearTypeField& activeSumOffDiag = SumOffDiag.asLinear(); for (register label coeffI = 0; coeffI < l.size(); coeffI++) { - activeDiagCopy[l[coeffI]] += activeUpper[coeffI]; - activeDiagCopy[u[coeffI]] += activeUpper[coeffI]; + activeSumOffDiag[l[coeffI]] += cmptMag(activeUpper[coeffI]); + activeSumOffDiag[u[coeffI]] += cmptMag(activeUpper[coeffI]); } - Info<< "void BlockLduMatrix::check() const : " - << "Symmetric matrix: raw matrix difference: " - << sum(mag(activeDiagCopy)) - << " scaled: " - << sum(mag(activeDiagCopy))/sum(mag(this->diag().asLinear())) + linearTypeField diagDiag = cmptMag(activeDiag); + + cmptDivide(diagDiag, diagDiag, activeSumOffDiag); + + InfoIn("void BlockLduMatrix::check() const)") + << "Symmetric matrix: " << activeDiag.size() + << " diagonal dominance sym linear: " + << Foam::min(diagDiag) << endl; } else if ( Upper.activeType() == blockCoeffBase::SCALAR - || DiagCopy.activeType() == blockCoeffBase::SCALAR + || d.activeType() == blockCoeffBase::SCALAR ) { + const scalarTypeField& activeDiag = d.asScalar(); + const scalarTypeField& activeUpper = Upper.asScalar(); - scalarTypeField& activeDiagCopy = DiagCopy.asScalar(); + scalarTypeField& activeSumOffDiag = SumOffDiag.asScalar(); for (register label coeffI = 0; coeffI < l.size(); coeffI++) { - activeDiagCopy[l[coeffI]] += activeUpper[coeffI]; - activeDiagCopy[u[coeffI]] += activeUpper[coeffI]; + activeSumOffDiag[l[coeffI]] += cmptMag(activeUpper[coeffI]); + activeSumOffDiag[u[coeffI]] += cmptMag(activeUpper[coeffI]); } - Info<< "void BlockLduMatrix::check() const : " - << "Symmetric matrix: raw matrix difference: " - << sum(mag(activeDiagCopy)) - << " scaled: " - << sum(mag(activeDiagCopy))/sum(mag(this->diag().asScalar())) + InfoIn("void BlockLduMatrix::check() const)") + << "Symmetric matrix: " << activeDiag.size() + << " diagonal dominance sym scalar: " + << Foam::min(mag(activeDiag)/activeSumOffDiag) << endl; } } @@ -398,78 +446,121 @@ void Foam::BlockLduMatrix::check() const ( Lower.activeType() == blockCoeffBase::SQUARE || Upper.activeType() == blockCoeffBase::SQUARE - || DiagCopy.activeType() == blockCoeffBase::SQUARE + || d.activeType() == blockCoeffBase::SQUARE ) { + // Note: For a square coefficient, the matrix needs to be analysed + // row-by-row, including the contribution of the off-diagonal + // elements in the diagonal matrix + + // Get result as linear + linearTypeField& activeSumOffDiag = SumOffDiag.asLinear(); + + // Do diagonal elements + + // Create the diagonal matrix element without the diagonal + const squareTypeField& activeDiag = d.asSquare(); + + linearTypeField diagDiag(activeDiag.size()); + squareTypeField luDiag(activeDiag.size()); + + // Take out the diagonal from the diag as a linear type + contractLinear(diagDiag, activeDiag); + + // Expand diagonal only to full square type and store into luDiag + expandLinear(luDiag, diagDiag); + + // Keep only off-diagonal in luDiag + luDiag = activeDiag - luDiag; + + sumMagToDiag(activeSumOffDiag, luDiag); + + // Do the off-diagonal elements by collapsing each row + // into the linear form + const squareTypeField& activeLower = Lower.asSquare(); const squareTypeField& activeUpper = Upper.asSquare(); - squareTypeField& activeDiagCopy = DiagCopy.asSquare(); for (register label coeffI = 0; coeffI < l.size(); coeffI++) { - activeDiagCopy[l[coeffI]] += activeLower[coeffI]; - activeDiagCopy[u[coeffI]] += activeUpper[coeffI]; + activeSumOffDiag[l[coeffI]] += + sumMagToDiag(activeLower[coeffI]); + + activeSumOffDiag[u[coeffI]] += + sumMagToDiag(activeUpper[coeffI]); } - Info<< "void BlockLduMatrix::check() const : " - << "Asymmetric matrix: raw matrix difference: " - << sum(mag(activeDiagCopy)) - << " scaled: " - << sum(mag(activeDiagCopy))/sum(mag(this->diag().asSquare())) + // Check diagonal dominance + + diagDiag = cmptMag(diagDiag); + + // Divide diagonal with sum of off-diagonals + cmptDivide(diagDiag, diagDiag, activeSumOffDiag); + + InfoIn("void BlockLduMatrix::check() const)") + << "Asymmetric matrix: " << activeDiag.size() + << " diagonal dominance assym square: " + << Foam::min(diagDiag) << endl; } else if ( Lower.activeType() == blockCoeffBase::LINEAR || Upper.activeType() == blockCoeffBase::LINEAR - || DiagCopy.activeType() == blockCoeffBase::LINEAR + || d.activeType() == blockCoeffBase::LINEAR ) { + const linearTypeField& activeDiag = d.asLinear(); + const linearTypeField& activeLower = Lower.asLinear(); const linearTypeField& activeUpper = Upper.asLinear(); - linearTypeField& activeDiagCopy = DiagCopy.asLinear(); + linearTypeField& activeSumOffDiag = SumOffDiag.asLinear(); for (register label coeffI = 0; coeffI < l.size(); coeffI++) { - activeDiagCopy[l[coeffI]] += activeLower[coeffI]; - activeDiagCopy[u[coeffI]] += activeUpper[coeffI]; + activeSumOffDiag[l[coeffI]] += cmptMag(activeLower[coeffI]); + activeSumOffDiag[u[coeffI]] += cmptMag(activeUpper[coeffI]); } - Info<< "void BlockLduMatrix::check() const : " - << "Asymmetric matrix: raw matrix difference: " - << sum(mag(activeDiagCopy)) - << " scaled: " - << sum(mag(activeDiagCopy))/sum(mag(this->diag().asLinear())) + linearTypeField diagDiag = cmptMag(activeDiag); + + cmptDivide(diagDiag, diagDiag, activeSumOffDiag); + + InfoIn("void BlockLduMatrix::check() const)") + << "Asymmetric matrix: " << activeDiag.size() + << " diagonal dominance assym linear: " + << Foam::min(diagDiag) << endl; } else if ( Lower.activeType() == blockCoeffBase::SCALAR || Upper.activeType() == blockCoeffBase::SCALAR - || DiagCopy.activeType() == blockCoeffBase::SCALAR + || d.activeType() == blockCoeffBase::SCALAR ) { + const scalarTypeField& activeDiag = d.asScalar(); + const scalarTypeField& activeLower = Lower.asScalar(); const scalarTypeField& activeUpper = Upper.asScalar(); - scalarTypeField& activeDiagCopy = DiagCopy.asScalar(); + scalarTypeField& activeSumOffDiag = SumOffDiag.asScalar(); for (register label coeffI = 0; coeffI < l.size(); coeffI++) { - activeDiagCopy[l[coeffI]] += activeLower[coeffI]; - activeDiagCopy[u[coeffI]] += activeUpper[coeffI]; + activeSumOffDiag[l[coeffI]] += cmptMag(activeLower[coeffI]); + activeSumOffDiag[u[coeffI]] += cmptMag(activeUpper[coeffI]); } - Info<< "void BlockLduMatrix::check() const : " - << "Asymmetric matrix: raw matrix difference: " - << sum(mag(activeDiagCopy)) - << " scaled: " - << sum(mag(activeDiagCopy))/sum(mag(this->diag().asScalar())) + InfoIn("void BlockLduMatrix::check() const)") + << "Asymmetric matrix: " << activeDiag.size() + << " diagonal dominance assym scalar: " + << Foam::min(mag(activeDiag)/activeSumOffDiag) << endl; } } else { - Info<< "void BlockLduMatrix::check() const : " + InfoIn("void BlockLduMatrix::check() const)") << "Diagonal matrix" << endl; } } diff --git a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.C b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.C index 42981b44b..ff209c3d5 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.C +++ b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.C @@ -35,8 +35,13 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { if (blockLdum.diagonal()) { - WarningIn("extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)") - << "Attempted to create extended lower/upper coeffs for block " + WarningIn + ( + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" + ) << "Attempted to create extended lower/upper coeffs for block " << "matrix that is diagonal." << nl << endl; } @@ -108,7 +113,10 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper coeffs type morphing." << abort(FatalError); @@ -195,7 +203,10 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper/lower coeffs type morphing." << abort(FatalError); @@ -210,27 +221,24 @@ template Foam::extendedBlockLduMatrix::extendedBlockLduMatrix ( const BlockLduMatrix& blockLdum, - const label extensionLevel, - const polyMesh& polyMesh + const extendedLduAddressing& extLduAddr ) : basicBlockLduMatrix_(blockLdum), - extLduAddr_ - ( - extendedLduAddressing::New - ( - polyMesh, - blockLdum.lduAddr(), - extensionLevel - ) - ), + extLduAddr_(extLduAddr), extendedLowerPtr_(NULL), extendedUpperPtr_(NULL) { if (debug) { - Info<< "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&) :" - "Constructing extendedBlockLduMatrix." + InfoIn + ( + "extendedBlockLduMatrix::extendedBlockLduMatrix\n" + "(\n" + " const BlockLduMatrix& blockLdum,\n" + " const extendedLduAddressing& extLduAddr\n" + ")" + ) << "Constructing extendedBlockLduMatrix." << endl; } diff --git a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.H b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.H index ded28183d..0b9dfa6b9 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.H +++ b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/extendedBlockLduMatrix.H @@ -39,9 +39,8 @@ SourceFiles #define extendedBlockLduMatrix_H #include "extendedLduAddressing.H" -#include "polyMesh.H" -#include "className.H" #include "BlockLduMatrix.H" +#include "className.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -103,8 +102,7 @@ public: extendedBlockLduMatrix ( const BlockLduMatrix&, - const label, - const polyMesh& + const extendedLduAddressing& ); diff --git a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/sphericalTensorExtendedBlockLduMatrix.C b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/sphericalTensorExtendedBlockLduMatrix.C index 720f8f9ec..87796e29c 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/sphericalTensorExtendedBlockLduMatrix.C +++ b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/sphericalTensorExtendedBlockLduMatrix.C @@ -41,8 +41,13 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { if (blockLdum.diagonal()) { - WarningIn("extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)") - << "Attempted to create extended lower/upper coeffs for block " + WarningIn + ( + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" + ) << "Attempted to create extended lower/upper coeffs for block " << "matrix that is diagonal." << nl << endl; } @@ -102,7 +107,11 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::" + "mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper coeffs type morphing." << abort(FatalError); @@ -158,7 +167,11 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::" + "mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix lower coeffs type morphing." << abort(FatalError); @@ -229,7 +242,11 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::" + "mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper/lower coeffs type morphing." << abort(FatalError); diff --git a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/symmTensorExtendedBlockLduMatrix.C b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/symmTensorExtendedBlockLduMatrix.C index 63715b2d3..75296b79d 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/symmTensorExtendedBlockLduMatrix.C +++ b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/symmTensorExtendedBlockLduMatrix.C @@ -41,8 +41,13 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { if (blockLdum.diagonal()) { - WarningIn("extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)") - << "Attempted to create extended lower/upper coeffs for block " + WarningIn + ( + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" + ) << "Attempted to create extended lower/upper coeffs for block " << "matrix that is diagonal." << nl << endl; } @@ -102,7 +107,11 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::" + "mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper coeffs type morphing." << abort(FatalError); @@ -158,7 +167,11 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::" + "mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix lower coeffs type morphing." << abort(FatalError); @@ -188,7 +201,8 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs if (upper.activeType() == blockCoeffBase::SCALAR) { // Helper type definition - typedef typename CoeffField::scalarTypeField activeType; + typedef typename CoeffField::scalarTypeField + activeType; // Get references to fields const activeType& activeUpper = upper.asScalar(); @@ -207,7 +221,8 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs else if (upper.activeType() == blockCoeffBase::LINEAR) { // Helper type definition - typedef typename CoeffField::linearTypeField activeType; + typedef typename CoeffField::linearTypeField + activeType; // Get references to fields const activeType& activeUpper = upper.asLinear(); @@ -227,7 +242,10 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper/lower coeffs type morphing." << abort(FatalError); diff --git a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/tensorExtendedBlockLduMatrix.C b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/tensorExtendedBlockLduMatrix.C index 25efd56ea..dd7e768df 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/tensorExtendedBlockLduMatrix.C +++ b/src/foam/matrices/blockLduMatrix/BlockLduMatrix/extendedBlockLduMatrix/tensorExtendedBlockLduMatrix.C @@ -41,8 +41,13 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { if (blockLdum.diagonal()) { - WarningIn("extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)") - << "Attempted to create extended lower/upper coeffs for block " + WarningIn + ( + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" + ) << "Attempted to create extended lower/upper coeffs for block " << "matrix that is diagonal." << nl << endl; } @@ -67,7 +72,8 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs if (upper.activeType() == blockCoeffBase::SCALAR) { // Helper type definition - typedef typename CoeffField::scalarTypeField activeType; + typedef typename CoeffField::scalarTypeField + activeType; // Get references to fields const activeType& activeUpper = upper.asScalar(); @@ -83,7 +89,8 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs else if (upper.activeType() == blockCoeffBase::LINEAR) { // Helper type definition - typedef typename CoeffField::linearTypeField activeType; + typedef typename CoeffField::linearTypeField + activeType; // Get references to fields const activeType& activeUpper = upper.asLinear(); @@ -100,7 +107,10 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper coeffs type morphing." << abort(FatalError); @@ -121,7 +131,8 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs if (lower.activeType() == blockCoeffBase::SCALAR) { // Helper type definition - typedef typename CoeffField::scalarTypeField activeType; + typedef typename CoeffField::scalarTypeField + activeType; // Get references to fields const activeType& activeLower = lower.asScalar(); @@ -137,7 +148,8 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs else if (lower.activeType() == blockCoeffBase::LINEAR) { // Helper type definition - typedef typename CoeffField::linearTypeField activeType; + typedef typename CoeffField::linearTypeField + activeType; // Get references to fields const activeType& activeLower = lower.asLinear(); @@ -154,7 +166,10 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix lower coeffs type morphing." << abort(FatalError); @@ -223,7 +238,10 @@ void Foam::extendedBlockLduMatrix::mapOffDiagCoeffs { FatalErrorIn ( - "extendedBlockLduMatrix(lduMatrix&, label, polyMesh&)" + "void extendedBlockLduMatrix::mapOffDiagCoeffs\n" + "(\n" + " const BlockLduMatrix& blockLdum\n" + ")" ) << "Problem between ordinary block matrix and extended" << " block matrix upper/lower coeffs type morphing." << abort(FatalError); diff --git a/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockGaussSeidelPrecon/BlockGaussSeidelPrecon.C b/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockGaussSeidelPrecon/BlockGaussSeidelPrecon.C index fff4a51c7..43f5a14be 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockGaussSeidelPrecon/BlockGaussSeidelPrecon.C +++ b/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockGaussSeidelPrecon/BlockGaussSeidelPrecon.C @@ -67,7 +67,6 @@ void Foam::BlockGaussSeidelPrecon::calcInvDiag() // For square diagonal invert diagonal only and store the rest // info LUDiag coefficient. This avoids full inverse of the // diagonal matrix. HJ, 20/Aug/2015 - Info<< "Square diag inverse" << endl; // Get reference to active diag const squareTypeField& activeDiag = d.asSquare(); @@ -83,7 +82,7 @@ void Foam::BlockGaussSeidelPrecon::calcInvDiag() // Expand diagonal only to full square type and store into luDiag expandLinear(luDiag, lf); - // Keep only off-diagonal in ldDiag. + // Keep only off-diagonal in luDiag. // Note change of sign to avoid multiplication with -1 when moving // to the other side. HJ, 20/Aug/2015 luDiag -= activeDiag; diff --git a/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.C b/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.C index 1f3589573..be722ae8d 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.C +++ b/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.C @@ -65,8 +65,10 @@ void Foam::BlockILUCpPrecon::calcActiveTypeFactorization const extendedLduAddressing& addr = extBlockMatrix_.extendedLduAddr(); // Get upper/lower extended addressing - const label* const __restrict__ uPtr = addr.extendedUpperAddr().begin(); - const label* const __restrict__ lPtr = addr.extendedLowerAddr().begin(); + const label* const __restrict__ uPtr = + addr.extendedUpperAddr().begin(); + const label* const __restrict__ lPtr = + addr.extendedLowerAddr().begin(); // Get extended owner start addressing const label* const __restrict__ ownStartPtr = @@ -87,8 +89,8 @@ void Foam::BlockILUCpPrecon::calcActiveTypeFactorization LDUType* __restrict__ zPtr = z.begin(); LDUType* __restrict__ wPtr = w.begin(); - // Define start and end face ("virtual" face when extended addressing is - // used) of this row/column. + // Define start and end face ("virtual" face when extended addressing + // is used) of this row/column. register label fStart, fEnd, fLsrStart, fLsrEnd; // Crout LU factorization @@ -505,17 +507,15 @@ Foam::BlockILUCpPrecon::BlockILUCpPrecon ) : BlockLduPrecon(matrix), - preconDiag_(matrix.diag()), - p_(readLabel(dict.lookup("fillInLevel"))), extBlockMatrix_ ( matrix, - p_, - matrix.mesh().thisDb().time().template lookupObject + matrix.mesh().lduAddr().extendedAddr ( - polyMesh::defaultRegion + readLabel(dict.lookup("fillInLevel")) ) - ) + ), + preconDiag_(matrix.diag()) { calcFactorization(); } diff --git a/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.H b/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.H index dc020ebbd..cf5c293b7 100644 --- a/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.H +++ b/src/foam/matrices/blockLduMatrix/BlockLduPrecons/BlockILUCpPrecon/BlockILUCpPrecon.H @@ -62,15 +62,12 @@ class BlockILUCpPrecon { // Private Data + //- Extended ldu matrix + mutable extendedBlockLduMatrix extBlockMatrix_; + //- Preconditioned diagonal mutable CoeffField preconDiag_; - //- Fill in level - const label p_; - - //- Extended lduMarix - mutable extendedBlockLduMatrix extBlockMatrix_; - // Private Member Functions diff --git a/src/foam/matrices/lduMatrix/lduAddressing/extendedLduAddressing/extendedLduAddressing.C b/src/foam/matrices/lduMatrix/lduAddressing/extendedLduAddressing/extendedLduAddressing.C index 70f179a44..8e0aa6a37 100644 --- a/src/foam/matrices/lduMatrix/lduAddressing/extendedLduAddressing/extendedLduAddressing.C +++ b/src/foam/matrices/lduMatrix/lduAddressing/extendedLduAddressing/extendedLduAddressing.C @@ -25,6 +25,7 @@ License #include "extendedLduAddressing.H" #include "mapPolyMesh.H" +#include "demandDrivenData.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -38,21 +39,10 @@ namespace Foam Foam::extendedLduAddressing::extendedLduAddressing ( - const polyMesh& mesh, const lduAddressing& lduAddr, const label extensionLevel ) : - MeshObject(mesh), - lowerAddr_ - ( - labelList::subList - ( - mesh.faceOwner(), - mesh.nInternalFaces() - ) - ), - upperAddr_(mesh.faceNeighbour()), lduAddr_(lduAddr), p_(extensionLevel), extendedLowerPtr_(NULL), @@ -146,6 +136,44 @@ void Foam::extendedLduAddressing::markNeighbours } +void Foam::extendedLduAddressing::calcCellCells +( + labelListList& cellCellAddr +) const +{ + // Algorithm taken from primiteMeshCellCells.C in calcCellCells() member + // function. + labelList ncc(lduAddr_.size(), 0); + + const unallocLabelList& own = lowerAddr(); + const unallocLabelList& nei = upperAddr(); + + forAll (nei, faceI) + { + ncc[own[faceI]]++; + ncc[nei[faceI]]++; + } + + // Size the list + cellCellAddr.setSize(ncc.size()); + + forAll (cellCellAddr, cellI) + { + cellCellAddr[cellI].setSize(ncc[cellI]); + } + ncc = 0; + + forAll (nei, faceI) + { + label ownCellI = own[faceI]; + label neiCellI = nei[faceI]; + + cellCellAddr[ownCellI][ncc[ownCellI]++] = neiCellI; + cellCellAddr[neiCellI][ncc[neiCellI]++] = ownCellI; + } +} + + void Foam::extendedLduAddressing::calcExtendedLowerUpper() const { if (extendedLowerPtr_ && extendedUpperPtr_) @@ -168,19 +196,16 @@ void Foam::extendedLduAddressing::calcExtendedLowerUpper() const << abort(FatalError); } - // Get polyMesh reference - const polyMesh& mesh = this->mesh(); - - // Allocate dynamic lists for extended owner/neighbour, which are later used - // to define ordinary labelLists (extendedLower, extendedUpper) + // Allocate dynamic lists for extended owner/neighbour, which are later + // used to define ordinary labelLists (extendedLower, extendedUpper) // Helper type definition typedef DynamicList