distributedWeightedFvPatchFieldMapper.H
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) 2015-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 Class
28  Foam::distributedWeightedFvPatchFieldMapper
29 
30 Description
31  FieldMapper with weighted mapping from (optionally remote) quantities.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef distributedWeightedFvPatchFieldMapper_H
36 #define distributedWeightedFvPatchFieldMapper_H
37 
38 #include "fvPatchFieldMapper.H"
39 #include "mapDistributeBase.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class distributedWeightedFvPatchFieldMapper Declaration
48 \*---------------------------------------------------------------------------*/
49 
51 :
52  public fvPatchFieldMapper
53 {
54  const mapDistributeBase* distMapPtr_;
55 
56  const labelListList& addressing_;
57 
58  const scalarListList& weights_;
59 
60  bool hasUnmapped_;
61 
62 public:
63 
64  // Constructors
65 
66  //- Construct given addressing
68  (
69  const label singlePatchProc, // global consistent
70  const label comm, // only on processors with
71  // patch faces
72  const mapDistributeBase* distMapPtr, // ,,
74  const scalarListList& weights
75  )
76  :
77  distMapPtr_(distMapPtr),
78  addressing_(addressing),
79  weights_(weights),
80  hasUnmapped_(false)
81  {
82  for (const labelList& addr : addressing)
83  {
84  if (addr.empty())
85  {
86  hasUnmapped_ = true;
87  break;
88  }
89  }
90 
91 
92  // singlePatchProc : >= 0
93  // - comm not relevant
94  // - distMap should not be set
95  // singlePatchProc : -1
96  // - if (comm != -1) we need a distMap
97  bool error = false;
98  if (singlePatchProc >= 0)
99  {
100  error = distMapPtr_;
101  }
102  else
103  {
104  // Need map (unless I don't have communicator)
105  if (comm >= 0)
106  {
107  error = !distMapPtr_;
108  }
109  else
110  {
111  error = distMapPtr_;
112  }
113  }
114  if (error)
115  {
117  << "Supply a mapDistributeBase if and only if "
118  << "singlePatchProc is -1"
119  << " singlePatchProc:" << singlePatchProc
120  << " distMapPtr_:" << (distMapPtr_ != nullptr)
121  << exit(FatalError);
122  }
123  }
124 
125  //- Destructor
126  virtual ~distributedWeightedFvPatchFieldMapper() = default;
127 
129  // Member Functions
130 
131  virtual label size() const
132  {
133  if (distributed())
134  {
135  return distributeMap().constructSize();
136  }
137  else
138  {
139  return addressing().size();
140  }
141  }
142 
143  virtual bool direct() const
144  {
145  return false;
146  }
147 
148  virtual bool distributed() const
149  {
150  return distMapPtr_;
151  }
152 
153  virtual const mapDistributeBase& distributeMap() const
154  {
155  if (!distMapPtr_)
156  {
158  << "Cannot ask for distributeMap on a non-distributed"
159  << " mapper" << exit(FatalError);
160  }
161  return *distMapPtr_;
162  }
163 
164  virtual bool hasUnmapped() const
165  {
166  return hasUnmapped_;
167  }
168 
169  virtual const labelListList& addressing() const
170  {
171  return addressing_;
172  }
173 
174  virtual const scalarListList& weights() const
175  {
176  return weights_;
177  }
178 
179 };
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 } // End namespace Foam
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #endif
188 
189 // ************************************************************************* //
virtual bool direct() const
Is it a direct (non-interpolating) mapper?
virtual const scalarListList & weights() const
Return the interpolation weights.
virtual bool distributed() const
Does the mapper have remote contributions?
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
FieldMapper with weighted mapping from (optionally remote) quantities.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
label constructSize() const noexcept
Constructed data size.
virtual label size() const
The size of the mapper.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:70
distributedWeightedFvPatchFieldMapper(const label singlePatchProc, const label comm, const mapDistributeBase *distMapPtr, const labelListList &addressing, const scalarListList &weights)
Construct given addressing.
A FieldMapper for finite-volume patch fields.
virtual const mapDistributeBase & distributeMap() const
Return the distribution map.
virtual ~distributedWeightedFvPatchFieldMapper()=default
Destructor.
Class containing processor-to-processor mapping information.
virtual const labelListList & addressing() const
Return the interpolation addressing.
Namespace for OpenFOAM.