コード例 #1
0
def automeshWithMaxCells(infile, outfile, meshing_factor, MAXCELLS, Lambda, a):
    sim = bfdtd.readBristolFDTD(infile)
    sim.autoMeshGeometry(meshing_factor)
    sim.writeInpFile(outfile)

    sim = bfdtd.readBristolFDTD(infile)
    sim.autoMeshGeometry(Lambda / a)
    while (sim.getNcells() > MAXCELLS and a > 1):
        a = a - 1
        sim.autoMeshGeometry(Lambda / a)
    sim.writeInpFile(outfile)
コード例 #2
0
def automeshWithMaxCells(infile, outfile, meshing_factor, MAXCELLS, Lambda, a):
    sim = bfdtd.readBristolFDTD(infile)
    sim.autoMeshGeometry(meshing_factor)
    sim.writeInpFile(outfile)

    sim = bfdtd.readBristolFDTD(infile)
    sim.autoMeshGeometry(Lambda / a)
    while sim.getNcells() > MAXCELLS and a > 1:
        a = a - 1
        sim.autoMeshGeometry(Lambda / a)
    sim.writeInpFile(outfile)
コード例 #3
0
def efficiency_run(src, dst):
    """ Copy src to dst while removing the geometry """
    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]

    FDTDobj.geometry_object_list[:] = []
    FDTDobj.writeAll(dst, fileBaseName)
コード例 #4
0
def efficiency_run(src, dst):
  ''' Copy src to dst while removing the geometry '''
  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]
    
  FDTDobj.geometry_object_list[:] = []
  FDTDobj.writeAll(dst,fileBaseName)
コード例 #5
0
def copyBFDTD(src, dst):
    """ Copy src to dst """
    src = src.rstrip(os.sep)
    dst = 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]

    FDTDobj.writeAll(dst, fileBaseName)
    bfdtd.GEOshellscript(dst + os.sep + fileBaseName + ".sh", fileBaseName, "$HOME/bin/fdtd", "$JOBDIR", WALLTIME=360)
