• Nenhum resultado encontrado

Comandos no Matlab®

%Conectando o Matlab® com o arquivo aberto em Aspen Hysys®

%As funções ‘hyconnect’, ‘hysys.Activedocument’ e ‘hyCase.Flowsheet’ foram obtidas a partir da biblioteca Hysislib disponibilizada por Olaf Trygve Berglihn em http://www.pvv.org/~olafb/hysyslib.

hysys = hyconnect;

hyCase = hysys.Activedocument; f=hyCase.Flowsheet;

%Definindo os valores iniciais para a otimização a partir dos valores atuais no modelo x0=zeros(3,1);

x0(1)=f.Operations.Item('SET-1').MultiplierValue;

x0(2)=f.MaterialStreams.Item('4_vsat').TemperatureValue; x0(3)=f.MaterialStreams.Item('8').TemperatureValue; %Definindo limites inferiores e superiores para a otimização lb=[ 0.2 35 -70]; ub=[ 0.9 100 -9];

%Configurando as opções da função de otimização

options = optimset ('Algorithm', 'interior-point', 'TolFun', 1e-6, 'DiffMinChange', 1e-1, 'MaxFunEval', 1000,'Display', 'iter','TypicalX', x0);

%Comando de otimização a partir da função objetivo, limites, restrições e opções definidos COP = fmincon(@objective,x0,[],[],[],[],lb,ub,@constr,options)

Funções

Função Objetivo – Maximização de COP function COP=objective(x)

%Calcula o COP com os valores atualizados hysys = hyconnect; hyCase = hysys.Activedocument; f=hyCase.Flowsheet; sol=hyCase.Solver; sol.CanSolve =0; ER = x(1); T4vsat=x(2); T8 = x(3);

f.Operations.Item('SET-1').MultiplierValue=ER;%1-Razão de expansão;

f.MaterialStreams.Item('4_vsat').TemperatureValue=T4vsat;%Temperatur a em 4_vsat;

f.MaterialStreams.Item('8').TemperatureValue=T8;%Temperatura em 8;

sol.CanSolve = 1;

COP=-(f.EnergyStreams.Item('COP_evap').HeatFlowValue)*3600; end

Função de restrições – Maximização de COP

function [C, Ceq] = constr(x) hysys = hyconnect; hyCase = hysys.Activedocument; f=hyCase.Flowsheet; sol=hyCase.Solver; sol.CanSolve =0; ER = x(1); T4vsat=x(2); T8 = x(3);

f.Operations.Item('SET-1').MultiplierValue=ER;%1-Razão de expansão;

f.MaterialStreams.Item('4_vsat').TemperatureValue=T4vsat;%Temperatur a em 4_vsat;

f.MaterialStreams.Item('8').TemperatureValue=T8;%Temperatura em 8;

dTmin = 4.999;

% Nonlinear equality constraints Ceq = [];

% Nonlinear inequality constraints C=zeros(2,1);

C(1) = dTmin-f.Operations.Item('Evap').MinimumApproachValue; C(2) = dTmin-f.Operations.Item('Cond').MinimumApproachValue; end

Função Objetivo – Minimização de custo function cAnual = optcostprfs(x)

% Otimiza a ER e as temperaturas do ciclo com compressor parafuso para % custo mínimo hysys = hyconnect; hyCase = hysys.Activedocument; f=hyCase.Flowsheet; sol=hyCase.Solver; sol.CanSolve = 0;

ER = x(1); T4vsat = x(2); T8 = x(3);

f.Operations.Item('SET-1').MultiplierValue = ER;

f.MaterialStreams.Item('4_vsat').TemperatureValue=T4vsat; f.MaterialStreams.Item('8').TemperatureValue=T8;

sol.CanSolve = 1;

UA=[f.Operations.Item('Evap').UAValue,f .Operations.Item('Cond').UAValue];

U = 0.5; A= UA/U;

cHX = zeros(2,1);

cHX(1)=(1.218*(exp(-0.9816+0.083*log(A(1)*10.76))) .*(0.7771+0.04981 *log(A(1)*10.76)) .*(0.8193+0.15984*log(A(1)*10.76)).* (exp(8.821-0.30863* log(A(1)*10.76)+ 0.0681*(log(A(1)*10.76))^2)))*2*(537.5/521.9);

% custo condensador FTVI

cHX(2)=(1.218*(exp(-0.9816+0.083*log(A(2)*10.76))) .*(0.7771+0.04981 *log(A(2)*10.76)) .*(0.8193+0.15984*log(A(2)*10.76)).* (exp(8.821-0.30863* log(A(2)*10.76)+ 0.0681*(log(A(2)*10.76))^2)))*2*(537.5/521.9);

