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 -------------------------------------------------------------------------------
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 "singleCellFvMesh.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template<class Type>
38 (
40 ) const
41 {
42  // 1. Create the complete field with dummy patch fields
43 
45  (
47  (
48  IOobject
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 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
tmp< GeometricField< Type, fvPatchField, volMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Map volField. Internal field set to average, patch fields straight copies.
const Internal::FieldType & primitiveField() const noexcept
Return a const-reference to the internal field values.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
Definition: tmpI.H:235
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:493
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Patch field mapper class for agglomerated meshes.
Generic GeometricField class.
Ignore writing from objectRegistry::writeObject()
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
DirectFieldMapper< fvPatchFieldMapper > directFvPatchFieldMapper
A fvPatchFieldMapper with direct mapping.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
Definition: ListOps.C:126
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...
Definition: labelLists.C:44
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
bool agglomerate() const noexcept
Type gAverage(const FieldField< Field, Type > &f)
Nothing to be read.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
Definition: fvPatchField.H:204
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition: fvMesh.H:395
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
const dimensionSet & dimensions() const noexcept
Return dimensions.