4 #ifndef DUNE_PDELAB_ADAPTIVITY_HH
5 #define DUNE_PDELAB_ADAPTIVITY_HH
7 #include<dune/common/exceptions.hh>
12 #include<unordered_map>
13 #include<dune/common/dynmatrix.hh>
14 #include<dune/geometry/quadraturerules.hh>
25 #include<dune/grid/io/file/vtk/subsamplingvtkwriter.hh>
31 template<
typename GFS>
35 typedef typename GFS::Traits::GridView::template Codim<0>::Entity
Cell;
40 typedef array<std::size_t,TypeTree::TreeInfo<GFS>::leafCount + 1>
LeafOffsets;
44 const LeafOffsets& leaf_offsets =
_leaf_offset_cache[GlobalGeometryTypeIndex::index(gt)];
46 assert(leaf_offsets.back() > 0);
52 LeafOffsets& leaf_offsets =
_leaf_offset_cache[GlobalGeometryTypeIndex::index(e.type())];
53 if (leaf_offsets.back() == 0)
58 std::partial_sum(leaf_offsets.begin(),leaf_offsets.end(),leaf_offsets.begin());
60 assert(leaf_offsets.back() ==
_lfs.
size());
77 template<
typename MassMatrices,
typename Cell>
78 struct inverse_mass_matrix_calculator
79 :
public TypeTree::TreeVisitor
80 ,
public TypeTree::DynamicTraversal
83 static const int dim = Cell::Geometry::mydimension;
84 typedef std::size_t size_type;
85 typedef typename MassMatrices::value_type MassMatrix;
86 typedef typename MassMatrix::field_type DF;
87 typedef typename Dune::QuadratureRule<DF,dim>::const_iterator QRIterator;
89 template<
typename GFS,
typename TreePath>
90 void leaf(
const GFS& gfs, TreePath treePath)
92 typedef typename GFS::Traits::FiniteElementMap FEM;
93 const FEM& fem = gfs.finiteElementMap();
94 typedef typename FEM::Traits::FiniteElement FiniteElement;
95 const FiniteElement& fe = fem.find(
_element);
96 size_type local_size = fe.localBasis().size();
99 mass_matrix.resize(local_size,local_size);
102 std::vector<typename FiniteElement::Traits::LocalBasisType::Traits::RangeType> phi;
103 phi.resize(std::max(phi.size(),local_size));
107 fe.localBasis().evaluateFunction(ip.position(),phi);
108 const DF factor = ip.weight();
110 for (size_type i = 0; i < local_size; ++i)
111 for (size_type j = 0; j < local_size; ++j)
112 mass_matrix[i][j] += phi[i] * phi[j] * factor;
115 mass_matrix.invert();
120 inverse_mass_matrix_calculator(MassMatrices& mass_matrices,
const Cell& element, size_type intorder)
144 template<
class GFS,
class U>
147 typedef typename GFS::Traits::GridViewType::Grid Grid;
148 typedef typename Grid::template Codim<0>::Entity Element;
150 typedef typename U::ElementType DF;
155 typedef array<MassMatrix,TypeTree::TreeInfo<GFS>::leafCount>
MassMatrices;
163 , _intorder(intorder)
164 , _inverse_mass_matrices(GlobalGeometryTypeIndex::size(Element::dimension))
174 const GeometryType gt = e.geometry().type();
175 MassMatrices& inverse_mass_matrices = _inverse_mass_matrices[GlobalGeometryTypeIndex::index(gt)];
177 if (inverse_mass_matrices[0].N() > 0)
178 return inverse_mass_matrices;
180 inverse_mass_matrix_calculator<MassMatrices,Element> calculate_mass_matrices(
181 inverse_mass_matrices,
186 TypeTree::applyToTree(_gfs,calculate_mass_matrices);
188 return inverse_mass_matrices;
195 std::vector<MassMatrices> _inverse_mass_matrices;
199 template<
typename GFS,
typename DOFVector,
typename TransferMap>
201 :
public TypeTree::TreeVisitor
202 ,
public TypeTree::DynamicTraversal
209 typedef typename GFS::Traits::GridView::Grid::LocalIdSet
IDSet;
210 typedef typename GFS::Traits::GridView::template Codim<0>::Entity
Cell;
212 static const int dim = Geometry::mydimension;
214 typedef typename DOFVector::ElementType
RF;
223 typedef typename GFS::Traits::GridView::ctype
DF;
225 template<
typename LFSLeaf,
typename TreePath>
226 void leaf(
const LFSLeaf& leaf_lfs, TreePath treePath)
229 typedef typename LFSLeaf::Traits::GridFunctionSpace::Traits::FiniteElementMap FEM;
230 typedef typename FEM::Traits::FiniteElement FE;
231 const FEM& fem = leaf_lfs.gridFunctionSpace().finiteElementMap();
235 typedef typename FE::Traits::LocalBasisType::Traits::RangeType Range;
239 std::vector<Range> coarse_phi;
240 std::vector<Range> fine_phi;
242 Geometry fine_geometry =
_current.geometry();
243 Geometry coarse_geometry =
_ancestor.geometry();
248 typename Geometry::LocalCoordinate coarse_local = coarse_geometry.local(fine_geometry.global(ip.position()));
250 fe->localBasis().evaluateFunction(ip.position(),fine_phi);
252 fe->localBasis().evaluateFunction(coarse_local,coarse_phi);
253 const DF factor = ip.weight()
254 * fine_geometry.integrationElement(ip.position())
255 / coarse_geometry.integrationElement(coarse_local);
258 for (size_type i = 0; i < fine_phi.size(); ++i)
260 val.axpy(
_u_fine[fine_offset + i],fine_phi[i]);
263 for (size_type i = 0; i < coarse_phi.size(); ++i)
266 for (size_type j = 0; j < inverse_mass_matrix.M(); ++j)
267 x.axpy(inverse_mass_matrix[i][j],coarse_phi[j]);
268 (*_u_coarse)[coarse_offset + i] += factor * (x * val);
307 for (
const auto& child : descendantElements(
_ancestor,max_level))
324 TypeTree::applyToTree(
_lfs,*
this);
331 Projection& projection,
333 LeafOffsetCache& leaf_offset_cache,
334 TransferMap& transfer_map,
335 std::size_t int_order = 2)
338 ,
_id_set(gfs.gridView().grid().localIdSet())
355 typename DOFVector::template ConstLocalView<LFSCache>
_u_view;
367 template<
typename GFS,
typename DOFVector,
typename CountVector>
369 :
public TypeTree::TreeVisitor
370 ,
public TypeTree::DynamicTraversal
377 typedef typename LFS::Traits::GridFunctionSpace::Traits::GridView::template Codim<0>::Entity
Cell;
379 typedef typename DOFVector::ElementType
RF;
385 template<
typename FiniteElement>
389 template<
typename X,
typename Y>
395 for (size_type i = 0; i <
_phi.size(); ++i)
399 coarse_function(
const FiniteElement& finite_element, Geometry coarse_geometry, Geometry fine_geometry,
const LocalDOFVector& dofs, size_type
offset)
411 mutable std::vector<typename FiniteElement::Traits::LocalBasisType::Traits::RangeType>
_phi;
417 template<
typename LeafLFS,
typename TreePath>
418 void leaf(
const LeafLFS& leaf_lfs, TreePath treePath)
421 typedef typename LeafLFS::Traits::GridFunctionSpace::Traits::FiniteElementMap FEM;
422 const FEM& fem = leaf_lfs.gridFunctionSpace().finiteElementMap();
427 const typename FEM::Traits::FiniteElement& fe = fem.find(
_element);
429 _u_tmp.resize(fe.localBasis().size());
431 fe.localInterpolation().interpolate(f,
_u_tmp);
437 void operator()(
const Cell& element,
const Cell& ancestor,
const LocalDOFVector& u_coarse)
459 TypeTree::applyToTree(
_lfs,*
this);
470 replay_visitor(
const GFS& gfs, DOFVector& u, CountVector& uc, LeafOffsetCache& leaf_offset_cache)
483 typename DOFVector::template LocalView<LFSCache>
_u_view;
484 typename CountVector::template LocalView<LFSCache>
_uc_view;
508 template<
class Gr
id,
class GFSU,
class U,
class Projection>
511 typedef typename Grid::LeafGridView LeafGridView;
512 typedef typename LeafGridView::template Codim<0>
513 ::template Partition<Dune::Interior_Partition>::Iterator LeafIterator;
514 typedef typename Grid::template Codim<0>::Entity Element;
515 typedef typename Grid::LocalIdSet IDSet;
516 typedef typename IDSet::IdType ID;
519 typedef std::unordered_map<ID,std::vector<typename U::ElementType> >
MapType;
527 : _leaf_offset_cache(gfs)
535 void backupData(Grid& grid, GFSU& gfsu, Projection& projection, U& u, MapType& transfer_map)
539 Visitor visitor(gfsu,projection,u,_leaf_offset_cache,transfer_map);
542 for(
const auto& cell : elements(grid.leafGridView(),Partitions::interior))
551 void replayData(Grid& grid, GFSU& gfsu, Projection& projection, U& u,
const MapType& transfer_map)
553 const IDSet& id_set = grid.globalIdSet();
556 CountVector uc(gfsu,0);
559 Visitor visitor(gfsu,u,uc,_leaf_offset_cache);
562 LeafGridView leafView = grid.leafGridView();
563 for (
const auto& cell : elements(leafView,Partitions::interior))
565 Element ancestor = cell;
567 typename MapType::const_iterator map_it;
568 while ((map_it = transfer_map.find(id_set.id(ancestor))) == transfer_map.end())
570 if (!ancestor.hasFather())
572 "transferMap of GridAdaptor didn't contain ancestor of element with id " << id_set.id(ancestor));
573 ancestor = ancestor.father();
576 visitor(cell,ancestor,map_it->second);
580 DOFHandle addHandle1(gfsu,u);
581 leafView.communicate (addHandle1,
582 Dune::InteriorBorder_InteriorBorder_Interface,Dune::ForwardCommunication);
584 CountHandle addHandle2(gfsu,uc);
585 leafView.communicate (addHandle2,
586 Dune::InteriorBorder_InteriorBorder_Interface,Dune::ForwardCommunication);
589 typename CountVector::iterator ucit = uc.begin();
590 for (
typename U::iterator uit = u.begin(), uend = u.end(); uit != uend; ++uit, ++ucit)
591 (*uit) /= ((*ucit) > 0 ? (*ucit) : 1.0);
610 template<
class Gr
id,
class GFS,
class X>
614 Projection projection(gfs,int_order);
623 grid_adaptor.
backupData(grid,gfs,projection,x1,transferMap1);
633 grid_adaptor.
replayData(grid,gfs,projection,x1,transferMap1);
650 template<
class Gr
id,
class GFS,
class X>
651 void adapt_grid (Grid& grid, GFS& gfs, X& x1, X& x2,
int int_order)
654 Projection projection(gfs,int_order);
663 grid_adaptor.
backupData(grid,gfs,projection,x1,transferMap1);
665 grid_adaptor.
backupData(grid,gfs,projection,x2,transferMap2);
675 grid_adaptor.
replayData(grid,gfs,projection,x1,transferMap1);
677 grid_adaptor.
replayData(grid,gfs,projection,x2,transferMap2);
685 void error_fraction(
const T& x,
typename T::ElementType alpha,
typename T::ElementType beta,
686 typename T::ElementType& eta_alpha,
typename T::ElementType& eta_beta,
int verbose=0)
689 std::cout <<
"+++ error fraction: alpha=" << alpha <<
" beta=" << beta << std::endl;
691 typedef typename T::ElementType NumberType;
692 NumberType total_error = x.one_norm();
693 NumberType max_error = x.infinity_norm();
694 NumberType eta_alpha_left = 0.0;
695 NumberType eta_alpha_right = max_error;
696 NumberType eta_beta_left = 0.0;
697 NumberType eta_beta_right = max_error;
698 for (
int j=1; j<=steps; j++)
700 eta_alpha = 0.5*(eta_alpha_left+eta_alpha_right);
701 eta_beta = 0.5*(eta_beta_left+eta_beta_right);
702 NumberType sum_alpha=0.0;
703 NumberType sum_beta=0.0;
704 unsigned int alpha_count = 0;
705 unsigned int beta_count = 0;
706 for (
typename T::const_iterator it = x.begin(),
711 if (*it >=eta_alpha) { sum_alpha += *it; alpha_count++;}
712 if (*it < eta_beta) { sum_beta += *it; beta_count++;}
716 std::cout <<
"+++ " << j <<
" eta_alpha=" << eta_alpha <<
" alpha_fraction=" << sum_alpha/total_error
717 <<
" elements: " << alpha_count <<
" of " << x.N() << std::endl;
718 std::cout <<
"+++ " << j <<
" eta_beta=" << eta_beta <<
" beta_fraction=" << sum_beta/total_error
719 <<
" elements: " << beta_count <<
" of " << x.N() << std::endl;
721 if (std::abs(alpha-sum_alpha/total_error) <= 0.01 && std::abs(beta-sum_beta/total_error) <= 0.01)
break;
722 if (sum_alpha>alpha*total_error)
723 eta_alpha_left = eta_alpha;
725 eta_alpha_right = eta_alpha;
726 if (sum_beta>beta*total_error)
727 eta_beta_right = eta_beta;
729 eta_beta_left = eta_beta;
733 std::cout <<
"+++ refine_threshold=" << eta_alpha
734 <<
" coarsen_threshold=" << eta_beta << std::endl;
740 void element_fraction(
const T& x,
typename T::ElementType alpha,
typename T::ElementType beta,
741 typename T::ElementType& eta_alpha,
typename T::ElementType& eta_beta,
int verbose=0)
744 typedef typename T::ElementType NumberType;
745 NumberType total_error =x.N();
746 NumberType max_error = x.infinity_norm();
747 NumberType eta_alpha_left = 0.0;
748 NumberType eta_alpha_right = max_error;
749 NumberType eta_beta_left = 0.0;
750 NumberType eta_beta_right = max_error;
751 for (
int j=1; j<=steps; j++)
753 eta_alpha = 0.5*(eta_alpha_left+eta_alpha_right);
754 eta_beta = 0.5*(eta_beta_left+eta_beta_right);
755 NumberType sum_alpha=0.0;
756 NumberType sum_beta=0.0;
757 unsigned int alpha_count = 0;
758 unsigned int beta_count = 0;
760 for (
typename T::const_iterator it = x.begin(),
765 if (*it>=eta_alpha) { sum_alpha += 1.0; alpha_count++;}
766 if (*it< eta_beta) { sum_beta +=1.0; beta_count++;}
770 std::cout << j <<
" eta_alpha=" << eta_alpha <<
" alpha_fraction=" << sum_alpha/total_error
771 <<
" elements: " << alpha_count <<
" of " << x.N() << std::endl;
772 std::cout << j <<
" eta_beta=" << eta_beta <<
" beta_fraction=" << sum_beta/total_error
773 <<
" elements: " << beta_count <<
" of " << x.N() << std::endl;
775 if (std::abs(alpha-sum_alpha/total_error) <= 0.01 && std::abs(beta-sum_beta/total_error) <= 0.01)
break;
776 if (sum_alpha>alpha*total_error)
777 eta_alpha_left = eta_alpha;
779 eta_alpha_right = eta_alpha;
780 if (sum_beta>beta*total_error)
781 eta_beta_right = eta_beta;
783 eta_beta_left = eta_beta;
787 std::cout <<
"+++ refine_threshold=" << eta_alpha
788 <<
" coarsen_threshold=" << eta_beta << std::endl;
798 typedef typename T::ElementType NumberType;
799 NumberType total_error = x.one_norm();
800 NumberType total_elements = x.N();
801 NumberType max_error = x.infinity_norm();
802 std::vector<NumberType> left(bins,0.0);
803 std::vector<NumberType> right(bins,max_error*(1.0+1
e-8));
804 std::vector<NumberType> eta(bins);
805 std::vector<NumberType> target(bins);
806 for (
unsigned int k=0; k<bins; k++)
807 target[k]= (k+1)/((NumberType)bins);
808 for (
int j=1; j<=steps; j++)
810 for (
unsigned int k=0; k<bins; k++)
811 eta[k]= 0.5*(left[k]+right[k]);
812 std::vector<NumberType> sum(bins,0.0);
813 std::vector<int> count(bins,0);
815 for (
typename T::const_iterator it = x.begin(),
820 for (
unsigned int k=0; k<bins; k++)
832 for (
unsigned int k=0; k<bins; k++)
833 if (sum[k]<=target[k]*total_error)
838 std::vector<NumberType> sum(bins,0.0);
839 std::vector<int> count(bins,0);
840 for (
unsigned int i=0; i<x.N(); i++)
841 for (
unsigned int k=0; k<bins; k++)
847 std::cout <<
"+++ error distribution" << std::endl;
848 std::cout <<
"+++ number of elements: " << x.N() << std::endl;
849 std::cout <<
"+++ max element error: " << max_error << std::endl;
850 std::cout <<
"+++ total error: " << total_error << std::endl;
851 std::cout <<
"+++ bin #elements eta sum/total " << std::endl;
852 for (
unsigned int k=0; k<bins; k++)
853 std::cout <<
"+++ " << k+1 <<
" " << count[k] <<
" " << eta[k] <<
" " << sum[k]/total_error << std::endl;
856 template<
typename Gr
id,
typename X>
857 void mark_grid (Grid &grid,
const X& x,
typename X::ElementType refine_threshold,
858 typename X::ElementType coarsen_threshold,
int min_level = 0,
int max_level = std::numeric_limits<int>::max(),
int verbose=0)
860 typedef typename Grid::LeafGridView GV;
862 GV gv = grid.leafGridView();
864 unsigned int refine_cnt=0;
865 unsigned int coarsen_cnt=0;
867 typedef typename X::GridFunctionSpace GFS;
870 typedef typename X::template ConstLocalView<LFSCache> XView;
872 LFS lfs(x.gridFunctionSpace());
873 LFSCache lfs_cache(lfs);
876 for(
const auto& cell : elements(gv))
880 x_view.bind(lfs_cache);
882 if (x_view[0]>=refine_threshold && cell.level() < max_level)
887 if (x_view[0]<=coarsen_threshold && cell.level() > min_level)
895 std::cout <<
"+++ mark_grid: " << refine_cnt <<
" marked for refinement, "
896 << coarsen_cnt <<
" marked for coarsening" << std::endl;
900 template<
typename Gr
id,
typename X>
902 typename X::ElementType coarsen_threshold,
int verbose=0)
904 typedef typename Grid::LeafGridView GV;
906 GV gv = grid.leafGridView();
908 unsigned int coarsen_cnt=0;
910 typedef typename X::GridFunctionSpace GFS;
913 typedef typename X::template ConstLocalView<LFSCache> XView;
915 LFS lfs(x.gridFunctionSpace());
916 LFSCache lfs_cache(lfs);
919 for(
const auto& cell : elements(gv))
923 x_view.bind(lfs_cache);
925 if (x_view[0]>=refine_threshold)
930 if (x_view[0]<=coarsen_threshold)
937 std::cout <<
"+++ mark_grid_for_coarsening: "
938 << coarsen_cnt <<
" marked for coarsening" << std::endl;
946 double optimistic_factor;
947 double coarsen_limit;
948 double balance_limit;
953 double refine_fraction_while_refinement;
954 double coarsen_fraction_while_refinement;
955 double coarsen_fraction_while_coarsening;
956 double timestep_decrease_factor;
957 double timestep_increase_factor;
967 bool have_decreased_time_step;
968 bool have_refined_grid;
971 double accumulated_estimated_error_squared;
972 double minenergy_rate;
976 : scaling(16.0), optimistic_factor(1.0), coarsen_limit(0.5), balance_limit(0.33333),
977 tol(tol_), T(T_), verbose(verbose_), no_adapt(false),
978 refine_fraction_while_refinement(0.7),
979 coarsen_fraction_while_refinement(0.2),
980 coarsen_fraction_while_coarsening(0.2),
981 timestep_decrease_factor(0.5), timestep_increase_factor(1.5),
982 accept(false), adapt_dt(false), adapt_grid(false), newdt(1.0),
983 have_decreased_time_step(false), have_refined_grid(false),
984 accumulated_estimated_error_squared(0.0),
991 timestep_decrease_factor=
s;
996 timestep_increase_factor=
s;
1001 refine_fraction_while_refinement=
s;
1006 coarsen_fraction_while_refinement=
s;
1011 coarsen_fraction_while_coarsening=
s;
1036 optimistic_factor=
s;
1086 return accumulated_estimated_error_squared;
1092 have_decreased_time_step =
false;
1093 have_refined_grid =
false;
1096 template<
typename GM,
typename X>
1097 void evaluate_estimators (GM& grid,
double time,
double dt,
const X& eta_space,
const X& eta_time,
double energy_timeslab)
1104 double spatial_error = eta_space.one_norm();
1105 double temporal_error = scaling*eta_time.one_norm();
1106 double sum = spatial_error + temporal_error;
1108 double allowed = tol*tol*(energy_timeslab+minenergy_rate*dt);
1109 q_s = spatial_error/sum;
1110 q_t = temporal_error/sum;
1117 <<
" sum/allowed=" << sum/allowed
1119 <<
" estimated error=" << sqrt(accumulated_estimated_error_squared+sum)
1120 <<
" energy_rate=" << energy_timeslab/dt
1127 accumulated_estimated_error_squared += sum;
1128 if (verbose>1) std::cout <<
"+++ no adapt mode" << std::endl;
1137 if (verbose>1) std::cout <<
"+++ accepting time step" << std::endl;
1138 accumulated_estimated_error_squared += sum;
1141 if (sum<coarsen_limit*allowed)
1144 if (q_t<balance_limit)
1147 newdt = timestep_increase_factor*dt;
1149 if (verbose>1) std::cout <<
"+++ spatial error dominates: increase time step" << std::endl;
1153 if (q_s>balance_limit)
1156 newdt = timestep_increase_factor*dt;
1158 if (verbose>1) std::cout <<
"+++ increasing time step" << std::endl;
1161 double eta_refine, eta_coarsen;
1162 if (verbose>1) std::cout <<
"+++ mark grid for coarsening" << std::endl;
1165 coarsen_fraction_while_coarsening,eta_refine,eta_coarsen);
1173 if (q_t<balance_limit)
1176 newdt = timestep_increase_factor*dt;
1178 if (verbose>1) std::cout <<
"+++ spatial error dominates: increase time step" << std::endl;
1185 if (verbose>1) std::cout <<
"+++ will redo time step" << std::endl;
1186 if (q_t>1-balance_limit)
1189 newdt = timestep_decrease_factor*dt;
1191 have_decreased_time_step =
true;
1192 if (verbose>1) std::cout <<
"+++ decreasing time step only" << std::endl;
1196 if (q_t<balance_limit)
1198 if (!have_decreased_time_step)
1201 newdt = timestep_increase_factor*dt;
1203 if (verbose>1) std::cout <<
"+++ increasing time step" << std::endl;
1209 newdt = timestep_decrease_factor*dt;
1211 have_decreased_time_step =
true;
1212 if (verbose>1) std::cout <<
"+++ decreasing time step" << std::endl;
1215 double eta_refine, eta_coarsen;
1216 if (verbose>1) std::cout <<
"+++ BINGO mark grid for refinement and coarsening" << std::endl;
1219 coarsen_fraction_while_refinement,eta_refine,eta_coarsen,0);
void adapt_grid(Grid &grid, GFS &gfs, X &x1, int int_order)
adapt a grid, corresponding function space and solution vectors
Definition: adaptivity.hh:611
const std::size_t offset
Definition: localfunctionspace.hh:74
LocalFunctionSpace< GFS > LFS
Definition: adaptivity.hh:373
GFS::Traits::GridView::Grid::LocalIdSet IDSet
Definition: adaptivity.hh:209
void leaf(const LFSLeaf &leaf_lfs, TreePath treePath)
Definition: adaptivity.hh:226
const MassMatrices & inverseMassMatrices(const Element &e)
Calculate the inverse local mass matrix, used in the local L2 projection.
Definition: adaptivity.hh:172
void mark_grid(Grid &grid, const X &x, typename X::ElementType refine_threshold, typename X::ElementType coarsen_threshold, int min_level=0, int max_level=std::numeric_limits< int >::max(), int verbose=0)
Definition: adaptivity.hh:857
void setAdaptationOff()
Definition: adaptivity.hh:1044
array< MassMatrix, TypeTree::TreeInfo< GFS >::leafCount > MassMatrices
Definition: adaptivity.hh:155
LeafOffsetCache & _leaf_offset_cache
Definition: adaptivity.hh:358
Definition: adaptivity.hh:200
LFSIndexCache< LFS > LFSCache
Definition: adaptivity.hh:374
DOFVector::template LocalView< LFSCache > _u_view
Definition: adaptivity.hh:483
const LeafOffsets & operator[](GeometryType gt) const
Definition: adaptivity.hh:42
Definition: adaptivity.hh:368
Definition: adaptivity.hh:942
void evaluate_estimators(GM &grid, double time, double dt, const X &eta_space, const X &eta_time, double energy_timeslab)
Definition: adaptivity.hh:1097
std::size_t size_type
Definition: adaptivity.hh:383
Cell::Geometry Geometry
Definition: adaptivity.hh:378
const LocalDOFVector & _dofs
Definition: adaptivity.hh:410
const Cell & _element
Definition: adaptivity.hh:127
LFSCache _lfs_cache
Definition: adaptivity.hh:480
Definition: adaptivity.hh:32
size_type _offset
Definition: adaptivity.hh:412
void evaluate(const X &x, Y &y) const
Definition: adaptivity.hh:390
bool acceptTimeStep() const
Definition: adaptivity.hh:1049
Projection & _projection
Definition: adaptivity.hh:354
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:112
const E & e
Definition: interpolate.hh:172
size_type _int_order
Definition: adaptivity.hh:359
LocalCountVector _counts
Definition: adaptivity.hh:490
void backupData(Grid &grid, GFSU &gfsu, Projection &projection, U &u, MapType &transfer_map)
Definition: adaptivity.hh:535
Projection::MassMatrices MassMatrices
Definition: adaptivity.hh:219
std::size_t size_type
Definition: adaptivity.hh:222
void setOptimisticFactor(double s)
Definition: adaptivity.hh:1034
LocalDOFVector _u_fine
Definition: adaptivity.hh:488
size_type size() const
Definition: lfsindexcache.hh:423
Dune::PDELab::LeafOffsetCache< GFS > LeafOffsetCache
Definition: adaptivity.hh:207
static const int dim
Definition: adaptivity.hh:212
Cell::HierarchicIterator HierarchicIterator
Definition: adaptivity.hh:213
void setCoarsenLimit(double s)
Definition: adaptivity.hh:1019
Cell _ancestor
Definition: adaptivity.hh:482
void setRefineFractionWhileRefinement(double s)
Definition: adaptivity.hh:999
Geometry _fine_geometry
Definition: adaptivity.hh:409
GridAdaptor(const GFSU &gfs)
The constructor.
Definition: adaptivity.hh:526
Iterator extract_lfs_leaf_sizes(const LFS &lfs, Iterator it)
Definition: lfsindexcache.hh:165
LocalDOFVector _u_tmp
Definition: adaptivity.hh:489
LocalFunctionSpace< GFS > LFS
Definition: adaptivity.hh:36
std::vector< LeafOffsets > _leaf_offset_cache
Definition: adaptivity.hh:70
Definition: adaptivity.hh:145
std::vector< typename FiniteElement::Traits::LocalBasisType::Traits::RangeType > _phi
Definition: adaptivity.hh:411
Dune::PDELab::LeafOffsetCache< GFS > LeafOffsetCache
Definition: adaptivity.hh:375
Traits::IndexContainer::size_type size() const
get current size
Definition: localfunctionspace.hh:206
void mark_grid_for_coarsening(Grid &grid, const X &x, typename X::ElementType refine_threshold, typename X::ElementType coarsen_threshold, int verbose=0)
Definition: adaptivity.hh:901
L2Projection(const GFS &gfs, int intorder=2)
The constructor.
Definition: adaptivity.hh:161
CountVector::template LocalView< LFSCache > _uc_view
Definition: adaptivity.hh:484
MassMatrices & _mass_matrices
Definition: adaptivity.hh:128
size_type _leaf_index
Definition: adaptivity.hh:130
DOFVector::template ConstLocalView< LFSCache > _u_view
Definition: adaptivity.hh:355
const FiniteElement & _finite_element
Definition: adaptivity.hh:407
LFS _lfs
Definition: adaptivity.hh:69
void setCoarsenFractionWhileRefinement(double s)
Definition: adaptivity.hh:1004
LFS::Traits::GridFunctionSpace::Traits::GridView::template Codim< 0 >::Entity Cell
Definition: adaptivity.hh:377
const LocalDOFVector * _u_coarse
Definition: adaptivity.hh:485
L2Projection< typename LFS::Traits::GridFunctionSpace, DOFVector > Projection
Definition: adaptivity.hh:218
TransferMap::mapped_type LocalDOFVector
Definition: adaptivity.hh:215
LFSIndexCache< LFS > LFSCache
Definition: adaptivity.hh:206
replay_visitor(const GFS &gfs, DOFVector &u, CountVector &uc, LeafOffsetCache &leaf_offset_cache)
Definition: adaptivity.hh:470
std::vector< RF > LocalDOFVector
Definition: adaptivity.hh:380
void update()
Definition: lfsindexcache.hh:300
LFS _lfs
Definition: adaptivity.hh:479
Base class for all PDELab exceptions.
Definition: exceptions.hh:17
void setTimeStepIncreaseFactor(double s)
Definition: adaptivity.hh:994
std::vector< typename CountVector::ElementType > LocalCountVector
Definition: adaptivity.hh:381
Definition: genericdatahandle.hh:622
LFS _lfs
Definition: adaptivity.hh:348
Projection::MassMatrix MassMatrix
Definition: adaptivity.hh:220
void setAdaptationOn()
Definition: adaptivity.hh:1039
std::unordered_map< ID, std::vector< typename U::ElementType > > MapType
Definition: adaptivity.hh:519
Definition: adaptivity.hh:27
void update(const Cell &e)
Definition: adaptivity.hh:50
void replayData(Grid &grid, GFSU &gfsu, Projection &projection, U &u, const MapType &transfer_map)
Definition: adaptivity.hh:551
GFS::Traits::GridView::template Codim< 0 >::Entity Cell
Definition: adaptivity.hh:35
LocalFunctionSpace< GFS > LFS
Definition: adaptivity.hh:205
Cell _element
Definition: adaptivity.hh:481
void setCoarsenFractionWhileCoarsening(double s)
Definition: adaptivity.hh:1009
LocalDOFVector _u_fine
Definition: adaptivity.hh:361
void element_fraction(const T &x, typename T::ElementType alpha, typename T::ElementType beta, typename T::ElementType &eta_alpha, typename T::ElementType &eta_beta, int verbose=0)
Definition: adaptivity.hh:740
const GFS & gridFunctionSpace() const
Returns the GridFunctionSpace underlying this LocalFunctionSpace.
Definition: localfunctionspace.hh:264
void error_fraction(const T &x, typename T::ElementType alpha, typename T::ElementType beta, typename T::ElementType &eta_alpha, typename T::ElementType &eta_beta, int verbose=0)
Definition: adaptivity.hh:685
void setBalanceLimit(double s)
Definition: adaptivity.hh:1024
static const int dim
Definition: adaptivity.hh:83
void leaf(const LeafLFS &leaf_lfs, TreePath treePath)
Definition: adaptivity.hh:418
double endT() const
Definition: adaptivity.hh:1079
backup_visitor(const GFS &gfs, Projection &projection, const DOFVector &u, LeafOffsetCache &leaf_offset_cache, TransferMap &transfer_map, std::size_t int_order=2)
Definition: adaptivity.hh:330
Cell _current
Definition: adaptivity.hh:353
double newDT() const
Definition: adaptivity.hh:1064
array< std::size_t, TypeTree::TreeInfo< GFS >::leafCount+1 > LeafOffsets
Definition: adaptivity.hh:40
void startTimeStep()
Definition: adaptivity.hh:1090
TransferMap & _transfer_map
Definition: adaptivity.hh:356
Class for automatic adaptation of the grid.
Definition: adaptivity.hh:509
LeafOffsetCache & _leaf_offset_cache
Definition: adaptivity.hh:486
bool adaptGrid() const
Definition: adaptivity.hh:1059
Cell::Geometry Geometry
Definition: adaptivity.hh:211
TimeAdaptationStrategy(double tol_, double T_, int verbose_=0)
Definition: adaptivity.hh:975
double accumulatedErrorSquared() const
Definition: adaptivity.hh:1084
Cell _ancestor
Definition: adaptivity.hh:352
const std::string s
Definition: function.hh:1102
bool adaptDT() const
Definition: adaptivity.hh:1054
void setTemporalScaling(double s)
Definition: adaptivity.hh:1029
void setMinEnergyRate(double s)
Definition: adaptivity.hh:1014
void error_distribution(const T &x, int bins)
Definition: adaptivity.hh:795
LeafOffsetCache(const GFS &gfs)
Definition: adaptivity.hh:64
LFSCache _lfs_cache
Definition: adaptivity.hh:349
Definition: adaptivity.hh:386
const IDSet & _id_set
Definition: adaptivity.hh:350
void operator()(const Cell &element, const Cell &ancestor, const LocalDOFVector &u_coarse)
Definition: adaptivity.hh:437
LocalDOFVector * _u_coarse
Definition: adaptivity.hh:357
Cell _element
Definition: adaptivity.hh:351
size_type _leaf_index
Definition: adaptivity.hh:487
double qs() const
Definition: adaptivity.hh:1069
double qt() const
Definition: adaptivity.hh:1074
DynamicMatrix< typename U::ElementType > MassMatrix
Definition: adaptivity.hh:154
void operator()(const Cell &element)
Definition: adaptivity.hh:275
GFS::Traits::GridView::template Codim< 0 >::Entity Cell
Definition: adaptivity.hh:210
void setTimeStepDecreaseFactor(double s)
Definition: adaptivity.hh:989
coarse_function(const FiniteElement &finite_element, Geometry coarse_geometry, Geometry fine_geometry, const LocalDOFVector &dofs, size_type offset)
Definition: adaptivity.hh:399
size_type _leaf_index
Definition: adaptivity.hh:360
GFS::Traits::GridView::ctype DF
Definition: adaptivity.hh:223
DOFVector::ElementType RF
Definition: adaptivity.hh:214
const QuadratureRule< DF, dim > & _quadrature_rule
Definition: adaptivity.hh:129
Geometry _coarse_geometry
Definition: adaptivity.hh:408
DOFVector::ElementType RF
Definition: adaptivity.hh:379