Reference documentation for deal.II version 8.4.1
signaling_nan.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__signaling_nan_h
17 #define dealii__signaling_nan_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/tensor.h>
21 #include <deal.II/base/symmetric_tensor.h>
22 #include <deal.II/base/derivative_form.h>
23 
24 #include <limits>
25 
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 namespace numbers
30 {
31 
32  namespace internal
33  {
39  namespace SignalingNaN
40  {
48  template <typename T>
50 
51 
57  template <>
58  struct NaNInitializer<float>
59  {
60  static float invalid_element ()
61  {
62  return std::numeric_limits<float>::signaling_NaN();
63  }
64  };
65 
66 
72  template <>
73  struct NaNInitializer<double>
74  {
75  static double invalid_element ()
76  {
77  return std::numeric_limits<double>::signaling_NaN();
78  }
79  };
80 
81 
87  template <int dim, typename T>
88  struct NaNInitializer<Tensor<1,dim,T> >
89  {
90  static Tensor<1,dim,T> invalid_element ()
91  {
92  Tensor<1,dim,T> nan_tensor;
93 
94  for (unsigned int i=0; i<dim; ++i)
95  nan_tensor[i] = NaNInitializer<T>::invalid_element();
96 
97  return nan_tensor;
98  }
99  };
100 
101 
102 
108  template <int rank, int dim, typename T>
109  struct NaNInitializer<Tensor<rank,dim,T> >
110  {
111  static Tensor<rank,dim,T> invalid_element ()
112  {
113  Tensor<rank,dim,T> nan_tensor;
114 
115  // recursively initialize sub-tensors with invalid elements
116  for (unsigned int i=0; i<dim; ++i)
117  nan_tensor[i] = NaNInitializer<Tensor<rank-1,dim,T> >::invalid_element();
118 
119  return nan_tensor;
120  }
121  };
122 
123 
124 
130  template <int rank, int dim, typename T>
131  struct NaNInitializer<SymmetricTensor<rank,dim,T> >
132  {
133  static SymmetricTensor<rank,dim,T> invalid_element ()
134  {
135  // initialize symmetric tensors via the unrolled list of elements
137  for (unsigned int i=0; i<SymmetricTensor<rank,dim,T>::n_independent_components; ++i)
138  initializers[i] = NaNInitializer<T>::invalid_element();
139 
140  return SymmetricTensor<rank,dim,T>(initializers);
141  }
142  };
143 
144 
145 
151  template <int order, int dim, int spacedim, typename T>
152  struct NaNInitializer<DerivativeForm<order,dim,spacedim,T> >
153  {
154  static DerivativeForm<order,dim,spacedim,T> invalid_element ()
155  {
157 
158  // recursively initialize sub-tensors with invalid elements
159  for (unsigned int i=0; i<spacedim; ++i)
160  form[i] = NaNInitializer<Tensor<order,dim,T> >::invalid_element();
161 
162  return form;
163  }
164  };
165  }
166  }
167 
168 
169 
170 
195  template <class T>
196  T
198  {
199  // dispatch to the classes in the internal namespace because there
200  // we can do partial specializations, which is not possible for
201  // template functions such as the current one
203  }
204 }
205 
206 
207 DEAL_II_NAMESPACE_CLOSE
208 
209 #endif
Definition: mpi.h:48
T signaling_nan()