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

Annotation of /trunk/doc/examples/cookbook/example10b.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3389 - (hide annotations)
Wed Dec 1 23:03:35 2010 UTC (8 years, 9 months ago) by ahallam
File MIME type: text/x-python
File size: 3401 byte(s)
Some changes to the cookbook examples. Starting Inversion experimentation.
1 ahallam 3135
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 ahallam 3195 # Model of gravitational Potential for a Gravity Well.
29 ahallam 3135
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.finley import Brick # This imports the rectangle domain function from finley
36 caltinay 3346 from esys.weipa import saveVTK # This imports the VTK file saver from weipa
37 ahallam 3135 import os, sys #This package is necessary to handle saving our data.
38    
39 ahallam 3389 from esys.escript.pdetools import Projector, Locator
40     import numpy as np
41    
42 ahallam 3135 ########################################################MPI WORLD CHECK
43     if getMPISizeWorld() > 1:
44     import sys
45     print "This example will not run in an MPI world."
46     sys.exit(0)
47    
48     #################################################ESTABLISHING VARIABLES
49     #Domain related.
50 ahallam 3389 mx = 500*m #meters - model length
51     my = 500*m #meters - model width
52     mz = -4000*m
53     ndx = 150 # mesh steps in x direction
54     ndy = 150 # mesh steps in y direction - one dimension means one element
55 ahallam 3374 ndz = 100
56 ahallam 3135 #PDE related
57 ahallam 3374 rho=100.0
58 ahallam 3135 rholoc=[0,0,-0]
59     G=6.67300*10E-11
60    
61     ################################################ESTABLISHING PARAMETERS
62     #the folder to put our outputs in, leave blank "" for script path
63     save_path= os.path.join("data","example10")
64     #ensure the dir exists
65     mkDir(save_path)
66    
67     ####################################################DOMAIN CONSTRUCTION
68     domain = Brick(l0=mx,l1=my,n0=ndx, n1=ndy,l2=mz,n2=ndz)
69     x=Solution(domain).getX()
70     x=x-[mx/2,my/2,mz/2]
71     domain.setX(x)
72     mask=wherePositive(100-length(x-rholoc))
73     rho=rho*mask
74     kro=kronecker(domain)
75    
76 ahallam 3389 mass=rho*vol(domain)
77     ipot=FunctionOnBoundary(domain)
78     xb=ipot.getX()
79    
80 ahallam 3135 q=whereZero(x[2]-inf(x[2]))
81     ###############################################ESCRIPT PDE CONSTRUCTION
82    
83     mypde=LinearPDE(domain)
84     mypde.setValue(A=kro,Y=4.*3.1415*G*rho,q=q,r=0)
85     mypde.setSymmetryOn()
86     sol=mypde.getSolution()
87     saveVTK(os.path.join(save_path,"ex10b.vtu"),\
88     grav_pot=sol,\
89     g_field=-grad(sol),\
90     g_fieldz=-grad(sol)*[0,0,1],\
91     gz=length(-grad(sol)*[0,0,1]))
92    
93 ahallam 3389 ################################################MODEL SIZE SAMPLING
94     sampler=[]
95     for i in range(-250,250,1):
96     sampler.append([i,0,250])
97    
98     sample=[] # array to hold values
99     rec=Locator(domain,sampler) #location to record
100     psol=rec.getValue(sol)
101     np.savetxt(os.path.join(save_path,"example10b_%04d.asc"%mx),psol)
102    

  ViewVC Help
Powered by ViewVC 1.1.26