Skip to content

Commit cf394c3

Browse files
Working on PR updates, have to fix a few more bugs
in regards to equations, handling volumes, etc.
1 parent 17c21c8 commit cf394c3

18 files changed

+164
-266
lines changed

doc/sphinx/develop/index.md

Lines changed: 12 additions & 11 deletions
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

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ 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
//!
128-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
128+
virtual void buildReactorJacobian(ReactorBase* r,
129+
vector<Eigen::Triplet<double>>& jacVector) {
129130
throw NotImplementedError(type() + "::buildReactorJacobian");
130131
}
131132

@@ -137,34 +138,13 @@ class FlowDevice
137138
//! @warning This function is an experimental part of the %Cantera API and may be
138139
//! changed
139140
//! or removed without notice.
140-
//! @since New in %Cantera 3.0.
141+
//! @since New in %Cantera 3.1.
141142
//!
142143
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
143-
if (!m_jac_calculated) {
144-
throw NotImplementedError(type() + "::buildNetworkJacobian");
145-
}
144+
throw NotImplementedError(type() + "::buildNetworkJacobian");
146145
}
147146

148-
//! Specify the jacobian terms have been calculated and should not be recalculated.
149-
//! @warning This function is an experimental part of the %Cantera API and may be
150-
//! changed
151-
//! or removed without notice.
152-
//! @since New in %Cantera 3.0.
153-
//!
154-
void jacobianCalculated() { m_jac_calculated = true; };
155-
156-
//! Specify that jacobian terms have not been calculated and should be recalculated.
157-
//! @warning This function is an experimental part of the %Cantera API and may be changed
158-
//! or removed without notice.
159-
//! @since New in %Cantera 3.0.
160-
//!
161-
void jacobianNotCalculated() { m_jac_calculated = false; };
162-
163147
protected:
164-
//! a variable to switch on and off so calculations are not doubled by the calling
165-
//! reactor or network
166-
bool m_jac_calculated = false;
167-
168148
double m_mdot = Undef;
169149

170150
//! Function set by setPressureFunction; used by updateMassFlowRate