%Horas de funcionamento por ano hour = 24*365;

%Custo eletricidade $/kWh realdolar=0.32;

elun =(175.48/1000)* realdolar; %Custo consumo eletricidade

w1= f.EnergyStreams.Item('W_comp1').HeatFlowValue; w2= f.EnergyStreams.Item('W_comp2').HeatFlowValue; cEl = hour*elun*(w1+w2); %Custo compressores cC=(1810*((w1+w2)*1.34)^0.71)*1.3*(537.5/521.9);

%massa Flash

v9 = f.MaterialStreams.Item('9').ActualVolumeFlowValue; %m³/s

ro7 = f.MaterialStreams.Item('7').MassDensityValue; ro9 = f.MaterialStreams.Item('9').MassDensityValue; aflash = ((v9*35.315)/(0.14*((ro7/ro9)-1)^0.5)); dflash = (aflash*4/pi)^0.5; mflash=(pi*3*dflash^2+2*aflash)*(0.3048^2)*7850*0.00635; %Custo Flash cFlash =(11600+34*mflash^0.85)*2.8 *(537.5/532.9); %Custo Valvulas m5 = f.MaterialStreams.Item('5').MassFlowValue; m8 = f.MaterialStreams.Item('8').MassFlowValue; cValv = zeros(2,1); cValv(1) =114.5*m5*2; cValv(2) =114.5*m8*2; % Custo ambiental

CO2eq = 0.0817;

cCO2 = 38.59/(2490)* realdolar; cEnv = CO2eq*hour*(w1+w2)*cCO2;

%Cálculo do valor anual ($) int = 0.14; % taxa de juros anual nutil = 15; %vida útil

CRF = (int*(1+int)^nutil)/((1+int)^nutil -1); %conversão valor atual para valor anual

phi = 1.06; %taxa de manutenção cAnual

=(cEl+cEnv+CRF*phi*(cHX(1)+cHX(2)+cC+cFlash+cValv(1)+cValv(2)));

Função de restrições – Minimização de custo function [ C, Ceq] = costconstr(x) hysys = hyconnect; hyCase = hysys.Activedocument; f=hyCase.Flowsheet; sol=hyCase.Solver;

sol.CanSolve = 0; ER = x(1); T4vsat = x(2); T8 = x(3);

f.Operations.Item('SET-1').MultiplierValue = ER;

f.MaterialStreams.Item('4_vsat').TemperatureValue=T4vsat; f.MaterialStreams.Item('8').TemperatureValue=T8; sol.CanSolve = 1; dTmin = 0; Ceq = []; C = zeros (3,1);

C(1)=dTmin-f.Operations.Item('Evap').MinimumApproachValue; C(2)=dTmin-f.Operations.Item('Cond').MinimumApproachValue;

C(3) = f.MaterialStreams.Item('Water_out').TemperatureValue - f.MaterialStreams.Item('4_vsat').TemperatureValue;

end

Função objetivo – Minimização de custo alterando a composição function cAnual = optcostcomp_prfs24(x)

hysys = hyconnect; hyCase = hysys.Activedocument; f=hyCase.Flowsheet; sol=hyCase.Solver; sol.CanSolve = 0; k = zeros(5,1); ER = x(1); T4vsat = x(2); T8 = x(3); c1 = x(4); c2 = x(5);

f.MaterialStreams.Item('4_vsat').TemperatureValue=T4vsat; f.MaterialStreams.Item('8').TemperatureValue=T8;

k(1) = c1; k(5) = c2;

%Colocando a nova composição no modelo

formatSpec =' Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.0" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.1" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.2" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.3" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message

"FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.4" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n';

fid = fopen('massflow.scp','wt'); fprintf(fid,formatSpec,k);

hyCase.Application.PlayScript([pwd,'\massflow.SCP']);

%Chama macro gravada em HYSYS (copref_VCC) para copiar a nova composição

%para as correntes desejadas

hyCase.Application.PlayScript([pwd,'\copref_VCC.SCP']); %solver

sol.CanSolve = 1;

%Liga e desliga set de ER

hyCase.Application.PlayScript([pwd,'\wdw.SCP']); %Liga e desliga simulação

hyCase.Application.PlayScript([pwd,'\on.SCP']); % fecha arquivos abertos

fopen('all'); fclose('all');

sol.CanSolve = 1;

UA=[f.Operations.Item('Evap').UAValue,f .Operations.Item('Cond').UAValue];

U = 0.5; A= UA/U;

cHX = zeros(2,1);

% custo evaporador FTVI

