Exemplo n.º 1
0
def addCentralXYZSnapshots(arguments):

    FDTDobj = bfdtd.readBristolFDTD(arguments.infile, arguments.verbosity)

    # hack: remove epsilon snapshots and probes to increase speed
    FDTDobj.clearEpsilonSnapshots()
    FDTDobj.clearProbes()
    FDTDobj.clearAllSnapshots()

    (size, res) = FDTDobj.mesh.getSizeAndResolution()

    if arguments.verbosity > 0:
        print("res = ", res)

    frequency_vector = []
    if arguments.freqListFile is not None:
        frequency_vector.extend(getFrequencies(arguments.freqListFile))
    if arguments.wavelength_mum is not None:
        frequency_vector.extend([get_c0() / i for i in arguments.wavelength_mum])
    if arguments.frequency_MHz is not None:
        frequency_vector.extend(arguments.frequency_MHz)

    if len(frequency_vector) <= 0:
        print("ERROR: Great scot! You forgot to specify frequencies.", file=sys.stderr)
        sys.exit(-1)

    FDTDobj.flag.iterations = arguments.iterations

    # hack: Make sure there will be at least one long duration snapshot at the end
    arguments.repetition = FDTDobj.flag.iterations - arguments.first

    # Add full X,Y,Z central snapshots
    pos = FDTDobj.box.getCentro()

    for i in [0, 1, 2]:
        letter = ["X", "Y", "Z"][i]
        f = FDTDobj.addFrequencySnapshot(letter, pos[i])
        f.name = "central." + letter + ".fsnap"
        f.first = arguments.first
        f.repetition = arguments.repetition
        f.frequency_vector = frequency_vector

    if arguments.outdir is None:
        print("ERROR: no outdir specified", file=sys.stderr)
        sys.exit(-1)

    if arguments.basename is None:
        arguments.basename = os.path.basename(os.path.abspath(arguments.outdir))

    FDTDobj.fileList = []
    FDTDobj.writeAll(arguments.outdir, arguments.basename)
    FDTDobj.writeShellScript(
        arguments.outdir + os.path.sep + arguments.basename + ".sh",
        arguments.basename,
        arguments.executable,
        "$JOBDIR",
        WALLTIME=arguments.walltime,
    )

    return
def addCentralXYZSnapshots(arguments):

  FDTDobj = bfdtd.readBristolFDTD(arguments.infile, arguments.verbosity)
  
  # hack: remove epsilon snapshots and probes to increase speed
  FDTDobj.clearEpsilonSnapshots()
  FDTDobj.clearProbes()
  FDTDobj.clearAllSnapshots()
  
  (size,res) = FDTDobj.mesh.getSizeAndResolution()
  
  if arguments.verbosity>0:
    print('res = ',res)
  
  frequency_vector = []
  if arguments.freqListFile is not None:
    frequency_vector.extend(getFrequencies(arguments.freqListFile))
  if arguments.wavelength_mum is not None:
    frequency_vector.extend([get_c0()/i for i in arguments.wavelength_mum])
  if arguments.frequency_MHz is not None:
    frequency_vector.extend(arguments.frequency_MHz)
  
  if len(frequency_vector)<=0:
    print('ERROR: Great scot! You forgot to specify frequencies.', file=sys.stderr)
    sys.exit(-1)

  FDTDobj.flag.iterations = arguments.iterations
  
  # hack: Make sure there will be at least one long duration snapshot at the end
  arguments.repetition = FDTDobj.flag.iterations - arguments.first
    
  # Add full X,Y,Z central snapshots
  pos = FDTDobj.box.getCentro()

  for i in [0,1,2]:
    letter = ['X','Y','Z'][i]
    f = FDTDobj.addFrequencySnapshot(letter,pos[i]);
    f.name = 'central.'+letter+'.fsnap'
    f.first = arguments.first
    f.repetition = arguments.repetition
    f.frequency_vector = frequency_vector
    
  if arguments.outdir is None:
    print('ERROR: no outdir specified', file=sys.stderr)
    sys.exit(-1)
  
  if arguments.basename is None:
    arguments.basename = os.path.basename(os.path.abspath(arguments.outdir))
  
  FDTDobj.fileList = []  
  FDTDobj.writeAll(arguments.outdir, arguments.basename)
  FDTDobj.writeShellScript(arguments.outdir + os.path.sep + arguments.basename + '.sh', arguments.basename, arguments.executable, '$JOBDIR', WALLTIME = arguments.walltime)

  return
