Closed michael-a-hansen closed 7 years ago
@michael-a-hansen ok, the issue here is that the t
argument in py_dydt
and py_eval_jacobian
actually represents time, not temperature. The state vector (for the C module) should consist of:
[T, Y0, Y1.... YNsp]
Hence you should get the correct results by calling this as:
Y = gas.Y
Y = np.concatenate(([T], Y))
dYdt = np.zeros_like(Y)
Jflat = np.zeros((nspec) * (nspec))
pyjacob.py_dydt(0, p, Y, dYdt)
pyjacob.py_eval_jacobian(0, p, Y, Jflat)
Also note that due to the formulation of our system, the Jacobian is actually Nsp x Nsp, i.e. 1 entry for Temperature and Nspecies - 1 entries for the species mass fractions (using the strict mass conservation formulation)
The reason for all this confusion is that typically in ODE solvers, the RHS / Jacobian function accept time as an argument in case the equations are dependent on it directly. To conform to CVODE, etc. it is also included here.
@kyleniemeyer didn't we have someone working on documentation for the python wrapper? It looks like an example would be particularly useful 👍
edit: also, we might want to just drop the 'time' argument, although that may hamper coupling pyJac to a python based integrator package
Terrific! Thank you. It is working as expected now :)
A note: it's very confusing that Y
is TY
in the higher-level functions (dydt
and such) and Y
in the lower-level methods (eval_conc
and such). Additionally, when looking at the auto-generated code, I saw a line like the following, which I was ready to submit as a massive bug report before I realized Y
is TY
and so y[1]
is actually the first mass fraction (first element of Y
, second of TY
)! I think simply replacing Y
with TY
where appropriate would help new developers and users immensely.
cp[0] * y[1] + cp[1] * y[2] + cp[2] * y[3] + cp[3] * y[4] ...
Hello,
I've just used pyJac's pyWrap utility to write C code that I can call from python. I'm getting
nan
s when I evaluatepy_dydt
andpy_eval_jacobian
, but not frompy_eval_conc
,py_eval_rxn_rates
,py_get_rxn_pres_mod
, orpy_eval_spec_rates
. See details below.Build procedure
pyJac call:
python3 -m pyjac -i h2-burke.xml -l c
pyWrap call:python3 -m pyjac.pywrap --source_dir out -l c
While pyWrap completes without errors, I get a deprecated numpy warning during compilation and the following warning during linkage. I'm not sure but it seems like it might be important.
Here's the input file (XML generated by cantera): h2-burke.xml.zip
Sample code (requires cantera, numpy, and generated pyjacob)
The snippet below evaluates some pyJac functions and prints the results, demonstrating (on my machine) that everything looks okay except for
dYdt
andJflat
, which are full ofnan
s.Software state