Page 1 of 1

Using Object Pascal

PostPosted: 15 August 2013, 13:35
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

Re: Using Object Pascal

PostPosted: 18 August 2013, 08:59
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.

Re: Using Object Pascal

PostPosted: 21 August 2013, 13:14
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

Re: Using Object Pascal

PostPosted: 21 August 2013, 13:34
by jasper
'molecularWeight' is available both as a scalar single-phase mixture property and as a compound constant.

Re: Using Object Pascal

PostPosted: 21 August 2013, 15:12
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.

Re: Using Object Pascal

PostPosted: 23 August 2013, 07:48
by HenkF
Thanks guys for the answers, you made my day!
Henk

Re: Using Object Pascal

PostPosted: 26 August 2013, 10:41
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.