tCheck if some output VTK file exist before writing all again - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
 (HTM) git clone git://src.adamsgaard.dk/sphere
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit c9b37d904623542765501b38f1d70f86951140d0
 (DIR) parent 500151199d40152b6de6a8c894a3c268b2f1a047
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       Date:   Mon,  2 Sep 2019 10:06:07 +0200
       
       Check if some output VTK file exist before writing all again
       
       Diffstat:
         M python/sphere.py                    |      51 ++++++++++++++++++++-----------
       
       1 file changed, 33 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/python/sphere.py b/python/sphere.py
       t@@ -1,5 +1,6 @@
        #!/usr/bin/env python
        import math
       +import os
        import numpy
        try:
            import matplotlib
       t@@ -1613,21 +1614,37 @@ class sim:
                :param forces: Write contact force files (slow) (default=False)
                :type forces: bool
                '''
       -        lastfile=status(self.sid)
       -        sb=sim(fluid=self.fluid)
       +        lastfile = status(self.sid)
       +        sb = sim(fluid=self.fluid)
                for i in range(lastfile+1):
       -            fn="../output/{0}.output{1:0=5}.bin".format(self.sid, i)
       -            sb.sid=self.sid + ".{:0=5}".format(i)
       +            fn = "../output/{0}.output{1:0=5}.bin".format(self.sid, i)
       +
       +            # check if output VTK file exists and if it is newer than spherebin
       +            fn_vtk = "../output/{0}.{1:0=5}.vtu".format(self.sid, i)
       +            if os.path.isfile(fn_vtk) and \
       +                (os.path.getmtime(fn) < os.path.getmtime(fn_vtk)):
       +                if verbose:
       +                    print('skipping ' + fn_vtk +
       +                          ': file exists and is newer than ' + fn)
       +                if self.fluid:
       +                    fn_vtk = "../output/fluid-{0}.{1:0=5}.vti".format(
       +                             self.sid, i)
       +                    if os.path.isfile(fn_vtk) and \
       +                        (os.path.getmtime(fn) < os.path.getmtime(fn_vtk)):
       +                        if verbose:
       +                            print('skipping ' + fn_vtk +
       +                                  ': file exists and is newer than ' + fn)
       +                        continue
       +                else:
       +                    continue
       +
       +            sb.sid = self.sid + ".{:0=5}".format(i)
                    sb.readbin(fn, verbose=False)
                    if sb.np > 0:
       -                if i == 0:
       -                    sb.writeVTK(verbose=verbose)
       -                    if forces:
       -                        sb.findContactStresses()
       -                        sb.writeVTKforces(verbose=verbose)
       -                elif i == lastfile:
       -                    if verbose:
       -                        print("\tto")
       +                if i == 0 or i == lastfile:
       +                    if i == lastfile:
       +                        if verbose:
       +                            print("\tto")
                            sb.writeVTK(verbose=verbose)
                            if forces:
                                sb.findContactStresses()
       t@@ -1638,12 +1655,10 @@ class sim:
                                sb.findContactStresses()
                                sb.writeVTKforces(verbose=False)
                    if self.fluid:
       -                if i == 0:
       -                    sb.writeFluidVTK(verbose=verbose,
       -                            cell_centered=cell_centered)
       -                elif (i == lastfile):
       -                    if verbose:
       -                        print("\tto")
       +                if i == 0 or i == lastfile:
       +                    if i == lastfile:
       +                        if verbose:
       +                            print("\tto")
                            sb.writeFluidVTK(verbose=verbose,
                                    cell_centered=cell_centered)
                        else: