Symbolic functions with multiple outputs
Hi again Just reading the GiNaC 1.3.1 manual, in the section about adding new symbolic functions, section 6.2 Is it possible to create symbolic functions that have multiple, matrix, or list outputs? Is there a way to assign the outputs of a multiple-valued symbolic function to elements of a list? lst(a,b,c) = three_valued_function(d,e); For example, a case where one might want to do this sort of thing would be evaluation of fluid properties, like so lst(p,h) = pressure_and_enthalpy_of_water(T, rho); When finally evaluating this numerically, eg once T and rho are known, having this as one symbolic function allows some intrinsic optimisation of calls to the thermodynamic property calculation routines. Thanks for your help, and sorry for the stream of silly questions... Cheers JP -- John Pye School of Mechanical and Manufacturing Engineering The University of New South Wales Sydney NSW 2052 Australia t +61 2 9385 5127 f +61 2 9663 1222 mailto:john.pye_AT_student_DOT_unsw.edu.au http://pye.dyndns.org/
Dear John, On Thu, 2005-09-08 at 15:57 +1000, John Pye wrote:
Is it possible to create symbolic functions that have multiple, matrix, or list outputs? Is there a way to assign the outputs of a multiple-valued symbolic function to elements of a list?
You could have a function that automatically evals into a list by supplying the appropriate eval_func. However, is there anything wrong with ex p=pressure_of_water(T,rho); and ex h=enthalpy_of_water(T,rho);? In the list case, perhaps what you really would want to have is a symbolic function water_variables(p,h) that does not evalutate further but can be used to hold pressure and enthalpy as results. Best wishes, Chris
Hi Chris, thanks for answering, Chris Dams wrote:
Is it possible to create symbolic functions that have multiple, matrix, or list outputs? Is there a way to assign the outputs of a multiple-valued symbolic function to elements of a list?
You could have a function that automatically evals into a list by supplying the appropriate eval_func. However, is there anything wrong with ex p=pressure_of_water(T,rho); and ex h=enthalpy_of_water(T,rho);?
By evaluating these at the same time in my final numerical evaluation stage, I can optimise a bit on the evaluation of the power series which is used to provide the steam properties I'm using, see http://pye.dyndns.org/freesteam/ I've got other areas where this would be useful too - I am trying to build very simplistic process simulator program, and if I could encapsulate system components (such as pumps or pipes etc) as GiNaC functions, then it would make it easier to express larger systems. This might not be the most efficient approach, but it was an approach I was thinking about, anyway. The more work I can get GiNaC to do, the easier it will be to get my code initially working...
In the list case, perhaps what you really would want to have is a symbolic function water_variables(p,h) that does not evalutate further but can be used to hold pressure and enthalpy as results.
Sorry, I don't understand what you mean here? Cheers JP -- John Pye School of Mechanical and Manufacturing Engineering The University of New South Wales Sydney NSW 2052 Australia t +61 2 9385 5127 f +61 2 9663 1222 mailto:john.pye_AT_student_DOT_unsw.edu.au http://pye.dyndns.org/
Dear John, On Thu, 8 Sep 2005, John Pye wrote:
In the list case, perhaps what you really would want to have is a symbolic function water_variables(p,h) that does not evalutate further but can be used to hold pressure and enthalpy as results.
Sorry, I don't understand what you mean here?
DECLARE_FUNCTION_2P(water_variables); REGISTER_FUNCTION(water_variables,dummy()); ex f=water_variables(p,h);
By evaluating these at the same time in my final numerical evaluation stage, I can optimise a bit on the evaluation of the power series which is used to provide the steam properties I'm using, see http://pye.dyndns.org/freesteam/
In the case with the water_variables function you could supply your own function for the numerical evalutation of such a function and you could use your optimisations. Best wishes, Chris
participants (2)
-
Chris Dams
-
John Pye