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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4576 - (show annotations)
Mon Dec 9 23:35:30 2013 UTC (4 years, 10 months ago) by sshaw
File MIME type: text/x-python
File size: 3469 byte(s)
python3ified things, replaced mixed whitespace and xrange calls
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 # example11b.py
29 # Model of gravitational Potential.
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
47 from cblib import toRegGrid
48
49 ########################################################MPI WORLD CHECK
50 if getMPISizeWorld() > 1:
51 import sys
52 print("This example will not run in an MPI world.")
53 sys.exit(0)
54
55 #################################################ESTABLISHING VARIABLES
56 #Domain related.
57 mx = 1000*m #meters - model length
58 my = -250*m #meters - model depth
59 ndx = 200 # mesh steps in x direction
60 ndy = 200 # mesh steps in y direction - one dimension means one element
61 #PDE related
62 res1=500.0
63 res2=10.0
64 res3=10000.0
65 #con=1/res
66 cur=1000.
67
68 ################################################ESTABLISHING PARAMETERS
69 #the folder to put our outputs in, leave blank "" for script path
70 save_path= os.path.join("data","example11")
71 #ensure the dir exists
72 mkDir(save_path)
73
74 ####################################################DOMAIN CONSTRUCTION
75 domain = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
76 x=Solution(domain).getX()
77
78 kro=kronecker(domain)
79 source1=[3.*mx/8.,0]; source2=[5.*mx/8.,0]
80
81 c1=length(exp(-length(x-source1)/(10.))); c1=c1/integrate(c1)
82 c2=-length(exp(-length(x-source2)/(10.))); c2=c2/integrate(c2)
83 sourceg=cur*(c1-c2)
84
85 res=res1*wherePositive(x[1]-my/3)+res2*whereNegative(x[1]-my/3)*wherePositive(x[1]-my*2/3)+res3*whereNegative(x[1]-my*2/3)
86 con=1/res
87 q=whereZero(x[1]-my)+whereZero(x[0])+whereZero(x[0]-mx)
88 ###############################################ESCRIPT PDE CONSTRUCTION
89
90 mypde=LinearPDE(domain)
91 mypde.setValue(A=con*kro,Y=sourceg,q=q,r=0)
92 #mypde.setSymmetryOn()
93 sol=mypde.getSolution()
94
95 # Save the output to file.
96 saveVTK(os.path.join(save_path,"ex11b.vtu"),\
97 source=sourceg,\
98 res_pot=sol,\
99 res=res,\
100 curden=-con*grad(sol),\
101 efield=-grad(sol))

  ViewVC Help
Powered by ViewVC 1.1.26