/[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 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 3127 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 electrical potential in a half-space.
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 import matplotlib
41 matplotlib.use('agg') #It's just here for automated testing
42 from esys.escript.pdetools import Projector
43 from cblib import toRegGrid
44
45
46 import pylab as pl #Plotting package
47 import numpy as np
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 = 2000*m #meters - model length
58 my = -1000*m #meters - model depth
59 ndx = 200 # mesh steps in x direction
60 ndy = 100 # mesh steps in y direction - one dimension means one element
61 #PDE related
62 res=1000.0
63 con=1/res
64 cur=10.
65
66 ################################################ESTABLISHING PARAMETERS
67 #the folder to put our outputs in, leave blank "" for script path
68 save_path= os.path.join("data","example11")
69 #ensure the dir exists
70 mkDir(save_path)
71
72 ####################################################DOMAIN CONSTRUCTION
73 domain = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
74 x=Solution(domain).getX()
75
76 kro=kronecker(domain)
77 source1=[mx/4.,0]; source2=[3.*mx/4.,0]
78
79 sourceg=length(exp(-length(x-source1)/(100.)))+length(exp(-length(x-source2)/(100.)))
80 sourceg=sourceg/integrate(sourceg)
81
82 q=whereZero(x[1]-my)+whereZero(x[0])+whereZero(x[0]-mx)
83 ###############################################ESCRIPT PDE CONSTRUCTION
84
85 mypde=LinearPDE(domain)
86 mypde.setValue(A=kro*con,Y=sourceg,q=q,r=0)
87 mypde.setSymmetryOn()
88 sol=mypde.getSolution()
89
90 # Save the output to file.
91 saveVTK(os.path.join(save_path,"ex11a.vtu"),source=sourceg,res_pot=sol)

  ViewVC Help
Powered by ViewVC 1.1.26