From: Denis Davydov Date: Thu, 24 Aug 2017 12:57:46 +0000 (+0200) Subject: extend Point::distance_square() to work with VectorizedArray X-Git-Tag: v9.0.0-rc1~1179^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4949%2Fhead;p=dealii.git extend Point::distance_square() to work with VectorizedArray --- diff --git a/doc/news/changes/minor/20170824DenisDavydov b/doc/news/changes/minor/20170824DenisDavydov new file mode 100644 index 0000000000..0f1898c91f --- /dev/null +++ b/doc/news/changes/minor/20170824DenisDavydov @@ -0,0 +1,3 @@ +New: extend Point::distance_square() to work with VectorizedArray numbers. +
+(Denis Davydov, 2017/08/24) diff --git a/include/deal.II/base/point.h b/include/deal.II/base/point.h index 0e1b913ac8..ab9a52ca98 100644 --- a/include/deal.II/base/point.h +++ b/include/deal.II/base/point.h @@ -494,10 +494,10 @@ inline typename numbers::NumberTraits::real_type Point::distance_square (const Point &p) const { - Number sum = Number(); + Number sum = internal::NumberType::value(0.0); for (unsigned int i=0; ivalues[i]-p(i); + const Number diff=static_cast(this->values[i])-p(i); sum += numbers::NumberTraits::abs_square (diff); } diff --git a/tests/base/point_03.cc b/tests/base/point_03.cc new file mode 100644 index 0000000000..79d6d0cda4 --- /dev/null +++ b/tests/base/point_03.cc @@ -0,0 +1,72 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2010 - 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. +// +// --------------------------------------------------------------------- + + +// test for Point::distance_square() for VectorizedArray numbers + +#include "../tests.h" +#include +#include + + +template +void check () +{ + VectorizedArray distance_vec; + Point> p1_vec, p2_vec; + + for (unsigned int v = 0; v < VectorizedArray::n_array_elements; ++v) + { + Point p1, p2; + for (unsigned int i=0; i distance_vec2 = p1_vec.distance_square(p2_vec); + distance_vec -= distance_vec2; + number diff = 0.; + + for (unsigned int v = 0; v < VectorizedArray::n_array_elements; ++v) + diff += std::abs(distance_vec[v]); + + AssertThrow(diff < 1e-10, + ExcMessage("diff is " + std::to_string(diff))); + + deallog << "Ok" << std::endl; +} + +int main () +{ + std::ofstream logfile("output"); + deallog << std::setprecision(3); + deallog.attach(logfile); + + check<1,float>(); + check<2,float>(); + check<3,float>(); + + check<1,double>(); + check<2,double>(); + check<3,double>(); + +} diff --git a/tests/base/point_03.output b/tests/base/point_03.output new file mode 100644 index 0000000000..b3d2bc3c9f --- /dev/null +++ b/tests/base/point_03.output @@ -0,0 +1,7 @@ + +DEAL::Ok +DEAL::Ok +DEAL::Ok +DEAL::Ok +DEAL::Ok +DEAL::Ok