COM CAPE-OPEN Wizard GetOverallPropery()

COM CAPE-OPEN Wizard GetOverallPropery()

Postby greTol » 14 July 2015, 15:27

Hello again,

I used the COM CAPE-OPEN Wizard 2.0 to generate a unit operation framework.
Classes for parameters, ports, material etc. are therefore automatically generated.

1. There is a typo in the "material" classes:
It reads "Propery" instead of "Property", e.g. "GetOverallPropery()". This is sometimes confusing when not using autocompletion all the time ;-)

2. I'm still failing to get properties out of the material object. Here some code of my calculate() function, where I want to get the pressure of an inlet:
Code: Select all
COMSmartPtr<MaterialPort> aPort = (MaterialPort*)(Port*)portCollection.items[0];
Material material = aPort->GetMaterial();
CVariant value = material->GetOverallPropery(L"pressure", NULL, false);
//check count
if (value.GetCount() != 1){
   SetError(L"Invalid value for pressure from material object: scalar expected", L"ICapeUnit", L"Calculate");
   return ECapeUnknownHR;
}


In this code value.GetCount() always returns 0 and the program stops. I debug mode I get errors like 'try to avoid this, this is expensive' when I assign the return value of "GetOverallPropery()" to the variable "value".
The "default" wizard implementation is used:
Code: Select all
CVariant GetOverallPropery(BSTR name,BSTR basis,bool isSpecialProp) override {
   CVariant res;
   HRESULT hr=mat->GetOverallProp(name,basis,res.OutputArgument());
   if (FAILED(hr)) throw COException(CO_Error(mat,hr));
   return res;
}

When I try to "convince" the variable "value" to be an array with size 1 representing a single double to obtain the pressure, I get something like minus infinity and not the actual value that should be 100000 [Pa] (the pressure is defined in the inlet stream in the flowsheet).

What do I have to do here, what is wrong with my approach?
greTol
 
Posts: 20
Joined: 26 August 2013, 14:45

Re: COM CAPE-OPEN Wizard GetOverallPropery()

Postby jasper » 14 July 2015, 15:41

1) Thank you - I corrected the typo. You can do the same in your code (find/replace in files, I counted 7 occurrences)

2) please pass true for the last argument: special properties are pressure, temperature, fraction, phaseFraction, flow, totalFlow. Which PME is this? Are you using thermo 1.0 or thermo 1.1? (the Material.h wrapper simply forwards it to the Material 1.0 or Material 1.1 implementation)

"try to avoid this" is an assert statement in the copy constructor and assignment operator of a CVariant. By the looks of your code that assert does not fire from within your routine. When it will use the copy constructor instead of move semantics (which should be used, much cheaper) is a bit tricky. Take the following example:

Code: Select all
CVariant v;
v=SomeFuncion();


where SomeFunction returns a CVariant. Here the assignment will likely be used (and the assert will fire). Where as this, apparently similar code,

Code: Select all
CVariant v=SomeFuncion();


allows the C++ compiler to utilize return value optimizion or use the move constructor.

If your problem persists, send me the code and I will have a look.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: COM CAPE-OPEN Wizard GetOverallPropery()

Postby greTol » 14 July 2015, 16:14

I corrected the special property argument in my code.
So far, I thought temperature, flow and pressure are quite common properties. That's why I set that special parameter to 'false' ;-)
The other reason: I use COCO/COFE for testing and expected it to use "Material11". There the 'special property' parameter is not used.

The problem persists and I send you the code.
greTol
 
Posts: 20
Joined: 26 August 2013, 14:45

Re: COM CAPE-OPEN Wizard GetOverallPropery()

Postby jasper » 14 July 2015, 17:44

There were several issues with the code. I returned some corrections via e-mail. Let me know if the problem persists.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: COM CAPE-OPEN Wizard GetOverallPropery()

Postby greTol » 15 July 2015, 12:07

Great, now it works!
My main problem was the missing "CheckArray" call. Without that, the count was not initialized and GetCount() always returned 0.
Here comes the corrected code snippet for the interested reader:
Code: Select all
    CBStrConst bstrPressure(L"pressure");
    wstring error;
    COMSmartPtr<MaterialPort> aPort = (MaterialPort*)(Port*)portCollection.items[0];
    Material material = aPort->GetMaterial();
    CVariant value = material->GetOverallPropery(bstrPressure, NULL, false);
    if (!value.CheckArray(VT_R8,error)) {
       throw COException(L"Invalid value for pressure: "+error);
    }
    //check count
    if (value.GetCount() != 1){
       throw COException(L"Invalid values for pressure from material object: scalar expected");
    }
greTol
 
Posts: 20
Joined: 26 August 2013, 14:45

Re: COM CAPE-OPEN Wizard GetOverallPropery()

Postby bcbooo » 16 July 2015, 03:00

greTol you'd better understand the "MixerSplitter" Unit Operation firstly, it's good for your creation of new modules.
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China


Return to Unit Operations

Who is online

Users browsing this forum: No registered users and 1 guest

cron