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-FileCopyrightText: 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 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | 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 |
1/2✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 | const auto c = std::to_string(numCells); |
65 |
5/12✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 13 taken 16 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 16 times.
✗ Branch 17 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 | 16 | SolutionStorage<TypeTag> storage; | |
70 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | auto& gridManager = storage.gridManager; |
71 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | 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 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | Dune::Timer timer; |
78 | |||
79 | // create the finite volume grid geometry | ||
80 | using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; | ||
81 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | auto gridGeometry = std::make_shared<GridGeometry>(leafGridView); |
82 | |||
83 | // the problem (boundary conditions) | ||
84 | using Problem = GetPropType<TypeTag, Properties::Problem>; | ||
85 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | auto problem = std::make_shared<Problem>(gridGeometry); |
86 | |||
87 | // the solution vector | ||
88 | using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>; | ||
89 |
3/9✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 6 not taken.
|
16 | auto x = std::make_shared<SolutionVector>(gridGeometry->numDofs()); |
90 | |||
91 | // the grid variables | ||
92 | using GridVariables = GetPropType<TypeTag, Properties::GridVariables>; | ||
93 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | auto gridVariables = std::make_shared<GridVariables>(problem, gridGeometry); |
94 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | gridVariables->init(*x); |
95 | |||
96 | // create assembler & linear solver | ||
97 | using Assembler = FVAssembler<TypeTag, DiffMethod::analytic>; | ||
98 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables); |
99 | |||
100 | using LinearSolver = ILUBiCGSTABIstlSolver<LinearSolverTraits<GridGeometry>, LinearAlgebraTraitsFromAssembler<Assembler>>; | ||
101 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | auto linearSolver = std::make_shared<LinearSolver>(gridGeometry->gridView(), gridGeometry->dofMapper()); |
102 | |||
103 | // solver the linear problem | ||
104 |
4/12✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 16 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 16 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
64 | LinearPDESolver<Assembler, LinearSolver> solver(assembler, linearSolver); |
105 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | 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 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | 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 |
3/6✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
|
16 | std::vector<Scalar> exact(gridGeometry->numDofs()); |
117 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | auto fvGeometry = localView(*gridGeometry); |
118 |
2/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | const auto periodLength = getParam<Scalar>("Problem.ExactSolPeriodLength"); |
119 |
4/8✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 34016 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 16 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 34000 times.
✗ Branch 11 not taken.
|
102032 | for (const auto& element : elements(gridGeometry->gridView())) |
120 | { | ||
121 |
1/2✓ Branch 1 taken 17000 times.
✗ Branch 2 not taken.
|
51000 | fvGeometry.bindElement(element); |
122 |
2/2✓ Branch 0 taken 85000 times.
✓ Branch 1 taken 34000 times.
|
119000 | for (const auto& scv : scvs(fvGeometry)) |
123 | 85000 | exact[scv.dofIndex()] = problem->exact(scv.dofPosition(), periodLength); | |
124 | } | ||
125 | |||
126 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 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 | 32 | } | |
129 | |||
130 | // fill storage and return | ||
131 | 16 | storage.gridGeometry = gridGeometry; | |
132 | 16 | storage.solution = x; | |
133 | 16 | return storage; | |
134 | 112 | } | |
135 | |||
136 | #endif | ||
137 |