SlicedGeometricField.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2022-2023 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 \*---------------------------------------------------------------------------*/
28 
29 #include "SlicedGeometricField.H"
30 
31 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
32 
33 template
34 <
35  class Type,
36  template<class> class PatchField,
37  template<class> class SlicedPatchField,
38  class GeoMesh
39 >
40 bool
43 (
44  const Mesh& mesh,
45  const label fieldSize
46 )
47 {
48  label maxAddress(0);
49 
50  if (!mesh.boundary().empty())
51  {
52  const auto& p = mesh.boundary().back();
53  maxAddress = (p.start() + p.size());
54  }
55 
56  // If field size appear to not include internal field
57  return (fieldSize < maxAddress);
58 }
59 
60 
61 template
62 <
63  class Type,
64  template<class> class PatchField,
65  template<class> class SlicedPatchField,
66  class GeoMesh
67 >
71 (
72  const Mesh& mesh,
73  const Field<Type>& completeOrBoundaryField,
74  const bool preserveCouples,
75  const bool preserveProcessorOnly,
76  const bool isBoundaryOnly
77 ) const
78 {
79  typedef typename
80  SlicedPatchField<Type>::processorPatchType
81  processorPatchType;
82 
83  auto tbf = tmp<FieldField<PatchField, Type>>::New(mesh.boundary().size());
84  auto& bf = tbf.ref();
85 
86  forAll(mesh.boundary(), patchi)
87  {
88  const auto& p = mesh.boundary()[patchi];
89 
90  if
91  (
92  preserveCouples && p.coupled()
93  && (!preserveProcessorOnly || isA<processorPatchType>(p))
94  )
95  {
96  // For coupled patched construct the correct patch field type
97  bf.set
98  (
99  patchi,
100  PatchField<Type>::New(p.type(), p, *this)
101  );
102 
103  // Initialize the values on the coupled patch to those of the slice
104  // of the given field.
105  // Note: these will usually be over-ridden by the boundary field
106  // evaluation e.g. in the case of processor and cyclic patches.
107  bf[patchi] = SlicedPatchField<Type>
108  (
109  p,
110  DimensionedField<Type, GeoMesh>::null(),
111  completeOrBoundaryField,
112  isBoundaryOnly
113  );
114  }
115  else
116  {
117  bf.set
118  (
119  patchi,
120  new SlicedPatchField<Type>
121  (
122  p,
123  DimensionedField<Type, GeoMesh>::null(),
124  completeOrBoundaryField,
125  isBoundaryOnly
126  )
127  );
128  }
129  }
130 
131  return tbf;
132 }
133 
134 
135 template
136 <
137  class Type,
138  template<class> class PatchField,
139  template<class> class SlicedPatchField,
140  class GeoMesh
141 >
145 (
146  const Mesh& mesh,
147  const FieldField<PatchField, Type>& bField,
148  const bool preserveCouples
149 ) const
150 {
151  auto tbf = tmp<FieldField<PatchField, Type>>::New(mesh.boundary().size());
152  auto& bf = tbf.ref();
153 
154  forAll(mesh.boundary(), patchi)
155  {
156  const auto& p = mesh.boundary()[patchi];
157 
158  if (preserveCouples && p.coupled())
159  {
160  // For coupled patched construct the correct patch field type
161  bf.set
162  (
163  patchi,
164  PatchField<Type>::New(p.type(), p, *this)
165  );
166 
167  // Assign field
168  bf[patchi] == bField[patchi];
169  }
170  else
171  {
172  // Create unallocated copy of patch field
173  bf.set
174  (
175  patchi,
176  new SlicedPatchField<Type>
177  (
178  p,
179  DimensionedField<Type, GeoMesh>::null(),
180  bField[patchi]
181  )
182  );
183  }
184  }
185 
186  return tbf;
187 }
188 
189 
190 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
191 
192 template
193 <
194  class Type,
195  template<class> class PatchField,
196  template<class> class SlicedPatchField,
197  class GeoMesh
198 >
201 (
202  const IOobject& io,
203  const Mesh& mesh,
204  const dimensionSet& dims,
205  const Field<Type>& completeField,
206  const bool preserveCouples
207 )
208 :
209  GeometricField<Type, PatchField, GeoMesh>
210  (
211  io,
212  mesh,
213  dims,
214  Field<Type>(),
215  // preserveProcessorOnly = false
216  // isBoundaryOnly = false
217  makeBoundary(mesh, completeField, preserveCouples)
218  )
219 {
220  // Set internalField to the slice of the complete field
222  (
223  SubList<Type>(completeField, GeoMesh::size(mesh))
224  );
225 
227 }
228 
229 
230 template
231 <
232  class Type,
233  template<class> class PatchField,
234  template<class> class SlicedPatchField,
235  class GeoMesh
236 >
239 (
240  const IOobject& io,
241  const Mesh& mesh,
242  const dimensionSet& dims,
243  const Field<Type>& completeIField,
244  const Field<Type>& completeBField,
245  const bool preserveCouples,
246  const bool preserveProcessorOnly
247 )
248 :
249  GeometricField<Type, PatchField, GeoMesh>
250  (
251  io,
252  mesh,
253  dims,
254  Field<Type>(),
255  makeBoundary
256  (
257  mesh,
258  completeBField,
259  preserveCouples,
260  preserveProcessorOnly,
261  isBoundaryAddressing(mesh, completeBField.size())
262  )
263  )
264 {
265  // Set internalField to the slice of the complete field
267  (
268  SubList<Type>(completeIField, GeoMesh::size(mesh))
269  );
270 
272 }
273 
274 
275 template
276 <
277  class Type,
278  template<class> class PatchField,
279  template<class> class SlicedPatchField,
280  class GeoMesh
281 >
284 (
285  const IOobject& io,
287  const bool preserveCouples
288 )
289 :
290  GeometricField<Type, PatchField, GeoMesh>
291  (
292  io,
293  gf.mesh(),
294  gf.dimensions(),
295  Field<Type>(),
296  makeBoundary(gf.mesh(), gf.boundaryField(), preserveCouples)
297  )
298 {
299  // Set internalField to the internal field
301 
303 }
304 
305 
306 template
307 <
308  class Type,
309  template<class> class PatchField,
310  template<class> class SlicedPatchField,
311  class GeoMesh
312 >
315 (
317 )
318 :
319  GeometricField<Type, PatchField, GeoMesh>
320  (
321  gf,
322  gf.mesh(),
323  gf.dimensions(),
324  Field<Type>(),
325  // preserveCouples = true
326  makeBoundary(gf.mesh(), gf.boundaryField(), true)
327  )
328 {
329  // Set internalField to the internal field
331 }
332 
333 
334 template
335 <
336  class Type,
337  template<class> class PatchField,
338  template<class> class SlicedPatchField,
339  class GeoMesh
340 >
341 Foam::tmp
342 <
344 >
346 clone() const
347 {
348  return tmp
349  <
351  >::New
352  (
353  *this
354  );
355 }
356 
357 
358 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
359 
360 template
361 <
362  class Type,
363  template<class> class PatchField,
364  template<class> class SlicedPatchField,
365  class GeoMesh
366 >
369 {
370  // Set internalField to nullptr to avoid deletion of underlying field
372 }
373 
374 
375 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
376 
377 template
378 <
379  class Type,
380  template<class> class PatchField,
381  template<class> class SlicedPatchField,
382  class GeoMesh
383 >
386 {
388 }
389 
390 
391 // ************************************************************************* //
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
SlicedGeometricField(const IOobject &, const Mesh &, const dimensionSet &dims, const Field< Type > &completeField, const bool preserveCouples=true)
Construct from components and field to slice.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
dynamicFvMesh & mesh
Generic templated field type.
Definition: Field.H:62
GeoMesh::Mesh Mesh
The mesh type for the DimensionedField.
const Mesh & mesh() const noexcept
Return mesh.
tmp< SlicedGeometricField< Type, PatchField, SlicedPatchField, GeoMesh > > clone() const
Clone.
void correctBoundaryConditions()
Correct boundary field.
void shallowCopy(T *__restrict__ ptr, const label len) noexcept
Copy the pointer and size.
Definition: UListI.H:316
void correctBoundaryConditions()
Correct boundary field.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:42
volScalarField & p
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Specialization of GeometricField which holds slices of given complete fields in a form that they act ...
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172