function [Cineq,Jacineq] = InEqReact_Un(nvar,into,colind,scl,def)

% Written by Julian Straus, Trondheim 09.12.2018
%
% This function defines the inequality constraints in the reaction section
% section of the simple ammonia loop. It can be modified to define the
% flowsheet differently. The inequalities in this file are given by
%
%   A minimum value for each split ratio
%   The total sum of the split ratio
%   Bounds for the reference temperature
%
% The input of this function is given by
%       nvar:   Total number of variables.
%
%       into:   Input values to the unit operation defined in the
%               flowsheet.
%
%       colind: Indexes of the columns i the Jacobian.
%
% The main output is defined as
%       Ceqdef: Cells containing the equality constraints of the
%               definitions.
%
%       Jacdef: Cells containing the rows of the Jacobian defined by the
%               definitions.
%
% The necessary structures and cells are defined as
%       scl:    Scaling factors of the system defined in cells representing
%               the unit operations defined in par.ReactSec.
%
%       def:    Defined stream values, e.g pressure and composition for all
%               inlets and the pressure of the outlets or the flow of the
%               inlets.

% Predefinition of the returning cells.
Jacineq = cell(def.sizeMat);
Cineq = Jacineq;

%% Inequalities in Split 1
k = 3;
% Calculation of the inequality constraints for Split 1
Cineq{k} = [into{k}(33:34).*scl{k}.Var(33:34)'-[14.7109; 76.6694];...
            [4.7109; 36.6694] - into{k}(33:34).*scl{k}.Var(33:34)'].*scl{k}.InEq;

% Calculation of the parts of the Jacobian given by the inequality
% constraint of Split 1
colindineq{k} = colind{k}([33 34 33 34]);
Jacineq{k} = sparse([1:numel(Cineq{k})],colindineq{k},[1 1 -1 -1].*scl{k}.InEq(1:numel(Cineq{k}))'.*scl{k}.Var([33 34 33 34]),...
                    numel(Cineq{k}),nvar);

%% Inequalities in Heat Exchanger 5
k = 17;
% Calculation of the inequality constraints for Heat Exchanger 5
Cineq{k} = [into{k}(9).*scl{k}.Var(9)'-175;...
            145 - into{k}(9).*scl{k}.Var(9)'].*scl{k}.InEq;

% Calculation of the parts of the Jacobian given by the inequality
% constraint of Heat Exchanger 5
colindineq{k} = colind{k}([9 9]);
Jacineq{k} = sparse([1:numel(Cineq{k})],colindineq{k},[1 -1].*scl{k}.InEq([1:numel(Cineq{k})])'.*scl{k}.Var([9 9]),...
                    numel(Cineq{k}),nvar);
