LUscalarMatrixTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "LUscalarMatrix.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class Type>
32 {
33  if (Pstream::parRun())
34  {
35  Field<Type> completeSourceSol(n());
36 
38  {
39  typename Field<Type>::subField
40  (
41  completeSourceSol,
42  sourceSol.size()
43  ).assign(sourceSol);
44 
45  for
46  (
47  int slave=Pstream::firstSlave();
48  slave<=Pstream::lastSlave(comm_);
49  slave++
50  )
51  {
53  (
55  slave,
56  reinterpret_cast<char*>
57  (
58  &(completeSourceSol[procOffsets_[slave]])
59  ),
60  (procOffsets_[slave+1]-procOffsets_[slave])*sizeof(Type),
62  comm_
63  );
64  }
65  }
66  else
67  {
69  (
72  reinterpret_cast<const char*>(sourceSol.begin()),
73  sourceSol.byteSize(),
75  comm_
76  );
77  }
78 
80  {
81  LUBacksubstitute(*this, pivotIndices_, completeSourceSol);
82 
83  sourceSol = typename Field<Type>::subField
84  (
85  completeSourceSol,
86  sourceSol.size()
87  );
88 
89  for
90  (
91  int slave=Pstream::firstSlave();
92  slave<=Pstream::lastSlave(comm_);
93  slave++
94  )
95  {
97  (
99  slave,
100  reinterpret_cast<const char*>
101  (
102  &(completeSourceSol[procOffsets_[slave]])
103  ),
104  (procOffsets_[slave + 1]-procOffsets_[slave])*sizeof(Type),
106  comm_
107  );
108  }
109  }
110  else
111  {
113  (
116  reinterpret_cast<char*>(sourceSol.begin()),
117  sourceSol.byteSize(),
119  comm_
120  );
121  }
122  }
123  else
124  {
125  LUBacksubstitute(*this, pivotIndices_, sourceSol);
126  }
127 }
128 
129 
130 // ************************************************************************* //
Foam::LUscalarMatrix::pivotIndices_
labelList pivotIndices_
The pivot indices used in the LU decomposition.
Definition: LUscalarMatrix.H:67
Foam::UPstream::scheduled
@ scheduled
Definition: UPstream.H:67
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::LUscalarMatrix::comm_
const label comm_
Communicator to use.
Definition: LUscalarMatrix.H:61
LUscalarMatrix.H
Foam::Matrix< SquareMatrix< scalar >, scalar >::n
label n() const
Return the number of rows.
Definition: MatrixI.H:56
Foam::LUscalarMatrix::solve
void solve(Field< T > &source) const
Solve the matrix using the LU decomposition with pivoting.
Foam::UIPstream::read
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Read into given buffer from given processor and return the.
Definition: UIPread.C:79
Foam::UOPstream::write
static bool write(const commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Write given buffer to given processor.
Definition: UOPwrite.C:34
Foam::Field< Type >
Foam::UPstream::lastSlave
static int lastSlave(const label communicator=0)
Process index of last slave.
Definition: UPstream.H:428
Foam::UPstream::masterNo
static int masterNo()
Process index of the master.
Definition: UPstream.H:393
Foam::UPstream::firstSlave
static int firstSlave()
Process index of first slave.
Definition: UPstream.H:422
Foam::LUBacksubstitute
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.
Definition: scalarMatricesTemplates.C:120
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:399
Foam::UPstream::msgType
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:452
Foam::Field::subField
SubField< Type > subField
Declare type of subField.
Definition: Field.H:89
Foam::LUscalarMatrix::procOffsets_
labelList procOffsets_
Processor matrix offsets.
Definition: LUscalarMatrix.H:64