# Diff of /trunk/doc/user/symbolic.tex

revision 5099 by caltinay, Mon Apr 28 04:03:41 2014 UTC revision 5100 by jduplessis, Tue Jul 15 07:36:29 2014 UTC
# Line 2  Line 2
2  \chapter{The escript symbolic toolbox}  \chapter{The escript symbolic toolbox}
3  \label{CHAP:Symbolic}  \label{CHAP:Symbolic}
4  \section{Introduction}  \section{Introduction}
5  Escript builds on the existing Sympy~\cite{Sympy} symbolic maths library to  \escript builds on the existing Sympy~\cite{Sympy} symbolic maths library to
6  provide a \SYMBOL class with support for escript Data objects. \SYMBOL objects  provide a \SYMBOL class with support for \escript Data objects. \SYMBOL objects
7  act as placeholders for a single mathematical symbol, such as \texttt{x}, or  act as placeholders for a single mathematical symbol, such as \texttt{x}, or
8  for arbitrarily complex mathematical expressions such as  for arbitrarily complex mathematical expressions such as
9  \texttt{c*x**4 + alpha*exp(x) - 2*sin(beta * x)}, where \texttt{alpha},  \texttt{c*x**4 + alpha*exp(x) - 2*sin(beta * x)}, where \texttt{alpha},
10  \texttt{beta}, \texttt{c}, and \texttt{x} are also symbols (the symbolic  \texttt{beta}, \texttt{c}, and \texttt{x} are also symbols (the symbolic
11  atoms" of the expression).  atoms" of the expression).
12  With the help of the \EVALUATOR class, these symbols and expressions can  With the help of the \EVALUATOR class, these symbols and expressions can
13  be evaluated by substituting numeric values and/or escript \Data objects  be evaluated by substituting numeric values and/or \escript \Data objects
14  for the atoms. Escript's \SYMBOL class has a shape (and thus a rank) as well  for the atoms. Escript's \SYMBOL class has a shape (and thus a rank) as well
15  as a dimensionality.  as a dimensionality.
16  Symbols are useful to perform mathematical simplifications, compute  Symbols are useful to perform mathematical simplifications, compute
17  derivatives, take gradients and in the case of escript describe PDEs.  derivatives, take gradients and in the case of \escript describe PDEs.
18  As an example of how the symbolic toolbox can be used, consider the following  As an example of how the symbolic toolbox can be used, consider the following
19  code extract.  code extract.
20  \begin{python}  \begin{python}
30  evalu.subs(u=2*es.symconstants.pi)  evalu.subs(u=2*es.symconstants.pi)
31  evaluated=evalu.evaluate()  evaluated=evalu.evaluate()
32    print "p3=", p3                  #The symbols can be printed, this line will print p3.
33  print(evaluated)  print(evaluated)
34  \end{python}  \end{python}
35  Running this code outputs \texttt{(1 + 6*pi + 8*pi**2, 0, 3 + 8*pi)}.  Running this code outputs:\\\texttt{p3= 4*u + 3\\(1 + 6*pi + 8*pi**2, 0, 3 + 8*pi)}.\\
36  To get the numeric value of the expression we replace \texttt{evalu.evaluate()}  To get the numeric value of the expression we replace \texttt{evalu.evaluate()}
37  with \texttt{evalu.evaluate(evalf=True)}. This results in  with \texttt{evalu.evaluate(evalf=True)}. This results in
38  \texttt{(98.8063911302536, 0, 28.1327412287183)}.  \texttt{(98.806, 0, 28.132)}.
39  The use of these Symbols becomes more interesting in the context of escript  The use of these Symbols becomes more interesting in the context of escript
40  when they are integrated with escript \Data objects.  when they are integrated with escript \Data objects.
41
# Line 42  when they are integrated with escript \D Line 43  when they are integrated with escript \D
43  The \NLPDE class in escript makes use of the escript \SYMBOL class and allows  The \NLPDE class in escript makes use of the escript \SYMBOL class and allows
44  for the solution of PDEs of the form:  for the solution of PDEs of the form:
45
46  -\nabla\cdotp X + Y = 0  -X_{ij,j} + Y_i = 0
47  \label{symbolic eq1}  \label{symbolic eq1}
48
49  where $X$ and $Y$ are both functions of $\nabla u$ and $u$, and $u$ is the  where $X$ and $Y$ are both functions of $u_{k,j}$ and $u_k$, and $u$ is the
50  unknown function implemented as a \SYMBOL. $\nabla\cdotp x$ denotes divergence  unknown function implemented as a \SYMBOL. $\nabla\cdotp x$ denotes divergence
51  of $x$.  of $x$.
52  The \NLPDE class uses the \SYMBOL class to solve the nonlinear PDE given in  The \NLPDE class uses the \SYMBOL class to solve the nonlinear PDE given in
# Line 60  the linear PDE for the update step. The Line 61  the linear PDE for the update step. The
61  \Sec{SEC LinearPDE} is used to solve the linear PDEs from the update step.  \Sec{SEC LinearPDE} is used to solve the linear PDEs from the update step.
62  The coefficients of the linear PDE to be solved are calculated as follows:  The coefficients of the linear PDE to be solved are calculated as follows:
63  \begin{equation*}  \begin{equation*}
64   A = \frac{\partial \text{X}}{\partial \nabla u}, B = \frac{\partial \text{X}}{\partial u}, C = \frac{\partial \text{Y}}{\partial \nabla u}, D = \frac{\partial \text{Y}}{\partial u}   A_{ijkl} = \frac{\partial \text{X_{ij}}}{\partial u_{k,l}}, B_{ijkl} = \frac{\partial \text{X_{ij}}}{\partial u_{k}}, C_{ijkl} = \frac{\partial \text{Y_{ij}}partial u_{k,l}}, D_{ijkl} = \frac{\partial \text{Y}}{\partial u_{k}}
65  \end{equation*}  \end{equation*}
66  \section{2D Plane Strain Problem}  \section{2D Plane Strain Problem}
67  The \NLPDE class can be used to solve a 2D plane strain problem. In continuous  The \NLPDE class can be used to solve a 2D plane strain problem. In continuous
68  media, stress is given by Lam\'e's \eqn{symbolic eq2}.  media, stress is given by Lam\'e's \eqn{symbolic eq2}.
69
70  -\nabla\cdotp\sigma=f  -\sigma_{ij,j}=f
71  \label{symbolic eq2}  \label{symbolic eq2}
72
73  Hook's Law provides a relation between $\sigma$ and $\epsilon$ in the following form  Hook's Law provides a relation between $\sigma$ and $\epsilon$ in the following form
# Line 92  Where $\epsilon = symmetric(grad(u)) \te Line 93 Where$\epsilon = symmetric(grad(u)) \te
93  \epsilon_{ij}=\frac{1}{2}\left(\frac{\partial u_i}{\partial x_j} + %  \epsilon_{ij}=\frac{1}{2}\left(\frac{\partial u_i}{\partial x_j} + %
94  {\frac{\partial u_j}{\partial x_i}}\right)$,$u$is the unknown function and {\frac{\partial u_j}{\partial x_i}}\right)$, $u$ is the unknown function and
95  $c_{ij}$ is the stiffness matrix. To fit this to the nonlinear PDE class'  $c_{ij}$ is the stiffness matrix. To fit this to the nonlinear PDE class'
96  standard form, X is set to $c \times symmetric(grad(u))$.  standard form, X is set to $C \times symmetric(grad(u))$.
97  The following \PYTHON extract shows how an example 2D plane strain problem can  The following \PYTHON extract shows how an example 2D plane strain problem can
98  be set up.  be set up.
99
# Line 362  unknown \texttt{u}. Line 363  unknown \texttt{u}.
363  \end{methoddesc}  \end{methoddesc}
364  \begin{methoddesc}[NonlinearPDE]{setValue}{  \begin{methoddesc}[NonlinearPDE]{setValue}{
365  \optional{X}\optional{, Y}  \optional{X}\optional{, Y}
366  \optional{, y}\optional{, y_contact}  \optional{, y}
\optional{, y_dirac}
367  \optional{, q}\optional{, r}}  \optional{, q}\optional{, r}}
368  Assigns new values to coefficients. By default all values are assumed to be  Assigns new values to coefficients. By default all values are assumed to be
369  zero\footnote{In fact, it is assumed they are not present by assigning the  zero\footnote{In fact, it is assumed they are not present by assigning the

Legend:
 Removed from v.5099 changed lines Added in v.5100