Esempio n. 1
0
    def _test_functions(
        self,
        readscalar,
        readsymmtensor,
        readtensor,
        readvector,
        readmesh,
        readarray,
    ):
        for sol in sols:
            alpha = readscalar(sol, "latestTime", "alpha")
            alpha = readscalar(sol, timename, "alpha")
            sigma = readsymmtensor(sol, timename, "sigma")
            dummy = readsymmtensor(sol, timename, "sigmauniform")
            taus = readtensor(sol, timename, "Taus")
            readtensor(sol, timename, "Taus", boundary="top")
            u1 = readarray(sol, timename, "U")

            u = readvector(sol, "latestTime", "U")
            dummy, dummy, dummy = readmesh(sol)
            x, y, dummy = readmesh(sol, time_name=timename)

            self.assertEqual(size, len(alpha))
            self.assertEqual(3 * size, u.size)
            self.assertEqual(3 * size, u1.size)
            self.assertEqual(6 * size, sigma.size)
            self.assertEqual(9 * size, taus.size)

            for i, v in u_samples.items():
                self.assertAlmostEqual(u1[i], v, places=places)
            for i, v in alpha_samples.items():
                self.assertAlmostEqual(v, alpha[i], places=places)
        alphashort1 = readscalar("output_samples/ascii", "0", "alpha10")
        readscalar("output_samples/ascii", "0", "T")
        alphauniform = readscalar("output_samples/ascii", "0", "alphauniform")
        readvector("output_samples/ascii", "0", "Uuniform")
        alphauniform = readscalar("output_samples/bin", "0", "alphauniform")
        x, y, z = readmesh("output_samples/ascii", boundary="bottom")
        x, y, z = readmesh("output_samples/bin", boundary="bottom")
        x, y, z = readmesh("output_samples/bin/3d")
        x, y, z = readmesh("output_samples/bin/3d", boundary="bottom")
        x, y, z = readmesh("output_samples/box", time_name="4")
        x, y, z = readmesh("output_samples/box", time_name="3")
        x, y, z = readmesh("output_samples/box", time_name="latestTime")
        self.assertEqual(10, len(alphashort1))
        self.assertEqual(1, len(alphauniform))
        fluidfoam.readscalar("output_samples/ascii/wohead", "p")
        fluidfoam.readvector("output_samples/ascii/wohead", "faceCentres")
Esempio n. 2
0
def readOpenFoam(sol, t0, Nt, Dt, Nx, Ny, Nz, N):
    tlist = t0 + np.arange(Nt) * Dt
    timeRange = [(repr(item).rstrip('0')).rstrip('.') for item in tlist]

    Xd, Yd, Zd = fluidfoam.readmesh(sol)  # ,shape=(Nx,Ny,Nz))
    toto = np.where(Xd >= 0)
    shape = (Nx, Ny, Nz)

    X = np.array((Nx, Ny, Nz))
    Y = np.array((Nx, Ny, Nz))
    # if the shape is prescribed, reshape the arrays
    if (max(shape) != 1):
        X = np.reshape(Xd[toto], shape, order="F")
        Y = np.reshape(Yd[toto], shape, order="F")
    Xp = X[:, 0, 0]
    Yp = Y[0, :, 0]
    time = np.zeros(Nt)
    alphap = np.zeros((Nx, Ny, Nz, Nt))
    ybed = np.zeros((Nx, Nt))  # bed interface

    k = -1
    for t in timeRange:
        print("Reading time: " + str(t) + " s")
        k = k + 1
        alphad = fluidfoam.readscalar(sol, t + '/', 'alpha_a')
        # if the shape is prescribed, reshape the arrays
        if (max(shape) != 1):
            alpha = np.reshape(alphad[toto], shape, order="F")
        alphap[:, :, :, k] = alpha[:, :, :]

        time[k] = float(t)
        for i in range(Nx):
            ybed[i, k] = Y[i, np.max((np.where(alphap[i, :, 0, k] > 0.57))), 0]

    return alphap, Xp, Yp, tlist, ybed
