Exemplo n.º 1
0
    def __init__(self, name, shape, cref=None, sref=None, group=None):
        super(Part, self).__init__(name)

        # Shape holder
        type_ = (Shape,)
        if isinstance(self, CurvePart):
            type_ = (Edge, Wire, Compound)
        elif isinstance(self, SurfacePart):
            type_ = (Face, Shell, Compound)
        ShapeHolder.__init__(self, type_, shape)

        # Random color
        self.random_color()

        # Unique ID
        self._id = Part._indx
        Part._indx += 1

        # Geometry data
        self._cref, self._sref = None, None
        if cref is not None:
            self.set_cref(cref)
        if sref is not None:
            self.set_sref(sref)

        # Other data
        self._subparts = {}

        # Add to group
        GroupAPI.add_parts(group, self)

        # Log
        msg = ' '.join(['Creating part:', name])
        logger.info(msg)
Exemplo n.º 2
0
    def fix(self,
            precision=None,
            min_tol=None,
            max_tol=None,
            context=None,
            include_subgroup=True):
        """
        Attempt to fix the shape of the part using :class:`.FixShape`.

        :param float precision: Basic precision value.
        :param float min_tol: Minimum tolerance.
        :param float max_tol: Maximum tolerance.
        :param context: The context shape or group.
        :type context: afem.topology.entities.Shape or
            afem.structure.entities.Group or str
        :param bool include_subgroup: Option to recursively include parts
            from any subgroups.

        :return: None.
        """
        if context is not None:
            if not isinstance(context, Shape):
                context = GroupAPI.get_shape(context, include_subgroup)

        new_shape = FixShape(self._shape, precision, min_tol, max_tol,
                             context).shape
        self.set_shape(new_shape)
Exemplo n.º 3
0
    def __init__(self, group=None, precision=None, min_tol=None, max_tol=None):
        group = GroupAPI.get_group(group)
        if not isinstance(group, Group):
            raise TypeError('Could not find group.')

        parts = group.get_parts()
        compound = group.get_shape()

        fix = FixShape(compound, precision, min_tol, max_tol)

        for part in parts:
            new_shape = fix.apply(part.shape)
            part.set_shape(new_shape)
Exemplo n.º 4
0
    def __init__(self, name, shape, cref=None, sref=None, group=None):
        types = (Shape, )
        if isinstance(self, CurvePart):
            types = (Edge, Wire, Compound)
        elif isinstance(self, SurfacePart):
            types = (Face, Shell, Compound)
        super(Part, self).__init__(name, shape, cref, sref, types)

        # Unique ID
        self._id = Part._indx
        Part._indx += 1

        # Add to group
        GroupAPI.add_parts(group, self)

        # Log
        msg = ' '.join(['Creating part:', name])
        logger.info(msg)

        # Groups for meshing
        self._node_group = None
        self._edge_group = None
        self._face_group = None
Exemplo n.º 5
0
    def __init__(self, target_size=1., allow_quads=True):
        group = GroupAPI.get_master()
        self._shape = group.get_shape()
        self._gen = MeshGen()
        self._mesh = self._gen.create_mesh(self._shape)

        # Initialize each part for meshing
        for part in group.get_parts():
            part.init_meshing(self._mesh)

        # Define global mesh control based on target size
        hyp1d = LocalLength1D(self._gen, target_size)
        alg1d = Regular1D(self._gen)
        hyp2d = NetgenSimple2D(self._gen, target_size, allow_quads=allow_quads)
        alg2d = NetgenAlgo2D(self._gen)
        self.add_controls([hyp1d, alg1d, hyp2d, alg2d])
Exemplo n.º 6
0
    def set_tolerance(group=None, tol=1.0e7):
        """
        Enforce tolerance on the given group.

        :param group: The group. If ``None`` then the active group is
            used.
        :type group: str or afem.structure.group.Group or None
        :param float tol: The tolerance.

        :return: None.

        :raise TypeError: If an :class:`.Group` instance is not found.
        """
        group = GroupAPI.get_group(group)
        if not isinstance(group, Group):
            raise TypeError('Could not find group.')

        shape = group.get_shape()
        return FixShape.set_tolerance(shape, tol)
Exemplo n.º 7
0
    def limit_tolerance(group=None, tol=1.0e-7):
        """
        Limit tolerances for the group shapes.

        :param group: The group. If ``None`` then the active group is
            used.
        :type group: str or afem.structure.group.Group or None
        :param float tol: Target tolerance.

        :return: *True* if at least one tolerance of a sub-shape was modified.
        :rtype: bool

        :raise TypeError: If an :class:`.Group` instance is not found.
        """
        group = GroupAPI.get_group(group)
        if not isinstance(group, Group):
            raise TypeError('Could not find group.')

        shape = group.get_shape()
        return FixShape.limit_tolerance(shape, tol)