hips
Loading...
Searching...
No Matches
hips Class Reference

Detailed Description

Definition at line 16 of file hips.h.

#include <hips.h>

Public Member Functions

void set_tree (int nLevels_, double domainLength_, double tau0_, std::vector< double > &ScHips_)
 Sets up the HiPS tree using explicitly specified tree parameters.
 
void set_tree (double Re_, double domainLength_, double tau0_, std::vector< double > &ScHips_, std::string approach_="rounding")
 Dynamically builds the HiPS tree based on Reynolds number and a selected strategy.
 
void set_varData (std::vector< double > &v, std::vector< double > &w, const std::string &varN)
 Assigns variables, their corresponding weights, and names to the parcels in the HiPS tree.
 
void set_varData (std::vector< double > &v, std::vector< double > &w, const std::string &varN, const std::vector< double > &rho)
 Assigns variables, weights, names, and densities to the parcels in the HiPS tree.
 
std::vector< std::vector< double > > get_varData ()
 Retrieves the final data from the simulation.
 
std::vector< std::pair< std::vector< double >, std::vector< double > > > get_varData_with_density ()
 Retrieves final simulation data, including both values and densities.
 
void setOutputIntervalTime (double interval)
 Sets the interval (in simulation time) for writing simulation data.
 
void setOutputIntervalEddy (int interval)
 Sets the interval (in number of eddy events) for writing simulation data.
 
void calculateSolution (const double tRun, bool shouldWriteData=false)
 Runs the HiPS simulation, advancing the solution using eddy events.
 
 hips (double C_param_, int forceTurb_, int nVar_, bool performReaction, std::shared_ptr< void > vcantSol=nullptr, int seed=10, int realization_=1)
 Constructor for initializing a HiPS object without building the tree immediately.
 
 hips (int nLevels_, double domainLength_, double tau0_, double C_param_, int forceTurb_, int nVar_, std::vector< double > &ScHips_, bool performReaction, std::shared_ptr< void > vcantSol=nullptr, int seed=10, int realization_=1)
 Constructor for initializing the full HiPS tree at the time of object creation.
 
void resetForNewRealization ()
 

Public Attributes

int nparcels
 number of parcels
 
int realization
 number of realizations
 
std::vector< std::shared_ptr< std::vector< double > > > varData
 vector of pointers to vector
 
double domainLength
 length of domain (m)
 
double tau0
 integral timescale
 
double C_param
 Eddy frequency parameter.
 
std::vector< double > Temp
 Vector containg temperature in each parcel;.
 

Private Member Functions

std::vector< double > projection (std::vector< double > &vcfd, std::vector< double > &weight)
 Projects values from flow particles onto HiPS parcels assuming constant density.
 
std::pair< std::vector< double >, std::vector< double > > projection (std::vector< double > &vcfd, std::vector< double > &weight, const std::vector< double > &density)
 Projects the values from flow particles onto HiPS parcels, accounting for particle density.
 
std::vector< double > setGridHips (int N)
 Generates a physical domain for HiPS parcels.
 
std::vector< double > setGridCfd (std::vector< double > &w)
 Generates a physical domain for flow particles based on their weights.
 
std::vector< double > projection_back (std::vector< double > &vb)
 Projects HiPS parcel values back onto the flow particles.
 
std::pair< std::vector< double >, std::vector< double > > projection_back_with_density (std::vector< double > &vh, std::vector< double > &rho_h)
 Projects HiPS parcel values and densities back onto the flow particles.
 
void sample_hips_eddy (double &dt, int &iLevel)
 Samples stochastic eddy events on the HiPS tree, determining the time increment and tree level.
 
void selectAndSwapTwoSubtrees (const int iLevel, int &iTree)
 Performs eddy events by swapping parcels within the HiPS tree.
 
void advanceHips (const int iLevel, const int iTree)
 Advances the HiPS model by simulating micromixing and reactions at a specific tree level.
 
int getVariableIndex (const std::string &varName) const
 Retrieves the index of a variable by its name in the varName list.
 
void reactParcels_LevelTree (const int iLevel, const int iTree)
 Simulates chemical reactions for parcels affected by a micromixing event.
 
void mixAcrossLevelTree (int kVar, const int iMixLevel, const int iTree)
 Uniformly mixes parcels at a specified level and subtree within the HiPS model.
 
void forceProfile ()
 Adjusts the HiPS profile to enforce statistical stationarity.
 
void writeData (int real, const int ifile, const double outputTime)
 Writes simulation data to a file for a specific realization, time, and file index.
 
void saveAllParameters ()
 Saves all user-defined to a file.
 

Private Attributes

int currentIndex = 0
 member variable to keep track of current index of variables
 
int nLevels
 number of tree levels
 
int nLevels_
 number of tree levels?
 
int forceTurb
 forcing function for statistically stationary: -1 = none, 1 = source term, 2 = dir
 
int nVar
 number of parcel variables (e.g., h, ysp)
 
int nsp
 number of species
 
int Nm1
 nLevels - 1
 
int Nm2
 nLevels - 2

 
int Nm3
 nLevels - 3
 
int iEta
 Kolmogorov level (needed for variable Sc scalars)
 
int nL
 adjusted number of levels based on the Reynolds number
 
bool LScHips
 hips schmidt number
 
bool performReaction
 flag indicating whether chemical reactions are performed in the simulation
 
bool LrandSet
 flag indicating new randomGen --> allow deletion
 
double time
 current simulation time
 
double eddyRate_total
 total rate of all eddies 0 through nLevels-3
 
double eddyRate_inertial
 total rate of all eddies 0 through iEta (= eddyRate_total if Sc=1)
 
