faMeshBoundaryHaloTemplates.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) 2021-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
28#include "faMeshBoundaryHalo.H"
29#include "IndirectList.H"
30#include "Pstream.H"
31
32// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33
34template<class Type>
36(
38 const labelUList& sparseInputLocations,
39 const labelUList& compactOutputMapping
40) const
41{
42 if (!Pstream::parRun())
43 {
44 return; // No-op in serial
45 }
46
47 // Construct data in compact addressing
48 List<Type> compactFld(constructSize(), Zero);
49
50 if (sparseInputLocations.empty())
51 {
52 // Copy in as dense field
53 forAll(fld, i)
54 {
55 compactFld[i] = fld[i];
56 }
57 }
58 else
59 {
60 if (fld.size() != sparseInputLocations.size())
61 {
63 << "Input field size (" << fld.size()
64 << " != sparse ids size ("
65 << sparseInputLocations.size() << ")\n"
66 << exit(FatalError);
67 }
68
69 // Copy in sparse locations
70 forAll(sparseInputLocations, i)
71 {
72 const label idx = sparseInputLocations[i];
73 if (idx != -1)
74 {
75 compactFld[idx] = fld[i];
76 }
77 }
78 }
79
80
81 // Pull all data
82 mapDistributeBase::distribute<Type>(compactFld);
83
84 // Rewrite to output
85 fld = UIndirectList<Type>(compactFld, compactOutputMapping);
86}
87
88
89template<class Type>
91(
93 const labelUList& sparseInputLocations
94) const
95{
96 this->distributeSparse(fld, sparseInputLocations, boundaryToCompact_);
97}
98
99
100template<class Type>
102{
103 this->distributeSparse(fld, inputMeshFaces_, boundaryToCompact_);
104}
105
106
107// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
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
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
void distributeSparse(List< Type > &fld, const labelUList &sparseInputLocations, const labelUList &compactOutputMapping) const
Distribute sparse data.
label constructSize() const noexcept
Constructed data size.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333