Reference documentation for deal.II version GIT relicensing-214-g6e74dec06b 2024-03-27 18:10:01+00:00
\(\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\}}\)
Loading...
Searching...
No Matches
signaling_nan.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2015 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_signaling_nan_h
16#define dealii_signaling_nan_h
17
18#include <deal.II/base/config.h>
19
21#include <deal.II/base/point.h>
23#include <deal.II/base/tensor.h>
24
25#include <limits>
26
27
29
30namespace numbers
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
62 {
63 return std::numeric_limits<float>::signaling_NaN();
64 }
65 };
66
67
73 template <>
74 struct NaNInitializer<double>
75 {
76 static double
78 {
79 return std::numeric_limits<double>::signaling_NaN();
80 }
81 };
82
83
84 template <typename T, size_t width>
94
95
101 template <int dim, typename T>
102 struct NaNInitializer<Tensor<1, dim, T>>
103 {
104 static Tensor<1, dim, T>
106 {
107 Tensor<1, dim, T> nan_tensor;
108
109 for (unsigned int i = 0; i < dim; ++i)
110 nan_tensor[i] = NaNInitializer<T>::invalid_element();
111
112 return nan_tensor;
113 }
114 };
115
116
117
123 template <int rank, int dim, typename T>
124 struct NaNInitializer<Tensor<rank, dim, T>>
125 {
128 {
129 Tensor<rank, dim, T> nan_tensor;
130
131 // recursively initialize sub-tensors with invalid elements
132 for (unsigned int i = 0; i < dim; ++i)
133 nan_tensor[i] =
134 NaNInitializer<Tensor<rank - 1, dim, T>>::invalid_element();
135
136 return nan_tensor;
137 }
138 };
139
140
141
147 template <int dim, typename T>
148 struct NaNInitializer<Point<dim, T>>
149 {
150 static Point<dim, T>
152 {
153 Point<dim, T> nan_point;
154
155 for (unsigned int i = 0; i < dim; ++i)
156 nan_point[i] = NaNInitializer<T>::invalid_element();
157
158 return nan_point;
159 }
160 };
161
162
163
169 template <int rank, int dim, typename T>
170 struct NaNInitializer<SymmetricTensor<rank, dim, T>>
171 {
174 {
175 // initialize symmetric tensors via the unrolled list of elements
176 T initializers
178 for (unsigned int i = 0;
179 i < SymmetricTensor<rank, dim, T>::n_independent_components;
180 ++i)
181 initializers[i] = NaNInitializer<T>::invalid_element();
182
183 return SymmetricTensor<rank, dim, T>(initializers);
184 }
185 };
186
187
188
194 template <int order, int dim, int spacedim, typename T>
195 struct NaNInitializer<DerivativeForm<order, dim, spacedim, T>>
196 {
199 {
201
202 // recursively initialize sub-tensors with invalid elements
203 for (unsigned int i = 0; i < spacedim; ++i)
204 form[i] = NaNInitializer<Tensor<order, dim, T>>::invalid_element();
205
206 return form;
207 }
208 };
209 } // namespace SignalingNaN
210 } // namespace internal
211
212
213
268 template <class T>
269 T
271 {
272 // dispatch to the classes in the internal namespace because there
273 // we can do partial specializations, which is not possible for
274 // template functions such as the current one
276 }
277} // namespace numbers
278
279
281
282#endif
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
T signaling_nan()