Esempio n. 3
0
def readOpenFoam(sol):
    import subprocess
    #
    # Reading SedFoam results
    #
    #
    proc = subprocess.Popen(['foamListTimes', '-case', sol, '-latestTime'],
                            stdout=subprocess.PIPE)
    output = proc.stdout.read()
    tread = output.rstrip() + '/'
    Nt = 1
    Y = fluidfoam.readscalar(sol, '0/', 'ccy')
    alpha = fluidfoam.readscalar(sol, tread, 'alpha')
    Ua = fluidfoam.readvector(sol, tread, 'Ua')
    Ub = fluidfoam.readvector(sol, tread, 'Ub')
    Tauf = fluidfoam.readtensor(sol, tread, 'Tauf')
    Taus = fluidfoam.readtensor(sol, tread, 'Taus')

    return Nt, Y, Ua[0, :], Ub[0, :], alpha, Tauf[1, :], Taus[1, :]
Esempio n. 4
0
def depth(sol, t, x, y, xi, yi):
    ybed = np.zeros(len(xi))
    if np.mod(t, 1) == 0:
        timename = str(int(t)) + '/'
    else:
        timename = str(t) + '/'
    alpha = fluidfoam.readscalar(sol, timename, 'alpha_a')
    alphai = mlab.griddata(x, y, alpha, xi, yi, interp='linear')
    for j in range(len(xi) - 1):
        tab = np.where(alphai[:, j+1] > 0.5)
        ybed[j] = yi[np.max(tab)]
    return ybed
def depth(sol, t, x, y, xi, yi):
    Nx = np.size(xi, 1)
    ybed = np.zeros(Nx)
    if np.mod(t, 1) == 0:
        timename = str(int(t)) + '/'
    else:
        timename = str(t) + '/'
    alpha = fluidfoam.readscalar(sol, timename, 'alpha_a')
    alphai = griddata((x, y), alpha, (xi, yi))
    for j in range(Nx - 1):
        tab = np.where(alphai[:, j + 1] > 0.5)
        ybed[j] = yi[np.max(tab), j + 1]
    return ybed
Esempio n. 6
0
def readOpenFoam(sol):
    import subprocess
    #
    # Reading SedFoam results
    try:
        proc = subprocess.Popen(['foamListTimes', '-latestTime', '-case', sol],
                                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]
    Nt = 1
    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')
    Tauf = fluidfoam.readtensor(sol, tread, 'Taub')
    Taus = fluidfoam.readtensor(sol, tread, 'Taua')
    k = fluidfoam.readscalar(sol, tread, 'k.b')
    Theta = fluidfoam.readscalar(sol, tread, 'Theta')

    return Nt, Y, Ua[0, :], Ub[0, :], alpha, Tauf[3, :], Taus[3, :], k, Theta
Esempio n. 7
0
###############################################################################
# Reads a scalar value at a given position for different times
# ------------------------------------------------------------
#
# .. note:: It reads the scalar field p at position 20 and stores it in the
#           numpy array time_series

# import readvector function from fluidfoam package
from fluidfoam import readscalar

sol = '../output_samples/box/'

time_series = np.empty(0)

for timename in time_list:
    p = readscalar(sol, timename, 'p')
    time_series = np.append(time_series, p[20])

###############################################################################
# Now plots the time series
# -------------------------
#

import matplotlib.pyplot as plt

plt.figure()

# Converts strings to float for plot
time_list = [float(i) for i in time_list]
plt.plot(time_list, time_series)
Esempio n. 8
0
theta=25 # plane slope
val_p=(rhoSolid-rhoFluid)*gravity*h # pressure at the bottom
timeAdim=(d/gravity)**0.5
velAdim=1000.*(gravity*d)**0.5
pressureAdim=rhoFluid*h*gravity

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

sol =  '../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', 'Ua')

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)
Esempio n. 9
0
    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]

eps_file = sol + case + '.eps'

#########################################
# 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

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

