Code: Select all
bool SetSinglePhaseFromFlowTPX(CVariant& compositionL, CVariant& compositionV , double flow, double flowL, double flowV ,double fractionL, double fractionV, double T, double P, wstring& error)
{
HRESULT hr;
int i;
VARIANT empty, v, phaseList, aggState, keyComps;
CVariant scalar;
v.vt = empty.vt = VT_EMPTY;
CBSTR mole(L"mole");
CBSTR phL(L"liquid");
CBSTR phV(L"vapor");
//ignore aggregation states and key compounds
VariantClear(&aggState);
VariantClear(&keyComps);
//check phase list
CVariant phaseLabels; //must be destroyed when done
phaseLabels.MakeArray(2, VT_BSTR);
phaseLabels.SetStringAt(0, phL);
phaseLabels.SetStringAt(1, phV);
if (!phaseLabels.CheckArray(VT_BSTR, error))
{
error = L"Invalid list of possible phases from material object2: " + error;
return false;
}
//set present phases on MO
CVariant phaseStatus;
phaseStatus.MakeArray(phaseLabels.GetCount(), VT_I4);
for (i = 0; i < phaseLabels.GetCount(); i++) phaseStatus.SetLongAt(i, CAPE_ATEQUILIBRIUM); //we have an initial guess // CAPE_UNDEFINED
hr = mat->SetPresentPhases(phaseLabels, phaseStatus);
if (FAILED(hr))
{
error = L"Failed to set list of present phases on material object: " + error;
return false;
}
scalar.MakeArray(1, VT_R8);
//set temperature
scalar.SetDoubleAt(0, T);
hr = mat->SetOverallProp(CBSTR(L"temperature"), NULL, scalar);
if (FAILED(hr))
{
error = L"Failed to set temperature on material object: ";
error += CO_Error(mat, hr);
return false;
}
//set pressure
scalar.SetDoubleAt(0, P);
hr = mat->SetOverallProp(CBSTR(L"pressure"), NULL, scalar);
if (FAILED(hr))
{
error = L"Failed to set pressure on material object: ";
error += CO_Error(mat, hr);
return false;
}
// set total flow
scalar.SetDoubleAt(0, flow);
hr = mat->SetOverallProp(CBSTR(L"totalFlow"), mole, scalar);
if (FAILED(hr))
{
error = L"Failed to set total flow on material object: ";
error += CO_Error(mat, hr);
return false;
}
scalar.SetDoubleAt(0, flowL);
hr = mat->SetSinglePhaseProp(CBSTR(L"totalFlow"), phL, mole, scalar);
if (FAILED(hr))
{
error = L"Failed to set total liquid flow on material object: ";
error += CO_Error(mat, hr);
return false;
}
scalar.SetDoubleAt(0, flowV);
hr = mat->SetSinglePhaseProp(CBSTR(L"totalFlow"), phV, mole, scalar);
if (FAILED(hr))
{
error = L"Failed to set total vapor flow on material object: ";
error += CO_Error(mat, hr);
return false;
}
//set composition
hr = mat->SetSinglePhaseProp(CBSTR(L"fraction"), phL, mole, compositionL);
if (FAILED(hr))
{
error = L"Failed to set composition of Liquid Phase on material object: ";
error += CO_Error(mat, hr);
return false;
}
hr = mat->SetSinglePhaseProp(CBSTR(L"fraction"), phV, mole, compositionV);
if (FAILED(hr))
{
error = L"Failed to set composition of Vapor Phase on material object: ";
error += CO_Error(mat, hr);
return false;
}
//set fraction of phase
/*scalar.SetDoubleAt(0, fractionL);
hr = mat->SetSinglePhaseProp(CBSTR(L"phaseFraction"), phL, mole, scalar);
if (FAILED(hr))
{
error = L"Failed to set vapor fraction on material object: ";
error += CO_Error(mat, hr);
return false;
}
scalar.SetDoubleAt(0, fractionV);
hr = mat->SetSinglePhaseProp(CBSTR(L"phaseFraction"), phV, mole, scalar);
if (FAILED(hr))
{
error = L"Failed to set vapor fraction material object: ";
error += CO_Error(mat, hr);
return false;
} */
return true;
After removing this types of error by setting the overall totalFlow and the phaseFractions (as it is commented out in the example), I receive a new error message : error: unit AlaklineSIM1D_1 did not flash outlet stream 4
I also adjusted materialObjectWrapper and MaterialObject. I call the method in calculate() with:
Code: Select all
if (port->IsConnected())
{
material = port->GetMaterial();
// set from composition, T and P and
if (!material.SetSinglePhaseFromFlowTPX(composition_c_l, composition_c_v, m_n_dot_c_out, m_n_dot_c_l_out , m_n_dot_c_v_out ,m_n_dot_c_l_out / m_n_dot_c_out, m_n_dot_c_v_out / m_n_dot_c_out, T_out, p, error))
{
SetError(error.c_str(), L"ICapeUnit", L"Calculate");
return false;
}
}
FYI: The UO should be integrated into PRO/II. I want to set the phases manually, because an electrolyte solution is used as material and the thermodynamic data for this are scarce.