46 os <<
tab << binPoints[pointi].x();
53 os <<
tab << binPoints[pointi].y();
60 os <<
tab << binPoints[pointi].z();
67 for (label i = 0; i <
nBin_; ++i)
94 const word& fieldName = fieldNames_[fieldi];
98 const VolFieldType* fieldPtr = mesh_.findObject<VolFieldType>(fieldName);
105 if (writeToFile() && !writtenHeader_)
107 writeFileHeader<Type>(filePtrs_[fieldi]);
110 const VolFieldType&
fld = *fieldPtr;
123 if (decomposePatchValues_)
128 List<List<Type>> data(nField);
129 for (
auto& binList : data)
131 binList.resize(nBin_,
Zero);
134 const auto whichBin = [&](
const scalar d) -> label
136 if (d >= binLimits_.min() && d <= binLimits_.max())
141 (d - binLimits_.min())/binWidth_
143 return min(
max(bini, 0), nBin_ - 1);
152 for (
const label zonei : cellZoneIDs_)
154 const cellZone& cZone = mesh_.cellZones()[zonei];
156 for (
const label celli : cZone)
158 const label bini = whichBin(mesh_.C()[celli] & binDir_);
162 data[0][bini] +=
fld[celli];
167 for (
const label patchi : patchIDs_)
169 const polyPatch&
pp = mesh_.boundaryMesh()[patchi];
170 const vectorField np(mesh_.boundary()[patchi].nf());
172 const auto&
pts =
pp.faceCentres();
176 const label bini = whichBin(
pts[facei] & binDir_);
180 const Type& v =
fld.boundaryField()[patchi][facei];
182 if (!decomposePatchValues(data, bini, v, np[facei]))
192 for (
auto& binList : data)
194 reduce(binList, sumOp<List<Type>>());
200 writeBinnedData(data, filePtrs_[fieldi]);
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Generic GeometricField class.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool & parRun() noexcept
Test if this a parallel run.
string writeComponents(const word &stem) const
Helper function to construct a string description for a given type.
const fvMesh & mesh_
Reference to the mesh.
PtrList< OFstream > filePtrs_
List of file pointers; 1 file per field.
void writeBinnedData(List< List< Type > > &data, Ostream &os) const
Write binned data to stream.
wordList fieldNames_
Names of operand fields.
label nBin_
Total number of bins.
bool decomposePatchValues(List< List< Type > > &data, const label bini, const Type &v, const vector &n) const
Helper function to decompose patch values into normal and tangential components.
bool decomposePatchValues_
Decompose patch values into normal and tangential components.
labelList cellZoneIDs_
Indices of operand cell zones.
labelList patchIDs_
Indices of operand patches.
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
bool writtenHeader_
Flag to identify whether the header has been written.
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
virtual bool writeToFile() const
Flag to allow writing to file.
A patch is a list of labels that address the faces in the global face list.
A class for handling words, derived from Foam::string.
OBJstream os(runTime.globalPath()/outputName)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Field< vector > vectorField
Specialisation of Field<T> for vector.
static constexpr const zero Zero
Global zero (0).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
constexpr char nl
The newline '\n' character (0x0a).
constexpr char tab
The tab '\t' character(0x09).
#define forAll(list, i)
Loop across all elements in list.