def resonance_run(src, dst, freqListFile):
  ''' Copy src to dst with added frequency snapshots from freqListFile '''
  src = os.path.abspath(src).rstrip(os.sep)
  dst = os.path.abspath(dst).rstrip(os.sep)
  if os.path.isdir(src):
    print(src +' is a directory')
    FDTDobj = bfdtd.readBristolFDTD(src+os.sep+os.path.basename(src)+'.in')
    fileBaseName = os.path.basename(src)
  else:
    print(src +' is not a directory')
    FDTDobj = bfdtd.readBristolFDTD(src)
    fileBaseName = os.path.splitext(os.path.basename(src))[0]
  
  freq_snapshots = getFrequencies(freqListFile)
  for obj in FDTDobj.frequency_snapshot_list:
    obj.frequency_vector = freq_snapshots
  
  FDTDobj.writeAll(dst,fileBaseName)
  FDTDobj.writeShellScript(dst+os.path.sep+fileBaseName+'.sh')
Exemplo n.º 4
0
def resonance_run(src, dst, freqListFile):
    """ Copy src to dst with added frequency snapshots from freqListFile """
    src = os.path.abspath(src).rstrip(os.sep)
    dst = os.path.abspath(dst).rstrip(os.sep)
    if os.path.isdir(src):
        print(src + " is a directory")
        FDTDobj = bfdtd.readBristolFDTD(src + os.sep + os.path.basename(src) + ".in")
        fileBaseName = os.path.basename(src)
    else:
        print(src + " is not a directory")
        FDTDobj = bfdtd.readBristolFDTD(src)
        fileBaseName = os.path.splitext(os.path.basename(src))[0]

    freq_snapshots = getFrequencies(freqListFile)
    for obj in FDTDobj.frequency_snapshot_list:
        obj.frequency_vector = freq_snapshots

    FDTDobj.writeAll(dst, fileBaseName)
    FDTDobj.writeShellScript(dst + os.path.sep + fileBaseName + ".sh")
