Page 1 of 1
How to calculate the matrix
Posted: 24 August 2017, 02:25
by King
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?
Re: How to cal the matrix
Posted: 24 August 2017, 07:29
by jasper
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?
Re: How to cal the matrix
Posted: 25 August 2017, 07:13
by King
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.
Re: How to cal the matrix
Posted: 25 August 2017, 11:31
by jasper
But if you do GetSinglePhaseProperty 1000x without CalcSinglePhaseProperty you will be getting the same value over and over again.
Re: How to cal the matrix
Posted: 25 August 2017, 15:28
by colancto
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.
Re: How to cal the matrix
Posted: 28 August 2017, 00:51
by King
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?
Re: How to cal the matrix
Posted: 28 August 2017, 00:58
by King
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!
Re: How to cal the matrix
Posted: 28 August 2017, 08:06
by jasper
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.
Re: How to cal the matrix
Posted: 29 August 2017, 00:49
by King
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.