Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
signaling_nan.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2018 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_signaling_nan_h
17 #define dealii_signaling_nan_h
18 
19 #include <deal.II/base/config.h>
20 
22 #include <deal.II/base/point.h>
24 #include <deal.II/base/tensor.h>
25 
26 #include <limits>
27 
28 
30 
31 namespace numbers
32 {
33  namespace internal
34  {
40  namespace SignalingNaN
41  {
49  template <typename T>
51 
52 
58  template <>
59  struct NaNInitializer<float>
60  {
61  static float
63  {
64  return std::numeric_limits<float>::signaling_NaN();
65  }
66  };
67 
68 
74  template <>
76  {
77  static double
79  {
80  return std::numeric_limits<double>::signaling_NaN();
81  }
82  };
83 
84 
90  template <int dim, typename T>
91  struct NaNInitializer<Tensor<1, dim, T>>
92  {
93  static Tensor<1, dim, T>
95  {
96  Tensor<1, dim, T> nan_tensor;
97 
98  for (unsigned int i = 0; i < dim; ++i)
99  nan_tensor[i] = NaNInitializer<T>::invalid_element();
100 
101  return nan_tensor;
102  }
103  };
104 
105 
106 
112  template <int rank, int dim, typename T>
113  struct NaNInitializer<Tensor<rank, dim, T>>
114  {
115  static Tensor<rank, dim, T>
117  {
118  Tensor<rank, dim, T> nan_tensor;
119 
120  // recursively initialize sub-tensors with invalid elements
121  for (unsigned int i = 0; i < dim; ++i)
122  nan_tensor[i] =
123  NaNInitializer<Tensor<rank - 1, dim, T>>::invalid_element();
124 
125  return nan_tensor;
126  }
127  };
128 
129 
130 
136  template <int dim, typename T>
137  struct NaNInitializer<Point<dim, T>>
138  {
139  static Point<dim, T>
141  {
142  Point<dim, T> nan_point;
143 
144  for (unsigned int i = 0; i < dim; ++i)
145  nan_point[i] = NaNInitializer<T>::invalid_element();
146 
147  return nan_point;
148  }
149  };
150 
151 
152 
158  template <int rank, int dim, typename T>
159  struct NaNInitializer<SymmetricTensor<rank, dim, T>>
160  {
163  {
164  // initialize symmetric tensors via the unrolled list of elements
165  T initializers
167  for (unsigned int i = 0;
168  i < SymmetricTensor<rank, dim, T>::n_independent_components;
169  ++i)
170  initializers[i] = NaNInitializer<T>::invalid_element();
171 
172  return SymmetricTensor<rank, dim, T>(initializers);
173  }
174  };
175 
176 
177 
183  template <int order, int dim, int spacedim, typename T>
184  struct NaNInitializer<DerivativeForm<order, dim, spacedim, T>>
185  {
188  {
190 
191  // recursively initialize sub-tensors with invalid elements
192  for (unsigned int i = 0; i < spacedim; ++i)
193  form[i] = NaNInitializer<Tensor<order, dim, T>>::invalid_element();
194 
195  return form;
196  }
197  };
198  } // namespace SignalingNaN
199  } // namespace internal
200 
201 
202 
227  template <class T>
228  T
230  {
231  // dispatch to the classes in the internal namespace because there
232  // we can do partial specializations, which is not possible for
233  // template functions such as the current one
235  }
236 } // namespace numbers
237 
238 
240 
241 #endif
derivative_form.h
numbers::internal::SignalingNaN::NaNInitializer< float >::invalid_element
static float invalid_element()
Definition: signaling_nan.h:62
SymmetricTensor
Definition: symmetric_tensor.h:611
DerivativeForm
Definition: derivative_form.h:60
LAPACKSupport::T
static const char T
Definition: lapack_support.h:163
tensor.h
double
Tensor
Definition: tensor.h:450
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
numbers::internal::SignalingNaN::NaNInitializer< DerivativeForm< order, dim, spacedim, T > >::invalid_element
static DerivativeForm< order, dim, spacedim, T > invalid_element()
Definition: signaling_nan.h:187
numbers::signaling_nan
T signaling_nan()
Definition: signaling_nan.h:229
numbers::internal::SignalingNaN::NaNInitializer< Point< dim, T > >::invalid_element
static Point< dim, T > invalid_element()
Definition: signaling_nan.h:140
numbers
Definition: numbers.h:207
numbers::internal::SignalingNaN::NaNInitializer< Tensor< rank, dim, T > >::invalid_element
static Tensor< rank, dim, T > invalid_element()
Definition: signaling_nan.h:116
symmetric_tensor.h
numbers::internal::SignalingNaN::NaNInitializer< SymmetricTensor< rank, dim, T > >::invalid_element
static SymmetricTensor< rank, dim, T > invalid_element()
Definition: signaling_nan.h:162
Point
Definition: point.h:111
numbers::internal::SignalingNaN::NaNInitializer< Tensor< 1, dim, T > >::invalid_element
static Tensor< 1, dim, T > invalid_element()
Definition: signaling_nan.h:94
config.h
internal
Definition: aligned_vector.h:369
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
numbers::internal::SignalingNaN::NaNInitializer< double >::invalid_element
static double invalid_element()
Definition: signaling_nan.h:78
numbers::internal::SignalingNaN::NaNInitializer
Definition: signaling_nan.h:50
point.h