Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Species Sensitivity Analysis for 1D Flames #1830

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
30 changes: 30 additions & 0 deletions interfaces/cython/cantera/onedim.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ def set_profile(self, component, positions, values):
"""
super().set_profile(self.flame, component, positions, values)

def get_species_reaction_sensitivities(self, species: str, ix: int):
r"""
Compute the normalized sensitivities of a species
:math:`S_u` with respect to the reaction rate constants :math:`k_i`:

.. math::
s_i = \frac{k_i}{X} \frac{dX}{dk_i}
:param species:
Species of interest for sensitivity calculation (i.e "NO")
:param ix:
grid point index (0 is the first, -1 is the last point in the domain)
"""

def g(sim):
return self.X[self.gas.species_index(species), ix]

Nvars = sum(D.n_components * D.n_points for D in self.domains)
marina8888 marked this conversation as resolved.
Show resolved Hide resolved

# Index of X[ix] in the global solution vector
i_Su = self.inlet.n_components + self.flame.component_index(species) + self.domains[1].n_components * ix
dgdx = np.zeros(Nvars)
dgdx[i_Su] = 1

Su0 = g(self)

def perturb(sim, i, dp):
sim.gas.set_multiplier(1 + dp, i)

return self.solve_adjoint(perturb, self.gas.n_reactions, dgdx) / Su0

@property
def max_grid_points(self):
"""
Expand Down
Loading