How to calculate the matrix

Discusses use of CAPE-OPEN compliant Process Modelling Components

Moderator: jasper

How to calculate the matrix

Postby King » 24 August 2017, 02:25

getSinglePhaseProperty can only calculate one composition condition. if there are lots of conditions to be calculated at the same time, for loop is not efficient.

is there some way to calculate a matrix composition?
King
 
Posts: 22
Joined: 17 February 2017, 06:22

Re: How to cal the matrix

Postby jasper » 24 August 2017, 07:29

Not in this version of CAPE-OPEN.

With a well written efficient material object the overhead need not to be too large though. I suppose you mean to call both CalcSinglePhaseProperty and GetSinglePhaeProperty?
User avatar
jasper
 
Posts: 989
Joined: 24 October 2012, 15:33
Location: Spain

Re: How to cal the matrix

Postby King » 25 August 2017, 07:13

jasper wrote:Not in this version of CAPE-OPEN.

With a well written efficient material object the overhead need not to be too large though. I suppose you mean to call both CalcSinglePhaseProperty and GetSinglePhaeProperty?

No, only GetSinglePhaseProperty, but there are maybe 10000 kinds of component conditions to be calculate, so I must use the 'for loop' to calculate one by one. As you can see, matrix compute is the most efficient way in matlab, for example, we can get sin(x) or x.*y (x,y are matrix) directly in matlab insdead of indexing one by one from each matrix and do the operation. I hope the matrix operation can be support by the cape-open function which is efficient and can save time.
King
 
Posts: 22
Joined: 17 February 2017, 06:22

Re: How to cal the matrix

Postby jasper » 25 August 2017, 11:31

But if you do GetSinglePhaseProperty 1000x without CalcSinglePhaseProperty you will be getting the same value over and over again.
User avatar
jasper
 
Posts: 989
Joined: 24 October 2012, 15:33
Location: Spain

Re: How to cal the matrix

Postby colancto » 25 August 2017, 15:28

Would be great to know more on the case at hand. It is not the first time the requirement for calculating a property at a number of condition sets has been formulated.
User avatar
colancto
Administrateur
 
Posts: 80
Joined: 23 October 2012, 11:46

Re: How to cal the matrix

Postby King » 28 August 2017, 00:51

jasper wrote:But if you do GetSinglePhaseProperty 1000x without CalcSinglePhaseProperty you will be getting the same value over and over again.

I don't find the CalcSinglePhaseProperty inthe help of the matlab unit operaton, what's that?
King
 
Posts: 22
Joined: 17 February 2017, 06:22

Re: How to cal the matrix

Postby King » 28 August 2017, 00:58

colancto wrote:Would be great to know more on the case at hand. It is not the first time the requirement for calculating a property at a number of condition sets has been formulated.

This idea was thought when I used matlab functions to calculate the matric operations. I think there may be some conditions which needs for matrix operation by cape-open functions. It can be efficient if it comes true!
King
 
Posts: 22
Joined: 17 February 2017, 06:22

Re: How to cal the matrix

Postby jasper » 28 August 2017, 08:06

King wrote:I don't find the CalcSinglePhaseProperty inthe help of the matlab unit operaton, what's that?


Ah - now I understand your question better. I was not aware that you were using the Matlab Unit Operation.

For Matlab Thermo, you can get values by vector (not by matrix, as this would make composition a tensor), from Matlab itself. But under the hood this translates to an individual property calculation for each item in the vector, as CAPE-OPEN itself does not allow for vector values. This is because the calculation results are stored on a material object, and there is only one of those.

For Matlab Unit Operation, this is not implemented, but doing the loop inside Matlab is not much less effective than the loop being done in the mex file, as is the case for thermo.

In any case the overhead of the loop is rather small, unless the underlying thermo (a) would be optimized for vector calculations, e.g. initialize each calculation by using the previous point in the vector, or (b) the calculations are very fast compared to the function call, which is not typically the case. Typically e.g. solving the equation of state takes longer than the function call itself.

The only true optimization I can think of is splitting the calculations over multiple threads, but Matlab Thermo currently is not designed to be thread safe, and Matlab Unit Operation cannot be designed that way, as it depends on a Material Object delivered by the simulation environment, for which it cannot be assumed that it can be duplicated and used from other threads. The latter is actually a restriction imposed by COM.
User avatar
jasper
 
Posts: 989
Joined: 24 October 2012, 15:33
Location: Spain

Re: How to cal the matrix

Postby King » 29 August 2017, 00:49

jasper wrote:
King wrote:I don't find the CalcSinglePhaseProperty inthe help of the matlab unit operaton, what's that?


Ah - now I understand your question better. I was not aware that you were using the Matlab Unit Operation.

For Matlab Thermo, you can get values by vector (not by matrix, as this would make composition a tensor), from Matlab itself. But under the hood this translates to an individual property calculation for each item in the vector, as CAPE-OPEN itself does not allow for vector values. This is because the calculation results are stored on a material object, and there is only one of those.

For Matlab Unit Operation, this is not implemented, but doing the loop inside Matlab is not much less effective than the loop being done in the mex file, as is the case for thermo.

In any case the overhead of the loop is rather small, unless the underlying thermo (a) would be optimized for vector calculations, e.g. initialize each calculation by using the previous point in the vector, or (b) the calculations are very fast compared to the function call, which is not typically the case. Typically e.g. solving the equation of state takes longer than the function call itself.

The only true optimization I can think of is splitting the calculations over multiple threads, but Matlab Thermo currently is not designed to be thread safe, and Matlab Unit Operation cannot be designed that way, as it depends on a Material Object delivered by the simulation environment, for which it cannot be assumed that it can be duplicated and used from other threads. The latter is actually a restriction imposed by COM.


Thank you for your patient answer Jasper, the work you did in cape-open provide much convenience for us.
King
 
Posts: 22
Joined: 17 February 2017, 06:22


Return to Process Modelling Components

Who is online

Users browsing this forum: No registered users and 1 guest

cron