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.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 {
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.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  <
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::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
Foam::surfaceMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: surfaceMesh.H:49
Foam::fvsPatchField
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:68
Foam::dynamicRefineFvMesh::mapNewInternalFaces
void mapNewInternalFaces(const labelList &faceMap, GeometricField< T, fvsPatchField, surfaceMesh > &)
Map single non-flux surface<Type>Field.
Definition: dynamicRefineFvMeshTemplates.C:34
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
surfaceFields.H
Foam::surfaceFields.
Foam::GeometricField::internalField
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
Definition: GeometricFieldI.H:43
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
Foam::Field< T >
forAllIters
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:223
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:382
Foam::List< label >
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::UList< label >
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:62
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62