hips
Loading...
Searching...
No Matches
ex_1.cc
Go to the documentation of this file.
1
26
28#include <iostream>
29#include <vector>
30#include "hips.h"
31
32using namespace std;
33
34// Initializes mixing fractions for fluid parcels
35// - numParcels: Number of parcels in the simulation
36// - Returns a vector with initialized mixing fractions (0 or 1)
37
38vector<double> initializeMixingFractions(int numParcels) {
39 vector<double> mixingFractions(numParcels);
40 for (int i = 0; i < numParcels; i++) {
41 // Assign 0.0 to the first half and 1.0 to the second half
42 mixingFractions[i] = (i < numParcels / 2) ? 0.0 : 1.0;
43 }
44 return mixingFractions;
45}
46
48int main() {
49 // HiPS tree and simulation parameters
50 int nLevels = 9; // Number of hierarchical levels
51 double domainLength = 1.0; // Simulation domain length
52 double tau0 = 1.0; // Initial time scale for the largest eddies
53 double C_param = 0.5; // Eddy turnover rate multiplier
54 double tRun = 300.0; // Total simulation time
55 int forceTurb = 2; // Forcing parameter to impose turbulent profile
56 vector<double> ScHips = {0.0625, 1.0, 16.0}; // Schmidt numbers for low and high diffusivity
57 int numVariables = 3; // Number of scalar fields
58
59 // Set up HiPS tree and calculate the number of parcels
60 hips HiPS(nLevels, domainLength, tau0, C_param, forceTurb, numVariables, ScHips, false);
61 int numParcels = HiPS.get_nparcels()
62;
63
64 // Initialize mixing fractions for each scalar variable
65 vector<vector<double>> mixingFractions(numVariables);
66 vector<double> weights(numParcels, 1.0 / numParcels); // Uniform weights
67
68 for (int i = 0; i < numVariables; ++i) {
69 // Initialize mixing fractions for variable i
70 mixingFractions[i] = initializeMixingFractions(numParcels);
71 HiPS.set_varData(mixingFractions[i], weights, "mixf_0" + to_string(i));
72 }
73
74 // Set output interval in terms of time
75 HiPS.setOutputIntervalTime(60.0); // Save results every 100 seconds
76
77 // Write initial condition
78 HiPS.writeData(1, 0, 0.0 );
79
80 // Run the simulation and calculate mixing dynamics
81 HiPS.calculateSolution(tRun, true);
82
83 return 0;
84}
85
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
vector< double > initializeMixingFractions(int numParcels)
Definition ex_1.cc:38
int main()
Definition ex_1.cc:48