classdef (Sealed = true) odeJacobian
    properties
        Jacobian % Jacobian function [ function_handle | constant matrix ]
        SparsityPattern = [] % Jacobian sparsity pattern [ sparse matrix ]
    end
    methods
        function obj = odeJacobian(nv)
            arguments
                nv.?odeJacobian
            end
            names = fieldnames(nv);
            for k = 1:numel(names)
                obj.(names{k}) = nv.(names{k});
            end            
        end
        function obj = set.Jacobian(obj,J)
            % We don't worry about what J looks like here. The ODE solver
            % will have to decide what to do with it, as the ODE_Jacobian
            % object doesn't have access to the ODE definition to bind
            % parameters or whatnot.
            if isa(J,'function_handle') || isnumeric(J)
                obj.Jacobian = J;
            else
                error(message("MATLAB:ode:InvalidJacobian"));
            end
        end
    end

    properties(Constant,Hidden)
        % 1.0 : Initial version (R2023b)
        Version = 1.0;
    end

    methods (Hidden)
        function b = saveobj(a)
            % Save all properties to struct. 
            b = ode.assignProps(a,false,"odeJacobian");
            % Keep track of versioning information.
            b.CompatibilityHelper.versionSavedFrom = a.Version;
            b.CompatibilityHelper.minCompatibleVersion = 1.0;
        end
    end

    methods (Hidden,Static)
        function b = loadobj(a)
            if odeJacobian.Version < a.CompatibilityHelper.minCompatibleVersion
                warning(message("MATLAB:ode:MinVersionIncompat","odeJacobian"));
                b = odeJacobian;
                return
            end
            b = ode.assignProps(a,true,"odeJacobian");
        end
    end

end

%    Copyright 2023 MathWorks, Inc.