Fix all the warnings in MSVC

This commit is contained in:
Ian Bell
2025-05-18 14:55:21 -04:00
parent fc777c4164
commit ddda253504
7 changed files with 46 additions and 48 deletions

View File

@@ -322,7 +322,7 @@ list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/externals/fmtlib"
if (MSVC)
# fmtlib requires that the utf-8 support be compiled in
# TODO: add the fmt target from fmtlib directly which does this
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 -D_CRT_SECURE_NO_WARNINGS")
endif()
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
list(APPEND APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src")

View File

@@ -1,7 +1,6 @@
#ifndef COOLPROP_CONFIGURATION
#define COOLPROP_CONFIGURATION
#define _CRT_SECURE_NO_WARNINGS
#include "Exceptions.h"
#include "CoolPropTools.h"
#include <cstdlib>

View File

@@ -21,7 +21,7 @@ class FuncWrapper1D
std::string errstring;
Dictionary options;
int iter;
FuncWrapper1D() : errcode(0), errstring(""){};
FuncWrapper1D() : errcode(0), errstring(""), iter(0) {};
virtual ~FuncWrapper1D(){};
virtual double call(double) = 0;
/**

View File

@@ -154,7 +154,7 @@ void add_fluids_as_JSON(const std::string& JSON) {
} else {
try {
library.add_many(dd);
} catch (std::exception& e) {
} catch (std::exception& /* e */) {
throw ValueError(format("Unable to load cubics library with error: %s", errstr.c_str()));
}
}

View File

