From: wolf Date: Mon, 18 Jul 2005 19:00:43 +0000 (+0000) Subject: New test. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dea495fd9591e4878b2999eceb2d26de6932f803;p=dealii-svn.git New test. git-svn-id: https://svn.dealii.org/trunk@11162 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/base/symmetric_tensor_19.cc b/tests/base/symmetric_tensor_19.cc new file mode 100644 index 0000000000..76c295407e --- /dev/null +++ b/tests/base/symmetric_tensor_19.cc @@ -0,0 +1,134 @@ +//---------------------------- symmetric_tensor_19.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005 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. +// +//---------------------------- symmetric_tensor_19.cc --------------------------- + +// check inversion of rank-4 tensor + +#include "../tests.h" +#include +#include +#include +#include + + + + +template +void check (const SymmetricTensor<4,dim> &A) +{ + const SymmetricTensor<4,dim> B = invert (A); + + // check left inverse + deallog << " checking left inverse" << std::endl; + const SymmetricTensor<4,dim> T_left = B*A; + for (unsigned int i=0; i()[i][j][k][l]) + < 1e-10, + ExcInternalError()); + } + + // check left inverse + deallog << " checking right inverse" << std::endl; + const SymmetricTensor<4,dim> T_right = A*B; + for (unsigned int i=0; i()[i][j][k][l]) + < 1e-10, + ExcInternalError()); + } +} + + + +template +void test () +{ + deallog << "dim=" << dim << std::endl; + + deallog << " unit tensor" << std::endl; + check (identity_tensor()); + + // do something with a more complicated + // tensor. make sure it is not + // rank-deficient, so choose elements by + // hand + deallog << " complicated tensor" << std::endl; + SymmetricTensor<4,dim> A; + switch (dim) + { + case 1: + A[0][0][0][0] = 2; + break; + + case 2: + A[0][0][0][0] = 2; + A[0][0][1][1] = 4; + A[0][0][0][1] = 8; + A[1][1][0][0] = 4; + A[1][1][1][1] = 6; + A[1][1][0][1] = 10; + A[0][1][0][0] = 6; + A[0][1][1][1] = 10; + A[0][1][0][1] = 16; + break; + + case 3: + // I'm too lazy to code something + // up by hand here + for (unsigned int i=0; i<3; ++i) + for (unsigned int j=0; j<3; ++j) + for (unsigned int k=0; k<3; ++k) + for (unsigned int l=0; l<3; ++l) + A[i][j][k][l] = 1.*rand()/RAND_MAX; + break; + + default: + Assert (false, ExcNotImplemented()); + } + check (A); +} + + + +int main () +{ + std::ofstream logfile("symmetric_tensor_19.output"); + logfile.precision(3); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + test<1> (); + test<2> (); + test<3> (); + + deallog << "OK" << std::endl; +}