Exemple #1
0
def write_silo_datfile(fname,mname,cycle=0, time=0, nodefields=[], edgefields=[]):
    from pyvisfile.silo import SiloFile, IntVector, DB_ZONETYPE_BEAM,\
        DB_NODECENT, DB_ZONECENT, DBOPT_CYCLE, DBOPT_DTIME, DBOPT_TIME, DB_CLOBBER
    from pyvisfile.silo import DBObjectType as DBOBjectType
    import numpy as np
    silo = SiloFile(fname, mode=DB_CLOBBER)
    silo.put_multimesh('foo', [(mname+":foo",DBOBjectType.DB_UCDMESH)])
    def putvar(n,fo,LOC):
        if len(f.shape)==1 or f.shape[1]==1:
            silo.put_ucdvar1("node_"+n,"foo",
                             np.asarray(f.T,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_datafile(fname,
                        mname,
                        cycle=0,
                        time=0,
                        nodefields={},
                        cellfields={}):
    try:
        from pyvisfile.silo import SiloFile, IntVector, DB_ZONETYPE_BEAM,\
            DB_NODECENT, DB_ZONECENT, DBOPT_CYCLE, DBOPT_DTIME, DBOPT_TIME, DB_CLOBBER
        from pyvisfile.silo import DBObjectType as DBOBjectType
    except ImportError:
        print("Need PyVisFile to write silo files. Use vtk for now.")
        raise
    import numpy as np
    silo = SiloFile(fname, mode=DB_CLOBBER)
    silo.put_multimesh('foo', [(mname + ":foo", DBOBjectType.DB_UCDMESH)])

    def putvar(n, fo, LOC):
        if len(f.shape) == 1 or f.shape[1] == 1:
            silo.put_ucdvar1(
                "node_" + n, "foo", np.asarray(f.T, 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.iteritems():
        putvar(n, f, DB_NODECENT)
    for n, f in cellfields.iteritems():
        putvar(n, f, DB_ZONECENT)

    silo.close()
    print("Wrote file " + fname)
    mesh_names.append((file_name + ':' + mesh_name, DB_COLLINEAR))

    options = dict()
    options[DBOPT_UNITS] = 'unit'

    var_name = 'variable'
    s.put_quadvar1(var_name,
                   mesh_name,
                   data,
                   data.shape,
                   centering=DB_NODECENT,
                   optlist=options)
    var_names.append((file_name + ':' + var_name, DBObjectType.DB_QUADVAR))

options = dict()
options[DBOPT_CYCLE] = 99
options[DBOPT_DTIME] = 0.99
options[DBOPT_XLABEL] = 'xx'
options[DBOPT_YLABEL] = 'yy'
options[DBOPT_XUNITS] = 'a'
options[DBOPT_YUNITS] = 'b'

s = SiloFile('example.silo',
             mode=DB_CLOBBER,
             filetype=DB_HDF5,
             target=DB_LOCAL,
             fileinfo='Example Metadata.')

s.put_multimesh('mesh', mesh_names, optlist=options)
s.put_multivar('scalar', var_names, optlist=options)
Exemple #4
0
    options[DBOPT_HI_OFFSET] = hi_offset[i]

    mesh_name = "mesh"
    s.put_quadmesh(mesh_name, axes, coordtype=DB_COLLINEAR, optlist=options)
    mesh_names.append((f"{file_name}:{mesh_name}", DB_COLLINEAR))

    options = dict()
    options[DBOPT_UNITS] = "unit"

    var_name = "variable"
    s.put_quadvar1(var_name, mesh_name, data, data.shape,
            centering=DB_NODECENT, optlist=options)
    var_names.append((f"{file_name}:{mesh_name}", DBObjectType.DB_QUADVAR))

options = dict()
options[DBOPT_CYCLE] = 99
options[DBOPT_DTIME] = 0.99
options[DBOPT_XLABEL] = "xx"
options[DBOPT_YLABEL] = "yy"
options[DBOPT_XUNITS] = "a"
options[DBOPT_YUNITS] = "b"

s = SiloFile("example.silo",
        mode=DB_CLOBBER,
        filetype=DB_HDF5,
        target=DB_LOCAL,
        fileinfo="Example Metadata.")

s.put_multimesh("mesh", mesh_names, optlist=options)
s.put_multivar("scalar", var_names, optlist=options)
    options[DBOPT_DTIME] = 0.99
    options[DBOPT_XLABEL] = 'X'
    options[DBOPT_YLABEL] = 'Y'
    options[DBOPT_XUNITS] = 'a'
    options[DBOPT_YUNITS] = 'b'
    options[DBOPT_HI_OFFSET] = hi_offset[i]

    mesh_name = 'mesh'
    s.put_quadmesh(mesh_name, axes, coordtype=DB_COLLINEAR, optlist=options)
    mesh_names.append((file_name+':'+mesh_name, DB_COLLINEAR))

    options = dict()
    options[DBOPT_UNITS] = 'unit'

    var_name = 'variable'
    s.put_quadvar1(var_name, mesh_name, data, data.shape, centering=DB_NODECENT, optlist=options)
    var_names.append((file_name+':'+var_name, DBObjectType.DB_QUADVAR))

options = dict()
options[DBOPT_CYCLE] = 99
options[DBOPT_DTIME] = 0.99
options[DBOPT_XLABEL] = 'xx'
options[DBOPT_YLABEL] = 'yy'
options[DBOPT_XUNITS] = 'a'
options[DBOPT_YUNITS] = 'b'

s = SiloFile('example.silo', mode=DB_CLOBBER, filetype=DB_HDF5, target=DB_LOCAL, fileinfo='Example Metadata.')

s.put_multimesh('mesh', mesh_names, optlist=options)
s.put_multivar('scalar', var_names, optlist=options)