Skip to content

Commit

Permalink
mark parameters and variables const where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
akva2 committed Sep 11, 2024
1 parent 8db7904 commit 6544544
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 49 deletions.
18 changes: 16 additions & 2 deletions msim/include/opm/msim/msim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,23 @@ class msim {
void post_step(data::Solution& sol, data::Wells& well_data, data::GroupAndNetworkValues& group_nwrk_data, size_t report_step, const time_point& sim_time);

private:
void run_step(const WellTestState& wtest_state,
UDQState& udq_state,
data::Solution& sol,
data::Wells& well_data,
data::GroupAndNetworkValues& group_nwrk_data,
size_t report_step,
EclipseIO& io);

void run_step(const WellTestState& wtest_state,
UDQState& udq_state,
data::Solution& sol,
data::Wells& well_data,
data::GroupAndNetworkValues& group_nwrk_data,
size_t report_step,
double dt,
EclipseIO& io);

void run_step(WellTestState& wtest_state, UDQState& udq_state, data::Solution& sol, data::Wells& well_data, data::GroupAndNetworkValues& group_nwrk_data, size_t report_step, EclipseIO& io);
void run_step(WellTestState& wtest_state, UDQState& udq_state, data::Solution& sol, data::Wells& well_data, data::GroupAndNetworkValues& group_nwrk_data, size_t report_step, double dt, EclipseIO& io);
void output(const WellTestState& wtest_state, const UDQState& udq_state,
size_t report_step, bool substep, double seconds_elapsed,
const data::Solution& sol, const data::Wells& well_data,
Expand Down
4 changes: 2 additions & 2 deletions msim/src/msim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void msim::post_step(data::Solution& /* sol */,
}


void msim::run_step(WellTestState& wtest_state,
void msim::run_step(const WellTestState& wtest_state,
UDQState& udq_state,
data::Solution& sol,
data::Wells& well_data,
Expand All @@ -160,7 +160,7 @@ void msim::run_step(WellTestState& wtest_state,
report_step, schedule.stepLength(report_step - 1), io);
}

void msim::run_step(WellTestState& wtest_state,
void msim::run_step(const WellTestState& wtest_state,
UDQState& udq_state,
data::Solution& sol,
data::Wells& well_data,
Expand Down
4 changes: 2 additions & 2 deletions opm/input/eclipse/Schedule/KeywordHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ namespace Opm {

namespace {

void handleAQUCT(HandlerContext& handlerContext)
void handleAQUCT(const HandlerContext& handlerContext)
{
throw OpmInputError("AQUCT is not supported as SCHEDULE keyword", handlerContext.keyword.location());
}

void handleAQUFETP(HandlerContext& handlerContext)
void handleAQUFETP(const HandlerContext& handlerContext)
{
throw OpmInputError("AQUFETP is not supported as SCHEDULE keyword", handlerContext.keyword.location());
}
Expand Down
2 changes: 1 addition & 1 deletion opm/input/eclipse/Schedule/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ namespace
/// \brief Check whether each MS well has COMPSEGS entry andissue error if not.
/// \param welsegs All wells with a WELSEGS entry together with the location.
/// \param compegs All wells with a COMPSEGS entry
void check_compsegs_consistency(Opm::WelSegsSet& welsegs,
void check_compsegs_consistency(const Opm::WelSegsSet& welsegs,
const std::set<std::string>& compsegs,
const std::vector<::Opm::Well>& wells)
{
Expand Down
2 changes: 1 addition & 1 deletion opm/input/eclipse/Schedule/UDQ/UDQConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ namespace Opm {
}

void UDQConfig::eval_define(const std::size_t report_step,
UDQState& udq_state,
const UDQState& udq_state,
UDQContext& context) const
{
auto var_type_bit = [](const UDQVarType var_type)
Expand Down
2 changes: 1 addition & 1 deletion opm/input/eclipse/Schedule/UDQ/UDQConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace Opm {
UDQContext& context) const;

void eval_define(std::size_t report_step,
UDQState& udq_state,
const UDQState& udq_state,
UDQContext& context) const;

void add_named_assign(const std::string& quantity,
Expand Down
2 changes: 1 addition & 1 deletion opm/io/eclipse/SummaryNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ std::string Opm::EclIO::SummaryNode::unique_key(number_renderer render_number) c
if (auto opt = display_number(render_number))
key_parts.emplace_back(opt.value());

auto compose_key = [](std::string& key, const std::string& key_part) -> std::string {
auto compose_key = [](const std::string& key, const std::string& key_part) -> std::string {
constexpr auto delimiter { ':' } ;
return key.empty() ? key_part : key + delimiter + key_part;
};
Expand Down
2 changes: 0 additions & 2 deletions opm/output/eclipse/AggregateActionxData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
#include <opm/io/eclipse/PaddedOutputString.hpp>

#include <cstddef>
#include <string>
#include <vector>
#include <map>

namespace Opm {
class Actdims;
Expand Down
2 changes: 1 addition & 1 deletion opm/output/eclipse/AggregateNetworkData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ std::optional<int> findInVector(const std::vector<T> & vecOfElements, const T
return (it != vecOfElements.end()) ? std::optional<int>{std::distance(vecOfElements.begin(), it)} : std::nullopt;
}

int next_branch(int node_no, std::vector<int>& inlets, std::vector<int>& outlets)
int next_branch(int node_no, const std::vector<int>& inlets, const std::vector<int>& outlets)
{
int nxt_br = 0;
auto res_inlets = findInVector<int>(inlets, node_no);
Expand Down
44 changes: 22 additions & 22 deletions opm/output/eclipse/EclipseGridInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,31 +225,31 @@ double EclipseGridInspector::cellVolumeVerticalPillars(int i, int j, int k) cons
// Computing the base area as half the 2d cross product of the diagonals.
int numxpill = logical_gridsize_[0] + 1;
int pix = i + j*numxpill;
double px[4] = { pillc[6*pix],
pillc[6*(pix + 1)],
pillc[6*(pix + numxpill)],
pillc[6*(pix + numxpill + 1)] };
double py[4] = { pillc[6*pix + 1],
pillc[6*(pix + 1) + 1],
pillc[6*(pix + numxpill) + 1],
pillc[6*(pix + numxpill + 1) + 1] };
double diag1[2] = { px[3] - px[0], py[3] - py[0] };
double diag2[2] = { px[2] - px[1], py[2] - py[1] };
double area = 0.5*(diag1[0]*diag2[1] - diag1[1]*diag2[0]);
const double px[4] = {pillc[6 * pix],
pillc[6 * (pix + 1)],
pillc[6 * (pix + numxpill)],
pillc[6 * (pix + numxpill + 1)]};
const double py[4] = {pillc[6 * pix + 1],
pillc[6 * (pix + 1) + 1],
pillc[6 * (pix + numxpill) + 1],
pillc[6 * (pix + numxpill + 1) + 1]};
const double diag1[2] = {px[3] - px[0], py[3] - py[0]};
const double diag2[2] = {px[2] - px[1], py[2] - py[1]};
const double area = 0.5*(diag1[0] * diag2[1] - diag1[1] * diag2[0]);

// Computing the average of the z-differences along each pillar.
int delta[3] = { 1,
2*logical_gridsize_[0],
4*logical_gridsize_[0]*logical_gridsize_[1] };
const int delta[3] = {1,
2 * logical_gridsize_[0],
4 * logical_gridsize_[0] * logical_gridsize_[1]};
int ix = 2*(i*delta[0] + j*delta[1] + k*delta[2]);
double cellz[8] = { z[ix], z[ix + delta[0]],
z[ix + delta[1]], z[ix + delta[1] + delta[0]],
z[ix + delta[2]], z[ix + delta[2] + delta[0]],
z[ix + delta[2] + delta[1]], z[ix + delta[2] + delta[1] + delta[0]] };
double diffz[4] = { cellz[4] - cellz[0],
cellz[5] - cellz[1],
cellz[6] - cellz[2],
cellz[7] - cellz[3] };
const double cellz[8] = {z[ix], z[ix + delta[0]],
z[ix + delta[1]], z[ix + delta[1] + delta[0]],
z[ix + delta[2]], z[ix + delta[2] + delta[0]],
z[ix + delta[2] + delta[1]], z[ix + delta[2] + delta[1] + delta[0]]};
const double diffz[4] = {cellz[4] - cellz[0],
cellz[5] - cellz[1],
cellz[6] - cellz[2],
cellz[7] - cellz[3]};
double averzdiff = 0.25*std::accumulate(diffz, diffz + 4, 0.0);
return averzdiff*area;
}
Expand Down
2 changes: 1 addition & 1 deletion opm/output/eclipse/report/WELSPECS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ namespace {
std::string grid_block(const context&, std::size_t, std::size_t) const {
const std::array<int,3> ijk { connection.getI() + 1, connection.getJ() + 1, connection.getK() + 1 } ;

auto compose_coordinates { [](std::string& out, int in) -> std::string {
auto compose_coordinates { [](const std::string& out, const int in) -> std::string {
constexpr auto delimiter { ',' } ;
std::string coordinate_part { std::to_string(in) } ;
right_align(coordinate_part, 3);
Expand Down
30 changes: 22 additions & 8 deletions test_util/EclFilesComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <set>
#include <type_traits>
#include <vector>

Expand All @@ -46,7 +44,14 @@
using Opm::EclIO::EGrid;

template <typename T>
void ECLFilesComparator::printValuesForCell(const std::string& keyword, const std::string& reference, size_t kw_size, size_t cell, EGrid *grid, const T& value1, const T& value2) const {
void ECLFilesComparator::
printValuesForCell(const std::string& keyword,
const std::string& reference,
size_t kw_size, size_t cell,
const EGrid *grid,
const T& value1,
const T& value2) const
{
if (grid) {
int nActive = grid->activeCells();
int nTot = grid->totalNumberOfCells();
Expand Down Expand Up @@ -85,15 +90,24 @@ void ECLFilesComparator::printValuesForCell(const std::string& keyword, const st
<< "(first value, second value) = (" << value1 << ", " << value2 << ")\n\n";
}

template void ECLFilesComparator::printValuesForCell<bool> (const std::string& keyword, const std::string& reference, size_t kw_size, size_t cell, EGrid *grid, const bool& value1, const bool& value2) const;
template void ECLFilesComparator::printValuesForCell<int> (const std::string& keyword, const std::string& reference, size_t kw_size, size_t cell, EGrid *grid, const int& value1, const int& value2) const;
template void ECLFilesComparator::printValuesForCell<double> (const std::string& keyword, const std::string& reference, size_t kw_size, size_t cell, EGrid *grid, const double& value1, const double& value2) const;
template void ECLFilesComparator::printValuesForCell<std::string>(const std::string& keyword, const std::string& reference, size_t kw_size, size_t cell, EGrid *grid, const std::string& value1, const std::string& value2) const;
#define INSTANTIATE_PRINTCELL(T) \
template void ECLFilesComparator::printValuesForCell(const std::string&, \
const std::string&, \
size_t, size_t, \
const EGrid *grid, \
const T&, \
const T&) const;

// Hack to work around case where std::vector<bool>::const_reference is not a bool. If it is we will initialize printValuesForCell<char> otherwise printValuesForCell<std::vector<bool>::const_reference>
using boolConstReference = typename std::vector<bool>::const_reference;
using boolTypeHelper = typename std::remove_const<typename std::remove_reference<boolConstReference>::type>::type;
using boolType = typename std::conditional<std::is_same<boolTypeHelper, bool>::value, char, boolTypeHelper>::type;
template void ECLFilesComparator::printValuesForCell<boolType> (const std::string& keyword, const std::string& reference, size_t kw_size, size_t cell, EGrid *grid, const boolType& value1, const boolType& value2) const;

INSTANTIATE_PRINTCELL(bool)
INSTANTIATE_PRINTCELL(int)
INSTANTIATE_PRINTCELL(double)
INSTANTIATE_PRINTCELL(std::string)
INSTANTIATE_PRINTCELL(boolType)

ECLFilesComparator::ECLFilesComparator(const std::string& basename1,
const std::string& basename2,
Expand Down
2 changes: 1 addition & 1 deletion test_util/EclFilesComparator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ECLFilesComparator {
const std::string& reference,
size_t kw_size,
size_t cell,
Opm::EclIO::EGrid *grid,
const Opm::EclIO::EGrid *grid,
const T& value1,
const T& value2) const;

Expand Down
7 changes: 5 additions & 2 deletions test_util/convertECL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,17 @@ void writeArray(std::string name, eclArrType arrType, T& file1, int index, int r
}


void writeC0nnArray(std::string name, int elementSize, EclFile& file1, int index, EclOutput& outFile)
void writeC0nnArray(const std::string& name, int elementSize, EclFile& file1, int index, EclOutput& outFile)
{
auto vect = file1.get<std::string>(index);
outFile.write(name, vect, elementSize);
}


void writeArrayList(std::vector<EclEntry>& arrayList, std::vector<int>& elementSizeList, EclFile file1, EclOutput& outFile) {
void writeArrayList(std::vector<EclEntry>& arrayList,
const std::vector<int>& elementSizeList,
EclFile& file1, EclOutput& outFile)
{

for (size_t index = 0; index < arrayList.size(); index++) {
std::string name = std::get<0>(arrayList[index]);
Expand Down
3 changes: 2 additions & 1 deletion tests/parser/ScheduleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5290,7 +5290,8 @@ bool compare_dates(const time_point& t, int year, int month, int day) {
return t == TimeService::from_time_t( asTimeT( TimeStampUTC(year, month, day)));
}

bool compare_dates(const time_point& t, std::array<int, 3>& ymd) {
bool compare_dates(const time_point& t, const std::array<int, 3>& ymd)
{
return compare_dates(t, ymd[0], ymd[1], ymd[2]);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/test_EclIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ bool operator==(const std::vector<T> & t1, const std::vector<T> & t2)
return std::equal(t1.begin(), t1.end(), t2.begin(), t2.end());
}

void write_header(std::ofstream& ofileH, std::string& arrName, int size, std::string arrtype){
void write_header(std::ofstream& ofileH, const std::string& arrName,
int size, const std::string& arrtype)
{

int bhead = flipEndianInt(16);
int fsize = flipEndianInt(size);
Expand Down

0 comments on commit 6544544

Please sign in to comment.