fvMeshSubsetProxy.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2021 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::fvMeshSubsetProxy
29 
30 Description
31  Simple proxy for holding a mesh, or mesh-subset.
32  The subMeshes are currently limited to cellSet or cellZone definitions.
33 
34 SourceFiles
35  fvMeshSubsetProxy.C
36  fvMeshSubsetProxyTemplates.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef fvMeshSubsetProxy_H
41 #define fvMeshSubsetProxy_H
42 
43 #include "wordRes.H"
44 #include "fvMeshSubset.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class fvMeshSubsetProxy Declaration
54 \*---------------------------------------------------------------------------*/
55 
57 {
58 public:
59 
60  // Data Types
61 
62  //- Internal bookkeeping for subset type
63  enum subsetType
64  {
65  NONE,
66  SET,
67  ZONE,
68  ZONES
69  };
70 
71 
72 private:
73 
74  // Private Data
75 
76  //- Reference to mesh
77  fvMesh& baseMesh_;
78 
79  //- Subsetting engine
80  fvMeshSubset subsetter_;
81 
82  //- Patch ID for exposed internal faces
83  label exposedPatchId_;
84 
85  //- The subsetting type
86  subsetType type_;
87 
88  //- Name of the cellSet/cellZone (or empty)
89  word name_;
90 
91  //- Selection for multiple cell zones
92  wordRes names_;
93 
94  //- The (cached) cell selection
95  bitSet selectedCells_;
96 
97 
98  // Private Member Functions
99 
100  //- Clear, set to NONE
101  void clearOut();
102 
103  //- No copy construct
104  fvMeshSubsetProxy(const fvMeshSubsetProxy&) = delete;
105 
106  //- No copy assignment
107  void operator=(const fvMeshSubsetProxy&) = delete;
108 
109 
110 public:
111 
112  // Constructors
113 
114  //- Construct a pass-through proxy. No correct() invoked or required.
115  explicit fvMeshSubsetProxy(fvMesh& baseMesh);
116 
117  //- Construct from components
119  (
120  fvMesh& baseMesh,
121  const subsetType type,
122  const word& selectionName,
123  label exposedPatchId = -1
124  );
125 
126  //- Construct from components. The subsetType is ZONES.
128  (
129  fvMesh& baseMesh,
130  const wordRes& zoneNames,
131  label exposedPatchId = -1
132  );
133 
134  //- Construct from components. The subsetType is ZONES.
136  (
137  fvMesh& baseMesh,
138  wordRes&& zoneNames,
139  label exposedPatchId = -1
140  );
141 
142 
143  // Member Functions
144 
145  // Access
146 
147  //- The entire base mesh
148  const fvMesh& baseMesh() const noexcept
149  {
150  return baseMesh_;
151  }
152 
153  //- The mesh subsetter
154  const fvMeshSubset& subsetter() const noexcept
155  {
156  return subsetter_;
157  }
158 
159  //- The mesh subsetter
160  fvMeshSubset& subsetter() noexcept
161  {
162  return subsetter_;
163  }
164 
165  //- True if sub-mesh should be used
166  bool useSubMesh() const noexcept
167  {
168  return type_ != subsetType::NONE;
169  }
170 
171  //- Access either base-mesh or sub-mesh
172  inline const fvMesh& mesh() const
173  {
174  if (useSubMesh())
175  {
176  return subsetter_.subMesh();
177  }
178 
179  return baseMesh_;
180  }
181 
182  //- The associated (set or zone) name if any.
183  const word& name() const noexcept
184  {
185  return name_;
186  }
187 
188  //- The current cell selection, when subsetting is active
189  const bitSet& selectedCells() const noexcept
190  {
191  return selectedCells_;
192  }
193 
194 
195  // Edit
196 
197  //- Define the zones selection, subset the mesh accordingly
198  void resetZones(const wordRes& zoneNames);
199 
200  //- Update of mesh subset.
201  // Return true if the subset changed from previous call.
202  bool correct(bool verbose = false);
203 
204  //- Read mesh. Correct on topo-change
206 
207 
208  // Fields
209 
210  //- Construct volField (with zeroGradient) from an internal field
211  template<class Type>
214  (
216  );
217 
218  //- Convert an internal field to a volume field (with zeroGradient)
219  template<class Type>
222  (
223  const fvMeshSubset& subsetter,
225  );
226 
227  //- Convert an internal field to a volume field (with zeroGradient)
228  // Currently no proper memory reuse
229  template<class Type>
232  (
233  const fvMeshSubset& subsetter,
235  );
236 
237  //- Wrapper for field or the subsetted field.
238  // Pass through or forward to fvMeshSubset::interpolate()
239  template<class GeoField>
241  (
242  const fvMeshSubset& subsetter,
243  const GeoField& fld
244  );
245 
246  //- Wrapper for field or the subsetted field.
247  // Pass through or forward to fvMeshSubset::interpolate()
248  template<class GeoField>
250  (
251  const fvMeshSubset& subsetter,
252  const tmp<GeoField>& fld
253  );
254 
255 
256  // Fields
257 
258  //- Convert an internal field to a volume field (with zeroGradient)
259  template<class Type>
262  (
264  ) const;
265 
266  //- Convert an internal field to a volume field (with zeroGradient)
267  // Currently no proper memory reuse
268  template<class Type>
271  (
273  ) const;
274 
275 
276  //- Wrapper for field or the subsetted field.
277  // Pass through or forward to fvMeshSubset::interpolate()
278  template<class GeoField>
279  tmp<GeoField> interpolate(const GeoField& fld) const;
280 
281  //- Wrapper for field or the subsetted field.
282  // Pass through or forward to fvMeshSubset::interpolate()
283  template<class GeoField>
285 };
286 
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 } // End namespace Foam
291 
292 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
293 
294 #ifdef NoRepository
296 #endif
297 
298 #endif
299 
300 // ************************************************************************* //
wordRes.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::fvMeshSubsetProxy::subsetter
const fvMeshSubset & subsetter() const noexcept
The mesh subsetter.
Definition: fvMeshSubsetProxy.H:153
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::fvMeshSubset
Given the original mesh and the list of selected cells, it creates the mesh consisting only of the de...
Definition: fvMeshSubset.H:73
fvMeshSubset.H
Foam::fvMeshSubsetProxy::mesh
const fvMesh & mesh() const
Access either base-mesh or sub-mesh.
Definition: fvMeshSubsetProxy.H:171
zeroGradientFvPatchField.H
Foam::fvMeshSubsetProxy::subsetType
subsetType
Internal bookkeeping for subset type.
Definition: fvMeshSubsetProxy.H:62
Foam::fvMeshSubsetProxy::interpolateInternal
static tmp< GeometricField< Type, fvPatchField, volMesh > > interpolateInternal(const fvMeshSubset &subsetter, const DimensionedField< Type, volMesh > &df)
Convert an internal field to a volume field (with zeroGradient)
Foam::fvMeshSubsetProxy::interpolate
static tmp< GeoField > interpolate(const fvMeshSubset &subsetter, const GeoField &fld)
Wrapper for field or the subsetted field.
Foam::fvMeshSubsetProxy::selectedCells
const bitSet & selectedCells() const noexcept
The current cell selection, when subsetting is active.
Definition: fvMeshSubsetProxy.H:188
Foam::fvMeshSubset::subMesh
const fvMesh & subMesh() const
Return reference to subset mesh.
Definition: fvMeshSubsetI.H:48
Foam::fvMeshSubsetProxy::subsetter
fvMeshSubset & subsetter() noexcept
The mesh subsetter.
Definition: fvMeshSubsetProxy.H:159
Foam::fvMeshSubsetProxy::zeroGradientField
static tmp< GeometricField< Type, fvPatchField, volMesh > > zeroGradientField(const DimensionedField< Type, volMesh > &df)
Construct volField (with zeroGradient) from an internal field.
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::fvMeshSubsetProxy::ZONES
Subset with multiple cellZones.
Definition: fvMeshSubsetProxy.H:67
Foam::fvMeshSubsetProxy::useSubMesh
bool useSubMesh() const noexcept
True if sub-mesh should be used.
Definition: fvMeshSubsetProxy.H:165
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fvMeshSubsetProxy
Simple proxy for holding a mesh, or mesh-subset. The subMeshes are currently limited to cellSet or ce...
Definition: fvMeshSubsetProxy.H:55
Foam::polyMesh::readUpdateState
readUpdateState
Enumeration defining the state of the mesh after a read update.
Definition: polyMesh.H:90
Foam::fvMeshSubsetProxy::ZONE
Subset with a cellZone.
Definition: fvMeshSubsetProxy.H:66
Foam::fvMeshSubsetProxy::name
const word & name() const noexcept
The associated (set or zone) name if any.
Definition: fvMeshSubsetProxy.H:182
Foam::fvMeshSubsetProxy::resetZones
void resetZones(const wordRes &zoneNames)
Define the zones selection, subset the mesh accordingly.
Definition: fvMeshSubsetProxy.C:130
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Foam::fvMeshSubsetProxy::NONE
No subset.
Definition: fvMeshSubsetProxy.H:64
Foam::fvMeshSubsetProxy::SET
Subset with a cellSet.
Definition: fvMeshSubsetProxy.H:65
Foam::fvMeshSubsetProxy::correct
bool correct(bool verbose=false)
Update of mesh subset.
Definition: fvMeshSubsetProxy.C:143
fvMeshSubsetProxyTemplates.C
Foam::fvMeshSubsetProxy::readUpdate
polyMesh::readUpdateState readUpdate()
Read mesh. Correct on topo-change.
Definition: fvMeshSubsetProxy.C:207
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::fvMeshSubsetProxy::baseMesh
const fvMesh & baseMesh() const noexcept
The entire base mesh.
Definition: fvMeshSubsetProxy.H:147