13#ifndef ALGORITHM_3_ERROR_ESTIMATOR_HH
14#define ALGORITHM_3_ERROR_ESTIMATOR_HH
21#include <boost/timer/timer.hpp>
22#include <boost/fusion/include/at_c.hpp>
36 struct InverseOperatorResult;
37 template <
class,
int>
class FieldVector;
42 template <
template <
class,
class,
class,
bool>
class Functional,
class VariableSetDescription,
class ExtensionVariableSetDescription,
class ExtensionSpace,
43 class NormFunctional,
class LinearSolverLA,
class LinearSolverHA,
class LinearSolverLM=LinearSolverLA,
class LinearSolverHM=LinearSolverHA,
45 class HierarchicalBasisErrorEstimator2 :
public AbstractHierarchicalErrorEstimator
47 static constexpr int noOfVariables = ExtensionVariableSetDescription::noOfVariables;
49 static constexpr int yId = 1, uId = 0, pId = 2;
51 typedef Functional<VariableSetDescription,VariableSetDescription,VariableSetDescription,lumpM>
FLL;
52 typedef Functional<ExtensionVariableSetDescription,VariableSetDescription,ExtensionVariableSetDescription,lumpM>
FHL;
53 typedef Functional<VariableSetDescription,ExtensionVariableSetDescription,VariableSetDescription,lumpM>
FLH;
54 typedef Functional<ExtensionVariableSetDescription,ExtensionVariableSetDescription,ExtensionVariableSetDescription,lumpM>
FHH;
81 static constexpr int dim = VariableSetDescription::Grid::dimension;
84 typedef typename VariableSetDescription::template CoefficientVectorRepresentation<>
CVL;
85 typedef typename VariableSetDescription::template CoefficientVectorRepresentation<yId,yId+1>
CVLY;
86 typedef typename VariableSetDescription::template CoefficientVectorRepresentation<uId,uId+1>
CVLU;
87 typedef typename VariableSetDescription::template CoefficientVectorRepresentation<pId,pId+1>
CVLP;
92 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<0,1>::type
CoefficientVectorH01;
93 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<0,2>::type
CoefficientVectorH02;
94 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<2,3>
CVH23;
95 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<2,3>::type
CoefficientVectorH23;
96 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<>
CVH;
97 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<yId,yId+1>
CVHY;
98 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<uId,uId+1>
CVHU;
99 typedef typename ExtensionVariableSetDescription::template CoefficientVectorRepresentation<pId,pId+1>
CVHP;
104 typedef typename ExtensionVariableSetDescription::GridView::template Codim<0>::Iterator
CellIterator;
114 ExtensionSpace& extensionSpace_,
Scalar fraction=0.7,
bool verbose_=
false)
115 : normFunctional(normFunctional_), variableSetDescription(variableSetDescription_), extensionVariableSetDescription(extensionVariableSetDescription_),
116 extensionSpace(extensionSpace_), assembler(extensionVariableSetDescription.spaces),
117 squaredFraction(fraction*fraction), verbose(verbose_)
124 void operator()(AbstractVector
const& x_, AbstractVector
const& dx_,
int step, AbstractVector
const&)
126 using boost::fusion::at_c;
127 if(verbose) std::cout <<
"ERROR ESTIMATOR: Start." << std::endl;
134 typename ExtensionVariableSetDescription::VariableSet tmpRep(extensionVariableSetDescription), mySol(extensionVariableSetDescription);
137 All all(*assll,
false);
138 Ahh ahh(*asshh,
false);
139 Alh alh(*asslh,
false);
141 Matrix mAll = all.template get<Matrix>();
143 Matrix mAhh = ahh.template get<Matrix>();
145 Matrix mAlh = alh.template get<Matrix>();
149 at_c<yId>(tmpRep.data) = at_c<0>(rhs0.data);
155 at_c<pId>(tmpRep.data) = at_c<0>(sol0.data);
156 at_c<pId>(mySol.data) = at_c<0>(sol0.data);
163 Bhl bhl(*asshl,
false);
164 Blh blh(*asslh,
false);
165 Bll bll(*assll,
false);
166 Bhh bhh(*asshh,
false);
169 std::vector<Scalar> tmpx, tmpy;
170 IstlInterfaceDetail::toVector(sol0,tmpy);
171 IstlInterfaceDetail::toVector(rhs1L,tmpx);
172 tmpmat.
usmtv(-1.0,tmpy,tmpx);
173 IstlInterfaceDetail::fromVector(tmpx,rhs1L);
176 tmpx.clear(); tmpy.clear();
177 IstlInterfaceDetail::toVector(sol0,tmpy);
178 IstlInterfaceDetail::toVector(rhs1H,tmpx);
179 tmpmat = bhh.template get<MatrixAsTriplet<Scalar> >();
180 tmpmat.
usmtv(-1.0,tmpy,tmpx);
181 IstlInterfaceDetail::fromVector(tmpx,rhs1H);
185 Muuhh muuhh(*asshh,
true);
186 Muull muull(*assll,
true);
187 Muulh muulh(*asslh,
true);
198 at_c<uId>(mySol.data) = at_c<0>(solhu.data);
216 at_c<yId>(mySol.data) = at_c<0>(solhy.data);
219 auto const& is = extensionSpace.gridManager().grid().leafIndexSet();
220 errorDistribution.clear();
221 errorDistribution.resize(is.size(0),std::make_pair(0.0,0));
222 Scalar errLevel(0.0), minRefine(0.2);
225 EnergyError energyError(normFunctional,xl.
get(),mySol);
227 EnergyErrorAssembler eeAssembler(extensionSpace.gridManager(), energyError.getSpaces());
230 typename EnergyError::ErrorVector distError( eeAssembler.rhs() );
231 typename EnergyError::AnsatzVars::VariableSet mde( energyError.getVariableSetDescription() );
237 std::string name =
"errorDistribution_";
238 name += boost::lexical_cast<std::string>(step);
239 writeVTKFile(mde.descriptions.gridView,mde.descriptions,mde,name);
244 CellIterator cend = extensionVariableSetDescription.gridView.template end<0>();
245 for (
CellIterator ci=extensionVariableSetDescription.gridView.template begin<0>(); ci!=cend; ++ci)
246 errorDistribution[is.index(*ci)] = std::make_pair( fabs(boost::fusion::at_c<0>(mde.data).value(*ci,
Dune::FieldVector<Scalar,dim>(0.3))) , is.index(*ci));
256 Scalar bulkCriterionTolerance = squaredFraction*totalErrorSquared;
259 std::cout <<
"ERROR ESTIMATOR: totalErrorSquared: " << totalErrorSquared << std::endl;
260 std::cout <<
"ERROR ESTIMATOR: bulkCriterionTolerance: " << bulkCriterionTolerance << std::endl;
262 Scalar bulkErrorSquared = 0;
264 std::vector<std::pair<Scalar,size_t> > bulkErrorDistribution;
265 auto const& is = extensionSpace.gridManager().grid().leafIndexSet();
266 CellIterator cend = extensionVariableSetDescription.gridView.template end<0>();
268 while(bulkErrorSquared < bulkCriterionTolerance)
270 bulkErrorDistribution.push_back(errorDistribution[bulkErrorDistribution.size()]);
271 bulkErrorSquared += bulkErrorDistribution.back().first;
274 if(verbose) std::cout <<
"ERROR ESTIMATOR: number of candidates for refinement: " << bulkErrorDistribution.size() << std::endl;
304 for (
CellIterator ci=extensionVariableSetDescription.gridView.template begin<0>(); ci!=cend; ++ci)
306 for(
int i=0; i<bulkErrorDistribution.size(); ++i)
307 if(is.index(*ci) == bulkErrorDistribution[i].second)
313 extensionSpace.gridManager().mark(1,*ci);
318 extensionSpace.gridManager().adaptAtOnce();
323 return sqrt(fabs(totalErrorSquared));
328 return extensionSpace.gridManager().grid().size(0);
331 template <
typename... Args>
334 Fll.reset(
new FLL(args...));
335 Flh.reset(
new FLH(args...));
336 Fhl.reset(
new FHL(args...));
337 Fhh.reset(
new FHH(args...));
341 void initAssemblers()
343 assll.reset(
new Assll(extensionVariableSetDescription.spaces));
344 asslh.reset(
new Asslh(extensionVariableSetDescription.spaces));
345 asshl.reset(
new Asshl(extensionVariableSetDescription.spaces));
346 asshh.reset(
new Asshh(extensionVariableSetDescription.spaces));
349 void assembleAt(
const Bridge::Vector<VarSet>& xl,
const Bridge::Vector<ExtVarSet>& xe)
351 assll->assemble(linearization(*Fll,xl.get()));
352 asslh->assemble(linearization(*Flh,xl.get()));
353 asshl->assemble(linearization(*Fhl,xe.get()));
354 asshh->assemble(linearization(*Fhh,xe.get()));
357 std::unique_ptr<FLL> Fll;
358 std::unique_ptr<FLH> Flh;
359 std::unique_ptr<FHL> Fhl;
360 std::unique_ptr<FHH> Fhh;
361 std::unique_ptr<Assll> assll;
362 std::unique_ptr<Asslh> asslh;
363 std::unique_ptr<Asshl> asshl;
364 std::unique_ptr<Asshh> asshh;
367 NormFunctional& normFunctional;
368 VariableSetDescription& variableSetDescription;
369 ExtensionVariableSetDescription& extensionVariableSetDescription;
370 ExtensionSpace& extensionSpace;
374 std::vector<std::pair<double,int> > errorDistribution;
An adaptor presenting a Dune::LinearOperator <domain_type,range_type> interface to a contiguous sub-b...
virtual void applyscaleadd(Scalar alpha, Domain const &x, Range &b) const
Compute .
Mathematical Vector that supports copy-on-write, implements AbstractFunctionSpaceElement.
Implementation const & get() const
Access to the data.
Defines assembly of hierarchically extended problems for defining DLY style error estimators.
CVLU::type CoefficientVectorLU
ExtensionVariableSetDescription::template CoefficientVectorRepresentation< 2, 3 > CVH23
size_t gridSize() const final
AssembledGalerkinOperator< Asshh, pId, pId+1, yId, yId+1 > Ahh
AssembledGalerkinOperator< Asshl, pId, pId+1, yId, yId+1 > Ahl
CVLY::type CoefficientVectorLY
void operator()(AbstractVector const &x_, AbstractVector const &dx_, int step, AbstractVector const &)
VariableSetDescription::template CoefficientVectorRepresentation CVL
VariableSetDescription::template CoefficientVectorRepresentation< uId, uId+1 > CVLU
AssembledGalerkinOperator< Asshh, pId, pId+1, uId, uId+1 > Bhh
ExtensionVariableSetDescription::template CoefficientVectorRepresentation< uId, uId+1 > CVHU
AssembledGalerkinOperator< Asshl, pId, pId+1, uId, uId+1 > Bhl
Functional< VariableSetDescription, ExtensionVariableSetDescription, VariableSetDescription, lumpM > FLH
VariableSetDescription::template CoefficientVectorRepresentation< pId, pId+1 > CVLP
void initFunctionals(const Args &... args)
AssembledGalerkinOperator< Asshh, uId, uId+1, uId, uId+1 > Muuhh
VariationalFunctionalAssembler< LinearizationAt< FLH > > Asslh
VariableSet< VariableSetDescription > VarSet
CVHU::type CoefficientVectorHU
AssembledGalerkinOperator< Asslh, uId, uId+1, uId, uId+1 > Muulh
AssembledGalerkinOperator< Asslh, pId, pId+1, yId, yId+1 > Alh
ExtensionVariableSetDescription::template CoefficientVectorRepresentation CVH
AssembledGalerkinOperator< Asshl, uId, uId+1, uId, uId+1 > Muuhl
CVHY::type CoefficientVectorHY
ExtensionVariableSetDescription::template CoefficientVectorRepresentation< pId, pId+1 > CVHP
AssembledGalerkinOperator< Asslh, pId, pId+1, uId, uId+1 > Blh
ExtensionVariableSetDescription::GridView::template Codim< 0 >::Iterator CellIterator
AssembledGalerkinOperator< Asshh, yId, yId+1, yId, yId+1 > Myyhh
VariationalFunctionalAssembler< LinearizationAt< FHL > > Asshl
HierarchicErrorEstimator< LinearizationAt< FLL >, ExtensionVariableSetDescription, ExtensionVariableSetDescription, HierarchicErrorEstimatorDetail::TakeAllD2< LinearizationAt< FLL > > > ErrorEstimator
Functional< ExtensionVariableSetDescription, ExtensionVariableSetDescription, ExtensionVariableSetDescription, lumpM > FHH
HierarchicalBasisErrorEstimator2(NormFunctional &normFunctional_, VariableSetDescription &variableSetDescription_, ExtensionVariableSetDescription &extensionVariableSetDescription_, ExtensionSpace &extensionSpace_, Scalar fraction=0.7, bool verbose_=false)
VariationalFunctionalAssembler< ErrorEstimator > Assembler
ExtensionVariableSetDescription::template CoefficientVectorRepresentation< 0, 1 >::type CoefficientVectorH01
AssembledGalerkinOperator< Assll, pId, pId+1, yId, yId+1 > All
CVHP::type CoefficientVectorHP
ExtensionVariableSetDescription::template CoefficientVectorRepresentation< 2, 3 >::type CoefficientVectorH23
Functional< VariableSetDescription, VariableSetDescription, VariableSetDescription, lumpM > FLL
AssembledGalerkinOperator< Assll, pId, pId+1, uId, uId+1 > Bll
VariationalFunctionalAssembler< LinearizationAt< FHH > > Asshh
VariableSetDescription::template CoefficientVectorRepresentation< yId, yId+1 > CVLY
Functional< ExtensionVariableSetDescription, VariableSetDescription, ExtensionVariableSetDescription, lumpM > FHL
double estimatedAbsoluteError() const final
CVLP::type CoefficientVectorLP
VariationalFunctionalAssembler< LinearizationAt< FLL > > Assll
CVH::type CoefficientVectorH
VariableSet< ExtensionVariableSetDescription > ExtVarSet
MatrixAsTriplet< Scalar > Matrix
ExtensionVariableSetDescription::template CoefficientVectorRepresentation< yId, yId+1 > CVHY
AssembledGalerkinOperator< Assll, uId, uId+1, uId, uId+1 > Muull
virtual ~HierarchicalBasisErrorEstimator2()
ExtensionVariableSetDescription::template CoefficientVectorRepresentation< 0, 2 >::type CoefficientVectorH02
CVL::type CoefficientVectorL
Functional_HH::Scalar Scalar
MatrixAsTriplet & transpose()
Transposition.
void usmtv(Scalar const alpha, X const &x, Y &y) const
Matrix-vector multiplication.
A class that stores information about a set of variables.
A class for storing a heterogeneous collection of FunctionSpaceElement s.
Error estimation via hierachic FEM.
@ MUMPS
MUMPS sparse solver.
bool biggerThanAbs(const std::pair< double, int > &x1, const std::pair< double, int > &x2)
double add(const double &x1, const std::pair< double, int > &x2)
Bridge classes that connect low level FE algorithms to higher level algorithms.
Variables and their descriptions.