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 #include <sampling/meshToMesh.H>
00027
00028
00029
00030 namespace Foam
00031 {
00032
00033
00034
00035 void meshToMesh::calculateInverseDistanceWeights() const
00036 {
00037 if (debug)
00038 {
00039 Info<< "meshToMesh::calculateInverseDistanceWeights() : "
00040 << "calculating inverse distance weighting factors" << endl;
00041 }
00042
00043 if (inverseDistanceWeightsPtr_)
00044 {
00045 FatalErrorIn("meshToMesh::calculateInverseDistanceWeights()")
00046 << "weighting factors already calculated"
00047 << exit(FatalError);
00048 }
00049
00050 inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
00051 scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
00052
00053
00054 const labelListList& cc = fromMesh_.cellCells();
00055 const vectorField& centreFrom = fromMesh_.C().internalField();
00056 const vectorField& centreTo = toMesh_.C().internalField();
00057
00058 forAll (cellAddressing_, celli)
00059 {
00060 if (cellAddressing_[celli] != -1)
00061 {
00062 const vector& target = centreTo[celli];
00063 scalar m = mag(target - centreFrom[cellAddressing_[celli]]);
00064
00065 const labelList& neighbours = cc[cellAddressing_[celli]];
00066
00067
00068
00069 if
00070 (
00071 m < directHitTol
00072 || neighbours.empty()
00073 )
00074 {
00075 invDistCoeffs[celli].setSize(1);
00076 invDistCoeffs[celli][0] = 1.0;
00077 }
00078 else
00079 {
00080 invDistCoeffs[celli].setSize(neighbours.size() + 1);
00081
00082
00083
00084 scalar invDist = 1.0/m;
00085 invDistCoeffs[celli][0] = invDist;
00086 scalar sumInvDist = invDist;
00087
00088
00089 forAll (neighbours, ni)
00090 {
00091 invDist = 1.0/mag(target - centreFrom[neighbours[ni]]);
00092 invDistCoeffs[celli][ni + 1] = invDist;
00093 sumInvDist += invDist;
00094 }
00095
00096
00097 forAll (invDistCoeffs[celli], i)
00098 {
00099 invDistCoeffs[celli][i] /= sumInvDist;
00100 }
00101 }
00102 }
00103 }
00104 }
00105
00106
00107
00108
00109 const scalarListList& meshToMesh::inverseDistanceWeights() const
00110 {
00111 if (!inverseDistanceWeightsPtr_)
00112 {
00113 calculateInverseDistanceWeights();
00114 }
00115
00116 return *inverseDistanceWeightsPtr_;
00117 }
00118
00119
00120
00121
00122 }
00123
00124