def main(args):
    """Plots the lift and drag coefficients versus the angle-of-attack of the
  flat-plate and compares to experimental results reported by 
  Taira et al. (2007) and Taira (2008).
  """
    simulations = collections.OrderedDict()
    for description, series in zip(args.descriptions, args.series):
        series_directory = os.path.join(args.directory, series)
        subfolders = sorted([
            folder for folder in os.listdir(series_directory)
            if os.path.isdir(os.path.join(series_directory, folder))
        ])
        simulations[description] = []
        for i, subfolder in enumerate(subfolders):
            simulation_directory = os.path.join(series_directory, subfolder)
            simulations[description].append(
                Simulation(directory=simulation_directory,
                           software=args.software,
                           angle=args.angles[i]))
            simulations[description][-1].read_forces()

    experiment = TairaEtAl2007FlatPlate()
    experiment.read_drag_coefficients(args.validation_data[0])
    experiment.read_lift_coefficients(args.validation_data[1])

    plot_coefficients_vs_angles(simulations,
                                experiment,
                                coefficient=args.coefficient,
                                save_directory=args.save_directory,
                                save_names=args.save_names,
                                limits=args.plot_limits,
                                show=args.show)
Example #2
0
def main(args):
  """Plots the instantaneous force coefficients."""
  simulations = []
  # register main simulation
  simulations.append(Simulation(description=args.description, 
                                directory=args.directory,
                                software=args.software))
  # register other simulations used for comparison
  for other in args.others:
    info = dict(zip(['software', 'directory', 'description'], other[:-1]))
    simulations.append(Simulation(**info))
  # read and compute some statistics
  for index, simulation in enumerate(simulations):
    try:
      simulations[index].read_forces(display_coefficients=args.display_coefficients)
    except:
      simulations[index].read_forces()
    simulation.get_mean_forces(limits=args.average_limits, 
                               last_period=args.last_period, 
                               order=args.order)
    if args.strouhal_limits:
      simulation.get_strouhal(limits=args.strouhal_limits,
                              order=args.order)
  # plot instantaneous forces (or force coefficients)
  simulations[0].plot_forces(indices=args.force_indices,
                             labels=args.force_labels,
                             display_coefficients=args.display_coefficients,
                             coefficient=args.coefficient,
                             display_extrema=args.display_extrema, 
                             order=args.order,
                             display_guides=args.display_guides,
                             fill_between=args.fill_between,
                             other_simulations=simulations[1:],
                             other_coefficients=[float(other[-1]) for other in args.others],
                             limits=args.plot_limits,
                             save_name=args.save_name, 
                             show=args.show)
  # display time-averaged values in table
  print(simulations[0].create_dataframe_forces(indices=args.force_indices,
                                               display_strouhal=(True if args.strouhal_limits 
                                                                      else False),
                                               display_coefficients=args.display_coefficients,
                                               coefficient=args.coefficient,
                                               other_simulations=simulations[1:],
                                               other_coefficients=[float(other[-1]) for other 
                                                                   in args.others]))
def main(args):
  """Plots the instantaneous drag coefficient 
  and compares to Koumoutsakos and Leonard (1995).
  """
  print('[info] simulation: {}'.format(args.directory))

  simulation = Simulation(directory=args.directory, 
                          description=args.description,
                          software=args.software)
  simulation.read_forces(display_coefficients=True)

  validation_data = KoumoutsakosLeonard1995()
  validation_data.read_drag(args.validation_data_path)

  plot_drag_coefficients(simulation, validation_data, 
                         directory=args.directory, 
                         save_name=args.save_name,
                         limits=args.plot_limits, 
                         show=args.show)
