From 8373c09d8cd8f736151df7776d9a2cb54951d979 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Thu, 25 Jan 2018 19:26:39 +0100 Subject: [PATCH] [geometry] Add function to compute a geometry's diameter --- dumux/common/geometry/CMakeLists.txt | 1 + dumux/common/geometry/diameter.hh | 49 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 dumux/common/geometry/diameter.hh diff --git a/dumux/common/geometry/CMakeLists.txt b/dumux/common/geometry/CMakeLists.txt index 25d3a6a071..5d6fc9ee40 100644 --- a/dumux/common/geometry/CMakeLists.txt +++ b/dumux/common/geometry/CMakeLists.txt @@ -1,6 +1,7 @@ install(FILES boundingboxtree.hh boundingboxtreeintersection.hh +diameter.hh geometricentityset.hh geometryintersection.hh grahamconvexhull.hh diff --git a/dumux/common/geometry/diameter.hh b/dumux/common/geometry/diameter.hh new file mode 100644 index 0000000000..395c86ec74 --- /dev/null +++ b/dumux/common/geometry/diameter.hh @@ -0,0 +1,49 @@ +/***************************************************************************** + * See the file COPYING for full copying permissions. * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *****************************************************************************/ +/*! + * \file + * \ingroup Common + * \brief A function to compute a geometry's diameter, i.e. + * the longest distance between points of a geometry + */ +#ifndef DUMUX_GEOMETRY_DIAMETER_HH +#define DUMUX_GEOMETRY_DIAMETER_HH + +#include <algorithm> + +namespace Dumux { + +/*! + * \ingroup Common + * \brief Computes the longest distance between points of a geometry + * \note Useful e.g. to compute the maximum cell diameter of a grid + */ +template<class Geometry> +typename Geometry::ctype diameter(const Geometry& geo) +{ + using std::max; + typename Geometry::ctype h = 0.0; + for (std::size_t i = 0; i < geo.corners(); ++i) + for (std::size_t j = i + 1; j < geo.corners(); ++j) + h = max(h, (geo.corner(i)-geo.corner(j)).two_norm()); + + return h; +} + +} // end namespace Dumux + +#endif -- GitLab