<commit_before>﻿"use strict";
window.DEBUG = false;

var compute_moment = function (moment, mkap, top, inverse) {
    /**
     * @param moment: Query moment
     * @param mkap: Object from the MomentKappa class
     * @param top: (bool) Depends if the hookup is sought for the top or the bottom of the cross section.
     */
    top = (typeof top !== "undefined") ? top : true;
    inverse = (typeof inverse !== "undefined") ? inverse : false;

    if (window.DEBUG) {
        console.log("In compute moment")
    }

    var count = 0;
    var factor;

    // grid search
    var grid_m = [];
    var grid_strain = [];

    var max_strain = mkap.compressive_diagram.strain[mkap.compressive_diagram.strain.length - 1];

    for (var i = 0; i < 30; i += 1) {
        mkap.solver(true, max_strain / 30 * i, inverse);
        mkap.det_m_kappa();
        grid_m.push(mkap.moment);

        if (top) {
            grid_strain.push(Math.abs(mkap.strain_top))
        }
        else {
            grid_strain.push(mkap.strain_btm)
        }
    }
    var closest_index = std.closest(grid_m, moment);
    var strain = grid_strain[closest_index];
    strain = (strain === 0) ? 0.5 : strain;

    while (1) {
        if (std.convergence_conditions(mkap.moment, moment, 1.01, 0.99)) {
            if (window.DEBUG) {<commit_msg>grid search moment more accurate<commit_after>﻿"use strict";
window.DEBUG = false;

var compute_moment = function (moment, mkap, top, inverse) {
    /**
     * @param moment: Query moment
     * @param mkap: Object from the MomentKappa class
     * @param top: (bool) Depends if the hookup is sought for the top or the bottom of the cross section.
     */
    top = (typeof top !== "undefined") ? top : true;
    inverse = (typeof inverse !== "undefined") ? inverse : false;

    if (window.DEBUG) {
        console.log("In compute moment")
    }

    var count = 0;
    var factor;

    // grid search
    var grid_m = [];
    var grid_strain = [];

    var max_strain = mkap.compressive_diagram.strain[mkap.compressive_diagram.strain.length - 1];
    var n = 100;

    for (var i = 0; i < n; i += 1) {
        mkap.solver(true, max_strain / n * i, inverse);
        mkap.det_m_kappa();
        grid_m.push(mkap.moment);

        if (top) {
            grid_strain.push(Math.abs(mkap.strain_top))
        }
        else {
            grid_strain.push(mkap.strain_btm)
        }
    }
    var closest_index = std.closest(grid_m, moment);
    var strain = grid_strain[closest_index];
    strain = (strain === 0) ? 0.5 : strain;

    while (1) {
        if (std.convergence_conditions(mkap.moment, moment, 1.001, 0.999)) {
            if (window.DEBUG) {
{'fraction_non_alphanumeric': 0.12968515742128936, 'fraction_numerical': 0.013868065967016492, 'mean_word_length': 2.3320848938826466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1322292', 'n_tokens_mistral': 933, 'n_tokens_neox': 863, 'n_words': 235}