Is the "ICapeThermoMaterialContext" useful?

Is the "ICapeThermoMaterialContext" useful?

Postby bcbooo » 27 March 2014, 06:40

The "CO_Thermo_1.1_Specification_311.pdf" says that :

"ICapeThermoMaterialContext should be implemented by all Thermodynamic and Physical Properties components that need an ICapeThermoMaterial interface in order to set and get a Material's property values. "

ICapeThermoMaterialContext has two functions "SetMaterial" & "UnsetMaterial", and the "SetMaterial" is used for:

"The SetMaterial method allows a Thermodynamic and Physical Properties component, such as a Property Package, to be given the ICapeThermoMaterial interface of a Material Object. This interface gives the component access to the descript ion of the Material for which Property Calculations or Equilibrium Calculat ions are required. The component can access property values directly using this interface. A client can also use the ICapeThermoMaterial interface to query a Material Object for its ICapeThermoCompounds and ICapeThermoPhases interfaces, which provide access to Compound and Phase information, respectively. "

***------------***-------------***

But the "ICapeThermoMaterialContext" makes me puzzled, I compose the code like the following:

////code start
class ATL_NO_VTABLE CPropertyPackage :
public CAPEOPENBaseObject,
public CComCoClass<CPropertyPackage, &CLSID_PropertyPackage>,
public IDispatchImpl<ICapeThermoCompounds, &__uuidof(ICapeThermoCompounds), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IDispatchImpl<ICapeThermoEquilibriumRoutine, &__uuidof(ICapeThermoEquilibriumRoutine), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IDispatchImpl<ICapeThermoMaterialContext, &__uuidof(ICapeThermoMaterialContext), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IDispatchImpl<ICapeThermoPhases, &__uuidof(ICapeThermoPhases), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IDispatchImpl<ICapeThermoPropertyRoutine, &__uuidof(ICapeThermoPropertyRoutine), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IDispatchImpl<ICapeThermoUniversalConstant, &__uuidof(ICapeThermoUniversalConstant), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IDispatchImpl<ICapeThermoMaterial, &__uuidof(ICapeThermoMaterial), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IDispatchImpl<ICapeUtilities, &__uuidof(ICapeUtilities), &LIBID_CAPEOPEN110, /* wMajor = */ 1, /* wMinor = */ 1>,
public IPersistStream
////code end

Here I combine the "ICapeThermoMaterial" interface with all other interfaces. The "ICapeThermoMaterial" of a Material Object will be created when the "CPropertyPackage" is initialized.

So it's meaningless to use "SetMaterial" function to set the "ICapeThermoMaterial" interface, my code has create the "ICapeThermoMaterial" interface automaticly.

Is there something wrong with my thought, or should not I combine "ICapeThermoMaterial" with other interfaces?
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Is the "ICapeThermoMaterialContext" useful?

Postby jasper » 27 March 2014, 09:02

Why would you implement a property package and a material object on one component? Typically the property package is implemented by the component that delivers the thermodynamic calculations and the material object is implemented by the component that request the thermodynamic property calculations.

The calculation conditions are set on the material object; the material object is set as the context material of the property package; the property package is requested to - say - calculate a property; the property package retrieves the calculation conditions (e.g T, P, X) from the material object; the property package performs the calculation; the property package stores the result on the material object; the property package returns control to the caller; the caller gets the results of the material object.

In which scenarario would you want a component to implement both the material object and the property package that the material object talks to? This scenario would imply that a component is asking itself to perform thermodynamic property calculations (fair enough, but why do so via CAPE-OPEN?)
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Is the "ICapeThermoMaterialContext" useful?

Postby jasper » 27 March 2014, 10:01

If your intent is to create a material object to use in combination with unit operations, then it makes sense for the thermodynamics to be implemented by the material object itself if no external property package is used. In this case "Material Object" is probably a better name for the object than "Property Package", and indeed in this case no Material Context is needed.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Is the "ICapeThermoMaterialContext" useful?

Postby bcbooo » 27 March 2014, 12:12

jasper wrote:If your intent is to create a material object to use in combination with unit operations, then it makes sense for the thermodynamics to be .....


Jasper you are right, I am developing a chemical enginneering process simulator according to CAPE-OPEN standard, so I need to create a material object and unit operations and the Process Modelling environment. The unit operation looks not difficult for me, but I feel puzzled on the material object.

I want to make the material object in my simulator could be connected by internal unit operations, and also external softwares according to CAPE-OPEN. Is it rational to combine the "ICapeThermoMaterial" interface with all other interfaces like "ICapeThermoPhases","ICapeThermoEquilibriumRoutine","ICapeThermoPropertyRoutine","ICapeThermoUniversalConstant" and so on in material object? I don't how other simulators like Hysys and ProII do it on their material object.

----------------------------------------------

Another question.

Jasper you said:

"The calculation conditions are set on the material object; the material object is set as the context material of the property package; the property package is requested to - say - calculate a property; the property package retrieves the calculation conditions (e.g T, P, X) from the material object; the property package performs the calculation; the property package stores the result on the material object; the property package returns control to the caller; the caller gets the results of the material object."

