3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
initialsolution.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_ASSEMBLY_INITIAL_SOLUTION_HH
25#define DUMUX_ASSEMBLY_INITIAL_SOLUTION_HH
26
27#include <vector>
28#include <type_traits>
29
31
32namespace Dumux {
33
39template<class SolutionVector, class Problem>
40void assembleInitialSolution(SolutionVector& sol, const Problem& problem)
41{
42 const auto& gg = problem.gridGeometry();
43 using GridGeometry = std::decay_t<decltype(gg)>;
44
45 // box method
46 if constexpr (GridGeometry::discMethod == DiscretizationMethod::box)
47 {
48 constexpr int dim = GridGeometry::GridView::dimension;
49 const auto numDofs = gg.vertexMapper().size();
50 const auto numVert = gg.gridView().size(dim);
51 sol.resize(numDofs);
52
53 // if there are more dofs than vertices (enriched nodal dofs), we have to
54 // call initial for all dofs at the nodes, coming from all neighboring elements.
55 if (numDofs != numVert)
56 {
57 std::vector<bool> dofVisited(numDofs, false);
58 for (const auto& element : elements(gg.gridView()))
59 {
60 for (int i = 0; i < element.subEntities(dim); ++i)
61 {
62 const auto dofIdxGlobal = gg.vertexMapper().subIndex(element, i, dim);
63 // forward to implementation if value at dof is not set yet
64 if (!dofVisited[dofIdxGlobal])
65 {
66 sol[dofIdxGlobal] = problem.initial(element.template subEntity<dim>(i));
67 dofVisited[dofIdxGlobal] = true;
68 }
69 }
70 }
71 }
72
73 // otherwise we directly loop over the vertices
74 else
75 {
76 for (const auto& vertex : vertices(gg.gridView()))
77 sol[gg.vertexMapper().index(vertex)] = problem.initial(vertex);
78 }
79 }
80
81 // staggered methods
82 else if constexpr (GridGeometry::discMethod == DiscretizationMethod::staggered)
83 {
84 problem.applyInitialSolution(sol);
85 }
86
87 // default: cell-centered methods
88 else
89 {
90 sol.resize(gg.numDofs());
91 for (const auto& element : elements(gg.gridView()))
92 sol[gg.elementMapper().index(element)] = problem.initial(element);
93 }
94}
95
101template<class SolutionVector, class Problem>
102SolutionVector makeInitialSolution(const Problem& problem)
103{
104 SolutionVector sol;
105 assembleInitialSolution(sol, problem);
106 return sol;
107}
108
109} // end namespace Dumux
110
111#endif
The available discretization methods in Dumux.
Definition: adapt.hh:29
void assembleInitialSolution(SolutionVector &sol, const Problem &problem)
Definition: initialsolution.hh:40
SolutionVector makeInitialSolution(const Problem &problem)
Definition: initialsolution.hh:102