1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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 "PrimitivePatchInterpolationTemplate.H"
28 #include "demandDrivenData.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 PrimitivePatchInterpolation<Patch>::faceToPointWeights() const
41 if (!faceToPointWeightsPtr_)
43 makeFaceToPointWeights();
46 return *faceToPointWeightsPtr_;
51 void PrimitivePatchInterpolation<Patch>::makeFaceToPointWeights() const
53 if (faceToPointWeightsPtr_)
57 "PrimitivePatchInterpolation<Patch>::makeFaceToPointWeights() const"
58 ) << "Face-to-edge weights already calculated"
62 const pointField& points = patch_.localPoints();
63 const faceList& faces = patch_.localFaces();
65 faceToPointWeightsPtr_ = new scalarListList(points.size());
66 scalarListList& weights = *faceToPointWeightsPtr_;
68 // get reference to addressing
69 const labelListList& pointFaces = patch_.pointFaces();
71 forAll(pointFaces, pointi)
73 const labelList& curFaces = pointFaces[pointi];
75 scalarList& pw = weights[pointi];
76 pw.setSize(curFaces.size());
80 forAll(curFaces, facei)
83 1.0/mag(faces[curFaces[facei]].centre(points) - points[pointi]);
87 forAll(curFaces, facei)
97 PrimitivePatchInterpolation<Patch>::faceToEdgeWeights() const
99 if (!faceToEdgeWeightsPtr_)
101 makeFaceToEdgeWeights();
104 return *faceToEdgeWeightsPtr_;
108 template<class Patch>
109 void PrimitivePatchInterpolation<Patch>::makeFaceToEdgeWeights() const
111 if (faceToEdgeWeightsPtr_)
115 "PrimitivePatchInterpolation<Patch>::makeFaceToEdgeWeights() const"
116 ) << "Face-to-edge weights already calculated"
117 << abort(FatalError);
120 const pointField& points = patch_.localPoints();
121 const faceList& faces = patch_.localFaces();
122 const edgeList& edges = patch_.edges();
123 const labelListList& edgeFaces = patch_.edgeFaces();
125 faceToEdgeWeightsPtr_ = new scalarList(patch_.nInternalEdges());
126 scalarList& weights = *faceToEdgeWeightsPtr_;
128 for (label edgei = 0; edgei < weights.size(); edgei++)
130 vector P = faces[edgeFaces[edgei][0]].centre(points);
131 vector N = faces[edgeFaces[edgei][1]].centre(points);
132 vector S = points[edges[edgei].start()];
133 vector e = edges[edgei].vec(points);
136 -(((N - P)^(S - P))&((N - P)^e))/(((N - P)^e )&((N - P)^e));
138 vector E = S + alpha*e;
140 weights[edgei] = mag(N - E)/(mag(N - E) + mag(E - P));
145 template<class Patch>
146 void PrimitivePatchInterpolation<Patch>::clearWeights()
148 deleteDemandDrivenData(faceToPointWeightsPtr_);
149 deleteDemandDrivenData(faceToEdgeWeightsPtr_);
153 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
155 template<class Patch>
156 PrimitivePatchInterpolation<Patch>::PrimitivePatchInterpolation(const Patch& p)
159 faceToPointWeightsPtr_(NULL),
160 faceToEdgeWeightsPtr_(NULL)
164 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
166 template<class Patch>
167 PrimitivePatchInterpolation<Patch>::~PrimitivePatchInterpolation()
173 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175 template<class Patch>
177 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToPointInterpolate
179 const Field<Type>& ff
182 // Check size of the given field
183 if (ff.size() != patch_.size())
187 "tmp<Field<Type> > PrimitivePatchInterpolation::"
188 "faceToPointInterpolate(const Field<Type> ff)"
189 ) << "given field does not correspond to patch. Patch size: "
190 << patch_.size() << " field size: " << ff.size()
191 << abort(FatalError);
194 tmp<Field<Type> > tresult
198 patch_.nPoints(), pTraits<Type>::zero
202 Field<Type>& result = tresult();
204 const labelListList& pointFaces = patch_.pointFaces();
205 const scalarListList& weights = faceToPointWeights();
207 forAll(pointFaces, pointi)
209 const labelList& curFaces = pointFaces[pointi];
210 const scalarList& w = weights[pointi];
212 forAll(curFaces, facei)
214 result[pointi] += w[facei]*ff[curFaces[facei]];
222 template<class Patch>
224 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToPointInterpolate
226 const tmp<Field<Type> >& tff
229 tmp<Field<Type> > tint = faceToPointInterpolate(tff());
235 template<class Patch>
237 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::pointToFaceInterpolate
239 const Field<Type>& pf
242 if (pf.size() != patch_.nPoints())
246 "tmp<Field<Type> > PrimitivePatchInterpolation::"
247 "pointToFaceInterpolate(const Field<Type> pf)"
248 ) << "given field does not correspond to patch. Patch size: "
249 << patch_.nPoints() << " field size: " << pf.size()
250 << abort(FatalError);
253 tmp<Field<Type> > tresult
262 Field<Type>& result = tresult();
264 const faceList& localFaces = patch_.localFaces();
266 forAll(result, facei)
268 const labelList& curPoints = localFaces[facei];
270 forAll(curPoints, pointi)
272 result[facei] += pf[curPoints[pointi]];
275 result[facei] /= curPoints.size();
282 template<class Patch>
284 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::pointToFaceInterpolate
286 const tmp<Field<Type> >& tpf
289 tmp<Field<Type> > tint = pointToFaceInterpolate(tpf());
295 template<class Patch>
297 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToEdgeInterpolate
299 const Field<Type>& pf
302 // Check size of the given field
303 if (pf.size() != patch_.size())
307 "tmp<Field<Type> > PrimitivePatchInterpolation::"
308 "faceToEdgeInterpolate(const Field<Type> ff)"
309 ) << "given field does not correspond to patch. Patch size: "
310 << patch_.size() << " field size: " << pf.size()
311 << abort(FatalError);
314 tmp<Field<Type> > tresult
316 new Field<Type>(patch_.nEdges(), pTraits<Type>::zero)
319 Field<Type>& result = tresult();
321 const edgeList& edges = patch_.edges();
322 const labelListList& edgeFaces = patch_.edgeFaces();
324 const scalarList& weights = faceToEdgeWeights();
326 for (label edgei = 0; edgei < patch_.nInternalEdges(); edgei++)
329 weights[edgei]*pf[edgeFaces[edgei][0]]
330 + (1.0 - weights[edgei])*pf[edgeFaces[edgei][1]];
333 for (label edgei = patch_.nInternalEdges(); edgei < edges.size(); edgei++)
335 result[edgei] = pf[edgeFaces[edgei][0]];
342 template<class Patch>
344 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToEdgeInterpolate
346 const tmp<Field<Type> >& tpf
349 tmp<Field<Type> > tint = faceToEdgeInterpolate(tpf());
355 template<class Patch>
356 bool PrimitivePatchInterpolation<Patch>::movePoints()
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
366 } // End namespace Foam
368 // ************************************************************************* //