Skip to content

Commit

Permalink
Merge pull request #220 from roystgnr/cxx11_fixes
Browse files Browse the repository at this point in the history
C++11 fixes
  • Loading branch information
roystgnr authored Jul 7, 2016
2 parents 18f427d + d9a3e84 commit c0c5d0b
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 104 deletions.
29 changes: 7 additions & 22 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -156,29 +156,14 @@ AC_SUBST(antioch_optional_test_LIBS)


dnl--------------------------
dnl Even if no dependency needed it,
dnl C++11 makes our asserts nicer,
dnl so let's try and enable it.
dnl Basic C++11 support is now required for Antioch.
dnl We'll test separately for required dependencies of some of our
dnl optional features just in case the user's compiler doesn't have
dnl full support.
dnl--------------------------
AC_ARG_ENABLE(cxx11,
AC_HELP_STRING([--enable-cxx11],
[build with C++11 support]),
[case "${enableval}" in
yes) enablecxx11=yes ;;
no) enablecxx11=no ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-cxx11) ;;
esac],
[enablecxx11=optional])

if (test x$enablecxx11 = xyes); then
AX_CXX_COMPILE_STDCXX_11(noext, mandatory)
AX_CXX_AUTO_THIS(optional)
AX_CXX_STATIC_ASSERT(optional)
elif (test x$enablecxx11 = xoptional); then
AX_CXX_COMPILE_STDCXX_11(noext, optional)
AX_CXX_AUTO_THIS(optional)
AX_CXX_STATIC_ASSERT(optional)
fi
AX_CXX_COMPILE_STDCXX_11(noext, mandatory)
AX_CXX_AUTO_THIS(optional)
AX_CXX_STATIC_ASSERT(optional)


dnl--------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/kinetics/include/antioch/kinetics_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace Antioch
// opposite directions to the same rate, then NaN is the
// correct output, and hopefully our user code has some way to
// recover from that.
// antioch_assert(!isnan(rate));
// antioch_assert(!has_nan(rate));

// reactant contributions
for (unsigned int r = 0; r < reaction.n_reactants(); r++)
Expand Down
19 changes: 10 additions & 9 deletions src/kinetics/include/antioch/reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@
#include "antioch/kinetics_parsing.h" // reset_parameter_of_rate

//C++
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

namespace Antioch
{
Expand Down Expand Up @@ -788,7 +789,7 @@ namespace Antioch
h_RT_minus_s_R[_product_ids[s]] );
}

antioch_assert(!isnan(exppower));
antioch_assert(!has_nan(exppower));

return ant_pow( P0_RT, static_cast<CoeffType>(this->gamma()) ) * ant_exp(exppower);
}
Expand Down Expand Up @@ -1041,7 +1042,7 @@ namespace Antioch
using std::abs;

StateType kfwd = this->compute_forward_rate_coefficient(molar_densities,conditions);
antioch_assert(!isnan(kfwd));
antioch_assert(!has_nan(kfwd));

StateType kfwd_times_reactants = kfwd;

Expand All @@ -1052,12 +1053,12 @@ namespace Antioch
ant_pow( molar_densities[this->reactant_id(ro)],
this->reactant_partial_order(ro));
}
antioch_assert(!isnan(kfwd_times_reactants));
antioch_assert(!has_nan(kfwd_times_reactants));

if(_reversible)
{
StateType Keq = this->equilibrium_constant( P0_RT, h_RT_minus_s_R );
antioch_assert(!isnan(Keq));
antioch_assert(!has_nan(Keq));

StateType kbkwd_times_products = kfwd/Keq;

Expand All @@ -1076,7 +1077,7 @@ namespace Antioch
kbkwd_times_products =
Antioch::if_else(is_nonzero, kbkwd_times_products,
Antioch::constant_clone(Keq, this->_max_rate));
antioch_assert(!isnan(kbkwd_times_products));
antioch_assert(!has_nan(kbkwd_times_products));

return kfwd_times_reactants - kbkwd_times_products;
}
Expand Down Expand Up @@ -1261,13 +1262,13 @@ namespace Antioch
kbkwd_times_products =
Antioch::if_else(is_nonzero, kbkwd_times_products,
Antioch::constant_clone(keq, this->_max_rate));
antioch_assert(!isnan(kbkwd_times_products));
antioch_assert(!has_nan(kbkwd_times_products));

// If our rate is maxed out then our derivatives are zero.
dRbkwd_dT =
Antioch::if_else(is_nonzero, dRbkwd_dT,
Antioch::zero_clone(keq));
antioch_assert(!isnan(dRbkwd_dT));
antioch_assert(!has_nan(dRbkwd_dT));

