45 patchName_(patchName),
51 triCumulativeMagSf_(),
57 <<
"Requested patch " <<
patchName_ <<
" not found" <<
nl 58 <<
"Available patches are: " <<
mesh.boundaryMesh().names() <<
nl 68 patchName_(pib.patchName_),
69 patchId_(pib.patchId_),
70 patchArea_(pib.patchArea_),
71 patchNormal_(pib.patchNormal_),
72 cellOwners_(pib.cellOwners_),
73 triFace_(pib.triFace_),
74 triCumulativeMagSf_(pib.triCumulativeMagSf_),
75 sumTriMagSf_(pib.sumTriMagSf_)
87 cellOwners_ =
patch.faceCells();
94 nTris +=
f.nTriangles();
97 DynamicList<labelledTri> dynTriFace(nTris);
98 DynamicList<face> tris(8);
102 const face&
f =
patch[facei];
107 for (
const auto& t : tris)
114 triFace_.transfer(dynTriFace);
123 triCumulativeMagSf_.resize_nocopy(triFace_.size()+1);
125 auto iter = triCumulativeMagSf_.begin();
128 scalar patchArea = 0;
132 for (
const auto& t : triFace_)
134 patchArea += t.mag(
points);
138 sumTriMagSf_.resize_nocopy(numProc+1);
143 slice[myProci] = patchArea;
148 for (label i = 1; i < sumTriMagSf_.size(); ++i)
150 sumTriMagSf_[i] += sumTriMagSf_[i-1];
156 patchNormal_ =
patch.faceAreas()/magSf;
164 const scalar fraction01,
174 if (!cellOwners_.empty())
177 const label proci = whichProc(fraction01);
181 const scalar areaFraction = fraction01*patchArea_;
185 scalar offset = sumTriMagSf_[proci];
188 if (areaFraction > triCumulativeMagSf_[i] + offset)
196 facei = triFace_[trii].index();
197 cellOwner = cellOwners_[facei];
202 const point pf = triFace_[trii].tri(
points).randomPoint(rnd);
205 const scalar a = rnd.
position(scalar(0.1), scalar(0.5));
208 mag((pf - pc) & patchNormal_[facei])*patchNormal_[facei];
216 if (tetFacei == -1 ||tetPti == -1)
223 if (tetFacei == -1 ||tetPti == -1)
226 cellOwner = cellOwners_[facei];
230 const List<tetIndices> cellTetIs =
235 for (label teti=1; teti<cellTetIs.size()-1; teti++)
239 + cellTetIs[teti].tet(
mesh).mag()/V[cellOwner];
241 cTetVFrac.
last() = 1;
244 const scalar volFrac = rnd.
sample01<scalar>();
248 if (cTetVFrac[vfI] > volFrac)
254 position = cellTetIs[teti].tet(
mesh).randomPoint(rnd);
255 tetFacei = cellTetIs[teti].face();
256 tetPti = cellTetIs[teti].tetPt();
285 scalar fraction01 = rnd.globalSample01<scalar>();
287 return setPositionAndCell
302 const scalar areaFraction = fraction01*patchArea_;
307 if (areaFraction >= sumTriMagSf_[i])
List< scalar > scalarList
List of scalar.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
const word patchName_
Patch name.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
label whichProc(const scalar fraction01) const
Return the processor that has the location specified by the fraction.
constexpr char nl
The newline '\n' character (0x0a)
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface...
SubList< scalar > subList
Declare type of subList.
patchInjectionBase(const polyMesh &mesh, const word &patchName)
Construct from mesh and patch name.
virtual void updateMesh(const polyMesh &mesh)
Update patch geometry and derived info for injection locations.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
static List< tetIndices > cellTetIndices(const polyMesh &mesh, label cI)
Return the tet decomposition of the given cell, see.
#define forAll(list, i)
Loop across all elements in list.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
vectorField pointField
pointField is a vectorField.
Type sample01()
Return a sample whose components lie in the range [0,1].
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
void findCellFacePt(const point &p, label &celli, label &tetFacei, label &tetPti) const
Find the cell, tetFacei and tetPti for point p.
const label patchId_
Patch ID.
const vectorField & cellCentres() const
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
T & last()
Access last element of the list, position [size()-1].
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
static void allGatherList(UList< T > &values, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Gather data, but keep individual values separate. Uses MPI_Allgather or manual linear/tree communicat...
vector point
Point is a vector.
label setPositionAndCell(const fvMesh &mesh, const scalar fraction01, Random &rnd, vector &position, label &cellOwner, label &tetFacei, label &tetPti)
Set the injection position and owner cell, tetFace and tetPt.
Mesh data needed to do the Finite Volume discretisation.
const std::string patch
OpenFOAM patch number as a std::string.
void findTetFacePt(const label celli, const point &p, label &tetFacei, label &tetPti) const
Find the tetFacei and tetPti for point p in celli.
Mesh consisting of general polyhedral cells.
#define forAllReverse(list, i)
Reverse loop across all elements in list.
A patch is a list of labels that address the faces in the global face list.
Type position(const Type &start, const Type &end)
Return a sample on the interval [start,end].
void reduce(T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) using linear/tree communication schedule.
static constexpr const zero Zero
Global zero (0)