From bc92fcac102f6f75305058a186a9558606e8c371 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Thu, 29 Jun 2023 08:42:58 -0600 Subject: [PATCH 1/4] [base] Use 'int' for SolutionArray API Fixes MSVC compiler warnings --- include/cantera/base/SolutionArray.h | 22 ++++---- src/base/SolutionArray.cpp | 77 +++++++++++++++------------- src/oneD/StFlow.cpp | 3 +- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/include/cantera/base/SolutionArray.h b/include/cantera/base/SolutionArray.h index 1dbc3242ab..b51216d0be 100644 --- a/include/cantera/base/SolutionArray.h +++ b/include/cantera/base/SolutionArray.h @@ -27,7 +27,7 @@ class SolutionArray { private: SolutionArray(const shared_ptr& sol, - size_t size, + int size, const AnyMap& meta); SolutionArray(const SolutionArray& arr, const vector& indices); @@ -43,7 +43,7 @@ class SolutionArray * @param meta AnyMap holding SolutionArray meta data */ static shared_ptr create(const shared_ptr& sol, - size_t size=0, + int size=0, const AnyMap& meta={}) { return shared_ptr(new SolutionArray(sol, size, meta)); @@ -70,7 +70,7 @@ class SolutionArray } //! Resize SolutionArray objects with a single dimension (default). - void resize(size_t size); + void resize(int size); //! SolutionArray shape information used by high-level API's. vector apiShape() const { @@ -82,8 +82,8 @@ class SolutionArray void setApiShape(const vector& shape); //! Number of SolutionArray dimensions used by high-level API's. - size_t apiNdim() const { - return m_apiShape.size(); + int apiNdim() const { + return static_cast(m_apiShape.size()); } /*! @@ -142,18 +142,18 @@ class SolutionArray /*! * Update the buffered location used to access SolutionArray entries. */ - void setLoc(size_t loc, bool restore=true); + void setLoc(int loc, bool restore=true); /*! * Update state at given location to state of associated Solution object. */ - void updateState(size_t loc); + void updateState(int loc); //! Retrieve the state vector for a given location. - vector getState(size_t loc); + vector getState(int loc); //! Set the state vector for a given location. - void setState(size_t loc, const vector& state); + void setState(int loc, const vector& state); //! Normalize mass/mole fractions void normalize(); @@ -178,10 +178,10 @@ class SolutionArray vector listExtra(bool all=true) const; //! Retrieve auxiliary data for a given location. - AnyMap getAuxiliary(size_t loc); + AnyMap getAuxiliary(int loc); //! Set auxiliary data for a given location. - void setAuxiliary(size_t loc, const AnyMap& data); + void setAuxiliary(int loc, const AnyMap& data); //! Append location entry at end of SolutionArray. void append(const vector& state, const AnyMap& extra); diff --git a/src/base/SolutionArray.cpp b/src/base/SolutionArray.cpp index 0d199ceb0e..56437ce3dd 100644 --- a/src/base/SolutionArray.cpp +++ b/src/base/SolutionArray.cpp @@ -37,7 +37,7 @@ namespace Cantera { SolutionArray::SolutionArray(const shared_ptr& sol, - size_t size, const AnyMap& meta) + int size, const AnyMap& meta) : m_sol(sol) , m_size(size) , m_dataSize(size) @@ -52,11 +52,11 @@ SolutionArray::SolutionArray(const shared_ptr& sol, m_extra = make_shared>(); m_order = make_shared>(); for (size_t i = 0; i < m_dataSize; ++i) { - m_active.push_back(i); + m_active.push_back(static_cast(i)); } reset(); m_apiShape.resize(1); - m_apiShape[0] = m_dataSize; + m_apiShape[0] = static_cast(m_dataSize); } SolutionArray::SolutionArray(const SolutionArray& other, @@ -150,7 +150,7 @@ void SolutionArray::reset() } } -void SolutionArray::resize(size_t size) +void SolutionArray::resize(int size) { if (apiNdim() > 1) { throw CanteraError("SolutionArray::resize", @@ -161,8 +161,8 @@ void SolutionArray::resize(size_t size) throw CanteraError("SolutionArray::resize", "Unable to resize as data are shared by multiple objects."); } - _resize(size); - m_apiShape[0] = size; + _resize(static_cast(size)); + m_apiShape[0] = static_cast(size); } void SolutionArray::setApiShape(const vector& shape) @@ -196,7 +196,7 @@ void SolutionArray::_resize(size_t size) } m_active.clear(); for (size_t i = 0; i < m_dataSize; ++i) { - m_active.push_back(i); + m_active.push_back(static_cast(i)); } } @@ -209,8 +209,9 @@ vector doubleColumn(string name, const vector& comp, vector data; vector raw; string notation = fmt::format("{{:{}.{}g}}", width, (width - 1) / 2); - int dots = comp.size() + 1; - if (comp.size() <= rows) { + int csize = static_cast(comp.size()); + int dots = csize + 1; + if (csize <= rows) { for (const auto& val : comp) { data.push_back(val); raw.push_back(boost::trim_copy(fmt::format(notation, val))); @@ -221,7 +222,7 @@ vector doubleColumn(string name, const vector& comp, data.push_back(comp[row]); raw.push_back(boost::trim_copy(fmt::format(notation, comp[row]))); } - for (int row = comp.size() - rows / 2; row < comp.size(); row++) { + for (int row = csize - rows / 2; row < csize; row++) { data.push_back(comp[row]); raw.push_back(boost::trim_copy(fmt::format(notation, comp[row]))); } @@ -296,8 +297,9 @@ vector integerColumn(string name, const vector& comp, vector data; string notation = fmt::format("{{:{}}}", width); size_t maxLen = 2; // minimum column width is 2 - int dots = comp.size() + 1; - if (comp.size() <= rows) { + int csize = static_cast(comp.size()); + int dots = csize + 1; + if (csize <= rows) { for (const auto& val : comp) { data.push_back(val); string name = boost::trim_copy(fmt::format(notation, val)); @@ -316,7 +318,7 @@ vector integerColumn(string name, const vector& comp, } maxLen = std::max(maxLen, name.size()); } - for (int row = comp.size() - rows / 2; row < comp.size(); row++) { + for (int row = csize - rows / 2; row < csize; row++) { data.push_back(comp[row]); string name = boost::trim_copy(fmt::format(notation, comp[row])); if (name[0] == '-') { @@ -355,8 +357,9 @@ vector stringColumn(string name, const vector& comp, vector data; string notation = fmt::format("{{:{}}}", width); size_t maxLen = 3; // minimum column width is 3 - int dots = comp.size() + 1; - if (comp.size() <= rows) { + int csize = static_cast(comp.size()); + int dots = csize + 1; + if (csize <= rows) { for (const auto& val : comp) { data.push_back(val); maxLen = std::max(maxLen, @@ -369,7 +372,7 @@ vector stringColumn(string name, const vector& comp, maxLen = std::max(maxLen, boost::trim_copy(fmt::format(notation, comp[row])).size()); } - for (int row = comp.size() - rows / 2; row < comp.size(); row++) { + for (int row = csize - rows / 2; row < csize; row++) { data.push_back(comp[row]); maxLen = std::max(maxLen, boost::trim_copy(fmt::format(notation, comp[row])).size()); @@ -434,7 +437,8 @@ vector formatColumn(string name, const AnyValue& comp, int rows, int wid col.push_back(repr); } col.push_back(fmt::format(notation, "...")); - for (int row = size - rows / 2; row < size; row++) { + int size_ = static_cast(size); + for (int row = size_ - rows / 2; row < size_; row++) { col.push_back(repr); } } @@ -732,37 +736,38 @@ void SolutionArray::setComponent(const string& name, const AnyValue& data) } } -void SolutionArray::setLoc(size_t loc, bool restore) +void SolutionArray::setLoc(int loc, bool restore) { + size_t loc_ = static_cast(loc); if (m_size == 0) { throw CanteraError("SolutionArray::setLoc", "Unable to set location in empty SolutionArray."); - } else if (loc == npos) { + } else if (loc < 0) { if (m_loc == npos) { throw CanteraError("SolutionArray::setLoc", "Both current and buffered indices are invalid."); } return; - } else if (m_active[loc] == (int)m_loc) { + } else if (m_active[loc_] == m_loc) { return; - } else if (loc >= m_size) { - throw IndexError("SolutionArray::setLoc", "indices", loc, m_size - 1); + } else if (loc_ >= m_size) { + throw IndexError("SolutionArray::setLoc", "indices", loc_, m_size - 1); } - m_loc = m_active[loc]; + m_loc = m_active[loc_]; if (restore) { size_t nState = m_sol->thermo()->stateSize(); m_sol->thermo()->restoreState(nState, m_data->data() + m_loc * m_stride); } } -void SolutionArray::updateState(size_t loc) +void SolutionArray::updateState(int loc) { setLoc(loc, false); size_t nState = m_sol->thermo()->stateSize(); m_sol->thermo()->saveState(nState, m_data->data() + m_loc * m_stride); } -vector SolutionArray::getState(size_t loc) +vector SolutionArray::getState(int loc) { setLoc(loc); size_t nState = m_sol->thermo()->stateSize(); @@ -771,7 +776,7 @@ vector SolutionArray::getState(size_t loc) return out; } -void SolutionArray::setState(size_t loc, const vector& state) +void SolutionArray::setState(int loc, const vector& state) { size_t nState = m_sol->thermo()->stateSize(); if (state.size() != nState) { @@ -794,7 +799,7 @@ void SolutionArray::normalize() { vector out(nState); if (nativeState.count("Y")) { size_t offset = nativeState["Y"]; - for (size_t loc = 0; loc < m_size; loc++) { + for (int loc = 0; loc < static_cast(m_size); loc++) { setLoc(loc, true); // set location and restore state phase->setMassFractions(m_data->data() + m_loc * m_stride + offset); m_sol->thermo()->saveState(out); @@ -802,7 +807,7 @@ void SolutionArray::normalize() { } } else if (nativeState.count("X")) { size_t offset = nativeState["X"]; - for (size_t loc = 0; loc < m_size; loc++) { + for (int loc = 0; loc < static_cast(m_size); loc++) { setLoc(loc, true); // set location and restore state phase->setMoleFractions(m_data->data() + m_loc * m_stride + offset); m_sol->thermo()->saveState(out); @@ -814,7 +819,7 @@ void SolutionArray::normalize() { } } -AnyMap SolutionArray::getAuxiliary(size_t loc) +AnyMap SolutionArray::getAuxiliary(int loc) { setLoc(loc); AnyMap out; @@ -842,7 +847,7 @@ AnyMap SolutionArray::getAuxiliary(size_t loc) return out; } -void SolutionArray::setAuxiliary(size_t loc, const AnyMap& data) +void SolutionArray::setAuxiliary(int loc, const AnyMap& data) { setLoc(loc, false); for (const auto& [name, value] : data) { @@ -1051,7 +1056,7 @@ void SolutionArray::writeEntry(const string& fname, bool overwrite, const string output << header.str() << std::endl << std::setprecision(9); vector buf(speciesNames.size(), 0.); - for (size_t row = 0; row < m_size; row++) { + for (int row = 0; row < static_cast(m_size); row++) { setLoc(row); if (mole) { m_sol->thermo()->getMoleFractions(buf.data()); @@ -1254,7 +1259,7 @@ void SolutionArray::append(const vector& state, const AnyMap& extra) "Unable to append multi-dimensional arrays."); } - size_t pos = size(); + int pos = size(); resize(pos + 1); try { setState(pos, state); @@ -1643,7 +1648,7 @@ void SolutionArray::readEntry(const string& fname, const string& name, m_meta.erase("api-shape"); } else { // legacy format; size needs to be detected - resize(size); + resize(static_cast(size)); } if (m_size == 0) { @@ -1793,7 +1798,7 @@ void SolutionArray::readEntry(const AnyMap& root, const string& name, const stri } // set size and initialize - size_t size = 0; + long size = 0; if (path.hasKey("size")) { // one-dimensional array resize(path["size"].asInt()); @@ -1806,9 +1811,9 @@ void SolutionArray::readEntry(const AnyMap& root, const string& name, const stri size = path.getInt("points", 0); if (!path.hasKey("T") && !path.hasKey("temperature")) { // overwrite size - Sim1D erroneously assigns '1' - size = 0; + size = (long)0; } - resize(size); + resize(static_cast(size)); } m_extra->clear(); diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index bc624b889d..90f2fefa70 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -789,7 +789,8 @@ AnyMap StFlow::getMeta() const shared_ptr StFlow::asArray(const double* soln) const { - auto arr = SolutionArray::create(m_solution, nPoints(), getMeta()); + auto arr = SolutionArray::create( + m_solution, static_cast(nPoints()), getMeta()); arr->addExtra("grid", false); // leading entry AnyValue value; value = m_z; From 745217c8e2962905806f0a5b9c7c447d74a4a996 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Thu, 29 Jun 2023 08:25:36 -0600 Subject: [PATCH 2/4] [clib] Fix MSVC compiler warnings Co-authored-by: Ray Speth --- src/clib/Cabinet.h | 7 +++---- src/clib/ctfunc.cpp | 19 ++++++++++--------- test/clib/test_ctonedim.cpp | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/clib/Cabinet.h b/src/clib/Cabinet.h index c7b265fd5a..9c3179b818 100644 --- a/src/clib/Cabinet.h +++ b/src/clib/Cabinet.h @@ -63,7 +63,7 @@ class SharedCabinet static int add(shared_ptr obj) { dataRef data = getData(); data.push_back(obj); - int idx = data.size() - 1; + int idx = static_cast(data.size()) - 1; lookupRef lookup = getLookup(); if (index(*obj) >= 0) { lookup[obj.get()].insert(idx); @@ -77,8 +77,7 @@ class SharedCabinet * Return cabinet size. */ static int size() { - int size = getData().size(); - return size; + return static_cast(getData().size()); } /** @@ -87,7 +86,7 @@ class SharedCabinet static int clear() { dataRef data = getData(); for (size_t i = 0; i < data.size(); i++) { - del(i); + del(static_cast(i)); } return 0; } diff --git a/src/clib/ctfunc.cpp b/src/clib/ctfunc.cpp index 9d9ba1eadb..641d1d9c4c 100644 --- a/src/clib/ctfunc.cpp +++ b/src/clib/ctfunc.cpp @@ -27,7 +27,8 @@ extern "C" { { try { shared_ptr r; - size_t m = lenp; + int m = static_cast(lenp); + int nn = static_cast(n); if (type == SinFuncType) { r = newFunc1("sin", params[0]); } else if (type == CosFuncType) { @@ -51,21 +52,21 @@ extern "C" { vector par(params, params + lenp); r = newFunc1("Arrhenius", par, n); } else if (type == PeriodicFuncType) { - r = newFunc1("periodic", FuncCabinet::at(n), params[0]); + r = newFunc1("periodic", FuncCabinet::at(nn), params[0]); } else if (type == SumFuncType) { - r = newFunc1("sum", FuncCabinet::at(n), FuncCabinet::at(m)); + r = newFunc1("sum", FuncCabinet::at(nn), FuncCabinet::at(m)); } else if (type == DiffFuncType) { - r = newFunc1("diff", FuncCabinet::at(n), FuncCabinet::at(m)); + r = newFunc1("diff", FuncCabinet::at(nn), FuncCabinet::at(m)); } else if (type == ProdFuncType) { - r = newFunc1("product", FuncCabinet::at(n), FuncCabinet::at(m)); + r = newFunc1("product", FuncCabinet::at(nn), FuncCabinet::at(m)); } else if (type == RatioFuncType) { - r = newFunc1("ratio", FuncCabinet::at(n), FuncCabinet::at(m)); + r = newFunc1("ratio", FuncCabinet::at(nn), FuncCabinet::at(m)); } else if (type == CompositeFuncType) { - r = newFunc1("composite", FuncCabinet::at(n), FuncCabinet::at(m)); + r = newFunc1("composite", FuncCabinet::at(nn), FuncCabinet::at(m)); } else if (type == TimesConstantFuncType) { - r = newFunc1("times-constant", FuncCabinet::at(n), params[0]); + r = newFunc1("times-constant", FuncCabinet::at(nn), params[0]); } else if (type == PlusConstantFuncType) { - r = newFunc1("plus-constant", FuncCabinet::at(n), params[0]); + r = newFunc1("plus-constant", FuncCabinet::at(nn), params[0]); } else { throw CanteraError("func_new", "unknown function type"); } diff --git a/test/clib/test_ctonedim.cpp b/test/clib/test_ctonedim.cpp index 124d2b2451..524ae99d6d 100644 --- a/test/clib/test_ctonedim.cpp +++ b/test/clib/test_ctonedim.cpp @@ -208,10 +208,10 @@ TEST(ctonedim, freeflame_from_parts) // set up initial guess vector locs{0.0, 0.3, 0.7, 1.0}; vector value{uin, uin, uout, uout}; - int comp = domain_componentIndex(flow, "velocity"); + int comp = static_cast(domain_componentIndex(flow, "velocity")); sim1D_setProfile(flame, dom, comp, 4, locs.data(), 4, value.data()); value = {T, T, Tad, Tad}; - comp = domain_componentIndex(flow, "T"); + comp = static_cast(domain_componentIndex(flow, "T")); sim1D_setProfile(flame, dom, comp, 4, locs.data(), 4, value.data()); for (size_t i = 0; i < nsp; i++) { value = {yin[i], yin[i], yout[i], yout[i]}; @@ -220,7 +220,7 @@ TEST(ctonedim, freeflame_from_parts) thermo_getSpeciesName(ph, i, buflen, buf); string name = buf; ASSERT_EQ(name, gas->speciesName(i)); - comp = domain_componentIndex(flow, buf); + comp = static_cast(domain_componentIndex(flow, buf)); sim1D_setProfile(flame, dom, comp, 4, locs.data(), 4, value.data()); } @@ -246,10 +246,10 @@ TEST(ctonedim, freeflame_from_parts) } ASSERT_EQ(domain_nPoints(flow), nz + 1); - comp = domain_componentIndex(dom, "T"); + comp = static_cast(domain_componentIndex(dom, "T")); double Tprev = sim1D_value(flame, dom, comp, 0); for (size_t n = 0; n < domain_nPoints(flow); n++) { - T = sim1D_value(flame, dom, comp, n); + T = sim1D_value(flame, dom, comp, static_cast(n)); ASSERT_GE(T, Tprev); Tprev = T; } From c6b24c18fd1b07d43f8ea462ea2365c48cc0015c Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Thu, 29 Jun 2023 10:30:08 -0600 Subject: [PATCH 3/4] [Python] Update SolutionArray pxd information --- interfaces/cython/cantera/solutionbase.pxd | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/interfaces/cython/cantera/solutionbase.pxd b/interfaces/cython/cantera/solutionbase.pxd index a00322e3ef..95e9e28efe 100644 --- a/interfaces/cython/cantera/solutionbase.pxd +++ b/interfaces/cython/cantera/solutionbase.pxd @@ -67,11 +67,11 @@ cdef extern from "cantera/base/SolutionArray.h" namespace "Cantera": cdef cppclass CxxSolutionArray "Cantera::SolutionArray": shared_ptr[CxxSolutionArray] share(vector[int]&) except +translate_exception void reset() except +translate_exception - size_t size() - void resize(size_t) except +translate_exception + int size() + void resize(int) except +translate_exception vector[long int] apiShape() except +translate_exception void setApiShape(vector[long int]&) except +translate_exception - size_t apiNdim() + int apiNdim() string info(vector[string]&, int, int) except +translate_exception CxxAnyMap meta() void setMeta(CxxAnyMap&) @@ -79,21 +79,21 @@ cdef extern from "cantera/base/SolutionArray.h" namespace "Cantera": cbool hasComponent(string&) CxxAnyValue getComponent(string&) except +translate_exception void setComponent(string&, CxxAnyValue&) except +translate_exception - void setLoc(size_t) except +translate_exception - void updateState(size_t) except +translate_exception - vector[double] getState(size_t) except +translate_exception - void setState(size_t, vector[double]&) except +translate_exception + void setLoc(int) except +translate_exception + void updateState(int) except +translate_exception + vector[double] getState(int) except +translate_exception + void setState(int, vector[double]&) except +translate_exception vector[string] listExtra() cbool hasExtra(string&) void addExtra(string&, cbool) except +translate_exception - CxxAnyMap getAuxiliary(size_t) except +translate_exception - void setAuxiliary(size_t, CxxAnyMap&) except +translate_exception + CxxAnyMap getAuxiliary(int) except +translate_exception + void setAuxiliary(int, CxxAnyMap&) except +translate_exception void append(vector[double]&, CxxAnyMap&) except +translate_exception void save(string&, string&, string&, string&, cbool, int, string&) except +translate_exception CxxAnyMap restore(string&, string&, string&) except +translate_exception cdef shared_ptr[CxxSolutionArray] CxxNewSolutionArray "Cantera::SolutionArray::create" ( - shared_ptr[CxxSolution], size_t, CxxAnyMap&) except +translate_exception + shared_ptr[CxxSolution], int, CxxAnyMap&) except +translate_exception ctypedef void (*transportMethod1d)(CxxTransport*, double*) except +translate_exception From bde12f210b3e7eb683c924dabe2e6c3ad4f84dd3 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 29 Jun 2023 10:35:25 -0400 Subject: [PATCH 4/4] Update yaml-cpp submodule to v0.7.0 --- ext/yaml-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/yaml-cpp b/ext/yaml-cpp index 0122697561..0579ae3d97 160000 --- a/ext/yaml-cpp +++ b/ext/yaml-cpp @@ -1 +1 @@ -Subproject commit 012269756149ae99745b6dafefd415843d7420bb +Subproject commit 0579ae3d976091d7d664aa9d2527e0d0cff25763