I encountered a strange behavior when calling Tea: It provides dirrerent values if I compute one or several properties simultaneously. Here is a "minimal" example (interesting part is the end after #ifdef):
Code: Select all
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr)) messages::get().error("Cannot initialize COM: Error %i", hr);
_mat = NULL;
hr = ::CoCreateInstance(__uuidof(fpCapeOpenCOM),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(ICapeThermoMaterial),
(void**)&_mat);
if (FAILED(hr)) messages::get().error("Cannot instantiate CAPE-OPEN material object: Error %i", hr);
GUID ppmId;
hr = CLSIDFromString(OLESTR("COCO_TEA.PropertyPackManager.1"), (LPCLSID)&ppmId);
//hr = CLSIDFromString(OLESTR("DWSIM.CAPEOPENPropertyPackageManager"), (LPCLSID)&teaId);
if (FAILED(hr)) messages::get().error("Cannot find property package id: Error %i", hr);
hr = ::CoCreateInstance(ppmId,
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(ICapeThermoPropertyPackageManager),
(void**)&_ppManager);
if (FAILED(hr)) messages::get().error("Cannot instantiate CAPE-OPEN property package manager and get interface: Error %i", hr);
/*CComVariant propPackages;
hr = _ppManager->GetPropertyPackageList(&propPackages);
if (FAILED(hr)) messages::get().error("Cannot get property packages list: Error %i", hr);
CComSafeArray <BSTR> propPackagesArray;
propPackagesArray.Attach(propPackages.parray);
messages::get().info("Number of available property packages %i", propPackagesArray.GetCount());
for (int i = 0; i < propPackagesArray.GetCount(); i++){
CComBSTR mElement(propPackagesArray.GetAt(i));
messages::get().info(" ---- (%i): %s", i, _com_util::ConvertBSTRToString(mElement.m_str));
}
propPackagesArray.Detach();*/
hr = _ppManager->GetPropertyPackage(L"Longpipe", (IDispatch**)&_pp);
//hr = _ppManager->GetPropertyPackage(L"RapidDecompression", (IDispatch**)&_pp);
if (FAILED(hr)) messages::get().error("Cannot get property package : Error %i", hr);
hr = _pp->QueryInterface(__uuidof(ICapeThermoMaterialContext), (LPVOID*)&_matContext);
if (FAILED(hr)) messages::get().error("Cannot get material context from property package : Error %i", hr);
hr = _matContext->SetMaterial(_mat);
if (FAILED(hr)) messages::get().error("Cannot set material to material context : Error %i", hr);
hr = _pp->QueryInterface(__uuidof(ICapeThermoPropertyRoutine), (LPVOID*)&_thermoPropRoutine);
if (FAILED(hr)) messages::get().error("Cannot get property routine from property package : Error %i", hr);
//Setting phases
CComSafeArray <BSTR> phases(1);
phases[0] = L"Vapor";
CComVariant phasesVar = phases;
CComSafeArray <int> status(1);
status[0] = CAPE_UNKNOWNPHASESTATUS;
CComVariant statusVar = status;
hr = _mat->SetPresentPhases(phasesVar, statusVar);
if (FAILED(hr)) messages::get().error("Cannot set phase");
//Setting temperature
CComSafeArray <double> currentTArr(1);
CComSafeArray <double> currentPArr(1);
currentTArr[0] = 270;
currentPArr[0] = 1.0e6;
CComVariant currentTVar = currentTArr;
CComVariant currentPVar = currentPArr;
hr = _mat->SetSinglePhaseProp(L"temperature", L"Vapor", NULL, currentTVar);
if (FAILED(hr)) messages::get().error("Cannot set temperature");
hr = _mat->SetSinglePhaseProp(L"pressure", L"Vapor", NULL, currentPVar);
if (FAILED(hr)) messages::get().error("Cannot set pressure");
CComSafeArray <double> fraction(10);
fraction[0] = 0.0137;
fraction[1] = 0.0138;
fraction[2] = 0.8742;
fraction[3] = 0.0697;
fraction[4] = 0.0213;
fraction[5] = 0.003;
fraction[6] = 0.0025;
fraction[7] = 0.0006;
fraction[8] = 0.0003;
fraction[9] = 0.0009;
CComVariant fractionVar = fraction;
hr = _mat->SetSinglePhaseProp(L"fraction", L"Vapor", L"Mole", fractionVar);
if (FAILED(hr)) messages::get().error("Cannot set mole fraction");
#if TEST==1
printf("test1\n");
int nbProps = 5;
CComSafeArray <BSTR> props(nbProps);
props[0] = L"density";
props[1] = L"internalEnergy";
props[2] = L"internalEnergy.Dtemperature";
props[3] = L"internalEnergy.Dpressure";
props[4] = L"molecularWeight";
CComVariant propsVar = props;
#elif TEST==2
printf("test2\n");
int nbProps = 3;
CComSafeArray <BSTR> props(nbProps);
props[0] = L"density";
props[1] = L"internalEnergy";
props[2] = L"molecularWeight";
CComVariant propsVar = props;
#elif TEST==3
printf("test3\n");
int nbProps = 2;
CComSafeArray <BSTR> props(nbProps);
props[0] = L"density";
props[1] = L"internalEnergy";
CComVariant propsVar = props;
#endif
hr = _thermoPropRoutine->CalcSinglePhaseProp(propsVar, L"Vapor");
if (FAILED(hr)) messages::get().error("Cannot compute properties: Error %i",hr);
CComVariant propGet;
CComSafeArray <double> propGetArr;
for (int iProp = 0; iProp < nbProps; iProp++){
hr = _mat->GetSinglePhaseProp(props[iProp], L"Vapor", NULL, &propGet);
if (FAILED(hr)) messages::get().error("Cannot get property %ws", props[iProp]);
propGetArr.Attach(propGet.parray);
printf("Property %ws is %.14e\n",props[iProp],propGetArr[0]);
propGetArr.Detach();
}
_thermoPropRoutine->Release();
_matContext->Release();
_pp->Release();
_ppManager->Release();
_mat->Release();
CoUninitialize();
Code: Select all
test1
Property density is 4.63068260659736e+002
Property internalEnergy is -3.48112448296645e+003
Property internalEnergy.Dtemperature is 2.96241259172201e+001
Property internalEnergy.Dpressure is -1.80752517698902e-004
Property molecularWeight is 1.85132287300110e+001
Code: Select all
test2
Property density is 4.63068260659736e+002
Property internalEnergy is -3.48112533568150e+003
Property molecularWeight is 1.85132287300110e+001
Code: Select all
test3
ERROR : Cannot compute properties: Error -2147220223
ERROR -99
Any idea where it can come from? Is it possible to test multiple properties computation in COFE calculator (I did not find a way).
Thanks