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 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 "UIndirectList.H"
30 #include "Pstream.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  List<Type>& fld,
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 
89 template<class Type>
91 (
92  List<Type>& fld,
93  const labelUList& sparseInputLocations
94 ) const
95 {
96  this->distributeSparse(fld, sparseInputLocations, boundaryToCompact_);
97 }
98 
99 
100 template<class Type>
102 {
103  this->distributeSparse(fld, inputMeshFaces_, boundaryToCompact_);
104 }
105 
106 
107 // ************************************************************************* //
UIndirectList.H
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::UList::empty
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
Foam::FatalError
error FatalError
Pstream.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::List< Type >
Foam::faMeshBoundaryHalo::distributeSparse
void distributeSparse(List< Type > &fld, const labelUList &sparseInputLocations, const labelUList &compactOutputMapping) const
Distribute sparse data.
Definition: faMeshBoundaryHaloTemplates.C:36
Foam::UList< label >
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
faMeshBoundaryHalo.H