def __init__(self,config_filepath=None,config=None,section="field parameters",
               time_dependent_function=None, scale=1.0, normalize=None, **kwargs):
    """
    Loads the config_filepath and puts the elements into the objects attributes.
    Also loads and saves the fields. 
    Args:
      config_filepath: filepath to the config file for the field.  Either this or the
        config object needs to be present.
      config: A config parser object.  Allows the reading of this data from an existent
        config parser object.
      section: The name of the section in the filepath with the field info.  Default
        is field parameters.
    Attributes:
      fields: A dict first pointing to the type of field (i.e. electric 
        or magnetic) then pointing to components of the field.
      stepsize: A dict containing the stepsize of each of the coordinates key
        by the coordinate.
      number_of_steps: A dict containing the number of steps of each of the coordinates key
        by the coordinate.
      zmin: The minimum value of the z coordinate in the filepath.
      zmax: The max z in the field.
      zlen: The length over which the field is applied.
      current_position: The position of the center of mass of the pulse
        to be used if a distance needs to be calculated.
      time_dependent_function: An option function callback (function is a function of top.time)
        that can add time dependence to the field.  Default is no such function.
      scale: An option that provides a hook to scale the field(s) being loaded.
    """
    if config_filepath is None and config is None:
      raise Exception("Either the config_filepath needs to be specified or a config parser object " + 
                      "needs to be passed to the init function.")
    if config is None:
      config = ConfigParser()
      config.read(config_filepath)
    self.config = config
    self.section = section
    
    self.xmin = config.get(section,"xmin")
    self.ymin = config.get(section,"ymin")
    self.zmin = config.get(section,"zmin")
    self.zmax = config.get(section,"zmax")
    self.zlen = config.get(section,"zlen")

    self.stepsize = {}
    self.number_of_steps = {}
    self.fields = {}
    for option in config.options(section):
      if option.startswith("d"):
        self.stepsize[option.replace("d","")] = config.get(section,option)
      if option.startswith("n"):
        self.number_of_steps[option.replace("n","")] = config.get(section,option)
      if option.endswith("_pickled_field"):
        field_type = option.replace("_pickled_field","")
        self.fields[field_type] = pickle.load( open(config.get(section,option), "rb") )
        for component in self.fields[field_type]:
          self.fields[field_type][component] = scale*np.array(self.fields[field_type][component],order="FORTRAN")
    self.time_dependent_function = time_dependent_function
Example #2
0
  def __init__(self,config_filepath=None,config=None,section="field parameters",
               time_dependent_function=None, **kwargs):
    """
    Loads the config_filepath and puts the elements into the objects attributes.
    Also loads and saves the fields. 
    Args:
      config_filepath: filepath to the config file for the field.  Either this or the
        config object needs to be present.
      config: A config parser object.  Allows the reading of this data from an existent
        config parser object.
      section: The name of the section in the filepath with the field info.  Default
        is field parameters.
    Attributes:
      fields: A dict first pointing to the type of field (i.e. electric 
        or magnetic) then pointing to components of the field.
      stepsize: A dict containing the stepsize of each of the coordinates key
        by the coordinate.
      number_of_steps: A dict containing the number of steps of each of the coordinates key
        by the coordinate.
      zmin: The minimum value of the z coordinate in the filepath.
      zmax: The max z in the field.
      zlen: The length over which the field is applied.
      current_position: The position of the center of mass of the pulse
        to be used if a distance needs to be calculated.
      time_dependent_function: An option function callback (function is a function of top.time)
        that can add time dependence to the field.  Default is no such function.
    """
    if config_filepath is None and config is None:
      raise Exception("Either the config_filepath needs to be specified or a config parser object " + 
                      "needs to be passed to the init function.")
    if config is None:
      config = ConfigParser()
      config.read(config_filepath)
    self.config = config
    self.section = section
    
    self.xmin = config.get(section,"xmin")
    self.ymin = config.get(section,"ymin")
    self.zmin = config.get(section,"zmin")
    self.zmax = config.get(section,"zmax")
    self.zlen = config.get(section,"zlen")

    self.stepsize = {}
    self.number_of_steps = {}
    self.fields = {}
    for option in config.options(section):
      if option.startswith("d"):
        self.stepsize[option.replace("d","")] = config.get(section,option)
      if option.startswith("n"):
        self.number_of_steps[option.replace("n","")] = config.get(section,option)
      if option.endswith("_pickled_field"):
        field_type = option.replace("_pickled_field","")
        self.fields[field_type] = pickle.load( open(config.get(section,option), "rb") )
        for component in self.fields[field_type]:
          self.fields[field_type][component] = np.array(self.fields[field_type][component],order="FORTRAN")
    self.time_dependent_function = time_dependent_function
