poreproperties.hh 4.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   This program is free software: you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation, either version 3 of the License, or       *
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 *****************************************************************************/
/*!
 * \file
 * \ingroup PoreNetworkModels
 * \brief This file contains functions related to calculate pore-body properties.
 */
#ifndef DUMUX_PNM_BASE_PORE_PROPERTIES_HH
#define DUMUX_PNM_BASE_PORE_PROPERTIES_HH

#include <string>
#include <dune/common/exceptions.hh>

namespace Dumux::PoreNetwork::Pore {

//! Collection of different pore-body shapes
enum class Shape
{ circle, square, cube, sphere, cylinder, tetrahedron, octahedron, icosahedron, dodecahedron };

//! Get the shape from a string description of the shape
inline std::string shapeToString(Shape s)
{
    switch (s)
    {
        case Shape::square: return "Square";
        case Shape::circle: return "Circle";
        case Shape::cube: return "Cube";
        case Shape::sphere: return "Sphere";
        case Shape::cylinder: return "Cylinder";
        case Shape::tetrahedron: return "Tetrahedron";
        case Shape::octahedron: return "Octahedron";
        case Shape::icosahedron: return "Icosahedron";
        case Shape::dodecahedron: return "Dodecahedron";
        default: DUNE_THROW(Dune::InvalidStateException, "Unknown shape!");
    }
}

//! Get the shape from a string description of the shape
inline Shape shapeFromString(const std::string& s)
{
    if (s == shapeToString(Shape::square)) return Shape::square;
    else if (s == shapeToString(Shape::circle)) return Shape::circle;
    else if (s == shapeToString(Shape::cube)) return Shape::cube;
    else if (s == shapeToString(Shape::sphere)) return Shape::sphere;
    else if (s == shapeToString(Shape::cylinder)) return Shape::cylinder;
    else if (s == shapeToString(Shape::tetrahedron)) return Shape::tetrahedron;
    else if (s == shapeToString(Shape::octahedron)) return Shape::octahedron;
    else if (s == shapeToString(Shape::icosahedron)) return Shape::icosahedron;
    else if (s == shapeToString(Shape::dodecahedron)) return Shape::dodecahedron;
    else DUNE_THROW(Dune::InvalidStateException, s << " is not a valid shape");
}


//! Returns the volume of a given geometry based on the inscribed radius
template<class Scalar>
inline Scalar volume(Shape shape, Scalar inscribedRadius)
{
    switch(shape)
    {
        case Shape::cube: return 8*inscribedRadius*inscribedRadius*inscribedRadius; break;
        case Shape::sphere: return 4.0/3.0*M_PI*inscribedRadius*inscribedRadius*inscribedRadius; break;
        case Shape::circle: return M_PI*inscribedRadius*inscribedRadius; break;
        case Shape::square: return 4.0*inscribedRadius*inscribedRadius; break;
        case Shape::tetrahedron: return 13.85*inscribedRadius*inscribedRadius*inscribedRadius; break;
        case Shape::octahedron: return 6.93*inscribedRadius*inscribedRadius*inscribedRadius; break;
        case Shape::icosahedron: return 5.05*inscribedRadius*inscribedRadius*inscribedRadius; break;
        case Shape::dodecahedron: return 5.55*inscribedRadius*inscribedRadius*inscribedRadius; break;
        default : DUNE_THROW(Dune::InvalidStateException, "Unsupported geometry");
    }
}


//! Returns the volume of a given geometry based on the inscribed radius and the height
template<class Scalar>
inline Scalar volume(Shape shape, Scalar inscribedRadius, Scalar height)
{
    switch(shape)
    {
        case Shape::cylinder: return M_PI*inscribedRadius*inscribedRadius*height; break;
        default : DUNE_THROW(Dune::InvalidStateException, "Unsupported geometry");
    }
}

} // end Dumux::PoreNetwork::Pore

#endif