-
Notifications
You must be signed in to change notification settings - Fork 4
/
scatterer.py
140 lines (114 loc) · 4.71 KB
/
scatterer.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
__author__ = 'Kryosugarra'
import numpy
import enum
import misc
# class Shape(enum.Enum):
# Sphere = 1
# Cube = 2
# Cyllinder = 3
# Spheroid = 4
#
# class Scatterer:
# def __init__(self):
# self.dipoles = []
# self.dipole_spacing = 0
#
# @staticmethod
# def load_dda_si_dipole_file(filename):
# f = open(filename, 'r')
# lines = f.readlines()
# dipoles = []
# for line in lines:
# dipole = []
# for d in line.split(','):
# dipole.append(float(d))
# dipoles.append(dipole)
#
# scat = Scatterer()
# scat.dipoles = numpy.asarray(dipoles)
# return scat
def dipole_sphere(dipoles_per_dimension, radius):
pow2 = misc.power_function(2)
pow3 = misc.power_function(3)
pow1d3 = misc.power_function(1. / 3.)
dipoles = []
for x in numpy.linspace(-radius, radius, dipoles_per_dimension):
for y in numpy.linspace(-radius, radius, dipoles_per_dimension):
for z in numpy.linspace(-radius, radius, dipoles_per_dimension):
if numpy.sqrt(pow2(x) + pow2(y) + pow2(z)) <= radius:
dipoles.append([x, y, z])
initial_spacing = 2*radius/(dipoles_per_dimension - 1)
dipole_spacing = pow1d3(4 / 3 * numpy.pi / len(dipoles)) * radius
dipoles = numpy.asarray(dipoles) * (dipole_spacing / initial_spacing)
return dipoles, dipoles.shape[0], dipole_spacing
def dipole_cube(dipoles_per_dimension, side):
dipoles = []
for x in numpy.linspace(-side / 2, side / 2, dipoles_per_dimension):
for y in numpy.linspace(-side / 2, side / 2, dipoles_per_dimension):
for z in numpy.linspace(-side / 2, side / 2, dipoles_per_dimension):
dipoles.append([x, y, z])
dipoles = numpy.asarray(dipoles)
dipole_spacing = 2*side / (dipoles_per_dimension - 1)
return dipoles, dipoles.shape[0], dipole_spacing
def dipole_cylinder(dipoles_per_min_dimension, radius, height):
pow2 = misc.power_function(2)
pow3 = misc.power_function(3)
pow1d3 = misc.power_function(1. / 3.)
dipoles = []
if radius * 2 < height:
r_dim = dipoles_per_min_dimension
h_dim = numpy.rint(dipoles_per_min_dimension * height / (radius * 2))
dipole_spacing = 2 * radius / (r_dim - 1)
else:
r_dim = numpy.rint(dipoles_per_min_dimension * (radius * 2) / height)
h_dim = dipoles_per_min_dimension
dipole_spacing = height / (h_dim - 1)
for x in numpy.linspace(-radius, radius, r_dim):
for y in numpy.linspace(-radius, radius, r_dim):
for z in numpy.linspace(-height / 2, height / 2, h_dim):
if numpy.sqrt(pow2(x) + pow2(y)) <= radius:
dipoles.append([x, y, z])
dipoles = numpy.asarray(dipoles)
return dipoles, dipoles.shape[0], dipole_spacing
def dipole_cylinder_r(dipoles_per_min_dimension, radius, height):
pow2 = misc.power_function(2)
pow3 = misc.power_function(3)
pow1d3 = misc.power_function(1. / 3.)
dipoles = []
r_dim = dipoles_per_min_dimension
h_dim = numpy.rint(dipoles_per_min_dimension * height / (radius * 2))
dipole_spacing = 2 * radius / (r_dim - 1)
for x in numpy.linspace(-radius, radius, r_dim):
for y in numpy.linspace(-radius, radius, r_dim):
for z in numpy.linspace(-height / 2, height / 2, h_dim):
if numpy.sqrt(pow2(x) + pow2(y)) <= radius:
dipoles.append([x, y, z])
dipoles = numpy.asarray(dipoles)
return dipoles, dipoles.shape[0], dipole_spacing
def dipole_spheroid(dipoles_per_min_dimension, a, b, testsphere=True):
pow2 = misc.power_function(2)
pow3 = misc.power_function(3)
pow1d3 = misc.power_function(1. / 3.)
dipoles = []
if a < b:
a_dim = dipoles_per_min_dimension
b_dim = numpy.rint(dipoles_per_min_dimension * b / a)
if testsphere:
assert not a_dim == b_dim
dipole_spacing = 2 * a / (a_dim - 1)
else:
b_dim = dipoles_per_min_dimension
a_dim = numpy.rint(dipoles_per_min_dimension * a / b)
if testsphere:
assert not a_dim == b_dim
dipole_spacing = 2 * b / (b_dim - 1)
for x in numpy.linspace(-a, a, a_dim):
for y in numpy.linspace(-a, a, a_dim):
for z in numpy.linspace(-b, b, b_dim):
if numpy.sqrt(pow2(x / a) + pow2(y / a) + pow2(z / b)) <= 1:
dipoles.append([x, y, z])
initial_spacing = dipole_spacing
dipole_spacing = pow1d3(4 / 3 * numpy.pi / len(dipoles) * a * a * b)
dipoles = numpy.asarray(dipoles)*(dipole_spacing/initial_spacing)
dipoles = numpy.asarray(dipoles)
return dipoles, dipoles.shape[0], dipole_spacing