/[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 564 by jgs, Wed Nov 9 02:02:19 2005 UTC revision 565 by gross, Mon Feb 27 00:04:17 2006 UTC
# Line 165  see \Chap{CHAPTER ON FINLEY}. Line 165  see \Chap{CHAPTER ON FINLEY}.
165  The following statements define the \Poisson class object \var{mypde} with domain \var{mydomain} and  The following statements define the \Poisson class object \var{mypde} with domain \var{mydomain} and
166  the right hand side $f$ of the PDE to constant $1$:  the right hand side $f$ of the PDE to constant $1$:
167  \begin{python}  \begin{python}
168  from esys.escript import Poisson  from esys.escript.linearPDEs import Poisson
169  mypde = Poisson(mydomain)  mypde = Poisson(mydomain)
170  mypde.setValue(f=1)  mypde.setValue(f=1)
171  \end{python}  \end{python}
# Line 178  a Dirichlet boundary condition \index{Di Line 178  a Dirichlet boundary condition \index{Di
178  by defining a characteristic function \index{characteristic function}  by defining a characteristic function \index{characteristic function}
179  which has positive values at locations $x=(x\hackscore{0},x\hackscore{1})$ where Dirichlet boundary condition is set  which has positive values at locations $x=(x\hackscore{0},x\hackscore{1})$ where Dirichlet boundary condition is set
180  and $0$ elsewhere. In our case of $\Gamma^D$ defined by \eqn{eq:FirstSteps.2c},  and $0$ elsewhere. In our case of $\Gamma^D$ defined by \eqn{eq:FirstSteps.2c},
181  we need a function which is positive for the cases $x\hackscore{0}=0$ or $x\hackscore{1}=0$:    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
182    an object \var{x} which represents locations in the domain one uses
183  \begin{python}  \begin{python}
184  x=mydomain.getX()  x=mydomain.getX() \;.
 gammaD=x[0].whereZero()+x[1].whereZero()  
185  \end{python}  \end{python}
186    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
187    that \var{x} has a
188    
189  In the first statement, the method \method{getX} of the \Domain \var{mydomain}  In the first statement, the method \method{getX} of the \Domain \var{mydomain}
190  gives access to locations  gives access to locations
191  in the domain defined by \var{mydomain}. The object \var{x} is actually a \Data object  in the domain defined by \var{mydomain}. The object \var{x} is actually a \Data object which is
192  which we will learn more about later. \code{x[0]} returns the $x\hackscore{0}$ coordinates of the locations and  discussed in Chpater\ref{X} in more details. What we need to know here is that
193  \code{x[0].whereZero()} creates function which equals $1$ where \code{x[0]} is (nearly) equal to zero  \var{x} has \Rank (=number of dimensions) and a \Shape (=tuple of dimensions) which can be checked by
194    calling the \method{getRank} and \method{getShape} methods:
195    \begin{python}
196    print "rank ",x.getRank(),", shape ",x.getShape()
197    \end{python}
198    will print something like
199    \begin{python}
200    rank 1, shape (2,)
201    \end{python}
202    The \Data object also maintains type information which is represented by the
203    \FunctionSpace of the object. For instance
204    \begin{python}
205    print x.getFunctionSpace()
206    \end{python}
207    will print
208    \begin{python}
209    Function space type: Finley_Nodes on FinleyMesh
210    \end{python}
211    which tells us that the coordinates are stored on the nodes of a \finley mesh.
212    To get the  $x\hackscore{0}$ coordinates of the locations we use the
213    statement
214    \begin{python}
215    x0=x[0]
216    \end{python}
217    Object \var{x0}
218    is again a \Data object now with \Rank $0$ and
219    \Shape $()$. It inherits the \FunctionSpace from \var{x}:
220    \begin{python}
221    print x0.getRank(),x0.getShape(),x0.getFunctionSpace()
222    \end{python}
223    will print
224    \begin{python}
225    0 () Function space type: Finley_Nodes on FinleyMesh
226    \end{python}
227    We can now construct the function \var{gammaD} by
228    \begin{python}
229    gammaD=whereZero(x[0])+whereZero(x[1])
230    \end{python}
231    where
232    \code{whereZero(x[0])} creates function which equals $1$ where \code{x[0]} is (allmost) equal to zero
233  and $0$ elsewhere.  and $0$ elsewhere.
234  Similarly, \code{x[1].whereZero()} creates function which equals $1$ where \code{x[1]} is  Similarly, \code{whereZero(x[1])} creates function which equals $1$ where \code{x[1]} is
235  equal to zero and $0$ elsewhere.  equal to zero and $0$ elsewhere.
236  The sum of the results of \code{x[0].whereZero()} and \code{x[1].whereZero()} gives a function on the domain \var{mydomain} which is exactly positive where $x\hackscore{0}$ or $x\hackscore{1}$ is equal to zero.  The sum of the results of \code{whereZero(x[0])} and \code{whereZero(x[1])}
237    gives a function on the domain \var{mydomain} which is exactly positive where $x\hackscore{0}$ or $x\hackscore{1}$ is equal to zero.
238    Note that \var{gammaD} has the same \Rank, \Shape and \FunctionSpace like \var{x0} used to define it. So from
239    \begin{python}
240    print gammaD.getRank(),gammaD.getShape(),gammaD.getFunctionSpace()
241    \end{python}
242    one gets
243    \begin{python}
244    0 () Function space type: Finley_Nodes on FinleyMesh
245    \end{python}
246  The additional parameter \var{q} of the \code{setValue} method of the \Poisson class defines the  The additional parameter \var{q} of the \code{setValue} method of the \Poisson class defines the
247  characteristic function \index{characteristic function} of the locations  characteristic function \index{characteristic function} of the locations
248  of the domain where homogeneous Dirichlet boundary condition \index{Dirichlet boundary condition!homogeneous}  of the domain where homogeneous Dirichlet boundary condition \index{Dirichlet boundary condition!homogeneous}
# Line 200  are set. The complete definition of our Line 250  are set. The complete definition of our
250  \begin{python}  \begin{python}
251  from esys.linearPDEs import Poisson  from esys.linearPDEs import Poisson
252  x = mydomain.getX()  x = mydomain.getX()
253  gammaD = x[0].whereZero()+x[1].whereZero()  gammaD = whereZero(x[0])+whereZero(x[1])
254  mypde = Poisson(domain=mydomain)  mypde = Poisson(domain=mydomain)
255  mypde = setValue(f=1,q=gammaD)  mypde = setValue(f=1,q=gammaD)
256  \end{python}  \end{python}
257  The first statement imports the \Poisson class definition form the \linearPDEsPack module which is part of the \ESyS package.  The first statement imports the \Poisson class definition form the \linearPDEs module \escript package.
258  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
259  \method{getSolution}.  \method{getSolution}.
260    
# Line 212  Now we can write the script to solve our Line 262  Now we can write the script to solve our
262  lines starting with '\#' are comment lines in Python) (available as \file{mypoisson.py}  lines starting with '\#' are comment lines in Python) (available as \file{mypoisson.py}
263  in the \ExampleDirectory):  in the \ExampleDirectory):
264  \begin{python}  \begin{python}
265    from esys.escript import *
266    from linearPDEs import Poisson
267  from esys.finley import Rectangle  from esys.finley import Rectangle
 from esys.linearPDEs import Poisson  
