Exemplo n.º 1
0
 def setUp(self):
     prefix = "examples/SimpleTrap/SimpleTrap"
     self.ele = Electrodes.from_trap(open("%s.ele" % prefix), scale=40e-6)
     self.tri = Mesh.from_electrodes(self.ele)
     self.tri.triangulate(opts="qQ")
     self.job = Configuration.select(self.tri, "RF").next()
     s, n = .1, 2 * 10
     self.grid = Grid(center=(0, 0, 1.5), step=(s, s, s), shape=(n, n, n))
Exemplo n.º 2
0
def main():
    prefix = "examples/system_to_3d/rfjunction"
    scale = 40e-6
    fname = "/home/rjordens/work/nist/qc-tools/trunk/bin/rfjunction_gaps.gds"

    logging.basicConfig(
        level=logging.DEBUG,
        format="%(asctime)s %(name)s %(processName)s[%(process)s] "
        "%(filename)s:%(funcName)s() %(levelname)s: %(message)s",
        filename="%s.log" % prefix,
        filemode="w")
    sh = logging.StreamHandler()
    sh.setLevel(logging.INFO)
    sh.setFormatter(
        logging.Formatter("%(processName)s[%(process)s] "
                          "%(filename)s:%(funcName)s(): %(message)s"))
    logging.getLogger().addHandler(sh)

    fil = open(fname)
    s = from_gds(fil, scale)
    if False:
        p = system_to_polygons(s)
        #check_validity(p)
        #p = remove_overlaps(p)
        ## p = add_gaps(p, .1)
        ele = Electrodes.from_polygons(p)
    else:
        ele = Electrodes.from_system(s)

    # ele.cleanup()
    ele.extrude(-.1)

    mesh = Mesh.from_electrodes(ele)
    mesh.triangulate(opts="Q")
    mesh.areas_from_constraints(
        Sphere(center=np.array([0, 0, 1.]), radius=3, inside=.2, outside=20.))
    mesh.triangulate(opts="qQ", new=False)
    mesh.to_vtk(prefix)

    sim = Simulation(mesh)

    #sel = list(sim.select(potentials=[], fields=["r"]))
    sel = list(sim.select(potentials=[".*"], fields=["r.*"]))

    n, s = 2 * 40, .05
    grid = Grid(center=(0, 0, 1.5), step=(s, s, s), shape=(n, n, n))

    pool = Pool(4)
    c = pool.map(run_job, ((sim, grid, prefix, job) for job in sel))

    print([i[0] for i in sel])
    print(np.array(c) * 4 * np.pi * epsilon_0 * scale)

    Result.view(prefix, "r")
Exemplo n.º 3
0
class SimpletrapNewCase(unittest.TestCase):
    """simple trap triangulation and bem simulation"""
    def setUp(self):
        prefix = "examples/SimpleTrap/SimpleTrap"
        self.ele = Electrodes.from_trap(open("%s.ele" % prefix), scale=40e-6)
        self.tri = Mesh.from_electrodes(self.ele)
        self.tri.triangulate(opts="qQ")
        self.job = Configuration.select(self.tri, "RF").next()
        s, n = .1, 2 * 10
        self.grid = Grid(center=(0, 0, 1.5), step=(s, s, s), shape=(n, n, n))

    def assertBetween(self, a, b, c):
        self.assertGreaterEqual(a, b)
        self.assertLess(a, c)

    def test_triangulation(self):
        self.assertBetween(self.tri.points.shape[0], 60, 90)
        self.assertEqual(self.tri.points.shape[1], 3)
        self.assertBetween(self.tri.triangles.shape[0], 40, 70)
        self.assertEqual(self.tri.triangles.shape[1], 3)

    def test_select(self):
        self.assertEqual(self.job.name, "RF")
        self.assertEqual(self.tri.keys().index("RF"),
                         self.job.potentials.argmax())

    def test_grid(self):
        self.assertEqual(self.grid.to_points().shape, (20**3, 3))

    def test_adapt(self):
        self.job.adapt_mesh(triangles=2e2)
        self.assertBetween(self.job.mesh.points.shape[0], 180, 220)
        self.job.adapt_mesh(triangles=1e3)
        self.assertBetween(self.job.mesh.points.shape[0], 700, 1100)

    def test_simulate(self):
        # refine twice adaptively with increasing number of triangles
        self.job.adapt_mesh(triangles=5e2)
        self.job.adapt_mesh(triangles=1e3)
        # solve for charges, get potentials and fields
        result = self.job.simulate(self.grid)

    def test_simulate_no_fmm(self):
        # refine twice adaptively with increasing number of triangles
        self.job.adapt_mesh(triangles=5e2)
        self.job.adapt_mesh(triangles=1e3)
        # solve for charges, get potentials and fields
        result = self.job.simulate(self.grid, num_lev=1)
Exemplo n.º 4
0
def evaluate(prefix, electrodes):
    logging.basicConfig(
        level=logging.DEBUG,
        format="%(asctime)s %(name)s %(processName)s[%(process)s] "
        "%(filename)s:%(funcName)s() %(levelname)s: %(message)s",
        filename="%s.log" % prefix,
        filemode="w")
    sh = logging.StreamHandler()
    sh.setLevel(logging.INFO)
    sh.setFormatter(
        logging.Formatter("%(processName)s[%(process)s] "
                          "%(filename)s:%(funcName)s(): %(message)s"))
    logging.getLogger().addHandler(sh)

    n, s = 2 * 10, .1  # FIXME: parametrize
    grid = Grid(center=(0, 0, 1.5), step=(s, s, s), shape=(n, n, n))

    pool = Pool()
    c = map(run_job,
            ((grid, prefix, (e, True, True, True)) for e in electrodes))

    for e in electrodes:
        Result.view(prefix, e + "_new")
Exemplo n.º 5
0
    result = job.simulate(grid, field=job.name == "RF", num_lev=1)
    result.to_vtk(prefix)
    print("finished job %s" % job.name)
    return job.collect_charges()


# set .1 max area within 3
mesh.areas_from_constraints(
    Sphere(center=np.array([0, 0, 1.]), radius=2, inside=.2, outside=10.))
# retriangulate quality and quiet with areas
mesh.triangulate(opts="qQ", new=False)
# save base mesh to vtk
mesh.to_vtk(prefix)
# grid to evalute potential and fields at
n, s = 2 * 10, .1
grid = Grid(center=(0, 0, 1.5), step=(s, s, s), shape=(n, n, n))
# generate electrode potential configurations to simulate
# use regexps to match electrode names
jobs = list(Configuration.select(mesh, "DC.*", "RF"))
# run the different electrodes on the parallel pool
#pmap = Pool().map # parallel map
pmap = map  # serial map
list(pmap(run_job, ((job, grid, prefix) for job in jobs)))

# isocontour plot of the RF pseudopotential radially
result = Result.from_vtk(prefix, "RF")
p = result.pseudo_potential
x = grid.to_mgrid()[:, p.shape[0] // 2]
p = p[p.shape[0] // 2]
fig, ax = plt.subplots()
ax.set_aspect("equal")