PrimitivePatchInterpolation.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "PrimitivePatchInterpolation.H"
00028 #include "faceList.H"
00029 #include "demandDrivenData.H"
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036
00037
00038 template<class Patch>
00039 const scalarListList&
00040 PrimitivePatchInterpolation<Patch>::faceToPointWeights() const
00041 {
00042 if (!faceToPointWeightsPtr_)
00043 {
00044 makeFaceToPointWeights();
00045 }
00046
00047 return *faceToPointWeightsPtr_;
00048 }
00049
00050
00051 template<class Patch>
00052 void PrimitivePatchInterpolation<Patch>::makeFaceToPointWeights() const
00053 {
00054 if (faceToPointWeightsPtr_)
00055 {
00056 FatalErrorIn
00057 (
00058 "PrimitivePatchInterpolation<Patch>::makeFaceToPointWeights() const"
00059 ) << "Face-to-edge weights already calculated"
00060 << abort(FatalError);
00061 }
00062
00063 const pointField& points = patch_.localPoints();
00064 const faceList& faces = patch_.localFaces();
00065
00066 faceToPointWeightsPtr_ = new scalarListList(points.size());
00067 scalarListList& weights = *faceToPointWeightsPtr_;
00068
00069
00070 const labelListList& pointFaces = patch_.pointFaces();
00071
00072 forAll(pointFaces, pointi)
00073 {
00074 const labelList& curFaces = pointFaces[pointi];
00075
00076 scalarList& pw = weights[pointi];
00077 pw.setSize(curFaces.size());
00078
00079 scalar sumw = 0.0;
00080
00081 forAll(curFaces, facei)
00082 {
00083 pw[facei] =
00084 1.0/mag(faces[curFaces[facei]].centre(points) - points[pointi]);
00085 sumw += pw[facei];
00086 }
00087
00088 forAll(curFaces, facei)
00089 {
00090 pw[facei] /= sumw;
00091 }
00092 }
00093 }
00094
00095
00096 template<class Patch>
00097 const scalarList&
00098 PrimitivePatchInterpolation<Patch>::faceToEdgeWeights() const
00099 {
00100 if (!faceToEdgeWeightsPtr_)
00101 {
00102 makeFaceToEdgeWeights();
00103 }
00104
00105 return *faceToEdgeWeightsPtr_;
00106 }
00107
00108
00109 template<class Patch>
00110 void PrimitivePatchInterpolation<Patch>::makeFaceToEdgeWeights() const
00111 {
00112 if (faceToEdgeWeightsPtr_)
00113 {
00114 FatalErrorIn
00115 (
00116 "PrimitivePatchInterpolation<Patch>::makeFaceToEdgeWeights() const"
00117 ) << "Face-to-edge weights already calculated"
00118 << abort(FatalError);
00119 }
00120
00121 const pointField& points = patch_.localPoints();
00122 const faceList& faces = patch_.localFaces();
00123 const edgeList& edges = patch_.edges();
00124 const labelListList& edgeFaces = patch_.edgeFaces();
00125
00126 faceToEdgeWeightsPtr_ = new scalarList(patch_.nInternalEdges());
00127 scalarList& weights = *faceToEdgeWeightsPtr_;
00128
00129 for (label edgei = 0; edgei < weights.size(); edgei++)
00130 {
00131 vector P = faces[edgeFaces[edgei][0]].centre(points);
00132 vector N = faces[edgeFaces[edgei][1]].centre(points);
00133 vector S = points[edges[edgei].start()];
00134 vector e = edges[edgei].vec(points);
00135
00136 scalar alpha =
00137 -(((N - P)^(S - P))&((N - P)^e))/(((N - P)^e )&((N - P)^e));
00138
00139 vector E = S + alpha*e;
00140
00141 weights[edgei] = mag(N - E)/(mag(N - E) + mag(E - P));
00142 }
00143 }
00144
00145
00146 template<class Patch>
00147 void PrimitivePatchInterpolation<Patch>::clearWeights()
00148 {
00149 deleteDemandDrivenData(faceToPointWeightsPtr_);
00150 deleteDemandDrivenData(faceToEdgeWeightsPtr_);
00151 }
00152
00153
00154
00155
00156 template<class Patch>
00157 PrimitivePatchInterpolation<Patch>::PrimitivePatchInterpolation(const Patch& p)
00158 :
00159 patch_(p),
00160 faceToPointWeightsPtr_(NULL),
00161 faceToEdgeWeightsPtr_(NULL)
00162 {}
00163
00164
00165
00166
00167 template<class Patch>
00168 PrimitivePatchInterpolation<Patch>::~PrimitivePatchInterpolation()
00169 {
00170 clearWeights();
00171 }
00172
00173
00174
00175
00176 template<class Patch>
00177 template<class Type>
00178 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToPointInterpolate
00179 (
00180 const Field<Type>& ff
00181 ) const
00182 {
00183
00184 if (ff.size() != patch_.size())
00185 {
00186 FatalErrorIn
00187 (
00188 "tmp<Field<Type> > PrimitivePatchInterpolation::"
00189 "faceToPointInterpolate(const Field<Type> ff)"
00190 ) << "given field does not correspond to patch. Patch size: "
00191 << patch_.size() << " field size: " << ff.size()
00192 << abort(FatalError);
00193 }
00194
00195 tmp<Field<Type> > tresult
00196 (
00197 new Field<Type>
00198 (
00199 patch_.nPoints(), pTraits<Type>::zero
00200 )
00201 );
00202
00203 Field<Type>& result = tresult();
00204
00205 const labelListList& pointFaces = patch_.pointFaces();
00206 const scalarListList& weights = faceToPointWeights();
00207
00208 forAll(pointFaces, pointi)
00209 {
00210 const labelList& curFaces = pointFaces[pointi];
00211 const scalarList& w = weights[pointi];
00212
00213 forAll(curFaces, facei)
00214 {
00215 result[pointi] += w[facei]*ff[curFaces[facei]];
00216 }
00217 }
00218
00219 return tresult;
00220 }
00221
00222
00223 template<class Patch>
00224 template<class Type>
00225 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToPointInterpolate
00226 (
00227 const tmp<Field<Type> >& tff
00228 ) const
00229 {
00230 tmp<Field<Type> > tint = faceToPointInterpolate(tff());
00231 tff.clear();
00232 return tint;
00233 }
00234
00235
00236 template<class Patch>
00237 template<class Type>
00238 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::pointToFaceInterpolate
00239 (
00240 const Field<Type>& pf
00241 ) const
00242 {
00243 if (pf.size() != patch_.nPoints())
00244 {
00245 FatalErrorIn
00246 (
00247 "tmp<Field<Type> > PrimitivePatchInterpolation::"
00248 "pointToFaceInterpolate(const Field<Type> pf)"
00249 ) << "given field does not correspond to patch. Patch size: "
00250 << patch_.nPoints() << " field size: " << pf.size()
00251 << abort(FatalError);
00252 }
00253
00254 tmp<Field<Type> > tresult
00255 (
00256 new Field<Type>
00257 (
00258 patch_.size(),
00259 pTraits<Type>::zero
00260 )
00261 );
00262
00263 Field<Type>& result = tresult();
00264
00265 const faceList& localFaces = patch_.localFaces();
00266
00267 forAll(result, facei)
00268 {
00269 const labelList& curPoints = localFaces[facei];
00270
00271 forAll(curPoints, pointi)
00272 {
00273 result[facei] += pf[curPoints[pointi]];
00274 }
00275
00276 result[facei] /= curPoints.size();
00277 }
00278
00279 return tresult;
00280 }
00281
00282
00283 template<class Patch>
00284 template<class Type>
00285 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::pointToFaceInterpolate
00286 (
00287 const tmp<Field<Type> >& tpf
00288 ) const
00289 {
00290 tmp<Field<Type> > tint = pointToFaceInterpolate(tpf());
00291 tpf.clear();
00292 return tint;
00293 }
00294
00295
00296 template<class Patch>
00297 template<class Type>
00298 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToEdgeInterpolate
00299 (
00300 const Field<Type>& pf
00301 ) const
00302 {
00303
00304 if (pf.size() != patch_.size())
00305 {
00306 FatalErrorIn
00307 (
00308 "tmp<Field<Type> > PrimitivePatchInterpolation::"
00309 "faceToEdgeInterpolate(const Field<Type> ff)"
00310 ) << "given field does not correspond to patch. Patch size: "
00311 << patch_.size() << " field size: " << pf.size()
00312 << abort(FatalError);
00313 }
00314
00315 tmp<Field<Type> > tresult
00316 (
00317 new Field<Type>(patch_.nEdges(), pTraits<Type>::zero)
00318 );
00319
00320 Field<Type>& result = tresult();
00321
00322 const pointField& points = patch_.localPoints();
00323 const faceList& faces = patch_.localFaces();
00324 const edgeList& edges = patch_.edges();
00325 const labelListList& edgeFaces = patch_.edgeFaces();
00326
00327 const scalarList& weights = faceToEdgeWeights();
00328
00329 for (label edgei = 0; edgei < patch_.nInternalEdges(); edgei++)
00330 {
00331 result[edgei] =
00332 weights[edgei]*pf[edgeFaces[edgei][0]]
00333 + (1.0 - weights[edgei])*pf[edgeFaces[edgei][1]];
00334 }
00335
00336 for (label edgei = patch_.nInternalEdges(); edgei < edges.size(); edgei++)
00337 {
00338 result[edgei] = pf[edgeFaces[edgei][0]];
00339 }
00340
00341 return tresult;
00342 }
00343
00344
00345 template<class Patch>
00346 template<class Type>
00347 tmp<Field<Type> > PrimitivePatchInterpolation<Patch>::faceToEdgeInterpolate
00348 (
00349 const tmp<Field<Type> >& tpf
00350 ) const
00351 {
00352 tmp<Field<Type> > tint = faceToEdgeInterpolate(tpf());
00353 tpf.clear();
00354 return tint;
00355 }
00356
00357
00358 template<class Patch>
00359 bool PrimitivePatchInterpolation<Patch>::movePoints()
00360 {
00361 clearWeights();
00362
00363 return true;
00364 }
00365
00366
00367
00368
00369 }
00370
00371
Copyright © 2000-2009 OpenCFD Ltd