Ejemplo n.º 1
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        discr = method.discretization

        eg, = discr.element_groups
        fg, = discr.face_groups
        ldis = eg.local_discretization

        from hedge.mesh import TAG_ALL
        bdry = discr.get_boundary(TAG_ALL)

        bdry_fg, = bdry.face_groups

        if self.filter_response:
            from hedge.discretization import Filter
            filter = Filter(discr, self.filter_response)
            filter_mat, = filter.filter_matrices
        else:
            filter_mat = numpy.zeros((0, 0))

        backend_class = getattr(
            _internal,
            "AdvectiveDepositor" + method.get_dimensionality_suffix())
        self.backend = backend_class(method.mesh_data,
                                     len(ldis.face_indices()),
                                     ldis.node_count(), ldis.mass_matrix(),
                                     ldis.inverse_mass_matrix(), filter_mat,
                                     ldis.face_mass_matrix(), fg, bdry_fg,
                                     self.activation_threshold,
                                     self.kill_threshold, self.upwind_alpha)

        for i, diffmat in enumerate(ldis.differentiation_matrices()):
            self.backend.add_local_diff_matrix(i, diffmat)
Ejemplo n.º 2
0
    def set_shape_function(self, state, sf):
        Depositor.set_shape_function(self, state, sf)

        state.depositor_state.clear()
        for pn in xrange(len(state)):
            self.backend.add_advective_particle(state.depositor_state,
                                                state.particle_state, sf, pn)
Ejemplo n.º 3
0
    def __init__(
        self,
        activation_threshold=1e-5,
        kill_threshold=1e-3,
        filter_amp=None,
        filter_order=None,
        upwind_alpha=1,
    ):
        Depositor.__init__(self)

        self.activation_threshold = activation_threshold
        self.kill_threshold = kill_threshold
        self.upwind_alpha = upwind_alpha

        self.shape_function = None

        self.filter_amp = filter_amp
        self.filter_order = filter_order

        if filter_amp is not None:
            from hedge.discretization import ExponentialFilterResponseFunction
            self.filter_response = ExponentialFilterResponseFunction(
                filter_amp, filter_order)
        else:
            self.filter_response = None
Ejemplo n.º 4
0
    def add_instrumentation(self, mgr, observer):
        Depositor.add_instrumentation(self, mgr, observer)

        # instrumentation
        from pytools.log import IntervalTimer, EventCounter
        self.element_activation_counter = EventCounter(
            "n_el_activations",
            "#Advective rec. elements activated this timestep")
        self.element_kill_counter = EventCounter(
            "n_el_kills", "#Advective rec. elements retired this timestep")
        self.advective_rhs_timer = IntervalTimer(
            "t_advective_rhs", "Time spent evaluating advective RHS")
        self.active_elements_log = ActiveAdvectiveElements(observer)

        mgr.add_quantity(self.element_activation_counter)
        mgr.add_quantity(self.element_kill_counter)
        mgr.add_quantity(self.advective_rhs_timer)
        mgr.add_quantity(self.active_elements_log)

        mgr.set_constant("el_activation_threshold", self.activation_threshold)
        mgr.set_constant("el_kill_threshold", self.kill_threshold)
        mgr.set_constant("adv_upwind_alpha", self.upwind_alpha)

        mgr.set_constant("filter_amp", self.filter_amp)
        mgr.set_constant("filter_amp", self.filter_order)
Ejemplo n.º 5
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        backend_class = getattr(
            _internal,
            "InterpolatingDepositor" + method.get_dimensionality_suffix())
        self.backend = backend_class(method.mesh_data)
Ejemplo n.º 6
0
    def add_instrumentation(self, mgr, observer):
        Depositor.add_instrumentation(self, mgr, observer)

        # instrumentation
        from pytools.log import IntervalTimer, EventCounter
        self.element_activation_counter = EventCounter(
                "n_el_activations",
                "#Advective rec. elements activated this timestep")
        self.element_kill_counter = EventCounter(
                "n_el_kills",
                "#Advective rec. elements retired this timestep")
        self.advective_rhs_timer = IntervalTimer(
                "t_advective_rhs",
                "Time spent evaluating advective RHS")
        self.active_elements_log = ActiveAdvectiveElements(observer)

        mgr.add_quantity(self.element_activation_counter)
        mgr.add_quantity(self.element_kill_counter)
        mgr.add_quantity(self.advective_rhs_timer)
        mgr.add_quantity(self.active_elements_log)

        mgr.set_constant("el_activation_threshold", self.activation_threshold)
        mgr.set_constant("el_kill_threshold", self.kill_threshold)
        mgr.set_constant("adv_upwind_alpha", self.upwind_alpha)

        mgr.set_constant("filter_amp", self.filter_amp)
        mgr.set_constant("filter_amp", self.filter_order)
