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 OnePTests | ||
10 | * \brief The solver of the single-phase convergence test | ||
11 | */ | ||
12 | #ifndef DUMUX_INCOMPRESSIBLE_ONEP_CONVERGENCETEST_SOLVER_HH | ||
13 | #define DUMUX_INCOMPRESSIBLE_ONEP_CONVERGENCETEST_SOLVER_HH | ||
14 | |||
15 | #include <iostream> | ||
16 | #include <string> | ||
17 | |||
18 | #include <dune/common/timer.hh> | ||
19 | #include <dune/grid/io/file/vtk.hh> | ||
20 | |||
21 | #include <dumux/linear/istlsolvers.hh> | ||
22 | #include <dumux/linear/linearsolvertraits.hh> | ||
23 | #include <dumux/linear/linearalgebratraits.hh> | ||
24 | #include <dumux/linear/pdesolver.hh> | ||
25 | |||
26 | #include <dumux/common/properties.hh> | ||
27 | #include <dumux/common/parameters.hh> | ||
28 | |||
29 | #include <dumux/io/vtkoutputmodule.hh> | ||
30 | #include <dumux/io/grid/gridmanager_base.hh> | ||
31 | |||
32 | #include <dumux/assembly/fvassembler.hh> | ||
33 | #include <dumux/assembly/diffmethod.hh> | ||
34 | |||
35 | #include "properties.hh" | ||
36 | |||
37 | // return type of solveRefinementLevel() | ||
38 | // stores the grid geometry and the produced solution | ||
39 | template<class TypeTag> | ||
40 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
32 | struct SolutionStorage |
41 | { | ||
42 | using Grid = Dumux::GetPropType<TypeTag, Dumux::Properties::Grid>; | ||
43 | using GridGeometry = Dumux::GetPropType<TypeTag, Dumux::Properties::GridGeometry>; | ||
44 | using SolutionVector = Dumux::GetPropType<TypeTag, Dumux::Properties::SolutionVector>; | ||
45 | |||
46 | public: | ||
47 | Dumux::GridManager<Grid> gridManager; | ||
48 | std::shared_ptr<GridGeometry> gridGeometry; | ||
49 | std::shared_ptr<SolutionVector> solution; | ||
50 | }; | ||
51 | |||
52 | /*! | ||
53 | * \brief Solves the problem for a given number of cells per direction. | ||
54 | * \param numCells the number of cells per direction to be used | ||
55 | * \return returns an object of SolutionStorage, which carries | ||
56 | * the grid and the solution after solving the problem | ||
57 | */ | ||
58 | template<class TypeTag> | ||
59 | 16 | SolutionStorage<TypeTag> solveRefinementLevel(int numCells) | |
60 | { | ||
61 | using namespace Dumux; | ||
62 | |||
63 | // adapt the parameter tree to carry given number of cells | ||
64 | 16 | const auto c = std::to_string(numCells); | |
65 |
13/38✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 16 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 16 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 21 taken 16 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 16 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 16 times.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✓ Branch 34 taken 16 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 16 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 16 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 16 times.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
|
80 | Parameters::init([&c] (auto& tree) { tree["Grid.Cells"] = c + " " + c; }); |
66 | |||
67 | // the returned object of this function | ||
68 | // we create the grid in there directly | ||
69 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | SolutionStorage<TypeTag> storage; |
70 | 16 | auto& gridManager = storage.gridManager; | |
71 |
5/12✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
32 | gridManager.init(); |
72 | |||
73 | // we compute on the leaf grid view | ||
74 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | const auto& leafGridView = gridManager.grid().leafGridView(); |
75 | |||
76 | // start timer | ||
77 | 16 | Dune::Timer timer; | |
78 | |||
79 | // create the finite volume grid geometry | ||
80 | using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; | ||
81 |
2/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
32 | auto gridGeometry = std::make_shared<GridGeometry>(leafGridView); |
82 | |||
83 | // the problem (boundary conditions) | ||
84 | using Problem = GetPropType<TypeTag, Properties::Problem>; | ||
85 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
|
32 | auto problem = std::make_shared<Problem>(gridGeometry); |
86 | |||
87 | // the solution vector | ||
88 | using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>; | ||
89 |
4/12✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 16 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
56 | auto x = std::make_shared<SolutionVector>(gridGeometry->numDofs()); |
90 | |||
91 | // the grid variables | ||
92 | using GridVariables = GetPropType<TypeTag, Properties::GridVariables>; | ||
93 |
2/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
32 | auto gridVariables = std::make_shared<GridVariables>(problem, gridGeometry); |
94 |
3/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
|
48 | gridVariables->init(*x); |
95 | |||
96 | // create assembler & linear solver | ||
97 | using Assembler = FVAssembler<TypeTag, DiffMethod::analytic>; | ||
98 |
2/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
32 | auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables); |
99 | |||
100 | using LinearSolver = ILUBiCGSTABIstlSolver<LinearSolverTraits<GridGeometry>, LinearAlgebraTraitsFromAssembler<Assembler>>; | ||
101 |
6/14✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 16 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 16 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
96 | auto linearSolver = std::make_shared<LinearSolver>(gridGeometry->gridView(), gridGeometry->dofMapper()); |
102 | |||
103 | // solver the linear problem | ||
104 |
8/20✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 16 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 16 times.
✓ Branch 19 taken 16 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 16 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
|
80 | LinearPDESolver<Assembler, LinearSolver> solver(assembler, linearSolver); |
105 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
32 | solver.solve(*x); |
106 | |||
107 | // maybe output result to vtk | ||
108 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
|
16 | if (getParam<bool>("IO.WriteVTK", false)) |
109 | { | ||
110 |
8/16✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 16 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 16 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 16 times.
✗ Branch 23 not taken.
|
48 | VtkOutputModule<GridVariables, SolutionVector> vtkWriter(*gridVariables, *x, problem->name()); |
111 | using IOFields = GetPropType<TypeTag, Properties::IOFields>; | ||
112 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | IOFields::initOutputModule(vtkWriter); // Add model specific output fields |
113 | |||
114 | // add exact solution | ||
115 | using Scalar = GetPropType<TypeTag, Properties::Scalar>; | ||
116 |
4/10✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 16 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
72 | std::vector<Scalar> exact(gridGeometry->numDofs()); |
117 |
3/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
|
48 | auto fvGeometry = localView(*gridGeometry); |
118 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | const auto periodLength = getParam<Scalar>("Problem.ExactSolPeriodLength"); |
119 |
5/10✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 34016 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 34000 times.
✗ Branch 13 not taken.
|
68048 | for (const auto& element : elements(gridGeometry->gridView())) |
120 | { | ||
121 |
1/2✓ Branch 1 taken 34000 times.
✗ Branch 2 not taken.
|
34000 | fvGeometry.bindElement(element); |
122 |
4/4✓ Branch 0 taken 85000 times.
✓ Branch 1 taken 34000 times.
✓ Branch 2 taken 68000 times.
✓ Branch 3 taken 17000 times.
|
204000 | for (const auto& scv : scvs(fvGeometry)) |
123 | 255000 | exact[scv.dofIndex()] = problem->exact(scv.dofPosition(), periodLength); | |
124 | } | ||
125 | |||
126 |
5/12✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 16 times.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
32 | vtkWriter.addField(exact, "p_exact"); |
127 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | vtkWriter.write(1.0); |
128 | } | ||
129 | |||
130 | // fill storage and return | ||
131 | 16 | storage.gridGeometry = gridGeometry; | |
132 | 16 | storage.solution = x; | |
133 | 16 | return storage; | |
134 | } | ||
135 | |||
136 | #endif | ||
137 |