Esempio n. 1
0
    def __init__(self,
                 frequency=None,
                 start_time=0,
                 end_time=1.0e20,
                 width=0,
                 fwidth=float('inf'),
                 cutoff=3.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(ContinuousSource, self).__init__(**kwargs)
        self.frequency = 1 / wavelength if wavelength else float(frequency)
        self.start_time = start_time
        self.end_time = end_time
        self.width = max(width, 1 / fwidth)
        self.cutoff = cutoff
        self.swigobj = mp.continuous_src_time(self.frequency, self.width,
                                              self.start_time, self.end_time,
                                              self.cutoff)
        self.swigobj.is_integrated = self.is_integrated
Esempio n. 2
0
    def radiating_base(self, sq_ratio, solve_cw=True):

        w = 0.30

        s = mp.structure(self.gv, one, mp.pml(self.ymax / 3.0))

        f = mp.fields(s)

        src = mp.continuous_src_time(w)
        f.add_point_source(mp.Ez, src, self.pnt_src_vec)

        # let the source reach steady state
        if solve_cw:
            f.solve_cw(1e-6)
        else:
            while f.time() < 400:
                f.step()

        # amp1 and amp2 are of type complex
        amp1 = f.get_field(mp.Ez, self.p1)
        amp2 = f.get_field(mp.Ez, self.p2)

        ratio = abs(amp1) / abs(amp2)
        if self.gv.dim == mp.D2:
            ratio = ratio**2  # in 2d, decay is ~1/sqrt(r), so square to get 1/r

        print("Ratio is {} from ({} {}) and ({} {})".format(
            ratio, amp1.real, amp1, amp2.real, amp2))

        fail_fmt = "Failed: amp1 = ({}, {}), amp2 = ({}, {})\nabs(amp1/amp2){} = {}, too far from 2.0"
        fail_msg = fail_fmt.format(amp1.real, amp1, amp2.real, amp2,
                                   "^2" if sq_ratio else "", ratio)

        self.assertTrue(ratio <= 2.12 and ratio >= 1.88, fail_msg)
Esempio n. 3
0
 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")
Esempio n. 4
0
    def __init__(self,
                 frequency=None,
                 start_time=0,
                 end_time=1.0e20,
                 width=0,
                 fwidth=float('inf'),
                 cutoff=3.0,
                 wavelength=None,
                 **kwargs):
        """
        Construct a `ContinuousSource`.

        + **`frequency` [`number`]** — The 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.

        + **`start_time` [`number`]** — The starting time for the source. Default is 0
          (turn on at $t=0$).

        + **`end_time` [`number`]** — The end time for the source. Default is
          10<sup>20</sup> (never turn off).

        + **`width` [`number`]** — Roughly, the temporal width of the smoothing
          (technically, the inverse of the exponential rate at which the current turns off
          and on). Default is 0 (no smoothing). 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).

        + **`slowness` [`number`]** — Controls how far into the exponential tail of the
          tanh function the source turns on. Default is 3.0. A larger value means that the
          source turns on more gradually at the beginning.

        + **`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 oscillates
          but does not increase for a sinusoidal current. 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`.
        """

        if frequency is None and wavelength is None:
            raise ValueError(
                "Must set either frequency or wavelength in {}.".format(
                    self.__class__.__name__))

        super(ContinuousSource, self).__init__(**kwargs)
        self.frequency = 1 / wavelength if wavelength else float(frequency)
        self.start_time = start_time
        self.end_time = end_time
        self.width = max(width, 1 / fwidth)
        self.cutoff = cutoff
        self.swigobj = mp.continuous_src_time(self.frequency, self.width,
                                              self.start_time, self.end_time,
                                              self.cutoff)
        self.swigobj.is_integrated = self.is_integrated
Esempio n. 5
0
File: source.py Progetto: eroen/meep
 def __init__(self,
              frequency,
              start_time=0,
              end_time=float('inf'),
              width=0,
              cutoff=3.0):
     super(ContinuousSource, self).__init__()
     self.frequency = frequency
     self.start_time = start_time
     self.end_time = end_time
     self.width = width
     self.cutoff = cutoff
     self.swigobj = mp.continuous_src_time(frequency, width, start_time,
                                           end_time, cutoff)
     self.swigobj.is_integrated = self.is_integrated
Esempio n. 6
0
    def __init__(self, frequency=None, start_time=0, end_time=1.0e20, width=0,
                 fwidth=float('inf'), cutoff=3.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(ContinuousSource, self).__init__(**kwargs)
        self.frequency = 1 / wavelength if wavelength else float(frequency)
        self.start_time = start_time
        self.end_time = end_time
        self.width = max(width, 1 / fwidth)
        self.cutoff = cutoff
        self.swigobj = mp.continuous_src_time(self.frequency, self.width, self.start_time,
                                              self.end_time, self.cutoff)
        self.swigobj.is_integrated = self.is_integrated