~emmanuel-lambert/python-meep/intec

« back to all changes in this revision

Viewing changes to tests/cylindrical.py

  • Committer: emmanuel.lambert at ugent
  • Date: 2009-11-23 10:23:17 UTC
  • Revision ID: emmanuel.lambert@intec.ugent.be-20091123102317-m00vrwyw0m6kpcmm
further merging with NS / replacing tests dir with default tests and creating new 'tests-intec' subdir

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# passed, but why eps initializes only with zeros ???
3
3
 
4
 
 
5
4
from meep import *
6
5
from math import fabs,sqrt,cos
7
6
 
11
10
        self.prints = 0 
12
11
 
13
12
    def complex_vec(self,v):
14
 
        return complex(self.eps(v), 1)
 
13
        if self.prints < 10:
 
14
            print v, self.get_complex(), self.eps(v)
 
15
            self.prints+=1
 
16
#        return complex(self.prints,1j)
 
17
        return self.eps(v)
15
18
 
16
19
    def eps(self,v):
17
20
        ther = v.r() + 0.0001 # Just to avoid roundoff issues.
46
49
            v1 = m_test.get_component(c)
47
50
            v2 = m1.get_component(c)
48
51
            if (abs(v1 - v2) > eps*abs(v2) and abs(v2) > eps):
49
 
                master_printf("%s differs:  %g %g out of %g %g\n",component_name(c), (v2-v1).real, (v2-v1).imag, (v2).real, (v2).imag)
 
52
                master_printf("%s differs:  %g %g out of %g %g\n",component_name(c), real(v2-v1), imag(v2-v1), real(v2), imag(v2))
50
53
                master_printf("This comes out to a fractional error of %g\n",abs(v1 - v2)/abs(v2))
51
54
                master_printf("Right now I'm looking at %g %g, time %g\n", p.r(), p.z(), f1.time())
52
55
                all_wait()
63
66
    
64
67
    for m in range (0,3):
65
68
        master_printf("Trying with m = %d and a splitting into %d chunks...\n", m, splitting);
66
 
        f=fields_complex(s, m)
 
69
        f=fields(s, m)
67
70
        f.use_bloch(vec(0.0))
68
71
        f.add_point_source(Ep, 0.7, 2.5, 0.0, 4.0, veccyl(0.5, 0.4), 1.0)
69
72
        f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, veccyl(0.401, 0.301), 1.0)
70
 
        f1=fields_complex(s1, m)
 
73
        f1=fields(s1, m)
71
74
        f1.use_bloch(vec(0.0))
72
75
        f1.add_point_source(Ep, 0.7, 2.5, 0.0, 4.0, veccyl(0.5, 0.4), 1.0)
73
76
        f1.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, veccyl(0.401, 0.301), 1.0)
113
116
    v = volcyl(1.5,0.8,a)
114
117
    s1= structure(v, eps)
115
118
    s=structure(v, eps, no_pml(), identity(), splitting)
116
 
    for m in range(0,3): #FIXME -- was (0,3) 
 
119
    for m in range(0,3): 
117
120
        master_printf("Metallic with m = %d and a splitting into %d chunks...\n", m, splitting)
118
 
        f=fields_complex(s, m)
 
121
        f=fields(s, m)
119
122
        f.add_point_source(Ep, 0.7, 2.5, 0.0, 4.0, veccyl(0.5, 0.4), 1.0)
120
123
        f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, veccyl(0.401, 0.301), 1.0)
121
 
        f1=fields_complex(s1, m)
 
124
        f1=fields(s1, m)
122
125
        f1.add_point_source(Ep, 0.7, 2.5, 0.0, 4.0, veccyl(0.5, 0.4), 1.0)
123
126
        f1.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, veccyl(0.401, 0.301), 1.0)
124
127
        if not compare(f1.count_volume(Ep), f.count_volume(Ep), "volume"):
159
162
    v = volcyl(1.5,0.8,a)
160
163
    s=structure(v, eps)
161
164
    
162
 
    for m in range(0,3): #FIXME -- was (0,3)
 
