Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure highly factorizable MPB sizes #1244

Merged
merged 1 commit into from
Jun 12, 2020
Merged

ensure highly factorizable MPB sizes #1244

merged 1 commit into from
Jun 12, 2020

Conversation

stevengj
Copy link
Collaborator

Fixes #1243.

@oskooi
Copy link
Collaborator

oskooi commented Jun 11, 2020

This PR does seem to generally provide a slight improvement compared to master in reducing the time for the MPB calculation in cases where the resolution is not factorizable (although the time reduction is not anywhere near an order of magnitude or more). This is demonstrated in the following test involving an eigenmode source for a 3d ridge waveguide. The wall-clock time for the eigenmode source as a function of the resolution in the integer range of 10 to 100 is shown using a linear and log-log plot.

Another feature of this PR apparent in the plots is that the MPB wall-clock time shows less variation than master with changes in the resolution.

eigsrc_mpb_time_comparison_linear

eigsrc_mpb_time_comparison_loglog

import meep as mp
import argparse

def main(args):
    resolution = args.res

    h = 0.22       # waveguide height                                                                                                                              
    w = 0.50       # waveguide width                                                                                                                               

    Si = mp.Medium(index=3.5)
    cladding = mp.Medium(index=1.5)

    sxy = 4
    sz = 4
    cell_size = mp.Vector3(sxy,sxy,sz)

    # input waveguide                                                                                                                                               
    geometry = [mp.Block(material=Si,
                         center=mp.Vector3(),
                         size=mp.Vector3(mp.inf,w,h))]

    dpml = 1.0
    boundary_layers = [mp.PML(dpml)]

    # mode frequency                                                                                                                                                
    fcen = 1/1.55

    # source width                                                                                                                                                  
    df = 0.2*fcen

    symmetries = [mp.Mirror(mp.Y,-1),mp.Mirror(mp.Z,+1)]               

    eig_parity = mp.ODD_Y+mp.EVEN_Z

    sources = [mp.EigenModeSource(src=mp.GaussianSource(fcen,fwidth=df),
                                  size=mp.Vector3(0,sxy-2*dpml,sz-2*dpml),
                                  center=mp.Vector3(-0.5*sxy+dpml,0,0),
                                  eig_match_freq=True,
                                  eig_parity=eig_parity)]

    sim = mp.Simulation(resolution=resolution,
			cell_size=cell_size,
			boundary_layers=boundary_layers,
			geometry=geometry,
			default_material=cladding,
			sources=sources,
			symmetries=symmetries)

    sim.init_sim()

    print("mpb-time:, {}, {}".format(resolution,sim.time_spent_on(6)[0]))

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-res', type=int, default=20, help='resolution (pixels/um)')
    args = parser.parse_args()
    main(args)

@stevengj stevengj merged commit 0c6942d into master Jun 12, 2020
@stevengj stevengj deleted the nextpow2357 branch June 12, 2020 19:56
@stevengj
Copy link
Collaborator Author

Note that this will only make a big difference if the number of pixels you are passing to MPB is a prime number.

If you resolution and the width of the eigenmode source are both nice "round" numbers, then their product isn't going to be prime.

@oskooi
Copy link
Collaborator

oskooi commented Jun 13, 2020

Indeed, by modifying the resolution to be less "rounded" via resolution = args.res + random.random(), the improvement in the MPB wall-clock time enabled by this PR compared to master becomes more pronounced than using integer values (approaching a factor of ~2 at a resolution of around 100).

eigsrc_mpb_time_comparison3

bencbartlett pushed a commit to bencbartlett/meep that referenced this pull request Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pass optimized grid size to MPB mode solver
2 participants