/[escript]/trunk/doc/cookbook/example01.tex
ViewVC logotype

Diff of /trunk/doc/cookbook/example01.tex

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

revision 2963 by artak, Wed Mar 3 01:10:11 2010 UTC revision 2964 by artak, Wed Mar 3 01:21:09 2010 UTC
# Line 400  if the system is configured correctly (P Line 400  if the system is configured correctly (P
400  \esc does not include its own plotting capabilities. However, it is possible to use a variety of free \pyt packages for visualisation.  \esc does not include its own plotting capabilities. However, it is possible to use a variety of free \pyt packages for visualisation.
401  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.  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.
402  The \mpl package is a component of SciPy\footnote{\url{http://www.scipy.org}} and is good for basic graphs and plots.  The \mpl package is a component of SciPy\footnote{\url{http://www.scipy.org}} and is good for basic graphs and plots.
403  For more complex visualisation tasks in particular when it comes to  two and three dimensional problems it is recommended to us more advanced tools for instance  \mayavi \footnote{\url{http://code.enthought.com/projects/mayavi/}}  For more complex visualisation tasks in particular when it comes to  two and three dimensional problems we recommend to use more advanced tools for instance  \mayavi \footnote{\url{http://code.enthought.com/projects/mayavi/}}
404  which bases on the \verb|VTK| toolkit. We will discuss the usage of \verb|VTK| based  which bases on the \verb|VTK| toolkit. We discuss the usage of \verb|VTK| based
405  visualization in Chapter~\ref{Sec:2DHD} where will discuss a two dimensional PDE.  visualization in Chapter~\ref{Sec:2DHD} where focus on a two dimensional PDE.
406    
407  For our simple problem we have two plotting tasks: Firstly we are interested in showing the  For our simple problem we have two plotting tasks: we are interested in showing the
408  behaviour of the total energy over time and secondly in how the temperature distribution within the block is  behaviour of the total energy over time and how the temperature distribution within the block is
409  developing over time. Lets start with the first task.  developing over time. Lets start with the first task.
410    
411  The trick is to create a record of the time marks and the corresponding total energies observed.  The trick is to create a record of the time marks and the corresponding total energies observed.
412  \pyt provides the concept of lists for this. Before  \pyt provides the concept of lists for this. Before
413  the time loop is opened we create empty lists for the time marks \verb|t_list| and the total energies \verb|E_list|.  the time loop is opened we create empty lists for the time marks \verb|t_list| and the total energies \verb|E_list|.
414  After the new temperature as been calculated by solving the PDE we append the new time marker and total energy  After the new temperature as been calculated by solving the PDE we append the new time marker and total energy
415  to the corresponding list using the \verb|append| method. With these modifications the script looks as follows:  to the corresponding list using the \verb|append| method. With these modifications our script looks as follows:
416  \begin{python}  \begin{python}
417  t_list=[]  t_list=[]
418  E_list=[]  E_list=[]
# Line 467  import os Line 467  import os
467  os.path.join(save_path, "tempT%03d.png"%i )  os.path.join(save_path, "tempT%03d.png"%i )
468  \end{python}  \end{python}
469  where \verb|i| is the time step counter.  where \verb|i| is the time step counter.
470  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 sub-folder called \verb data  would be defined by;  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, for example a single sub-folder called \verb data  would be defined by;
471  \begin{verbatim}  \begin{verbatim}
472  save_path = "data"  save_path = "data"
473  \end{verbatim}  \end{verbatim}
# Line 497  mkDir(save_path) Line 497  mkDir(save_path)
497  \end{verbatim}  \end{verbatim}
498  will check for the existence of \verb save_path  and if missing, make the required directories.  will check for the existence of \verb save_path  and if missing, make the required directories.
499    
500  We start by modifying our solution script from before.  We start by modifying our solution script.
501  Prior to the \verb|while| loop we will need to extract our finite solution points to a data object that is compatible with \mpl. First we create the node coordinates of the sample points used to represent  Prior to the \verb|while| loop we will need to extract our finite solution points to a data object that is compatible with \mpl. First we create the node coordinates of the sample points used to represent
502  the temperature as a \pyt list of tuples or a \numpy array as requested by the plotting function.  the temperature as a \pyt list of tuples or a \numpy array as requested by the plotting function.
503  We need to convert thearray \verb|x| previously set as \verb|Solution(blocks).getX()| into a \pyt list  We need to convert the array \verb|x| previously set as \verb|Solution(blocks).getX()| into a \pyt list
504  and then to a \numpy array. The $x\hackscore{0}$ component is then extracted via an array slice to the variable \verb|plx|;  and then to a \numpy array. The $x\hackscore{0}$ component is then extracted via an array slice to the variable \verb|plx|;
505  \begin{python}  \begin{python}
506  import numpy as np # array package.  import numpy as np # array package.
# Line 520  plx = plx[:,0] # extract x locations Line 520  plx = plx[:,0] # extract x locations
520  \end{center}  \end{center}
521  \end{figure}  \end{figure}
522    
523  For each time step we will generate a plot of the temperature distribution and save each to a file. We use the same  We use the same techniques provided by \mpl as we have used to plot the total energy over time.
524  techniques provided by \mpl as we have used to plot the total energy over time.  For each time step we generate a plot of the temperature distribution and save each to a file.
525  The following is appended to the end of the \verb while  loop and creates one figure of the temperature distribution. We start by converting the solution to a tuple and then plotting this against our \textit{x coordinates} \verb plx  we have generated before. We add a title to the diagram before it is rendered into a file.  The following is appended to the end of the \verb while  loop and creates one figure of the temperature distribution. We start by converting the solution to a tuple and then plotting this against our \textit{x coordinates} \verb plx  we have generated before. We add a title to the diagram before it is rendered into a file.
526  Finally, the figure is saved to a \verb|*.png| file and cleared for the following iteration.  Finally, the figure is saved to a \verb|*.png| file and cleared for the following iteration.
527  \begin{python}  \begin{python}
# Line 541  while t<tend: Line 541  while t<tend:
541  Some results are shown in \reffig{fig:onedheatout}.  Some results are shown in \reffig{fig:onedheatout}.
542    
543  \subsection{Make a video}  \subsection{Make a video}
544  Our saved plots from the previous section can be cast into a video using the following command appended to the end of the script. \verb mencoder  is Linux only however, and other platform users will need to use an alternative video encoder.  Our saved plots from the previous section can be cast into a video using the following command appended to the end of the script. The \verb mencoder command is Linux only, so other platform users need to use an alternative video encoder.
545  \begin{python}  \begin{python}
546  # compile the *.png files to create a *.avi videos that show T change  # compile the *.png files to create a *.avi videos that show T change
547  # with time. This operation uses Linux mencoder. For other operating  # with time. This operation uses Linux mencoder. For other operating

Legend:
Removed from v.2963  
changed lines
  Added in v.2964

  ViewVC Help
Powered by ViewVC 1.1.26