Esempio n. 1
0
    def updateGeometry(self):
        """Update geometry"""

        cfu.info("Creating geometry...")

        self.g = cfg.geometry()
        g = self.g

        # Just a shorthand. We use this to make the circle arcs.

        s2 = 1 / sqrt(2)

        points = [
            [0, 3],
            [2.5, 3],
            [3, 3],
            [4 - s2, 3 - s2],
            [4, 2],  #0-4
            [4 + s2, 3 - s2],
            [5, 3],
            [5.5, 3],
            [8, 3],
            [0, 1.5],  #5-9
            [2.5, 1.5],
            [4, 1.5],
            [5.5, 1.5],
            [8, 1.5],
            [0, 0],  #10-14
            [2.5, 0],
            [3, 0],
            [4 - s2, s2],
            [4, 1],
            [4 + s2, s2],  #15-19
            [5, 0],
            [5.5, 0],
            [8, 0],
            [4, 3],
            [4, 0]
        ]  #20-24

        for xp, yp in points:
            g.point([xp * 0.1, yp * 0.1])

        splines = [
            [0, 1],
            [1, 2],
            [6, 7],
            [7, 8],
            [8, 13],  #0-4
            [13, 22],
            [22, 21],
            [21, 20],
            [16, 15],
            [15, 14],  #5-9
            [14, 9],
            [9, 0],
            [9, 10],
            [10, 1],
            [10, 15],  #10-14
            [10, 11],
            [11, 4],
            [11, 18],
            [11, 12],
            [12, 7],  #15-19
            [12, 21],
            [12, 13],
            [3, 10],
            [5, 12],
            [10, 17],  #20-24
            [12, 19]
        ]  #25

        for s in splines:
            g.spline(s, elOnCurve=5)

        g.curveMarker(ID=4,
                      marker=7)  #Assign marker 7 to the splines on the right.
        g.curveMarker(
            ID=5, marker=7)  # We will apply a force on nodes with marker 7.
        g.curveMarker(ID=10,
                      marker=5)  #Assign marker 5 to the splines on the left.
        g.curveMarker(
            ID=11,
            marker=5)  # The nodes with marker 5 will be locked in place.

        # Points in circle arcs are [start, center, end]

        circlearcs = [
            [2, 23, 3],
            [3, 23, 4],
            [4, 23, 5],
            [5, 23, 6],  #26-29
            [16, 24, 17],
            [17, 24, 18],
            [18, 24, 19],
            [19, 24, 20]
        ]  #30-33

        for c in circlearcs:
            g.circle(c, elOnCurve=5)

        g.structuredSurface([11, 12, 13, 0])  #0
        g.structuredSurface([14, 12, 10, 9])
        g.structuredSurface([8, 30, 24, 14])
        g.structuredSurface([24, 31, 17, 15])
        g.structuredSurface([15, 16, 27, 22])  #4
        g.structuredSurface([22, 26, 1, 13])
        g.structuredSurface([16, 18, 23, 28])
        g.structuredSurface([19, 2, 29, 23])
        g.structuredSurface([19, 21, 4, 3])  #8
        g.structuredSurface([20, 6, 5, 21])
        g.structuredSurface([25, 20, 7, 33])
        g.structuredSurface([32, 17, 18, 25])  #11
Esempio n. 2
0
            event.x, event.y, event.xdata, event.ydata))

    def on_plt_keypress(self, event):
        print("keypres")

def cfedit(geometry):
    app = QApplication(sys.argv)
    window = MainWindow(app, geometry)
    sys.exit(app.exec_())     
       

if __name__ == '__main__':

    # ---- Create Geometry ------------------------------------------------------

    g = cfg.geometry()

    # Add Points:

    points = [
        [0,0], 
        [0,100], 
        [0,150], 
        [100,0], 
        [150,0], 
        [100,-100], 
        [150,-100]
    ]

    for p in points:
        g.point(p)
