Skip to content

Commit

Permalink
Temp PR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-walker committed Jun 3, 2024
1 parent 51eb21c commit 3193fa3
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 127 deletions.
23 changes: 12 additions & 11 deletions doc/sphinx/develop/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Develop

(sec-compiling)=

## Compiling Cantera from Source

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

The following additional references may also be useful:

- [](compiling/dependencies.md)
- [](compiling/config-options)
- [](compiling/special-cases)
- [](compiling/dependencies.md)
- [](compiling/config-options)
- [](compiling/special-cases)

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

- [](reactor-integration)
- [](reactor-integration)

```{toctree}
:caption: How Cantera Works
Expand All @@ -47,13 +48,13 @@ reactor-integration

## Adding New Features to Cantera

- [](CONTRIBUTING)
- [](style-guidelines)
- [](vscode-tips)
- [](writing-tests)
- [](running-tests)
- [](writing-examples)
- [](doc-formatting)
- [](CONTRIBUTING)
- [](style-guidelines)
- [](vscode-tips)
- [](writing-tests)
- [](running-tests)
- [](writing-examples)
- [](doc-formatting)

```{toctree}
:caption: Adding New Features to Cantera
Expand Down
12 changes: 6 additions & 6 deletions include/cantera/zeroD/FlowDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class FlowDevice
//! @warning This function is an experimental part of the %Cantera API and may be
//! changed
//! or removed without notice.
//! @since New in %Cantera 3.0.
//! @since New in %Cantera 3.1.
//!
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
throw NotImplementedError(type() + "::buildReactorJacobian");
Expand All @@ -137,7 +137,7 @@ class FlowDevice
//! @warning This function is an experimental part of the %Cantera API and may be
//! changed
//! or removed without notice.
//! @since New in %Cantera 3.0.
//! @since New in %Cantera 3.1.
//!
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
if (!m_jac_calculated) {
Expand All @@ -149,16 +149,16 @@ class FlowDevice
//! @warning This function is an experimental part of the %Cantera API and may be
//! changed
//! or removed without notice.
//! @since New in %Cantera 3.0.
//! @since New in %Cantera 3.1.
//!
void jacobianCalculated() { m_jac_calculated = true; };
void calculatedJacobian() { m_jac_calculated = true; };

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

protected:
//! a variable to switch on and off so calculations are not doubled by the calling
Expand Down
4 changes: 1 addition & 3 deletions include/cantera/zeroD/IdealGasConstPressureMoleReactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class IdealGasConstPressureMoleReactor : public ConstPressureMoleReactor

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

double moleDerivative(size_t index) override;

double moleRadiationDerivative(size_t index) override;
double temperature_ddni(size_t index) override;

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

Expand Down
4 changes: 1 addition & 3 deletions include/cantera/zeroD/IdealGasMoleReactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class IdealGasMoleReactor : public MoleReactor

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

double moleDerivative(size_t index) override;

double moleRadiationDerivative(size_t index) override;
double temperature_ddni(size_t index) override;

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

Expand Down
13 changes: 0 additions & 13 deletions include/cantera/zeroD/Reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ class Reactor : public ReactorBase
m_chem = cflag;
}

//! Returns `true` if changes in the reactor composition due to chemical reactions
//! are enabled.
bool chemistryEnabled() const {
return m_chem;
}

void setEnergy(int eflag=1) override {
if (eflag > 0) {
m_energy = true;
Expand All @@ -98,11 +92,6 @@ class Reactor : public ReactorBase
}
}

//! Returns `true` if solution of the energy equation is enabled.
bool energyEnabled() const {
return m_energy;
}

