11#include <dune/common/fvector.hh>
12#include <dune/common/fmatrix.hh>
13#include <dune/common/shared_ptr.hh>
15#include <dune/grid/common/grid.hh>
17#include <amdis/AdaptInfo.hpp>
18#include <amdis/AdaptiveGrid.hpp>
19#include <amdis/Assembler.hpp>
20#include <amdis/BiLinearForm.hpp>
21#include <amdis/CreatorInterface.hpp>
22#include <amdis/CreatorMap.hpp>
23#include <amdis/DirichletBC.hpp>
24#include <amdis/SymmetricDirichletBC.hpp>
25#include <amdis/DOFVector.hpp>
27#include <amdis/Flag.hpp>
28#include <amdis/Initfile.hpp>
29#include <amdis/LinearAlgebra.hpp>
30#include <amdis/LinearForm.hpp>
31#include <amdis/Marker.hpp>
32#include <amdis/MeshCreator.hpp>
33#include <amdis/PeriodicBC.hpp>
34#include <amdis/ProblemStatBase.hpp>
35#include <amdis/ProblemStatTraits.hpp>
36#include <amdis/StandardProblemIteration.hpp>
37#include <amdis/common/SharedPtr.hpp>
38#include <amdis/common/TupleUtility.hpp>
39#include <amdis/common/TypeTraits.hpp>
40#include <amdis/GridFunctions.hpp>
41#include <amdis/gridfunctions/DiscreteFunction.hpp>
42#include <amdis/io/FileWriterBase.hpp>
43#include <amdis/typetree/Concepts.hpp>
44#include <amdis/typetree/TreePath.hpp>
49 template <
class Traits>
52 template <
class Traits>
63 using GlobalBasis =
typename Traits::GlobalBasis;
65 using Grid = AdaptiveGrid_t<typename GridView::Grid>;
66 using Element =
typename GridView::template Codim<0>::Entity;
67 using WorldVector =
typename Element::Geometry::GlobalCoordinate;
68 using WorldMatrix = FieldMatrix<typename WorldVector::field_type, WorldVector::dimension, WorldVector::dimension>;
71 static constexpr int dim = Grid::dimension;
74 static constexpr int dow = Grid::dimensionworld;
76 using value_type =
typename Traits::CoefficientType;
78 using Mat =
typename Traits::Backend::template Matrix<GlobalBasis,GlobalBasis>::template
Impl<value_type>;
79 using Vec =
typename Traits::Backend::template Vector<GlobalBasis>::template
Impl<value_type>;
99 template <
class Gr
id_>
103 adoptGrid(wrap_or_share(FWD(
grid)));
108 template <
class Gr
id_,
class Basis_,
class B_ = Underlying_t<Basis_>,
109 REQUIRES(Concepts::GlobalBasis<B_>)>
118 template <class Grid_, class PBF_, class GV_ = typename Underlying_t<Grid_>::LeafGridView,
119 REQUIRES(Concepts::PreBasisFactory<PBF_, GV_>)>
123 adoptGlobalBasis(makeSharedPtr(GlobalBasis{
grid_->leafGridView(), preBasisFactory}));
131 void initialize(
Flag initFlag, Self* adoptProblem =
nullptr,
Flag adoptFlag = INIT_NOTHING);
161 template <
class Operator,
class RowTreePath = RootTreePath,
class ColTreePath = RootTreePath>
164 static constexpr bool isValidTreePath =
165 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, RowTreePath> &&
166 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, ColTreePath>;
167 static_assert(isValidTreePath,
"Invalid row and/or col treepath passed to addMatrixOperator!");
169 if constexpr (isValidTreePath)
170 systemMatrix_->addOperator(tag::element_operator<Element>{}, op, row, col);
192 template <
class Operator,
class RowTreePath = RootTreePath,
class ColTreePath = RootTreePath>
195 using I =
typename GridView::Intersection;
196 static constexpr bool isValidTreePath =
197 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, RowTreePath> &&
198 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, ColTreePath>;
199 static_assert(isValidTreePath,
"Invalid row and/or col treepath passed to addMatrixOperator!");
201 if constexpr (isValidTreePath)
202 systemMatrix_->addOperator(BoundarySubset<I>{*boundaryManager_,b}, op, row, col);
224 template <
class Operator,
class TreePath = RootTreePath>
227 static constexpr bool isValidTreePath =
228 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, TreePath>;
229 static_assert(isValidTreePath,
"Invalid treepath passed to addVectorOperator!");
231 if constexpr (isValidTreePath)
252 template <
class Operator,
class TreePath = RootTreePath>
255 using I =
typename GridView::Intersection;
256 static constexpr bool isValidTreePath =
257 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, TreePath>;
258 static_assert(isValidTreePath,
"Invalid treepath passed to addVectorOperator!");
260 if constexpr (isValidTreePath)
288 template <
class Predicate,
class RowTreePath,
class ColTreePath,
class Values>
289 void addDirichletBC(Predicate
const& predicate,
290 RowTreePath row, ColTreePath col,
291 Values
const& values);
293 template <
class RowTreePath,
class ColTreePath,
class Values>
294 void addDirichletBC(BoundaryType
id,
295 RowTreePath row, ColTreePath col,
296 Values
const& values);
299 template <
class Identifier,
class Values>
300 void addDirichletBC(Identifier&&
id, Values&& values)
302 addDirichletBC(FWD(
id), RootTreePath{}, RootTreePath{}, FWD(values));
305 template <
class Predicate,
class Path,
class Values>
306 void addSymmetricDirichletBC(Predicate
const& predicate,
308 Values
const& values);
310 template <
class Path,
class Values>
311 void addSymmetricDirichletBC(BoundaryType
id,
313 Values
const& values);
315 template <
class Identifier,
class Values>
316 void addSymmetricDirichletBC(Identifier&&
id, Values&& values)
318 addSymmetricDirichletBC(FWD(
id), RootTreePath{}, FWD(values));
323 void addPeriodicBC(BoundaryType
id, WorldMatrix
const& A, WorldVector
const& b);
326 void addConstraint(BoundaryCondition<SystemMatrix, SolutionVector, SystemVector> constraint)
328 constraints_.push_back(constraint);
336 return StandardProblemIteration::oneIteration(adaptInfo, toDo);
340 void buildAfterAdapt(
AdaptInfo& adaptInfo,
342 bool asmMatrix =
true,
343 bool asmVector =
true)
override;
349 buildAfterAdapt(adaptInfo,
Flag{0},
true,
true);
354 bool createMatrixData =
true,
355 bool storeMatrixData =
false)
override;
367 Flag globalCoarsen(
int n)
override;
370 Flag globalRefine(
int n)
override;
373 void writeFiles(
AdaptInfo& adaptInfo,
bool force =
false);
379 std::string
const&
name()
const override {
return name_; }
382 std::shared_ptr<Grid>
grid() {
return grid_; }
383 std::shared_ptr<Grid const> grid()
const {
return grid_; }
386 GridView
gridView()
const {
return globalBasis_->gridView(); }
390 std::shared_ptr<BoundaryManager<Grid>
const> boundaryManager()
const {
return boundaryManager_; }
393 std::shared_ptr<GlobalBasis>
globalBasis() {
return globalBasis_; }
394 std::shared_ptr<GlobalBasis const> globalBasis()
const {
return globalBasis_; }
397 std::shared_ptr<LinearSolverInterface>
solver() {
return linearSolver_; }
398 std::shared_ptr<LinearSolverInterface const> solver()
const {
return linearSolver_; }
402 std::shared_ptr<SystemMatrix const> systemMatrix()
const {
return systemMatrix_; }
406 std::shared_ptr<SolutionVector const> solutionVector()
const {
return solution_; }
409 std::shared_ptr<SystemVector>
rhsVector() {
return rhs_; }
410 std::shared_ptr<SystemVector const> rhsVector()
const {
return rhs_; }
418 template <
class Range = void,
class... Indices>
421 assert(
bool(solution_) &&
"You have to call initialize() before.");
422 return valueOf<Range>(*solution_, ii...);
430 template <
class Range = void,
class... Indices>
433 assert(
bool(solution_) &&
"You have to call initialize() before.");
434 return valueOf<Range>(*solution_, ii...);
441 template <
class Solver_>
444 linearSolver_ = wrap_or_share(FWD(solver));
451 template <
class Gr
id_>
454 adoptGrid(wrap_or_share(FWD(grid)));
456 createMatricesAndVectors();
466 template <
class Marker_>
469 auto marker = wrap_or_share(FWD(m));
470 auto it = marker_.emplace(marker->name(), marker);
471 if (marker_.size() > 1)
472 it.first->second->setMaximumMarking(
true);
478 std::size_t num = marker_.erase(name);
479 test_warning(num == 1,
"A marker with the given name '{}' does not exist.", name);
485 removeMarker(marker.
name());
489 template<
class FileWriter_>
492 filewriter_.push_back(wrap_or_share(FWD(f)));
503 void createGlobalBasis();
505 void createMatricesAndVectors();
508 void createFileWriter();
510 void adoptGlobalBasis(std::shared_ptr<GlobalBasis> globalBasis)
512 globalBasis_ = std::move(globalBasis);
516 void adoptGrid(std::shared_ptr<Grid>
const& grid,
517 std::shared_ptr<BoundaryManager<Grid>>
const& boundaryManager)
520 boundaryManager_ = boundaryManager;
521 Parameters::get(name_ +
"->mesh", gridName_);
524 void adoptGrid(std::shared_ptr<Grid>
const& grid)
526 adoptGrid(grid, std::make_shared<BoundaryManager<Grid>>(grid));
529 void adoptGrid(std::shared_ptr<typename Grid::HostGrid>
const& hostGrid)
531 auto grid = std::make_shared<Grid>(hostGrid);
532 adoptGrid(grid, std::make_shared<BoundaryManager<Grid>>(grid));
537 void createGlobalBasisImpl(std::true_type);
538 void createGlobalBasisImpl(std::false_type);
540 void initGlobalBasis();
551 std::string gridName_ =
"mesh";
563 std::map<std::string, std::shared_ptr<Marker<Grid>>>
marker_;
579 std::shared_ptr<SystemVector>
rhs_;
586 std::list<BoundaryCondition<SystemMatrix, SolutionVector, SystemVector>>
constraints_;
592 template <
class Gr
id,
class B,
class =
void>
593 struct DeducedProblemTraits;
595 template <
class Gr
id,
class PB>
596 struct DeducedProblemTraits<Grid,
GlobalBasis<PB>,void>
601 template <
class Gr
id,
class PB>
602 struct DeducedProblemTraits<Grid,const GlobalBasis<PB>,void>
604 using type = DefaultProblemTraits<GlobalBasis<PB>>;
607 template <
class G,
class PBF>
608 struct DeducedProblemTraits<G,PBF,
609 std::enable_if_t<Concepts::PreBasisFactory<PBF, typename G::LeafGridView>>>
611 using Grid = AdaptiveGrid_t<G>;
612 using GridView =
typename Grid::LeafGridView;
613 using Basis =
decltype(
GlobalBasis{std::declval<GridView>(),std::declval<PBF>()});
615 using type = DefaultProblemTraits<Basis>;
618 template <
class Gr
id,
class Basis>
619 using DeducedProblemTraits_t =
typename DeducedProblemTraits<Grid,Basis>::type;
624 template <
class Gr
id,
class Basis>
625 ProblemStat(std::string name, Grid&& grid, Basis&& globalBasis)
626 -> ProblemStat<Impl::DeducedProblemTraits_t<Underlying_t<Grid>,Underlying_t<Basis>>>;
630#include "ProblemStat.inc.hpp"
Holds adapt parameters and infos about the problem.
Definition AdaptInfo.hpp:26
Class defining a subset of a domain boundary.
Definition BoundarySubset.hpp:24
The basic container that stores a base vector and a corresponding basis.
Definition DOFVector.hpp:43
The Flag class encapsulates flags which represents simple information. Used e.g. while mesh traversal...
Definition Flag.hpp:14
Global basis defined on a pre-basis.
Definition GlobalBasis.hpp:47
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition GlobalBasis.hpp:56
Definition LinearSolverInterface.hpp:9
Implementation of LinearSolverInterface for EIGEN solvers.
Definition LinearSolver.hpp:16
Base class for all markers.
Definition Marker.hpp:29
std::string const & name() const
Returns name_ of the Marker.
Definition Marker.hpp:81
The base class for an operator to be used in an Assembler.
Definition Operator.hpp:80
Standard implementation of ProblemTimeInterface for a time dependent problems.
Definition ProblemInstat.hpp:26
Interface for time independent problems. Concrete problems must override all pure virtual methods....
Definition ProblemStatBase.hpp:59
Definition ProblemStat.hpp:56
void setSolver(Solver_ &&solver)
Set a new linear solver for the problem.
Definition ProblemStat.hpp:442
void removeMarker(Marker< Grid > const &marker)
Remove a marker from the problem.
Definition ProblemStat.hpp:483
ProblemStat(std::string const &name)
Constructor. Takes the name of the problem that is used to access values corresponding to this proble...
Definition ProblemStat.hpp:93
void addFileWriter(FileWriter_ &&f)
Add another filewriter to the problem.
Definition ProblemStat.hpp:490
std::shared_ptr< Grid > grid_
Grid of this problem.
Definition ProblemStat.hpp:548
static constexpr int dim
Dimension of the grid.
Definition ProblemStat.hpp:71
void addMatrixOperator(Operator const &op, RowTreePath row={}, ColTreePath col={})
Add an operator to A.
Definition ProblemStat.hpp:162
ProblemStat(std::string const &name, Grid_ &&grid, PBF_ const &preBasisFactory)
Constructor taking a grid and pre-basis factory to create a global basis on the fly.
Definition ProblemStat.hpp:120
std::shared_ptr< SystemMatrix > systemMatrix()
Returns a reference to system-matrix, systemMatrix_.
Definition ProblemStat.hpp:401
void addMarker(Marker_ &&m)
Store the shared_ptr and the name of the marker in the problem.
Definition ProblemStat.hpp:467
void removeMarker(std::string name)
Remove a marker with the given name from the problem.
Definition ProblemStat.hpp:476
Flag oneIteration(AdaptInfo &adaptInfo, Flag toDo=FULL_ITERATION) override
Implementation of StandardProblemIteration::oneIteration.
Definition ProblemStat.hpp:334
ProblemStat(std::string const &name, Grid_ &&grid)
Definition ProblemStat.hpp:100
std::shared_ptr< BoundaryManager< Grid > > boundaryManager()
Return the boundary manager to identify boundary segments.
Definition ProblemStat.hpp:389
std::string name_
Name of this problem.
Definition ProblemStat.hpp:545
std::list< BoundaryCondition< SystemMatrix, SolutionVector, SystemVector > > constraints_
List of constraints to apply to matrix, solution and rhs.
Definition ProblemStat.hpp:586
void addVectorOperator(BoundaryType b, Operator const &op, TreePath path={})
Operator evaluated on the boundary of the domain with boundary index b
Definition ProblemStat.hpp:253
void initialize(Flag initFlag, Self *adoptProblem=nullptr, Flag adoptFlag=INIT_NOTHING)
Initialisation of the problem.
Definition ProblemStat.inc.hpp:23
void estimate(AdaptInfo &) override
Implementation of ProblemStatBase::estimate.
Definition ProblemStat.hpp:358
std::shared_ptr< GlobalBasis > globalBasis_
FE space of this problem.
Definition ProblemStat.hpp:557
void setGrid(Grid_ &&grid)
Definition ProblemStat.hpp:452
ProblemStat(std::string const &name, Grid_ &&grid, Basis_ &&globalBasis)
Constructor taking a grid and basis. Wraps both in shared pointers.
Definition ProblemStat.hpp:110
void assemble(AdaptInfo &adaptInfo)
Assemble the linear system by calling buildAfterAdapt with asmMatrix and asmVector set to true.
Definition ProblemStat.hpp:347
void restore(Flag initFlag)
Read the grid and solution from backup files and initialize the problem.
Definition ProblemStat.inc.hpp:108
std::list< std::shared_ptr< FileWriterInterface > > filewriter_
A FileWriter object.
Definition ProblemStat.hpp:560
GridView gridView() const
Return the gridView of the basis.
Definition ProblemStat.hpp:386
std::shared_ptr< SystemMatrix > systemMatrix_
Matrix that is filled during assembling.
Definition ProblemStat.hpp:572
std::shared_ptr< Grid > grid()
Return the grid_.
Definition ProblemStat.hpp:382
std::shared_ptr< LinearSolverInterface > solver()
Return a reference to the linear solver, linearSolver.
Definition ProblemStat.hpp:397
auto solution(Indices... ii)
Return a mutable view to a solution component.
Definition ProblemStat.hpp:419
std::string const & name() const override
Implementation of ProblemStatBase::name.
Definition ProblemStat.hpp:379
std::shared_ptr< SolutionVector > solution_
Vector with the solution components.
Definition ProblemStat.hpp:575
auto solution(Indices... ii) const
Return a const view to a solution component.
Definition ProblemStat.hpp:431
void addVectorOperator(Operator const &op, TreePath path={})
Add an operator to rhs.
Definition ProblemStat.hpp:225
static constexpr int dow
Dimension of the world.
Definition ProblemStat.hpp:74
std::map< std::string, std::shared_ptr< Marker< Grid > > > marker_
Pointer to the adaptation markers.
Definition ProblemStat.hpp:563
std::shared_ptr< SystemVector > rhs_
Definition ProblemStat.hpp:579
void addMatrixOperator(BoundaryType b, Operator const &op, RowTreePath row={}, ColTreePath col={})
Operator evaluated on the boundary of the domain with boundary index b
Definition ProblemStat.hpp:193
void clearFileWriter()
Deletes all filewriters.
Definition ProblemStat.hpp:496
std::shared_ptr< LinearSolverInterface > linearSolver_
Pointer to the estimators for this problem.
Definition ProblemStat.hpp:569
std::map< std::string, std::vector< double > > estimates_
Definition ProblemStat.hpp:583
std::shared_ptr< SolutionVector > solutionVector()
Returns a reference to the solution vector, solution_.
Definition ProblemStat.hpp:405
std::shared_ptr< BoundaryManager< Grid > > boundaryManager_
Management of boundary conditions.
Definition ProblemStat.hpp:554
std::shared_ptr< SystemVector > rhsVector()
Return a reference to the rhs system-vector, rhs.
Definition ProblemStat.hpp:409
std::shared_ptr< GlobalBasis > globalBasis()
Return the globalBasis_.
Definition ProblemStat.hpp:393
StandardProblemIteration when derived from ProblemStat.
Definition StandardProblemIteration.hpp:73
constexpr bool GlobalBasis
A Dune::Functions::GlobalBasis type.
Definition Concepts.hpp:189
Wrapper around a global basis providing default traits.
Definition ProblemStatTraits.hpp:77
Definition Assembler.hpp:15