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

Contents of /trunk/doc/examples/cookbook/example11c.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: 4074 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 # example11c.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
37 import os, sys #This package is necessary to handle saving our data.
38 from math import pi, sqrt, sin, cos
39 import pylab as pl #Plotting package
40 import numpy as np
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 ReadMesh,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
65
66 mx = 500*m #meters - model length
67 my = 500*m #meters - model depth
68 mz = 250
69 ndx = 200 # mesh steps in x direction
70 ndy = 200 # mesh steps in y direction - one dimension means one element
71 #PDE related
72 res1=500.0
73 res2=10.0
74 res3=1000.0
75 res4=10000.0
76 #con=1/res
77 cur=1000.
78
79 ################################################ESTABLISHING PARAMETERS
80 #the folder to put our outputs in, leave blank "" for script path
81 save_path= os.path.join("data","example11")
82 #ensure the dir exists
83 mkDir(save_path)
84
85 ####################################################DOMAIN CONSTRUCTION
86 domain=ReadMesh(os.path.join(save_path,'example11lc.fly')) # create the domain
87
88 res=Scalar(0,Function(domain))
89 res.setTaggedValue("volume_0",res1)
90 res.setTaggedValue("volume_1",res2)
91 res.setTaggedValue("volume_2",res3)
92 res.setTaggedValue("volume_3",res4)
93 con=1/res
94 x=Solution(domain).getX()
95
96 kro=kronecker(domain)
97 source1=[3.*mx/8.,my/2,0]; source2=[5.*mx/8.,my/2,0]
98
99 c1=length(exp(-length(x-source1)/(10.))); c1=c1/integrate(c1)
100 c2=-length(exp(-length(x-source2)/(10.))); c2=c2/integrate(c2)
101 sourceg=cur*(c1-c2)
102
103 q=whereZero(x[1]-my)+whereZero(x[1])+whereZero(x[0])+whereZero(x[0]-mx)+whereZero(x[2]-mz)
104 ###############################################ESCRIPT PDE CONSTRUCTION
105
106 mypde=LinearPDE(domain)
107 mypde.setValue(A=con*kro,Y=sourceg,q=q,r=0)
108 #mypde.setSymmetryOn()
109 sol=mypde.getSolution()
110
111 res.expand()
112
113 # Save the output to file.
114 saveVTK(os.path.join(save_path,"ex11c.vtu"),\
115 source=sourceg,\
116 res_pot=sol,\
117 res=res,\
118 curden=-con*grad(sol),\
119 abscd=length(-con*grad(sol)),\
120 efield=-grad(sol))
121

  ViewVC Help
Powered by ViewVC 1.1.26