parPointFieldDistributor.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) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
29#include "processorPointPatch.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
34
35
36// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37
39(
40 const pointMesh& srcMesh,
41 const bool savePoints,
42 const bool isWriteProc
43)
44:
45 srcMesh_(srcMesh),
46 nOldPoints_(srcMesh.size()),
47 patchMeshPoints_(),
48 tgtMeshRef_(nullptr),
49 distMapRef_(nullptr),
50 patchPointMaps_(),
51 isWriteProc_(isWriteProc)
52{
53 if (savePoints)
54 {
55 saveMeshPoints();
56 }
57}
58
59
61(
62 const pointMesh& srcMesh,
63 const pointMesh& tgtMesh,
64 const mapDistributePolyMesh& distMap,
65 const bool savePoints,
66 const bool isWriteProc
67)
68:
69 srcMesh_(srcMesh),
70 nOldPoints_(srcMesh.size()),
71 patchMeshPoints_(),
72 tgtMeshRef_(tgtMesh),
73 distMapRef_(distMap),
74 patchPointMaps_(),
75 isWriteProc_(isWriteProc)
76{
77 if (savePoints)
78 {
79 saveMeshPoints();
80 }
81}
82
83
84// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85
87{
88 return !patchMeshPoints_.empty();
89}
90
91
93{
94 return !patchPointMaps_.empty();
95}
96
97
99{
100 return (tgtMeshRef_ && distMapRef_);
101}
102
103
105{
106 patchMeshPoints_.clear();
107}
108
110{
111 patchPointMaps_.clear();
112}
113
114
116{
117 const pointBoundaryMesh& patches = srcMesh_.boundary();
118
119 patchMeshPoints_.clear();
120 patchMeshPoints_.resize(patches.size());
121
122 forAll(patches, patchi)
123 {
124 if (!isA<processorPointPatch>(patches[patchi]))
125 {
126 // Copy meshPoints
127 patchMeshPoints_.set
128 (
129 patchi,
130 new labelList(patches[patchi].meshPoints())
131 );
132 }
133 }
134}
135
136
138{
139 if (!tgtMeshRef_ || !distMapRef_)
140 {
142 << "Cannot create maps without target mesh and/or distribution!"
143 << abort(FatalError);
144 }
145
146 const auto& tgtMesh = tgtMeshRef_();
147 const auto& distMap = distMapRef_();
148
149 const auto& newPatches = tgtMesh.boundary();
150 const auto& oldPatches = srcMesh_.boundary();
151
152 patchPointMaps_.clear();
153 patchPointMaps_.resize(oldPatches.size());
154
155 // if (patchPointMaps_.size() != patchMeshPoints_.size())
156 // {
157 // // Warn?
158 // }
159
160 forAll(oldPatches, patchi)
161 {
162 if (!isA<processorPointPatch>(oldPatches[patchi]))
163 {
164 // Create map for patch points only
165 labelList oldToNewSub;
166 labelList oldToNewConstruct;
167
168 // Copy point map
169 patchPointMaps_.set
170 (
171 patchi,
172 new mapDistributeBase(distMap.pointMap())
173 );
174
175 const labelList& oldMeshPoints =
176 (
177 patchMeshPoints_.test(patchi)
178 ? patchMeshPoints_[patchi]
179 : oldPatches[patchi].meshPoints() // <- Questionable!
180 );
181
182 patchPointMaps_[patchi].compactData
183 (
184 oldMeshPoints,
185 newPatches[patchi].meshPoints(),
186 oldToNewSub,
187 oldToNewConstruct,
188 nOldPoints_,
190 );
191 }
192 }
193}
194
195
197{
198 tgtMeshRef_.reset(nullptr);
199 distMapRef_.reset(nullptr);
200
201 // Old maps are now invalid
202 clearPatchPointMaps();
203}
204
205
207(
208 const pointMesh& tgtMesh,
209 const mapDistributePolyMesh& distMap
210)
211{
212 tgtMeshRef_.cref(tgtMesh);
213 distMapRef_.cref(distMap);
214
215 // Old maps are now invalid
216 clearPatchPointMaps();
217}
218
219
221(
222 const IOobjectList& objects,
223 const wordRes& selected
224) const
225{
226 label nTotal = 0;
227
228 nTotal += distributePointFields<scalar>(objects, selected);
229 nTotal += distributePointFields<vector>(objects, selected);
230 nTotal += distributePointFields<symmTensor>(objects, selected);
231 nTotal += distributePointFields<sphericalTensor>(objects, selected);
232 nTotal += distributePointFields<tensor>(objects, selected);
233
234 return nTotal;
235}
236
237
238// ************************************************************************* //
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:330
void clear()
Clear the PtrList. Delete allocated entries and set size to zero.
Definition: PtrListI.H:97
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:556
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
Distributor/redistributor for point fields, uses a two (or three) stage construction.
label distributeAllFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
bool hasPatchPointMaps() const
True if patch maps (per boundary) exist.
void resetTarget()
Clear target mesh / distribution map.
void clearMeshPoints()
Clear out meshPoints (per boundary) for the source mesh.
void clearPatchPointMaps()
Clear out patch maps (per boundary)
void saveMeshPoints()
Create/recreate meshPoints (per boundary) for the source mesh.
static int verbose_
Output verbosity when writing.
void createPatchPointMaps()
Construct per-patch addressing.
bool hasTarget() const
True if a target mesh/distribution map has been attached.
const polyBoundaryMesh & patches
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
List< label > labelList
A List of labels.
Definition: List.H:66
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333