version 3.11-dev
Loading...
Searching...
No Matches
gridmanager_oned.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-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_IO_GRID_MANAGER_ONED_HH
14#define DUMUX_IO_GRID_MANAGER_ONED_HH
15
16#include <dune/grid/onedgrid.hh>
17#include <dune/grid/io/file/dgfparser/dgfoned.hh>
18
19#ifndef DUMUX_IO_GRID_MANAGER_BASE_HH
21#endif
22
23namespace Dumux {
24
41template<>
42class GridManager<Dune::OneDGrid>
43: public GridManagerBase<Dune::OneDGrid>
44{
45public:
46 using Grid = Dune::OneDGrid;
48
52 void init(const std::string& modelParamGroup = "")
53 {
54
55 // First, try to create it from a DGF file in GridParameterGroup.File
56 if (hasParamInGroup(modelParamGroup, "Grid.File"))
57 {
59 postProcessing_(modelParamGroup);
60 return;
61 }
62
63 // Then look for the necessary keys to construct from the input file
64 else if (hasParamInGroup(modelParamGroup, "Grid.RightBoundary"))
65 {
66 // The required parameters
67 using CoordinateType = typename Grid::ctype;
68 const auto leftBoundary = getParamFromGroup<CoordinateType>(modelParamGroup, "Grid.LeftBoundary", 0.0);
69 const auto rightBoundary = getParamFromGroup<CoordinateType>(modelParamGroup, "Grid.RightBoundary");
70 const int cells = getParamFromGroup<int>(modelParamGroup, "Grid.Cells", 1);
71
72 ParentType::gridPtr() = std::make_shared<Grid>(cells, leftBoundary, rightBoundary);
73 postProcessing_(modelParamGroup);
74 return;
75 }
76
77 // Then look for the necessary keys to construct from the input file with just a coordinates vector
78 else if (hasParamInGroup(modelParamGroup, "Grid.Coordinates"))
79 {
80 const auto coordinates = getParamFromGroup<std::vector<typename Grid::ctype>>(modelParamGroup, "Grid.Coordinates");
81 ParentType::gridPtr() = std::make_shared<Grid>(coordinates);
82 postProcessing_(modelParamGroup);
83 }
84
85 // Didn't find a way to construct the grid
86 else
87 {
88 const auto prefix = modelParamGroup.empty() ? modelParamGroup : modelParamGroup + ".";
89 DUNE_THROW(ParameterException, "Please supply one of the parameters "
90 << prefix + "Grid.RightBoundary"
91 << ", or " << prefix + "Grid.Coordinates"
92 << ", or a grid file in " << prefix + "Grid.File");
93 }
94 }
95
99 void loadBalance() {}
100
101private:
105 void postProcessing_(const std::string& modelParamGroup)
106 {
107 // Set refinement type
108 const auto refType = getParamFromGroup<std::string>(modelParamGroup, "Grid.RefinementType", "Local");
109 if (refType == "Local")
110 ParentType::grid().setRefinementType(Dune::OneDGrid::RefinementType::LOCAL);
111 else if (refType == "Copy")
112 ParentType::grid().setRefinementType(Dune::OneDGrid::RefinementType::COPY);
113 else
114 DUNE_THROW(Dune::IOError, "OneGrid only supports 'Local' or 'Copy' as refinement type. Not '"<< refType<<"'!");
115
116 // Check if should refine the grid
117 ParentType::maybeRefineGrid(modelParamGroup);
118 loadBalance();
119 }
120};
121
122} // end namespace Dumux
123
124#endif
void init(const std::string &modelParamGroup="")
Make the grid. This is implemented by specializations of this method.
Definition gridmanager_oned.hh:52
void loadBalance()
Call loadBalance() function of the grid. OneDGrid is not parallel an thus cannot communicate.
Definition gridmanager_oned.hh:99
GridManagerBase< Grid > ParentType
Definition gridmanager_oned.hh:47
Dune::OneDGrid Grid
Definition gridmanager_oned.hh:46
The grid manager base interface (public) and methods common to most grid manager specializations (pro...
Definition gridmanager_base.hh:56
void makeGridFromDgfFile(const std::string &fileName)
Definition gridmanager_base.hh:265
void loadBalance()
Definition gridmanager_base.hh:98
std::shared_ptr< Grid > & gridPtr()
Definition gridmanager_base.hh:163
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition gridmanager_base.hh:344
Exception thrown if a run-time parameter is not specified correctly.
Definition exceptions.hh:48
Provides a grid manager for all supported grid managers with input file interfaces....
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:149
bool hasParamInGroup(const std::string &paramGroup, const std::string &param)
Check whether a key exists in the parameter tree with a model group prefix.
Definition parameters.hh:165
Definition adapt.hh:17
Definition common/pdesolver.hh:24