34 forAll(d.cellAvgCell_, cellAvgi)
36 d.cellCellAvg_[d.cellAvgCell_[cellAvgi]] = -1;
38 d.cellAvgCell_.clear();
39 d.cellAvgCount_.clear();
40 if (d.cellAvgWeightSumPtr_.valid()) d.cellAvgWeightSumPtr_->clear();
41 d.cellAvgSum_.clear();
48 const LagrangianSubSubField<scalar>& weightOrNull,
49 const LagrangianSubSubField<Type>& psiOrWeightPsi,
53 const LagrangianSubMesh& subMesh = psiOrWeightPsi.mesh();
58 if (
notNull(weightOrNull) != d.cellAvgWeightSumPtr_.valid())
61 <<
"Inconsistent weight specification for average of field "
65 forAll(psiOrWeightPsi, subi)
67 const label celli = subMesh.mesh().celli()[subMesh.start() + subi];
68 const label cellAvgi = d.cellCellAvg_[celli];
73 if (cellAvgi == -1 || d.cellAvgCount_[cellAvgi] == 0)
76 <<
"Negative count for average of field "
81 d.cellAvgCount_[cellAvgi] --;
84 d.cellAvgWeightSumPtr_()[cellAvgi] -= weightOrNull[subi];
85 d.cellAvgSum_[cellAvgi] -= weightOrNull[subi]*psiOrWeightPsi[subi];
89 d.cellAvgSum_[cellAvgi] -= psiOrWeightPsi[subi];
104 const LagrangianSubSubField<scalar>& weightOrNull,
105 const LagrangianSubSubField<Type>& psiOrWeightPsi,
109 const LagrangianSubMesh& subMesh = psiOrWeightPsi.mesh();
114 if (
notNull(weightOrNull) != d.cellAvgWeightSumPtr_.valid())
117 <<
"Inconsistent weight specification for average of field "
121 forAll(psiOrWeightPsi, subi)
123 const label celli = subMesh.mesh().celli()[subMesh.start() + subi];
124 label cellAvgi = d.cellCellAvg_[celli];
129 cellAvgi = d.cellAvgCell_.size();
130 d.cellCellAvg_[celli] = cellAvgi;
131 d.cellAvgCell_.append(celli);
132 d.cellAvgCount_.append(
label(0));
135 d.cellAvgWeightSumPtr_().append(scalar(0));
137 d.cellAvgSum_.append(pTraits<Type>::zero);
144 d.cellAvgCount_[cellAvgi] ++;
147 d.cellAvgWeightSumPtr_()[cellAvgi] += weightOrNull[subi];
148 d.cellAvgSum_[cellAvgi] += weightOrNull[subi]*psiOrWeightPsi[subi];
152 d.cellAvgSum_[cellAvgi] += psiOrWeightPsi[subi];
167 LagrangianSubField<Type>& result
170 const LagrangianSubMesh& subMesh = result.mesh();
174 const label celli = subMesh.mesh().celli()[subMesh.start() + subi];
175 const label cellAvgi = data_.cellCellAvg_[celli];
176 const label dCellAvgi = dData_.cellCellAvg_[celli];
177 const bool haveData =
178 cellAvgi != -1 && data_.cellAvgCount_[cellAvgi] != 0;
179 const bool haveDData =
180 dCellAvgi != -1 && dData_.cellAvgCount_[dCellAvgi] != 0;
182 if (!haveData && !haveDData)
185 <<
"Interpolated value requested for a cell in which no "
186 <<
"elements have been averaged"
190 static const Type& z = pTraits<Type>::zero;
194 (haveData ? data_.cellAvgSum_[cellAvgi] : z)
195 + (haveDData ? dData_.cellAvgSum_[dCellAvgi] : z)
199 ? (haveData ? data_.cellAvgWeightSumPtr_()[cellAvgi] : 0)
200 + (haveDData ? dData_.cellAvgWeightSumPtr_()[dCellAvgi] : 0)
213 const bool hasWeightSum
216 cellCellAvg_(nCells,
label(-1)),
219 cellAvgWeightSumPtr_(hasWeightSum ? new DynamicList<scalar>() : nullptr),
234 weightSum_(weightSum),
236 dDataIsValid_(false),
260 <<
"Cannot remove from an average with a cached difference"
264 remove(weightOrNull, psiOrWeightPsi, data_);
279 <<
"Cannot add to an average with a cached difference"
283 dDataIsValid_ = cache;
285 add(weightOrNull, psiOrWeightPsi, cache ? dData_ : data_);
300 <<
"Cannot correct an average without a cached difference"
306 dDataIsValid_ = cache;
308 add(weightOrNull, psiOrWeightPsi, cache ? dData_ : data_);
#define forAll(list, i)
Loop across all elements in list.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Basic Lagrangian averaging process in which values are averaged in the cells and then interpolated as...
cell(const word &name, const LagrangianMesh &mesh, const dimensionSet &dimensions, const Field< scalar > &weightSum)
Construct with a name, for a mesh and with given dimensions.
virtual void correct(const LagrangianSubSubField< scalar > &weight, const LagrangianSubSubField< Type > &psi, const bool cache)
Correct weighted values in the average.
virtual ~cell()
Destructor.
Class containing Lagrangian geometry and topology.
Dimension set for the base types.
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.
errorManipArg< error, int > exit(error &err, const int errNo=1)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
void add(LagrangianPatchField< typename typeOfSum< Type1, Type2 >::type > &f, const LagrangianPatchField< Type1 > &f1, const LagrangianPatchField< Type2 > &f2)