hips
Loading...
Searching...
No Matches
ex_2.cc
Go to the documentation of this file.
1
31
33#include "hips.h"
34#include "cantera/base/Solution.h"
35#include "cantera/thermo.h"
36
37#include <vector>
38#include <string>
39#include <fstream>
40#include <sstream>
41#include <iostream>
42
43using namespace std;
44
46int main() {
47 // HiPS simulation parameters for premixed combustion
48 int nLevels = 8; // Number of hierarchical levels
49 double domainLength = 0.01; // Domain length scale
50 double tau0 = 0.00005; // Mixing timescale (fast mixing)
51 double C_param = 0.5; // Eddy rate multiplier
52 double tRun = 0.002; // Total simulation runtime
53 bool forceTurb = false; // No forced turbulence
54 vector<double> ScHips(54, 1); // Schmidt number (unity for all species)
55
56 // Initialize Cantera for combustion chemistry
57 auto cantSol = Cantera::newSolution("gri30.yaml");
58 auto gas = cantSol->thermo();
59 size_t nsp = gas->nSpecies();
60 int nVar = nsp + 1; // Number of variables (species + enthalpy)
61
62 // Create HiPS instance with reaction support
63 hips HiPS(nLevels, domainLength, tau0, C_param, forceTurb, nVar, ScHips, true, cantSol, 11);
64
65 int nparcels = HiPS.get_nparcels();
66
67 // Define variables for species mass fractions, temperature, and enthalpy
68 vector<vector<double>> ysp(nsp, vector<double>(nparcels, 0));
69 vector<double> h(nparcels);
70 vector<double> rho(nparcels);
71
72 vector<double> y0(nsp), y1(nsp); // Initial species mass fractions
73 double T0 = 300.0, T1 = 300.0; // Initial temperature
74 double h0, h1; // Enthalpy values for reactants and products
75
76 vector<string> variableNames(nsp + 1); // Variable names: enthalpy and species
77
78 // Fraction of parcels that are pre-combusted
79 double fracBurn = 0.25;
80
81 // Initialize fresh reactants
82 gas->setState_TPX(T0, Cantera::OneAtm, "C2H4:1, O2:3, N2:11.25");
83 h0 = gas->enthalpy_mass();
84 gas->getMassFractions(y0.data());
85
86 // Assign fresh reactant properties to parcels
87 for (int i = 0; i < nsp; i++) {
88 for (int j = 0; j <= (1 - fracBurn) * nparcels; j++) {
89 h[j] = h0;
90 ysp[i][j] = y0[i];
91 rho[j] = gas->density();
92 }
93 }
94
95 // Initialize pre-combusted parcels
96 gas->setState_TPX(T1, Cantera::OneAtm, "C2H4:1, O2:3, N2:11.25");
97 h1 = gas->enthalpy_mass();
98 gas->setState_HP(h1, gas->pressure());
99 gas->equilibrate("HP");
100 gas->getMassFractions(y1.data());
101
102 // Assign pre-combusted properties to parcels
103 for (int i = 0; i < nsp; i++) {
104 for (int j = ((1 - fracBurn) * nparcels + 1); j < nparcels; j++) {
105 h[j] = h1;
106 ysp[i][j] = y1[i];
107 rho[j] = gas->density();
108 }
109 }
110
111 // Set initial conditions in HiPS
112
113 variableNames[0] = "enthalpy";
114 for (int i = 0; i < ysp.size(); i++) {
115 variableNames[i + 1] = gas->speciesName(i);
116 }
117
118 vector<double> weight(nparcels, 1.0 / nparcels); // Uniform weights
119
120 // Assign variables to HiPS
121 HiPS.set_varData(h, weight, variableNames[0], rho);
122 for (int k = 0; k < ysp.size(); k++)
123 HiPS.set_varData(ysp[k], weight, variableNames[k + 1], rho);
124
125 // Set output interval in terms of time
126 HiPS.setOutputIntervalTime(tRun/10); // Save results every 100 seconds
127
128 // Write initial condition
129 HiPS.writeData(1, 0, 0.0 );
130
131 // Run the combustion simulation
132 HiPS.calculateSolution(tRun, true);
133
134 return 0;
135}
136
Definition hips.h:16
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
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
void setOutputIntervalTime(double interval)
Sets the interval (in simulation time) for writing simulation data.
Definition hips.cc:1518
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 main()
Definition ex_2.cc:46