GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/porenetwork/common/poreproperties.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 24 38 63.2%
Functions: 4 4 100.0%
Branches: 33 141 23.4%

Line Branch Exec Source
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 //
7 /*!
8 * \file
9 * \ingroup PoreNetworkModels
10 * \brief This file contains functions related to calculate pore-body properties.
11 */
12 #ifndef DUMUX_PNM_BASE_PORE_PROPERTIES_HH
13 #define DUMUX_PNM_BASE_PORE_PROPERTIES_HH
14
15 #include <cmath>
16 #include <string>
17 #include <dune/common/exceptions.hh>
18
19 namespace Dumux::PoreNetwork::Pore {
20
21 //! Collection of different pore-body shapes
22 enum class Shape
23 { circle, square, cube, sphere, cylinder, tetrahedron, octahedron, icosahedron, dodecahedron };
24
25 //! Get the shape from a string description of the shape
26 173 inline std::string shapeToString(Shape s)
27 {
28
9/10
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 26 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
173 switch (s)
29 {
30 90 case Shape::square: return "Square";
31 90 case Shape::circle: return "Circle";
32 94 case Shape::cube: return "Cube";
33 52 case Shape::sphere: return "Sphere";
34 4 case Shape::cylinder: return "Cylinder";
35 4 case Shape::tetrahedron: return "Tetrahedron";
36 4 case Shape::octahedron: return "Octahedron";
37 4 case Shape::icosahedron: return "Icosahedron";
38 4 case Shape::dodecahedron: return "Dodecahedron";
39 default: DUNE_THROW(Dune::InvalidStateException, "Unknown shape!");
40 }
41 }
42
43 //! Get the shape from a string description of the shape
44 45 inline Shape shapeFromString(const std::string& s)
45 {
46
4/6
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 45 times.
✗ Branch 6 not taken.
69 if (s == shapeToString(Shape::square)) return Shape::square;
47
4/6
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 45 times.
✗ Branch 6 not taken.
69 else if (s == shapeToString(Shape::circle)) return Shape::circle;
48
5/6
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 26 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 26 times.
✓ Branch 6 taken 19 times.
64 else if (s == shapeToString(Shape::cube)) return Shape::cube;
49
5/6
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 26 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 24 times.
50 else if (s == shapeToString(Shape::sphere)) return Shape::sphere;
50
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
4 else if (s == shapeToString(Shape::cylinder)) return Shape::cylinder;
51 else if (s == shapeToString(Shape::tetrahedron)) return Shape::tetrahedron;
52 else if (s == shapeToString(Shape::octahedron)) return Shape::octahedron;
53 else if (s == shapeToString(Shape::icosahedron)) return Shape::icosahedron;
54 else if (s == shapeToString(Shape::dodecahedron)) return Shape::dodecahedron;
55 else DUNE_THROW(Dune::InvalidStateException, s << " is not a valid shape");
56 }
57
58
59 //! Returns the volume of a given geometry based on the inscribed radius
60 template<class Scalar>
61 17731 inline Scalar volume(Shape shape, Scalar inscribedRadius)
62 {
63
2/9
✓ Branch 0 taken 1539 times.
✓ Branch 1 taken 16192 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
17731 switch(shape)
64 {
65 1539 case Shape::cube: return 8*inscribedRadius*inscribedRadius*inscribedRadius; break;
66 16192 case Shape::sphere: return 4.0/3.0*M_PI*inscribedRadius*inscribedRadius*inscribedRadius; break;
67 case Shape::circle: return M_PI*inscribedRadius*inscribedRadius; break;
68 case Shape::square: return 4.0*inscribedRadius*inscribedRadius; break;
69 case Shape::tetrahedron: return 13.85*inscribedRadius*inscribedRadius*inscribedRadius; break;
70 case Shape::octahedron: return 6.93*inscribedRadius*inscribedRadius*inscribedRadius; break;
71 case Shape::icosahedron: return 5.05*inscribedRadius*inscribedRadius*inscribedRadius; break;
72 case Shape::dodecahedron: return 5.55*inscribedRadius*inscribedRadius*inscribedRadius; break;
73 default : DUNE_THROW(Dune::InvalidStateException, "Unsupported geometry");
74 }
75 }
76
77
78 //! Returns the volume of a given geometry based on the inscribed radius and the height
79 template<class Scalar>
80 40 inline Scalar volume(Shape shape, Scalar inscribedRadius, Scalar height)
81 {
82
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 switch(shape)
83 {
84 40 case Shape::cylinder: return M_PI*inscribedRadius*inscribedRadius*height; break;
85 default : DUNE_THROW(Dune::InvalidStateException, "Unsupported geometry");
86 }
87 }
88
89 } // end Dumux::PoreNetwork::Pore
90
91 #endif
92