<commit_before>function boltzmann(lattice_width, lattice_height) {
    var four9ths = 4/9;
    var one9th = 1/9;
    var one36th = 1/36;
    var node_directions = {
        0: {'x':0, 'y':0},
        1: {'x':1, 'y':0},
        2: {'x':0, 'y':-1},
        3: {'x':-1, 'y':0},
        4: {'x':0, 'y':1},
        5: {'x':1, 'y':-1},
        6: {'x':-1, 'y':-1},
        7: {'x':-1, 'y':1},
        8: {'x':1, 'y':1}
    };
    var node_weight = {
        0: four9ths,
        1: one9th,
        2: one9th,
        3: one9th,
        4: one9th,
        5: one36th,
        6: one36th,
        7: one36th,
        8: one36th
    };
    var reflection = {
        0: 0,
        1: 3,
        2: 4,
        3: 1,
        4: 2,
        5: 7,
        6: 8,
        7: 5,
        8: 6
    };

    function LatticeNode() {
        this.distribution = [0,0,0,0,0,0,0,0,0]; // Individual density distributions for 
        // each of the nine possible discrete velocities of a node.
        this.stream = [0,0,0,0,0,0,0,0,0]; // Used to temporarily hold streamed values
        this.density = 0; // Macroscopic density of a node.
        this.ux = 0; // X component of macroscopic velocity of a node.
        this.uy = 0; // Y component of macroscopic velocity of a node.
        this.barrier = false; // Boolean indicating if node is a barrier.
        this.curl = 0; // Curl of node.
    }
    function make_lattice(lattice_width, lattice_height) {
        // Make a new lattice 
        var new_lattice = [];
        for (var i = 0; i < lattice_width; i++) {
            new_lattice[i] = [];
            for (var j = 0; j < lattice_height; j++) {
                new_lattice[i][j] = new LatticeNode();
            }
        }
        return new_lattice;
    }

    function init_flow(ux, uy, rho) {
        // Initialize all nodes in lattice to flow with velocity (ux, uy) and density rho
        for (var x = 0; x < lattice_width; x++) {
            for (var y = 0; y < lattice_height; y++) {
                var node = lattice[x][y];
                if (!node.barrier) {
                    node.density = rho;
                    node.ux = ux;
                    node.uy = uy;
                    var eq = equilibrium(ux, uy, rho);
                    node.distribution = eq.slice(0);
                    node.stream = eq.slice(0);
                }
            }
        }
    }
    function move_particles() {
        for (var x = 0, l1=particles.length; x < l1; x++) {
            for (var y = 0, l2=particles[0].length; y < l2; y++) {
                var loc = particles[x][y];
                var lx = Math.floor(loc.x);
                var ly = Math.floor(loc.y);
                if (lx >=0 && lx < lattice_width &&
                    ly >=0 && ly < lattice_height) {
                    var node = lattice[lx][ly];
                    var ux = node.ux;
                    var uy = node.uy;
                    loc.x += ux;
                    loc.y += uy;
                }
            }
        }
    }

    function init_barrier() {
        // Initialize barrier nodes. At some point this may be
        // used to set different barrier configurations, but for now
        // it just initializes the outer edges, and a rectangle in the middle.
        // for (var x = 0; x < lattice_width; x++) {
        //     for (var y = 0; y < lattice_height; y++) {
        //         if (x === 0 || x === lattice_width - 1 ||
        //             y === 0 || y === lattice_height - 1) {
        //             lattice[x][y].barrier = true;
        //         }
        //     }
        // }
    }

    function equilibrium(ux, uy, rho) {
        // Calculate equilibrium densities of a node
        // This is no longer performed in a loop, as that required
        // too many redundant calculations and was a performance drag.
        var eq = []; // Equilibrium values for all velocities in a node.
        var ux3 = 3 * ux;
        var uy3 = 3 * uy;
        var ux2 = ux * ux;
        var uy2 = uy * uy;
        var uxuy2 = 2 * ux * uy;
        var u2 = ux2 + uy2;
        var u215 = 1.5 * u2;
        eq[0] = four9ths * rho * (1 - u215);
        eq[1] = one9th * rho * (1 + ux3 + 4.5*ux2 - u215);
        eq[2] = one9th * rho * (1 - uy3 + 4.5*uy2 - u215);
        eq[3] = one9th * rho * (1 - ux3 + 4.5*ux2 - u215);
        eq[4] = one9th * rho * (1 + uy3 + 4.5*uy2 - u215);
        eq[5] = one36th * rho * (1 + ux3 - uy3 + 4.5*(u2-uxuy2) - u215);
        eq[6] = one36th * rho * (1 - ux3 - uy3 + 4.5*(u2+uxuy2) - u215);
        eq[7] = one36th * rho * (1 - ux3 + uy3 + 4.5*(u2-uxuy2) - u215);
        eq[8] = one36th * rho * (1 + ux3 + uy3 + 4.5*(u2+uxuy2) - u215);
        return eq;
    }

    function stream() {
        // Stream distributions from old lattice to new lattice. Boundary conditions are
        // considered at this stage, and distributions are bounced back to originating node
        // if a boundary is encountered.
        for (var x = 0; x < lattice_width; x++) {
            for (var y = 0; y < lattice_height; y++) {
                var node = lattice[x][y];
                // Compute curl. Non-edge nodes only.
                if (x > 0 && x < lattice_width - 1 &&
                    y > 0 && y < lattice_height - 1) {
                    node.curl = lattice[x+1][y].uy - lattice[x-1][y].uy - lattice[x][y+1].ux + lattice[x][y-1].ux;
                }
                for (var d = 0; d < 9; d++) {
                    var move = node_directions[d];
                    var newx = move.x + x;
                    var newy = move.y + y;
                    // Check if new node is in the lattice
                    if (newx >= 0 && newx < lattice_width && newy >= 0 && newy < lattice_height) {
                        // If destination node is barrier, bounce distribution back to 
                        // originating node in opposite direction.
                        // TODO: Look more closely into boundary conditions. 
                        // Simple reflection might be a bit simplistic.
                        if (lattice[newx][newy].barrier) {
                            lattice[x][y].stream[reflection[d]] = node.distribution[d];
                        } else {
                            lattice[newx][newy].stream[d] = node.distribution[d];
                        }<commit_msg>Reinstate barriers<commit_after>function boltzmann(lattice_width, lattice_height) {
    var four9ths = 4/9;
    var one9th = 1/9;
    var one36th = 1/36;
    var node_directions = {
        0: {'x':0, 'y':0},
        1: {'x':1, 'y':0},
        2: {'x':0, 'y':-1},
        3: {'x':-1, 'y':0},
        4: {'x':0, 'y':1},
        5: {'x':1, 'y':-1},
        6: {'x':-1, 'y':-1},
        7: {'x':-1, 'y':1},
        8: {'x':1, 'y':1}
    };
    var node_weight = {
        0: four9ths,
        1: one9th,
        2: one9th,
        3: one9th,
        4: one9th,
        5: one36th,
        6: one36th,
        7: one36th,
        8: one36th
    };
    var reflection = {
        0: 0,
        1: 3,
        2: 4,
        3: 1,
        4: 2,
        5: 7,
        6: 8,
        7: 5,
        8: 6
    };

    function LatticeNode() {
        this.distribution = [0,0,0,0,0,0,0,0,0]; // Individual density distributions for 
        // each of the nine possible discrete velocities of a node.
        this.stream = [0,0,0,0,0,0,0,0,0]; // Used to temporarily hold streamed values
        this.density = 0; // Macroscopic density of a node.
        this.ux = 0; // X component of macroscopic velocity of a node.
        this.uy = 0; // Y component of macroscopic velocity of a node.
        this.barrier = false; // Boolean indicating if node is a barrier.
        this.curl = 0; // Curl of node.
    }
    function make_lattice(lattice_width, lattice_height) {
        // Make a new lattice 
        var new_lattice = [];
        for (var i = 0; i < lattice_width; i++) {
            new_lattice[i] = [];
            for (var j = 0; j < lattice_height; j++) {
                new_lattice[i][j] = new LatticeNode();
            }
        }
        return new_lattice;
    }

    function init_flow(ux, uy, rho) {
        // Initialize all nodes in lattice to flow with velocity (ux, uy) and density rho
        for (var x = 0; x < lattice_width; x++) {
            for (var y = 0; y < lattice_height; y++) {
                var node = lattice[x][y];
                if (!node.barrier) {
                    node.density = rho;
                    node.ux = ux;
                    node.uy = uy;
                    var eq = equilibrium(ux, uy, rho);
                    node.distribution = eq.slice(0);
                    node.stream = eq.slice(0);
                }
            }
        }
    }
    function move_particles() {
        for (var x = 0, l1=particles.length; x < l1; x++) {
            for (var y = 0, l2=particles[0].length; y < l2; y++) {
                var loc = particles[x][y];
                var lx = Math.floor(loc.x);
                var ly = Math.floor(loc.y);
                if (lx >=0 && lx < lattice_width &&
                    ly >=0 && ly < lattice_height) {
                    var node = lattice[lx][ly];
                    var ux = node.ux;
                    var uy = node.uy;
                    loc.x += ux;
                    loc.y += uy;
                }
            }
        }
    }

    function init_barrier() {
        // Initialize barrier nodes. At some point this may be
        // used to set different barrier configurations, but for now
        // it just initializes the outer edges, and a rectangle in the middle.
        for (var x = 0; x < lattice_width; x++) {
            for (var y = 0; y < lattice_height; y++) {
                if (x === 0 || x === lattice_width - 1 ||
                    y === 0 || y === lattice_height - 1 ||
                    (Math.abs((lattice_width/2)-x) < 10 &&
                        Math.abs((lattice_height/2)-y) < 10)) {
                    lattice[x][y].barrier = true;
                }
            }
        }
    }

    function equilibrium(ux, uy, rho) {
        // Calculate equilibrium densities of a node
        // This is no longer performed in a loop, as that required
        // too many redundant calculations and was a performance drag.
        var eq = []; // Equilibrium values for all velocities in a node.
        var ux3 = 3 * ux;
        var uy3 = 3 * uy;
        var ux2 = ux * ux;
        var uy2 = uy * uy;
        var uxuy2 = 2 * ux * uy;
        var u2 = ux2 + uy2;
        var u215 = 1.5 * u2;
        eq[0] = four9ths * rho * (1 - u215);
        eq[1] = one9th * rho * (1 + ux3 + 4.5*ux2 - u215);
        eq[2] = one9th * rho * (1 - uy3 + 4.5*uy2 - u215);
        eq[3] = one9th * rho * (1 - ux3 + 4.5*ux2 - u215);
        eq[4] = one9th * rho * (1 + uy3 + 4.5*uy2 - u215);
        eq[5] = one36th * rho * (1 + ux3 - uy3 + 4.5*(u2-uxuy2) - u215);
        eq[6] = one36th * rho * (1 - ux3 - uy3 + 4.5*(u2+uxuy2) - u215);
        eq[7] = one36th * rho * (1 - ux3 + uy3 + 4.5*(u2-uxuy2) - u215);
        eq[8] = one36th * rho * (1 + ux3 + uy3 + 4.5*(u2+uxuy2) - u215);
        return eq;
    }

    function stream() {
        // Stream distributions from old lattice to new lattice. Boundary conditions are
        // considered at this stage, and distributions are bounced back to originating node
        // if a boundary is encountered.
        for (var x = 0; x < lattice_width; x++) {
            for (var y = 0; y < lattice_height; y++) {
                var node = lattice[x][y];
                if (!node.barrier) {
                    // Compute curl. Non-edge nodes only.
                    if (x > 0 && x < lattice_width - 1 &&
                        y > 0 && y < lattice_height - 1) {
                        node.curl = lattice[x+1][y].uy - lattice[x-1][y].uy - lattice[x][y+1].ux + lattice[x][y-1].ux;
                    }
                    for (var d = 0; d < 9; d++) {
                        var move = node_directions[d];
                        var newx = move.x + x;
                        var newy = move.y + y;
                        // Check if new node is in the lattice
                        if (newx >= 0 && newx < lattice_width && newy >= 0 && newy < lattice_height) {
                            // If destination node is barrier, bounce distribution back to 
                            // originating node in opposite direction.
                            // TODO: Look more closely into boundary conditions. 
                            // Simple reflection might be a bit simplistic.
                            if (lattice[newx][newy].barrier) {
                                lattice[x][y].stream[reflection[d]] = node.distribution[d];
                            } else {
                                lattice[newx][newy].stream[d] = node.distribution[d];
                            }
                        }
{'fraction_non_alphanumeric': 0.13502829238043562, 'fraction_numerical': 0.039221765754592665, 'mean_word_length': 1.2782977220554477, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4296726', 'n_tokens_mistral': 4406, 'n_tokens_neox': 4087, 'n_words': 1229}