/[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 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 9 months ago) by jfenwick
File MIME type: text/x-python
File size: 3365 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



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

  ViewVC Help
Powered by ViewVC 1.1.26