/[escript]/trunk/doc/user/firststep.tex
ViewVC logotype

Diff of /trunk/doc/user/firststep.tex

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 565 by gross, Mon Feb 27 00:04:17 2006 UTC revision 660 by gross, Fri Mar 24 08:43:21 2006 UTC
# Line 1  Line 1 
1  % $Id$  % $Id$
2    %
3    %           Copyright © 2006 by ACcESS MNRF
4    %               \url{http://www.access.edu.au
5    %         Primary Business: Queensland, Australia.
6    %   Licensed under the Open Software License version 3.0
7    %      http://www.opensource.org/licenses/osl-3.0.php
8    %
9    
10    
11  \section{The First Steps}  \section{The First Steps}
12  \label{FirstSteps}  \label{FirstSteps}
13    
14  \begin{figure}  \begin{figure}
15  \centerline{\includegraphics[width=\figwidth]{FirstStepDomain}}  \centerline{\includegraphics[width=\figwidth]{figures/FirstStepDomain}}
16  \caption{Domain $\Omega=[0,1]^2$ with outer normal field $n$.}  \caption{Domain $\Omega=[0,1]^2$ with outer normal field $n$.}
17  \label{fig:FirstSteps.1}  \label{fig:FirstSteps.1}
18  \end{figure}  \end{figure}
# Line 69  With the summation convention we can wri Line 77  With the summation convention we can wri
77  - u\hackscore{,ii} =1  - u\hackscore{,ii} =1
78  \label{eq:FirstSteps.1.sum}  \label{eq:FirstSteps.1.sum}
79  \end{equation}  \end{equation}
80    where $f=1$ in this example.
81    
82  On the boundary of the domain $\Omega$ the normal derivative $n\hackscore{i} u\hackscore{,i}$  On the boundary of the domain $\Omega$ the normal derivative $n\hackscore{i} u\hackscore{,i}$
83  of the solution $u$ shall be zero, ie. $u$ shall fulfill  of the solution $u$ shall be zero, ie. $u$ shall fulfill
84  the homogeneous Neumann boundary condition\index{Neumann  the homogeneous Neumann boundary condition\index{Neumann
# Line 115  function $u$. Line 125  function $u$.
125    
126    
127  \begin{figure}  \begin{figure}
128  \centerline{\includegraphics[width=\figwidth]{FirstStepMesh}}  \centerline{\includegraphics[width=\figwidth]{figures/FirstStepMesh.eps}}
129  \caption{Mesh of $4 \time 4$ elements on a rectangular domain.  Here  \caption{Mesh of $4 \time 4$ elements on a rectangular domain.  Here
130  each element is a quadrilateral and described by four nodes, namely  each element is a quadrilateral and described by four nodes, namely
131  the corner points. The solution is interpolated by a bi-linear  the corner points. The solution is interpolated by a bi-linear
# Line 130  method} (FEM\index{finite element Line 140  method} (FEM\index{finite element
140  method!FEM}). The basic idea is to fill the domain with a  method!FEM}). The basic idea is to fill the domain with a
141  set of points called nodes. The solution is approximated by its  set of points called nodes. The solution is approximated by its
142  values on the nodes\index{finite element  values on the nodes\index{finite element
143  method!nodes}. Moreover, the domain is subdivided into small,  method!nodes}. Moreover, the domain is subdivided into smaller
144  sub-domain called elements \index{finite element  sub-domains called elements \index{finite element
145  method!element}. On each element the solution is  method!element}. On each element the solution is
146  represented by a polynomial of a certain degree through its values at  represented by a polynomial of a certain degree through its values at
147  the nodes located in the element. The nodes and its connection through  the nodes located in the element. The nodes and its connection through
# Line 181  and $0$ elsewhere. In our case of $\Gamm Line 191  and $0$ elsewhere. In our case of $\Gamm
191  we need to construct a function \var{gammaD} which is positive for the cases $x\hackscore{0}=0$ or $x\hackscore{1}=0$. To get  we need to construct a function \var{gammaD} which is positive for the cases $x\hackscore{0}=0$ or $x\hackscore{1}=0$. To get
192  an object \var{x} which represents locations in the domain one uses  an object \var{x} which represents locations in the domain one uses
193  \begin{python}  \begin{python}
194  x=mydomain.getX() \;.  x=mydomain.getX()
195  \end{python}  \end{python}
196  In fact \var{x} is a \Data object which we will learn more about in Chapter~\ref{X}. At this stage we only have to know  The method \method{getX} of the \Domain \var{mydomain}
 that \var{x} has a  
   
 In the first statement, the method \method{getX} of the \Domain \var{mydomain}  
197  gives access to locations  gives access to locations
198  in the domain defined by \var{mydomain}. The object \var{x} is actually a \Data object which is  in the domain defined by \var{mydomain}. The object \var{x} is actually a \Data object which is
199  discussed in Chpater\ref{X} in more details. What we need to know here is that  discussed in \Chap{ESCRIPT CHAP} in more details. What we need to know here is that
200    
201  \var{x} has \Rank (=number of dimensions) and a \Shape (=tuple of dimensions) which can be checked by  \var{x} has \Rank (=number of dimensions) and a \Shape (=tuple of dimensions) which can be checked by
202  calling the \method{getRank} and \method{getShape} methods:  calling the \method{getRank} and \method{getShape} methods:
203  \begin{python}  \begin{python}
# Line 226  will print Line 234  will print
234  \end{python}  \end{python}
235  We can now construct the function \var{gammaD} by  We can now construct the function \var{gammaD} by
236  \begin{python}  \begin{python}
237    from esys.escript import whereZero
238  gammaD=whereZero(x[0])+whereZero(x[1])  gammaD=whereZero(x[0])+whereZero(x[1])
239  \end{python}  \end{python}
240  where  where
# Line 252  from esys.linearPDEs import Poisson Line 261  from esys.linearPDEs import Poisson
261  x = mydomain.getX()  x = mydomain.getX()
262  gammaD = whereZero(x[0])+whereZero(x[1])  gammaD = whereZero(x[0])+whereZero(x[1])
263  mypde = Poisson(domain=mydomain)  mypde = Poisson(domain=mydomain)
264  mypde = setValue(f=1,q=gammaD)  mypde.setValue(f=1,q=gammaD)
265  \end{python}  \end{python}
266  The first statement imports the \Poisson class definition form the \linearPDEs module \escript package.  The first statement imports the \Poisson class definition from the \linearPDEs module \escript package.
267  To get the solution of the Poisson equation defined by \var{mypde} we just have to call its  To get the solution of the Poisson equation defined by \var{mypde} we just have to call its
268  \method{getSolution}.  \method{getSolution}.
269    
270  Now we can write the script to solve our test problem (Remember that  Now we can write the script to solve our test problem (Remember that
271  lines starting with '\#' are comment lines in Python) (available as \file{mypoisson.py}  lines starting with '\#' are comment lines in Python) (available as \file{poisson.py}
272  in the \ExampleDirectory):  in the \ExampleDirectory):
273  \begin{python}  \begin{python}
274  from esys.escript import *  from esys.escript import *
275  from linearPDEs import Poisson  from esys.escript.linearPDEs import Poisson
276  from esys.finley import Rectangle  from esys.finley import Rectangle
277  # generate domain:  # generate domain:
278  mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)  mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
# Line 280  saveVTK("u.xml",sol=u) Line 289  saveVTK("u.xml",sol=u)
289  The last statement writes the solution tagged with the name "sol" to the external file \file{u.xml} in  The last statement writes the solution tagged with the name "sol" to the external file \file{u.xml} in
290  \VTK file format. \VTK is a software library  \VTK file format. \VTK is a software library
291  for the visualization of scientific, engineering and analytical data and is freely available  for the visualization of scientific, engineering and analytical data and is freely available
292  from \url{http://www.vtk.org}. There are a variaty of graphical user interfaces  from \url{http://www.vtk.org}. There are a variety of graphical user interfaces
293  for \VTK available, for instance \mayavi which can be downloaded from \url{http://mayavi.sourceforge.net/} but is also available on most  for \VTK available, for instance \mayavi which can be downloaded from \url{http://mayavi.sourceforge.net/} but is also available on most
294  \LINUX distributions.  \LINUX distributions.
295    
296  \begin{figure}  \begin{figure}
297  \centerline{\includegraphics[width=\figwidth]{FirstStepResult.eps}}  \centerline{\includegraphics[width=\figwidth]{figures/FirstStepResult.eps}}
298  \caption{Visualization of the Possion Equation Solution for $f=1$}  \caption{Visualization of the Poisson Equation Solution for $f=1$}
299  \label{fig:FirstSteps.3}  \label{fig:FirstSteps.3}
300  \end{figure}  \end{figure}
301    
302  You can edit the script file using your favourite text editor (or the Integrated DeveLopment Environment IDLE  You can edit the script file using your favourite text editor (or the Integrated DeveLopment Environment IDLE
303  for Python, see \url{http://idlefork.sourceforge.net}). If the script file has the name \file{mypoisson.py} \index{scripts!\file{mypoisson.py}} you can run the  for Python, see \url{http://idlefork.sourceforge.net}). If the script file has the name \file{poisson.py} \index{scripts!\file{poisson.py}} you can run the
304  script from any shell using the command:  script from any shell using the command:
305  \begin{python}  \begin{python}
306  python mypoisson.py  python poisson.py
307  \end{python}  \end{python}
308  After the script has (hopefully successfully) been completed you will find the file \file{u.dx} in the current  After the script has (hopefully successfully) been completed you will find the file \file{u.xml} in the current
309  directory. An easy way to visualize the results is the command  directory. An easy way to visualize the results is the command
310  \begin{python}  \begin{python}
311  mayavi -d u.xml -m SurfaceMap &  mayavi -d u.xml -m SurfaceMap &

Legend:
Removed from v.565  
changed lines
  Added in v.660

  ViewVC Help
Powered by ViewVC 1.1.26