3.4
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
dgfwriter.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_PORE_NETWORK_DGF_WRITER_HH
25#define DUMUX_PORE_NETWORK_DGF_WRITER_HH
26
27#include <string>
28#include <iostream>
29#include <fstream>
30
31namespace Dumux::PoreNetwork {
32
37template<class GridView, class GridData>
38void writeDgf(const std::string& fileName, const GridView& gridView, const GridData& gridData)
39{
40 const auto someElement = *(elements(gridView).begin());
41 const auto someVertex = *(vertices(gridView).begin());
42 const auto numVertexParams = gridData.parameters(someVertex).size();
43 const auto numElementParams = gridData.parameters(someElement).size();
44
45 std::ofstream dgfFile(fileName);
46 dgfFile << "DGF\nVertex % Coordinates, volumes and boundary flags of the pore bodies\nparameters " << numVertexParams << "\n";
47 dgfFile << "% Vertex parameters: ";
48 for (const auto& p : gridData.vertexParameterNames())
49 dgfFile << p << " ";
50 dgfFile << "\n% Element parameters: ";
51 for (const auto& p : gridData.elementParameterNames())
52 dgfFile << p << " ";
53 dgfFile << std::endl;
54
55 for (const auto& vertex : vertices(gridView))
56 {
57 dgfFile << vertex.geometry().center() << " ";
58
59 const auto& params = gridData.parameters(vertex);
60 for (int i = 0; i < params.size(); ++i)
61 {
62 dgfFile << params[i];
63
64 if (i < params.size() - 1)
65 dgfFile << " ";
66 }
67
68 dgfFile << std::endl;
69 }
70
71 dgfFile << "#\nSIMPLEX % Connections of the pore bodies (pore throats)\nparameters " << numElementParams << "\n";
72
73 for (const auto& element : elements(gridView))
74 {
75 dgfFile << gridView.indexSet().subIndex(element, 0, 1) << " ";
76 dgfFile << gridView.indexSet().subIndex(element, 1, 1) << " ";
77
78 const auto& params = gridData.parameters(element);
79 for (int i = 0; i < params.size(); ++i)
80 {
81 dgfFile << params[i];
82
83 if (i < params.size() - 1)
84 dgfFile << " ";
85 }
86
87 dgfFile << std::endl;
88 }
89
90 dgfFile << "#";
91}
92
93} // end namespace Dumux::PoreNetwork
94
95#endif
void writeDgf(const std::string &fileName, const GridView &gridView, const GridData &gridData)
Write pore-network grids with attached data to dgf file.
Definition: dgfwriter.hh:38
Definition: discretization/porenetwork/fvelementgeometry.hh:33
Class for grid data attached to dgf or gmsh grid files.
Definition: porenetwork/griddata.hh:55
const std::vector< std::string > & vertexParameterNames() const
Returns the names of the vertex parameters.
Definition: porenetwork/griddata.hh:300
const std::vector< std::string > & elementParameterNames() const
Returns the names of the element parameters.
Definition: porenetwork/griddata.hh:306
const std::vector< double > & parameters(const Vertex &vertex) const
Call the parameters function of the DGF grid pointer if available for vertex data.
Definition: porenetwork/griddata.hh:97