Example #3
0
from injectors.injector_classes import ElectronInjector
from injectors.steves_uem_injection import steves_injectelectrons
from class_and_config_conversion import set_attributes_with_config_section
from moving_grid.moving_classes import SyncToCOM
from warp import *

# from histplot import *

# Invoke setup routine: needed to created a cgm file for plots
setup()

# Load the config file and parameters from config file.
config = MyConfigParser()
config.read(args.config_file)

adv_dt = array(config.get("Simulation parameters", "adv_dt"))  # Numpy array of dts
adv_steps = array(config.get("Simulation parameters", "adv_steps"))  # Number of steps for each dt
# Mesh size
dx = config.get("Simulation parameters", "dx")
dz = config.get("Simulation parameters", "dz")
xmax = config.get("Simulation parameters", "xmax")
zmin = config.get("Simulation parameters", "zmin")
zmax = config.get("Simulation parameters", "zmax")
# When to do diagnostics
diagnostic_time_interval = config.get("Simulation parameters", "diagnostic_time_interval")

# Load the parameters for the w3d and top objects from the config.
set_attributes_with_config_section(top, config, "top parameters", {",": parse_key_as_numpy_array})
set_attributes_with_config_section(w3d, config, "w3d parameters")
set_attributes_with_config_section(f3d, config, "f3d parameters")
top, w3d, f3d, adv_dt, adv_steps = photoemission_parameters(
    config, args, top, w3d, f3d)
solver = get_solver("wrz", top, w3d)
registersolver(solver)

#Install the conductor elements
conductor_elements = handle_cathode_and_anode(config, args.extraction_field,
                                              args.potential)
for conductor_element in conductor_elements:
    installconductor(
        conductor_element)  # install conductors into the warp framework
    print "Installed " + str(conductor_element)

#Add grid refinement near diodes
handle_rz_1D_mesh_refinements(config, solver, conductor_elements,
                              config.get("Simulation parameters", "xmax"))

# Create the electron beam species.  This function reads in input coordinates
# and saves them in particle objects.  The time coordinate is used to specify
# at what step the program will ``create'' the relavent particles.
electron_injector = ElectronInjector(steves_injectelectrons,
                                     top,
                                     args.input_file,
                                     top.echarge / top.emass,
                                     args.electrons_per_macroparticle,
                                     loader=photoemission_loader)
installuserinjection(
    electron_injector.callFunction)  # install injection function in timestep

#Diagnostics to the cgm file.
diagnostic_time_interval = config.get("Simulation parameters",
Example #5
0
#from histplot import *

# Invoke setup routine: needed to created a cgm file for plots

#Handle the output path and setup of the plots.
if args.prefix is None:
    prefix, ext = os.path.splitext(args.config_file)
else:
    prefix = args.prefix
setup(prefix=prefix, cgmlog=0)

#Load the config file and parameters from config file.
config = MyConfigParser()
config.read(args.config_file)

adv_dt = array(config.get("Simulation parameters",
                          "adv_dt"))  # Numpy array of dts
adv_steps = array(config.get("Simulation parameters",
                             "adv_steps"))  #Number of steps for each dt
#Mesh size
dx = config.get("Simulation parameters", "dx")
dz = config.get("Simulation parameters", "dz")
xmax = config.get("Simulation parameters", "xmax")
zmin = config.get("Simulation parameters", "zmin")
zmax = config.get("Simulation parameters", "zmax")
#When to do diagnostics
diagnostic_time_interval = config.get("Simulation parameters",
                                      "diagnostic_time_interval")

#Load the parameters for the w3d and top objects from the config.
set_attributes_with_config_section(top, config, "top parameters",
                                   {",": parse_key_as_numpy_array})