Example #1
0
def writeSim(n, lbcs, pointSets):
    sim = mx.Simulation(simName, dim)

    grid = mx.Grid(3 * [n], origin, [lx, ly, lz])

    output = mx.Output()
    for name, points in pointSets.iteritems():
        output.fieldValues(name, points)

    bcs = mx.BoundaryConditions()
    bcs.setUpperBCs(["pec", "pec", "pec"])
    bcs.setLowerBCs(lbcs)

    eigParams = globEigParams
    eigParams["nev"] = len(dm.octModes(lbcs, nev)[0])

    sim.setGrid(grid)
    sim.addDielectric(diel)
    sim.addPEC(pecSph)
    sim.setBCs(bcs)
    sim.setOutput(output)
    sim.setEigensolverParameters(eigParams)
    sim.write()
Example #2
0
def main():

    # create the cmd line parser
    parser = argparse.ArgumentParser()

    # Just examples for now
    parser.add_argument("-m",
                        "--maximum-time",
                        help="Maximum time (seconds) the job will run",
                        action="store",
                        dest="maxtime",
                        type=int)
    parser.add_argument("-t",
                        "--testing",
                        help="test signal catching",
                        action="store_true")
    (args, unkargs) = parser.parse_known_args()

    # Basic parameters from Zhu, Brown,
    # "Full-vectorial finite-difference analysis of microstructured optical fibers"
    # The calculation window is chosen to be the first quadrant of the fiber
    # cross section with a computation window size of 6um by 6 um.
    fiberRadius = 3.e-6
    refractionIndex = 1.45
    n_eff = 1.438604  # Computed value
    wavelen = 1.5e-6
    relPermittivity = refractionIndex**2
    vacWavelen = wavelen * refractionIndex
    freq = speed_of_light / (wavelen / n_eff)
    print("Vacuum wavelength = %g, frequency = %g" % (vacWavelen, freq))

    # Grid parameters
    resolution = 0.05  # Number of cells per wavelength
    endyz = 6.e-6
    bgnyz = -endyz
    lenyz = endyz - bgnyz
    dl = resolution * fiberRadius
    yzcells_half = int(endyz / dl)
    yzcells = 2 * yzcells_half
    xcells = 2
    lenx = xcells * dl
    print("%d cells in the x direction, %d cells in the y and z directions." %
          (xcells, yzcells))
    # set the grid
    dim = 3
    grid = mx.Grid([xcells, yzcells, yzcells], [0., bgnyz, bgnyz],
                   [lenx, lenyz, lenyz])

    # boundary conditions
    bcs = mx.BoundaryConditions()
    bcs.setLowerBCs(['periodic', 'pec', 'pec'])
    bcs.setUpperBCs(['periodic', 'pec', 'pec'])
    kay = n_eff * 2. * math.pi / vacWavelen
    phaseShift = kay * lenx
    bcs.setPhaseShifts([phaseShift, 0., 0.])
    print("phase shift = %g." % (phaseShift))

    cylLen = lenx + 4. * dl
    cylStart = -2. * dl
    cyl = mx.Cylinder(fiberRadius, [1., 0., 0.], [cylStart, 0., 0.])
    # mu = mx.Mu(sph, muDiag=[9.4, 9.4, 11.6], losstan=0.e-1)
    diel = mx.Dielectric(
        cyl, epsDiag=[relPermittivity, relPermittivity, relPermittivity])

    # setup simulation
    baseName = "cylinder"  # Should come from args
    sim = mx.Simulation(baseName, dim)
    sim.setGrid(grid)
    sim.addDielectric(diel)
    sim.setBCs(bcs)

    # create new eigensolver object
    eig = mx.Eigensolver()
    eig.setParams({"nev": 10, "basis": 30})
    prec = mx.AMG()
    lin = mx.LinearSolver(prec=prec)
    # lin.setParams({"sweeps": 2, "type": "gmres",
    # "prec type": "amg",
    # "smoother": "Chebyshev",
    # "levels": 10, "basis": 20})
    eig.setLinearSolver(lin)
    sim.setSolver(eig)

    # Write input file and run simulation
    sim.write()
    mxwl = "../../builds/maxwell/ser/src/maxwell"
    exline = mxwl + " --infile=" + baseName + ".mx"
    print(exline)
    if os.path.isfile(mxwl):
        os.system(exline)
Example #3
0
##########################
# Boundary conditions
##########################

bcs = mx.BoundaryConditions()  # defaults to periodic in all directions
#bcs.setUpperBCs(["pec","pec","pec"])
#bcs.setLowerBCs(["pec","pec","pec"])
bcs.setPhaseShifts([0, 0, phAdv])
#bcs.setPhaseShifts([0, 0, 0])

##########################

##########################
# Simulation setup
##########################

sim = mx.Simulation(baseName, dim)
sim.setGrid(grid)
sim.addPEC(cav)
sim.setBCs(bcs)
sim.setEigensolverParameters({"nev": 10, "basis": 20})
sim.setLinearSolverParameters({
    "sweeps": 2,
    "type": "gmres",
    "prec type": "amg",
    "levels": 2,
    "basis": 20,
    "smoother": "Chebyshev"
})
sim.write()
Example #4
0
o = -0.5

# the object
sph = mx.Sphere(0.37, [0.0, 0.0, 0.0])
epsDiag = [10.225, 10.225, 9.95]
epsOffDiag = [0.67360967926537398, -0.67360967926537398, -0.825]
diel = mx.Dielectric(sph, epsDiag=epsDiag, epsOffDiag=epsOffDiag)

# the solver
solver = mx.Eigensolver()

#resolutions = range(8, 32)
resolutions = [36]
print resolutions

for r in resolutions:
    name = baseName + "-%.3d" % r

    grid = mx.Grid(dim * [r], dim * [o], dim * [l])
    sim = mx.Simulation(name, dim)

    sim.setGrid(grid)
    sim.addDielectric(diel)
    #sim.setLinearSolverParameters({"sweeps": 5, "type": "gmg-gmres", "levels": 3, "basis": 20})
    sim.setSolver(solver)
    sim.write()

    #os.system("mpirun -machinefile ./nodes -np 4 src/maxwell --infile=%s" % (name + ".mx"))
    #os.system("src/maxwell --infile=%s" % (name + ".mx"))
    #os.system("cp mxEigenfrequenciesReal.h5 eigfreqs-fit-phc-sapph/eigfreqs%.3d.h5" % r)
Example #5
0
pad = 2

delta = cellLen / float(cellRes)
nz = numCells * cellRes + 2 * pad
lz = float(nz) * delta
oz = -0.5 * lz

ny = nx = 2 * (int(math.ceil(cavRad / delta)) + pad)
ly = lx = float(nx) * delta
oy = ox = -0.5 * lx

grid = mx.Grid([nx, ny, nz], [ox, oy, oz], [lx, ly, lz])

# simulation setup

sim = mx.Simulation("crabcav.mx", 3)
sim.setGrid(grid)
sim.addPEC(cav)
sim.setLinearSolverParameters({"sweeps": 3})
sim.setEigensolverParameters({"nev": 15})
sim.write()

sys.exit()

resolutions = range(36, 40)
print resolutions

for r in resolutions:
    name = baseName + "-%.3d" % r

    grid = mx.Grid(dim * [r], dim * [o], dim * [l])