Exemplo n.º 1
0
def _solve_varproblem(*args, **kwargs):
    "Solve variational problem a == L or F == 0"

    # Extract arguments
    eq, u, bcs, J, Jp, M, form_compiler_parameters, \
        solver_parameters, nullspace, nullspace_T, \
        near_nullspace, \
        options_prefix = _extract_args(*args, **kwargs)

    appctx = kwargs.get("appctx", {})
    # Solve linear variational problem
    if isinstance(eq.lhs, ufl.Form) and isinstance(eq.rhs, ufl.Form):

        # Create problem
        problem = vs.LinearVariationalProblem(
            eq.lhs,
            eq.rhs,
            u,
            bcs,
            Jp,
            form_compiler_parameters=form_compiler_parameters)

        # Create solver and call solve
        solver = vs.LinearVariationalSolver(
            problem,
            solver_parameters=solver_parameters,
            nullspace=nullspace,
            transpose_nullspace=nullspace_T,
            near_nullspace=near_nullspace,
            options_prefix=options_prefix,
            appctx=appctx)
        solver.solve()

    # Solve nonlinear variational problem
    else:

        if eq.rhs != 0:
            raise TypeError(
                "Only '0' support on RHS of nonlinear Equation, not %r" %
                eq.rhs)
        # Create problem
        problem = vs.NonlinearVariationalProblem(
            eq.lhs,
            u,
            bcs,
            J,
            Jp,
            form_compiler_parameters=form_compiler_parameters)

        # Create solver and call solve
        solver = vs.NonlinearVariationalSolver(
            problem,
            solver_parameters=solver_parameters,
            nullspace=nullspace,
            transpose_nullspace=nullspace_T,
            near_nullspace=near_nullspace,
            options_prefix=options_prefix,
            appctx=appctx)
        solver.solve()
Exemplo n.º 2
0
def _solve_varproblem(*args, **kwargs):
    "Solve variational problem a == L or F == 0"

    # Extract arguments
    eq, u, bcs, J, Jp, M, form_compiler_parameters, \
        solver_parameters, nullspace, options_prefix, \
        nest = _extract_args(*args, **kwargs)

    # Solve linear variational problem
    if isinstance(eq.lhs, ufl.Form) and isinstance(eq.rhs, ufl.Form):

        # Create problem
        problem = vs.LinearVariationalProblem(
            eq.lhs,
            eq.rhs,
            u,
            bcs,
            Jp,
            form_compiler_parameters=form_compiler_parameters,
            nest=nest)

        # Create solver and call solve
        solver = vs.LinearVariationalSolver(
            problem,
            solver_parameters=solver_parameters,
            nullspace=nullspace,
            options_prefix=options_prefix)
        with progress(INFO, 'Solving linear variational problem'):
            solver.solve()

    # Solve nonlinear variational problem
    else:

        if eq.rhs != 0:
            raise TypeError(
                "Only '0' support on RHS of nonlinear Equation, not %r" %
                eq.rhs)
        # Create problem
        problem = vs.NonlinearVariationalProblem(
            eq.lhs,
            u,
            bcs,
            J,
            Jp,
            form_compiler_parameters=form_compiler_parameters,
            nest=nest)

        # Create solver and call solve
        solver = vs.NonlinearVariationalSolver(
            problem,
            solver_parameters=solver_parameters,
            nullspace=nullspace,
            options_prefix=options_prefix)
        with progress(INFO, 'Solving nonlinear variational problem'):
            solver.solve()