Exemplo n.º 1
0
def _write_vtu_series(grid, coordinates, connectivity, data, filename_base, last_step, is_cell_data):
    steps = last_step + 1 if last_step is not None else len(data)
    fn_tpl = "{}_{:08d}"

    npoints = len(coordinates[0])
    ncells = len(connectivity)

    ref = grid.reference_element
    if ref is ref is referenceelements.triangle:
        points_per_cell = 3
        vtk_el_type = VtkTriangle.tid
    elif ref is referenceelements.square:
        points_per_cell = 4
        vtk_el_type = VtkQuad.tid
    else:
        raise NotImplementedError("vtk output only available for grids with triangle or rectangle reference elments")

    connectivity = connectivity.reshape(-1)
    cell_types = np.empty(ncells, dtype='uint8')
    cell_types[:] = vtk_el_type
    offsets = np.arange(start=points_per_cell, stop=ncells*points_per_cell+1, step=points_per_cell, dtype='int32')

    group = VtkGroup(filename_base)
    for i in range(steps):
        fn = fn_tpl.format(filename_base, i)
        vtk_data = data[i, :]
        w = VtkFile(fn, VtkUnstructuredGrid)
        w.openGrid()
        w.openPiece(ncells=ncells, npoints=npoints)

        w.openElement("Points")
        w.addData("Coordinates", coordinates)
        w.closeElement("Points")
        w.openElement("Cells")
        w.addData("connectivity", connectivity)
        w.addData("offsets", offsets)
        w.addData("types", cell_types)
        w.closeElement("Cells")
        if is_cell_data:
            _addDataToFile(w, cellData={"Data": vtk_data}, pointData=None)
        else:
            _addDataToFile(w, cellData=None, pointData={"Data": vtk_data})

        w.closePiece()
        w.closeGrid()
        w.appendData(coordinates)
        w.appendData(connectivity).appendData(offsets).appendData(cell_types)
        if is_cell_data:
            _appendDataToFile(w, cellData={"Data": vtk_data}, pointData=None)
        else:
            _appendDataToFile(w, cellData=None, pointData={"Data": vtk_data})

        w.save()
        group.addFile(filepath=fn, sim_time=i)
    group.save()
Exemplo n.º 2
0
def run():
    print("Running group...")
    g = VtkGroup(FILE_PATH)
    g.addFile(filepath="sim0000.vtu", sim_time=0.0)
    g.addFile(filepath="sim0001.vtu", sim_time=1.0)
    g.addFile(filepath="sim0002.vtu", sim_time=2.0)
    g.addFile(filepath="sim0003.vtu", sim_time=3.0)
    g.save()
Exemplo n.º 3
0
    def __init__(self, path, mesh, submesh):
        '''Prebuild and then only receive data'''
        comm = mesh.mpi_comm()
        rank = comm.rank
        size = comm.size

        dirname, basaname = os.path.dirname(path), os.path.basename(path)
        if dirname:
            not os.path.exists(dirname) and comm.rank == 0 and os.mkdir(
                dirname)

        local_has_piece = np.zeros(comm.size, dtype=bool)

        if submesh.num_cells() == 0:
            self.write_vtu_piece = lambda data, counter, path=path, rank=rank, size=size: (
                "%s_p%d_of%d_%06d.vtu" % (path, rank, size, counter))
        else:
            local_has_piece[comm.rank] = True

            x, y, z = map(np.array, submesh.coordinates().T)
            cells = submesh.cells()
            ncells, nvertices_cell = cells.shape
            assert nvertices_cell == 3

            connectivity = cells.flatten()
            offsets = np.cumsum(np.repeat(3, ncells))
            connectivity = connectivity.astype(offsets.dtype)
            cell_types = VtkTriangle.tid * np.ones(ncells)

            self.write_vtu_piece = lambda data, counter, path=path, rank=rank, size=size: (
                unstructuredGridToVTK("%s_p%d_of%d_%06d" %
                                      (path, rank, size, counter),
                                      x,
                                      y,
                                      z,
                                      connectivity,
                                      offsets,
                                      cell_types,
                                      cellData=data))
        # Root will write the group file
        global_has_piece = sum(comm.allgather(local_has_piece),
                               np.zeros_like(local_has_piece))
        self.has_piece, = np.where(global_has_piece)
        # Only other piece to remember is for parallel writeing on root
        self.counter = 0  # Of times write_vtu_piece was called
        self.path = path
        self.world_rank = comm.rank
        self.world_size = comm.size

        # Also group file goes into the directory
        self.world_rank == 0 and setattr(self, 'group', VtkGroup(path))