165
    for m in range(0,3):
163
166
        master_printf("Checking at r == 0 with m = %d...\n", m)
164
 
        f=fields_complex(s, m)
 
167
        f=fields(s, m)
165
168
        f.add_point_source(Ep, 0.7, 2.5, 0.0, 4.0, veccyl(0.5, 0.4), 1.0)
166
169
        f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, veccyl(0.401, 0.301), 1.0)
167
170
 
168
171
        while (f.time() < ttot):
169
172
            f.step()
170
 
 
171
173
        p=monitor_point()
172
174
        f.get_point(p, veccyl(0.0, 0.5))
173
175
 
192
194
            return 0
193
195
 
194
196
        if (p.get_component(Hp) != 0.0 and not (m & 1)):
195
 
            master_printf("Got non-zero Hp of %g %g with m == %d\n", (p.get_component(Hp)).real, (p.get_component(Hp)).imag, m)
 
197
            master_printf("Got non-zero Hp of %g %g with m == %d\n", real(p.get_component(Hp)), imag(p.get_component(Hp)), m)
196
198
            return 0
197
199
 
198
200
    return 1
204
206
    s1=structure(v, eps, pml(2.0))
205
207
    s=structure(v, eps, pml(2.0), identity(), splitting)
206
208
    
207
 
    for m in range(0,3): #FIXME -- was (0,3)
 
209
    for m in range(0,3):
208
210
        master_printf("PML with m = %d and a splitting into %d chunks...\n",m, splitting)
209
 
        f=fields_complex(s, m)
 
211
        f=fields(s, m)
210
212
        f.add_point_source(Ep, 0.7, 2.5, 0.0, 4.0, veccyl(0.3, 7.0), 1.0)
211
213
        f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, veccyl(0.3, 7.0), 1.0)
212
 
        f1=fields_complex(s1, m)
 
214
        f1=fields(s1, m)
213
215
        f1.add_point_source(Ep, 0.7, 2.5, 0.0, 4.0, veccyl(0.3, 7.0), 1.0)
214
216
        f1.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, veccyl(0.3, 7.0), 1.0)
215
217
        if not compare(f1.count_volume(Ep), f.count_volume(Ep), "volume", 3e-14):
249
251
    s = structure(v, eps, no_pml(), identity(), splitting)
250
252
    for m in range(0,1):
251
253
        master_printf("Trying test pattern with m = %d and %d chunks...\n", m, splitting);
252
 
        f=fields_complex(s, m)
 
254
        f=fields(s, m)
253
255
        f.use_bloch(vec(0.0))
254
 
        f1=fields_complex(s1, m)
 
256
        f1=fields(s1, m)
255
257
        f1.use_bloch(vec(0.0))
256
258
 
257
259
        if not compare(f1.count_volume(Ep), f.count_volume(Ep), "volume"):
284
286
 
285
287
master_printf("Testing cylindrical coords under different splittings...\n");
286
288
 
287
 
master_printf("Stage 1 ...\n");
288
 
        
289
289
if not test_r_equals_zero(ONE):
290
290
    abort("error in test_r_equals_zero")
291
291
 
292
 
master_printf("Stage 2 ...\n");
293
 
 
294
292
for s in range(2,6):
295
293
    if not test_pattern(ONE, s):
296
294
        abort("error in test_pattern\n")
297
295
 
298
 
master_printf("Stage 3 ...\n");
299
 
 
300
296
for s in range(2,4):
301
297
    if not test_simple_periodic(ONE, s):
302
298
        abort("error in test_simple_periodic\n")
303
 
 
304
 
master_printf("Stage 4 ...\n");
305
 
 
306
299
for s in range(2,5):
307
300
    if not test_simple_metallic(ONE, s):
308
301
        abort("error in test_simple_metallic\n")
309
 
 
310
 
master_printf("Stage 5 ...\n");
311
302
        
312
303
for s in range(2,6):
313
304
    if not test_pml(ONE, s):
314
305
        abort("error in test_pml\n")
315
306
 
316
 
master_printf("All tests passed ...\n");