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
24 std::vector<std::shared_ptr<std::vector<double>>> varData;
25
26#ifdef REACTIONS_ENABLED
27 std::shared_ptr<Cantera::ThermoPhase> gas;
28 std::shared_ptr<batchReactor> bRxr;
29#endif
30
31 double domainLength;
32 double tau0;
33 double C_param;
34 std::vector<double> Temp;
35
36private:
37
38 int currentIndex = 0;
39 int nLevels;
42 int nVar;
43 int nsp;
44 int Nm1;
45 int Nm2;
46 int Nm3;
47 int iEta;
48 int nL;
49
50 bool LScHips;
52 bool LrandSet;
53
54 double time;
57 double Afac = 0.5;
58 double Re;
59 double dtEE;
60 double Prob;
61 double lStar;
62 double Anew;
63
65
66 std::vector<int> i_plus;
67 std::vector<int> pLoc;
68 std::vector<double> varRho;
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 approach;
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
87
88
90
91public:
109
110
111 void set_tree(int nLevels_, double domainLength_, double tau0_, std::vector<double> &ScHips_); // setting the HiPS tree based on the number of levels
112
136
137 void set_tree(double Re_, double domainLength_, double tau0_, std::vector<double> &ScHips_, std::string approach_ = "rounding");
138
140
141 void set_varData(std::vector<double> &v, std::vector<double> &w, const std::string &varN); // passing all variables to vector of pointer
142 void set_varData(std::vector<double> &v, std::vector<double> &w, const std::string &varN,
143 const std::vector<double> &rho); // passing all variables to vector of pointer
144
145 std::vector<std::vector<double>> get_varData(); // Retrieves modified data from the HiPS library and stores it in the provided vector.
146 std::vector<std::pair<std::vector<double>, std::vector<double>>> get_varData_with_density();
147
148 void setOutputIntervalTime(double interval);
149 void setOutputIntervalEddy(int interval);
150
151 void calculateSolution(const double tRun, bool shouldWriteData =false); // Running simulations
152
153private:
154
155 std::vector<double> projection(std::vector<double> &vcfd, std::vector<double> &weight); // Perform vector projection of flow particles onto hips parcels operation without density
156
157 std::pair<std::vector<double>, std::vector<double>> projection(std::vector<double> &vcfd, std::vector<double> &weight,
158 const std::vector<double> &density); // Perform vector projection flow particles onto hips parcels operation with density
159
160 std::vector<double> setGridHips(int N); // Set Hips grid with a specified number of grid points equal to number of parcels
161 std::vector<double> setGridCfd(std::vector<double> &w); // Set CFD grid using provided weight vector
162 std::vector<double> projection_back(std::vector<double> &vb);
163 std::pair<std::vector<double>, std::vector<double>> projection_back_with_density(std::vector<double> &vh,
164 std::vector<double> &rho_h);
165
166
167
168
169 void sample_hips_eddy(double &dt, int &iLevel); // Sample hips eddy with specified time step and level
170 void selectAndSwapTwoSubtrees(const int iLevel, int &iTree); // Select and swap two subtrees in the level tree
171 void advanceHips(const int iLevel, const int iTree); // Advancing simulations to do mixing and reaction
172
173 int getVariableIndex(const std::string &varName) const;
174
175 void reactParcels_LevelTree(const int iLevel, const int iTree); // Reacting parcels involved in micro-mixing
176 void mixAcrossLevelTree(int kVar, const int iMixLevel, const int iTree); // Mixing paecels involved in micr0-mixing.
177
178 void forceProfile();
179
180 void writeData(int real, const int ifile, const double outputTime); // Writing the results for a user-defined number of eddies in the data folder.
181 void saveAllParameters(); // Function to save ALL parameters
182
184
185
186public:
187
209
210 hips(double C_param_,
211 int forceTurb_,
212 int nVar_,
213 bool performReaction,
214 std::shared_ptr<void> vcantSol = nullptr,
215 int seed = 10,
216 int realization_ = 1);
217
247
248
250 double domainLength_,
251 double tau0_,
252 double C_param_,
253 int forceTurb_,
254 int nVar_,
255 std::vector<double> &ScHips_,
256 bool performReaction,
257 std::shared_ptr<void> vcantSol = nullptr,
258 int seed = 10,
259 int realization_ = 1);
260
261 void resetForNewRealization() { // Reset the number of Index to use for new realization
262 currentIndex = 0;
263 }
264
265};
Definition hips.h:16
int Nm3
nLevels - 3
Definition hips.h:46
std::vector< double > setGridHips(int N)
Generates a physical domain for HiPS parcels.
Definition hips.cc:560
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:45
int nVar
number of parcel variables (e.g., h, ysp)
Definition hips.h:42
int nLevels_
number of tree levels?
Definition hips.h:40
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.
Definition hips.cc:1256
int getVariableIndex(const std::string &varName) const
Retrieves the index of a variable by its name in the varName list.
Definition hips.cc:852
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.
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:67
bool performReaction
flag indicating whether chemical reactions are performed in the simulation
Definition hips.h:51
std::vector< std::pair< std::vector< double >, std::vector< double > > > get_varData_with_density()
Retrieves final simulation data, including both values and densities.
Definition hips.cc:1341
void forceProfile()
Adjusts the HiPS profile to enforce statistical stationarity.
Definition hips.cc:1030
std::vector< double > xh
vector containing physical domain of HiPS parcels
Definition hips.h:75
int nL
adjusted number of levels based on the Reynolds number
Definition hips.h:48
bool LrandSet
flag indicating new randomGen --> allow deletion
Definition hips.h:52
void resetForNewRealization()
Definition hips.h:261
std::vector< double > projection_back(std::vector< double > &vb)
Projects HiPS parcel values back onto the flow particles.
Definition hips.cc:1180
void setOutputIntervalEddy(int interval)
Sets the interval (in number of eddy events) for writing simulation data.
Definition hips.cc:1370
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.
std::vector< std::vector< double > > get_varData()
Retrieves the final data from the simulation.
Definition hips.cc:1311
std::vector< int > i_plus
ceil(i_batchelor)
Definition hips.h:66
double outputIntervalTime
Default: write data every 0.1s.
Definition hips.h:79
double Afac
level lengthscale reduction factor (0.5)
Definition hips.h:57
double C_param
Eddy frequency parameter.
Definition hips.h:33
int forceTurb
forcing function for statistically stationary: -1 = none, 1 = source term, 2 = dir
Definition hips.h:41
int nsp
number of species
Definition hips.h:43
int realization
number of realizations
Definition hips.h:23
std::string approach
Definition hips.h:77
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:762
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:1086
double eddyRate_inertial
total rate of all eddies 0 through iEta (= eddyRate_total if Sc=1)
Definition hips.h:56
double Anew
adjusted level lengthscale reduction factor for dynamic adjustment of reduction factor
Definition hips.h:62
int currentIndex
member variable to keep track of current index of variables
Definition hips.h:38
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:608
randomGenerator rand
Definition hips.h:64
double time
current simulation time
Definition hips.h:54
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:680
void setOutputIntervalTime(double interval)
Sets the interval (in simulation time) for writing simulation data.
Definition hips.cc:1390
std::vector< double > varRho
Definition hips.h:68
void reactParcels_LevelTree(const int iLevel, const int iTree)
Simulates chemical reactions for parcels affected by a micromixing event.
Definition hips.cc:889
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:58
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:337
int nparcels
number of parcels
Definition hips.h:22
double Prob
probability value for probability-based solution
Definition hips.h:60
std::vector< double > Temp
Vector containg temperature in each parcel;.
Definition hips.h:34
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:967
double dtEE
time increment to next eddy event
Definition hips.h:59
int iEta
Kolmogorov level (needed for variable Sc scalars)
Definition hips.h:47
double eddyRate_total
total rate of all eddies 0 through nLevels-3
Definition hips.h:55
double domainLength
length of domain (m)
Definition hips.h:31
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:24
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:400
std::vector< double > setGridCfd(std::vector< double > &w)
Generates a physical domain for flow particles based on their weights.
Definition hips.cc:526
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:804
double lStar
length of the level associated with the Reynolds number
Definition hips.h:61
int outputIntervalEddy
Default: write data every 10 eddy events.
Definition hips.h:78
double tau0
integral timescale
Definition hips.h:32
void saveAllParameters()
Saves all user-defined to a file.
Definition hips.cc:1411
int nLevels
number of tree levels
Definition hips.h:39
bool LScHips
hips schmidt number
Definition hips.h:50
int Nm1
nLevels - 1
Definition hips.h:44
void set_tree(int nLevels_, double domainLength_, double tau0_, std::vector< double > &ScHips_)
Sets up the HiPS tree using explicitly specified tree parameters.
std::vector< double > ScHips
vector containing Schmidt numbers related to each variable
Definition hips.h:69