<commit_before>/**
 * @file Domain1D.cpp
 *
 */

#include "cantera/oneD/Domain1D.h"

#include <cstdio>

using namespace std;

namespace Cantera
{

void Domain1D::
setTolerances(size_t nr, const doublereal* rtol,
              size_t na, const doublereal* atol, int ts)
{
    if (nr < m_nv || na < m_nv)
        throw CanteraError("Domain1D::setTolerances",
                           "wrong array size for solution error tolerances. "
                           "Size should be at least "+int2str(m_nv));
    if (ts >= 0) {
        copy(rtol, rtol + m_nv, m_rtol_ss.begin());
        copy(atol, atol + m_nv, m_atol_ss.begin());
    }
    if (ts <= 0) {
        copy(rtol, rtol + m_nv, m_rtol_ts.begin());
        copy(atol, atol + m_nv, m_atol_ts.begin());
    }
}

void Domain1D::
setTolerances(size_t n, doublereal rtol, doublereal atol, int ts)
{
    if (ts >= 0) {
        m_rtol_ss[n] = rtol;
        m_atol_ss[n] = atol;
    }
    if (ts <= 0) {
        m_rtol_ts[n] = rtol;
        m_atol_ts[n] = atol;
    }
}

void Domain1D::
setTolerances(doublereal rtol, doublereal atol,int ts)
{
    for (size_t n = 0; n < m_nv; n++) {
        if (ts >= 0) {
            m_rtol_ss[n] = rtol;
            m_atol_ss[n] = atol;
        }
        if (ts <= 0) {
            m_rtol_ts[n] = rtol;
            m_atol_ts[n] = atol;
        }
    }
}

void Domain1D::
setTolerancesTS(doublereal rtol, doublereal atol)
{
    for (size_t n = 0; n < m_nv; n++) {
        m_rtol_ts[n] = rtol;
        m_atol_ts[n] = atol;
    }
}

void Domain1D::
setTolerancesSS(doublereal rtol, doublereal atol)
{
    for (size_t n = 0; n < m_nv; n++) {
        m_rtol_ss[n] = rtol;
        m_atol_ss[n] = atol;
    }
}

void Domain1D::
eval(size_t jg, doublereal* xg, doublereal* rg,
     integer* mask, doublereal rdt)
{

    if (jg != npos && (jg + 1 < firstPoint() || jg > lastPoint() + 1)) {
        return;
    }

    // if evaluating a Jacobian, compute the steady-state residual
    if (jg != npos) {
        rdt = 0.0;
    }

    // start of local part of global arrays
    doublereal* x = xg + loc();
    doublereal* rsd = rg + loc();
    integer* diag = mask + loc();

    size_t jmin, jmax, jpt,  j, i;
    jpt = jg - firstPoint();

    if (jg == npos) {      // evaluate all points
        jmin = 0;
        jmax = m_points - 1;
    } else {          // evaluate points for Jacobian
        jmin = std::max<size_t>(jpt-1, 0);
        jmax = std::min(jpt+1,m_points-1);
    }

    for (j = jmin; j <= jmax; j++) {
        if (j == 0 || j == m_points - 1) {
            for (i = 0; i < m_nv; i++) {
                rsd[index(i,j)] = residual(x,i,j);
                diag[index(i,j)] = 0;
            }
        } else {
            for (i = 0; i < m_nv; i++) {
                rsd[index(i,j)] = residual(x,i,j)
                                  - timeDerivativeFlag(i)*rdt*(value(x,i,j) - prevSoln(i,j));
                diag[index(i,j)] = timeDerivativeFlag(i);
            }
        }
    }
}


// called to set up initial grid, and after grid refinement
void Domain1D::setupGrid(size_t n, const doublereal* z)<commit_msg>[1D] Fixed an indexing error that affected Jacobian evaluations<commit_after>/**
 * @file Domain1D.cpp
 *
 */

#include "cantera/oneD/Domain1D.h"

#include <cstdio>

using namespace std;

namespace Cantera
{

void Domain1D::
setTolerances(size_t nr, const doublereal* rtol,
              size_t na, const doublereal* atol, int ts)
{
    if (nr < m_nv || na < m_nv)
        throw CanteraError("Domain1D::setTolerances",
                           "wrong array size for solution error tolerances. "
                           "Size should be at least "+int2str(m_nv));
    if (ts >= 0) {
        copy(rtol, rtol + m_nv, m_rtol_ss.begin());
        copy(atol, atol + m_nv, m_atol_ss.begin());
    }
    if (ts <= 0) {
        copy(rtol, rtol + m_nv, m_rtol_ts.begin());
        copy(atol, atol + m_nv, m_atol_ts.begin());
    }
}

void Domain1D::
setTolerances(size_t n, doublereal rtol, doublereal atol, int ts)
{
    if (ts >= 0) {
        m_rtol_ss[n] = rtol;
        m_atol_ss[n] = atol;
    }
    if (ts <= 0) {
        m_rtol_ts[n] = rtol;
        m_atol_ts[n] = atol;
    }
}

void Domain1D::
setTolerances(doublereal rtol, doublereal atol,int ts)
{
    for (size_t n = 0; n < m_nv; n++) {
        if (ts >= 0) {
            m_rtol_ss[n] = rtol;
            m_atol_ss[n] = atol;
        }
        if (ts <= 0) {
            m_rtol_ts[n] = rtol;
            m_atol_ts[n] = atol;
        }
    }
}

void Domain1D::
setTolerancesTS(doublereal rtol, doublereal atol)
{
    for (size_t n = 0; n < m_nv; n++) {
        m_rtol_ts[n] = rtol;
        m_atol_ts[n] = atol;
    }
}

void Domain1D::
setTolerancesSS(doublereal rtol, doublereal atol)
{
    for (size_t n = 0; n < m_nv; n++) {
        m_rtol_ss[n] = rtol;
        m_atol_ss[n] = atol;
    }
}

void Domain1D::
eval(size_t jg, doublereal* xg, doublereal* rg,
     integer* mask, doublereal rdt)
{

    if (jg != npos && (jg + 1 < firstPoint() || jg > lastPoint() + 1)) {
        return;
    }

    // if evaluating a Jacobian, compute the steady-state residual
    if (jg != npos) {
        rdt = 0.0;
    }

    // start of local part of global arrays
    doublereal* x = xg + loc();
    doublereal* rsd = rg + loc();
    integer* diag = mask + loc();

    size_t jmin, jmax, jpt,  j, i;
    jpt = jg - firstPoint();

    if (jg == npos) {      // evaluate all points
        jmin = 0;
        jmax = m_points - 1;
    } else {          // evaluate points for Jacobian
        jmin = std::max<size_t>(jpt, 1) - 1;
        jmax = std::min(jpt+1,m_points-1);
    }

    for (j = jmin; j <= jmax; j++) {
        if (j == 0 || j == m_points - 1) {
            for (i = 0; i < m_nv; i++) {
                rsd[index(i,j)] = residual(x,i,j);
                diag[index(i,j)] = 0;
            }
        } else {
            for (i = 0; i < m_nv; i++) {
                rsd[index(i,j)] = residual(x,i,j)
                                  - timeDerivativeFlag(i)*rdt*(value(x,i,j) - prevSoln(i,j));
                diag[index(i,j)] = timeDerivativeFlag(i);
            }
        }
    }
}


// called to set up initial grid, and after grid refinement
void Domain1D::setupGrid(size_t n, const doublereal* z)
{'fraction_non_alphanumeric': 0.14641943734015345, 'fraction_numerical': 0.011349104859335038, 'mean_word_length': 1.8794293603313392, 'pattern_counts': {'":': 0, '<': 31, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3475833', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2425, 'n_words': 586}