Пример #1
0
    def test_OnePart1(self):
        numD = 2  # number of dimensions
        enum = 2  # number of elements in each dof
        nodes = nodeList(1, 1, 1, enum, enum)
        ien = get_ien(enum, enum)
        cc = [1.0, 0.0]

        wall = nsel('x', 'n', 0, 0.01, nodes)  # select the wall
        edge = nsel('x', 'n', 1, 0.01, nodes)  # select free edge

        ida, ncons, cons0, loads = constrain(nodes, wall, ien, 'x', 0)
        ida, ncons, cons1, loads = constrain(nodes, wall, ien, 'y', 0.0, cons0)
        ida, ncons, cons2, loads = constrain(nodes, edge, ien, 'x', 1.0, cons1)

        deform, i = solver(numD, loads, nodes, ien, ida, ncons, cons2, cc)

        correct = [0, 0, 0.5, 0, 1, 0, 0, 0, 0.5, 0, 1, 0, 0, 0, 0.5, 0, 1, 0]
        for i in range(len(deform)):  # for every item in the solution...
            self.assertAlmostEqual((correct[i] + 1) / (correct[i] + 1), 1)

        c = contourPlot(deform, ien, nodes, 'sigma_x', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'sigma_y', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'tau_xy', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'd_x', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'd_y', 'z', cc)
Пример #2
0
    def setUp(self):
        # Here, we generate the mesh
        thetaDomain = pi / 2.0  # quarter circle of the pipe
        self.ri = 1.2  # the inner radius of the pipe
        self.ro = 1.8  # the outer radius of the pipe
        self.nr = 8  # the number of elements in the radial direction
        self.nt = 16  # the number of elements in the circumfrential direction
        self.nodes = []  # stores the nodes in the cylindrical mesh
        self.p = -2.0e6  # the pressure (Pa) (against the surface normal)

        for i in range(self.nr + 1):  # for every node in the r-direction...
            for j in range(self.nt +
                           1):  # for every node in the theta-direction...
                radius = i * (self.ro - self.ri) / self.nr + self.ri
                theta = j * thetaDomain / self.nt
                self.nodes.append(
                    [radius * sin(theta), radius * cos(theta), 0])

        self.ien = get_ien(self.nt, self.nr)

        # now the fun begins. We solve this problem using roller constraints on
        # the straight faces and pressure loads on the inner face.
        s0 = nsel('y', 'n', 0, 0.01, self.nodes)
        s1 = nsel('x', 'n', 0, 0.01, self.nodes)

        ida, ncons, cons0, loads = constrain(self.nodes, s0, self.ien, 'y', 0)
        ida, ncons, cons, loads = constrain(self.nodes, s1, self.ien, 'x', 0,
                                            cons0)
        for i in range(self.nt):  # for every inner element...
            loads[3][i] = self.p

        self.deform, i = solver(2, loads, self.nodes, self.ien, ida, ncons,
                                cons)
        self.ps0 = nsel('y', 'n', 0, 0.01, self.nodes)
Пример #3
0
    def test_SubsetSelection(self):
        s0 = nsel('z', 'n', 1.5, 0.01, self.nodes)  # get a new set
        s1 = nsel('x', 's', 0, 0.01, self.nodes, s0)  # intersect with new set
        s2 = nsel('y', 's', 1.5, 0.01, self.nodes,
                  s0)  # intersect with new set

        correct = [[18, 21, 24], [24, 25, 26]]

        for i in range(len(s1)):  # for each component...
            self.assertAlmostEqual(correct[0][i], s1[i])
        for i in range(len(s2)):  # for each component...
            self.assertAlmostEqual(correct[1][i], s2[i])
Пример #4
0
    def test_AdditionalSelection(self):
        s0 = nsel('z', 'n', 1.5, 0.01, self.nodes)  # get a new set
        s1 = nsel('x', 'a', 0, 0.01, self.nodes, s0)  # intersect with new set
        s2 = nsel('y', 'a', 1.5, 0.01, self.nodes,
                  s0)  # intersect with new set

        correct = [[0, 3, 6, 9, 12, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26],
                   [6, 7, 8, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]]

        for i in range(len(s1)):  # for each component...
            self.assertAlmostEqual(correct[0][i], s1[i])
        for i in range(len(s2)):  # for each component...
            self.assertAlmostEqual(correct[1][i], s2[i])
