예제 #1
0
    proc = subprocess.Popen(['foamListTimes', '-latestTime', '-case', sol],
                            stdout=subprocess.PIPE)
except:
    print("foamListTimes : command not found")
    print("Did you loaded OpenFoam environement?")
    sys.exit(0)
output = proc.stdout.read()
tread = output.decode().rstrip().split('\n')[0]

#########################################
# Reading SedFoam results
#########################################

X, Y, Z = fluidfoam.readmesh(sol)
alpha = fluidfoam.readscalar(sol, tread, 'alpha.a')
Ua = fluidfoam.readvector(sol, tread, 'U.a')
Ub = fluidfoam.readvector(sol, tread, 'U.b')
pff = fluidfoam.readscalar(sol, tread, 'pff')
pa = fluidfoam.readscalar(sol, tread, 'pa')
muI = fluidfoam.readscalar(sol, tread, 'muI')
nuEffa = fluidfoam.readscalar(sol, tread, 'nuEffa')
nuEffb = fluidfoam.readscalar(sol, tread, 'nuEffb')
nuFra = fluidfoam.readscalar(sol, tread, 'nuFra')
Tauf = fluidfoam.readtensor(sol, tread, 'Taub')
Taus = fluidfoam.readtensor(sol, tread, 'Taua')
try:
    gradUa = fluidfoam.readtensor(sol, tread, 'grad(U.a)')
except:
    print(
        "grad(Ua) was not found -> Introduce - postProcess -func 'grad(U.a)' - in the command line"
    )
예제 #2
0
pressureAdim = rhoFluid * h * gravity

#########################################
# Loading SedFoam results
#########################################

sol = '../laminar/1DWetAvalanche'
X, Y, Z = fluidfoam.readmesh(sol)
tolAlpha = 0.55

# this part of the script analyzes the vertical profiles at time=0 (before tilting the plane)
alpha_0 = fluidfoam.readscalar(sol, '200', 'alpha.a')
pff_0 = fluidfoam.readscalar(sol, '200', 'pff')
pa_0 = fluidfoam.readscalar(sol, '200', 'pa')
p_rbgh_0 = fluidfoam.readscalar(sol, '200', 'p_rbgh')
Ua_0 = fluidfoam.readvector(sol, '200', 'U.a')

vel_0 = []
phi_0 = []
y_0 = []
p_excess_0 = []
p_c_0 = []

for k in range(len(alpha_0)):
    if (alpha_0[k] > tolAlpha):
        vel_0.append(Ua_0[0, k] * 1000 / velAdim)
        phi_0.append(alpha_0[k])
        y_0.append(Y[k] / h)
        p_c_0.append(0)
        p_excess_0.append((p_rbgh_0[k] / val_p))
    else:
예제 #3
0
#
#---------------Loading OpenFoam results--------------------
#
basepath = '../RAS/'

#
# Loading OpenFoam results
#
casedir = '1DBoundaryLayer/'
tout = '2500'

sol = basepath + casedir

x, z, y = fluidfoam.readmesh(sol)
k = fluidfoam.readscalar(sol, tout, 'k.b')
U = fluidfoam.readvector(sol, tout, 'U.b')
Tauf = fluidfoam.readtensor(sol, tout, 'Taub')
u = U[0, :]
#########################################
#
# Physical parameters
#

rhof = 1
nu = 7.2727e-5

wallShear = np.max(Tauf[3, :]) / rhof

H = np.max(z)
Umax = np.max(U)
Um = np.trapz(u, z) / H
예제 #4
0
                            stdout=subprocess.PIPE)
except:
    print("foamListTimes : command not found")
    print("Do you have load OpenFoam environement?")
    sys.exit(0)
output = proc.stdout.read()
tread = output.decode().rstrip().split('\n')[0]

#########################################
# Reading SedFoam results
#########################################
X, Y, Z = fluidfoam.readmesh(sol)

z = Y
phi = fluidfoam.readscalar(sol, tread, 'alpha.a')
vxPart = fluidfoam.readvector(sol, tread, 'U.a')[0]
vxFluid = fluidfoam.readvector(sol, tread, 'U.b')[0]
T = fluidfoam.readscalar(sol, tread, 'Theta')

