3.6-git
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
38template<class SolutionVector, class Problem>
39void assembleInitialSolution(SolutionVector& sol, const Problem& problem)
40{
41 const auto& gg = problem.gridGeometry();
42 using GridGeometry = std::decay_t<decltype(gg)>;
43
44 // box method
45 if constexpr (GridGeometry::discMethod == DiscretizationMethods::box)
46 {
47 constexpr int dim = GridGeometry::GridView::dimension;
48 const auto numDofs = gg.vertexMapper().size();
49 const auto numVert = gg.gridView().size(dim);
50 sol.resize(numDofs);
51
52 // if there are more dofs than vertices (enriched nodal dofs), we have to
53 // call initial for all dofs at the nodes, coming from all neighboring elements.
54 if (numDofs != numVert)
55 {
56 std::vector<bool> dofVisited(numDofs, false);
57 for (const auto& element : elements(gg.gridView()))
58 {
59 for (int i = 0; i < element.subEntities(dim); ++i)
60 {
61 const auto dofIdxGlobal = gg.vertexMapper().subIndex(element, i, dim);
62 // forward to implementation if value at dof is not set yet
63 if (!dofVisited[dofIdxGlobal])
64 {
65 sol[dofIdxGlobal] = problem.initial(element.template subEntity<dim>(i));
66 dofVisited[dofIdxGlobal] = true;
67 }
68 }
69 }
70 }
71
72 // otherwise we directly loop over the vertices
73 else
74 {
75 for (const auto& vertex : vertices(gg.gridView()))
76 sol[gg.vertexMapper().index(vertex)] = problem.initial(vertex);
77 }
78 }
79
80 // staggered methods
81 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::staggered)
82 {
83 problem.applyInitialSolution(sol);
84 }
85
86 // default: cell-centered methods
87 else
88 {
89 sol.resize(gg.numDofs());
90 for (const auto& element : elements(gg.gridView()))
91 sol[gg.elementMapper().index(element)] = problem.initial(element);
92 }
93}
94
99template<class SolutionVector, class Problem>
100SolutionVector makeInitialSolution(const Problem& problem)
101{
102 SolutionVector sol;
103 assembleInitialSolution(sol, problem);
104 return sol;
105}
106
107} // end namespace Dumux
108
109#endif
The available discretization methods in Dumux.
void assembleInitialSolution(SolutionVector &sol, const Problem &problem)
Set a solution vector to the initial solution provided by the problem.
Definition: initialsolution.hh:39
SolutionVector makeInitialSolution(const Problem &problem)
Create a solution vector filled with the initial solution provided by the problem.
Definition: initialsolution.hh:100
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
constexpr Box box
Definition: method.hh:136
constexpr Staggered staggered
Definition: method.hh:138