How to use Aspen Plus - Matlab Link?
Show older comments
Please help me I am new to Matlab and Aspen Plus but have basic knowledge so please guide in detail. Please tell me what steps do I follow to link Aspen file and Matlab.
The Matlab cod file is:
%% Created by Ing. Andrés Felipe Abril. Universidad Nacional de Colombia. Departamento de Ingeniería Química.
%% Linking
Aspen = actxserver('Apwn.Document.36.0'); %34.0 ---> V8.8; 35.0 ---> V9.0; and 36.0 ---> V10.0
[stat,mess]=fileattrib; % get attributes of folder (Necessary to establish the location of the simulation)
Simulation_Name = 'Reactive_Distillation';% Aspeen Plus Simulation Name
Aspen.invoke('InitFromArchive2',[mess.Name '\' Simulation_Name '.bkp']);
Aspen.Visible = 1; % 1 ---> Aspen is Visible; 0 ---> Aspen is open but not visible
Aspen.SuppressDialogs = 1; % Suppress windows dialogs.
Aspen.Engine.Run2(1); % Run the simulation
while Aspen.Engine.IsRunning == 1 % 1 --> If Aspen is running; 0 ---> If Aspen stop.
pause(0.5);
end
%% Example of Application
Reflux_Ratio = [1, 3, 5, 7];
for i = 1:length(Reflux_Ratio)
Aspen.Tree.FindNode("\Data\Blocks\RC-101\Input\BASIS_RR").Value = Reflux_Ratio(i); % Column Reflux
Aspen.Reinit; % Reinit simulation
Aspen.Engine.Run2(1); %Run the simulation. (1) ---> Matlab isnt busy; (0) Matlab is Busy;
time = 1;
while Aspen.Engine.IsRunning == 1 % 1 --> If Aspen is running; 0 ---> If Aspen stop.
pause(0.5);
time = time+1;
if time==15 % Control of simulation time.
Aspen.Engine.Stop;
end
end
Simulation_Convergency = Aspen.Tree.FindNode("\Data\Results Summary\Run-Status\Output\PCESSTAT").Value; % 1 Doesn't Convergence; 0 Converge
if Simulation_Convergency == 0 && time < 10
Duty(i) = Aspen.Tree.FindNode("\Data\Blocks\RC-101\Output\REB_UTL_DUTY").Value; %Duty value of reactive column
else
Duty(i) = inf; % Its Penalized if simulation doesn't converge;
end
end
%% Plotting
figure()
plot(Reflux_Ratio, Duty, 'ok');
Aspen.Close;
Aspen.Quit;
8 Comments
panyawut charoensri
on 16 Apr 2023
Aspen+ V.12
Aspen = actxserver('Apwn.Document.38.0')
alright
MINH
on 9 Aug 2024
when i run my code, which is to link aspen plus and matlab to run a SAA optimazition i get this error : Unrecognized method, property, or field 'Name' for class 'handle'.
Walter Roberson
on 9 Aug 2024
Is the error showing up on the line
Aspen.invoke('InitFromArchive2',[mess.Name '\' Simulation_Name '.bkp']);
??
If so, that would be odd, as mess is an output from fileattrib and that output is a struct rather than a handle.
MINH
on 19 Aug 2024
Moved: Walter Roberson
on 19 Aug 2024
No, it is not from that line of code, it appear, when i try to call out the column diameter value after conducting internal column feature in Aspen Plus, i have switch from the equilibrium to rate-base, and use the column diameter as the input . But when i run my code it always come out with the error i have mentioned. I hope you can help me, sorry for the late reply.
Walter Roberson
on 19 Aug 2024
Sorry, we would need to see your code to have a chance of debugging this.
MINH
on 26 Aug 2024
function [Qc, QR, Tc, TR, purity, Dt,diameter ] = retrieve_results(Aspen)
% Initialize output variables
Qc = NaN;
QR = NaN;
Tc = NaN;
TR = NaN;
purity = NaN;
Dt = NaN;
try
% Retrieve nodes
Qc_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Output\COND_DUTY");
QR_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Output\REB_DUTY");
Tc_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Output\TOP_TEMP");
TR_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Output\REB_TOUT");
purity_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Output\COMPONENT\BENZENE\2");
BOTTOM_TEMP_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Output\BOTTOM_TEMP");
FEED_TEMP_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Output\TEMP\1");
diameter_node = Aspen.Tree.FindNode("\Data\Blocks\C1\Input\CA_DIAM\INT-1\CS-1");
% Debugging: Print node paths
fprintf('Qc_node path: %s\n', Qc_node.Name);
fprintf('QR_node path: %s\n', QR_node.Name);
fprintf('Tc_node path: %s\n', Tc_node.Name);
fprintf('TR_node path: %s\n', TR_node.Name);
fprintf('Purity_node path: %s\n', purity_node.Name);
fprintf('BOTTOM_TEMP_node path: %s\n', BOTTOM_TEMP_node.Name);
fprintf('FEED_TEMP_node path: %s\n', FEED_TEMP_node.Name);
fprintf('Diameter_node path: %s\n', diameter_node.Name);
% Check if nodes exist
if isempty(Qc_node)
error('Node for condenser duty not found');
end
if isempty(QR_node)
error('Node for reboiler duty not found');
end
if isempty(Tc_node)
error('Node for condenser temperature not found');
end
if isempty(TR_node)
error('Node for reboiler temperature not found');
end
if isempty(purity_node)
error('Node for top product purity not found');
end
if isempty(BOTTOM_TEMP_node)
error('Node for bottom temperature not found');
end
if isempty(FEED_TEMP_node)
error('Node for feed temperature not found');
end
if isempty(diameter_node)
error('diameter_node not found');
end
% Retrieve and convert node values
Qc = Qc_node.Value * 0.00419; % Convert to kW
QR = QR_node.Value * 0.00419; % Convert to kW
Tc = Tc_node.Value + 273.15; % Convert to Kelvin
TR = TR_node.Value + 273.15; % Convert to Kelvin
purity = purity_node.Value;
BOTTOM_TEMP = BOTTOM_TEMP_node.Value + 273.15; % Convert to Kelvin
FEED_TEMP = FEED_TEMP_node.Value + 273.15; % Convert to Kelvin
diameter= diameter_node.Value;
MINH
on 26 Aug 2024
I send you my diameter retrival code, if you want more please like the picture of process flowsheet in aspen just let me know
Walter Roberson
on 26 Aug 2024
All of the places that you use the Name property are within a try block. You do not show the catch block code.
You should probably put a breakpoint at the assignment to Qc_node and single-step looking at the results of the FindNode calls -- looking to see what size() and class() is being returned, and testing whether the result has an accessible Name property.
Answers (0)
Categories
Find more on Wind Power in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!