3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
test/porousmediumflow/1p/implicit/convergence/solver.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_INCOMPRESSIBLE_ONEP_CONVERGENCETEST_SOLVER_HH
25#define DUMUX_INCOMPRESSIBLE_ONEP_CONVERGENCETEST_SOLVER_HH
26
27#include <iostream>
28#include <string>
29
30#include <dune/common/timer.hh>
31#include <dune/grid/io/file/dgfparser/dgfexception.hh>
32#include <dune/grid/io/file/vtk.hh>
33
36
39
42
45
46#include "problem.hh"
47
48// return type of solveRefinementLevel()
49// stores the grid geometry and the produced solution
50template<class TypeTag>
52{
56
57public:
59 std::shared_ptr<GridGeometry> gridGeometry;
60 std::shared_ptr<SolutionVector> solution;
61};
62
69template<class TypeTag>
71{
72 using namespace Dumux;
73
74 // adapt the parameter tree to carry given number of cells
75 const auto c = std::to_string(numCells);
76 Parameters::init([&c] (auto& tree) { tree["Grid.Cells"] = c + " " + c; });
77
78 // the returned object of this function
79 // we create the grid in there directly
81 auto& gridManager = storage.gridManager;
82 gridManager.init();
83
84 // we compute on the leaf grid view
85 const auto& leafGridView = gridManager.grid().leafGridView();
86
87 // start timer
88 Dune::Timer timer;
89
90 // create the finite volume grid geometry
92 auto gridGeometry = std::make_shared<GridGeometry>(leafGridView);
93 gridGeometry->update();
94
95 // the problem (boundary conditions)
97 auto problem = std::make_shared<Problem>(gridGeometry);
98
99 // the solution vector
101 auto x = std::make_shared<SolutionVector>(gridGeometry->numDofs());
102
103 // the grid variables
105 auto gridVariables = std::make_shared<GridVariables>(problem, gridGeometry);
106 gridVariables->init(*x);
107
108 // create assembler & linear solver
110 auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables);
111
113 auto linearSolver = std::make_shared<LinearSolver>();
114
115 // solver the linear problem
116 LinearPDESolver<Assembler, LinearSolver> solver(assembler, linearSolver);
117 solver.solve(*x);
118
119 // maybe output result to vtk
120 if (getParam<bool>("IO.WriteVTK", false))
121 {
122 VtkOutputModule<GridVariables, SolutionVector> vtkWriter(*gridVariables, *x, problem->name());
124 IOFields::initOutputModule(vtkWriter); // Add model specific output fields
125
126 // add exact solution
128 std::vector<Scalar> exact(gridGeometry->numDofs());
129
130 for (const auto& element : elements(gridGeometry->gridView()))
131 {
132 auto fvGeometry = localView(*gridGeometry);
133 fvGeometry.bindElement(element);
134
135 for (const auto& scv : scvs(fvGeometry))
136 exact[scv.dofIndex()] = problem->exact(scv.dofPosition());
137 }
138
139 vtkWriter.addField(exact, "p_exact");
140 vtkWriter.write(1.0);
141 }
142
143 // fill storage and return
144 storage.gridGeometry = gridGeometry;
145 storage.solution = x;
146 return storage;
147}
148
149#endif
An enum class to define various differentiation methods available in order to compute the derivatives...
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Dumux sequential linear solver backends.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
A linear system assembler (residual and Jacobian) for finite volume schemes (box, tpfa,...
Definition: assembly/fvassembler.hh:52
The grid manager (this is the class used by the user) for all supported grid managers that constructs...
Definition: gridmanager_base.hh:312
A VTK output module to simplify writing dumux simulation data to VTK format.
Definition: io/vtkoutputmodule.hh:66
void write(double time, Dune::VTK::OutputType type=Dune::VTK::ascii)
Writing data.
Definition: io/vtkoutputmodule.hh:210
void addField(const Vector &v, const std::string &name, FieldType fieldType=FieldType::automatic)
Definition: io/vtkoutputmodule.hh:161
An implementation of a linear PDE solver.
Definition: linear/pdesolver.hh:62
void solve(SolutionVector &uCurrentIter) override
Solve a linear PDE system.
Definition: linear/pdesolver.hh:88
Sequential ILU(0)-preconditioned BiCGSTAB solver.
Definition: seqsolverbackend.hh:580
Base class for linear solvers.
Definition: dumux/linear/solver.hh:37
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:52
std::shared_ptr< SolutionVector > solution
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:60
Dumux::GridManager< Grid > gridManager
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:58
Dumux::GetPropType< TypeTag, Dumux::Properties::GridGeometry > GridGeometry
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:54
std::shared_ptr< GridGeometry > gridGeometry
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:59
Dumux::GetPropType< TypeTag, Dumux::Properties::Grid > Grid
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:53
Dumux::GetPropType< TypeTag, Dumux::Properties::SolutionVector > SolutionVector
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:55
A linear system assembler (residual and Jacobian) for finite volume schemes.
A high-level solver interface for a linear PDE solver.
Declares all properties used in Dumux.
Definition of a problem for the MaxwellStefan problem: A rotating velocity field mixes a MaxwellStefa...
Convience header that includes all grid manager specializations.
A VTK output module to simplify writing dumux simulation data to VTK format.
SolutionStorage< TypeTag > solveRefinementLevel(int numCells)
Solves the problem for a given number of cells per direction.
Definition: test/porousmediumflow/1p/implicit/convergence/solver.hh:70