Example #1
0
    def test_dl(self):
        for cells, domain_size, dim, bc in zip(self.cells_array,
                                               self.domain_size_array,
                                               self.dims, self.bcs):

            j = simulation.Simulation(time_step_nbr=self.time_step_nbr,
                                      boundary_types=bc,
                                      cells=cells,
                                      domain_size=domain_size,
                                      final_time=self.final_time)

            if phare_utilities.none_iterable(domain_size, cells):
                domain_size = phare_utilities.listify(domain_size)
                cells = phare_utilities.listify(cells)

            for d in np.arange(dim):
                self.assertEqual(j.dl[d], domain_size[d] / float(cells[d]))

            global_vars.sim = None
Example #2
0
def ghost_area_boxes(hierarchy, quantities, levelNbrs=[], time=0):
    """
    this function returns boxes representing ghost cell boxes for all levels
    a ghost cell box is a box containing cells of contiguous AMR index not
    contained in the domain box.

    if  - = domain cell and o = ghost cell

    patchdata = o o o o o  - - - - - - - - - - o o o o o
    boxes =     ^-------^                      ^-------^

    return : {level_number : [{"pdata":patch_data1, "boxes":ghost_boxes},
                              {"pdata":patch_data2, "boxes":ghost_boxes}, ...]}
    """
    levelNbrs = listify(levelNbrs)
    if len(levelNbrs) == 0:
        levelNbrs = list(hierarchy.levels(time).keys())

    gaboxes = {}

    for ilvl in levelNbrs:
        lvl = hierarchy.level(ilvl, time)
        for patch in lvl.patches:

            for pd_key, pd in patch.patch_datas.items():

                skip = not any([pd_key.endswith(qty) for qty in quantities])

                if skip:
                    continue

                patch_data = patch.patch_datas[pd_key]
                gbox = patch_data.ghost_box
                box = patch.box

                if ilvl not in gaboxes:
                    gaboxes[ilvl] = {}

                if pd_key not in gaboxes[ilvl]:
                    gaboxes[ilvl][pd_key] = []

                gaboxes[ilvl][pd_key] += [{
                    "pdata": patch_data,
                    "boxes": boxm.remove(gbox, box)
                }]

    return gaboxes
Example #3
0
def build_kwargs(**kwargs):

    quantities = ["Bx", "By", "Bz", "Ex", "Ey", "Ez", "particles"]

    if "simulation" in kwargs:
        for k in kwargs:
            if k != "simulation":
                print("warning: 'simulation' given, {} discarded".format(k))

        sim = kwargs["simulation"]
        kwargs["nbr_cells"] = sim.cells
        kwargs["origin"] = sim.origin
        kwargs["interp_order"] = sim.interp_order
        kwargs["domain_size"] = sim.simulation_domain()
        kwargs["cell_width"] = sim.dl
        kwargs["refinement_boxes"] = sim.refinement_boxes

    kwargs["quantities"] = listify(kwargs.get("quantities", quantities))
    kwargs["refinement_ratio"] = 2

    return kwargs
Example #4
0
def level_ghost_boxes(hierarchy, quantities):
    """
    this function returns boxes representing level ghost cell boxes for all levels
    A level ghost cell box is a ghost cell box that does not overlap any cell contained
    in a patchData interior
    patchdata1           : o o o o o - - - - - - - - - - - - o o o o o
    patchdata2           :                               o o o o o - - - - - - - - -
    lvl ghost cell boxes :                                   ^---^
    returns a dictionnary which keys are level_number and value is a list of dict with :
     keys:value :
        - pdata : patch_data for which level ghost cell boxes are detected
        - boxes : level ghost cell boxes
    return : {level_number : [{"pdata":patch_data1, "boxes":lvl_ghost_boxes},
                              {"pdata":patch_data2, "boxes":lvl_ghost_boxes}, ...]}
    """
    quantities = listify(quantities)
    gaboxes = ghost_area_boxes(hierarchy, quantities)
    lvl_gaboxes = {}

    for ilvl, lvl in hierarchy.levels().items():

        if is_root_lvl(
                lvl):  # level ghost do not make sense for periodic root level
            continue

        for pd_key, info_list in gaboxes[ilvl].items():

            if True:  # if periodic, always true for now
                refined_domain_box = hierarchy.refined_domain_box(ilvl)
                n_ghosts = lvl.patches[0].patch_datas[pd_key].ghosts_nbr
                patches = get_periodic_list(lvl.patches, refined_domain_box,
                                            n_ghosts)

            for info in info_list:

                patch_data, ghostAreaBoxes = info["pdata"], info["boxes"]

                check_patches = [
                    p for p in patches
                    if p.patch_datas[pd_key] is not patch_data
                ]

                for gabox in ghostAreaBoxes:

                    if len(check_patches) == 0:
                        assert len(patches) == 1  # only valid case
                        check_patches = patches

                    remaining = boxm.remove(gabox, check_patches[0].box)

                    for patch in check_patches[1:]:
                        tmp = remaining
                        remove = []
                        for i, rem in enumerate(remaining):
                            if rem * patch.box is not None:
                                tmp += boxm.remove(rem, patch.box)
                                remove.append(i)
                        for rm in remove:
                            del tmp[rm]
                        remaining = tmp

                    if ilvl not in lvl_gaboxes:
                        lvl_gaboxes[ilvl] = {}

                    if pd_key not in lvl_gaboxes[ilvl]:
                        lvl_gaboxes[ilvl] = {pd_key: []}

                    if len(remaining):
                        lvl_gaboxes[ilvl][pd_key] += [{
                            "pdata": patch_data,
                            "boxes": remaining
                        }]

    return lvl_gaboxes
