Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / chem / KPP / kpp / kpp-2.1 / util / dFun_dRcoeff.m
blobafd0e98b6fb50fb46ad16b8b54633dce18b2f549
1 % ------------------------------------------------------------------------------
2 % Subroutine for the derivative of Fun with respect to rate coefficients
3 % -----------------------------------------------------------------------------
5 DFDR = function dFun_dRcoeff( V, F, NCOEFF, JCOEFF )
7 % V/F - Concentrations of variable/fixed species            
8 % NCOEFF - the number of rate coefficients with respect to which we differentiate
9 % JCOEFF - a vector of integers containing the indices of reactions (rate
10 %          coefficients) with respect to which we differentiate
11 %      INTEGER JCOEFF(NCOEFF)       
12 % DFDR  - a matrix containg derivative values; specifically, 
13 %         column j contains d Fun(1:KPP_NVAR) / d RCT( JCOEFF(j) )
14 %         for each 1 <= j <= NCOEFF
15 %         This matrix is stored in a column-wise linearized format
16 %      KPP_REAL DFDR(KPP_NVAR*NCOEFF)
18 % A_RPROD - Local vector with reactant products      
19 % Compute the reactant products of all reactions     
20       A_RPROD = ReactantProd ( V, F );
22 % Compute the derivatives by multiplying column JCOEFF(j) of the stoichiometric matrix with A_RPROD       
23       for j=1:NCOEFF
24 %                  Initialize the j-th column of derivative matrix to zero       
25          for i=1:KPP_NVAR
26            DFDR(i+KPP_NVAR*(j-1)) = 0.0;
27          end
28 %                  Column JCOEFF(j) in the stoichiometric matrix times the
29 %                  reactant product  of the JCOEFF(j)-th reaction      
30 %                  give the j-th column of the derivative matrix   
31          aj = A_RPROD(JCOEFF(j));
32          for k=CCOL_STOICM(JCOEFF(j)):CCOL_STOICM(JCOEFF(j)+1)-1
33            DFDR(IROW_STOICM(k)+KPP_NVAR*(j-1)) = STOICM(k)*aj;
34          end
35       end
36       
37 return % dFun_dRcoeff