From 1651b55423f826cf9fc76876c952105ab4b88998 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 18 Jan 2018 15:39:34 -0700 Subject: [PATCH] Add a test for LinearAlgebra::Vector::add_and_dot(). --- tests/lac/la_vector_add_and_dot_complex.cc | 77 +++++++++++++++++++ .../lac/la_vector_add_and_dot_complex.output | 52 +++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 tests/lac/la_vector_add_and_dot_complex.cc create mode 100644 tests/lac/la_vector_add_and_dot_complex.output diff --git a/tests/lac/la_vector_add_and_dot_complex.cc b/tests/lac/la_vector_add_and_dot_complex.cc new file mode 100644 index 0000000000..ad0c24353f --- /dev/null +++ b/tests/lac/la_vector_add_and_dot_complex.cc @@ -0,0 +1,77 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2012 - 2015 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. +// +// --------------------------------------------------------------------- + + +// check that LinearAlgebra::Vector::add_and_dot works correctly for complex-valued +// vectors + +#include "../tests.h" +#include + + + + +template +void check () +{ + for (unsigned int test=0; test<5; ++test) + { + const unsigned int size = 17 + test*1101; + LinearAlgebra::Vector> v1 (size), v2(size), v3(size), check(size); + for (unsigned int i=0; i(0.1 + 0.005 * i, 1.234 + 12 * i); + v2(i) = std::complex(-5.2 + 0.18 * i, 42.4242 + 42 * i); + v3(i) = std::complex(3.14159 + 2.7183/(1.+i), 13.); + } + check = v1; + const std::complex factor = std::complex(0.01432); + + // do things by hand once + v1.add(factor, v2); + const std::complex prod = v1 * v3; + + // then do it a second time with the add_and_dot function + const std::complex prod_check = check.add_and_dot(factor, v2, v3); + if (test == 0 && std::is_same::value) + { + deallog << "Vector add reference: "; + v1.print(deallog.get_file_stream()); + deallog << std::endl; + deallog << "Vector check reference: "; + check.print(deallog.get_file_stream()); + deallog << std::endl; + } + + deallog << "Add and dot should be " << prod/static_cast(size) + << ", is " << prod_check/static_cast(size) + << std::endl; + } +} + + +int main() +{ + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(2); + deallog.attach(logfile); + + check(); + check(); + deallog << "OK" << std::endl; +} + + diff --git a/tests/lac/la_vector_add_and_dot_complex.output b/tests/lac/la_vector_add_and_dot_complex.output new file mode 100644 index 0000000000..d901301702 --- /dev/null +++ b/tests/lac/la_vector_add_and_dot_complex.output @@ -0,0 +1,52 @@ + +DEAL::Add and dot should be (1334.79,349.71), is (1334.79,349.71) +DEAL::Add and dot should be (91530.09,22094.70), is (91530.09,22094.70) +DEAL::Add and dot should be (181725.41,43834.06), is (181725.41,43834.06) +DEAL::Add and dot should be (271920.72,65573.37), is (271920.72,65573.37) +DEAL::Add and dot should be (362116.03,87312.66), is (362116.03,87312.66) +IndexSet: {[0,16]} + +[0]: (2.554e-02,1.842e+00) +[1]: (3.311e-02,1.444e+01) +[2]: (4.069e-02,2.704e+01) +[3]: (4.827e-02,3.965e+01) +[4]: (5.585e-02,5.225e+01) +[5]: (6.342e-02,6.485e+01) +[6]: (7.100e-02,7.745e+01) +[7]: (7.858e-02,9.005e+01) +[8]: (8.616e-02,1.027e+02) +[9]: (9.373e-02,1.153e+02) +[10]: (1.013e-01,1.279e+02) +[11]: (1.089e-01,1.405e+02) +[12]: (1.165e-01,1.531e+02) +[13]: (1.240e-01,1.657e+02) +[14]: (1.316e-01,1.783e+02) +[15]: (1.392e-01,1.909e+02) +[16]: (1.468e-01,2.035e+02) +DEAL::Vector add reference: +IndexSet: {[0,16]} + +[0]: (2.554e-02,1.842e+00) +[1]: (3.311e-02,1.444e+01) +[2]: (4.069e-02,2.704e+01) +[3]: (4.827e-02,3.965e+01) +[4]: (5.585e-02,5.225e+01) +[5]: (6.342e-02,6.485e+01) +[6]: (7.100e-02,7.745e+01) +[7]: (7.858e-02,9.005e+01) +[8]: (8.616e-02,1.027e+02) +[9]: (9.373e-02,1.153e+02) +[10]: (1.013e-01,1.279e+02) +[11]: (1.089e-01,1.405e+02) +[12]: (1.165e-01,1.531e+02) +[13]: (1.240e-01,1.657e+02) +[14]: (1.316e-01,1.783e+02) +[15]: (1.392e-01,1.909e+02) +[16]: (1.468e-01,2.035e+02) +DEAL::Vector check reference: +DEAL::Add and dot should be (1334.79,349.71), is (1334.79,349.71) +DEAL::Add and dot should be (91530.09,22094.70), is (91530.09,22094.70) +DEAL::Add and dot should be (181725.40,43834.06), is (181725.40,43834.06) +DEAL::Add and dot should be (271920.71,65573.37), is (271920.71,65573.37) +DEAL::Add and dot should be (362116.02,87312.66), is (362116.02,87312.66) +DEAL::OK -- 2.39.5