Пример #5
0
 def test_1Elem1DPlot(self):
     s0 = nsel('x', 'n', 0, 0.01, self.nodes1)
     ida, ncons, cons, loads = constrain(self.nodes1, s0, self.ien1, 'x', 0)
     loads[2][0] = 1.0e8  #Pa
     deform, i = solver(1, loads, self.nodes1, self.ien1, ida, ncons, cons)
     #c = plotResults(deform, self.nodes1, self.nnums1, [1, 0, 0], 'x')
     self.assertEqual(0, 0)
Пример #6
0
    def setUp(self):
        self.nodes = nodeList(1, 1, 1, 1, 1, 1)
        self.ien = get_ien(1, 1, 1)
        self.nnums = np.linspace(0, len(self.nodes) - 1, len(self.nodes))

        self.s0 = nsel('x', 'n', 1, 0.01, self.nodes)

        self.ida, self.ncons, self.cons, loads = constrain(
            self.nodes, self.s0, self.ien, 'y', 0)
Пример #7
0
    def test_NormalSelection(self):
        s1 = nsel('x', 'n', 0.75, 0.01, self.nodes)
        s2 = nsel('y', 'n', 1.5, 0.01, self.nodes)
        s3 = nsel('z', 'n', 1.5, 1, self.nodes)

        correct = [[0, 3, 6, 9, 12, 15, 18, 21, 24],
                   [6, 7, 8, 15, 16, 17, 24, 25, 26],
                   [
                       9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
                       23, 24, 25, 26
                   ]]

        for i in range(len(s1)):  # for each component...
            self.assertAlmostEqual(correct[0][i] + 1, s1[i])
        for i in range(len(s2)):  # for each component...
            self.assertAlmostEqual(correct[1][i], s2[i])
        for i in range(len(s3)):  # for each component...
            self.assertAlmostEqual(correct[2][i], s3[i])
Пример #8
0
    def test_1Elem3DPlot(self):
        s0 = nsel('x', 'n', 0, 0.01, self.nodes)
        ida, ncons, cons, loads = constrain(self.nodes, s0, self.ien, 'x', 0)
        s1 = nsel('z', 's', 0, 0.01, self.nodes, s0)
        ida, ncons, cons, loads = constrain(self.nodes, s1, self.ien, 'z', 0,
                                            cons)
        s2 = nsel('y', 's', 0, 0.01, self.nodes, s1)
        ida, ncons, cons, loads = constrain(self.nodes, s2, self.ien, 'y', 0,
                                            cons)
        loads[2][1] = 1.0e8  #Pa
        loads[2][3] = 1.0e8
        loads[2][5] = 1.0e8
        loads[2][7] = 1.0e8

        deform, i = solver(3, loads, self.nodes, self.ien, ida, ncons, cons)
        ps0 = nsel('y', 'n', 0, 0.01, self.nodes)
        ps1 = nsel('z', 's', 0, 0.01, self.nodes, ps0)
        #c = plotResults(deform, self.nodes, ps1, [1, 0, 0], 'x')

        self.assertEqual(0, 0)
Пример #9
0
    def test_CylinderPlot(self):
        # Here, we generate the mesh
        thetaDomain = pi / 2.0  # quarter circle of the pipe
        self.ri = 1.2  # the inner radius of the pipe
        self.ro = 1.8  # the outer radius of the pipe
        self.nr = 16  # the number of elements in the radial direction
        self.nt = 32  # the number of elements in the circumfrential direction
        self.nodes = []  # stores the nodes in the cylindrical mesh
        self.p = -2.0e6  # the pressure (Pa)
        cc = [2.0e11, 0.3]  # [Young's Modulus, Poisson's Ratio]

        for i in range(self.nr + 1):  # for every node in the r-direction...
            for j in range(self.nt +
                           1):  # for every node in the theta-direction...
                radius = i * (self.ro - self.ri) / self.nr + self.ri
                theta = j * thetaDomain / self.nt
                self.nodes.append(
                    [radius * sin(theta), radius * cos(theta), 0])

        self.ien = get_ien(self.nt, self.nr)
        self.nnums = np.linspace(0, len(self.nodes) - 1, len(self.nodes))

        # now the fun begins. We solve this problem using roller constraints on
        # the straight faces and pressure loads on the inner face.
        s0 = nsel('y', 'n', 0, 0.01, self.nodes)
        s1 = nsel('x', 'n', 0, 0.01, self.nodes)

        ida, ncons, cons0, loads = constrain(self.nodes, s0, self.ien, 'y', 0)
        ida, ncons, cons, loads = constrain(self.nodes, s1, self.ien, 'x', 0,
                                            cons0)
        for i in range(self.nt):  # for every inner element...
            loads[3][i] = self.p

        self.deform, i = solver(2, loads, self.nodes, self.ien, ida, ncons,
                                cons)
        ps0 = nsel('y', 'n', 0, 0.01, self.nodes)
        #c = plotResults(deform, self.nodes, ps0, [1, 0, 0], 'x')
        c = contourPlot(self.deform, self.ien, self.nodes, 'sigma_t', 'z', cc)
