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>
41 tmp<GeometricField<Type, fvPatchField, volMesh>> singleCellFvMesh::interpolate
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 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:51
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
calculatedFvPatchFields.H
Foam::singleCellFvMesh::agglomPatchFieldMapper
Patch field mapper class for agglomerated meshes.
Definition: singleCellFvMesh.H:93
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::singleCellFvMesh::interpolate
tmp< GeometricField< Type, fvPatchField, volMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &) const
Definition: singleCellFvMeshInterpolate.C:42
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
directFvPatchFieldMapper.H
singleCellFvMesh.H
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::calculatedFvPatchField
This boundary condition is not designed to be evaluated; it is assmued that the value is assigned via...
Definition: calculatedFvPatchField.H:66
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Time.H
Foam::GeometricField::boundaryFieldRef
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
Definition: GeometricField.C:783
Foam::List< label >
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::directFvPatchFieldMapper
direct fvPatchFieldMapper
Definition: directFvPatchFieldMapper.H:48
Foam::inplaceReorder
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
Definition: ListOpsTemplates.C:124
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::invertOneToMany
labelListList invertOneToMany(const label len, const labelUList &map)
Invert one-to-many map. Unmapped elements will be size 0.
Definition: ListOps.C:114
boundary
faceListList boundary
Definition: createBlockMesh.H:4
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54