Exemplo n.º 1
0
def test_three_grids(nx=11, ny=11, ratio=3, offset=0):
    """Computes the observed order of convergence using the solution on three
  consecutive grids with constant refinement ratio.

  The solution on the finest grid is random.
  The solution of the medium grid is the finest solution restricted 
  and incremented by 1.
  The solution of the coarsest grid is the finest solution restricted
  and incremented by 1+ratio.
  Therefore, no matter the norm used, we expect an order of convergence of 1.

  Parameters
  ----------
  nx, ny: integers, optional
    Number of grid-points along each direction on the grid used a mask 
    to project the three solutions;
    default: 11, 11.
  ratio: integer, optional
    Grid refinement ratio;
    default: 3.
  offset: integer, optional
    Position of the coarsest grid relatively to the mask grid;
    default: 0 (the coarsest solution is defined on the mask grid)
  """
    # grid used as mask
    grid = [numpy.random.random(nx), numpy.random.random(ny)]
    # create fields
    fine = Field(values=numpy.random.rand(ny * ratio**(offset + 2),
                                          nx * ratio**(offset + 2)),
                 label='fine')
    medium = Field(values=fine.values[::ratio, ::ratio] + 1.0, label='medium')
    coarse = Field(values=fine.values[::ratio**2, ::ratio**2] + (1.0 + ratio),
                   label='coarse')
    # fill nodal stations
    coarse.x, coarse.y = numpy.ones(nx * ratio**offset), numpy.ones(
        ny * ratio**offset)
    coarse.x[::ratio**offset], coarse.y[::ratio**offset] = grid[0][:], grid[
        1][:]
    medium.x, medium.y = numpy.ones(nx * ratio**(offset + 1)), numpy.ones(
        ny * ratio**(offset + 1))
    medium.x[::ratio**(offset +
                       1)], medium.y[::ratio**(offset +
                                               1)] = grid[0][:], grid[1][:]
    fine.x, fine.y = numpy.ones(nx * ratio**(offset + 2)), numpy.ones(
        ny * ratio**(offset + 2))
    fine.x[::ratio**(offset +
                     2)], fine.y[::ratio**(offset +
                                           2)] = grid[0][:], grid[1][:]
    # compute observed order of convergence
    p = convergence.get_observed_order(coarse, medium, fine, ratio, grid)
    assert p == 1.0
    p = convergence.get_observed_order(coarse,
                                       medium,
                                       fine,
                                       ratio,
                                       grid,
                                       order=numpy.inf)
    assert p == 1.0
Exemplo n.º 2
0
def test_three_grids(nx=11, ny=11, ratio=3, offset=0):
  """Computes the observed order of convergence using the solution on three
  consecutive grids with constant refinement ratio.

  The solution on the finest grid is random.
  The solution of the medium grid is the finest solution restricted 
  and incremented by 1.
  The solution of the coarsest grid is the finest solution restricted
  and incremented by 1+ratio.
  Therefore, no matter the norm used, we expect an order of convergence of 1.

  Parameters
  ----------
  nx, ny: integers, optional
    Number of grid-points along each direction on the grid used a mask 
    to project the three solutions;
    default: 11, 11.
  ratio: integer, optional
    Grid refinement ratio;
    default: 3.
  offset: integer, optional
    Position of the coarsest grid relatively to the mask grid;
    default: 0 (the coarsest solution is defined on the mask grid)
  """
  # grid used as mask
  grid = [numpy.random.random(nx), numpy.random.random(ny)]
  # create fields
  fine = Field(values=numpy.random.rand(ny*ratio**(offset+2), nx*ratio**(offset+2)), 
               label='fine')
  medium = Field(values=fine.values[::ratio, ::ratio]+1.0, 
                 label='medium')
  coarse = Field(values=fine.values[::ratio**2, ::ratio**2]+(1.0+ratio), 
                 label='coarse')
  # fill nodal stations
  coarse.x, coarse.y = numpy.ones(nx*ratio**offset), numpy.ones(ny*ratio**offset)
  coarse.x[::ratio**offset], coarse.y[::ratio**offset] = grid[0][:], grid[1][:]
  medium.x, medium.y = numpy.ones(nx*ratio**(offset+1)), numpy.ones(ny*ratio**(offset+1))
  medium.x[::ratio**(offset+1)], medium.y[::ratio**(offset+1)] = grid[0][:], grid[1][:]
  fine.x, fine.y = numpy.ones(nx*ratio**(offset+2)), numpy.ones(ny*ratio**(offset+2))
  fine.x[::ratio**(offset+2)], fine.y[::ratio**(offset+2)] = grid[0][:], grid[1][:]
  # compute observed order of convergence
  p = convergence.get_observed_order(coarse, medium, fine, ratio, grid)
  assert p == 1.0
  p = convergence.get_observed_order(coarse, medium, fine, ratio, grid,
                                     order=numpy.inf)
  assert p == 1.0