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()
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()
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()
# and contact area # w.openData("Cell") # w.addData("area", area) # w.closeData("Cell") # and heat flux # w.openData("Cell") # w.addData("heatflux", heatflux) # w.closeData("Cell") # Wrap up w.closePiece() w.closeGrid() # Append binary data w.appendData( (x,y,z) ) w.appendData(connections).appendData(offset).appendData(celltype) w.appendData(forceClean).appendData(connectionLengthClean) w.save() # Add this file to the group of all timesteps groupfile.addFile(filepath = os.path.relpath(vtufile,inputdir), sim_time = timestep) fileindex += 1 timestep = forcedata.next() # end of main loop - close group file groupfile.save()
# * * # * 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()
# and contact area # w.openData("Cell") # w.addData("area", area) # w.closeData("Cell") # and heat flux # w.openData("Cell") # w.addData("heatflux", heatflux) # w.closeData("Cell") # Wrap up w.closePiece() w.closeGrid() # Append binary data w.appendData((x, y, z)) w.appendData(connections).appendData(offset).appendData(celltype) w.appendData(forceClean).appendData(connectionLengthClean) w.save() # Add this file to the group of all timesteps groupfile.addFile(filepath=os.path.relpath(vtufile, inputdir), sim_time=timestep) fileindex += 1 timestep = forcedata.next() # end of main loop - close group file groupfile.save()
del edens try: del spindens except NameError: pass t = instance.transmission(instance.grl) transmissions[i] = t np.save(filepath + '/' + name + '_transmission', transmissions) print 'Calculated transmission: ', t del instance.grl transmissions[i] = t gc.collect() #dens = instance.dorrgm(energy_multi*instance.t0) #dens = -dens.imag/(instance.a**2)*instance.fermifunction(energy_multi*instance.t0, instance.mu) #intdens = intdens + spindens g.addFile(filepath=filename + '.vtr', sim_time=i) # plt.figure(figsize=(3,3)) # plt.imshow(edens) # plt.colorbar() # plt.title('Page '+str(i)) # pdf.savefig() #close() # i+=1 g.save() # plt.figure(figsize=(3,3)) # plt.plot(transmissions) # pdf.savefig() # pdf.close() #import pudb; pudb.set_trace() return transmissions
#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()