Beispiel #1
0
def add_to_silo_file(silo,
                     mesh,
                     cell_data=[],
                     point_data=[],
                     line_integral_rules=[],
                     mesh_name="mesh",
                     real_only=False):
    zonelist_name = mesh_name + "_zonelist"

    from pyvisfile.silo import IntVector

    nodelist = IntVector()
    nodelist.extend(int(i) for i in mesh.elements.flat)

    shapetypes = IntVector()
    from pyvisfile.silo import DB_ZONETYPE_TRIANGLE
    shapetypes.append(DB_ZONETYPE_TRIANGLE)

    shapesizes = IntVector()
    shapesizes.append(3)

    shapecounts = IntVector()
    shapecounts.append(len(mesh))

    silo.put_zonelist_2(zonelist_name, len(mesh), mesh.dimensions, nodelist, 0,
                        0, shapetypes, shapesizes, shapecounts)

    silo.put_ucdmesh(mesh_name, [],
                     np.asarray(mesh.vertex_coordinates.T, order="C"),
                     len(mesh), zonelist_name, None)

    from pyvisfile.silo import DB_NODECENT, DB_ZONECENT
    silo.put_ucdvar1(
        "myvar", mesh_name,
        np.arange(mesh.vertex_coordinates.shape[0], dtype=np.double),
        DB_NODECENT)
    silo.put_ucdvar1("myvar2", mesh_name,
                     np.arange(len(mesh), dtype=np.double), DB_ZONECENT)
Beispiel #2
0
def add_to_silo_file(silo, mesh, cell_data=[], point_data=[],
        line_integral_rules=[],
        mesh_name="mesh",
        real_only=False):
    zonelist_name = mesh_name + "_zonelist"

    from pyvisfile.silo import IntVector

    nodelist = IntVector()
    nodelist.extend(int(i) for i in mesh.elements.flat)

    shapetypes = IntVector()
    from pyvisfile.silo import DB_ZONETYPE_TRIANGLE
    shapetypes.append(DB_ZONETYPE_TRIANGLE)

    shapesizes = IntVector()
    shapesizes.append(3)

    shapecounts = IntVector()
    shapecounts.append(len(mesh))

    silo.put_zonelist_2(zonelist_name, len(mesh), mesh.dimensions, nodelist,
            0, 0, shapetypes, shapesizes, shapecounts)

    silo.put_ucdmesh(mesh_name, [],
            np.asarray(mesh.vertex_coordinates.T, order="C"), len(mesh),
            zonelist_name, None)

    from pyvisfile.silo import DB_NODECENT, DB_ZONECENT
    silo.put_ucdvar1("myvar", mesh_name,
            np.arange(mesh.vertex_coordinates.shape[0], dtype=np.double),
            DB_NODECENT)
    silo.put_ucdvar1("myvar2", mesh_name,
            np.arange(len(mesh), dtype=np.double),
            DB_ZONECENT)
Beispiel #3
0
def write_silo_meshfile(fname, H,X):
    from pyvisfile.silo import SiloFile, IntVector, DB_ZONETYPE_BEAM, DB_NODECENT, DB_ZONECENT, DBOPT_CYCLE, DBOPT_DTIME, DBOPT_TIME, DB_CLOBBER
    import numpy as np
    silo = SiloFile(fname, mode=DB_CLOBBER)

    pair_edges = H.view()[0]
    zonelist_name = "foo_zonelist"
    nodelist = IntVector()
    nodelist.extend( int(i) for i in pair_edges[:,0:2].flat)
    shapetypes = IntVector()
    shapetypes.append(DB_ZONETYPE_BEAM)
    shapesizes = IntVector()
    shapesizes.append(2)
    shapecounts = IntVector()
    shapecounts.append(len(pair_edges))
    silo.put_zonelist_2(zonelist_name, len(pair_edges), 2, nodelist,
                            0,0, shapetypes, shapesizes, shapecounts)
    silo.put_ucdmesh("foo", [],
                     np.asarray(X.T,order="C"), len(pair_edges),
                     zonelist_name, None)
    silo.close()