double Afac = 0.5
 level lengthscale reduction factor (0.5)
 
double Re
 Reynolds number.
 
double dtEE
 time increment to next eddy event
 
double Prob
 probability value for probability-based solution
 
double lStar
 length of the level associated with the Reynolds number
 
double Anew
 adjusted level lengthscale reduction factor for dynamic adjustment of reduction factor
 
randomGenerator rand
 
std::vector< int > i_plus
 ceil(i_batchelor)
 
std::vector< int > pLoc
 parcel index array for fast implementation of swaps
 
std::vector< double > varRho
 
std::vector< double > ScHips
 vector containing Schmidt numbers related to each variable
 
std::vector< std::string > varName
 vector containing the names of parcel variables
 
std::vector< double > parcelTimes
 current times corresponding to the parcel states
 
std::vector< double > levelRates
 list of eddy event rates at each level
 
std::vector< double > i_batchelor
 Batchelor level for variable Sc scalars; NOTE: double, as in, between levels.
 
std::vector< double > xc
 vector containing physical domain of flow particles
 
std::vector< double > xh
 vector containing physical domain of HiPS parcels
 
std::string approach
 
int outputIntervalEddy = 10
 Default: write data every 10 eddy events.
 
double outputIntervalTime = 0.1
 Default: write data every 0.1s.
 
int eddyCounter = 0
 Counter for eddy events.
 
double lastOutputTime = 0.0
 Last time data was written.
 
bool useEddyBasedWriting = false
 Tracks if eddy writing is set.
 
bool useTimeBasedWriting = false
 Tracks if time writing is set.
 
const int DEFAULT_EDDY_INTERVAL = 1000
 Default: Write every 1000 eddies.
 
const double DEFAULT_TIME_INTERVAL = 0.1
 Default: Write every 0.1s.
 

Constructor & Destructor Documentation

◆ hips() [1/2]

hips::hips ( double C_param_,
int forceTurb_,
int nVar_,
bool performReaction,
std::shared_ptr< void > vcantSol = nullptr,
int seed = 10,
int realization_ = 1 )

Constructor for initializing a HiPS object without building the tree immediately.

This constructor is designed for simulations where the HiPS tree must be configured dynamically, such as grid-based simulations with cell-specific turbulence properties. The tree can be created or updated later using one of the set_tree functions.

Parameters
C_param_Eddy coefficient controlling mixing rate.
forceTurb_Flag to enforce turbulence activation.
nVar_Number of transported variables.
performReaction_Enables chemical reactions if set to true.
cantSolCantera solution object (required when REACTIONS_ENABLED).
seedRandom seed (negative for random initialization).
realization_Realization index for ensemble or parallel runs.
Note
This constructor does not call any set_tree() function. The user is responsible for building the tree explicitly by calling either version of set_tree(...).
See the full constructor for chemical integrator behavior under REACTIONS_ENABLED.
See also
hips::set_tree() for deferred tree construction.

◆ hips() [2/2]

hips::hips ( int nLevels_,
double domainLength_,
double tau0_,
double C_param_,
int forceTurb_,
int nVar_,
std::vector< double > & ScHips_,
bool performReaction,
std::shared_ptr< void > vcantSol = nullptr,
int seed = 10,
int realization_ = 1 )

Constructor for initializing the full HiPS tree at the time of object creation.

This constructor is intended for simulations where the domain structure and turbulence properties are fixed throughout the run (e.g., standalone mixing or reacting cases). The HiPS tree is initialized immediately using the provided parameters, and the structure remains constant throughout the simulation.

Parameters
nLevels_Number of levels in the HiPS binary tree (can be adjusted for high Sc).
domainLength_Domain length for defining spatial scales.
tau0_Characteristic time scale for the smallest eddy.
C_param_Eddy coefficient controlling mixing rate.
forceTurb_Flag to enforce turbulence activation.
nVar_Number of transported variables.
ScHips_Vector of Schmidt numbers (one per variable).
performReaction_Enables chemical reactions if set to true.
cantSolCantera solution object (required when REACTIONS_ENABLED).
seedRandom seed (negative for random initialization).
realization_Realization index for ensemble or parallel runs.
Note
This constructor calls set_tree(nLevels, domainLength, tau0, ScHips) internally to fully build the tree at initialization time. This setup is optimal for cases where tree reconfiguration is not needed during runtime.
If REACTIONS_ENABLED is defined, the default chemical integrator is batchReactor_cvode. To use batchReactor_cantera instead, uncomment the corresponding line in the constructor code.
See also
hips::set_tree() for the internal tree setup logic.

Member Function Documentation

◆ set_tree() [1/2]

void hips::set_tree ( int nLevels_,
double domainLength_,
double tau0_,
std::vector< double > & ScHips_ )

Sets up the HiPS tree using explicitly specified tree parameters.

This method builds the binary HiPS tree using a user-defined number of levels and physical parameters. It also automatically adjusts the number of levels to account for high Schmidt numbers, ensuring that micromixing is properly resolved.

Parameters
nLevels_Base number of levels in the HiPS tree.
domainLength_Domain size for determining eddy length scales.
tau0_Time scale of the smallest eddy (Kolmogorov scale).
ScHips_Vector of Schmidt numbers (one per variable).
Note
This function is used by the full constructor and can also be called manually after using the dynamic constructor.
Warning
The number of levels may be increased automatically for large Schmidt numbers to ensure accurate scalar mixing across scales.

◆ set_tree() [2/2]

void hips::set_tree ( double Re_,
double domainLength_,
double tau0_,
std::vector< double > & ScHips_,
std::string approach_ = "rounding" )

Dynamically builds the HiPS tree based on Reynolds number and a selected strategy.

This method configures the HiPS tree using a continuous Reynolds number and one of several initialization strategies. It is intended for simulations where local turbulence conditions change over time or space, requiring the tree to be updated dynamically.

Parameters
Re_Reynolds number used to determine base tree level.
domainLength_Domain length for spatial scaling.
tau0_Base time scale for the largest eddy.
ScHips_Vector of Schmidt numbers (one per variable).
approach_Strategy to convert continuous Re to tree level:
  • "rounding" → Round to nearest discrete level
  • "probability" → Use probabilistic interpolation between levels
  • "micromixing" → Use fixed level with adjusted mixing rate
  • "dynamic_A" → Adjust geometric scale factor A to fit Re
Note
This method is ideal for Lagrangian simulations using grid cells with different Re values. It supports runtime reconfiguration of the tree without reinitializing the hips object.
Warning
Ensure consistent approach_ handling across the simulation to avoid inconsistencies.
See also
hips::set_tree(int, ...) for direct-level setup.

Definition at line 209 of file hips.cc.

◆ set_varData() [1/2]

void hips::set_varData ( std::vector< double > & v,
std::vector< double > & w,
const std::string & varN )

Assigns variables, their corresponding weights, and names to the parcels in the HiPS tree.

This function projects the provided variables onto the parcels within the HiPS tree structure, using their corresponding weights. It ensures that each parcel in the tree is associated with the correct variable and weight, along with a descriptive name for better identification.

Parameters
vVector of variables to be assigned to the parcels in the HiPS tree.
wVector of weights corresponding to each variable or parcel.
varNString representing the name of the variable being assigned.
Note
The size of v and w must match to ensure a one-to-one correspondence between variables and their weights. The function does not perform size validation internally.
Warning
Ensure that the weights in w are normalized or appropriately scaled, as they directly influence the projection and subsequent simulations.

Definition at line 337 of file hips.cc.

◆ set_varData() [2/2]

void hips::set_varData ( std::vector< double > & v,
std::vector< double > & w,
const std::string & varN,
const std::vector< double > & rho )

Assigns variables, weights, names, and densities to the parcels in the HiPS tree.

This overloaded function assigns the specified variables, along with their associated weights, names, and densities, to the parcels within the HiPS tree structure. The function incorporates particle density during the projection process, ensuring a more accurate representation of parcel properties in the simulation.

Parameters
vVector of variables to be assigned to the HiPS tree.
wVector of weights corresponding to each variable or parcel.
varNString representing the name of the variable being assigned.
rhoVector of densities corresponding to each flow particle.
Note
This function is specifically overloaded to account for particle density, which enhances the accuracy of the parcel projection. Ensure that the size of v, w, and rho are consistent.
Warning
The values in rho should be physically meaningful and consistent with the simulation's requirements. Improper density values may lead to inaccuracies or instabilities in the simulation.

Definition at line 365 of file hips.cc.

◆ get_varData()

std::vector< std::vector< double > > hips::get_varData ( )

Retrieves the final data from the simulation.

This function returns the final state of the simulation, packaged as a vector of vectors. It is particularly useful when integrating HiPS as a subgrid model in CFD simulations, enabling seamless transfer of data for further analysis or post-processing.

Returns
A vector of vectors containing the final results, where:
  • Each inner vector represents a specific variable or property.
  • The outer vector contains all variables across parcels.
Note
  • This function is specifically designed for use when HiPS is employed as a subgrid model in CFD simulations.
  • The structure of the returned data ensures compatibility with CFD solvers that require parcel-level data.
Warning
  • Ensure the simulation has reached completion before calling this function to avoid incomplete or inconsistent data.
  • The returned data structure should be interpreted according to the simulation setup and variable ordering.

Definition at line 1311 of file hips.cc.

◆ get_varData_with_density()

std::vector< std::pair< std::vector< double >, std::vector< double > > > hips::get_varData_with_density ( )

Retrieves final simulation data, including both values and densities.

This function processes the HiPS data and projects both the values and densities back onto the flow particles. It returns a vector of pairs, where each pair contains the values and corresponding densities for a specific variable. This function is designed to support HiPS as a subgrid model in CFD simulations, ensuring compatibility with solvers that require both values and density information.

Returns
A vector of pairs:
  • Each pair consists of two vectors:
    • The first vector contains the final results for the values.
    • The second vector contains the corresponding density results.
Note
  • This function is tailored for integrating HiPS as a subgrid model in CFD simulations, providing both value and density data for accurate modeling.
  • Ensure that all HiPS parcels are properly initialized and contain valid values and densities before invoking this function.

Definition at line 1341 of file hips.cc.

◆ setOutputIntervalTime()

void hips::setOutputIntervalTime ( double interval)

Sets the interval (in simulation time) for writing simulation data.

Calling this function enables time-based writing and disables eddy-based writing. If the user does not call this function or setOutputIntervalEddy(), the default behavior is eddy-based writing every 1000 eddies.

Parameters
intervalThe time interval (in seconds) between data writes (e.g., 0.1 writes data every 0.1s).
Note
Calling this function automatically disables eddy-based writing (setOutputIntervalEddy()). To revert to default settings, the user must explicitly set a new interval or avoid calling this function.

< Enables time-based writing

< Disables eddy-based writing

Definition at line 1390 of file hips.cc.

◆ setOutputIntervalEddy()

void hips::setOutputIntervalEddy ( int interval)

Sets the interval (in number of eddy events) for writing simulation data.

Calling this function enables eddy-based writing and disables time-based writing. If the user does not call this function or setOutputIntervalTime(), the default interval is set to 1000 eddy events.