Exemplo n.º 4
0
def _write_vtu_series(grid, coordinates, connectivity, data, filename_base, last_step, is_cell_data):
    steps = last_step + 1 if last_step is not None else len(data)
    fn_tpl = "{}_{:08d}"

    npoints = len(coordinates[0])
    ncells = len(connectivity)

    ref = grid.reference_element
    if ref is ref is referenceelements.triangle:
        points_per_cell = 3
        vtk_el_type = VtkTriangle.tid
    elif ref is referenceelements.square:
        points_per_cell = 4
        vtk_el_type = VtkQuad.tid
    else:
        raise NotImplementedError("vtk output only available for grids with triangle or rectangle reference elments")

    connectivity = connectivity.reshape(-1)
    cell_types = np.empty(ncells, dtype='uint8')
    cell_types[:] = vtk_el_type
    offsets = np.arange(start=points_per_cell, stop=ncells*points_per_cell+1, step=points_per_cell, dtype='int32')

    group = VtkGroup(filename_base)
    for i in range(steps):
        fn = fn_tpl.format(filename_base, i)
        vtk_data = data[i, :]
        w = VtkFile(fn, VtkUnstructuredGrid)
        w.openGrid()
        w.openPiece(ncells=ncells, npoints=npoints)

        w.openElement("Points")
        w.addData("Coordinates", coordinates)
        w.closeElement("Points")
        w.openElement("Cells")
        w.addData("connectivity", connectivity)
        w.addData("offsets", offsets)
        w.addData("types", cell_types)
        w.closeElement("Cells")
        if is_cell_data:
            _addDataToFile(w, cellData={"Data": vtk_data}, pointData=None)
        else:
            _addDataToFile(w, cellData=None, pointData={"Data": vtk_data})

        w.closePiece()
        w.closeGrid()
        w.appendData(coordinates)
        w.appendData(connectivity).appendData(offsets).appendData(cell_types)
        if is_cell_data:
            _appendDataToFile(w, cellData={"Data": vtk_data}, pointData=None)
        else:
            _appendDataToFile(w, cellData=None, pointData={"Data": vtk_data})

        w.save()
        group.addFile(filepath=fn + '.vtu', sim_time=i)
    group.save()
Exemplo n.º 5
0
# create a sub-directory for the output .vtu files
outputdir = os.path.join(inputdir,fileprefix)
try:
    os.mkdir(outputdir)
except:
    pass

# Read in the dump file - since we can have many contacts (i.e. >> nparticles)
# and many timesteps I will deal with one timestep at a time in memory,
# write to the appropriate .vtu file for a single timestep, then move on.

forcedata = bdump(filename,0)

groupfile = fileprefix
groupfile = os.path.join(inputdir,groupfile)
groupfile = VtkGroup(groupfile)

fileindex = 0
timestep = forcedata.next()

# check that we have the right number of colums (>11)
#
# NOTE: the first timesteps are often blank, and then natoms returns 0, so this doesn't really work...
#
if forcedata.snaps[fileindex].natoms !=0 and len(forcedata.snaps[0].atoms[0]) < 12:
    print "Error - dump file requires at least all parameters from a compute pair/gran/local id pos force (12 in total)"
    sys.exit()

# loop through available timesteps
#
while timestep >= 0:
Exemplo n.º 6
0
# *                                                                                 *
# *  2. Redistributions in binary form must reproduce the above copyright notice,   *
# *  this list of conditions and the following disclaimer in the documentation      *
# *  and/or other materials provided with the distribution.                         *
# *                                                                                 *
# * THIS SOFTWARE IS PROVIDED BY PAULO A. HERRERA ``AS IS'' AND ANY EXPRESS OR      *
# * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF    *
# * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO      *
# * EVENT SHALL <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,        *
# * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,  *
# * BUT NOT LIMITED TO, PROCUREMEN OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,    *
# * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY           *
# * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING  *
# * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS              *
# * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                    *
# ************************************************************************

# **************************************************************
# * Example of how to create a VTK group to visualize time     *
# * dependent data.                                            *
# **************************************************************

from evtk.vtk import VtkGroup

g = VtkGroup("./group")
g.addFile(filepath="sim0000.vtu", sim_time=0.0)
g.addFile(filepath="sim0001.vtu", sim_time=1.0)
g.addFile(filepath="sim0002.vtu", sim_time=2.0)
g.addFile(filepath="sim0003.vtu", sim_time=3.0)
g.save()
Exemplo n.º 7
0
# create a sub-directory for the output .vtu files
outputdir = os.path.join(inputdir, fileprefix)
try:
    os.mkdir(outputdir)
