SLACKHA / pyJac

Creates C and CUDA analytical Jacobians for chemical kinetics ODE systems
http://slackha.github.io/pyJac/
MIT License
52 stars 23 forks source link

a compile warning about numpy api #23

Closed ghost closed 6 years ago

ghost commented 6 years ago
# ... a lot of other compiling works
gcc -pthread -B /root/miniconda/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Iout/ -I/root/miniconda/lib/python3.6/site-packages/numpy/core/include -I/root/miniconda/include/python3.6m -c /root/miniconda/lib/python3.6/site-packages/pyjac/pywrap/pyjacob_wrapper.c -o build/temp.linux-x86_64-3.6/root/miniconda/lib/python3.6/site-packages/pyjac/pywrap/pyjacob_wrapper.o -frounding-math -fsignaling-nans
In file included from /root/miniconda/lib/python3.6/site-packages/numpy/core/include/numpy/ndarraytypes.h:1809:0,
                 from /root/miniconda/lib/python3.6/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
                 from /root/miniconda/lib/python3.6/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /root/miniconda/lib/python3.6/site-packages/pyjac/pywrap/pyjacob_wrapper.c:525:
/root/miniconda/lib/python3.6/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \
  ^
gcc -pthread -shared -B /root/miniconda/compiler_compat -L/root/miniconda/lib -Wl,-rpath=/root/miniconda/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/root/miniconda/lib/python3.6/site-packages/pyjac/pywrap/pyjacob_wrapper.o /root/build/temp.linux-x86_64-3.6/libc_pyjac.a -o /root/pyjacob.cpython-36m-x86_64-linux-gnu.so

Code:

###  Jupyter IPython
%matplotlib inline
import pyjac as pj
import cantera as ct
import numpy as np

#create gas from original mechanism file gri30.cti
gas = ct.Solution('gri30.cti')
#reorder the gas to match pyJac
n2_ind = gas.species_index('N2')
specs = gas.species()[:]
gas = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',
        species=specs[:n2_ind] + specs[n2_ind + 1:] + [specs[n2_ind]],
        reactions=gas.reactions())

# generate the c code to ./out folder
pj.create_jacobian(lang='c',gas=gas)
!python -m pyjac.libgen --source_dir ./out \
       --lang c
!python -m pyjac.pywrap --source_dir ./out \
       --lang c
import pyjacob 
#set the gas state
T = 1000
P = ct.one_atm
gas.TPY = T, P, "CH4:1.0, O2:2, N2:7.52"

#setup the state vector
y = np.zeros(gas.n_species)
y[0] = T
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)

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

# eigen
import numpy as np
print(np.linalg.eig(jac))
michael-a-hansen commented 6 years ago

The numpy warning is a cython thing. It's annoying but not an indicator of a problem: http://docs.cython.org/en/latest/src/reference/compilation.html#configuring-the-c-build

More importantly, your reshape should do column-major ordering: reshape((ns, ns), order='F').

ghost commented 6 years ago

Thanks, I just found the problem. The spy of sparse matrix seems transposed. The third body reaction made the indicator.