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 slave : Pstream::subProcs(comm_))
58  {
60  (
61  Pstream::commsTypes::scheduled,
62  slave,
63  reinterpret_cast<char*>
64  (
65  &(X[procOffsets_[slave]])
66  ),
67  (procOffsets_[slave+1]-procOffsets_[slave])*sizeof(Type),
68  Pstream::msgType(),
69  comm_
70  );
71  }
72  }
73  else
74  {
76  (
77  Pstream::commsTypes::scheduled,
78  Pstream::masterNo(),
79  x.cdata_bytes(),
80  x.byteSize(),
81  Pstream::msgType(),
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 slave : Pstream::subProcs(comm_))
93  {
95  (
96  Pstream::commsTypes::scheduled,
97  slave,
98  reinterpret_cast<const char*>
99  (
100  &(X[procOffsets_[slave]])
101  ),
102  (procOffsets_[slave+1]-procOffsets_[slave])*sizeof(Type),
103  Pstream::msgType(),
104  comm_
105  );
106  }
107  }
108  else
109  {
111  (
112  Pstream::commsTypes::scheduled,
113  Pstream::masterNo(),
114  x.data_bytes(),
115  x.byteSize(),
116  Pstream::msgType(),
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 // ************************************************************************* //
SubList.H
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
LUscalarMatrix.H
solve
CEqn solve()
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::LUscalarMatrix::solve
void solve(List< Type > &x, const UList< Type > &source) const
Solve the linear system with the given source.
Definition: LUscalarMatrixTemplates.C:36
Foam::LUBacksubstitute
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
Definition: scalarMatricesTemplates.C:120
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::List< Type >
Foam::UList< Type >
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36