Hi there I'm struggling to understand how to correctly use the 'idx' functionality in GiNaC. If anyway would be able to offer some suggestions or relevant examples, I'd be very appreciative. My application is for something like a simple one-dimensional pipe flow calculation. For example, I would like to evaluate the pressures in the flow alow a pipe. I will set up some expressions relating the values of my pressures at different nodes in my pipe, then I will substitute values for those pressures and then evaluate residuals from my expressions. So I am hoping to write something like sym p[100] = sym[]("p"); sym mdot[100] = sym[]("mdot"); sym rho("rho"); lst f; for(int i=1; i<100; ++i){ f.append( p[i] - p[i-1] - 0.5 * rho * pow( mdot[i-1] / (rho * A) , 2) ); } for(int i=1; i<100; ++i){ f.subs(p[i] == 1.5454223494); } cerr << f << endl; In this way, I will have an array of symbols and a lst of expressions. I can then use those to generate equations which can be exported to s numerical solver. Perhaps the best way to do this is to create standard C-style array of symbols? I am hoping there's a more elegant way. Also, I'd like to know your thoughts on how efficient this sort of approach might be as the number of equations / symbols grows. Am I right in thinking I shuold be using the 'idx' class? 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/
On Wed, Sep 07, 2005 at 05:56:01PM +1000, John Pye wrote:
I'm struggling to understand how to correctly use the 'idx' functionality in GiNaC.
See http://www.ginac.de/FAQ.html#matrix_indexed for a (short) explanation.
My application is for something like a simple one-dimensional pipe flow calculation. For example, I would like to evaluate the pressures in the flow alow a pipe. I will set up some expressions relating the values of my pressures at different nodes in my pipe, then I will substitute values for those pressures and then evaluate residuals from my expressions. So I am hoping to write something like
sym p[100] = sym[]("p"); sym mdot[100] = sym[]("mdot"); sym rho("rho");
lst f; for(int i=1; i<100; ++i){ f.append( p[i] - p[i-1] - 0.5 * rho * pow( mdot[i-1] / (rho * A) , 2) ); }
for(int i=1; i<100; ++i){ f.subs(p[i] == 1.5454223494); }
cerr << f << endl;
In this way, I will have an array of symbols and a lst of expressions. I can then use those to generate equations which can be exported to numerical solver.
Probably, I'm just missing something important, but I don't understand why you need to do _symbolic_ manipulations in this problem.
Perhaps the best way to do this is to create standard C-style array of symbols? I am hoping there's a more elegant way.
Why don't you use an associative array, e.g. std::map<sybol, ex, ex_is_less>, or just GiNaC::exmap?
Also, I'd like to know your thoughts on how efficient this sort of approach might be as the number of equations / symbols grows.
I don't think your approach will be efficient.
Am I right in thinking I shuold be using the 'idx' class?
NO! -- All science is either physics or stamp collecting.
Hi Alexei, Thanks very much for your reply. It looks like I might have been going in the wrong direction with those ideas, perhaps I need to rethink how I implement my code for the case of arrays equations for finite elements. The reasons I needed to use GiNaC were probably not apparent from my example. I am using it to perform symbolic differentiation. Also I would like possibly at some point be able to analyse the 'topology' of my equations, for use in some of the cleverer 'tearing' algorithms for systems of nonlinear equations. I could use GiNaC to determine whether the structure of an equation was logarithmic, or reciprocal, or product or trigonometric, etc, fairly easily. Finally, using GiNaC allows me to express systems of nonlinear equations directly in C++ without needing to write a separate language lexer as is done in much other nonlinear solver software, and I can easily embed custom functions which can I can also provide with derivatives etc. Anyway, thanks again for your advice, JP Sheplyakov Alexei wrote:
On Wed, Sep 07, 2005 at 05:56:01PM +1000, John Pye wrote:
I'm struggling to understand how to correctly use the 'idx' functionality in GiNaC.
See http://www.ginac.de/FAQ.html#matrix_indexed for a (short) explanation.
My application is for something like a simple one-dimensional pipe flow calculation. For example, I would like to evaluate the pressures in the flow alow a pipe. I will set up some expressions relating the values of my pressures at different nodes in my pipe, then I will substitute values for those pressures and then evaluate residuals from my expressions. So I am hoping to write something like
sym p[100] = sym[]("p"); sym mdot[100] = sym[]("mdot"); sym rho("rho");
lst f; for(int i=1; i<100; ++i){ f.append( p[i] - p[i-1] - 0.5 * rho * pow( mdot[i-1] / (rho * A) , 2) ); }
for(int i=1; i<100; ++i){ f.subs(p[i] == 1.5454223494); }
cerr << f << endl;
In this way, I will have an array of symbols and a lst of expressions. I can then use those to generate equations which can be exported to numerical solver.
Probably, I'm just missing something important, but I don't understand why you need to do _symbolic_ manipulations in this problem.
Perhaps the best way to do this is to create standard C-style array of symbols? I am hoping there's a more elegant way.
Why don't you use an associative array, e.g. std::map<sybol, ex, ex_is_less>, or just GiNaC::exmap?
Also, I'd like to know your thoughts on how efficient this sort of approach might be as the number of equations / symbols grows.
I don't think your approach will be efficient.
Am I right in thinking I shuold be using the 'idx' class?
NO!
------------------------------------------------------------------------
_______________________________________________ GiNaC-list mailing list GiNaC-list@ginac.de http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
participants (2)
-
John Pye
-
varg@theor.jinr.ru