cHX(1)=(1.218*(exp(-0.9816+0.083*log(A(1)*10.76))) .*(0.7771+0.04981 *log(A(1)*10.76)) .*(0.8193+0.15984*log(A(1)*10.76)).* (exp(8.821-0.30863* log(A(1)*10.76)+ 0.0681*(log(A(1)*10.76))^2)))*2*(537.5/521.9);

% custo condensador FTVI

cHX(2)=(1.218*(exp(-0.9816+0.083*log(A(2)*10.76))) .*(0.7771+0.04981 *log(A(2)*10.76)) .*(0.8193+0.15984*log(A(2)*10.76)).* (exp(8.821-0.30863* log(A(2)*10.76)+ 0.0681*(log(A(2)*10.76))^2)))*2*(537.5/521.9);

%Horas de funcionamento por ano hour = 24*365;

%Custo eletricidade $/kWh realdolar=0.32;

%Custo consumo eletricidade

w1= f.EnergyStreams.Item('W_comp1').HeatFlowValue; w2= f.EnergyStreams.Item('W_comp2').HeatFlowValue; cEl = hour*elun*(w1+w2); %Custo compressores cC=(1810*((w1+w2)*1.34)^0.71)*1.3*(537.5/521.9); %massa Flash v9 = f.MaterialStreams.Item('9').ActualVolumeFlowValue; %m³/s

ro7 = f.MaterialStreams.Item('7').MassDensityValue; ro9 = f.MaterialStreams.Item('9').MassDensityValue; aflash = ((v9*35.315)/(0.14*((ro7/ro9)-1)^0.5)); dflash = (aflash*4/pi)^0.5; mflash=(pi*3*dflash^2+2*aflash)*(0.3048^2)*7850*0.00635; %Custo Flash cFlash =(11600+34*mflash^0.85)*2.8 *(537.5/532.9);

%Custo Valvulas m5 = f.MaterialStreams.Item('5').MassFlowValue; m8 = f.MaterialStreams.Item('8').MassFlowValue; cValv = zeros(2,1); cValv(1) =114.5*m5*2; cValv(2) =114.5*m8*2; % Custo ambiental CO2eq = 0.0817; cCO2 = 38.59/(2490)* realdolar; cEnv = CO2eq*hour*(w1+w2)*cCO2;

%Cálculo do valor anual ($) int = 0.14; % taxa de juros anual nutil = 15; %vida útil em anos

CRF = (int*(1+int)^nutil)/((1+int)^nutil -1); %conversão valor atual para valor anual

phi = 1.06; %taxa de manutenção cAnual

Função de restrições - Minimização de custo alterando a composição function [ C, Ceq] = costconstrcomp(x)

hysys = hyconnect; hyCase = hysys.Activedocument; f=hyCase.Flowsheet; sol=hyCase.Solver; sol.CanSolve = 0; k = zeros(5,1); ER = x(1); T4vsat = x(2); T8 = x(3); c1 = x(4); c2 = x(5);

f.MaterialStreams.Item('4_vsat').TemperatureValue=T4vsat; f.MaterialStreams.Item('8').TemperatureValue=T8;

k(1)=c1; k(5)=c2;

%Colocando a nova composição no modelo

formatSpec =' Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.0" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.1" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.2" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message "FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.3" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n Message

"FlowSht.1/StreamObject.400(Ref)" "view"\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 0.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":Enum.590" 2.000000000000e+000\n Specify "FlowSht.1/StreamObject.400(Ref)" ":CompMassFlow.530.0.4" %0.4e\n Message "FlowSht.1/StreamObject.400(Ref)" "AcceptComp"\n SpecWhileSolving Message "FlowSht.1/StreamObject.400(Ref)" "CloseView"\n\n'; fid = fopen('massflow.scp','wt'); fprintf(fid,formatSpec,k); hyCase.Application.PlayScript([pwd,'\massflow.SCP']); hyCase.Application.PlayScript([pwd,'\copref_VCC.SCP']); %solver sol.CanSolve = 1;

%Liga e desliga set de ER

hyCase.Application.PlayScript([pwd,'\wdw.SCP']); %Liga e desliga simulação

hyCase.Application.PlayScript([pwd,'\on.SCP']); % fecha arquivos abertos

fopen('all'); fclose('all');

sol.CanSolve = 1;

dTmin = 0;

Ceq = [];

C = zeros (3,1);

C(1)=dTmin-f.Operations.Item('Evap').MinimumApproachValue; C(2)=dTmin-f.Operations.Item('Cond').MinimumApproachValue;

C(3) = f.MaterialStreams.Item('Water_out').TemperatureValue - f.MaterialStreams.Item('4_vsat').TemperatureValue;