def init_grid_and_problem(config):
    logger = getLogger('senegal_proceedings_problem.senegal_proceedings_problem')
    logger.info('initializing grid and problem ... ')

    lower_left = [-1, -1]
    upper_right = [1, 1]
    inner_boundary_id = 18446744073709551573
    grid = make_grid(lower_left=lower_left,
                     upper_right=upper_right,
                     num_elements=config['num_coarse_grid_elements'],
                     num_refinements=config['num_grid_refinements'],
                     num_partitions=config['num_grid_subdomains'],
                     num_oversampling_layers=config['num_grid_oversampling_layers'],
                     inner_boundary_segment_index=inner_boundary_id)

    all_dirichlet_boundary_info = make_boundary_info(grid, {'type': 'xt.grid.boundaryinfo.alldirichlet'})

    def make_values(background, foreground):
        checkerboard_values = [[background]]*36
        for ii in (7, 25):
            checkerboard_values[ii] = [foreground]
        return checkerboard_values

    diffusion_functions = [make_checkerboard_function_1x1(grid, lower_left, upper_right,
                                                          [6, 6], make_values(1., 0.),
                                                          name='lambda_0'),
                           make_checkerboard_function_1x1(grid, lower_left, upper_right,
                                                          [6, 6], make_values(0., 1.),
                                                          name='lambda_1')]

    parameter_type = {'diffusion': (2,)}
    coefficients = [ExpressionParameterFunctional('1.1 + sin(diffusion[0])*diffusion[1]', parameter_type),
                    ExpressionParameterFunctional('1.1 + sin(diffusion[1])', parameter_type)]

    kappa = make_constant_function_2x2(grid, [[1., 0.], [0., 1.]], name='kappa')
    f = make_expression_function_1x1(grid, 'x', '0.5*pi*pi*cos(0.5*pi*x[0])*cos(0.5*pi*x[1])', order=2, name='f')
    lambda_bar = make_checkerboard_function_1x1(grid, lower_left, upper_right, [6, 6], make_values(1.1, 1.1), name='lambda_bar')
    lambda_hat = make_checkerboard_function_1x1(grid, lower_left, upper_right, [6, 6], make_values(1.1, 1.1), name='lambda_hat')

    return {'grid': grid,
            'boundary_info': all_dirichlet_boundary_info,
            'inner_boundary_id': inner_boundary_id,
            'lambda': {'functions': diffusion_functions,
                       'coefficients': coefficients},
            'lambda_bar': lambda_bar,
            'lambda_hat': lambda_hat,
            'kappa': kappa,
            'f': f,
            'parameter_type': parameter_type,
            'mu_bar': (0, 0),
            'mu_hat': (0, 0),
            'mu_min': (0, 0),
            'mu_max': (np.pi, np.pi),
            'parameter_range': (0, np.pi)}
Example #2
0
def test_blockspace():
    from dune.gdt.__spaces_block import make_block_dg_dd_subdomain_view_to_1x1_gdt_p1_space as make_block_space
    grid = make_grid()
    block_space = make_block_space(grid)
    diffusion = make_expression_function_1x1(grid, 'x', '1', order=2, name='lambda_0')
    kappa = make_constant_function_2x2(grid, [[1., 0.], [0., 1.]], name='kappa')
    local_all_neumann_boundary_info = make_boundary_info_on_dd_subdomain_layer(grid, {'type': 'xt.grid.boundaryinfo.allneumann'})

    local_matrices = [None] * grid.num_subdomains
    local_patterns = [block_space.local_space(ii).compute_pattern('face_and_volume')
                      for ii in range(block_space.num_blocks)]
    for ii in range(grid.num_subdomains):
        local_matrices[ii] = Matrix(block_space.local_space(ii).size(),
                                    block_space.local_space(ii).size(),
                                    local_patterns[ii])
        ipdg_operator = make_elliptic_swipdg_matrix_operator(diffusion_factor=diffusion, diffusion_tensor=kappa,
                                                             boundary_info=local_all_neumann_boundary_info,
                                                             matrix=local_matrices[ii],
                                                             space=block_space.local_space(ii), over_integrate=2)
        ipdg_operator.assemble()
Example #3
0
def init_grid_and_problem(config, mu_bar=(1, 1, 1, 1), mu_hat=(1, 1, 1, 1)):
    logger = getLogger('thermalblock_problem.thermalblock_problem')
    logger.info('initializing grid and problem ... ')

    lower_left = [-1, -1]
    upper_right = [1, 1]
    inner_boundary_id = 18446744073709551573
    grid = make_grid((lower_left, upper_right), config['num_subdomains'],
                     config['half_num_fine_elements_per_subdomain_and_dim'],
                     inner_boundary_id)
    all_dirichlet_boundary_info = make_boundary_info(
        grid, {'type': 'xt.grid.boundaryinfo.alldirichlet'})

    XBLOCKS = 2
    YBLOCKS = 2

    def diffusion_function_factory(ix, iy):
        values = [[0.]] * (YBLOCKS * XBLOCKS)
        values[ix + XBLOCKS * iy] = [1.]
        return make_checkerboard_function_1x1(grid_provider=grid,
                                              lower_left=lower_left,
                                              upper_right=upper_right,
                                              num_elements=[XBLOCKS, YBLOCKS],
                                              values=values,
                                              name='diffusion_{}_{}'.format(
                                                  ix, iy))

    diffusion_functions = [
        diffusion_function_factory(ix, iy)
        for ix, iy in product(range(XBLOCKS), range(YBLOCKS))
    ]

    parameter_type = {'diffusion': (YBLOCKS, XBLOCKS)}
    coefficients = [
        ProjectionParameterFunctional(component_name='diffusion',
                                      component_shape=(YBLOCKS, XBLOCKS),
                                      coordinates=(YBLOCKS - y - 1, x))
        for x in range(XBLOCKS) for y in range(YBLOCKS)
    ]

    kappa = make_constant_function_2x2(grid, [[1., 0.], [0., 1.]],
                                       name='kappa')
    f = make_expression_function_1x1(
        grid,
        'x',
        '0.5*pi*pi*cos(0.5*pi*x[0])*cos(0.5*pi*x[1])',
        order=2,
        name='f')
    lambda_bar_values = [[0.]] * (YBLOCKS * XBLOCKS)
    lambda_hat_values = [[0.]] * (YBLOCKS * XBLOCKS)
    counter = 0
    for ix in range(YBLOCKS):
        for iy in range(XBLOCKS):
            lambda_bar_values[ix + XBLOCKS * iy] = [
                coefficients[counter].evaluate(mu_bar)
            ]
            lambda_hat_values[ix + XBLOCKS * iy] = [
                coefficients[counter].evaluate(mu_hat)
            ]
            counter += 1
    lambda_bar = make_checkerboard_function_1x1(
        grid_provider=grid,
        lower_left=lower_left,
        upper_right=upper_right,
        num_elements=[XBLOCKS, YBLOCKS],
        values=lambda_bar_values,
        name='lambda_bar')
    lambda_hat = make_checkerboard_function_1x1(
        grid_provider=grid,
        lower_left=lower_left,
        upper_right=upper_right,
        num_elements=[XBLOCKS, YBLOCKS],
        values=lambda_hat_values,
        name='lambda_hat')

    return {
        'grid':
        grid,
        'boundary_info':
        all_dirichlet_boundary_info,
        'inner_boundary_id':
        inner_boundary_id,
        'lambda': {
            'functions': diffusion_functions,
            'coefficients': coefficients
        },
        'lambda_bar':
        lambda_bar,
        'lambda_hat':
        lambda_hat,
        'kappa':
        kappa,
        'f':
        f,
        'parameter_type':
        parameter_type,
        'mu_bar':
        mu_bar,
        'mu_hat':
        mu_hat,
        'mu_min': (min(0.1, b, h) for b, h in zip(mu_bar, mu_hat)),
        'mu_max': (max(1, b, h) for b, h in zip(mu_bar, mu_hat)),
        'parameter_range':
        (min((0.1, ) + mu_bar + mu_hat), max((1, ) + mu_bar + mu_hat))
    }
def init_grid_and_problem(config, mu_bar=1, mu_hat=1, mpi_comm=MPI.COMM_WORLD):
    # assert mpi_comm.Get_size() < MPI.COMM_WORLD.Get_size() or mpi_comm.Get_size() == 1
    logger = getLogger('non_paramtric_problem')
    logger.info('initializing grid and problem ... ')

    lower_left = [-1, -1]
    upper_right = [1, 1]
    inner_boundary_id = 18446744073709551573
    grid = make_grid((lower_left, upper_right),
                     config['num_subdomains'],
                     config['half_num_fine_elements_per_subdomain_and_dim'],
                     inner_boundary_id,
                     mpi_comm=mpi_comm)
    all_dirichlet_boundary_info = make_boundary_info(
        grid, {'type': 'xt.grid.boundaryinfo.alldirichlet'})

    diffusion_functions = make_expression_function_1x1(
        grid,
        'x',
        '1+(cos(0.5*pi*x[0])*cos(0.5*pi*x[1]))',
        order=2,
        name='lambda_0')
    diffusion_functions = make_constant_function_1x1(grid, 1, name='lambda')

    kappa = make_constant_function_2x2(grid, [[1., 0.], [0., 1.]],
                                       name='kappa')
    f = make_expression_function_1x1(
        grid,
        'x',
        '0.5*pi*pi*cos(0.5*pi*x[0])*cos(0.5*pi*x[1])',
        order=2,
        name='f')
    lambda_bar = make_expression_function_1x1(
        grid,
        'x',
        '1+(1-{})*(cos(0.5*pi*x[0])*cos(0.5*pi*x[1]))'.format(mu_bar),
        order=2,
        name='lambda_bar')
    lambda_hat = make_expression_function_1x1(
        grid,
        'x',
        '1+(1-{})*(cos(0.5*pi*x[0])*cos(0.5*pi*x[1]))'.format(mu_hat),
        order=2,
        name='lambda_hat')

    return {
        'grid': grid,
        'mpi_comm': mpi_comm,
        'boundary_info': all_dirichlet_boundary_info,
        'inner_boundary_id': inner_boundary_id,
        'lambda': diffusion_functions,
        'lambda_bar': lambda_bar,
        'lambda_hat': lambda_hat,
        'kappa': kappa,
        'f': f,
        'parameter_type': None,
        'mu_bar': None,
        'mu_hat': None,
        'mu_min': None,
        'mu_max': None,
        'parameter_range': (min(0.1, mu_bar, mu_hat), max(1, mu_bar, mu_hat))
    }
