/[escript]/trunk/doc/examples/cookbook/example11a.py
ViewVC logotype

Contents of /trunk/doc/examples/cookbook/example11a.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (show annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 6 months ago) by sshaw
File MIME type: text/x-python
File size: 3516 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1 ##############################################################################
2 #
3 # Copyright (c) 2009-2015 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Open Software License version 3.0
8 # http://www.opensource.org/licenses/osl-3.0.php
9 #
10 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 # Development 2012-2013 by School of Earth Sciences
12 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 #
14 ##############################################################################
15 from __future__ import division, print_function
16
17 __copyright__="""Copyright (c) 2009-2015 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 """
25 Author: Antony Hallam antony.hallam@uqconnect.edu.au
26 """
27
28 ############################################################FILE HEADER
29 # example11a.py
30 # Model of electrical potential in a half-space.
31
32 #######################################################EXTERNAL MODULES
33 # To solve the problem it is necessary to import the modules we require.
34 import matplotlib
35 matplotlib.use('agg') #It's just here for automated testing
36 import os, sys #This package is necessary to handle saving our data.
37 from math import pi, sqrt, sin, cos
38 import numpy as np
39 import pylab as pl #Plotting package
40
41 from esys.escript import * # This imports everything from the escript library
42 from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE
43 from esys.escript.pdetools import Projector
44 from esys.escript.unitsSI import *
45 from esys.weipa import saveVTK
46 from cblib import toRegGrid
47
48 try:
49 from esys.finley import Rectangle
50 HAVE_FINLEY = True
51 except ImportError:
52 print("Finley module not available")
53 HAVE_FINLEY = False
54 ########################################################MPI WORLD CHECK
55 if getMPISizeWorld() > 1:
56 import sys
57 print("This example will not run in an MPI world.")
58 sys.exit(0)
59
60 if HAVE_FINLEY:
61 #################################################ESTABLISHING VARIABLES
62 #Domain related.
63 mx = 2000*m #meters - model length
64 my = -1000*m #meters - model depth
65 ndx = 200 # mesh steps in x direction
66 ndy = 100 # mesh steps in y direction - one dimension means one element
67 #PDE related
68 res=1000.0
69 con=1/res
70 cur=10.
71
72 ################################################ESTABLISHING PARAMETERS
73 #the folder to put our outputs in, leave blank "" for script path
74 save_path= os.path.join("data","example11")
75 #ensure the dir exists
76 mkDir(save_path)
77
78 ####################################################DOMAIN CONSTRUCTION
79 domain = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
80 x=Solution(domain).getX()
81
82 kro=kronecker(domain)
83 source1=[mx/4.,0]; source2=[3.*mx/4.,0]
84
85 sourceg=length(exp(-length(x-source1)/(100.)))+length(exp(-length(x-source2)/(100.)))
86 sourceg=sourceg/integrate(sourceg)
87
88 q=whereZero(x[1]-my)+whereZero(x[0])+whereZero(x[0]-mx)
89 ###############################################ESCRIPT PDE CONSTRUCTION
90
91 mypde=LinearPDE(domain)
92 mypde.setValue(A=kro*con,Y=sourceg,q=q,r=0)
93 mypde.setSymmetryOn()
94 sol=mypde.getSolution()
95
96 # Save the output to file.
97 saveVTK(os.path.join(save_path,"ex11a.vtu"),source=sourceg,res_pot=sol)

  ViewVC Help
Powered by ViewVC 1.1.26