コード例 #6
0
def copyBFDTD(src,dst):
  ''' Copy src to dst '''
  src = src.rstrip(os.sep)
  dst = 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]
  
  FDTDobj.writeAll(dst,fileBaseName)
  bfdtd.GEOshellscript(dst+os.sep+fileBaseName+'.sh', fileBaseName,'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)
コード例 #7
0
def fixSnapshots(infile, newbasename):
    '''
  -read infile
  -remove any time snapshots
  -set frequency snapshots to first=3200, repetition=32000
  -move snapshots 1 grid away from excitation.P1
  -write to ./fixedSnapshots/newbasename
  '''
    sim = bfdtd.readBristolFDTD(infile)
    sim.fileList = []
    sim.clearTimeSnapshots()
    for s in sim.snapshot_list:
        s.first = 3200
        s.repetition = 32000

    refP = sim.excitation_list[0].P1

    (idxX, valX) = findNearest(sim.mesh.getXmesh(), refP[0])
    (idxY, valY) = findNearest(sim.mesh.getYmesh(), refP[1])
    (idxZ, valZ) = findNearest(sim.mesh.getZmesh(), refP[2])

    sim.snapshot_list[0].P1[0] = sim.snapshot_list[0].P2[
        0] = sim.mesh.getXmesh()[idxX - 1]
    sim.snapshot_list[1].P1[1] = sim.snapshot_list[1].P2[
        1] = sim.mesh.getYmesh()[idxY - 1]
    sim.snapshot_list[2].P1[2] = sim.snapshot_list[2].P2[
        2] = sim.mesh.getZmesh()[idxZ - 1]

    sim.writeAll('./fixedSnapshots', newbasename)
コード例 #8
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
コード例 #9
0
def clearOutputs(arguments):
    if arguments.infile is None:
        print('ERROR: No infile specified.')
        sys.exit(-1)

    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 = bfdtd.readBristolFDTD(arguments.infile, arguments.verbosity)
    FDTDobj.clearProbes()
    FDTDobj.clearAllSnapshots()

    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
コード例 #10
0
def clearOutputs(arguments):
    if arguments.infile is None:
        print("ERROR: No infile specified.")
        sys.exit(-1)

    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 = bfdtd.readBristolFDTD(arguments.infile, arguments.verbosity)
    FDTDobj.clearProbes()
    FDTDobj.clearAllSnapshots()

    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
コード例 #11
0
def fixSnapshots(infile, newbasename):
    """
  -read infile
  -remove any time snapshots
  -set frequency snapshots to first=3200, repetition=32000
  -move snapshots 1 grid away from excitation.P1
  -write to ./fixedSnapshots/newbasename
  """
    sim = bfdtd.readBristolFDTD(infile)
    sim.fileList = []
    sim.clearTimeSnapshots()
    for s in sim.snapshot_list:
        s.first = 3200
        s.repetition = 32000

    refP = sim.excitation_list[0].P1

    (idxX, valX) = findNearest(sim.mesh.getXmesh(), refP[0])
    (idxY, valY) = findNearest(sim.mesh.getYmesh(), refP[1])
    (idxZ, valZ) = findNearest(sim.mesh.getZmesh(), refP[2])

    sim.snapshot_list[0].P1[0] = sim.snapshot_list[0].P2[0] = sim.mesh.getXmesh()[idxX - 1]
    sim.snapshot_list[1].P1[1] = sim.snapshot_list[1].P2[1] = sim.mesh.getYmesh()[idxY - 1]
    sim.snapshot_list[2].P1[2] = sim.snapshot_list[2].P2[2] = sim.mesh.getZmesh()[idxZ - 1]

    sim.writeAll("./fixedSnapshots", newbasename)
コード例 #12
0
def rerun_with_new_excitation(src, dst, excitation_wavelength_nm, excitation_time_constant):
  ''' Copy src to dst, only changing excitation_wavelength_nm and excitation_time_constant'''
  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]
    
  FDTDobj.excitation_list[0].time_constant = excitation_time_constant
  FDTDobj.excitation_list[0].frequency = get_c0()/(1e-3*excitation_wavelength_nm)
    
  FDTDobj.writeAll(dst,fileBaseName)
  bfdtd.GEOshellscript(dst+os.sep+fileBaseName+'.sh', fileBaseName,'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)
コード例 #13
0
def rerun_with_new_excitation(src, dst, excitation_wavelength_nm, excitation_time_constant):
    """ Copy src to dst, only changing excitation_wavelength_nm and excitation_time_constant"""
    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]

    FDTDobj.excitation_list[0].time_constant = excitation_time_constant
    FDTDobj.excitation_list[0].frequency = get_c0() / (1e-3 * excitation_wavelength_nm)

    FDTDobj.writeAll(dst, fileBaseName)
    bfdtd.GEOshellscript(dst + os.sep + fileBaseName + ".sh", fileBaseName, "$HOME/bin/fdtd", "$JOBDIR", WALLTIME=360)
コード例 #14
0
def printFrequencySnapshotInfo(arguments):
    FDTDobj = bfdtd.readBristolFDTD(*arguments.infile,
                                    verbosity=arguments.BFDTDreader_verbosity)

    for idx, fsnap in enumerate(FDTDobj.getFrequencySnapshots()):
        print('idx+1={}, name={}, plane={}, f={}, centro={}, pos:{}={}'.format(
            idx + 1, fsnap.getName(), fsnap.getPlaneLetter(),
            fsnap.getFrequencies(), fsnap.getCentro(), fsnap.getPlaneLetter(),
            fsnap.getCentro()[fsnap.getPlanePythonIndex()]))
    return
