ViewVC logotype

Contents of /trunk/doc/cookbook/escpybas.tex

Parent Directory Parent Directory | Revision Log Revision Log

Revision 2870 - (show annotations)
Mon Jan 25 08:34:15 2010 UTC (9 years, 6 months ago) by gross
File MIME type: application/x-tex
File size: 5734 byte(s)
more review on the cookbook.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % Copyright (c) 2003-2009 by University of Queensland
5 % Earth Systems Science Computational Center (ESSCC)
6 % http://www.uq.edu.au/esscc
7 %
8 % Primary Business: Queensland, Australia
9 % Licensed under the Open Software License version 3.0
10 % http://www.opensource.org/licenses/osl-3.0.php
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 \section{Escript and Python Basics} \label{sec:escpybas}
16 The \pyt scripting language is a powerful and easy to learn environment with a wide variety of applications. \esc has been developed as a packaged module for \pyt specifically to solve complex partial differential equations. As a result, all the conventions and programming syntax associated with \pyt are coherrent with \esc. If you are unfamiliar with \pyt, there are a large number of simple to advanced guides and tutorials availabe online. These texts should provide an introduction that is comprehensive enough for the use of \esc. A handful of \pyt tutorials have been listed below.
17 \begin{itemize}
18 \item This is a very crisp introduction \url{http://hetland.org/writing/instant-python.html}. It covers everthing you need to get started with \esc.
19 \item A nice and easy to follow introduction: \url{http://www.sthurlow.com/python/}
20 \item Another crisp tutorial \url{http://www.zetcode.com/tutorials/pythontutorial/}.
21 \item A very comprehensive tutorial from the \pyt authors: \url{http://www.python.org/doc/2.5.2/tut/tut.html}. It covers much more than what you will ever need for \esc.
22 \item Another comprehensive tutorial: \url{http://www.tutorialspoint.com/python/index.htm}
23 \end{itemize}
25 \subsection{The \modesys Modules}
26 \esc is part of the \esys package.
27 Besides the particle simualation code
28 \verb|ESyS-Particle|\footnote{see \url{https://launchpad.net/esys-particle}} which is not covered
29 in this tutorial \esys includes the following modules
30 \begin{enumerate}
31 \item \modescript is the PDE solving module.
32 \item \modfinley is the discretisation tool and finite element package.
33 \item \modpycad is a special development for creating irregular shaped domains.
34 \end{enumerate}
35 Further explanations on each of these is available in the \esc user guide or in the API documentation\footnote{Available from \url{https://launchpad.net/escript-finley/+download}}.
36 \esc is also dependent on a few other open-source packages which are not maintained by the \esc development team. These are \modnumpy an array and matrix handling package, \modmpl \footnote{\modnumpy and \modmpl are part of the SciPy package, see \url{http://www.scipy.org/}} a simple plotting tool, \modvtk \footnote{See \url{http://www.vtk.org/}} an advanced visualisation package and \verb gmsh \footnote{See \url{http://www.geuz.org/gmsh/}} which is required by \modpycad. These packages (\textbf{except} for \verb gmsh ) are included with the support bundles.
38 \subsection{File Commands and Operations in \esc}
39 A number of common file operations and commands are used throughout this cookbook. It is often advantageous to implement these commands when large numbers of output files are generated or dependencies are located in other locations.
41 To develop an incrementing file name we can use the following convention. For this example we are going to use the \verb|os.path.join| command to join a subdirectory which already exists with the file name which we want to use for our output. The command is;
42 \begin{python}
43 os.path.join(save_path, "data%03d.xml"%i )
44 \end{python}
45 There are two arguments to the \verb join command. The \verb save_path variable is a predefined string pointing to the directory we want to save our data in, for example a single subfolder called \verb data would be defined by;
46 \begin{verbatim}
47 save_path = "data"
48 \end{verbatim}
49 while a subfolder of \verb data called \verb ans_one would be defined by;
50 \begin{verbatim}
51 save_path = "data/ans_one"
52 \end{verbatim}
53 The second argument of \verb join \xspace contains a string which is the filename. We can use the operator \verb|%| to increment our file names with the value \verb|i| denoting a incrementing counter. The substring \verb %03d does this by defining the following parameters;
54 \begin{itemize}
55 \item \verb 0 becomes the padding number;
56 \item \verb 3 tells us the amount of padding numbers that are required; and
57 \item \verb d indicates the end of the \verb % operator.
58 \end{itemize}
59 To increment the file name a \verb %i is required directly after the operation the string is involved in. When correctly implemented the output files from this command would be place in the directory defined by \verb save_path as;
60 \begin{verbatim}
61 data001.xml
62 data002.xml
63 data003.xml
64 ...
65 \end{verbatim}
66 and so on.
68 A subfolder check/constructor is available in the cookbook \verb cblib library called \verb needdirs . The command;
69 \begin{verbatim}
70 needdirs(save_path)
71 \end{verbatim}
72 will check for the existence of \verb save_path and if missing, make the required directories.
75 \subsection{Visualisation and Plotting}
76 \esc does not include its own plotting capabilities. However, it is possible to use a variety of free \pyt packages for visualisation.
77 Two types will be demonstrated in this cookbook; \mpl\footnote{\url{http://matplotlib.sourceforge.net/}} and \verb VTK \footnote{\url{http://www.vtk.org/}} visualisation.
78 The \mpl package is a component of SciPy\footnote{\url{http://www.scipy.org}} and is good for basic graphs and plots. The \verb VTK toolkit allows the \esc data to be exported in a standardised format with powerful visualisation capabilities. This format can be interpreted by many programs, \mayavi \footnote{\url{http://code.enthought.com/projects/mayavi/}} as an example.

  ViewVC Help
Powered by ViewVC 1.1.26