Example #4
0
def main(args):
    """Plots and writes the velocity components at the centerline of the cavity
  and compares with experimental results form Ghia et al. (1982).
  """
    # register simulation
    simulation = Simulation(directory=args.directory, software=args.software)

    # get time-step
    if not args.time_step:
        args.time_step = simulation.get_time_steps()[-1]

    simulation.read_grid()
    simulation.read_fields(['x-velocity', 'y-velocity'], args.time_step)

    # read validation data from Ghia et al. (1982)
    u, v = get_validation_data(args.validation_data_path, args.Re)

    software_name = {'petibm': 'PetIBM', 'cuibm': 'cuIBM'}
    plot_settings = {
        'label': software_name[args.software],
        'color': '#336699',
        'linestyle': '-',
        'linewidth': 3,
        'zorder': 10
    }
    validation_plot_settings = {
        'label': 'Ghia et al. (1982)',
        'color': '#993333',
        'linewidth': 0,
        'markeredgewidth': 2,
        'markeredgecolor': '#993333',
        'markerfacecolor': 'none',
        'marker': 'o',
        'markersize': 8,
        'zorder': 10
    }

    save_directory = os.path.join(simulation.directory, 'images')
    if not os.path.isdir(save_directory):
        os.makedirs(save_directory)
    simulation.x_velocity.plot_vertical_gridline_values(
        0.5,
        plot_settings=plot_settings,
        plot_limits=[0.0, 1.0, -0.75, 1.25],
        save_directory=save_directory,
        show=args.show,
        validation_data=(u.y, u.values),
        validation_plot_settings=validation_plot_settings)
    simulation.y_velocity.plot_horizontal_gridline_values(
        0.5,
        plot_settings=plot_settings,
        plot_limits=[0.0, 1.0, -0.75, 1.25],
        save_directory=save_directory,
        show=args.show,
        validation_data=(v.x, v.values),
        validation_plot_settings=validation_plot_settings)
Example #5
0
def main(args):
    """Grid convergence study.
  Computes the observed order of convergence using the solution on three 
  consecutive grids with constant grid refinement.
  Computes the Grid Convergence Index and plots the asymptotic ranges.
  Plots the log-log error versus grid-spacing.
  """
    # read numerical solutions
    simulations = collections.OrderedDict()
    for size in args.gridline_sizes:
        simulations[size] = Simulation(directory=os.path.join(
            args.directory, str(size)),
                                       description=size,
                                       software=args.software)
        simulations[size].read_grid()
        simulations[size].read_fields(
            args.field_names,
            args.time_step,
            periodic_directions=args.periodic_directions)

    for sizes in args.observed_order:
        alpha = convergence.get_observed_orders(
            [simulations[size] for size in sizes],
            args.field_names,
            simulations[args.mask],
            directory=os.path.join(args.directory, 'data'))
        if args.plot_asymptotic_ranges:
            convergence.plot_asymptotic_ranges(
                [simulations[size] for size in sizes],
                alpha,
                simulations[args.mask],
                directory=os.path.join(args.directory, 'images'))

    exact = convergence.get_exact_solution(simulations, args.mask,
                                           *args.analytical_solution)
    if args.plot_analytical_solution:
        exact.plot_fields(args.time_step,
                          view=args.bottom_left + args.top_right,
                          directory=os.path.join(args.directory, 'images'))

    convergence.plot_grid_convergence(simulations.values(),
                                      exact,
                                      mask=simulations[args.mask],
                                      field_names=args.field_names,
                                      norms=args.norms,
                                      directory=os.path.join(
                                          args.directory, 'images'),
                                      save_name=args.save_name,
                                      show=args.show)
