示例#1
0
    def refine_locals(self, child_boxes, local_exps):
        rscale = 1  # FIXME

        from pyfmmlib import h2dlocloc_vec

        for tgt_ibox in child_boxes:
            tgt_center = self.tree.box_centers[:, tgt_ibox]
            src_ibox = self.tree.box_parent_ids[tgt_ibox]
            src_center = self.tree.box_centers[:, src_ibox]

            tmp_loc_exp = h2dlocloc_vec(self.helmholtz_k, rscale, src_center,
                                        local_exps[src_ibox], rscale,
                                        tgt_center, self.nterms)[:, 0]

            local_exps[tgt_ibox] += tmp_loc_exp

        return local_exps
示例#2
0
    def refine_locals(self, child_boxes, local_exps):
        rscale = 1  # FIXME

        from pyfmmlib import h2dlocloc_vec

        for tgt_ibox in child_boxes:
            tgt_center = self.tree.box_centers[:, tgt_ibox]
            src_ibox = self.tree.box_parent_ids[tgt_ibox]
            src_center = self.tree.box_centers[:, src_ibox]

            tmp_loc_exp = h2dlocloc_vec(
                        self.helmholtz_k,
                        rscale, src_center, local_exps[src_ibox],
                        rscale, tgt_center, self.nterms)[:, 0]

            local_exps[tgt_ibox] += tmp_loc_exp

        return local_exps
示例#3
0
    def refine_locals(self, level_start_target_or_target_parent_box_nrs,
            target_or_target_parent_boxes, local_exps):
        rscale = 1  # FIXME

        from pyfmmlib import h2dlocloc_vec

        for target_lev in range(1, self.tree.nlevels):
            start, stop = level_start_target_or_target_parent_box_nrs[
                    target_lev:target_lev+2]

            for tgt_ibox in target_or_target_parent_boxes[start:stop]:
                tgt_center = self.tree.box_centers[:, tgt_ibox]
                src_ibox = self.tree.box_parent_ids[tgt_ibox]
                src_center = self.tree.box_centers[:, src_ibox]

                tmp_loc_exp = h2dlocloc_vec(
                            self.helmholtz_k,
                            rscale, src_center, local_exps[src_ibox],
                            rscale, tgt_center, self.nterms)[:, 0]

                local_exps[tgt_ibox] += tmp_loc_exp

        return local_exps
示例#4
0
def test_translations():
    nterms = 15
    zk = 3
    rscale = 1

    n = 40
    # centered at the origin, extent [-.5,.5]
    sources = np.random.uniform(size=(n, 2)) - 0.5
    charges = np.random.uniform(size=n)

    targets_center = np.array([10, 0])
    targets = np.random.uniform(size=(n, 2)) - 0.5 + targets_center

    from pyfmmlib import (h2dformmp, h2dmpmp_vec, h2dmploc_vec, h2dlocloc_vec,
                          h2dtaeval_vec, hpotgrad2dall_vec, h2dmpeval_vec)

    ref_value, _, _ = hpotgrad2dall_vec(ifgrad=False,
                                        ifhess=False,
                                        sources=sources.T,
                                        charge=charges,
                                        targets=targets.T,
                                        zk=zk)

    # {{{ multipole 1

    mp1_center = np.array([0, 0])
    ier, mp1 = h2dformmp(zk, rscale, sources.T, charges, mp1_center, nterms)
    assert ier == 0

    mp1_value, _, _ = h2dmpeval_vec(zk,
                                    rscale,
                                    mp1_center,
                                    mp1,
                                    ztarg=targets.T,
                                    ifgrad=False,
                                    ifhess=False)

    assert la.norm(mp1_value - ref_value) / la.norm(ref_value) < 1e-12

    # }}}

    # {{{ multipole 2

    mp2_center = np.array([2, 0])
    mp2 = h2dmpmp_vec(zk, rscale, mp1_center, mp1, rscale, mp2_center, nterms)

    mp2_value, _, _ = h2dmpeval_vec(zk,
                                    rscale,
                                    mp2_center,
                                    mp2,
                                    ztarg=targets.T,
                                    ifgrad=False,
                                    ifhess=False)

    assert la.norm(mp2_value - ref_value) / la.norm(ref_value) < 3e-5

    # }}}

    # {{{ local 1

    loc1_center = targets_center - np.array([1, 0])
    loc1 = h2dmploc_vec(zk, rscale, mp2_center, mp2, rscale, loc1_center,
                        nterms)

    loc1_value, _, _ = h2dtaeval_vec(zk,
                                     rscale,
                                     loc1_center,
                                     loc1,
                                     ztarg=targets.T,
                                     ifgrad=False,
                                     ifhess=False)

    assert la.norm(loc1_value - ref_value) / la.norm(ref_value) < 3e-5

    # }}}

    # {{{ local 2

    loc2_center = targets_center
    loc2 = h2dlocloc_vec(zk, rscale, loc1_center, loc1, rscale, loc2_center,
                         nterms)

    loc2_value, _, _ = h2dtaeval_vec(zk,
                                     rscale,
                                     loc2_center,
                                     loc2,
                                     ztarg=targets.T,
                                     ifgrad=False,
                                     ifhess=False)

    assert la.norm(loc2_value - ref_value) / la.norm(ref_value) < 1e-4
