version 3.10-dev
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_PORE_NETWORK_DGF_WRITER_HH
13#define DUMUX_PORE_NETWORK_DGF_WRITER_HH
14
15#include <string>
16#include <iostream>
17#include <fstream>
18
19namespace Dumux::PoreNetwork {
20
25template<class GridView, class GridData>
26void writeDgf(const std::string& fileName, const GridView& gridView, const GridData& gridData)
27{
28 const auto someElement = *(elements(gridView).begin());
29 const auto someVertex = *(vertices(gridView).begin());
30 const auto numVertexParams = gridData.parameters(someVertex).size();
31 const auto numElementParams = gridData.parameters(someElement).size();
32
33 std::ofstream dgfFile(fileName);
34 dgfFile << "DGF\nVertex % Coordinates, volumes and boundary flags of the pore bodies\nparameters " << numVertexParams << "\n";
35 dgfFile << "% Vertex parameters: ";
36 for (const auto& p : gridData.vertexParameterNames())
37 dgfFile << p << " ";
38 dgfFile << "\n% Element parameters: ";
39 for (const auto& p : gridData.elementParameterNames())
40 dgfFile << p << " ";
41 dgfFile << std::endl;
42
43 for (const auto& vertex : vertices(gridView))
44 {
45 dgfFile << vertex.geometry().center() << " ";
46
47 const auto& params = gridData.parameters(vertex);
48 for (int i = 0; i < params.size(); ++i)
49 {
50 dgfFile << params[i];
51
52 if (i < params.size() - 1)
53 dgfFile << " ";
54 }
55
56 dgfFile << std::endl;
57 }
58
59 dgfFile << "#\nSIMPLEX % Connections of the pore bodies (pore throats)\nparameters " << numElementParams << "\n";
60
61 for (const auto& element : elements(gridView))
62 {
63 dgfFile << gridView.indexSet().subIndex(element, 0, 1) << " ";
64 dgfFile << gridView.indexSet().subIndex(element, 1, 1) << " ";
65
66 const auto& params = gridData.parameters(element);
67 for (int i = 0; i < params.size(); ++i)
68 {
69 dgfFile << params[i];
70
71 if (i < params.size() - 1)
72 dgfFile << " ";
73 }
74
75 dgfFile << std::endl;
76 }
77
78 dgfFile << "#";
79}
80
81} // end namespace Dumux::PoreNetwork
82
83#endif
Class for grid data attached to dgf or gmsh grid files.
Definition: porenetwork/griddata.hh:44
const std::vector< std::string > & vertexParameterNames() const
Returns the names of the vertex parameters.
Definition: porenetwork/griddata.hh:289
const std::vector< std::string > & elementParameterNames() const
Returns the names of the element parameters.
Definition: porenetwork/griddata.hh:295
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:86
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:26
Definition: discretization/porenetwork/fvelementgeometry.hh:24