<commit_before>#!/usr/bin/env python

import glob
import sys
import os
import vtktools
import numpy
import pylab
from math import isinf
import re

def get_filelist():

    def key(s):
        return int(s.split('_')[-1].split('.')[0])
   
    list = glob.glob("*vtu")
    list = [l for l in list if 'check' not in l]
    vtu_nos = [float(s.split('_')[-1].split('.')[0]) for s in list]
    vals = zip(vtu_nos, list)
    vals.sort()
    unzip = lambda l:tuple(apply(zip,l))
    vtu_nos, list = unzip(vals)

    return list

#### taken from http://www.codinghorror.com/blog/archives/001018.html  #######
def tryint(s):
    try:
        return int(s)
    except:
        return s
    
def alphanum_key(s):
    """ Turn a string into a list of string and number chunks.
        "z23a" -> ["z", 23, "a"]
    """
    return [ tryint(c) for c in re.split('([0-9]+)', s) ]

def sort_nicely(l):
    """ Sort the given list in the way that humans expect.
    """
    l.sort(key=alphanum_key)
##############################################################################
# There are shorter and more elegant version of the above, but this works
# on CX1, where this test might be run...

###################################################################

# Reattachment length:
def reatt_length(filelist, yarray, exclude_initial_results):

  print "Calculating reattachment point locations using change of x-velocity sign\n"
  print "Processing output files...\n"
  nums=[]; results=[]
  files = []

  ##### check for no files
  if (len(filelist) == 0):
    print "No files!"
    sys.exit(1)
  for file in filelist:
    try:
      os.stat(file)
    except:
      print "No such file: %s" % file
      sys.exit(1)
    num = int(re.split("\.p?vtu", file)[0].split('_')[-1])
    ##### Exclude data from simulation spin-up time
    if num > exclude_initial_results:
        print file
        files.append(file)

  

  sort_nicely(files)

  for file in files:

    print file
    ##### Read in data from vtu
    datafile = vtktools.vtu(file)

    ##### points near bottom surface, 0 < x < 25
    x2array=[]; pts=[]; no_pts = 52; offset = 0.1
    x = 0.0
    for i in range(1, no_pts):
      x2array.append(x)
      for j in range(len(yarray)):
        pts.append((x, yarray[j], offset))
      x += 0.5

    x2array = numpy.array(x2array)
    pts = numpy.array(pts)

    ##### Get x-velocity on bottom boundary
    uvw = datafile.ProbeData(pts, "Velocity")
    u = uvw[:,0]
    u = u.reshape([x2array.size,yarray.size])

    ##### Find all potential reattachment points:
    points = []
    for j in range(len(u[0,:])):
      for i in range(len(u[:,0])-1):
        ##### Hack to ignore division by zero entries in u.
        ##### All u should be nonzero away from boundary!
        if((u[i,j] / u[i+1,j]) < 0. and not isinf(u[i,j] / u[i+1,j])):
          ##### interpolate between nodes
          p = x2array[i] + (x2array[i+1]-x2array[i]) * (0.0-u[i,j]) / (u[i+1,j]-u[i,j])
          ##### Ignore spurious corner points
          if(p>0.1):
            points.append(p)

    ##### This is the spanwise-averaged reattachment point:
    avpt = sum(points) / len(points)
    ##### Get time for plot:
    t = min(datafile.GetScalarField("Time"))
    results.append([avpt,t])

  return results

#########################################################################

# Velocity profiles:
def meanvelo(filelist,xarray,yarray,zarray):

  print "\nRunning velocity profile script on files at times...\n"
  ##### check for no files
  if (len(filelist) < 0):
    print "No files!"
    sys.exit(1)

  ##### create array of points
  pts=[]
  for i in range(len(xarray)):
    for j in range(len(yarray)):
      for k in range(len(zarray)):
        pts.append([xarray[i], yarray[j], zarray[k]])<commit_msg>numpy.isinf() available widely, math.isinf() not, hence changing this in the test.<commit_after>#!/usr/bin/env python