Parameters
intervalThe number of eddy events between data writes (e.g., 1000 writes data every 1000 eddies).
Note
Calling this function automatically disables time-based writing (setOutputIntervalTime()). To revert to default settings, the user must explicitly set a new interval or avoid calling this function.

< Enables eddy-based writing

< Disables time-based writing

Definition at line 1370 of file hips.cc.

◆ calculateSolution()

void hips::calculateSolution ( const double tRun,
bool shouldWriteData = false )

Runs the HiPS simulation, advancing the solution using eddy events.

This function performs the core HiPS loop: sampling eddy events, performing subtree swaps, advancing parcels, and optionally triggering reactions. It runs until the specified simulation time (tRun) is reached and writes data periodically based on either eddy count or elapsed simulation time.

Key operations:

  • Samples the next eddy event time (dtEE)
  • Selects and swaps subtrees at a given level
  • Applies micromixing and reactions (if enabled)
  • Writes output data either:
    • Every outputIntervalEddy eddy events (if enabled), or
    • Every outputIntervalTime seconds (if enabled)
  • At the end of the simulation, calls saveAllParameters() to store input and configuration data in ../post/parameters.dat.
Parameters
tRunTotal simulation run time (in seconds).
shouldWriteDataFlag to enable/disable periodic data writing.
Note
To control output frequency, use:
Output files are saved using writeData(realization, ...) and include the realization index.
At the end of the run, saveAllParameters() is automatically called to document simulation settings.
Warning
Long simulations may generate many output files. Adjust output intervals or disable writing (shouldWriteData = false) to manage storage needs.
See also
hips::writeData(), hips::saveAllParameters()

Definition at line 608 of file hips.cc.

◆ projection() [1/2]

std::vector< double > hips::projection ( std::vector< double > & vcfd,
std::vector< double > & weight )
private

Projects values from flow particles onto HiPS parcels assuming constant density.

This function maps the values of flow particles onto HiPS parcels under the assumption of constant density. The projection is performed using the following equation:

\[ \sum_{i=0}^{\text{Number of Flow Particles (FP)}} (\phi_{\text{FP}} \, \mathrm{d}x_{\text{FP}})_{i} = \sum_{j=0}^{\text{Number of HiPS Parcels (HP)}} (\phi_{\text{HP}} \, \mathrm{d}x_{\text{HP}})_{j} \]

This ensures conservation of properties such as mass or concentration during the projection.

Parameters
vcfdVector of variables from flow particles to be mapped to HiPS parcels.
weightVector of weights, with one weight assigned to each flow particle.
Returns
Vector of projected values for HiPS parcels.
Note
The function assumes constant density throughout the domain. For cases with varying density, use an appropriate overloaded function or method.
Warning
Ensure that the vcfd and weight vectors have matching sizes, as any discrepancy may result in undefined behavior or incorrect projections.

Definition at line 400 of file hips.cc.

◆ projection() [2/2]

std::pair< std::vector< double >, std::vector< double > > hips::projection ( std::vector< double > & vcfd,
std::vector< double > & weight,
const std::vector< double > & density )
private

Projects the values from flow particles onto HiPS parcels, accounting for particle density.

This function calculates the projection of values from flow particles onto HiPS parcels, incorporating the density of each particle into the computation. The resulting projection ensures conservation of both the property values and the density. The function returns a pair of vectors: one representing the projected values on the HiPS parcels and another for the densities.

Parameters
vcfdVector of variables from flow particles to be projected onto HiPS parcels.
weightVector of weights corresponding to each flow particle.
densityVector of densities associated with each flow particle.
Returns
A pair of vectors:
  • First vector: Projected values on the HiPS parcels.
  • Second vector: Densities on the HiPS parcels.
Note
This is an overloaded version of the projection function, designed to include particle density in the computation. Ensure that the vcfd, weight, and density vectors are of equal size for consistency.
Warning
Discrepancies in the size of the input vectors (vcfd, weight, and density) may lead to undefined behavior or inaccurate projections. Verify the inputs before calling this function.

Definition at line 464 of file hips.cc.

◆ setGridHips()

std::vector< double > hips::setGridHips ( int N)
private

Generates a physical domain for HiPS parcels.

This function creates a grid of positions for HiPS parcels, where each parcel occupies an equal portion of the physical domain. The total size of the domain corresponds to the size specified in the setGridCfd() function, ensuring consistency between the HiPS and flow particle domains.

Parameters
NThe number of grid points for the HiPS parcels.
Returns
A vector representing the grid positions for the HiPS parcels.
Note
The function assumes that the physical domain is evenly divided among the parcels. Ensure that the number of grid points (N) is consistent with the physical domain size defined in the simulation setup.
Warning
If N is less than or equal to zero, the function may produce an empty or invalid grid. Validate the input to avoid unexpected behavior.

Definition at line 560 of file hips.cc.

◆ setGridCfd()

std::vector< double > hips::setGridCfd ( std::vector< double > & w)
private

Generates a physical domain for flow particles based on their weights.

This function creates a grid of positions for flow particles, where each particle occupies a portion of the domain proportional to its weight. The total length of the domain is assumed to be 1, and the sum of all portions equals 1. The resulting vector represents the positions of particles along the domain.

Parameters
wVector of weights, where each weight determines the portion of the domain occupied by a particle.
Returns
A vector of grid positions for the flow particles.
Note
The function assumes that the weights in w are normalized or properly scaled such that the total sum matches the domain length of 1. If the weights are not normalized, the resulting grid may not represent a valid physical domain.
Warning
Ensure that the input weight vector w is non-empty and contains positive values. Zero or negative weights may lead to undefined behavior or invalid domain generation.