コード例 #15
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")
コード例 #16
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')
コード例 #17
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
コード例 #18
0
def calculateModeVolume(arguments):
    # .. todo:: Finish this
    # NOTE: Add way to specify snapshots, epsilon/frequency snapshot pairs

    # read in mesh
    if arguments.meshfile is None:
        print('ERROR: No meshfile specified.', file=sys.stderr)
        sys.exit(-1)
    sim_mesh = bfdtd.readBristolFDTD(arguments.meshfile, arguments.verbosity)

    # read in snapshot files from the various input files
    if len(arguments.infile) <= 0:
        print('ERROR: No infile(s) specified.', file=sys.stderr)
        sys.exit(-1)
    sim_in = bfdtd.BFDTDobject()
    sim_in.verbosity = arguments.verbosity
    for infile in arguments.infile:
        sim_in.readBristolFDTD(infile)

    # .. todo:: add path of file based on where it was read from
    # .. todo:: read in .prn files
    # calculate mode volume

    snaplist = sim_in.getFrequencySnapshots()
    for numID in range(len(snaplist)):
        snapshot = snaplist[numID]
        #print(['x','y','z'][snapshot.plane-1])
        #print(sim_in.flag.id_string)
        fsnap_filename, alphaID, pair = brisFDTD_ID_info.numID_to_alphaID_FrequencySnapshot(
            numID + 1, ['x', 'y', 'z'][snapshot.plane - 1],
            sim_in.flag.id_string.strip('"'),
            snap_time_number=1)
        print(fsnap_filename)
        esnap_filename, alphaID, pair = brisFDTD_ID_info.numID_to_alphaID_EpsilonSnapshot(
            numID + 1, ['x', 'y', 'z'][snapshot.plane - 1],
            sim_in.flag.id_string.strip('"'),
            snap_time_number=1)
        print(esnap_filename)

    #if arguments.fsnapfiles is None:
    #arguments.fsnapfiles = sim_in.getFrequencySnapshots():
    #if arguments.esnapfiles is None:
    #arguments.esnapfiles = sim_in.getEpsilonSnapshots()

    #if len(arguments.fsnapfiles) != len(arguments.esnapfiles):
    #print('ERROR: number of frequency snapshots and epsilon snapshots do not match', file=sys.stderr)
    #sys.exit(-1)
    #else:
    #print('OK')

    #print(arguments.fsnapfiles)
    #print(arguments.esnapfiles)

    return
コード例 #19
0
def calculateModeVolume(arguments):
    # TODO: Finish this
    # NOTE: Add way to specify snapshots, epsilon/frequency snapshot pairs

    # read in mesh
    if arguments.meshfile is None:
        print("ERROR: No meshfile specified.", file=sys.stderr)
        sys.exit(-1)
    sim_mesh = bfdtd.readBristolFDTD(arguments.meshfile, arguments.verbosity)

    # read in snapshot files from the various input files
    if len(arguments.infile) <= 0:
        print("ERROR: No infile(s) specified.", file=sys.stderr)
        sys.exit(-1)
    sim_in = bfdtd.BFDTDobject()
    sim_in.verbosity = arguments.verbosity
    for infile in arguments.infile:
        sim_in.readBristolFDTD(infile)

    # TODO: add path of file based on where it was read from
    # TODO: read in .prn files
    # calculate mode volume

    snaplist = sim_in.getFrequencySnapshots()
    for numID in range(len(snaplist)):
        snapshot = snaplist[numID]
        # print(['x','y','z'][snapshot.plane-1])
        # print(sim_in.flag.id_string)
        fsnap_filename, alphaID, pair = brisFDTD_ID_info.numID_to_alphaID_FrequencySnapshot(
            numID + 1, ["x", "y", "z"][snapshot.plane - 1], sim_in.flag.id_string.strip('"'), snap_time_number=1
        )
        print(fsnap_filename)
        esnap_filename, alphaID, pair = brisFDTD_ID_info.numID_to_alphaID_EpsilonSnapshot(
            numID + 1, ["x", "y", "z"][snapshot.plane - 1], sim_in.flag.id_string.strip('"'), snap_time_number=1
        )
        print(esnap_filename)

    # if arguments.fsnapfiles is None:
    # arguments.fsnapfiles = sim_in.getFrequencySnapshots():
    # if arguments.esnapfiles is None:
    # arguments.esnapfiles = sim_in.getEpsilonSnapshots()

    # if len(arguments.fsnapfiles) != len(arguments.esnapfiles):
    # print('ERROR: number of frequency snapshots and epsilon snapshots do not match', file=sys.stderr)
    # sys.exit(-1)
    # else:
    # print('OK')

    # print(arguments.fsnapfiles)
    # print(arguments.esnapfiles)

    return