Ejemplo n.º 7
0
    def set_shape_function(self, state, sf):
        Depositor.set_shape_function(self, state, sf)

        state.depositor_state.clear()
        for pn in xrange(len(state)):
            self.backend.add_advective_particle(
                    state.depositor_state,
                    state.particle_state,
                    sf, pn)
Ejemplo n.º 8
0
    def add_instrumentation(self, mgr, observer):
        Depositor.add_instrumentation(self, mgr, observer)

        mgr.set_constant("rec_grid_el_tolerance", self.el_tolerance)
        mgr.set_constant("rec_grid_enforce_continuity", self.enforce_continuity)
        mgr.set_constant("rec_grid_method", self.submethod)
        mgr.set_constant("rec_grid_jiggle_radius", self.jiggle_radius)

        self.brick_generator.log_data(mgr)
Ejemplo n.º 9
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        eg, = method.discretization.element_groups
        ldis = eg.local_discretization

        backend_class = getattr(_internal, "NormalizingInterpolatingDepositor" 
                + method.get_dimensionality_suffix())
        self.backend = backend_class(method.mesh_data, ldis.mass_matrix())
Ejemplo n.º 10
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        eg, = method.discretization.element_groups
        ldis = eg.local_discretization

        backend_class = getattr(
            _internal, "NormalizingInterpolatingDepositor" +
            method.get_dimensionality_suffix())
        self.backend = backend_class(method.mesh_data, ldis.mass_matrix())
Ejemplo n.º 11
0
    def add_instrumentation(self, mgr, observer):
        Depositor.add_instrumentation(self, mgr, observer)

        mgr.set_constant("rec_grid_el_tolerance", self.el_tolerance)
        mgr.set_constant("rec_grid_enforce_continuity",
                         self.enforce_continuity)
        mgr.set_constant("rec_grid_method", self.submethod)
        mgr.set_constant("rec_grid_jiggle_radius", self.jiggle_radius)

        self.brick_generator.log_data(mgr)
Ejemplo n.º 12
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        if self.jiggle_radius:
            dep_type = "Jiggly"
        else:
            dep_type = "Regular"

        backend_class = getattr(
            _internal,
            dep_type + "GridDepositor" + method.get_dimensionality_suffix())
        backend = self.backend = backend_class(method.mesh_data)

        discr = method.discretization

        if self.enforce_continuity:
            self.prepare_average_groups()
        else:
            backend.average_group_starts.append(0)

        if self.filter_min_amplification is not None:
            from hedge.discretization import Filter, ExponentialFilterResponseFunction
            self.filter = Filter(
                discr,
                ExponentialFilterResponseFunction(
                    self.filter_min_amplification, self.filter_order))
        else:
            self.filter = None

        for i, (stepwidths, origin,
                dims) in enumerate(self.brick_generator(discr)):
            if self.jiggle_radius:
                brk = _internal.JigglyBrick(
                    i,
                    backend.grid_node_count_with_extra(),
                    stepwidths,
                    origin,
                    dims,
                    jiggle_radius=self.jiggle_radius)
            else:
                brk = _internal.Brick(i, backend.grid_node_count_with_extra(),
                                      stepwidths, origin, dims)
            backend.bricks.append(brk)

        if self.submethod == "simplex_extra":
            self.prepare_with_pointwise_projection_and_extra_points()
        elif self.submethod == "simplex_enlarge":
            self.prepare_with_pointwise_projection_and_enlargement()
        elif self.submethod == "simplex_reduce":
            self.prepare_with_pointwise_projection_and_basis_reduction()
        elif self.submethod == "brick":
            self.prepare_with_brick_interpolation()
        else:
            raise RuntimeError, "invalid rec_grid submethod specified"
