示例#1
0
def run():
    from pyformex import simple
    smooth()
    linewidth(2)
    clear()
    S = simple.sphere()
    SA = draw(S)

    p = 0
    for P, N, L, div in [
            #
            # Each line contains a point, a normal, an extrusion length
            # and the number of elements along this length
        ((0.6, 0., 0.), (1., 0., 0.), 2.5, 5),
        ((-0.6, 0.6, 0.), (-1., 1., 0.), 4., (16, 1.0, 1.0)),
        ((-0.6, -0.6, 0.), (-1., -1., 0.), 3., 2),
    ]:
        B, S = cutBorderClose(S, P, N)
        draw(B)
        p += 1
        E = B.extrude(div, dir=normalize(N), length=L,
                      eltype='tri3').setProp(p)
        draw(E)

    draw(S)
    undraw(SA)
    zoomAll()
示例#2
0
def create():
    """Create a closed surface and a set of points."""
    nx, ny, nz = npts

    # Create surface
    if surface == 'file':
        S = TriSurface.read(filename).centered()
    elif surface == 'sphere':
        S = simple.sphere(ndiv=grade)

    if refine > S.nedges():
        S = S.refine(refine)

    draw(S, color='red')

    if not S.isClosedManifold():
        warning("This is not a closed manifold surface. Try another.")
        return None, None

    # Create points

    if points == 'grid':
        P = simple.regularGrid([-1., -1., -1.], [1., 1., 1.], [nx-1, ny-1, nz-1])
    else:
        P = random.rand(nx*ny*nz*3)

    sc = array(scale)
    siz = array(S.sizes())
    tr = array(trl)
    P = Formex(P.reshape(-1, 3)).resized(sc*siz).centered().translate(tr*siz)
    draw(P, marksize=1, color='black')
    zoomAll()

    return S, P
示例#3
0
def run():
    clear()
    smooth()

    from pyformex.simple import sphere
    S = sphere(8).scale(3.)
    T = S.cutWithPlane(
        [[2., 0., 0.], [0., 1., 0.], [-2., 0., 0.], [0., -1., 0.]],
        [[-1., 0., 0.], [0., -1., 0.], [1., 0., 0.], [0., +1., 0.]],
        side='-')
    draw(T)
示例#4
0
def createGeometry():
    """Create some geometry.

    This example creates a sphere, a cone and a cylinder, all
    partially overlapping. It sets some rendering attributes
    on the objects.
    """
    # A sphere
    S = sphere().scale(1.2)
    # A Cone
    T = sector(1.0, 360., 6, 36, h=1.0,
               diag='u').toSurface().scale(1.5).reverse()
    # A Cylinder
    C = cylinder(1.2, 1.5, 24, 4, diag='u').toSurface().trl([0.5, 0.5,
                                                             0.5]).reverse()

    # Add some rendering attributes. These attributes will be used
    # when doing default drawing. The attributes will also be exported
    # to WebGL models. Finally, the attributes can be used to create
    # a dialog for interactively changing the rendering.

    # Attributes can be created using different styles.

    # Style 1: specify them as parameters in the attrib() method call
    S.attrib(
        name='Sphere',
        caption='A sphere',
        color=red,
        alpha=0.7,
    )

    T.attrib(
        name='Cone',
        caption='A cone',
        color=blue,
        alpha=1.0,
    )

    C.attrib(
        name='Cylinder',
        caption='A cylinder',
        color='cyan',
        bkcolor='green',
        alpha=1.0,
    )

    # Style 2: alternately, you can directly set the values as attributes
    # on the created attrib. This style is mostly used to modify or add
    # some attribute afterwards.
    T.attrib.alpha = 0.6

    return List([S, T, C])
示例#5
0
def createSurface(surface, filename, grade, **kargs):
    """Create and draw a closed surface from input data

    """
    if surface == 'file':
        S = TriSurface.read(filename).centered()
    elif surface == 'sphere':
        S = simple.sphere(ndiv=grade)

    draw(S)

    if not S.isClosedManifold():
        warning("This is not a closed manifold surface. Try another.")
        return None
    return S
示例#6
0
def run():

    clear()
    transparent()
    smoothwire

    nsphere = 10
    S = sphere(nsphere)

    bbs = cuboid(*S.bbox()).toMesh().scale([0.8, 0.8, 1]).rot(30, 1).rot(
        20, 0).shear(2, 1, 0.3).toSurface()

    clippedIn = vtkClip(S, implicitdata=bbs, method='surface', insideout=0)
    clippedOut = vtkClip(S, implicitdata=bbs, method='surface', insideout=1)

    draw(clippedIn, color=red, alpha=1)
    draw(clippedOut, color=blue, alpha=1)
    draw(bbs, color=yellow)
