Vector parameters in SciLab Unit Operation?

Moderator: jasper

Vector parameters in SciLab Unit Operation?

Postby cocofan » 09 May 2020, 18:32

My question is regarding the input/output parameters in COCO custom models, e.g., SciLab or MATLAB CAPE-OPEN Unit Operations. Is there any way to define a parameter as a vector with its size being the number of components? For example, in a membrane module you may need to ask the user to enter permeance, which is defined per component and you don't know in advance how many components exist (so you don't know how many scalar parameters you should define).
As an alternative, is it possible to define such parameters as a new property in the thermo package (so it is automatically populated for every component)?
Any solution or workaround to this issue would be appreciated!
cocofan
 
Posts: 11
Joined: 24 March 2020, 02:36

Re: Vector parameters in SciLab Unit Operation?

Postby jasper » 10 May 2020, 08:49

The parameters that are exposed by a property package, that is up to the property package. Apart from that parameter support for property packages is virtually non-existent.

If you want to automatically populate all unit operations of your particular type, I suppose you can have machinery that is specific to your unit operation (perhaps a centrally located data file with data for all compounds?).

The Scilab CAPE-OPEN unit operation currently does not allow for exposing array parameters. Can you illustrate how you would use such a parameter? Is it just so that the user can change it?
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Vector parameters in SciLab Unit Operation?

Postby cocofan » 10 May 2020, 15:54

Thanks for your response. The few membrane modules I have seen in COCO so far have permeance hard-coded, rather than exposing it as an input parameter. The issue is if I want to make my membrane module generic and usable for any set of components (not known a priori), then I need to leave it to the user to specify the permeance parameters for each component defined in the simulation. A simple workaround is to define more than enough number of scalar parameters like: permeance1, permeance2, etc (attached screenshot). For, say, 4 components, you just set values to the first four and the rest won't be used. But I was looking for a cleaner way.
Code: Select all
//setting permeance parameters in the code
J(1)=getParameter('Permeance1')        //(mol/s m2 Pa)
J(2)=getParameter('Permeance2')        //(mol/s m2 Pa)


I think your solution was, instead of defining input parameters, identify the stream components in the Scilab code (by some builtin function). Then, use the obtained component IDs to read the required data from a databank (all done internally through Scilab).
Attachments
input_param.JPG
input_param.JPG (29.64 KiB) Viewed 10055 times
cocofan
 
Posts: 11
Joined: 24 March 2020, 02:36

Re: Vector parameters in SciLab Unit Operation?

Postby jasper » 11 May 2020, 07:52

The Scilab UO is not really for production and dissemination - it was developed to prototype. As such, its GUI focuses around the script, and not the parameters.

Neverthless, the user can access the script- can you not simply in the top of the script have a dictionary that the user can edit? e.g.

Code: Select all
#Users enter permeances here:
permeance("water")=1.3;
permeance("ethane")=1.2;


and later down in the code something like

Code: Select all
for i=1:size(compNames,2)
   try
      p=permeance(compNames{i});
      //do something
   catch
      error(strcat(["No permeance defined for compound ",compNames{i}]))
   end
end
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Vector parameters in SciLab Unit Operation?

Postby cocofan » 11 May 2020, 19:58

Thanks Jasper. Your solution worked and it is a better approach than defining dozens of scalar parameters. Also, you don't have to worry about the right order of components as they are called by names, rather than index. I just had to change size(compNames,2) to size(compNames,1) as it seems the compounds are stored in a column vector
Code: Select all
for i=1:size(compNames,1)
   try
      p(i)=permeance(compNames(i));  //(mol/s m2 Pa)
      //do something
   catch
      error(strcat(["No permeance defined for compound ",compNames{i}]))
   end
end
cocofan
 
Posts: 11
Joined: 24 March 2020, 02:36

Re: Vector parameters in SciLab Unit Operation?

Postby jasper » 11 May 2020, 20:49

Glad to hear it works.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain


Return to Scilab Unit Operation (AmsterCHEM)

Who is online

Users browsing this forum: No registered users and 0 guests

cron