def runSeries(job, cases=[1, 2, 3], results_collector=''):
    """
    The main public function of the module.
    'job' parameter is a string formatted as [remoteComputerName:]pathToInputFile
    The function runs a series of simulations for automatically refined resolutions.
    The jobs are sent in forms of single cases to remote servers, if the name of the computer is provided in the job name.
    The function should only be runned on the main computer collecting data.
    """
    remote_computer = ''
    if ':' in job:
        remote_computer, testFile = job.split(':')
    else:
        testFile = job
    testFile = os.path.abspath(testFile)
    testDir = os.path.split(testFile)[0]
    solver = pproc.determineSolver(testFile)
    testName = os.path.split(os.path.splitext(testFile)[0])[1]
    for case in cases:
        logInScreen('{} {}/{}'.format(testName, case, len(cases)),
                    computer=remote_computer or local_computer,
                    solver=solver)
        if remote_computer:
            copyInputRemote(testDir, remote_computer)
            subprocess.call(
                'ssh -t {} runsolvers.py {} {} --results_collector {}'.format(
                    remote_computer, testFile, case, local_computer),
                shell=True)  #thanks to -t, output appears immediately
        else:
            runCase(testFile, case, results_collector=results_collector)

    if not results_collector:  #do the plotting on the local machine, to take into account result of the previous simulations
        if 'runup' in testFile or 'propagation' in testFile:
            pproc.plotCollections(testDir)
        elif 'moving' in testFile or 'cylinder' in testFile:
            xsections.cylinder()
Example #2
0
def runSeries(job,cases=[1,2,3],results_collector=''):
    """
    The main public function of the module.
    'job' parameter is a string formatted as [remoteComputerName:]pathToInputFile
    The function runs a series of simulations for automatically refined resolutions.
    The jobs are sent in forms of single cases to remote servers, if the name of the computer is provided in the job name.
    The function should only be runned on the main computer collecting data.
    """
    remote_computer = ''
    if ':' in job:
        remote_computer,testFile = job.split(':')
    else:
        testFile = job
    testFile = os.path.abspath( testFile )
    testDir = os.path.split(testFile)[0]
    solver = pproc.determineSolver(testFile)
    testName = os.path.split( os.path.splitext(testFile)[0] )[1]
    for case in cases:
        logInScreen('{} {}/{}'.format(testName,case,len(cases)),computer=remote_computer or local_computer,solver=solver)
        if remote_computer:
            copyInputRemote(testDir,remote_computer)
            subprocess.call('ssh -t {} runsolvers.py {} {} --results_collector {}'.format(remote_computer,testFile,case,local_computer),shell=True)  #thanks to -t, output appears immediately
        else:
            runCase(testFile,case,results_collector=results_collector)

    if not results_collector: #do the plotting on the local machine, to take into account result of the previous simulations
        if 'runup' in testFile or 'propagation' in testFile:
            pproc.plotCollections(testDir)
        elif 'moving' in testFile or 'cylinder' in testFile:
            xsections.cylinder()
Example #3
0
def runCase(job,case,results_collector=''):
    """
    Runs a single simulation on a local machine.
    job is a string of the format 'path_to_the_case_file[!name_of_the_remote_compouter]'
    If the optional remote_computer is provided, the results are sent to the remote computer and removed from the local machine.
    """
    testFile = os.path.abspath(job)
    solver = pproc.determineSolver(testFile)
    if not os.path.exists(testFile) or os.path.splitext(testFile)[1]!=inputExt[solver]:
        sys.exit("Please provide a {} {} case file as an argument".format(solver,inputExt[solver]))
        
    testDir,testName = os.path.split( os.path.splitext(testFile)[0] )
    
    print 'Running {}, case {}, on {}'.format(testFile,case,local_computer)
    sys.stdout.flush()
    caseDir = run[solver](testFile, testDir, testName, case)

    if 'propagation' in testDir or 'runup' in testDir or 'stillwater' in testDir:
        pproc.postprocess(caseDir)
    elif 'moving' in testDir or 'cylinder' in testDir:
        pproc.postprocess1phase(caseDir)
    
    os.chdir(testDir)

    if results_collector:
        r = copyRemote(caseDir,results_collector,force_remove=True) #copying results from a single case dir

        #cleanup
        if not r:
            shutil.rmtree(caseDir)
        removeInput(testDir)
        if not os.listdir(testDir): #empty dir
            os.chdir(os.path.split(testDir)[0])
            shutil.rmtree(testDir)