268  # generate domain:  # generate domain:
269  mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)  mydomain = Rectangle(l0=1.,l1=1.,n0=40, n1=20)
270  # define characteristic function of Gamma^D  # define characteristic function of Gamma^D
271  x = mydomain.getX()  x = mydomain.getX()
272  gammaD = x[0].whereZero()+x[1].whereZero()  gammaD = whereZero(x[0])+whereZero(x[1])
273  # define PDE and get its solution u  # define PDE and get its solution u
274  mypde = Poisson(domain=mydomain,f=1,q=gammaD)  mypde = Poisson(domain=mydomain)
275    mypde.setValue(f=1,q=gammaD)
276  u = mypde.getSolution()  u = mypde.getSolution()
277  # write u to an external file  # write u to an external file
278  u.saveDX("u.dx")  saveVTK("u.xml",sol=u)
279  \end{python}  \end{python}
280  The last statement writes the solution to the external file \file{u.dx} in  The last statement writes the solution tagged with the name "sol" to the external file \file{u.xml} in
281  \OpenDX file format. \OpenDX is a software package  \VTK file format. \VTK is a software library
282  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
283  from \url{http://www.opendx.org}.  from \url{http://www.vtk.org}. There are a variaty of graphical user interfaces
284    for \VTK available, for instance \mayavi which can be downloaded from \url{http://mayavi.sourceforge.net/} but is also available on most
285    \LINUX distributions.
286    
287  \begin{figure}  \begin{figure}
288  \centerline{\includegraphics[width=\figwidth]{FirstStepResult.eps}}  \centerline{\includegraphics[width=\figwidth]{FirstStepResult.eps}}
289  \caption{\OpenDX Visualization of the Possion Equation Solution for $f=1$}  \caption{Visualization of the Possion Equation Solution for $f=1$}
290  \label{fig:FirstSteps.3}  \label{fig:FirstSteps.3}
291  \end{figure}  \end{figure}
292    
293  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
294  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{mypoisson.py} \index{scripts!\file{mypoisson.py}} you can run the
295  script from any shell using the command:  script from any shell using the command:
296  \begin{verbatim}  \begin{python}
297  python mypoisson.py  python mypoisson.py
298  \end{verbatim}  \end{python}
299  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.dx} in the current
300  directory. An easy way to visualize the results is the command  directory. An easy way to visualize the results is the command
301  \begin{verbatim}  \begin{python}
302  dx -prompter &  mayavi -d u.xml -m SurfaceMap &
303  \end{verbatim}  \end{python}
304  to start the generic data visualization interface of \OpenDX. \fig{fig:FirstSteps.3} shows the result.  to show the results, see \fig{fig:FirstSteps.3}.

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

  ViewVC Help
Powered by ViewVC 1.1.26