I am trying to use a vector of pointers for my gas objects and reactor objects. I am then adding all the reactors to a reactor network which I am advancing in time. However I get a segmentation fault. I also tried the same exercise by having one reactor per reactor network which is working. I would like any possible help in this regard.
#include "cantera/thermo.h"
#include <iostream>
#include "cantera/IdealGasMix.h"
#include "cantera/zerodim.h"
#include "vector"
std::vector<std::unique_ptr<Cantera::IdealGasMix>> gas;
std::vector<std::unique_ptr<Cantera::IdealGasConstPressureReactor>> React;
std::vector<std::unique_ptr<Cantera::ReactorNet>> net;
void run()
{
int nsp;
int n;
double p = 101325;
double temp = 1000;
int n_size = 1000;
net.emplace_back(new Cantera::ReactorNet);
for (int i=0; i<n_size; i++) {
React.emplace_back(new Cantera::IdealGasConstPressureReactor);
gas.emplace_back(new Cantera::IdealGasMix("gri30.xml"));
}
nsp = gas[0]->nSpecies();
Cantera::vector_fp x(nsp, 0.0);
x[gas[0]->speciesIndex("CH4")] = 1.0;
x[gas[0]->speciesIndex("O2")] = 2;
x[gas[0]->speciesIndex("N2")] = 7.52;
for (int i=0; i<n_size; i++) {
gas[i]->setState_TPY(temp,p,x.data());
React[i]->insert(*gas[i]);
net[0]->addReactor(*React[i]);
}
net[0]->advance(0.002);
n = net[0]->neq();
std::cout << n << "\n";
}
void main()
{
run();
}