Ejemplo n.º 1
0
    def test_integration_points_curve_2d():
        model = an.Model()

        model.add_array(r"""[
            {
                "key": "TestData",
                "type": "NurbsCurveGeometry2D",
                "degree": 1,
                "nb_poles": 2,
                "knots": [-1, 0, 1],
                "poles": [[-1, 0], [0, 0], [2, 0]]
            }
        ]""")

        curve = model.get(0).data

        integration_points = an.integration_points(
            degree=2,
            curve=curve,
        )

        assert_array_almost_equal(
            integration_points,
            [(-0.788675, 0.5), (-0.211325, 0.5), (0.211325, 1.0),
             (0.788675, 1.0)],
        )
Ejemplo n.º 2
0
    def test_integration_points_surface_3d():
        model = an.Model()

        model.add_array(r"""[
            {
                "type": "NurbsSurfaceGeometry3D",
                "degree_u": 2,
                "degree_v": 1,
                "knots_u": [0.0,0.0,5.0,10.0,10.0],
                "knots_v": [0.0,20.0],
                "nb_poles_u": 4,
                "nb_poles_v": 2,
                "poles": [[0.0,0.0,0.0],[0.0,10.0,0.0],[2.00900107273569,0.0,0.0],[4.0763840660860486,7.8742350860349752,0.0],[7.0668900221629363,0.0,0.0],[12.011764418152659,7.1771412301834934,0.0],[10.0,0.0,0.0],[15.0,10.0,0.0]]
            }
        ]""")

        surface = model.get(0).data

        integration_points = an.integration_points(
            degree=2,
            surface=surface,
        )

        assert_array_almost_equal(
            integration_points,
            [(1.0566243270259357, 4.226497308103743, 11.759664385301264),
             (1.0566243270259357, 15.773502691896258, 17.31405070545194),
             (3.9433756729740645, 4.226497308103743, 10.883683768349144),
             (3.9433756729740645, 15.773502691896258, 15.000698744981156),
             (6.0566243270259355, 4.226497308103743, 10.603123001336892),
             (6.0566243270259355, 15.773502691896258, 12.7153914474524),
             (8.943375672974064, 4.226497308103743, 11.952054522910226),
             (8.943375672974064, 15.773502691896258, 9.795549688797168)],
        )
Ejemplo n.º 3
0
    def test_integration_points_minus_1_to_1():
        integration_points = an.integration_points(
            degree=2,
            domain=an.Interval(-1, 1),
        )

        assert_array_almost_equal(
            integration_points,
            [(-0.5773502691896257, 1), (0.5773502691896257, 1)],
        )
Ejemplo n.º 4
0
    def test_integration_points_0_to_1():
        integration_points = an.integration_points(
            degree=2,
            domain=an.Interval(0, 1),
        )

        assert_array_almost_equal(
            integration_points,
            [(0.21132486540518713, 0.5), (0.7886751345948129, 0.5)],
        )
Ejemplo n.º 5
0
    def test_integration_points_minus_1_to_1_x_minus_1_to_1():
        integration_points = an.integration_points(
            degree_u=2,
            degree_v=3,
            domain_u=an.Interval(-1, 1),
            domain_v=an.Interval(-1, 1),
        )

        assert_array_almost_equal(
            integration_points,
            [(-0.5773502691896257, -0.7745966692414834, 0.5555555555555557),
             (-0.5773502691896257, 0.0000000000000000, 0.8888888888888888),
             (-0.5773502691896257, 0.7745966692414834, 0.5555555555555557),
             (0.5773502691896257, -0.7745966692414834, 0.5555555555555557),
             (0.5773502691896257, 0.0000000000000000, 0.8888888888888888),
             (0.5773502691896257, 0.7745966692414834, 0.5555555555555557)],
        )
Ejemplo n.º 6
0
    def test_integration_points_0_to_1_x_0_to_1():
        integration_points = an.integration_points(
            degree_u=2,
            degree_v=3,
            domain_u=an.Interval(0, 1),
            domain_v=an.Interval(0, 1),
        )

        assert_array_almost_equal(
            integration_points,
            [(0.21132486540518713, 0.1127016653792583, 0.13888888888888892),
             (0.21132486540518713, 0.5000000000000000, 0.22222222222222220),
             (0.21132486540518713, 0.8872983346207417, 0.13888888888888892),
             (0.78867513459481290, 0.1127016653792583, 0.13888888888888892),
             (0.78867513459481290, 0.5000000000000000, 0.22222222222222220),
             (0.78867513459481290, 0.8872983346207417, 0.13888888888888892)],
        )
Ejemplo n.º 7
0
    def run(self, config, job, data, log):
        cad_model = data.get('cad_model', None)
        model_tolerance = job.model_tolerance

        nb_objectives = 0

        # FIXME: Check for None

        data['nodes'] = data.get('nodes', {})
        elements = []

        for key, face in cad_model.of_type('BrepFace'):
            surface_geometry_key = surface_geometry = face.surface_geometry.data

            if surface_geometry_key not in data['nodes']:
                nodes = []

                for x, y, z in surface_geometry.poles:
                    nodes.append(eq.Node(x, y, z))
                nodes = np.array(nodes, object)
                data['nodes'][surface_geometry_key] = nodes
            else:
                nodes = data['nodes'][surface_geometry_key]

            for u, v, weight in an.integration_points(face, model_tolerance):
                nonzero_indices, shape_functions = surface_geometry.shape_functions_at(u, v, 2)

                element = REDUCED_SHELL_3P(nodes[nonzero_indices], self.membrane_stiffness, self.bending_stiffness)
                element.add(shape_functions, weight)

                elements.append(element)

                nb_objectives += 1

        data['elements'] = data.get('elements', [])
        data['elements'].append(('ReducedIgaShell', elements, self.weight))

        # output

        log.info(f'{len(elements)} elements with {nb_objectives} new objectives')
