← back to ncmaclachlan__me523-cfd-project

Function bodies 112 total

All specs Real LLM only Function bodies
compute_residual method · cpp · L127-L147 (21 LOC)
src/pressure_solver.cpp
void PressureSolver::compute_residual(Level& lev) const {
    const int nx = lev.nx;
    const int ny = lev.ny;
    const double inv_dx2 = 1.0 / (lev.dx * lev.dx);
    const double inv_dy2 = 1.0 / (lev.dy * lev.dy);

    periodic_fill(lev.phi, nx, ny);

    auto phi = lev.phi;
    auto f   = lev.f;
    auto r   = lev.r;

    Kokkos::parallel_for("mg_residual",
        Kokkos::MDRangePolicy<Kokkos::Rank<2>>({1, 1}, {nx + 1, ny + 1}),
        KOKKOS_LAMBDA(int i, int j) {
            const double lap = (phi(i+1,j) - 2.0*phi(i,j) + phi(i-1,j)) * inv_dx2
                             + (phi(i,j+1) - 2.0*phi(i,j) + phi(i,j-1)) * inv_dy2;
            r(i, j) = f(i, j) - lap;
        });
}
KOKKOS_LAMBDA function · cpp · L142-L146 (5 LOC)
src/pressure_solver.cpp
        KOKKOS_LAMBDA(int i, int j) {
            const double lap = (phi(i+1,j) - 2.0*phi(i,j) + phi(i-1,j)) * inv_dx2
                             + (phi(i,j+1) - 2.0*phi(i,j) + phi(i,j-1)) * inv_dy2;
            r(i, j) = f(i, j) - lap;
        });
restrict_to method · cpp · L152-L170 (19 LOC)
src/pressure_solver.cpp
void PressureSolver::restrict_to(const Level& fine, Level& coarse) const {
    periodic_fill(const_cast<Level&>(fine).r, fine.nx, fine.ny);

    const int nc_x = coarse.nx;
    const int nc_y = coarse.ny;
    auto r_f = fine.r;
    auto f_c = coarse.f;

    Kokkos::parallel_for("mg_restrict",
        Kokkos::MDRangePolicy<Kokkos::Rank<2>>({1, 1}, {nc_x + 1, nc_y + 1}),
        KOKKOS_LAMBDA(int ic, int jc) {
            // Coarse cell (ic,jc) covers fine cells (2*ic-1,2*jc-1)..(2*ic,2*jc)
            const int if0 = 2 * ic - 1;
            const int jf0 = 2 * jc - 1;
            f_c(ic, jc) = 0.25 * (r_f(if0,   jf0)   + r_f(if0+1, jf0)
                                 + r_f(if0,   jf0+1) + r_f(if0+1, jf0+1));
        });
}
KOKKOS_LAMBDA function · cpp · L163-L169 (7 LOC)
src/pressure_solver.cpp
        KOKKOS_LAMBDA(int ic, int jc) {
            // Coarse cell (ic,jc) covers fine cells (2*ic-1,2*jc-1)..(2*ic,2*jc)
            const int if0 = 2 * ic - 1;
            const int jf0 = 2 * jc - 1;
            f_c(ic, jc) = 0.25 * (r_f(if0,   jf0)   + r_f(if0+1, jf0)
                                 + r_f(if0,   jf0+1) + r_f(if0+1, jf0+1));
        });