Пример #10
0
    def test_accuracyPressCylinSol(self):
        ps = nsel('y', 'n', 0, 0.01, self.nodes)
        dsol = []  # stores the nodal values
        rsol = []  # stores the node radial location
        error = 0  # stores the total solution error
        E = 2.0e11
        nu = 0.3

        for i in range(len(ps)):  # for every node...
            s = 2 * ps[i]  # starting position of the node displacement
            e = 2 * ps[i] + 2  # ending position of the node displacement
            # the magnitude of the nodal displacement
            dsol.append(np.linalg.norm(np.array(self.deform[s:e])))
            v = self.nodes[ps[i]]  # a vector position of the node
            rsol.append(v[0])  # the radius of the point

        for i in range(self.nr):  # for every radial element...
            # Here, we calculate the exact solution
            d = 1.0 / 3**0.5  # the absolute distance of 2-point gauss quadrature
            es = rsol[i + 1] - rsol[i]  # element size
            r0 = rsol[i] + (1 - d) * es / 2.0  # first gauss quadrature point
            r1 = rsol[i] + (1 + d) * es / 2.0  # second gauss quadrature point
            a = self.p * self.ri**2 / (E *
                                       (self.ro**2 - self.ri**2))  # first part

            b0 = ((1 - nu) * r0 + self.ro**2 * (1 + nu) / r0)  # second part
            b1 = ((1 - nu) * r1 + self.ro**2 * (1 + nu) / r1)
            u0 = a * b0  # the exact solution at the first gauss quadrature point
            u1 = a * b1  # the exact solution at the second gauss quadrature point
            us0 = 0.5 * (1 + d) * dsol[i] + 0.5 * (
                1 - d) * dsol[i + 1]  # solution deform
            us1 = 0.5 * (1 - d) * dsol[i] + 0.5 * (
                1 + d) * dsol[i + 1]  # solution deform
            error += ((us0 - u0)**2 + (us1 - u1)**2) * es / 2.0
            print('Error at the first Gauss point:', abs(us0 - u0))

        self.assertLess(error, 8.0e-6)
Пример #11
0
    def test_OnePart2(self):
        numD = 2  # number of dimensions
        enum = 10  # number of elements in each dof
        nodes = nodeList(1, 1, 1, enum, enum)
        ien = get_ien(enum, enum)
        cc = [1.0e7, 0.3]

        wall = nsel('x', 'n', 0, 0.01, nodes)  # select the wall

        ida, ncons, cons0, loads = constrain(nodes, wall, ien, 'x', 0)
        ida, ncons, cons1, loads = constrain(nodes, wall, ien, 'y', 0.0, cons0)
        for i in range(enum):  # for every element on a side...
            loads[2][enum * (i + 1) - 1] = 1000.0  # traction on the right

        deform, i = solver(numD, loads, nodes, ien, ida, ncons, cons1, cc)

        c = contourPlot(deform, ien, nodes, 'd_abs', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'd_x', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'd_y', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'sigma_x', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'sigma_y', 'z', cc)
        c = contourPlot(deform, ien, nodes, 'tau_xy', 'z', cc)

        self.assertEqual(c, 0)
Пример #12
0
    def test_SphericalSelection(self):
        s0 = nsel('r', 'n', 1.5, 0.01, self.nodes)
        correct = [2, 6, 18]

        for i in range(len(s0)):  # for each component...
            self.assertEqual(correct[i], s0[i])