@@ -35,7 +35,7 @@ void UNIFAC::UNIFACMixture::set_interaction_parameter(const std::size_t mgi1, co
}
}
double UNIFAC::UNIFACMixture::get_interaction_parameter(const std::size_t mgi1, const std::size_t mgi2, const std::string& parameter) {
std::map<std::pair<int, int>, UNIFACLibrary::InteractionParameters>::iterator it = this->interaction.find(std::pair<int, int>(mgi1, mgi2));
std::map<std::pair<int, int>, UNIFACLibrary::InteractionParameters>::iterator it = this->interaction.find(std::pair<int, int>(static_cast<int>(mgi1), static_cast<int>(mgi2)));
if (it == this->interaction.end()) {
throw CoolProp::ValueError(format("Unable to match mgi-mgi pair: [%d,%d]", static_cast<int>(mgi1), static_cast<int>(mgi1)));
} else {

View File

@@ -437,12 +437,12 @@ CoolPropDbl PCSAFTBackend::calc_alphar(void) {
// these indices are necessary because we are only using 1D vectors
vector<double> XA (num_sites, 0);
vector<double> delta_ij(num_sites * num_sites, 0);
auto idxa = 0UL;
auto idxi = 0UL; // index for the ii-th compound
auto idxj = 0UL; // index for the jj-th compound
for (auto i = 0UL; i < num_sites; i++) {
auto idxa = 0ULL;
auto idxi = 0ULL; // index for the ii-th compound
auto idxj = 0ULL; // index for the jj-th compound
for (auto i = 0; i < num_sites; i++) {
idxi = iA[i]*ncomp+iA[i];
for (int j = 0UL; j < num_sites; j++) {
for (int j = 0; j < num_sites; j++) {
idxj = iA[j]*ncomp+iA[j];
if (assoc_matrix[idxa] != 0) {
double eABij = (components[iA[i]].getUAB()+components[iA[j]].getUAB())/2.;
@@ -754,12 +754,12 @@ CoolPropDbl PCSAFTBackend::calc_dadt(void) {
vector<double> XA (num_sites, 0);
vector<double> delta_ij(num_sites * num_sites, 0);
vector<double> ddelta_dt(num_sites * num_sites, 0);
auto idxa = 0UL;
auto idxi = 0UL; // index for the ii-th compound
auto idxj = 0UL; // index for the jj-th compound
for (auto i = 0UL; i < num_sites; i++) {
std::size_t idxa = 0UL;
std::size_t idxi = 0UL; // index for the ii-th compound
std::size_t idxj = 0UL; // index for the jj-th compound
for (auto i = 0; i < num_sites; i++) {
idxi = iA[i]*ncomp+iA[i];
for (auto j = 0UL; j < num_sites; j++) {
for (auto j = 0; j < num_sites; j++) {
idxj = iA[j]*ncomp+iA[j];
if (assoc_matrix[idxa] != 0) {
double eABij = (components[iA[i]].getUAB()+components[iA[j]].getUAB())/2.;
@@ -1211,12 +1211,12 @@ vector<CoolPropDbl> PCSAFTBackend::calc_fugacity_coefficients(void) {
// these indices are necessary because we are only using 1D vectors
vector<double> XA (num_sites, 0);
vector<double> delta_ij(num_sites * num_sites, 0);
auto idxa = 0UL;
auto idxi = 0UL; // index for the ii-th compound
auto idxj = 0UL; // index for the jj-th compound
for (auto i = 0UL; i < num_sites; i++) {
std::size_t idxa = 0UL;
std::size_t idxi = 0UL; // index for the ii-th compound
std::size_t idxj = 0UL; // index for the jj-th compound
for (auto i = 0UL; i < static_cast<std::size_t>(num_sites); i++) {
idxi = iA[i]*ncomp+iA[i];
for (auto j = 0UL; j < num_sites; j++) {
for (auto j = 0UL; j < static_cast<std::size_t>(num_sites); j++) {
idxj = iA[j]*ncomp+iA[j];
if (assoc_matrix[idxa] != 0) {
double eABij = (components[iA[i]].getUAB()+components[iA[j]].getUAB())/2.;
@@ -1235,12 +1235,12 @@ vector<CoolPropDbl> PCSAFTBackend::calc_fugacity_coefficients(void) {
vector<double> ddelta_dx(num_sites * num_sites * ncomp, 0);
int idx_ddelta = 0;
for (int k = 0; k < ncomp; k++) {
auto idxi = 0UL; // index for the ii-th compound
auto idxj = 0UL; // index for the jj-th compound
std::size_t idxi = 0UL; // index for the ii-th compound
std::size_t idxj = 0UL; // index for the jj-th compound
idxa = 0;
for (auto i = 0UL; i < num_sites; i++) {
for (auto i = 0UL; i < static_cast<std::size_t>(num_sites); i++) {
idxi = iA[i]*ncomp+iA[i];
for (auto j = 0UL; j < num_sites; j++) {
for (auto j = 0UL; j < static_cast<std::size_t>(num_sites); j++) {
idxj = iA[j]*ncomp+iA[j];
if (assoc_matrix[idxa] != 0) {
double eABij = (components[iA[i]].getUAB()+components[iA[j]].getUAB())/2.;
@@ -1565,12 +1565,12 @@ CoolPropDbl PCSAFTBackend::calc_compressibility_factor(void) {
// these indices are necessary because we are only using 1D vectors
vector<double> XA (num_sites, 0);
vector<double> delta_ij(num_sites * num_sites, 0);
auto idxa = 0UL;
auto idxi = 0UL; // index for the ii-th compound
auto idxj = 0UL; // index for the jj-th compound
for (auto i = 0UL; i < num_sites; i++) {
std::size_t idxa = 0UL;
std::size_t idxi = 0UL; // index for the ii-th compound
std::size_t idxj = 0UL; // index for the jj-th compound
for (auto i = 0UL; i < static_cast<std::size_t>(num_sites); i++) {
idxi = iA[i]*ncomp+iA[i];
for (auto j = 0UL; j < num_sites; j++) {
for (auto j = 0UL; j < static_cast<std::size_t>(num_sites); j++) {
idxj = iA[j]*ncomp+iA[j];
if (assoc_matrix[idxa] != 0) {
double eABij = (components[iA[i]].getUAB()+components[iA[j]].getUAB())/2.;
@@ -1589,12 +1589,12 @@ CoolPropDbl PCSAFTBackend::calc_compressibility_factor(void) {
vector<double> ddelta_dx(num_sites * num_sites * ncomp, 0);
int idx_ddelta = 0;
for (int k = 0; k < ncomp; k++) {
auto idxi = 0UL; // index for the ii-th compound
auto idxj = 0UL; // index for the jj-th compound
std::size_t idxi = 0UL; // index for the ii-th compound
std::size_t idxj = 0UL; // index for the jj-th compound
idxa = 0;
for (auto i = 0UL; i < num_sites; i++) {
for (auto i = 0UL; i < static_cast<std::size_t>(num_sites); i++) {
idxi = iA[i]*ncomp+iA[i];
for (auto j = 0UL; j < num_sites; j++) {
for (auto j = 0UL; j < static_cast<std::size_t>(num_sites); j++) {
idxj = iA[j]*ncomp+iA[j];
if (assoc_matrix[idxa] != 0) {
double eABij = (components[iA[i]].getUAB()+components[iA[j]].getUAB())/2.;
@@ -1874,8 +1874,7 @@ phases PCSAFTBackend::calc_phase_internal(CoolProp::input_pairs input_pair) {
SatL->_T = _T; SatV->_T = _T;
try {
flash_QT(*this);
}
catch (const SolutionError& ex) {
} catch (const SolutionError& /* ex */) {
phase = iphase_supercritical;
break;
}
@@ -1916,7 +1915,7 @@ phases PCSAFTBackend::calc_phase_internal(CoolProp::input_pairs input_pair) {
SatV->_T = _T;
try {
flash_QT(*this);
} catch (const SolutionError& ex) {
} catch (const SolutionError& /* ex */) {
phase = iphase_supercritical;
break;
}
@@ -1964,9 +1963,9 @@ void PCSAFTBackend::flash_QT(PCSAFTBackend &PCSAFT) {
p_guess = estimate_flash_p(PCSAFT);
p = outerTQ(p_guess, PCSAFT);
solution_found = true;
} catch (const SolutionError& /* ex */) {
} catch (const ValueError& /* ex */) {
}
catch (const SolutionError& ex) {}
catch (const ValueError& ex) {}
// if solution hasn't been found, try cycling through a range of pressures
if (!solution_found) {
@@ -1978,9 +1977,9 @@ void PCSAFTBackend::flash_QT(PCSAFTBackend &PCSAFT) {
try {
p = outerTQ(pow(10, p_guess), PCSAFT);
solution_found = true;
} catch (const SolutionError& ex) {
} catch (const SolutionError& /* ex */) {
p_guess += p_step;
} catch (const ValueError& ex) {
} catch (const ValueError& /* ex */) {
p_guess += p_step;
}
}
@@ -2005,9 +2004,9 @@ void PCSAFTBackend::flash_PQ(PCSAFTBackend &PCSAFT) {
t_guess = estimate_flash_t(PCSAFT);
t = outerPQ(t_guess, PCSAFT);
solution_found = true;
} catch (const SolutionError& /* ex */) {
} catch (const ValueError& /* ex */) {
}
catch (const SolutionError& ex) {}
catch (const ValueError& ex) {}
// if solution hasn't been found, try calling the flash function directly with a range of initial temperatures
if (!solution_found) {
@@ -2023,9 +2022,9 @@ void PCSAFTBackend::flash_PQ(PCSAFTBackend &PCSAFT) {
try {
t = outerPQ(t_guess, PCSAFT);
solution_found = true;
} catch (const SolutionError& ex) {
} catch (const SolutionError& /* ex */) {
t_guess -= t_step;
} catch (const ValueError& ex) {
} catch (const ValueError& /* ex */) {
t_guess -= t_step;
}
}
@@ -2046,7 +2045,7 @@ double PCSAFTBackend::outerPQ(double t_guess, PCSAFTBackend &PCSAFT) {
// Based on the algorithm proposed in H. A. J. Watson, M. Vikse, T. Gundersen, and P. I. Barton, “Reliable Flash Calculations: Part 1. Nonsmooth Inside-Out Algorithms,” Ind. Eng. Chem. Res., vol. 56, no. 4, pp. 960973, Feb. 2017, doi: 10.1021/acs.iecr.6b03956.
auto ncomp = N; // number of components
double TOL = 1e-8;
double MAXITER = 200;
int MAXITER = 200;
// Define the residual to be driven to zero
class SolverInnerResid : public FuncWrapper1D
@@ -2308,7 +2307,7 @@ double PCSAFTBackend::outerTQ(double p_guess, PCSAFTBackend &PCSAFT) {
// Based on the algorithm proposed in H. A. J. Watson, M. Vikse, T. Gundersen, and P. I. Barton, “Reliable Flash Calculations: Part 1. Nonsmooth Inside-Out Algorithms,” Ind. Eng. Chem. Res., vol. 56, no. 4, pp. 960973, Feb. 2017, doi: 10.1021/acs.iecr.6b03956.
auto ncomp = N; // number of components
double TOL = 1e-8;
double MAXITER = 200;
int MAXITER = 200;
// Define the residual to be driven to zero
class SolverInnerResid : public FuncWrapper1D
@@ -2590,7 +2589,7 @@ double PCSAFTBackend::estimate_flash_t(PCSAFTBackend &PCSAFT) {
double intercept = std::log10(p1) - slope * (1/t);
t_guess = slope / (std::log10(PCSAFT._p) - intercept);
guess_found = true;
} catch (const SolutionError& ex) {
} catch (const SolutionError& /* ex */) {
t_start -= t_step;
}
}

View File

@@ -403,7 +403,7 @@ static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess)
if (!ValidNumber(T)) {
throw CoolProp::ValueError("Intermediate value for Tdb is invalid");
}
} catch (std::exception& e) {
} catch (std::exception& /* e */) {
T = CoolProp::Brent(Resids, 100, 640, 1e-15, 1e-10, 100);
}