Exemple #1
0
    def test_entity_volumes(self):
        import sfepy
        from sfepy.discrete.fem import Mesh, FEDomain
        from sfepy.discrete.common import Field
        from sfepy.discrete import Integral

        mesh = Mesh.from_file('meshes/3d/special/cross3d.mesh',
                              prefix_dir=sfepy.data_dir)
        domain = FEDomain('domain', mesh)

        omega = domain.create_region('Omega', 'all')
        gamma = domain.create_region('Gamma', 'vertices of surface', 'facet')
        top = domain.create_region('Top', 'cell 2')

        vfield = Field.from_args('v', nm.float64, 'scalar', omega,
                                 approx_order=1)
        sfield = Field.from_args('s', nm.float64, 'scalar', gamma,
                                 approx_order=1)

        integral = Integral('i', order=3)
        vgeo, _ = vfield.get_mapping(omega, integral, 'volume')
        domain.create_surface_group(gamma)
        sgeo, _ = sfield.get_mapping(gamma, integral, 'surface')

        evols = mesh.cmesh.get_volumes(1)
        fvols = mesh.cmesh.get_volumes(2) # Approximate for non-planar faces.
        cvols = mesh.cmesh.get_volumes(3)

        ok = True
        _ok = abs(cvols.sum() - vgeo.volume.sum()) < 1e-15
        self.report('total cell volume: %s (ok: %s)' % (cvols.sum(), _ok))
        ok = _ok and ok

        top_evols = nm.array([ 1.                ,  1.                ,
                               1.                ,  1.                ,
                               0.7211102550927979,  0.7211102550927979,
                               0.7211102550927979,  0.7211102550927979,
                               1.16619037896906  ,  1.16619037896906  ,
                               1.16619037896906  ,  1.16619037896906  ])

        _ok = nm.allclose(top_evols, evols[top.edges], rtol=0.0, atol=1e-15)
        self.report('total top cell edge length: %s (ok: %s)'
                    % (evols[top.edges].sum(), _ok))
        ok = _ok and ok

        i1 = [5, 6, 8, 9]
        i2 = nm.setdiff1d(nm.arange(len(gamma.faces)), i1)
        aux = fvols[gamma.faces] - sgeo.volume.ravel()

        _ok = nm.allclose(aux[i1], 0.10560208437556773, rtol=0.0, atol=1e-15)
        ok = _ok and ok
        self.report('non-planar faces diff: %s (ok: %s)' % (aux[i1], _ok))

        _ok = (nm.abs(aux[i2]) < 1e-15).all()
        self.report('max. planar faces diff: %s (ok: %s)'
                    % (nm.abs(aux[i2]).max(), _ok))
        ok = _ok and ok

        return ok
Exemple #2
0
    def test_ref_coors_iga(self):
        from sfepy.discrete.iga.domain import IGDomain

        domain = IGDomain.from_file(
            op.join(sfepy.data_dir, 'meshes/iga/block2d.iga'))

        omega = domain.create_region('Omega', 'all')

        field = Field.from_args('iga',
                                nm.float64,
                                'scalar',
                                omega,
                                approx_order='iga',
                                poly_space_base='iga')

        mcoors = field.nurbs.cps
        conn = field.get_econn('volume', field.region)

        bbox = domain.eval_mesh.get_bounding_box()
        ray = nm.linspace(bbox[0, 0], bbox[1, 0], 11)
        coors = nm.c_[ray, ray]

        ref_coors, cells, status = gi.get_ref_coors(field,
                                                    coors,
                                                    strategy='general',
                                                    close_limit=0.0,
                                                    verbose=False)
        self.report(ref_coors)
        self.report(cells)
        self.report(status)

        ok = nm.all(status == 0)

        ctx = field.create_basis_context()

        for ic, cell in enumerate(cells):
            ctx.iel = cell
            bf = ctx.evaluate(ref_coors[ic:ic + 1])

            cell_coors = mcoors[conn[cell]]
            coor = nm.dot(bf, cell_coors).ravel()

            _ok = nm.allclose(coor, coors[ic], atol=1e-14, rtol=0.0)
            if not _ok:
                self.report('point %d:' % ic)
                self.report(' - wrong reference coordinates %s!' %
                            ref_coors[ic])
                self.report(' - given point: %s' % coors[ic])
                self.report(' - found point: %s' % coor)
            ok = ok and _ok

        return ok
