Skip to content

Commit 647634f

Browse files
anthony-walkerspeth
authored andcommitted
Working on PR updates, have to fix a few more bugs
in regards to equations, handling volumes, etc.
1 parent cdf9793 commit 647634f

File tree

17 files changed

+155
-280
lines changed

17 files changed

+155
-280
lines changed

doc/sphinx/develop/index.md

Lines changed: 5 additions & 4 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

include/cantera/zeroD/FlowDevice.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,10 @@ class FlowDevice : public ConnectorNode
172172
//! @warning This function is an experimental part of the %Cantera API and may be
173173
//! changed
174174
//! or removed without notice.
175-
//! @since New in %Cantera 3.0.
175+
//! @since New in %Cantera 3.1.
176176
//!
177-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
177+
virtual void buildReactorJacobian(ReactorBase* r,
178+
vector<Eigen::Triplet<double>>& jacVector) {
178179
throw NotImplementedError(type() + "::buildReactorJacobian");
179180
}
180181

@@ -186,29 +187,12 @@ class FlowDevice : public ConnectorNode
186187
//! @warning This function is an experimental part of the %Cantera API and may be
187188
//! changed
188189
//! or removed without notice.
189-
//! @since New in %Cantera 3.0.
190+
//! @since New in %Cantera 3.1.
190191
//!
191192
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
192-
if (!m_jac_calculated) {
193-
throw NotImplementedError(type() + "::buildNetworkJacobian");
194-
}
193+
throw NotImplementedError(type() + "::buildNetworkJacobian");
195194
}
196195

197-
//! Specify the jacobian terms have been calculated and should not be recalculated.
198-
//! @warning This function is an experimental part of the %Cantera API and may be
199-
//! changed
200-
//! or removed without notice.
201-
//! @since New in %Cantera 3.0.
202-
//!
203-
void jacobianCalculated() { m_jac_calculated = true; };
204-
205-
//! Specify that jacobian terms have not been calculated and should be recalculated.
206-
//! @warning This function is an experimental part of the %Cantera API and may be changed
207-
//! or removed without notice.
208-
//! @since New in %Cantera 3.0.
209-
//!
210-
void jacobianNotCalculated() { m_jac_calculated = false; };
211-
212196
protected:
213197
string m_name; //!< Flow device name.
214198
bool m_defaultNameSet = false; //!< `true` if default name has been previously set.

include/cantera/zeroD/IdealGasConstPressureMoleReactor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class IdealGasConstPressureMoleReactor : public ConstPressureMoleReactor
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/IdealGasMoleReactor.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ class IdealGasMoleReactor : public MoleReactor
4545

4646
bool preconditionerSupported() const override {return true;};
4747

48-
double moleDerivative(size_t index) override;
49-
50-
double moleRadiationDerivative(size_t index) override;
48+
double temperature_ddni(size_t index) override;
5149

5250
size_t speciesOffset() const override { return m_sidx; };
5351

include/cantera/zeroD/Reactor.h

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ class Reactor : public ReactorBase
7474
m_chem = cflag;
7575
}
7676

77-
//! Returns `true` if changes in the reactor composition due to chemical reactions
78-
//! are enabled.
79-
bool chemistryEnabled() const {
80-
return m_chem;
81-
}
82-
8377
void setEnergy(int eflag=1) override {
8478
if (eflag > 0) {
8579
m_energy = true;
@@ -88,11 +82,6 @@ class Reactor : public ReactorBase
8882
}
8983
}
9084

