Skip to content

Commit 3193fa3

Browse files
Temp PR updates
1 parent 51eb21c commit 3193fa3

14 files changed

+88
-127
lines changed

doc/sphinx/develop/index.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Develop
22

33
(sec-compiling)=
4+
45
## Compiling Cantera from Source
56

67
If you're interested in contributing new features to Cantera, or you want to try the
@@ -12,9 +13,9 @@ Cantera](compiling/configure-build) on your computer.
1213

1314
The following additional references may also be useful:
1415

15-
- [](compiling/dependencies.md)
16-
- [](compiling/config-options)
17-
- [](compiling/special-cases)
16+
- [](compiling/dependencies.md)
17+
- [](compiling/config-options)
18+
- [](compiling/special-cases)
1819

1920
```{toctree}
2021
:caption: Compiling Cantera from Source
@@ -35,7 +36,7 @@ compiling/special-cases
3536
This section is a work in progress.
3637
```
3738

38-
- [](reactor-integration)
39+
- [](reactor-integration)
3940

4041
```{toctree}
4142
:caption: How Cantera Works
@@ -47,13 +48,13 @@ reactor-integration
4748

4849
## Adding New Features to Cantera
4950

50-
- [](CONTRIBUTING)
51-
- [](style-guidelines)
52-
- [](vscode-tips)
53-
- [](writing-tests)
54-
- [](running-tests)
55-
- [](writing-examples)
56-
- [](doc-formatting)
51+
- [](CONTRIBUTING)
52+
- [](style-guidelines)
53+
- [](vscode-tips)
54+
- [](writing-tests)
55+
- [](running-tests)
56+
- [](writing-examples)
57+
- [](doc-formatting)
5758

5859
```{toctree}
5960
:caption: Adding New Features to Cantera

include/cantera/zeroD/FlowDevice.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class FlowDevice
123123
//! @warning This function is an experimental part of the %Cantera API and may be
124124
//! changed
125125
//! or removed without notice.
126-
//! @since New in %Cantera 3.0.
126+
//! @since New in %Cantera 3.1.
127127
//!
128128
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
129129
throw NotImplementedError(type() + "::buildReactorJacobian");
@@ -137,7 +137,7 @@ class FlowDevice
137137
//! @warning This function is an experimental part of the %Cantera API and may be
138138
//! changed
139139
//! or removed without notice.
140-
//! @since New in %Cantera 3.0.
140+
//! @since New in %Cantera 3.1.
141141
//!
142142
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
143143
if (!m_jac_calculated) {
@@ -149,16 +149,16 @@ class FlowDevice
149149
//! @warning This function is an experimental part of the %Cantera API and may be
150150
//! changed
151151
//! or removed without notice.
152-
//! @since New in %Cantera 3.0.
152+
//! @since New in %Cantera 3.1.
153153
//!
154-
void jacobianCalculated() { m_jac_calculated = true; };
154+
void calculatedJacobian() { m_jac_calculated = true; };
155155

156156
//! Specify that jacobian terms have not been calculated and should be recalculated.
157157
//! @warning This function is an experimental part of the %Cantera API and may be changed
158158
//! or removed without notice.
159-
//! @since New in %Cantera 3.0.
159+
//! @since New in %Cantera 3.1.
160160
//!
161-
void jacobianNotCalculated() { m_jac_calculated = false; };
161+
void notCalculatedJacobian() { m_jac_calculated = false; };
162162

163163
protected:
164164
//! a variable to switch on and off so calculations are not doubled by the calling

include/cantera/zeroD/IdealGasConstPressureMoleReactor.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ class IdealGasConstPressureMoleReactor : public ConstPressureMoleReactor
4747

4848
bool preconditionerSupported() const override { return true; };
4949

50-
double moleDerivative(size_t index) override;
51-
52-
double moleRadiationDerivative(size_t index) override;
50+
double temperature_ddni(size_t index) override;
5351

5452
size_t speciesOffset() const override { return m_sidx; };
5553

include/cantera/zeroD/IdealGasMoleReactor.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class IdealGasMoleReactor : public MoleReactor
4343

4444
bool preconditionerSupported() const override {return true;};
4545

46-
double moleDerivative(size_t index) override;
47-
48-
double moleRadiationDerivative(size_t index) override;
46+
double temperature_ddni(size_t index) override;
4947

5048
size_t speciesOffset() const override { return m_sidx; };
5149

include/cantera/zeroD/Reactor.h

-13
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ class Reactor : public ReactorBase
8484
m_chem = cflag;
8585
}
8686

87-
//! Returns `true` if changes in the reactor composition due to chemical reactions
88-
//! are enabled.
89-
bool chemistryEnabled() const {
90-
return m_chem;
91-
}
92-
9387
void setEnergy(int eflag=1) override {
9488
if (eflag > 0) {
9589
m_energy = true;
@@ -98,11 +92,6 @@ class Reactor : public ReactorBase
9892
}
9993
}
10094