Ejemplo n.º 13
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        if self.jiggle_radius:
            dep_type = "Jiggly"
        else:
            dep_type = "Regular"

        backend_class = getattr(_internal, 
                dep_type + "GridDepositor" + method.get_dimensionality_suffix())
        backend = self.backend = backend_class(method.mesh_data)

        discr = method.discretization

        if self.enforce_continuity:
            self.prepare_average_groups()
        else:
            backend.average_group_starts.append(0)

        if self.filter_min_amplification is not None:
            from hedge.discretization import Filter, ExponentialFilterResponseFunction
            self.filter = Filter(discr, ExponentialFilterResponseFunction(
                    self.filter_min_amplification, self.filter_order))
        else:
            self.filter = None

        for i, (stepwidths, origin, dims) in enumerate(
                self.brick_generator(discr)):
            if self.jiggle_radius:
                brk = _internal.JigglyBrick(i, backend.grid_node_count_with_extra(), 
                        stepwidths, origin, dims,
                        jiggle_radius=self.jiggle_radius)
            else:
                brk = _internal.Brick(i, backend.grid_node_count_with_extra(), 
                        stepwidths, origin, dims)
            backend.bricks.append(brk)

        if self.submethod == "simplex_extra":
            self.prepare_with_pointwise_projection_and_extra_points()
        elif self.submethod == "simplex_enlarge":
            self.prepare_with_pointwise_projection_and_enlargement()
        elif self.submethod == "simplex_reduce":
            self.prepare_with_pointwise_projection_and_basis_reduction()
        elif self.submethod == "brick":
            self.prepare_with_brick_interpolation()
        else:
            raise RuntimeError, "invalid rec_grid submethod specified"
Ejemplo n.º 14
0
    def add_instrumentation(self, mgr, observer):
        Depositor.add_instrumentation(self, mgr, observer)

        from pyrticle.log import StatsGathererLogQuantity
        mgr.add_quantity(StatsGathererLogQuantity(
            lambda : observer.state.depositor_state.stats.normalization_stats,
            "normshape_norm", "1", 
            "normalization constants applied during deposition"))

        mgr.add_quantity(StatsGathererLogQuantity(
            lambda : observer.state.depositor_state.stats.centroid_distance_stats,
            "normshape_centroid_dist", "m", 
            "distance of shape center from element centroid"))

        mgr.add_quantity(StatsGathererLogQuantity(
            lambda : observer.state.depositor_state.stats.el_per_particle_stats,
            "normshape_el_per_particle", "1", 
            "number of elements per particle"))
Ejemplo n.º 15
0
    def __init__(self, brick_generator=SingleBrickGenerator(), 
            el_tolerance=0.12,
            max_extra_points=20,
            enforce_continuity=False,
            submethod="simplex_reduce",
            filter_min_amplification=None,
            filter_order=None,
            jiggle_radius=0.0,
            ):
        Depositor.__init__(self)
        self.brick_generator = brick_generator
        self.el_tolerance = el_tolerance
        self.max_extra_points = max_extra_points
        self.enforce_continuity = enforce_continuity
        self.submethod = submethod

        self.filter_min_amplification = filter_min_amplification
        self.filter_order = filter_order

        self.jiggle_radius = jiggle_radius
Ejemplo n.º 16
0
    def __init__(self, activation_threshold=1e-5, kill_threshold=1e-3,
            filter_amp=None, filter_order=None,
            upwind_alpha=1,
            ):
        Depositor.__init__(self)

        self.activation_threshold = activation_threshold
        self.kill_threshold = kill_threshold
        self.upwind_alpha = upwind_alpha

        self.shape_function = None

        self.filter_amp = filter_amp
        self.filter_order = filter_order

        if filter_amp is not None:
            from hedge.discretization import ExponentialFilterResponseFunction
            self.filter_response = ExponentialFilterResponseFunction(
                    filter_amp, filter_order)
        else:
            self.filter_response = None
Ejemplo n.º 17
0
    def add_instrumentation(self, mgr, observer):
        Depositor.add_instrumentation(self, mgr, observer)

        from pyrticle.log import StatsGathererLogQuantity
        mgr.add_quantity(
            StatsGathererLogQuantity(
                lambda: observer.state.depositor_state.stats.
                normalization_stats, "normshape_norm", "1",
                "normalization constants applied during deposition"))

        mgr.add_quantity(
            StatsGathererLogQuantity(
                lambda: observer.state.depositor_state.stats.
                centroid_distance_stats, "normshape_centroid_dist", "m",
                "distance of shape center from element centroid"))

        mgr.add_quantity(
            StatsGathererLogQuantity(
                lambda: observer.state.depositor_state.stats.
                el_per_particle_stats, "normshape_el_per_particle", "1",
                "number of elements per particle"))