include/cantera/zeroD/IdealGasConstPressureMoleReactor.h

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 22 deletions
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) {
@@ -209,15 +198,7 @@ class Reactor : public ReactorBase
209198
//!
210199
//! @warning This method is an experimental part of the %Cantera
211200
//! API and may be changed or removed without notice.
212-
virtual Eigen::SparseMatrix<double> jacobian() {
213-
m_jac_trips.clear();
214-
// Add before, during, after evals
215-
buildJacobian(m_jac_trips);
216-
// construct jacobian from vector
217-
Eigen::SparseMatrix<double> jac(m_nv, m_nv);
218-
jac.setFromTriplets(m_jac_trips.begin(), m_jac_trips.end());
219-
return jac;
220-
}
201+
virtual Eigen::SparseMatrix<double> jacobian();
221202

222203
//! Calculate the Jacobian of a specific Reactor specialization.
223204
//! @param jacVector vector where jacobian triplets are added
@@ -335,8 +316,6 @@ class Reactor : public ReactorBase
335316

336317
vector<double> m_wdot; //!< Species net molar production rates
337318
vector<double> m_uk; //!< Species molar internal energies
338-
bool m_chem = false;
339-
bool m_energy = true;
340319
size_t m_nv = 0;
341320
size_t m_nv_surf; //!!< Number of variables associated with reactor surfaces
342321

include/cantera/zeroD/ReactorBase.h

Lines changed: 24 additions & 18 deletions
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
283-
//! @warning This function is an experimental part of the %Cantera API and may be changed
284-
//! 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.
283+
//! @warning This function is an experimental part of the %Cantera API and may
284+
//! be changed or removed without notice.
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/ReactorDelegator.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class ReactorDelegator : public Delegator, public R, public ReactorAccessor
7272
install("updateState", m_updateState,
7373
[this](std::array<size_t, 1> sizes, double* y) { R::updateState(y); });
7474
install("updateSurfaceState", m_updateSurfaceState,
75-
[this](std::array<size_t, 1> sizes, double* y) { R::updateSurfaceState(y); });
75+
[this](std::array<size_t, 1> sizes, double* y)
76+
{ R::updateSurfaceState(y); });
7677
install("getSurfaceInitialConditions", m_getSurfaceInitialConditions,
7778
[this](std::array<size_t, 1> sizes, double* y) {
7879
R::getSurfaceInitialConditions(y);
@@ -87,8 +88,8 @@ class ReactorDelegator : public Delegator, public R, public ReactorAccessor
8788
);
8889
install("evalWalls", m_evalWalls, [this](double t) { R::evalWalls(t); });
8990
install("evalSurfaces", m_evalSurfaces,
90-
[this](std::array<size_t, 3> sizes, double* LHS, double* RHS, double* sdot) {
91-
R::evalSurfaces(LHS, RHS, sdot);
91+
[this](std::array<size_t, 3> sizes, double* LHS, double* RHS, double* sd) {
92+
R::evalSurfaces(LHS, RHS, sd);
9293
}
9394
);
9495
install("componentName", m_componentName,

include/cantera/zeroD/ReactorNet.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#define CT_REACTORNET_H
88

99
#include "Reactor.h"
10+
#include "Wall.h"
11+
#include "FlowDevice.h"
1012
#include "cantera/numerics/FuncEval.h"
1113

1214

@@ -239,16 +241,7 @@ class ReactorNet : public FuncEval
239241
//! Return the index corresponding to the start of the reactor specific state
240242
//! vector in the reactor with index *reactor* in the global state vector for the
241243
//! reactor network.
242-
size_t globalStartIndex(Reactor* curr_reactor) {
243-
for (size_t i = 0; i < m_reactors.size(); i++) {
244-
if (curr_reactor == m_reactors[i]) {
245-
return m_start[i];
246-
}
247-
}
248-
throw CanteraError("ReactorNet::globalStartIndex: ",
249-
curr_reactor->name(), " not found in network.");
250-
return npos;
251-
}
244+
size_t globalStartIndex(ReactorBase* curr_reactor);
252245

253246
//! Return the name of the i-th component of the global state vector. The
254247
//! name returned includes both the name of the reactor and the specific
@@ -413,6 +406,10 @@ class ReactorNet : public FuncEval
413406
//! derivative settings
414407
bool m_jac_skip_walls = false;
415408
bool m_jac_skip_flow_devices = false;
409+
//! set to store walls for Jacobian calculation
410+
set<WallBase*> m_walls;
411+
//! set to store flow devices for Jacobian calculation
412+
set<FlowDevice*> m_flow_devices;
416413
};
417414
}
418415

include/cantera/zeroD/Wall.h

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -95,47 +95,27 @@ 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
99-
//! reactor
98+
//! @param jacVector a vector of triplets to be added to the reactor Jacobian
10099
//! @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.
100+
//! changed or removed without notice.
101+
//! @since New in %Cantera 3.1.
104102
//!
105-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
103+
virtual void buildReactorJacobian(ReactorBase* r,
104+
vector<Eigen::Triplet<double>>& jacVector) {
106105
throw NotImplementedError("WallBase::buildReactorJacobian");
107106
}
108107

109-
//! Build the Jacobian terms specific to the flow device for the network. These
110-
//! terms
111-
//! 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
113-
//! reactor
108+
//! Build the Jacobian cross-reactor terms specific to the flow device for the
109+
//! network.
110+
//! @param jacVector a vector of triplets to be added to the network Jacobian
114111
//! @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.
112+
//! changed or removed without notice.
113+
//! @since New in %Cantera 3.1.
118114
//!
119115
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
120116
throw NotImplementedError("WallBase::buildNetworkJacobian");
121117
}
122118

123-
//! Specify the jacobian terms have been calculated and should not be recalculated.
124-
//! @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.
128-
//!
129-
void jacobianCalculated() { m_jac_calculated = true; };
130-
131-
//! Specify that jacobian terms have not been calculated and should be recalculated.
132-
//! @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.
136-
//!
137-
void jacobianNotCalculated() { m_jac_calculated = false; };
138-
139119
protected:
140120
ReactorBase* m_left = nullptr;
141121
ReactorBase* m_right = nullptr;
@@ -144,10 +124,6 @@ class WallBase
144124
double m_time = 0.0;
145125

146126
double m_area = 1.0;
147-
148-
//! a variable to switch on and off so calculations are not doubled by the calling
149-
//! reactor or network
150-
bool m_jac_calculated = false;
151127
};
152128

153129
//! Represents a wall between between two ReactorBase objects.
@@ -252,9 +228,11 @@ class Wall : public WallBase
252228
return m_k;
253229
}
254230

255-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) override;
231+
void buildReactorJacobian(ReactorBase* r,
232+
vector<Eigen::Triplet<double>>& jacVector) override;
256233

257-
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) override;
234+
void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector)
235+
override;
258236

259237
protected:
260238

interfaces/cython/cantera/delegator.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ cdef int assign_delegates(obj, CxxDelegator* delegator) except -1:
319319

320320
if when is None:
321321
continue
322+
322323
cxx_name = stringify(options[0])
323324
callback = options[1].replace(' ', '')
324325

0 commit comments

Comments
 (0)