40 namespace functionObjects
56 Foam::functionObjects::patchCutLayerAverage::calcNonInterpolatingWeights
67 const faceList& faces = pp.localFaces();
76 DynamicList<weight> dynWeights(faces.size()*2);
80 const label facei = faceMinOrder[i];
82 const scalar a = faceAreas[facei] & faceNormals[facei];
85 while (faceMinXs[facei] > plotXs[layeri + 1])
91 label layerj = layeri;
92 while (faceMaxXs[facei] > plotXs[layerj])
94 const scalar x0 = plotXs[layerj], x1 = plotXs[layerj + 1];
97 dynWeights.append({facei, layerj, a});
100 if (faceMinXs[facei] < x0)
102 dynWeights.last().value -=
114 ).first() & faceNormals[facei];
118 if (faceMaxXs[facei] > x1)
120 dynWeights.last().value -=
132 ).first() & faceNormals[facei];
140 List<weight> weights;
141 weights.transfer(dynWeights);
149 layerWeightSums[weights[weighti].layeri] += weights[weighti].value;
157 weights[weighti].value /=
158 (layerWeightSums[weights[weighti].layeri] + vSmall);
167 Foam::functionObjects::patchCutLayerAverage::calcInterpolatingWeights
177 const polyPatch& pp = mesh_.boundaryMesh()[patchName_];
178 const faceList& faces = pp.localFaces();
189 DynamicList<weight> dynWeights(faces.size()*2);
193 const label facei = faceMinOrder[i];
195 const scalar a = faceAreas[facei] & faceNormals[facei];
198 while (faceMinXs[facei] > plotXs[layeri + 1])
204 label layerj = layeri;
205 while (layerj == 0 || faceMaxXs[facei] > plotXs[layerj - 1])
207 const scalar xLeft = layerj > 0 ? plotXs[layerj - 1] : NaN;
208 const scalar xMid = plotXs[layerj];
209 const scalar xRight =
210 layerj < nLayers_ - 1 ? plotXs[layerj + 1] : NaN;
213 dynWeights.append({facei, layerj, 0});
216 if (layerj > 0 && faceMinXs[facei] < xMid)
218 forAll(faces[facei], facePointi)
220 const label pointi = faces[facei][facePointi];
222 (pointXs[pointi] - xLeft)/(xMid - xLeft);
225 const scalar
f = faces[facei].average(
points, pointFs);
228 dynWeights.last().value +=
f*a;
231 if (faceMinXs[facei] < xLeft)
233 dynWeights.last().value -=
245 ).second() & faceNormals[facei];
249 if (faceMaxXs[facei] > xMid)
251 dynWeights.last().value -=
263 ).second() & faceNormals[facei];
268 if (layerj < nLayers_ - 1 && faceMaxXs[facei] > xMid)
270 forAll(faces[facei], facePointi)
272 const label pointi = faces[facei][facePointi];
274 (xRight - pointXs[pointi])/(xRight - xMid);
277 const scalar
f = faces[facei].average(
points, pointFs);
280 dynWeights.last().value +=
f*a;
283 if (faceMinXs[facei] < xMid)
285 dynWeights.last().value -=
297 ).second() & faceNormals[facei];
301 if (faceMaxXs[facei] > xRight)
303 dynWeights.last().value -=
315 ).second() & faceNormals[facei];
324 List<weight> weights;
325 weights.transfer(dynWeights);
335 layerWeightSums[weights[weighti].layeri] += weights[weighti].value;
343 weights[weighti].value /=
344 (layerWeightSums[weights[weighti].layeri] + vSmall);
353 weights[weighti].layeri == 0
354 || weights[weighti].layeri == nLayers_ - 1
357 weights[weighti].value *= 2;
367 Foam::functionObjects::patchCutLayerAverage::calcWeights
379 ? calcInterpolatingWeights
388 : calcNonInterpolatingWeights
402 Foam::functionObjects::patchCutLayerAverage::applyWeights
412 tLayerValues.
ref()[weights[weighti].layeri] +=
413 weights[weighti].value*faceValues[weights[weighti].facei];
423 void Foam::functionObjects::patchCutLayerAverage::initialise()
432 const label nPlot = interpolate_ ? nLayers_ : nLayers_ + 1;
442 forAll(faces[facei], facePointi)
444 const label pointi = faces[facei][facePointi];
445 faceMinXs[facei] =
min(faceMinXs[facei], pointXs[pointi]);
446 faceMaxXs[facei] =
max(faceMaxXs[facei], pointXs[pointi]);
464 #define DeclareTypeFieldValues(Type, nullArg) \
465 PtrList<Field<Type>> Type##FieldValues;
467 #undef DeclareTypeFieldValues
471 for (
label iteri = 0; iteri < nOptimiseIter_ + debug; ++ iteri)
474 const List<weight> weights =
491 const label nFields0 = (2 + !interpolate_)*iteri;
492 const label nFields = (2 + !interpolate_)*(iteri + 1);
495 #define ResizeTypeFieldValues(Type, nullArg) \
496 Type##FieldValues.resize(nFields);
498 #undef ResizeTypeFieldValues
502 const SubField<scalar> distance0s(plotXs, nLayers_);
503 const SubField<scalar> distance1s(plotXs, nLayers_, 1);
506 scalarFieldValues.set(nFields0, (distance0s + distance1s)/2);
509 scalarFieldValues.set(nFields0 + 1, distance1s - distance0s);
514 scalarFieldValues.set(nFields0,
new scalarField(plotXs));
518 scalarFieldValues.set(nFields - 1,
new scalarField(layerCounts));
520 if (iteri == nOptimiseIter_)
break;
525 for (
label ploti = 0; ploti < nPlot - 1; ++ ploti)
527 plotSumCounts[ploti + 1] =
531 ? (layerCounts[ploti + 1] + layerCounts[ploti])/2
537 const scalar plotDeltaCount = plotSumCounts.last()/(nPlot - 1);
542 plotXs.first() =
xMin;
544 for (
label ploti0 = 0; ploti0 < nPlot - 1; ++ ploti0)
546 while (plotSumCounts[ploti0 + 1] > ploti*plotDeltaCount)
549 (ploti*plotDeltaCount - plotSumCounts[ploti0])
550 /(plotSumCounts[ploti0 + 1] - plotSumCounts[ploti0]);
552 plotXs[ploti] = (1 -
f)*plot0Xs[ploti0] +
f*plot0Xs[ploti0 + 1];
557 plotXs.last() =
xMax;
592 layerDistances_ = plotXs;
596 const SubField<scalar> distance0s(plotXs, nLayers_);
597 const SubField<scalar> distance1s(plotXs, nLayers_, 1);
598 layerDistances_ = (distance0s + distance1s)/2;
599 layerThicknesses_.reset((distance1s - distance0s).ptr());
607 Foam::fileName Foam::functionObjects::patchCutLayerAverage::outputPath()
const
643 patchName_ =
dict.lookup<
word>(
"patch");
645 nLayers_ =
dict.lookup<
label>(
"nPoints");
647 interpolate_ =
dict.lookupOrDefault<
bool>(
"interpolate",
false);
663 nOptimiseIter_ =
dict.lookupOrDefault(
"nOptimiseIter", 2);
687 const bool writeThickness =
715 cannotFindObject(fields_[fieldi]);
720 #define DeclareTypeFieldValues(Type, nullArg) \
721 PtrList<Field<Type>> Type##FieldValues(fieldNames.size());
723 #undef DeclareTypeFieldValues
726 scalarFieldValues.set(0,
new scalarField(layerThicknesses_));
730 #define CollapseTypeFields(Type, nullArg) \
731 if (mesh_.foundObject<VolField<Type>>(fieldNames[fieldi])) \
733 const VolField<Type>& field = \
734 mesh_.lookupObject<VolField<Type>>(fieldNames[fieldi]); \
736 Type##FieldValues.set \
739 applyWeights(weights_, field.boundaryField()[pp.index()]) \
743 #undef CollapseTypeFields
792 if (&map.
mesh() == &mesh_)
804 if (&map.
mesh() == &mesh_)
816 if (&map.
mesh() == &mesh_)
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.
Pre-declare SubField and related Field type.
SubField< vector > subField
Declare type of subField.
Generic GeometricField class.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
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.
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
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.
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.
Holds list of sampling positions.
static const NamedEnum< axisType, 6 > axisTypeNames_
String representation of axis enums.
A list of keyword definitions, which are a keyword followed by any number of values (e....
A class for handling file names.
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
This function object writes graphs of patch face values, area-averaged in planes perpendicular to a g...
patchCutLayerAverage(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
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 ~patchCutLayerAverage()
Destructor.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the patchCutLayerAverage.
virtual bool read(const dictionary &)
Read the patchCutLayerAverage data.
static const word outputPrefix
Directory prefix.
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.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
A patch is a list of labels that address the faces in the global face list.
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
const vectorField::subField faceCentres() const
Return face centres.
const scalarField::subField magFaceAreas() const
Return face area magnitudes.
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.
volScalarField scalarField(fieldObject, mesh)
static List< word > fieldNames
Tuple2< vector, typename outerProduct< vector, Type >::type > faceCutAreaIntegral(const face &f, const vector &fArea, const Type &fPsi, const List< labelPair > &fCuts, const pointField &ps, const Field< Type > &pPsis, const scalarField &pAlphas, const scalar isoAlpha, const bool below)
Compute the face-area and face-area-integral of the given property over.
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.
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
List< word > wordList
A List of words.
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.
word name(const bool)
Return a word representation of a bool.
vectorField pointField
pointField is a vectorField.
List< scalar > scalarList
A List of scalars.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensionSet normalised(const dimensionSet &)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Field< vector > vectorField
Specialisation of Field<T> for vector.
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
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.
Type gMax(const FieldField< Field, Type > &f)
#define TypeFieldValuesParameter(Type, nullArg)
#define FoundTypeField(Type, nullArg)
#define DeclareTypeFieldValues(Type, nullArg)
#define CollapseTypeFields(Type, nullArg)
#define ResizeTypeFieldValues(Type, nullArg)