Example #5
0
def level_ghost_boxes(hierarchy, quantities, levelNbrs=[], time=None):
    """
    this function returns boxes representing level ghost cell boxes for all levels
    A level ghost cell box is a ghost cell box that does not overlap any cell contained
    in a patchData interior
    patchdata1           : o o o o o - - - - - - - - - - - - o o o o o
    patchdata2           :                               o o o o o - - - - - - - - -
    lvl ghost cell boxes :                                   ^---^
    returns a dictionnary which keys are level_number and value is a list of dict with :
     keys:value :
        - pdata : patch_data for which level ghost cell boxes are detected
        - boxes : level ghost cell boxes
    return : {level_number : [{"pdata":patch_data1, "boxes":lvl_ghost_boxes},
                              {"pdata":patch_data2, "boxes":lvl_ghost_boxes}, ...]}

    optional parameters
    -----
      levelNbrs : limit working set of hierarchy levels to those requested, if scalar, returns just that level
      time      : the simulation time to access the appropriate data for the requested time
    -----
    """
    quantities = listify(quantities)

    levelNbrs_is_scalar = is_scalar(levelNbrs)
    levelNbrs = listify(levelNbrs)
    if len(levelNbrs) == 0:
        levelNbrs = list(hierarchy.levels(time).keys())

    gaboxes = ghost_area_boxes(hierarchy, quantities, levelNbrs, time)
    lvl_gaboxes = {}

    for ilvl in levelNbrs:
        lvl = hierarchy.level(ilvl, time)

        if is_root_lvl(lvl):  # level ghost do not make sense for periodic root level
            continue

        for pd_key, info_list in gaboxes[ilvl].items():

            # if periodic, always true for now
            if True:  #lgtm [py/constant-conditional-expression]
                refined_domain_box = hierarchy.refined_domain_box(ilvl)
                n_ghosts = lvl.patches[0].patch_datas[pd_key].ghosts_nbr
                patches = get_periodic_list(lvl.patches, refined_domain_box, n_ghosts)

            for info in info_list:

                patch_data, ghostAreaBoxes = info["pdata"], info["boxes"]

                check_patches = [p for p in patches if p.patch_datas[pd_key] is not patch_data]

                if len(check_patches) == 0:
                    check_patches = patches

                for gabox in ghostAreaBoxes:

                    remaining = gabox - check_patches[0].box

                    for patch in check_patches[1:]:
                        tmp = []
                        remove = []
                        for i, rem in enumerate(remaining):
                            if rem * patch.box is not None:
                                remove.append(i)
                                tmp += rem - patch.box
                        for rm in reversed(remove):
                            del remaining[rm]
                        remaining += tmp

                    if ilvl not in lvl_gaboxes:
                        lvl_gaboxes[ilvl] = {}

                    if pd_key not in lvl_gaboxes[ilvl]:
                        lvl_gaboxes[ilvl][pd_key] = []

                    if len(remaining):
                        lvl_gaboxes[ilvl][pd_key] += [{"pdata": patch_data, "boxes": remaining}]

    if levelNbrs_is_scalar:
        return lvl_gaboxes[levelNbrs[0]]
    return lvl_gaboxes