phi_interp = np.interp(zDATA, z, phi)
rms_phi = rms(phi_interp - phiDATA)
assert (rms_phi <= 0.02)

vxPart_interp = np.interp(zDATA, z, vxPart)
I = np.where(zDATA < 17.5 * 0.006)
rms_vxP = rms(vxPart_interp[I] - vxPDATA[I])
assert (rms_vxP <= 0.1)

vxFluid_interp = np.interp(zDATA, z, vxFluid)
rms_vxF = rms(vxFluid_interp - vxFDATA)
assert (rms_vxF <= 0.15)
예제 #5
0
#
# Reading SedFoam results
#
tread = '16'

print('########## Writing averaged data file ##########')
# Read vertical coordinates
x, y, z = fluidfoam.readmesh(sol, True, precision=12)
ny = len(y[0, :, 0])
uny = int(ny / 2)
yi = y[0, 0:uny, 0]

# Read temporaly averaged variables
alpha_ta = fluidfoam.readscalar(sol, tread, 'alpha_aMean', True, precision=12)
ubf_ta = fluidfoam.readvector(sol, tread, 'UbMeanF', True, precision=12)
uaf_ta = fluidfoam.readvector(sol, tread, 'UaMeanF', True, precision=12)
ubprimf_ta = fluidfoam.readtensor(sol,
                                  tread,
                                  'UbPrime2MeanF',
                                  True,
                                  precision=12)
uaprimf_ta = fluidfoam.readtensor(sol,
                                  tread,
                                  'UaPrime2MeanF',
                                  True,
                                  precision=12)

# Usable data
alpha_ta = alpha_ta[:, 0:uny, :]
ubf_ta = ubf_ta[:, :, 0:uny, :]
예제 #6
0
#
#
# U
#
#
i = -1

zex = np.linspace(0, h, 200)

for data in datalist:
    i = i + 1
    print(data)

    #ufile=basepath+data+'Uf.xy'
    #zu,u=np.loadtxt(ufile,unpack=True)
    Ub = fluidfoam.readvector(sol, data + '/', 'Ub')
    u = Ub[0, :]
    zu = y - np.min(y)

    figure(1)

    ax1 = subplot(1, 1, 1)
    pO = ax1.plot(u / U0, zu / delta, '--r', label="OpenFOAM")  # phi="+phi[i])

    if i == 0:
        p1 = ax1.plot(u_phi315, zu_phi315, '-b',
                      label="Guizien et al (2003)")  # phi=-45")
        p2 = ax1.plot(u_OW_phi315, zu_OW_phi315, '-.g',
                      label="Wilcox")  # phi=-45")
        p3 = ax1.plot(u_DNS_phi315, zu_DNS_phi315, ':k',
                      label="DNS")  # phi=-45")

X,Y,Z = fluidfoam.readmesh(sol)
time_sim_dila_0=[]
vel_sim_dila_0=[]
p_sim_dila_0=[]
tolAlpha=0.55
tolL=5e-4

			
for i in range(200,int(final_tread)):
	if (i % 10 ==0):
		time_sim_dila_0.append((i-200)/timeAdim)
		tread=str(i)+'/'
		alpha_0 = fluidfoam.readscalar(sol, tread, 'alpha_a')
		Ua_0 = fluidfoam.readvector(sol, tread, 'Ua')
		p_rbgh_0 = fluidfoam.readscalar(sol, tread, 'p_rbgh')
		velCol=0
		P1Col=0
		P2Col=0
		for k in range(len(alpha_0)):
				if ((X[k]>-tolL) and (X[k]<tolL) and (Y[k]<h) and (Y[k]>h-tolL) and (velCol==0)):
						vel_sim_dila_0.append(Ua_0[0, k]*1000/velAdim)
						velCol=1
				if (alpha_0[k]<tolAlpha and (X[k]>-tolL) and (X[k]<tolL) and (Y[k]>h) and (P1Col==0)):
						P1Col=1
						P_surface=p_rbgh_0[k]
				if (alpha_0[k]>tolAlpha and (X[k]>-tolL) and (X[k]<tolL) and (Y[k]<tolL) and (P2Col==0)):
						P2Col=1
						P_bottom=p_rbgh_0[k]
				if ((velCol==1) and (P1Col==1) and (P2Col==1)):
예제 #8
0
        stdout=subprocess.PIPE,
    )
