From: Wolfgang Bangerth Date: Thu, 18 Jan 2018 22:33:55 +0000 (-0700) Subject: Add a test for Vector::add_and_dot(). X-Git-Tag: v9.0.0-rc1~552^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a9ed36e8642c62fdbccfef5bc7654b3d890f6f;p=dealii.git Add a test for Vector::add_and_dot(). --- diff --git a/tests/lac/vector_add_and_dot_complex.cc b/tests/lac/vector_add_and_dot_complex.cc new file mode 100644 index 0000000000..aafd8ea972 --- /dev/null +++ b/tests/lac/vector_add_and_dot_complex.cc @@ -0,0 +1,75 @@ +// --------------------------------------------------------------------- +// +// 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 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; + 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); + deallog << "Vector check reference: "; + check.print(deallog); + } + + 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/vector_add_and_dot_complex.output b/tests/lac/vector_add_and_dot_complex.output new file mode 100644 index 0000000000..1997230214 --- /dev/null +++ b/tests/lac/vector_add_and_dot_complex.output @@ -0,0 +1,14 @@ + +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) +DEAL::Vector add reference: (0.03,1.84) (0.03,14.44) (0.04,27.04) (0.05,39.65) (0.06,52.25) (0.06,64.85) (0.07,77.45) (0.08,90.05) (0.09,102.65) (0.09,115.25) (0.10,127.86) (0.11,140.46) (0.12,153.06) (0.12,165.66) (0.13,178.26) (0.14,190.86) (0.15,203.46) +DEAL::Vector check reference: (0.03,1.84) (0.03,14.44) (0.04,27.04) (0.05,39.65) (0.06,52.25) (0.06,64.85) (0.07,77.45) (0.08,90.05) (0.09,102.65) (0.09,115.25) (0.10,127.86) (0.11,140.46) (0.12,153.06) (0.12,165.66) (0.13,178.26) (0.14,190.86) (0.15,203.46) +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