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

Fix issues identified by _GLIBCXX_ASSERTIONS and various build warnings #1441

Merged
merged 7 commits into from
Feb 25, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ jobs:
- name: Build Cantera
run: |
python3 `which scons` build env_vars=all -j2 debug=n --debug=time \
hdf_libdir=$HDF5_LIBDIR hdf_include=$HDF5_INCLUDEDIR
hdf_libdir=$HDF5_LIBDIR hdf_include=$HDF5_INCLUDEDIR \
cc_flags=-D_GLIBCXX_ASSERTIONS
- name: Upload shared library
uses: actions/upload-artifact@v3
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-22.04'
Expand Down
12 changes: 6 additions & 6 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ if conda_prefix is not None:
env["extra_lib_dirs"].append(conda_lib_dir)
logger.info(f"Adding conda include and library paths: {conda_prefix}")

env.Append(CPPPATH=env['extra_inc_dirs'],
LIBPATH=env['extra_lib_dirs'])
add_system_include(env, env['extra_inc_dirs'])
env.Append(LIBPATH=env['extra_lib_dirs'])

if env['use_rpath_linkage']:
env.Append(RPATH=env['extra_lib_dirs'])
Expand All @@ -1054,7 +1054,7 @@ else:

if env['boost_inc_dir']:
env["boost_inc_dir"] = Path(env["boost_inc_dir"]).as_posix()
env.Append(CPPPATH=env['boost_inc_dir'])
add_system_include(env, env['boost_inc_dir'])