101-
//! Returns `true` if solution of the energy equation is enabled.
102-
bool energyEnabled() const {
103-
return m_energy;
104-
}
105-
10695
//! Number of equations (state variables) for this reactor
10796
size_t neq() {
10897
if (!m_nv) {
@@ -335,8 +324,6 @@ class Reactor : public ReactorBase
335324

336325
vector<double> m_wdot; //!< Species net molar production rates
337326
vector<double> m_uk; //!< Species molar internal energies
338-
bool m_chem = false;
339-
bool m_energy = true;
340327
size_t m_nv = 0;
341328
size_t m_nv_surf; //!!< Number of variables associated with reactor surfaces
342329

include/cantera/zeroD/ReactorBase.h

+22-16
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,15 @@ class ReactorBase
277277
//! Set the ReactorNet that this reactor belongs to.
278278
void setNetwork(ReactorNet* net);
279279

280-
//! Calculate the derivative of T with respect to the ith species in the heat
281-
//! transfer equation based on the reactor specific equation of state.
280+
//! Calculate the derivative of T with respect to the ith species in the energy
281+
//! conservation equation based on the reactor specific equation of state.
282282
//! @param index index of the species the derivative is with respect too
283283
//! @warning This function is an experimental part of the %Cantera API and may be changed
284284
//! or removed without notice.
285-
//! @since New in %Cantera 3.0.
286-
//!
287-
virtual double moleDerivative(size_t index) {
288-
throw NotImplementedError("Reactor::moleDerivative");
289-
}
290-
291-
//! Calculate the derivative of T with respect to the ith species in the heat
292-
//! transfer radiation equation based on the reactor specific equation of state.
293-
//! @param index index of the species the derivative is with respect too
294-
//! @warning This function is an experimental part of the %Cantera API and may be changed
295-
//! or removed without notice.
296-
//! @since New in %Cantera 3.0.
285+
//! @since New in %Cantera 3.1.
297286
//!
298-
virtual double moleRadiationDerivative(size_t index) {
299-
throw NotImplementedError("Reactor::moleRadiationDerivative");
287+
virtual double temperature_ddni(size_t index) {
288+
throw NotImplementedError("Reactor::temperature_ddni");
300289
}
301290

302291
//! Return the index associated with energy of the system
@@ -305,6 +294,17 @@ class ReactorBase
305294
//! Return the offset between species and state variables
306295
virtual size_t speciesOffset() const { return m_sidx; };
307296

297+
//! Returns `true` if solution of the energy equation is enabled.
298+
virtual bool energyEnabled() const {
299+
return m_energy;
300+
}
301+
302+
//! Returns `true` if changes in the reactor composition due to chemical reactions
303+
//! are enabled.
304+
bool chemistryEnabled() const {
305+
return m_chem;
306+
}
307+
308308
protected:
309309
//! Specify the mixture contained in the reactor. Note that a pointer to
310310
//! this substance is stored, and as the integration proceeds, the state of
@@ -348,6 +348,12 @@ class ReactorBase
348348

349349
//! Composite thermo/kinetics/transport handler
350350
shared_ptr<Solution> m_solution;
351+
352+
//! A bool that enables the energy equation
353+
bool m_energy = true;
354+
355+
//! A bool that enables the chemical kinetics equations
356+
bool m_chem = false;
351357
};
352358
}
353359

include/cantera/zeroD/ReactorNet.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class ReactorNet : public FuncEval
239239
//! Return the index corresponding to the start of the reactor specific state
240240
//! vector in the reactor with index *reactor* in the global state vector for the
241241
//! reactor network.
242-
size_t globalStartIndex(Reactor* curr_reactor) {
242+
size_t globalStartIndex(ReactorBase* curr_reactor) {
243243
for (size_t i = 0; i < m_reactors.size(); i++) {
244244
if (curr_reactor == m_reactors[i]) {
245245
return m_start[i];

include/cantera/zeroD/Wall.h

+14-18
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ class WallBase
9595
//! Build the Jacobian terms specific to the flow device for the given connected
9696
//! reactor.
9797
//! @param r a pointer to the calling reactor
98-
//! @param jacVector a vector of triplets to be added to the jacobian for the
98+
//! @param jacVector a vector of triplets to be added to the Jacobian for the
9999
//! reactor
100100
//! @warning This function is an experimental part of the %Cantera API and may be
101-
//! changed
102-
//! or removed without notice.
103-
//! @since New in %Cantera 3.0.
101+
//! changed or removed without notice.
102+
//! @since New in %Cantera 3.1.
104103
//!
105104
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
106105
throw NotImplementedError("WallBase::buildReactorJacobian");
@@ -109,32 +108,29 @@ class WallBase
109108
//! Build the Jacobian terms specific to the flow device for the network. These
110109
//! terms
111110
//! will be adjusted to the networks indexing system outside of the reactor.
112-
//! @param jacVector a vector of triplets to be added to the jacobian for the
111+
//! @param jacVector a vector of triplets to be added to the Jacobian for the
113112
//! reactor
114113
//! @warning This function is an experimental part of the %Cantera API and may be
115-
//! changed
116-
//! or removed without notice.
117-
//! @since New in %Cantera 3.0.
114+
//! changed or removed without notice.
115+
//! @since New in %Cantera 3.1.
118116
//!
119117
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
120118
throw NotImplementedError("WallBase::buildNetworkJacobian");
121119
}
122120

123-
//! Specify the jacobian terms have been calculated and should not be recalculated.
121+
//! Specify the Jacobian terms have been calculated and should not be recalculated.
124122
//! @warning This function is an experimental part of the %Cantera API and may be
125-
//! changed
126-
//! or removed without notice.
127-
//! @since New in %Cantera 3.0.
123+
//! changed or removed without notice.
124+
//! @since New in %Cantera 3.1.
128125
//!
129-
void jacobianCalculated() { m_jac_calculated = true; };
126+
void calculatedJacobian() { m_jac_calculated = true; };
130127

131-
//! Specify that jacobian terms have not been calculated and should be recalculated.
128+
//! Specify that Jacobian terms have not been calculated and should be recalculated.
132129
//! @warning This function is an experimental part of the %Cantera API and may be
133-
//! changed
134-
//! or removed without notice.
135-
//! @since New in %Cantera 3.0.
130+
//! changed or removed without notice.
131+
//! @since New in %Cantera 3.1.
136132
//!
137-
void jacobianNotCalculated() { m_jac_calculated = false; };
133+
void notCalculatedJacobian() { m_jac_calculated = false; };
138134

139135
protected:
140136
ReactorBase* m_left = nullptr;

src/zeroD/IdealGasConstPressureMoleReactor.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -273,23 +273,11 @@ string IdealGasConstPressureMoleReactor::componentName(size_t k) {
273273
"Index is out of bounds.");
274274
}
275275

276-
double IdealGasConstPressureMoleReactor::moleDerivative(size_t index)
276+
double IdealGasConstPressureMoleReactor::temperature_ddni(size_t index)
277277
{
278278
// derivative of temperature transformed by ideal gas law
279-
vector<double> moles(m_nsp);
280-
getMoles(moles.data());
281-
double dTdni = pressure() * m_vol / GasConstant / std::accumulate(moles.begin(), moles.end(), 0.0);
282-
return dTdni;
283-
}
284-
285-
double IdealGasConstPressureMoleReactor::moleRadiationDerivative(size_t index)
286-
{
287-
// derivative of temperature transformed by ideal gas law
288-
vector<double> moles(m_nsp);
289-
getMoles(moles.data());
290-
double dT4dni = std::pow(pressure() * m_vol / GasConstant, 4);
291-
dT4dni *= std::pow(1 / std::accumulate(moles.begin(), moles.end(), 0.0), 5);
292-
return dT4dni;
279+
double n_total = m_mass / m_thermo->meanMolecularWeight();
280+
return pressure() * m_vol / GasConstant / n_total;
293281
}
294282

295283
}

src/zeroD/IdealGasMoleReactor.cpp

+3-19
Original file line numberDiff line numberDiff line change
@@ -244,32 +244,16 @@ void IdealGasMoleReactor::buildJacobian(vector<Eigen::Triplet<double>>& jacVecto
244244
jacVector.emplace_back(0, static_cast<int>(j + m_sidx),
245245
(specificHeat[j] * qdot - NCv * uk_dnkdnj_sums[j]) * denom);
246246
}
247-
248-
// build wall jacobian
249247
buildWallJacobian(jacVector);
250248
}
251-
252-
// build flow jacobian
253249
buildFlowJacobian(jacVector);
254250
}
255251

