コード例 #1
0
    def get_fargs(self, mat, kappa, virtual, state,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        from sfepy.discrete.variables import create_adof_conn

        geo, _ = self.get_mapping(state)

        n_fa, n_qp, dim, n_fn, n_c = self.get_data_shape(virtual)

        # Expand basis for all components.
        bf = geo.bf
        ebf = nm.zeros(bf.shape[:2] + (dim, n_fn * dim), dtype=nm.float64)
        for ir in range(dim):
            ebf[..., ir, ir*n_fn:(ir+1)*n_fn] = bf[..., 0, :]

        gmat = _build_wave_strain_op(kappa, ebf)

        if diff_var is None:
            econn = state.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(state.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = state()[adc]
            # Same as nm.einsum('qij,cj->cqi', gmat[0], vals)[..., None]
            aux = dot_sequences(gmat, vals[:, None, :, None])
            out_qp = dot_sequences(gmat, dot_sequences(mat, aux), 'ATB')
            fmode = 0

        else:
            out_qp = dot_sequences(gmat, dot_sequences(mat, gmat), 'ATB')
            fmode = 1

        return out_qp, geo, fmode
コード例 #2
0
    def get_fargs(self,
                  kappa,
                  virtual,
                  state,
                  mode=None,
                  term_mode=None,
                  diff_var=None,
                  **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(state)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(virtual)

        ebf = expand_basis(geo.bf, dim)

        aux = nm.einsum('i,...ij->...j', kappa, ebf)[0, :, None, :]
        kebf = insert_strided_axis(aux, 0, n_el)

        if diff_var is None:
            econn = state.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(state.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = state()[adc]
            aux = dot_sequences(kebf, vals[:, None, :, None])
            out_qp = dot_sequences(kebf, aux, 'ATB')
            fmode = 0

        else:
            out_qp = dot_sequences(kebf, kebf, 'ATB')
            fmode = 1

        return out_qp, geo, fmode
コード例 #3
0
ファイル: terms_navier_stokes.py プロジェクト: rc/sfepy
    def get_fargs(self, kappa, virtual, state,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(state)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(virtual)

        ebf = expand_basis(geo.bf, dim)

        aux = nm.einsum('i,...ij->...j', kappa, ebf)[0, :, None, :]
        kebf = insert_strided_axis(aux, 0, n_el)

        if diff_var is None:
            econn = state.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(state.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = state()[adc]
            aux = dot_sequences(kebf, vals[:, None, :, None])
            out_qp = dot_sequences(kebf, aux, 'ATB')
            fmode = 0

        else:
            out_qp = dot_sequences(kebf, kebf, 'ATB')
            fmode = 1

        return out_qp, geo, fmode
コード例 #4
0
    def get_fargs(self,
                  mat,
                  kappa,
                  virtual,
                  state,
                  mode=None,
                  term_mode=None,
                  diff_var=None,
                  **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(state)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(virtual)

        ebf = expand_basis(geo.bf, dim)

        gmat = _build_wave_strain_op(kappa, ebf)

        if diff_var is None:
            econn = state.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(state.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = state()[adc]
            # Same as nm.einsum('qij,cj->cqi', gmat[0], vals)[..., None]
            aux = dot_sequences(gmat, vals[:, None, :, None])
            out_qp = dot_sequences(gmat, dot_sequences(mat, aux), 'ATB')
            fmode = 0

        else:
            out_qp = dot_sequences(gmat, dot_sequences(mat, gmat), 'ATB')
            fmode = 1

        return out_qp, geo, fmode
コード例 #5
0
ファイル: terms_elastic.py プロジェクト: rc/sfepy
    def get_fargs(self, mat, kappa, virtual, state,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(state)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(virtual)

        ebf = expand_basis(geo.bf, dim)

        gmat = _build_wave_strain_op(kappa, ebf)

        if diff_var is None:
            econn = state.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(state.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = state()[adc]
            # Same as nm.einsum('qij,cj->cqi', gmat[0], vals)[..., None]
            aux = dot_sequences(gmat, vals[:, None, :, None])
            out_qp = dot_sequences(gmat, dot_sequences(mat, aux), 'ATB')
            fmode = 0

        else:
            out_qp = dot_sequences(gmat, dot_sequences(mat, gmat), 'ATB')
            fmode = 1

        return out_qp, geo, fmode
コード例 #6
0
    def get_fargs(self,
                  mtx_d,
                  drill,
                  virtual,
                  state,
                  mode=None,
                  term_mode=None,
                  diff_var=None,
                  **kwargs):
        from sfepy.discrete.variables import create_adof_conn

        vv, vu = virtual, state
        geo, _ = self.get_mapping(vv)

        # Displacements of element nodes.
        vec_u = vu()
        econn = vu.field.get_econn('volume', self.region)
        adc = create_adof_conn(nm.arange(vu.n_dof, dtype=nm.int32), econn, 6,
                               0)
        el_u = vec_u[adc]

        qp_coors = geo.qp.vals

        dsg = shell10x.get_dsg_strain(geo.coors_loc, geo.qp.vals)
        mtx_b = shell10x.create_strain_matrix(geo.bfgm, geo.dxidx, dsg)
        mtx_be = shell10x.add_eas_dofs(mtx_b, qp_coors, geo.det, geo.det0,
                                       geo.dxidx0)

        mtx_dr = shell10x.rotate_elastic_tensor(mtx_d, geo.bfu, geo.ebs)
        mtx_k_qp = ddot(ddot(mtx_be, mtx_dr, 'ATB'), mtx_be, 'AB')

        # Integrate.
        mtx_k = (mtx_k_qp * (geo.det * geo.qp.weights)[..., None, None]).sum(1)

        # Static condensation.
        k11 = mtx_k[:, :24, :24]
        k12 = mtx_k[:, :24, 24:]
        k22 = mtx_k[:, 24:, 24:]

        mtx_k = k11 - ddot(ddot(k12, nm.linalg.inv(k22)), k12.transpose(
            0, 2, 1))

        if drill != 0.0:
            coefs = mtx_dr[..., 3, 3].mean(1) * geo.volume * drill
            mtx_k = shell10x.lock_drilling_rotations(mtx_k, geo.ebs, coefs)

        # DOFs in mtx_k are DOF-by-DOF. Transform is u and phi node-by-node.
        blocks = nm.arange(24).reshape(2, 3, 4)
        blocks = blocks.transpose((0, 2, 1)).reshape((-1, 3))
        shell10x.transform_asm_matrices(mtx_k[:, None, ...], geo.mtx_t, blocks)

        fmode = diff_var is not None

        return (mtx_k, el_u, fmode)
コード例 #7
0
    def get_fargs(self,
                  kappa,
                  kvar,
                  dvar,
                  mode=None,
                  term_mode=None,
                  diff_var=None,
                  **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(dvar)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(kvar)

        ebf = expand_basis(geo.bf, dim)

        aux = nm.einsum('i,...ij->...j', kappa, ebf)[0, :, None, :]
        kebf = insert_strided_axis(aux, 0, n_el)

        div_bf = geo.bfg

        div_bf = div_bf.reshape((n_el, n_qp, 1, dim * n_en))
        div_bf = nm.ascontiguousarray(div_bf)

        if diff_var is None:
            avar = dvar if self.mode == 'kd' else kvar
            econn = avar.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(avar.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = avar()[adc]

            if self.mode == 'kd':
                aux = dot_sequences(div_bf, vals[:, None, :, None])
                out_qp = dot_sequences(kebf, aux, 'ATB')

            else:
                aux = dot_sequences(kebf, vals[:, None, :, None])
                out_qp = dot_sequences(div_bf, aux, 'ATB')

            fmode = 0

        else:
            if self.mode == 'kd':
                out_qp = dot_sequences(kebf, div_bf, 'ATB')

            else:
                out_qp = dot_sequences(div_bf, kebf, 'ATB')

            fmode = 1

        return out_qp, geo, fmode
コード例 #8
0
ファイル: terms_elastic.py プロジェクト: zitkat/sfepy
    def get_fargs(self,
                  mat,
                  kappa,
                  gvar,
                  evar,
                  mode=None,
                  term_mode=None,
                  diff_var=None,
                  **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(evar)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(gvar)

        ebf = expand_basis(geo.bf, dim)

        mat = Term.tile_mat(mat, n_el)
        gmat = _build_wave_strain_op(kappa, ebf)
        emat = _build_cauchy_strain_op(geo.bfg)

        if diff_var is None:
            avar = evar if self.mode == 'ge' else gvar
            econn = avar.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(avar.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = avar()[adc]

            if self.mode == 'ge':
                # Same as aux = self.get(avar, 'cauchy_strain'),
                aux = dot_sequences(emat, vals[:, None, :, None])
                out_qp = dot_sequences(gmat, dot_sequences(mat, aux), 'ATB')

            else:
                aux = dot_sequences(gmat, vals[:, None, :, None])
                out_qp = dot_sequences(emat, dot_sequences(mat, aux), 'ATB')

            fmode = 0

        else:
            if self.mode == 'ge':
                out_qp = dot_sequences(gmat, dot_sequences(mat, emat), 'ATB')

            else:
                out_qp = dot_sequences(emat, dot_sequences(mat, gmat), 'ATB')

            fmode = 1

        return out_qp, geo, fmode
コード例 #9
0
ファイル: terms_shells.py プロジェクト: Gkdnz/sfepy
    def get_fargs(self, mtx_d, drill, virtual, state,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        from sfepy.discrete.variables import create_adof_conn

        vv, vu = virtual, state
        geo, _ = self.get_mapping(vv)

        # Displacements of element nodes.
        vec_u = vu()
        econn = vu.field.get_econn('volume', self.region)
        adc = create_adof_conn(nm.arange(vu.n_dof, dtype=nm.int32), econn, 6, 0)
        el_u = vec_u[adc]

        qp_coors = geo.qp.vals

        dsg = shell10x.get_dsg_strain(geo.coors_loc, geo.qp.vals)
        mtx_b = shell10x.create_strain_matrix(geo.bfgm, geo.dxidx, dsg)
        mtx_be = shell10x.add_eas_dofs(mtx_b, qp_coors, geo.det,
                                       geo.det0, geo.dxidx0)

        mtx_dr = shell10x.rotate_elastic_tensor(mtx_d, geo.bfu, geo.ebs)
        mtx_k_qp = ddot(ddot(mtx_be, mtx_dr, 'ATB'), mtx_be, 'AB')

        # Integrate.
        mtx_k = (mtx_k_qp * (geo.det * geo.qp.weights)[..., None, None]).sum(1)

        # Static condensation.
        k11 = mtx_k[:, :24, :24]
        k12 = mtx_k[:, :24, 24:]
        k22 = mtx_k[:, 24:, 24:]

        mtx_k = k11 - ddot(ddot(k12, nm.linalg.inv(k22)),
                           k12.transpose(0, 2, 1))

        if drill != 0.0:
            coefs =  mtx_dr[..., 3, 3].mean(1) * geo.volume * drill
            mtx_k = shell10x.lock_drilling_rotations(mtx_k, geo.ebs, coefs)

        # DOFs in mtx_k are DOF-by-DOF. Transform is u and phi node-by-node.
        blocks = nm.arange(24).reshape(2, 3, 4)
        blocks = blocks.transpose((0, 2, 1)).reshape((-1, 3))
        shell10x.transform_asm_matrices(mtx_k[:, None, ...], geo.mtx_t, blocks)

        fmode = diff_var is not None

        return (mtx_k, el_u, fmode)
コード例 #10
0
ファイル: terms_navier_stokes.py プロジェクト: rc/sfepy
    def get_fargs(self, kappa, kvar, dvar,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(dvar)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(kvar)

        ebf = expand_basis(geo.bf, dim)

        aux = nm.einsum('i,...ij->...j', kappa, ebf)[0, :, None, :]
        kebf = insert_strided_axis(aux, 0, n_el)

        div_bf = geo.bfg

        div_bf = div_bf.reshape((n_el, n_qp, 1, dim * n_en))
        div_bf = nm.ascontiguousarray(div_bf)

        if diff_var is None:
            avar = dvar if self.mode == 'kd' else kvar
            econn = avar.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(avar.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = avar()[adc]

            if self.mode == 'kd':
                aux = dot_sequences(div_bf, vals[:, None, :, None])
                out_qp = dot_sequences(kebf, aux, 'ATB')

            else:
                aux = dot_sequences(kebf, vals[:, None, :, None])
                out_qp = dot_sequences(div_bf, aux, 'ATB')

            fmode = 0

        else:
            if self.mode == 'kd':
                out_qp = dot_sequences(kebf, div_bf, 'ATB')

            else:
                out_qp = dot_sequences(div_bf, kebf, 'ATB')

            fmode = 1

        return out_qp, geo, fmode
コード例 #11
0
    def get_fargs(self, mat, kappa, gvar, evar,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        from sfepy.discrete.variables import create_adof_conn

        geo, _ = self.get_mapping(evar)

        n_fa, n_qp, dim, n_fn, n_c = self.get_data_shape(gvar)

        # Expand basis for all components.
        bf = geo.bf
        ebf = nm.zeros(bf.shape[:2] + (dim, n_fn * dim), dtype=nm.float64)
        for ir in range(dim):
            ebf[..., ir, ir*n_fn:(ir+1)*n_fn] = bf[..., 0, :]

        gmat = _build_wave_strain_op(kappa, ebf)
        emat = _build_cauchy_strain_op(geo.bfg)

        if diff_var is None:
            avar = evar if self.mode == 'ge' else gvar
            econn = avar.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(avar.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = avar()[adc]

            if self.mode == 'ge':
                # Same as aux = self.get(avar, 'cauchy_strain'),
                aux = dot_sequences(emat, vals[:, None, :, None])
                out_qp = dot_sequences(gmat, dot_sequences(mat, aux), 'ATB')

            else:
                aux = dot_sequences(gmat, vals[:, None, :, None])
                out_qp = dot_sequences(emat, dot_sequences(mat, aux), 'ATB')

            fmode = 0

        else:
            if self.mode == 'ge':
                out_qp = dot_sequences(gmat, dot_sequences(mat, emat), 'ATB')

            else:
                out_qp = dot_sequences(emat, dot_sequences(mat, gmat), 'ATB')

            fmode = 1

        return out_qp, geo, fmode
コード例 #12
0
ファイル: terms_elastic.py プロジェクト: rc/sfepy
    def get_fargs(self, mat, kappa, gvar, evar,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        from sfepy.discrete.variables import create_adof_conn, expand_basis

        geo, _ = self.get_mapping(evar)

        n_el, n_qp, dim, n_en, n_c = self.get_data_shape(gvar)

        ebf = expand_basis(geo.bf, dim)

        gmat = _build_wave_strain_op(kappa, ebf)
        emat = _build_cauchy_strain_op(geo.bfg)

        if diff_var is None:
            avar = evar if self.mode == 'ge' else gvar
            econn = avar.field.get_econn('volume', self.region)
            adc = create_adof_conn(nm.arange(avar.n_dof, dtype=nm.int32),
                                   econn, n_c, 0)
            vals = avar()[adc]

            if self.mode == 'ge':
                # Same as aux = self.get(avar, 'cauchy_strain'),
                aux = dot_sequences(emat, vals[:, None, :, None])
                out_qp = dot_sequences(gmat, dot_sequences(mat, aux), 'ATB')

            else:
                aux = dot_sequences(gmat, vals[:, None, :, None])
                out_qp = dot_sequences(emat, dot_sequences(mat, aux), 'ATB')

            fmode = 0

        else:
            if self.mode == 'ge':
                out_qp = dot_sequences(gmat, dot_sequences(mat, emat), 'ATB')

            else:
                out_qp = dot_sequences(emat, dot_sequences(mat, gmat), 'ATB')

            fmode = 1

        return out_qp, geo, fmode
コード例 #13
0
ファイル: terms_contact.py プロジェクト: rc/sfepy
    def get_fargs(self, epss, virtual, state,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        geo, _ = self.get_mapping(virtual)

        ci = self.get_contact_info(geo, state)

        X = nm.asfortranarray(state.field.coors)
        Um = nm.asfortranarray(state().reshape((-1, ci.nsd)))
        xx = nm.asfortranarray(X + Um)

        GPs = ci.update(xx)

        if mode == 'weak':
            Gc = nm.zeros(ci.neq, dtype=nm.float64)

            activeGPs = GPs[:, 2*ci.nsd+3]
            # gap = GPs[:, nsd + 2]
            # print activeGPs
            # print gap
            # print 'active:', activeGPs.sum()

            if diff_var is None:
                max_num = 1
                keyContactDetection = self.detect
                keyAssembleKc = 0

            else:
                max_num = 4 * (ci.nsd * ci.nsn)**2 * ci.ngp * GPs.shape[0]
                keyContactDetection = self.detect
                keyAssembleKc = 1

            # print 'max_num:', max_num
            vals = nm.empty(max_num, dtype=nm.float64)
            rows = nm.empty(max_num, dtype=nm.int32)
            cols = nm.empty(max_num, dtype=nm.int32)

            aux = cc.assemble_contact_residual_and_stiffness(
                Gc, vals, rows, cols, ci.GPs, ci.ISN, ci.IEN, X, Um,
                ci.H, ci.dH, ci.gw, activeGPs, ci.neq, ci.npd,
                epss, keyContactDetection, keyAssembleKc)
            Gc, vals, rows, cols, num = aux
            # print 'true num:', num

            # Uncomment this to detect only in the 1. iteration.
            #self.detect = max(0, self.detect - 1)
            if diff_var is None:
                from sfepy.discrete.variables import create_adof_conn
                rows = nm.unique(create_adof_conn(nm.arange(len(Gc)),
                                                  ci.sd.econn,
                                                  ci.nsd, 0))
                out_cc = (Gc[rows], rows, state)

            else:
                out_cc = (vals[:num], rows[:num], cols[:num], state, state)

            return self.function_weak, out_cc

        elif mode in ('el_avg', 'qp'):
            fmode = {'el_avg' : 1, 'qp' : 2}[mode]

            if term_mode == 'gap':
                gap = GPs[:, ci.nsd + 2].reshape(-1, ci.ngp, 1, 1)
                gap[gap > 0] = 0.0
                return self.integrate, gap, geo, fmode

            else:
                raise ValueError('unsupported term mode in %s! (%s)'
                                 % (self.name, term_mode))

        else:
            raise ValueError('unsupported evaluation mode in %s! (%s)'
                             % (self.name, mode))
コード例 #14
0
ファイル: terms_contact.py プロジェクト: clazaro/sfepy
    def get_fargs(self, epss, virtual, state,
                  mode=None, term_mode=None, diff_var=None, **kwargs):
        geo, _ = self.get_mapping(virtual)

        region = self.region

        if self.ci is None:
            self.ci = ContactInfo()

        # Uses field connectivity (higher order nodes).
        sd = state.field.surface_data[region.name]

        ISN = state.field.efaces.T.copy()
        nsd = region.dim
        ngp = geo.n_qp
        neq = state.n_dof
        nsn = ISN.shape[0]

        fis = region.get_facet_indices()
        elementID = fis[:, 0].copy()
        segmentID = fis[:, 1].copy()

        n = len(elementID)
        IEN = state.field.econn
        # Need surface bf, bfg corresponding to field approximation here, not
        # geo...
        H = nm.asfortranarray(geo.bf[0, :, 0, :])
        ps = state.field.gel.surface_facet.poly_space
        gps, gw = self.integral.get_qp(state.field.gel.surface_facet.name)
        bfg = ps.eval_base(gps, diff=True)
        dH  = nm.asfortranarray(bfg.ravel().reshape(((nsd - 1) * ngp, nsn)))

        X = nm.asfortranarray(state.field.coors)
        Um = nm.asfortranarray(state().reshape((-1, nsd)))
        xx = nm.asfortranarray(X + Um)

        import sfepy.mechanics.extmods.ccontres as cc

        GPs = nm.empty((n*ngp, 2*nsd+6), dtype=nm.float64, order='F')

        longestEdge, GPs = cc.get_longest_edge_and_gps(GPs, neq,
                                                       elementID, segmentID,
                                                       ISN, IEN, H, xx)

        AABBmin, AABBmax = cc.get_AABB(xx, longestEdge, IEN, ISN,
                                       elementID, segmentID, neq);

        AABBmin = AABBmin - (0.5*longestEdge);
        AABBmax = AABBmax + (0.5*longestEdge);
        N = nm.ceil((AABBmax - AABBmin) / (0.5*longestEdge)).astype(nm.int32)
        N = nm.ones(nsd, dtype=nm.int32) # BUG workaround.

        head, next = cc.init_global_search(N, AABBmin, AABBmax, GPs[:,:nsd])

        npd = region.tdim - 1
        GPs = cc.evaluate_contact_constraints(GPs, ISN, IEN, N,
                                              AABBmin, AABBmax,
                                              head, next, xx,
                                              elementID, segmentID,
                                              npd, neq, longestEdge)

        Gc = nm.zeros(neq, dtype=nm.float64)

        activeGPs = GPs[:, 2*nsd+3]
        # gap = GPs[:, nsd + 2]
        # print activeGPs
        # print gap
        # print 'active:', activeGPs.sum()

        if diff_var is None:
            max_num = 1
            keyContactDetection = self.detect
            keyAssembleKc = 0

        else:
            max_num = 4 * (nsd * nsn)**2 * ngp * GPs.shape[0]
            keyContactDetection = self.detect
            keyAssembleKc = 1

        # print 'max_num:', max_num
        vals = nm.empty(max_num, dtype=nm.float64)
        rows = nm.empty(max_num, dtype=nm.int32)
        cols = nm.empty(max_num, dtype=nm.int32)

        aux = cc.assemble_contact_residual_and_stiffness(Gc, vals, rows, cols,
                                                         GPs, ISN, IEN,
                                                         X, Um, H, dH, gw,
                                                         activeGPs, neq, npd,
                                                         epss,
                                                         keyContactDetection,
                                                         keyAssembleKc)
        Gc, vals, rows, cols, num = aux
        # print 'true num:', num

        # Uncomment this to detect only in the 1. iteration.
        #self.detect = max(0, self.detect - 1)
        if diff_var is None:
            from sfepy.discrete.variables import create_adof_conn
            rows = nm.unique(create_adof_conn(nm.arange(len(Gc)), sd.econn,
                                              nsd, 0))
            out_cc = (Gc[rows], rows, state)

        else:
            out_cc = (vals[:num], rows[:num], cols[:num], state, state)

        return out_cc,
コード例 #15
0
ファイル: terms_contact.py プロジェクト: rocksonchan/sfepy
    def get_fargs(self,
                  epss,
                  virtual,
                  state,
                  mode=None,
                  term_mode=None,
                  diff_var=None,
                  **kwargs):
        geo, _ = self.get_mapping(virtual)

        region = self.region

        if self.ci is None:
            self.ci = ContactInfo()

        # Uses field connectivity (higher order nodes).
        sd = state.field.surface_data[region.name]

        ISN = state.field.efaces.T.copy()
        nsd = region.dim
        ngp = geo.n_qp
        neq = state.n_dof
        nsn = ISN.shape[0]

        fis = region.get_facet_indices()
        elementID = fis[:, 0].copy()
        segmentID = fis[:, 1].copy()

        n = len(elementID)
        IEN = state.field.econn
        # Need surface bf, bfg corresponding to field approximation here, not
        # geo...
        H = nm.asfortranarray(geo.bf[0, :, 0, :])
        ps = state.field.gel.surface_facet.poly_space
        gps, gw = self.integral.get_qp(state.field.gel.surface_facet.name)
        bfg = ps.eval_base(gps, diff=True)
        dH = nm.asfortranarray(bfg.ravel().reshape(((nsd - 1) * ngp, nsn)))

        X = nm.asfortranarray(state.field.coors)
        Um = nm.asfortranarray(state().reshape((-1, nsd)))
        xx = nm.asfortranarray(X + Um)

        import sfepy.mechanics.extmods.ccontres as cc

        GPs = nm.empty((n * ngp, 2 * nsd + 6), dtype=nm.float64, order='F')

        longestEdge, GPs = cc.get_longest_edge_and_gps(GPs, neq, elementID,
                                                       segmentID, ISN, IEN, H,
                                                       xx)

        AABBmin, AABBmax = cc.get_AABB(xx, longestEdge, IEN, ISN, elementID,
                                       segmentID, neq)

        AABBmin = AABBmin - (0.5 * longestEdge)
        AABBmax = AABBmax + (0.5 * longestEdge)
        N = nm.ceil((AABBmax - AABBmin) / (0.5 * longestEdge)).astype(nm.int32)

        head, next = cc.init_global_search(N, AABBmin, AABBmax, GPs[:, :nsd])

        npd = region.tdim - 1
        GPs = cc.evaluate_contact_constraints(GPs, ISN, IEN, N, AABBmin,
                                              AABBmax, head, next, xx,
                                              elementID, segmentID, npd, neq,
                                              longestEdge)

        Gc = nm.zeros(neq, dtype=nm.float64)

        activeGPs = GPs[:, 2 * nsd + 3]
        # gap = GPs[:, nsd + 2]
        # print activeGPs
        # print gap
        # print 'active:', activeGPs.sum()

        if diff_var is None:
            max_num = 1
            keyContactDetection = self.detect
            keyAssembleKc = 0

        else:
            max_num = 4 * (nsd * nsn)**2 * ngp * GPs.shape[0]
            keyContactDetection = self.detect
            keyAssembleKc = 1

        # print 'max_num:', max_num
        vals = nm.empty(max_num, dtype=nm.float64)
        rows = nm.empty(max_num, dtype=nm.int32)
        cols = nm.empty(max_num, dtype=nm.int32)

        aux = cc.assemble_contact_residual_and_stiffness(
            Gc, vals, rows, cols, GPs, ISN, IEN, X, Um, H, dH, gw, activeGPs,
            neq, npd, epss, keyContactDetection, keyAssembleKc)
        Gc, vals, rows, cols, num = aux
        # print 'true num:', num

        # Uncomment this to detect only in the 1. iteration.
        #self.detect = max(0, self.detect - 1)
        if diff_var is None:
            from sfepy.discrete.variables import create_adof_conn
            rows = nm.unique(
                create_adof_conn(nm.arange(len(Gc)), sd.econn, nsd, 0))
            out_cc = (Gc[rows], rows, state)

        else:
            out_cc = (vals[:num], rows[:num], cols[:num], state, state)

        return out_cc,
コード例 #16
0
    def get_fargs(self,
                  epss,
                  virtual,
                  state,
                  mode=None,
                  term_mode=None,
                  diff_var=None,
                  **kwargs):
        geo, _ = self.get_mapping(virtual)

        ci = self.get_contact_info(geo, state)

        X = nm.asfortranarray(state.field.coors)
        Um = nm.asfortranarray(state().reshape((-1, ci.nsd)))
        xx = nm.asfortranarray(X + Um)

        GPs = ci.update(xx)

        if mode == 'weak':
            Gc = nm.zeros(ci.neq, dtype=nm.float64)

            activeGPs = GPs[:, 2 * ci.nsd + 3]
            # gap = GPs[:, nsd + 2]
            # print activeGPs
            # print gap
            # print 'active:', activeGPs.sum()

            if diff_var is None:
                max_num = 1
                keyContactDetection = self.detect
                keyAssembleKc = 0

            else:
                max_num = 4 * (ci.nsd * ci.nsn)**2 * ci.ngp * GPs.shape[0]
                keyContactDetection = self.detect
                keyAssembleKc = 1

            # print 'max_num:', max_num
            vals = nm.empty(max_num, dtype=nm.float64)
            rows = nm.empty(max_num, dtype=nm.int32)
            cols = nm.empty(max_num, dtype=nm.int32)

            aux = cc.assemble_contact_residual_and_stiffness(
                Gc, vals, rows, cols, ci.GPs, ci.ISN, ci.IEN, X, Um, ci.H,
                ci.dH, ci.gw, activeGPs, ci.neq, ci.npd, epss,
                keyContactDetection, keyAssembleKc)
            Gc, vals, rows, cols, num = aux
            # print 'true num:', num

            # Uncomment this to detect only in the 1. iteration.
            #self.detect = max(0, self.detect - 1)
            if diff_var is None:
                from sfepy.discrete.variables import create_adof_conn
                rows = nm.unique(
                    create_adof_conn(nm.arange(len(Gc)), ci.sd.econn, ci.nsd,
                                     0))
                out_cc = (Gc[rows], rows, state)

            else:
                out_cc = (vals[:num], rows[:num], cols[:num], state, state)

            return self.function_weak, out_cc

        elif mode in ('el_avg', 'qp'):
            fmode = {'el_avg': 1, 'qp': 2}[mode]

            if term_mode == 'gap':
                gap = GPs[:, ci.nsd + 2].reshape(-1, ci.ngp, 1, 1)
                gap[gap > 0] = 0.0
                return self.integrate, gap, geo, fmode

            else:
                raise ValueError('unsupported term mode in %s! (%s)' %
                                 (self.name, term_mode))

        else:
            raise ValueError('unsupported evaluation mode in %s! (%s)' %
                             (self.name, mode))