def run():

    clear()
    transparent()

    nquad = 1
    nsphere = 5

    S = sphere(nsphere)

    #Creating the points to define the intersecting lines
    R = regularGrid([0., 0., 0.], [0., 1., 1.], [1, nquad, nquad])
    L0 = Coords(R.reshape(-1, 3)).trl([-2., -1. / 2, -1. / 2]).fuse()[0]
    L1 = L0.trl([4., 0., 0.])

    P, X = S.intersectionWithLines(q=L0, q2=L1, method='line', atol=1e-5)

    # Retrieving the index of the points and the correspending lines and hit triangles
    id_pts = X[:, 0]
    id_intersected_line = X[:, 1]
    id_hit_triangle = X[:, 2]

    hitsxline = inverseIndex(id_intersected_line.reshape(-1, 1))
    Nhitsxline = (hitsxline > -1).sum(axis=1)

    ptsok = id_pts[hitsxline[where(hitsxline > -1)]]
    hittriangles = id_hit_triangle[hitsxline[where(hitsxline > -1)]]

    colors = ['red', 'green', 'blue', 'cyan']
    [
        draw(Formex([[p0, p1]]), color=c, linewidth=2, alpha=0.7)
        for p0, p1, c in zip(L0, L1, colors)
    ]

    id = 0
    for icolor, nhits in enumerate(Nhitsxline):
        for i in range(nhits):
            draw(P[ptsok][id], color=colors[icolor], marksize=5, alpha=1)
            draw(S.select([hittriangles[id]]),
                 ontop=True,
                 color=colors[icolor])
            id += 1
    draw(S, alpha=0.3)
示例#8
0
def run():
    smoothwire()

    print("======================")
    print("A cube with side = 1.0")
    F = cuboid().toMesh().convert('tet4').toFormex()
    clear()
    draw(F.toMesh().getBorderMesh())
    print("Number of tetrahedrons: %s" % F.shape[0])
    print("Bounding box: %s" % F.bbox())
    V, M, C, I = inertia.tetrahedral_inertia(F.coords)
    # Analytical
    Va = 1.
    Ma = Va
    Ca = [0.5, 0.5, 0.5]
    Ia = [1. / 6, 1. / 6, 1. / 6, 0., 0., 0.]
    print("Volume = %s (corr. %s)" % (V, Va))
    print("Mass = %s (corr. %s)" % (M, Ma))
    print("Center of mass = %s (corr. %s)" % (C, Ca))
    print("Inertia tensor = %s (corr. %s)" % (I, Ia))

    pause()
    print("======================")
    print("A sphere with radius = 1.0")
    # Increase the quality to better approximate the sphere
    quality = 4
    F = sphere(quality).tetgen().toFormex()
    clear()
    draw(F.toMesh().getBorderMesh())
    print("Number of tetrahedrons: %s" % F.shape[0])
    print("Bounding box: %s" % F.bbox())
    V, M, C, I = inertia.tetrahedral_inertia(F.coords)
    # Analytical
    Va = 4 * pi / 3
    Ma = Va
    Ca = [0., 0., 0.]
    ia = 8 * pi / 15
    Ia = [ia, ia, ia, 0., 0., 0.]
    print("Volume = %s (corr. %s)" % (V, Va))
    print("Mass = %s (corr. %s)" % (M, Ma))
    print("Center of mass = %s (corr. %s)" % (C, Ca))
    print("Inertia tensor = %s (corr. %s)" % (I, Ia))
