prime2 is added and readme update

This commit is contained in:
Hamidreza 2025-04-24 14:08:17 +03:30
parent a9e5b9bb59
commit f2e8e69899
7 changed files with 407 additions and 174 deletions

View File

@ -77,6 +77,7 @@ pFlow::PostprocessOperationAverage::PostprocessOperationAverage
}
}
/// Performs weighted average of field values within each region
bool pFlow::PostprocessOperationAverage::execute
(
@ -109,7 +110,7 @@ bool pFlow::PostprocessOperationAverage::execute
allField)
);
if(calculateFluctuation2_)
if(calculateFluctuation2_())
{
auto& processedRegField = processedRegFieldPtr_();
fluctuation2FieldPtr_ = makeUnique<processedRegFieldType>
@ -136,5 +137,40 @@ bool pFlow::PostprocessOperationAverage::execute
}
return true;
}
bool pFlow::PostprocessOperationAverage::write(const fileSystem &parDir) const
{
if(! postprocessOperation::write(parDir))
{
return false;
}
if(!calculateFluctuation2_())
{
return true;
}
auto ti = time().TimeInfo();
if(!os2Ptr_)
{
fileSystem path = parDir+(
processedFieldName()+"_prime2" + ".Start_" + ti.timeName());
os2Ptr_ = makeUnique<oFstream>(path);
regPoints().write(os2Ptr_());
}
std::visit
(
[&](auto&& arg)->bool
{
return writeField(os2Ptr_(), ti.t(), arg, threshold());
},
fluctuation2FieldPtr_()
);
return true;
}

View File

@ -150,6 +150,9 @@ private:
uniquePtr<processedRegFieldType> fluctuation2FieldPtr_ = nullptr;
/// Pointer to the output stream for writing fluctuation2 results
mutable uniquePtr<oFstream> os2Ptr_ = nullptr;
public:
TypeInfo("PostprocessOperation<average>");
@ -190,6 +193,10 @@ public:
return processedRegFieldPtr_();
}
/// write to os stream
bool write(const fileSystem &parDir)const override;
/// @brief Execute average operation on field values
/// @param weights Weight factors for particles
/// @return True if successful

View File

@ -23,64 +23,6 @@ Licence:
#include "regionPoints.hpp"
#include "fieldsDataBase.hpp"
namespace pFlow
{
template<typename T>
inline
bool writeField
(
iOstream& os,
timeValue t,
const regionField<T> field,
uint32 threshold,
const T& defValue=T{}
)
{
const auto& regPoints = field.regPoints();
const uint32 n = field.size();
os<<t<<tab;
for(uint32 i=0; i<n; i++)
{
auto numPar = regPoints.indices(i).size();
if(numPar >= threshold)
{
if constexpr(std::is_same_v<T,realx3>)
{
os<<field[i].x()<<' '<<field[i].y()<<' '<<field[i].z()<<tab;
}
else if constexpr( std::is_same_v<T,realx4>)
{
os << field[i].x() << ' ' << field[i].y() << ' ' << field[i].z() << ' ' << field[i].w() << tab;
}
else
{
os<<field[i]<<tab;
}
}
else
{
if constexpr(std::is_same_v<T,realx3>)
{
os<<defValue.x()<<' '<<defValue.y()<<' '<<defValue.z()<<tab;
}
else if constexpr( std::is_same_v<T,realx4>)
{
os << defValue.x() << ' ' << defValue.y() << ' ' << defValue.z() << ' ' << defValue.w() << tab;
}
else
{
os<<defValue<<tab;
}
}
}
os<<endl;
return true;
}
}
pFlow::postprocessOperation::postprocessOperation
(

View File

@ -76,19 +76,12 @@ Licence:
#include "oFstream.hpp"
#include "regionField.hpp"
#include "includeMask.hpp"
#include "postprocessOperationFunctions.hpp"
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>,
regionField<realx3>,
regionField<realx4>
>;
/// - forward declaration
class fieldsDataBase;

View File

@ -0,0 +1,100 @@
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __postprocessOperationFunctions_hpp__
#define __postprocessOperationFunctions_hpp__
#include <variant>
#include "types.hpp"
#include "iOstream.hpp"
#include "regionField.hpp"
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>,
regionField<realx3>,
regionField<realx4>
>;
template<typename T>
inline
bool writeField
(
iOstream& os,
timeValue t,
const regionField<T> field,
uint32 threshold,
const T& defValue=T{}
)
{
const auto& regPoints = field.regPoints();
const uint32 n = field.size();
os<<t<<tab;
for(uint32 i=0; i<n; i++)
{
auto numPar = regPoints.indices(i).size();
if(numPar >= threshold)
{
if constexpr(std::is_same_v<T,realx3>)
{
os<<field[i].x()<<' '<<field[i].y()<<' '<<field[i].z()<<tab;
}
else if constexpr( std::is_same_v<T,realx4>)
{
os << field[i].x() << ' ' << field[i].y() << ' ' << field[i].z() << ' ' << field[i].w() << tab;
}
else
{
os<<field[i]<<tab;
}
}
else
{
if constexpr(std::is_same_v<T,realx3>)
{
os<<defValue.x()<<' '<<defValue.y()<<' '<<defValue.z()<<tab;
}
else if constexpr( std::is_same_v<T,realx4>)
{
os << defValue.x() << ' ' << defValue.y() << ' ' << defValue.z() << ' ' << defValue.w() << tab;
}
else
{
os<<defValue<<tab;
}
}
}
os<<endl;
return true;
}
} // namespace pFlow
#endif //__postprocessOperationFunctions_hpp__

View File

@ -2,7 +2,7 @@
The `PostprocessData` module in phasicFlow provides powerful tools for analyzing particle-based simulations both during runtime (in-simulation) and after simulation completion (post-simulation). This document explains how to configure and use the postprocessing features through the dictionary-based input system.
## Overview
## 1. Overview
Postprocessing in phasicFlow allows you to:
@ -12,11 +12,36 @@ Postprocessing in phasicFlow allows you to:
- Apply different weighing methods when calculating statistics
- Perform postprocessing at specific time intervals
## Setting Up Postprocessing
## Table of Contents
- [1. Overview](#1-overview)
- [2. Setting Up Postprocessing](#2-setting-up-postprocessing)
- [2.1. Basic Configuration](#21-basic-configuration)
- [3. Time Control Options](#3-time-control-options)
- [4. Processing Methods](#4-processing-methods)
- [5. Region Types](#5-region-types)
- [6. Processing Operations](#6-processing-operations)
- [6.1. Available Functions in average](#61-available-functions-in-average)
- [6.2. About fluctuation2 in average function](#62-about-fluctuation2-in-average-function)
- [6.3. Derived Functions](#63-derived-functions)
- [6.4. Available Fields](#64-available-fields)
- [6.5. Optional Parameters](#65-optional-parameters)
- [7. Examples](#7-examples)
- [7.1. Example 1: Probing Individual Particles](#71-example-1-probing-individual-particles)
- [7.2. Example 2: Processing in a Spherical Region](#72-example-2-processing-in-a-spherical-region)
- [7.3. Example 3: Processing Along a Line](#73-example-3-processing-along-a-line)
- [8. Advanced Features](#8-advanced-features)
- [8.1. Special functions applied on fields](#81-special-functions-applied-on-fields)
- [8.2. Particle Filtering with includeMask](#82-particle-filtering-with-includemask)
- [8.3. Implementation Notes](#83-implementation-notes)
- [9. Mathematical Formulations](#9-mathematical-formulations)
- [10. A complete dictioanry file (postprocessDataDict)](#10-a-complete-dictioanry-file-postprocessdatadict)
## 2. Setting Up Postprocessing
Postprocessing is configured through a dictionary file named `postprocessDataDict` which should be placed in the `settings` directory. Below is a detailed explanation of the configuration options.
### Basic Configuration
### 2.1. Basic Configuration
The input dictionary, **settings/postprocessDataDict**, may look like this:
@ -56,7 +81,7 @@ auxFunctions postprocessData;
This will link the postprocessing library to your simulation, allowing you to use its features. Note that, anytime you want to deactivate the in-simulation postprocessing, you can simply change the `runTimeActive` option to `no` in `postprocessDataDict` file.
## Time Control Options
## 3. Time Control Options
Each postprocessing component can either use the default time control settings or define its own. There are three main options for time control:
@ -69,7 +94,7 @@ Each postprocessing component can either use the default time control settings o
If no time control is specified, the `default` option is used automatically.
## Processing Methods
## 4. Processing Methods
The postprocessing module provides several methods for processing particle data. They are categorized into two main groups: bulk and individual methods.
@ -83,7 +108,7 @@ The postprocessing module provides several methods for processing particle data.
| `GaussianDistribution` | bulk | Weight contribution based on distance from center with Gaussian falloff | $w_i = \exp(-\|x_i - c\|^2/(2\sigma^2))/\sqrt{2\pi\sigma^2}$ |
| `particleProbe` | individual | Extracts values from specific particles | Direct access to particle properties |
## Region Types
## 5. Region Types
Regions define where in the domain the postprocessing operations are applied:
@ -94,24 +119,24 @@ Regions define where in the domain the postprocessing operations are applied:
| `line` | Spheres along a line with specified radius | `p1`, `p2`, `nSpheres`, `radius` | bulk |
| `centerPoints` | Specific particles selected by ID | `ids` | individual |
## Processing Operations
## 6. Processing Operations
Within each processing region of type `bulk`, you can define multiple operations to be performed:
### Available Functions
### 6.1. Available Functions in average
| Function | Property type | Description | Formula | Required Parameters |
|----------|---------------|-------------|---------|---------------------|
| `average` | bulk | Weighted average of particle field values | see Equation 1 | `field`, `phi` (optional), `threshold` (optional), `includeMask` (optional), `divideByVolume` (optional) |
| `average` | bulk | Weighted average of particle field values | see Equation 1 | `field`, `phi` (optional), `threshold` (optional), `includeMask` (optional), `divideByVolume` (optional), `fluctuation2` (optional) |
| `sum` | bulk | Weighted sum of particle field values | see Equation 2 | `field`, `phi` (optional),`threshold` (optional), `includeMask` (optional), `divideByVolume` (optional) |
Equation 1:
$$\text{result} = \frac{\sum_j w_j \cdot \phi_j \cdot \text{field}_j}{\sum_i w_i \cdot \phi_i}$$
$$\text{mean} = \frac{\sum_j w_j \cdot \phi_j \cdot \text{field}_j}{\sum_i w_i \cdot \phi_i}$$
Equation 2:
$$\text{result} = \sum_j w_j \cdot \phi_j \cdot \text{field}_j$$
$$\text{sum} = \sum_j w_j \cdot \phi_j \cdot \text{field}_j$$
where:
@ -121,8 +146,19 @@ where:
- $\phi_j$ is the value of the `phi` field for particle $j$ (default is 1)
- $field_j$ is the value of the specified field for particle $j$
### 6.2. About fluctuation2 in average function
### Derived Functions
Fluctuation2 is an optional parameter that can be used to account for fluctuations in the particle field values with respect to mean value of the field.
It is used in the `average` function to calculate the fluctuation of the field values around the mean. The formula for fluctuation2 is:
$$\text{fluctuation}^2 = \frac{\sum_j w_j \cdot \phi_j \cdot (\text{field}_j - \text{mean})^2}{\sum_i w_i \cdot \phi_i}$$
where:
- `mean`: is the average value of the field in the region.
- `field`: The field to be processed (e.g., `velocity`, `mass`, etc.)
- `fluctuation2`: Optional parameter to account for fluctuations in the particle field values.
### 6.3. Derived Functions
In addition to the above basic functions, some derived functions are available for specific calculations:
@ -130,7 +166,7 @@ In addition to the above basic functions, some derived functions are available f
|----------|---------------|-------------|---------|---------------------|
|`avMassVelocity` | bulk | Average velocity weighted by mass | $\frac{\sum_{i \in \text{region}} m_i \cdot v_i}{\sum_{i \in \text{region}} m_i}$ | - |
### Available Fields
### 6.4. Available Fields
All the pointFields in the simulation database (for in-simulation processing), or the ones stored in the time folders (for post-simulation processing) can be referenced in the operations. In addition to them, some extra fields are available for use in the operations. The following fields are available for use in the operations:
@ -161,17 +197,19 @@ All the pointFields in the simulation database (for in-simulation processing), o
The above fields may vary from one type of simulation to other. Pleas note that this is only a tentative list.
### Optional Parameters
### 6.5. Optional Parameters
| Parameter | Description | Default | Options |
|-----------|-------------|---------|---------|
| `divideByVolume` | Divide result by region volume | `no` | `yes`, `no` |
| `divideByVolume` | Divide result by region volume | `no` | `yes` or `no` |
| `threshold` | Exclude regions with fewer particles | 1 | Integer value |
| `includeMask` | Filter particles based on a field value | `all` | `all`, `lessThan`, `greaterThan`, `between`, `lessThanOrEq`, `greaterThanEq`, `betweenEq` |
| `includeMask` | Filter particles based on a field value | `all` | `all`, `lessThan`, `greaterThan`, `between`, `lessThanOrEq`, `greaterThanOrEq`, `betweenEq` |
|`fluctuation2` (in average only)| Calculate fluctuation of field values | `no` | `yes` or `no` |
| `phi` | Field to be used for weighted averaging | `one` | Any valid field name |
## Examples
## 7. Examples
### Example 1: Probing Individual Particles
### 7.1. Example 1: Probing Individual Particles
```cpp
velocityProb
@ -187,7 +225,7 @@ velocityProb
This example extracts the y-component of the position for particles with IDs 0, 10, and 100.
### Example 2: Processing in a Spherical Region
### 7.2. Example 2: Processing in a Spherical Region
```cpp
on_single_sphere
@ -210,6 +248,7 @@ on_single_sphere
function average;
field mag(velocity);
divideByVolume no;
fluctuation2 yes;
threshold 3;
includeMask all;
}
@ -246,7 +285,7 @@ This example defines a sphere region and performs three operations:
2. Calculate the fraction of particles with diameter less than 0.0031
3. Calculate the number density by summing and dividing by volume
### Example 3: Processing Along a Line
### 7.3. Example 3: Processing Along a Line
In this example, a line region is defined. The `lineInfo` section specifies the start and end points of the line, the number of spheres to create along the line, and the radius of each point. Bulk properties are calculated in each sphere, based on the properties of particles contained in each sphere.
@ -291,9 +330,9 @@ along_a_line
This example creates 10 spherical regions along a line from (0,0,0) to (0,0.15,0.15) and calculates the bulk density and volume density in each region.
## Advanced Features
## 8. Advanced Features
### Special functions applied on fields
### 8.1. Special functions applied on fields
You can access specific components of vector fields (`realx3`) using the `component` function:
@ -316,7 +355,7 @@ Here is a complete list of these special functions:
| `magnitude square root` | `realx3` | `magSqrt(acceleration)` |
### Particle Filtering with includeMask
### 8.2. Particle Filtering with includeMask
The `includeMask` parameter allows you to filter particles based on field values:
@ -339,7 +378,7 @@ Supported masks:
- `greaterThanOrEq`: Include particles where field ≥ value
- `betweenEq`: Include particles where value1 ≤ field ≤ value2
## Implementation Notes
### 8.3. Implementation Notes
- The postprocessing system can work both during simulation (`runTimeActive yes`) or after simulation completion.
- When using post-simulation mode, you must specify the correct `shapeType` to properly initialize the shape objects.
@ -347,17 +386,179 @@ Supported masks:
- The `threshold` parameter helps eliminate statistical noise in regions with few particles.
- Setting `divideByVolume` to `yes` normalizes results by the volume of the region, useful for calculating densities.
## Mathematical Formulations
## 9. Mathematical Formulations
For weighted `bulk` properties calculation:
For weighted `bulk` properties calculation, we have these two general formulations:
- For weighted averaging:
$$ \text{average} = \frac{\sum_{i \in \text{region and includeMask}} w_i \cdot \phi_i \cdot \text{field}_i}{\sum_{i \in \text{region}} w_i \cdot \phi_i} $$
$$ \text{average} = \frac{\sum_j w_j \cdot \phi_j \cdot \text{field}_j}{\sum_i w_i \cdot \phi_i} $$
For weighted summing:
- For weighted summing:
$$ \text{sum} = \sum_{i \in \text{region and includeMask}} w_i \cdot \phi_i \cdot \text{field}_i $$
$$ \text{sum} = \sum_j w_j \cdot \phi_j \cdot \text{field}_j $$
If `divideByVolume` is set to `yes`, the result is divided by the volume of the region:
$$ \text{volumetric result} = \frac{\text{result}}{V_{\text{region}}} $$
## 10. A complete dictioanry file (postprocessDataDict)
```C++
/* -------------------------------*- C++ -*--------------------------------- *\
| phasicFlow File |
| copyright: www.cemf.ir |
\* ------------------------------------------------------------------------- */
objectName postprocessDataDict;
objectType dictionary;;
fileFormat ASCII;
/*---------------------------------------------------------------------------*/
// Yes: postprocessing is active during the simulation
// No: postprocessing is not active during the simulation
// and it can be done after simulation
runTimeActive yes;
// shapeType: defines the type of the shape that is used in the simulation
// (for example: sphere, grain, etc).
// shapeType is only used when postprocessing is done after simulation
// to initialize the shape object for post processing operatoins
shapeType sphere;
// default time control to be used in the postprocessing components
defaultTimeControl
{
timeControl timeStep; // timeStep, simulationTime are the options here
startTime 0;
endTime 1000;
executionInterval 150;
}
// list of postprocessing components
components
(
// probing particles for their state variables, like velocity, position, etc
velocityProb
{
processMethod particleProbe;
processRegion centerPoints;
selector id;
field component(position,y);
ids (0 10 100);
timeControl default; // other options are settings, timeStep, simulationTime
// settings: uses parameters from settingsDict file
// timeStep: uses the time step of the simulation controlling the execution of postprocessing
// simulationTime: uses the simulation time of the simulation controlling the execution of postprocessing
// default: uses the default time control (defined in defaultTimeControl).
// default behavior: if you do not specify it, parameters in defaultTimeControl is used.
}
on_single_sphere
{
// method of performing the sum (arithmetic, uniformDistribution, GaussianDistribution)
processMethod arithmetic;
// Postprocessing is done on particles whose centers are inside this spehre
processRegion sphere;
sphereInfo
{
radius 0.01; // radius of sphere
center (-0.08 -0.08 0.015); // center of sphere
}
timeControl default;
/// all the postprocess operations to be done on sphere region
operations
(
// computes the arithmetic mean of particle velocity
averageVel
{
function average;
field velocity;
fluctuation2 yes;
divideByVolume no; // default is no
threshold 3; // default is 1
includeMask all; // default is all
}
// - function: average, sum, and other derived ones from sum and average
// - field: names of the fields in the simulation. Some special fields
// are: mass, density, volume, position, one, I.
// - divideByVolume: whether the result is divided by the volume of the region
// - threshold: exclude regions that contains particles less than threshold
// - includeMask: all, lessThan, greaterThan, between, lessThanOrEq, greaterThanEq, betweenEq
// computes the fraction of par1 in the region
par1Fraction
{
function average;
field one; // default
phi one; // default
divideByVolume no;
includeMask lessThan;
// diameter of par1 is 0.003, so these settings
// will select only particles of type par1
lessThanInfo
{
field diameter;
value 0.0031;
}
}
numberDensity
{
function sum;
field one;
phi one;
divideByVolume yes;
}
);
}
along_a_line
{
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);
nSpheres 10;
radius 0.01;
}
operations
(
// computes the arithmetic mean of particle velocity
numberDensity
{
function sum;
field one;
divideByVolume yes; //default is no
}
volumeDensity
{
function sum;
field volume; //
divideByVolume yes; //default is no
}
);
}
);
```

View File

@ -70,6 +70,7 @@ components
{
function average;
field velocity;
fluctuation2 yes;
divideByVolume no; // default is no
threshold 3; // default is 1
includeMask all; // default is all
@ -113,91 +114,44 @@ components
along_a_line
{
processMethod arithmetic;
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
{
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);
nSpheres 10;
radius 0.01;
}
operations
(
// computes the arithmetic mean of particle velocity
numberDensity
{
function sum;
field one;
divideByVolume yes; //default is no
}
volumeDensity
{
}
operations
(
// computes the arithmetic mean of particle velocity
numberDensity
{
function sum;
field one;
divideByVolume yes; //default is no
}
volumeDensity
{
function sum;
field volume; //
divideByVolume yes; //default is no
}
);
}
);
}
);
/*
About processMethod
This defines the type of the processing method to be done.
The processing is done either on a collection of selected particles (the first three ones)
or individual particles (particleProbe).
Options are:
- arithmetic
- uniformDistribution
- GaussianDistribution
- particleProbe (only used with centerPoints)
When you use the first three optoins, then you can either perform two types of processing is possible
- sum
\f[
\text{result} = \sum_{i \in \text{processRegion and includeMask}} w_i \cdot \phi_i \cdot \text{field}_i
\f]
- average
\f[
\text{result} = \frac{1}{V_{\text{region}}} \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]
*/
/*
About processRegion
processRegion, defines processing regions on which postprocess operation are performed. Particles
whose centers are inside the regions are selected for post processing operation. Note that
you are allowed to use a correct combination of processRegion and processMethod.
For example centerPoints only works with particleProbe.
Options are:
- sphere
- multipleSpheres
- line
- centerPoints (only works with particleProbe)
- rectMesh: Not implemented yet
- generalMesh: not implemented yet
*/