Esempio n. 3
0
    def convertToGeometry(self, max_el_size=1):
        """Takes exterior and interior line lists generated from readDXF to convert to Calfem-readable geometry"""
        # ------ First, store the dxf lines as local variables
        outline = self.exterior
        holes = self.interior

        # ------ Create a geometry instance to store our geometry parameters
        g = cfg.geometry()

        # ------ Create points for the model
        for line in outline:
            g.addPoint([line[0][0], line[0][1]], ID=line[4])
        for hole in holes:
            # Check to see if it's a circle, if so, do things differently
            if hole[3] == 'CIRCLE':
                g.addPoint([hole[0][0], hole[0][1]],
                           ID=hole[4],
                           elSize=max_el_size * 1.5)  # Right side
                g.addPoint([hole[7][0], hole[7][1]],
                           ID=hole[4] + 1,
                           elSize=max_el_size * 1.5)  # Top side
                g.addPoint([hole[1][0], hole[1][1]],
                           ID=hole[4] + 2,
                           elSize=max_el_size * 1.5)  # Left side
                g.addPoint([hole[8][0], hole[8][1]],
                           ID=hole[4] + 3,
                           elSize=max_el_size * 1.5)  # Bottom side
                g.addPoint([hole[6][0], hole[6][1]],
                           ID=hole[4] + 4,
                           elSize=max_el_size * 1.5)  # Center
            else:
                g.addPoint([hole[0][0], hole[0][1]],
                           ID=hole[4],
                           elSize=max_el_size * 1.5)

        # ------ Create links between the points of the model

        # --- First, define a dictionary to fill with all curves belonging to each layer
        curve_list = []
        for i in range(len(self.markers)):
            curve_list.append([])
        curve_dict = {}
        exterior_splines = []

        # Define exterior lines
        for line in outline:
            if (line[4] == len(outline) - 1):
                # For the final element, make sure to loop back to zero
                g.spline([line[4], outline[0][4]],
                         ID=line[4],
                         marker=self.markers[line[2]])
            else:
                g.spline([line[4], line[4] + 1],
                         ID=line[4],
                         marker=self.markers[line[2]])
            # Convert marker number to curve list idx num, i.e.: 10 -> 0, 20 -> 1, etc.
            curve_list[int(self.markers[line[2]] / 10 - 1)].append(line[4])
            exterior_splines.append(line[4])

        # Define interior lines (holes)
        hole_num = 0
        hole_start_idx = 0
        hole_temp = []
        hole_splines = []
        for idx, hole in zip(range(len(holes)), holes):
            # Check if it's a circle, if so, add the necessary splines
            if hole[3] == 'CIRCLE':
                g.addCircle([hole[4], hole[4] + 4, hole[4] + 1],
                            ID=hole[4],
                            marker=self.markers[hole[2]])  # Right to top
                g.addCircle([hole[4] + 1, hole[4] + 4, hole[4] + 2],
                            ID=hole[4] + 1,
                            marker=self.markers[hole[2]])  # Top to left
                g.addCircle([hole[4] + 2, hole[4] + 4, hole[4] + 3],
                            ID=hole[4] + 2,
                            marker=self.markers[hole[2]])  # Left to bottom
                g.addCircle([hole[4] + 3, hole[4] + 4, hole[4]],
                            ID=hole[4] + 3,
                            marker=self.markers[hole[2]])  # Bottom to left
                curve_list[int(self.markers[hole[2]] / 10 - 1)].append(hole[4])
                curve_list[int(self.markers[hole[2]] / 10 -
                               1)].append(hole[4] + 1)
                curve_list[int(self.markers[hole[2]] / 10 -
                               1)].append(hole[4] + 2)
                curve_list[int(self.markers[hole[2]] / 10 -
                               1)].append(hole[4] + 3)
                hole_num = hole_num + 1
                hole_temp.append(hole[4])
                hole_temp.append(hole[4] + 1)
                hole_temp.append(hole[4] + 2)
                hole_temp.append(hole[4] + 3)
                hole_splines.append(hole_temp)
                hole_temp = []
                hole_start_idx = idx + 1
                continue
            elif hole[1] == holes[hole_start_idx][0]:
                # For the final element, make sure to loop back to the start idx
                g.spline([hole[4], holes[hole_start_idx][4]],
                         ID=hole[4],
                         marker=self.markers[hole[2]])
                curve_list[int(self.markers[hole[2]] / 10 - 1)].append(hole[4])
                hole_num = hole_num + 1
                hole_temp.append(hole[4])
                hole_splines.append(hole_temp)
                hole_temp = []
                hole_start_idx = idx + 1
                continue
            else:
                g.spline([hole[4], hole[4] + 1],
                         ID=hole[4],
                         marker=self.markers[hole[2]])
                curve_list[int(self.markers[hole[2]] / 10 - 1)].append(hole[4])
            hole_temp.append(hole[4])

        # ------ Define the surface on which the mesh is to be generated
        g.addSurface(exterior_splines, hole_splines)

        # ------ Convert the curve list to a dictionary
        for mark, curves in zip(self.markers, curve_list):
            curve_dict.update({mark: curves})

        # ------ Return the created geometry and curve dictionary
        return g, curve_dict