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 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
58  (
59  int slave=Pstream::firstSlave();
60  slave<=Pstream::lastSlave(comm_);
61  slave++
62  )
63  {
65  (
66  Pstream::commsTypes::scheduled,
67  slave,
68  reinterpret_cast<char*>
69  (
70  &(X[procOffsets_[slave]])
71  ),
72  (procOffsets_[slave+1]-procOffsets_[slave])*sizeof(Type),
73  Pstream::msgType(),
74  comm_
75  );
76  }
77  }
78  else
79  {
81  (
82  Pstream::commsTypes::scheduled,
83  Pstream::masterNo(),
84  reinterpret_cast<const char*>(x.cdata()),
85  x.byteSize(),
86  Pstream::msgType(),
87  comm_
88  );
89  }
90 
91  if (Pstream::master(comm_))
92  {
93  LUBacksubstitute(*this, pivotIndices_, X);
94 
95  x = SubList<Type>(X, x.size());
96 
97  for
98  (
99  int slave=Pstream::firstSlave();
100  slave<=Pstream::lastSlave(comm_);
101  slave++
102  )
103  {
105  (
106  Pstream::commsTypes::scheduled,
107  slave,
108  reinterpret_cast<const char*>
109  (
110  &(X[procOffsets_[slave]])
111  ),
112  (procOffsets_[slave+1]-procOffsets_[slave])*sizeof(Type),
113  Pstream::msgType(),
114  comm_
115  );
116  }
117  }
118  else
119  {
121  (
122  Pstream::commsTypes::scheduled,
123  Pstream::masterNo(),
124  reinterpret_cast<char*>(x.data()),
125  x.byteSize(),
126  Pstream::msgType(),
127  comm_
128  );
129  }
130  }
131  else
132  {
133  LUBacksubstitute(*this, pivotIndices_, x);
134  }
135 }
136 
137 
138 template<class Type>
140 (
141  const UList<Type>& source
142 ) const
143 {
144  auto tx(tmp<Field<Type>>::New(m()));
145 
146  solve(tx.ref(), source);
147 
148  return tx;
149 }
150 
151 
152 // ************************************************************************* //
SubList.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
LUscalarMatrix.H
solve
CEqn solve()
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::List::resize
void resize(const label newSize)
Adjust allocated size of list.
Definition: ListI.H:139
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::blockMeshTools::read
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:33
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:35