From 48781c29be1503a3981cce1e0a9aa57201aca5ad Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Sun, 12 Apr 2015 18:18:43 +0200 Subject: [PATCH] [Cleanup] Move distance helper to polyhedrondistance --- dune/tectonic/polyhedrondistance.hh | 28 +++++++++++++++++++++++ src/diameter.hh | 16 ++++++++++++++ src/distances.hh | 33 ---------------------------- src/sand-wedge-data/mygrid.cc | 7 ++++-- src/sand-wedge-data/patchfunction.hh | 2 +- src/sand-wedge.cc | 2 +- 6 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 src/diameter.hh delete mode 100644 src/distances.hh diff --git a/dune/tectonic/polyhedrondistance.hh b/dune/tectonic/polyhedrondistance.hh index a133f296..e45c7f03 100644 --- a/dune/tectonic/polyhedrondistance.hh +++ b/dune/tectonic/polyhedrondistance.hh @@ -188,4 +188,32 @@ double distance(const ConvexPolyhedron<Coordinate> &s1, assert(false); } +// Point-to-Geometry convenience method +template <class Geometry> +double distance(typename Geometry::GlobalCoordinate const &point, + Geometry const &geo, double valueCorrectionTolerance) { + using Coordinate = typename Geometry::GlobalCoordinate; + + ConvexPolyhedron<Coordinate> polyhedron; + polyhedron.vertices.resize(geo.corners()); + for (size_t i = 0; i < polyhedron.vertices.size(); ++i) + polyhedron.vertices[i] = geo.corner(i); + + return distance(point, polyhedron, valueCorrectionTolerance); +} + +// Polyhedron-to-Geometry convenience method +template <class Geometry> +double distance(ConvexPolyhedron<typename Geometry::GlobalCoordinate> const &p1, + Geometry const &geo, double valueCorrectionTolerance) { + using Coordinate = typename Geometry::GlobalCoordinate; + + ConvexPolyhedron<Coordinate> p2; + p2.vertices.resize(geo.corners()); + for (size_t i = 0; i < p2.vertices.size(); ++i) + p2.vertices[i] = geo.corner(i); + + return distance(p2, p1, valueCorrectionTolerance); +} + #endif diff --git a/src/diameter.hh b/src/diameter.hh new file mode 100644 index 00000000..45b446f0 --- /dev/null +++ b/src/diameter.hh @@ -0,0 +1,16 @@ +#ifndef SRC_DIAMETER_HH +#define SRC_DIAMETER_HH + +template <class Geometry> double diameter(Geometry const &geometry) { + auto const numCorners = geometry.corners(); + std::vector<typename Geometry::GlobalCoordinate> corners(numCorners); + + double diameter = 0.0; + for (int i = 0; i < numCorners; ++i) { + corners[i] = geometry.corner(i); + for (int j = 0; j < i; ++j) + diameter = std::max(diameter, (corners[i] - corners[j]).two_norm()); + } + return diameter; +} +#endif diff --git a/src/distances.hh b/src/distances.hh deleted file mode 100644 index ffe7dd51..00000000 --- a/src/distances.hh +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef SRC_DISTANCES_HH -#define SRC_DISTANCES_HH - -#include <dune/tectonic/polyhedrondistance.hh> -#include "sand-wedge-data/mygeometry.hh" - -template <class Geometry> double diameter(Geometry const &geometry) { - auto const numCorners = geometry.corners(); - std::vector<typename Geometry::GlobalCoordinate> corners(numCorners); - - double diameter = 0.0; - for (int i = 0; i < numCorners; ++i) { - corners[i] = geometry.corner(i); - for (int j = 0; j < i; ++j) - diameter = std::max(diameter, (corners[i] - corners[j]).two_norm()); - } - return diameter; -} - -template <class Geometry> -double distance( - Geometry const &g, - ConvexPolyhedron<typename Geometry::GlobalCoordinate> const &weakPatch) { - using Coordinate = typename Geometry::GlobalCoordinate; - - ConvexPolyhedron<Coordinate> bsg; - bsg.vertices.resize(g.corners()); - for (size_t i = 0; i < bsg.vertices.size(); ++i) - bsg.vertices[i] = g.corner(i); - - return distance(bsg, weakPatch, 1e-6 * MyGeometry::lengthScale); -} -#endif diff --git a/src/sand-wedge-data/mygrid.cc b/src/sand-wedge-data/mygrid.cc index 93e3a883..0e7d6e39 100644 --- a/src/sand-wedge-data/mygrid.cc +++ b/src/sand-wedge-data/mygrid.cc @@ -2,9 +2,11 @@ #include "config.h" #endif +#include <dune/tectonic/polyhedrondistance.hh> + #include "mygrid.hh" #include "midpoint.hh" -#include "../distances.hh" +#include "../diameter.hh" #if MY_DIM == 3 SimplexManager::SimplexManager(unsigned int shift) : shift_(shift) {} @@ -203,7 +205,8 @@ void refine(Grid &grid, ConvexPolyhedron<LocalVector> const &weakPatch, it != grid.template leafend<0>(); ++it) { auto const geometry = it->geometry(); - auto const weakeningRegionDistance = distance(geometry, weakPatch); + auto const weakeningRegionDistance = + distance(weakPatch, geometry, 1e-6 * MyGeometry::lengthScale); auto const admissibleDiameter = computeAdmissibleDiameter(weakeningRegionDistance, smallestDiameter); diff --git a/src/sand-wedge-data/patchfunction.hh b/src/sand-wedge-data/patchfunction.hh index 4fcc1eb1..c3b7b9c5 100644 --- a/src/sand-wedge-data/patchfunction.hh +++ b/src/sand-wedge-data/patchfunction.hh @@ -5,7 +5,7 @@ #include <dune/common/fvector.hh> #include <dune/common/parametertree.hh> -#include <dune/tectonic/convexpolyhedron.hh> +#include <dune/tectonic/polyhedrondistance.hh> class PatchFunction : public Dune::VirtualFunction<Dune::FieldVector<double, MY_DIM>, diff --git a/src/sand-wedge.cc b/src/sand-wedge.cc index f6ed0693..3b7aa548 100644 --- a/src/sand-wedge.cc +++ b/src/sand-wedge.cc @@ -55,7 +55,7 @@ #include "adaptivetimestepper.hh" #include "assemblers.hh" -#include "distances.hh" +#include "diameter.hh" #include "enumparser.hh" #include "enums.hh" #include "friction_writer.hh" -- GitLab