Skip to content

Commit 3b892b6

Browse files
Working on PR updates, have to fix a few more bugs
in regards to equations, handling volumes, etc.
1 parent 7794f7e commit 3b892b6

File tree

17 files changed

+162
-261
lines changed

17 files changed

+162
-261
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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ class FlowDevice
141141
//! @warning This function is an experimental part of the %Cantera API and may be
142142
//! changed
143143
//! or removed without notice.
144-
//! @since New in %Cantera 3.0.
144+
//! @since New in %Cantera 3.1.
145145
//!
146-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
146+
virtual void buildReactorJacobian(ReactorBase* r,
147+
vector<Eigen::Triplet<double>>& jacVector) {
147148
throw NotImplementedError(type() + "::buildReactorJacobian");
148149
}
149150

@@ -155,29 +156,12 @@ class FlowDevice
155156
//! @warning This function is an experimental part of the %Cantera API and may be
156157
//! changed
157158
//! or removed without notice.
158-
//! @since New in %Cantera 3.0.
159+
//! @since New in %Cantera 3.1.
159160
//!
160161
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
161-
if (!m_jac_calculated) {
162-
throw NotImplementedError(type() + "::buildNetworkJacobian");
163-
}
162+
throw NotImplementedError(type() + "::buildNetworkJacobian");
164163
}
165164

166-
//! Specify the jacobian terms have been calculated and should not be recalculated.
167-
//! @warning This function is an experimental part of the %Cantera API and may be
168-
//! changed
169-
//! or removed without notice.
170-
//! @since New in %Cantera 3.0.
171-
//!
172-
void jacobianCalculated() { m_jac_calculated = true; };
173-
174-
//! Specify that jacobian terms have not been calculated and should be recalculated.
175-
//! @warning This function is an experimental part of the %Cantera API and may be changed
176-
//! or removed without notice.
177-
//! @since New in %Cantera 3.0.
178-
//!
179-
void jacobianNotCalculated() { m_jac_calculated = false; };
180-
181165
protected:
182166
string m_name; //!< Flow device name.
183167
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
@@ -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
@@ -70,12 +70,6 @@ class Reactor : public ReactorBase
7070
m_chem = cflag;
7171
}
7272

73-
//! Returns `true` if changes in the reactor composition due to chemical reactions
74-
//! are enabled.
75-
bool chemistryEnabled() const {
76-
return m_chem;
77-
}
78-
7973
void setEnergy(int eflag=1) override {
8074
if (eflag > 0) {
8175
m_energy = true;
@@ -84,11 +78,6 @@ class Reactor : public ReactorBase
8478
}
8579
}
8680

87-
//! Returns `true` if solution of the energy equation is enabled.
88-
bool energyEnabled() const {
89-
return m_energy;
90-
}
91-
9281
//! Number of equations (state variables) for this reactor
9382
size_t neq() {
9483
if (!m_nv) {
@@ -195,15 +184,7 @@ class Reactor : public ReactorBase
195184
//!
196185
//! @warning This method is an experimental part of the %Cantera
197186
//! API and may be changed or removed without notice.
198-
virtual Eigen::SparseMatrix<double> jacobian() {
199-
m_jac_trips.clear();
200-
// Add before, during, after evals
201-
buildJacobian(m_jac_trips);
202-
// construct jacobian from vector
203-
Eigen::SparseMatrix<double> jac(m_nv, m_nv);
204-
jac.setFromTriplets(m_jac_trips.begin(), m_jac_trips.end());
205-
return jac;
206-
}
187+
virtual Eigen::SparseMatrix<double> jacobian();
207188

208189
//! Calculate the Jacobian of a specific Reactor specialization.
209190
//! @param jacVector vector where jacobian triplets are added
@@ -321,8 +302,6 @@ class Reactor : public ReactorBase
321302

322303
vector<double> m_wdot; //!< Species net molar production rates
323304
vector<double> m_uk; //!< Species molar internal energies
324-
bool m_chem = false;
325-
bool m_energy = true;
326305
size_t m_nv = 0;
327306
size_t m_nv_surf; //!!< Number of variables associated with reactor surfaces
328307

include/cantera/zeroD/ReactorBase.h

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,15 @@ class ReactorBase
266266
//! Set the ReactorNet that this reactor belongs to.
267267
void setNetwork(ReactorNet* net);
268268

269-
//! Calculate the derivative of T with respect to the ith species in the heat
270-
//! transfer equation based on the reactor specific equation of state.
269+
//! Calculate the derivative of T with respect to the ith species in the energy
270+
//! conservation equation based on the reactor specific equation of state.
271271
//! @param index index of the species the derivative is with respect too
272-
//! @warning This function is an experimental part of the %Cantera API and may be changed
273-
//! or removed without notice.
274-
//! @since New in %Cantera 3.0.
275-
//!
276-
virtual double moleDerivative(size_t index) {
277-
throw NotImplementedError("Reactor::moleDerivative");
278-
}
279-
280-
//! Calculate the derivative of T with respect to the ith species in the heat
281-
//! transfer radiation equation based on the reactor specific equation of state.
282-
//! @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.
272+
//! @warning This function is an experimental part of the %Cantera API and may
273+
//! be changed or removed without notice.
274+
//! @since New in %Cantera 3.1.
286275
//!
287-
virtual double moleRadiationDerivative(size_t index) {
288-
throw NotImplementedError("Reactor::moleRadiationDerivative");
276+
virtual double temperature_ddni(size_t index) {
277+
throw NotImplementedError("Reactor::temperature_ddni");
289278
}
290279

291280
//! Return the index associated with energy of the system
@@ -294,6 +283,17 @@ class ReactorBase
294283
//! Return the offset between species and state variables
295284
virtual size_t speciesOffset() const { return m_sidx; };
296285

286+
//! Returns `true` if solution of the energy equation is enabled.
287+
virtual bool energyEnabled() const {
288+
return m_energy;
289+
}
290+
291+
//! Returns `true` if changes in the reactor composition due to chemical reactions
292+
//! are enabled.
293+
bool chemistryEnabled() const {
294+
return m_chem;
295+
}
296+
297297
protected:
298298
//! Specify the mixture contained in the reactor. Note that a pointer to
299299
//! this substance is stored, and as the integration proceeds, the state of
@@ -338,6 +338,12 @@ class ReactorBase
338338

339339
//! Composite thermo/kinetics/transport handler
340340
shared_ptr<Solution> m_solution;
341+
342+
//! A bool that enables the energy equation
343+
bool m_energy = true;
344+
345+
//! A bool that enables the chemical kinetics equations
346+
bool m_chem = false;
341347
};
342348
}
343349

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

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
@@ -417,6 +410,10 @@ class ReactorNet : public FuncEval
417410
//! derivative settings
418411
bool m_jac_skip_walls = false;
419412
bool m_jac_skip_flow_devices = false;
413+
//! set to store walls for Jacobian calculation
414+
set<WallBase*> m_walls;
415+
//! set to store flow devices for Jacobian calculation
416+
set<FlowDevice*> m_flow_devices;
420417
};
421418
}
422419

