64 const label
patchId =
mesh.boundaryMesh().findPatchID(patchName);
71 Info<<
"Adding exposed internal faces to "
72 << (
patchId == -1 ?
"new" :
"existing")
73 <<
" patch: " << patchName <<
nl <<
endl;
87 nFaces +=
pbm[patchi].size();
91 List<topoDistanceData<label>> cellData(
mesh.nCells());
92 List<topoDistanceData<label>> faceData(
mesh.nFaces());
96 List<topoDistanceData<label>> patchData(nFaces);
104 patchFaces[nFaces] =
pp.start()+i;
118 mesh.globalData().nTotalCells()+1
125 bool haveWarned =
false;
128 if (!faceData[faceI].valid(deltaCalc.data()))
133 <<
"Did not visit some faces, e.g. face " << faceI
134 <<
" at " <<
mesh.faceCentres()[faceI] <<
nl
135 <<
"Using patch " <<
patchIDs[0] <<
" as nearest"
143 nearest[faceI] = faceData[faceI].data();
154template<
class FieldType>
175 Info<<
"Subsetting " << FieldType::typeName <<
" (";
198 auto& subField = subFields[nFields];
202 subField.rename(
io.name());
215template<
class FieldType>
237 Info<<
"Subsetting " << FieldType::typeName <<
" (";
260 auto& subField = subFields[nFields];
264 subField.rename(
io.name());
276template<
class TopoSet>
294 const TopoSet&
set = sets[seti];
304 if (
set.found(map[i]))
327int main(
int argc,
char *argv[])
331 "Create a mesh subset for a particular region of interest based on a"
332 " cellSet or cellZone(s) specified as the first command argument.\n"
333 "See setSet/topoSet utilities on how to select cells based on"
342 "The cellSet name, but with the -zone option this is interpreted"
343 " to be a cellZone selection by name(s) or regex.\n"
344 "Eg 'mixer' or '( mixer \"moving.*\" )'"
351 "Add exposed internal faces to specified patch"
352 " instead of \"oldInternalFaces\""
358 "Add exposed internal faces to closest of specified patches"
359 " instead of \"oldInternalFaces\""
365 "Exclude single or multiple patches from the -patches selection"
370 "Subset with cellZone(s) instead of cellSet."
371 " The command argument may be a list of words or regexs"
377 "Specify a time for the resulting mesh"
392 word meshInstance =
mesh.pointsInstance();
395 const bool useCellZone =
args.found(
"zone");
396 const bool overwrite =
args.found(
"overwrite");
397 const bool specifiedInstance =
args.readIfPresent
402 if (specifiedInstance)
405 meshInstance = fieldsInstance;
412 wordRes includePatches, excludePatches;
414 if (!
args.readListIfPresent<
wordRe>(
"patches", includePatches))
416 if (
args.found(
"patch"))
418 includePatches.resize(1);
419 includePatches.front() =
args.get<
word>(
"patch");
422 args.readListIfPresent<
wordRe>(
"exclude-patches", excludePatches);
424 if (includePatches.size() == 1 && includePatches.front().isLiteral())
427 exposedPatchIDs.front() =
428 getExposedPatchId(
mesh, includePatches.front());
430 else if (!includePatches.empty())
434 mesh.boundaryMesh().indices(includePatches, excludePatches);
437 const label nNonProcessor
439 mesh.boundaryMesh().nNonProcessor()
442 forAll(exposedPatchIDs, i)
444 if (exposedPatchIDs[i] > nNonProcessor)
446 exposedPatchIDs.resize(i);
451 const wordList allPatchNames(
mesh.boundaryMesh().names());
453 Info<<
"Adding exposed internal faces to nearest of patches:" <<
nl
458 if (exposedPatchIDs.empty())
461 <<
nl <<
"No patches matched. Patches: "
468 Info<<
"Adding exposed internal faces to patch \""
470 <<
"\" (created if necessary)" <<
nl
487 if (
mesh.cellZones().findIndex(zoneNames) == -1)
498 Info<<
"Using cellSet " << selectionName <<
nl <<
endl;
508 bitSet selectedCells =
512 :
mesh.cellZones().selection(zoneNames)
515 if (exposedPatchIDs.size() == 1)
518 subsetter.reset(selectedCells, exposedPatchIDs.front(), true);
523 labelList nearestExposedPatch(nearestPatch(mesh, exposedPatchIDs));
525 labelList exposedFaces
527 subsetter.getExposedFaces(selectedCells, true)
530 subsetter.setCellSubset
534 labelUIndList(nearestExposedPatch, exposedFaces)(),
541 cellCount[1] =
mesh.nCells();
544 Info<<
"Subset " << cellCount[0] <<
" of " << cellCount[1]
545 <<
" cells" <<
nl <<
nl;
553 #undef createSubsetFields
554 #define createSubsetFields(FieldType, Variable) \
555 PtrList<FieldType> Variable \
557 subsetFields<FieldType>(subsetter, objects) \
591 #undef createSubsetFields
592 #define createSubsetFields(FieldType, Variable) \
593 PtrList<FieldType> Variable \
595 subsetFields<FieldType>(subsetter, objects, pMesh) \
604 #undef createSubsetFields
618 objects.
remove(*cellSetPtr);
650 if (overwrite || specifiedInstance)
664 Info<<
"Writing subsetted mesh and fields to time " <<
runTime.timeName()
669 auto* subPointMeshPtr =
678 subPointMesh.
write();
683 for (
const auto&
fld : vScalarFlds) {
fld.write(); }
684 for (
const auto&
fld : vVectorFlds) {
fld.write(); }
685 for (
const auto&
fld : vSphTensorFlds) {
fld.write(); }
686 for (
const auto&
fld : vSymmTensorFlds) {
fld.write(); }
687 for (
const auto&
fld : vTensorFlds) {
fld.write(); }
690 for (
const auto&
fld : sScalarFlds) {
fld.write(); }
691 for (
const auto&
fld : sVectorFlds) {
fld.write(); }
692 for (
const auto&
fld : sSphTensorFlds) {
fld.write(); }
693 for (
const auto&
fld : sSymmTensorFlds) {
fld.write(); }
694 for (
const auto&
fld : sTensorFlds) {
fld.write(); }
697 for (
const auto&
fld : dScalarFlds) {
fld.write(); }
698 for (
const auto&
fld : dVectorFlds) {
fld.write(); }
699 for (
const auto&
fld : dSphTensorFlds) {
fld.write(); }
700 for (
const auto&
fld : dSymmTensorFlds) {
fld.write(); }
701 for (
const auto&
fld : dTensorFlds) {
fld.write(); }
704 for (
const auto&
fld : pScalarFlds) {
fld.write(); }
705 for (
const auto&
fld : pVectorFlds) {
fld.write(); }
706 for (
const auto&
fld : pSphTensorFlds) {
fld.write(); }
707 for (
const auto&
fld : pSymmTensorFlds) {
fld.write(); }
708 for (
const auto&
fld : pTensorFlds) {
fld.write(); }
Field reading functions for post-processing utilities.
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())
const polyBoundaryMesh & pbm
Wave propagation of information through grid. Every iteration information goes through one layer of c...
A 1D vector of objects of type <T> with a fixed length <N>.
DimensionedField< scalar, volMesh > Internal
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
autoPtr< IOobject > remove(const IOobject &io)
Remove object from the list by its IOobject::name().
@ NO_REGISTER
Do not request registration (bool: false).
@ READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
static FOAM_NO_DANGLING_REFERENCE const pointMesh & New(const polyMesh &mesh, Args &&... args)
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
void resize_null(const label newLen)
Set the addressed list to the given size, deleting all existing entries. Afterwards the list contains...
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
void size(const label n)
Older name for setAddressableSize.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
label size() const noexcept
The number of entries in the list.
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
T & emplace(Args &&... args)
Reset with emplace construction. Return reference to the new content.
Holds a reference to the original mesh (the baseMesh) and optionally to a subset of that mesh (the su...
static word exposedPatchName
Name for exposed internal faces (default: oldInternalFaces).
const fvMesh & baseMesh() const noexcept
Original mesh.
const labelList & faceMap() const
Return face map.
const labelList & cellMap() const
Return cell map.
static tmp< DimensionedField< Type, volMesh > > interpolate(const DimensionedField< Type, volMesh > &, const fvMesh &sMesh, const labelUList &cellMap)
Map volume internal (dimensioned) field.
const fvMesh & subMesh() const
Return reference to subset mesh.
const labelList & pointMap() const
Return point map.
Extends Foam::fvMeshSubset with two-step subsetting (uses polyTopoChange modification).
Mesh data needed to do the Finite Volume discretisation.
virtual const objectRegistry & thisDb() const
Return the object registry - resolve conflict polyMesh/lduMesh.
const Time & time() const
Return the top-level database.
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
const Time & time() const noexcept
Return time registry.
const Type * findObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Mesh representing a set of points created from polyMesh.
void setInstance(const fileName &instance, const IOobjectOption::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
const objectRegistry & thisDb() const
Return database. For now is its polyMesh.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
Mesh consisting of general polyhedral cells.
void setInstance(const fileName &instance, const IOobjectOption::writeOption wOpt=IOobject::AUTO_WRITE)
Set the instance for mesh files.
const fileName & facesInstance() const
Return the current instance directory for faces.
A patch is a list of labels that address the faces in the global face list.
label nCells() const noexcept
Number of mesh cells.
static void removeFiles(const polyMesh &mesh)
Helper: remove all procAddressing files from mesh instance.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
For use with FaceCellWave. Determines topological distance to starting faces. Templated on passive tr...
static void setInstance(const fileName &instance, Container &items)
Helper: set instance on all items in container.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
A List of wordRe with additional matching capabilities.
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
bitSet create(const label n, const labelHashSet &locations, const bool on=true)
Create a bitSet with length n with the specified on locations.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
wordList ReadFields(const typename GeoMesh::Mesh &mesh, const IOobjectList &objects, PtrList< GeometricField< Type, PatchField, GeoMesh > > &fields, const bool syncPar=true, const bool readOldTime=false)
Read Geometric fields of templated type.
List< word > wordList
List of word.
GeometricField< vector, fvPatchField, volMesh > volVectorField
GeometricField< tensor, pointPatchField, pointMesh > pointTensorField
GeometricField< scalar, pointPatchField, pointMesh > pointScalarField
List< label > labelList
A List of labels.
GeometricField< sphericalTensor, pointPatchField, pointMesh > pointSphericalTensorField
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
messageStream Info
Information stream (stdout output on master, null elsewhere).
GeometricField< vector, pointPatchField, pointMesh > pointVectorField
List< T > subset(const BoolListType &select, const UList< T > &input, const bool invert=false)
Extract elements of the input list when select is true.
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
GeometricField< symmTensor, pointPatchField, pointMesh > pointSymmTensorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
GeometricField< tensor, fvsPatchField, surfaceMesh > surfaceTensorField
GeometricField< sphericalTensor, fvPatchField, volMesh > volSphericalTensorField
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.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
GeometricField< sphericalTensor, fvsPatchField, surfaceMesh > surfaceSphericalTensorField
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
GeometricField< symmTensor, fvsPatchField, surfaceMesh > surfaceSymmTensorField
constexpr char nl
The newline '\n' character (0x0a).
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.