コード例 #1
0
ファイル: test_conditions.py プロジェクト: Gkdnz/sfepy
    def test_epbcs(self):
        from sfepy.discrete import Function, Functions
        from sfepy.discrete.conditions import Conditions, PeriodicBC
        from sfepy.discrete.common.dof_info import expand_nodes_to_equations
        from sfepy.discrete.fem.periodic import match_y_line

        variables = self.variables
        regions = self.problem.domain.regions

        match_y_line = Function('match_y_line', match_y_line)
        pbc = PeriodicBC('pbc', [regions['LeftStrip'], regions['RightStrip']],
                         {'u.[1,0]' : 'u.[0,1]'}, match='match_y_line')

        functions = Functions([match_y_line])

        epbcs = Conditions([pbc])
        variables.equation_mapping(ebcs=None, epbcs=epbcs,
                                   ts=None, functions=functions)

        vec = init_vec(variables)
        variables.apply_ebc(vec)

        var = variables['u']
        var_bcs = epbcs.group_by_variables()['u']
        bc = var_bcs['pbc']
        bc.canonize_dof_names(var.dofs)

        nods0 = var.field.get_dofs_in_region(bc.regions[0])
        nods1 = var.field.get_dofs_in_region(bc.regions[1])

        coors0 = var.field.get_coor(nods0)
        coors1 = var.field.get_coor(nods1)
        i0, i1 = match_y_line(coors0, coors1)

        eq0 = expand_nodes_to_equations(nods0[i0], bc.dofs[0], var.dofs)
        eq1 = expand_nodes_to_equations(nods1[i1], bc.dofs[1], var.dofs)

        ok = True

        _ok = len(nm.setdiff1d(eq0, var.eq_map.master)) == 0
        if not _ok:
            self.report('master equations mismatch! (set(%s) == set(%s))'
                        % (eq0, var.eq_map.master))
        ok = ok and _ok

        _ok = len(nm.setdiff1d(eq1, var.eq_map.slave)) == 0
        if not _ok:
            self.report('slave equations mismatch! (set(%s) == set(%s))'
                        % (eq1, var.eq_map.slave))
        ok = ok and _ok

        off = variables.di.indx['u'].start
        _ok = nm.allclose(vec[off + eq0], vec[off + eq1], atol=1e-14, rtol=0.0)
        if not _ok:
            self.report('periodicity test failed! (%s == %s)'
                        % (vec[off + eq0], vec[off + eq0]))
        ok = ok and _ok

        return ok
コード例 #2
0
ファイル: lcbc_operators.py プロジェクト: Gkdnz/sfepy
    def __init__(self, name, regions, dof_names, dof_map_fun, shift_fun, variables, ts, functions):
        LCBCOperator.__init__(self, name, regions, dof_names, dof_map_fun, variables, functions=functions)

        self.shift_fun = get_condition_value(shift_fun, functions, "LCBC", "shift")

        mvar = variables[self.var_names[0]]
        svar = variables[self.var_names[1]]

        mfield = mvar.field
        sfield = svar.field

        nmaster = mfield.get_dofs_in_region(regions[0], merge=True)
        nslave = sfield.get_dofs_in_region(regions[1], merge=True)

        if nmaster.shape != nslave.shape:
            msg = "shifted EPBC node list lengths do not match!\n(%s,\n %s)" % (nmaster, nslave)
            raise ValueError(msg)

        mcoor = mfield.get_coor(nmaster)
        scoor = sfield.get_coor(nslave)

        i1, i2 = self.dof_map_fun(mcoor, scoor)
        self.mdofs = expand_nodes_to_equations(nmaster[i1], dof_names[0], self.all_dof_names[0])
        self.sdofs = expand_nodes_to_equations(nslave[i2], dof_names[1], self.all_dof_names[1])

        self.shift = self.shift_fun(ts, scoor[i2], regions[1])

        meq = mvar.eq_map.eq[self.mdofs]
        seq = svar.eq_map.eq[self.sdofs]

        # Ignore DOFs with EBCs or EPBCs.
        mia = nm.where(meq >= 0)[0]
        sia = nm.where(seq >= 0)[0]

        ia = nm.intersect1d(mia, sia)

        meq = meq[ia]
        seq = seq[ia]

        num = len(ia)

        ones = nm.ones(num, dtype=nm.float64)
        n_dofs = [variables.adi.n_dof[ii] for ii in self.var_names]
        mtx = sp.coo_matrix((ones, (meq, seq)), shape=n_dofs)

        self.mtx = mtx.tocsr()

        self.rhs = self.shift.ravel()[ia]

        self.ameq = meq
        self.aseq = seq

        self.n_mdof = len(nm.unique(meq))
        self.n_sdof = len(nm.unique(seq))
        self.n_new_dof = 0
