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 | * | ||
10 | * \brief Utility functions for writing pore-network grids to vtp files. | ||
11 | */ | ||
12 | #ifndef DUMUX_TEST_IO_GRIDMANAGER_TEST_PNM_GRID_UTILITIES | ||
13 | #define DUMUX_TEST_IO_GRIDMANAGER_TEST_PNM_GRID_UTILITIES | ||
14 | |||
15 | #include "config.h" | ||
16 | |||
17 | #include <vector> | ||
18 | #include <dune/grid/io/file/vtk.hh> | ||
19 | |||
20 | namespace Dumux::PoreNetwork { | ||
21 | |||
22 | //! Extract the vertex parameters from a pore network. | ||
23 | template<class GridView, class GridData> | ||
24 | 28 | std::vector<std::vector<double>> getVertexParams(const GridView& gridView, const GridData& gridData) | |
25 | { | ||
26 | 28 | const auto someVertex = *(vertices(gridView).begin()); | |
27 | 28 | const auto numVertexParams = gridData.parameters(someVertex).size(); | |
28 | 56 | std::vector<std::vector<double>> result(numVertexParams); | |
29 | |||
30 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 14 times.
|
116 | for(int i = 0; i < result.size(); ++i) |
31 |
1/2✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
|
176 | result[i].resize(gridView.size(1)); |
32 | |||
33 |
8/10✓ Branch 1 taken 1413 times.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 1628 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 216 times.
✓ Branch 6 taken 1413 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 216 times.
✓ Branch 10 taken 216 times.
✗ Branch 11 not taken.
|
4148 | for(const auto& vertex : vertices(gridView)) |
34 | { | ||
35 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 1628 times.
✓ Branch 3 taken 216 times.
✗ Branch 4 not taken.
|
3256 | const auto vIdx = gridView.indexSet().index(vertex); |
36 |
4/4✓ Branch 0 taken 6100 times.
✓ Branch 1 taken 1628 times.
✓ Branch 2 taken 6100 times.
✓ Branch 3 taken 1628 times.
|
27656 | for(int i = 0; i < result.size(); ++i) |
37 |
1/2✓ Branch 1 taken 6100 times.
✗ Branch 2 not taken.
|
12200 | result[i][vIdx] = gridData.parameters(vertex)[i]; |
38 | } | ||
39 | |||
40 | 28 | return result; | |
41 | } | ||
42 | |||
43 | //! Extract the element parameters from a pore network. | ||
44 | template<class GridView, class GridData> | ||
45 | 28 | std::vector<std::vector<double>> getElementParams(const GridView& gridView, const GridData& gridData) | |
46 | { | ||
47 | 28 | const auto someElement = *(elements(gridView).begin()); | |
48 | 28 | const auto numElementParams = gridData.parameters(someElement).size(); | |
49 | 56 | std::vector<std::vector<double>> result(numElementParams); | |
50 | |||
51 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 14 times.
|
116 | for(int i = 0; i < result.size(); ++i) |
52 |
1/2✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
|
176 | result[i].resize(gridView.size(0)); |
53 | |||
54 |
8/10✓ Branch 1 taken 10949 times.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 12573 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 1625 times.
✓ Branch 6 taken 10949 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1625 times.
✓ Branch 10 taken 1625 times.
✗ Branch 11 not taken.
|
31674 | for(const auto& element : elements(gridView)) |
55 | { | ||
56 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 12573 times.
✓ Branch 3 taken 1625 times.
✗ Branch 4 not taken.
|
25146 | const auto eIdx = gridView.indexSet().index(element); |
57 |
4/4✓ Branch 0 taken 49820 times.
✓ Branch 1 taken 12573 times.
✓ Branch 2 taken 49820 times.
✓ Branch 3 taken 12573 times.
|
224426 | for(int i = 0; i < result.size(); ++i) |
58 |
1/2✓ Branch 1 taken 49820 times.
✗ Branch 2 not taken.
|
99640 | result[i][eIdx] = gridData.parameters(element)[i]; |
59 | } | ||
60 | |||
61 | 28 | return result; | |
62 | } | ||
63 | |||
64 | //! Write a pore-network grid to a vtp file. | ||
65 | template<class GridView, class GridData> | ||
66 | 28 | void writeToVtk(const std::string& fileName, const GridView& gridView, const GridData& gridData) | |
67 | { | ||
68 | using VTKWriter = Dune::VTKWriter<GridView>; | ||
69 | 112 | auto poreParameterNames = gridData->vertexParameterNames(); | |
70 |
3/6✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
|
112 | auto throatParameterNames = gridData->elementParameterNames(); |
71 | |||
72 | // make first letter of names lower case for consistency | ||
73 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 14 times.
|
260 | for (auto& name : poreParameterNames) |
74 | 264 | name[0] = std::tolower(name[0]); | |
75 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 14 times.
|
260 | for (auto& name : throatParameterNames) |
76 | 264 | name[0] = std::tolower(name[0]); | |
77 | |||
78 |
2/4✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
|
84 | const auto vertexData = getVertexParams(gridView, *gridData); |
79 |
2/4✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
|
84 | const auto elementData = getElementParams(gridView, *gridData); |
80 | |||
81 |
1/2✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
|
28 | VTKWriter vtkWriter(gridView); |
82 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 14 times.
|
144 | for(int i = 0; i < poreParameterNames.size(); ++i) |
83 |
3/6✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 44 times.
✗ Branch 8 not taken.
|
264 | vtkWriter.addVertexData(vertexData[i], poreParameterNames[i]); |
84 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 14 times.
|
144 | for(int i = 0; i < throatParameterNames.size(); ++i) |
85 |
3/6✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 44 times.
✗ Branch 8 not taken.
|
264 | vtkWriter.addCellData(elementData[i], throatParameterNames[i]); |
86 | |||
87 |
2/4✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
|
56 | vtkWriter.write(fileName); |
88 | 28 | } | |
89 | |||
90 | } // end namespace Dumux::PoreNetwork | ||
91 | |||
92 | #endif | ||
93 |