include/cantera/zeroD/Wall.h

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -108,47 +108,27 @@ class WallBase
108108
//! Build the Jacobian terms specific to the flow device for the given connected
109109
//! reactor.
110110
//! @param r a pointer to the calling reactor
111-
//! @param jacVector a vector of triplets to be added to the jacobian for the
112-
//! reactor
111+
//! @param jacVector a vector of triplets to be added to the reactor Jacobian
113112
//! @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.
113+
//! changed or removed without notice.
114+
//! @since New in %Cantera 3.1.
117115
//!
118-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
116+
virtual void buildReactorJacobian(ReactorBase* r,
117+
vector<Eigen::Triplet<double>>& jacVector) {
119118
throw NotImplementedError("WallBase::buildReactorJacobian");
120119
}
121120

122-
//! Build the Jacobian terms specific to the flow device for the network. These
123-
//! terms
124-
//! will be adjusted to the networks indexing system outside of the reactor.
125-
//! @param jacVector a vector of triplets to be added to the jacobian for the
126-
//! reactor
121+
//! Build the Jacobian cross-reactor terms specific to the flow device for the
122+
//! network.
123+
//! @param jacVector a vector of triplets to be added to the network Jacobian
127124
//! @warning This function is an experimental part of the %Cantera API and may be
128-
//! changed
129-
//! or removed without notice.
130-
//! @since New in %Cantera 3.0.
125+
//! changed or removed without notice.
126+
//! @since New in %Cantera 3.1.
131127
//!
132128
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
133129
throw NotImplementedError("WallBase::buildNetworkJacobian");
134130
}
135131

136-
//! Specify the jacobian terms have been calculated and should not be recalculated.
137-
//! @warning This function is an experimental part of the %Cantera API and may be
138-
//! changed
139-
//! or removed without notice.
140-
//! @since New in %Cantera 3.0.
141-
//!
142-
void jacobianCalculated() { m_jac_calculated = true; };
143-
144-
//! Specify that jacobian terms have not been calculated and should be recalculated.
145-
//! @warning This function is an experimental part of the %Cantera API and may be
146-
//! changed
147-
//! or removed without notice.
148-
//! @since New in %Cantera 3.0.
149-
//!
150-
void jacobianNotCalculated() { m_jac_calculated = false; };
151-
152132
protected:
153133
string m_name; //!< Wall name.
154134
bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
@@ -160,10 +140,6 @@ class WallBase
160140
double m_time = 0.0;
161141

162142
double m_area = 1.0;
163-
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;
167143
};
168144

169145
//! Represents a wall between between two ReactorBase objects.
@@ -268,9 +244,11 @@ class Wall : public WallBase
268244
return m_k;
269245
}
270246

271-
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) override;
247+
void buildReactorJacobian(ReactorBase* r,
248+
vector<Eigen::Triplet<double>>& jacVector) override;
272249

273-
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) override;
250+
void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector)
251+
override;
274252

275253
protected:
276254

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)