#!/usr/bin/python

import sys
import os
import os.path
import subprocess
sys.path.insert(0, '/usr/lib/python2.7/site-packages')
from FreeFOAM.compat import *
import FreeFOAM.tutorial

class rhoPorousMRFPimpleMixerVessel2DRunner(FreeFOAM.tutorial.CaseRunner):
   def __init__(self):
      FreeFOAM.tutorial.CaseRunner.__init__(self, 'rhoPorousMRFPimple_mixerVessel2D')
      self.add_step('prepareBlockMeshDict', self._prepareMesh)
      self.add_app_step('blockMesh')
      self.add_app_step('rhoPorousMRFPimple')

   def _prepareMesh(self, case_dir, stamp_file, test_mode):
      blockMeshDict = os.path.join(case_dir, 'constant', 'polyMesh',
            'blockMeshDict')
      try:
         stat = subprocess.call('/usr/bin/m4',
               stdin=open(blockMeshDict+'.m4', 'rt'),
               stdout=open(blockMeshDict, 'wt')) == 0
         stamp_file.write('Created blockMeshDict\n')
      except Exception:
         e = sys.exc_info()[1]
         stat = False
         stamp_file.write('*** Error *** Creating blockMeshDict:\n'+str(e))
      stamp_file.write('REPORT: ')
      if stat:
         stamp_file.write('SUCCESS\n')
      else:
         stamp_file.write('FAILURE\n')
      return stat

if __name__ == '__main__':
   os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
   runner = FreeFOAM.tutorial.TutorialRunner()
   runner.add_case(rhoPorousMRFPimpleMixerVessel2DRunner())
   sys.exit(runner.main())

# ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file
