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/>.
28 Collection of lduMatrices solved together as a block system
31 Hrvoje Jasak, Wikki Ltd. All rights reserved
33 \*---------------------------------------------------------------------------*/
35 #include "coupledLduMatrix.H"
36 #include "processorLduInterfaceField.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 defineTypeNameAndDebug(coupledLduMatrix, 1);
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 // Construct given size
49 Foam::coupledLduMatrix::coupledLduMatrix(const label size)
51 PtrList<lduMatrix>(size)
55 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
57 Foam::coupledLduMatrix::~coupledLduMatrix()
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 bool Foam::coupledLduMatrix::diagonal() const
65 const PtrList<lduMatrix>& matrices = *this;
69 forAll (matrices, matrixI)
71 diag = diag && matrices[matrixI].diagonal();
78 bool Foam::coupledLduMatrix::symmetric() const
80 const PtrList<lduMatrix>& matrices = *this;
84 forAll (matrices, matrixI)
87 (sym && matrices[matrixI].diagonal())
88 || (sym && matrices[matrixI].symmetric());
95 bool Foam::coupledLduMatrix::asymmetric() const
97 const PtrList<lduMatrix>& matrices = *this;
101 forAll (matrices, matrixI)
103 asym = (asym || matrices[matrixI].asymmetric());
110 void Foam::coupledLduMatrix::Amul
112 FieldField<Field, scalar>& result,
113 const FieldField<Field, scalar>& x,
114 const PtrList<FieldField<Field, scalar> >& bouCoeffs,
115 const lduInterfaceFieldPtrsListList& interfaces,
119 const PtrList<lduMatrix>& matrices = *this;
121 // Reset product to zero
124 // Initialise the update of coupled interfaces
134 forAll (matrices, rowI)
136 matrices[rowI].AmulCore(result[rowI], x[rowI]);
139 // Update couple interfaces
140 updateMatrixInterfaces
151 void Foam::coupledLduMatrix::Tmul
153 FieldField<Field, scalar>& result,
154 const FieldField<Field, scalar>& x,
155 const PtrList<FieldField<Field, scalar> >& intCoeffs,
156 const lduInterfaceFieldPtrsListList& interfaces,
160 const PtrList<lduMatrix>& matrices = *this;
162 // Reset product to zero
165 // Initialise the update of coupled interfaces
175 forAll (matrices, rowI)
177 matrices[rowI].TmulCore(result[rowI], x[rowI]);
180 // Update couple interfaces
181 updateMatrixInterfaces
192 void Foam::coupledLduMatrix::initMatrixInterfaces
194 const PtrList<FieldField<Field, scalar> >& coupleCoeffs,
195 const lduInterfaceFieldPtrsListList& interfaces,
196 const FieldField<Field, scalar>& x,
197 FieldField<Field, scalar>& result,
201 const PtrList<lduMatrix>& matrices = *this;
203 // Note. The comms design requires all non-processor interfaces
204 // to be updated first, followed by the update of processor
205 // interfaces. The reason is that non-processor coupled
206 // interfaces require a complex comms pattern involving more than
207 // pairwise communications.
208 // Under normal circumstances this is achieved naturall, since
209 // processor interfaces come last on the list and other coupled
210 // interfaces execute complex comms at init() level.
211 // For coupled matrices, the update loop needs to be split over
212 // all matrices by hand
213 // Bug fix: Zeljko Tukovic, 7/Apr/2015
215 // Init update all non-processor coupled interfaces
216 forAll (matrices, rowI)
220 Pstream::defaultCommsType() == Pstream::blocking
221 || Pstream::defaultCommsType() == Pstream::nonBlocking
224 forAll (interfaces[rowI], interfaceI)
226 if (interfaces[rowI].set(interfaceI))
230 !isA<processorLduInterfaceField>
232 interfaces[rowI][interfaceI]
236 interfaces[rowI][interfaceI].initInterfaceMatrixUpdate
241 coupleCoeffs[rowI][interfaceI],
243 static_cast<const Pstream::commsTypes>
245 Pstream::defaultCommsType()
255 matrices[rowI].initMatrixInterfaces
266 // Init update for all processor interfaces
267 forAll (matrices, rowI)
271 Pstream::defaultCommsType() == Pstream::blocking
272 || Pstream::defaultCommsType() == Pstream::nonBlocking
275 forAll (interfaces[rowI], interfaceI)
277 if (interfaces[rowI].set(interfaceI))
281 isA<processorLduInterfaceField>
283 interfaces[rowI][interfaceI]
287 interfaces[rowI][interfaceI].initInterfaceMatrixUpdate
292 coupleCoeffs[rowI][interfaceI],
294 static_cast<const Pstream::commsTypes>
296 Pstream::defaultCommsType()
308 void Foam::coupledLduMatrix::updateMatrixInterfaces
310 const PtrList<FieldField<Field, scalar> >& coupleCoeffs,
311 const lduInterfaceFieldPtrsListList& interfaces,
312 const FieldField<Field, scalar>& x,
313 FieldField<Field, scalar>& result,
317 const PtrList<lduMatrix>& matrices = *this;
319 forAll (matrices, rowI)
321 matrices[rowI].updateMatrixInterfaces
333 // ************************************************************************* //