1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Tetrahedral Finite Element matrix check for diagonal dominance.
27 Especially useful for debugging complex interfaces
29 \*---------------------------------------------------------------------------*/
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
39 void tetFemMatrix<Type>::check()
43 Info<< "tetFemMatrix<Type>::check : checking tetFemMatrix<Type>"
47 Pout << "First check diagonal dominance" << endl;
49 // Get constant matrix access
50 const tetFemMatrix<Type>& constMatrix = *this;
52 const scalarField& lower = constMatrix.lower();
53 const scalarField& upper = constMatrix.upper();
54 const scalarField& dd = constMatrix.diag();
56 // Calculate local matrix off-diag sum
57 scalarField dummySource(lduAddr().size(), 0.0);
59 const scalarField oldLower = lower;
60 const scalarField oldUpper = upper;
61 const scalarField oldDiag = dd;
63 // Get matrix addressing
64 const unallocLabelList& L = lduAddr().lowerAddr();
65 const unallocLabelList& U = lduAddr().upperAddr();
68 scalarField matrixSumOffDiag(lduAddr().size(), 0.0);
69 scalarField dummyInternal(lduAddr().size(), 1.0);
73 matrixSumOffDiag[L[face]] += oldLower[face];
74 matrixSumOffDiag[U[face]] += oldUpper[face];
77 Pout<< "void tetFemMatrix<Type>::check() : "
78 << "Raw matrix difference: "
79 << sum(mag(matrixSumOffDiag + oldDiag)) << endl;
82 // Add the coupling coefficients
85 addCouplingSource(dummySource);
87 // Make a copy of interfaces: no longer a reference
89 lduInterfaceFieldPtrsList interfaces = psi_.boundaryField().interfaces();
91 // Prepare for coupled interface update
92 FieldField<Field, scalar> coupledBouCoeffs(psi_.boundaryField().size());
93 FieldField<Field, scalar> coupledIntCoeffs(psi_.boundaryField().size());
95 forAll(psi_.boundaryField(), patchI)
97 const tetPolyPatchField<Type>& ptf = psi_.boundaryField()[patchI];
99 coupledBouCoeffs.set(patchI, ptf.cutBouCoeffs(*this));
101 coupledIntCoeffs.set(patchI, ptf.cutIntCoeffs(*this));
104 eliminateCouplingCoeffs();
106 Pout << "Second check diagonal dominance" << endl;
107 // Calculate local matrix off-diag sum
109 scalarField matrixSumOffDiag(lduAddr().size(), 0.0);
110 scalarField dummyInternal(lduAddr().size(), 1.0);
114 matrixSumOffDiag[L[face]] += lower[face];
115 matrixSumOffDiag[U[face]] += upper[face];
118 // Initialise coupling
119 forAll (interfaces, interfaceI)
121 // Check if the pointer is set
122 if (interfaces.set(interfaceI))
124 interfaces[interfaceI].initInterfaceMatrixUpdate
129 coupledBouCoeffs[interfaceI],
131 Pstream::defaultCommsType
136 // Update coupled interface
137 forAll (interfaces, interfaceI)
139 if (interfaces.set(interfaceI))
141 interfaces[interfaceI].updateInterfaceMatrix
146 coupledBouCoeffs[interfaceI],
148 Pstream::defaultCommsType
153 Pout<< "void tetFemMatrix<Type>::check() : "
154 << "parallel matrix difference: "
155 << sum(mag(matrixSumOffDiag + dd)) << endl;
158 // restore the matrix in the original state
161 this->upper() = oldUpper;
166 this->lower() = oldLower;
171 this->diag() = oldDiag;
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 } // End namespace Foam
180 // ************************************************************************* //