function [f dfdx dfdp] = flux2rhs(w, dwdx, dwdp, nX, nP)
%% sums individual reaction fluxes into the ode's full RHS
% 
% This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative 
% Works 3.0 United States License. To view a copy of this license, visit 
% http://creativecommons.org/licenses/by-nc-nd/3.0/us/ or send a letter to Creative Commons,
% 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

f = @rhs;
dfdx = @ddxrhs;
dfdp = @ddprhs;

    function val = rhs(t,x)
        val = zeros(nX, 1);
        for i = 1:length(w)
            val = val + w{i}(t,x);
        end
    end
    function val = ddxrhs(t,x)
        val = zeros(nX, nX);
        for i = 1:length(dwdx)
            val = val + dwdx{i}(t,x);
        end
    end
    function val = ddprhs(t,x)
        val = zeros(nX, nP);
        for i = 1:length(dwdp)
            val = val + dwdp{i}(t,x);
        end
    end
end