nearWallFieldsTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "nearWallFields.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  PtrList<VolField<Type>>& sfields
34 ) const
35 {
37 
38  forAll(fields, i)
39  {
40  const VolField<Type>& field = fields[i];
41 
42  if (fieldMap_.found(field.name()))
43  {
44  const word& sampleFieldName = fieldMap_[field.name()];
45 
46  if (obr_.found(sampleFieldName))
47  {
48  Log << " a field " << sampleFieldName
49  << " already exists on the mesh."
50  << endl;
51  }
52  else
53  {
54  label sz = sfields.size();
55  sfields.setSize(sz+1);
56 
57  sfields.set
58  (
59  sz,
60  new VolField<Type>
61  (
62  IOobject
63  (
64  sampleFieldName,
65  time_.name(),
66  mesh_
67  ),
68  field,
69  calculatedFvPatchScalarField::typeName
70  )
71  );
72 
73  Log << " created " << sfields[sz].name()
74  << " to sample " << field.name() << endl;
75  }
76  }
77  }
78 }
79 
80 
81 template<class Type>
83 (
84  const interpolationCellPoint<Type>& interpolator,
85  VolField<Type>& field
86 ) const
87 {
88  // Construct flat fields for all patch faces to be sampled
89  Field<Type> sampledValues(getPatchDataMapPtr_().constructSize());
90 
91  forAll(cellToWalls_, celli)
92  {
93  const labelList& cData = cellToWalls_[celli];
94 
95  forAll(cData, i)
96  {
97  const point& samplePt = cellToSamples_[celli][i];
98  sampledValues[cData[i]] = interpolator.interpolate(samplePt, celli);
99  }
100  }
101 
102  // Send back sampled values to patch faces
103  getPatchDataMapPtr_().reverseDistribute
104  (
105  getPatchDataMapPtr_().constructSize(),
106  sampledValues
107  );
108 
109  typename VolField<Type>::
110  Boundary& fieldBf = field.boundaryFieldRef();
111 
112  // Pick up data
113  label nPatchFaces = 0;
114  forAllConstIter(labelHashSet, patchSet_, iter)
115  {
116  label patchi = iter.key();
117 
118  fvPatchField<Type>& pfield = fieldBf[patchi];
119 
120  Field<Type> newField(pfield.size());
121  forAll(pfield, i)
122  {
123  newField[i] = sampledValues[nPatchFaces++];
124  }
125 
126  pfield == newField;
127  }
128 }
129 
130 
131 template<class Type>
133 (
134  PtrList<VolField<Type>>& sfields
135 ) const
136 {
137  forAll(sfields, i)
138  {
139  const word& fieldName = reverseFieldMap_[sfields[i].name()];
140  const VolField<Type>& field =
141  obr_.lookupObject<VolField<Type>>(fieldName);
142 
143  // Take over internal and boundary values
144  sfields[i] == field;
145 
146  // Construct interpolation method
147  interpolationCellPoint<Type> interpolator(field);
148 
149  // Override sampled values
150  sampleBoundaryField(interpolator, sfields[i]);
151  }
152 }
153 
154 
155 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:138
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:310
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
const word & name() const
Return const reference to name.
const Time & time_
Reference to time.
const fvMesh & mesh_
Reference to the fvMesh.
void sampleFields(PtrList< VolField< Type >> &) const
void createFields(PtrList< VolField< Type >> &) const
virtual wordList fields() const
Return the list of fields required.
void sampleBoundaryField(const interpolationCellPoint< Type > &interpolator, VolField< Type > &fld) const
Override boundary fields with sampled values.
HashTable< word > fieldMap_
From original field to sampled result.
const objectRegistry & obr_
Reference to the region objectRegistry.
UPtrList< GeoField > fields(const bool strict=false) const
Return the list of fields of type GeoField.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
Given cell centre values and point (vertex) values decompose into tetrahedra and linear interpolate w...
Type interpolate(const cellPointWeight &cpw) const
Interpolate field for the given cellPointWeight.
A class for handling words, derived from string.
Definition: word.H:62
label patchi
#define Log
Report write to Foam::Info if the local log switch is true.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257