| 103 | } |
| 104 | |
| 105 | void ReactorNet::initialize() |
| 106 | { |
| 107 | m_nv = 0; |
| 108 | debuglog("Initializing reactor network.\n", m_verbose); |
| 109 | if (m_reactors.empty()) { |
| 110 | throw CanteraError("ReactorNet::initialize", |
| 111 | "no reactors in network!"); |
| 112 | } |
| 113 | m_start.assign(1, 0); |
| 114 | for (size_t n = 0; n < m_reactors.size(); n++) { |
| 115 | Reactor& r = *m_reactors[n]; |
| 116 | r.initialize(m_time); |
| 117 | size_t nv = r.neq(); |
| 118 | m_nv += nv; |
| 119 | m_start.push_back(m_nv); |
| 120 | |
| 121 | if (m_verbose) { |
| 122 | writelog("Reactor {:d}: {:d} variables.\n", n, nv); |
| 123 | writelog(" {:d} sensitivity params.\n", r.nSensParams()); |
| 124 | } |
| 125 | if (r.type() == "FlowReactor" && m_reactors.size() > 1) { |
| 126 | throw CanteraError("ReactorNet::initialize", |
| 127 | "FlowReactors must be used alone."); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | m_ydot.resize(m_nv,0.0); |
| 132 | m_yest.resize(m_nv,0.0); |
| 133 | m_advancelimits.resize(m_nv,-1.0); |
| 134 | m_atol.resize(neq()); |
| 135 | fill(m_atol.begin(), m_atol.end(), m_atols); |
| 136 | m_integ->setTolerances(m_rtol, neq(), m_atol.data()); |
| 137 | m_integ->setSensitivityTolerances(m_rtolsens, m_atolsens); |
| 138 | if (!m_linearSolverType.empty()) { |
| 139 | m_integ->setLinearSolverType(m_linearSolverType); |
| 140 | } |
| 141 | if (m_precon) { |
| 142 | m_integ->setPreconditioner(m_precon); |
| 143 | } |
| 144 | m_integ->initialize(m_time, *this); |
| 145 | if (m_verbose) { |
| 146 | writelog("Number of equations: {:d}\n", neq()); |
| 147 | writelog("Maximum time step: {:14.6g}\n", m_maxstep); |
| 148 | } |
| 149 | if (m_integ->preconditionerSide() != PreconditionerSide::NO_PRECONDITION) { |
| 150 | checkPreconditionerSupported(); |
| 151 | } |
| 152 | m_integrator_init = true; |
| 153 | m_init = true; |
| 154 | } |
| 155 | |
| 156 | void ReactorNet::reinitialize() |
| 157 | { |