import glob
import sys
import os
import vtktools
import numpy
import pylab
import re

def get_filelist():

    def key(s):
        return int(s.split('_')[-1].split('.')[0])
   
    list = glob.glob("*vtu")
    list = [l for l in list if 'check' not in l]
    vtu_nos = [float(s.split('_')[-1].split('.')[0]) for s in list]
    vals = zip(vtu_nos, list)
    vals.sort()
    unzip = lambda l:tuple(apply(zip,l))
    vtu_nos, list = unzip(vals)

    return list

#### taken from http://www.codinghorror.com/blog/archives/001018.html  #######
def tryint(s):
    try:
        return int(s)
    except:
        return s
    
def alphanum_key(s):
    """ Turn a string into a list of string and number chunks.
        "z23a" -> ["z", 23, "a"]
    """
    return [ tryint(c) for c in re.split('([0-9]+)', s) ]

def sort_nicely(l):
    """ Sort the given list in the way that humans expect.
    """
    l.sort(key=alphanum_key)
##############################################################################
# There are shorter and more elegant version of the above, but this works
# on CX1, where this test might be run...

###################################################################

# Reattachment length:
def reatt_length(filelist, yarray, exclude_initial_results):

  print "Calculating reattachment point locations using change of x-velocity sign\n"
  print "Processing output files...\n"
  nums=[]; results=[]
  files = []

  ##### check for no files
  if (len(filelist) == 0):
    print "No files!"
    sys.exit(1)
  for file in filelist:
    try:
      os.stat(file)
    except:
      print "No such file: %s" % file
      sys.exit(1)
    num = int(re.split("\.p?vtu", file)[0].split('_')[-1])
    ##### Exclude data from simulation spin-up time
    if num > exclude_initial_results:
        print file
        files.append(file)

  

  sort_nicely(files)

  for file in files:

    print file
    ##### Read in data from vtu
    datafile = vtktools.vtu(file)

    ##### points near bottom surface, 0 < x < 25
    x2array=[]; pts=[]; no_pts = 52; offset = 0.1
    x = 0.0
    for i in range(1, no_pts):
      x2array.append(x)
      for j in range(len(yarray)):
        pts.append((x, yarray[j], offset))
      x += 0.5

    x2array = numpy.array(x2array)
    pts = numpy.array(pts)

    ##### Get x-velocity on bottom boundary
    uvw = datafile.ProbeData(pts, "Velocity")
    u = uvw[:,0]
    u = u.reshape([x2array.size,yarray.size])

    ##### Find all potential reattachment points:
    points = []
    for j in range(len(u[0,:])):
      for i in range(len(u[:,0])-1):
        ##### Hack to ignore division by zero entries in u.
        ##### All u should be nonzero away from boundary!
        if((u[i,j] / u[i+1,j]) < 0. and not numpy.isinf(u[i,j] / u[i+1,j])):
          ##### interpolate between nodes
          p = x2array[i] + (x2array[i+1]-x2array[i]) * (0.0-u[i,j]) / (u[i+1,j]-u[i,j])
          ##### Ignore spurious corner points
          if(p>0.1):
            points.append(p)

    ##### This is the spanwise-averaged reattachment point:
    avpt = sum(points) / len(points)
    ##### Get time for plot:
    t = min(datafile.GetScalarField("Time"))
    results.append([avpt,t])

  return results

#########################################################################

# Velocity profiles:
def meanvelo(filelist,xarray,yarray,zarray):

  print "\nRunning velocity profile script on files at times...\n"
  ##### check for no files
  if (len(filelist) < 0):
    print "No files!"
    sys.exit(1)

  ##### create array of points
  pts=[]
  for i in range(len(xarray)):
    for j in range(len(yarray)):
      for k in range(len(zarray)):
        pts.append([xarray[i], yarray[j], zarray[k]])
{'fraction_non_alphanumeric': 0.2079285901811499, 'fraction_numerical': 0.014964557626673668, 'mean_word_length': 2.945624029000518, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '821654', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2537, 'n_words': 731}