def main(args):
  """Plots and writes the velocity components at the centerline of the cavity
  and compares with experimental results form Ghia et al. (1982).
  """
  # register simulation
  simulation = Simulation(directory=args.directory, 
                          software=args.software)
  
  # get time-step
  if not args.time_step:
    args.time_step = simulation.get_time_steps()[-1]
  
  simulation.read_grid()
  simulation.read_fields(['x-velocity', 'y-velocity'], args.time_step)

  # read validation data from Ghia et al. (1982)
  u, v = get_validation_data(args.validation_data_path, args.Re)

  software_name = {'petibm': 'PetIBM', 'cuibm': 'cuIBM'}
  plot_settings = {'label': software_name[args.software],
                   'color': '#336699', 'linestyle': '-', 'linewidth': 3,
                   'zorder': 10}
  validation_plot_settings = {'label': 'Ghia et al. (1982)',
                              'color': '#993333', 'linewidth': 0,
                              'markeredgewidth': 2, 'markeredgecolor': '#993333',
                              'markerfacecolor': 'none',
                              'marker': 'o', 'markersize': 8,
                              'zorder': 10}

  save_directory = os.path.join(simulation.directory, 'images')
  if not os.path.isdir(save_directory):
    os.makedirs(save_directory)
  simulation.fields['x-velocity'].plot_vertical_gridline_values(0.5,
                              plot_settings=plot_settings,
                              plot_limits=[0.0, 1.0, -0.75, 1.25],
                              save_directory=save_directory,
                              show=args.show,
                              validation_data=(u.y, u.values),
                              validation_plot_settings=validation_plot_settings,
                              style=os.path.join(os.environ['SNAKE'],
                                                 'snake', 
                                                 'styles', 
                                                 'mesnardo.mplstyle'))
  simulation.fields['y-velocity'].plot_horizontal_gridline_values(0.5,
                              plot_settings=plot_settings,
                              plot_limits=[0.0, 1.0, -0.75, 1.25],
                              save_directory=save_directory,
                              show=args.show,
                              validation_data=(v.x, v.values),
                              validation_plot_settings=validation_plot_settings,
                              style=os.path.join(os.environ['SNAKE'],
                                                 'snake', 
                                                 'styles', 
                                                 'mesnardo.mplstyle'))
def main(args):
    """Plots the steady drag coefficient of a sphere versus Reynolds number 
  and compares to experimental data (Roos and Willmarth, 1971)."""
    simulations = []
    for index, directory in enumerate(args.directories):
        simulations.append(
            Simulation(directory=directory,
                       description=args.description,
                       software=args.software,
                       re=args.re[index]))
        simulations[-1].read_forces()

    roos_willmarth_1971 = RoosWillmarth1971(
        file_path=args.validation_data_path)

    plot_drag_coefficient(simulations,
                          validation=roos_willmarth_1971,
                          save_directory=args.save_directory,
                          save_name=args.save_name,
                          limits=args.plot_limits,
                          show=args.show)
Example #8
0
def main(args):
  """Plots the the velocity, pressure, or vorticity fields at saved time-steps
  for a two-dimensional simulation.
  """
  simulation = Simulation(directory=args.directory, software=args.software)
  time_steps = simulation.get_time_steps(time_steps_range=args.time_steps_range)
  simulation.read_grid()
  bodies = [Body(path) for path in args.body_paths]

  if args.subtract_simulation:
    info = dict(zip(['software', 'directory'], 
                    args.subtract_simulation))
    other = Simulation(**info)
    other.read_grid()

  for time_step in time_steps:
    simulation.read_fields([args.field_name], time_step, 
                           periodic_directions=args.periodic_directions)
    
    field_name = (args.field_name if not args.subtract_simulation
                                  else args.field_name+'-subtracted')
    if args.subtract_simulation:
      other.read_fields([args.field_name], time_step, 
                        periodic_directions=args.periodic_directions)
      simulation.subtract(other, args.field_name, field_name)

    simulation.plot_contour(field_name,
                            field_range=args.range,
                            filled_contour=args.filled_contour,
                            view=args.bottom_left+args.top_right,
                            bodies=bodies,
                            save_name=args.save_name,
                            width=args.width, 
                            dpi=args.dpi)
