// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
+/**
+ * Compute the determinant of a tensor or rank 2, here for all dimensions for
+ * which no explicit specialization is available above.
+ *
+ * @relates Tensor
+ * @author Wolfgang Bangerth, 2009
+ */
+template <int dim>
+inline
+double determinant (const Tensor<2,dim> &t)
+{
+ // compute the determinant using the
+ // Laplace expansion of the
+ // determinant. this may not be the most
+ // efficient algorithm, but it does for
+ // small n.
+ //
+ // for some algorithmic simplicity, we use
+ // the expansion along the last row
+ double det = 0;
+
+ for (unsigned int k=0; k<dim; ++k)
+ {
+ Tensor<2,dim-1> minor;
+ for (unsigned int i=0; i<dim-1; ++i)
+ for (unsigned int j=0; j<dim-1; ++j)
+ minor[i][j] = t[i][j<k ? j : j+1];
+
+ const double cofactor = std::pow (-1, k+1) *
+ determinant (minor);
+
+ det += t[dim-1][k] * cofactor;
+ }
+
+ return std::pow (-1, dim) * det;
+}
+
+
+
/**
* Compute and return the trace of a tensor of rank 2, i.e. the sum of
* its diagonal entries.
--- /dev/null
+//---------------------------- full_tensor_10.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2005, 2009 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.
+//
+//---------------------------- full_tensor_10.cc ---------------------------
+
+// test the determinant code for n>3
+
+#include "../tests.h"
+#include <base/tensor.h>
+#include <base/logstream.h>
+#include <fstream>
+#include <iomanip>
+
+
+template <int dim>
+void test ()
+{
+ Tensor<2,dim> t;
+
+ // choose the same symmetric tensor
+ // as in symmetric_tensor_10
+ for (unsigned int i=0; i<dim; ++i)
+ for (unsigned int j=0; j<dim; ++j)
+ t[i][j] = 1. * rand() / RAND_MAX;
+
+ for (unsigned int i=0; i<dim; ++i)
+ for (unsigned int j=0; j<dim; ++j)
+ deallog << "A[" << i+1 << ',' << j+1 << "] := " << t[i][j] << ';'
+ << std::endl;
+
+ deallog << determinant(t) << std::endl;
+}
+
+
+
+
+int main ()
+{
+ std::ofstream logfile("full_tensor_10/output");
+ deallog << std::setprecision(3);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test<4> ();
+ test<5> ();
+ test<6> ();
+ test<7> ();
+ test<8> ();
+
+ deallog << "OK" << std::endl;
+}