Ejemplo n.º 18
0
    def __init__(
        self,
        brick_generator=SingleBrickGenerator(),
        el_tolerance=0.12,
        max_extra_points=20,
        enforce_continuity=False,
        submethod="simplex_reduce",
        filter_min_amplification=None,
        filter_order=None,
        jiggle_radius=0.0,
    ):
        Depositor.__init__(self)
        self.brick_generator = brick_generator
        self.el_tolerance = el_tolerance
        self.max_extra_points = max_extra_points
        self.enforce_continuity = enforce_continuity
        self.submethod = submethod

        self.filter_min_amplification = filter_min_amplification
        self.filter_order = filter_order

        self.jiggle_radius = jiggle_radius
Ejemplo n.º 19
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        discr = method.discretization

        eg, = discr.element_groups
        fg, = discr.face_groups
        ldis = eg.local_discretization

        from hedge.mesh import TAG_ALL
        bdry = discr.get_boundary(TAG_ALL)

        bdry_fg, = bdry.face_groups

        if self.filter_response:
            from hedge.discretization import Filter
            filter = Filter(discr, self.filter_response)
            filter_mat, = filter.filter_matrices
        else:
            filter_mat = numpy.zeros((0,0))

        backend_class = getattr(_internal, "AdvectiveDepositor"
                + method.get_dimensionality_suffix())
        self.backend = backend_class(method.mesh_data,
                len(ldis.face_indices()),
                ldis.node_count(),
                ldis.mass_matrix(),
                ldis.inverse_mass_matrix(),
                filter_mat,
                ldis.face_mass_matrix(),
                fg,
                bdry_fg,
                self.activation_threshold,
                self.kill_threshold,
                self.upwind_alpha)

        for i, diffmat in enumerate(ldis.differentiation_matrices()):
            self.backend.add_local_diff_matrix(i, diffmat)
Ejemplo n.º 20
0
 def clear_particles(self):
     Depositor.clear_particles(self)
     self.cloud.pic_algorithm.clear_advective_particles()
Ejemplo n.º 21
0
 def clear_particles(self):
     Depositor.clear_particles(self)
     self.cloud.pic_algorithm.clear_advective_particles()
Ejemplo n.º 22
0
 def set_shape_function(self, state, sf):
     Depositor.set_shape_function(self, state, sf)
     self.backend.shape_function = sf
Ejemplo n.º 23
0
 def set_shape_function(self, state, sf):
     Depositor.set_shape_function(self, state, sf)
     self.backend.shape_function = sf
Ejemplo n.º 24
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        backend_class = getattr(_internal, "InterpolatingDepositor" 
                + method.get_dimensionality_suffix())
        self.backend = backend_class(method.mesh_data)
Ejemplo n.º 25
0
 def __init__(self, brick_generator=None):
     Depositor.__init__(self)
     self.brick_generator = brick_generator
