Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / finiteVolume / fvMesh / singleCellFvMesh / singleCellFvMeshInterpolate.C
blob428819912dffd9a45c3abf7942616a07755b7634
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "singleCellFvMesh.H"
27 #include "foamTime.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 template<class Type>
37 tmp<GeometricField<Type, fvPatchField, volMesh> > singleCellFvMesh::interpolate
39     const GeometricField<Type, fvPatchField, volMesh>& vf
40 ) const
42     // Create internal-field values
43     Field<Type> internalField(1, gAverage(vf));
45     // Create and map the patch field values
46     PtrList<fvPatchField<Type> > patchFields(vf.boundaryField().size());
48     if (agglomerate())
49     {
50         forAll(vf.boundaryField(), patchI)
51         {
52             const labelList& agglom = patchFaceAgglomeration_[patchI];
53             label nAgglom = max(agglom) + 1;
55             // Use inverse of agglomeration. This is from agglomeration to
56             // original (fine) mesh patch face.
57             labelListList coarseToFine(invertOneToMany(nAgglom, agglom));
58             inplaceReorder(patchFaceMap_[patchI], coarseToFine);
59             scalarListList coarseWeights(nAgglom);
60             forAll(coarseToFine, coarseI)
61             {
62                 const labelList& fineFaces = coarseToFine[coarseI];
63                 coarseWeights[coarseI] = scalarList
64                 (
65                     fineFaces.size(),
66                     1.0/fineFaces.size()
67                 );
68             }
70             patchFields.set
71             (
72                 patchI,
73                 fvPatchField<Type>::New
74                 (
75                     vf.boundaryField()[patchI],
76                     boundary()[patchI],
77                     DimensionedField<Type, volMesh>::null(),
78                     agglomPatchFieldMapper(coarseToFine, coarseWeights, agglom.size())
79                 )
80             );
81         }
82     }
83     else
84     {
85         forAll(vf.boundaryField(), patchI)
86         {
87             labelList map(identity(vf.boundaryField()[patchI].size()));
89             patchFields.set
90             (
91                 patchI,
92                 fvPatchField<Type>::New
93                 (
94                     vf.boundaryField()[patchI],
95                     boundary()[patchI],
96                     DimensionedField<Type, volMesh>::null(),
97                     directPatchFieldMapper(map, map.size())
98                 )
99             );
100         }
101     }
103     // Create the complete field from the pieces
104     tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
105     (
106         new GeometricField<Type, fvPatchField, volMesh>
107         (
108             IOobject
109             (
110                 vf.name(),
111                 time().timeName(),
112                 *this,
113                 IOobject::NO_READ,
114                 IOobject::NO_WRITE
115             ),
116             *this,
117             vf.dimensions(),
118             internalField,
119             patchFields
120         )
121     );
123     return tresF;
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129 } // End namespace Foam
131 // ************************************************************************* //