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-2017 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 initialize 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  (
65  Pstream::commsTypes::scheduled,
66  slave,
67  reinterpret_cast<char*>
68  (
69  &(X[procOffsets_[slave]])
70  ),
71  (procOffsets_[slave+1]-procOffsets_[slave])*sizeof(Type),
72  Pstream::msgType(),
73  comm_
74  );
75  }
76  }
77  else
78  {
80  (
81  Pstream::commsTypes::scheduled,
82  Pstream::masterNo(),
83  reinterpret_cast<const char*>(x.begin()),
84  x.byteSize(),
85  Pstream::msgType(),
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  (
109  Pstream::commsTypes::scheduled,
110  slave,
111  reinterpret_cast<const char*>
112  (
113  &(X[procOffsets_[slave]])
114  ),
115  (procOffsets_[slave + 1]-procOffsets_[slave])*sizeof(Type),
116  Pstream::msgType(),
117  comm_
118  );
119  }
120  }
121  else
122  {
124  (
125  Pstream::commsTypes::scheduled,
126  Pstream::masterNo(),
127  reinterpret_cast<char*>(x.begin()),
128  x.byteSize(),
129  Pstream::msgType(),
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 // ************************************************************************* //
void solve(Field< Type > &x, const Field< Type > &source) const
Solve the linear system with the given source.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
Pre-declare related SubField type.
Definition: Field.H:61
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
Pre-declare SubField and related Field type.
Definition: Field.H:57
rhoEqn solve()
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
std::streamsize byteSize() const
Return the binary size in number of characters of the UList.
Definition: UList.C:100
A class for managing temporary objects.
Definition: PtrList.H:53
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.