version 3.10-dev
normalaxis.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_NORMAL_AXIS_HH
13#define DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_NORMAL_AXIS_HH
14
15#include <cstddef>
16#include <algorithm>
17#include <numeric>
18
19namespace Dumux {
20
25template<class Vector>
26inline static std::size_t normalAxis(const Vector& v)
27{
28 using std::abs;
29
30 constexpr auto eps = 1e-8;
31 assert(std::any_of(v.begin(), v.end(), [=](auto x){ return abs(x) > eps; }));
32
33 const auto result = std::distance(
34 std::begin(v), std::find_if(v.begin(), v.end(), [eps=eps](auto x){ return abs(x) > eps; })
35 );
36
37 // make sure there is only one non-zero entry
38 assert(v[result] == std::accumulate(v.begin(), v.end(), 0.0));
39
40 return result;
41}
42
43} // end namespace Dumux
44
45#endif
static std::size_t normalAxis(const Vector &v)
Returns the normal axis index of a unit vector (0 = x, 1 = y, 2 = z)
Definition: normalaxis.hh:26
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
Definition: adapt.hh:17