~emmanuel-lambert/python-meep/intec

« back to all changes in this revision

Viewing changes to tests/flux.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:
146
146
 
147
147
    return compare(start_energy - delta_energy,  start_energy - defl, 0.032 if (timewait>50) else 0.004, "Flux")
148
148
    
149
 
#DEPRECATED - in production scripts, use getFluxData function instead
150
 
def get_flux(flux_obj):
151
 
    val = []
152
 
    _fl=flux_obj.flux()
153
 
    for _i in range(0,flux_obj.Nfreq):
154
 
        val.append(flux_helper(_fl,_i))
155
 
    return val
156
 
 
157
 
 
158
149
def flux_2d(xmax, ymax, eps):
159
150
    a = 8.0
160
151
    master_printf("\nFlux_2d(%g,%g) test...\n", xmax, ymax)
213
204
    # dft_flux.flux() returns a pointer to unbound array of doubles, Nfreq length , not an array itself 
214
205
    # so directly calling this function will return only the first double number !
215
206
    # in order to obtain the whole array, we use a temporary workaround 
 
207
 
 
208
    #fl1 = flux1.flux()
 
209
    #fl2 = flux2.flux()
 
210
 
216
211
    fl1=get_flux(flux1)
217
212
    fl2=get_flux(flux2)
218
213
 
226
221
 
227
222
 
228
223
def flux_cyl(rmax, zmax, eps, m):
229
 
    use_averaging(False) #to speed up the test
230
224
    a = 8.0
231
225
    master_printf("\nFlux_cyl(%g,%g) test...\n", rmax, zmax)
232
226
    v = volcyl(rmax,zmax,a)
233
 
    master_printf("\nFlux_cyl(%g,%g) test...defining structure...\n", rmax, zmax)
234
227
    s = structure(v, eps, pml(0.5))
235
228
 
236
 
    master_printf("\nFlux_cyl(%g,%g) test...stage 1...\n", rmax, zmax)
237
 
    f = fields_complex(s, m)
 
229
    f = fields(s, m)
238
230
    f.add_point_source(Ep, 0.25, 3.5, 0., 8., veccyl(rmax*5/6+0.1, zmax/6+0.3), 1.)
239
231
  
240
232
    lb= veccyl(-rmax/3, zmax/3)
243
235
    rt= veccyl(2*rmax/3, 2*zmax/3)
244
236
    box =  volume(lb, rt)
245
237
 
246
 
    master_printf("\nFlux_cyl(%g,%g) test...stage 2...\n", rmax, zmax)
247
238
    box1 = volume (veccyl(rmax*5/6-0.4, zmax/6-0.2),    veccyl(rmax*5/6+0.6, zmax/6+0.8))
248
239
    box2 = volume (veccyl(rmax*5/6-0.9, zmax/6-0.7),    veccyl(rmax*5/6+1.1, zmax/6+1.3))
249
240
 
253
244
    flux1 = f.add_dft_flux_box(box1, fmin, fmax, Nfreq)
254
245
    flux2 = f.add_dft_flux_box(box2, fmin, fmax, Nfreq)
255
246
 
256
 
    master_printf("\nFlux_cyl(%g,%g) test...stage 3...\n", rmax, zmax)
257
247
    left = f.add_flux_plane(lb, lt)
258
248
    right = f.add_flux_plane(rb, rt)
259
249
    bottom = f.add_flux_plane(lb, rb)
261
251
 
262
252
    ttot = 130
263
253
 
264
 
    master_printf("\nFlux_cyl(%g,%g) test...stage 4...\n", rmax, zmax)
265
254
    f.step()
266
 
    master_printf("\nFlux_cyl(%g,%g) test...stage 5...\n", rmax, zmax)
267
255
    init_energy = f.energy_in_box(box)
268
256
    master_printf("Initial energy is %g\n", init_energy)
269
257
    fluxL = 0
271
259
        f.step()
272
260
        fluxL += f.dt * (left.flux() - right.flux() + bottom.flux() - top.flux())
273
261
    
274
 
    master_printf("\nFlux_cyl(%g,%g) test...stage 6...\n", rmax, zmax)
275
262
    flux = fluxL
276
263
    del_energy = f.energy_in_box(box) - init_energy
277
264
    master_printf("Final energy is %g\n", f.energy_in_box(box))
328
315
width = 5.0
329
316
attempt("Flux 2D 5", flux_2d(10.0, 10.0, EPS))
330
317
width = 5.0
331
 
attempt("Flux cylindrical 5", flux_cyl(20.0, 10.0, EPS, 1)) 
332
 
 
 
318
attempt("Flux cylindrical 5", flux_cyl(20.0, 10.0, EPS, 1))
333
319