示例#5
0
def test_translations():
    nterms = 15
    zk = 3
    rscale = 1

    n = 40
    # centered at the origin, extent [-.5,.5]
    sources = np.random.uniform(size=(n, 2)) - 0.5
    charges = np.random.uniform(size=n)

    targets_center = np.array([10, 0])
    targets = np.random.uniform(size=(n, 2)) - 0.5 + targets_center

    from pyfmmlib import (h2dformmp, h2dmpmp_vec, h2dmploc_vec,
            h2dlocloc_vec, h2dtaeval_vec, hpotgrad2dall_vec, h2dmpeval_vec)

    ref_value, _, _ = hpotgrad2dall_vec(ifgrad=False, ifhess=False,
            sources=sources.T, charge=charges,
            targets=targets.T, zk=zk)

    # {{{ multipole 1

    mp1_center = np.array([0, 0])
    ier, mp1 = h2dformmp(zk, rscale, sources.T, charges, mp1_center, nterms)
    assert ier == 0

    mp1_value, _, _ = h2dmpeval_vec(zk, rscale, mp1_center, mp1, ztarg=targets.T,
            ifgrad=False, ifhess=False)

    assert la.norm(mp1_value - ref_value) / la.norm(ref_value) < 1e-12

    # }}}

    # {{{ multipole 2

    mp2_center = np.array([2, 0])
    mp2 = h2dmpmp_vec(zk, rscale, mp1_center, mp1, rscale, mp2_center, nterms)

    mp2_value, _, _ = h2dmpeval_vec(zk, rscale, mp2_center, mp2, ztarg=targets.T,
            ifgrad=False, ifhess=False)

    assert la.norm(mp2_value - ref_value) / la.norm(ref_value) < 3e-5

    # }}}

    # {{{ local 1

    loc1_center = targets_center - np.array([1, 0])
    loc1 = h2dmploc_vec(zk, rscale, mp2_center, mp2, rscale, loc1_center, nterms)

    loc1_value, _, _ = h2dtaeval_vec(zk, rscale, loc1_center, loc1,
            ztarg=targets.T, ifgrad=False, ifhess=False)

    assert la.norm(loc1_value - ref_value) / la.norm(ref_value) < 3e-5

    # }}}

    # {{{ local 2

    loc2_center = targets_center
    loc2 = h2dlocloc_vec(zk, rscale, loc1_center, loc1, rscale, loc2_center, nterms)

    loc2_value, _, _ = h2dtaeval_vec(zk, rscale, loc2_center, loc2, ztarg=targets.T,
            ifgrad=False, ifhess=False)

    assert la.norm(loc2_value - ref_value) / la.norm(ref_value) < 1e-4