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-FileCopyrightText: 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 Class for sub grid data attached to dgf or gmsh grid files | ||
11 | */ | ||
12 | #ifndef DUMUX_IO_GRID_PORENETWORK_SUBGRID_DATA_HH | ||
13 | #define DUMUX_IO_GRID_PORENETWORK_SUBGRID_DATA_HH | ||
14 | |||
15 | #include <vector> | ||
16 | #include <memory> | ||
17 | #include "griddata.hh" | ||
18 | |||
19 | namespace Dumux::PoreNetwork { | ||
20 | |||
21 | /*! | ||
22 | * \ingroup PoreNetworkModels | ||
23 | * \brief wrapper for subgrid data | ||
24 | */ | ||
25 | template<class HostGrid, class SubGrid> | ||
26 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | class SubGridData |
27 | { | ||
28 | static constexpr int dim = SubGrid::dimension; | ||
29 | static constexpr int dimWorld = SubGrid::dimensionworld; | ||
30 | using Intersection = typename SubGrid::LeafIntersection; | ||
31 | using Element = typename SubGrid::template Codim<0>::Entity; | ||
32 | using Vertex = typename SubGrid::template Codim<dim>::Entity; | ||
33 | using GridView = typename SubGrid::LeafGridView; | ||
34 | using GlobalPosition = typename Element::Geometry::GlobalCoordinate; | ||
35 | using SmallLocalIndex = typename IndexTraits<GridView>::SmallLocalIndex; | ||
36 | |||
37 | public: | ||
38 | 3 | SubGridData(const SubGrid& subGrid, | |
39 | std::shared_ptr<const GridData<HostGrid>> hostGridData) | ||
40 | 3 | : subGrid_(subGrid) | |
41 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | , hostGridData_(hostGridData) |
42 | {} | ||
43 | |||
44 | /*! | ||
45 | * \brief Call the parameters function of the DGF grid pointer if available for vertex data | ||
46 | * \note You can only pass vertices that exist on level 0! | ||
47 | */ | ||
48 | 5761 | const std::vector<double>& parameters(const Vertex& vertex) const | |
49 |
1/2✓ Branch 5 taken 864 times.
✗ Branch 6 not taken.
|
5761 | { return hostGridData_->parameters(vertex.impl().hostEntity()); } |
50 | |||
51 | /*! | ||
52 | * \brief Call the parameters function of the DGF grid pointer if available for element data | ||
53 | */ | ||
54 | 17700 | const std::vector<double>& parameters(const Element& element) const | |
55 |
4/7✓ Branch 5 taken 6500 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 1 taken 2184 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1007 times.
|
17700 | { return hostGridData_->parameters(element.impl().hostEntity()); } |
56 | |||
57 | /*! | ||
58 | * \brief Returns the value of an element parameter | ||
59 | */ | ||
60 | 1625 | auto getParameter(const Element& element, const std::string& param) const | |
61 |
1/2✓ Branch 1 taken 1625 times.
✗ Branch 2 not taken.
|
1625 | { return hostGridData_->getParameter(element.impl().hostEntity(), param); } |
62 | |||
63 | /*! | ||
64 | * \brief Returns the value of an vertex parameter | ||
65 | */ | ||
66 | 1116 | auto getParameter(const Vertex& vertex, const std::string& param) const | |
67 |
2/6✓ Branch 1 taken 560 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 556 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
1116 | { return hostGridData_->getParameter(vertex.impl().hostEntity(), param); } |
68 | |||
69 | /*! | ||
70 | * \brief Call the parameters function of the DGF grid pointer if available | ||
71 | */ | ||
72 | template <class GridImp, class IntersectionImp> | ||
73 | const Dune::DGFBoundaryParameter::type& parameters(const Dune::Intersection<GridImp, IntersectionImp>& intersection) const | ||
74 | { return hostGridData_->parameters(intersection); } | ||
75 | |||
76 | /*! | ||
77 | * \brief Computes and returns the label of a given throat | ||
78 | * | ||
79 | * \param element The element (throat) | ||
80 | */ | ||
81 | auto throatLabel(const Element& element) const | ||
82 | { return hostGridData_->throatLabel(element.impl().hostEntity()); } | ||
83 | |||
84 | /*! | ||
85 | * \brief Returns the boundary face marker index at given position | ||
86 | * | ||
87 | * \param pos The current position | ||
88 | */ | ||
89 | int boundaryFaceMarkerAtPos(const GlobalPosition& pos) const | ||
90 | { return hostGridData_->boundaryFaceMarkerAtPos(pos); } | ||
91 | |||
92 | /*! | ||
93 | * \brief Returns the coordination numbers for all pore bodies. | ||
94 | */ | ||
95 | 5 | std::vector<SmallLocalIndex> getCoordinationNumbers() const | |
96 | { | ||
97 | 5 | const auto gridView = subGrid_.leafGridView(); | |
98 | |||
99 |
1/2✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
|
5 | std::vector<SmallLocalIndex> coordinationNumbers(gridView.size(dim), 0); |
100 | |||
101 |
3/4✓ Branch 1 taken 8007 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8007 times.
✓ Branch 4 taken 5 times.
|
16019 | for (const auto &element : elements(gridView)) |
102 | { | ||
103 |
2/2✓ Branch 0 taken 16014 times.
✓ Branch 1 taken 8007 times.
|
24021 | for (SmallLocalIndex vIdxLocal = 0; vIdxLocal < 2; ++vIdxLocal) |
104 | { | ||
105 |
1/2✓ Branch 1 taken 16014 times.
✗ Branch 2 not taken.
|
16014 | const auto vIdxGlobal = gridView.indexSet().subIndex(element, vIdxLocal, dim); |
106 | 16014 | coordinationNumbers[vIdxGlobal] += 1; | |
107 | } | ||
108 | } | ||
109 | |||
110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (std::any_of(coordinationNumbers.begin(), coordinationNumbers.end(), [](auto i){ return i == 0; })) |
111 | ✗ | DUNE_THROW(Dune::InvalidStateException, "One of the pores is not connected to another pore. SanitizeGrid will not help in this case. Check your grid file"); | |
112 | |||
113 | 5 | return coordinationNumbers; | |
114 | ✗ | } | |
115 | |||
116 | /*! | ||
117 | * \brief Return the index for a given parameter name | ||
118 | */ | ||
119 | 9587 | int parameterIndex(const std::string& paramName) const | |
120 |
16/34✓ Branch 1 taken 2184 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2184 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2185 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1007 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1008 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1008 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 1 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 1 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 1 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 1 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 49 taken 1 times.
✗ Branch 50 not taken.
|
9587 | { return hostGridData_->parameterIndex(paramName); } |
121 | |||
122 | /*! | ||
123 | * \brief Return the parameter group | ||
124 | * \todo For now we don't support two different parameter groups for the subgrids | ||
125 | */ | ||
126 | 19 | const std::string& paramGroup() const | |
127 |
4/16✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 13 taken 5 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 5 times.
✗ Branch 21 not taken.
✓ Branch 24 taken 2 times.
✗ Branch 25 not taken.
|
19 | { return hostGridData_->paramGroup(); } |
128 | |||
129 | /*! | ||
130 | * \brief Return if a given element parameter is provided by the grid | ||
131 | */ | ||
132 | 4 | bool gridHasElementParameter(const std::string& param) const | |
133 | 4 | { return hostGridData_->gridHasElementParameter(param); } | |
134 | |||
135 | /*! | ||
136 | * \brief Return if a given vertex parameter is provided by the grid | ||
137 | */ | ||
138 | 2 | bool gridHasVertexParameter(const std::string& param) const | |
139 | 2 | { return hostGridData_->gridHasVertexParameter(param); } | |
140 | |||
141 | /*! | ||
142 | * \brief Returns the names of the vertex parameters | ||
143 | */ | ||
144 | 1 | const std::vector<std::string>& vertexParameterNames() const | |
145 | 1 | { return hostGridData_->vertexParameterNames() ; } | |
146 | |||
147 | /*! | ||
148 | * \brief Returns the names of the element parameters | ||
149 | */ | ||
150 | 1 | const std::vector<std::string>& elementParameterNames() const | |
151 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | { return hostGridData_->elementParameterNames() ; } |
152 | |||
153 | private: | ||
154 | const SubGrid& subGrid_; | ||
155 | std::shared_ptr<const GridData<HostGrid>> hostGridData_; | ||
156 | }; | ||
157 | |||
158 | } // end namespace Dumux::PoreNetwork | ||
159 | |||
160 | #endif | ||
161 |