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/DOFVector.hpp>
26#include <amdis/Flag.hpp>
27#include <amdis/Initfile.hpp>
28#include <amdis/LinearAlgebra.hpp>
29#include <amdis/LinearForm.hpp>
30#include <amdis/Marker.hpp>
31#include <amdis/MeshCreator.hpp>
32#include <amdis/PeriodicBC.hpp>
33#include <amdis/ProblemStatBase.hpp>
34#include <amdis/ProblemStatTraits.hpp>
35#include <amdis/StandardProblemIteration.hpp>
36#include <amdis/common/SharedPtr.hpp>
37#include <amdis/common/TupleUtility.hpp>
38#include <amdis/common/TypeTraits.hpp>
39#include <amdis/GridFunctions.hpp>
40#include <amdis/gridfunctions/DiscreteFunction.hpp>
41#include <amdis/io/FileWriterBase.hpp>
42#include <amdis/typetree/Concepts.hpp>
43#include <amdis/typetree/TreePath.hpp>
48 template <
class Traits>
51 template <
class Traits>
64 using Grid = AdaptiveGrid_t<typename GridView::Grid>;
65 using Element =
typename GridView::template Codim<0>::Entity;
66 using WorldVector =
typename Element::Geometry::GlobalCoordinate;
67 using WorldMatrix = FieldMatrix<typename WorldVector::field_type, WorldVector::dimension, WorldVector::dimension>;
70 static constexpr int dim = Grid::dimension;
73 static constexpr int dow = Grid::dimensionworld;
75 using value_type =
typename Traits::CoefficientType;
77 using Mat =
typename Traits::Backend::template Matrix<GlobalBasis,GlobalBasis>::template
Impl<value_type>;
78 using Vec =
typename Traits::Backend::template Vector<GlobalBasis>::template
Impl<value_type>;
98 template <
class Gr
id_>
102 adoptGrid(wrap_or_share(FWD(
grid)));
107 template <
class Gr
id_,
class Basis_,
class B_ = Underlying_t<Basis_>,
108 REQUIRES(Concepts::GlobalBasis<B_>)>
117 template <class Grid_, class PBF_, class GV_ = typename Underlying_t<Grid_>::LeafGridView,
118 REQUIRES(Concepts::PreBasisFactory<PBF_, GV_>)>
122 adoptGlobalBasis(makeSharedPtr(GlobalBasis{
grid_->leafGridView(), preBasisFactory}));
130 void initialize(
Flag initFlag, Self* adoptProblem =
nullptr,
Flag adoptFlag = INIT_NOTHING);
160 template <
class Operator,
class RowTreePath = RootTreePath,
class ColTreePath = RootTreePath>
163 static constexpr bool isValidTreePath =
164 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, RowTreePath> &&
165 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, ColTreePath>;
166 static_assert(isValidTreePath,
"Invalid row and/or col treepath passed to addMatrixOperator!");
168 if constexpr (isValidTreePath)
169 systemMatrix_->addOperator(tag::element_operator<Element>{}, op, row, col);
191 template <
class Operator,
class RowTreePath = RootTreePath,
class ColTreePath = RootTreePath>
194 using I =
typename GridView::Intersection;
195 static constexpr bool isValidTreePath =
196 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, RowTreePath> &&
197 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, ColTreePath>;
198 static_assert(isValidTreePath,
"Invalid row and/or col treepath passed to addMatrixOperator!");
200 if constexpr (isValidTreePath)
201 systemMatrix_->addOperator(BoundarySubset<I>{*boundaryManager_,b}, op, row, col);
223 template <
class Operator,
class TreePath = RootTreePath>
226 static constexpr bool isValidTreePath =
227 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, TreePath>;
228 static_assert(isValidTreePath,
"Invalid treepath passed to addVectorOperator!");
230 if constexpr (isValidTreePath)
251 template <
class Operator,
class TreePath = RootTreePath>
254 using I =
typename GridView::Intersection;
255 static constexpr bool isValidTreePath =
256 Concepts::ValidTreePath<typename GlobalBasis::LocalView::Tree, TreePath>;
257 static_assert(isValidTreePath,
"Invalid treepath passed to addVectorOperator!");
259 if constexpr (isValidTreePath)
287 template <
class Predicate,
class RowTreePath,
class ColTreePath,
class Values>
288 void addDirichletBC(
Predicate const& predicate,
289 RowTreePath row, ColTreePath col,
290 Values
const& values);
292 template <
class RowTreePath,
class ColTreePath,
class Values>
293 void addDirichletBC(BoundaryType
id,
294 RowTreePath row, ColTreePath col,
295 Values
const& values);
297 template <
class Identifier,
class Values>
298 void addDirichletBC(Identifier&&
id, Values&& values)
300 addDirichletBC(FWD(
id), RootTreePath{}, RootTreePath{}, FWD(values));
305 void addPeriodicBC(BoundaryType
id, WorldMatrix
const& A, WorldVector
const& b);
308 void addConstraint(BoundaryCondition<SystemMatrix, SolutionVector, SystemVector> constraint)
310 constraints_.push_back(constraint);
318 return StandardProblemIteration::oneIteration(adaptInfo, toDo);
322 void buildAfterAdapt(
AdaptInfo& adaptInfo,
324 bool asmMatrix =
true,
325 bool asmVector =
true)
override;
331 buildAfterAdapt(adaptInfo,
Flag{0},
true,
true);
336 bool createMatrixData =
true,
337 bool storeMatrixData =
false)
override;
349 Flag globalCoarsen(
int n)
override;
352 Flag globalRefine(
int n)
override;
355 void writeFiles(
AdaptInfo& adaptInfo,
bool force =
false);
361 std::string
const&
name()
const override {
return name_; }
364 std::shared_ptr<Grid>
grid() {
return grid_; }
365 std::shared_ptr<Grid const> grid()
const {
return grid_; }
368 GridView
gridView()
const {
return globalBasis_->gridView(); }
372 std::shared_ptr<BoundaryManager<Grid>
const> boundaryManager()
const {
return boundaryManager_; }
375 std::shared_ptr<GlobalBasis>
globalBasis() {
return globalBasis_; }
376 std::shared_ptr<GlobalBasis const> globalBasis()
const {
return globalBasis_; }
379 std::shared_ptr<LinearSolverInterface>
solver() {
return linearSolver_; }
380 std::shared_ptr<LinearSolverInterface const> solver()
const {
return linearSolver_; }
384 std::shared_ptr<SystemMatrix const> systemMatrix()
const {
return systemMatrix_; }
388 std::shared_ptr<SolutionVector const> solutionVector()
const {
return solution_; }
391 std::shared_ptr<SystemVector>
rhsVector() {
return rhs_; }
392 std::shared_ptr<SystemVector const> rhsVector()
const {
return rhs_; }
400 template <
class Range = void,
class... Indices>
403 assert(
bool(solution_) &&
"You have to call initialize() before.");
404 return valueOf<Range>(*solution_, ii...);
412 template <
class Range = void,
class... Indices>
415 assert(
bool(solution_) &&
"You have to call initialize() before.");
416 return valueOf<Range>(*solution_, ii...);
423 template <
class Solver_>
426 linearSolver_ = wrap_or_share(FWD(solver));
433 template <
class Gr
id_>
436 adoptGrid(wrap_or_share(FWD(grid)));
438 createMatricesAndVectors();
448 template <
class Marker_>
451 auto marker = wrap_or_share(FWD(m));
452 auto it = marker_.emplace(marker->name(), marker);
453 if (marker_.size() > 1)
454 it.first->second->setMaximumMarking(
true);
460 std::size_t num = marker_.erase(name);
461 test_warning(num == 1,
"A marker with the given name '{}' does not exist.", name);
467 removeMarker(marker.
name());
471 template<
class FileWriter_>
474 filewriter_.push_back(wrap_or_share(FWD(f)));
485 void createGlobalBasis();
487 void createMatricesAndVectors();
490 void createFileWriter();
492 void adoptGlobalBasis(std::shared_ptr<GlobalBasis> globalBasis)
494 globalBasis_ = std::move(globalBasis);
498 void adoptGrid(std::shared_ptr<Grid>
const& grid,
499 std::shared_ptr<BoundaryManager<Grid>>
const& boundaryManager)
502 boundaryManager_ = boundaryManager;
503 Parameters::get(name_ +
"->mesh", gridName_);
506 void adoptGrid(std::shared_ptr<Grid>
const& grid)
508 adoptGrid(grid, std::make_shared<BoundaryManager<Grid>>(grid));
511 void adoptGrid(std::shared_ptr<typename Grid::HostGrid>
const& hostGrid)
513 auto grid = std::make_shared<Grid>(hostGrid);
514 adoptGrid(grid, std::make_shared<BoundaryManager<Grid>>(grid));
519 void createGlobalBasisImpl(std::true_type);
520 void createGlobalBasisImpl(std::false_type);
522 void initGlobalBasis();
533 std::string gridName_ =
"mesh";
545 std::map<std::string, std::shared_ptr<Marker<Grid>>>
marker_;
561 std::shared_ptr<SystemVector>
rhs_;
568 std::list<BoundaryCondition<SystemMatrix, SolutionVector, SystemVector>>
constraints_;
574 template <
class Gr
id,
class B,
class =
void>
575 struct DeducedProblemTraits;
577 template <
class Gr
id,
class PB>
578 struct DeducedProblemTraits<Grid,
GlobalBasis<PB>,void>
583 template <
class Gr
id,
class PB>
584 struct DeducedProblemTraits<Grid,const
GlobalBasis<PB>,void>
586 using type = DefaultProblemTraits<GlobalBasis<PB>>;
589 template <
class G,
class PBF>
590 struct DeducedProblemTraits<G,PBF,
591 std::enable_if_t<Concepts::PreBasisFactory<PBF, typename G::LeafGridView>>>
593 using Grid = AdaptiveGrid_t<G>;
594 using GridView =
typename Grid::LeafGridView;
595 using Basis =
decltype(
GlobalBasis{std::declval<GridView>(),std::declval<PBF>()});
597 using type = DefaultProblemTraits<Basis>;
600 template <
class Gr
id,
class Basis>
601 using DeducedProblemTraits_t =
typename DeducedProblemTraits<Grid,Basis>::type;
606 template <
class Gr
id,
class Basis>
607 ProblemStat(std::string name, Grid&& grid, Basis&& globalBasis)
608 -> ProblemStat<Impl::DeducedProblemTraits_t<Underlying_t<Grid>,Underlying_t<Basis>>>;
612 extern template class ProblemStat<LagrangeBasis<Dune::YaspGrid<2>,1>>;
613 extern template class ProblemStat<LagrangeBasis<Dune::YaspGrid<2>,1,1>>;
617#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:48
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:57
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:55
void setSolver(Solver_ &&solver)
Set a new linear solver for the problem.
Definition: ProblemStat.hpp:424
void removeMarker(Marker< Grid > const &marker)
Remove a marker from the problem.
Definition: ProblemStat.hpp:465
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:92
void addFileWriter(FileWriter_ &&f)
Add another filewriter to the problem.
Definition: ProblemStat.hpp:472
std::shared_ptr< Grid > grid_
Grid of this problem.
Definition: ProblemStat.hpp:530
static constexpr int dim
Dimension of the grid.
Definition: ProblemStat.hpp:70
void addMatrixOperator(Operator const &op, RowTreePath row={}, ColTreePath col={})
Add an operator to A.
Definition: ProblemStat.hpp:161
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:119
std::shared_ptr< SystemMatrix > systemMatrix()
Returns a reference to system-matrix, systemMatrix_.
Definition: ProblemStat.hpp:383
void addMarker(Marker_ &&m)
Store the shared_ptr and the name of the marker in the problem.
Definition: ProblemStat.hpp:449
void removeMarker(std::string name)
Remove a marker with the given name from the problem.
Definition: ProblemStat.hpp:458
Flag oneIteration(AdaptInfo &adaptInfo, Flag toDo=FULL_ITERATION) override
Implementation of StandardProblemIteration::oneIteration.
Definition: ProblemStat.hpp:316
ProblemStat(std::string const &name, Grid_ &&grid)
Definition: ProblemStat.hpp:99
std::shared_ptr< BoundaryManager< Grid > > boundaryManager()
Return the boundary manager to identify boundary segments.
Definition: ProblemStat.hpp:371
std::string name_
Name of this problem.
Definition: ProblemStat.hpp:527
std::list< BoundaryCondition< SystemMatrix, SolutionVector, SystemVector > > constraints_
List of constraints to apply to matrix, solution and rhs.
Definition: ProblemStat.hpp:568
void addVectorOperator(BoundaryType b, Operator const &op, TreePath path={})
Operator evaluated on the boundary of the domain with boundary index b
Definition: ProblemStat.hpp:252
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:340
std::shared_ptr< GlobalBasis > globalBasis_
FE space of this problem.
Definition: ProblemStat.hpp:539
void setGrid(Grid_ &&grid)
Definition: ProblemStat.hpp:434
ProblemStat(std::string const &name, Grid_ &&grid, Basis_ &&globalBasis)
Constructor taking a grid and basis. Wraps both in shared pointers.
Definition: ProblemStat.hpp:109
void assemble(AdaptInfo &adaptInfo)
Assemble the linear system by calling buildAfterAdapt with asmMatrix and asmVector set to true.
Definition: ProblemStat.hpp:329
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:542
GridView gridView() const
Return the gridView of the basis.
Definition: ProblemStat.hpp:368
std::shared_ptr< SystemMatrix > systemMatrix_
Matrix that is filled during assembling.
Definition: ProblemStat.hpp:554
std::shared_ptr< Grid > grid()
Return the grid_.
Definition: ProblemStat.hpp:364
std::shared_ptr< LinearSolverInterface > solver()
Return a reference to the linear solver, linearSolver.
Definition: ProblemStat.hpp:379
auto solution(Indices... ii)
Return a mutable view to a solution component.
Definition: ProblemStat.hpp:401
std::string const & name() const override
Implementation of ProblemStatBase::name.
Definition: ProblemStat.hpp:361
std::shared_ptr< SolutionVector > solution_
Vector with the solution components.
Definition: ProblemStat.hpp:557
auto solution(Indices... ii) const
Return a const view to a solution component.
Definition: ProblemStat.hpp:413
void addVectorOperator(Operator const &op, TreePath path={})
Add an operator to rhs.
Definition: ProblemStat.hpp:224
static constexpr int dow
Dimension of the world.
Definition: ProblemStat.hpp:73
std::map< std::string, std::shared_ptr< Marker< Grid > > > marker_
Pointer to the adaptation markers.
Definition: ProblemStat.hpp:545
std::shared_ptr< SystemVector > rhs_
Definition: ProblemStat.hpp:561
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:192
void clearFileWriter()
Deletes all filewriters.
Definition: ProblemStat.hpp:478
std::shared_ptr< LinearSolverInterface > linearSolver_
Pointer to the estimators for this problem.
Definition: ProblemStat.hpp:551
std::map< std::string, std::vector< double > > estimates_
Definition: ProblemStat.hpp:565
std::shared_ptr< SolutionVector > solutionVector()
Returns a reference to the solution vector, solution_.
Definition: ProblemStat.hpp:387
std::shared_ptr< BoundaryManager< Grid > > boundaryManager_
Management of boundary conditions.
Definition: ProblemStat.hpp:536
std::shared_ptr< SystemVector > rhsVector()
Return a reference to the rhs system-vector, rhs.
Definition: ProblemStat.hpp:391
std::shared_ptr< GlobalBasis > globalBasis()
Return the globalBasis_.
Definition: ProblemStat.hpp:375
StandardProblemIteration when derived from ProblemStat.
Definition: StandardProblemIteration.hpp:73
constexpr bool GlobalBasis
A Dune::Functions::GlobalBasis type.
Definition: Concepts.hpp:189
constexpr bool Predicate
A predicate is a function that returns a boolean.
Definition: Concepts.hpp:141
Wrapper around a global basis providing default traits.
Definition: ProblemStatTraits.hpp:77
Definition: Assembler.hpp:15