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

Contents of /trunk/doc/examples/cookbook/example10b.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: 3963 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 # example10a.py
31 # Model of gravitational Potential for a Gravity Well.
32
33 #######################################################EXTERNAL MODULES
34 # To solve the problem it is necessary to import the modules we require.
35 from esys.escript import * # This imports everything from the escript library
36 from esys.escript.unitsSI import *
37 from esys.escript.linearPDEs import LinearPDE # This defines LinearPDE as LinearPDE
38 from esys.weipa import saveVTK # This imports the VTK file saver from weipa
39 import os, sys #This package is necessary to handle saving our data.
40
41 from esys.escript.pdetools import Projector, Locator
42 import numpy as np
43
44 try:
45 # This imports the rectangle domain function
46 from esys.finley import Brick
47 HAVE_FINLEY = True
48 except ImportError:
49 print("Finley module not available")
50 HAVE_FINLEY = False
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 if HAVE_FINLEY:
58 #################################################ESTABLISHING VARIABLES
59 #Domain related.
60 mx = 500*m #meters - model length
61 my = 500*m #meters - model width
62 mz = -4000*m
63 ndx = 15 # mesh steps in x direction
64 ndy = 15 # mesh steps in y direction - one dimension means one element
65 ndz = 10
66 #PDE related
67 rho=100.0
68 rholoc=[0,0,-0]
69 G=6.67300*10E-11
70
71 ################################################ESTABLISHING PARAMETERS
72 #the folder to put our outputs in, leave blank "" for script path
73 save_path= os.path.join("data","example10")
74 #ensure the dir exists
75 mkDir(save_path)
76
77 ####################################################DOMAIN CONSTRUCTION
78 domain = Brick(l0=mx,l1=my,n0=ndx, n1=ndy,l2=mz,n2=ndz)
79 x=Solution(domain).getX()
80 x=x-[mx/2,my/2,mz/2]
81 domain.setX(interpolate(x, ContinuousFunction(domain)))
82 mask=wherePositive(100-length(x-rholoc))
83 rho=rho*mask
84 kro=kronecker(domain)
85
86 mass=rho*vol(domain)
87 ipot=FunctionOnBoundary(domain)
88 xb=ipot.getX()
89
90 q=whereZero(x[2]-inf(x[2]))
91 ###############################################ESCRIPT PDE CONSTRUCTION
92
93 mypde=LinearPDE(domain)
94 mypde.setValue(A=kro,Y=4.*3.1415*G*rho,q=q,r=0)
95 mypde.setSymmetryOn()
96 sol=mypde.getSolution()
97 saveVTK(os.path.join(save_path,"ex10b.vtu"),\
98 grav_pot=sol,\
99 g_field=-grad(sol),\
100 g_fieldz=-grad(sol)*[0,0,1],\
101 gz=length(-grad(sol)*[0,0,1]))
102
103 ################################################MODEL SIZE SAMPLING
104 sampler=[]
105 for i in range(-250,250,1):
106 sampler.append([i,0,250])
107
108 sample=[] # array to hold values
109 rec=Locator(domain,sampler) #location to record
110 psol=rec.getValue(sol)
111 np.savetxt(os.path.join(save_path,"example10b_%04d.asc"%mx),psol)
112

  ViewVC Help
Powered by ViewVC 1.1.26