figure(num=1,
       figsize=(figwidth, figheight),
       dpi=60,
Esempio n. 10
0
    print("Do you have load OpenFoam environement?")
    sys.exit(0)
output = proc.stdout.read()
tread = output.decode().rstrip().split('\n')[0]

Nx = 1
Ny = 200
Nz = 1

eps_file = sol + case + '.eps'

#
# 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')

Ny = np.size(Y)
U = np.zeros(Ny)
U = alpha[:] * Ua[0, :] + (1 - alpha[:]) * Ub[0, :]

print("max(Ub)=" + str(np.amax(Ub)) + " m/s")

#
# figure 1
#
figure(num=1,
       figsize=(figwidth, figheight),
Esempio n. 11
0
        ['foamListTimes', '-latestTime', '-case', sol], 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]

eps_file = sol + case + '.eps'

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

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

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

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

figure(num=1, figsize=(figwidth, figheight),
       dpi=60, facecolor='w', edgecolor='w')
Esempio n. 12
0
#tread = list(output.split('\n'))
tread = output.decode().rstrip().split('\n')


del tread[-1]
Nt = len(tread)
time = np.zeros(Nt)
X, Y, Z = fluidfoam.readmesh(sol)
alphat = np.zeros((Ny, Nt))

k = -1
for t in tread:
    print("Reading time: %s s" % t)
    k = k + 1

    alphat[:, k] = fluidfoam.readscalar(sol, t + '/', 'alpha_a')
    time[k] = float(t)


#
# parameter
#
zmin = 0.
zmax = np.max(Y)

tmax = 1800.
tadj = 172.

fontsize = 18.
#
# calcul zint et zint2
    sys.exit(0)
output = proc.stdout.read()
final_tread = output.decode().rstrip().split('\n')[0]

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)
Esempio n. 14
0
    proc = subprocess.Popen(
        ['foamListTimes', '-latestTime', '-case', sol], 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
#########################################
prec=9
X,Y,Z = fluidfoam.readmesh(sol)

alpha_0 = fluidfoam.readscalar(sol, tread, 'alpha.a')
Ua_0   = fluidfoam.readvector(sol, tread, 'U.a')
p_rbgh_0    = fluidfoam.readscalar(sol, tread, 'p_rbgh')
delta_0 = fluidfoam.readscalar(sol, tread, 'delta')

Y_list=[]
alpha_list=[]
vel_list=[]
p_rbgh_list=[]
delta_list=[]

tolAlpha=0.54
for k, alpha0k in enumerate(alpha_0):
    if (alpha0k<tolAlpha):
        break
    Y_list.append(Y[k])
Esempio n. 15
0
    ylabel(r'$z / \delta$')
    ax1.axis([-1.2, 1.2, 0, 30])

#
#
# TKE,R
#
#
i = -1
sub = [1, 3, 2, 4]
for data in datalist:
    i = i + 1
    print(data)

    k = fluidfoam.readscalar(sol, data + '/', 'k.b')
    zk = y - np.min(y)
    #omega = fluidfoam.readscalar(sol, data+'/', 'omega')

    #
    #
    #
    figure(2)

    ax2 = subplot(2, 2, sub[i])
    pO = ax2.plot(k / U0**2, zk / delta, '--r', label="OpenFOAM")
    # pO   = ax2.plot(omega/U0**3,zk/delta,'-r',label="OpenFOAM")

    if i == 0:
        p1 = ax2.plot(TKE_phi90,
                      zTKE_phi90,
Esempio n. 16
0
        ["foamListTimes", "-latestTime", "-case", sol],
        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, 'U.a')[0]
vxFluid = fluidfoam.readvector(sol, timeStep, 'U.b')[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,
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
ngridy = 180
Esempio n. 18
0
sol = basepath + case + '/'

#
# 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, :]
Esempio n. 19
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()
Esempio n. 20
0
    except ValueError:
        return False

sol = input('Nombre de la carpeta de la simulacion: ')
#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/alpha/'

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

for t in timename:
    alpha = flf.readscalar(sol, t, 'alpha.water', True, precision = 5)
    #Color plot
    plt.figure(figsize = (5,6))
    plt.title('z = 0 (m)')
    plt.imshow(alpha[:,:,0].T, origin = 'lower' , extent=[np.amin(x),np.amax(x),np.amin(y),np.amax(y)])
    plt.colorbar().ax.set_ylabel(r'$\alpha$')
    plt.xlabel('x (m)')
    plt.ylabel('y (m)')
    plt.tight_layout()
    plt.savefig(Outdir + 'alpha_' + t + '.png')
    plt.close()
#
#
#---------------Loading OpenFoam results--------------------
#
basepath = '../'

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

sol = basepath + casedir

x, z, y = fluidfoam.readmesh(sol)
k = fluidfoam.readscalar(sol, tout, 'k')
U = fluidfoam.readvector(sol, tout, 'Ub')
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)
# Reading SedFoam results
#
try:
    proc = subprocess.Popen(['foamListTimes', '-withZero', '-case', sol],
                            stdout=subprocess.PIPE)
except:
    print("foamListTimes : command not found")
    print("Do you have load OpenFoam environement?")
    sys.exit(0)
output = proc.stdout.read()
tread = list(output.split('\n'))
del tread[-1]
Nt = len(tread)

time = np.zeros(Nt)
Y = fluidfoam.readscalar(sol, '0/', 'ccy')
alphat = np.zeros((Ny, Nt))

k = -1
for t in tread:
    print("Reading time: %s s" % t)
    k = k + 1

    alphat[:, k] = fluidfoam.readscalar(sol, t + '/', 'alpha')
    time[k] = float(t)

#
# parameter
#
zmin = 0.
zmax = np.max(Y)
Esempio n. 23
0
gs.update(left=0.1, right=0.95, top=0.95,bottom=0.1, wspace=0.125, hspace=0.25)
#########################################
# Reading SedFoam results
#########################################
sol='./'
proc = subprocess.Popen(
    ['foamListTimes', '-case', sol, '-latestTime'], stdout=subprocess.PIPE)
output = proc.stdout.read()
tread = output.decode().rstrip()
if float(tread)>1900:
    tread='1900'
tread=tread+'/'
tread = '1900/'

X, Y, Z = fluidfoam.readmesh(sol)
alpha = fluidfoam.readscalar(sol, tread, 'alpha_a')
Ua = fluidfoam.readvector(sol, tread, 'Ua')
Ub = fluidfoam.readvector(sol, tread, 'Ub')
#pff = fluidfoam.readscalar(sol, tread, 'pff')
#p = fluidfoam.readscalar(sol, tread, 'p')

Ny = np.size(Y)
U = np.zeros(Ny)
U = alpha[:] * Ua[0, :] + (1 - alpha[:]) * Ub[0, :]

print("max(Ub)=" + str(np.amax(Ub)) + " m/s")
#figure(1)
#plot(Ub[0,:],Y)
#plot(uex,xex)
#show()
RMSU = RMS(Y,Ub[0,:],xex,uex)
Esempio n. 24
0
    proc = subprocess.Popen(['foamListTimes', '-latestTime', '-case', sol],
                            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, 'Ua')[0]
vxFluid = fluidfoam.readvector(sol, tread, 'Ub')[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)
Esempio n. 25
0
#
# Read data over four periods and average
#

# alpha_a
if write_alpha:
    rootgrp = Dataset(sol + '/postProcessing/' + case + '_alpha.nc', 'w')
    rootgrp.createDimension('n', len(yi))
    rootgrp.createDimension('p', n_div)
    pos_file = rootgrp.createVariable('pos', np.float64, 'n')
    phase_file = rootgrp.createVariable('phase', np.float64, 'p')
    alpha_file = rootgrp.createVariable('alpha', np.float64, ('n', 'p'))
    pos_file[:] = yi
    phase_file[:] = np.linspace(0, 5, n_div)
    for i, time in enumerate(time_list[1:n_div]):
        alpha1 = fluidfoam.readscalar(sol, time, 'alpha_a', True, precision=12)
        alpha2 = fluidfoam.readscalar(sol,
                                      time_list[i + n_div + 1],
                                      'alpha_a',
                                      True,
                                      precision=12)
        alpha3 = fluidfoam.readscalar(sol,
                                      time_list[i + 2 * n_div + 1],
                                      'alpha_a',
                                      True,
                                      precision=12)
        alpha4 = fluidfoam.readscalar(sol,
                                      time_list[i + 3 * n_div + 1],
                                      'alpha_a',
                                      True,
                                      precision=12)
Esempio n. 26
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/Pressure/'

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

for t in timename:
    P = flf.readscalar(sol, t, 'p', True, precision=5)
    #Color plot
    plt.figure(figsize=(5, 6))
    plt.title('z = 0 (m)')
    plt.imshow(P[:, :, 0].T,
               origin='lower',
               extent=[np.amin(x),
                       np.amax(x),
                       np.amin(y),
                       np.amax(y)])
    plt.colorbar().ax.set_ylabel('Pressure (Pa)')
    plt.xlabel('x (m)')
    plt.ylabel('y (m)')
    plt.tight_layout()
    plt.savefig(Outdir + 'P_' + t + '.png')
    plt.close()
Esempio n. 27
0
                        stdout=subprocess.PIPE)
