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

  ViewVC Help
Powered by ViewVC 1.1.26