* <code>long double</code>.
*/
bool is_finite (const std::complex<long double> x);
+
+ /**
+ * A structure that, together with its
+ * partial specializations, provides traits
+ * and member functions that make it
+ * possible to write templates that work on
+ * both real number types and complex
+ * number types. This template is mostly
+ * used to implement linear algebra classes
+ * such as vectors and matrices that work
+ * for both real and complex numbers.
+ *
+ * @author Wolfgang Bangerth, 2007
+ */
+ template <typename number>
+ struct NumberTraits
+ {
+ /**
+ * For this data type, typedef the
+ * corresponding real type. Since the
+ * general template is selected for all
+ * data types that are not
+ * specializations of std::complex<T>,
+ * the underlying type must be
+ * real-values, so the real_type is
+ * equal to the underlying type.
+ */
+ typedef number real_type;
+
+ /**
+ * Return the complex-conjugate of the
+ * given number. Since the general
+ * template is selected if number is
+ * not a complex data type, this
+ * function simply returns the given
+ * number.
+ */
+ static
+ const number & conjugate (const number &x);
+
+ /**
+ * Return the square of the absolute
+ * value of the given number. Since the
+ * general template is chosen for types
+ * not equal to std::complex, this
+ * function simply returns the square
+ * of the given number.
+ */
+ static
+ real_type abs_square (const number &x);
+ };
+
+
+ /**
+ * Specialization of the general
+ * NumberTraits class that provides the
+ * relevant information if the underlying
+ * data type is std::complex<T>.
+ *
+ * @author Wolfgang Bangerth, 2007
+ */
+ template <typename number>
+ struct NumberTraits<std::complex<number> >
+ {
+ /**
+ * For this data type, typedef the
+ * corresponding real type. Since this
+ * specialization of the template is
+ * selected for number types
+ * std::complex<T>, the real type is
+ * equal to the type used to store the
+ * two components of the complex
+ * number.
+ */
+ typedef number real_type;
+
+ /**
+ * Return the complex-conjugate of the
+ * given number.
+ */
+ static
+ std::complex<number> conjugate (const std::complex<number> &x);
+
+ /**
+ * Return the square of the absolute
+ * value of the given number. Since
+ * this specialization of the general
+ * template is chosen for types equal
+ * to std::complex, this function
+ * returns the product of a number and
+ * its complex conjugate.
+ */
+ static
+ real_type abs_square (const std::complex<number> &x);
+ };
+
}
namespace deal_II_numbers = numbers;
+/* --------------- inline and template functions ---------------- */
+namespace numbers
+{
+ template <typename number>
+ const number &
+ NumberTraits<number>::conjugate (const number &x)
+ {
+ return x;
+ }
+
+
+
+ template <typename number>
+ typename NumberTraits<number>::real_type
+ NumberTraits<number>::abs_square (const number &x)
+ {
+ return x * x;
+ }
+
+
+
+ template <typename number>
+ std::complex<number>
+ NumberTraits<std::complex<number> >::conjugate (const std::complex<number> &x)
+ {
+ return std::conj(x);
+ }
+
+
+
+ template <typename number>
+ typename NumberTraits<std::complex<number> >::real_type
+ NumberTraits<std::complex<number> >::abs_square (const std::complex<number> &x)
+ {
+ return std::norm (x);
+ }
+
+}
+
+
DEAL_II_NAMESPACE_CLOSE
<h3>base</h3>
<ol>
+ <li> <p>New: There is now a template numbers::NumberTraits that provides
+ the means to implement linear algebra and other algorithms for both real
+ and complex data types.
+ <br>
+ (WB 2007/11/03)
+ </p> </li>
<li> <p>New: The DataOutBase class and derived classes can now deal with data that is
logically vector-valued, i.e. derived classes can pass down information that some of
functions_* \
function_parser \
utilities_* \
- is_finite
+ is_finite \
+ number_traits_*
ifeq ($(enable-multithreading),no)
tests_x += threads
--- /dev/null
+//---------------------------- number_traits_complex.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2005, 2006, 2007 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- number_traits_complex.cc ---------------------------
+
+// check numbers::NumberTraits for real data types
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+#include <limits>
+#include <typeinfo>
+
+
+template <typename number>
+void check (const number &x)
+{
+ deallog << "typeid(x).name() = " << typeid(x).name()
+ << std::endl;
+
+ deallog << "typeid(NumberTraits<number>::real_type).name() = "
+ << typeid(typename numbers::NumberTraits<number>::real_type).name()
+ << std::endl;
+
+ deallog << numbers::NumberTraits<number>::conjugate (x)
+ << std::endl;
+
+ deallog << numbers::NumberTraits<number>::abs_square (x)
+ << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("number_traits_complex/output");
+ logfile.precision(3);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ check (std::complex<float>(1.5, 2.5));
+ check (std::complex<float>(-1.5, -2.5));
+
+ check (std::complex<double>(1.5, 2.5));
+ check (std::complex<double>(-1.5, -2.5));
+
+ check (std::complex<long double>(1.5, 2.5));
+ check (std::complex<long double>(-1.5, -2.5));
+
+ return 0;
+}
+
--- /dev/null
+
+DEAL::typeid(x).name() = St7complexIfE
+DEAL::typeid(NumberTraits<number>::real_type).name() = f
+DEAL::(1.50,-2.50)
+DEAL::8.50
+DEAL::typeid(x).name() = St7complexIfE
+DEAL::typeid(NumberTraits<number>::real_type).name() = f
+DEAL::(-1.50,2.50)
+DEAL::8.50
+DEAL::typeid(x).name() = St7complexIdE
+DEAL::typeid(NumberTraits<number>::real_type).name() = d
+DEAL::(1.50,-2.50)
+DEAL::8.50
+DEAL::typeid(x).name() = St7complexIdE
+DEAL::typeid(NumberTraits<number>::real_type).name() = d
+DEAL::(-1.50,2.50)
+DEAL::8.50
+DEAL::typeid(x).name() = St7complexIeE
+DEAL::typeid(NumberTraits<number>::real_type).name() = e
+DEAL::(1.50,-2.50)
+DEAL::8.50
+DEAL::typeid(x).name() = St7complexIeE
+DEAL::typeid(NumberTraits<number>::real_type).name() = e
+DEAL::(-1.50,2.50)
+DEAL::8.50
--- /dev/null
+//---------------------------- number_traits_real.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2005, 2006, 2007 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- number_traits_real.cc ---------------------------
+
+// check numbers::NumberTraits for real data types
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <fstream>
+#include <iostream>
+#include <limits>
+#include <typeinfo>
+
+
+template <typename number>
+void check (const number &x)
+{
+ deallog << "typeid(x).name() = " << typeid(x).name()
+ << std::endl;
+
+ deallog << "typeid(NumberTraits<number>::real_type).name() = "
+ << typeid(typename numbers::NumberTraits<number>::real_type).name()
+ << std::endl;
+
+ deallog << numbers::NumberTraits<number>::conjugate (x)
+ << std::endl;
+
+ deallog << numbers::NumberTraits<number>::abs_square (x)
+ << std::endl;
+}
+
+
+
+int main ()
+{
+ std::ofstream logfile("number_traits_real/output");
+ logfile.precision(3);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ check ((float)1.5);
+ check ((float)-1.5);
+
+ check ((double)1.5);
+ check ((double)-1.5);
+
+ check ((long double)1.5);
+ check ((long double)-1.5);
+
+ return 0;
+}
+
--- /dev/null
+
+DEAL::typeid(x).name() = f
+DEAL::typeid(NumberTraits<number>::real_type).name() = f
+DEAL::1.50
+DEAL::2.25
+DEAL::typeid(x).name() = f
+DEAL::typeid(NumberTraits<number>::real_type).name() = f
+DEAL::-1.50
+DEAL::2.25
+DEAL::typeid(x).name() = d
+DEAL::typeid(NumberTraits<number>::real_type).name() = d
+DEAL::1.50
+DEAL::2.25
+DEAL::typeid(x).name() = d
+DEAL::typeid(NumberTraits<number>::real_type).name() = d
+DEAL::-1.50
+DEAL::2.25
+DEAL::typeid(x).name() = e
+DEAL::typeid(NumberTraits<number>::real_type).name() = e
+DEAL::1.50
+DEAL::2.25
+DEAL::typeid(x).name() = e
+DEAL::typeid(NumberTraits<number>::real_type).name() = e
+DEAL::-1.50
+DEAL::2.25