Ejemplo n.º 1
0
def run():
    import simple
    smooth()
    linewidth(2)
    clear()
    S = simple.sphere()
    SA = draw(S)

    p = 0
    for P, N, L, ndiv 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),
        ((-0.6, -0.6, 0.), (-1., -1., 0.), 3., 2),
    ]:
        B, S = cutBorderClose(S, P, N)
        draw(B)
        p += 1
        E = B.extrude(n=ndiv, step=L / ndiv, dir=normalize(N),
                      eltype='tri3').setProp(p)
        draw(E)

    draw(S)
    undraw(SA)
    zoomAll()
Ejemplo n.º 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
Ejemplo n.º 3
0
def run():
    clear()
    smooth()

    from 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)
Ejemplo n.º 4
0
def run():
    clear()
    smooth()

    from 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)
Ejemplo n.º 5
0
def createSphere():
    res = askItems([_I('name','__auto__'),
                    _I('ndiv',8,min=1),
                    ])
    if res:
        name = res['name']
        ndiv = res['ndiv']
        S = simple.sphere(ndiv)
        export({name:S})
        selection.set([name])
        selection.draw()
Ejemplo n.º 6
0
def run():
    reset()
    clear()
    smooth()
    transparent()
    view('right')

    # Create some geometry
    S = sphere()
    T = sector(1.0,360.,6,36,h=1.0,diag='u').toSurface().scale(1.5).reverse()
    C = cylinder(1.2,1.5,24,4,diag='u').toSurface().trl([0.5,0.5,0.5]).reverse()

    # Draw the geometry with given colors/opacity
    # Settings colors and opacity in this way makes the model
    # directly ready to export as WebGL
    S.color = red
    S.alpha = 0.7
    S.caption = 'A sphere'
    S.control = ['visible','opacity','color']
    S.setNormals('avg')

    T.color = blue
    T.caption = 'A cone'
    T.alpha = 1.0
    T.control = ['visible','opacity','color']
    #S.setNormals('auto')

    C.color = 'yellow'
    C.caption = 'A cylinder'
    C.alpha = 0.8
    C.control = ['visible','opacity','color']
    #S.setNormals('auto')

    export({'sphere':S,'cone':T,'cylinder':C})

    draw([S,T,C])
    zoomAll()
    rotRight(30.)

    camera = pf.canvas.camera
    print("Camera focus: %s; eye: %s" % (camera.focus, camera.eye))

    if checkWorkdir():
        # Export everything to webgl
        W = WebGL()
        W.addScene()
        W.export('Scene1','Two spheres and a cone',createdby=True)
Ejemplo n.º 7
0
def createSphere():
    _data_ = _name_ + 'createSphere_data'
    dia = Dialog(
        items=[
            _I('name', '__auto__'),
            _I('object type',
               itemtype='radio',
               choices=['TriSurface', 'Mesh', 'Formex']),
            _I('method', choices=['icosa', 'geo']),
            _I('ndiv', 8),
            _I('nx', 36),
            _I('ny', 18),
        ],
        enablers=[
            ('method', 'icosa', 'ndiv'),
            ('method', 'geo', 'nx', 'ny'),
        ],
    )
    if _data_ in pf.PF:
        dia.updateData(pf.PF[_data_])
    res = dia.getResults()
    if res:
        pf.PF[_data_] = res
        name = res['name']
        if name == '__auto__':
            name = autoName(res['object type']).next()
        if res['method'] == 'icosa':
            F = simple.sphere(res['ndiv'])
            print("Surface has %s vertices and %s faces" %
                  (F.ncoords(), F.nelems()))
            F = convert_Mesh_TriSurface(F, res['object type'])
        else:
            F = simple.sphere3(res['nx'], res['ny'])
            F = convertFormex(F, res['object type'])
            print("Surface has  %s faces" % F.nelems())
        export({name: F})
        selection.set([name])
        if res['object type'] == 'TriSurface':
            surface_menu.selection.set([name])
        selection.draw()
Ejemplo n.º 8
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:
        # tetmesh may not be available
        Bol = BolSurface.tetmesh(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 plugins.fe_abq import Interaction
    P.Prop(tag='init',
           generalinteraction=Interaction(name='interaction1', friction=0.1))

    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, bound=['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)
Ejemplo n.º 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:
        # tetmesh may not be available
        Bol = BolSurface.tetmesh(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 plugins.fe_abq import Interaction
    P.Prop(tag='init',generalinteraction=Interaction(name='interaction1',friction=0.1))

    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,bound=['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)
Ejemplo n.º 10
0
def sphere_mesh():
    F = simple.sphere(6)
    F += F.trl([2., 0., 0.])
    return Mesh(F).scale(x / 2.).trl(1, -y)
Ejemplo n.º 11
0
def sphere_mesh():
    F =simple.sphere(6)
    F += F.trl([2., 0., 0.])
    return Mesh(F).scale(x/2.).trl(1, -y)