prolongate_add method · cpp · L175-L205 (31 LOC)
src/pressure_solver.cpp
void PressureSolver::prolongate_add(const Level& coarse, Level& fine) const {
    periodic_fill(const_cast<Level&>(coarse).phi, coarse.nx, coarse.ny);

    const int nf_x = fine.nx;
    const int nf_y = fine.ny;
    auto phi_c = coarse.phi;
    auto phi_f = fine.phi;

    Kokkos::parallel_for("mg_prolongate",
        Kokkos::MDRangePolicy<Kokkos::Rank<2>>({1, 1}, {nf_x + 1, nf_y + 1}),
        KOKKOS_LAMBDA(int i_f, int j_f) {
            // Determine which coarse cell owns this fine cell
            const int ic = (i_f - 1) / 2 + 1;
            const int jc = (j_f - 1) / 2 + 1;

            // Sub-cell position: 0 = near side, 1 = far side
            const int si = (i_f - 1) % 2;
            const int sj = (j_f - 1) % 2;

            // Neighbor direction: left/down (si==0) or right/up (si==1)
            const int di = (si == 0) ? -1 : 1;
            const int dj = (sj == 0) ? -1 : 1;

            // Bilinear weights (tensor product of 1D: 3/4 near, 1/4 far)
            phi_f(i_f, 
KOKKOS_LAMBDA function · cpp · L186-L204 (19 LOC)
src/pressure_solver.cpp
        KOKKOS_LAMBDA(int i_f, int j_f) {
            // Determine which coarse cell owns this fine cell
            const int ic = (i_f - 1) / 2 + 1;
            const int jc = (j_f - 1) / 2 + 1;

            // Sub-cell position: 0 = near side, 1 = far side
            const int si = (i_f - 1) % 2;
            const int sj = (j_f - 1) % 2;

            // Neighbor direction: left/down (si==0) or right/up (si==1)
            const int di = (si == 0) ? -1 : 1;
            const int dj = (sj == 0) ? -1 : 1;

            // Bilinear weights (tensor product of 1D: 3/4 near, 1/4 far)
            phi_f(i_f, j_f) += 0.5625 * phi_c(ic,      jc)        // 9/16
                             + 0.1875 * phi_c(ic + di,  jc)        // 3/16
                             + 0.1875 * phi_c(ic,       jc + dj)   // 3/16
                             + 0.0625 * phi_c(ic + di,  jc + dj);  // 1/16
        });
subtract_mean method · cpp · L210-L227 (18 LOC)
src/pressure_solver.cpp
void PressureSolver::subtract_mean(Kokkos::View<double**> v,
                                   int nx, int ny) const {
    double sum = 0.0;
    Kokkos::parallel_reduce("mg_mean",
        Kokkos::MDRangePolicy<Kokkos::Rank<2>>({1, 1}, {nx + 1, ny + 1}),
        KOKKOS_LAMBDA(int i, int j, double& lsum) {
            lsum += v(i, j);
        }, sum);

    const double mean = sum / static_cast<double>(nx * ny);

    Kokkos::parallel_for("mg_sub_mean",
        Kokkos::MDRangePolicy<Kokkos::Rank<2>>({1, 1}, {nx + 1, ny + 1}),
        KOKKOS_LAMBDA(int i, int j) {
            v(i, j) -= mean;
        });
}
If a scraper extracted this row, it came from Repobility (https://repobility.com)
KOKKOS_LAMBDA function · cpp · L216-L218 (3 LOC)
src/pressure_solver.cpp
        KOKKOS_LAMBDA(int i, int j, double& lsum) {
            lsum += v(i, j);
        }, sum);
KOKKOS_LAMBDA function · cpp · L224-L226 (3 LOC)
src/pressure_solver.cpp
        KOKKOS_LAMBDA(int i, int j) {
            v(i, j) -= mean;
        });
vcycle method · cpp · L232-L266 (35 LOC)
src/pressure_solver.cpp
void PressureSolver::vcycle(int l) const {
    const int nlev = static_cast<int>(levels_.size());

    if (l == nlev - 1) {
        // Coarsest level: iterate many sweeps (cheap — only 2x2 = 4 cells)
        const_cast<PressureSolver*>(this)->smooth_rbgs(
            const_cast<Level&>(levels_[l]), 50);
        return;
    }

    auto& fine   = const_cast<Level&>(levels_[l]);
    auto& coarse = const_cast<Level&>(levels_[l + 1]);

    // Pre-smooth
    const_cast<PressureSolver*>(this)->smooth_rbgs(fine, nu_pre);

    // Compute residual
    const_cast<PressureSolver*>(this)->compute_residual(fine);

    // Restrict residual to coarse RHS
    const_cast<PressureSolver*>(this)->restrict_to(fine, coarse);

    // Zero coarse-grid correction
    Kokkos::deep_copy(coarse.phi, 0.0);

    // Recurse
    vcycle(l + 1);

    // Prolongate correction and add to fine solution
    const_cast<PressureSolver*>(this)->prolongate_add(coarse, fine);

    // Post-smooth
    const_cast<PressureSolver*>
solve method · cpp · L271-L317 (47 LOC)
src/pressure_solver.cpp
PressureSolveResult PressureSolver::solve(SimState& s,
                                          Kokkos::View<double**> rhs) {
    if (!initialized_) init(s.grid);

    const int nx = levels_[0].nx;
    const int ny = levels_[0].ny;

    // Copy RHS and initial guess into level 0
    Kokkos::deep_copy(levels_[0].f,   rhs);
    Kokkos::deep_copy(levels_[0].phi, s.p);

    // Enforce compatibility: mean(f) = 0
    subtract_mean(levels_[0].f, nx, ny);

    double rnorm = 0.0;

    for (int iter = 0; iter < max_vcycles; ++iter) {
        vcycle(0);

        // Enforce mean-zero gauge on solution
        subtract_mean(levels_[0].phi, nx, ny);

        // Check convergence
        compute_residual(levels_[0]);

        rnorm = 0.0;
        auto r = levels_[0].r;
        Kokkos::parallel_reduce("mg_rnorm",
            Kokkos::MDRangePolicy<Kokkos::Rank<2>>({1, 1}, {nx + 1, ny + 1}),
            KOKKOS_LAMBDA(int i, int j, double& lsum) {
                lsum += r(i, j) * r(i, j);
           
KOKKOS_LAMBDA function · cpp · L301-L303 (3 LOC)
src/pressure_solver.cpp
            KOKKOS_LAMBDA(int i, int j, double& lsum) {
                lsum += r(i, j) * r(i, j);
            }, rnorm);
‹ prevpage 3 / 3