Exemple #1
0
def determineRotation():
    if 'rotated' in os.getcwd():
        if 'stillwater' in os.getcwd():
            angle = np.pi/18
            tx=0.5
            tz = -0.5
        else:
            a = pproc.determineAmplitude()
            angle = np.pi/18   #10 degrees rotation of the domain
            tx=0.0
            tz = 4.22
        return angle,tx,tz
    else:
        return 0,0,0
Exemple #2
0
def initialize(a=None, solitonPosition=15):
    print 'Initialization of a solitary wave from numerical data'
    sys.stdout.flush()
    solver = pproc.determineSolver()
    a = a or pproc.determineAmplitude()
    refDir = os.path.join(referenceDirectoryMain,str(a))
    if not os.path.exists(refDir):
        print 'No data for given amplitude found. Amplitude provided:',a,', available data:'
        for d in sorted(glob.glob(os.path.join(refDir,'../0.*'))):
            print d
        sys.exit()
    surf = np.loadtxt(os.path.join(refDir,'surf'))
    surf[:,0] = surf[:,0] + solitonPosition
    surf = np.vstack((np.array([-200,0.]),surf,np.array([200,0]))) #if the left side is inside the domain, vofOfManyPolygons has problems
    np.savetxt('interface.ini',surf,fmt='%10.6f')
        
    if solver == 'Gerris':
        initializeGerris(refDir)
    elif solver == 'OpenFOAM':
        initializeOpenFOAM(refDir)
    elif solver == 'Truchas':
        initializeTruchas(refDir)
    elif solver == 'Thetis':
        initializeThetis(refDir)
Exemple #3
0
def plotCrossSections(path, time=None, a=None, solver=None, x_c=25, bw=0, suffix='', difference=False):
    """
    Plots the velocity profiles along vertical crossections of a solitary wave, for a single time step.
    In previous versions multiple timesteps were supported, but is not any more.

    :param difference: Take a difference between the reference solution and numerical results
    :type difference: bool
    """

    solver = solver or postprocess.determineSolver(path)
    a = a or postprocess.determineAmplitude(path)
    
    path=os.path.abspath(path)
    dirs = glob.glob(path + '/case[1-4]/*postprocessed.dat') + glob.glob(path + '/*-[1-4]/*postprocessed.dat')
    dirs = [os.path.split(dir)[0] for dir in dirs]
    dirs.sort()
    if not (dirs): 
        print 'Empty directory:', path
        return 1
    else: 
        print dirs
    
    #correct time:
    dt = postprocess.findDt(path)
    time_step = int(round(time/dt))
    time = time_step*dt

    ref_line, u_ref = get_reference(a, time, x_c)
    y_ref = ref_line[:, 1]
    ux_ref = u_ref[:, 0]

    ux_num_list, sample_line_z_list = [], []
    
    for path in dirs:
        vtk_file = postprocess.globFiles(path, ext='.vtk', verbose=False)[time_step]
        if difference:
            p1 = [x_c, np.min(y_ref)]
            p2 = [x_c, np.max(y_ref)]
            line, vel = sample_vtk(vtk_file, p1=p1, p2=p2, N_points=len(y_ref))
            vel[:, 0] = vel[:, 0] - ux_ref
        else:
            line, vel = sample_vtk(vtk_file, x_c=x_c)
        ux_num_list.append(vel[:, 0])  #x component
        sample_line_z_list.append(line[:, 2]) #vertical component
    
    print "Plotting..."
    
    gravity = 'sourceGrav' if 'sourceGrav' in path else ''
    results = ['VelCross', "A0{0:g}".format(a*10), solver, gravity, suffix]
    results = [p for p in results if p]  #remove empty strings
    results = '_'.join(results)
    
    xlim = {0.1: [-0.03, 0.45], 0.3: [-0.3, 1.3]}
    plt.clf()
    fig = plt.figure()
    fig.subplots_adjust(0.15, 0.15, 0.95, None)
    #plt.title('Propagation of a {2:.1f} soliton, t={0:.2f} s, $\Delta x$={1:.2f}m, {3}'.format(t, x_c-15, a, solver))
    
    ls = ['-.', '--', '-']
    for j in range(len(ux_num_list)):
        case = dirs[j][-1:]
        u = ux_num_list[j]
        sample_line_z = sample_line_z_list[j]
        if bw:
            plt.plot(u, sample_line_z, label='Resolution ' + case, ls=ls[j], color='k')
        else:
            plt.plot(u, sample_line_z, label='Resolution ' + case, ls=ls[j])
    if not difference:
        plt.plot(ux_ref, y_ref, label='Reference', color='k', ls='-', lw=2)
    plt.legend(loc='best')
    
    plt.ylabel('z $[m]$')
    plt.xlabel('Velocity $[\\frac{m}{s}]$')
    plt.ylim(-1, np.max(sample_line_z))
    plt.xlim(xlim[a])
    if bw:
        results = results+'_bw'
    plt.savefig(results+'.png'.format(time))
    plt.savefig(results+'.pdf'.format(time))
Exemple #4
0
def plotCrossSections(path,
                      time=None,
                      a=None,
                      solver=None,
                      x_c=25,
                      bw=0,
                      suffix='',
                      difference=False):
    """
    Plots the velocity profiles along vertical crossections of a solitary wave, for a single time step.
    In previous versions multiple timesteps were supported, but is not any more.

    :param difference: Take a difference between the reference solution and numerical results
    :type difference: bool
    """

    solver = solver or postprocess.determineSolver(path)
    a = a or postprocess.determineAmplitude(path)

    path = os.path.abspath(path)
    dirs = glob.glob(path + '/case[1-4]/*postprocessed.dat') + glob.glob(
        path + '/*-[1-4]/*postprocessed.dat')
    dirs = [os.path.split(dir)[0] for dir in dirs]
    dirs.sort()
    if not (dirs):
        print 'Empty directory:', path
        return 1
    else:
        print dirs

    #correct time:
    dt = postprocess.findDt(path)
    time_step = int(round(time / dt))
    time = time_step * dt

    ref_line, u_ref = get_reference(a, time, x_c)
    y_ref = ref_line[:, 1]
    ux_ref = u_ref[:, 0]

    ux_num_list, sample_line_z_list = [], []

    for path in dirs:
        vtk_file = postprocess.globFiles(path, ext='.vtk',
                                         verbose=False)[time_step]
        if difference:
            p1 = [x_c, np.min(y_ref)]
            p2 = [x_c, np.max(y_ref)]
            line, vel = sample_vtk(vtk_file, p1=p1, p2=p2, N_points=len(y_ref))
            vel[:, 0] = vel[:, 0] - ux_ref
        else:
            line, vel = sample_vtk(vtk_file, x_c=x_c)
        ux_num_list.append(vel[:, 0])  #x component
        sample_line_z_list.append(line[:, 2])  #vertical component

    print "Plotting..."

    gravity = 'sourceGrav' if 'sourceGrav' in path else ''
    results = ['VelCross', "A0{0:g}".format(a * 10), solver, gravity, suffix]
    results = [p for p in results if p]  #remove empty strings
    results = '_'.join(results)

    xlim = {0.1: [-0.03, 0.45], 0.3: [-0.3, 1.3]}
    plt.clf()
    fig = plt.figure()
    fig.subplots_adjust(0.15, 0.15, 0.95, None)
    #plt.title('Propagation of a {2:.1f} soliton, t={0:.2f} s, $\Delta x$={1:.2f}m, {3}'.format(t, x_c-15, a, solver))

    ls = ['-.', '--', '-']
    for j in range(len(ux_num_list)):
        case = dirs[j][-1:]
        u = ux_num_list[j]
        sample_line_z = sample_line_z_list[j]
        if bw:
            plt.plot(u,
                     sample_line_z,
                     label='Resolution ' + case,
                     ls=ls[j],
                     color='k')
        else:
            plt.plot(u, sample_line_z, label='Resolution ' + case, ls=ls[j])