I think this process is applied on CAPE-OPEN Thermo 1.0, not fit for CAPE-OPEN 1.1. Because in CAPE-OPEN 1.1, property package don't have functions like "CalcProp()" in CAPE-OPEN 1.0. Is the "overall mixture calculation functions" should be executed automatically in "GetOverallProp()" in CAPE-OPEN 1.1?
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Is the "ICapeThermoMaterialContext" useful?

Postby jasper » 27 March 2014, 12:28

Yes, a 1.1 material object implements all the interfaces that a 1.1 property package does. Except the material context.

What is in 1.0 GetProp, translates in 1.1 to GetSinglePhaseProp, GetTwoPhaseProp and GetOverallProp; notice that there is no Pure or Mixture anymore, all of these assume Mixture; support for the pure properties has been replaced by GetTemperatureDependentProperty / GetPressureDependentProperty, which does not require storage on the MO. Also there is a shortcut for lnFugacityCoefficient calculations that does not require the properties to be stored on the MO.

What was CalcProp is therefore now CalcSinglePhaseProp, CalcTwoPhaseProp (plus GetTemperatureDependentProperty / GetPressureDependentProperty / CalcAndGetLnFugacityCoefficients); there is no direct support for calculation of overall properties in 1.1; you will have to loop over the phases and add it up.

So the strategy is the same for mixture properties:

Calculate a single phase property:
1.0: set T,P,X on the MO for the phase, CalcProp for the phase, set result on the MO
1.1: set T,P,X on the MO for the phase (SetSinglePhaseProp), CalcSinglePhaseProp, set the result on the MO

Similar for a two-phase property

Not similar for T- and P-dependent properties: that is just one call, no storage on the MO

No support for overall property calculations in 1.1; in 1.1 the overall properties represent in- and output for flash calculations only

Do check the comments in the specification regarding CalcEquilibrium; this works in conjuction with Set/GetPresentPhases (both upon input and output)
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Is the "ICapeThermoMaterialContext" useful?

Postby jasper » 27 March 2014, 12:29

The CalcSinglePhaseProp / CalcTwoPhaseProp functions live on ICapeThermoPropertyRoutine
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Is the "ICapeThermoMaterialContext" useful?

Postby bcbooo » 27 March 2014, 13:15

jasper wrote:Yes, a 1.1 material object implements all the interfaces that a 1.1 property ......


Thank you Jasper for your excellent response!
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Is the "ICapeThermoMaterialContext" useful?

Postby jasper » 27 March 2014, 13:25

One small correction:

No support for overall property calculations in 1.1; in 1.1 the overall properties represent in- and output for flash calculations only


The overall properties also serve to define what flows into a unit operation via the feed ports and out of a unit operation via the product ports. Like with 1.0, in 1.1 you can assume the feed port materials are in equilibrium, you may not perform any operations that affect the state of the feed port materials (but you can duplicate it) and you must flash the product ports.
User avatar
jasper
 
Posts: 1128
Joined: 24 October 2012, 15:33
Location: Spain

Re: Is the "ICapeThermoMaterialContext" useful?

Postby bcbooo » 28 March 2014, 00:44

Sorry Jasper, I don't agree with you on this point:

jasper wrote:you must flash the product ports.


I think it's not essential to flash the product ports. In your "CPP Mixer Splitter example" you don't flash the product ports, too. I prefer to flash the material object when it's needed.
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Re: Is the "ICapeThermoMaterialContext" useful?

Postby bcbooo » 28 March 2014, 01:08

On the other hand, I want to change the calculation mechanism in CAPE-OPEN like following:

At normal ways, if user wants to get the property of the overall mixture, he must do two things. Here take "overall mixture enthalpy calculation" for instance:
(1) Firstly, he must call "CalcSinglePhaseProp()" for every "phaseLabel";
(2) Secondly, he use "GetSinglePhaseProp()" to get the enthalpy from every "phaseLabel", then add all the enthalpy values to get the "overall mixture enthalpy".

I think this way is exhausting, I advise to hide the "CalcSinglePhaseProp" into "GetOverallProp". Users just need to call "GetOverallProp" merely, rather than "CalcSinglePhaseProp"& "GetOverallProp" sequently.

Of course, here I will set a value to indicate whether the "overall mixture enthalpy" have been calculated. if the enthalpy has been calculated, when user call the '"GetOverallProp", this function return the "enthalpy value" immediately; otherwise, this function will call the "CalcSinglePhaseProp" function to calculate "overall mixtrue enthalpy", then return the "enthalpy value" again.

the code like folloing:

Code: Select all
//header file
BOOL overallMixtureEnthalpyHaveBeenCalculated; //the default value is FALSE
double overallMixtureEnthalpy; //the overall mixture enthalpy value

//cpp file
double GetOverallProp(..........)
{
if(overallMixtureEnthalpyHaveBeenCalculated) return overallMixtureEnthalpy;
else
{
overallMixtureEnthalpy=0;
for(int i=0;i<phaseLabelsCount;i++) overallMixtureEnthalpy+=CalcSinglePhaseProp(...);
overallMixtureEnthalpyHaveBeenCalculated=TRUE;
return overallMixtureEnthalpy;
}

}



When the condition(T, P, composition, etc.) in material object is changed, the overallMixtureEnthalpyHaveBeenCalculated will be set FALSE.
bcbooo
 
Posts: 66
Joined: 22 November 2012, 06:41
Location: China

Next

Return to Thermodynamic components

Who is online

Users browsing this forum: No registered users and 1 guest

cron