def scalar(parents=(), potential="drift", **kwds): ''' Solve Nuemann boundary condition using pure scalar calculation. ''' kwds = knobs(**kwds) # set BEM++ accuracy knobs sres = parents[0] grid = larf.surface.grid(sres) DirichletClass = get_method("larf.potentials.%s" % potential) dirichlet_data = DirichletClass(**kwds) dfunarr, nfunarr = larf.solve.boundary_functions(grid, dirichlet_data) arrays = [ Array(type='scalar', name='dirichlet', data=dfunarr), Array(type='scalar', name='neumann', data=nfunarr), ] return arrays
def scalar(parents=(), **kwds): ''' Evaluate potential on volumes. ''' kwds = knobs(**kwds) # set BEM++ accuracy knobs bres = parents[0] vreses = parents[1:] grid, dfun, nfun = result_to_grid_funs(bres) pcspace, plspace = spaces(grid) arrays = list() for vres in vreses: points = vres.array_data_by_type()['points'] npoints = len(points) points = points.T slp_pot = bempp.api.operators.potential.laplace.single_layer(pcspace, points) pot = slp_pot * nfun arrays.append(Array(type = 'scalar', name = vres.name, data = pot.T)) return arrays
def scalar(parents=(), **kwds): ''' Evaluate potential on volumes. ''' kwds = knobs(**kwds) # set BEM++ accuracy knobs bres = parents[0] vreses = parents[1:] grid, dfun, nfun = result_to_grid_funs(bres) pcspace, plspace = spaces(grid) arrays = list() for vres in vreses: points = vres.array_data_by_type()['points'] npoints = len(points) points = points.T slp_pot = bempp.api.operators.potential.laplace.single_layer( pcspace, points) pot = slp_pot * nfun arrays.append(Array(type='scalar', name=vres.name, data=pot.T)) return arrays
def drift( parents=(), # boundary, wires, points start_time=0.0, gradlcar=10 * units.um, steptime=0.1 * units.us, stuck=1 * units.um, maxiter=300, maxtime=30 * units.us, stop_radius=0.2 * units.mm, temperature=89 * units.Kelvin, namepat="{source}-{count:05d}", # pattern to name path arrays stepper='rkck', batch_paths=100, # max number of paths to run in parallel, not including x7 at each step for gradient **kwds): ''' From parent results (boundary, wires, points) return paths stepped through drift field given by boundary starting at given points and until hitting on of the wires or other halt conditions. A collection of (name, path) pairs are returned. Each path is a numpy array of ( (x,y,z), (vx,vy,vz), (ex,ey,ez), t). ''' kwds = knobs(**kwds) bres, wres, pres = parents wire_arrays = [a.data for a in wres.arrays] print[a.shape for a in wire_arrays] stop = StopStepping(stuck, stop_radius, *wire_arrays) potential = Points(*result_to_grid_funs(bres)) efield = BatchedGradientFunction(potential, gradlcar) velo = BatchedVelocity(efield, temperature) if stepper == 'rkck': stepper = BatchedStepper_rkck(velo) if stepper == 'jump': stepper = BatchedStepper_jump(velo) points = list() point_set_desc = list() for typ, nam, arr in pres.triplets(): if typ != 'points': continue point_set_desc.append((nam, arr.size / 3)) points.append(numpy.vstack(arr)) points = numpy.vstack(points) npoints = len(points) times = numpy.asarray([start_time] * npoints) points = numpy.hstack((points, times.reshape(npoints, 1))) batches = larf.points.batch(points, batch_paths) paths = list() for batch in batches: print "Stepping batch of %d paths" % len(batch) all_paths = [[p] for p in batch] active_paths = list(all_paths) tips = batch for istep in range(maxiter): if 0 == len(tips): break if 0 == len(active_paths): break print "step %d/%d with %d paths, %d points" % ( istep, maxiter, len(active_paths), len(tips)) print "batch[0] tip point: %s" % tips[0] next_points = stepper(steptime, tips) tips, active_paths = step_maybe(active_paths, next_points, stop) if len(points) <= 0: break if points[0, 3] > maxtime: break paths += all_paths arrays = list() for name, size in point_set_desc: for ipt in range(size): print name, size, ipt, len(paths) path = paths.pop(0) aname = namepat.format(count=ipt, source=name) array = Array(type='path', name=aname, data=numpy.asarray(path)) arrays.append(array) extra = [ ('points', 'potential_points', efield.scalar_points), ('pscalar', 'potential', efield.scalars), ('points', 'gradient_points', efield.gradient_points), ('ptuple', 'gradient', efield.gradients), ('points', 'velocity_points', velo.points), ('ptuple', 'velocity', velo.velocities), ] for t, n, a in extra: arrays.append(Array(type=t, name=n, data=numpy.asarray(a))) return arrays
def linear(parents=(), **kwds): kwds = knobs(**kwds) # set BEM++ accuracy knobs bres = parents[0] # get boundary grid, dfun, nfun = result_to_grid_funs(bres) return linear_lowlevel(grid, dfun, nfun, **kwds)