ENH: patchCloud: return pTraits<Type>::max for unfound points
[OpenFOAM-1.7.x.git] / src / finiteVolume / interpolation / volPointInterpolation / pointPatchInterpolation / pointPatchInterpolate.C
blob54c0c8ea10933be727631caabb4e1b3546695451
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 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
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 "pointPatchInterpolation.H"
27 #include "volFields.H"
28 #include "pointFields.H"
29 #include "emptyFvPatch.H"
30 #include "valuePointPatchField.H"
31 #include "coupledPointPatchField.H"
32 #include "coupledFacePointPatch.H"
33 #include "transform.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 namespace Foam
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 template<class Type>
43 void pointPatchInterpolation::interpolate
45     const GeometricField<Type, fvPatchField, volMesh>& vf,
46     GeometricField<Type, pointPatchField, pointMesh>& pf,
47     bool overrideFixedValue
48 ) const
50     if (debug)
51     {
52         Info<< "pointPatchInterpolation::interpolate("
53             << "const GeometricField<Type, fvPatchField, volMesh>&, "
54             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
55             << "interpolating field from cells to points"
56             << endl;
57     }
59     // Interpolate patch values: over-ride the internal values for the points
60     // on the patch with the interpolated point values from the faces of the
61     // patch
63     const fvBoundaryMesh& bm = fvMesh_.boundary();
64     const pointBoundaryMesh& pbm = pointMesh::New(fvMesh_).boundary();
66     forAll(bm, patchi)
67     {
68         if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
69         {
70             pointPatchField<Type>& ppf = pf.boundaryField()[patchi];
72             // Only map the values corresponding to the points associated with
73             // faces, not "lone" points due to decomposition
74             ppf.setInInternalField
75             (
76                 pf.internalField(),
77                 patchInterpolators_[patchi]
78                .faceToPointInterpolate(vf.boundaryField()[patchi])(),
79                 bm[patchi].patch().meshPoints()
80             );
82             if
83             (
84                 overrideFixedValue
85              && isA<valuePointPatchField<Type> >(ppf)
86             )
87             {
88                 refCast<valuePointPatchField<Type> >(ppf) = ppf;
89             }
90         }
91         else if (bm[patchi].coupled())
92         {
93             // Initialise the "lone" points on the coupled patch to zero,
94             // these values are obtained from the couple-transfer
96             const labelList& loneMeshPoints =
97                 refCast<const coupledFacePointPatch>(pbm[patchi])
98                .loneMeshPoints();
100             forAll(loneMeshPoints, i)
101             {
102                 pf[loneMeshPoints[i]] = pTraits<Type>::zero;
103             }
104         }
106     }
109     // Correct patch-patch boundary points by interpolation "around" corners
110     const labelListList& PointFaces = fvMesh_.pointFaces();
112     forAll(patchPatchPoints_, pointi)
113     {
114         const label curPoint = patchPatchPoints_[pointi];
115         const labelList& curFaces = PointFaces[curPoint];
117         label fI = 0;
119         // Reset the boundary value before accumulation
120         pf[curPoint] = pTraits<Type>::zero;
122         // Go through all the faces
123         forAll(curFaces, facei)
124         {
125             if (!fvMesh_.isInternalFace(curFaces[facei]))
126             {
127                 label patchi =
128                     fvMesh_.boundaryMesh().whichPatch(curFaces[facei]);
130                 if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
131                 {
132                     label faceInPatchi =
133                         bm[patchi].patch().whichFace(curFaces[facei]);
135                     pf[curPoint] +=
136                         patchPatchPointWeights_[pointi][fI]
137                        *vf.boundaryField()[patchi][faceInPatchi];
139                     fI++;
140                 }
141             }
142         }
143     }
145     // Update coupled boundaries
146     forAll(pf.boundaryField(), patchi)
147     {
148         if (pf.boundaryField()[patchi].coupled())
149         {
150             refCast<coupledPointPatchField<Type> >(pf.boundaryField()[patchi])
151                 .initSwapAdd(pf.internalField());
152         }
153     }
155     forAll(pf.boundaryField(), patchi)
156     {
157         if (pf.boundaryField()[patchi].coupled())
158         {
159             refCast<coupledPointPatchField<Type> >(pf.boundaryField()[patchi])
160                 .swapAdd(pf.internalField());
161         }
162     }
165     // Override constrained pointPatchField types with the constraint value.
166     // This relys on only constrained pointPatchField implementing the evaluate
167     // function
168     pf.correctBoundaryConditions();
171     // Apply multiple constraints on edge/corner points
172     applyCornerConstraints(pf);
175     if (debug)
176     {
177         Info<< "pointPatchInterpolation::interpolate("
178             << "const GeometricField<Type, fvPatchField, volMesh>&, "
179             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
180             << "finished interpolating field from cells to points"
181             << endl;
182     }
186 template<class Type>
187 void pointPatchInterpolation::applyCornerConstraints
189     GeometricField<Type, pointPatchField, pointMesh>& pf
190 ) const
192     forAll(patchPatchPointConstraintPoints_, pointi)
193     {
194         pf[patchPatchPointConstraintPoints_[pointi]] = transform
195         (
196             patchPatchPointConstraintTensors_[pointi],
197             pf[patchPatchPointConstraintPoints_[pointi]]
198         );
199     }
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 } // End namespace Foam
207 // ************************************************************************* //