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

% Written by Julian Straus, Trondheim 09.12.2018
%
% This function defines the inequality constraints in the separation 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 temperatures
%
% 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 2
k = 3;
% Calculation of the inequality constraints for Split 2
Cineq{k} = [into{k}(26).*scl{k}.Var(26)'-83.3784;...
            23.3784 - into{k}(26).*scl{k}.Var(26)'].*scl{k}.InEq;

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

%% Inequalities in Split 3
k = 7;
% Calculation of the inequality constraints for Split 3
Cineq{k} = [into{k}(26).*scl{k}.Var(26)'-99;...
            0.5 - into{k}(26).*scl{k}.Var(26)'].*scl{k}.InEq;

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

%% Inequalities in Heat Exchanger 8
k = 9;
% Calculation of the inequality constraints for Heat Exchanger 8
Cineq{k} = [into{k}(9).*scl{k}.Var(9)'-17.54;...
            9.54 - 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 8
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);

%% Inequalities in Heat Exchanger 9
k = 11;
% Calculation of the inequality constraints for Heat Exchanger 9
Cineq{k} = [into{k}(9).*scl{k}.Var(9)'-0.458;...
            -7.542 - 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 9
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);

%% Inequalities in Heat Exchanger 10
k = 15;
% Calculation of the inequality constraints for Heat Exchanger 10
Cineq{k} = [into{k}(9).*scl{k}.Var(9)'+9.1;...
            -25.1 - 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 10
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);

