44 namespace functionObjects
93 Foam::labelList Foam::functionObjects::fieldValues::surfaceFieldValue::patchis
105 if (patchiis.empty())
108 <<
type() <<
' ' << this->
name() <<
": "
110 <<
"(" << patchNames[i] <<
"):" <<
nl
112 <<
". Valid patch names are: "
117 patchis.append(patchiis);
124 void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
126 const faceZone& zone = faceZonePtr_->zone();
129 mesh_.polyBFacePatches();
130 mesh_.polyBFacePatchFaces();
132 DynamicList<label> faceIds(zone.size());
133 DynamicList<label> facePatchIds(zone.size());
134 DynamicList<label> faceSigns(zone.size());
138 const label facei = zone[zoneFacei];
139 const label faceSign = zone.flipMap()[zoneFacei] ? -1 : 1;
141 if (mesh_.isInternalFace(facei))
143 faceIds.append(facei);
144 facePatchIds.append(-1);
145 faceSigns.append(faceSign);
149 const label bFacei = facei - mesh_.nInternalFaces();
152 const labelUList patchFaces = mesh_.polyBFacePatchFaces()[bFacei];
157 const fvPatch& fvp = mesh_.boundary()[
patches[i]];
160 isType<processorFvPatch>(fvp)
161 && refCast<const processorFvPatch>(fvp).neighbour()
167 faceIds.append(patchFaces[i]);
168 facePatchIds.append(
patches[i]);
169 faceSigns.append(faceSign);
174 faceId_.transfer(faceIds);
175 facePatchId_.transfer(facePatchIds);
176 faceSign_.transfer(faceSigns);
182 void Foam::functionObjects::fieldValues::surfaceFieldValue::setPatchesFaces()
184 const labelList patchis = this->patchis(patchNames_);
187 facePatchId_.clear();
193 const fvPatch& fvp = mesh_.boundary()[
patchi];
197 faceSign_.append(
labelList(fvp.size(), 1));
201 forAll(mesh_.boundary(), pcPatchj)
203 const fvPatch& pcFvp = mesh_.boundary()[pcPatchj];
207 isA<processorCyclicFvPatch>(pcFvp)
208 && refCast<const processorCyclicFvPatch>(pcFvp).referPatchIndex()
213 facePatchId_.append(
labelList(pcFvp.size(), pcPatchj));
214 faceSign_.append(
labelList(pcFvp.size(), 1));
224 Foam::functionObjects::fieldValues::surfaceFieldValue::setSampledSurfaceFaces()
226 surfacePtr_().update();
228 nFaces_ =
returnReduce(surfacePtr_().faces().size(), sumOp<label>());
232 void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
244 if (facePatchId_[i] != -1)
247 globalFacesIs[i] += mesh_.boundaryMesh()[
patchi].start();
254 IndirectList<face>(mesh_.faces(), globalFacesIs),
268 nFaces += allFaces[proci].size();
269 nPoints += allPoints[proci].size();
272 faces.setSize(nFaces);
283 const face&
f = fcs[i];
284 face& newF = faces[nFaces++];
285 newF.setSize(
f.size());
304 const faceList& fcs = allFaces[proci];
307 const face&
f = fcs[i];
308 face& newF = faces[nFaces++];
309 newF.setSize(
f.size());
338 points.transfer(newPoints);
347 void Foam::functionObjects::fieldValues::surfaceFieldValue::
348 combineSurfaceGeometry
354 if (selectionType_ == selectionTypes::sampledSurface)
356 const sampledSurface&
s = surfacePtr_();
361 scalar mergeDim = 1
e-10*mesh_.bounds().mag();
370 SubList<face>(
s.faces(),
s.faces().size()),
388 Foam::functionObjects::fieldValues::surfaceFieldValue::area()
const
390 if (selectionType_ == selectionTypes::sampledSurface)
392 return gSum(surfacePtr_().magSf());
396 return gSum(filterField(mesh_.magSf()));
408 if (operation_ != operationType::none)
410 writeCommented(
file(),
"Selection");
413 << selectionTypeNames[selectionType_] <<
"("
414 << selectionName_.c_str() <<
")" <<
endl;
416 writeHeaderValue(
file(),
"Faces", nFaces_);
418 writeHeaderValue(
file(),
"Area", area_);
420 writeCommented(
file(),
"Time");
422 if (writeNFaces_)
file() <<
tab <<
"Faces";
423 if (writeArea_)
file() <<
tab <<
"Area";
428 <<
tab << operationTypeNames_[operation_]
429 <<
"(" << fields_[fieldi] <<
")";
451 return processValuesTypeType
475 case operationType::areaNormalAverage:
477 result =
gSum(weights*values & Sf)/
gSum(
mag(weights*Sf));
480 case operationType::areaNormalIntegrate:
482 result =
gSum(weights*values & Sf);
496 switch (selectionType_)
498 case selectionTypes::faceZone:
499 if (faceZonePtr_->zone().moveUpdate()) setFaceZoneFaces();
501 case selectionTypes::patch:
504 case selectionTypes::sampledSurface:
505 surfacePtr_->expire();
506 setSampledSurfaceFaces();
510 area_ = nFaces_ ? area() : NaN;
516 switch (selectionType_)
518 case selectionTypes::faceZone:
519 if (!faceZonePtr_->zone().moveUpdate()) setFaceZoneFaces();
521 case selectionTypes::patch:
525 case selectionTypes::sampledSurface:
543 surfaceWriterPtr_(nullptr),
544 selectionType_(selectionTypeNames.select(
dict)),
545 selectionName_(
string::null),
546 operation_(operationTypeNames_.
read(
dict.lookup(
"operation"))),
550 writeNFaces_(
dict.lookupOrDefault(
"writeNumberOfFaces", false)),
551 writeArea_(
dict.lookupOrDefault(
"writeArea", false)),
552 faceZonePtr_(nullptr),
570 surfaceWriterPtr_(nullptr),
571 selectionType_(selectionTypeNames.select(
dict)),
572 selectionName_(
string::null),
573 operation_(operationTypeNames_.
read(
dict.lookup(
"operation"))),
577 writeNFaces_(
dict.lookupOrDefault(
"writeNumberOfFaces", false)),
578 writeArea_(
dict.lookupOrDefault(
"writeArea", false)),
579 faceZonePtr_(nullptr),
605 const word selection(selectionTypeNames[selectionType_]);
607 switch (selectionType_)
609 case selectionTypes::faceZone:
615 case selectionTypes::patch:
623 ?
'"' + patchName +
'"'
632 const labelList patchis = this->patchis(patchNames_);
634 selectionName_.clear();
638 const fvPatch& fvp = mesh_.boundary()[patchis[i]];
639 selectionName_.append((i ?
" " :
"") + fvp.
name());
644 case selectionTypes::sampledSurface:
648 selectionName_ = surfacePtr_().name();
654 if (
dict.found(
"weightFields"))
656 dict.lookup(
"weightFields") >> weightFieldNames_;
658 else if (
dict.found(
"weightField"))
660 weightFieldNames_.setSize(1);
662 dict.lookup(
"weightField") >> weightFieldNames_[0];
667 const word surfaceFormat(
dict.lookup(
"surfaceFormat"));
669 surfaceWriterPtr_.reset
679 Info<<
" number of faces = " << nFaces_ <<
nl;
682 Info<<
" area = " << area_ <<
nl;
684 Info<<
" operation = " << operationTypeNames_[operation_] <<
nl;
685 if (weightFieldNames_.size() == 1)
687 Info<<
" weight field = " << weightFieldNames_[0] <<
nl;
689 if (weightFieldNames_.size() > 1)
691 Info<<
" weight fields =";
692 forAll(weightFieldNames_, i)
Info<<
' ' << weightFieldNames_[i];
709 bool anyFields =
false;
712 #define validFieldType(fieldType, none) \
713 anyFields = anyFields || validField<fieldType>(fields_[i]);
715 #undef validFieldType
717 if (!anyFields && fields_.size() > 1)
719 cannotFindObjects(fields_);
723 if (anyFields && operation_ != operationType::none)
729 if (selectionType_ == selectionTypes::sampledSurface)
731 surfacePtr_().update();
735 if (anyFields && operation_ != operationType::none &&
Pstream::master())
741 if (anyFields && operation_ != operationType::none &&
Pstream::master())
754 Log <<
" number of faces = " << nFaces_ <<
endl;
758 Log <<
" area = " << area_ <<
endl;
764 selectionType_ == selectionTypes::sampledSurface
769 forAll(weightFieldNames_, i)
771 weights *= getFieldValues<scalar>(weightFieldNames_[i]);
775 selectionType_ == selectionTypes::sampledSurface
777 : (signs*filterField(mesh_.Sf()))()
781 #define DeclareValues(fieldType, nullArg) \
782 PtrList<Field<fieldType>> fieldType##Values(fields_.size());
790 const word& fieldName = fields_[i];
793 #define writeValuesFieldType(fieldType, none) \
795 const bool typeOk = validField<fieldType>(fieldName); \
799 tmp<Field<fieldType>> values = \
800 getFieldValues<fieldType>(fieldName); \
802 writeValues<fieldType> \
813 fieldType##Values.set \
816 getFieldValues<fieldType>(fieldName).ptr() \
824 #undef writeValuesFieldType
828 cannotFindObject(fieldName);
833 if (anyFields && operation_ != operationType::none &&
Pstream::master())
845 if (selectionType_ == selectionTypes::sampledSurface)
847 combineSurfaceGeometry(faces,
points);
851 combineMeshGeometry(faces,
points);
856 surfaceWriterPtr_->write
858 baseFileDir()/
name()/time_.name(),
859 word(selectionTypeNames[selectionType_])
863 ? selectionName_.replace(
" ",
",").c_str()
864 : selectionName_.c_str()
891 if (selectionType_ == selectionTypes::faceZone)
893 faceZonePtr_->movePoints();
908 if (selectionType_ == selectionTypes::faceZone)
910 faceZonePtr_->topoChange(map);
925 if (selectionType_ == selectionTypes::faceZone)
927 faceZonePtr_->mapMesh(map);
942 if (selectionType_ == selectionTypes::faceZone)
944 faceZonePtr_->distribute(map);
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Initialise the NamedEnum HashTable from the static list of names.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
static bool master(const label communicator=0)
Am I the master process.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static bool & parRun()
Is this a parallel run?
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Abstract base-class for Time/database functionObjects.
virtual const word & type() const =0
Runtime type information.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void movePoints(const polyMesh &mesh)
Update topology using the given map.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
const word & name() const
Return the name of this functionObject.
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
Base class for field value -based function objects.
const dictionary & dict() const
Return the reference to the construction dictionary.
virtual bool read(const dictionary &dict)
Read from dictionary.
virtual bool write()
Write.
Surface, patch or faceZone selection class.
surfaceFieldValue(const word &name, const Time &runTime, const dictionary &dict)
Construct from name, Time and dictionary.
void changeMesh()
Update the surface following mesh change.
static const NamedEnum< selectionTypes, 4 > selectionTypeNames
Selection type names.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
void moveMesh()
Update the surface following mesh motion.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
static const NamedEnum< operationType, 15 > operationTypeNames_
Operation type names.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
selectionTypes selectionType_
Selection type.
virtual void writeFileHeader(const label i)
Output file header information.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
bool processValues(const Field< Type > &values, const scalarField &signs, const scalarField &weights, const vectorField &Sf, ResultType &result) const
Apply the operation to the values, and return true if successful.
virtual bool write()
Calculate and write.
virtual ~surfaceFieldValue()
Destructor.
virtual bool read(const dictionary &)
Read from dictionary.
selectionTypes
Selection type enumeration.
operationType
Operation type enumeration.
const fvMesh & mesh_
Reference to the fvMesh.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
virtual const word & name() const
Return name.
faceZone selection or generation class
Registry of regIOobjects.
wordList names() const
Return the list of patch names.
labelList findIndices(const wordRe &, const bool usePatchGroups=true) const
Return patch indices for all matches. Optionally matches patchGroups.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
const polyMesh & mesh() const
Return polyMesh.
Class containing mesh-to-mesh mapping information.
const polyMesh & mesh() const
Return polyMesh.
Mesh consisting of general polyhedral cells.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const polyMesh & mesh() const
Return polyMesh.
static autoPtr< sampledSurface > New(const word &name, const polyMesh &, const dictionary &)
Return a reference to the selected surface.
A class for handling character strings derived from std::string.
static autoPtr< surfaceWriter > New(const word &writeType, const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Select given write options.
A wordRe is a word, but can also have a regular expression for matching words.
static bool isPattern(const string &)
Test string for regular expression meta characters.
A class for handling words, derived from string.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const fvPatchList & patches
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(fieldValueDelta, 0)
addToRunTimeSelectionTable(functionObject, fieldValueDelta, dictionary)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Type gSum(const FieldField< Field, Type > &f)
bool read(const char *, int32_t &)
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Omanip< int > setw(const int i)
vectorField pointField
pointField is a vectorField.
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
PrimitivePatch< SubList< face >, const pointField & > primitivePatch
Addressing for a faceList slice.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
label mergePoints(const UList< Type > &points, const scalar mergeTol, const bool verbose, labelList &pointMap, const Type &origin=Type::zero)
Sorts and merges points. All points closer than/equal mergeTol get merged.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
List< wordRe > wordReList
A List of wordRe (word or regular expression)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
Foam::indirectPrimitivePatch.
UList< label > labelUList
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
wordList patchNames(nPatches)
#define ValuesParameter(fieldType, nullArg)
#define DeclareValues(fieldType, nullArg)
#define writeValuesFieldType(fieldType, none)
#define validFieldType(fieldType, none)