91-
//! Returns `true` if solution of the energy equation is enabled.
92-
bool energyEnabled() const {
93-
return m_energy;
94-
}
95-
9685
//! Number of equations (state variables) for this reactor
9786
size_t neq() {
9887
if (!m_nv) {
@@ -214,15 +203,7 @@ class Reactor : public ReactorBase
214203
//!
215204
//! @warning This method is an experimental part of the %Cantera
216205
//! API and may be changed or removed without notice.
217-
virtual Eigen::SparseMatrix<double> jacobian() {
218-
m_jac_trips.clear();
219-
// Add before, during, after evals
220-
buildJacobian(m_jac_trips);
221-
// construct jacobian from vector
222-
Eigen::SparseMatrix<double> jac(m_nv, m_nv);
223-
jac.setFromTriplets(m_jac_trips.begin(), m_jac_trips.end());
224-
return jac;
225-
}
206+
virtual Eigen::SparseMatrix<double> jacobian();
226207

227208
//! Calculate the Jacobian of a specific Reactor specialization.
228209
//! @param jacVector vector where jacobian triplets are added
@@ -341,8 +322,6 @@ class Reactor : public ReactorBase
341322

342323
vector<double> m_wdot; //!< Species net molar production rates
343324
vector<double> m_uk; //!< Species molar internal energies
344-
bool m_chem = false;
345-
bool m_energy = true;
346325
size_t m_nv = 0;
347326
size_t m_nv_surf; //!!< Number of variables associated with reactor surfaces
348327

include/cantera/zeroD/ReactorBase.h

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -282,52 +282,15 @@ class ReactorBase
282282
return m_sensParams.size();
283283
}
284284

285-
//! Calculate the derivative of temperature with respect to the temperature in the
286-
//! heat transfer equation based on the reactor specific equation of state.
287-
//! This function should also transform the state of the derivative to that
288-
//! appropriate for the jacobian's state/
289-
//! @warning This function is an experimental part of the %Cantera API and may be changed
290-
//! or removed without notice.
291-
//! @since New in %Cantera 3.0.
292-
//!
293-
virtual double temperatureDerivative() {
294-
throw NotImplementedError("Reactor::temperatureDerivative");
295-
}
296-
297-
//! Calculate the derivative of temperature with respect to the temperature in the
298-
//! heat transfer radiation equation based on the reactor specific equation of
299-
//! state.
300-
//! This function should also transform the state of the derivative to that
301-
//! appropriate for the jacobian's state/
302-
//! @warning This function is an experimental part of the %Cantera API and may be
303-
//! changed
304-
//! or removed without notice.
305-
//! @since New in %Cantera 3.0.
306-
//!
307-
virtual double temperatureRadiationDerivative() {
308-
throw NotImplementedError("Reactor::temperatureRadiationDerivative");
309-
}
310-
311-
//! Calculate the derivative of T with respect to the ith species in the heat
312-
//! transfer equation based on the reactor specific equation of state.
285+
//! Calculate the derivative of T with respect to the ith species in the energy
286+
//! conservation equation based on the reactor specific equation of state.
313287
//! @param index index of the species the derivative is with respect too
314-
//! @warning This function is an experimental part of the %Cantera API and may be changed
315-
//! or removed without notice.
316-
//! @since New in %Cantera 3.0.
317-
//!
318-
virtual double moleDerivative(size_t index) {
319-
throw NotImplementedError("Reactor::moleDerivative");
320-
}
321-
322-
//! Calculate the derivative of T with respect to the ith species in the heat
323-
//! transfer radiation equation based on the reactor specific equation of state.
324-
//! @param index index of the species the derivative is with respect too
325-
//! @warning This function is an experimental part of the %Cantera API and may be changed
326-
//! or removed without notice.
327-
//! @since New in %Cantera 3.0.
288+
//! @warning This function is an experimental part of the %Cantera API and may
289+
//! be changed or removed without notice.
290+
//! @since New in %Cantera 3.1.
328291
//!
329-
virtual double moleRadiationDerivative(size_t index) {
330-
throw NotImplementedError("Reactor::moleRadiationDerivative");
292+
virtual double temperature_ddni(size_t index) {
293+
throw NotImplementedError("Reactor::temperature_ddni");
331294
}
332295

333296
//! Return the index associated with energy of the system
@@ -336,6 +299,17 @@ class ReactorBase
336299
//! Return the offset between species and state variables
337300
virtual size_t speciesOffset() const { return m_sidx; };
338301

302+
//! Returns `true` if solution of the energy equation is enabled.
303+
virtual bool energyEnabled() const {
304+
return m_energy;
305+
}
306+
307+
//! Returns `true` if changes in the reactor composition due to chemical reactions
308+
//! are enabled.
309+
bool chemistryEnabled() const {
310+
return m_chem;
311+
}
312+
339313
protected:
340314
//! Specify the mixture contained in the reactor. Note that a pointer to
341315
//! this substance is stored, and as the integration proceeds, the state of
@@ -389,6 +363,12 @@ class ReactorBase
389363

390364
// Data associated each sensitivity parameter
391365
vector<SensitivityParameter> m_sensParams;
366+
367+
//! A bool that enables the energy equation
368+
bool m_energy = true;
369+
370+
//! A bool that enables the chemical kinetics equations
371+
bool m_chem = false;
392372
};
393373
}
394374

