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_METAPROGRAMMING_H
28 #define ANTIOCH_METAPROGRAMMING_H
29
30 // Antioch
31 #include "antioch/metaprogramming_decl.h"
32
33 // C++
34 #include <cstddef> // For size_t
35
36 namespace Antioch
37 {
38 template <typename T>
39 inline
set_zero(T & output)40 void set_zero(T& output) { output = 0; }
41
42 template <typename T>
43 inline
zero_clone(const T &)44 T zero_clone(const T& /* example */) { return 0; }
45
46 template <typename T, typename T2>
47 inline
zero_clone(T & output,const T2 &)48 void zero_clone(T& output, const T2& /* example */) { output = 0; }
49
50 template <typename T>
51 inline
init_clone(T & output,const T & example)52 void init_clone(T& output, const T& example) { output = example; }
53
54 template <typename Vector, typename Scalar>
55 inline
init_constant(Vector & output,const Scalar & example)56 void init_constant(Vector& output, const Scalar& example)
57 {
58 for (typename Antioch::size_type<Vector>::type i=0;
59 i != output.size(); ++i)
60 init_clone(output[i], example);
61 }
62
63 template <typename T, typename Scalar>
64 inline
constant_clone(const T &,const Scalar & value)65 T constant_clone(const T& /* example */, const Scalar& value) { return value; }
66
67 template <typename T, typename Scalar>
68 inline
constant_fill(T & output,const Scalar & value)69 void constant_fill(T& output, const Scalar& value) { output = value; }
70
71 template <typename T, typename VectorScalar>
72 inline
custom_clone(const T &,const VectorScalar & values,unsigned int indexes)73 T custom_clone(const T& /*example*/, const VectorScalar& values, unsigned int indexes) {return values[indexes];}
74
75 template <typename T, typename VectorScalar>
76 inline
custom_clone(const T &,const VectorScalar & values,const typename Antioch::rebind<T,unsigned int>::type & indexes)77 T custom_clone(const T& /*example*/, const VectorScalar& values, const typename Antioch::rebind<T,unsigned int>::type & indexes)
78 {
79 T returnval(indexes.size()); //bof bof - metaphysicl has size within type, this suppose that size_type<indexes>::type can be changed in value_type<T>::type
80
81 for(unsigned int i = 0; i < indexes.size(); i++)
82 {
83 returnval[i] = values[indexes[i]];
84 }
85 return returnval;
86 }
87
88
89 template <typename VectorT>
90 inline
91 typename value_type<VectorT>::type
eval_index(const VectorT & vec,unsigned int index)92 eval_index(const VectorT& vec, unsigned int index)
93 {
94 return vec[index];
95 }
96
97 inline
conjunction(const bool & vec)98 bool conjunction(const bool & vec)
99 {
100 return vec;
101 }
102
103 template <typename T>
104 inline
conjunction(const T & vec)105 bool conjunction(const T & vec)
106 {
107 typedef typename tag_type<T>::type tag;
108 return conjunction_root(vec,tag());
109 }
110
111 template <typename T>
112 inline
conjunction_root(const T & vec,numeric_library_tag)113 bool conjunction_root(const T & vec, numeric_library_tag)
114 {
115 for(unsigned int i = 0; i < vec.size(); i++)
116 {
117 if(!vec[i])return false;
118 }
119 return true;
120 }
121
122 inline
disjunction(const bool & vec)123 bool disjunction(const bool & vec)
124 {
125 return vec;
126 }
127
128 template <typename T>
129 inline
disjunction(const T & vec)130 bool disjunction(const T & vec)
131 {
132 typedef typename tag_type<T>::type tag;
133 return disjunction_root(vec,tag());
134 }
135
136 template <typename T>
137 inline
disjunction_root(const T & vec,numeric_library_tag)138 bool disjunction_root(const T & vec, numeric_library_tag)
139 {
140 for(unsigned int i = 0; i < vec.size(); i++)
141 {
142 if(vec[i])return true;
143 }
144 return false;
145 }
146
147 } // end namespace Antioch
148
149 #endif //ANTIOCH_METAPROGRAMMING_H
150