Definition at line 526 of file hips.cc.

◆ projection_back()

std::vector< double > hips::projection_back ( std::vector< double > & vh)
private

Projects HiPS parcel values back onto the flow particles.

This function reverses the projection process, redistributing the values stored in the HiPS parcels back to the flow particles. It ensures conservation of properties such as mass or concentration by maintaining consistency between the HiPS parcels and flow particles.

Conservation Principle:

The projection follows the equation:

\[ \sum_{j=0}^{\text{Number of HP}} (\phi_{\text{HP}} \, \mathrm{d}x_{\text{HP}})_{j} = \sum_{i=0}^{\text{Number of FP}} (\phi_{\text{FP}} \, \mathrm{d}x_{\text{FP}})_{i} \]

where:

  • \(\phi_{\text{HP}}\): Values in HiPS parcels.
  • \(\mathrm{d}x_{\text{HP}}\): Differential volume elements for HiPS parcels.
  • \(\phi_{\text{FP}}\): Values in flow particles.
  • \(\mathrm{d}x_{\text{FP}}\): Differential volume elements for flow particles.
Parameters
vhVector of values from HiPS parcels to be projected back.
Returns
Vector of values redistributed onto the flow particles.
Note
  • This function is the reverse of the projection function, ensuring consistency in value transfers between HiPS parcels and flow particles.
  • The input vector vh should be consistent with the HiPS parcel structure.
Warning
  • Ensure that the HiPS parcels have been properly populated with values before invoking this function.
  • Mismatches in data sizes between HiPS parcels and flow particles may lead to unexpected results.

Definition at line 1180 of file hips.cc.

◆ projection_back_with_density()

std::pair< std::vector< double >, std::vector< double > > hips::projection_back_with_density ( std::vector< double > & vh,
std::vector< double > & rho_h )
private

Projects HiPS parcel values and densities back onto the flow particles.

This function reverses the projection process, redistributing both the values and densities stored in the HiPS parcels back to the flow particles. It ensures conservation of both the property values and densities, maintaining consistency between the HiPS parcels and flow particles.

Conservation Principle:

The projection follows the equation:

\[ \sum_{j=0}^{\text{Number of HP}} (\phi_{\text{HP}} \, \rho_{\text{HP}} \, \mathrm{d}x_{\text{HP}})_{j} = \sum_{i=0}^{\text{Number of FP}} (\phi_{\text{FP}} \, \rho_{\text{FP}} \, \mathrm{d}x_{\text{FP}})_{i} \]

where:

  • \(\phi_{\text{HP}}\): Values in HiPS parcels.
  • \(\rho_{\text{HP}}\): Densities in HiPS parcels.
  • \(\mathrm{d}x_{\text{HP}}\): Differential volume elements for HiPS parcels.
  • \(\phi_{\text{FP}}\): Values in flow particles.
  • \(\rho_{\text{FP}}\): Densities in flow particles.
  • \(\mathrm{d}x_{\text{FP}}\): Differential volume elements for flow particles.
Parameters
vhVector of values from HiPS parcels to be projected back.
rho_hVector of density values from HiPS parcels.
Returns
A pair of vectors:
  • The first vector contains the values projected back onto the flow particles.
  • The second vector contains the densities redistributed to the flow particles.
Note
  • This function is the reverse of the projection function that includes density.
  • The input vectors vh and rho_h should be consistent with the HiPS parcel structure and sizes.
Warning
  • Ensure that the HiPS parcels are populated with valid values and densities before invoking this function.
  • Mismatches in data sizes between HiPS parcels and flow particles may lead to inaccurate results.

Definition at line 1256 of file hips.cc.

◆ sample_hips_eddy()

void hips::sample_hips_eddy ( double & dtEE,
int & iLevel )
private

Samples stochastic eddy events on the HiPS tree, determining the time increment and tree level.

This function performs stochastic sampling to determine when ( \(\Delta t_{EE}\)) and at what level ( \(i_{Level}\)) in the HiPS tree the next eddy event will occur. The time to the next eddy event is sampled based on the total eddy rate. The tree level of the event is chosen depending on whether it occurs in the inertial or Batchelor region of turbulence.

Parameters
dtEETime increment to the next eddy event ( \(\Delta t_{EE}\)), sampled stochastically.
iLevelTree level ( \(i_{Level}\)) at which the eddy event occurs, determined probabilistically.
Note
The function distinguishes between events in the inertial and Batchelor regions based on turbulence properties. Ensure that the HiPS tree is correctly initialized before calling this function.
Warning
The stochastic nature of this function requires a properly seeded random generator to ensure reproducibility in simulations where determinism is necessary.

Definition at line 680 of file hips.cc.

◆ selectAndSwapTwoSubtrees()

void hips::selectAndSwapTwoSubtrees ( const int iLevel,
int & iTree )
private

Performs eddy events by swapping parcels within the HiPS tree.

This function executes parcel swaps by randomly selecting nodes at the specified level of the HiPS tree. It identifies the starting indices of subtrees to be swapped, calculates the number of parcels to swap, and performs the swap operation efficiently using bitwise operations. The process mimics the hierarchical structure of turbulent mixing.

Parameters
iLevelInput level of the tree where the base of the swap occurs.
iTreeOutput parameter indicating which subtree at the given level is selected for swapping.

The process is as follows:

  • Randomly select a node on iLevel.
  • Traverse two levels down to identify subtrees 0q and 1r, where q and r are random binary values (0 or 1).
  • Determine the starting indices of the Q-tree and R-tree for the swap and compute the number of parcels.
  • Swap the corresponding parcels between the subtrees.

