Postprocess framework

- Executed has been completed and testd.
- regions multipleSpheres are compelete
- Docs for regions is comelete.
This commit is contained in:
Hamidreza
2025-04-15 21:27:49 +03:30
parent 077f25842a
commit 093160ba32
21 changed files with 762 additions and 171 deletions

View File

@ -3,6 +3,7 @@
#include "fieldsDataBase.hpp"
#include "fieldFunctions.hpp"
/// Constructs sum processor and initializes result field based on input field type
pFlow::PostprocessOperationSum::PostprocessOperationSum
(
const dictionary &opDict,
@ -37,6 +38,7 @@ pFlow::PostprocessOperationSum::PostprocessOperationSum
}
}
/// Performs weighted sum of field values within each region
bool pFlow::PostprocessOperationSum::execute
(
const std::vector<span<real>>& weights

View File

@ -21,6 +21,107 @@ Licence:
#ifndef __PostprocessOperationSum_hpp__
#define __PostprocessOperationSum_hpp__
/*!
* @class PostprocessOperationSum
* @brief A class for summing field values within specified regions during post-processing.
*
* @details
* The PostprocessOperationSum class is a specialized post-processing operation that
* calculates the sum of field values within specified regions. It inherits from the
* postprocessOperation base class and implements a weighted summation operation that
* can be applied to scalar (real), vector (realx3), and tensor (realx4) fields.
*
* The sum operation follows the mathematical formula:
* \f[
* \text{result} = \sum_{i \in \text{processRegion}} w_i \cdot \phi_i \cdot \text{field}_i
* \f]
*
* Where:
* - \f$ i \f$ represents particles within the specified processing region
* - \f$ w_i \f$ is the weight factor for particle \f$ i \f$
* - \f$ \phi_i \f$ is the value from the phi field for particle \f$ i \f$
* - \f$ \text{field}_i \f$ is the value from the target field for particle \f$ i \f$
*
* The calculation can optionally be divided by the region volume (when divideByVolume is set to yes),
* which allows calculating density-like quantities:
* \f[
* \text{result} = \frac{1}{V_{\text{region}}} \sum_{i \in \text{processRegion}} w_i \cdot \phi_i \cdot \text{field}_i
* \f]
*
* The summation can be further filtered using an includeMask to selectively include only
* specific particles that satisfy certain criteria.
*
* This class supports the following field types:
* - real (scalar values)
* - realx3 (vector values)
* - realx4 (tensor values)
*
* @section usage Usage
*
* To use the PostprocessOperationSum class in a postprocessDataDict file, the following
* parameters can be specified:
*
* - function: Must be set to "sum" to use this operation
* - field: The name of the field to process (e.g., "velocity", "diameter", "one")
* - Special fields like "one" (constant value 1) are also supported
* - Expressions like "cube(diameter)" can be used for mathematical operations
* - dividedByVolume: Whether to divide the sum by the region volume (yes/no, default: no)
* - includeMask: Optional mask to filter which particles to include in the calculation
*
* @section example Example Configuration
*
* Here is an example configuration in the postprocessDataDict file:
*
* @code
* {
* processMethod arithmetic;
* processRegion line;
*
* // the time interval for executing the post-processing
* // other options: timeStep, default, and settings
* timeControl simulationTime;
* startTime 1.0;
* endTime 3.0;
* executionInterval 0.1;
*
* // 10 spheres with radius 0.01 along the straight line defined by p1 and p2
* lineInfo
* {
* p1 (0 0 0);
* p2 (0 0.15 0.15);
* numPoints 10;
* radius 0.01;
* }
*
* operations
* (
* // computes the number density (particles per unit volume)
* numberDensity
* {
* function sum;
* field one; // constant field with value 1.0
* dividedByVolume yes; // divide by region volume
* }
*
* // computes an approximation of volume fraction
* volumeDensity
* {
* function sum;
* field cube(diameter); // d^3, although it differs by pi/6
* dividedByVolume yes;
* }
* );
* }
* @endcode
*
* In this example:
* - numberDensity: Calculates the number of particles per unit volume
* - volumeDensity: Calculates an approximation of the volume fraction using d³
*
* @see postprocessOperation
* @see executeSumOperation
*/
#include <variant>
#include <vector>
@ -37,21 +138,26 @@ class PostprocessOperationSum
public postprocessOperation
{
private:
/// Pointer to the include mask used for masking operations.
/// Result field containing sums for each region (real, realx3, or realx4)
uniquePtr<processedRegFieldType> processedRegField_ = nullptr;
public:
TypeInfo("PostprocessOperation<sum>");
/// @brief Constructs sum operation processor
/// @param opDict Operation parameters dictionary
/// @param regPoints Region points data
/// @param fieldsDB Fields database
PostprocessOperationSum(
const dictionary& opDict,
const regionPoints& regPoints,
fieldsDataBase& fieldsDB);
/// destructor
~PostprocessOperationSum() override = default;
/// add this virtual constructor to the base class
add_vCtor
(
postprocessOperation,
@ -59,11 +165,16 @@ public:
dictionary
);
/// @brief Get the processed field containing regional sums
/// @return Const reference to sum results
const processedRegFieldType& processedField()const override
{
return processedRegField_();
}
/// @brief Execute sum operation on field values
/// @param weights Weight factors for particles
/// @return True if successful
bool execute(const std::vector<span<real>>& weights) override;
};
@ -71,4 +182,4 @@ public:
}
#endif //__PostprocessOperation_hpp__
#endif //__PostprocessOperationSum_hpp__

