Add new Material Port after UO loaded into simulator

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

Moderator: jasper

Add new Material Port after UO loaded into simulator

Postby bcbooo » 09 March 2015, 03:13

For a "Mixer" unit operation block, I create one inlet port and one outlet port on it's initialization. When an inlet stream is connected to it's inlet port, I will create a new inlet port and add to the "port collection", then the UO will have two inlet ports and one outlet port. More inlet ports will be created and added while inlet streams connected.

I find that Simulator only refreshes ports connection status when UO intialized or Edited, whether COFE or Aspen Plus. So after new port created and added to port collection, Simulator doesn't know this change and still has the same inlet ports count as before, unless click on the UO icon to open it's Edit Window by hand.

So I wonder are there any other strategies to refresh ports status after new port created?
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Add new Material Port after UO loaded into simulator

Postby jasper » 09 March 2015, 07:25

The port and parameter collections can only be changed during Edit and at instantiation. So the strategy for changing the number of ports upon connection of a port (or for example upon changing a parameter "number of inlets") is not recommended. I am afraid you will need to depend on the user to enter the unit's Edit method. Alternatively, just create your unit with sufficient (10?) ports, and allow that ports remain unconnected. This strategy is ok, not all ports need to be connected to run. It is up to Validate to decide whether unconnected ports are ok or not.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Add new Material Port after UO loaded into simulator

Postby bcbooo » 09 March 2015, 07:44

Thank you Jasper for your reply.

Creating a Unit Operation Block with sufficient ports is not rational for users, on one hand UO can't decide how many ports is sufficient, maybe 10, 20, even 100 more; On the other hand, especially in Aspen Plus' environment, when user connects the stream with port, Aspen Plus will popup a dialog with the list of ports for the user to select which port to be connected, too many ports pre-assigned will make user puzzled.

So I advise simulators to modify some strategies, for example, when stream is connected to a port, the simulator will refresh the port collection to get ports count and connection status.

Thank you for your consideration.
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Add new Material Port after UO loaded into simulator

Postby jasper » 09 March 2015, 08:04

It is considered an unreasonable overhead to require simulators to re-evaluate the collection of ports and parameters upon any change in port connection, parameter value (e.g. parameter "number of inlet ports") or operating condition. So the unit operation specification clearly states that the simulator only has the requirement to re-evaluate the port collection upon initialization, loading and editing. The parameter common interface specification makes a similar statement about the parameter collection.

CAPE-OPEN remains an interaction between PMEs and PMCs, and both will have to adhere to the agreements for the interaction to work. The agreement in this case is that it is not required for the PME to continuously re-evaluate the port collection upon any change.

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

Re: Add new Material Port after UO loaded into simulator

Postby bcbooo » 21 March 2015, 02:14

I finished a "Duplicator" Unit Operation that works well at Aspen Plus,but not at COFE.

The core codes like following:

Code: Select all
OLECHAR buf[128];
swprintf_s(buf,128,L"NewOutletPort-%d",index++);
portCollection->AddItem(CreateMaterialPort(buf,L"New Material Port",CAPE_OUTLET));


These codes will be called in the MaterialPort's "Connect" function,used to add a new outlet port to the Unit Operation.There will be one inlet port and one outlet port when UO initilized.When I have connected one inlet port and two outlet ports, the "Ports Dialog" shows like “Untitled.jpg”, which is normal and right.

But when I run the process, error occurs like following:

Code: Select all
error: port NewOutletPort-2 not found on unit CPP Mixer Splitter Example_1
incomplete specification for input stream 2


This case will not happen at Aspen Plus.Of course, CAPE-OPEN doesn't allow to add new port to UO after created, maybe COFE doesn't consider this point. But for the flexible usage of UO, I hope you could fix this flaw.

"Dynamic Add New Port.zip" is the sample source code, many extra codes are deleted and only usable codes remained.
Attachments
Dynamic Add New Port.zip
(78.54 KiB) Downloaded 776 times
Untitled.jpg
Untitled.jpg (114.95 KiB) Viewed 26831 times
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Add new Material Port after UO loaded into simulator

Postby jasper » 21 March 2015, 09:19

It is ok to add a new port after a unit operation has been created. But not during Correct. You should do so during ICapeUtilities::Edit.

The new clarifications document is in the process of being reviewed. The text regarding this subject

2.7 Port Collection
Issue: It is not reasonable to assume the PME must re-evaluate the Port Collection each time the value of a Parameter changes or a Port gets disconnected.
Clarification: Therefore the Unit Operation must keep the Port Collection constant (order, name, type, direction of Ports need to remain the same) after changing a Parameter value or after connecting or disconnecting a Port. The only places suitable for changing the Port Collection is during Edit and Initialize. So the PME should re-evaluate the Port Collection after Edit is completed. The PME should exercise caution regarding change of names for Ports: equivalence of Ports before and after Edit can be asserted through the objects still connected to the Ports. During Edit, the PMC should retain connections of Ports that are not deleted.


Note that this text is not final yet, but these are:

UC-002 SPECIFY MATERIAL CONNECTION OF UNIT
UC-003 SPECIFY ENERGY CONNECTION OF UNIT
UC-004 SPECIFY INFORMATION CONNECTION OF UNIT
UC-008 CONFIGURE UNIT
UC-014 SET UNIT SPECIFIC DATA (*)
UC-015 CHECK UNIT

Specifically, (*) is the case where the port collection may have changed. It is invoked from UC-0015, but not from UC-002 - UC-008.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Add new Material Port after UO loaded into simulator

Postby bcbooo » 23 March 2015, 00:40

Sorry Jasper, you may misunderstand my point. There is a bug in COFE, when the dynamic created outlet port is connected with a stream, the "ports dialog" considers the stream as a outlet stream, but the bottom tip window considers the stream as a inlet stream, it conflicts.

I surmise COFE doesn't take the dynamic port method into consideration, so that the bug occurs. I hope you could fix this problem. Thanks!
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Add new Material Port after UO loaded into simulator

Postby jasper » 23 March 2015, 08:25

I do not think there is a bug in COFE. I think you are not implementing persistence.

That what happens is; you hit Solve. COFE creates a new thread, saves your unit in the original thread (if you implement save), creates your unit in the new thread, loads it (if you implement load) and tries to connect the ports that were connected in the original unit.

If the copied unit does not contain the port, that will result in that message.

You can easily verify my hypothesis: Edit, Preferences, turn off "Allow solving flowsheet in a separate thread". Now you are running the same unit as the one in the foreground thread. If this runs ok, please check if you have implemented persistence, and if persistence properly restores the ports.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Add new Material Port after UO loaded into simulator

Postby bcbooo » 25 March 2015, 00:35

:lol:
Jasper you are right, I forgot the persistence. Sorry for disturbing.
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Add new Material Port after UO loaded into simulator

Postby jasper » 25 March 2015, 08:05

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


Return to COCO (AmsterCHEM)

Who is online

Users browsing this forum: No registered users and 2 guests

cron