Using Object Pascal

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

Moderator: jasper

Post Reply
HenkF
Posts: 87
Joined: 24 February 2013, 14:50
Location: Hengelo,NL

Using Object Pascal

Post by HenkF »

Hello!
For I while I have been using COCO now, and I'm quite happy with it, especcialy regarding the freedom of adding my own models. For some simple ones I succeeded in (re)building them, using the Delphi Wizard stuff. E.g. temperature, pressure, overall enthalpy and molar flows, component names all are easily accesible (after some struggle...) However, I also would like to use other properties, available from ICapeThermoMaterialObject.GetProp.

I call it using Delphi like:

procedure TSimplePressureChanger.GetInputData;
var
Visc : OleVariant;
begin
...
InPort := Ports.Items[1];
// synchronize
Inport.SynchronizePortAndConnectedObject;
Visc := Inport.StreamObject.GetProp('viscosity','Vapor',null,'Mixture','');
...
end;

The Visc:= call fails.

I guess few are using Delphi, but if, could someone please tell me how to use the GetProp function call?
Meanwhile I keep digging...

FYI : I tried to use FPC/Lazarus instead of Delphi.
Due to a somewhat different COM/ActiveX calling sequence, I unfortunately didn't succeed.

regards, Henk
ccrause
Posts: 2
Joined: 29 July 2013, 11:50
Location: South Africa
Contact:

Re: Using Object Pascal

Post by ccrause »

Henk,

When I inserted your code for getting viscosity COFE gave the follwoing error:
warning: Material object error in GetProp: no values set for viscosity, phase vapor, CalcType mixture

This means that the simulator did not calculate the property and therefore there isn't a value to return. One should normally first calculate a property and then request the property:

var
phases, props, v: OLEvariant;
visc: double;

begin
// other code

// Calculate & retrieve viscosity
props := VarArrayCreate([0, 0], varOleStr);
phases := VarArrayCreate([0, 0], varOleStr);
props[0] := 'viscosity';
phases[0] := 'vapor';
Inport.StreamObject.CalcProp(props, phases, 'mixture');

v := Inport.StreamObject.GetProp('viscosity', 'vapor', Unassigned, 'mixture', '');
visc := v[0];

Also note that in Delphi you should use the variant function Unassigned, and not Null to work properly with COCO.
HenkF
Posts: 87
Joined: 24 February 2013, 14:50
Location: Hengelo,NL

Re: Using Object Pascal

Post by HenkF »

Hi Christian,
that is really helpfull! Great! I wil go on playing with the suggestions you made.

One question for the moment : what would be the best way to read the moleweights of the components?
It is available as a property, but I have not succeeded in getting proper data out...

Thanks a lot for your support!
regards, Henk
User avatar
jasper
Posts: 1129
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: Using Object Pascal

Post by jasper »

'molecularWeight' is available both as a scalar single-phase mixture property and as a compound constant.
ccrause
Posts: 2
Joined: 29 July 2013, 11:50
Location: South Africa
Contact:

Re: Using Object Pascal

Post by ccrause »

A method to read component molecular weights is implemented in the TCapeUnitPort class to do this:

function TCapeUnitPort.FGetMolecularWeigths: TDoubleDynArray;
var
v: variant;
begin
v := VarArrayCreate([0,0], varOleStr);
v[0] := 'molecularWeight';
v := FConnectedStream.GetComponentConstant(v, Unassigned);
DynArrayFromVariant(pointer(result), v, TypeInfo(TDoubleDynArray));
end;

This retrieves the molecular weights for the component list and then converts the variant array into an array of double.

This code is in the trunc version which you can also view here:
http://sourceforge.net/p/capeopenwizard ... t.pas#l325

The trunc version also contains methods to retrieve properties such as phaseFraction, Mw of a stream, CASr numbers, chemicalFormula in addition to the methods implemented in version 1.
HenkF
Posts: 87
Joined: 24 February 2013, 14:50
Location: Hengelo,NL

Re: Using Object Pascal

Post by HenkF »

Thanks guys for the answers, you made my day!
Henk
User avatar
colancto
Administrateur
Posts: 92
Joined: 23 October 2012, 11:46
Contact:

Re: Using Object Pascal

Post by colancto »

May be worth pointing out that a Unit Operation (hence his developer), when accessing a Material Object linked to one of its inlet Ports, should not expect any property to be there except temperature, pressure, composition and flowrates. For instance one should not assume enthalpy is already there in the MO. To get enthalpy, the MO should first be duplicated and then the property should be calculated on the duplicated MO and subsequently retrieved from it. The CAPE-OPEN contract stipulates that MOs connected to inlet Ports are never modified by the UO. The UO is on the other hand responsible for modifying the MOs connected to outlet Ports.
Post Reply

Return to “COCO (AmsterCHEM)”