added README_changes.txt
[wrffire.git] / wrfv2_fire / chem / KPP / kpp / kpp-2.1 / util / dJac_dRcoeff.m
blob08f990b5f85b2e533b733b9a48d6aefe688d63a8
1 % ------------------------------------------------------------------------------
2 % Subroutine for the derivative of Jac with respect to rate coefficients
3 % Times a user vector
4 % -----------------------------------------------------------------------------
6 DJDR = function dJac_dRcoeff( V, F, U, NCOEFF, JCOEFF )
8 % V - Concentrations of variable/fixed species            
9 %        KPP_REAL V(KPP_NVAR), F(NFIX)
10 % U - User-supplied Vector           
11 %         KPP_REAL U(KPP_NVAR)
12 % NCOEFF - the number of rate coefficients with respect to which we differentiate
13 %       INTEGER NCOEFF       
14 % JCOEFF - a vector of integers containing the indices of reactions (rate
15 %          coefficients) with respect to which we differentiate
16 %          INTEGER JCOEFF(NCOEFF)       
17 % DFDR  - a matrix containg derivative values; specifiy, 
18 %         column j contains d Jac(1:KPP_NVAR) / d RCT( JCOEFF(j) ) * U
19 %                     for each 1 <= j <= NCOEFF
20 %         This matrix is stored in a column-wise linearized format
21 %         KPP_REAL DJDR(KPP_NVAR*NCOEFF)
23 % Local vector for Jacobian of reactant products
24 %         KPP_REAL JV_RPROD(NJVRP)
25 % Compute the Jacobian of all reactant products   
26       JV_RPROD = JacReactantProd( V, F );
28 % Compute the derivatives by multiplying column JCOEFF(j) of the stoichiometric matrix with A_PROD       
29       for j=1:NCOEFF
30 %                  Initialize the j-th column of derivative matrix to zero       
31          for i=1,KPP_NVAR
32            DJDR(i+KPP_NVAR*(j-1)) = 0.0;
33          end
34 %                  Column JCOEFF(j) in the stoichiometric matrix times the
35 %                  ( Gradient of reactant product of the JCOEFF(j)-th reaction X user vector )    
36 %                  give the j-th column of the derivative matrix   
38 %          Row JCOEFF(j) of JV_RPROD times the user vector
39          aj = 0.0;
40          for k=CROW_JVRP(JCOEFF(j)):CROW_JVRP(JCOEFF(j)+1)-1
41              aj = aj + JV_RPROD(k)*U(ICOL_JVRP(k));
42          end
43 %          Column JCOEFF(j) of Stoichiom. matrix times aj         
44          for k=CCOL_STOICM(JCOEFF(j)):CCOL_STOICM(JCOEFF(j)+1)-1
45            DJDR(IROW_STOICM(k)+KPP_NVAR*(j-1)) = STOICM(k)*aj;
46          end
47       end
48       
49 return % dJac_dRcoeff