-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeometry.py
109 lines (86 loc) · 3.67 KB
/
geometry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#Copyright 2009-2016 Seyed Hessam Moosavi Mehr, Juergen Probst
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
import objects
import log
from objects import *
class Geometry(object):
def __init__(
self, width, height, objects, depth=None, triangular=False):
self.width = width
self.height = height
self.objects = objects
if depth is None:
self.depth = 'no-size'
else:
self.depth = depth
self.triangular = triangular
self.substrate_index = 1
def add_substrate(self, material, start_at):
if self.substrate_index != 1:
log.error('Geometry: a substrate was added before, will ignore '
'this call')
return
if self.depth == 'no-size':
log.error('Geometry: can only add a substrate if depth is '
'given (third dimension). Substrate not added.')
return
self.substrate_index = material.index
self.objects.append(
Block(
x=0, y=0, z=start_at / 2.0 - self.depth / 4.0,
material=material,
size=(
#make it bigger than computational cell, just in case:
2 * self.width, 2 * self.height,
self.depth / 2.0 + start_at)
))
def get_is3D(self):
return 'no-size' not in [self.width, self.height, self.depth]
is3D = property(get_is3D)
def get_area(self):
return self.width*self.height
cell_area = property(get_area)
def get_lattice(self):
if self.triangular:
return ('(make lattice (size %s %s %s)'
'\n (basis1 (/ (sqrt 3) 2) 0.5)'
'\n (basis2 (/ (sqrt 3) 2) -0.5))') % \
(self.width, self.height, self.depth)
else:
return '(make lattice (size %s %s %s))' % \
(self.width, self.height, self.depth)
lattice = property(get_lattice)
## def get_max_epsilon(self):
## return max(a.material.epsilon for a in self.objects)
## max_epsilon = property(get_max_epsilon)
## def __repr__(self):
## object_template = {
## objects.Rod : ("EdgeForm[Directive[Dashed,Darker["
## "Green,0.6]],Disk[{%(x)s,%(y)s},%(radius)s")}
#maxeps = self.max_epsilon
#hue_function = lambda epsilon:(maxeps-epsilon)/epsilon
## return('Graphics[{'+','.join(object_template[a.__class__]\
## %a.__dict__ for a in self.objects)+'}]')
def __str__(self):
return '(list' + ''.join(str(a) for a in self.objects) + ')'
def __repr__(self):
s = '; '.join(
[
'lattice = {0!r}'.format(self.lattice),
'geometry = {0!r}'.format(self.__str__())])
return '<geometry.Geometry object: {0}>'.format(s)
def __iter__(self):
return self
#~ def geom_objects(self):
#~ for obj in self.objects:
#~ yield