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 |
|
|
* \ingroup InputOutput |
10 |
|
|
* \brief Grid manager specialization for OneDGrid |
11 |
|
|
*/ |
12 |
|
|
#ifndef DUMUX_IO_GRID_MANAGER_ONED_HH |
13 |
|
|
#define DUMUX_IO_GRID_MANAGER_ONED_HH |
14 |
|
|
|
15 |
|
|
#include <dune/grid/onedgrid.hh> |
16 |
|
|
#include <dune/grid/io/file/dgfparser/dgfoned.hh> |
17 |
|
|
|
18 |
|
|
#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH |
19 |
|
|
#include <dumux/io/grid/gridmanager_base.hh> |
20 |
|
|
#endif |
21 |
|
|
|
22 |
|
|
namespace Dumux { |
23 |
|
|
|
24 |
|
|
/*! |
25 |
|
|
* \ingroup InputOutput |
26 |
|
|
* \brief Provides a grid manager for OneDGrids |
27 |
|
|
* from information in the input file |
28 |
|
|
* |
29 |
|
|
* All keys are expected to be in group GridParameterGroup. |
30 |
|
|
* The following keys are recognized: |
31 |
|
|
* - LeftBoundary : start coordinate |
32 |
|
|
* - RightBoundary : end coordinate |
33 |
|
|
* - Cells : the number of cell |
34 |
|
|
* - RefinementType : local or copy |
35 |
|
|
* - Refinement : the number of global refines to apply initially. |
36 |
|
|
* |
37 |
|
|
*/ |
38 |
|
|
template<> |
39 |
|
✗ |
class GridManager<Dune::OneDGrid> |
40 |
|
|
: public GridManagerBase<Dune::OneDGrid> |
41 |
|
|
{ |
42 |
|
|
public: |
43 |
|
|
using Grid = Dune::OneDGrid; |
44 |
|
|
using ParentType = GridManagerBase<Grid>; |
45 |
|
|
|
46 |
|
|
/*! |
47 |
|
|
* \brief Make the grid. This is implemented by specializations of this method. |
48 |
|
|
*/ |
49 |
|
✗ |
void init(const std::string& modelParamGroup = "") |
50 |
|
|
{ |
51 |
|
|
|
52 |
|
|
// try to create it from a DGF or msh file in GridParameterGroup.File |
53 |
|
✗ |
if (hasParamInGroup(modelParamGroup, "Grid.File")) |
54 |
|
|
{ |
55 |
|
✗ |
ParentType::makeGridFromDgfFile(getParamFromGroup<std::string>(modelParamGroup, "Grid.File")); |
56 |
|
✗ |
postProcessing_(modelParamGroup); |
57 |
|
✗ |
return; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
// Look for the necessary keys to construct from the input file |
61 |
|
✗ |
else if (hasParamInGroup(modelParamGroup, "Grid.RightBoundary")) |
62 |
|
|
{ |
63 |
|
|
// The required parameters |
64 |
|
✗ |
using CoordinateType = typename Grid::ctype; |
65 |
|
✗ |
const auto leftBoundary = getParamFromGroup<CoordinateType>(modelParamGroup, "Grid.LeftBoundary", 0.0); |
66 |
|
✗ |
const auto rightBoundary = getParamFromGroup<CoordinateType>(modelParamGroup, "Grid.RightBoundary"); |
67 |
|
✗ |
const int cells = getParamFromGroup<int>(modelParamGroup, "Grid.Cells", 1); |
68 |
|
|
|
69 |
|
✗ |
ParentType::gridPtr() = std::make_shared<Grid>(cells, leftBoundary, rightBoundary); |
70 |
|
✗ |
postProcessing_(modelParamGroup); |
71 |
|
✗ |
return; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
// Look for the necessary keys to construct from the input file with just a coordinates vector |
75 |
|
✗ |
else if (hasParamInGroup(modelParamGroup, "Grid.Coordinates")) |
76 |
|
|
{ |
77 |
|
✗ |
const auto coordinates = getParamFromGroup<std::vector<typename Grid::ctype>>(modelParamGroup, "Grid.Coordinates"); |
78 |
|
✗ |
ParentType::gridPtr() = std::make_shared<Grid>(coordinates); |
79 |
|
✗ |
postProcessing_(modelParamGroup); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
// Didn't find a way to construct the grid |
83 |
|
|
else |
84 |
|
|
{ |
85 |
|
✗ |
const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + "."; |
86 |
|
✗ |
DUNE_THROW(ParameterException, "Please supply one of the parameters " |
87 |
|
|
<< prefix + "Grid.RightBoundary" |
88 |
|
|
<< ", or " << prefix + "Grid.Coordinates" |
89 |
|
|
<< ", or a grid file in " << prefix + "Grid.File"); |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
/*! |
94 |
|
|
* \brief Call loadBalance() function of the grid. OneDGrid is not parallel an thus cannot communicate. |
95 |
|
|
*/ |
96 |
|
✗ |
void loadBalance() {} |
97 |
|
|
|
98 |
|
|
private: |
99 |
|
|
/*! |
100 |
|
|
* \brief Do some operatrion after making the grid, like global refinement |
101 |
|
|
*/ |
102 |
|
✗ |
void postProcessing_(const std::string& modelParamGroup) |
103 |
|
|
{ |
104 |
|
|
// Set refinement type |
105 |
|
✗ |
const auto refType = getParamFromGroup<std::string>(modelParamGroup, "Grid.RefinementType", "Local"); |
106 |
|
✗ |
if (refType == "Local") |
107 |
|
✗ |
ParentType::grid().setRefinementType(Dune::OneDGrid::RefinementType::LOCAL); |
108 |
|
✗ |
else if (refType == "Copy") |
109 |
|
✗ |
ParentType::grid().setRefinementType(Dune::OneDGrid::RefinementType::COPY); |
110 |
|
|
else |
111 |
|
✗ |
DUNE_THROW(Dune::IOError, "OneGrid only supports 'Local' or 'Copy' as refinement type. Not '"<< refType<<"'!"); |
112 |
|
|
|
113 |
|
|
// Check if should refine the grid |
114 |
|
✗ |
ParentType::maybeRefineGrid(modelParamGroup); |
115 |
|
✗ |
loadBalance(); |
116 |
|
✗ |
} |
117 |
|
|
}; |
118 |
|
|
|
119 |
|
|
} // end namespace Dumux |
120 |
|
|
|
121 |
|
|
#endif |
122 |
|
|
|