def __init__(self, K, N, M, fstart, fend, fPath='', fPrefix=["upp_Ux", "upp_Uy", "upp_Uz"]): self.nFiles = fend - fstart + 1 self.fStart = fstart self.fEnd = fend self.fPath = fPath self.fNames = [] for x in range(fstart, fend + 1): self.fNames.append(map(lambda y: fPath + y + "_" + str(x), fPrefix)) # original input has permuted directions # (left - input, right - standard naming convention, applied here) # (Ux,Uy,Uz) --> (Uy,Uz,Ux) with open(self.fNames[x-fstart][0],'r') as Uy, \ open(self.fNames[x-fstart][1],'r') as Uz, \ open(self.fNames[x-fstart][2],'r') as Ux : # input data is in a matrix, and we first have to reshape # it to be a 3D field # then directions must be permuted (np.transpose) # attribute of type Channel is added setattr( self, "field_" + str(x), hs.Channel( np.transpose(np.loadtxt(Ux).reshape(N, M, K), axes=(2, 0, 1)), np.transpose(np.loadtxt(Uy).reshape(N, M, K), axes=(2, 0, 1)), np.transpose(np.loadtxt(Uz).reshape(N, M, K), axes=(2, 0, 1)), K, N, M))
def test_input2(self): with self.assertRaises(ValueError): hs.Channel([[[1], [1]], [[1], [1]]], [[[1], [1]], [[1], [1]]], [[[1], [1]], [[1], [1]]], 1, 2, 1)
def test_input1(self): try: hs.Channel([[[1]]], [[[2]]], [[[3]]], 1, 1, 1) except ValueError: self.fail("an unexpected ValueError")
def test_input0(self): with self.assertRaises(ValueError): hs.Channel([], [], [], 0, 0, 0)
# Last modified: 11-07-2017 12:43:07 # Purpose: test of module homstat.py # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import numpy as np import homstat as hs import unittest #****************************************** #useful input examples and constants #****************************************** #real DNS dimensions zeros128 = np.zeros(shape=(128, 128, 128)) test_128 = hs.Channel(zeros128, zeros128, zeros128, 128, 128, 128) zeros129 = np.zeros(shape=(128, 129, 128)) test_129 = hs.Channel(zeros129, zeros129, zeros129, 128, 129, 128) ones128 = np.ones(shape=(128, 128, 128)) test_128ones = hs.Channel(ones128, ones128, ones128, 128, 128, 128) #real LES dimensions zeros64_32 = np.zeros(shape=(32, 32, 64)) test_64_32 = hs.Channel(zeros64_32, zeros64_32, zeros64_32, 32, 32, 64) ones_32 = np.ones(shape=(32, 32, 64)) test_32ones = hs.Channel(ones_32, ones_32, ones_32, 32, 32, 64) # input examples for standard deviation and correlation testing
indices_64 = np.arange(0,128,2) Ux_SGS = np.empty([32,33,64]) Uy_SGS = np.empty([32,33,64]) Uz_SGS = np.empty([32,33,64]) for iLES,iDNS in enumerate(indices_32): for jLES,jDNS in enumerate(indices_33): for kLES,kDNS in enumerate(indices_64): Ux_SGS[iLES,jLES,kLES] = DNS_data.Ux[iDNS,jDNS,kDNS] - LES_data.Ux[iLES,jLES,kLES] Uy_SGS[iLES,jLES,kLES] = DNS_data.Uy[iDNS,jDNS,kDNS] - LES_data.Uy[iLES,jLES,kLES] Uz_SGS[iLES,jLES,kLES] = DNS_data.Uz[iDNS,jDNS,kDNS] - LES_data.Uz[iLES,jLES,kLES] SGS_LES = hs.Channel(Ux_SGS,Uy_SGS,Uz_SGS,LES_data.K,LES_data.N, LES_data.M ) #..................................................... # VERSION 2: we take the difference in DNS nodes # and interpolate LES to DNS position # # For this we need to write the data to file # since interpolation takes a lot of time (~ 3h for each velocity = ~9h) # is run only if option 'INTERPOLATE' is activated # in the command line run # e.g. python SGS_fluid_stats.py --interpolate INTERPOLATE = False if '--interpolate' in sys.argv: