40 namespace functionObjects
115 return layeri %
faceis_.size();
123 const label nActiveLayers,
176 const label nActiveLayers,
182 faceCuts_(nActiveLayers),
183 faceCutAreas_(nActiveLayers)
212 for (
label sidei = 0; sidei <= 1; ++ sidei)
263 const label nActiveLayers,
270 pointFs_(nActiveLayers),
271 faceFs_(nActiveLayers),
272 faceCutFs_(nActiveLayers)
315 label fi = (layeri > 0 ? 0 : 1);
331 label fi = (layeri > 0 ? 0 : 1);
336 for (
label sidei = 0; sidei <= 1; ++ sidei)
339 fi == 0 && sidei == 0 ? layeri - 1
340 : fi == 1 && sidei == 1 ? layeri + 1
343 if (layerj < 0 || layerj >
plotXs_.
size() - 1)
continue;
359 const scalar magSqrArea =
magSqr(integral.
first());
390 Foam::fileName Foam::functionObjects::cutLayerAverage::outputPath()
const
402 Foam::functionObjects::cutLayerAverage::calcNonInterpolatingWeights
414 const scalarField& cellVolumes = mesh_.cellVolumes();
415 const faceList& faces = mesh_.faces();
417 const pointField& faceCentres = mesh_.faceCentres();
422 label nActiveLayers = 0;
425 forAll(zoneCellMinOrder, zoneCellMinOrderi)
427 const label zoneCelli = zoneCellMinOrder[zoneCellMinOrderi];
430 while (zoneCellMinXs[zoneCelli] > plotXs[layeri + 1]) layeri ++;
433 label layerj = layeri;
434 while (zoneCellMaxXs[zoneCelli] > plotXs[layerj]) layerj ++;
436 nActiveLayers =
max(nActiveLayers, layerj - layeri);
441 faceCutData fcd(mesh_, nActiveLayers, pointXs, plotXs);
444 DynamicList<weight> dynWeights(zone_.nCells()*2);
446 forAll(zoneCellMinOrder, zoneCellMinOrderi)
448 const label zoneCelli = zoneCellMinOrder[zoneCellMinOrderi];
449 const label celli = zone_.celli(zoneCelli);
453 while (zoneCellMinXs[zoneCelli] > plotXs[layeri + 1])
460 label layerj = layeri;
461 while (zoneCellMaxXs[zoneCelli] > plotXs[layerj])
464 fcd.cache(celli, layerj);
465 fcd.cache(celli, layerj + 1);
468 dynWeights.append({celli, layerj, cellVolumes[celli]});
471 if (zoneCellMinXs[zoneCelli] < plotXs[layerj])
473 dynWeights.last().value -=
484 fcd.faceCuts(layerj),
491 fcd.faceCutAreas(layerj)[0],
500 if (zoneCellMaxXs[zoneCelli] > plotXs[layerj + 1])
502 dynWeights.last().value -=
513 fcd.faceCuts(layerj + 1),
520 fcd.faceCutAreas(layerj + 1)[1],
533 List<weight> weights;
534 weights.transfer(dynWeights);
542 layerWeightSums[weights[weighti].layeri] += weights[weighti].value;
550 weights[weighti].value /=
551 (layerWeightSums[weights[weighti].layeri] + vSmall);
560 Foam::functionObjects::cutLayerAverage::calcInterpolatingWeights
572 const scalarField& cellVolumes = mesh_.cellVolumes();
573 const faceList& faces = mesh_.faces();
575 const pointField& faceCentres = mesh_.faceCentres();
580 label nActiveLayers = 0;
583 forAll(zoneCellMinOrder, zoneCellMinOrderi)
585 const label zoneCelli = zoneCellMinOrder[zoneCellMinOrderi];
588 while (zoneCellMinXs[zoneCelli] > plotXs[layeri + 1])
594 label layerj = layeri;
595 while (zoneCellMaxXs[zoneCelli] > plotXs[
max(layerj - 1, 0)])
600 nActiveLayers =
max(nActiveLayers, layerj - layeri + 1);
605 faceCutData fcd(mesh_, nActiveLayers, pointXs, plotXs);
606 faceFsData ffs(fcd, mesh_, nActiveLayers, pointXs, plotXs);
609 DynamicList<weight> dynWeights(zone_.nCells()*2);
611 forAll(zoneCellMinOrder, zoneCellMinOrderi)
613 const label zoneCelli = zoneCellMinOrder[zoneCellMinOrderi];
614 const label celli = zone_.celli(zoneCelli);
618 while (zoneCellMinXs[zoneCelli] > plotXs[layeri + 1])
620 if (layeri != 0) fcd.clear(layeri - 1);
626 label layerj = layeri;
627 while (zoneCellMaxXs[zoneCelli] > plotXs[
max(layerj - 1, 0)])
630 if (layerj != 0) fcd.cache(celli, layerj - 1);
631 fcd.cache(celli, layerj);
632 if (layerj != nLayers_ - 1) fcd.cache(celli, layerj + 1);
633 ffs.cache(celli, layerj);
636 dynWeights.append({celli, layerj, 0});
648 fcd.faceCuts(layerj),
657 && zoneCellMinXs[zoneCelli] < plotXs[layerj]
660 const scalar cellVF =
667 ffs.faceFs(layerj)[0]
671 dynWeights.last().value += cellVF;
674 if (zoneCellMinXs[zoneCelli] < plotXs[layerj - 1])
676 dynWeights.last().value -=
682 cellVF/cellVolumes[celli],
688 fcd.faceCuts(layerj - 1),
695 ffs.faceFs(layerj)[0],
696 fcd.faceCutAreas(layerj - 1)[0],
697 ffs.faceCutFs(layerj)[0][0],
699 ffs.pointFs(layerj)[0],
707 if (zoneCellMaxXs[zoneCelli] > plotXs[layerj])
709 dynWeights.last().value -=
715 cellVF/cellVolumes[celli],
720 ffs.faceFs(layerj)[0],
721 fcd.faceCutAreas(layerj)[1],
722 ffs.faceCutFs(layerj)[0][1],
724 ffs.pointFs(layerj)[0],
735 layerj < nLayers_ - 1
736 && zoneCellMaxXs[zoneCelli] > plotXs[layerj]
739 const scalar cellVF =
746 ffs.faceFs(layerj)[1]
750 dynWeights.last().value += cellVF;
753 if (zoneCellMinXs[zoneCelli] < plotXs[layerj])
755 dynWeights.last().value -=
761 cellVF/cellVolumes[celli],
766 ffs.faceFs(layerj)[1],
767 fcd.faceCutAreas(layerj)[0],
768 ffs.faceCutFs(layerj)[1][0],
770 ffs.pointFs(layerj)[1],
778 if (zoneCellMaxXs[zoneCelli] > plotXs[layerj + 1])
780 dynWeights.last().value -=
786 cellVF/cellVolumes[celli],
792 fcd.faceCuts(layerj + 1),
799 ffs.faceFs(layerj)[1],
800 fcd.faceCutAreas(layerj + 1)[1],
801 ffs.faceCutFs(layerj)[1][1],
803 ffs.pointFs(layerj)[1],
816 List<weight> weights;
817 weights.transfer(dynWeights);
827 layerWeightSums[weights[weighti].layeri] += weights[weighti].value;
835 weights[weighti].value /=
836 (layerWeightSums[weights[weighti].layeri] + vSmall);
845 weights[weighti].layeri == 0
846 || weights[weighti].layeri == nLayers_ - 1
849 weights[weighti].value *= 2;
859 Foam::functionObjects::cutLayerAverage::calcWeights
871 ? calcInterpolatingWeights
880 : calcNonInterpolatingWeights
892 void Foam::functionObjects::cutLayerAverage::calcWeights()
895 const faceList& faces = mesh_.faces();
901 const label nPlot = interpolate_ ? nLayers_ : nLayers_ + 1;
904 tmp<pointScalarField> tdistance =
906 ? tmp<pointScalarField>(
nullptr)
916 tmp<scalarField> tpointXs =
919 : tmp<scalarField>(tdistance().primitiveField());
924 scalarField zoneCellMaxXs(zone_.nCells(), -vGreat);
925 forAll(zoneCellMinXs, zoneCelli)
927 const label celli = zone_.celli(zoneCelli);
931 forAll(faces[facei], facePointi)
933 const label pointi = faces[facei][facePointi];
934 zoneCellMinXs[zoneCelli] =
935 min(zoneCellMinXs[zoneCelli], pointXs[pointi]);
936 zoneCellMaxXs[zoneCelli] =
937 max(zoneCellMaxXs[zoneCelli], pointXs[pointi]);
943 labelList zoneCellMinOrder(zone_.nCells());
956 #define DeclareTypeFieldValues(Type, nullArg) \
957 PtrList<Field<Type>> Type##FieldValues;
959 #undef DeclareTypeFieldValues
963 for (
label iteri = 0; iteri < nOptimiseIter_ + debug; ++ iteri)
966 const List<weight> weights =
978 applyWeights<scalar>(weights, (1/mesh_.V())())
983 const label nFields0 = (2 + !interpolate_)*iteri;
984 const label nFields = (2 + !interpolate_)*(iteri + 1);
987 #define ResizeTypeFieldValues(Type, nullArg) \
988 Type##FieldValues.resize(nFields);
990 #undef ResizeTypeFieldValues
994 const SubField<scalar> distance0s(plotXs, nLayers_);
995 const SubField<scalar> distance1s(plotXs, nLayers_, 1);
998 scalarFieldValues.set(nFields0, (distance0s + distance1s)/2);
1001 scalarFieldValues.set(nFields0 + 1, distance1s - distance0s);
1006 scalarFieldValues.set(nFields0,
new scalarField(plotXs));
1010 scalarFieldValues.set(nFields - 1,
new scalarField(layerCounts));
1012 if (iteri == nOptimiseIter_)
break;
1017 for (
label ploti = 0; ploti < nPlot - 1; ++ ploti)
1019 plotSumCounts[ploti + 1] =
1020 plotSumCounts[ploti]
1023 ? (layerCounts[ploti + 1] + layerCounts[ploti])/2
1024 : layerCounts[ploti]
1029 const scalar plotDeltaCount = plotSumCounts.last()/(nPlot - 1);
1034 plotXs.first() =
xMin;
1036 for (
label ploti0 = 0; ploti0 < nPlot - 1; ++ ploti0)
1041 && plotSumCounts[ploti0 + 1] > ploti*plotDeltaCount
1045 (ploti*plotDeltaCount - plotSumCounts[ploti0])
1046 /(plotSumCounts[ploti0 + 1] - plotSumCounts[ploti0]);
1048 plotXs[ploti] = (1 -
f)*plot0Xs[ploti0] +
f*plot0Xs[ploti0 + 1];
1053 plotXs.last() =
xMax;
1058 mkDir(outputPath());
1063 typeName +
"_count",
1097 const SubField<scalar> distance0s(plotXs, nLayers_);
1098 const SubField<scalar> distance1s(plotXs, nLayers_, 1);
1099 layerDistances_.reset(((distance0s + distance1s)/2).ptr());
1100 layerThicknesses_.reset((distance1s - distance0s).ptr());
1104 layerPositions_.reset
1106 applyWeights<vector>(weights_, mesh_.C()).ptr()
1111 const List<weight> weights =
1127 mesh_.time().name(),
1136 const weight& w = weights[weighti];
1139 w.value/mesh_.V()[w.celli];
1142 Info<<
name() <<
": Writing " << layers.name() <<
endl;
1149 template<
class Type>
1151 Foam::functionObjects::cutLayerAverage::applyWeights
1161 tLayerValues.
ref()[weights[weighti].layeri] +=
1162 weights[weighti].value*cellValues[weights[weighti].celli];
1168 return tLayerValues;
1172 void Foam::functionObjects::cutLayerAverage::clear()
1175 layerDistances_.clear();
1176 layerThicknesses_.clear();
1177 layerPositions_.clear();
1186 const Time& runTime,
1209 const bool haveDirection =
dict.found(
"direction");
1210 const bool haveDistance =
dict.found(
"distance");
1211 if (haveDirection == haveDistance)
1214 <<
"keywords direction and distance both "
1215 << (haveDirection ?
"" :
"un") <<
"defined in "
1216 <<
"dictionary " <<
dict.name()
1219 else if (haveDirection)
1224 else if (haveDistance)
1227 distanceName_ =
dict.lookup<
word>(
"distance");
1230 nLayers_ =
dict.lookup<
label>(
"nPoints");
1232 interpolate_ =
dict.lookupOrDefault<
bool>(
"interpolate",
false);
1248 nOptimiseIter_ =
dict.lookupOrDefault(
"nOptimiseIter", 2);
1262 result.
append(distanceName_);
1277 if (!weights_.valid())
1282 const bool writeThickness =
1310 cannotFindObject(fields_[fieldi]);
1315 #define DeclareTypeFieldValues(Type, nullArg) \
1316 PtrList<Field<Type>> Type##FieldValues(fieldNames.size());
1318 #undef DeclareTypeFieldValues
1321 scalarFieldValues.set(0,
new scalarField(layerThicknesses_));
1325 #define CollapseTypeFields(Type, GeoField) \
1326 if (mesh_.foundObject<GeoField<Type>>(fieldNames[fieldi])) \
1328 const GeoField<Type>& field = \
1329 mesh_.lookupObject<GeoField<Type>>(fieldNames[fieldi]); \
1331 Type##FieldValues.set \
1334 applyWeights<Type>(weights_, field) \
1339 #undef CollapseTypeFields
1345 mkDir(outputPath());
1376 if (&
mesh == &mesh_)
1389 if (&map.
mesh() == &mesh_)
1391 zone_.topoChange(map);
1402 if (&map.
mesh() == &mesh_)
1415 if (&map.
mesh() == &mesh_)
1417 zone_.distribute(map);
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
static cellEdgeAddressingList & New(const word &name, const polyMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
Pre-declare SubField and related Field type.
Generic GeometricField class.
DimensionedField< Type, GeoMesh, PrimitiveField > Internal
Type of the internal field from which this GeometricField is derived.
void append(const T &)
Append an element at the end of the list.
void resize(const label)
Alias for setSize(const label)
void size(const label)
Override size to be inconsistent with allocated storage.
virtual Ostream & write(const char)=0
Write character.
An ordered pair of two objects of type <Type> with first() and second() elements.
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
bool set(const label) const
Is element set.
fileName globalPath() const
Return the global path.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A 2-tuple for storing two objects of different types.
const Type2 & second() const
Return second.
const Type1 & first() const
Return first.
A List with indirect addressing.
static bool master(const label communicator=0)
Am I the master process.
static const direction nComponents
Number of components in this vector space.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Holds list of sampling positions.
static const NamedEnum< axisType, 6 > axisTypeNames_
String representation of axis enums.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
const word & name() const
Return const reference to name.
Class to manage face cut data.
const Pair< vectorField > & faceCutAreas(const label layeri) const
const List< List< labelPair > > & faceCuts(const label layeri) const
void cache(const label celli, const label layeri)
faceCutData(const fvMesh &mesh, const label nActiveLayers, const scalarField &pointXs, const scalarField &plotXs)
Base class for classes which manage incomplete sets of face data.
const scalarField & pointXs_
const pointField & points_
PtrList< DynamicList< label > > faceis_
void clear(const label layeri)
label activeLayeri(const label layeri) const
const scalarField & plotXs_
const pointField & faceCentres_
const cellEdgeAddressingList & cAddrs_
PtrList< boolList > haveFaces_
const scalarField & cellVolumes_
faceData(const fvMesh &mesh, const label nActiveLayers, const scalarField &pointXs, const scalarField &plotXs)
const vectorField & faceAreas_
Class to manage face basis function data.
void cache(const label celli, const label layeri)
const Pair< scalarField > & faceFs(const label layeri) const
faceFsData(const faceCutData &fcd, const fvMesh &mesh, const label nActiveLayers, const scalarField &pointXs, const scalarField &plotXs)
const Pair< scalarField > & pointFs(const label layeri) const
const Pair< Pair< scalarField > > & faceCutFs(const label layeri) const
A class for handling file names.
Abstract base-class for Time/database functionObjects.
const Time & time_
Reference to time.
const word & name() const
Return the name of this functionObject.
This function object writes graphs of cell values, volume-averaged in planes perpendicular to a given...
virtual wordList fields() const
Return the list of fields required.
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
cutLayerAverage(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the cutLayerAverage.
virtual ~cutLayerAverage()
Destructor.
virtual bool read(const dictionary &)
Read the cutLayerAverage data.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
static const word outputPrefix
Directory prefix.
Mesh data needed to do the Finite Volume discretisation.
const word & name() const
Return reference to name.
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.
static word defaultRegion
Return the default region name.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const polyMesh & mesh() const
Return polyMesh.
static autoPtr< setWriter > New(const word &writeType, const IOstream::streamFormat writeFormat=IOstream::ASCII, const IOstream::compressionType writeCompression=IOstream::UNCOMPRESSED)
Select given write options.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
A class for handling words, derived from string.
static const word null
An empty word.
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define TypeFieldValuesParameter(Type, nullArg)
#define CollapseTypeFields(Type, GeoField)
#define FoundTypeField(Type, nullArg)
#define DeclareTypeFieldValues(Type, nullArg)
#define ResizeTypeFieldValues(Type, nullArg)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
static List< word > fieldNames
Tuple2< vector, std::tuple< AreaIntegralType< Types > ... > > faceCutAreaIntegral(const face &f, const vector &fArea, const std::tuple< Types ... > &fPsis, const List< labelPair > &fCuts, const pointField &ps, const std::tuple< const Field< Types > &... > &pPsis, const scalarField &pAlphas, const scalar isoAlpha, const bool below)
Compute the face-cut-area and face-cut-area-integral of the given properties.
vector faceCutArea(const face &f, const vector &fArea, const List< labelPair > &fCuts, const pointField &ps, const scalarField &pAlphas, const scalar isoAlpha, const bool below)
Compute the face-cut-area.
Tuple2< scalar, std::tuple< Types ... > > cellCutVolumeIntegral(const cell &c, const cellEdgeAddressing &cAddr, const scalar cVolume, const std::tuple< Types ... > &cPsis, const labelListList &cCuts, const faceUList &fs, const vectorField &fAreas, const pointField &fCentres, const std::tuple< const Field< Types > &... > &fPsis, const vectorField &fCutAreas, const std::tuple< const Field< Types > &... > &fCutPsis, const pointField &ps, const std::tuple< const Field< Types > &... > &pPsis, const scalarField &pAlphas, const scalar isoAlpha, const bool below)
Compute the cell-cut-volume and cell-cut-volume-integral.
Tuple2< scalar, std::tuple< Types ... > > cellVolumeIntegral(const cell &c, const cellEdgeAddressing &cAddr, const point &cPAvg, const std::tuple< Types ... > &cPsiAvgs, const vectorField &fAreas, const pointField &fCentres, const std::tuple< const Field< Types > &... > &fPsis)
Compute the cell-volume and cell-volume-integrals of the given properties.
Tuple2< vector, std::tuple< Types ... > > faceAreaAverage(const FaceValues< point > &fPs, const point &fPAvg, const std::tuple< FaceValues< Types > ... > &fPsis, const std::tuple< Types ... > &fPsiAvgs)
Compute the face-area and face-area-averages of the given properties.
List< labelPair > faceCuts(const face &f, const scalarField &pAlphas, const scalar isoAlpha)
Return the cuts for a given face. This returns a list of pairs of.
labelListList cellCuts(const cell &c, const cellEdgeAddressing &cAddr, const faceUList &fs, const List< List< labelPair >> &fCuts, const scalarField &pAlphas, const scalar isoAlpha)
Return the cuts for a given cell. This returns a list of lists of cell-edge.
scalar cellCutVolume(const cell &c, const cellEdgeAddressing &cAddr, const scalar cVolume, const labelListList &cCuts, const faceUList &fs, const vectorField &fAreas, const pointField &fCentres, const vectorField &fCutAreas, const pointField &ps, const scalarField &pAlphas, const scalar isoAlpha, const bool below)
Compute the cell-cut-volume.
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< word > wordList
A List of words.
dimensioned< tensor > dimensionedTensor
Dimensioned tensor obtained from generic dimensioned type.
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.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
List< cell > cellList
list of cells
Ostream & endl(Ostream &os)
Add newline and flush stream.
autoPtr< Pair< Field< Type > > > fieldPairPtr(const label size)
Allocate and return a pair of fields.
const dimensionSet dimless
vectorField pointField
pointField is a vectorField.
List< bool > boolList
Bool container classes.
List< scalar > scalarList
A List of scalars.
autoPtr< Pair< Pair< Field< Type > > > > fieldPairPairPtr(const label size)
Allocate and return a pair of a pair of fields.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
PointField< scalar > pointScalarField
List< labelList > labelListList
A List of labelList.
VolField< scalar > volScalarField
dimensionSet normalised(const dimensionSet &)
typename VolField< Type >::Internal VolInternalField
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Field< vector > vectorField
Specialisation of Field<T> for vector.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Type gMin(const FieldField< Field, Type > &f)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
quaternion normalise(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
Type gMax(const FieldField< Field, Type > &f)