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 
37  if (Pstream::master(comm_))
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 
79  if (Pstream::master(comm_))
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 // ************************************************************************* //
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:380
std::streamsize byteSize() const
Return the binary size in number of characters of the UList.
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.
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
label n() const
Return the number of rows.
void size(const label)
Override size to be inconsistent with allocated storage.
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:100
iterator begin()
Return an iterator to begin traversing the UList.
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:451
Pre-declare SubField and related Field type.
Definition: Field.H:57
void solve(Field< T > &source) const
Solve the matrix using the LU decomposition with pivoting.
SubField< Type > subField
Declare type of subField.
Definition: Field.H:89
static int masterNo()
Process index of the master.
Definition: UPstream.H:392
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:398
static int firstSlave()
Process index of first slave.
Definition: UPstream.H:421
static int lastSlave(const label communicator=0)
Process index of last slave.
Definition: UPstream.H:427