34 namespace patchToPatches
44 bool Foam::patchToPatches::inverseDistance::rayHitsFace
52 using namespace constant::mathematical;
67 if (geometricMeanMagSqrAB < small*meanMagSqrAB)
return true;
71 *
acos(
min(
max(-1, (a &
b)/geometricMeanMagSqrAB), +1));
74 return pi < angle && angle < 3*
pi;
80 void Foam::patchToPatches::inverseDistance::initialise
96 srcWeights_.resize(srcPatch.size());
99 srcWeights_[i].clear();
102 tgtWeights_.resize(tgtPatch.size());
105 tgtWeights_[i].clear();
110 void Foam::patchToPatches::inverseDistance::generateWeights
121 List<DynamicList<label>>& otherFaces,
122 List<DynamicList<scalar>>& weights
127 if (otherFaces[facei].empty())
continue;
129 label otherFacei = -1;
132 forAll(otherFaces[facei], i)
138 patch.faceCentres()[facei],
139 (
reverse ? -1 : +1)*patch.faceNormals()[facei],
140 otherPatch[otherFaces[facei][i]],
145 otherFacei = otherFaces[facei][i];
150 const point&
c = patch.faceCentres()[facei];
153 if (otherFacei == -1)
155 scalar minDistSqr = vGreat;
157 forAll(otherFaces[facei], i)
159 const point& otherC =
160 otherPatch.faceCentres()[otherFaces[facei][i]];
161 const scalar distSqr =
magSqr(
c - otherC);
162 if (distSqr < minDistSqr)
164 minDistSqr = distSqr;
165 otherFacei = otherFaces[facei][i];
171 otherFaces[facei].clear();
174 const point& otherC = otherPatch.faceCentres()[otherFacei];
175 otherFaces[facei].append(otherFacei);
176 weights[facei].append(1/(
mag(
c - otherC) + rootVSmall));
178 forAll(otherPatch.faceFaces()[otherFacei], i)
180 const label otherFacej = otherPatch.faceFaces()[otherFacei][i];
182 const point& otherC = otherPatch.faceCentres()[otherFacej];
183 otherFaces[facei].append(otherFacej);
184 weights[facei].append(1/(
mag(
c - otherC) + rootVSmall));
203 generateWeights(srcPatch, tgtPatch);
214 tgtWeights_ = List<DynamicList<scalar>>(tgtWeights_, newToOldLocalTgtFace);
216 return newToOldLocalTgtFace;
220 void Foam::patchToPatches::inverseDistance::rDistributeTgt
238 Foam::label Foam::patchToPatches::inverseDistance::finalise
247 const label nCouples =
261 generateWeights(srcPatch, tgtPatch);
265 forAll(srcWeights_, srcFacei)
267 const scalar w =
sum(srcWeights_[srcFacei]);
268 forAll(srcWeights_[srcFacei], i)
270 srcWeights_[srcFacei][i] /=
max(w, vSmall);
273 forAll(tgtWeights_, tgtFacei)
275 const scalar w =
sum(tgtWeights_[tgtFacei]);
276 forAll(tgtWeights_[tgtFacei], i)
278 tgtWeights_[tgtFacei][i] /=
max(w, vSmall);
284 auto histogram = [](
const List<DynamicList<label>>& ll)
289 result.setSize(
max(result.size(), ll[i].size() + 1), 0);
290 result[ll[i].size()] ++;
293 result.resize(
returnReduce(result.size(), maxOp<label>()), 0);
302 <<
"Number of source faces by number of target connections = "
305 <<
"Number of target faces by number of source connections = "
314 Foam::patchToPatches::inverseDistance::srcWeights()
const
321 Foam::patchToPatches::inverseDistance::tgtWeights()
const
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
Class to generate coupling geometry between two primitive patches.
const bool reverse_
Flag to indicate that the two patches are co-directional and.
tmp< Field< Type > > tgtToSrc(const Field< Type > &tgtFld) const
Interpolate a target patch field to the source with no left.
List< DynamicList< label > > tgtLocalSrcFaces_
For each target face, the coupled local source faces.
bool isSingleProcess() const
Is this intersection on a single process?
virtual void rDistributeTgt(const primitiveOldTimePatch &tgtPatch)
Send data that resulted from an intersection between the source.
virtual labelList finaliseLocal(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch)
Finalise the intersection locally. Trims the local target patch.
List< DynamicList< label > > srcLocalTgtFaces_
For each source face, the coupled local target faces.
bool reverse() const
Flag to indicate that the two patches are co-directional and.
autoPtr< distributionMap > tgtMapPtr_
Map from target patch faces to source-local target patch faces.
virtual label finalise(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch, const transformer &tgtToSrc)
Finalising.
Class to generate patchToPatch coupling geometry. Couples a face to the opposite face onto which its ...
~inverseDistance()
Destructor.
inverseDistance(const bool reverse)
Construct from components.
Class to generate patchToPatch coupling geometry. Couples a face to the single nearby opposite face o...
virtual void initialise(const primitiveOldTimePatch &srcPatch, const vectorField &srcPointNormals, const vectorField &srcPointNormals0, const primitiveOldTimePatch &tgtPatch)
Initialisation.
A class for managing temporary objects without reference counting.
const dimensionedScalar c
Speed of light in a vacuum.
addToRunTimeSelectionTable(patchToPatch, intersection, bool)
defineTypeNameAndDebug(intersection, 0)
List< label > labelList
A List of labels.
dimensionedScalar sign(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Tensor< scalar > tensor
Tensor of scalars.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
vectorField pointField
pointField is a vectorField.
vector point
Point is a vector.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
Vector< scalar > vector
A scalar version of the templated Vector.
dimensionedScalar sqrt(const dimensionedScalar &ds)
PrimitiveOldTimePatch< SubList< face >, const pointField & > primitiveOldTimePatch
Addressing for a faceList slice.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensioned< scalar > mag(const dimensioned< Type > &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Ostream & indent(Ostream &os)
Indent stream.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dimensionedScalar acos(const dimensionedScalar &ds)