From 4f12480544da068740e471ed54a592e2484b4577 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Tue, 15 Aug 2017 09:01:02 -0600 Subject: [PATCH] Add more comprehensive test for symmetric tensor operator+= and friends --- tests/base/symmetric_tensor_43.cc | 91 ++++++++++++++++++++ tests/base/symmetric_tensor_43.output | 114 ++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 tests/base/symmetric_tensor_43.cc create mode 100644 tests/base/symmetric_tensor_43.output diff --git a/tests/base/symmetric_tensor_43.cc b/tests/base/symmetric_tensor_43.cc new file mode 100644 index 0000000000..440dd104b5 --- /dev/null +++ b/tests/base/symmetric_tensor_43.cc @@ -0,0 +1,91 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Verify that symmetric tensor operators+= and friends work with different +// number types + +#include "../tests.h" +#include + +#include + +template +void fill_tensor (SymmetricTensor &t) +{ + for (unsigned int i=0; i!=t.n_independent_components; ++i) + { + t.access_raw_entry(i) = i+1; + } +} + +template +void test_operators () +{ + const OtherNumberType s1 = 2.0; + const OtherNumberType s2 = 0.5; + + deallog << "operator *=" << std::endl; + SymmetricTensor t1; + fill_tensor(t1); + t1 *= s1; + deallog << t1 << std::endl; + + deallog << "operator /=" << std::endl; + SymmetricTensor t2; + fill_tensor(t2); + t2 /= s2; + deallog << t2 << std::endl; + + SymmetricTensor t3; + fill_tensor(t3); + + deallog << "operator +=" << std::endl; + t1 += t3; + deallog << t1 << std::endl; + + deallog << "operator -=" << std::endl; + t2 -= t3; + deallog << t2 << std::endl; +} + +template +void test () +{ + deallog << "dim=" << 1 << std::endl; + test_operators<1,rank,NumberType,OtherNumberType> (); + deallog << "dim=" << 2 << std::endl; + test_operators<2,rank,NumberType,OtherNumberType> (); + deallog << "dim=" << 3 << std::endl; + test_operators<3,rank,NumberType,OtherNumberType> (); +} + + +int main () +{ + initlog(); + + deallog << "rank 2, double" << std::endl; + test<2, double, float >(); + deallog << "rank 2, std::complex" << std::endl; + test<2, std::complex, std::complex >(); + + deallog << "rank 4, double" << std::endl; + test<4, double, float >(); + deallog << "rank 4, std::complex" << std::endl; + test<4, std::complex, std::complex >(); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/symmetric_tensor_43.output b/tests/base/symmetric_tensor_43.output new file mode 100644 index 0000000000..56e48b7437 --- /dev/null +++ b/tests/base/symmetric_tensor_43.output @@ -0,0 +1,114 @@ + +DEAL::rank 2, double +DEAL::dim=1 +DEAL::operator *= +DEAL::2.00000 +DEAL::operator /= +DEAL::2.00000 +DEAL::operator += +DEAL::3.00000 +DEAL::operator -= +DEAL::1.00000 +DEAL::dim=2 +DEAL::operator *= +DEAL::2.00000 6.00000 6.00000 4.00000 +DEAL::operator /= +DEAL::2.00000 6.00000 6.00000 4.00000 +DEAL::operator += +DEAL::3.00000 9.00000 9.00000 6.00000 +DEAL::operator -= +DEAL::1.00000 3.00000 3.00000 2.00000 +DEAL::dim=3 +DEAL::operator *= +DEAL::2.00000 8.00000 10.0000 8.00000 4.00000 12.0000 10.0000 12.0000 6.00000 +DEAL::operator /= +DEAL::2.00000 8.00000 10.0000 8.00000 4.00000 12.0000 10.0000 12.0000 6.00000 +DEAL::operator += +DEAL::3.00000 12.0000 15.0000 12.0000 6.00000 18.0000 15.0000 18.0000 9.00000 +DEAL::operator -= +DEAL::1.00000 4.00000 5.00000 4.00000 2.00000 6.00000 5.00000 6.00000 3.00000 +DEAL::rank 2, std::complex +DEAL::dim=1 +DEAL::operator *= +DEAL::(2.00000,0.00000) +DEAL::operator /= +DEAL::(2.00000,0.00000) +DEAL::operator += +DEAL::(3.00000,0.00000) +DEAL::operator -= +DEAL::(1.00000,0.00000) +DEAL::dim=2 +DEAL::operator *= +DEAL::(2.00000,0.00000) (6.00000,0.00000) (6.00000,0.00000) (4.00000,0.00000) +DEAL::operator /= +DEAL::(2.00000,0.00000) (6.00000,0.00000) (6.00000,0.00000) (4.00000,0.00000) +DEAL::operator += +DEAL::(3.00000,0.00000) (9.00000,0.00000) (9.00000,0.00000) (6.00000,0.00000) +DEAL::operator -= +DEAL::(1.00000,0.00000) (3.00000,0.00000) (3.00000,0.00000) (2.00000,0.00000) +DEAL::dim=3 +DEAL::operator *= +DEAL::(2.00000,0.00000) (8.00000,0.00000) (10.0000,0.00000) (8.00000,0.00000) (4.00000,0.00000) (12.0000,0.00000) (10.0000,0.00000) (12.0000,0.00000) (6.00000,0.00000) +DEAL::operator /= +DEAL::(2.00000,0.00000) (8.00000,0.00000) (10.0000,0.00000) (8.00000,0.00000) (4.00000,0.00000) (12.0000,0.00000) (10.0000,0.00000) (12.0000,0.00000) (6.00000,0.00000) +DEAL::operator += +DEAL::(3.00000,0.00000) (12.0000,0.00000) (15.0000,0.00000) (12.0000,0.00000) (6.00000,0.00000) (18.0000,0.00000) (15.0000,0.00000) (18.0000,0.00000) (9.00000,0.00000) +DEAL::operator -= +DEAL::(1.00000,0.00000) (4.00000,0.00000) (5.00000,0.00000) (4.00000,0.00000) (2.00000,0.00000) (6.00000,0.00000) (5.00000,0.00000) (6.00000,0.00000) (3.00000,0.00000) +DEAL::rank 4, double +DEAL::dim=1 +DEAL::operator *= +DEAL::2.00000 +DEAL::operator /= +DEAL::2.00000 +DEAL::operator += +DEAL::3.00000 +DEAL::operator -= +DEAL::1.00000 +DEAL::dim=2 +DEAL::operator *= +DEAL::2.00000 6.00000 6.00000 4.00000 14.0000 18.0000 18.0000 16.0000 14.0000 18.0000 18.0000 16.0000 8.00000 12.0000 12.0000 10.0000 +DEAL::operator /= +DEAL::2.00000 6.00000 6.00000 4.00000 14.0000 18.0000 18.0000 16.0000 14.0000 18.0000 18.0000 16.0000 8.00000 12.0000 12.0000 10.0000 +DEAL::operator += +DEAL::3.00000 9.00000 9.00000 6.00000 21.0000 27.0000 27.0000 24.0000 21.0000 27.0000 27.0000 24.0000 12.0000 18.0000 18.0000 15.0000 +DEAL::operator -= +DEAL::1.00000 3.00000 3.00000 2.00000 7.00000 9.00000 9.00000 8.00000 7.00000 9.00000 9.00000 8.00000 4.00000 6.00000 6.00000 5.00000 +DEAL::dim=3 +DEAL::operator *= +DEAL::2.00000 8.00000 10.0000 8.00000 4.00000 12.0000 10.0000 12.0000 6.00000 38.0000 44.0000 46.0000 44.0000 40.0000 48.0000 46.0000 48.0000 42.0000 50.0000 56.0000 58.0000 56.0000 52.0000 60.0000 58.0000 60.0000 54.0000 38.0000 44.0000 46.0000 44.0000 40.0000 48.0000 46.0000 48.0000 42.0000 14.0000 20.0000 22.0000 20.0000 16.0000 24.0000 22.0000 24.0000 18.0000 62.0000 68.0000 70.0000 68.0000 64.0000 72.0000 70.0000 72.0000 66.0000 50.0000 56.0000 58.0000 56.0000 52.0000 60.0000 58.0000 60.0000 54.0000 62.0000 68.0000 70.0000 68.0000 64.0000 72.0000 70.0000 72.0000 66.0000 26.0000 32.0000 34.0000 32.0000 28.0000 36.0000 34.0000 36.0000 30.0000 +DEAL::operator /= +DEAL::2.00000 8.00000 10.0000 8.00000 4.00000 12.0000 10.0000 12.0000 6.00000 38.0000 44.0000 46.0000 44.0000 40.0000 48.0000 46.0000 48.0000 42.0000 50.0000 56.0000 58.0000 56.0000 52.0000 60.0000 58.0000 60.0000 54.0000 38.0000 44.0000 46.0000 44.0000 40.0000 48.0000 46.0000 48.0000 42.0000 14.0000 20.0000 22.0000 20.0000 16.0000 24.0000 22.0000 24.0000 18.0000 62.0000 68.0000 70.0000 68.0000 64.0000 72.0000 70.0000 72.0000 66.0000 50.0000 56.0000 58.0000 56.0000 52.0000 60.0000 58.0000 60.0000 54.0000 62.0000 68.0000 70.0000 68.0000 64.0000 72.0000 70.0000 72.0000 66.0000 26.0000 32.0000 34.0000 32.0000 28.0000 36.0000 34.0000 36.0000 30.0000 +DEAL::operator += +DEAL::3.00000 12.0000 15.0000 12.0000 6.00000 18.0000 15.0000 18.0000 9.00000 57.0000 66.0000 69.0000 66.0000 60.0000 72.0000 69.0000 72.0000 63.0000 75.0000 84.0000 87.0000 84.0000 78.0000 90.0000 87.0000 90.0000 81.0000 57.0000 66.0000 69.0000 66.0000 60.0000 72.0000 69.0000 72.0000 63.0000 21.0000 30.0000 33.0000 30.0000 24.0000 36.0000 33.0000 36.0000 27.0000 93.0000 102.000 105.000 102.000 96.0000 108.000 105.000 108.000 99.0000 75.0000 84.0000 87.0000 84.0000 78.0000 90.0000 87.0000 90.0000 81.0000 93.0000 102.000 105.000 102.000 96.0000 108.000 105.000 108.000 99.0000 39.0000 48.0000 51.0000 48.0000 42.0000 54.0000 51.0000 54.0000 45.0000 +DEAL::operator -= +DEAL::1.00000 4.00000 5.00000 4.00000 2.00000 6.00000 5.00000 6.00000 3.00000 19.0000 22.0000 23.0000 22.0000 20.0000 24.0000 23.0000 24.0000 21.0000 25.0000 28.0000 29.0000 28.0000 26.0000 30.0000 29.0000 30.0000 27.0000 19.0000 22.0000 23.0000 22.0000 20.0000 24.0000 23.0000 24.0000 21.0000 7.00000 10.0000 11.0000 10.0000 8.00000 12.0000 11.0000 12.0000 9.00000 31.0000 34.0000 35.0000 34.0000 32.0000 36.0000 35.0000 36.0000 33.0000 25.0000 28.0000 29.0000 28.0000 26.0000 30.0000 29.0000 30.0000 27.0000 31.0000 34.0000 35.0000 34.0000 32.0000 36.0000 35.0000 36.0000 33.0000 13.0000 16.0000 17.0000 16.0000 14.0000 18.0000 17.0000 18.0000 15.0000 +DEAL::rank 4, std::complex +DEAL::dim=1 +DEAL::operator *= +DEAL::(2.00000,0.00000) +DEAL::operator /= +DEAL::(2.00000,0.00000) +DEAL::operator += +DEAL::(3.00000,0.00000) +DEAL::operator -= +DEAL::(1.00000,0.00000) +DEAL::dim=2 +DEAL::operator *= +DEAL::(2.00000,0.00000) (6.00000,0.00000) (6.00000,0.00000) (4.00000,0.00000) (14.0000,0.00000) (18.0000,0.00000) (18.0000,0.00000) (16.0000,0.00000) (14.0000,0.00000) (18.0000,0.00000) (18.0000,0.00000) (16.0000,0.00000) (8.00000,0.00000) (12.0000,0.00000) (12.0000,0.00000) (10.0000,0.00000) +DEAL::operator /= +DEAL::(2.00000,0.00000) (6.00000,0.00000) (6.00000,0.00000) (4.00000,0.00000) (14.0000,0.00000) (18.0000,0.00000) (18.0000,0.00000) (16.0000,0.00000) (14.0000,0.00000) (18.0000,0.00000) (18.0000,0.00000) (16.0000,0.00000) (8.00000,0.00000) (12.0000,0.00000) (12.0000,0.00000) (10.0000,0.00000) +DEAL::operator += +DEAL::(3.00000,0.00000) (9.00000,0.00000) (9.00000,0.00000) (6.00000,0.00000) (21.0000,0.00000) (27.0000,0.00000) (27.0000,0.00000) (24.0000,0.00000) (21.0000,0.00000) (27.0000,0.00000) (27.0000,0.00000) (24.0000,0.00000) (12.0000,0.00000) (18.0000,0.00000) (18.0000,0.00000) (15.0000,0.00000) +DEAL::operator -= +DEAL::(1.00000,0.00000) (3.00000,0.00000) (3.00000,0.00000) (2.00000,0.00000) (7.00000,0.00000) (9.00000,0.00000) (9.00000,0.00000) (8.00000,0.00000) (7.00000,0.00000) (9.00000,0.00000) (9.00000,0.00000) (8.00000,0.00000) (4.00000,0.00000) (6.00000,0.00000) (6.00000,0.00000) (5.00000,0.00000) +DEAL::dim=3 +DEAL::operator *= +DEAL::(2.00000,0.00000) (8.00000,0.00000) (10.0000,0.00000) (8.00000,0.00000) (4.00000,0.00000) (12.0000,0.00000) (10.0000,0.00000) (12.0000,0.00000) (6.00000,0.00000) (38.0000,0.00000) (44.0000,0.00000) (46.0000,0.00000) (44.0000,0.00000) (40.0000,0.00000) (48.0000,0.00000) (46.0000,0.00000) (48.0000,0.00000) (42.0000,0.00000) (50.0000,0.00000) (56.0000,0.00000) (58.0000,0.00000) (56.0000,0.00000) (52.0000,0.00000) (60.0000,0.00000) (58.0000,0.00000) (60.0000,0.00000) (54.0000,0.00000) (38.0000,0.00000) (44.0000,0.00000) (46.0000,0.00000) (44.0000,0.00000) (40.0000,0.00000) (48.0000,0.00000) (46.0000,0.00000) (48.0000,0.00000) (42.0000,0.00000) (14.0000,0.00000) (20.0000,0.00000) (22.0000,0.00000) (20.0000,0.00000) (16.0000,0.00000) (24.0000,0.00000) (22.0000,0.00000) (24.0000,0.00000) (18.0000,0.00000) (62.0000,0.00000) (68.0000,0.00000) (70.0000,0.00000) (68.0000,0.00000) (64.0000,0.00000) (72.0000,0.00000) (70.0000,0.00000) (72.0000,0.00000) (66.0000,0.00000) (50.0000,0.00000) (56.0000,0.00000) (58.0000,0.00000) (56.0000,0.00000) (52.0000,0.00000) (60.0000,0.00000) (58.0000,0.00000) (60.0000,0.00000) (54.0000,0.00000) (62.0000,0.00000) (68.0000,0.00000) (70.0000,0.00000) (68.0000,0.00000) (64.0000,0.00000) (72.0000,0.00000) (70.0000,0.00000) (72.0000,0.00000) (66.0000,0.00000) (26.0000,0.00000) (32.0000,0.00000) (34.0000,0.00000) (32.0000,0.00000) (28.0000,0.00000) (36.0000,0.00000) (34.0000,0.00000) (36.0000,0.00000) (30.0000,0.00000) +DEAL::operator /= +DEAL::(2.00000,0.00000) (8.00000,0.00000) (10.0000,0.00000) (8.00000,0.00000) (4.00000,0.00000) (12.0000,0.00000) (10.0000,0.00000) (12.0000,0.00000) (6.00000,0.00000) (38.0000,0.00000) (44.0000,0.00000) (46.0000,0.00000) (44.0000,0.00000) (40.0000,0.00000) (48.0000,0.00000) (46.0000,0.00000) (48.0000,0.00000) (42.0000,0.00000) (50.0000,0.00000) (56.0000,0.00000) (58.0000,0.00000) (56.0000,0.00000) (52.0000,0.00000) (60.0000,0.00000) (58.0000,0.00000) (60.0000,0.00000) (54.0000,0.00000) (38.0000,0.00000) (44.0000,0.00000) (46.0000,0.00000) (44.0000,0.00000) (40.0000,0.00000) (48.0000,0.00000) (46.0000,0.00000) (48.0000,0.00000) (42.0000,0.00000) (14.0000,0.00000) (20.0000,0.00000) (22.0000,0.00000) (20.0000,0.00000) (16.0000,0.00000) (24.0000,0.00000) (22.0000,0.00000) (24.0000,0.00000) (18.0000,0.00000) (62.0000,0.00000) (68.0000,0.00000) (70.0000,0.00000) (68.0000,0.00000) (64.0000,0.00000) (72.0000,0.00000) (70.0000,0.00000) (72.0000,0.00000) (66.0000,0.00000) (50.0000,0.00000) (56.0000,0.00000) (58.0000,0.00000) (56.0000,0.00000) (52.0000,0.00000) (60.0000,0.00000) (58.0000,0.00000) (60.0000,0.00000) (54.0000,0.00000) (62.0000,0.00000) (68.0000,0.00000) (70.0000,0.00000) (68.0000,0.00000) (64.0000,0.00000) (72.0000,0.00000) (70.0000,0.00000) (72.0000,0.00000) (66.0000,0.00000) (26.0000,0.00000) (32.0000,0.00000) (34.0000,0.00000) (32.0000,0.00000) (28.0000,0.00000) (36.0000,0.00000) (34.0000,0.00000) (36.0000,0.00000) (30.0000,0.00000) +DEAL::operator += +DEAL::(3.00000,0.00000) (12.0000,0.00000) (15.0000,0.00000) (12.0000,0.00000) (6.00000,0.00000) (18.0000,0.00000) (15.0000,0.00000) (18.0000,0.00000) (9.00000,0.00000) (57.0000,0.00000) (66.0000,0.00000) (69.0000,0.00000) (66.0000,0.00000) (60.0000,0.00000) (72.0000,0.00000) (69.0000,0.00000) (72.0000,0.00000) (63.0000,0.00000) (75.0000,0.00000) (84.0000,0.00000) (87.0000,0.00000) (84.0000,0.00000) (78.0000,0.00000) (90.0000,0.00000) (87.0000,0.00000) (90.0000,0.00000) (81.0000,0.00000) (57.0000,0.00000) (66.0000,0.00000) (69.0000,0.00000) (66.0000,0.00000) (60.0000,0.00000) (72.0000,0.00000) (69.0000,0.00000) (72.0000,0.00000) (63.0000,0.00000) (21.0000,0.00000) (30.0000,0.00000) (33.0000,0.00000) (30.0000,0.00000) (24.0000,0.00000) (36.0000,0.00000) (33.0000,0.00000) (36.0000,0.00000) (27.0000,0.00000) (93.0000,0.00000) (102.000,0.00000) (105.000,0.00000) (102.000,0.00000) (96.0000,0.00000) (108.000,0.00000) (105.000,0.00000) (108.000,0.00000) (99.0000,0.00000) (75.0000,0.00000) (84.0000,0.00000) (87.0000,0.00000) (84.0000,0.00000) (78.0000,0.00000) (90.0000,0.00000) (87.0000,0.00000) (90.0000,0.00000) (81.0000,0.00000) (93.0000,0.00000) (102.000,0.00000) (105.000,0.00000) (102.000,0.00000) (96.0000,0.00000) (108.000,0.00000) (105.000,0.00000) (108.000,0.00000) (99.0000,0.00000) (39.0000,0.00000) (48.0000,0.00000) (51.0000,0.00000) (48.0000,0.00000) (42.0000,0.00000) (54.0000,0.00000) (51.0000,0.00000) (54.0000,0.00000) (45.0000,0.00000) +DEAL::operator -= +DEAL::(1.00000,0.00000) (4.00000,0.00000) (5.00000,0.00000) (4.00000,0.00000) (2.00000,0.00000) (6.00000,0.00000) (5.00000,0.00000) (6.00000,0.00000) (3.00000,0.00000) (19.0000,0.00000) (22.0000,0.00000) (23.0000,0.00000) (22.0000,0.00000) (20.0000,0.00000) (24.0000,0.00000) (23.0000,0.00000) (24.0000,0.00000) (21.0000,0.00000) (25.0000,0.00000) (28.0000,0.00000) (29.0000,0.00000) (28.0000,0.00000) (26.0000,0.00000) (30.0000,0.00000) (29.0000,0.00000) (30.0000,0.00000) (27.0000,0.00000) (19.0000,0.00000) (22.0000,0.00000) (23.0000,0.00000) (22.0000,0.00000) (20.0000,0.00000) (24.0000,0.00000) (23.0000,0.00000) (24.0000,0.00000) (21.0000,0.00000) (7.00000,0.00000) (10.0000,0.00000) (11.0000,0.00000) (10.0000,0.00000) (8.00000,0.00000) (12.0000,0.00000) (11.0000,0.00000) (12.0000,0.00000) (9.00000,0.00000) (31.0000,0.00000) (34.0000,0.00000) (35.0000,0.00000) (34.0000,0.00000) (32.0000,0.00000) (36.0000,0.00000) (35.0000,0.00000) (36.0000,0.00000) (33.0000,0.00000) (25.0000,0.00000) (28.0000,0.00000) (29.0000,0.00000) (28.0000,0.00000) (26.0000,0.00000) (30.0000,0.00000) (29.0000,0.00000) (30.0000,0.00000) (27.0000,0.00000) (31.0000,0.00000) (34.0000,0.00000) (35.0000,0.00000) (34.0000,0.00000) (32.0000,0.00000) (36.0000,0.00000) (35.0000,0.00000) (36.0000,0.00000) (33.0000,0.00000) (13.0000,0.00000) (16.0000,0.00000) (17.0000,0.00000) (16.0000,0.00000) (14.0000,0.00000) (18.0000,0.00000) (17.0000,0.00000) (18.0000,0.00000) (15.0000,0.00000) +DEAL::OK -- 2.39.5