|
|
Subject: Re: Referencing array of symbols? - msg#00004
List: mathematics.ginac.general
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-HEL5OUoDxoc@xxxxxxxxxxxxxxxx
> http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
>
>
_______________________________________________
GiNaC-list mailing list
GiNaC-list-HEL5OUoDxoc@xxxxxxxxxxxxxxxx
http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
Re: Referencing array of symbols?
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.
signature.asc
Description: Digital signature
_______________________________________________
GiNaC-list mailing list
GiNaC-list-HEL5OUoDxoc@xxxxxxxxxxxxxxxx
http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
Next Message by Date:
click to view message preview
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/
_______________________________________________
GiNaC-list mailing list
GiNaC-list-HEL5OUoDxoc@xxxxxxxxxxxxxxxx
http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
Previous Message by Thread:
click to view message preview
Re: Referencing array of symbols?
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.
signature.asc
Description: Digital signature
_______________________________________________
GiNaC-list mailing list
GiNaC-list-HEL5OUoDxoc@xxxxxxxxxxxxxxxx
http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
Next Message by Thread:
click to view message preview
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/
_______________________________________________
GiNaC-list mailing list
GiNaC-list-HEL5OUoDxoc@xxxxxxxxxxxxxxxx
http://thep.physik.uni-mainz.de/mailman/listinfo/ginac-list
|
|