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-------------------------------------------------------------------------------
10License
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
32template<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
101template<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 {
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
135template<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 {
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 {
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// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
const Internal & internalField() const
Return a const-reference to the dimensioned internal field.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition: SubField.H:62
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:57
void mapNewInternalFaces(const labelList &faceMap, GeometricField< T, fvsPatchField, surfaceMesh > &)
Map single non-flux surface<Type>Field.
const labelUList & owner() const
Internal face owner. Note bypassing virtual mechanism so.
Definition: fvMesh.H:417
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:423
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:79
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1121
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1127
label nInternalFaces() const noexcept
Number of internal faces.
label nFaces() const noexcept
Number of mesh faces.
Mesh data needed to do the Finite Volume discretisation.
Definition: surfaceMesh.H:52
type
Volume classification types.
Definition: volumeType.H:66
const volScalarField & T
const cellShapeList & cells
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllIters(container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:260
A non-counting (dummy) refCount.
Definition: refCount.H:59
Foam::surfaceFields.