Example for a 6-level tree:

  • Tree levels: 0, 1, 2, 3, 4, 5.
  • If iLevel = 1:
    • Suppose the selected node is i = 01.
    • Subtrees for swapping are 0q = 00 and 1r = 11.
    • Swapping involves parcels 0100** with 0111**, or (01|00|**) with (01|11|**).
    • In binary terms, the swap is equivalent to exchanging i0qs with i1rs, where:
      • i = 01
      • 0q = 00
      • 1r = 11
      • s = ** (remaining bits).

Implementation:

  • Bitwise operations are used for efficient calculations of powers of 2.
  • The swap operation is performed by flipping the bits for 0q and 1r, which effectively swaps the subtrees.

Visual Representation of Tree:

Level 0 * (root)
/ \
Level 1 * (*)
/ \ / \
Level 2 * * * *
Level 3 * [*] * [*]
Level 4 * * * * * * * *
Level 5 00 01 02 03 ... 30 31
  • Subtrees 0q and 1r correspond to specific branches of the tree.
  • Swapping occurs within highlighted sections of Level 3, identified by bit manipulation.
Warning
Ensure that the input iLevel is within the valid range of tree levels and that the tree is properly initialized before invoking this function.

Definition at line 762 of file hips.cc.

◆ advanceHips()

void hips::advanceHips ( const int iLevel,
const int iTree )
private

Advances the HiPS model by simulating micromixing and reactions at a specific tree level.

This function models the interaction of parcels within the HiPS tree structure at a given level, simulating the effects of micromixing and reactions. The process involves determining whether conditions for micromixing are met and, if so, triggering reactions and mixing for parcels under the specified node. The operation depends on turbulence forcing and micromixing thresholds.

Parameters
iLevelThe level of the HiPS tree at which the eddy event occurs.
iTreeThe root node of the eddy event at the specified level.

Key Operations:

  • Identifies parcels within the specified tree level.
  • Checks whether conditions for micromixing are satisfied.
  • Applies turbulence forcing if enabled.
  • Triggers reactions for the first variable that meets micromixing conditions.
  • Applies mixing to subsequent variables without additional reactions.
Note
Reactions are only performed for the first variable that satisfies the micromixing conditions. For all subsequent variables, only mixing operations are performed.
Warning
Ensure that the HiPS tree structure is properly initialized and that iLevel and iTree correspond to valid levels and nodes within the tree to prevent undefined behavior.

Definition at line 804 of file hips.cc.

◆ getVariableIndex()

int hips::getVariableIndex ( const std::string & varName) const
private

Retrieves the index of a variable by its name in the varName list.

This function searches the varName list for the specified variable name and determines its index. It uses std::find and std::distance to locate the variable efficiently. If the variable name is not found, the function throws a std::runtime_error. This functionality is crucial for referencing variables dynamically within the HiPS model.

Parameters
varNameThe name of the variable to search for (e.g., "enthalpy").
Returns
int The index of the variable in the varName list.
Exceptions
std::runtime_errorIf the variable name is not found in the varName list.

Usage Example:

// Assume varName list is populated: {"temperature", "enthalpy", "density"}
int index = hips.get_varIndex("enthalpy"); // Returns 1
Definition hips.h:16
Note
This function is case-sensitive and assumes that the varName list has been populated, typically via the set_varData method. Ensure that the variable names match exactly, including case, to avoid errors.
Warning
If the varName list is empty or not properly populated, the function may throw unexpected errors. Verify the list contents before invoking this method.
See also
set_varData

Definition at line 852 of file hips.cc.

◆ reactParcels_LevelTree()

void hips::reactParcels_LevelTree ( const int iLevel,
const int iTree )
private

Simulates chemical reactions for parcels affected by a micromixing event.

This function performs chemical reactions for parcels involved in a micromixing process at a specific level and tree node within the HiPS structure. The reaction times are determined based on the last reaction time stored in parcelTimes. It dynamically retrieves the indices of relevant variables such as enthalpy and species mass fractions for accurate state updates.

Parameters
iLevelThe tree level where the eddy event occurred.
iTreeThe root node of the eddy event at the specified level.
  • getVariableIndex("enthalpy") is used to retrieve the index for enthalpy.
  • Indices for species are dynamically retrieved using gas->speciesName(i).
  • The function updates parcel states, including enthalpy and species mass fractions, based on the reactions.
Exceptions
std::runtime_errorIf a variable name is not found in the varName list.
Note
  • The varName list must be populated using set_varData before invoking this function.
  • Reaction functionality is only available if REACTIONS_ENABLED is defined during compilation.
  • This function relies on the HiPS model's proper initialization and an accurate setup of parcelTimes.
Warning
Ensure that the necessary reaction data and variable names are correctly configured. Missing or incorrectly configured varName entries may lead to runtime errors.
See also
set_varData, getVariableIndex

Definition at line 889 of file hips.cc.

◆ mixAcrossLevelTree()

void hips::mixAcrossLevelTree ( int kVar,
const int iLevel,
const int iTree )
private

Uniformly mixes parcels at a specified level and subtree within the HiPS model.

This function performs uniform mixing of parcels based on their average values at a specified level and subtree of the HiPS tree. It is particularly suited for low Schmidt number ( \(Sc\)) variables and supports mixing at levels above the lowest in the tree. Parcels are mixed in pairs or groups depending on the level and subtree index.

Parameters
kVarIndex of the variable to be mixed (typically a transported variable determined by the caller).
iLevelThe tree level whose grandchildren will be mixed.
iTreeThe subtree at the given level where mixing will occur.