if env['blas_lapack_dir']:
env["blas_lapack_dir"] = Path(env["blas_lapack_dir"]).as_posix()
Expand All @@ -1065,7 +1065,7 @@ if env['blas_lapack_dir']:
if env['system_sundials'] in ('y','default'):
if env['sundials_include']:
env["sundials_include"] = Path(env["sundials_include"]).as_posix()
env.Append(CPPPATH=[env['sundials_include']])
add_system_include(env, env['sundials_include'])
env['system_sundials'] = 'y'
if env['sundials_libdir']:
env["sundials_libdir"] = Path(env["sundials_libdir"]).as_posix()
Expand Down Expand Up @@ -1100,7 +1100,7 @@ int main(int argc, char** argv) {
return result

# Set up compiler options before running configuration tests
env['CXXFLAGS'] = listify(env['cxx_flags'])
env.Append(CXXFLAGS=listify(env['cxx_flags']))
env['CCFLAGS'] = listify(env['cc_flags']) + listify(env['thread_flags'])
env['LINKFLAGS'] += listify(env['thread_flags'])
env['CPPDEFINES'] = {}
Expand Down Expand Up @@ -1531,7 +1531,7 @@ else: # env['system_sundials'] == 'n'

if env["hdf_include"]:
env["hdf_include"] = Path(env["hdf_include"]).as_posix()
env.Append(CPPPATH=[env["hdf_include"]])
add_system_include(env, env["hdf_include"])
env["hdf_support"] = "y"
if env["hdf_libdir"]:
env["hdf_libdir"] = Path(env["hdf_libdir"]).as_posix()
Expand Down
8 changes: 7 additions & 1 deletion interfaces/cython/setup.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ install_requires =
python_requires = >=@py_min_ver_str@
packages =
cantera
cantera.data
cantera.test
cantera.examples

[options.package_data]
# The module extension needs to be here since we don't want setuptools to compile
# the extension, so there are no ``source`` files in the setup.py ``extension`` and
# we have to treat the module as package data.
cantera = *.pxd, *.dll, *@py_module_ext@, test/*.txt, examples/*.txt, data/*.*
cantera = *.pxd, *.dll, *@py_module_ext@
cantera.data = *.*
cantera.test = *.txt
cantera.examples = *.txt

[options.extras_require]
hdf5 = h5py
Expand Down
26 changes: 24 additions & 2 deletions site_scons/buildutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
__all__ = ("Option", "PathOption", "BoolOption", "EnumOption", "Configuration",
"logger", "remove_directory", "remove_file", "test_results",
"add_RegressionTest", "get_command_output", "listify", "which",
"ConfigBuilder", "multi_glob", "get_spawn", "quoted",
"ConfigBuilder", "multi_glob", "get_spawn", "quoted", "add_system_include",
"get_pip_install_location", "compiler_flag_list", "setup_python_env")

if TYPE_CHECKING:
Expand Down Expand Up @@ -1118,6 +1118,27 @@ def compiler_flag_list(
return cc_flags


def add_system_include(env, include, mode='append'):
# Add a file to the include path as a "system" include directory, which will
# suppress warnings stemming from code that isn't part of Cantera, and reduces
# time spent scanning these files for changes.
if mode == 'append':
add = env.Append
elif mode == 'prepend':
add = env.Prepend
else:
raise ValueError("mode must be 'append' or 'prepend'")

if env['CC'] == 'cl':
add(CPPPATH=include)
else:
if isinstance(include, (list, tuple)):
for inc in include:
add(CXXFLAGS=('-isystem', inc))
else:
add(CXXFLAGS=('-isystem', include))


def quoted(s: str) -> str:
"""Return the given string wrapped in double quotes."""
return f'"{s}"'
Expand Down Expand Up @@ -1284,7 +1305,8 @@ def setup_python_env(env):
py_version_nodot = info["py_version_nodot"]
plat = info['plat'].replace('-', '_').replace('.', '_')
numpy_include = info["numpy_include"]
env.Prepend(CPPPATH=[Dir('#include'), inc, numpy_include])
env.Prepend(CPPPATH=Dir('#include'))
add_system_include(env, (inc, numpy_include), 'prepend')
env.Prepend(LIBS=env['cantera_shared_libs'])

# Fix the module extension for Windows from the sysconfig library.
Expand Down
3 changes: 2 additions & 1 deletion src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ libs = [('base', ['cpp'], baseSetup),
]

localenv = env.Clone()
localenv.Prepend(CPPPATH=[Dir('#include'), Dir('#include/cantera/ext'), Dir('.')])
localenv.Prepend(CPPPATH=[Dir('#include'), Dir('.')])
add_system_include(localenv, Dir('#include/cantera/ext'), 'prepend')
localenv.Append(CCFLAGS=env['warning_flags'])
indicatorEnv = localenv.Clone() # Get this before any of the PCH complications

Expand Down
5 changes: 3 additions & 2 deletions src/base/SolutionArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ void SolutionArray::writeEntry(const std::string& fname, const std::string& id,
std::vector<vector_fp> prop;
for (size_t i = 0; i < m_size; i++) {
size_t first = offset + i * m_stride;
prop.push_back(vector_fp(&m_data[first], &m_data[first + nSpecies]));
prop.emplace_back(m_data.begin() + first,
m_data.begin() + first + nSpecies);
}
file.writeMatrix(id, name, prop);
} else {
Expand Down Expand Up @@ -428,7 +429,7 @@ std::string SolutionArray::detectMode(const std::set<std::string>& names, bool n
// check set of available names against state acronyms defined by Phase::fullStates
std::string mode = "";
const auto& nativeState = m_sol->thermo()->nativeState();
bool usesNativeState;
bool usesNativeState = false;
auto surf = std::dynamic_pointer_cast<SurfPhase>(m_sol->thermo());
for (const auto& item : m_sol->thermo()->fullStates()) {
bool found = true;
Expand Down
4 changes: 2 additions & 2 deletions src/equil/MultiPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ void MultiPhase::uploadMoleFractionsFromPhases()
size_t loc = 0;
for (size_t ip = 0; ip < nPhases(); ip++) {
ThermoPhase* p = m_phase[ip];
p->getMoleFractions(&m_moleFractions[loc]);
p->getMoleFractions(m_moleFractions.data() + loc);
loc += p->nSpecies();
}
calcElemAbundances();
Expand All @@ -828,7 +828,7 @@ void MultiPhase::updatePhases() const
{
size_t loc = 0;
for (size_t p = 0; p < nPhases(); p++) {
m_phase[p]->setState_TPX(m_temp, m_press, &m_moleFractions[loc]);
m_phase[p]->setState_TPX(m_temp, m_press, m_moleFractions.data() + loc);
loc += m_phase[p]->nSpecies();
m_temp_OK[p] = true;
if (m_temp < m_phase[p]->minTemp() || m_temp > m_phase[p]->maxTemp()) {
Expand Down
56 changes: 31 additions & 25 deletions src/equil/vcs_solve_TP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ using namespace std;
namespace {
enum stages {MAIN, EQUILIB_CHECK, ELEM_ABUND_CHECK,
RECHECK_DELETED, RETURN_A, RETURN_B};

const int anote_size = 128;
}

namespace Cantera
Expand Down Expand Up @@ -56,7 +58,7 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit)
bool uptodate_minors = true;
int forceComponentCalc = 1;

char ANOTE[128];
char ANOTE[anote_size];
// Set the debug print lvl to the same as the print lvl.
m_debug_print_lvl = printDetails;
if (printDetails > 0 && print_lvl == 0) {
Expand Down Expand Up @@ -476,7 +478,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
if (iph == iphasePop) {
dx = m_deltaMolNumSpecies[kspec];
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + m_deltaMolNumSpecies[kspec];
sprintf(ANOTE, "Phase pop");
snprintf(ANOTE, anote_size, "Phase pop");
} else {
dx = 0.0;
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
Expand All @@ -500,15 +502,18 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
resurrect = false;
sprintf(ANOTE, "Species stays zeroed: DG = %11.4E", m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size, "Species stays zeroed: DG = %11.4E",
m_deltaGRxn_new[irxn]);
if (m_deltaGRxn_new[irxn] < 0.0) {
if (m_speciesStatus[kspec] == VCS_SPECIES_STOICHZERO) {
sprintf(ANOTE, "Species stays zeroed even though dg neg due to "
"STOICH/PHASEPOP constraint: DG = %11.4E",
m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size,
"Species stays zeroed even though dg neg due to "
"STOICH/PHASEPOP constraint: DG = %11.4E",
m_deltaGRxn_new[irxn]);
} else {
sprintf(ANOTE, "Species stays zeroed even though dg neg: DG = %11.4E, ds zeroed",
m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size, "Species stays zeroed even"
" though dg neg: DG = %11.4E, ds zeroed",
m_deltaGRxn_new[irxn]);
}
}
} else {
Expand All @@ -519,9 +524,9 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
if (atomComp > 0.0) {
double maxPermissible = m_elemAbundancesGoal[j] / atomComp;
if (maxPermissible < VCS_DELETE_MINORSPECIES_CUTOFF) {
sprintf(ANOTE, "Species stays zeroed even though dG "
"neg, because of %s elemAbund",
m_elementName[j].c_str());
snprintf(ANOTE, anote_size, "Species stays zeroed"
" even though dG neg, because of %s elemAbund",
m_elementName[j].c_str());
resurrect = false;
break;
}
Expand Down Expand Up @@ -554,7 +559,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
dx = m_molNumSpecies_new[kspec] - m_molNumSpecies_old[kspec];
}
m_deltaMolNumSpecies[kspec] = dx;
sprintf(ANOTE, "Born:IC=-1 to IC=1:DG=%11.4E", m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size, "Born:IC=-1 to IC=1:DG=%11.4E",
m_deltaGRxn_new[irxn]);
} else {
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
Expand All @@ -569,7 +575,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
dx = 0.0;
sprintf(ANOTE,"minor species not considered");
snprintf(ANOTE, anote_size, "minor species not considered");
if (m_debug_print_lvl >= 2) {
plogf(" --- %-12s%3d% 11.4E %11.4E %11.4E | %s\n",
m_speciesName[kspec], m_speciesStatus[kspec], m_molNumSpecies_old[kspec], m_molNumSpecies_new[kspec],
Expand Down Expand Up @@ -623,7 +629,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
}
} else {
// MAJOR SPECIES
sprintf(ANOTE, "Normal Major Calc");
snprintf(ANOTE, anote_size, "Normal Major Calc");

// Check for superconvergence of the formation reaction. Do
// nothing if it is superconverged. Skip to the end of the irxn
Expand All @@ -632,7 +638,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
dx = 0.0;
sprintf(ANOTE, "major species is converged");
snprintf(ANOTE, anote_size, "major species is converged");
if (m_debug_print_lvl >= 2) {
plogf(" --- %-12s %3d %11.4E %11.4E %11.4E | %s\n",
m_speciesName[kspec], m_speciesStatus[kspec], m_molNumSpecies_old[kspec], m_molNumSpecies_new[kspec],
Expand All @@ -653,8 +659,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
} else {
dx = 0.0;
m_deltaMolNumSpecies[kspec] = 0.0;
sprintf(ANOTE, "dx set to 0, DG flipped sign due to "
"changed initial point");
snprintf(ANOTE, anote_size, "dx set to 0, DG flipped sign due to "
"changed initial point");
}

//Form a tentative value of the new species moles
Expand All @@ -665,8 +671,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
// the outcome, we branch to sections below, or we restart the
// entire iteration.
if (m_molNumSpecies_new[kspec] <= 0.0) {
sprintf(ANOTE, "initial nonpos kmoles= %11.3E",
m_molNumSpecies_new[kspec]);
snprintf(ANOTE, anote_size, "initial nonpos kmoles= %11.3E",
m_molNumSpecies_new[kspec]);
// NON-POSITIVE MOLES OF MAJOR SPECIES
//
// We are here when a tentative value of a mole fraction
Expand Down Expand Up @@ -705,15 +711,15 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + dx;
if (m_molNumSpecies_new[kspec] > 0.0) {
m_deltaMolNumSpecies[kspec] = dx;
sprintf(ANOTE,
"zeroing SS phase created a neg component species "
"-> reducing step size instead");
snprintf(ANOTE, anote_size,
"zeroing SS phase created a neg component species "
"-> reducing step size instead");
} else {
// We are going to zero the single species phase.
// Set the existence flag
iph = m_phaseID[kspec];
Vphase = m_VolPhaseList[iph].get();
sprintf(ANOTE, "zeroing out SS phase: ");
snprintf(ANOTE, anote_size, "zeroing out SS phase: ");

// Change the base mole numbers for the iteration.
// We need to do this here, because we have decided
Expand Down Expand Up @@ -1365,7 +1371,7 @@ double VCS_SOLVE::vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete,
}
dg_irxn = std::max(dg_irxn, -200.0);
if (ANOTE) {
sprintf(ANOTE,"minor species alternative calc");
snprintf(ANOTE, anote_size, "minor species alternative calc");
}
if (dg_irxn >= 23.0) {
double molNum_kspec_new = w_kspec * 1.0e-10;
Expand Down Expand Up @@ -1428,7 +1434,7 @@ double VCS_SOLVE::vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete,
// Need to check the sign -> This is good for electrons
double dx = m_deltaGRxn_old[irxn]/ m_Faraday_dim;
if (ANOTE) {
sprintf(ANOTE,"voltage species alternative calc");
snprintf(ANOTE, anote_size, "voltage species alternative calc");
}
return dx;
}
Expand Down
4 changes: 2 additions & 2 deletions src/numerics/AdaptivePreconditioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void AdaptivePreconditioner::setup()
// check for errors
if (m_solver.info() != Eigen::Success) {
throw CanteraError("AdaptivePreconditioner::setup",
"error code: {}", m_solver.info());
"error code: {}", static_cast<int>(m_solver.info()));
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ void AdaptivePreconditioner::solve(const size_t stateSize, double* rhs_vector, d
xVector = m_solver.solve(bVector);
if (m_solver.info() != Eigen::Success) {
throw CanteraError("AdaptivePreconditioner::solve",
"error code: {}", m_solver.info());
"error code: {}", static_cast<int>(m_solver.info()));
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/oneD/Sim1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,14 @@ AnyMap legacyH5(shared_ptr<SolutionArray> arr, const AnyMap& header={})
if (header.hasKey("fixed_temperature")) {
double temp = header.getDouble("fixed_temperature", -1.);
auto profile = arr->getComponent("T");
size_t ix = 0;
int ix = 0;
while (profile[ix] <= temp && ix < arr->size()) {
ix++;
}
out["fixed-point"]["location"] = arr->getComponent("grid")[ix - 1];
out["fixed-point"]["temperature"] = temp;
if (ix != 0) {
out["fixed-point"]["location"] = arr->getComponent("grid")[ix - 1];
out["fixed-point"]["temperature"] = temp;
}
}

return out;
Expand Down Expand Up @@ -558,7 +560,9 @@ int Sim1D::refine(int loglevel)
for (size_t n = 0; n < nDomains(); n++) {
Domain1D& d = domain(n);
gridsize = dsize[n];
d.setupGrid(gridsize, &znew[gridstart]);
if (gridsize != 0) {
d.setupGrid(gridsize, &znew[gridstart]);
}
gridstart += gridsize;
}

Expand Down
6 changes: 3 additions & 3 deletions src/transport/IonGasTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void IonGasTransport::init(ThermoPhase* thermo, int mode, int log_level)
// Find the index of electron
size_t nElectronSpecies = 0;
for (size_t k = 0; k < m_nsp; k++) {
if (m_thermo->molecularWeight(k) ==
m_thermo->atomicWeight(m_thermo->elementIndex("E")) &&
m_thermo->charge(k) == -1) {
if (m_thermo->molecularWeight(k) == getElementWeight("E") &&
m_thermo->charge(k) == -1)
{
m_kElectron = k;
nElectronSpecies++;
}
Expand Down
2 changes: 1 addition & 1 deletion test/general/test_composite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ TEST(Interface, from_AnyMap_and_Solution)
auto& phase = root["phases"].getMapWhere("name", "Pt_surf");
auto surf = newInterface(phase, root, {gas});
ASSERT_EQ(gas.get(), surf->adjacent(0).get());
ASSERT_EQ(surf->kinetics()->nReactions(), 24);
ASSERT_EQ(surf->kinetics()->nReactions(), 24u);
}
Loading