Hello, I'd like to ask you something concerning optimization communicating with aspen HYSYS
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jiwon Choi
am 24 Jul. 2020
Beantwortet: Pedro Siscato
am 13 Jun. 2024
Hello, I'm struggling with MATLAB for learning optimization
But it's quite hard to do and need some help with my code.
I've made the code like the follow but MATLAB specified 'Unrecognized function or variable 'x''
So I was trying to use 'global x' before or blank variable.
And as you're expecting, it surely didn't work
Is there anyone who could give me advise for me please?
Thank you for reading my asking
function y = Objective
MyObject=actxserver('Hysys.Application');
% global simcase;
FileNamePath='Test_Compressor stage_simplified';
MySimCase=MyObject.SimulationCases.Open('C:\Users\PSE_7\Desktop\LNG liquefaction sytem\N2 expander cycle\Multi-objective optimization\Aspen HYSYS\Test_Compressor stage_simplified.hsc');
MySimCase.Visible=true; % The case is opened in Aspen HYSYS
MyOperations=MySimCase.Flowsheet.Operations; % Getting data from our simcase operations
MyFlowSheet=MySimCase.get('flowsheet'); %accessing to flowsheet
MyMaterialStreams=MyFlowSheet.get('MaterialStreams'); %accessing to simulated material streams
MyEnergyStreams=MyFlowSheet.get('EnergyStreams'); % Energy streams
MyK1=get(MyOperations,'Item','K-1');
MyK2=get(MyOperations,'Item','K-2');
MyE1=get(MyOperations,'Item','E-1');
MyStreams=MySimCase.Flowsheet.Streams;
MyM0=get(MyStreams,'Item','M0');
MyM1=get(MyStreams,'Item','M1');
MyM2=get(MyStreams,'Item','M2');
MyM3=get(MyStreams,'Item','M3');
MyW_1=get(MyStreams,'Item','W-1');
MyW_2=get(MyStreams,'Item','W-2');
MyQ_1=get(MyStreams,'Item','Q-1');
MyK1_Energy = MyK1.EnergyValue
MyK2_Energy = MyK2.EnergyValue
lb = [107];
ub = [1000];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [150];
nonlincon = @GA_Con_Comps;
% opts = optimoptions('ga','Display','iter','Algorithm','interior-point');
MyM1.PressureValue = x;
if MyM2.TemperatureValue < 30
MyM3.TemperatureValue = MyM2.TemperatureValue;
else
MyM3.TemperatureValue = 30;
end
Objective = MyK1_Energy + MyK2_Energy
x = ga(Objective,1,A,b,Aeq,beq,lb,ub,nonlincon,opts);
disp(x)
disp(['Final objective:' num2str(Objective(x))])
end
0 Kommentare
Akzeptierte Antwort
Mario Malic
am 26 Jul. 2020
Bearbeitet: Mario Malic
am 26 Jul. 2020
I did something similar, you should put all this code related to Hysys into your function 'Objective', and then call it as an anonymous function.
[x, fval] = ga(@(x)Objective(x),1,A,b,Aeq,beq,lb,ub,nonlincon,opts);
You don't have to have declared x variable for ga.
function fobj = Objective(x)
% Hysis code here
% Send x into simulation
% Get value that you want to optimize into fobj
fobj = MyK1_Energy + MyK2_Energy;
end
13 Kommentare
Md Nur Islam Sarker Nayan
am 27 Mai 2021
@Jiwon Choi Thank you for your reply. I will try to solve the problem.
Weitere Antworten (1)
Pedro Siscato
am 13 Jun. 2024
I'm trying optimizing the reflux ratio of a column. But I don't know how change the value in Hysis through MATLab. Someone can help me?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!