nearWallFieldsTemplates.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-2016 OpenFOAM Foundation
9  Copyright (C) 2015-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 \*---------------------------------------------------------------------------*/
28 
29 #include "nearWallFields.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
37 ) const
38 {
40 
41  for (const VolFieldType& fld : obr_.csorted<VolFieldType>())
42  {
43  const auto fieldMapIter = fieldMap_.cfind(fld.name());
44 
45  if (fieldMapIter.good())
46  {
47  const word& sampleFldName = fieldMapIter.val();
48 
49  if (obr_.found(sampleFldName))
50  {
52  << " a field named " << sampleFldName
53  << " already exists on the mesh"
54  << endl;
55  }
56  else
57  {
58  IOobject io(fld);
59  io.readOpt(IOobjectOption::NO_READ);
60  io.writeOpt(IOobjectOption::NO_WRITE);
61  io.rename(sampleFldName);
62 
63  // Override bc to be calculated
64  const label newFieldi = sflds.size();
65  sflds.resize(newFieldi+1);
66 
67  sflds.set
68  (
69  newFieldi,
70  new VolFieldType
71  (
72  io,
73  fld,
74  patchIDs_,
76  )
77  );
78 
79  Log << " created " << io.name()
80  << " to sample " << fld.name() << endl;
81  }
82  }
83  }
84 }
85 
86 
87 template<class Type>
89 (
90  const interpolationCellPoint<Type>& interpolator,
91  GeometricField<Type, fvPatchField, volMesh>& fld
92 ) const
93 {
94  // Construct flat fields for all patch faces to be sampled
95  Field<Type> sampledValues(getPatchDataMapPtr_().constructSize());
96 
97  forAll(cellToWalls_, celli)
98  {
99  const labelList& cData = cellToWalls_[celli];
100 
101  forAll(cData, i)
102  {
103  const point& samplePt = cellToSamples_[celli][i];
104  sampledValues[cData[i]] = interpolator.interpolate(samplePt, celli);
105  }
106  }
107 
108  // Send back sampled values to patch faces
109  getPatchDataMapPtr_().reverseDistribute
110  (
111  getPatchDataMapPtr_().constructSize(),
112  sampledValues
113  );
114 
115  typename GeometricField<Type, fvPatchField, volMesh>::
116  Boundary& fldBf = fld.boundaryFieldRef();
117 
118  // Pick up data
119  label nPatchFaces = 0;
120  for (const label patchi : patchIDs_)
121  {
122  fvPatchField<Type>& pfld = fldBf[patchi];
123 
124  Field<Type> newFld(pfld.size());
125  forAll(pfld, i)
126  {
127  newFld[i] = sampledValues[nPatchFaces++];
128  }
129 
130  pfld == newFld;
131  }
132 }
133 
134 
135 template<class Type>
137 (
139 ) const
140 {
141  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
142 
143  forAll(sflds, i)
144  {
145  const word& fldName = reverseFieldMap_[sflds[i].name()];
146  const VolFieldType& fld = obr_.lookupObject<VolFieldType>(fldName);
147 
148  // Take over internal and boundary values
149  sflds[i] == fld;
150 
151  // Construct interpolation method
152  interpolationCellPoint<Type> interpolator(fld);
153 
154  // Override sampled values
155  sampleBoundaryField(interpolator, sflds[i]);
156  }
157 }
158 
159 
160 // ************************************************************************* //
UPtrList< const Type > csorted() const
Return sorted list of objects with a class satisfying isA<Type> or isType<Type> (with Strict) ...
labelList patchIDs_
Patches to sample.
void sampleBoundaryField(const interpolationCellPoint< Type > &interpolator, GeometricField< Type, fvPatchField, volMesh > &fld) const
Override boundary fields with sampled values.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
Ignore writing from objectRegistry::writeObject()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
A class for handling words, derived from Foam::string.
Definition: word.H:63
HashTable< word > fieldMap_
From original field to sampled result.
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))
Given cell centre values and point (vertex) values decompose into tetrahedra and linear interpolate w...
vector point
Point is a vector.
Definition: point.H:37
#define WarningInFunction
Report a warning using Foam::Warning.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
const objectRegistry & obr_
Reference to the region objectRegistry.
Nothing to be read.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
Definition: fvPatchField.H:204
#define Log
Definition: PDRblock.C:28
bool found(const word &name, bool recursive=false) const
Same as contains()
void createFields(PtrList< GeometricField< Type, fvPatchField, volMesh >> &) const
List< label > labelList
A List of labels.
Definition: List.H:62
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
void sampleFields(PtrList< GeometricField< Type, fvPatchField, volMesh >> &) const
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172