コード例 #3
0
ファイル: test_conditions.py プロジェクト: Gkdnz/sfepy
def check_vec(self, vec, ii, ok, conds, variables):
    from sfepy.discrete.common.dof_info import expand_nodes_to_equations

    for var_name, var_conds in conds.group_by_variables().iteritems():
        var = variables[var_name]
        for cond in var_conds:
            cond.canonize_dof_names(var.dofs)
            self.report('%d: %s %s: %s %s'
                        % (ii, var.name,
                           cond.name, cond.region.name, cond.dofs[0]))
            nods = var.field.get_dofs_in_region(cond.region)
            eq = expand_nodes_to_equations(nods, cond.dofs[0], var.dofs)

            off = variables.di.indx[var_name].start
            n_nod = len(nods)
            for cdof, dof_name in enumerate(cond.dofs[0]):
                idof = var.dofs.index(dof_name)
                eqs = eq[n_nod * cdof : n_nod * (cdof + 1)]

                _ok = nm.allclose(vec[off + eqs], idof,
                                  atol=1e-14, rtol=0.0)
                if not _ok:
                    self.report(' %s: failed! (all of %s == %f)'
                                % (dof_name, vec[off + eqs], idof))
                ok = ok and _ok

    return ok
コード例 #4
0
ファイル: test_conditions.py プロジェクト: uberstig/sfepy
def check_vec(self, vec, ii, ok, conds, variables):
    from sfepy.discrete.common.dof_info import expand_nodes_to_equations

    for var_name, var_conds in conds.group_by_variables().iteritems():
        var = variables[var_name]
        for cond in var_conds:
            cond.canonize_dof_names(var.dofs)
            self.report(
                '%d: %s %s: %s %s' %
                (ii, var.name, cond.name, cond.region.name, cond.dofs[0]))
            nods = var.field.get_dofs_in_region(cond.region)
            eq = expand_nodes_to_equations(nods, cond.dofs[0], var.dofs)

            off = variables.di.indx[var_name].start
            n_nod = len(nods)
            for cdof, dof_name in enumerate(cond.dofs[0]):
                idof = var.dofs.index(dof_name)
                eqs = eq[n_nod * cdof:n_nod * (cdof + 1)]

                _ok = nm.allclose(vec[off + eqs], idof, atol=1e-14, rtol=0.0)
                if not _ok:
                    self.report(' %s: failed! (all of %s == %f)' %
                                (dof_name, vec[off + eqs], idof))
                ok = ok and _ok

    return ok
コード例 #5
0
    def setup(self):
        eq = self.eq_map.eq
        meq = expand_nodes_to_equations(self.mdofs, self.dof_names,
                                        self.all_dof_names)
        self.ameq = eq[meq]
        assert_(nm.all(self.ameq >= 0))

        if self.eq_map.n_epbc:
            self.treat_pbcs(meq, self.eq_map.master)
コード例 #6
0
ファイル: lcbc_operators.py プロジェクト: clazaro/sfepy
    def setup(self):
        eq = self.eq_map.eq
        meq = expand_nodes_to_equations(self.mdofs, self.dof_names,
                                        self.all_dof_names)
        self.ameq = eq[meq]
        assert_(nm.all(self.ameq >= 0))

        if self.eq_map.n_epbc:
            self.treat_pbcs(meq, self.eq_map.master)
コード例 #7
0
ファイル: lcbc_operators.py プロジェクト: Gkdnz/sfepy
    def setup(self):
        eq = self.eq_map.eq
        meq = expand_nodes_to_equations(self.mdofs, self.dof_names, self.all_dof_names)
        ameq = eq[meq]
        assert_(nm.all(ameq >= 0))

        if self.eq_map.n_epbc:
            self.treat_pbcs(meq, self.eq_map.master)

        # Node-by-node order compatible with MRLCBCOperator matrices.
        self.ameq = ameq.reshape((len(self.dof_names), -1)).T.ravel()
コード例 #8
0
    def setup(self):
        eq = self.eq_map.eq
        meq = expand_nodes_to_equations(self.mdofs, self.dof_names,
                                         self.all_dof_names)
        ameq = eq[meq]
        assert_(nm.all(ameq >= 0))

        if self.eq_map.n_epbc:
            self.treat_pbcs(meq, self.eq_map.master)

        # Node-by-node order compatible with MRLCBCOperator matrices.
        self.ameq = ameq.reshape((len(self.dof_names), -1)).T.ravel()
コード例 #9
0
ファイル: lcbc_operators.py プロジェクト: vondrejc/sfepy
    def append(self, op):
        Container.append(self, op)

        eq = self.eq_map.eq
        dofs = expand_nodes_to_equations(op.nodes, op.dof_names,
                                         self.eq_map.dof_names)
        meq = eq[dofs]
        assert_(nm.all(meq >= 0))

        if self.eq_map.n_epbc:
            op.treat_pbcs(dofs, self.eq_map.master)

        self.markers.append(self.offset + self.n_op + 1)
        self.eq_lcbc[meq] = self.markers[-1]

        self.n_transformed_dof.append(op.n_dof)
        self.n_op = len(self)