except:
    pass

# Read in the dump file - since we can have many contacts (i.e. >> nparticles)
# and many timesteps I will deal with one timestep at a time in memory,
# write to the appropriate .vtu file for a single timestep, then move on.

forcedata = bdump(filename, 0)

groupfile = fileprefix
groupfile = os.path.join(inputdir, groupfile)
groupfile = VtkGroup(groupfile)

fileindex = 0
timestep = forcedata.next()

# check that we have the right number of colums (>11)
#
# NOTE: the first timesteps are often blank, and then natoms returns 0, so this doesn't really work...
#
if forcedata.snaps[fileindex].natoms != 0 and len(
        forcedata.snaps[0].atoms[0]) < 12:
    print "Error - dump file requires at least all parameters from a compute pair/gran/local id pos force (12 in total)"
    sys.exit()

# loop through available timesteps
#
Exemplo n.º 8
0
    # create a sub-directory for the output .vtu files
    outputdir = os.path.join(inputdir, fileprefix)
    try:
        os.mkdir(outputdir)
    except:
        pass

    # Read in the dump file - since we can have many contacts (i.e. >> nparticles)
    # and many timesteps I will deal with one timestep at a time in memory,
    # write to the appropriate .vtu file for a single timestep, then move on.

    forcedata = dump(filename, 0)

    groupfile = fileprefix
    groupfile = os.path.join(inputdir, groupfile)
    groupfile = VtkGroup(groupfile)

    fileindex = 0
    timestep = forcedata.next()

    # check that we have the right number of colums (>11)
    #
    # NOTE: the first timesteps are often blank, and then natoms returns 0, so this doesn't really work...
    #
    #if forcedata.snaps[fileindex].natoms !=0 and len(forcedata.snaps[0].atoms[0]) < 11:
    #    print "Error - dump file requires at least all parameters from a compute pair/gran/local id pos force (12 in total)"
    #    sys.exit()

    # loop through available timesteps

    while timestep >= 0:
Exemplo n.º 9
0
 name = time.strftime('%b-%d-%Y-%H.%M')
 import os, errno
 home = os.environ['HOME']
 filepath = home + '/spinr/output/' + str(
     instance.atlas[-15:-4]) + '-' + str(instance.p.task_id)
 try:
     print 'trying to create dir', filepath
     os.makedirs(filepath)
 except OSError, e:
     if e.errno != errno.EEXIST:
         raise
 # from matplotlib.backends.backend_pdf import PdfPages
 #from pylab import plot,figure,title,close,imshow
 # import matplotlib.pyplot as plt
 print 'creating group file'
 g = VtkGroup(filepath + "/group" + name)
 print 'finished creating group file'
 # i=0
 # pdf = PdfPages('Density_and_Conductivity'+name+'.pdf')
 sweep_range = 400
 transmissions = np.zeros(sweep_range, dtype=complex128)
 print 'Setting mode to graph'
 instance.setmode('spin_graph')
 print 'done setting mode to spin_graph'
 # shift = -140
 #charge = 8
 slope = 0
 for i in range(sweep_range):
     print '---------------------------------------------------------'
     print 'Step Number: ', i
     print '---------------------------------------------------------'
Exemplo n.º 10
0
#NOTE: In order for this to work it needs a folder called 'meshes' in the directory where this file is located.


def saveVTK(filename, i, j):
    ind = numpy.arange(0, len(i)*len(j), dtype = 'uint32')
    temp = numpy.zeros((1), dtype = 'int32')

    def fun(x,y):
        array = numpy.zeros((len(x),len(y)))
        for i in range(len(x)):
            array[i, :] = x[i]*y

        return array

    dictionary = {'whatever': fun(i,j)[:,None]}
    evtk.gridToVTK(filename, i, j, temp, pointData = dictionary)

i = numpy.arange(2, 10.5, 0.5)
j = numpy.arange(-4, 4.5, 0.5)
saveVTK("./meshes/test-1", i,j)

i = numpy.arange(2, 5.25, 0.25)
j = numpy.arange(-4, 4.25, 0.25)
saveVTK("./meshes/test-2", i,j)

g = VtkGroup("./group")
g.addFile(filepath = "./meshes/test-1.vtr", sim_time = 0.0)
g.addFile(filepath = "./meshes/test-2.vtr", sim_time = 0.0)
g.save()