Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
convexpolyhedron.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_FUFEM_GEOMETRY_CONVEXPOLYHEDRON_HH
5#define DUNE_FUFEM_GEOMETRY_CONVEXPOLYHEDRON_HH
6
9
10template <class Coordinate> struct ConvexPolyhedron {
12
13 template <class DynamicVector>
14 Coordinate barycentricToGlobal(DynamicVector const &b) const {
15 assert(b.size() == vertices.size());
16 Coordinate r(0);
17 for (size_t i = 0; i < b.size(); i++)
18 for(auto j : Dune::range(r.size()))
19 r[j] += b[i]*vertices[i][j];
20 return r;
21 }
22
23 template <class DynamicVector>
24 void sanityCheck(DynamicVector const &b, double tol) const {
25 double sum = 0;
26 for (size_t i = 0; i < b.size(); i++) {
27 if (b[i] < -tol)
28 DUNE_THROW(Dune::Exception, "No barycentric coords " << b[1] << " nr. "
29 << i);
30 sum += b[i];
31 }
32 if (sum > 1 + tol)
33 DUNE_THROW(Dune::Exception, "No barycentric coords, sum: " << sum);
34 }
35};
36#endif
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
#define DUNE_THROW(E,...)
Definition convexpolyhedron.hh:10
void sanityCheck(DynamicVector const &b, double tol) const
Definition convexpolyhedron.hh:24
std::vector< Coordinate > vertices
Definition convexpolyhedron.hh:11
Coordinate barycentricToGlobal(DynamicVector const &b) const
Definition convexpolyhedron.hh:14
T size(T... args)