예제 #1
0
def main():
    path = tempfile.mkdtemp()
    try:
        silo = SiloFile(os.path.join(path, 'file.silo'))
        add_to_silo_file(silo, Mesh())
        silo.close()
    finally:
        shutil.rmtree(path)
예제 #2
0
def main():
    path = tempfile.mkdtemp()
    try:
        silo = SiloFile(os.path.join(path, 'file.silo'))
        add_to_silo_file(silo, Mesh())
        silo.close()
    finally:
        shutil.rmtree(path)
예제 #3
0
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)
예제 #4
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()
예제 #5
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()
예제 #6
0
    def make_file(self, pathname):
        """This function returns either a :class:`pyvisfile.silo.SiloFile` or a
        :class:`pyvisfile.silo.ParallelSiloFile`, depending on the ParallelContext
        under which we are running

        An extension of .silo is automatically appended to *pathname*.
        """
        if not self.generated:
            self._generate()

        if self.pcontext is None or len(self.pcontext.ranks) == 1:
            from pyvisfile.silo import SiloFile
            return SiloFile(pathname + ".silo")
        else:
            from pyvisfile.silo import ParallelSiloFile
            return ParallelSiloFile(pathname, self.pcontext.rank,
                                    self.pcontext.ranks)
예제 #7
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()
예제 #8
0
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)
예제 #9
0
def main():
    from pyvisfile.silo import SiloFile
    silo = SiloFile("out.silo")
    add_to_silo_file(silo, Mesh())
    silo.close()
예제 #10
0
hi_offset = [(1, 1), (0, 1), (1, 0), (0, 0)]

data_global[:20, :20] = 0.
data_global[20:, :20] = 1.
data_global[:20, 20:] = 2.
data_global[20:, 20:] = 3.

mesh_names = []
var_names = []

for i in range(4):

    file_name = 'example_%05d.silo' % i
    s = SiloFile(file_name,
                 mode=DB_CLOBBER,
                 filetype=DB_HDF5,
                 target=DB_LOCAL,
                 fileinfo='Example Silo %05d.' % i)

    axes = (x[x_from[i]:x_to[i]], y[y_from[i]:y_to[i]])

    # Copy necessary due to slicing!
    data = data_global[y_from[i]:y_to[i], x_from[i]:x_to[i]].copy()

    options = dict()
    options[DBOPT_CYCLE] = 99
    options[DBOPT_DTIME] = 0.99
    options[DBOPT_XLABEL] = 'X'
    options[DBOPT_YLABEL] = 'Y'
    options[DBOPT_XUNITS] = 'a'
    options[DBOPT_YUNITS] = 'b'
예제 #11
0
from __future__ import absolute_import
from __future__ import print_function
from pyvisfile.silo import SiloFile, DB_READ
db = SiloFile("qmesh.silo", create=False, mode=DB_READ)
print(db.get_toc().qmesh_names)
print(db.get_toc().qvar_names)

qmesh = db.get_quadmesh("meshxy")
print(qmesh.coords)
qvar = db.get_quadvar("value")
print(qvar.vals)

예제 #12
0
hi_offset = [(1, 1), (0, 1), (1, 0), (0, 0)]

data_global[:20, :20] = 0.
data_global[20:, :20] = 1.
data_global[:20, 20:] = 2.
data_global[20:, 20:] = 3.

mesh_names = []
var_names = []

for i in range(4):

    file_name = "example_%05d.silo" % i
    s = SiloFile(file_name,
            mode=DB_CLOBBER,
            filetype=DB_HDF5,
            target=DB_LOCAL,
            fileinfo=f"Example Silo {i:05d}.")

    axes = (x[x_from[i]:x_to[i]], y[y_from[i]:y_to[i]])

    # Copy necessary due to slicing!
    data = data_global[y_from[i]:y_to[i], x_from[i]:x_to[i]].copy()

    options = dict()
    options[DBOPT_CYCLE] = 99
    options[DBOPT_DTIME] = 0.99
    options[DBOPT_XLABEL] = "X"
    options[DBOPT_YLABEL] = "Y"
    options[DBOPT_XUNITS] = "a"
    options[DBOPT_YUNITS] = "b"
예제 #13
0
# Mark the Ghostzones (at least in one direction).
hi_offset = [(1, 1), (0, 1), (1, 0), (0, 0)]

data_global[:20, :20] = 0.
data_global[20:, :20] = 1.
data_global[:20, 20:] = 2.
data_global[20:, 20:] = 3.

mesh_names = []
var_names = []

for i in range(4):

    file_name = 'example_%05d.silo' % i
    s = SiloFile(file_name, mode=DB_CLOBBER, filetype=DB_HDF5, target=DB_LOCAL, fileinfo='Example Silo %05d.' % i)

    axes = (x[x_from[i]:x_to[i]], y[y_from[i]:y_to[i]])

    # Copy necessary due to slicing!
    data = data_global[y_from[i]:y_to[i], x_from[i]:x_to[i]].copy()

    options = dict()
    options[DBOPT_CYCLE] = 99
    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]
예제 #14
0
def main():
    from pyvisfile.silo import SiloFile
    silo = SiloFile("out.silo")
    add_to_silo_file(silo, Mesh())
    silo.close()
예제 #15
0
def test_silo_unstructured():
    from pyvisfile.silo import SiloFile

    silo = SiloFile("out.silo")
    add_to_silo_file(silo, Mesh())
    silo.close()