コード例 #1
0
def elliptic_oned_demo(args):
    args['PROBLEM-NUMBER'] = int(args['PROBLEM-NUMBER'])
    assert 0 <= args['PROBLEM-NUMBER'] <= 1, ValueError('Invalid problem number.')
    args['N'] = int(args['N'])

    rhss = [ExpressionFunction('ones(x.shape[:-1]) * 10', 1, ()),
            ExpressionFunction('(x - 0.5)**2 * 1000', 1, ())]
    rhs = rhss[args['PROBLEM-NUMBER']]

    d0 = ExpressionFunction('1 - x', 1, ())
    d1 = ExpressionFunction('x', 1, ())

    parameter_space = CubicParameterSpace({'diffusionl': 0}, 0.1, 1)
    f0 = ProjectionParameterFunctional('diffusionl', 0)
    f1 = ExpressionParameterFunctional('1', {})

    problem = StationaryProblem(
        domain=LineDomain(),
        rhs=rhs,
        diffusion=LincombFunction([d0, d1], [f0, f1]),
        dirichlet_data=ConstantFunction(value=0, dim_domain=1),
        name='1DProblem'
    )

    print('Discretize ...')
    discretizer = discretize_stationary_fv if args['--fv'] else discretize_stationary_cg
    d, data = discretizer(problem, diameter=1 / args['N'])
    print(data['grid'])
    print()

    print('Solve ...')
    U = d.solution_space.empty()
    for mu in parameter_space.sample_uniformly(10):
        U.append(d.solve(mu))
    d.visualize(U, title='Solution for diffusionl in [0.1, 1]')
コード例 #2
0
def elliptic_oned_demo(args):
    args['PROBLEM-NUMBER'] = int(args['PROBLEM-NUMBER'])
    assert 0 <= args['PROBLEM-NUMBER'] <= 1, ValueError('Invalid problem number.')
    args['N'] = int(args['N'])

    rhss = [GenericFunction(lambda X: np.ones(X.shape[:-1]) * 10, dim_domain=1),
            GenericFunction(lambda X: (X[..., 0] - 0.5) ** 2 * 1000, dim_domain=1)]
    rhs = rhss[args['PROBLEM-NUMBER']]

    d0 = GenericFunction(lambda X: 1 - X[..., 0], dim_domain=1)
    d1 = GenericFunction(lambda X: X[..., 0], dim_domain=1)

    parameter_space = CubicParameterSpace({'diffusionl': 0}, 0.1, 1)
    f0 = ProjectionParameterFunctional('diffusionl', 0)
    f1 = GenericParameterFunctional(lambda mu: 1, {})

    print('Solving on OnedGrid(({0},{0}))'.format(args['N']))

    print('Setup Problem ...')
    problem = EllipticProblem(domain=LineDomain(), rhs=rhs, diffusion_functions=(d0, d1),
                              diffusion_functionals=(f0, f1), dirichlet_data=ConstantFunction(value=0, dim_domain=1),
                              name='1DProblem')

    print('Discretize ...')
    discretizer = discretize_elliptic_fv if args['--fv'] else discretize_elliptic_cg
    discretization, _ = discretizer(problem, diameter=1 / args['N'])

    print('The parameter type is {}'.format(discretization.parameter_type))

    U = discretization.solution_space.empty()
    for mu in parameter_space.sample_uniformly(10):
        U.append(discretization.solve(mu))

    print('Plot ...')
    discretization.visualize(U, title='Solution for diffusionl in [0.1, 1]')
コード例 #3
0
def burgers_problem(v=1.,
                    circle=True,
                    initial_data_type='sin',
                    parameter_range=(1., 2.)):
    """One-dimensional Burgers-type problem.

    The problem is to solve ::

        ∂_t u(x, t, μ)  +  ∂_x (v * u(x, t, μ)^μ) = 0
                                       u(x, 0, μ) = u_0(x)

    for u with t in [0, 0.3] and x in [0, 2].

    Parameters
    ----------
    v
        The velocity v.
    circle
        If `True`, impose periodic boundary conditions. Otherwise Dirichlet left,
        outflow right.
    initial_data_type
        Type of initial data (`'sin'` or `'bump'`).
    parameter_range
        The interval in which μ is allowed to vary.
    """

    assert initial_data_type in ('sin', 'bump')

    if initial_data_type == 'sin':
        initial_data = ExpressionFunction('0.5 * (sin(2 * pi * x) + 1.)', 1,
                                          ())
        dirichlet_data = ConstantFunction(dim_domain=1, value=0.5)
    else:
        initial_data = ExpressionFunction('(x >= 0.5) * (x <= 1) * 1.', 1, ())
        dirichlet_data = ConstantFunction(dim_domain=1, value=0.)

    return InstationaryProblem(
        StationaryProblem(
            domain=CircleDomain([0, 2]) if circle else LineDomain([0, 2],
                                                                  right=None),
            dirichlet_data=dirichlet_data,
            rhs=None,
            nonlinear_advection=ExpressionFunction('abs(x)**exponent * v', 1,
                                                   (1, ), {'exponent':
                                                           ()}, {'v': v}),
            nonlinear_advection_derivative=ExpressionFunction(
                'exponent * abs(x)**(exponent-1) * sign(x) * v', 1, (1, ),
                {'exponent': ()}, {'v': v}),
        ),
        T=0.3,
        initial_data=initial_data,
        parameter_space=CubicParameterSpace({'exponent': 0}, *parameter_range),
        name="burgers_problem({}, {}, '{}')".format(v, circle,
                                                    initial_data_type))
