version 3.11-dev
Loading...
Searching...
No Matches
scvfnormal.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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_SCVF_NORMAL_HH
13#define DUMUX_DISCRETIZATION_SCVF_NORMAL_HH
14
15#include <dumux/common/math.hh>
17
18namespace Dumux::Detail {
19
32template<class ElementGeometry, class CornerStorage>
33inline auto scvfUnitNormal(const ElementGeometry& geo, const CornerStorage& corners)
34{
35 using GlobalPosition = typename ElementGeometry::GlobalCoordinate;
36 static constexpr int dim = ElementGeometry::mydimension;
37 static constexpr int dimWorld = ElementGeometry::coorddimension;
38 static_assert(dim > 1 && dim <= 3 && dimWorld <= 3);
39
40 const auto normalize = [](GlobalPosition n){ n /= n.two_norm(); return n; };
41
42 if constexpr (dim == 2 && dimWorld == 2)
43 return Dumux::unitNormal(GlobalPosition(corners[1] - corners[0]));
44
45 else if constexpr (dim == 2 && dimWorld == 3)
46 {
47 // A segment's two corners do not determine the element plane.
48 const auto elementNormal = crossProduct(
49 GlobalPosition(geo.corner(1) - geo.corner(0)),
50 GlobalPosition(geo.corner(2) - geo.corner(0))
51 );
52 return normalize(crossProduct(elementNormal, GlobalPosition(corners[1] - corners[0])));
53 }
54
55 else
56 return normalize(crossProduct(
57 GlobalPosition(corners[1] - corners[0]),
58 GlobalPosition(corners[2] - corners[0])
59 ));
60}
61
62} // end namespace Dumux::Detail
63
64#endif
Dune::FieldVector< Scalar, 3 > crossProduct(const Dune::FieldVector< Scalar, 3 > &vec1, const Dune::FieldVector< Scalar, 3 > &vec2)
Cross product of two vectors in three-dimensional Euclidean space.
Definition math.hh:671
auto scvfUnitNormal(const ElementGeometry &geo, const CornerStorage &corners)
Unit normal of an interior sub-control volume face, up to sign.
Definition scvfnormal.hh:33
Vector unitNormal(const Vector &v)
Create a vector normal to the given one (v is expected to be non-zero).
Definition normal.hh:58
Define some often used mathematical functions.
Definition cvfelocalresidual.hh:25
Helper functions for normals.