Exemple #3
0
    def test_ref_coors_iga(self):
        from sfepy.discrete.iga.domain import IGDomain

        domain = IGDomain.from_file(op.join(sfepy.data_dir,
                                            'meshes/iga/block2d.iga'))

        omega = domain.create_region('Omega', 'all')

        field = Field.from_args('iga', nm.float64, 'scalar', omega,
                                approx_order='iga', poly_space_base='iga')

        mcoors = field.nurbs.cps
        conn = field.get_econn('volume', field.region)

        bbox = domain.eval_mesh.get_bounding_box()
        ray = nm.linspace(bbox[0, 0], bbox[1, 0], 11)
        coors = nm.c_[ray, ray]

        ref_coors, cells, status = gi.get_ref_coors(field, coors,
                                                    strategy='general',
                                                    close_limit=0.0,
                                                    verbose=False)
        self.report(ref_coors)
        self.report(cells)
        self.report(status)

        ok = nm.all(status == 0)

        ctx = field.create_basis_context()

        for ic, cell in enumerate(cells):
            ctx.iel = cell
            bf = ctx.evaluate(ref_coors[ic:ic+1])

            cell_coors = mcoors[conn[cell]]
            coor = nm.dot(bf, cell_coors).ravel()

            _ok = nm.allclose(coor, coors[ic], atol=1e-14, rtol=0.0)
            if not _ok:
                self.report('point %d:' % ic)
                self.report(' - wrong reference coordinates %s!'
                            % ref_coors[ic])
                self.report(' - given point: %s' % coors[ic])
                self.report(' - found point: %s' % coor)
            ok = ok and _ok

        return ok
    def test_entity_volumes(self):
        import sfepy
        from sfepy.discrete.fem import Mesh, FEDomain
        from sfepy.discrete.common import Field
        from sfepy.discrete import Integral

        mesh = Mesh.from_file('meshes/3d/special/cross3d.mesh',
                              prefix_dir=sfepy.data_dir)
        domain = FEDomain('domain', mesh)

        omega = domain.create_region('Omega', 'all')
        gamma = domain.create_region('Gamma', 'vertices of surface', 'facet')
        top = domain.create_region('Top', 'cell 2')

        vfield = Field.from_args('v',
                                 nm.float64,
                                 'scalar',
                                 omega,
                                 approx_order=1)
        sfield = Field.from_args('s',
                                 nm.float64,
                                 'scalar',
                                 gamma,
                                 approx_order=1)

        integral = Integral('i', order=3)
        vgeo, _ = vfield.get_mapping(omega, integral, 'volume')
        domain.create_surface_group(gamma)
        sgeo, _ = sfield.get_mapping(gamma, integral, 'surface')

        evols = mesh.cmesh.get_volumes(1)
        fvols = mesh.cmesh.get_volumes(2)  # Approximate for non-planar faces.
        cvols = mesh.cmesh.get_volumes(3)

        ok = True
        _ok = abs(cvols.sum() - vgeo.volume.sum()) < 1e-15
        self.report('total cell volume: %s (ok: %s)' % (cvols.sum(), _ok))
        ok = _ok and ok

        top_evols = nm.array([
            1., 1., 1., 1., 0.7211102550927979, 0.7211102550927979,
            0.7211102550927979, 0.7211102550927979, 1.16619037896906,
            1.16619037896906, 1.16619037896906, 1.16619037896906
        ])

        _ok = nm.allclose(top_evols, evols[top.edges], rtol=0.0, atol=1e-15)
        self.report('total top cell edge length: %s (ok: %s)' %
                    (evols[top.edges].sum(), _ok))
        ok = _ok and ok

        i1 = [5, 6, 8, 9]
        i2 = nm.setdiff1d(nm.arange(len(gamma.faces)), i1)
        aux = fvols[gamma.faces] - sgeo.volume.ravel()

        _ok = nm.allclose(aux[i1], 0.10560208437556773, rtol=0.0, atol=1e-15)
        ok = _ok and ok
        self.report('non-planar faces diff: %s (ok: %s)' % (aux[i1], _ok))

        _ok = (nm.abs(aux[i2]) < 1e-15).all()
        self.report('max. planar faces diff: %s (ok: %s)' %
                    (nm.abs(aux[i2]).max(), _ok))
        ok = _ok and ok

        return ok