//! Number of equations (state variables) for this reactor
size_t neq() {
if (!m_nv) {
Expand Down Expand Up @@ -335,8 +324,6 @@ class Reactor : public ReactorBase

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

Expand Down
38 changes: 22 additions & 16 deletions include/cantera/zeroD/ReactorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,15 @@ class ReactorBase
//! Set the ReactorNet that this reactor belongs to.
void setNetwork(ReactorNet* net);

//! Calculate the derivative of T with respect to the ith species in the heat
//! transfer equation based on the reactor specific equation of state.
//! Calculate the derivative of T with respect to the ith species in the energy
//! conservation equation based on the reactor specific equation of state.
//! @param index index of the species the derivative is with respect too
//! @warning This function is an experimental part of the %Cantera API and may be changed
//! or removed without notice.
//! @since New in %Cantera 3.0.
//!
virtual double moleDerivative(size_t index) {
throw NotImplementedError("Reactor::moleDerivative");
}

//! Calculate the derivative of T with respect to the ith species in the heat
//! transfer radiation equation based on the reactor specific equation of state.
//! @param index index of the species the derivative is with respect too
//! @warning This function is an experimental part of the %Cantera API and may be changed
//! or removed without notice.
//! @since New in %Cantera 3.0.
//! @since New in %Cantera 3.1.
//!
virtual double moleRadiationDerivative(size_t index) {
throw NotImplementedError("Reactor::moleRadiationDerivative");
virtual double temperature_ddni(size_t index) {
throw NotImplementedError("Reactor::temperature_ddni");

Check warning on line 288 in include/cantera/zeroD/ReactorBase.h

View check run for this annotation

Codecov / codecov/patch

include/cantera/zeroD/ReactorBase.h#L287-L288

Added lines #L287 - L288 were not covered by tests
}

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

Check warning on line 295 in include/cantera/zeroD/ReactorBase.h

View check run for this annotation

Codecov / codecov/patch

include/cantera/zeroD/ReactorBase.h#L295

Added line #L295 was not covered by tests

//! Returns `true` if solution of the energy equation is enabled.
virtual bool energyEnabled() const {
return m_energy;
}

//! Returns `true` if changes in the reactor composition due to chemical reactions
//! are enabled.
bool chemistryEnabled() const {
return m_chem;

Check warning on line 305 in include/cantera/zeroD/ReactorBase.h

View check run for this annotation

Codecov / codecov/patch

include/cantera/zeroD/ReactorBase.h#L304-L305

Added lines #L304 - L305 were not covered by tests
}

protected:
//! Specify the mixture contained in the reactor. Note that a pointer to
//! this substance is stored, and as the integration proceeds, the state of
Expand Down Expand Up @@ -348,6 +348,12 @@ class ReactorBase

//! Composite thermo/kinetics/transport handler
shared_ptr<Solution> m_solution;

//! A bool that enables the energy equation
bool m_energy = true;

//! A bool that enables the chemical kinetics equations
bool m_chem = false;
};
}

Expand Down
2 changes: 1 addition & 1 deletion include/cantera/zeroD/ReactorNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class ReactorNet : public FuncEval
//! Return the index corresponding to the start of the reactor specific state
//! vector in the reactor with index *reactor* in the global state vector for the
//! reactor network.
size_t globalStartIndex(Reactor* curr_reactor) {
size_t globalStartIndex(ReactorBase* curr_reactor) {
for (size_t i = 0; i < m_reactors.size(); i++) {
if (curr_reactor == m_reactors[i]) {
return m_start[i];
Expand Down
32 changes: 14 additions & 18 deletions include/cantera/zeroD/Wall.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ class WallBase
//! Build the Jacobian terms specific to the flow device for the given connected
//! reactor.
//! @param r a pointer to the calling reactor
//! @param jacVector a vector of triplets to be added to the jacobian for the
//! @param jacVector a vector of triplets to be added to the Jacobian for the
//! reactor
//! @warning This function is an experimental part of the %Cantera API and may be
//! changed
//! or removed without notice.
//! @since New in %Cantera 3.0.
//! changed or removed without notice.
//! @since New in %Cantera 3.1.
//!
virtual void buildReactorJacobian(ReactorBase* r, vector<Eigen::Triplet<double>>& jacVector) {
throw NotImplementedError("WallBase::buildReactorJacobian");

Check warning on line 105 in include/cantera/zeroD/Wall.h

View check run for this annotation

Codecov / codecov/patch

include/cantera/zeroD/Wall.h#L104-L105

Added lines #L104 - L105 were not covered by tests
Expand All @@ -109,32 +108,29 @@ class WallBase
//! Build the Jacobian terms specific to the flow device for the network. These
//! terms
//! will be adjusted to the networks indexing system outside of the reactor.
//! @param jacVector a vector of triplets to be added to the jacobian for the
//! @param jacVector a vector of triplets to be added to the Jacobian for the
//! reactor
//! @warning This function is an experimental part of the %Cantera API and may be
//! changed
//! or removed without notice.
//! @since New in %Cantera 3.0.
//! changed or removed without notice.
//! @since New in %Cantera 3.1.
//!
virtual void buildNetworkJacobian(vector<Eigen::Triplet<double>>& jacVector) {
throw NotImplementedError("WallBase::buildNetworkJacobian");

Check warning on line 118 in include/cantera/zeroD/Wall.h

View check run for this annotation

Codecov / codecov/patch

include/cantera/zeroD/Wall.h#L117-L118

Added lines #L117 - L118 were not covered by tests
}

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

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

protected:
ReactorBase* m_left = nullptr;
Expand Down
18 changes: 3 additions & 15 deletions src/zeroD/IdealGasConstPressureMoleReactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,11 @@ string IdealGasConstPressureMoleReactor::componentName(size_t k) {
"Index is out of bounds.");
}

double IdealGasConstPressureMoleReactor::moleDerivative(size_t index)
double IdealGasConstPressureMoleReactor::temperature_ddni(size_t index)
{
// derivative of temperature transformed by ideal gas law
vector<double> moles(m_nsp);
getMoles(moles.data());
double dTdni = pressure() * m_vol / GasConstant / std::accumulate(moles.begin(), moles.end(), 0.0);
return dTdni;
}

double IdealGasConstPressureMoleReactor::moleRadiationDerivative(size_t index)
{
// derivative of temperature transformed by ideal gas law
vector<double> moles(m_nsp);
getMoles(moles.data());
double dT4dni = std::pow(pressure() * m_vol / GasConstant, 4);
dT4dni *= std::pow(1 / std::accumulate(moles.begin(), moles.end(), 0.0), 5);
return dT4dni;
double n_total = m_mass / m_thermo->meanMolecularWeight();
return pressure() * m_vol / GasConstant / n_total;
}

}
22 changes: 3 additions & 19 deletions src/zeroD/IdealGasMoleReactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,32 +244,16 @@ void IdealGasMoleReactor::buildJacobian(vector<Eigen::Triplet<double>>& jacVecto
jacVector.emplace_back(0, static_cast<int>(j + m_sidx),

Check warning on line 244 in src/zeroD/IdealGasMoleReactor.cpp

View check run for this annotation

Codecov / codecov/patch

src/zeroD/IdealGasMoleReactor.cpp#L244

Added line #L244 was not covered by tests
(specificHeat[j] * qdot - NCv * uk_dnkdnj_sums[j]) * denom);
}

// build wall jacobian
buildWallJacobian(jacVector);
}

// build flow jacobian
buildFlowJacobian(jacVector);
}

double IdealGasMoleReactor::moleDerivative(size_t index)
{
// derivative of temperature transformed by ideal gas law
vector<double> moles(m_nsp);
getMoles(moles.data());
double dTdni = pressure() * m_vol / GasConstant / std::accumulate(moles.begin(), moles.end(), 0.0);
return dTdni;
}

double IdealGasMoleReactor::moleRadiationDerivative(size_t index)
double IdealGasMoleReactor::temperature_ddni(size_t index)
{
// derivative of temperature transformed by ideal gas law
vector<double> moles(m_nsp);
getMoles(moles.data());
double dT4dni = std::pow(pressure() * m_vol / GasConstant, 4);
dT4dni *= std::pow(1 / std::accumulate(moles.begin(), moles.end(), 0.0), 5);
return dT4dni;
double n_total = m_mass / m_thermo->meanMolecularWeight();
return pressure() * m_vol / GasConstant / n_total;
}

}
2 changes: 1 addition & 1 deletion src/zeroD/Reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void Reactor::setAdvanceLimit(const string& nm, const double limit)
}
}

void Reactor:: buildWallJacobian(vector<Eigen::Triplet<double>>& jacVector)
void Reactor::buildWallJacobian(vector<Eigen::Triplet<double>>& jacVector)
{
if (!m_jac_skip_walls) {
for (size_t i = 0; i < m_wall.size(); i++) {
Expand Down
Loading

0 comments on commit 3193fa3

Please sign in to comment.