コード例 #10
0
ファイル: lcbc_operators.py プロジェクト: LeiDai/sfepy
    def append(self, op):
        Container.append(self, op)

        eq = self.eq_map.eq
        dofs = expand_nodes_to_equations(op.nodes, op.dof_names,
                                         self.eq_map.dof_names)
        meq = eq[dofs]
        assert_(nm.all(meq >= 0))

        if self.eq_map.n_epbc:
            op.treat_pbcs(dofs, self.eq_map.master)

        self.markers.append(self.offset + self.n_op + 1)
        self.eq_lcbc[meq] = self.markers[-1]

        self.n_transformed_dof.append(op.n_dof)
        self.n_op = len(self)
コード例 #11
0
ファイル: test_conditions.py プロジェクト: uberstig/sfepy
    def test_epbcs(self):
        from sfepy.discrete import Function, Functions
        from sfepy.discrete.conditions import Conditions, PeriodicBC
        from sfepy.discrete.common.dof_info import expand_nodes_to_equations
        from sfepy.discrete.fem.periodic import match_y_line

        variables = self.variables
        regions = self.problem.domain.regions

        match_y_line = Function('match_y_line', match_y_line)
        pbc = PeriodicBC('pbc', [regions['LeftStrip'], regions['RightStrip']],
                         {'u.[1,0]': 'u.[0,1]'},
                         match='match_y_line')

        functions = Functions([match_y_line])

        epbcs = Conditions([pbc])
        variables.equation_mapping(ebcs=None,
                                   epbcs=epbcs,
                                   ts=None,
                                   functions=functions)

        vec = init_vec(variables)
        variables.apply_ebc(vec)

        var = variables['u']
        var_bcs = epbcs.group_by_variables()['u']
        bc = var_bcs['pbc']
        bc.canonize_dof_names(var.dofs)

        nods0 = var.field.get_dofs_in_region(bc.regions[0])
        nods1 = var.field.get_dofs_in_region(bc.regions[1])

        coors0 = var.field.get_coor(nods0)
        coors1 = var.field.get_coor(nods1)
        i0, i1 = match_y_line(coors0, coors1)

        eq0 = expand_nodes_to_equations(nods0[i0], bc.dofs[0], var.dofs)
        eq1 = expand_nodes_to_equations(nods1[i1], bc.dofs[1], var.dofs)

        ok = True

        _ok = len(nm.setdiff1d(eq0, var.eq_map.master)) == 0
        if not _ok:
            self.report('master equations mismatch! (set(%s) == set(%s))' %
                        (eq0, var.eq_map.master))
        ok = ok and _ok

        _ok = len(nm.setdiff1d(eq1, var.eq_map.slave)) == 0
        if not _ok:
            self.report('slave equations mismatch! (set(%s) == set(%s))' %
                        (eq1, var.eq_map.slave))
        ok = ok and _ok

        off = variables.di.indx['u'].start
        _ok = nm.allclose(vec[off + eq0], vec[off + eq1], atol=1e-14, rtol=0.0)
        if not _ok:
            self.report('periodicity test failed! (%s == %s)' %
                        (vec[off + eq0], vec[off + eq0]))
        ok = ok and _ok

        return ok
コード例 #12
0
    def __init__(self, name, regions, dof_names, dof_map_fun, shift_fun,
                 variables, ts, functions):
        LCBCOperator.__init__(self, name, regions, dof_names, dof_map_fun,
                              variables, functions=functions)

        self.shift_fun = get_condition_value(shift_fun, functions,
                                             'LCBC', 'shift')

        mvar = variables[self.var_names[0]]
        svar = variables[self.var_names[1]]

        mfield = mvar.field
        sfield = svar.field

        nmaster = mfield.get_dofs_in_region(regions[0], merge=True)
        nslave = sfield.get_dofs_in_region(regions[1], merge=True)

        if nmaster.shape != nslave.shape:
            msg = 'shifted EPBC node list lengths do not match!\n(%s,\n %s)' %\
                  (nmaster, nslave)
            raise ValueError(msg)

        mcoor = mfield.get_coor(nmaster)
        scoor = sfield.get_coor(nslave)

        i1, i2 = self.dof_map_fun(mcoor, scoor)
        self.mdofs = expand_nodes_to_equations(nmaster[i1], dof_names[0],
                                               self.all_dof_names[0])
        self.sdofs = expand_nodes_to_equations(nslave[i2], dof_names[1],
                                               self.all_dof_names[1])

        self.shift = self.shift_fun(ts, scoor[i2], regions[1])

        meq = mvar.eq_map.eq[self.mdofs]
        seq = svar.eq_map.eq[self.sdofs]

        # Ignore DOFs with EBCs or EPBCs.
        mia = nm.where(meq >= 0)[0]
        sia = nm.where(seq >= 0)[0]

        ia = nm.intersect1d(mia, sia)

        meq = meq[ia]
        seq = seq[ia]

        num = len(ia)

        ones = nm.ones(num, dtype=nm.float64)
        n_dofs = [variables.adi.n_dof[ii] for ii in self.var_names]
        mtx = sp.coo_matrix((ones, (meq, seq)), shape=n_dofs)

        self.mtx = mtx.tocsr()

        self.rhs = self.shift.ravel()[ia]

        self.ameq = meq
        self.aseq = seq

        self.n_mdof = len(nm.unique(meq))
        self.n_sdof = len(nm.unique(seq))
        self.n_new_dof = 0