except:
    print("foamListTimes : command not found")
    print("Do you have load OpenFoam environement?")
    sys.exit(0)
output = proc.stdout.read(
)  #to obtain the output of function foamListTimes from the subprocess
timeStep = output.decode().rstrip().split('\n')[
    0]  #Some management on the output to obtain a number

#Read the data
X, Y, Z = fluidfoam.readmesh(sol)
z = Y
phi = fluidfoam.readscalar(sol, timeStep, 'alpha_a')
vxPart = fluidfoam.readvector(sol, timeStep, 'Ua')[0]
vxFluid = fluidfoam.readvector(sol, timeStep, 'Ub')[0]
T = fluidfoam.readscalar(sol, timeStep, 'Theta')

######################
#Plot results
######################
d = 0.006  #6mm diameter particles
plt.figure(figsize=[10, 5])
plt.subplot(141)
plt.plot(phiDEM, zDEM / d, 'k--', label=r'DEM')
plt.plot(phi, z / d, label=r'SedFoam')
plt.xlabel(r'$\phi$', fontsize=25)
plt.ylabel(r'$\frac{z}{d}$',
           fontsize=30,
           rotation=True,
예제 #9
0
This example doesn't do much, it just reads and makes a simple plot of OpenFoam
field in case of files without header (as for example the output of sampling
library)
"""

###############################################################################
# Read a scalar sampled field and the associated mesh
# ---------------------------------------------------
#
# .. note:: It reads a scalar sampled field and the associated mesh 

# import readscalar, readvector function from fluidfoam package
from fluidfoam import readscalar, readvector

sol = '../output_samples/ascii/wohead'

X, Y, Z = readvector(sol, 'faceCentres')
pressure = readscalar(sol, 'p')
###############################################################################
# Now plot this scalar field
# --------------------------
# In this example it is the pressure coefficient around an airfoil.
# It can be useful to sort the data in order to plot a line and not stars

import matplotlib.pyplot as plt
plt.figure()
plt.plot(X, pressure, '*')
plt.grid()
plt.show()
예제 #10
0
Folders = glob.glob(sol + '*')

timename = []
for folder in Folders:
    folder = folder.replace(sol, '')
    if isfloat(folder):
        if float(folder) != 0:
            timename.append(folder)

veli = ['x', 'y', 'z']
Outdir = ''  #'Figures/Vel_comp/'

x, y, z = flf.readmesh(sol, True, precision=5)

for t in timename:
    vel = flf.readvector(sol, t, 'U', True, precision=5)
    for i in range(3):
        #Color plot
        plt.figure(figsize=(5, 6))
        plt.title('z = 0 (m)')
        plt.imshow(1e3 * vel[i, :, :, 0].T,
                   origin='lower',
                   extent=[np.amin(x),
                           np.amax(x),
                           np.amin(y),
                           np.amax(y)])
        plt.colorbar().ax.set_ylabel(r'$U_{%s}$' % veli[i] + r' (mm/s)')
        plt.xlabel('x (m)')
        plt.ylabel('y (m)')
        plt.tight_layout()
        plt.savefig(Outdir + 'cavity' + veli[i] + t + '.png')
예제 #11
0
#Create time list
Folders = glob.glob(sol + '*')

timename = []
for folder in Folders:
    folder = folder.replace(sol, '')
    if isfloat(folder):
        if float(folder) != 0:
            timename.append(folder)

Outdir = ''  #'Figures/Streamlines/'

x, y, z = flf.readmesh(sol, True)

for t in timename:
    vel = flf.readvector(sol, t, 'U', True)
    #Module of velocity. The quantity is measured transposed, according to stream plot config.
    V = np.sqrt(vel[0, :, :, 0].T**2 + vel[1, :, :, 0].T**2)
    #Color plot
    plt.figure(figsize=(6, 6))
    plt.title('z = 0 (m)')
    #plt.plot(y[:,:,0],x[:,:,0],'.w')
    plt.streamplot(y[:, :, 0],
                   x[:, :, 0],
                   vel[0, :, :, 0].T,
                   vel[1, :, :, 0].T,
                   color=V,
                   linewidth=2,
                   cmap=plt.cm.viridis)
    plt.colorbar(fraction=0.046, pad=0.04).ax.set_ylabel('|U| (m/s)')
    plt.ylabel('y (m)')
예제 #12
0
nx, ny, nz = x.shape
print("Nx = ", nx, "Ny = ", ny, "Nz = ", nz)

###############################################################################
# Reads a vector field
# --------------------
#
# .. note:: It reads a vector field from a structured mesh
#           and stores it in vel variable

# import readvector function from fluidfoam package
from fluidfoam import readvector

timename = '0'
vel = readvector(sol, timename, 'U', structured=True)

###############################################################################
# Now plots the contour of the first velocity component at a given z position
# ---------------------------------------------------------------------------
#
# .. note:: Here the position z is the middle (// is used to have an integer)

import matplotlib.pyplot as plt
import numpy as np

plt.figure()
levels = np.arange(0, 0.178, 0.001)
plt.contourf(x[:, :, nz // 2],
             y[:, :, nz // 2],
             vel[0, :, :, nz // 2],
예제 #13
0
x, y, z = readmesh(sol, True)

###############################################################################
# Reads a vector field
# --------------------
#
# .. note:: It reads a vector field from a structured mesh
#           and stores it in vel variable

# import readvector function from fluidfoam package
from fluidfoam import readvector

sol = '../output_samples/box/'
timename = '0'
vel = readvector(sol, timename, 'U', True)

###############################################################################
# Averaging along x and z axis (1 and 3)
# --------------------------------------
#
import numpy as np

vel_averaged = np.mean(np.mean(vel, 3), 1)

###############################################################################
# Now plots the profile of the averaged first velocity component
# --------------------------------------------------------------
#

import matplotlib.pyplot as plt
sol = '../../output_samples/pipeline/'

x, y, z = readmesh(sol)

###############################################################################
# Reads vector and scalar field
# -----------------------------
#
# .. note:: It reads vector and scalar field from an unstructured mesh
#           and stores them in vel and phi variables

# import readvector and readscalar functions from fluidfoam package
from fluidfoam import readvector, readscalar

timename = '25'
vel = readvector(sol, timename, 'Ub')
phi = readscalar(sol, timename, 'phi')

###############################################################################
# Interpolate the fields on a structured grid
# -------------------------------------------
#
# .. note:: The vector and scalar fields are interpolated on a specified
#           structured grid

# import griddata from scipy package
from scipy.interpolate import griddata
import numpy as np

# Number of division for linear interpolation
ngridx = 500
예제 #15
0
nface = x.shape
print("Boundary shape = ", nface)

###############################################################################
# Reads a vector field
# --------------------
#
# .. note:: It reads a vector field of a boundary from a structured mesh
#           and stores it in vel variable

# import readvector function from fluidfoam package
from fluidfoam import readvector

timename = "0"
vel = readvector(sol, timename, "U", structured=True, boundary="topWall")

###############################################################################
# Now plots the contour of the first velocity component on the topWall boundary
# -----------------------------------------------------------------------------
#
# .. note:: Here the topWall boundary is in (x, z) plane

import matplotlib.pyplot as plt
import numpy as np

plt.figure()

levels = np.arange(0, np.max(vel[0]), 0.001)
ax = plt.contourf(x[:, 0, :], z[:, 0, :], vel[0, :, 0, :], levels=levels)
cbar = plt.colorbar(ax)
예제 #16
0
except:
    print("foamListTimes : command not found")
    print("Do you have load OpenFoam environement?")
    sys.exit(0)
output = proc.stdout.read()
tread = output.decode().rstrip().split('\n')[0]

#########################################
# Reading SedFoam results
#########################################
prec=9
X,Y,Z = fluidfoam.readmesh(sol,True,precision=prec)
nx,ny,nz = X.shape

alpha = fluidfoam.readscalar(sol, tread, 'alpha_a',True,precision=prec)
Ua    = fluidfoam.readvector(sol, tread, 'Ua',True,precision=prec)
pa    = fluidfoam.readscalar(sol, tread, 'pa',True,precision=prec)
Theta = fluidfoam.readscalar(sol, tread, 'Theta',True,precision=prec)

Ny = np.size(Y)
H = np.max(np.max(Y))
U = 1

iprof=0

#########################################
# figure 1
#########################################

# =============================================================================
# figure(num=1, figsize=(figwidth, figheight),