include/cantera/zeroD/ReactorDelegator.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class ReactorDelegator : public Delegator, public R, public ReactorAccessor
7474
install("updateState", m_updateState,
7575
[this](std::array<size_t, 1> sizes, double* y) { R::updateState(y); });
7676
install("updateSurfaceState", m_updateSurfaceState,
77-
[this](std::array<size_t, 1> sizes, double* y) { R::updateSurfaceState(y); });
77+
[this](std::array<size_t, 1> sizes, double* y)
78+
{ R::updateSurfaceState(y); });
7879
install("getSurfaceInitialConditions", m_getSurfaceInitialConditions,
7980
[this](std::array<size_t, 1> sizes, double* y) {
8081
R::getSurfaceInitialConditions(y);
@@ -89,8 +90,8 @@ class ReactorDelegator : public Delegator, public R, public ReactorAccessor
8990
);
9091
install("evalWalls", m_evalWalls, [this](double t) { R::evalWalls(t); });
9192
install("evalSurfaces", m_evalSurfaces,
92-
[this](std::array<size_t, 3> sizes, double* LHS, double* RHS, double* sdot) {
93-
R::evalSurfaces(LHS, RHS, sdot);
93+
[this](std::array<size_t, 3> sizes, double* LHS, double* RHS, double* sd) {
94+
R::evalSurfaces(LHS, RHS, sd);
9495
}
9596
);
9697
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
#include "cantera/numerics/SteadyStateSystem.h"
1214

@@ -289,16 +291,7 @@ class ReactorNet : public FuncEval
289291
//! Return the index corresponding to the start of the reactor specific state
290292
//! vector in the reactor with index *reactor* in the global state vector for the
291293
//! reactor network.
292-
size_t globalStartIndex(Reactor* curr_reactor) {
293-
for (size_t i = 0; i < m_reactors.size(); i++) {
294-
if (curr_reactor == m_reactors[i]) {
295-
return m_start[i];
296-
}
297-
}
298-
throw CanteraError("ReactorNet::globalStartIndex: ",
299-
curr_reactor->name(), " not found in network.");
300-
return npos;
301-
}
294+
size_t globalStartIndex(ReactorBase* curr_reactor);
302295

303296
//! Return the name of the i-th component of the global state vector. The
304297
//! name returned includes both the name of the reactor and the specific
@@ -485,6 +478,10 @@ class ReactorNet : public FuncEval
485478
//! derivative settings
486479
bool m_jac_skip_walls = false;
487480
bool m_jac_skip_flow_devices = false;
481+
//! set to store walls for Jacobian calculation
482+
set<WallBase*> m_walls;
483+
//! set to store flow devices for Jacobian calculation
484+
set<FlowDevice*> m_flow_devices;
488485
};
489486

490487

include/cantera/zeroD/Wall.h

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,47 +94,27 @@ class WallBase : public ConnectorNode
9494
//! Build the Jacobian terms specific to the flow device for the given connected
9595
//! reactor.
9696
//! @param r a pointer to the calling reactor
97-
//! @param jacVector a vector of triplets to be added to the jacobian for the
98-
//! reactor
97+
//! @param jacVector a vector of triplets to be added to the reactor Jacobian
9998
//! @warning This function is an experimental part of the %Cantera API and may be
100-
//! changed
101-
//! or removed without notice.
102-
//! @since New in %Cantera 3.0.
99+
//! changed or removed without notice.
100+
//! @since New in %Cantera 3.1.
103101
//!
104-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
102+
virtual void buildReactorJacobian(ReactorBase* r,
103+
vector<Eigen::Triplet<double>>& jacVector) {
105104
throw NotImplementedError("WallBase::buildReactorJacobian");
106105
}
107106

108-
//! Build the Jacobian terms specific to the flow device for the network. These
109-
//! terms
110-
//! will be adjusted to the networks indexing system outside of the reactor.
111-
//! @param jacVector a vector of triplets to be added to the jacobian for the
112-
//! reactor
107+
//! Build the Jacobian cross-reactor terms specific to the flow device for the
108+
//! network.
109+
//! @param jacVector a vector of triplets to be added to the network Jacobian
113110
//! @warning This function is an experimental part of the %Cantera API and may be
114-
//! changed
115-
//! or removed without notice.
116-
//! @since New in %Cantera 3.0.
111+
//! changed or removed without notice.
112+
//! @since New in %Cantera 3.1.
117113
//!
118114
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
119115
throw NotImplementedError("WallBase::buildNetworkJacobian");
120116
}
121117

122-
//! Specify the jacobian terms have been calculated and should not be recalculated.
123-
//! @warning This function is an experimental part of the %Cantera API and may be
124-
//! changed
125-
//! or removed without notice.
126-
//! @since New in %Cantera 3.0.
127-
//!
128-
void jacobianCalculated() { m_jac_calculated = true; };
129-
130-
//! Specify that jacobian terms have not been calculated and should be recalculated.
131-
//! @warning This function is an experimental part of the %Cantera API and may be
132-
//! changed
133-
//! or removed without notice.
134-
//! @since New in %Cantera 3.0.
135-
//!
136-
void jacobianNotCalculated() { m_jac_calculated = false; };
137-
138118
protected:
139119
ReactorBase* m_left = nullptr;
140120
ReactorBase* m_right = nullptr;
@@ -143,10 +123,6 @@ class WallBase : public ConnectorNode
143123
double m_time = 0.0;
144124

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

152128
//! Represents a wall between between two ReactorBase objects.
@@ -276,9 +252,11 @@ class Wall : public WallBase
276252
return m_k;
277253
}
278254

279-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) override;
255+
void buildReactorJacobian(ReactorBase* r,
256+
vector<Eigen::Triplet<double>>& jacVector) override;
280257

281-
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) override;
258+
void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector)
259+
override;
282260

283261
protected:
284262

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)