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 -------------------------------------------------------------------------------
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 "SlicedGeometricField.H"
29 #include "processorFvPatch.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 >
43 (
44  const Mesh& mesh,
45  const Field<Type>& completeField,
46  const bool preserveCouples,
47  const bool preserveProcessorOnly
48 )
49 {
50  tmp<FieldField<PatchField, Type>> tbf
51  (
52  new FieldField<PatchField, Type>(mesh.boundary().size())
53  );
54  FieldField<PatchField, Type>& bf = tbf.ref();
55 
56  forAll(mesh.boundary(), patchi)
57  {
58  if
59  (
60  preserveCouples
61  && mesh.boundary()[patchi].coupled()
62  && (
63  !preserveProcessorOnly
64  || isA<processorFvPatch>(mesh.boundary()[patchi])
65  )
66  )
67  {
68  // For coupled patched construct the correct patch field type
69  bf.set
70  (
71  patchi,
73  (
74  mesh.boundary()[patchi].type(),
75  mesh.boundary()[patchi],
76  *this
77  )
78  );
79 
80  // Initialize the values on the coupled patch to those of the slice
81  // of the given field.
82  // Note: these will usually be over-ridden by the boundary field
83  // evaluation e.g. in the case of processor and cyclic patches.
84  bf[patchi] = SlicedPatchField<Type>
85  (
86  mesh.boundary()[patchi],
87  DimensionedField<Type, GeoMesh>::null(),
88  completeField
89  );
90  }
91  else
92  {
93  bf.set
94  (
95  patchi,
96  new SlicedPatchField<Type>
97  (
98  mesh.boundary()[patchi],
99  DimensionedField<Type, GeoMesh>::null(),
100  completeField
101  )
102  );
103  }
104  }
105 
106  return tbf;
107 }
108 
109 
110 template
111 <
112  class Type,
113  template<class> class PatchField,
114  template<class> class SlicedPatchField,
115  class GeoMesh
116 >
120 (
121  const Mesh& mesh,
122  const FieldField<PatchField, Type>& bField,
123  const bool preserveCouples
124 )
125 {
126  tmp<FieldField<PatchField, Type>> tbf
127  (
128  new FieldField<PatchField, Type>(mesh.boundary().size())
129  );
130  FieldField<PatchField, Type>& bf = tbf.ref();
131 
132  forAll(mesh.boundary(), patchi)
133  {
134  if (preserveCouples && mesh.boundary()[patchi].coupled())
135  {
136  // For coupled patched construct the correct patch field type
137  bf.set
138  (
139  patchi,
141  (
142  mesh.boundary()[patchi].type(),
143  mesh.boundary()[patchi],
144  *this
145  )
146  );
147 
148  // Assign field
149  bf[patchi] == bField[patchi];
150  }
151  else
152  {
153  // Create unallocated copy of patch field
154  bf.set
155  (
156  patchi,
157  new SlicedPatchField<Type>
158  (
159  mesh.boundary()[patchi],
160  DimensionedField<Type, GeoMesh>::null()
161  )
162  );
163  bf[patchi].UList<Type>::shallowCopy(bField[patchi]);
164  }
165  }
166 
167  return tbf;
168 }
169 
170 
171 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
172 
173 template
174 <
175  class Type,
176  template<class> class PatchField,
177  template<class> class SlicedPatchField,
178  class GeoMesh
179 >
182 (
183  const IOobject& io,
184  const Mesh& mesh,
185  const dimensionSet& ds,
186  const Field<Type>& iField
187 )
188 :
190  (
191  io,
192  mesh,
193  ds,
194  Field<Type>()
195  )
196 {
197  // Set the internalField to the slice of the complete field
199  (
200  typename Field<Type>::subField(iField, GeoMesh::size(mesh))
201  );
202 }
203 
204 
205 template
206 <
207  class Type,
208  template<class> class PatchField,
209  template<class> class SlicedPatchField,
210  class GeoMesh
211 >
214 (
215  const IOobject& io,
216  const Mesh& mesh,
217  const dimensionSet& ds,
218  const Field<Type>& completeField,
219  const bool preserveCouples
220 )
221 :
223  (
224  io,
225  mesh,
226  ds,
227  Field<Type>(),
228  slicedBoundaryField(mesh, completeField, preserveCouples)
229  )
230 {
231  // Set the internalField to the slice of the complete field
233  (
234  typename Field<Type>::subField(completeField, GeoMesh::size(mesh))
235  );
236 
238 }
239 
240 
241 template
242 <
243  class Type,
244  template<class> class PatchField,
245  template<class> class SlicedPatchField,
246  class GeoMesh
247 >
250 (
251  const IOobject& io,
252  const Mesh& mesh,
253  const dimensionSet& ds,
254  const Field<Type>& completeIField,
255  const Field<Type>& completeBField,
256  const bool preserveCouples,
257  const bool preserveProcessorOnly
258 )
259 :
261  (
262  io,
263  mesh,
264  ds,
265  Field<Type>(),
266  slicedBoundaryField
267  (
268  mesh,
269  completeBField,
270  preserveCouples,
271  preserveProcessorOnly
272  )
273  )
274 {
275  // Set the internalField to the slice of the complete field
277  (
278  typename Field<Type>::subField(completeIField, GeoMesh::size(mesh))
279  );
280 
282 }
283 
284 
285 template
286 <
287  class Type,
288  template<class> class PatchField,
289  template<class> class SlicedPatchField,
290  class GeoMesh
291 >
294 (
295  const IOobject& io,
297  const bool preserveCouples
298 )
299 :
301  (
302  io,
303  gf.mesh(),
304  gf.dimensions(),
305  Field<Type>(),
306  slicedBoundaryField(gf.mesh(), gf.boundaryField(), preserveCouples)
307  )
308 {
309  // Set the internalField to the supplied internal field
311 
313 }
314 
315 
316 template
317 <
318  class Type,
319  template<class> class PatchField,
320  template<class> class SlicedPatchField,
321  class GeoMesh
322 >
325 (
327 )
328 :
330  (
331  gf,
332  gf.mesh(),
333  gf.dimensions(),
334  Field<Type>(),
335  slicedBoundaryField(gf.mesh(), gf.boundaryField(), true)
336  )
337 {
338  // Set the internalField to the supplied internal field
339  UList<Type>::shallowCopy(gf.primitiveField());
340 }
341 
342 
343 template
344 <
345  class Type,
346  template<class> class PatchField,
347  template<class> class SlicedPatchField,
348  class GeoMesh
349 >
350 Foam::tmp
351 <
353 >
355 clone() const
356 {
357  return tmp
358  <
360  >
361  (
363  (
364  *this
365  )
366  );
367 }
368 
369 
370 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
371 
372 template
373 <
374  class Type,
375  template<class> class PatchField,
376  template<class> class SlicedPatchField,
377  class GeoMesh
378 >
381 {
382  // Set the internalField storage pointer to nullptr before its destruction
383  // to protect the field it a slice of.
385 }
386 
387 
388 template
389 <
390  class Type,
391  template<class> class PatchField,
392  template<class> class SlicedPatchField,
393  class GeoMesh
394 >
397 {
398  // Set the internalField storage pointer to nullptr before its destruction
399  // to protect the field it a slice of.
401 }
402 
403 
404 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
405 
406 template
407 <
408  class Type,
409  template<class> class PatchField,
410  template<class> class SlicedPatchField,
411  class GeoMesh
412 >
415 {
417 }
418 
419 
420 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
processorFvPatch.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
SlicedGeometricField.H
Foam::GeometricField::primitiveField
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Definition: GeometricFieldI.H:53
Foam::SlicedGeometricField::clone
tmp< SlicedGeometricField< Type, PatchField, SlicedPatchField, GeoMesh > > clone() const
Clone.
Foam::SlicedGeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: SlicedGeometricField.C:414
Foam::dimensionSet
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:108
Foam::SlicedGeometricField::SlicedGeometricField
SlicedGeometricField(const IOobject &, const Mesh &, const dimensionSet &, const Field< Type > &completeField, const bool preserveCouples=true)
Construct from components and field to slice.
Definition: SlicedGeometricField.C:214
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::SubField
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition: Field.H:64
correctBoundaryConditions
cellMask correctBoundaryConditions()
Foam::DimensionedField::Mesh
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
Definition: DimensionedField.H:86
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::SlicedGeometricField::Internal::Internal
Internal(const IOobject &, const Mesh &, const dimensionSet &, const Field< Type > &iField)
Construct from components and field to slice.
Definition: SlicedGeometricField.C:182
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::GeoMesh
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:48
Foam::SlicedGeometricField::Mesh
GeoMesh::Mesh Mesh
Definition: SlicedGeometricField.H:71
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::SlicedGeometricField
Specialization of GeometricField which holds slices of given complete fields in a form that they act ...
Definition: slicedSurfaceFieldsFwd.H:58
Foam::SlicedGeometricField::~SlicedGeometricField
~SlicedGeometricField()
Destructor.
Definition: SlicedGeometricField.C:380
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::SlicedGeometricField::Internal::~Internal
~Internal()
Destructor.
Definition: SlicedGeometricField.C:396
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54