for (unsigned int s = 0; s < this->n_species(); s++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/include/antioch/eigen_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ template <typename T>
inline
typename Antioch::enable_if_c<is_eigen<T>::value,
bool>::type
isnan(const T& in)
has_nan(const T& in)
{
using std::isnan;

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/include/antioch/eigen_utils_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ template <typename T>
inline
typename Antioch::enable_if_c<is_eigen<T>::value,
bool>::type
isnan(const T& in);
has_nan(const T& in);


template <
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/include/antioch/metaphysicl_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ inline
typename Antioch::enable_if_c<
is_metaphysicl<T>::value,
bool>::type
isnan (const T& in)
has_nan (const T& in)
{
using std::isnan;

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/include/antioch/metaphysicl_utils_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ inline
typename Antioch::enable_if_c<
is_metaphysicl<T>::value,
bool>::type
isnan (const T& in);
has_nan (const T& in);

template <typename T>
struct has_size<T, typename Antioch::enable_if_c<is_metaphysicl<T>::value,void>::type>;
Expand Down
64 changes: 0 additions & 64 deletions src/utilities/include/antioch/metaprogramming.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,70 +35,6 @@

namespace Antioch
{
#define ANTIOCH_PLAIN_SCALAR(Type) \
\
inline \
Type \
max (const Type& in) { return in; } \
\
inline \
Type \
min (const Type& in) { return in; } \
\
template <> \
inline \
Type if_else(bool condition, \
Type if_true, \
Type if_false) \
{ \
if (condition) \
return if_true; \
else \
return if_false; \
} \
\
template <> \
struct has_size<Type> \
{ \
const static bool value = false; \
}; \
\
template <> \
struct return_auto<Type> \
{ \
const static bool value = false; \
}; \
\
template <> \
struct value_type<Type> \
{ \
typedef Type type; \
}; \
\
template <> \
struct raw_value_type<Type> \
{ \
typedef Type type; \
}; \
\
template <typename NewScalar> \
struct rebind<Type, NewScalar> \
{ \
typedef NewScalar type; \
}


ANTIOCH_PLAIN_SCALAR(float);
ANTIOCH_PLAIN_SCALAR(double);
ANTIOCH_PLAIN_SCALAR(long double);
ANTIOCH_PLAIN_SCALAR(bool);
ANTIOCH_PLAIN_SCALAR(short);
ANTIOCH_PLAIN_SCALAR(int);
ANTIOCH_PLAIN_SCALAR(long);
ANTIOCH_PLAIN_SCALAR(unsigned short);
ANTIOCH_PLAIN_SCALAR(unsigned int);
ANTIOCH_PLAIN_SCALAR(unsigned long);

template <typename T>
inline
void set_zero(T& output) { output = 0; }
Expand Down
75 changes: 75 additions & 0 deletions src/utilities/include/antioch/metaprogramming_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#ifndef ANTIOCH_METAPROGRAMMING_DECL_H
#define ANTIOCH_METAPROGRAMMING_DECL_H

// C++
#include <cmath> // For isnan

namespace Antioch
{
// A workaround for trying to use commas in arguments to macros
Expand Down Expand Up @@ -254,6 +257,78 @@ namespace Antioch
inline
bool disjunction(const T & vec);

#define ANTIOCH_PLAIN_SCALAR(Type) \
\
inline \
Type \
max (const Type& in) { return in; } \
\
inline \
Type \
min (const Type& in) { return in; } \
\
inline \
bool \
has_nan (const Type & in) \
{ \
using std::isnan; \
\
return isnan(in); \
} \
\
template <> \
inline \
Type if_else(bool condition, \
Type if_true, \
Type if_false) \
{ \
if (condition) \
return if_true; \
else \
return if_false; \
} \
\
template <> \
struct has_size<Type> \
{ \
const static bool value = false; \
}; \
\
template <> \
struct return_auto<Type> \
{ \
const static bool value = false; \
}; \
\
template <> \
struct value_type<Type> \
{ \
typedef Type type; \
}; \
\
template <> \
struct raw_value_type<Type> \
{ \
typedef Type type; \
}; \
\
template <typename NewScalar> \
struct rebind<Type, NewScalar> \
{ \
typedef NewScalar type; \
}

ANTIOCH_PLAIN_SCALAR(float);
ANTIOCH_PLAIN_SCALAR(double);
ANTIOCH_PLAIN_SCALAR(long double);
ANTIOCH_PLAIN_SCALAR(bool);
ANTIOCH_PLAIN_SCALAR(short);
ANTIOCH_PLAIN_SCALAR(int);
ANTIOCH_PLAIN_SCALAR(long);
ANTIOCH_PLAIN_SCALAR(unsigned short);
ANTIOCH_PLAIN_SCALAR(unsigned int);
ANTIOCH_PLAIN_SCALAR(unsigned long);

} // end namespace Antioch

#endif //ANTIOCH_METAPROGRAMMING_DECL_H
2 changes: 1 addition & 1 deletion src/utilities/include/antioch/valarray_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ eval_index(const VectorT& vec, const std::valarray<unsigned int>& index)
template <typename T>
inline
bool
isnan (const std::valarray<T>& in)
has_nan (const std::valarray<T>& in)
{
using std::isnan;

Expand Down
2 changes: 1 addition & 1 deletion src/utilities/include/antioch/valarray_utils_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct valarray_library_tag : public numeric_library_tag {};
template <typename T>
inline
bool
isnan (const std::valarray<T>& in);
has_nan (const std::valarray<T>& in);

}

Expand Down
3 changes: 1 addition & 2 deletions test/kinetics_unit.C
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ int tester(const std::string& input_name, Scalar max_reaction_rate, const std::s
{
using std::abs;
using std::isfinite;
using std::isnan;

std::vector<std::string> species_str_list;
const unsigned int n_species = 5;
Expand Down Expand Up @@ -205,7 +204,7 @@ int tester(const std::string& input_name, Scalar max_reaction_rate, const std::s
// reactions are allowed to be infinite unless user-limited,
// but in this test case we don't have any competing
// ridiculously-stiff reactions so we shouldn't get a NaN.
if (isnan(omega_dot[s]))
if (Antioch::has_nan(omega_dot[s]))
{
return_flag = 1;
std::cerr << "Error: omega_dot(" << chem_mixture.chemical_species()[s]->species()
Expand Down

0 comments on commit c0c5d0b

Please sign in to comment.