Beispiel #4
0
def write_silo(fname, H,X,cycle=0, time=0,nodefields=[], edgefields=[], PUTMESH=True, PUTCONN=True):
    from pyvisfile.silo import SiloFile, IntVector, DB_ZONETYPE_BEAM, DB_NODECENT, DB_ZONECENT, DBOPT_CYCLE, DBOPT_DTIME, DBOPT_TIME, DB_CLOBBER
    import numpy as np
    silo = SiloFile(fname, mode=DB_CLOBBER)

    pair_edges = H.view()[0]
    zonelist_name = "foo_zonelist"
    nodelist = IntVector()
    nodelist.extend( int(i) for i in pair_edges[:,0:2].flat)
    shapetypes = IntVector()
    shapetypes.append(DB_ZONETYPE_BEAM)
    shapesizes = IntVector()
    shapesizes.append(2)
    shapecounts = IntVector()
    shapecounts.append(len(pair_edges))
    #from IPython import embed
    #embed()
    if PUTCONN:
        silo.put_zonelist_2(zonelist_name, len(pair_edges), 2, nodelist,
                            0,0, shapetypes, shapesizes, shapecounts)
    if PUTMESH:
        silo.put_ucdmesh("foo", [],
                     np.asarray(X.T,order="C"), len(pair_edges),
                     zonelist_name, None)
    def putvar(n,fo,LOC):
        if len(f.shape)==1 or f.shape[1]==1:
            silo.put_ucdvar1("node_"+n,"foo",
                             np.asarray(f,order="C",dtype=np.double),
                             LOC, {DBOPT_CYCLE:cycle,DBOPT_DTIME:float(time),DBOPT_TIME:float(time)})
        elif f.shape[1]==2:
            silo.put_ucdvar("node_"+n,"foo", [n+"x",n+"y"],
                            np.asarray(f.T,order="C",dtype=np.double),
                            LOC, {DBOPT_CYCLE:cycle,DBOPT_DTIME:float(time),DBOPT_TIME:float(time)})
        else:
            silo.put_ucdvar("node_"+n,"foo", [n+"x",n+"y",n+"z"],
                            np.asarray(f.T,order="C",dtype=np.double),
                            LOC,  {DBOPT_CYCLE:cycle,DBOPT_DTIME:float(time),DBOPT_TIME:float(time)})
   
    for n,f in nodefields:
        putvar(n,f,DB_NODECENT)
    for n,f in edgefields:
        putvar(n,f,DB_ZONECENT)

    silo.close()
def silo_write_meshfile(fname, X, elems):
    try:
        from pyvisfile.silo import SiloFile, IntVector, DB_ZONETYPE_BEAM, DB_ZONETYPE_HEX, \
            DB_NODECENT, DB_ZONECENT, DBOPT_CYCLE, DBOPT_DTIME, DBOPT_TIME, DB_CLOBBER
    except ImportError:
        print("Need PyVisFile to write silo files. Use vtk for now.")
        raise
    import numpy as np

    silo = SiloFile(fname, mode=DB_CLOBBER)

    # TODO: Check to see if it should be connections or bricks
    zonelist_name = "foo_zonelist"
    nodelist = IntVector()
    nodelist.extend(int(i) for i in elems[:, :].flat)
    shapetypes = IntVector()
    if elems.shape[1] == 2:
        shapetypes.append(DB_ZONETYPE_BEAM)
    elif elems.shape[1] == 8:
        shapetypes.append(DB_ZONETYPE_HEX)
    shapesizes = IntVector()
    shapesizes.append(elems.shape[1])
    shapecounts = IntVector()
    shapecounts.append(len(elems))
    silo.put_zonelist_2(zonelist_name, len(elems), 2, nodelist, 0, 0,
                        shapetypes, shapesizes, shapecounts)
    silo.put_ucdmesh("foo", [], np.asarray(X.T, order="C"), len(elems),
                     zonelist_name, None)
    silo.close()
    print("Wrote file " + fname)