View File

@ -31,7 +31,6 @@ Licence:
namespace pFlow
{
template<typename T>
regionField<T> executeSumOperation
(
@ -45,13 +44,14 @@ regionField<T> executeSumOperation
)
{
regionField<T> processedField(regFieldName, regPoints, T{});
auto vols = regPoints.volumes();
for(uint32 reg =0; reg<regPoints.size(); reg++)
{
auto partIndices = regPoints.indices(reg);
auto vols = regPoints.volumes();
auto w = weights[reg];
T sum{};
T sum = T{};
uint n = 0;
for(auto index:partIndices)
{
@ -80,33 +80,106 @@ regionField<T> executeAverageOperation
(
const word& regFieldName,
const span<T>& field,
const regionPoints& regPoints,
const regionPoints& regPoints,
const bool devideByVol,
const std::vector<span<real>>& weights,
const span<real>& phi,
const includeMask::Mask& mask
)
{
regionField<T> processedField(regFieldName, regPoints, T{});
auto vols = regPoints.volumes();
for(uint32 reg =0; reg<regPoints.size(); reg++)
{
auto partIndices = regPoints.indices(reg);
auto w = weights[reg];
T sumNum{};
real sumDen{};
T sumNum = T{};
real sumDen = 0;
uint n = 0;
for(auto index:partIndices)
{
if( index!= -1 && mask( index ))
if( index!= -1)
{
sumNum += w[n] * field[index]* phi[index];
if( mask(index))
{
sumNum += w[n] * field[index]* phi[index];
}
sumDen += w[n] * phi[index];
}
sumDen += w[n] * phi[index];
n++;
}
if(devideByVol)
{
processedField[reg] = sumNum / max(sumDen, smallValue) / vols[reg];
}
else
{
processedField[reg] = sumNum / max(sumDen, smallValue);
}
}
sumDen = max(sumDen, smallValue);
processedField[reg] = sumNum/sumDen;
return processedField;
}
template<typename T>
regionField<T> executeFluctuation2Operation
(
const word& regFieldName,
const span<T>& field,
const regionField<T>& fieldAvg,
const bool devideByVol,
const std::vector<span<real>>& weights,
const includeMask::Mask& mask
)
{
const auto& regPoints = fieldAvg.regPoints();
regionField<T> processedField(regFieldName, regPoints, T{});
auto vols = regPoints.volumes();
for(uint32 reg =0; reg<regPoints.size(); reg++)
{
auto partIndices = regPoints.indices(reg);
auto w = weights[reg];
auto vol = vols[reg];
T avField{};
if(devideByVol)
{
avField = vol * fieldAvg[reg];
}
else
{
avField = fieldAvg[reg];
}
T sumNum = T{};
real sumDen = 0;
uint n = 0;
for(auto index:partIndices)
{
if( index!= -1)
{
if( mask(index))
{
sumNum += w[n] * pow( avField- field[index],static_cast<real>(2));
}
sumDen += w[n];
}
n++;
}
if(devideByVol)
{
processedField[reg] = sumNum / max(sumDen, smallValue) / vol;
}
else
{
processedField[reg] = sumNum / max(sumDen, smallValue);
}
}

View File

@ -33,11 +33,21 @@ pFlow::includeMask::includeMask
database_(fieldDB)
{}
pFlow::includeMask::includeMask
(
const word &type,
const dictionary &opDict,
fieldsDataBase &fieldsDB
)
:
database_(fieldsDB)
{
}
pFlow::uniquePtr<pFlow::includeMask> pFlow::includeMask::create
(
const dictionary& opDict,
fieldsDataBase& feildsDB
fieldsDataBase& fieldsDB
)
{
word mask = opDict.getValOrSet<word>("includeMask", "all");
@ -47,7 +57,7 @@ pFlow::uniquePtr<pFlow::includeMask> pFlow::includeMask::create
auto& maskDict = opDict.subDict(mask+"Info");
word maskField = maskDict.getVal<word>("field");
if( !feildsDB.getPointFieldType(maskField, fieldType) )
if( !fieldsDB.getPointFieldType(maskField, fieldType) )
{
fatalErrorInFunction<<"Error in retriving the type of field"
<< maskField <<" from dictionary "
@ -68,7 +78,7 @@ pFlow::uniquePtr<pFlow::includeMask> pFlow::includeMask::create
{
auto objPtr =
dictionaryvCtorSelector_[method]
(opDict, feildsDB);
(opDict, fieldsDB);
return objPtr;
}
else
@ -87,5 +97,56 @@ pFlow::uniquePtr<pFlow::includeMask> pFlow::includeMask::create
return nullptr;
}
pFlow::uniquePtr<pFlow::includeMask>
pFlow::includeMask::create
(
const word &type,
const dictionary &opDict,
fieldsDataBase &fieldsDB
)
{
word fieldType;
if( type != "all")
{
auto& maskDict = opDict.subDict(type+"Info");
word maskField = maskDict.getVal<word>("field");
if( !fieldsDB.getPointFieldType(maskField, fieldType) )
{
fatalErrorInFunction<<"Error in retriving the type of field"
<< maskField <<" from dictionary "
<< maskDict.globalName()
<< endl;
fatalExit;
return nullptr;
}
}
else
{
fieldType = getTypeName<real>();
}
word method = angleBracketsNames2("IncludeMask", fieldType, type);
if( wordvCtorSelector_.search(method) )
{
auto objPtr =
wordvCtorSelector_[method]
(type, opDict, fieldsDB);
return objPtr;
}
else
{
printKeys
(
fatalError << "Ctor Selector "<<
method << " dose not exist. \n"
<<"Avaiable ones are: \n\n"
,
dictionaryvCtorSelector_
);
fatalExit;
return nullptr;
}
return nullptr;
}

View File

@ -74,6 +74,8 @@ public:
includeMask(const dictionary& opDict, fieldsDataBase& feildsDB);
includeMask(const word& type, const dictionary& opDict, fieldsDataBase& feildsDB);
virtual ~includeMask() = default;
create_vCtor
@ -85,6 +87,18 @@ public:
),
(opDict, feildsDB)
);
create_vCtor
(
includeMask,
word,
(
const word& type,
const dictionary& opDict,
fieldsDataBase& feildsDB
),
(type, opDict, feildsDB)
);
const fieldsDataBase& database()const
{
@ -103,6 +117,12 @@ public:
uniquePtr<includeMask> create(
const dictionary& opDict,
fieldsDataBase& feildsDB);
static
uniquePtr<includeMask> create(
const word& type,
const dictionary& opDict,
fieldsDataBase& feildsDB);
};

View File

@ -82,14 +82,33 @@ bool writeField
}
pFlow::postprocessOperation::postprocessOperation
(
const dictionary &opDict,
const regionPoints& regPoints,
fieldsDataBase &fieldsDB
)
:
postprocessOperation
(
opDict,
opDict.getVal<word>("field"),
opDict.getValOrSet<word>("phi", "one"),
opDict.getValOrSet<word>("includeMask", "all"),
regPoints,
fieldsDB
)
{}
pFlow::postprocessOperation::postprocessOperation
(
const dictionary &opDict,
const word &fieldName,
const word &phiName,
const word& includeName,
const regionPoints &regPoints,
fieldsDataBase &fieldsDB
)
:
operationDict_(opDict),
threshold_
@ -110,15 +129,15 @@ pFlow::postprocessOperation::postprocessOperation
),
fieldName_
(
opDict.getValOrSet<word>("field", "one")
fieldName
),
phiFieldName_
(
opDict.getValOrSet<word>("phi", "one")
phiName
),
includeMask_
(
includeMask::create(opDict, fieldsDB)
includeMask::create(includeName, opDict, fieldsDB)
)
{
@ -128,7 +147,6 @@ pFlow::postprocessOperation::postprocessOperation
fatalExit;
}
}
const pFlow::Time& pFlow::postprocessOperation::time() const
{
return database_.time();

View File

@ -20,6 +20,53 @@ Licence:
#ifndef __postprocessOperation_hpp__
#define __postprocessOperation_hpp__
/*!
* @class postprocessOperation
* @file postprocessOperation.hpp
* @brief Base class for post-processing operations on particle data.
* This class provides the foundational structure and functionality
* for performing various post-processing operations on simulation data.
*
* @details
* The postprocessOperation class operates on field data (specified in the input dictionary)
* and performs specific operations on that field within defined regions. It serves as
* part of the post-processing framework in phasicFlow to analyze particle simulation results.
*
* Operations are performed on specific subsets of particles defined by region points and
* can be filtered using include masks. The class supports different field types (real,
* realx3, realx4) through the processedRegFieldType variant.
*
* The main operations supported include:
*
* 1. Sum operation:
* - Calculates:
* \f[
* \text{result} = \sum_{i \in \text{processRegion}} w_i \cdot \phi_i \cdot \text{field}_i
* \f]
* - Where \f$ i \f$ belongs to the particles in the specified processRegion
* - \f$ w_i \f$ is the weight factor for particle \f$ i \f$
* - \f$ \phi_i \f$ is the value from the phi field for particle \f$ i \f$
* - \f$ \text{field}_i \f$ is the value from the target field for particle \f$ i \f$
* - Implemented in the derived class PostprocessOperationSum
*
* 2. Average operation:
* - Calculates:
* \f[
* \text{result} = \frac{\sum_{j \in \text{includeMask}} w_j \cdot \phi_j \cdot \text{field}_j}
* {\sum_{i \in \text{processRegion}} w_i \cdot \phi_i}
* \f]
* - Where \f$ i \f$ belongs to all particles in the specified processRegion
* - \f$ j \f$ belongs to a subset of \f$ i \f$ based on an includeMask defined in the input dictionary
* - This allows calculating regional averages on specific subsets of particles
*
* The class uses threshold values to exclude regions with insufficient particles
* and supports optional division by volume for density-like calculations. Results are written
* to files for later analysis or visualization.
*
* @note The actual processing is performed by derived classes that implement
* the execute() method for specific operation types.
*/
#include <variant>
#include "virtualConstructor.hpp"
@ -33,6 +80,9 @@ Licence:
namespace pFlow
{
/// Type alias for processed region field types.
/// Only regionField<real>, regionField<realx3>, and regionField<realx4> are supported
/// in the postprocessOperation class.
using processedRegFieldType = std::variant
<
regionField<real>,
@ -40,14 +90,10 @@ using processedRegFieldType = std::variant
regionField<realx4>
>;
/// - forward declaration
class fieldsDataBase;
class Time;
/*!
* @brief Base class for post-processing operations.
* This class provides the basic structure and functionality
* for performing post-processing operations on simulation data.
*/
class postprocessOperation
{
public:
@ -88,16 +134,31 @@ private:
public:
/// Type info
TypeInfo("postprocessOperation");
/// Constructor
/// @param opDict Dictionary containing operation-specific parameters.
/// @param regPoints Reference to the region points used in the operation.
/// @param fieldsDB Reference to the fields database containing field data.
postprocessOperation(
const dictionary& opDict,
const regionPoints& regPoints,
fieldsDataBase& fieldsDB );
postprocessOperation(
const dictionary& opDict,
const word& fieldName,
const word& phiName,
const word& includeName,
const regionPoints& regPoints,
fieldsDataBase& fieldsDB
);
/// destructor
virtual ~postprocessOperation()=default;
/// Active the virtual constructor for creating derived classes.
create_vCtor(
postprocessOperation,
dictionary,
@ -108,74 +169,99 @@ public:
),
(opDict, regPoints, fieldsDB));
/// Access to regionPoints instance
const regionPoints& regPoints()const
{
return regionPoints_;
}
/// Access to fields database instance
const fieldsDataBase& database()const
{
return database_;
}
/// Access to fields database instance
fieldsDataBase& database()
{
return database_;
}
/// Access to the time instance
const Time& time()const;
/// Return the name of the processed field.
word processedFieldName()const
{
return operationDict_.name();
}
/// return the name of the field to be processed.
const word& fieldName()const
{
return fieldName_;
}
/// return the type name of the field to be processed.
const word& fieldType()const
{
return fieldType_;
}
/// return the name of the phi field to be processed.
const word& phiFieldName()const
{
return phiFieldName_;
}
/// Access to the operation dictionary
const dictionary& operationDict()const
{
return operationDict_;
}
/// return threshold value
/// which is used to exclude the regions which contain
/// particles fewer than this value.
const uint32 threshold()const
{
return threshold_;
}
/// whether the result is divided by volume of the region
bool divideByVolume()const
{
return divideByVolume_();
}
/// return the include mask
Mask getMask()
{
return includeMask_().getMask();
}
/// return the processed field
virtual
const processedRegFieldType& processedField()const=0;
virtual
bool execute(const std::vector<span<real>>& weights) = 0;
/// execute the operation
/// @param weights Vector of weights for the operation.
virtual bool execute(const std::vector<span<real>>& weights) = 0;
/// write the result to a file
/// @param parDir Parent directory for the output file.
virtual
bool write(const fileSystem &parDir)const;
/// write the result to output stream (possibly a file)
/// @param os Output stream to write the result.
virtual
bool write(iOstream& os)const {return true;}
/// Create the polymorphic object using the virtual constructor.
/// @param opDict Dictionary containing operation-specific parameters.
/// @param regPoints Reference to the region points used in the operation.
/// @param fieldsDB Reference to the fields database containing field data.
static
uniquePtr<postprocessOperation> create(
const dictionary& opDict,