Process Overview:

  • At each level, the function mixes parcels in pairs or larger groups as determined by the tree structure.
  • The level (iLevel) defines the size of the groups to mix:
    • Higher levels mix larger groups (e.g., groups of 4 parcels at Level 1).
    • Lower levels mix smaller groups (e.g., pairs of parcels at Level 2).
  • Mixing is performed uniformly by averaging the variable values (kVar) of parcels.

Example for a 5-Level Tree (Levels: 0 to 4):

  • iLevel = 2:
    • If iTree = 0, parcels (0,1) and (2,3) will be mixed.
    • If iTree = 1, parcels (4,5) and (6,7) will be mixed.
    • If iTree = 2, parcels (8,9) and (10,11) will be mixed.
    • If iTree = 3, parcels (12,13) and (14,15) will be mixed.
  • iLevel = 1:
    • If iTree = 0, parcels (0,1,2,3) and (4,5,6,7) will be mixed.
    • If iTree = 1, parcels (8,9,10,11) and (12,13,14,15) will be mixed.

Notes:

  • Density Assumption: The function assumes all parcels have the same density. Be cautious when mixing scalars like mass fractions, as the current implementation directly mixes \(Y_i\).
  • Index Calculation: The function uses bitwise left shift (<<) to calculate the starting and ending indices for parcel mixing.
Warning
Ensure that iLevel and iTree correspond to valid levels and subtrees in the HiPS structure to prevent undefined behavior.

Definition at line 967 of file hips.cc.

◆ forceProfile()

void hips::forceProfile ( )
private

Adjusts the HiPS profile to enforce statistical stationarity.

This function modifies the parcel values in the HiPS profile to achieve statistical stationarity. Specifically, it adjusts the average value of parcels in the left half of the profile to 0 and the average value in the right half to 1. This is particularly useful for simple scalar variables, such as a mixture fraction ranging between 0 and 1.

Process Overview:

  • For each variable in the HiPS profile:
    1. Compute the average value of parcels in the left half.
    2. Compute the average value of parcels in the right half.
    3. Adjust the parcel values to enforce the desired averages (0 for the left half, 1 for the right half).
Note
  • This function directly modifies the parcel data in the HiPS profile.
  • It assumes that variable values are bounded and appropriate for normalization (e.g., scalars between 0 and 1).
Warning
  • Ensure that the HiPS profile is properly initialized and contains valid data before calling this function.
  • Unbounded or inappropriate variable values may lead to unexpected results.

Definition at line 1030 of file hips.cc.

◆ writeData()

void hips::writeData ( int real,
const int ifile,
const double outputTime )
private

Writes simulation data to a file for a specific realization, time, and file index.

This function saves the current state of simulation data to a file, organized by realization and time step. The output is stored in a subdirectory corresponding to the realization index (e.g., rlz_00000, rlz_00001), and the file is named sequentially (e.g., Data_00001.dat, Data_00002.dat) to maintain an ordered record of outputs. The simulation time is also written into the file for reference.

Key Operations:

  1. Creates a subdirectory named rlz_XXXXX based on the realization index.
  2. Constructs the output filename using the sequential file index.
  3. Writes the simulation variables (e.g., temperature, species mass fractions) in scientific format with high precision.
Parameters
realRealization index used to name the subdirectory (rlz_XXXXX).
ifileSequential index for naming the output file within the realization.
outputTimeSimulation time associated with the data, included in the file header.
Note
  • The function ensures the output directory for the specified realization is created if it does not exist.
  • It writes all data with high precision for accurate post-processing.
Warning
  • If the function fails to create the directory or open the output file, it may throw an error or silently fail. Ensure file system permissions and disk space are sufficient.

Definition at line 1086 of file hips.cc.

◆ saveAllParameters()

void hips::saveAllParameters ( )
private

Saves all user-defined to a file.

This function writes both input parameters (provided by the user) for post-processing. The file is stored in the post/ directory.

The file includes:

  • User-defined input parameters, such as grid levels, domain size, turbulence settings, and variable names.
Note
The parameters are saved to ../post/parameters.dat. Ensure that the post/ directory exists, or the function may fail to write the file.
Warning
If the file cannot be openedx, an error message is printed, and no data is saved.

< Output file path for simulation parameters

< Number of hierarchical levels in the HiPS model

< Length of the computational domain

< Reference eddy turnover time

< Model constant controlling turbulence behavior

< Flag for forced turbulence (1 = enabled, 0 = disabled)

< Number of variables tracked in the simulation

< Flag indicating whether chemical reactions are simulated

< Current simulation realization (for multiple runs)

< Separate variable names by spaces

< Print each element separated by space

Definition at line 1411 of file hips.cc.

◆ resetForNewRealization()

void hips::resetForNewRealization ( )
inline

Definition at line 261 of file hips.h.

Member Data Documentation

◆ nparcels

int hips::nparcels

number of parcels

Definition at line 22 of file hips.h.

◆ realization

int hips::realization

number of realizations

Definition at line 23 of file hips.h.

◆ varData

std::vector<std::shared_ptr<std::vector<double> > > hips::varData

vector of pointers to vector

Definition at line 24 of file hips.h.

◆ domainLength

double hips::domainLength

length of domain (m)

Definition at line 31 of file hips.h.

◆ tau0

double hips::tau0

integral timescale

Definition at line 32 of file hips.h.

◆ C_param

double hips::C_param

Eddy frequency parameter.

Definition at line 33 of file hips.h.

◆ Temp

std::vector<double> hips::Temp

Vector containg temperature in each parcel;.

Definition at line 34 of file hips.h.

◆ currentIndex

int hips::currentIndex = 0
private

member variable to keep track of current index of variables

Definition at line 38 of file hips.h.

◆ nLevels