示例#9
0
def run():
    reset()
    clear()

    # Property numbers used
    pbol = 1  # Bol
    ptop = 2  # Top plate
    pbot = 3  # Bottom plate

    scale = 15.   # scale (grid unit in mm)

    # Create a solid sphere
    BolSurface = simple.sphere().scale(scale)
    try:
        # tetgen may not be available
        Bol = BolSurface.tetgen(quality=True).setProp(pbol)
    except:
        return
    draw(Bol)

    # Create top and bottom plates
    plate = simple.rectangle(4, 4).toMesh().centered()
    topplate = plate.setProp(ptop).trl(2, 1.).scale(scale)
    botplate = plate.setProp(pbot).trl(2, -1.).scale(scale)
    draw([topplate, botplate])

    # model is completely drawn, keep fixed bbox
    setDrawOptions({'bbox':'last','marksize':8})

    # Assemble the model
    M = Model(meshes=[Bol, topplate, botplate])

    # Create the property database
    P = PropertyDB()

    # In this simple example, we do not use a material/section database,
    # but define the data directly
    steel = {
        'name': 'steel',
        'young_modulus': 207000,
        'poisson_ratio': 0.3,
        'density': 7.85e-9,
        'plastic': [
            (305.45,       0.),
            (306.52, 0.003507),
            (308.05, 0.008462),
            (310.96,  0.01784),
            (316.2, 0.018275),
            (367.5, 0.047015),
            (412.5, 0.093317),
            (448.11, 0.154839),
            (459.6, 0.180101),
            (494., 0.259978),
            (506.25, 0.297659),
            (497., 0.334071),
            (482.8, 0.348325),
            (422.5, 0.366015),
            (399.58,   0.3717),
            (1.,  0.37363),
            ],
        }
    solid_steel = {
        'name': 'solid_steel',
        'sectiontype': 'solid',
        'material': 'steel',   # Need material reference for Abaqus
        }
    steel_plate = {
        'name': 'solid_steel',
        'sectiontype': 'solid',
        'thickness': 3,
        'material': 'steel',   # Need material reference for Abaqus
        }

    # Set the element properties
    eset = dict([(p, where(M.prop==p)[0]) for p in [pbol, ptop, pbot]])

    # Bol is elasto/plastic
    P.elemProp(set=eset[pbol], name='Bol', eltype='C3D4', section=ElemSection(section=solid_steel, material=steel))

    # Top plate is rigid or elasto-plastic
    topplate_rigid = True
    if topplate_rigid:
        # Rigid bodies need a reference node.
        # We select the most central node, but any node would also work,
        # e.g. pbref = M.elems[1][0][0], the very first node in the group
        reftop = groupCentralPoint(M, 1)
        print("Top plate refnode: %s" % reftop)
        draw(M.coords[reftop], color=green)
        P.elemProp(set=eset[ptop], name='TopPlate', eltype='R3D4', section=ElemSection(sectiontype='rigid', refnode=reftop))
    else:
        P.elemProp(set=eset[ptop], name='TopPlate', eltype='CPS4', section=ElemSection(section=steel_plate, material=steel))


    # Bottom plate is rigid or elasto-plastic
    refbot = groupCentralPoint(M, 2)
    print("Bottom plate refnode: %s" % refbot)
    draw(M.coords[refbot], color=blue)
    P.elemProp(set=eset[pbot], name='BottomPlate', eltype='R3D4', section=ElemSection(sectiontype='rigid', refnode=refbot))

    # Set the boundary conditions
    # Bottom plate is fixed
    fixed = unique(M.elems[2])
    P.nodeProp(tag='init', set=[refbot], name='Fixed', bound=[1, 1, 1, 1, 1, 1])

    # Set the loading conditions
    # Top plate gets z-displacement of -5 mm
    displ = unique(M.elems[1])
    P.nodeProp(tag='init', set=[reftop], name='Displ', bound=[1, 1, 0, 1, 1, 1])
    P.nodeProp(tag='step1', set=[reftop], name='Refnod', displ=[(2, -0.5)])

    ## # Set the loading conditions
    ## # All elements of Plate1 have a pressure loading of 10 MPa
    ## loaded = M.elemNrs(1)
    ## P.elemProp(tag='step1',set=loaded,name='Loaded',dload=ElemLoad('P',10.0))

    from pyformex.plugins.fe_abq import Interaction
    P.Prop(tag='init', generalinteraction=Interaction(name='interaction1', friction=0.1))
    P.Prop(tag='init', generalcontact='interaction1')

    print("Element properties")
    for p in P.getProp('e'):
        print(p)
    print("Node properties")
    for p in P.getProp('n'):
        print(p)
    print("Model properties")
    for p in P.getProp(''):
        print(p)

    out = [ Output(type='history'),
            Output(type='field'),
            ]

    # Create requests for output to the .fil file.
    # - the displacements in all nodes
    # - the stress components in all elements
    # - the stresses averaged at the nodes
    # - the principal stresses and stress invariants in the elements of part B.
    # (add output='PRINT' to get the results printed in the .dat file)
    res = [ Result(kind='NODE', keys=['U']),
            Result(kind='ELEMENT', keys=['S'], set='Bol'),
            Result(kind='ELEMENT', keys=['S'], pos='AVERAGED AT NODES', set='Bol'),
            Result(kind='ELEMENT', keys=['SP', 'SINV'], set='Bol'),
            ]

    # Define steps (default is static)
    step1 = Step('DYNAMIC', time=[1., 1., 0.01, 1.], tags=['step1'])

    data = AbqData(M, prop=P, steps=[step1], res=res, initial=['init'])

    if ack('Export this model in ABAQUS input format?', default='No'):
        fn = askNewFilename(filter='inp')
        if fn:
            data.write(jobname=fn, group_by_group=True)
示例#10
0
def sphere_mesh():
    F =simple.sphere(6)
    F += F.trl([2., 0., 0.])
    return Mesh(F).scale(x/2.).trl(1, -y)