initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / interpolation / volPointInterpolation / pointPatchInterpolation / pointPatchInterpolate.C
blobd7307e0d1f7a5df1f357d0dee8ed1832c33e1105
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "pointPatchInterpolation.H"
28 #include "volFields.H"
29 #include "pointFields.H"
30 #include "emptyFvPatch.H"
31 #include "valuePointPatchField.H"
32 #include "coupledPointPatchField.H"
33 #include "coupledFacePointPatch.H"
34 #include "transform.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 template<class Type>
44 void pointPatchInterpolation::interpolate
46     const GeometricField<Type, fvPatchField, volMesh>& vf,
47     GeometricField<Type, pointPatchField, pointMesh>& pf,
48     bool overrideFixedValue
49 ) const
51     if (debug)
52     {
53         Info<< "pointPatchInterpolation::interpolate("
54             << "const GeometricField<Type, fvPatchField, volMesh>&, "
55             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
56             << "interpolating field from cells to points"
57             << endl;
58     }
60     // Interpolate patch values: over-ride the internal values for the points
61     // on the patch with the interpolated point values from the faces of the
62     // patch
64     const fvBoundaryMesh& bm = fvMesh_.boundary();
65     const pointBoundaryMesh& pbm = pointMesh::New(fvMesh_).boundary();
67     forAll(bm, patchi)
68     {
69         if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
70         {
71             pointPatchField<Type>& ppf = pf.boundaryField()[patchi];
73             // Only map the values corresponding to the points associated with
74             // faces, not "lone" points due to decomposition
75             ppf.setInInternalField
76             (
77                 pf.internalField(),
78                 patchInterpolators_[patchi]
79                .faceToPointInterpolate(vf.boundaryField()[patchi])(),
80                 bm[patchi].patch().meshPoints()
81             );
83             if
84             (
85                 overrideFixedValue
86              && isA<valuePointPatchField<Type> >(ppf)
87             )
88             {
89                 refCast<valuePointPatchField<Type> >(ppf) = ppf;
90             }
91         }
92         else if (bm[patchi].coupled())
93         {
94             // Initialise the "lone" points on the coupled patch to zero,
95             // these values are obtained from the couple-transfer
97             const labelList& loneMeshPoints =
98                 refCast<const coupledFacePointPatch>(pbm[patchi])
99                .loneMeshPoints();
101             forAll(loneMeshPoints, i)
102             {
103                 pf[loneMeshPoints[i]] = pTraits<Type>::zero;
104             }
105         }
107     }
110     // Correct patch-patch boundary points by interpolation "around" corners
111     const labelListList& PointFaces = fvMesh_.pointFaces();
113     forAll(patchPatchPoints_, pointi)
114     {
115         const label curPoint = patchPatchPoints_[pointi];
116         const labelList& curFaces = PointFaces[curPoint];
118         label fI = 0;
120         // Reset the boundary value before accumulation
121         pf[curPoint] = pTraits<Type>::zero;
123         // Go through all the faces
124         forAll(curFaces, facei)
125         {
126             if (!fvMesh_.isInternalFace(curFaces[facei]))
127             {
128                 label patchi =
129                     fvMesh_.boundaryMesh().whichPatch(curFaces[facei]);
131                 if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
132                 {
133                     label faceInPatchi =
134                         bm[patchi].patch().whichFace(curFaces[facei]);
136                     pf[curPoint] +=
137                         patchPatchPointWeights_[pointi][fI]
138                        *vf.boundaryField()[patchi][faceInPatchi];
140                     fI++;
141                 }
142             }
143         }
144     }
146     // Update coupled boundaries
147     forAll(pf.boundaryField(), patchi)
148     {
149         if (pf.boundaryField()[patchi].coupled())
150         {
151             refCast<coupledPointPatchField<Type> >(pf.boundaryField()[patchi])
152                 .initSwapAdd(pf.internalField());
153         }
154     }
156     forAll(pf.boundaryField(), patchi)
157     {
158         if (pf.boundaryField()[patchi].coupled())
159         {
160             refCast<coupledPointPatchField<Type> >(pf.boundaryField()[patchi])
161                 .swapAdd(pf.internalField());
162         }
163     }
166     // Override constrained pointPatchField types with the constraint value.
167     // This relys on only constrained pointPatchField implementing the evaluate
168     // function
169     pf.correctBoundaryConditions();
172     // Apply multiple constraints on edge/corner points
173     applyCornerConstraints(pf);
176     if (debug)
177     {
178         Info<< "pointPatchInterpolation::interpolate("
179             << "const GeometricField<Type, fvPatchField, volMesh>&, "
180             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
181             << "finished interpolating field from cells to points"
182             << endl;
183     }
187 template<class Type>
188 void pointPatchInterpolation::applyCornerConstraints
190     GeometricField<Type, pointPatchField, pointMesh>& pf
191 ) const
193     forAll(patchPatchPointConstraintPoints_, pointi)
194     {
195         pf[patchPatchPointConstraintPoints_[pointi]] = transform
196         (
197             patchPatchPointConstraintTensors_[pointi],
198             pf[patchPatchPointConstraintPoints_[pointi]]
199         );
200     }
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 } // End namespace Foam
208 // ************************************************************************* //