def removeInput(path):
    """
    Removes input files in the given directory
    """
    path = os.path.abspath(path)
    solver = pproc.determineSolver(path)
    for pattern in inputPatterns[solver]:
        for obj in glob(os.path.join(path, pattern)):
            subprocess.call('rm -r ' + obj, shell=True)
Example #5
0
def removeInput(path):
    """
    Removes input files in the given directory
    """
    path = os.path.abspath(path)
    solver = pproc.determineSolver(path)
    for pattern in inputPatterns[solver]:
        for obj in glob(os.path.join(path,pattern)):
            subprocess.call('rm -r '+obj,shell=True)
Example #6
0
def logInScreen(job,computer='',ending='',solver=None):
    """
    Changes the name of the currently used screen, for information purposes.
    """
    solver = solver or pproc.determineSolver()
    solver = solverShort[solver]
    screenCommand = 'screen -X title \"{}\"'.format(' '.join([solver,job,compNameShort[computer],ending]))
    if os.getenv('STY'): #env var giving the name of the screen session
        subprocess.call(screenCommand,shell=True)
def logInScreen(job, computer='', ending='', solver=None):
    """
    Changes the name of the currently used screen, for information purposes.
    """
    solver = solver or pproc.determineSolver()
    solver = solverShort[solver]
    screenCommand = 'screen -X title \"{}\"'.format(' '.join(
        [solver, job, compNameShort[computer], ending]))
    if os.getenv('STY'):  #env var giving the name of the screen session
        subprocess.call(screenCommand, shell=True)
def copyInputRemote(source, target):
    """
    Copies the input found below the source directory to the target maching.
    Retains the directory structure.
    """
    source = os.path.abspath(source)
    solver = pproc.determineSolver(source)
    for i in range(10):
        if glob(os.path.join(source, i * '*/', '*' + inputExt[solver])):
            for pattern in inputPatterns[solver]:
                for path in glob(os.path.join(source, i * '*/', pattern)):
                    copyRemote(path, target, force_remove=True)
            break
Example #9
0
def copyInputRemote(source,target):
    """
    Copies the input found below the source directory to the target maching.
    Retains the directory structure.
    """
    source = os.path.abspath(source)
    solver = pproc.determineSolver(source)
    for i in range(10):
        if glob(os.path.join(source,i*'*/','*'+inputExt[solver])):
            for pattern in inputPatterns[solver]:
                for path in glob(os.path.join(source,i*'*/',pattern)):
                    copyRemote(path, target,force_remove=True)
            break
    'Gerris': runGerrisCase,
    'OpenFOAM': runFoamCase,
    'Thetis': runThetisCase,
    'Truchas': runTruchasCase,
    'TruchasEnSight': runTruchas200Case
}


def runCase(job, case, results_collector=''):
    """
    Runs a single simulation on a local machine.
    job is a string of the format 'path_to_the_case_file[!name_of_the_remote_compouter]'
    If the optional remote_computer is provided, the results are sent to the remote computer and removed from the local machine.
    """
    testFile = os.path.abspath(job)
    solver = pproc.determineSolver(testFile)
    if not os.path.exists(
            testFile) or os.path.splitext(testFile)[1] != inputExt[solver]:
        sys.exit("Please provide a {} {} case file as an argument".format(
            solver, inputExt[solver]))

    testDir, testName = os.path.split(os.path.splitext(testFile)[0])

    print 'Running {}, case {}, on {}'.format(testFile, case, local_computer)
    sys.stdout.flush()
    caseDir = run[solver](testFile, testDir, testName, case)

    if 'propagation' in testDir or 'runup' in testDir or 'stillwater' in testDir:
        pproc.postprocess(caseDir)
    elif 'moving' in testDir or 'cylinder' in testDir:
        pproc.postprocess1phase(caseDir)