computes the Strouhal number within a range, plots the force coefficients,
saves the figure, and prints a data-frame that contains the mean values.
"""

from snake.simulation import Simulation
from snake.cuibm.simulation import CuIBMSimulation


simulation = CuIBMSimulation(description='cuIBM (present)')
simulation.read_forces()
time_limits = (32.0, 64.0)
simulation.get_mean_forces(limits=time_limits)
simulation.get_strouhal(limits=time_limits, order=200)

other = Simulation(description='',
                   directory='',
                   software='')
other.read_forces()
other.get_mean_forces(limits=time_limits)
other.get_strouhal(limits=time_limits, order=200)

simulation.plot_forces(display_coefficients=True,
                       coefficient=2.0,
                       display_extrema=True, order=200,
                       limits=(0.0, 80.0, 0.0, 3.0),
                       other_simulations=other,
                       other_coefficients=2.0,
                       style='mesnardo',
                       save_name='forceCoefficientsCompareOther')

dataframe = simulation.create_dataframe_forces(display_strouhal=True,
Example #10
0
def main(args):
    """Writes the numerical solution into .vtk files."""
    # parse command-line
    simulation = Simulation(directory=args.directory, software=args.software)

    time_steps = simulation.get_time_steps(args.case_directory, args.time_steps)

    simulation.read_grid()

    for time_step in time_steps:
        if "velocity" in args.field_names:
            simulation.read_fields(
                ["x-velocity", "y-velocity", "z-velocity"], time_step, periodic_directions=args.periodic_directions
            )
            # need to get velocity at cell-centers, not staggered arrangement
            simulation.get_velocity_cell_centers()
            simulation.write_vtk("velocity", view=[args.bottom_left, args.top_right], stride=args.stride)
        if "pressure" in args.field_names:
            simulation.read_fields(["pressure"], time_step)
            simulation.write_vtk("pressure", view=[args.bottom_left, args.top_right], stride=args.stride)
Example #11
0
def main(args):
    """Writes the numerical solution into .vtk files."""
    # parse command-line
    simulation = Simulation(directory=args.directory, software=args.software)

    time_steps = simulation.get_time_steps(args.case_directory,
                                           args.time_steps)

    simulation.read_grid()

    for time_step in time_steps:
        if 'velocity' in args.field_names:
            simulation.read_fields(
                ['x-velocity', 'y-velocity', 'z-velocity'],
                time_step,
                periodic_directions=args.periodic_directions)
            # need to get velocity at cell-centers, not staggered arrangement
            simulation.get_velocity_cell_centers()
            simulation.write_vtk('velocity',
                                 view=[args.bottom_left, args.top_right],
                                 stride=args.stride)
        if 'pressure' in args.field_names:
            simulation.read_fields(['pressure'], time_step)
            simulation.write_vtk('pressure',
                                 view=[args.bottom_left, args.top_right],
                                 stride=args.stride)
computes the Strouhal number within a range, plots the force coefficients,
saves the figure, and prints a data-frame that contains the mean values.
"""

from snake.simulation import Simulation
from snake.openfoam.simulation import OpenFOAMSimulation


simulation = OpenFOAMSimulation(description='present')
simulation.read_forces(display_coefficients=True)
time_limits = (32.0, 64.0)
simulation.get_mean_forces(limits=time_limits)
simulation.get_strouhal(limits=time_limits, order=200)

other = Simulation(description='',
                   directory='',
                   software='')
other.read_forces()
other.get_mean_forces(limits=time_limits)
other.get_strouhal(limits=time_limits, order=200)

simulation.plot_forces(display_coefficients=True,
                       display_extrema=True, order=200,
                       limits=(0.0, 80.0, 0.0, 3.0),
                       other_simulations=other,
                       other_coefficients=1.0,
                       save_name='forceCoefficientsCompareOther',
                       style='mesnardo',
                       show=True)

dataframe = simulation.create_dataframe_forces(display_strouhal=True,
# description: Plots the instantaneous force coefficients
#              and compare to other results.
# Run this script from the simulation directory.


from snake.simulation import Simulation
from snake.petibm.simulation import PetIBMSimulation


simulation = PetIBMSimulation(description='PetIBM (present)')
simulation.read_forces()
simulation.get_mean_forces(limits=[32.0, 64.0])
simulation.get_strouhal(limits=[32.0, 64.0], order=200)

other = Simulation(description='',
                   directory='',
                   software='')
other.read_forces()
other.get_mean_forces(limits=[32.0, 64.0])
other.get_strouhal(limits=[32.0, 64.0], order=200)

simulation.plot_forces(display_coefficients=True,
                       coefficient=2.0,
                       display_extrema=True, order=200,
                       limits=(0.0, 80.0, 0.0, 3.0),
                       other_simulations=other,
                       other_coefficients=2.0,
                       save_name='forceCoefficientsCompare')

dataframe = simulation.create_dataframe_forces(display_strouhal=True,
                                               display_coefficients=True,