Differentiation of a function with respect to a tensor
Hi everyone, I've recently discovered GiNaC and I'm really excited about its capabilities. There is one thing that I would like to know if it is able to do that I haven't found in the tutorial.pdf or in any other place that I've searched. I would like to know if, given a function \Psi=\Psi(E), like the strain energy function for the St. Venant-Kirchhoff material \Psi(E) = 0.5 * \lambda * (tr E)^2 + \mu E:E is it possible to differentiate it with respect to E, that is i would like to compute \frac{\partial \Psi}{\partial E}. If this is possible, could someone please send some examples or maybe point to which classes should I use to do that? That's all for now. Many thanks in advance. Best regards, Bernardo M. R.
Dear Bernardo,
On Wed, 9 Feb 2011 10:07:51 -0200, Bernardo Rocha <bernardosk@gmail.com> said: BMR> the strain energy function for the St. Venant-Kirchhoff BMR> material BMR> \Psi(E) = 0.5 * \lambda * (tr E)^2 + \mu E:E
To start with, can you write this functions as a GiNaC expression? Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/
Dear Vladimir, first of all thanks for your reply. Well, defining the function as a GiNaC expression is part of my doubt, since I do not know how to represent the second-order tensor E in GiNaC, and consequently, how to differentiate Psi with respect to it. I've seen some classes for special tensors, like clifford, delta, etc, but it is not clear for me how to represent a second order tensor. I was guess I should use matrix and idx....but how? and how do I use diff afterwards? Many thanks in advance. Best regards, Bernardo M. Rocha 2011/2/10 Vladimir V. Kisil <kisilv@maths.leeds.ac.uk>
Dear Bernardo,
On Wed, 9 Feb 2011 10:07:51 -0200, Bernardo Rocha < bernardosk@gmail.com> said: BMR> the strain energy function for the St. Venant-Kirchhoff BMR> material BMR> \Psi(E) = 0.5 * \lambda * (tr E)^2 + \mu E:E
To start with, can you write this functions as a GiNaC expression?
Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/
Dear Bernardo,
On Thu, 10 Feb 2011 16:11:41 -0200, Bernardo Rocha <bernardosk@gmail.com> said: BMR> Well, defining the function as a GiNaC expression is part of my BMR> doubt,
You need to define an indexed object, see respective section (4.14.1) in the manual. In the example symbol i_sym("i"), j_sym("j"); idx i(i_sym, 3), j(j_sym, 3); symbol A("A"); ex E=indexed(A, i, j); you need to replace A by a suitable GiNaC expression, which will encode properties of your tensor. In some cases you may need to define your own class for it if you wish a fine control on its behaviour. Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk -- www: http://www.maths.leeds.ac.uk/~kisilv/
Bernardo Rocha wrote:
Hi everyone,
I've recently discovered GiNaC and I'm really excited about its capabilities. There is one thing that I would like to know if it is able to do that I haven't found in the tutorial.pdf or in any other place that I've searched.
I would like to know if, given a function \Psi=\Psi(E), like the strain energy function for the St. Venant-Kirchhoff material
\Psi(E) = 0.5 * \lambda * (tr E)^2 + \mu E:E
is it possible to differentiate it with respect to E, that is i would like to compute \frac{\partial \Psi}{\partial E}. If this is possible, could someone please send some examples or maybe point to which classes should I use to do that?
That's all for now. Many thanks in advance.
Best regards, Bernardo M. R.
Couldn't you do it this way? Write \Psi(E) as an expression involving the variables e11,e12,e13,...,e33 which are the entries of E. Then compute the partial derivatives \frac{\partial \Psi}{\partial eij} for 1<=i,j<=3. (Presumably you suppose that E is symmetric so only six partial derivatives need to be computed, but even if it is not necessarily symmetric you still only need 9 partial derivatives.) Just store this as something like: expr dPsi_dE[3][3] or vector<expr> dPsi_dE or something similar.
Dear Stephen, thanks a lot for your support. I was considering if doing it this way it would work, now I got my confirmation. Thanks a lot again. Best regards, Bernardo 2011/2/11 Stephen Montgomery-Smith <stephen@missouri.edu>
Bernardo Rocha wrote:
Hi everyone,
I've recently discovered GiNaC and I'm really excited about its capabilities. There is one thing that I would like to know if it is able to do that I haven't found in the tutorial.pdf or in any other place that I've searched.
I would like to know if, given a function \Psi=\Psi(E), like the strain energy function for the St. Venant-Kirchhoff material
\Psi(E) = 0.5 * \lambda * (tr E)^2 + \mu E:E
is it possible to differentiate it with respect to E, that is i would like to compute \frac{\partial \Psi}{\partial E}. If this is possible, could someone please send some examples or maybe point to which classes should I use to do that?
That's all for now. Many thanks in advance.
Best regards, Bernardo M. R.
Couldn't you do it this way? Write \Psi(E) as an expression involving the variables e11,e12,e13,...,e33 which are the entries of E. Then compute the partial derivatives \frac{\partial \Psi}{\partial eij} for 1<=i,j<=3. (Presumably you suppose that E is symmetric so only six partial derivatives need to be computed, but even if it is not necessarily symmetric you still only need 9 partial derivatives.) Just store this as something like:
expr dPsi_dE[3][3]
or
vector<expr> dPsi_dE
or something similar.
But do remember, if E is symmetric, that you have to somehow tell GiNaC that e12=e21. I do a lot of similar stuff in Mathematica, and I start with a statement like E = {{e11,e12,e13},{e12,e22,e23},{e13,e23,e33}} so one way you could do this in GiNaC is to create a variable E: expr E[3][3] and set E[i][j] = to eij or eji as appropriate. And then for something like E:E you get expr EddE = 0; for (i=0;i<3;i++) for (j=0;j<3;j++) EddE += E[i][j]*E[i][j]; (In Mathematica you could more easily do EddE = Tr[E.E] but Mathematica costs a fortune unless you are part of a university with a site license.) Bernardo Rocha wrote:
Dear Stephen,
thanks a lot for your support. I was considering if doing it this way it would work, now I got my confirmation. Thanks a lot again.
Best regards, Bernardo
2011/2/11 Stephen Montgomery-Smith <stephen@missouri.edu <mailto:stephen@missouri.edu>>
Bernardo Rocha wrote:
Hi everyone,
I've recently discovered GiNaC and I'm really excited about its capabilities. There is one thing that I would like to know if it is able to do that I haven't found in the tutorial.pdf or in any other place that I've searched.
I would like to know if, given a function \Psi=\Psi(E), like the strain energy function for the St. Venant-Kirchhoff material
\Psi(E) = 0.5 * \lambda * (tr E)^2 + \mu E:E
is it possible to differentiate it with respect to E, that is i would like to compute \frac{\partial \Psi}{\partial E}. If this is possible, could someone please send some examples or maybe point to which classes should I use to do that?
That's all for now. Many thanks in advance.
Best regards, Bernardo M. R.
Couldn't you do it this way? Write \Psi(E) as an expression involving the variables e11,e12,e13,...,e33 which are the entries of E. Then compute the partial derivatives \frac{\partial \Psi}{\partial eij} for 1<=i,j<=3. (Presumably you suppose that E is symmetric so only six partial derivatives need to be computed, but even if it is not necessarily symmetric you still only need 9 partial derivatives.) Just store this as something like:
expr dPsi_dE[3][3]
or
vector<expr> dPsi_dE
or something similar.
participants (3)
-
Bernardo Rocha
-
Stephen Montgomery-Smith
-
Vladimir V. Kisil