Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const qualifiers #651

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions include/micm/process/process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ namespace micm
auto react_id = reactant_ids_.begin();
auto prod_id = product_ids_.begin();
auto yield = yields_.begin();
std::size_t offset_rc = i_group * rate_constants.GroupSize();
std::size_t offset_state = i_group * state_variables.GroupSize();
std::size_t offset_forcing = i_group * forcing.GroupSize();
const std::size_t offset_rc = i_group * rate_constants.GroupSize();
const std::size_t offset_state = i_group * state_variables.GroupSize();
const std::size_t offset_forcing = i_group * forcing.GroupSize();
std::vector<double> rate(L, 0);
for (std::size_t i_rxn = 0; i_rxn < number_of_reactants_.size(); ++i_rxn)
{
auto v_rate_subrange_begin = v_rate_constants_begin + offset_rc + (i_rxn * L);
const auto v_rate_subrange_begin = v_rate_constants_begin + offset_rc + (i_rxn * L);
rate.assign(v_rate_subrange_begin, v_rate_subrange_begin + L);
for (std::size_t i_react = 0; i_react < number_of_reactants_[i_rxn]; ++i_react)
for (std::size_t i_cell = 0; i_cell < L; ++i_cell)
Expand Down Expand Up @@ -381,9 +381,9 @@ namespace micm
{
auto react_id = reactant_ids_.begin();
auto yield = yields_.begin();
std::size_t offset_rc = i_group * rate_constants.GroupSize();
std::size_t offset_state = i_group * state_variables.GroupSize();
std::size_t offset_jacobian = i_group * jacobian.GroupSize(jacobian.FlatBlockSize());
const std::size_t offset_rc = i_group * rate_constants.GroupSize();
const std::size_t offset_state = i_group * state_variables.GroupSize();
const std::size_t offset_jacobian = i_group * jacobian.GroupSize(jacobian.FlatBlockSize());
auto flat_id = jacobian_flat_ids_.begin();

for (std::size_t i_rxn = 0; i_rxn < number_of_reactants_.size(); ++i_rxn)
Expand All @@ -398,7 +398,7 @@ namespace micm
{
continue;
}
std::size_t idx_state_variables = offset_state + (react_id[i_react] * L);
const std::size_t idx_state_variables = offset_state + (react_id[i_react] * L);
for (std::size_t i_cell = 0; i_cell < L; ++i_cell)
d_rate_d_ind[i_cell] *= v_state_variables[idx_state_variables + i_cell];
}
Expand Down
14 changes: 7 additions & 7 deletions include/micm/solver/linear_solver.inl
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ namespace micm
{
for (std::size_t i = 0; i < nLij_Lii.first; ++i)
{
std::size_t Lij_yj_first = (*Lij_yj).first;
std::size_t Lij_yj_second_times_n_cells = (*Lij_yj).second * n_cells;
const std::size_t Lij_yj_first = (*Lij_yj).first;
const std::size_t Lij_yj_second_times_n_cells = (*Lij_yj).second * n_cells;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
y_elem[i_cell] -= L_group[Lij_yj_first + i_cell] * x_group[Lij_yj_second_times_n_cells + i_cell];
++Lij_yj;
}
std::size_t nLij_Lii_second = nLij_Lii.second;
const std::size_t nLij_Lii_second = nLij_Lii.second;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
y_elem[i_cell] /= L_group[nLij_Lii_second + i_cell];
y_elem += n_cells;
Expand All @@ -220,18 +220,18 @@ namespace micm
// x_elem starts out as y_elem from the previous loop
for (std::size_t i = 0; i < nUij_Uii.first; ++i)
{
std::size_t Uij_xj_first = (*Uij_xj).first;
std::size_t Uij_xj_second_times_n_cells = (*Uij_xj).second * n_cells;
const std::size_t Uij_xj_first = (*Uij_xj).first;
const std::size_t Uij_xj_second_times_n_cells = (*Uij_xj).second * n_cells;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
x_elem[i_cell] -= U_group[Uij_xj_first + i_cell] * x_group[Uij_xj_second_times_n_cells + i_cell];
++Uij_xj;
}
std::size_t nUij_Uii_second = nUij_Uii.second;
const std::size_t nUij_Uii_second = nUij_Uii.second;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
x_elem[i_cell] /= U_group[nUij_Uii_second + i_cell];

// don't iterate before the beginning of the vector
std::size_t x_elem_distance = std::distance(x.AsVector().begin(), x_elem);
const std::size_t x_elem_distance = std::distance(x.AsVector().begin(), x_elem);
x_elem -= std::min(n_cells, x_elem_distance);
}
}
Expand Down
33 changes: 16 additions & 17 deletions include/micm/solver/lu_decomposition.inl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace micm
auto lki_nkj = lki_nkj_.begin();
auto lkj_uji = lkj_uji_.begin();
auto uii = uii_.begin();
for (auto& inLU : niLU_)
for (const auto& inLU : niLU_)
{
// Upper trianglur matrix
for (std::size_t iU = 0; iU < inLU.second; ++iU)
Expand Down Expand Up @@ -241,11 +241,11 @@ namespace micm
{
MICM_PROFILE_FUNCTION();

std::size_t A_BlockSize = A.NumberOfBlocks();
std::size_t A_GroupVectorSize = A.GroupVectorSize();
std::size_t A_GroupSizeOfFlatBlockSize = A.GroupSize(A.FlatBlockSize());
std::size_t L_GroupSizeOfFlatBlockSize = L.GroupSize(L.FlatBlockSize());
std::size_t U_GroupSizeOfFlatBlockSize = U.GroupSize(U.FlatBlockSize());
const std::size_t A_BlockSize = A.NumberOfBlocks();
const std::size_t A_GroupVectorSize = A.GroupVectorSize();
const std::size_t A_GroupSizeOfFlatBlockSize = A.GroupSize(A.FlatBlockSize());
const std::size_t L_GroupSizeOfFlatBlockSize = L.GroupSize(L.FlatBlockSize());
const std::size_t U_GroupSizeOfFlatBlockSize = U.GroupSize(U.FlatBlockSize());
is_singular = false;

// Loop over groups of blocks
Expand All @@ -264,49 +264,48 @@ namespace micm
auto lkj_uji = lkj_uji_.begin();
auto uii = uii_.begin();
const std::size_t n_cells = std::min(A_GroupVectorSize, A_BlockSize - i_group * A_GroupVectorSize);
for (auto& inLU : niLU_)
for (const auto& inLU : niLU_)
{
// Upper trianglur matrix
for (std::size_t iU = 0; iU < inLU.second; ++iU)
{
std::size_t uik_nkj_first = uik_nkj->first;
const std::size_t uik_nkj_first = uik_nkj->first;
if (*(do_aik++))
{
std::copy(A_vector + *aik, A_vector + *aik + n_cells, U_vector + uik_nkj_first);
++aik;
}
for (std::size_t ikj = 0; ikj < uik_nkj->second; ++ikj)
{
std::size_t lij_ujk_first = lij_ujk->first;
std::size_t lij_ujk_second = lij_ujk->second;
const std::size_t lij_ujk_first = lij_ujk->first;
const std::size_t lij_ujk_second = lij_ujk->second;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
U_vector[uik_nkj_first + i_cell] -= L_vector[lij_ujk_first + i_cell] * U_vector[lij_ujk_second + i_cell];
++lij_ujk;
}
++uik_nkj;
}
// Lower triangular matrix
std::size_t lki_nkj_first = lki_nkj->first;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
L_vector[lki_nkj_first + i_cell] = 1.0;
L_vector[lki_nkj->first + i_cell] = 1.0;
++lki_nkj;
for (std::size_t iL = 0; iL < inLU.first; ++iL)
{
lki_nkj_first = lki_nkj->first;
const std::size_t lki_nkj_first = lki_nkj->first;
if (*(do_aki++))
{
std::copy(A_vector + *aki, A_vector + *aki + n_cells, L_vector + lki_nkj_first);
++aki;
}
for (std::size_t ikj = 0; ikj < lki_nkj->second; ++ikj)
{
std::size_t lkj_uji_first = lkj_uji->first;
std::size_t lkj_uji_second = lkj_uji->second;
const std::size_t lkj_uji_first = lkj_uji->first;
const std::size_t lkj_uji_second = lkj_uji->second;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
L_vector[lki_nkj_first + i_cell] -= L_vector[lkj_uji_first + i_cell] * U_vector[lkj_uji_second + i_cell];
++lkj_uji;
}
std::size_t uii_deref = *uii;
const std::size_t uii_deref = *uii;
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
{
if (U_vector[uii_deref + i_cell] == 0.0)
Expand All @@ -319,7 +318,7 @@ namespace micm
++uii;
}
}
std::size_t uii_deref = *uii;
const std::size_t uii_deref = *uii;
if (n_cells != A_GroupVectorSize)
{
// check the bottom right corner of the matrix
Expand Down
14 changes: 7 additions & 7 deletions include/micm/solver/rosenbrock.inl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ namespace micm
auto& _y = Y.AsVector();
auto& _ynew = Ynew.AsVector();
auto& _errors = errors.AsVector();
std::size_t N = Y.AsVector().size();
std::size_t n_vars = parameters_.absolute_tolerance_.size();
const std::size_t N = Y.AsVector().size();
const std::size_t n_vars = parameters_.absolute_tolerance_.size();

double ymax = 0;
double errors_over_scale = 0;
Expand Down Expand Up @@ -316,11 +316,11 @@ namespace micm
auto y_iter = Y.AsVector().begin();
auto ynew_iter = Ynew.AsVector().begin();
auto errors_iter = errors.AsVector().begin();
std::size_t N = Y.NumRows() * Y.NumColumns();
const std::size_t N = Y.NumRows() * Y.NumColumns();
const std::size_t L = Y.GroupVectorSize();
std::size_t n_vars = parameters_.absolute_tolerance_.size();
const std::size_t n_vars = parameters_.absolute_tolerance_.size();

std::size_t whole_blocks = std::floor(Y.NumRows() / Y.GroupVectorSize()) * Y.GroupSize();
const std::size_t whole_blocks = std::floor(Y.NumRows() / Y.GroupVectorSize()) * Y.GroupSize();

double errors_over_scale = 0;
double error = 0;
Expand All @@ -338,15 +338,15 @@ namespace micm
}

// compute the error over the remaining elements that are in the next group but didn't fill a full group
std::size_t remaining_rows = Y.NumRows() % Y.GroupVectorSize();
const std::size_t remaining_rows = Y.NumRows() % Y.GroupVectorSize();

if (remaining_rows > 0)
{
for (std::size_t y = 0; y < Y.NumColumns(); ++y)
{
for (std::size_t x = 0; x < remaining_rows; ++x)
{
std::size_t idx = y * L + x;
const std::size_t idx = y * L + x;
errors_over_scale = errors_iter[idx] /
(parameters_.absolute_tolerance_[y] +
parameters_.relative_tolerance_ * std::max(std::abs(y_iter[idx]), std::abs(ynew_iter[idx])));
Expand Down
Loading