antioch-0.4.0
metaphysicl_utils.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 
27 #ifndef ANTIOCH_METAPHYSICL_UTILS_H
28 #define ANTIOCH_METAPHYSICL_UTILS_H
29 
30 #ifdef ANTIOCH_METAPROGRAMMING_H
31 # ifndef ANTIOCH_METAPHYSICL_UTILS_DECL_H
32 # error metaphysicl_utils_decl.h must be included before metaprogramming.h
33 # endif
34 #endif
35 
36 #include "antioch_config.h"
37 
38 #include <cstddef> // std::size_t
39 
40 #ifdef ANTIOCH_HAVE_METAPHYSICL
41 // Though the following implementations are all valid without
42 // <metaphysicl/numberarray.h>, successfully using them with
43 // MetaPhysicL types requires MetaPhysicL to be included first.
44 // Configure-time MetaPhysicL support enforces this constraint but
45 // header-only MetaPhysicL may be mixed with header-only Antioch
46 // without configure-time flags.
47 #include "metaphysicl/numberarray.h"
48 #else
49 // Forward declaration instead
50 namespace MetaPhysicL {
51 template <std::size_t size, typename T> class NumberArray;
52 }
53 #endif
54 
56 
57 // Specializations to match other Antioch workarounds
58 
59 namespace Antioch
60 {
61 
62 template <typename T>
63 inline
64 typename Antioch::enable_if_c<
65  is_metaphysicl<T>::value,
66  typename value_type<T>::type>::type
67 max (const T& in)
68 {
69  using std::max;
70 
71  typename value_type<T>::type maxval = in[0];
72  const std::size_t size = in.size();
73  for (std::size_t i = 1; i < size; ++i)
74  maxval = max(maxval, in[i]);
75 
76  return maxval;
77 }
78 
79 template <typename T>
80 inline
81 typename Antioch::enable_if_c<
82  is_metaphysicl<T>::value,
83  typename value_type<T>::type>::type
84 min (const T& in)
85 {
86  using std::min;
87 
88  typename value_type<T>::type minval = in[0];
89  const std::size_t size = in.size();
90  for (std::size_t i = 1; i < size; ++i)
91  minval = min(minval, in[i]);
92 
93  return minval;
94 }
95 
96 template <typename T>
97 struct has_size<T, typename Antioch::enable_if_c<is_metaphysicl<T>::value,void>::type>
98 {
99  static const bool value = true;
100 };
101 
102 template <typename T>
103 struct return_auto<T, typename Antioch::enable_if_c<is_metaphysicl<T>::value,void>::type>
104 {
105  static const bool value = true;
106 };
107 
108 template <typename T>
109 struct size_type<T, typename Antioch::enable_if_c<is_metaphysicl<T>::value,void>::type>
110 {
111  typedef std::size_t type;
112 };
113 
114 template <typename T>
115 struct value_type<T, typename Antioch::enable_if_c<is_metaphysicl<T>::value,void>::type>
116 {
117  typedef typename T::value_type type;
118 };
119 
120 template <typename T>
121 struct raw_value_type<T, typename Antioch::enable_if_c<is_metaphysicl<T>::value,void>::type>
122 {
124 };
125 
126 template <typename Tbool, typename Ttrue, typename Tfalse>
127 inline
128 typename Antioch::enable_if_c<
132  typename state_type<Ttrue>::type>::type
133 if_else(const Tbool& condition,
134  const Ttrue& if_true,
135  const Tfalse& if_false)
136 {
137  typename state_type<Ttrue>::type returnval;
138  antioch_assert_equal_to(condition.size(), if_true.size());
139  antioch_assert_equal_to(condition.size(), if_false.size());
140 
141  for (std::size_t i=0; i != condition.size(); ++i)
142  returnval[i] = condition[i] ? if_true[i] : if_false[i];
143 
144  return returnval;
145 }
146 
147 template <typename VectorT, typename UIntType>
148 inline
149 typename Antioch::enable_if_c<
150  is_metaphysicl<typename Antioch::value_type<VectorT>::type >::value &&
151  is_metaphysicl<UIntType>::value,
153 >::type
154 eval_index(const VectorT & vec, const UIntType & indexes)
155 {
156  typename Antioch::value_type<VectorT>::type returnval;
157 
158  for(typename Antioch::size_type<typename Antioch::value_type<VectorT>::type>::type i = 0;
159  i < indexes.size(); i++)
160  returnval[i] = vec[indexes[i]][i];
161 
162  return returnval;
163 }
164 
165 } // end namespace Antioch
166 
167 #endif // ANTIOCH_METAPHYSICL_UTILS_H
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
#define antioch_assert_equal_to(expr1, expr2)
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type min(const T &in)
Definition: eigen_utils.h:98
enable_if_c< is_eigen< typename value_type< VectorT >::type >::value, typename value_type< VectorT >::type >::type eval_index(const VectorT &vec, const _Matrix< _UIntT, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &index)
Definition: eigen_utils.h:268
max(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >
enable_if_c< is_eigen< T1 >::value &&is_eigen< T2 >::value, typename state_type< T1 >::type >::type if_else(const Condition &condition, const T1 &if_true, const T2 &if_false)
Definition: eigen_utils.h:250
The parameters are reduced parameters.
typename _Scalar int _Rows int _Cols int _Options int _MaxRows int _MaxCols inline min(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >

Generated on Thu Jul 7 2016 11:09:46 for antioch-0.4.0 by  doxygen 1.8.8