#!/usr/bin/env python
# 
# This example shows is like the readers and writers example ('io.py'),
# but this one also calculates some statistics on the elapsed time, the
# number of vertices an cells read, etc.

from __future__ import print_function

# In this example, we will set up a domain of triangles in the cartesian 3D
# space from the contents of a Netgen mesh file.
# 
# For that purpose, we need to define a domain and, eventually, also a segmentation
# (in case we want to read segmentation data from the mesh file), and we need the
# Netgen reader function, too.
# 
# (Notice that the 'read_netgen' function and all other I/O functions
# work with any type of domain and segmentation without name change.)

from viennagrid.wrapper import TriangularCartesian3D_Domain as Domain
from viennagrid.wrapper import TriangularCartesian3D_Segmentation as Segmentation
from viennagrid.wrapper import read_netgen

import time

# In case we want to read only the domain information from the mesh file, we would
# just create an empty domain and call the Netgen reader on it with the file path
# where the mesh file can be found.

domain = Domain()

start_time = time.time()

read_netgen('../data/half-trigate.mesh', domain)

end_time = time.time()
elapsed_time = end_time - start_time

print('Elapsed time: ', elapsed_time, ' seconds (', elapsed_time / 60, ')', sep='')
print('Read domain with', domain.num_vertices, 'vertices')

# 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)

start_time = time.time()

read_netgen('../data/half-trigate.mesh', domain, segmentation)

end_time = time.time()
elapsed_time = end_time - start_time

print('Elapsed time: ', elapsed_time, ' seconds (', elapsed_time / 60, ')', sep='')
print('Read domain with', domain.num_vertices, 'vertices')
print('Read segmentation with', segmentation.num_segments, 'segmets')
for i, seg in enumerate(segmentation.segments):
	print('Segment #', i, ' contains ', seg.num_cells, ' cells', sep='')

Create a copy of the Netgen reader example and add some statistics calculation.
Create a copy of the Netgen reader example and add some statistics calculation.

These additions calculate the elapsed time (the time that the reader has taken in order to read the mesh file), the number of vertices in the domain and the number of cells in the segmentation (if applicable).