コード例 #20
0
def printFormattedString(arguments):
    FDTDobj = bfdtd.readBristolFDTD(*arguments.infile,
                                    verbosity=arguments.BFDTDreader_verbosity)

    dt = FDTDobj.getTimeStep()
    iterations = FDTDobj.getIterations()
    total_time = FDTDobj.getSimulationTime()

    lmin = []
    lcen = []
    lmax = []
    fmin = []
    fcen = []
    fmax = []
    eloc = []

    for E in FDTDobj.getExcitations():
        lmin.append(E.getWavelengthMin())
        lcen.append(E.getWavelength())
        lmax.append(E.getWavelengthMax())
        fmin.append(E.getFrequencyMin())
        fcen.append(E.getFrequency())
        fmax.append(E.getFrequencyMax())
        eloc.append(E.getLocation())

    print(
        arguments.FORMAT.format(dt=dt,
                                total_time=total_time,
                                iterations=iterations,
                                lmin=lmin,
                                lcen=lcen,
                                lmax=lmax,
                                fmin=fmin,
                                fcen=fcen,
                                fmax=fmax,
                                eloc=eloc))
    return
コード例 #21
0
def rotate(infile, outfile, axis_point, axis_direction, angle_degrees):
    sim = bfdtd.readBristolFDTD(infile)
    sim.rotate(axis_point, axis_direction, angle_degrees)
    sim.writeGeoFile(outfile)
コード例 #22
0
def rotate(infile, outfile, axis_point, axis_direction, angle_degrees):
    sim = bfdtd.readBristolFDTD(infile)
    sim.rotate(axis_point, axis_direction, angle_degrees)
    sim.writeGeoFile(outfile)
コード例 #23
0
def automeshWithMeshingFactor(infile, outfile, meshing_factor):
    sim = bfdtd.readBristolFDTD(infile)
    sim.autoMeshGeometry(meshing_factor)
    sim.writeInpFile(outfile)
