[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 483: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
CAPE-OPEN • View topic - Connecting to COCO from MATLAB

Connecting to COCO from MATLAB

Discusses use of COCO, the process simulation and modelling software suite from AmsterCHEM, downloadable from http://www.cocosimulator.org

Moderator: jasper

Connecting to COCO from MATLAB

Postby samvithvr » 21 February 2018, 19:28

Here is an email exchange I had with Jasper regarding the subject topic. It will be useful to someone who is treading the same path as mine.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello Jasper,

I wish to:
1. automate some COCO operations through MATLAB (eg - automatically calculate a flowsheet by cycling through a matrix of values for certain variables) and
2. Access certain parameters (eg: flow, composition, etc) from within MATLAB.

I have been through your site and forums in great detail. I have tried to emulate instructions here https://www.cocosimulator.org/index_hel ... eation.htm but I seem to hit a wall after inputting this command: a=actxserver('COCO_COFE.Document') in MATLAB. I cannot seem to access any flowsheet in the directory. See image.

Please help me understand what to do next.

Thanks very much,
Samvith
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dear Samvith,

COCO's type lib is not baked into COCO, Matlab does not like that:

https://es.mathworks.com/matlabcentral/ ... com-object

Even if this were so, the CAPE-OPEN interfaces are exposed only as early binding, something that Matlab does not like either. You can still access from Matlab the functions described here:

https://www.cocosimulator.org/index_hel ... rfaces.htm

and see sub topics. But you would have to do so via invoke:

a=actxserver('COCO_COFE.Document')
a.invoke("ShowMainConfiguration")

All of this is not of much use, as without access to the CAPE-OPEN interfaces there is no way to get to thermo property calculations, to stream content, to unit operation parameters etc, as far as I can tell. This is because Matlab does not support early binding on COM objects, and it is hard, if not impossible, to implement CAPE-OPEN interfaces via late binding (IDispatch) due to some restrictions in CAPE-OPEN itself (technical background, see here: https://www.cocosimulator.org/downloads ... t_2014.pdf, slide 10 an on)

Here's possible work-arounds:

1) wait until Matlab supports early binding (probably not an option)
2) wait until COFE 4, which might introduce more elegant early binding interfaces to circumvent this (probably not an option)
3) use an external scripting tool that does support early binding (which excludes vbscript) and invoke that from Matlab, or
4) do it all from Matlab, but via a different route. This is the approach I would look into:

Flowsheet fsd files are zip files. In there you will find an XML file called flowsheet.xml. You can parse (and change and rewrite) the xml from matlab: https://es.mathworks.com/help/matlab/ref/xmlread.html. Do do so you must unzip (and re-zip) the file, https://es.mathworks.com/help/matlab/ref/zip.html. Now all you are short on is to run the file: https://www.cocosimulator.org/index_hel ... estand.htm.

Hope that helps.

Best wishes,

Jasper
Attachments
error.PNG
Screenshot
error.PNG (9.3 KiB) Viewed 21828 times
samvithvr
 
Posts: 2
Joined: 01 February 2018, 22:03

Re: Connecting to COCO from MATLAB

Postby jasper » 22 February 2018, 09:12

Did it work out?
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Connecting to COCO from MATLAB

Postby samvithvr » 26 February 2018, 07:53

Yes. Thanks again Jasper
samvithvr
 
Posts: 2
Joined: 01 February 2018, 22:03

Re: Connecting to COCO from MATLAB

Postby jasper » 26 February 2018, 08:15

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

Re: Connecting to COCO from MATLAB

Postby cocofan » 10 April 2020, 09:52

Thanks @jasper and @samvithvr for sharing this. So, as I understand, it is not even possible to pull (get) information from COCO directly into MATLAB using ActiveX(?).
Also, I followed the xml approach proposed by @jasper and built a sample case where Octave (or MATLAB) is used to optimize a simple process (the optimization doesn't make much sense physically as the compressor work is being maximized :) )
I thought it'd be good to share it in the forum. The only major problem here (specially for optimization work) is the computational speed, which is hugely affected by frequent zipping/unzipping of the xml. I'm not sure if there is a better way to code this. Or maybe instead of working with xmls, putting Excel between Octave and COCO would result in faster data exchanges; or a different way to zip/upzip(?) Any comments would be appreciated!
Attachments
COCO_Octave_or_MATLAB.zip
Link between Octave (or MATLAB) and COCO through xml
(20.08 KiB) Downloaded 975 times
cocofan
 
Posts: 11
Joined: 24 March 2020, 02:36

Re: Connecting to COCO from MATLAB

Postby jasper » 10 April 2020, 11:32

User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Connecting to COCO from MATLAB

Postby cocofan » 12 April 2020, 05:40

Thanks a lot @jasper for your prompt reply and writing that piece of Python code for me. You were right about the speed bottleneck, which is Cofestand, rather than the zip/unzip process (the cpu time Cofestand takes for this particular example is an order of magnitude higher than that for zipping or unzipping). In clock time, solving the simulation through Cofestand takes about 8 s, whereas solving it from the COCO environment takes only less than a second. It'd be great if at least solveflowsheet could be called right from MATLAB through ActiveX (which I suppose would have much less overhead than Cofestand?), removing the need to use Cofestand.

Also, regarding sys_cmd_unzip in my code, I was not using it and should have removed it for more clarity. I had tried it to see if 7z could be a faster alternative to the builtin Octave zip/unzip. But, it turns out this is not the bottleneck here.
cocofan
 
Posts: 11
Joined: 24 March 2020, 02:36

Re: Connecting to COCO from MATLAB

Postby jasper » 12 April 2020, 11:42

Given the availability to access python directly from Matlab, give this route a try?

https://www.oreilly.com/library/view/py ... 03s03.html

Python should be able to access COFE via early binding.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Connecting to COCO from MATLAB

Postby jasper » 12 April 2020, 11:43

8 seconds?? That's a lot - I do not see that kind of latency. Could it be that these 8 seconds are eaten by a virus scanner while loading COFEStand64.exe?
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Connecting to COCO from MATLAB

Postby jasper » 12 April 2020, 11:44

.. and you see 8 seconds on each turn-around, or just on the first call?
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Next

Return to COCO (AmsterCHEM)

Who is online

Users browsing this forum: No registered users and 5 guests

cron