version 3.8
normal.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_GEOMETRY_NORMAL_HH
13#define DUMUX_GEOMETRY_NORMAL_HH
14
15#include <algorithm>
16#include <dune/common/float_cmp.hh>
17
18namespace Dumux {
19
25template<class Vector>
26inline Vector normal(const Vector& v)
27{
28 static_assert(Vector::size() > 1, "normal expects a coordinate dimension > 1");
29
30 if constexpr (Vector::size() == 2)
31 return Vector({-v[1], v[0]});
32
33 const auto it = std::find_if(v.begin(), v.end(), [](const auto& x) { return Dune::FloatCmp::ne(x, 0.0); });
34 const auto index = std::distance(v.begin(), it);
35 if (index != Vector::size()-1)
36 {
37 Vector normal(0.0);
38 normal[index] = -v[index+1];
39 normal[index+1] = v[index];
40 return normal;
41 }
42 else
43 {
44 Vector normal(0.0);
45 normal[index-1] = -v[index];
46 normal[index] = v[index-1];
47 return normal;
48
49 }
50}
51
57template<class Vector>
58inline Vector unitNormal(const Vector& v)
59{
60 auto normal = Dumux::normal(v);
61 normal /= normal.two_norm();
62 return normal;
63}
64
65} // end namespace Dumux
66
67#endif
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
Vector normal(const Vector &v)
Create a vector normal to the given one (v is expected to be non-zero)
Definition: normal.hh:26
Vector unitNormal(const Vector &v)
Create a vector normal to the given one (v is expected to be non-zero)
Definition: normal.hh:58
Definition: adapt.hh:17