From: Wolfgang Bangerth Date: Wed, 6 Apr 2005 15:22:50 +0000 (+0000) Subject: Tests for full tensors. X-Git-Tag: v8.0.0~14160 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec01f639eb1ad6adac4196a042249802487caf42;p=dealii.git Tests for full tensors. git-svn-id: https://svn.dealii.org/trunk@10387 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/base/Makefile b/tests/base/Makefile index 6dfa667f9d..71c44f4055 100644 --- a/tests/base/Makefile +++ b/tests/base/Makefile @@ -30,6 +30,7 @@ tests_x = logtest \ table \ tensor \ symmetric_tensor_* \ + full_tensor_* \ timer \ threads \ polynomial* \ diff --git a/tests/base/full_tensor_01.cc b/tests/base/full_tensor_01.cc new file mode 100644 index 0000000000..4e5d10df45 --- /dev/null +++ b/tests/base/full_tensor_01.cc @@ -0,0 +1,43 @@ +//---------------------------- full_tensor_01.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. +// +//---------------------------- full_tensor_01.cc --------------------------- + +// test full 2x2 tensors + +#include "../tests.h" +#include +#include +#include +#include + +int main () +{ + std::ofstream logfile("full_tensor_01.output"); + logfile.precision(3); + deallog.attach(logfile); + deallog.depth_console(0); + + Tensor<2,2> t; + t[0][0] = 1; + t[1][1] = 2; + t[0][1] = 4; + t[1][0] = 4; + // make sure transposition doesn't change + // anything + Assert (t == transpose(t), ExcInternalError()); + + // check norm of tensor + Assert (std::fabs(t.norm() - std::sqrt(1.*1+2*2+2*4*4)) < 1e-14, + ExcInternalError()); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/full_tensor_02.cc b/tests/base/full_tensor_02.cc new file mode 100644 index 0000000000..7d9569afc4 --- /dev/null +++ b/tests/base/full_tensor_02.cc @@ -0,0 +1,52 @@ +//---------------------------- full_tensor_02.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. +// +//---------------------------- full_tensor_02.cc --------------------------- + +// test full 3x3 tensors + +#include "../tests.h" +#include +#include +#include +#include + +int main () +{ + std::ofstream logfile("full_tensor_02.output"); + logfile.precision(3); + deallog.attach(logfile); + deallog.depth_console(0); + + Tensor<2,3> t; + t[0][0] = 1; + t[1][1] = 2; + t[2][2] = 3; + t[0][1] = 4; + t[1][0] = 4; + t[0][2] = 5; + t[2][0] = 5; + t[1][2] = 6; + t[2][1] = 6; + + Assert (t[0][1] == t[1][0], ExcInternalError()); + + // make sure transposition doesn't change + // anything + Assert (t == transpose(t), ExcInternalError()); + + // check norm of tensor + Assert (std::fabs(t.norm() - std::sqrt(1.*1+2*2+3*3+2*4*4+2*5*5+2*6*6)) + < 1e-14, + ExcInternalError()); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/full_tensor_03.cc b/tests/base/full_tensor_03.cc new file mode 100644 index 0000000000..f2b58dbef9 --- /dev/null +++ b/tests/base/full_tensor_03.cc @@ -0,0 +1,53 @@ +//---------------------------- full_tensor_03.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. +// +//---------------------------- full_tensor_03.cc --------------------------- + +// test full 2x2x2x2 tensors + +#include "../tests.h" +#include +#include +#include +#include + +int main () +{ + std::ofstream logfile("full_tensor_03.output"); + logfile.precision(3); + deallog.attach(logfile); + deallog.depth_console(0); + + Tensor<4,2> t; + t[0][0][0][0] = 1; + t[1][1][1][1] = 2; + t[0][1][0][1] = 3; + t[1][0][1][0] = 3; + + Assert (t[0][1][0][1] == t[1][0][1][0], ExcInternalError()); + + // check norm of tensor + deallog << t.norm() << std::endl; + + // make sure norm is induced by scalar + // product + double norm_sqr = 0; + for (unsigned int i=0; i<2; ++i) + for (unsigned int j=0; j<2; ++j) + for (unsigned int k=0; k<2; ++k) + for (unsigned int l=0; l<2; ++l) + norm_sqr += t[i][j][k][l] * t[i][j][k][l]; + + Assert (std::fabs (t.norm()*t.norm() - norm_sqr) < 1e-14, + ExcInternalError()); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/full_tensor_04.cc b/tests/base/full_tensor_04.cc new file mode 100644 index 0000000000..fad59d5579 --- /dev/null +++ b/tests/base/full_tensor_04.cc @@ -0,0 +1,52 @@ +//---------------------------- full_tensor_04.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. +// +//---------------------------- full_tensor_04.cc --------------------------- + +// test full 3x3x3x3 tensors + +#include "../tests.h" +#include +#include +#include +#include + +int main () +{ + std::ofstream logfile("full_tensor_04.output"); + logfile.precision(3); + deallog.attach(logfile); + deallog.depth_console(0); + + Tensor<4,3> t; + t[0][0][0][0] = 1; + t[1][1][1][1] = 2; + t[0][1][0][1] = 3; + t[1][0][1][0] = 3; + + Assert (t[0][1][0][1] == t[1][0][1][0], ExcInternalError()); + + // check norm of tensor + deallog << t.norm() << std::endl; + + // make sure norm is induced by scalar + // product + double norm_sqr = 0; + for (unsigned int i=0; i<2; ++i) + for (unsigned int j=0; j<2; ++j) + for (unsigned int k=0; k<2; ++k) + for (unsigned int l=0; l<2; ++l) + norm_sqr += t[i][j][k][l] * t[i][j][k][l]; + Assert (std::fabs (t.norm()*t.norm() - norm_sqr) < 1e-14, + ExcInternalError()); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/full_tensor_05.cc b/tests/base/full_tensor_05.cc new file mode 100644 index 0000000000..368692fe9e --- /dev/null +++ b/tests/base/full_tensor_05.cc @@ -0,0 +1,87 @@ +//---------------------------- full_tensor_05.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. +// +//---------------------------- full_tensor_05.cc --------------------------- + +// make sure the tensor t_ijkl=delta_ik delta_jl +// actually maps a rank-2 tensor onto twice itself + +#include "../tests.h" +#include +#include +#include +#include + + +template +void test () +{ + Tensor<4,dim> t; + for (unsigned int i=0; i a, b; + a[0][0] = 1; + a[1][1] = 2; + a[0][1] = 3; + + for (unsigned int i=0; i (); + test<3> (); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/full_tensor_06.cc b/tests/base/full_tensor_06.cc new file mode 100644 index 0000000000..dfd3b0fbd6 --- /dev/null +++ b/tests/base/full_tensor_06.cc @@ -0,0 +1,92 @@ +//---------------------------- full_tensor_06.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. +// +//---------------------------- full_tensor_06.cc --------------------------- + +// make sure a tensor similar to the elasticity tensor for the +// isotropic case works as expected by comparing with a full tensor + +#include "../tests.h" +#include +#include +#include +#include +#include + + +template +void test () +{ + const double lambda = 5, + mu = 7; + Tensor<4,dim> ts; + Tensor<4,dim> ta; + for (unsigned int i=0; i as, bs; + Tensor<2,dim> aa, ba; + + for (unsigned int i=0; i (); + test<3> (); + + deallog << "OK" << std::endl; +}