Ejemplo n.º 8
0
    def run(self, config, job, data, log):
        model_tolerance = job.model_tolerance
        cad_model = data.get('cad_model', None)

        if isinstance(self.weight, float):
            weight_displacement = self.weight
            weight_rotation = self.weight
        else:
            weight_displacement = self.weight.get('displacement', 0)
            weight_rotation = self.weight.get('rotation', 0)

        # FIXME: Check for None

        nb_objectives = 0

        data['nodes'] = nodes = data.get('nodes', {})
        point_distance_group = []
        normal_distance_group = []

        for key, edge in cad_model.of_type('BrepEdge'):
            if edge.nb_trims != 2:
                continue

            (_, trim_a), (_, trim_b) = edge.trims

            nurbs_surface_key_a, nurbs_surface_a = trim_a.surface_geometry
            nurbs_surface_key_b, nurbs_surface_b = trim_b.surface_geometry

            if nurbs_surface_a not in nodes:
                nurbs_surface_nodes = []

                for x, y, z in nurbs_surface_a.poles:
                    nurbs_surface_nodes.append(eq.Node(x, y, z))

                nurbs_surface_nodes_a = np.array(nurbs_surface_nodes, object)

                nodes[nurbs_surface_a] = nurbs_surface_nodes_a
            else:
                nurbs_surface_nodes_a = nodes[nurbs_surface_a]

            if nurbs_surface_b not in nodes:
                nurbs_surface_nodes = []

                for x, y, z in nurbs_surface_b.poles:
                    nurbs_surface_nodes.append(eq.Node(x, y, z))

                nurbs_surface_nodes_b = np.array(nurbs_surface_nodes, object)

                nodes[nurbs_surface_b] = nurbs_surface_nodes_b
            else:
                nurbs_surface_nodes_b = nodes[nurbs_surface_b]

            integration_points_a, integration_points_b = an.integration_points(edge, tolerance=self.projection_tolerance, tessellation_tolerance=model_tolerance)

            for (t_a, weight), (t_b, _) in zip(integration_points_a, integration_points_b):
                u_a, v_a = trim_a.curve_geometry.data.point_at(t_a)
                u_b, v_b = trim_b.curve_geometry.data.point_at(t_b)

                indices_a, shape_functions_a = nurbs_surface_a.shape_functions_at(u_a, v_a, 1)
                indices_b, shape_functions_b = nurbs_surface_b.shape_functions_at(u_b, v_b, 1)

                element_nodes_a = [nurbs_surface_nodes_a[i] for i in indices_a]
                element_nodes_b = [nurbs_surface_nodes_b[i] for i in indices_b]

                if weight_displacement != 0:
                    element = POINT_DISTANCE(element_nodes_a, element_nodes_b)
                    element.add(shape_functions_a, shape_functions_b, weight * weight_displacement)
                    point_distance_group.append(element)

                    nb_objectives += 1

                if weight_rotation != 0:
                    _, axis = trim_a.curve_3d.derivatives_at(t_a, order=1)

                    element = NORMAL_DISTANCE(element_nodes_a, element_nodes_b)
                    element.add(shape_functions_a, shape_functions_b, axis, weight=weight * weight_rotation)
                    normal_distance_group.append(element)

                    nb_objectives += 1

                if self.debug:
                    point_a = nurbs_surface_a.point_at(u_a, v_a)
                    point_b = nurbs_surface_b.point_at(u_b, v_b)
                    cad_model.add(an.Point3D(point_a), r'{"layer": "Debug/ApplyEdgeCoupling/PointsA"}')
                    cad_model.add(an.Point3D(point_b), r'{"layer": "Debug/ApplyEdgeCoupling/PointsB"}')

                    if weight_rotation != 0:
                        cad_model.add(an.Line3D(point_a, point_a + axis), r'{"layer": "Debug/ApplyEdgeCoupling/RotationAxis"}')

        data['elements'] = data.get('elements', [])

        if weight_displacement != 0:
            data['elements'].append(('DisplacementCoupling', point_distance_group, weight_displacement))

        if weight_rotation != 0:
            data['elements'].append(('IgaRotationCouplingAD', normal_distance_group, weight_rotation))

        # output

        log.info(f'{len(point_distance_group) + len(normal_distance_group)} with {nb_objectives} new objectives')
    def run(self, config, job, data, log):
        model_tolerance = job.model_tolerance
        cad_model = data.get('cad_model', None)

        # FIXME: Check for None

        nb_objectives = 0

        data['nodes'] = nodes = data.get('nodes', {})
        group = []

        for key, face in cad_model.of_type('BrepFace'):
            _, surface_geometry = face.surface_geometry

            if surface_geometry not in nodes:
                surface_nodes = []

                for x, y, z in surface_geometry.poles:
                    surface_nodes.append(eq.Node(x, y, z))

                surface_nodes = np.array(surface_nodes, object)

                nodes[surface_geometry] = surface_nodes
            else:
                surface_nodes = nodes[surface_geometry]

            for u, span_u_a, span_u_b in _get_multiple_knots(
                    surface_geometry.degree_u, surface_geometry.knots_u):
                for (span_v, v0,
                     v1) in _nonzero_spans(surface_geometry.degree_v,
                                           surface_geometry.knots_v):
                    for v, weight in an.integration_points(
                            surface_geometry.degree_v + 1, an.Interval(v0,
                                                                       v1)):
                        nonzero_indices_a, shape_functions_a = surface_geometry.shape_functions_at_span(
                            u=u, v=v, span_u=span_u_a, span_v=span_v, order=1)
                        nonzero_indices_b, shape_functions_b = surface_geometry.shape_functions_at_span(
                            u=u, v=v, span_u=span_u_b, span_v=span_v, order=1)

                        element_nodes_a = surface_nodes[nonzero_indices_a]
                        element_nodes_b = surface_nodes[nonzero_indices_b]

                        element = POINT_DISTANCE(element_nodes_a,
                                                 element_nodes_b)

                        element.add([shape_functions_a[1]],
                                    [shape_functions_b[1]],
                                    weight * self.weight)

                        group.append(element)

                        nb_objectives += 1

                        if self.debug:
                            point = surface_geometry.point_at(u, v)
                            cad_model.add(
                                an.Point3D(point),
                                r'{"layer": "Debug/ApplyMultipleKnotCoupling/PointsU"}'
                            )

            for v, span_v_a, span_v_b in _get_multiple_knots(
                    surface_geometry.degree_v, surface_geometry.knots_v):
                for (span_u, u0,
                     u1) in _nonzero_spans(surface_geometry.degree_u,
                                           surface_geometry.knots_u):
                    for u, weight in an.integration_points(
                            surface_geometry.degree_u + 1, an.Interval(u0,
                                                                       u1)):
                        nonzero_indices_a, shape_functions_a = surface_geometry.shape_functions_at_span(
                            u=u, v=v, span_u=span_u, span_v=span_v_a, order=1)
                        nonzero_indices_b, shape_functions_b = surface_geometry.shape_functions_at_span(
                            u=u, v=v, span_u=span_u, span_v=span_v_b, order=1)

                        element_nodes_a = surface_nodes[nonzero_indices_a]
                        element_nodes_b = surface_nodes[nonzero_indices_b]

                        element = POINT_DISTANCE(element_nodes_a,
                                                 element_nodes_b)

                        element.add([shape_functions_a[2]],
                                    [shape_functions_b[2]],
                                    weight * self.weight)

                        group.append(element)

                        nb_objectives += 1

                        if self.debug:
                            point = surface_geometry.point_at(u, v)
                            cad_model.add(
                                an.Point3D(point),
                                r'{"layer": "Debug/ApplyMultipleKnotCoupling/PointsV"}'
                            )

        data['elements'] = data.get('elements', [])

        data['elements'].append(('DisplacementCoupling', group, self.weight))

        # output

        log.info(f'{len(group)} elements with {nb_objectives} new objectives')
Ejemplo n.º 10
0
 def degree_too_low():
     an.integration_points(degree=0, domain=an.Interval(0, 1))
Ejemplo n.º 11
0
 def degree_too_high():
     an.integration_points(degree=100, domain=an.Interval(0, 1))