ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / finiteVolume / fvMesh / singleCellFvMesh / singleCellFvMeshInterpolate.C
blob33e8316ac7f110dfc7e213eea8177e522c8bca4e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "singleCellFvMesh.H"
27 #include "Time.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)
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)
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 // ************************************************************************* //