def addModeVolumeFrequencySnapshots(arguments):
  
  FDTDobj = bfdtd.BFDTDobject()
  FDTDobj.verbosity = arguments.verbosity
  for infile in arguments.infile:
    FDTDobj.readBristolFDTD(infile)
  
  (size,res) = FDTDobj.mesh.getSizeAndResolution()
  
  if arguments.verbosity>0:
    print('res = ',res)

  if arguments.slicing_direction is None:
    # take the direction with the smallest number of snapshots to reduce number of generated .prn files
    S = ['X','Y','Z']
    arguments.slicing_direction = S[res.index(min(res))]
    
  frequency_vector = []
  if arguments.freqListFile is not None:
    frequency_vector.extend(getFrequencies(arguments.freqListFile))
  if arguments.wavelength_mum is not None:
    frequency_vector.extend([get_c0()/i for i in arguments.wavelength_mum])
  if arguments.frequency_MHz is not None:
    frequency_vector.extend(arguments.frequency_MHz)
  
  if len(frequency_vector)<=0:
    print('ERROR: Great scot! You forgot to specify frequencies.', file=sys.stderr)
    sys.exit(-1)

  FDTDobj.flag.iterations = arguments.iterations
  
  NAME = 'ModeVolume'
  #print(arguments.slicing_direction)
  if arguments.slicing_direction == 'X':
    pos_list = FDTDobj.mesh.getXmesh()
    for pos in pos_list:
      e = FDTDobj.addEpsilonSnapshot('X',pos)
      e.name = NAME + '.eps'
      e.first = 1
      e.repetition = FDTDobj.flag.iterations + 1 # So that only one epsilon snapshot is created. We don't need more.
      f = FDTDobj.addFrequencySnapshot('X',pos)
      f.name = NAME + '.freq'
      f.first = arguments.first
      f.repetition = arguments.repetition
      f.starting_sample = arguments.starting_sample
      f.frequency_vector = frequency_vector
  elif arguments.slicing_direction == 'Y':
    pos_list = FDTDobj.mesh.getYmesh()
    for pos in pos_list:
      e = FDTDobj.addEpsilonSnapshot('Y',pos)
      e.name = NAME + '.eps'
      e.first = 1
      e.repetition = FDTDobj.flag.iterations + 1 # So that only one epsilon snapshot is created. We don't need more.
      f = FDTDobj.addFrequencySnapshot('Y',pos)
      f.name = NAME + '.freq'
      f.first = arguments.first
      f.repetition = arguments.repetition
      f.starting_sample = arguments.starting_sample
      f.frequency_vector = frequency_vector
  elif arguments.slicing_direction == 'Z':
    pos_list = FDTDobj.mesh.getZmesh()
    #for pos in pos_list:
    # another quick hack to reduce the number of snapshots to 101 around the center... TODO: add options for that...
    reduced_range = range(len(pos_list))
    pos_mid = int(numpy.floor(len(pos_list)/2))
    #reduced_range = pos_list[ pos_mid-50:pos_mid+50+1]
    reduced_range = pos_list[ pos_mid-25:pos_mid+25+1]
    #reduced_range = pos_list[ pos_mid-1:pos_mid+1+1]
    #reduced_range = pos_list[ pos_mid-12:pos_mid+12+1]

    # temporary hack
    #arguments.repetition = FDTDobj.flag.iterations - arguments.first
    
    full_list = []
    for pos in reduced_range:
      ##pos = pos_list[idx]
      #e = FDTDobj.addEpsilonSnapshot('Z',pos)
      #e.name = NAME + '.eps'
      #e.first = 1
      #e.repetition = FDTDobj.flag.iterations + 1 # So that only one epsilon snapshot is created. We don't need more.
      
      ## and more quick hacks...
      #e.P1[0] = min(reduced_range)
      #e.P1[1] = min(reduced_range)
      #e.P2[0] = max(reduced_range)
      #e.P2[1] = max(reduced_range)
      
      #f = FDTDobj.addFrequencySnapshot('Z',pos)
      #f.name = NAME + '.freq'
      #f.first = arguments.first
      #f.repetition = arguments.repetition
      #f.frequency_vector = frequency_vector
      
      F = bfdtd.FrequencySnapshot()
      F.name = NAME + '.freq'
      F.plane = 'Z'
      F.P1 = [ FDTDobj.box.lower[0], FDTDobj.box.lower[1], pos]
      F.P2 = [ FDTDobj.box.upper[0], FDTDobj.box.upper[1], pos]
      F.first = arguments.first
      F.repetition = arguments.repetition
      F.starting_sample = arguments.starting_sample
      F.frequency_vector = frequency_vector
      
      full_list.append(F)
      
      ## and more quick hacks...
      #f.P1[0] = min(reduced_range)
      #f.P1[1] = min(reduced_range)
      #f.P2[0] = max(reduced_range)
      #f.P2[1] = max(reduced_range)
      
  else:
    print('ERROR: invalid slicing direction : arguments.slicing_direction = ' + str(arguments.slicing_direction), file=sys.stderr)
    sys.exit(-1)

  ## temporary hack to rectify excitation direction
  #P1 = numpy.array(FDTDobj.excitation_list[0].P1)
  #P2 = numpy.array(FDTDobj.excitation_list[0].P2)
  #Pdiff = P2-P1
  #Pdiff = list(Pdiff)
  #exc_dir = Pdiff.index(max(Pdiff))
  #if exc_dir == 0:
    #FDTDobj.excitation_list[0].E = [1,0,0]
  #elif exc_dir == 1:
    #FDTDobj.excitation_list[0].E = [0,1,0]
  #elif exc_dir == 2:
    #FDTDobj.excitation_list[0].E = [0,0,1]
  #else:
    #print('ERROR: wrong exc_dir = '+str(exc_dir)+' Pdiff = '+str(Pdiff), file=sys.stderr)
    #sys.exit(-1)

  # temporary hack to disable frequency snaphsots
  #FDTDobj.clearFrequencySnapshots()
  #FDTDobj.clearTimeSnapshots()

  # Add full X,Y,Z central snapshots for reference
  pos = FDTDobj.box.getCentro()

  for i in [0,1]:
    letter = ['X','Y','Z'][i]
    #e = FDTDobj.addEpsilonSnapshot(letter,pos[i])
    #e.name = 'central.'+letter+'.eps'
    #e.first = 1
    #e.repetition = FDTDobj.flag.iterations + 1 # So that only one epsilon snapshot is created. We don't need more.
    f = FDTDobj.addFrequencySnapshot(letter,pos[i]);
    f.name = 'central.'+letter+'.fsnap'
    f.first = arguments.first
    f.repetition = arguments.repetition
    f.starting_sample = arguments.starting_sample
    f.frequency_vector = frequency_vector
    full_list.append(f)

  print(full_list)
  list_1 = full_list[0:len(full_list)//2]
  list_2 = full_list[len(full_list)//2:len(full_list)]
    
  if arguments.outdir is None:
    print('ERROR: no outdir specified', file=sys.stderr)
    sys.exit(-1)
  
  if arguments.basename is None:
    arguments.basename = os.path.basename(os.path.abspath(arguments.outdir))
  
  # hack: remove epsilon snapshots and probes to increase speed
  FDTDobj.clearAllSnapshots()
  FDTDobj.clearEpsilonSnapshots()
  FDTDobj.clearProbes()
  
  FDTDobj.fileList = []
  
  destdir = os.path.join(arguments.outdir,'./part_1')
  FDTDobj.snapshot_list = list_1
  FDTDobj.writeAll(destdir, arguments.basename)
  FDTDobj.writeShellScript(destdir + os.path.sep + arguments.basename + '.sh', arguments.basename, arguments.executable, '$JOBDIR', WALLTIME = arguments.walltime)

  destdir = os.path.join(arguments.outdir,'./part_2')
  FDTDobj.snapshot_list = list_2
  FDTDobj.writeAll(destdir, arguments.basename)
  FDTDobj.writeShellScript(destdir + os.path.sep + arguments.basename + '.sh', arguments.basename, arguments.executable, '$JOBDIR', WALLTIME = arguments.walltime)

  return
Exemplo n.º 6
0
def addModeVolumeFrequencySnapshots(arguments):

    FDTDobj = bfdtd.BFDTDobject()
    FDTDobj.verbosity = arguments.verbosity
    for infile in arguments.infile:
        FDTDobj.readBristolFDTD(infile)

    (size, res) = FDTDobj.mesh.getSizeAndResolution()

    if arguments.verbosity > 0:
        print("res = ", res)

    if arguments.slicing_direction is None:
        # take the direction with the smallest number of snapshots to reduce number of generated .prn files
        S = ["X", "Y", "Z"]
        arguments.slicing_direction = S[res.index(min(res))]

    frequency_vector = []
    if arguments.freqListFile is not None:
        frequency_vector.extend(getFrequencies(arguments.freqListFile))
    if arguments.wavelength_mum is not None:
        frequency_vector.extend([get_c0() / i for i in arguments.wavelength_mum])
    if arguments.frequency_MHz is not None:
        frequency_vector.extend(arguments.frequency_MHz)

    if len(frequency_vector) <= 0:
        print("ERROR: Great scot! You forgot to specify frequencies.", file=sys.stderr)
        sys.exit(-1)

    FDTDobj.flag.iterations = arguments.iterations

    NAME = "ModeVolume"
    # print(arguments.slicing_direction)
    if arguments.slicing_direction == "X":
        pos_list = FDTDobj.mesh.getXmesh()
        for pos in pos_list:
            e = FDTDobj.addEpsilonSnapshot("X", pos)
            e.name = NAME + ".eps"
            e.first = 1
            e.repetition = (
                FDTDobj.flag.iterations + 1
            )  # So that only one epsilon snapshot is created. We don't need more.
            f = FDTDobj.addFrequencySnapshot("X", pos)
            f.name = NAME + ".freq"
            f.first = arguments.first
            f.repetition = arguments.repetition
            f.starting_sample = arguments.starting_sample
            f.frequency_vector = frequency_vector
    elif arguments.slicing_direction == "Y":
        pos_list = FDTDobj.mesh.getYmesh()
        for pos in pos_list:
            e = FDTDobj.addEpsilonSnapshot("Y", pos)
            e.name = NAME + ".eps"
            e.first = 1
            e.repetition = (
                FDTDobj.flag.iterations + 1
            )  # So that only one epsilon snapshot is created. We don't need more.
            f = FDTDobj.addFrequencySnapshot("Y", pos)
            f.name = NAME + ".freq"
            f.first = arguments.first
            f.repetition = arguments.repetition
            f.starting_sample = arguments.starting_sample
            f.frequency_vector = frequency_vector
    elif arguments.slicing_direction == "Z":
        pos_list = FDTDobj.mesh.getZmesh()
        # for pos in pos_list:
        # another quick hack to reduce the number of snapshots to 101 around the center... TODO: add options for that...
        reduced_range = range(len(pos_list))
        pos_mid = int(numpy.floor(len(pos_list) / 2))
        # reduced_range = pos_list[ pos_mid-50:pos_mid+50+1]
        reduced_range = pos_list[pos_mid - 25 : pos_mid + 25 + 1]
        # reduced_range = pos_list[ pos_mid-1:pos_mid+1+1]
        # reduced_range = pos_list[ pos_mid-12:pos_mid+12+1]

        # temporary hack
        # arguments.repetition = FDTDobj.flag.iterations - arguments.first

        full_list = []
        for pos in reduced_range:
            ##pos = pos_list[idx]
            # e = FDTDobj.addEpsilonSnapshot('Z',pos)
            # e.name = NAME + '.eps'
            # e.first = 1
            # e.repetition = FDTDobj.flag.iterations + 1 # So that only one epsilon snapshot is created. We don't need more.

            ## and more quick hacks...
            # e.P1[0] = min(reduced_range)
            # e.P1[1] = min(reduced_range)
            # e.P2[0] = max(reduced_range)
            # e.P2[1] = max(reduced_range)

            # f = FDTDobj.addFrequencySnapshot('Z',pos)
            # f.name = NAME + '.freq'
            # f.first = arguments.first
            # f.repetition = arguments.repetition
            # f.frequency_vector = frequency_vector

            F = bfdtd.FrequencySnapshot()
            F.name = NAME + ".freq"
            F.plane = "Z"
            F.P1 = [FDTDobj.box.lower[0], FDTDobj.box.lower[1], pos]
            F.P2 = [FDTDobj.box.upper[0], FDTDobj.box.upper[1], pos]
            F.first = arguments.first
            F.repetition = arguments.repetition
            F.starting_sample = arguments.starting_sample
            F.frequency_vector = frequency_vector

            full_list.append(F)

            ## and more quick hacks...
            # f.P1[0] = min(reduced_range)
            # f.P1[1] = min(reduced_range)
            # f.P2[0] = max(reduced_range)
            # f.P2[1] = max(reduced_range)

    else:
        print(
            "ERROR: invalid slicing direction : arguments.slicing_direction = " + str(arguments.slicing_direction),
            file=sys.stderr,
        )
        sys.exit(-1)

    ## temporary hack to rectify excitation direction
    # P1 = numpy.array(FDTDobj.excitation_list[0].P1)
    # P2 = numpy.array(FDTDobj.excitation_list[0].P2)
    # Pdiff = P2-P1
    # Pdiff = list(Pdiff)
    # exc_dir = Pdiff.index(max(Pdiff))
    # if exc_dir == 0:
    # FDTDobj.excitation_list[0].E = [1,0,0]
    # elif exc_dir == 1:
    # FDTDobj.excitation_list[0].E = [0,1,0]
    # elif exc_dir == 2:
    # FDTDobj.excitation_list[0].E = [0,0,1]
    # else:
    # print('ERROR: wrong exc_dir = '+str(exc_dir)+' Pdiff = '+str(Pdiff), file=sys.stderr)
    # sys.exit(-1)

    # temporary hack to disable frequency snaphsots
    # FDTDobj.clearFrequencySnapshots()
    # FDTDobj.clearTimeSnapshots()

    # Add full X,Y,Z central snapshots for reference
    pos = FDTDobj.box.getCentro()

    for i in [0, 1]:
        letter = ["X", "Y", "Z"][i]
        # e = FDTDobj.addEpsilonSnapshot(letter,pos[i])
        # e.name = 'central.'+letter+'.eps'
        # e.first = 1
        # e.repetition = FDTDobj.flag.iterations + 1 # So that only one epsilon snapshot is created. We don't need more.
        f = FDTDobj.addFrequencySnapshot(letter, pos[i])
        f.name = "central." + letter + ".fsnap"
        f.first = arguments.first
        f.repetition = arguments.repetition
        f.starting_sample = arguments.starting_sample
        f.frequency_vector = frequency_vector
        full_list.append(f)

    print(full_list)
    list_1 = full_list[0 : len(full_list) // 2]
    list_2 = full_list[len(full_list) // 2 : len(full_list)]

    if arguments.outdir is None:
        print("ERROR: no outdir specified", file=sys.stderr)
        sys.exit(-1)

    if arguments.basename is None:
        arguments.basename = os.path.basename(os.path.abspath(arguments.outdir))

    # hack: remove epsilon snapshots and probes to increase speed
    FDTDobj.clearAllSnapshots()
    FDTDobj.clearEpsilonSnapshots()
    FDTDobj.clearProbes()

    FDTDobj.fileList = []

    destdir = os.path.join(arguments.outdir, "./part_1")
    FDTDobj.snapshot_list = list_1
    FDTDobj.writeAll(destdir, arguments.basename)
    FDTDobj.writeShellScript(
        destdir + os.path.sep + arguments.basename + ".sh",
        arguments.basename,
        arguments.executable,
        "$JOBDIR",
        WALLTIME=arguments.walltime,
    )

    destdir = os.path.join(arguments.outdir, "./part_2")
    FDTDobj.snapshot_list = list_2
    FDTDobj.writeAll(destdir, arguments.basename)
    FDTDobj.writeShellScript(
        destdir + os.path.sep + arguments.basename + ".sh",
        arguments.basename,
        arguments.executable,
        "$JOBDIR",
        WALLTIME=arguments.walltime,
    )

    return