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 "PatchToPatchInterpolation.H"
00028 #include "objectHit.H"
00029 #include "pointHit.H"
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036
00037
00038 template<class FromPatch, class ToPatch>
00039 scalar PatchToPatchInterpolation<FromPatch, ToPatch>::projectionTol_ = 0.05;
00040
00041
00042
00043
00044 template<class FromPatch, class ToPatch>
00045 void PatchToPatchInterpolation<FromPatch, ToPatch>::calcPointAddressing() const
00046 {
00047
00048
00049 pointWeightsPtr_ = new FieldField<Field, scalar>(toPatch_.nPoints());
00050 FieldField<Field, scalar>& pointWeights = *pointWeightsPtr_;
00051
00052 pointDistancePtr_ = new scalarField(toPatch_.nPoints(), GREAT);
00053 scalarField& pointDistance = *pointDistancePtr_;
00054
00055 const pointField& fromPatchPoints = fromPatch_.localPoints();
00056 const List<typename FromPatch::FaceType>& fromPatchFaces =
00057 fromPatch_.localFaces();
00058
00059 const pointField& toPatchPoints = toPatch_.localPoints();
00060 const vectorField& projectionDirection = toPatch_.pointNormals();
00061 const edgeList& toPatchEdges = toPatch_.edges();
00062 const labelListList& toPatchPointEdges = toPatch_.pointEdges();
00063
00064 if (debug)
00065 {
00066 Info << "projecting points" << endl;
00067 }
00068
00069 List<objectHit> proj =
00070 toPatch_.projectPoints(fromPatch_, projectionDirection, alg_, dir_);
00071
00072 pointAddressingPtr_ = new labelList(proj.size(), -1);
00073 labelList& pointAddressing = *pointAddressingPtr_;
00074
00075 bool doWeights = false;
00076
00077 forAll (pointAddressing, pointI)
00078 {
00079 doWeights = false;
00080
00081 const typename FromPatch::FaceType& hitFace =
00082 fromPatchFaces[proj[pointI].hitObject()];
00083
00084 point hitPoint = point::zero;
00085
00086 if (proj[pointI].hit())
00087 {
00088
00089 doWeights = true;
00090
00091 pointAddressing[pointI] = proj[pointI].hitObject();
00092
00093 pointHit curHit =
00094 hitFace.ray
00095 (
00096 toPatchPoints[pointI],
00097 projectionDirection[pointI],
00098 fromPatchPoints,
00099 alg_,
00100 dir_
00101 );
00102
00103
00104 if (dir_ == intersection::CONTACT_SPHERE)
00105 {
00106 pointDistance[pointI] =
00107 hitFace.contactSphereDiameter
00108 (
00109 toPatchPoints[pointI],
00110 projectionDirection[pointI],
00111 fromPatchPoints
00112 );
00113 }
00114 else
00115 {
00116 pointDistance[pointI] = curHit.distance();
00117 }
00118
00119
00120 hitPoint = curHit.hitPoint();
00121 }
00122 else if (projectionTol_ > SMALL)
00123 {
00124
00125 pointHit ph =
00126 hitFace.ray
00127 (
00128 toPatchPoints[pointI],
00129 projectionDirection[pointI],
00130 fromPatchPoints,
00131 alg_,
00132 dir_
00133 );
00134
00135 scalar dist =
00136 Foam::mag
00137 (
00138 toPatchPoints[pointI]
00139 + projectionDirection[pointI]*ph.distance()
00140 - ph.missPoint()
00141 );
00142
00143
00144 scalar minEdgeLength = GREAT;
00145
00146
00147 edgeList hitFaceEdges =
00148 fromPatchFaces[proj[pointI].hitObject()].edges();
00149
00150 forAll (hitFaceEdges, edgeI)
00151 {
00152 minEdgeLength =
00153 min
00154 (
00155 minEdgeLength,
00156 hitFaceEdges[edgeI].mag(fromPatchPoints)
00157 );
00158 }
00159
00160 const labelList& curEdges = toPatchPointEdges[pointI];
00161
00162 forAll (curEdges, edgeI)
00163 {
00164 minEdgeLength =
00165 min
00166 (
00167 minEdgeLength,
00168 toPatchEdges[curEdges[edgeI]].mag(toPatchPoints)
00169 );
00170 }
00171
00172 if (dist < minEdgeLength*projectionTol_)
00173 {
00174
00175 doWeights = true;
00176
00177 pointAddressing[pointI] = proj[pointI].hitObject();
00178
00179
00180 hitPoint = ph.missPoint();
00181
00182
00183 if (dir_ == intersection::CONTACT_SPHERE)
00184 {
00185 pointDistance[pointI] =
00186 hitFace.contactSphereDiameter
00187 (
00188 toPatchPoints[pointI],
00189 projectionDirection[pointI],
00190 fromPatchPoints
00191 );
00192 }
00193 else
00194 {
00195 pointDistance[pointI] =
00196 (
00197 projectionDirection[pointI]
00198 /mag(projectionDirection[pointI])
00199 )
00200 & (hitPoint - toPatchPoints[pointI]);
00201 }
00202 }
00203 }
00204
00205 if (doWeights)
00206 {
00207
00208 pointWeights.set(pointI, new scalarField(hitFace.size()));
00209
00210 pointField hitFacePoints = hitFace.points(fromPatchPoints);
00211
00212 forAll (hitFacePoints, masterPointI)
00213 {
00214 pointWeights[pointI][masterPointI] =
00215 1.0/
00216 (
00217 mag
00218 (
00219 hitFacePoints[masterPointI]
00220 - hitPoint
00221 )
00222 + VSMALL
00223 );
00224 }
00225
00226 pointWeights[pointI] /= sum(pointWeights[pointI]);
00227 }
00228 else
00229 {
00230 pointWeights.set(pointI, new scalarField(0));
00231 }
00232 }
00233 }
00234
00235
00236 template<class FromPatch, class ToPatch>
00237 void PatchToPatchInterpolation<FromPatch, ToPatch>::calcFaceAddressing() const
00238 {
00239 faceWeightsPtr_ = new FieldField<Field, scalar>(toPatch_.size());
00240 FieldField<Field, scalar>& faceWeights = *faceWeightsPtr_;
00241
00242 faceDistancePtr_ = new scalarField(toPatch_.size(), GREAT);
00243 scalarField& faceDistance = *faceDistancePtr_;
00244
00245 if (debug)
00246 {
00247 Info << "projecting face centres" << endl;
00248 }
00249
00250 const pointField& fromPatchPoints = fromPatch_.points();
00251 const typename FromPatch::FaceListType& fromPatchFaces = fromPatch_;
00252 const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
00253
00254 vectorField fromPatchFaceCentres(fromPatchFaces.size());
00255
00256 forAll (fromPatchFaceCentres, faceI)
00257 {
00258 fromPatchFaceCentres[faceI] =
00259 fromPatchFaces[faceI].centre(fromPatchPoints);
00260 }
00261
00262 const pointField& toPatchPoints = toPatch_.points();
00263 const typename ToPatch::FaceListType& toPatchFaces = toPatch_;
00264
00265 const vectorField& projectionDirection = toPatch_.faceNormals();
00266
00267 List<objectHit> proj =
00268 toPatch_.projectFaceCentres
00269 (
00270 fromPatch_,
00271 projectionDirection,
00272 alg_,
00273 dir_
00274 );
00275
00276 faceAddressingPtr_ = new labelList(proj.size(), -1);
00277 labelList& faceAddressing = *faceAddressingPtr_;
00278
00279 forAll (faceAddressing, faceI)
00280 {
00281 if (proj[faceI].hit())
00282 {
00283
00284 faceAddressing[faceI] = proj[faceI].hitObject();
00285
00286 const typename FromPatch::FaceType& hitFace =
00287 fromPatchFaces[faceAddressing[faceI]];
00288
00289 pointHit curHit =
00290 hitFace.ray
00291 (
00292 toPatchFaces[faceI].centre(toPatchPoints),
00293 projectionDirection[faceI],
00294 fromPatchPoints,
00295 alg_,
00296 dir_
00297 );
00298
00299
00300 faceDistance[faceI] = curHit.distance();
00301
00302
00303 const point& hitFaceCentre =
00304 fromPatchFaceCentres[faceAddressing[faceI]];
00305
00306
00307 const labelList& neighbours =
00308 fromPatchFaceFaces[faceAddressing[faceI]];
00309
00310 scalar m = mag(curHit.hitPoint() - hitFaceCentre);
00311
00312 if
00313 (
00314 m < directHitTol
00315 || neighbours.empty()
00316 )
00317 {
00318 faceWeights.set(faceI, new scalarField(1));
00319 faceWeights[faceI][0] = 1.0;
00320 }
00321 else
00322 {
00323
00324
00325
00326
00327 faceWeights.set(faceI, new scalarField(neighbours.size() + 1));
00328
00329 faceWeights[faceI][0] = 1.0/m;
00330
00331 forAll (neighbours, nI)
00332 {
00333 faceWeights[faceI][nI + 1] =
00334 1.0/
00335 (
00336 mag
00337 (
00338 fromPatchFaceCentres[neighbours[nI]]
00339 - curHit.hitPoint()
00340 )
00341 + VSMALL
00342 );
00343 }
00344 }
00345
00346 faceWeights[faceI] /= sum(faceWeights[faceI]);
00347 }
00348 else
00349 {
00350 faceWeights.set(faceI, new scalarField(0));
00351 }
00352 }
00353 }
00354
00355
00356
00357
00358 }
00359
00360