1 |
# -*- coding: utf-8 -*- |
2 |
|
3 |
############################################################################## |
4 |
# |
5 |
# Copyright (c) 2003-2020 by The University of Queensland |
6 |
# http://www.uq.edu.au |
7 |
# |
8 |
# Primary Business: Queensland, Australia |
9 |
# Licensed under the Apache License, version 2.0 |
10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
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 |
# Development from 2019 by School of Earth and Environmental Sciences |
16 |
# |
17 |
############################################################################## |
18 |
|
19 |
from __future__ import print_function, division |
20 |
|
21 |
__copyright__="""Copyright (c) 2003-2020 by The University of Queensland |
22 |
http://www.uq.edu.au |
23 |
Primary Business: Queensland, Australia""" |
24 |
__license__="""Licensed under the Apache License, version 2.0 |
25 |
http://www.apache.org/licenses/LICENSE-2.0""" |
26 |
__url__="https://launchpad.net/escript-finley" |
27 |
|
28 |
""" |
29 |
Layer Cake |
30 |
|
31 |
This script uses the pycad module to build a rectangular layered |
32 |
system of prisms for modelling. |
33 |
|
34 |
:var __author__: name of author |
35 |
:var __copyright__: copyrights |
36 |
:var __license__: licence agreement |
37 |
:var __url__: url entry point on documentation |
38 |
:var __version__: version |
39 |
:var __date__: date of the version |
40 |
""" |
41 |
|
42 |
__author__="Antony Hallam antony.hallam@uqconnect.edu.au" |
43 |
|
44 |
import esys.pycad as pycad |
45 |
|
46 |
def buildFreeSurface(xwidth,ywidth): |
47 |
''' |
48 |
Build a free surface to start the layer cake model. |
49 |
This surface is planar. |
50 |
|
51 |
Parameters: |
52 |
xwidth :: width in x direction in meters.\ |
53 |
ywidth :: width in y direction in meters.\ |
54 |
''' |
55 |
|
56 |
# Layer Corners |
57 |
corner_points=[] |
58 |
corner_points.append(pycad.Point(0.0, 0.0, 0.0)) |
59 |
corner_points.append(pycad.Point(xwidth, 0.0, 0.0)) |
60 |
corner_points.append(pycad.Point(xwidth, ywidth, 0.0)) |
61 |
corner_points.append(pycad.Point(0.0, ywidth, 0.0)) |
62 |
corner_points.append(corner_points[0]) #repeated point for line looping |
63 |
|
64 |
# Edges of Free Surface |
65 |
hor_lines=[] |
66 |
for i in range(0,4): # loop through four sides |
67 |
hor_lines.append(pycad.Line(corner_points[i],corner_points[i+1])) |
68 |
|
69 |
# Create Free Surface |
70 |
free_surf = pycad.PlaneSurface(pycad.CurveLoop(*tuple(hor_lines[0:4]))) |
71 |
|
72 |
# Return Surface and primative arrays. |
73 |
return free_surf,hor_lines,corner_points |
74 |
|
75 |
def buildLayer(xwidth,ywidth,depth,lay_surf,hor_lines,corner_points): |
76 |
''' |
77 |
Builds a boxlike volume and returns primatives for layered model |
78 |
construction. |
79 |
|
80 |
Parameters: |
81 |
xwidth :: width in x direction in meters.\ |
82 |
ywidth :: width in y direction in meters.\ |
83 |
depth :: depth to bottom of layer in meters.\ |
84 |
lay_surf :: surface at top of layer (see buildFreeSurf)\ |
85 |
hor_lines :: lines of lay_surf\ |
86 |
corner_points :: points of hor_lines\ |
87 |
''' |
88 |
# Layer Corners |
89 |
corner_points.append(pycad.Point(0.0, 0.0, depth)) |
90 |
corner_points.append(pycad.Point(xwidth, 0.0, depth)) |
91 |
corner_points.append(pycad.Point(xwidth, ywidth, depth)) |
92 |
corner_points.append(pycad.Point(0.0, ywidth, depth)) |
93 |
corner_points.append(corner_points[5]) #repeated point for line looping |
94 |
|
95 |
# Build the bottom surface edges. |
96 |
for i in range(0,4): # loop through four edges |
97 |
hor_lines.append(pycad.Line(corner_points[5+i],corner_points[6+i])) |
98 |
|
99 |
# Join corners vertically. |
100 |
ver_lines=[] |
101 |
for i in range(0,4): # loop through four corners |
102 |
ver_lines.append(pycad.Line(corner_points[i],corner_points[i+5])) |
103 |
ver_lines.append(ver_lines[0]) #repeated edge for surface looping |
104 |
|
105 |
# Build surface array. |
106 |
lay_surf=[-lay_surf] #Negative of top surface |
107 |
# Bottom Surface |
108 |
lay_surf.append(pycad.PlaneSurface(pycad.CurveLoop(*tuple(hor_lines[4:8])))) |
109 |
for i in range(0,4): # loop through four sides |
110 |
lay_surf.append(pycad.PlaneSurface(pycad.CurveLoop(\ |
111 |
-ver_lines[i],-hor_lines[i+4],\ |
112 |
ver_lines[i+1],hor_lines[i] ))) |
113 |
|
114 |
# Build Layer Volume |
115 |
lay_vol=pycad.Volume(-pycad.SurfaceLoop(*tuple(lay_surf))) |
116 |
|
117 |
# Return new volume, and primatives for next volume layer. |
118 |
return lay_vol,-lay_surf[1],hor_lines[4:8],corner_points[5:10] |
119 |
|
120 |
|
121 |
def layer_cake(domain,xwidth,ywidth,depths): |
122 |
''' |
123 |
Builds a horizontally layered box like model. All layers are |
124 |
tagged as 'intface_i' where i is the python style integer denoting |
125 |
that layer. For example, the free surface is tagged 'interface_0'. |
126 |
Volumes are similarly tagged as 'volume_i'. |
127 |
|
128 |
Parameters: |
129 |
domain :: output of Pycad.Design - It needs to be dim 3.\ |
130 |
xwidth :: width in x direction in meters.\ |
131 |
ywidth :: width in y direction in meters.\ |
132 |
depth :: depth to bottom of layer in meters.\ |
133 |
|
134 |
One may save the domain using: |
135 |
# Output settings.\ |
136 |
domain.setScriptFileName(os.path.join(save_path,fname+".geo"))\ |
137 |
domain.setMeshFileName(os.path.join(save_path,fname+".msh"))\ |
138 |
findomain=fin.MakeDomain(domain) # make the finley domain:\ |
139 |
|
140 |
Create a file that can be read back in to python with ReadMesh.\ |
141 |
findomain.write(os.path.join(save_path,fname+".fly"))\ |
142 |
''' |
143 |
|
144 |
#get number of layers |
145 |
if not hasattr(depths,"__len__"): depths = [ depths, ] |
146 |
ndepths=len(depths) |
147 |
|
148 |
if domain.getDim() != 3: |
149 |
raise TypeError("domain must be of dimension order 3.") |
150 |
|
151 |
# Build the First Surface and add it to the domain |
152 |
fsuf,fsurl,fsurp=buildFreeSurface(xwidth,ywidth) |
153 |
domain.addItems(pycad.PropertySet('intface_%d'%(0),fsuf)) |
154 |
|
155 |
# Build each layer sequentially |
156 |
# Set up temporary variables. |
157 |
tsuf=fsuf; tsurl=fsurl; tsurp=fsurp |
158 |
# Loop through all depths. |
159 |
for i in range(0,ndepths): |
160 |
# Build new layer. |
161 |
tvol,tsuf,tsurl,tsurp=buildLayer(xwidth,ywidth,depths[i],\ |
162 |
tsuf,tsurl,tsurp) |
163 |
# Add the new interface to the domain. |
164 |
domain.addItems(pycad.PropertySet('intface_%d'%(i+1),tsuf)) |
165 |
# Add the new volume/layer to the domain. |
166 |
domain.addItems(pycad.PropertySet('volume_%d'%i,tvol)) |
167 |
|
168 |
return domain |
169 |
|