hips
Loading...
Searching...
No Matches
hips.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef REACTIONS_ENABLED
4#include "cantera/base/Solution.h"
5#include "cantera/thermo.h"
6#include "batchReactor.h"
7#endif
8
9#include <iostream>
10#include <vector>
11#include <string>
12#include <vector>
13#include <memory>
14#include "randomGenerator.h"
15
16class hips {
17
19
20public:
21
23 std::vector<std::shared_ptr<std::vector<double>>> varData;
24 std::vector<double> varRho;
25 std::vector<int> pLoc;
26 std::vector<double> wPar;
27
28
29#ifdef REACTIONS_ENABLED
30 std::shared_ptr<Cantera::ThermoPhase> gas;
31 std::shared_ptr<batchReactor> bRxr;
32#endif
33
34 double domainLength;
35 double tau0;
36 double C_param;
37
38private:
39
41 int currentIndex = 0;
42 int nLevels;
44 int nVar;
45 int nsp;
46 int Nm1;
47 int Nm2;
48 int Nm3;
49 int iEta;
50 int nL;
51 bool forceTurb;
52
53 bool LScHips;
55
56 double time;
59 double Afac = 0.5;
60 double Re;
61 double dtEE;
62 double Prob;
63 double lStar;
64 double Anew;
65
67
68 std::vector<int> i_plus;
69 std::vector<double> ScHips;
70 std::vector<std::string> varName;
71 std::vector<double> parcelTimes;
72 std::vector<double> levelRates;
73 std::vector<double> i_batchelor;
74 std::vector<double> xc;
75 std::vector<double> xh;
76
77 std::string ReApproach;
79 double outputIntervalTime = 0.1;
80 int eddyCounter = 0;
81 double lastOutputTime = 0.0;
82 bool useEddyBasedWriting = false;
83 bool useTimeBasedWriting = false;
84 const int DEFAULT_EDDY_INTERVAL = 1000;
85 const double DEFAULT_TIME_INTERVAL = 0.1;
86 //bool density_weighted_mixing = false; ///< default: simple (uniform) mixing
87
88
89
91
92public:
93
111
112 void set_tree(int nLevels_, double domainLength_, double tau0_); // setting the HiPS tree based on the number of levels
113
114
138
139 void set_tree(double Re_, double domainLength_, double tau0_, std::string ReApproach_ = "rounding");
140
142
143 void set_varData(std::vector<double> &v, std::vector<double> &w, const std::string &varN); // passing all variables to vector of pointer
144 void set_varData(std::vector<double> &v, std::vector<double> &w, const std::string &varN,
145 const std::vector<double> &rho); // passing all variables to vector of pointer
146
147 std::vector<std::vector<double>> get_varData(); // Retrieves modified data from the HiPS library and stores it in the provided vector, projection to CFD
148 std::pair<std::vector<std::vector<double>>, std::vector<double>> get_varData_with_density();
149
150 void setOutputIntervalTime(double interval);
151 void setOutputIntervalEddy(int interval);
152
153 void calculateSolution(const double tRun, bool shouldWriteData =false); // Running simulations
154
155 void writeData(int real, const int ifile, const double outputTime); // Writing the results for a user-defined number of eddies in the data folder.
156 int get_nparcels() const { return nparcels; }
157
158 const std::vector<int>& get_pLoc() const { return pLoc; }
159 const std::vector<std::shared_ptr<std::vector<double>>>& get_HipsVarData_ptr() const { return varData; } // internal HiPS varData, sized to nparcels
160
161
162
163
164private:
165
166 std::vector<double> projection(std::vector<double> &vcfd, std::vector<double> &weight); // Perform vector projection of flow particles onto hips parcels operation without density
167
168 std::pair<std::vector<double>, std::vector<double>> projection(std::vector<double> &vcfd, std::vector<double> &weight,
169 const std::vector<double> &density); // Perform vector projection flow particles onto hips parcels operation with density
170
171 std::vector<double> setGridHips(int N); // Set Hips grid with a specified number of grid points equal to number of parcels
172 std::vector<double> setGridCfd(std::vector<double> &w); // Set CFD grid using provided weight vector
173 std::vector<double> projection_back(std::vector<double> &vb);
174 std::vector<double> projection_back_with_density(std::vector<double> &vh,
175 std::vector<double> &rho_h,
176 std::vector<double> &rho_c);
177
178
179
180
181 void sample_hips_eddy(double &dt, int &iLevel); // Sample hips eddy with specified time step and level
182 void selectAndSwapTwoSubtrees(const int iLevel, int &iTree); // Select and swap two subtrees in the level tree
183 void advanceHips(const int iLevel, const int iTree); // Advancing simulations to do mixing and reaction
184
185 int getVariableIndex(const std::string &varName) const;
186
187 void reactParcels_LevelTree(const int iLevel, const int iTree); // Reacting parcels involved in micro-mixing
188 void mixAcrossLevelTree(int kVar, const int iMixLevel, const int iTree); // Mixing paecels involved in micr0-mixing.
189
190 void forceProfile();
191
192 void saveAllParameters(); // Function to save ALL parameters
193
195
196
197public:
198
220
221 hips(double C_param_,
222 bool forceTurb_,
223 int nVar_,
224 std::vector<double> &ScHips_,
225 bool performReaction,
226 std::shared_ptr<void> vcantSol = nullptr,
227 int seed = 10,
228 int realization_ = 1);
229
259
260
262 double domainLength_,
263 double tau0_,
264 double C_param_,
265 bool forceTurb_,
266 int nVar_,
267 std::vector<double> &ScHips_,
268 bool performReaction,
269 std::shared_ptr<void> vcantSol = nullptr,
270 int seed = 10,
271 int realization_ = 1);
272
273};
Definition hips.h:16
int Nm3
nLevels - 3
Definition hips.h:48
std::vector< double > setGridHips(int N)
Generates a physical domain for HiPS parcels.
Definition hips.cc:601
std::vector< double > parcelTimes
current times corresponding to the parcel states
Definition hips.h:71
const double DEFAULT_TIME_INTERVAL
Default: Write every 0.1s.
Definition hips.h:85
double lastOutputTime
Last time data was written.
Definition hips.h:81
int Nm2
nLevels - 2
Definition hips.h:47
int nVar
number of parcel variables (e.g., h, ysp)
Definition hips.h:44
int nLevels_
number of tree levels?
Definition hips.h:43
int getVariableIndex(const std::string &varName) const
Retrieves the index of a variable by its name in the varName list.
Definition hips.cc:893
std::vector< double > xc
vector containing physical domain of flow particles
Definition hips.h:74
std::vector< int > pLoc
parcel index array for fast implementation of swaps
Definition hips.h:25
bool performReaction
flag indicating whether chemical reactions are performed in the simulation
Definition hips.h:54
void forceProfile()
Adjusts the HiPS profile to enforce statistical stationarity.
Definition hips.cc:1114
hips(int nLevels_, double domainLength_, double tau0_, double C_param_, bool 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.
std::string ReApproach
Definition hips.h:77
std::vector< double > xh
vector containing physical domain of HiPS parcels
Definition hips.h:75
void set_tree(int nLevels_, double domainLength_, double tau0_)
Sets up the HiPS tree using explicitly specified tree parameters.
Definition hips.cc:124
std::vector< double > wPar
parcel volume fractions
Definition hips.h:26
int nL
adjusted number of levels based on the Reynolds number
Definition hips.h:50
bool forceTurb
forcing function for statistically stationary: -1 = none, 1 = source term, 2 = dir
Definition hips.h:51
std::vector< double > projection_back(std::vector< double > &vb)
Projects HiPS parcel values back onto the flow particles.
Definition hips.cc:1281
void setOutputIntervalEddy(int interval)
Sets the interval (in number of eddy events) for writing simulation data.
Definition hips.cc:1498
std::vector< std::vector< double > > get_varData()
Retrieves the final data from the simulation.
Definition hips.cc:1420
std::vector< int > i_plus
ceil(i_batchelor)
Definition hips.h:68
double outputIntervalTime
Default: write data every 0.1s.
Definition hips.h:79
const std::vector< std::shared_ptr< std::vector< double > > > & get_HipsVarData_ptr() const
Definition hips.h:159
double Afac
level lengthscale reduction factor (0.5)
Definition hips.h:59
double C_param
Eddy frequency parameter.
Definition hips.h:36
int nsp
number of species
Definition hips.h:45
int realization
number of realizations
Definition hips.h:22
const int DEFAULT_EDDY_INTERVAL
Default: Write every 1000 eddies.
Definition hips.h:84
void selectAndSwapTwoSubtrees(const int iLevel, int &iTree)
Performs eddy events by swapping parcels within the HiPS tree.
Definition hips.cc:803
void writeData(int real, const int ifile, const double outputTime)
Writes simulation data to a file for a specific realization, time, and file index.
Definition hips.cc:1170
double eddyRate_inertial
total rate of all eddies 0 through iEta (= eddyRate_total if Sc=1)
Definition hips.h:58
double Anew
adjusted level lengthscale reduction factor for dynamic adjustment of reduction factor
Definition hips.h:64
int currentIndex
member variable to keep track of current index of variables
Definition hips.h:41
std::vector< double > projection_back_with_density(std::vector< double > &vh, std::vector< double > &rho_h, std::vector< double > &rho_c)
Projects HiPS parcel values and densities back onto the flow particles (CFD cells).
Definition hips.cc:1355
std::vector< double > i_batchelor
Batchelor level for variable Sc scalars; NOTE: double, as in, between levels.
Definition hips.h:73
void calculateSolution(const double tRun, bool shouldWriteData=false)
Runs the HiPS simulation, advancing the solution using eddy events.
Definition hips.cc:649
int get_nparcels() const
Definition hips.h:156
randomGenerator rand
Definition hips.h:66
double time
current simulation time
Definition hips.h:56
void sample_hips_eddy(double &dt, int &iLevel)
Samples stochastic eddy events on the HiPS tree, determining the time increment and tree level.
Definition hips.cc:721
void setOutputIntervalTime(double interval)
Sets the interval (in simulation time) for writing simulation data.
Definition hips.cc:1518
std::vector< double > varRho
density
Definition hips.h:24
void reactParcels_LevelTree(const int iLevel, const int iTree)
Simulates chemical reactions for parcels affected by a micromixing event.
Definition hips.cc:933
hips(double C_param_, bool forceTurb_, int nVar_, std::vector< double > &ScHips_, 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.
std::pair< std::vector< std::vector< double > >, std::vector< double > > get_varData_with_density()
Retrieves final simulation data, including both values and densities.
Definition hips.cc:1459
bool useTimeBasedWriting
Tracks if time writing is set.
Definition hips.h:83
std::vector< double > levelRates
list of eddy event rates at each level
Definition hips.h:72
std::vector< std::string > varName
vector containing the names of parcel variables
Definition hips.h:70
double Re
Reynolds number.
Definition hips.h:60
bool useEddyBasedWriting
Tracks if eddy writing is set.
Definition hips.h:82
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.
Definition hips.cc:343
int nparcels
number of parcels
Definition hips.h:40
double Prob
probability value for probability-based solution
Definition hips.h:62
const std::vector< int > & get_pLoc() const
Definition hips.h:158
void mixAcrossLevelTree(int kVar, const int iMixLevel, const int iTree)
Uniformly mixes parcels at a specified level and subtree within the HiPS model.
Definition hips.cc:1028
double dtEE
time increment to next eddy event
Definition hips.h:61
int iEta
Kolmogorov level (needed for variable Sc scalars)
Definition hips.h:49
double eddyRate_total
total rate of all eddies 0 through nLevels-3
Definition hips.h:57
double domainLength
length of domain (m)
Definition hips.h:34
int eddyCounter
Counter for eddy events.
Definition hips.h:80
std::vector< std::shared_ptr< std::vector< double > > > varData
vector of pointers to vector
Definition hips.h:23
std::vector< double > projection(std::vector< double > &vcfd, std::vector< double > &weight)
Projects values from flow particles onto HiPS parcels assuming constant density.
Definition hips.cc:404
std::vector< double > setGridCfd(std::vector< double > &w)
Generates a physical domain for flow particles based on their weights.
Definition hips.cc:563
void advanceHips(const int iLevel, const int iTree)
Advances the HiPS model by simulating micromixing and reactions at a specific tree level.
Definition hips.cc:845
double lStar
length of the level associated with the Reynolds number
Definition hips.h:63
int outputIntervalEddy
Default: write data every 10 eddy events.
Definition hips.h:78
double tau0
integral timescale
Definition hips.h:35
void saveAllParameters()
Saves all user-defined to a file.
Definition hips.cc:1539
int nLevels
number of tree levels
Definition hips.h:42
bool LScHips
hips schmidt number
Definition hips.h:53
int Nm1
nLevels - 1
Definition hips.h:46
std::vector< double > ScHips
vector containing Schmidt numbers related to each variable
Definition hips.h:69