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

  ViewVC Help
Powered by ViewVC 1.1.26