python
This module contains all the different writers per reactor for the python language.
Batch
- class pykinetic.writers.python.Batch(**kwargs)[source]
Writer class of python scripts for Batch reactor models
- constant(reaction, value_format='{:0.10e}')[source]
Takes in a reaction and returns 2 expressions, the string of the variable and the string with the value of the constant. I.e.
# Reaction(1 => 2)
A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)>
'k01', '1.00000000' = PythonWriter.constant(A)
- Parameters:
reaction (Reaction) -- Any reaction
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- jacobian_element(Jac_ij)[source]
Takes the partial differential of a MB and returns the variable of the jacobian and the string of the expression. I.e.
# Given a Chemical system with only Reaction('A <=> B')
# d[A]dt = -r1 + r2 = -k01[A] + k2[B]
# being A.key = 0 and B.key = 1
C = <JacobianElement(Reaction(1),Compound(A))>
'Jac[0,0]', '-k01' = PythonWriter.jacobian_element(A)
- Parameters:
Jac_ij (JacobianElement) -- Any JacobianElement object
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- massbalance(MassBalance)[source]
Takes in a mass balance and returns 2 expressions, the string of the variable and the string of the expression. I.e.
# Given a Chemical system with only Reaction('A <=> B')
# d[A]dt = -r1 + r2 = -k01[A] + k2[B]
# being A.key = 0 and B.key = 1
A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)>
'dxdt[0]', '-k01*x[1] +k02[B]' = PythonWriter.massbalance(A)
- Parameters:
reaction (MassBalance) -- Any MassBalance
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- ratelaw(reaction)[source]
Takes in a reaction and returns 2 expressions, the string of the variable and the string of the ratelaw expression. I.e. # Reaction(1 => 2) A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)> 'r01', 'k01*x[1]' = PythonWriter.ratelaw(A)
- Parameters:
reaction (Reaction) -- Any reaction
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
- ratelaw_partial(reaction, compound)[source]
Takes in a reaction and returns and the string of the partial derivative the ratelaw with respect to the concentration of compound. I.e.
# Reaction(1 => 2), Compound 1
A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)>
# r01,'k01*x[1]'ratelaw(A)
'k01' = PythonWriter.ratelaw_partial(A)
PFR
- class pykinetic.writers.python.PFR(flow=1.0, volume=1.0, **kwargs)[source]
Writer class of python scripts for ideal Plug Flow Reactors (PFR) models. Models using this writer take inlet concentrations as floats and not tuples. Allows providing the parameters through a SimulationParameters instance or directly upon instantiation.
- Parameters:
flow (float) -- Flowrate in L/s
volume (float) -- Reactor Volume in L
SemiBatch
- class pykinetic.writers.python.SemiBatch(flow, Vini, **kwargs)[source]
A writer to account for a SemiBatch Reactor with an influx of species coupled after a 'tsection' time of the total simulation with a Batch reactor. As a consequence the Simulation parameters required for this type of model require the parameters 'tsection' and 'tfin' as well as the parameters for the initial SemiBatch reactor.
- Parameters:
flow (float) -- Flowrate in L/s
volume (float) -- Reactor Volume in L
- massbalance(MassBalance)[source]
Takes in a mass balance and returns 2 expressions, the string of the variable and the string of the expression. I.e.
# Given a Chemical system with only Reaction('A <=> B')
# d[A]dt = -r1 + r2 = -k01[A] + k2[B]
# being A.key = 0 and B.key = 1
A = <ElementalStep 1 of Type '=>' with reacts=(1,) products(2,)>
'dxdt[0]', '-k01*x[1] +k02[B]' = PythonWriter.massbalance(A)
- Parameters:
reaction (MassBalance) -- Any MassBalance
- Returns:
variable and expresion of the reaction
- Return type:
var,expr
SemiBatchExtended
- class pykinetic.writers.python.SemiBatchExtended(flow, Vini, **kwargs)[source]
Extension of the SemiBatch reactor model that allows up to 2 chemical systems, one per section.
- fill(system1, system2=None)[source]
Reads the information of the chemical system and updates the values needed for writing.
- Parameters:
system1 (ChemicalSystem) -- Chemical System to be written for the SemiBatch reactor model section
system2 (ChemicalSystem, optional) -- Chemical System to be written for the Batch reactor model section, If none is provided it defaults to the system1.