I have been trying to perform a sensitivity analysis varying two input (Temp & Pperm) in a process engineering software: Aspen Plus. Please find below my best effort about writing the function. The communication appears to be functioning, as evidenced by the successful test in the script but the parameter variation remains unresponsive. Would you please have any suggestion? / more judicious implementation?
function output = myAspenModel2(X)
AspenPath = 'C:\Users\DT6107\Documents\Chap-0 Dynamic modelling of membrane reactors\matlab_aspen_sensitivity\NH3_PEM_COMBO_v7.apwz';
Aspen = actxserver('Apwn.Document.40.0');
Aspen.invoke('InitFromFile2', AspenPath);
Aspen.visible = 1;
temp= X(1,1); %<======== INPUT crash happen when I put the full column
Pperm= X(1,2); %<======== INPUT crash happen when I put the full column
Aspen.Application.Tree.FindNode('\Data\Blocks\HEATER\Input\TEMP').value=temp;
Aspen.Application.Tree.FindNode('\Data\Blocks\B6\Input\P_OUT').value=Pperm;
Run2(Aspen.Engine);
EFF = Aspen.Application.Tree.FindNode('\Data\Flowsheeting Options\Calculator\EFF\Output\READ_VAL\17').value; %<===========OUTPUT calculated
output = EFF;
end
The X_test works correctly when I run the script (cf. infra), and it provides the expected output for the specified parameters. However, unlike the example I’ve been consulting, the parameters I need to vary cannot be written as column vectors using expressions like temp = X(:,1) and Pperm = X(:,2) . In my case, it seems I need to handle these two parameters differently. (I am not sure) or perhaps not the right way to proceed in linking those software
clc;
clear;
uqlab;
ModelOpts.mFile = 'myAspenModel2';
%modelopts.isVectorized = false;
myModel = uq_createModel(ModelOpts);
InputOpts.Marginals(1).Name = 'temp';
InputOpts.Marginals(1).Type = 'Uniform';
InputOpts.Marginals(1).Parameters = [355, 370];
InputOpts.Marginals(2).Name = 'Pperm';
InputOpts.Marginals(2).Type = 'Uniform';
InputOpts.Marginals(2).Parameters = [7, 15];
myInput = uq_createInput(InputOpts);
uq_print(myInput);
uq_display(myInput);
%1. Test the model function with arbitrary values
X_test = [360,10];
output_test=myAspenModel2(X_test);
%disp(['test output for myAspenMOdel with X_test' , num2str(output_test)]);
%Quasi monte carlo method using Sobol's sequence
SobolOpts.Type = 'Sensitivity';
SobolOpts.Method = 'Sobol';
SobolOpts.Sobol.Order = 1; % Only first-order Sobol indices
SobolOpts.Sobol.SampleSize = 10; % Increase sample size for better estimation
SobolOpts.Model = myModel; % Link the model to the sensitivity analysis
SobolAnalysis = uq_createAnalysis(SobolOpts);
uq_print(SobolAnalysis)
uq_display(SobolAnalysis)
SobolAnalysis.Results