Exemplo n.º 1
0
def solve(tstep, w_, w_1, w_tmp, solvers, enable_PF, enable_EC, enable_NS,
          **namespace):
    """ Solve equations. """
    timer_outer = df.Timer("Solve system")
    if enable_PF:
        timer_inner = df.Timer("Solve supproblem PF")
        mpi_barrier()
        solvers["PF"].solve()
        timer_inner.stop()
    if enable_EC:
        timer_inner = df.Timer("Solve subproblem EC")
        mpi_barrier()
        solvers["EC"].solve()
        timer_inner.stop()
    if enable_NS:
        # Step 1: Predict u
        timer = df.Timer("NS: Predict velocity.")
        solvers["NSu"]["predict"].solve()
        timer.stop()

        # Step 2: Pressure correction
        timer = df.Timer("NS: Pressure correction")
        solvers["NSp"].solve()
        timer.stop()

        # Step 3: Velocity correction
        timer = df.Timer("NS: Velocity correction")
        solvers["NSu"]["correct"].solve()
        timer.stop()

    timer_outer.stop()
Exemplo n.º 2
0
def solve(w_, t, dt, q_rhs, solvers, enable_EC, enable_NS,
          use_iterative_solvers, bcs,
          **namespace):
    """ Solve equations. """
    # Update the time-dependent source terms
    # Update the time-dependent source terms
    for qi in q_rhs.values():
        qi.t = t+dt
    # Update the time-dependent boundary conditions
    for boundary_name, bcs_fields in bcs.items():
        for field, bc in bcs_fields.items():
            if isinstance(bc.value, df.Expression):
                bc.value.t = t+dt

    timer_outer = df.Timer("Solve system")
    for subproblem, enable in zip(["EC", "NS"], [enable_EC, enable_NS]):
        if enable:
            timer_inner = df.Timer("Solve subproblem " + subproblem)
            mpi_barrier()
            if subproblem == "NS" and use_iterative_solvers:
                solver, a, L, bcs = solvers[subproblem]
                A = df.assemble(a)
                b = df.assemble(L)
                for bc in bcs:
                    bc.apply(A)
                    bc.apply(b)
                solver.set_operator(A)
                solver.solve(w_["NS"].vector(), b)
            else:
                solvers[subproblem].solve()
            timer_inner.stop()

    timer_outer.stop()
Exemplo n.º 3
0
def solve(w_, solvers, enable_PF, enable_EC, enable_NS, **namespace):
    """ Solve equations. """
    timer_outer = df.Timer("Solve system")
    for subproblem, enable in zip(["PF", "EC", "NS"],
                                  [enable_PF, enable_EC, enable_NS]):
        if enable:
            timer_inner = df.Timer("Solve subproblem " + subproblem)
            mpi_barrier()
            solvers[subproblem].solve()
            timer_inner.stop()

    timer_outer.stop()
Exemplo n.º 4
0
def solve(tstep, w_, w_1, w_tmp, solvers, enable_PF, enable_EC, enable_NS,
          **namespace):
    """ Solve equations. """
    timer_outer = df.Timer("Solve system")
    for subproblem, enable in zip(["PF", "EC"], [enable_PF, enable_EC]):
        if enable:
            timer_inner = df.Timer("Solve subproblem " + subproblem)
            mpi_barrier()
            solvers[subproblem].solve()
            timer_inner.stop()
    if enable_NS:
        # timer = df.Timer("NS: Assemble matrices")
        # A1 = df.assemble(solvers["NSu"]["a1"])
        # A2 = df.assemble(solvers["NSp"]["a2"])
        # A3 = df.assemble(solvers["NSu"]["a3"])
        # timer.stop()

        # timer = df.Timer("NS: Apply BCs 1")
        # [bc.apply(A1) for bc in solvers["NSu"]["bcs"]]
        # [bc.apply(A2) for bc in solvers["NSp"]["bcs"]]
        # timer.stop()
        du = np.array([1e9])
        tol = 1e-6
        max_num_iterations = 1
        i_iter = 0

        Fu = solvers["NSu"]["Fu"]
        bcs_u = solvers["NSu"]["bcs"]

        while du > tol and i_iter < max_num_iterations:
            i_iter += 1
            du[0] = 0.
            # Step 1: Tentative velocity
            timer = df.Timer("NS: Tentative velocity")
            # b1 = df.assemble(solvers["NSu"]["L1"])
            # [bc.apply(b1) for bc in solvers["NSu"]["bcs"]]
            # df.solve(A1, w_["NSu"].vector(), b1)

            w_tmp["NSu"].vector()[:] = w_["NSu"].vector()

            # A, L = df.system(Fu)
            # df.solve(A == L, w_["NSu"], bcs_u)
            df.solve(df.lhs(Fu) == df.rhs(Fu), w_["NSu"], bcs_u)

            du[0] += df.norm(w_["NSu"].vector() - w_tmp["NSu"].vector())
            timer.stop()

            # Step 2: Pressure correction
            timer = df.Timer("NS: Pressure correction")
            # b2 = df.assemble(solvers["NSp"]["L2"])
            # [bc.apply(b2) for bc in solvers["NSp"]["bcs"]]
            # df.solve(A2, w_["NSp"].vector(), b2)

            Fp = solvers["NSp"]["Fp"]
            bcs_p = solvers["NSp"]["bcs"]
            df.solve(df.lhs(Fp) == df.rhs(Fp), w_["NSp"], bcs_p)

            w_1["NSp"].assign(w_["NSp"])

            timer.stop()

        # Step 3: Velocity correction
        timer = df.Timer("NS: Velocity correction")
        # b3 = df.assemble(solvers["NSu"]["L3"])
        # df.solve(A3, w_["NSu"].vector(), b3)
        Fu_corr = solvers["NSu"]["Fu_corr"]

        df.solve(df.lhs(Fu_corr) == df.rhs(Fu_corr), w_["NSu"], bcs_u)

        timer.stop()

    timer_outer.stop()