コード例 #24
0
def process(maindir,
            destdir,
            overwrite,
            dry_run,
            disabled_epsilon=False,
            disabled_directions=[]):
    print('maindir = {}'.format(maindir))
    print('destdir = {}'.format(destdir))
    print('overwrite = {}'.format(overwrite))
    print('dry_run = {}'.format(dry_run))
    print('disabled_epsilon = {}'.format(disabled_epsilon))
    print('disabled_directions = {}'.format(disabled_directions))

    for direction in ['Ex', 'Ey', 'Ez']:

        if direction not in disabled_directions:
            # get the frequency list, to fail quickly in case of problems
            flist = os.path.join(maindir, direction, 'frequency-selection.txt')
            freq_MHz_list = getFrequencies(flist)

        # read in base file
        infile = os.path.join(maindir, direction, 'RCD111.in')
        sim = readBristolFDTD(infile, verbosity=0)
        sim.setFileBaseName('RCD111')
        # clean sim
        sim.clearProbes()
        sim.clearAllSnapshots()
        sim.clearFileList()

        # get excitation location
        excitation = sim.getExcitations()[0]
        excitation_location = excitation.getLocation()

        # get min/max param values
        dt = sim.getTimeStep()
        time_offset = max(
            excitation.getTimeOffset(),
            MIN_TIME_OFFSET_TIME_CONSTANT_RATIO * excitation.getTimeConstant())
        starting_sample_min = int(
            ceil((time_offset + MIN_TIME_OFFSET_TIME_CONSTANT_RATIO *
                  excitation.getTimeConstant()) / dt))
        #print(dt)
        #print(starting_sample_min)
        Npoints_per_period_min = int(
            floor((1 / excitation.getFrequencyMax()) / dt))
        #print(Npoints_per_period_min)
        repetition_min_1 = int(
            ceil((MIN_SAMPLINGTIME_MAXPERIOD_RATIO /
                  excitation.getFrequencyMin()) / dt))
        repetition_min_2 = int(
            ceil(
                (MIN_NFFT_POINTS_IN_EXCITATION_RANGE /
                 (excitation.getFrequencyMax() - excitation.getFrequencyMin()))
                / dt))
        #print(repetition_min_1)
        #print(repetition_min_2)

        first_min = starting_sample_min + max(repetition_min_1,
                                              repetition_min_2)
        #print(first_min)

        repetition = max([repetition_min_1, repetition_min_2] + REPETITION)
        starting_sample = max([starting_sample_min] + STARTING_SAMPLE)
        first = max([starting_sample + repetition] + FIRST)

        print('starting_sample = {}, first = {}, repetition = {}'.format(
            starting_sample, first, repetition))

        #print('starting_sample = {}'.format(starting_sample))
        #print('first = {}'.format(first))
        #print('repetition = {}'.format(repetition))

        # set up the volume box
        partial_box = SnapshotBoxVolume()

        # set up the XYZ box
        xyz_box = SnapshotBoxXYZ()
        xyz_box.setIntersectionPoint(excitation_location)

        # MV box size is chosen so that it will cover 1+2*47 = 95 mesh lines (we want Nsnaps<=99, but that includes 3 x/y/z snaps)
        xmesh = sim.getXmesh()
        (idx, val) = findNearestInSortedArray(xmesh, excitation_location[0], 0)
        MV_box_size = (xmesh[idx + 42] + xmesh[idx + 43]) / 2 - (
            xmesh[idx - 42] + xmesh[idx - 43]) / 2
        print('MV_box_size = {} = {}*sim.getSize()'.format(
            MV_box_size, MV_box_size / (sim.getSize()[0])))

        # set up base frequency snapshot (we need two at the moment because one has full extension and the other one does not)
        fsnap_base_partial = FrequencySnapshot()
        fsnap_base_partial.setCentro(excitation_location)
        fsnap_base_partial.setSize([MV_box_size, MV_box_size, MV_box_size])
        fsnap_base_partial.setPlaneOrientationX()
        fsnap_base_partial.setFullExtensionOn()
        fsnap_base_partial.setStartingSample(starting_sample)
        fsnap_base_partial.setFirst(first)
        fsnap_base_partial.setRepetition(repetition)

        fsnap_base_full = FrequencySnapshot()
        fsnap_base_full.setFromSnapshot(fsnap_base_partial)
        fsnap_base_full.setFullExtensionOn()
        #fsnap_base_full.setCentro(excitation_location)
        #fsnap_base_full.setSize(MV_box_size)
        #fsnap_base_full.setPlaneOrientationX()

        # custom snapshots
        fsnap_custom = FrequencySnapshot()
        fsnap_custom.setPlaneOrientationZ()
        fsnap_custom.setFullExtensionOn()
        fsnap_custom.setStartingSample(starting_sample)
        fsnap_custom.setFirst(first)
        fsnap_custom.setRepetition(repetition)

        f1 = copy.deepcopy(fsnap_custom)
        f1.setCentro([6.216506, 6.216506, 1.121651E+01])
        f2 = copy.deepcopy(fsnap_custom)
        f2.setCentro([6.216506, 6.216506, 1.021651E+01])
        f3 = copy.deepcopy(fsnap_custom)
        f3.setCentro([6.216506, 6.216506, 9.216510E+00])
        f4 = copy.deepcopy(fsnap_custom)
        f4.setCentro([6.216506, 6.216506, 8.216510E+00])
        f5 = copy.deepcopy(fsnap_custom)
        f5.setCentro([6.216506, 6.216506, 7.216510E+00])
        #   f6 = copy.deepcopy(fsnap_custom); f6.setCentro([6.216506,6.216506,6.216510E+00])
        f7 = copy.deepcopy(fsnap_custom)
        f7.setCentro([6.216506, 6.216506, 5.216510E+00])
        f8 = copy.deepcopy(fsnap_custom)
        f8.setCentro([6.216506, 6.216506, 4.216510E+00])
        f9 = copy.deepcopy(fsnap_custom)
        f9.setCentro([6.216506, 6.216506, 3.216510E+00])
        f10 = copy.deepcopy(fsnap_custom)
        f10.setCentro([6.216506, 6.216506, 2.216510E+00])
        f11 = copy.deepcopy(fsnap_custom)
        f11.setCentro([6.216506, 6.216506, 1.216510E+00])

        if direction == 'Ex':
            # create epsilon run
            outdir_epsilon = os.path.join(destdir, 'epsilon')
            print('outdir_epsilon = {}'.format(outdir_epsilon))

            # set up base epsilon snapshots
            esnap_base_partial = EpsilonSnapshot()
            esnap_base_partial.setFromSnapshot(fsnap_base_partial)

            esnap_base_full = EpsilonSnapshot()
            esnap_base_full.setFromSnapshot(fsnap_base_full)

            #esnap_base_partial.setCentro(excitation_location)
            #esnap_base_partial.setSize(sim.getSize()/2)
            #esnap_base_partial.setPlaneOrientationY()

            ## set up base frequency snapshot
            #fsnap_base = FrequencySnapshot()
            #fsnap_base.setFromSnapshot(esnap_base)

            # attach base snapshots to boxes
            partial_box.setBaseSnapshot(esnap_base_partial)
            xyz_box.setBaseSnapshot(esnap_base_full)
            # add the snapshots
            sim.setSnapshots([partial_box, xyz_box])

            # set up a short simulation
            sim.setIterations(1)
            sim.setWallTime(120)

            # write
            if not dry_run and not disabled_epsilon:
                sim.writeTorqueJobDirectory(outdir_epsilon,
                                            overwrite=overwrite)
                checkSnapshotNumber(os.path.join(
                    outdir_epsilon,
                    sim.getFileBaseName() + '.inp'),
                                    verbose=True)

        if direction not in disabled_directions:
            for freq_MHz in freq_MHz_list:
                print('freq_MHz = {}'.format(freq_MHz))
                wavelength_mum = get_c0() / freq_MHz
                outdir_MV = os.path.join(
                    destdir, direction,
                    'MV-freq-{:.0f}-MHz-lambda-{:.6f}-mum'.format(
                        freq_MHz, wavelength_mum))
                print('outdir_MV = {}'.format(outdir_MV))

                # set snapshot frequency
                fsnap_base_partial.setFrequencies([freq_MHz])
                fsnap_base_full.setFrequencies([freq_MHz])
                fsnap_custom.setFrequencies([freq_MHz])

                # attach base snapshots to boxes
                partial_box.setBaseSnapshot(fsnap_base_partial)
                xyz_box.setBaseSnapshot(fsnap_base_full)
                # add the snapshots
                sim.setSnapshots([
                    partial_box, xyz_box, f1, f2, f3, f4, f5, f7, f8, f9, f10,
                    f11
                ])

                # set up a long simulation
                sim.setIterations(1e9)
                sim.setWallTime(360)

                # write
                if not dry_run:
                    sim.writeTorqueJobDirectory(outdir_MV, overwrite=overwrite)
                    checkSnapshotNumber(os.path.join(
                        outdir_MV,
                        sim.getFileBaseName() + '.inp'),
                                        verbose=True)

    return
コード例 #25
0
def automeshWithMeshingFactor(infile, outfile, meshing_factor):
    sim = bfdtd.readBristolFDTD(infile)
    sim.autoMeshGeometry(meshing_factor)
    sim.writeInpFile(outfile)