int hips::nLevels
private

number of tree levels

Definition at line 39 of file hips.h.

◆ nLevels_

int hips::nLevels_
private

number of tree levels?

Definition at line 40 of file hips.h.

◆ forceTurb

int hips::forceTurb
private

forcing function for statistically stationary: -1 = none, 1 = source term, 2 = dir

Definition at line 41 of file hips.h.

◆ nVar

int hips::nVar
private

number of parcel variables (e.g., h, ysp)

Definition at line 42 of file hips.h.

◆ nsp

int hips::nsp
private

number of species

Definition at line 43 of file hips.h.

◆ Nm1

int hips::Nm1
private

nLevels - 1

Definition at line 44 of file hips.h.

◆ Nm2

int hips::Nm2
private

nLevels - 2

Definition at line 45 of file hips.h.

◆ Nm3

int hips::Nm3
private

nLevels - 3

Definition at line 46 of file hips.h.

◆ iEta

int hips::iEta
private

Kolmogorov level (needed for variable Sc scalars)

Definition at line 47 of file hips.h.

◆ nL

int hips::nL
private

adjusted number of levels based on the Reynolds number

Definition at line 48 of file hips.h.

◆ LScHips

bool hips::LScHips
private

hips schmidt number

Definition at line 50 of file hips.h.

◆ performReaction

bool hips::performReaction
private

flag indicating whether chemical reactions are performed in the simulation

Definition at line 51 of file hips.h.

◆ LrandSet

bool hips::LrandSet
private

flag indicating new randomGen --> allow deletion

Definition at line 52 of file hips.h.

◆ time

double hips::time
private

current simulation time

Definition at line 54 of file hips.h.

◆ eddyRate_total

double hips::eddyRate_total
private

total rate of all eddies 0 through nLevels-3

Definition at line 55 of file hips.h.

◆ eddyRate_inertial

double hips::eddyRate_inertial
private

total rate of all eddies 0 through iEta (= eddyRate_total if Sc=1)

Definition at line 56 of file hips.h.

◆ Afac

double hips::Afac = 0.5
private

level lengthscale reduction factor (0.5)

Definition at line 57 of file hips.h.

◆ Re

double hips::Re
private

Reynolds number.

Definition at line 58 of file hips.h.

◆ dtEE

double hips::dtEE
private

time increment to next eddy event

Definition at line 59 of file hips.h.

◆ Prob

double hips::Prob
private

probability value for probability-based solution

Definition at line 60 of file hips.h.

◆ lStar

double hips::lStar
private

length of the level associated with the Reynolds number

Definition at line 61 of file hips.h.

◆ Anew

double hips::Anew
private

adjusted level lengthscale reduction factor for dynamic adjustment of reduction factor

Definition at line 62 of file hips.h.

◆ rand

randomGenerator hips::rand
private

Definition at line 64 of file hips.h.

◆ i_plus

std::vector<int> hips::i_plus
private

ceil(i_batchelor)

Definition at line 66 of file hips.h.

◆ pLoc

std::vector<int> hips::pLoc
private

parcel index array for fast implementation of swaps

Definition at line 67 of file hips.h.

◆ varRho

std::vector<double> hips::varRho
private

Definition at line 68 of file hips.h.

◆ ScHips

std::vector<double> hips::ScHips
private

vector containing Schmidt numbers related to each variable

Definition at line 69 of file hips.h.

◆ varName

std::vector<std::string> hips::varName
private

vector containing the names of parcel variables

Definition at line 70 of file hips.h.

◆ parcelTimes

std::vector<double> hips::parcelTimes
private

current times corresponding to the parcel states

Definition at line 71 of file hips.h.

◆ levelRates

std::vector<double> hips::levelRates
private

list of eddy event rates at each level

Definition at line 72 of file hips.h.

◆ i_batchelor

std::vector<double> hips::i_batchelor
private

Batchelor level for variable Sc scalars; NOTE: double, as in, between levels.

Definition at line 73 of file hips.h.

◆ xc

std::vector<double> hips::xc
private

vector containing physical domain of flow particles

Definition at line 74 of file hips.h.

◆ xh

std::vector<double> hips::xh
private

vector containing physical domain of HiPS parcels

Definition at line 75 of file hips.h.

◆ approach

std::string hips::approach
private

Definition at line 77 of file hips.h.

◆ outputIntervalEddy

int hips::outputIntervalEddy = 10
private

Default: write data every 10 eddy events.

Definition at line 78 of file hips.h.

◆ outputIntervalTime

double hips::outputIntervalTime = 0.1
private

Default: write data every 0.1s.

Definition at line 79 of file hips.h.

◆ eddyCounter

int hips::eddyCounter = 0
private

Counter for eddy events.

Definition at line 80 of file hips.h.

◆ lastOutputTime

double hips::lastOutputTime = 0.0
private

Last time data was written.

Definition at line 81 of file hips.h.

◆ useEddyBasedWriting

bool hips::useEddyBasedWriting = false
private

Tracks if eddy writing is set.

Definition at line 82 of file hips.h.

◆ useTimeBasedWriting

bool hips::useTimeBasedWriting = false
private

Tracks if time writing is set.

Definition at line 83 of file hips.h.

◆ DEFAULT_EDDY_INTERVAL

const int hips::DEFAULT_EDDY_INTERVAL = 1000
private

Default: Write every 1000 eddies.

Definition at line 84 of file hips.h.

◆ DEFAULT_TIME_INTERVAL

const double hips::DEFAULT_TIME_INTERVAL = 0.1
private

Default: Write every 0.1s.

Definition at line 85 of file hips.h.


The documentation for this class was generated from the following files: