Example #1
0
    def __call__(self, discr):
        mesh = discr.mesh
        bbox_min, bbox_max = mesh.bounding_box()
        d = len(bbox_min)

        core_axis = self.core_axis
        if core_axis is None:
            core_axis = d-1

        # calculate outer bbox, as above
        from hedge.discretization import ones_on_volume
        mesh_volume = discr.integral(ones_on_volume(discr))
        dx =  (mesh_volume / len(discr)/ self.overresolve)**(1/discr.dimensions)
                
        bbox_min -= self.mesh_margin
        bbox_max += self.mesh_margin

        bbox_size = bbox_max-bbox_min
        dims = numpy.asarray(bbox_size/dx, dtype=numpy.int32)
        stepwidths = bbox_size/dims

        # calculate inner bbox
        core_margin_dims = (dims*(1-self.core_fraction)/2).astype(numpy.int32)
        core_margin_dims[core_axis] = 0
        core_dx = dx/self.core_factor
        core_min = bbox_min + stepwidths*core_margin_dims
        core_max = bbox_max - stepwidths*core_margin_dims
        core_size = core_max-core_min
        core_dims = numpy.asarray(core_size/core_dx, dtype=numpy.int32)
        core_stepwidths = core_size/core_dims

        # yield the core
        yield core_stepwidths, core_min, core_dims

        # yield the surrounding bricks
        from hedge.tools import unit_vector
        axis_vec = unit_vector(d, core_axis, dtype=numpy.int32)
        if d == 2:
            margin_dims = core_margin_dims + dims*axis_vec
            yield stepwidths, bbox_min, margin_dims
            yield -stepwidths, bbox_max, margin_dims
        elif d == 3:
            other_axes = set(range(d)) - set([core_axis])
            x, y = other_axes

            # ^ y
            # |
            # +----+----------+-----+
            # |    |     2    |     |
            # |    +----------+     |
            # | 1  |   core   |  1  |
            # |    +----------+     |
            # |    |     2    |     |
            # +----+----------+-----+--> x
            # 

            x_vec = unit_vector(d, x, dtype=numpy.int32)

            dims1 = dims.copy()
            dims1[x] = core_margin_dims[x]
            dims2 = dims.copy()
            dims2[x] = dims[x]-2*core_margin_dims[x]
            dims2[y] = core_margin_dims[y]

            yield stepwidths, bbox_min, dims1
            yield -stepwidths, bbox_max, dims1

            x_offset_2 = x_vec*core_margin_dims[x]*stepwidths[x]
            yield stepwidths, bbox_min+x_offset_2, dims2
            yield -stepwidths, bbox_max-x_offset_2, dims2
        else:
            raise ValueError, "invalid dimensionality"
 def matrix_rep(op):
     h, w = op.shape
     mat = numpy.zeros(op.shape)
     for j in range(w):
         mat[:, j] = op(unit_vector(w, j))
     return mat
Example #3
0
    def __call__(self, discr):
        mesh = discr.mesh
        bbox_min, bbox_max = mesh.bounding_box()
        d = len(bbox_min)

        core_axis = self.core_axis
        if core_axis is None:
            core_axis = d - 1

        # calculate outer bbox, as above
        from hedge.discretization import ones_on_volume
        mesh_volume = discr.integral(ones_on_volume(discr))
        dx = (mesh_volume / len(discr) / self.overresolve)**(1 /
                                                             discr.dimensions)

        bbox_min -= self.mesh_margin
        bbox_max += self.mesh_margin

        bbox_size = bbox_max - bbox_min
        dims = numpy.asarray(bbox_size / dx, dtype=numpy.int32)
        stepwidths = bbox_size / dims

        # calculate inner bbox
        core_margin_dims = (dims * (1 - self.core_fraction) / 2).astype(
            numpy.int32)
        core_margin_dims[core_axis] = 0
        core_dx = dx / self.core_factor
        core_min = bbox_min + stepwidths * core_margin_dims
        core_max = bbox_max - stepwidths * core_margin_dims
        core_size = core_max - core_min
        core_dims = numpy.asarray(core_size / core_dx, dtype=numpy.int32)
        core_stepwidths = core_size / core_dims

        # yield the core
        yield core_stepwidths, core_min, core_dims

        # yield the surrounding bricks
        from hedge.tools import unit_vector
        axis_vec = unit_vector(d, core_axis, dtype=numpy.int32)
        if d == 2:
            margin_dims = core_margin_dims + dims * axis_vec
            yield stepwidths, bbox_min, margin_dims
            yield -stepwidths, bbox_max, margin_dims
        elif d == 3:
            other_axes = set(range(d)) - set([core_axis])
            x, y = other_axes

            # ^ y
            # |
            # +----+----------+-----+
            # |    |     2    |     |
            # |    +----------+     |
            # | 1  |   core   |  1  |
            # |    +----------+     |
            # |    |     2    |     |
            # +----+----------+-----+--> x
            #

            x_vec = unit_vector(d, x, dtype=numpy.int32)

            dims1 = dims.copy()
            dims1[x] = core_margin_dims[x]
            dims2 = dims.copy()
            dims2[x] = dims[x] - 2 * core_margin_dims[x]
            dims2[y] = core_margin_dims[y]

            yield stepwidths, bbox_min, dims1
            yield -stepwidths, bbox_max, dims1

            x_offset_2 = x_vec * core_margin_dims[x] * stepwidths[x]
            yield stepwidths, bbox_min + x_offset_2, dims2
            yield -stepwidths, bbox_max - x_offset_2, dims2
        else:
            raise ValueError, "invalid dimensionality"
 def matrix_rep(op):
     h, w = op.shape
     mat = numpy.zeros(op.shape)
     for j in range(w):
         mat[:, j] = op(unit_vector(w, j))
     return mat
Example #5
0
    def add_instrumentation(self, logmgr):
        from pytools.log import \
                add_simulation_quantities, \
                add_general_quantities, \
                add_run_info, ETA
        from pyrticle.log import add_particle_quantities, add_field_quantities, \
                add_beam_quantities, add_currents

        setup = self.setup

        from pyrticle.log import StateObserver
        self.observer = StateObserver(self.method, self.maxwell_op)
        self.observer.set_fields_and_state(self.fields, self.state)

        add_run_info(logmgr)
        add_general_quantities(logmgr)
        add_simulation_quantities(logmgr)
        add_particle_quantities(logmgr, self.observer)
        add_field_quantities(logmgr, self.observer)

        if setup.beam_axis is not None and setup.beam_diag_axis is not None:
            add_beam_quantities(logmgr, self.observer, 
                    axis=setup.beam_diag_axis, 
                    beam_axis=setup.beam_axis)

        if setup.tube_length is not None:
            from hedge.tools import unit_vector
            add_currents(logmgr, self.observer, 
                    unit_vector(self.method.dimensions_velocity, setup.beam_axis), 
                    setup.tube_length)

        self.method.add_instrumentation(logmgr, self.observer)

        self.f_rhs_calculator.add_instrumentation(logmgr)

        if hasattr(self.stepper, "add_instrumentation"):
            self.stepper.add_instrumentation(logmgr)

        mean_beta = self.method.mean_beta(self.state)
        gamma = self.method.units.gamma_from_beta(mean_beta)

        logmgr.set_constant("dt", self.dt)
        logmgr.set_constant("beta", mean_beta)
        logmgr.set_constant("gamma", gamma)
        logmgr.set_constant("v", mean_beta*self.units.VACUUM_LIGHT_SPEED())
        logmgr.set_constant("Q0", self.total_charge)
        logmgr.set_constant("n_part_0", setup.nparticles)
        logmgr.set_constant("pmass", setup.distribution.mean()[3][0])
        logmgr.set_constant("chi", setup.chi)
        logmgr.set_constant("phi_decay", setup.phi_decay)
        logmgr.set_constant("shape_radius_setup", setup.shape_bandwidth)
        logmgr.set_constant("shape_radius", self.method.depositor.shape_function.radius)
        logmgr.set_constant("shape_exponent", self.method.depositor.shape_function.exponent)

        from pytools.log import IntervalTimer
        self.vis_timer = IntervalTimer("t_vis", "Time spent visualizing")
        logmgr.add_quantity(self.vis_timer)

        logmgr.add_quantity(ETA(self.nsteps))

        logmgr.add_watches(setup.watch_vars)
Example #6
0
    def add_instrumentation(self, logmgr):
        from pytools.log import \
                add_simulation_quantities, \
                add_general_quantities, \
                add_run_info, ETA
        from pyrticle.log import add_particle_quantities, add_field_quantities, \
                add_beam_quantities, add_currents

        setup = self.setup

        from pyrticle.log import StateObserver
        self.observer = StateObserver(self.method, self.maxwell_op)
        self.observer.set_fields_and_state(self.fields, self.state)

        add_run_info(logmgr)
        add_general_quantities(logmgr)
        add_simulation_quantities(logmgr)
        add_particle_quantities(logmgr, self.observer)
        add_field_quantities(logmgr, self.observer)

        if setup.beam_axis is not None and setup.beam_diag_axis is not None:
            add_beam_quantities(logmgr,
                                self.observer,
                                axis=setup.beam_diag_axis,
                                beam_axis=setup.beam_axis)

        if setup.tube_length is not None:
            from hedge.tools import unit_vector
            add_currents(
                logmgr, self.observer,
                unit_vector(self.method.dimensions_velocity, setup.beam_axis),
                setup.tube_length)

        self.method.add_instrumentation(logmgr, self.observer)

        self.f_rhs_calculator.add_instrumentation(logmgr)

        if hasattr(self.stepper, "add_instrumentation"):
            self.stepper.add_instrumentation(logmgr)

        mean_beta = self.method.mean_beta(self.state)
        gamma = self.method.units.gamma_from_beta(mean_beta)

        logmgr.set_constant("dt", self.dt)
        logmgr.set_constant("beta", mean_beta)
        logmgr.set_constant("gamma", gamma)
        logmgr.set_constant("v", mean_beta * self.units.VACUUM_LIGHT_SPEED())
        logmgr.set_constant("Q0", self.total_charge)
        logmgr.set_constant("n_part_0", setup.nparticles)
        logmgr.set_constant("pmass", setup.distribution.mean()[3][0])
        logmgr.set_constant("chi", setup.chi)
        logmgr.set_constant("phi_decay", setup.phi_decay)
        logmgr.set_constant("shape_radius_setup", setup.shape_bandwidth)
        logmgr.set_constant("shape_radius",
                            self.method.depositor.shape_function.radius)
        logmgr.set_constant("shape_exponent",
                            self.method.depositor.shape_function.exponent)

        from pytools.log import IntervalTimer
        self.vis_timer = IntervalTimer("t_vis", "Time spent visualizing")
        logmgr.add_quantity(self.vis_timer)

        logmgr.add_quantity(ETA(self.nsteps))

        logmgr.add_watches(setup.watch_vars)