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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
39 
40 template<class Type>
42 (
44 ) const
45 {
46  // 1. Create the complete field with dummy patch fields
47  PtrList<fvPatchField<Type>> patchFields(vf.boundaryField().size());
48 
49  forAll(patchFields, patchi)
50  {
51  patchFields.set
52  (
53  patchi,
55  (
57  boundary()[patchi],
59  )
60  );
61  }
62 
63  // Create the complete field from the pieces
65  (
67  (
68  IOobject
69  (
70  vf.name(),
71  time().timeName(),
72  *this,
75  ),
76  *this,
77  vf.dimensions(),
78  Field<Type>(1, gAverage(vf)),
79  patchFields
80  )
81  );
83 
84 
85  // 2. Change the fvPatchFields to the correct type using a mapper
86  // constructor (with reference to the now correct internal field)
87 
89  Boundary& bf = resF.boundaryFieldRef();
90 
91  if (agglomerate())
92  {
93  forAll(vf.boundaryField(), patchi)
94  {
95  const labelList& agglom = patchFaceAgglomeration_[patchi];
96  label nAgglom = max(agglom)+1;
97 
98  // Use inverse of agglomeration. This is from agglomeration to
99  // original (fine) mesh patch face.
100  labelListList coarseToFine(invertOneToMany(nAgglom, agglom));
101  inplaceReorder(patchFaceMap_[patchi], coarseToFine);
102  scalarListList coarseWeights(nAgglom);
103  forAll(coarseToFine, coarseI)
104  {
105  const labelList& fineFaces = coarseToFine[coarseI];
106  coarseWeights[coarseI] = scalarList
107  (
108  fineFaces.size(),
109  1.0/fineFaces.size()
110  );
111  }
112 
113  bf.set
114  (
115  patchi,
117  (
118  vf.boundaryField()[patchi],
119  boundary()[patchi],
120  resF(),
121  agglomPatchFieldMapper(coarseToFine, coarseWeights)
122  )
123  );
124  }
125  }
126  else
127  {
128  forAll(vf.boundaryField(), patchi)
129  {
130  labelList map(identity(vf.boundaryField()[patchi].size()));
131 
132  bf.set
133  (
134  patchi,
136  (
137  vf.boundaryField()[patchi],
138  boundary()[patchi],
139  resF(),
141  )
142  );
143  }
144  }
145 
146  return tresF;
147 }
148 
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 } // End namespace Foam
153 
154 // ************************************************************************* //
List< scalar > scalarList
List of scalar.
Definition: scalarList.H:32
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
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:489
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.
tmp< GeometricField< Type, fvPatchField, volMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Map volField. Internal field set to average, patch fields straight copies.
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
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:107
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
Generic templated field type.
Definition: Field.H:62
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
Type gAverage(const FieldField< Field, Type > &f)
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
Nothing to be read.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
Definition: fvPatchField.H:204
Internal & ref(const bool updateAccessTime=true)
Same as internalFieldRef()
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:172
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
Namespace for OpenFOAM.
const dimensionSet & dimensions() const noexcept
Return dimensions.