Skip to content

Commit

Permalink
Fix compiler warnings from SolutionArray
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jul 2, 2023
1 parent 07bc22a commit 4b8173c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
40 changes: 20 additions & 20 deletions src/base/SolutionArray.cpp
Expand Up @@ -12,6 +12,7 @@
#include "cantera/base/stringUtils.h"
#include "cantera/thermo/ThermoPhase.h"
#include "cantera/thermo/SurfPhase.h"
#include "cantera/base/utilities.h"
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <sstream>
Expand Down Expand Up @@ -279,7 +280,7 @@ vector<string> doubleColumn(string name, const vector<double>& comp,
// assemble output
string section = fmt::format("{{:>{}}}", maxLen);
vector<string> col = {fmt::format(section, name)};
size_t count = 0;
int count = 0;
for (const auto& val : data) {
col.push_back(fmt::format(notation, val));
count++;
Expand Down Expand Up @@ -339,7 +340,7 @@ vector<string> integerColumn(string name, const vector<long int>& comp,

// assemble output
vector<string> col = {fmt::format(notation, name)};
size_t count = 0;
int count = 0;
for (const auto& val : data) {
col.push_back(fmt::format(notation, val));
count++;
Expand Down Expand Up @@ -382,7 +383,7 @@ vector<string> stringColumn(string name, const vector<string>& comp,
// assemble output
notation = fmt::format(" {{:>{}}}", maxLen);
vector<string> col = {fmt::format(notation, name)};
size_t count = 0;
int count = 0;
for (const auto& val : data) {
col.push_back(fmt::format(notation, val));
count++;
Expand All @@ -407,16 +408,16 @@ vector<string> formatColumn(string name, const AnyValue& comp, int rows, int wid

// create alternative representation
string repr;
size_t size;
int size;
if (comp.isVector<vector<double>>()) {
repr = "[ <double> ]";
size = comp.asVector<vector<double>>().size();
size = len(comp.asVector<vector<double>>());
} else if (comp.isVector<vector<long int>>()) {
repr = "[ <long int> ]";
size = comp.asVector<vector<long int>>().size();
size = len(comp.asVector<vector<long int>>());
} else if (comp.isVector<vector<string>>()) {
repr = "[ <string> ]";
size = comp.asVector<vector<string>>().size();
size = len(comp.asVector<vector<string>>());
} else {
throw CanteraError(
"formatColumn", "Encountered invalid data for component '{}'.", name);
Expand All @@ -437,8 +438,7 @@ vector<string> formatColumn(string name, const AnyValue& comp, int rows, int wid
col.push_back(repr);
}
col.push_back(fmt::format(notation, "..."));
int size_ = static_cast<int>(size);
for (int row = size_ - rows / 2; row < size_; row++) {
for (int row = size - rows / 2; row < size; row++) {
col.push_back(repr);
}
}
Expand Down Expand Up @@ -470,24 +470,24 @@ string SolutionArray::info(const vector<string>& keys, int rows, int width)
// assemble columns fitting within a maximum width; if this width is exceeded,
// a "..." separator is inserted close to the center. Accordingly, the matrix
// needs to be assembled from two halves.
size_t front = 0;
size_t back = components.size() - 1;
size_t fLen = cols.back()[0].size();
size_t bLen = 0;
size_t sep = 5; // separator width
int front = 0;
int back = len(components) - 1;
int fLen = len(cols.back()[0]);
int bLen = 0;
int sep = 5; // separator width
bool done = false;
while (!done && front <= back) {
string key;
while (bLen + sep <= fLen && front <= back) {
// add trailing columns
key = components[back];
auto col = formatColumn(key, getComponent(key), rows, col_width);
if (col[0].size() + fLen + bLen + sep > width) {
if (len(col[0]) + fLen + bLen + sep > width) {
done = true;
break;
}
tail.push_back(col);
bLen += tail.back()[0].size();
bLen += len(tail.back()[0]);
back--;
}
if (done || front > back) {
Expand All @@ -497,12 +497,12 @@ string SolutionArray::info(const vector<string>& keys, int rows, int width)
// add leading columns
key = components[front];
auto col = formatColumn(key, getComponent(key), rows, col_width);
if (col[0].size() + fLen + bLen + sep > width) {
if (len(col[0]) + fLen + bLen + sep > width) {
done = true;
break;
}
cols.push_back(col);
fLen += cols.back()[0].size();
fLen += len(cols.back()[0]);
front++;
}
}
Expand Down Expand Up @@ -748,12 +748,12 @@ void SolutionArray::setLoc(int loc, bool restore)
"Both current and buffered indices are invalid.");
}
return;
} else if (m_active[loc_] == m_loc) {
} else if (static_cast<size_t>(m_active[loc_]) == m_loc) {
return;
} else if (loc_ >= m_size) {
throw IndexError("SolutionArray::setLoc", "indices", loc_, m_size - 1);
}
m_loc = m_active[loc_];
m_loc = static_cast<size_t>(m_active[loc_]);
if (restore) {
size_t nState = m_sol->thermo()->stateSize();
m_sol->thermo()->restoreState(nState, m_data->data() + m_loc * m_stride);
Expand Down
34 changes: 17 additions & 17 deletions test/general/test_composite.cpp
Expand Up @@ -87,15 +87,15 @@ TEST(SolutionArray, normalize)
vector<double> state = arr->getState(0); // size is 12
vector<double> newState = {state[0], state[1], 1, 1, 1, 1, 1, 1, 1, 1, 1, -1e12};
ASSERT_EQ(newState.size(), state.size());
for (size_t loc = 0; loc < arr->size(); loc++) {
for (int loc = 0; loc < arr->size(); loc++) {
arr->setState(loc, newState);
state = arr->getState(loc);
for (size_t i = 0; i < state.size(); i++) {
ASSERT_EQ(state[i], newState[i]);
}
}
arr->normalize();
for (size_t loc = 0; loc < arr->size(); loc++) {
for (int loc = 0; loc < arr->size(); loc++) {
state = arr->getState(loc);
for (size_t i = 2; i < state.size() - 1; i++) {
// test normalized species mass fractions - all are equal except last
Expand All @@ -109,15 +109,15 @@ TEST(SolutionArray, normalize)

newState = {state[0], state[1], 100, 0, 0, 0, 0, 0, 0, 0, 0, -1e12};
ASSERT_EQ(newState.size(), state.size());
for (size_t loc = 0; loc < arr->size(); loc++) {
for (int loc = 0; loc < arr->size(); loc++) {
arr->setState(loc, newState);
state = arr->getState(loc);
for (size_t i = 0; i < state.size(); i++) {
ASSERT_EQ(state[i], newState[i]);
}
}
arr->normalize();
for (size_t loc = 0; loc < arr->size(); loc++) {
for (int loc = 0; loc < arr->size(); loc++) {
state = arr->getState(loc);
ASSERT_EQ(state[2], 1.);
for (size_t i = 3; i < state.size(); i++) {
Expand Down Expand Up @@ -222,7 +222,7 @@ TEST(SolutionArray, extraSingle) {
template<class T>
void testSingleCol(SolutionArray& arr, const T& value, bool sliced=false)
{
size_t size = arr.size();
int size = arr.size();
T defaultValue = vector<T>(1)[0];

AnyValue any;
Expand All @@ -240,8 +240,8 @@ void testSingleCol(SolutionArray& arr, const T& value, bool sliced=false)
AnyValue extra;
extra = arr.getComponent("spam");
ASSERT_TRUE(extra.isVector<T>());
ASSERT_EQ(extra.asVector<T>().size(), arr.size());
for (size_t i = 0; i < size; ++i) {
ASSERT_EQ(len(extra.asVector<T>()), arr.size());
for (int i = 0; i < size; ++i) {
ASSERT_EQ(extra.asVector<T>()[i], value);
}

Expand All @@ -259,7 +259,7 @@ void testSingleCol(SolutionArray& arr, const T& value, bool sliced=false)
extra = arr.getComponent("spam");
ASSERT_TRUE(extra.isVector<T>());
ASSERT_EQ(arr.size(), 2 * size);
for (size_t i = 0; i < size; ++i) {
for (int i = 0; i < size; ++i) {
ASSERT_EQ(extra.asVector<T>()[i], value);
ASSERT_EQ(extra.asVector<T>()[i + size], defaultValue);
}
Expand All @@ -269,7 +269,7 @@ void testSingleCol(SolutionArray& arr, const T& value, bool sliced=false)
extra = arr.getComponent("spam");
AnyMap m;
m["spam"] = value;
for (size_t i = 0; i < arr.size(); ++i) {
for (int i = 0; i < arr.size(); ++i) {
ASSERT_EQ(extra.asVector<T>()[i], defaultValue);
arr.setAuxiliary(i, m);
ASSERT_EQ(arr.getAuxiliary(i)["spam"].as<T>(), value);
Expand All @@ -279,7 +279,7 @@ void testSingleCol(SolutionArray& arr, const T& value, bool sliced=false)
any = value;
arr.setComponent("spam", any);
extra = arr.getComponent("spam");
for (size_t i = 0; i < arr.size(); ++i) {
for (int i = 0; i < arr.size(); ++i) {
ASSERT_EQ(extra.asVector<T>()[i], value);
}
}
Expand Down Expand Up @@ -361,7 +361,7 @@ TEST(SolutionArray, extraSlicedStrings) {
template<class T>
void testMultiCol(SolutionArray& arr, const vector<T>& value, bool sliced=false)
{
size_t size = arr.size();
int size = arr.size();
T defaultValue = vector<T>(1)[0];

AnyValue any;
Expand All @@ -382,8 +382,8 @@ void testMultiCol(SolutionArray& arr, const vector<T>& value, bool sliced=false)
ASSERT_TRUE(extra.isMatrix<T>());
ASSERT_EQ(extra.matrixShape().first, arr.size());
ASSERT_EQ(extra.matrixShape().second, any.vectorSize());
for (size_t i = 0; i < size; ++i) {
for (size_t j = 0; j < value.size(); ++j) {
for (int i = 0; i < size; ++i) {
for (int j = 0; j < value.size(); ++j) {
ASSERT_EQ(extra.asVector<vector<T>>()[i][j], value[j]);
}
}
Expand All @@ -406,9 +406,9 @@ void testMultiCol(SolutionArray& arr, const vector<T>& value, bool sliced=false)
arr.resize(2 * size);
extra = arr.getComponent("spam");
ASSERT_EQ(arr.size(), 2 * size);
ASSERT_EQ(extra.asVector<vector<T>>().size(), 2 * size);
for (size_t i = 0; i < size; ++i) {
for (size_t j = 0; j < value.size(); ++j) {
ASSERT_EQ(len(extra.asVector<vector<T>>()), 2 * size);
for (int i = 0; i < size; ++i) {
for (int j = 0; j < value.size(); ++j) {
ASSERT_EQ(extra.asVector<vector<T>>()[i][j], value[j]);
ASSERT_EQ(extra.asVector<vector<T>>()[i + size][j], defaultValue);
}
Expand All @@ -421,7 +421,7 @@ void testMultiCol(SolutionArray& arr, const vector<T>& value, bool sliced=false)
extra = arr.getComponent("spam");
ASSERT_TRUE(extra.isMatrix<T>());
ASSERT_EQ(extra.matrixShape().second, value.size());
for (size_t i = 0; i < arr.size(); ++i) {
for (int i = 0; i < arr.size(); ++i) {
for (size_t j = 0; j < value.size(); ++j) {
ASSERT_EQ(extra.asVector<vector<T>>()[i][j], defaultValue);
}
Expand Down

0 comments on commit 4b8173c

Please sign in to comment.