示例#1
0
def test_sample_timeSeries():

    cwd = os.getcwd()
    dir_path = os.path.dirname(os.path.realpath(__file__))
    os.chdir(dir_path)

    solutionDir = "sample1"
    file = "centreLine_T.xy"
    caseStructure = [['Ux1', 'Ux3'], ['T1'], ['p1'], ['string10']]
    baseCase = "Cases"

    surf_time = casefoam.posField_to_timeSeries(solutionDir, file,
                                                getFreeSurfaceWallAndCentre,
                                                caseStructure, baseCase)

    grouped_df = surf_time.groupby(['var_0', 'var_1', 'var_2', 'var_3'])

    assert len(grouped_df.size()) == 2
    assert surf_time['min'].max() == 0
    assert surf_time['max'].max() == 1

    os.chdir(cwd)
示例#2
0
baseCase = 'Cases'
solutionDir = 'reconSurfaces'
file = 'alpha.water_freeSurf.raw'

analytical = pd.read_csv("analyticalWave.dat",
                         delim_whitespace=True,
                         header=None)
analytical.columns = ['time', "analytical"]
analytical["analytical"] *= 100

postFunction = postFunctions.getFreeSurfaceWallAndCentre

sol = casefoam.posField_to_timeSeries(solutionDir,
                                      file,
                                      postFunction,
                                      cases,
                                      baseCase,
                                      axis=1)
sol = sol.reset_index()
sol.columns = [
    'time', 'min', 'mean', 'max', 'interfaceType', 'Method', 'nCells'
]
sol = sol.replace('coarse', 32)
sol = sol.replace('mid', 64)
sol = sol.replace('fine', 128)
sol['max'] /= 3e-5
sol['time'] /= 1.475e-5
ax = analytical.plot(x='time', y='analytical', c='black', marker='o')
sns.set_style("ticks")
plicRDF = sol[sol['interfaceType'] == 'plicRDF']
plicRDF.to_csv("sinwaveTri.csv", index=False)
示例#3
0
import casefoam
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

solutionDir = 'surfaces'
filename = 'p_freeSurf.raw'


def centreAndWall(caseComb, time, currentDataFrame):
    """Return the centre and wall pos.

    """
    centre = currentDataFrame.iloc[:, 1].min()
    wall = currentDataFrame.iloc[:, 1].max()
    df = pd.DataFrame(np.array([time, centre, wall], ndmin=2),
                      columns=['time', 'centre', 'wall'])
    print(df)
    df = df.set_index('time')

    return df


sol = casefoam.posField_to_timeSeries(solutionDir, filename, centreAndWall)
sol.sort_values('time', inplace=True)
sol[['centre', 'wall']].plot()
plt.show()
示例#4
0
import casefoam
from casefoam import postFunctions
import seaborn as sns
# output_notebook()
sns.set_style("ticks")

caseStructure = [['isoSurface', 'plicRDF'],
                 ['implicitGrad', 'explicitGrad', 'Schrage'],
                 ['grid1', 'grid2', 'grid3']]

baseCase = 'Cases'
solutionDir = 'surfaces'
file = 'interfaceEnergyFluxLiquid_freeSurf.raw'
postFunction = postFunctions.getRadius

surfPos = casefoam.posField_to_timeSeries(solutionDir, file, postFunction,
                                          caseStructure, baseCase)

surfPos.columns = ['min', 'r', 'max', 'interFaceType', 'Method', 'Resolution']
surfPos = surfPos.sort_index()
surfPos = surfPos.reset_index('time')
surfPos[['min', 'r', 'max']] *= 1000

# plot analytical solution
analytical_data = pd.read_csv('init/data.dat', delim_whitespace=True)

analytical_data['r'] *= 1000
ax = analytical_data.plot(x='t', y='r', label='analytical', color='black')
surfPos_plicRDF = surfPos[surfPos.interFaceType == 'plicRDF']

ax = sns.lineplot(x='time',
                  y='r',
示例#5
0
forcesDir = 'forces/0'
forces = time_series(forcesDir, 'force.dat', caseStructure, baseCase)
forces = forces.reset_index()

plt.figure()
sns.lineplot(x='t', y=1, hue='var_0', style='var_1', data=forces)
plt.xlabel('x [m]')
plt.ylabel('F [N]')


def max_min_Height(caseComb, time, currentDataFrame):
    t = time
    minimum = currentDataFrame.iloc[:, 1].min()
    maximum = currentDataFrame.iloc[:, 1].max()
    df = pd.DataFrame(np.array([time, minimum, maximum], ndmin=2),
                      columns=['time', 'min', 'max'])
    df = df.set_index('time')
    return df


surf_Heights = casefoam.posField_to_timeSeries(surfaceDir, 'p_freeSurface.raw',
                                               max_min_Height, caseStructure,
                                               baseCase)
surf_Heights = surf_Heights.reset_index()

plt.figure()
sns.lineplot(x='time', y='max', hue='var_0', style='var_1', data=surf_Heights)
plt.xlabel('x [m]')
plt.ylabel('h [m]')
plt.show()