Loading...
Searching...
No Matches
singleCellFvMeshInterpolate.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-------------------------------------------------------------------------------
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 "singleCellFvMesh.H"
31#include "Time.H"
32
33// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34
35template<class Type>
38(
40) const
41{
42 // 1. Create the complete field with dummy patch fields
43
45 (
47 (
49 (
50 vf.name(),
51 time().timeName(),
52 *this,
55 ),
56 *this,
57 Type(gAverage(vf.primitiveField())),
58 vf.dimensions(),
60 )
61 );
62 auto& result = tresult.ref();
63
64
65 // 2. Change the fvPatchFields to the correct type using a mapper
66 // constructor (with reference to the now correct internal field)
67
68 auto& bf = result.boundaryFieldRef();
69
70 if (agglomerate())
71 {
72 forAll(vf.boundaryField(), patchi)
73 {
74 const labelList& agglom = patchFaceAgglomeration_[patchi];
75 label nAgglom = max(agglom)+1;
76
77 // Use inverse of agglomeration. This is from agglomeration to
78 // original (fine) mesh patch face.
79 labelListList coarseToFine(invertOneToMany(nAgglom, agglom));
80 inplaceReorder(patchFaceMap_[patchi], coarseToFine);
81 scalarListList coarseWeights(nAgglom);
82 forAll(coarseToFine, coarseI)
83 {
84 const labelList& fineFaces = coarseToFine[coarseI];
85 coarseWeights[coarseI] = scalarList
86 (
87 fineFaces.size(),
88 1.0/fineFaces.size()
89 );
90 }
91
92 bf.set
93 (
94 patchi,
96 (
97 vf.boundaryField()[patchi],
98 boundary()[patchi],
99 result.internalField(),
100 agglomPatchFieldMapper(coarseToFine, coarseWeights)
101 )
102 );
103 }
104 }
105 else
106 {
107 forAll(vf.boundaryField(), patchi)
108 {
109 labelList map(identity(vf.boundaryField()[patchi].size()));
110
111 bf.set
112 (
113 patchi,
115 (
116 vf.boundaryField()[patchi],
117 boundary()[patchi],
118 result.internalField(),
120 )
121 );
122 }
123 }
124
125 return tresult;
126}
127
128
129// ************************************************************************* //
const dimensionSet & dimensions() const noexcept
Return dimensions.
Generic GeometricField class.
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
const Time & time() const
Return the top-level database.
Definition fvMesh.H:360
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition fvMesh.H:395
static const word & calculatedType() noexcept
The type name for calculated patch fields.
static tmp< fvPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, volMesh > &)
Return a pointer to a new patchField created on freestore given.
Patch field mapper class for agglomerated meshes.
bool agglomerate() const noexcept
tmp< GeometricField< Type, fvPatchField, volMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Map volField. Internal field set to average, patch fields straight copies.
A class for managing temporary objects.
Definition tmp.H:75
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition tmpI.H:235
word timeName
Definition getTimeIndex.H:3
List< scalarList > scalarListList
List of scalarList.
Definition scalarList.H:35
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
DirectFieldMapper< fvPatchFieldMapper > directFvPatchFieldMapper
A fvPatchFieldMapper with direct mapping.
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
Definition ListOps.C:125
List< scalar > scalarList
List of scalar.
Definition scalarList.H:32
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299