/[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 5288 - (show annotations)
Tue Dec 2 23:18:40 2014 UTC (4 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 3530 byte(s)
fixing tests for cases where required domains not built
1 from __future__ import division
2 from __future__ import print_function
3 ##############################################################################
4 #
5 # Copyright (c) 2009-2014 by University of Queensland
6 # http://www.uq.edu.au
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 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 # Development 2012-2013 by School of Earth Sciences
14 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
15 #
16 ##############################################################################
17
18 __copyright__="""Copyright (c) 2009-2014 by University of Queensland
19 http://www.uq.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Open Software License version 3.0
22 http://www.opensource.org/licenses/osl-3.0.php"""
23 __url__="https://launchpad.net/escript-finley"
24
25 """
26 Author: Antony Hallam antony.hallam@uqconnect.edu.au
27 """
28
29 ############################################################FILE HEADER
30 # example11a.py
31 # Model of electrical potential in a half-space.
32
33 #######################################################EXTERNAL MODULES
34 # To solve the problem it is necessary to import the modules we require.
35 import matplotlib
36 matplotlib.use('agg') #It's just here for automated testing
37 import os, sys #This package is necessary to handle saving our data.
38 from math import pi, sqrt, sin, cos
39 import numpy as np
40 import pylab as pl #Plotting package
41
42 from esys.escript import * # This imports everything from the escript library
43 from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE
44 from esys.escript.pdetools import Projector
45 from esys.escript.unitsSI import *
46 from esys.weipa import saveVTK
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 = 2000*m #meters - model length
65 my = -1000*m #meters - model depth
66 ndx = 200 # mesh steps in x direction
67 ndy = 100 # mesh steps in y direction - one dimension means one element
68 #PDE related
69 res=1000.0
70 con=1/res
71 cur=10.
72
73 ################################################ESTABLISHING PARAMETERS
74 #the folder to put our outputs in, leave blank "" for script path
75 save_path= os.path.join("data","example11")
76 #ensure the dir exists
77 mkDir(save_path)
78
79 ####################################################DOMAIN CONSTRUCTION
80 domain = Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
81 x=Solution(domain).getX()
82
83 kro=kronecker(domain)
84 source1=[mx/4.,0]; source2=[3.*mx/4.,0]
85
86 sourceg=length(exp(-length(x-source1)/(100.)))+length(exp(-length(x-source2)/(100.)))
87 sourceg=sourceg/integrate(sourceg)
88
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=kro*con,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,"ex11a.vtu"),source=sourceg,res_pot=sol)

  ViewVC Help
Powered by ViewVC 1.1.26