Skip to content
Snippets Groups Projects
Commit 65432bfb authored by Franck Pérignon's avatar Franck Pérignon
Browse files

update printer for parallel output

parent a9aff277
No related branches found
No related tags found
No related merge requests found
...@@ -30,12 +30,12 @@ class Printer(Monitoring): ...@@ -30,12 +30,12 @@ class Printer(Monitoring):
Monitoring.__init__(self, fields, frequency, name="Printer") Monitoring.__init__(self, fields, frequency, name="Printer")
## output file name prefix ## output file name prefix
if prefix is None: if prefix is None:
self.prefix = './out_' + str(main_rank) self.prefix = './out_'
else: else:
self.prefix = prefix + str(main_rank) self.prefix = prefix
## Extension for filename ## Extension for filename
if ext is None: if ext is None:
self.ext = '.vtk' self.ext = ''
else: else:
self.ext = ext self.ext = ext
self.input = fields self.input = fields
...@@ -67,8 +67,10 @@ class Printer(Monitoring): ...@@ -67,8 +67,10 @@ class Printer(Monitoring):
def _build_vtk_dict(self): def _build_vtk_dict(self):
"""Build a dictionary from fields to VTK image.""" """Build a dictionary from fields to VTK image."""
res = {} res = {}
for f in self.variables: for f in self.variables:
for df in f.discreteFields.values(): for df in f.discreteFields.values():
#ind = df.topology.mesh.iCompute
if f.isVector: if f.isVector:
for d in xrange(len(df.data)): for d in xrange(len(df.data)):
if len(df.data[d].shape) == 2: if len(df.data[d].shape) == 2:
...@@ -113,12 +115,22 @@ class Printer(Monitoring): ...@@ -113,12 +115,22 @@ class Printer(Monitoring):
except AttributeError: except AttributeError:
pass pass
# Set output file name # Set output file name
filename = self.prefix + '_it_' + str(ite) + self.ext filename = self.prefix + 'iter_' + str(ite)
filename += '_' + str(main_rank) + self.ext
print "Print to file " + filename print "Print to file " + filename
## VTK output \todo: Need fix in 2D, getting an IOError. ## VTK output \todo: Need fix in 2D, getting an IOError.
try: try:
orig = self.variables[0].discreteFields.values()[0].topology.mesh.global_start #orig = self.variables[0].discreteFields.values()[0].topology.mesh.global_start
evtk.imageToVTK(filename, origin=(orig[0], orig[1], orig[2]), pointData=self._build_vtk_dict()) topo = self.variables[0].discreteFields.keys()[0]
orig = tuple([topo.mesh.origin[i]
for i in xrange(topo.mesh.dim)])
coords = topo.mesh.coords
ind = topo.mesh.local_start
orig = tuple([topo.mesh.coords[i].flatten()[ind[i]]
for i in xrange(topo.mesh.dim)])
spacing = tuple(topo.mesh.space_step)
evtk.imageToVTK(filename, origin=orig, spacing=spacing,
pointData=self._build_vtk_dict()))
except IOError: except IOError:
if self.variables[0].domain.dimension == 2: if self.variables[0].domain.dimension == 2:
## Standard output ## Standard output
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment