dynamicRefineFvMeshTemplates.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) 2018-2019 OpenCFD Ltd.
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 "surfaceFields.H"
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class T>
34 (
35  const labelList& faceMap,
37 )
38 {
40 
41  //- Make flat field for ease of looping
42  Field<T> tsFld(this->nFaces(), Zero);
43  SubField<T>(tsFld, this->nInternalFaces()) = sFld.internalField();
44 
45  const typename GeoField::Boundary& bFld = sFld.boundaryField();
46  forAll(bFld, patchi)
47  {
48  label facei = this->boundaryMesh()[patchi].start();
49  for (const T& val : bFld[patchi])
50  {
51  tsFld[facei++] = val;
52  }
53  }
54 
55  const labelUList& owner = this->faceOwner();
56  const labelUList& neighbour = this->faceNeighbour();
57  const cellList& cells = this->cells();
58 
59  for (label facei = 0; facei < nInternalFaces(); facei++)
60  {
61  label oldFacei = faceMap[facei];
62 
63  // Map surface field on newly generated faces by obtaining the
64  // hull of the outside faces
65  if (oldFacei == -1)
66  {
67  // Loop over all owner/neighbour cell faces
68  // and find already mapped ones (master-faces):
69  T tmpValue(pTraits<T>::zero);
70  label counter = 0;
71 
72  const cell& ownFaces = cells[owner[facei]];
73  for (auto ownFacei : ownFaces)
74  {
75  if (faceMap[ownFacei] != -1)
76  {
77  tmpValue += tsFld[ownFacei];
78  counter++;
79  }
80  }
81 
82  const cell& neiFaces = cells[neighbour[facei]];
83  for (auto neiFacei : neiFaces)
84  {
85  if (faceMap[neiFacei] != -1)
86  {
87  tmpValue += tsFld[neiFacei];
88  counter++;
89  }
90  }
91 
92  if (counter > 0)
93  {
94  sFld[facei] = tmpValue/counter;
95  }
96  }
97  }
98 }
99 
100 
101 template<class T>
103 (
104  const labelList& faceMap
105 )
106 {
108  HashTable<GeoField*> sFlds(this->objectRegistry::lookupClass<GeoField>());
109 
110  forAllIters(sFlds, iter)
111  {
112  //if (mapSurfaceFields_.found(iter.key()))
113  {
114  DebugInfo
115  << "dynamicRefineFvMesh::mapNewInternalFaces():"
116  << " Mapping new internal faces by interpolation on "
117  << iter.key()<< endl;
118 
119  GeoField& sFld = *iter();
120 
121  if (sFld.is_oriented())
122  {
123  WarningInFunction << "Ignoring mapping oriented field "
124  << sFld.name() << " since of type " << sFld.type()
125  << endl;
126  }
127  else
128  {
129  mapNewInternalFaces(faceMap, sFld);
130  }
131  }
132  }
133 }
134 
135 template<class T>
137 (
138  const surfaceVectorField& Sf,
139  const surfaceScalarField& magSf,
140  const labelList& faceMap
141 )
142 {
143  typedef GeometricField<T, fvsPatchField, surfaceMesh> GeoField;
144  HashTable<GeoField*> sFlds(this->objectRegistry::lookupClass<GeoField>());
145 
146  forAllIters(sFlds, iter)
147  {
148  //if (mapSurfaceFields_.found(iter.key()))
149  {
150  DebugInfo
151  << "dynamicRefineFvMesh::mapNewInternalFaces():"
152  << " Mapping new internal faces by interpolation on "
153  << iter.key() << endl;
154 
155  GeoField& sFld = *iter();
156 
157  if (sFld.is_oriented())
158  {
159  DebugInfo
160  << "dynamicRefineFvMesh::mapNewInternalFaces(): "
161  << "Converting oriented field " << iter.key()
162  << " to intensive field and mapping" << endl;
163 
164  // Assume any oriented field is face area weighted (i.e. a flux)
165  // Convert to intensive (& oriented) before mapping. Untested.
166 
167  typedef GeometricField
168  <
170  fvsPatchField,
171  surfaceMesh
172  > NormalGeoField;
173 
174  // Convert to intensive and non oriented
175  NormalGeoField fFld(sFld*Sf/Foam::sqr(magSf));
176 
177  // Interpolate
178  mapNewInternalFaces(faceMap, fFld);
179 
180  // Convert back to extensive and oriented
181  sFld = (fFld & Sf);
182  }
183  else
184  {
185  mapNewInternalFaces(faceMap, sFld);
186  }
187  }
188  }
189 }
190 
191 
192 // ************************************************************************* //
Foam::surfaceFields.
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1117
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const Internal & internalField() const noexcept
Return a const-reference to the dimensioned internal field.
label start() const noexcept
The start label of boundary faces in the polyMesh face list.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
A traits class, which is primarily used for primitives.
Definition: pTraits.H:51
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
const cellList & cells() const
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
label nFaces() const noexcept
Number of mesh faces.
SubField is a Field obtained as a section of another Field, without its own allocation. SubField is derived from a SubList rather than a List.
Definition: Field.H:63
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:549
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
void mapNewInternalFaces(const labelList &faceMap, GeometricField< T, fvsPatchField, surfaceMesh > &)
Map single non-flux surface<Type>Field.
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:584
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1111
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:329
label nInternalFaces() const noexcept
Number of internal faces.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:102
#define DebugInfo
Report an information message using Foam::Info.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const labelUList & owner() const
Internal face owner. Note bypassing virtual mechanism so.
Definition: fvMesh.H:541
#define WarningInFunction
Report a warning using Foam::Warning.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:53
List< label > labelList
A List of labels.
Definition: List.H:62
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:133