Exemple #5
0
    def test_ref_coors_fem(self):
        from sfepy.discrete.fem import Mesh, FEDomain

        mesh = Mesh.from_file('meshes/3d/special/cross3d.mesh',
                              prefix_dir=sfepy.data_dir)
        domain = FEDomain('domain', mesh)

        omega = domain.create_region('Omega', 'all')

        field = Field.from_args('linear', nm.float64, 'scalar', omega,
                                approx_order=1)


        mcoors = field.domain.get_mesh_coors()
        conn = field.domain.get_conn()

        bbox = field.domain.get_mesh_bounding_box()
        ray = nm.linspace(bbox[0, 0], bbox[1, 0], 7)
        coors = nm.zeros((ray.shape[0], 3), dtype=nm.float64)

        def gen_rays():
            coors[:, 0] = ray
            yield coors

            coors.fill(0.0)
            coors[:, 1] = ray
            yield coors

            coors.fill(0.0)
            coors[:, 2] = ray
            yield coors

        ok = True

        ctx = field.create_basis_context()._geo_ctx

        for ir, coors in enumerate(gen_rays()):
            self.report('ray %d' % ir)
            ref_coors, cells, status = gi.get_ref_coors(field, coors,
                                                        strategy='general',
                                                        close_limit=0.0,
                                                        verbose=False)
            self.report(ref_coors)
            self.report(cells)
            self.report(status)

            # In the distorted cell 2, the Newton method finds a solution
            # outside of the cell. This will be fixed when box constraints
            # are applied.
            _ok = nm.all((status == 0) | ((cells == 2) & (status == 3)))
            if not _ok:
                self.report('wrong status %s for ray %d!' % (status, ir))

            ok = ok and _ok

            for ic, cell in enumerate(cells):
                ctx.iel = cell
                bf = ctx.evaluate(ref_coors[ic:ic+1], check_errors=False)

                cell_coors = mcoors[conn[cell]]
                coor = nm.dot(bf, cell_coors).ravel()

                _ok = nm.allclose(coor, coors[ic], atol=1e-14, rtol=0.0)
                if not _ok:
                    self.report('ray %d point %d:' % (ir, ic))
                    self.report(' - wrong reference coordinates %s!'
                                % ref_coors[ic])
                    self.report(' - given point: %s' % coors[ic])
                    self.report(' - found point: %s' % coor)
                ok = ok and _ok

        return ok
Exemple #6
0
    def test_ref_coors_fem(self):
        from sfepy.discrete.fem import Mesh, FEDomain

        mesh = Mesh.from_file('meshes/3d/special/cross3d.mesh',
                              prefix_dir=sfepy.data_dir)
        domain = FEDomain('domain', mesh)

        omega = domain.create_region('Omega', 'all')

        field = Field.from_args('linear',
                                nm.float64,
                                'scalar',
                                omega,
                                approx_order=1)

        mcoors = field.domain.get_mesh_coors()
        conn = field.domain.get_conn()

        bbox = field.domain.get_mesh_bounding_box()
        ray = nm.linspace(bbox[0, 0], bbox[1, 0], 7)
        coors = nm.zeros((ray.shape[0], 3), dtype=nm.float64)

        def gen_rays():
            coors[:, 0] = ray
            yield coors

            coors.fill(0.0)
            coors[:, 1] = ray
            yield coors

            coors.fill(0.0)
            coors[:, 2] = ray
            yield coors

        ok = True

        ctx = field.create_basis_context()._geo_ctx

        for ir, coors in enumerate(gen_rays()):
            self.report('ray %d' % ir)
            ref_coors, cells, status = gi.get_ref_coors(field,
                                                        coors,
                                                        strategy='general',
                                                        close_limit=0.0,
                                                        verbose=False)
            self.report(ref_coors)
            self.report(cells)
            self.report(status)

            # In the distorted cell 2, the Newton method finds a solution
            # outside of the cell. This will be fixed when box constraints
            # are applied.
            _ok = nm.all((status == 0) | ((cells == 2) & (status == 3)))
            if not _ok:
                self.report('wrong status %s for ray %d!' % (status, ir))

            ok = ok and _ok

            for ic, cell in enumerate(cells):
                ctx.iel = cell
                bf = ctx.evaluate(ref_coors[ic:ic + 1], check_errors=False)

                cell_coors = mcoors[conn[cell]]
                coor = nm.dot(bf, cell_coors).ravel()

                _ok = nm.allclose(coor, coors[ic], atol=1e-14, rtol=0.0)
                if not _ok:
                    self.report('ray %d point %d:' % (ir, ic))
                    self.report(' - wrong reference coordinates %s!' %
                                ref_coors[ic])
                    self.report(' - given point: %s' % coors[ic])
                    self.report(' - found point: %s' % coor)
                ok = ok and _ok

        return ok