Reference documentation for deal.II version Git f40be01994 2020-04-09 07:13:12 +0200
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
signaling_nan.h
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 
21 #include <deal.II/base/derivative_form.h>
22 #include <deal.II/base/point.h>
24 #include <deal.II/base/tensor.h>
25 
26 #include <limits>
27 
28 
29 DEAL_II_NAMESPACE_OPEN
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
62  invalid_element()
63  {
64  return std::numeric_limits<float>::signaling_NaN();
65  }
66  };
67 
68 
74  template <>
75  struct NaNInitializer<double>
76  {
77  static double
78  invalid_element()
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>
94  invalid_element()
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>
116  invalid_element()
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>
140  invalid_element()
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  {
162  invalid_element()
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  {
187  invalid_element()
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 
239 DEAL_II_NAMESPACE_CLOSE
240 
241 #endif
Definition: point.h:111
Definition: tensor.h:417
T signaling_nan()