1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Tetrahedral Finite Element matrix check for diagonal dominance.
26 Especially useful for debugging complex interfaces
28 \*---------------------------------------------------------------------------*/
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
38 void tetFemMatrix<Type>::check()
42 Info<< "tetFemMatrix<Type>::check : checking tetFemMatrix<Type>"
46 Pout << "First check diagonal dominance" << endl;
48 // Get constant matrix access
49 const tetFemMatrix<Type>& constMatrix = *this;
51 const scalarField& lower = constMatrix.lower();
52 const scalarField& upper = constMatrix.upper();
53 const scalarField& dd = constMatrix.diag();
55 // Calculate local matrix off-diag sum
56 scalarField dummySource(lduAddr().size(), 0.0);
58 const scalarField oldLower = lower;
59 const scalarField oldUpper = upper;
60 const scalarField oldDiag = dd;
62 // Get matrix addressing
63 const unallocLabelList& L = lduAddr().lowerAddr();
64 const unallocLabelList& U = lduAddr().upperAddr();
67 scalarField matrixSumOffDiag(lduAddr().size(), 0.0);
68 scalarField dummyInternal(lduAddr().size(), 1.0);
72 matrixSumOffDiag[L[face]] += oldLower[face];
73 matrixSumOffDiag[U[face]] += oldUpper[face];
76 Pout<< "void tetFemMatrix<Type>::check() : "
77 << "Raw matrix difference: "
78 << sum(mag(matrixSumOffDiag + oldDiag)) << endl;
81 // Add the coupling coefficients
84 addCouplingSource(dummySource);
86 // Make a copy of interfaces: no longer a reference
88 lduInterfaceFieldPtrsList interfaces = psi_.boundaryField().interfaces();
90 // Prepare for coupled interface update
91 FieldField<Field, scalar> coupledBouCoeffs(psi_.boundaryField().size());
92 FieldField<Field, scalar> coupledIntCoeffs(psi_.boundaryField().size());
94 forAll(psi_.boundaryField(), patchI)
96 const tetPolyPatchField<Type>& ptf = psi_.boundaryField()[patchI];
98 coupledBouCoeffs.set(patchI, ptf.cutBouCoeffs(*this));
100 coupledIntCoeffs.set(patchI, ptf.cutIntCoeffs(*this));
103 eliminateCouplingCoeffs();
105 Pout << "Second check diagonal dominance" << endl;
106 // Calculate local matrix off-diag sum
108 scalarField matrixSumOffDiag(lduAddr().size(), 0.0);
109 scalarField dummyInternal(lduAddr().size(), 1.0);
113 matrixSumOffDiag[L[face]] += lower[face];
114 matrixSumOffDiag[U[face]] += upper[face];
117 // Initialise coupling
118 forAll (interfaces, interfaceI)
120 // Check if the pointer is set
121 if (interfaces.set(interfaceI))
123 interfaces[interfaceI].initInterfaceMatrixUpdate
128 coupledBouCoeffs[interfaceI],
130 static_cast<Pstream::commsTypes>
132 Pstream::defaultCommsType()
134 false // Do not switch to lhs
139 // Update coupled interface
140 forAll (interfaces, interfaceI)
142 if (interfaces.set(interfaceI))
144 interfaces[interfaceI].updateInterfaceMatrix
149 coupledBouCoeffs[interfaceI],
151 static_cast<Pstream::commsTypes>(Pstream::defaultCommsType()),
152 false // Do not switch to lhs
157 Pout<< "void tetFemMatrix<Type>::check() : "
158 << "parallel matrix difference: "
159 << sum(mag(matrixSumOffDiag + dd)) << endl;
162 // restore the matrix in the original state
165 this->upper() = oldUpper;
170 this->lower() = oldLower;
175 this->diag() = oldDiag;
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 } // End namespace Foam
184 // ************************************************************************* //