version 3.10-dev
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// 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_ASSEMBLY_INITIAL_SOLUTION_HH
13#define DUMUX_ASSEMBLY_INITIAL_SOLUTION_HH
14
15#include <vector>
16#include <type_traits>
17
19
20namespace Dumux {
21
26template<class SolutionVector, class Problem>
27void assembleInitialSolution(SolutionVector& sol, const Problem& problem)
28{
29 const auto& gg = problem.gridGeometry();
30 using GridGeometry = std::decay_t<decltype(gg)>;
31
32 // box method
33 if constexpr (GridGeometry::discMethod == DiscretizationMethods::box)
34 {
35 constexpr int dim = GridGeometry::GridView::dimension;
36 const auto numDofs = gg.vertexMapper().size();
37 const auto numVert = gg.gridView().size(dim);
38 sol.resize(numDofs);
39
40 // if there are more dofs than vertices (enriched nodal dofs), we have to
41 // call initial for all dofs at the nodes, coming from all neighboring elements.
42 if (numDofs != numVert)
43 {
44 std::vector<bool> dofVisited(numDofs, false);
45 for (const auto& element : elements(gg.gridView()))
46 {
47 for (int i = 0; i < element.subEntities(dim); ++i)
48 {
49 const auto dofIdxGlobal = gg.vertexMapper().subIndex(element, i, dim);
50 // forward to implementation if value at dof is not set yet
51 if (!dofVisited[dofIdxGlobal])
52 {
53 sol[dofIdxGlobal] = problem.initial(element.template subEntity<dim>(i));
54 dofVisited[dofIdxGlobal] = true;
55 }
56 }
57 }
58 }
59
60 // otherwise we directly loop over the vertices
61 else
62 {
63 for (const auto& vertex : vertices(gg.gridView()))
64 sol[gg.vertexMapper().index(vertex)] = problem.initial(vertex);
65 }
66 }
67
68 // staggered methods
69 else if constexpr (GridGeometry::discMethod == DiscretizationMethods::staggered)
70 {
71 problem.applyInitialSolution(sol);
72 }
73
74 // default: cell-centered methods
75 else
76 {
77 sol.resize(gg.numDofs());
78 for (const auto& element : elements(gg.gridView()))
79 sol[gg.elementMapper().index(element)] = problem.initial(element);
80 }
81}
82
87template<class SolutionVector, class Problem>
88SolutionVector makeInitialSolution(const Problem& problem)
89{
90 SolutionVector sol;
91 assembleInitialSolution(sol, problem);
92 return sol;
93}
94
95} // end namespace Dumux
96
97#endif
void assembleInitialSolution(SolutionVector &sol, const Problem &problem)
Set a solution vector to the initial solution provided by the problem.
Definition: initialsolution.hh:27
SolutionVector makeInitialSolution(const Problem &problem)
Create a solution vector filled with the initial solution provided by the problem.
Definition: initialsolution.hh:88
The available discretization methods in Dumux.
constexpr Box box
Definition: method.hh:147
constexpr Staggered staggered
Definition: method.hh:149
Definition: adapt.hh:17