Beispiel #1
0
def create_jacobian(T, P, y):

    n_species = len(y)
    dydt = np.zeros_like(y)
    pyjacob.py_dydt(0, P, y, dydt)

    #create a jacobian vector
    jac = np.zeros(n_species * n_species)

    #evaluate the Jacobian
    pyjacob.py_eval_jacobian(0, P, y, jac)
    jac = jac.reshape(n_species, n_species)

    return jac
Beispiel #2
0
def jacobval(time, state, press):
    """Force the integrator to use the right arguments."""
    # Need to get rid of N2 because PyJac doesn't compute it.
    # new = state[:-1]
    # print('Jacobian function called.')
    a = len(state)
    jacobian = np.zeros(a**2)
    # Obtain the jacobian from pyJac
    pyjacob.py_eval_jacobian(time, press, state, jacobian)
    jacobian = np.reshape(jacobian, (a, a))
    # Re-add the zeros back in
    # jacobian = np.insert(jacobian, a, np.zeros(a), axis=1)
    # jacobian = np.vstack((jacobian, np.zeros(a+1)))
    return jacobian
Beispiel #3
0
def max_eig_gas(gas):

    # input arg: gas cantera object
    # output arg: eigenvalue vector, left and right eigenvector matrices

    T = gas.T
    P = gas.P

    # #setup the state vector
    y = np.zeros(gas.n_species)
    y[0] = T

    for i in range(1, gas.n_species):
        if gas.species_name(i) != 'N2':
            # print(gas.species_name(i))
            y[i] = gas.Y[i]
    # y[1:] = gas.Y[:-1]

    # #create a dydt vector
    dydt = np.zeros_like(y)
    pyjacob.py_dydt(0, P, y, dydt)

    #create a jacobian vector
    jac = np.zeros(gas.n_species * gas.n_species)

    #evaluate the Jacobian
    pyjacob.py_eval_jacobian(0, P, y, jac)

    jac = jac.reshape(gas.n_species, gas.n_species)

    # Solve eigenvalue PB > D: eigenvalues
    D, vl, vr = LA.eig(jac, left=True)

    D = D.real
    # vl=vl.real
    # vr=vr.real

    # introduced to get rid of zeros: careful!
    # D = np.delete(D,np.where(D==0.0))
    # cannot delete here, must be after (affects EI)

    # return D, vl, vr

    return np.amax(D)
Beispiel #4
0
# rearrange species in solution object
gas = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',
        species=specs[:last_idx] + specs[last_idx + 1:] + [specs[last_idx]],
        reactions=gas.reactions())

#set the gas state
T = 1200
P = ct.one_atm
gas.TPY = T, P, "CH4:0.2, O2:2, N2:7.52"

# #setup the thermochemical state vector
y = np.zeros(gas.n_species)
y[0] = T
y[1:] = gas.Y[:-1] # all species mass fractions except the one belonging to last_spec

# create a dy/dt vector
dydt = np.zeros_like(y)
pyjacob.py_dydt(0, P, y, dydt)

#create a jacobian vector
jac = np.zeros(gas.n_species * gas.n_species)

#evaluate the Jacobian
pyjacob.py_eval_jacobian(0, P, y, jac)

jac = jac.reshape(gas.n_species,gas.n_species)          # reshape into matrix for further calculations

print(jac) 

print('test: successful')