output = proc.stdout.read()
tread = output.decode().rstrip() + '/'

Nx = 1
Ny = 120
Nz = 1

eps_file = sol + case + '.eps'

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

X, Y, Z = fluidfoam.readmesh(sol)
alpha = fluidfoam.readscalar(sol, tread, 'alpha_a')
Ua = fluidfoam.readvector(sol, tread, 'Ua')
Ub = fluidfoam.readvector(sol, tread, 'Ub')
pff = fluidfoam.readscalar(sol, tread, 'pff')
pa = fluidfoam.readscalar(sol, tread, 'pa')
p = fluidfoam.readscalar(sol, tread, 'p')

Ny = np.size(Y)
U = np.zeros(Ny)
U = alpha[:] * Ua[0, :] + (1 - alpha[:]) * Ub[0, :]

print("max(Ub)=" + str(np.amax(Ub)) + " m/s")

#########################################
# figure 1
#########################################
Esempio n. 28
0
proc = subprocess.Popen(['foamListTimes', '-case', sol, '-latestTime'],
                        stdout=subprocess.PIPE)
output = proc.stdout.read()
tread = output.rstrip() + '/'

Nx = 1
Ny = 200
Nz = 1

eps_file = sol + case + '.eps'

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

Y = fluidfoam.readscalar(sol, '0/', 'ccy')
alpha = fluidfoam.readscalar(sol, tread, 'alpha')
Ua = fluidfoam.readvector(sol, tread, 'Ua')
Ub = fluidfoam.readvector(sol, tread, 'Ub')
pff = fluidfoam.readscalar(sol, tread, 'pff')
p = fluidfoam.readscalar(sol, tread, 'p')

Ny = np.size(Y)
U = np.zeros(Ny)
U = alpha[:] * Ua[0, :] + (1 - alpha[:]) * Ub[0, :]

print("max(Ub)=" + str(np.amax(Ub)) + " m/s")

#########################################
# figure 1
#########################################
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 alpha variables

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

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

###############################################################################
# Interpolate the fields on a structured grid
# -------------------------------------------
#
# .. note:: The vector and scalar fields are interpolated on a specified
#           structured grid
import numpy as np
from scipy.interpolate import griddata

# Number of division for linear interpolation
ngridx = 500
ngridy = 180

# Interpolation grid dimensions
Esempio n. 30
0
try:
    proc = subprocess.Popen(
        ['foamListTimes', '-latestTime', '-case', sol], 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)
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(U.a) was not found -> postProcess -func 'grad(U.a)'")
    os.system("postProcess -case "+sol+" -func \'grad(U.a)\' -time "+tread)