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()
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)
nz = int(lz / d) + 1 nx = ny = int(lx / d) + 1 origin = [-0.5 * lx, -0.5 * ly, 0.0] # set the grid grid = mx.Grid([nx, ny, nz], origin, [lx, ly, lz]) ########################## ########################## # 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)
sys.path.insert(0, "../src") import mx import os import math baseName = "phcMu" dim = 3 l = 1.0 o = 0.0 r = 16 #resolution in each direction # set the grid grid = mx.Grid(dim * [r], dim * [o], dim * [l]) # boundary conditions bcs = mx.BoundaryConditions() bcs.setLowerBCs(['periodic', 'periodic', 'periodic']) bcs.setUpperBCs(['periodic', 'periodic', 'periodic']) factor = 0.0e-8 bcs.setPhaseShifts( [factor * math.pi / 4., factor * math.pi / 3., factor * math.pi]) #bcs.setPhaseShifts([0, 0, factor*math.pi]) sph = mx.Sphere(0.37, [l / 2., l / 2., l / 2.]) mu = mx.Mu(sph, muDiag=[9.4, 9.4, 11.6], losstan=0.e-1) #diel = mx.Dielectric(sph, epsDiag=[1.0, 1.0, 1.0]) # setup simulation sim = mx.Simulation(baseName, dim) sim.setGrid(grid) sim.addMu(mu)