-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathobjects.py
76 lines (61 loc) · 2.69 KB
/
objects.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
#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 math
import data
class Object(object):
template_str = (
"\n (make %(shape)s\n"
" (center %(x)s %(y)s %(z)s)\n"
" %(other)s\n"
" (material %(material)s) )")
def __init__(self,x,y,z,material,shape='',**others):
self.x = x
self.y = y
self.z = z
self.material = material
self.others = others
self.shape = shape
def __str__(self):
self.other = '\n '.join(
'(%s %s)'%(a,self.others[a]) for a in self.others)
return Object.template_str % self.__dict__
del self.other
class Rod(Object):
def __init__(self, x, y, material, radius):
self.radius = radius
super(Rod,self).__init__(x, y, 0, material, 'cylinder',
height='infinity', radius=radius)
class Block(Object):
def __init__(self, x, y, z, material, size):
self.size = size
super(Block, self).__init__(x, y, z, material, 'block',
size=' '.join([str(s) for s in size]))
class Dielectric(object):
def __init__(self,dielectric):
if hasattr(dielectric,'__int__'):
self.epsilon = dielectric
self.index = math.sqrt(dielectric)
self.name = 'eps{0:.3f}'.format(dielectric)
else:
self.epsilon = data.dielectrics[dielectric]
self.index = data.refr_index[dielectric]
self.name = data.material_names[dielectric]
def __str__(self):
if isinstance(self.epsilon, (list, tuple)) and len(self.epsilon) == 3:
return ('(make dielectric-anisotropic\n'
' (epsilon-diag '
'{0[0]} {0[1]} {0[2]}))'.format(self.epsilon))
else:
return '(make dielectric (epsilon %(epsilon)s))' % self.__dict__
def __repr__(self):
return 'Dielectric with epsilon = %(epsilon)s' % self.__dict__