def init_grid_and_problem(config, mu_bar=1, mu_hat=1, mpi_comm=MPI.COMM_WORLD):
    # assert mpi_comm.Get_size() < MPI.COMM_WORLD.Get_size() or mpi_comm.Get_size() == 1
    logger = getLogger('OS2015_academic_problem.OS2015_academic_problem')
    logger.info('initializing grid and problem ... ')

    lower_left = [-1, -1]
    upper_right = [1, 1]
    inner_boundary_id = 18446744073709551573
    grid = make_grid((lower_left, upper_right),
                     config['num_subdomains'],
                     config['half_num_fine_elements_per_subdomain_and_dim'],
                     inner_boundary_id,
                     mpi_comm=mpi_comm)
    grid_info(logger.error, grid, mpi_comm)
    all_dirichlet_boundary_info = make_boundary_info(
        grid, {'type': 'xt.grid.boundaryinfo.alldirichlet'})

    cos = '(cos(0.5*pi*x[0])*cos(0.5*pi*x[1]))'
    diffusion_functions = [
        make_expression_function_1x1(grid,
                                     'x',
                                     '1+{}'.format(cos),
                                     order=2,
                                     name='lambda_0'),
        make_expression_function_1x1(grid,
                                     'x',
                                     '-1*{}'.format(cos),
                                     order=2,
                                     name='lambda_1')
    ]
    # diffusion_functions = [make_expression_function_1x1(
    #     grid, 'x', '1', order=2, name='lambda_0'),
    #     make_expression_function_1x1(grid, 'x', 'x[0]', order=2, name='lambda_1')]
    parameter_type = {'diffusion': (1, )}
    coefficients = [
        ExpressionParameterFunctional('1.', parameter_type),
        ExpressionParameterFunctional('diffusion', parameter_type)
    ]

    kappa = make_constant_function_2x2(grid, [[1., 0.], [0., 1.]],
                                       name='kappa')
    f = make_expression_function_1x1(grid,
                                     'x',
                                     '0.5*pi*pi*{}'.format(cos),
                                     order=2,
                                     name='f')
    mbc = '1+(1-{})*{}'.format(mu_bar, cos)
    lambda_bar = make_expression_function_1x1(grid,
                                              'x',
                                              mbc,
                                              order=2,
                                              name='lambda_bar')
    lambda_hat = make_expression_function_1x1(grid,
                                              'x',
                                              mbc,
                                              order=2,
                                              name='lambda_hat')

    return {
        'grid': grid,
        'mpi_comm': mpi_comm,
        'boundary_info': all_dirichlet_boundary_info,
        'inner_boundary_id': inner_boundary_id,
        'lambda': {
            'functions': diffusion_functions,
            'coefficients': coefficients
        },
        'lambda_bar': lambda_bar,
        'lambda_hat': lambda_hat,
        'kappa': kappa,
        'f': f,
        'parameter_type': parameter_type,
        'mu_bar': (mu_bar, ),
        'mu_hat': (mu_hat, ),
        'mu_min': (min(0.1, mu_bar, mu_hat), ),
        'mu_max': (max(1, mu_bar, mu_hat), ),
        'parameter_range': (min(0.1, mu_bar, mu_hat), max(1, mu_bar, mu_hat))
    }
