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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "LUscalarMatrix.H"
30 #include "SubList.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  List<Type>& x,
38  const UList<Type>& source
39 ) const
40 {
41  // If x and source are different initialize x = source
42  if (&x != &source)
43  {
44  x = source;
45  }
46 
47  if (Pstream::parRun())
48  {
49  List<Type> X; // scratch space (on master)
50 
51  if (Pstream::master(comm_))
52  {
53  X.resize(m());
54 
55  SubList<Type>(X, x.size()) = x;
56 
57  for (const int proci : Pstream::subProcs(comm_))
58  {
60  (
62  proci,
63  reinterpret_cast<char*>
64  (
65  &(X[procOffsets_[proci]])
66  ),
67  (procOffsets_[proci+1]-procOffsets_[proci])*sizeof(Type),
69  comm_
70  );
71  }
72  }
73  else
74  {
76  (
79  x.cdata_bytes(),
80  x.byteSize(),
82  comm_
83  );
84  }
85 
86  if (Pstream::master(comm_))
87  {
88  LUBacksubstitute(*this, pivotIndices_, X);
89 
90  x = SubList<Type>(X, x.size());
91 
92  for (const int proci : Pstream::subProcs(comm_))
93  {
95  (
97  proci,
98  reinterpret_cast<const char*>
99  (
100  &(X[procOffsets_[proci]])
101  ),
102  (procOffsets_[proci+1]-procOffsets_[proci])*sizeof(Type),
104  comm_
105  );
106  }
107  }
108  else
109  {
111  (
114  x.data_bytes(),
115  x.byteSize(),
117  comm_
118  );
119  }
120  }
121  else
122  {
123  LUBacksubstitute(*this, pivotIndices_, x);
124  }
125 }
126 
127 
128 template<class Type>
130 (
131  const UList<Type>& source
132 ) const
133 {
134  auto tx(tmp<Field<Type>>::New(m()));
135 
136  solve(tx.ref(), source);
137 
138  return tx;
139 }
140 
141 
142 // ************************************************************************* //
void solve(List< Type > &x, const UList< Type > &source) const
Solve the linear system with the given source.
static label read(const UPstream::commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr)
Read buffer contents from given processor.
Definition: UIPstreamRead.C:35
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1049
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1229
"scheduled" : (MPI_Send, MPI_Recv)
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
Definition: UPstream.H:1059
SolverPerformance< Type > solve(faMatrix< Type > &, const dictionary &solverControls)
Solve returning the solution statistics given convergence tolerance.
label m() const noexcept
The number of rows.
Definition: Matrix.H:248
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1082
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr, const UPstream::sendModes sendMode=UPstream::sendModes::normal)
Write buffer contents to given processor.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:1185
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution in the source.