256-
double IdealGasMoleReactor::moleDerivative(size_t index)
257-
{
258-
// derivative of temperature transformed by ideal gas law
259-
vector<double> moles(m_nsp);
260-
getMoles(moles.data());
261-
double dTdni = pressure() * m_vol / GasConstant / std::accumulate(moles.begin(), moles.end(), 0.0);
262-
return dTdni;
263-
}
264-
265-
double IdealGasMoleReactor::moleRadiationDerivative(size_t index)
252+
double IdealGasMoleReactor::temperature_ddni(size_t index)
266253
{
267254
// derivative of temperature transformed by ideal gas law
268-
vector<double> moles(m_nsp);
269-
getMoles(moles.data());
270-
double dT4dni = std::pow(pressure() * m_vol / GasConstant, 4);
271-
dT4dni *= std::pow(1 / std::accumulate(moles.begin(), moles.end(), 0.0), 5);
272-
return dT4dni;
255+
double n_total = m_mass / m_thermo->meanMolecularWeight();
256+
return pressure() * m_vol / GasConstant / n_total;
273257
}
274258

275259
}

src/zeroD/Reactor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ void Reactor::setAdvanceLimit(const string& nm, const double limit)
603603
}
604604
}
605605

606-
void Reactor:: buildWallJacobian(vector<Eigen::Triplet<double>>& jacVector)
606+
void Reactor::buildWallJacobian(vector<Eigen::Triplet<double>>& jacVector)
607607
{
608608
if (!m_jac_skip_walls) {
609609
for (size_t i = 0; i < m_wall.size(); i++) {

0 commit comments

Comments
 (0)