コード例 #4
0
ファイル: gui.py プロジェクト: ftschindler-work/pymor
def test_visualize_patch(backend_gridtype):
    backend, gridtype = backend_gridtype
    domain = LineDomain() if gridtype is OnedGrid else RectDomain()
    dim = 1 if gridtype is OnedGrid else 2
    rhs = GenericFunction(lambda X: np.ones(X.shape[:-1]) * 10, dim)  # NOQA
    dirichlet = GenericFunction(lambda X: np.zeros(X.shape[:-1]), dim)  # NOQA
    diffusion = GenericFunction(lambda X: np.ones(X.shape[:-1]), dim)  # NOQA
    problem = StationaryProblem(domain=domain, rhs=rhs, dirichlet_data=dirichlet, diffusion=diffusion)
    grid, bi = discretize_domain_default(problem.domain, grid_type=gridtype)
    m, data = discretize_stationary_cg(analytical_problem=problem, grid=grid, boundary_info=bi)
    U = m.solve()
    try:
        visualize_patch(data['grid'], U=U, backend=backend)
    except QtMissing as ie:
        pytest.xfail("Qt missing")
    finally:
        stop_gui_processes()
コード例 #5
0
ファイル: gui.py プロジェクト: michaellaier/pymor
def test_visualize_patch(backend_gridtype):
    backend, gridtype = backend_gridtype
    domain = LineDomain() if gridtype is OnedGrid else RectDomain()
    dim = 1 if gridtype is OnedGrid else 2
    rhs = GenericFunction(lambda X: np.ones(X.shape[:-1]) * 10, dim)  # NOQA
    dirichlet = GenericFunction(lambda X: np.zeros(X.shape[:-1]), dim)  # NOQA
    diffusion = GenericFunction(lambda X: np.ones(X.shape[:-1]), dim)  # NOQA
    problem = EllipticProblem(domain=domain,
                              rhs=rhs,
                              dirichlet_data=dirichlet,
                              diffusion_functions=(diffusion, ))
    grid, bi = discretize_domain_default(problem.domain, grid_type=gridtype)
    discretization, data = discretize_elliptic_cg(analytical_problem=problem,
                                                  grid=grid,
                                                  boundary_info=bi)
    U = discretization.solve()
    visualize_patch(data['grid'], U=U, backend=backend)
    sleep(2)  # so gui has a chance to popup
    for child in multiprocessing.active_children():
        child.terminate()
コード例 #6
0
ファイル: burgers.py プロジェクト: michaellaier/pymor
    def __init__(self,
                 v=1.,
                 circle=True,
                 initial_data_type='sin',
                 parameter_range=(1., 2.)):

        assert initial_data_type in ('sin', 'bump')

        flux_function = BurgersFlux(v)
        flux_function_derivative = BurgersFluxDerivative(v)

        if initial_data_type == 'sin':
            initial_data = BurgersSinInitialData()
            dirichlet_data = ConstantFunction(dim_domain=1, value=0.5)
        else:
            initial_data = BurgersBumpInitialData()
            dirichlet_data = ConstantFunction(dim_domain=1, value=0)

        if circle:
            domain = CircleDomain([0, 2])
        else:
            domain = LineDomain([0, 2], right=None)

        super(BurgersProblem,
              self).__init__(domain=domain,
                             rhs=None,
                             flux_function=flux_function,
                             flux_function_derivative=flux_function_derivative,
                             initial_data=initial_data,
                             dirichlet_data=dirichlet_data,
                             T=0.3,
                             name='BurgersProblem')

        self.parameter_space = CubicParameterSpace({'exponent': 0},
                                                   *parameter_range)
        self.parameter_range = parameter_range
        self.initial_data_type = initial_data_type
        self.circle = circle
        self.v = v