def init_grid_and_problem(config, mu_bar=(1, ), mu_hat=(1, )):
    logger = getLogger(
        'artificial_channels_problem.artificial_channels_problem')
    logger.info('initializing grid and problem ... ')

    lower_left = [0, 0]
    upper_right = [1, 1]

    mu_min = min((0.01, ) + mu_bar + mu_hat)
    mu_max = max((1, ) + mu_bar + mu_hat)

    inner_boundary_id = 18446744073709551573
    grid = make_grid((lower_left, upper_right), config['num_subdomains'],
                     config['half_num_fine_elements_per_subdomain_and_dim'],
                     inner_boundary_id)

    all_dirichlet_boundary_info = make_boundary_info(
        grid, {'type': 'xt.grid.boundaryinfo.alldirichlet'})

    def horizontal_channels(value):
        return [[[[1 / 16, 1 / 8 - 1 / 32], [1 - 1 / 16, 1 / 8 + 1 / 32]],
                 value],
                [[[1 / 16, 3 / 8 - 1 / 32], [1 - 1 / 16, 3 / 8 + 1 / 32]],
                 value],
                [[[1 / 16, 5 / 8 - 1 / 32], [1 - 1 / 16, 5 / 8 + 1 / 32]],
                 value],
                [[[1 / 16, 7 / 8 - 1 / 32], [1 - 1 / 16, 7 / 8 + 1 / 32]],
                 value]]

    def fixed_vertical_connections(value):
        return [[[[1 / 16, 1 / 8 + 1 / 32], [1 / 4 - 1 / 16, 3 / 8 - 1 / 32]],
                 value],
                [[[1 / 16, 5 / 8 + 1 / 32], [1 / 4 - 1 / 16, 7 / 8 - 1 / 32]],
                 value],
                [[[3 / 4 + 1 / 16, 1 / 8 + 1 / 32],
                  [1 - 1 / 16, 3 / 8 - 1 / 32]], value],
                [[[3 / 4 + 1 / 16, 5 / 8 + 1 / 32],
                  [1 - 1 / 16, 7 / 8 - 1 / 32]], value]]

    def switched_vertical_connections(value):
        return [[[[1 / 16, 3 / 8 + 1 / 32], [1 / 4 - 1 / 16, 5 / 8 - 1 / 32]],
                 value],
                [[[3 / 4 + 1 / 16, 3 / 8 + 1 / 32],
                  [1 - 1 / 16, 5 / 8 - 1 / 32]], value]]

    diffusion_horizontal_channels = make_indicator_function_1x1(
        grid, horizontal_channels(1), 'horizontal_channels')
    diffusion_fixed_vertical_connections = make_indicator_function_1x1(
        grid, fixed_vertical_connections(1), 'fixed_vertical_connections')
    diffusion_switched_vertical_connections_right = make_indicator_function_1x1(
        grid, switched_vertical_connections(1),
        'switched_vertical_connections')
    diffusion_background = (make_constant_function_1x1(grid, 1) -
                            diffusion_horizontal_channels -
                            diffusion_fixed_vertical_connections -
                            diffusion_switched_vertical_connections_right)

    parameter_type = {'switch': (1, )}
    lambda_functions = [
        diffusion_background, diffusion_horizontal_channels,
        diffusion_fixed_vertical_connections,
        diffusion_switched_vertical_connections_right
    ]
    lambda_coefficients = [
        ExpressionParameterFunctional(str(mu_min), parameter_type),
        ExpressionParameterFunctional(str(mu_max), parameter_type),
        ExpressionParameterFunctional(str(mu_max), parameter_type),
        ProjectionParameterFunctional(component_name='switch',
                                      component_shape=(1, ),
                                      coordinates=(0, ))
    ]
    kappa = make_constant_function_2x2(grid, [[1., 0.], [0., 1.]],
                                       name='kappa')
    f_functions = [
        make_indicator_function_1x1(grid, [
            [[[1 / 16, 5 / 8 + 1 / 32], [1 / 4 - 1 / 16, 7 / 8 - 1 / 32]], 1],
        ], 'top_left'),
        make_indicator_function_1x1(grid, [[
            [[3 / 4 + 1 / 16, 1 / 8 + 1 / 32], [1 - 1 / 16, 3 / 8 - 1 / 32]], 1
        ], [[[3 / 4 + 1 / 16, 5 / 8 + 1 / 32], [1 - 1 / 16, 7 / 8 - 1 / 32]], 1
            ]], 'right')
    ]
    f_coefficients = [
        ExpressionParameterFunctional('sin(2 * 2 * pi * _t) > 0', {'_t': ()}),
        ExpressionParameterFunctional('-1', None)
    ]

    def create_lambda(mu):
        return (
            make_constant_function_1x1(grid, mu_min) -
            make_indicator_function_1x1(grid, horizontal_channels(mu_min)) -
            make_indicator_function_1x1(grid,
                                        fixed_vertical_connections(mu_min)) -
            make_indicator_function_1x1(
                grid, switched_vertical_connections(mu_min)) +
            make_indicator_function_1x1(grid, horizontal_channels(mu_max)) +
            make_indicator_function_1x1(grid,
                                        fixed_vertical_connections(mu_max)) +
            make_indicator_function_1x1(grid,
                                        switched_vertical_connections(mu[0])))

    return {
        'grid': grid,
        'boundary_info': all_dirichlet_boundary_info,
        'inner_boundary_id': inner_boundary_id,
        'lambda': {
            'functions': lambda_functions,
            'coefficients': lambda_coefficients
        },
        'lambda_bar': create_lambda(mu_bar),
        'lambda_hat': create_lambda(mu_hat),
        'kappa': kappa,
        'f': {
            'functions': f_functions,
            'coefficients': f_coefficients
        },
        'parameter_type': parameter_type,
        'mu_bar': mu_bar,
        'mu_hat': mu_hat,
        'mu_min': (mu_min, ),
        'mu_max': (mu_max, ),
        'parameter_range': (mu_min, mu_max)
    }