LUscalarMatrixTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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 #include "SubField.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  Field<Type>& x,
35  const Field<Type>& source
36 ) const
37 {
38  // If x and source are different initialise x = source
39  if (&x != &source)
40  {
41  x = source;
42  }
43 
44  if (Pstream::parRun())
45  {
46  Field<Type> X(m());
47 
48  if (Pstream::master(comm_))
49  {
50  typename Field<Type>::subField
51  (
52  X,
53  x.size()
54  ) = x;
55 
56  for
57  (
58  int slave=Pstream::firstSlave();
59  slave<=Pstream::lastSlave(comm_);
60  slave++
61  )
62  {
64  (
66  slave,
67  reinterpret_cast<char*>
68  (
69  &(X[procOffsets_[slave]])
70  ),
71  (procOffsets_[slave+1]-procOffsets_[slave])*sizeof(Type),
73  comm_
74  );
75  }
76  }
77  else
78  {
80  (
83  reinterpret_cast<const char*>(x.begin()),
84  x.byteSize(),
86  comm_
87  );
88  }
89 
90  if (Pstream::master(comm_))
91  {
92  LUBacksubstitute(*this, pivotIndices_, X);
93 
94  x = typename Field<Type>::subField
95  (
96  X,
97  x.size()
98  );
99 
100  for
101  (
102  int slave=Pstream::firstSlave();
103  slave<=Pstream::lastSlave(comm_);
104  slave++
105  )
106  {
108  (
110  slave,
111  reinterpret_cast<const char*>
112  (
113  &(X[procOffsets_[slave]])
114  ),
115  (procOffsets_[slave + 1]-procOffsets_[slave])*sizeof(Type),
117  comm_
118  );
119  }
120  }
121  else
122  {
124  (
127  reinterpret_cast<char*>(x.begin()),
128  x.byteSize(),
130  comm_
131  );
132  }
133  }
134  else
135  {
136  LUBacksubstitute(*this, pivotIndices_, x);
137  }
138 }
139 
140 
141 template<class Type>
143 (
144  const Field<Type>& source
145 ) const
146 {
147  tmp<Field<Type>> tx(new Field<Type>(m()));
148  Field<Type>& x = tx.ref();
149 
150  solve(x, source);
151 
152  return tx;
153 }
154 
155 
156 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
SubField< Type > subField
Declare type of subField.
Definition: Field.H:101
void solve(Field< Type > &x, const Field< Type > &source) const
Solve the linear system with the given source.
label m() const
Return the number of rows.
Definition: MatrixI.H:57
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
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
static int masterNo()
Process index of the master.
Definition: UPstream.H:417
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
static int lastSlave(const label communicator=0)
Process index of last slave.
Definition: UPstream.H:452
static int firstSlave()
Process index of first slave.
Definition: UPstream.H:446
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:476
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.
SolverPerformance< Type > solve(fvMatrix< Type > &, const word &)
Solve returning the solution statistics given convergence tolerance.