Ejemplo n.º 26
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        backend_class = getattr(_internal, "GridFindDepositor" 
                + method.get_dimensionality_suffix())
        backend = self.backend = backend_class(method.mesh_data)

        discr = method.discretization

        grid_node_num_to_nodes = {}

        if self.brick_generator is None:
            bbox_min, bbox_max = discr.mesh.bounding_box()
            max_bbox_size = max(bbox_max-bbox_min)
            self.brick_generator = SingleBrickGenerator(
                    mesh_margin=1e-3*max_bbox_size,
                    overresolve=0.2)

        from pyrticle._internal import Brick
        for i, (stepwidths, origin, dims) in enumerate(
                self.brick_generator(discr)):
            backend.bricks.append(
                    Brick(i, backend.grid_node_count(), stepwidths, origin, dims))

        from pyrticle._internal import BoxFloat
        for eg in discr.element_groups:
            ldis = eg.local_discretization

            for el in eg.members:
                el_bbox = BoxFloat(*el.bounding_box(discr.mesh.points))
                el_slice = discr.find_el_range(el.id)

                for brk in backend.bricks:
                    if brk.bounding_box().intersect(el_bbox).is_empty():
                        continue

                    for node_num in range(el_slice.start, el_slice.stop):
                        try:
                            cell_number = brk.which_cell(
                                        discr.nodes[node_num])
                        except ValueError:
                            pass
                        else:
                            grid_node_num_to_nodes.setdefault(
                                    brk.index(cell_number), []).append(node_num)

        from pytools import flatten
        unassigned_nodes = (set(xrange(len(discr))) 
                - set(flatten(grid_node_num_to_nodes.itervalues())))

        if unassigned_nodes:
            raise RuntimeError("dep_grid_find: unassigned mesh nodes found. "
                    "you should specify a mesh_margin when generating "
                    "bricks")

        usecounts = numpy.zeros(
                (backend.grid_node_count(),))
        for gnn in xrange(backend.grid_node_count()):
            grid_nodes = grid_node_num_to_nodes.get(gnn, [])
            usecounts[gnn] = len(grid_nodes)
            backend.node_number_list_starts.append(len(backend.node_number_lists))
            backend.node_number_lists.extend(grid_nodes)
        backend.node_number_list_starts.append(len(backend.node_number_lists))

        if "depositor" in method.debug:
            from hedge.visualization import SiloVisualizer
            vis = SiloVisualizer(discr)
            visf = vis.make_file("grid-find-debug")
            vis.add_data(visf, [])
            self.visualize_grid_quantities(visf, [
                    ("usecounts", usecounts)
                    ])
            visf.close()

            if "interactive" in cloud.debug:
                from matplotlib.pylab import hist, show
                hist(usecounts, bins=20)
                show()
Ejemplo n.º 27
0
 def __init__(self, brick_generator=None):
     Depositor.__init__(self)
     self.brick_generator = brick_generator
Ejemplo n.º 28
0
    def initialize(self, method):
        Depositor.initialize(self, method)

        backend_class = getattr(
            _internal,
            "GridFindDepositor" + method.get_dimensionality_suffix())
        backend = self.backend = backend_class(method.mesh_data)

        discr = method.discretization

        grid_node_num_to_nodes = {}

        if self.brick_generator is None:
            bbox_min, bbox_max = discr.mesh.bounding_box()
            max_bbox_size = max(bbox_max - bbox_min)
            self.brick_generator = SingleBrickGenerator(mesh_margin=1e-3 *
                                                        max_bbox_size,
                                                        overresolve=0.2)

        from pyrticle._internal import Brick
        for i, (stepwidths, origin,
                dims) in enumerate(self.brick_generator(discr)):
            backend.bricks.append(
                Brick(i, backend.grid_node_count(), stepwidths, origin, dims))

        from pyrticle._internal import BoxFloat
        for eg in discr.element_groups:
            ldis = eg.local_discretization

            for el in eg.members:
                el_bbox = BoxFloat(*el.bounding_box(discr.mesh.points))
                el_slice = discr.find_el_range(el.id)

                for brk in backend.bricks:
                    if brk.bounding_box().intersect(el_bbox).is_empty():
                        continue

                    for node_num in range(el_slice.start, el_slice.stop):
                        try:
                            cell_number = brk.which_cell(discr.nodes[node_num])
                        except ValueError:
                            pass
                        else:
                            grid_node_num_to_nodes.setdefault(
                                brk.index(cell_number), []).append(node_num)

        from pytools import flatten
        unassigned_nodes = (set(xrange(len(discr))) -
                            set(flatten(grid_node_num_to_nodes.itervalues())))

        if unassigned_nodes:
            raise RuntimeError(
                "dep_grid_find: unassigned mesh nodes found. "
                "you should specify a mesh_margin when generating "
                "bricks")

        usecounts = numpy.zeros((backend.grid_node_count(), ))
        for gnn in xrange(backend.grid_node_count()):
            grid_nodes = grid_node_num_to_nodes.get(gnn, [])
            usecounts[gnn] = len(grid_nodes)
            backend.node_number_list_starts.append(
                len(backend.node_number_lists))
            backend.node_number_lists.extend(grid_nodes)
        backend.node_number_list_starts.append(len(backend.node_number_lists))

        if "depositor" in method.debug:
            from hedge.visualization import SiloVisualizer
            vis = SiloVisualizer(discr)
            visf = vis.make_file("grid-find-debug")
            vis.add_data(visf, [])
            self.visualize_grid_quantities(visf, [("usecounts", usecounts)])
            visf.close()

            if "interactive" in cloud.debug:
                from matplotlib.pylab import hist, show
                hist(usecounts, bins=20)
                show()