32bool Foam::triangulatedPatch::randomPoint
45 if (triWght_.empty() || c < triWght_.front() || c > triWght_.back())
55 for (label i = 0; i < triWght_.size() - 1; ++i)
57 if (c > triWght_[i] && c <= triWght_[i+1])
67 result = triFace_[trii].tri(
points).randomPoint(rnd);
68 facei = triFace_[trii].index();
69 celli = patch_.faceCells()[facei];
73 const polyMesh&
mesh = patch_.boundaryMesh().mesh();
74 const point& cc =
mesh.cellCentres()[celli];
77 const vector&
n = patch_.faceNormals()[facei];
78 result -= perturbTol_*
n*
mag(
n & (cc - result));
93 const scalar perturbTol
97 perturbTol_(perturbTol),
108 const word& patchName,
109 const scalar perturbTol
118void Foam::triangulatedPatch::triangulate
121 List<labelledTri>& tris
128 for (
const face&
f :
pp)
130 nTris +=
f.nTriangles();
142 for (
const auto& t : tfaces)
144 dynTris.emplace_back(t[0], t[1], t[2], facei);
149 tris.transfer(dynTris);
155void Foam::triangulatedPatch::update()
160 triangulate(patch_, triFace_);
168 triWght_.resize_nocopy(triFace_.size()+1);
170 auto iter = triWght_.begin();
173 scalar patchArea = 0;
177 for (
const auto& t : triFace_)
179 patchArea += t.mag(
points);
188 slice[myProci] = patchArea;
193 for (label i = 1; i < procSumArea.size(); ++i)
195 procSumArea[i] += procSumArea[i-1];
198 const scalar offset = procSumArea[myProci];
199 const scalar totalArea = procSumArea.back();
202 for (scalar& w : triWght_)
204 w = (w + offset) / totalArea;
217 if (triWght_.empty())
225 const scalar c = rnd.position<scalar>(triWght_.front(), triWght_.back());
227 return randomPoint(rnd, c, result, facei, celli);
241 const scalar c = rnd.
sample01<scalar>();
242 const bool ok = randomPoint(rnd, c, result, facei, celli);
247 label proci = valid.find(
true);
254 return randomLocalPoint(rnd, result, facei, celli);
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
SubList< scalar > subList
static void allGatherList(UList< T > &values, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Gather data, but keep individual values separate. Uses MPI_Allgather or manual communication.
Type position(const Type &start, const Type &end)
Return a sample on the interval [start,end].
Type sample01()
Return a sample whose components lie in the range [0,1].
label find(const T &val) const
Find index of the first occurrence of the value.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static List< T > listGatherValues(const T &localValue, const int communicator=UPstream::worldComm)
Gather individual values into list locations.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run.
@ broadcast
broadcast [MPI]
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
A face is a list of labels corresponding to mesh vertices.
Mesh consisting of general polyhedral cells.
A patch is a list of labels that address the faces in the global face list.
Performs a triangulation of a patch to return randomised point locations.
bool randomGlobalPoint(Random &rnd, point &result, label &facei, label &celli) const
Set a global random point on the patch.
triangulatedPatch(const polyPatch &patch, const scalar perturbTol)
Constructors.
bool randomLocalPoint(Random &rnd, point &result, label &facei, label &celli) const
Set a random point on the local patch.
A class for handling words, derived from Foam::string.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
vector point
Point is a vector.
List< bool > boolList
A List of bools.
vectorField pointField
pointField is a vectorField.
List< scalar > scalarList
List of scalar.