def test_typemap_swig_raises(self): src = mp.gaussian_src_time(0.15, 0.1) self.assertTrue(src.is_equal(src)) with self.assertRaises(TypeError) as error: src.is_equal(mp.vec()) self.assertEqual(error.exception.message, self.expected_msg)
def run(self, interactive_mode=False): self.engine.initialise_engine(self.landscape) #mandatory ! self.save_engine_dielectricum_to_file( ) #export to file the dielectricum as it was received by Meep #create a reference to the meep fields object fields = meep.fields(self.engine.structure) #If you want to use the mode profile at a certain port in your python-meep scripting,then you can retrieve it as follows (THIS IS NOT ACTUALLY USED FURTHER IN THE SCRIPT, IT'S JUST AN ILLUSTRATION OF WHAT YOU COULD DO...) mp = get_mode_profile_at_port( structure=mmi, resolution=simul_params["resolution"], port=mmi.west_ports[0], wavelength=simul_params["center_wavelength"]) print mp #create a Gaussian source center_wavelength = simul_params["center_wavelength"] pulse_width = 30 center_freq = 1.0 / (float(center_wavelength) / 1000.0) pulse_width_freq = ((float(pulse_width) / 1000.0) / (float(center_wavelength) / 1000.0)) * center_freq src_gaussian = meep.gaussian_src_time(center_freq, pulse_width_freq) #add a point source (linked to the Gaussian source) at the position of the west port source_position_vec = self.make_meep_vec( mmi.west_ports[0].transform_copy( Translation(translation=(-9.0, 0))).position) fields.add_point_source(meep.Hz, src_gaussian, source_position_vec) #add a probing point to the upper output arm probing_point_vec = self.make_meep_vec(mmi.east_ports[1].position) #run the simulation h5_file = meep.prepareHDF5File("./mmi_low_level.h5") meep.runUntilFieldsDecayed(fields, self.engine.meepVol, meep.Hz, probing_point_vec, pHDF5OutputFile=h5_file, pH5OutputIntervalSteps=100)
def __addMeepSource(self, src, meep_fields): '''Convert a source (runtime.basic.__EMSource__) into a Meep source and add it to the Meep fields object''' if not isinstance(src, __EMSource__): raise InvalidArgumentException("Invalid argument:: not of type runtime.basic.__EMSource__") LOG.debug("Meep node %i -Adding source...." %(self.node_nr)) #create Meep source object meepSource = None center_freq = 1.0 / (float(src.center_wavelength) / 1000.0) if isinstance(src, __GaussianSource__): pw = ( (float(src.pulse_width)/1000.0) / (float(src.center_wavelength)/1000.0) ) * center_freq meepSource = Meep.gaussian_src_time(center_freq, pw) if isinstance(src, __ContinuousSource__): meepSource = Meep.continuous_src_time(center_freq, src.smoothing_width, src.start_time, src.stop_time, src.cutoff) #create Meep component meepComp = self.__makeMeepComponent(src.field_component) #add source to the Meep field if isinstance(src, __EMPointSource__): vec = self.__make_meep_vec__(src.point) meep_fields.add_point_source(meepComp, meepSource, vec) print "Point source at point (%f , %f)" %(vec.x(), vec.y()) elif isinstance(src, __EMVolumeSource__): vec1 = self.__make_meep_vec__(src.south) vec2 = self.__make_meep_vec__(src.north) LOG.debug("Meep node %i -Creating volume for source plane..." %(self.node_nr)) meepSrcVol = Meep.volume(vec1, vec2) print "Meep node %i - source plane between points (%f , %f) and (%f , %f)." %(self.node_nr, vec1.x(), vec1.y(), vec2.x(), vec2.y()) LOG.debug("Meep node %i -Now adding the volume source to Meep..." %(self.node_nr)) if isinstance(src, __AmplitudeShapedSource__): ampl = AmplitudeFactor(source = src) Meep.set_AMPL_Callback(ampl.__disown__()) meep_fields.add_volume_source(meepComp, meepSource, meepSrcVol, Meep.AMPL) else: meep_fields.add_volume_source(meepComp, meepSource, meepSrcVol, src.amplitude) else: raise NotImplementedException("Unexpected case in MeepSimulationEngine::__addMeepSource")
def __init__(self, frequency=None, width=0, fwidth=float('inf'), start_time=0, cutoff=5.0, wavelength=None, **kwargs): """ Construct a `GaussianSource`. + **`frequency` [`number`]** — The center frequency $f$ in units of $c$/distance (or ω in units of 2π$c$/distance). See [Units](Introduction.md#units-in-meep). No default value. You can instead specify `wavelength=x` or `period=x`, which are both a synonym for `frequency=1/x`; i.e. 1/ω in these units is the vacuum wavelength or the temporal period. + **`width` [`number`]** — The width $w$ used in the Gaussian. No default value. You can instead specify `fwidth=x`, which is a synonym for `width=1/x` (i.e. the frequency width is proportional to the inverse of the temporal width). + **`start_time` [`number`]** — The starting time for the source; default is 0 (turn on at $t=0$). This is not the time of the peak. See below. + **`cutoff` [`number`]** — How many `width`s the current decays for before it is cut off and set to zero — this applies for both turn-on and turn-off of the pulse. Default is 5.0. A larger value of `cutoff` will reduce the amount of high-frequency components that are introduced by the start/stop of the source, but will of course lead to longer simulation times. The peak of the Gaussian is reached at the time $t_0$=`start_time + cutoff*width`. + **`is_integrated` [`boolean`]** — If `True`, the source is the integral of the current (the [dipole moment](https://en.wikipedia.org/wiki/Electric_dipole_moment)) which is guaranteed to be zero after the current turns off. In practice, there is little difference between integrated and non-integrated sources *except* for [planewaves extending into PML](Perfectly_Matched_Layer.md#planewave-sources-extending-into-pml). Default is `False`. + **`fourier_transform(f)`** — Returns the Fourier transform of the current evaluated at frequency `f` (`ω=2πf`) given by: $$ \\widetilde G(\\omega) \\equiv \\frac{1}{\\sqrt{2\\pi}} \\int e^{i\\omega t}G(t)\\,dt \\equiv \\frac{1}{\\Delta f} e^{i\\omega t_0 -\\frac{(\\omega-\\omega_0)^2}{2\\Delta f^2}} $$ where $G(t)$ is the current (not the dipole moment). In this formula, $\\Delta f$ is the `fwidth` of the source, $\\omega_0$ is $2\\pi$ times its `frequency,` and $t_0$ is the peak time discussed above. Note that this does not include any `amplitude` or `amp_func` factor that you specified for the source. """ if frequency is None and wavelength is None: raise ValueError("Must set either frequency or wavelength in {}.".format(self.__class__.__name__)) super(GaussianSource, self).__init__(**kwargs) self.frequency = 1 / wavelength if wavelength else float(frequency) self.width = max(width, 1 / fwidth) self.start_time = start_time self.cutoff = cutoff self.swigobj = mp.gaussian_src_time(self.frequency, self.width, self.start_time, self.start_time + 2 * self.width * self.cutoff) self.swigobj.is_integrated = self.is_integrated
def __init__(self, frequency=None, width=0, fwidth=float('inf'), start_time=0, cutoff=5.0, wavelength=None): if frequency is None and wavelength is None: raise ValueError("Must set either frequency or wavelength in {}.".format(self.__class__.__name__)) super(GaussianSource, self).__init__() self.frequency = 1 / wavelength if wavelength else float(frequency) self.width = max(width, 1 / fwidth) self.start_time = start_time self.cutoff = cutoff self.swigobj = mp.gaussian_src_time(self.frequency, self.width, self.start_time, self.start_time + 2 * self.width * self.cutoff) self.swigobj.is_integrated = self.is_integrated
def __init__(self, frequency=None, width=0, fwidth=float('inf'), start_time=0, cutoff=5.0, wavelength=None, **kwargs): if frequency is None and wavelength is None: raise ValueError("Must set either frequency or wavelength in {}.".format(self.__class__.__name__)) super(GaussianSource, self).__init__(**kwargs) self.frequency = 1 / wavelength if wavelength else float(frequency) self.width = max(width, 1 / fwidth) self.start_time = start_time self.cutoff = cutoff self.swigobj = mp.gaussian_src_time(self.frequency, self.width, self.start_time, self.start_time + 2 * self.width * self.cutoff) self.swigobj.is_integrated = self.is_integrated
def __init__(self, frequency, width=0, fwidth=float('inf'), start_time=0, cutoff=5.0): super(GaussianSource, self).__init__() self.frequency = frequency self.width = max(width, 1 / fwidth) self.start_time = start_time self.cutoff = cutoff self.swigobj = mp.gaussian_src_time( frequency, self.width, start_time, start_time + 2 * self.width * cutoff) self.swigobj.is_integrated = self.is_integrated
def test_typemap_swig(self): src = mp.gaussian_src_time(0.15, 0.1) self.f.add_volume_source(mp.Ez, src, self.v)
def get_time_src(self): return gaussian_src_time(self.f,self.df)