# of the accessor specifying the cell and the value that we want to assign to # the cell. for cell in domain.cells: cell_surface_accessor.set_value(cell, surface(cell)) # Now we want to read the value corresponding to each cell stored in the accessor. # Since the cells that have a value stored in the accessor are all the cells of the # domain, we simply iterate over the cells of the domain and get the value stored # in the accessor for that cell using the 'get_value' method of the accessor. for i, cell in enumerate(domain.cells): value = cell_surface_accessor.get_value(cell) print('Cell #%(i)d has surface %(value)f' % locals()) # Next, we want to write the mesh and the scalar data to a VTK file. To do that, # we must provide each accessor with a name for the data stored in it, preferrably # a descriptive name of what the data mean. # # Since we have stored the surface of the cells, we will call the data 'surface'. # Then, we create a dictionary associating the quantity name to the accessor that # stores that given quantity. Since we only have one accessor to save, this dictionary # will have only one key. accessors = {'surface': cell_surface_accessor} # Now we call the VTK write as in the I/O tutorial, but we also specify the dictionary # that contains all accessors that should be written to the file. write_vtk('tri2d_mesh_with_surface_data_no_segment', domain, accessors) # If you want to save the segmentation information, too, you must call the writer as # explained in the I/O tutorial, also specifying the segmentation: write_vtk('tri2d_mesh_with_surface_data', domain, segmentation, accessors)
# In case we want to read not only the domain information, but also the segmentation # information from the mesh file, we would have to create an empty domain and an # empty segmentation on that domain, and then call the Netgen reader. domain = Domain() segmentation = Segmentation(domain) read_netgen(file_path, domain, segmentation) ############## # VTK writer # ############## # In order to write a domain to a VTK file, you just have to call the VTK reader # specifying the file path and the domain to be written write_vtk('output_file.vtu', domain) # If you want to write the information of both a domain and a segmentation of that # domain, you have to specify the segmentation, too: write_vtk('output_file.vtu', domain, segmentation) ################# # OpenDX writer # ################# # The OpenDX writer works similarly to the VTK writer, but it doesn't support # segmentation, so you can only write the information contained in a domain: write_opendx('output_opendx_file.out', domain)