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-------------------------------------------------------------------------------
11License
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
34template<class Type>
36(
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 (
62 slave,
63 reinterpret_cast<char*>
64 (
65 &(X[procOffsets_[slave]])
66 ),
67 (procOffsets_[slave+1]-procOffsets_[slave])*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 slave : Pstream::subProcs(comm_))
93 {
95 (
97 slave,
98 reinterpret_cast<const char*>
99 (
100 &(X[procOffsets_[slave]])
101 ),
102 (procOffsets_[slave+1]-procOffsets_[slave])*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
128template<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// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
label m() const noexcept
The number of rows.
Definition: MatrixI.H:96
UPstream::rangeType subProcs() const noexcept
Range of sub-processes indices associated with PstreamBuffers.
virtual bool read()
Re-read model coefficients if they have changed.
A List obtained as a section of another List.
Definition: SubList.H:70
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:451
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
virtual bool write()
Write the output fields.
splitCell * master() const
Definition: splitCell.H:113
A class for managing temporary objects.
Definition: tmp.H:65
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
CEqn solve()