35#ifndef TIME_EXTRAPOLATION_H_
36#define TIME_EXTRAPOLATION_H_
42#include "common/common.h"
43#include "common/util/smart_pointer.h"
45#include "lib_algebra/lib_algebra.h"
46#include "lib_algebra/operator/debug_writer.h"
48#include "lib_disc/function_spaces/grid_function.h"
49#include "lib_disc/function_spaces/grid_function_user_data.h"
50#include "lib_disc/function_spaces/integrate.h"
51#include "lib_disc/function_spaces/metric_spaces.h"
53#include "lib_disc/time_disc/time_disc_interface.h"
54#include "lib_disc/spatial_disc/user_data/linker/scale_add_linker.h"
83 inline void VecScaleAddWithNormRel(
double &vUpdate,
double alpha2,
const double &vFine,
double alpha3,
const double &vCoarse,
double &norm)
85 const double update = alpha2*vFine + alpha3*vCoarse;
86 vUpdate = vUpdate + update;
87 norm = std::max(norm, 0.5*fabs(update)/(1.0+fabs(vFine)+fabs(vCoarse)));
91 template<
typename vector_t,
template <
class T>
class TE_VEC>
92 inline void VecScaleAddWithNormRel(TE_VEC<vector_t> &vUpdate,
double alpha2,
const TE_VEC<vector_t> &vFine,
double alpha3,
const TE_VEC<vector_t> &vCoarse,
double &norm)
94 for(
size_t i=0; i<vUpdate.size(); i++)
95 VecScaleAddWithNormRel(vUpdate[i], alpha2, vFine[i], alpha3, vCoarse[i], norm);
99 inline void VecScaleAddWithNormInf(
double &vUpdate,
double alpha2,
const double &vFine,
double alpha3,
const double &vCoarse,
double &norm)
101 const double update = alpha2*vFine + alpha3*vCoarse;
102 vUpdate = vUpdate + update;
103 norm = std::max(norm, fabs(update));
107 template<
typename vector_t,
template <
class T>
class TE_VEC>
108 inline void VecScaleAddWithNormInf(TE_VEC<vector_t> &vUpdate,
double alpha2,
const TE_VEC<vector_t> &vFine,
double alpha3,
const TE_VEC<vector_t> &vCoarse,
double &norm,
const int delta=1,
const int offset=0)
111 for(
size_t i=offset; i<vUpdate.size(); i+=delta)
112 VecScaleAddWithNormInf(vUpdate[i], alpha2, vFine[i], alpha3, vCoarse[i], norm);
119 inline void VecScaleAddWithNorm2(
double &vUpdate,
double alpha2,
const double &vFine,
double alpha3,
const double &vCoarse,
double &norm)
121 const double update = alpha2*vFine + alpha3*vCoarse;
122 vUpdate = vUpdate+ update;
123 norm += update*update;
127 template<
typename vector_t,
template <
class T>
class TE_VEC>
128 inline void VecScaleAddWithNorm2(TE_VEC<vector_t> &vUpdate,
double alpha2,
const TE_VEC<vector_t> &vFine,
double alpha3,
const TE_VEC<vector_t> &vCoarse,
double &norm,
const int delta=1,
const int offset=0)
130 for(
size_t i=offset; i<vUpdate.size(); i+=delta)
131 VecScaleAddWithNorm2(vUpdate[i], alpha2, vFine[i], alpha3, vCoarse[i], norm);
142template <
class TVector>
143class ISubDiagErrorEst
147 ISubDiagErrorEst() : m_est(0.0) {};
150 virtual ~ISubDiagErrorEst() {};
153 virtual bool update(SmartPtr<TVector> vUpdate, number alpha2, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse) = 0;
157 void reset_estimate() { m_est=0.0; };
159 virtual std::string config_string()
const {
return "ISubDiagErrorEst";}
143class ISubDiagErrorEst {
…};
169template <
class TVector>
170class NormInfEstimator :
public ISubDiagErrorEst<TVector>
173 typedef ISubDiagErrorEst<TVector> base_type;
180 ISubDiagErrorEst<TVector>(), m_stride(1), m_offset(0) {};
184 bool update(SmartPtr<TVector> vUpdate, number alpha2, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse)
186 const int delta = m_stride;
187 const int offset = m_offset;
188 base_type::m_est=0.0;
189 tools::VecScaleAddWithNormInf(*vUpdate, alpha2, *vFine, -alpha2, *vCoarse, base_type::m_est, delta, offset);
184 bool update(SmartPtr<TVector> vUpdate, number alpha2, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse) {
…}
194 void set_offset(
int offset) {m_offset=offset;}
197 void set_stride(
int delta) {m_stride=delta;}
170class NormInfEstimator :
public ISubDiagErrorEst<TVector> {
…};
203template <
class TVector>
204class Norm2Estimator :
public ISubDiagErrorEst<TVector>
207 typedef ISubDiagErrorEst<TVector> base_type;
214 ISubDiagErrorEst<TVector>(), m_stride(1), m_offset(0) {};
215 Norm2Estimator(
int stride) :
216 ISubDiagErrorEst<TVector>(), m_stride(stride), m_offset(0) {};
217 Norm2Estimator(
int delta,
int offset) :
218 ISubDiagErrorEst<TVector>(), m_stride(delta), m_offset (offset) {};
221 bool update(SmartPtr<TVector> vUpdate, number alpha2, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse)
223 const int delta = m_stride;
224 const int offset = m_offset;
225 base_type::m_est=0.0;
226 tools::VecScaleAddWithNorm2(*vUpdate, alpha2, *vFine, -alpha2, *vCoarse, base_type::m_est, delta, offset);
228 double locEst = base_type::m_est;
230 vUpdate->layouts()->proc_comm().allreduce(&locEst, &globEst, 1, PCL_DT_DOUBLE, PCL_RO_SUM);
231 base_type::m_est = globEst;
233 base_type::m_est = sqrt(base_type::m_est);
221 bool update(SmartPtr<TVector> vUpdate, number alpha2, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse) {
…}
238 void set_offset(
int offset) { m_offset=offset;}
241 void set_stride(
int delta) { m_stride=delta;}
204class Norm2Estimator :
public ISubDiagErrorEst<TVector> {
…};
247template <
class TVector>
248class NormRelEstimator :
public ISubDiagErrorEst<TVector>
251 typedef ISubDiagErrorEst<TVector> base_type;
255 NormRelEstimator() : ISubDiagErrorEst<TVector>() {};
258 bool update(SmartPtr<TVector> vUpdate, number alpha2, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse)
261 tools::VecScaleAddWithNormRel(*vUpdate, alpha2, *vFine, -alpha2, *vCoarse, base_type::m_est);
258 bool update(SmartPtr<TVector> vUpdate, number alpha2, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse) {
…}
248class NormRelEstimator :
public ISubDiagErrorEst<TVector> {
…};
273 typedef TVector vector_type;
276 VectorDebugWritingEstimator()
277 : VectorDebugWritingObject<vector_type>() {}
279 VectorDebugWritingEstimator(SmartPtr<IVectorDebugWriter<vector_type> > spDebugWriter)
280 : VectorDebugWritingObject<vector_type>(spDebugWriter) {}
282 int get_call_id() { return m_dgbCall; }
283 void inc_call_id() { m_dgbCall++; }
295template <
typename TGr
idFunction>
296class SupErrorEvaluator
297:
public IComponentSpace<TGridFunction>
300 typedef IComponentSpace<TGridFunction> base_type;
302 SupErrorEvaluator(
const char *fctNames) : base_type(fctNames) {};
304 SupErrorEvaluator(
const char *fctNames,
const char* ssNames )
305 : base_type(fctNames, ssNames, 1) {};
306 ~SupErrorEvaluator() {};
309 using IComponentSpace<TGridFunction>::norm;
310 using IComponentSpace<TGridFunction>::distance;
312 double norm(SmartPtr<TGridFunction> uFine)
313 {
return norm(*uFine); }
315 double norm(TGridFunction& uFine)
318 SubsetGroup ssGrp(uFine.domain()->subset_handler());
319 if (base_type::m_ssNames != NULL)
320 ssGrp.add(TokenizeString(base_type::m_ssNames));
327 for (
size_t i = 0; i < ssGrp.size(); ++i)
330 const int si = ssGrp[i];
333 switch (ssGrp.dim(i))
335 case DIM_SUBSET_EMPTY_GRID:
break;
336 case 0: maxVal = std::max(maxVal, findFctMaxOnSubset<Vertex>(uFine, si));
break;
337 case 1: maxVal = std::max(maxVal, findFctMaxOnSubset<Edge>(uFine, si));
break;
338 case 2: maxVal = std::max(maxVal, findFctMaxOnSubset<Face>(uFine, si));
break;
339 case 3: maxVal = std::max(maxVal, findFctMaxOnSubset<Volume>(uFine, si));
break;
340 default: UG_THROW(
"SupErrorEvaluator::norm: Dimension " << ssGrp.dim(i) <<
" not supported.");
346 if (pcl::NumProcs() > 1)
348 pcl::ProcessCommunicator com;
349 number local = maxVal;
350 com.allreduce(&local, &maxVal, 1, PCL_DT_DOUBLE, PCL_RO_MAX);
358 double norm2(TGridFunction& uFine)
359 {
double norm1 = norm(uFine);
return norm1*norm1;}
361 double distance(TGridFunction& uFine, TGridFunction& uCoarse)
363 UG_COND_THROW(uFine.dof_distribution().get() != uCoarse.dof_distribution().get(),
364 "Coarse and fine solutions do not have the same underlying dof distro.");
366 SmartPtr<TGridFunction> uErr = uCoarse.clone();
367 uErr->operator-=(uFine);
371 double distance2(TGridFunction& uFine, TGridFunction& uCoarse)
372 {
double dist = distance(uFine, uCoarse);
return dist*dist;}
375 template <
typename TBaseElem>
376 number findFctMaxOnSubset(
const TGridFunction& u,
int si)
const
378 ConstSmartPtr<DoFDistribution> dd = u.dof_distribution();
381 try {fct = dd->fct_id_by_name(base_type::m_fctNames.c_str());}
382 UG_CATCH_THROW(
"Function index could not be determined.\n"
383 "Bear in mind that only one function can be evaluated in this error evaluator.");
386 typename DoFDistribution::traits<TBaseElem>::const_iterator it = dd->begin<TBaseElem>(si);
387 typename DoFDistribution::traits<TBaseElem>::const_iterator itEnd = dd->end<TBaseElem>(si);
388 for (; it != itEnd; ++it)
390 std::vector<DoFIndex> vInd;
395 size_t nInd = dd->dof_indices(*it, fct, vInd,
false,
false);
396 for (
size_t i = 0; i < nInd; ++i)
397 maxVal = std::max(maxVal, fabs(DoFRef(u, vInd[i])));
296class SupErrorEvaluator {
…};
410template <
typename TDataIn,
typename TGr
idFunction>
412 :
public StdIntegrand<number, TGridFunction::dim, DeltaSquareIntegrand<TDataIn, TGridFunction> >
416 static const int worldDim = TGridFunction::dim;
419 typedef TDataIn data_type;
423 static number product(
const number &x,
const number &y)
426 static number product(
const MathVector<worldDim> &x,
const MathVector<worldDim> &y)
427 {
return VecDot(x,y);}
431 SmartPtr<UserData<TDataIn, worldDim> > m_spData;
434 const TGridFunction* m_pGridFct1;
435 const TGridFunction* m_pGridFct2;
443 const TGridFunction* pGridFct1,
const TGridFunction* pGridFct2,
445 : m_spData(spData), m_pGridFct1(pGridFct1), m_pGridFct2(pGridFct2), m_time(time)
447 m_spData->set_function_pattern(pGridFct1->function_pattern());
452 : m_spData(spData), m_pGridFct1(NULL), m_pGridFct2(NULL), m_time(time)
454 if(m_spData->requires_grid_fct())
455 UG_THROW(
"UserDataDeltaIntegrand: Missing GridFunction, but "
456 " data requires grid function.")
462 template <
int elemDim>
463 void get_values(TDataIn vValue[],
464 ConstSmartPtr<UserData<TDataIn, worldDim> > spData,
465 const TGridFunction& gridFct,
466 const MathVector<worldDim> vGlobIP[],
468 const MathVector<worldDim> vCornerCoords[],
469 const MathVector<elemDim> vLocIP[],
470 const MathMatrix<elemDim, worldDim> vJT[],
474 if(spData->requires_grid_fct())
481 gridFct.indices(pElem, ind);
487 GetLocalVector(u, gridFct);
488 std::cout << u << std::endl;
492 (*spData)(vValue, vGlobIP, m_time, this->m_si, pElem,
493 vCornerCoords, vLocIP, numIP, &u, &vJT[0]);
495 UG_CATCH_THROW(
"UserDataDeltaIntegrand: Cannot evaluate data.");
501 (*spData)(vValue, vGlobIP, m_time, this->m_si, numIP);
503 UG_CATCH_THROW(
"UserDataDeltaIntegrand: Cannot evaluate data.");
510 template <
int elemDim>
512 const MathVector<worldDim> vGlobIP[],
514 const MathVector<worldDim> vCornerCoords[],
515 const MathVector<elemDim> vLocIP[],
516 const MathMatrix<elemDim, worldDim> vJT[],
519 std::vector<TDataIn> v1(numIP);
521 get_values<elemDim>(&v1[0], m_spData, *m_pGridFct1, vGlobIP, pElem, vCornerCoords, vLocIP, vJT, numIP);
522 std::cout <<
"--- got v1!" << std::endl;
524 if (m_pGridFct2 != NULL)
526 std::vector<TDataIn> v2(numIP);
529 get_values<elemDim>(&v2[0], m_spData, *m_pGridFct2, vGlobIP, pElem, vCornerCoords, vLocIP, vJT, numIP);
530 std::cout <<
"--- got v2!" << std::endl;
532 for (
size_t ip=0; ip<numIP; ++ip)
535 std::cout << std::setprecision(12) << v1[ip] <<
" "<< std::setprecision(12) << v2[ip] << std::endl;
537 vValue[ip] = this->product(v1[ip], v1[ip]);
542 for (
size_t ip=0; ip<numIP; ++ip)
543 { vValue[ip] = this->product(v1[ip], v1[ip]); }
551template <
typename TGr
idFunction,
typename TDataInput>
552class UserDataSpace :
public IComponentSpace<TGridFunction>
555 typedef IComponentSpace<TGridFunction> base_type;
556 typedef UserData<TDataInput, TGridFunction::dim> input_user_data_type;
558 UserDataSpace(
const char *fctNames) : base_type(fctNames) {};
559 UserDataSpace(
const char *fctNames,
int order) : base_type(fctNames, order) {};
562 void set_user_data(SmartPtr<input_user_data_type> spData)
563 { m_userData = spData; }
567 using IComponentSpace<TGridFunction>::norm;
568 using IComponentSpace<TGridFunction>::distance;
570 double norm2(TGridFunction& uFine)
573 return IntegrateSubsets(spIntegrand, uFine, base_type::m_ssNames, base_type::m_quadorder,
"best");
576 double distance2(TGridFunction& uFine, TGridFunction& uCoarse)
579 std::cerr <<
"uFine="<<(
void*) (&uFine) <<
", uCoarse="<< (
void*) (&uCoarse) << std::endl;
580 return IntegrateSubsets(spIntegrand, uFine, base_type::m_ssNames, base_type::m_quadorder,
"best");
584 SmartPtr<input_user_data_type> m_userData;
552class UserDataSpace :
public IComponentSpace<TGridFunction> {
…};
590template <class TDomain, class TAlgebra>
591class GridFunctionEstimator :
592 public ISubDiagErrorEst<typename TAlgebra::vector_type>
595 typedef typename TAlgebra::vector_type TVector;
596 typedef GridFunction<TDomain, TAlgebra> grid_function_type;
597 typedef IErrorEvaluator<grid_function_type> evaluator_type;
599 std::vector<SmartPtr<evaluator_type> > m_evaluators;
600 number m_refNormValue;
603 typedef ISubDiagErrorEst<TVector> base_type;
606 ScaledGridFunctionEstimator() : m_refNormValue(0.0) {}
607 ScaledGridFunctionEstimator(number ref) : m_refNormValue(ref) {}
609 void add(SmartPtr<evaluator_type> eval)
611 m_evaluators.push_back(eval);
615 bool update(SmartPtr<TVector> vUpdate, number alpha, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse)
617 // typedef ScaleAddLinker<number, TDomain::dim, number> linker_type;
618 typedef GridFunctionNumberData<TGridFunction> TNumberData;
621 SmartPtr<grid_function_type> uFine = vFine.template cast_dynamic<grid_function_type>();
622 SmartPtr<grid_function_type> uCoarse = vCoarse.template cast_dynamic<grid_function_type>();
623 if (uFine.invalid() || uCoarse.invalid()) return false;
626 if (m_refNormValue<=0.0)
628 // relative error estimator
629 //number unorm = L2Norm(uFine, m_fctNames.c_str(), m_quadorder);
630 //number enorm = alpha*L2Error(uFine, m_fctNames.c_str(), uCoarse, m_fctNames.c_str() ,m_quadorder);
634 for (typename std::vector<evaluator_type>::iterator it = m_evaluators.begin(); it!= m_evaluators.end(); ++it)
636 enorm = alpha * it->distance(uFine, uCoarse);
637 unorm = std::max(it->norm(uFine), 1e-10);
638 est += (enorm*enorm)/(unorm*unorm);
639 std::cerr << "unorm=" << unorm << "enorm=" << enorm << "est="<<est << std::endl;
642 base_type::m_est = sqrt(est)/m_evaluators.size();
643 std::cerr << "eps="<< base_type::m_est << std::endl;
648 // weighted error estimator
650 for (typename std::vector<evaluator_type>::iterator it = m_evaluators.begin(); it!= m_evaluators.end(); ++it)
652 enorm += alpha * it->distance(uFine, uCoarse);
654 base_type::m_est = enorm/m_refNormValue;
656 std::cerr << "unorm (FIXED)=" << m_refNormValue << "enorm=" << enorm << "eps="<< base_type::m_est << std::endl;
661 VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
665 void set_reference_norm(number norm)
666 {m_refNormValue = norm; }
670 std::string config_string() const
672 std::stringstream ss;
673 ss << "GridFunctionEstimator:\n";
674 for (typename std::vector<GridFunctionEvaluator>::const_iterator it = m_evaluators.begin(); it!= m_evaluators.end(); ++it)
676 ss << it->config_string();
689template <
class TDomain,
class TAlgebra>
690class GridFunctionEstimator :
691 public ISubDiagErrorEst<typename TAlgebra::vector_type>
694 typedef typename TAlgebra::vector_type TVector;
696 typedef ISubDiagErrorEst<TVector> base_type;
697 typedef GridFunction<TDomain, TAlgebra> grid_function_type;
698 typedef IGridFunctionSpace<grid_function_type> subspace_type ;
702 typedef std::pair<SmartPtr<subspace_type>, number> weighted_obj_type;
704 number m_refNormValue;
705 std::vector<weighted_obj_type> m_spWeightedSubspaces;
709 GridFunctionEstimator() : ISubDiagErrorEst<TVector>(), m_refNormValue(0.0)
713 GridFunctionEstimator(
double ref) : ISubDiagErrorEst<TVector>(), m_refNormValue(ref)
717 void add(SmartPtr<subspace_type> spSubspace)
718 { m_spWeightedSubspaces.push_back(std::make_pair(spSubspace, 1.0)); }
717 void add(SmartPtr<subspace_type> spSubspace) {
…}
720 void add(SmartPtr<subspace_type> spSubspace, number sigma)
721 { m_spWeightedSubspaces.push_back(std::make_pair(spSubspace, sigma)); }
725 bool update(SmartPtr<TVector> vUpdate, number alpha, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse)
728 typedef ScaleAddLinker<number, TDomain::dim, number> linker_type;
729 typedef GridFunction<TDomain, TAlgebra> grid_function_type;
732 SmartPtr<grid_function_type> uFine = vFine.template cast_dynamic<grid_function_type>();
733 SmartPtr<grid_function_type> uCoarse = vCoarse.template cast_dynamic<grid_function_type>();
734 if (uFine.invalid() || uCoarse.invalid())
return false;
737 if (m_refNormValue<=0.0)
742 for (
typename std::vector<weighted_obj_type>::iterator it = m_spWeightedSubspaces.begin(); it!= m_spWeightedSubspaces.end(); ++it)
744 const double sigma = it->second;
745 const double norm2 = it->first->norm2(*uFine);
746 const double dist2 = alpha * alpha * (it->first->distance2(*uFine, *uCoarse));
747 unorm2 += sigma * norm2;
748 enorm2 += sigma * dist2;
750 UG_LOG(
"unorm=" << norm2 <<
"\tenorm=" << dist2 <<
"\tsigma=" << sigma << std::endl);
753 base_type::m_est = sqrt(enorm2/unorm2);
754 UG_LOG(
">>> unorm2=" << unorm2 <<
"\tenorm2=" << enorm2 <<
"\teps="<< base_type::m_est << std::endl);
760 for (
typename std::vector<weighted_obj_type>::iterator it = m_spWeightedSubspaces.begin(); it!= m_spWeightedSubspaces.end(); ++it)
762 const double sigma = it->second;
763 const double dist2 = alpha * alpha * (it->first->distance2(*uFine, *uCoarse));
764 enorm2 += sigma*dist2;
767 base_type::m_est = sqrt(enorm2)/m_refNormValue;
768 UG_LOG(
"unorm (FIXED)=" << m_refNormValue <<
"enorm2=" << enorm2 <<
"eps="<< base_type::m_est << std::endl);
772 VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
725 bool update(SmartPtr<TVector> vUpdate, number alpha, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse) {
…}
776 void set_reference_norm(number norm)
777 {m_refNormValue = norm; }
783 std::stringstream ss;
784 ss <<
"GridFunctionEstimator:\n";
785 for (
typename std::vector<weighted_obj_type>::const_iterator it = m_spWeightedSubspaces.begin(); it!= m_spWeightedSubspaces.end(); ++it)
787 ss << it->second <<
"*" << it->first->config_string();
690class GridFunctionEstimator : {
…};
794template <
class TDomain,
class TAlgebra>
795class ScaledGridFunctionEstimator :
796 public ISubDiagErrorEst<typename TAlgebra::vector_type>
799 typedef typename TAlgebra::vector_type TVector;
802 typedef ISubDiagErrorEst<TVector> base_type;
803 typedef GridFunction<TDomain, TAlgebra> grid_function_type;
804 typedef IComponentSpace<grid_function_type> subspace_type;
805 typedef CompositeSpace<grid_function_type> composite_type;
808 ScaledGridFunctionEstimator() : base_type() {}
811 void add(SmartPtr<subspace_type> spSubspace)
812 { m_spSubspaces.push_back(spSubspace); }
815 void add(SmartPtr<composite_type> spCompositeSpace)
817 typedef typename composite_type::weighted_obj_type weighted_obj_type;
818 const std::vector<weighted_obj_type> &spaces = spCompositeSpace->get_subspaces();
819 for (
typename std::vector<weighted_obj_type>::const_iterator it = spaces.begin(); it != spaces.end(); ++it)
821 m_spSubspaces.push_back(it->first);
827 bool update(SmartPtr<TVector> vUpdate, number alpha, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse)
831 SmartPtr<grid_function_type> uFine = vFine.template cast_dynamic<grid_function_type>();
832 SmartPtr<grid_function_type> uCoarse = vCoarse.template cast_dynamic<grid_function_type>();
833 if (uFine.invalid() || uCoarse.invalid())
return false;
837 for (
typename std::vector<SmartPtr<subspace_type> >::iterator it = m_spSubspaces.begin();
838 it!= m_spSubspaces.end(); ++it)
841 double enorm2 = (alpha*alpha) * (*it)->distance2(*uFine, *uCoarse);
842 double unorm2 = std::max((*it)->norm2(*uFine), 1e-10*enorm2);
843 est += (enorm2)/(unorm2);
844 UG_LOGN(
"unorm2=" << unorm2 <<
"\tenorm2=" << enorm2 <<
"\tratio2="<< (enorm2)/(unorm2) <<
"est2=" << est);
847 base_type::m_est = sqrt(est)/m_spSubspaces.size();
848 UG_LOGN(
"eps="<< base_type::m_est);
851 VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
827 bool update(SmartPtr<TVector> vUpdate, number alpha, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse) {
…}
859 std::stringstream ss;
860 ss <<
"ScaledGridFunctionEstimator:\n";
861 for (
typename std::vector<SmartPtr<subspace_type> >::const_iterator it = m_spSubspaces.begin();
862 it!= m_spSubspaces.end(); ++it)
864 ss << (*it)->config_string();
871 std::vector<SmartPtr<subspace_type> > m_spSubspaces;
795class ScaledGridFunctionEstimator : {
…};
878template <
class TDomain,
class TAlgebra>
879class CompositeGridFunctionEstimator :
880 public ISubDiagErrorEst<typename TAlgebra::vector_type>
883 typedef typename TAlgebra::vector_type TVector;
886 typedef ISubDiagErrorEst<TVector> base_type;
887 typedef GridFunction<TDomain, TAlgebra> grid_function_type;
888 typedef IComponentSpace<grid_function_type> subspace_type;
889 typedef CompositeSpace<grid_function_type> composite_type;
892 CompositeGridFunctionEstimator() : base_type(), m_strictRelativeError(
false) {}
894 void use_strict_relative_norms(
bool b)
895 { m_strictRelativeError = b; }
898 void add(SmartPtr<subspace_type> spSubspace)
899 { m_spSubspaces.push_back(spSubspace); }
902 void add(SmartPtr<composite_type> spCompositeSpace)
904 typedef typename composite_type::weighted_obj_type weighted_obj_type;
905 const std::vector<weighted_obj_type> &spaces = spCompositeSpace->get_subspaces();
906 for (
typename std::vector<weighted_obj_type>::const_iterator it = spaces.begin(); it != spaces.end(); ++it)
908 m_spSubspaces.push_back(it->first);
914 bool update(SmartPtr<TVector> vUpdate, number alpha, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse)
918 SmartPtr<grid_function_type> uFine = vFine.template cast_dynamic<grid_function_type>();
919 SmartPtr<grid_function_type> uCoarse = vCoarse.template cast_dynamic<grid_function_type>();
920 if (uFine.invalid() || uCoarse.invalid())
return false;
925 const double SMALL = 1e-10;
927 double max_rel = 0.0;
931 for (
typename std::vector<SmartPtr<subspace_type> >::iterator it = m_spSubspaces.begin();
932 it!= m_spSubspaces.end(); ++it)
935 double cmp_e2 = (alpha*alpha) * (*it)->distance2(*uFine, *uCoarse);
936 double cmp_u2 = (*it)->norm2(*uFine);
939 max_rel = std::max(max_rel, cmp_e2/
940 (cmp_u2 + SMALL/ (1.0+cmp_e2+cmp_u2)));
946 UG_LOGN(
"ui-2=" << cmp_u2 <<
"\tei-2=" << cmp_e2<<
947 "\tunorm2=" << unorm2 <<
"\tenorm2=" << enorm2 <<
948 "\tratio2="<< (enorm2)/(unorm2) <<
949 "\tmax. rel (squared) ="<< max_rel);
953 base_type::m_est = (m_strictRelativeError) ? sqrt(max_rel) :
954 sqrt(enorm2/std::max(unorm2, SMALL*enorm2));
955 UG_LOGN(
"eps="<< base_type::m_est);
958 VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
914 bool update(SmartPtr<TVector> vUpdate, number alpha, SmartPtr<TVector> vFine, SmartPtr<TVector> vCoarse) {
…}
966 std::stringstream ss;
967 ss <<
"CompositeGridFunctionEstimator:\n";
968 for (
typename std::vector<SmartPtr<subspace_type> >::const_iterator it = m_spSubspaces.begin();
969 it!= m_spSubspaces.end(); ++it)
971 ss << (*it)->config_string();
978 std::vector<SmartPtr<subspace_type> > m_spSubspaces;
979 bool m_strictRelativeError;
879class CompositeGridFunctionEstimator : {
…};
984template <
typename TVector>
998 m_solution(nsteps.size()),
999 m_subdiag_error_est(nsteps.size(), INFINITY)
1005 m_num_steps(nsteps),
1006 m_solution(nsteps.size()),
1007 m_subdiag_error_est(nsteps.size(), INFINITY)
1010 virtual ~AitkenNevilleTimex() {}
1012 void set_global_stepsize(number H) {m_stepsize=H;}
1013 number get_global_stepsize() {
return m_stepsize;}
1017 { m_solution[i] = soli; }
1021 {
return m_solution[i]; }
1026 m_subdiag = subdiag;
1030 const std::vector<number>& get_error_estimates()
const
1031 {
return m_subdiag_error_est; }
1035 {
return m_subdiag_error_est[k];}
1046 int get_best_index() const
1048 std::vector<number>::iterator best = std::min_element(m_subdiag_error_est.begin(), m_subdiag_error_est.end());
1049 //std::cout << "min element at: " << std::distance(std::begin(m_subdiag_error_est), best);
1050 return std::distance(m_subdiag_error_est.begin(), best);
1065 void apply(
size_t nstages,
bool with_error=
true)
1067 UG_ASSERT(nstages <= m_solution.size(),
1068 "Dimensions do not match:" << nstages <<
">" << m_solution.size());
1073 for (
size_t k=1; k<m_solution.size(); ++k)
1074 { m_subdiag_error_est[k] = INFINITY; }
1079 for (
size_t k=1; k<nstages; ++k)
1083 for (
size_t i=nstages-1; i>=k; --i)
1085 UG_ASSERT(m_solution[i].valid(),
"Invalid SmarPtr!");
1086 UG_ASSERT(m_solution[i-1].valid(),
"Invalid SmarPtr!");
1088 SmartPtr<vector_type> solcoarse = m_solution[i-1];
1089 SmartPtr<vector_type> solfine = m_solution[i];
1093 const number scaling = ((1.0*m_num_steps[i])/(1.0*m_num_steps[i-k])-1.0);
1094 UG_LOG(
"scaling="<<i <<
","<< k <<
1095 ": ns["<<i<<
"]="<< m_num_steps[i] <<
1096 "ns2["<<i-k<<
"]=" << m_num_steps[i-k] <<
"=" << scaling << std::endl);
1098 if (with_error && (i==k))
1101 m_subdiag->update(solfine, (1.0/scaling), solfine, solcoarse);
1102 number subdiag_error_est=m_subdiag->get_current_estimate();
1105 m_subdiag_error_est[k]=subdiag_error_est;
1107 UG_LOG(
" ErrorEst["<< k<<
"]=" << m_subdiag_error_est[k] <<
";" << std::endl);
1112 VecScaleAdd(*solfine, (1.0+1.0/scaling), *solfine,
1113 -(1.0/scaling), *solcoarse);
1065 void apply(
size_t nstages,
bool with_error=
true) {
…}
1126 const size_t nstages = m_num_steps.size();
1133 number substep(
size_t i) {
return m_stepsize/m_num_steps[i];}
1138 static const int m_order=1;
1141 SmartPtr<ISubDiagErrorEst<vector_type> > m_subdiag;
1144 std::vector<size_t> m_num_steps;
1147 std::vector<SmartPtr<vector_type> > m_solution;
1150 std::vector<number> m_subdiag_error_est;
SmartPtr< vector_type > get_solution(size_t i)
get solution (on stage i)
Definition time_extrapolation.h:1020
void apply()
apply for all stages
Definition time_extrapolation.h:1123
void set_error_estimate(SmartPtr< ISubDiagErrorEst< vector_type > > subdiag)
set error estimator
Definition time_extrapolation.h:1024
void apply(size_t nstages, bool with_error=true)
best error estimate
Definition time_extrapolation.h:1065
void set_solution(SmartPtr< vector_type > soli, int i)
set solution (for stage i)
Definition time_extrapolation.h:1016
AitkenNevilleTimex(std::vector< size_t > nsteps)
Definition time_extrapolation.h:994
number get_error_estimate(int k) const
error estimate on stage k
Definition time_extrapolation.h:1034
vector_type vector_type
Definition time_extrapolation.h:989
bool update(SmartPtr< TVector > vUpdate, number alpha, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)
compute update vUpdate = vFine + alpha * (vFine- vCoarse) AND estimate error | alpha * (vFine- vCoars...
Definition time_extrapolation.h:914
std::string config_string() const
print config string
Definition time_extrapolation.h:964
Definition time_extrapolation.h:413
DeltaSquareIntegrand(SmartPtr< UserData< TDataIn, worldDim > > spData, number time)
constructor
Definition time_extrapolation.h:451
DeltaSquareIntegrand(SmartPtr< UserData< TDataIn, worldDim > > spData, const TGridFunction *pGridFct1, const TGridFunction *pGridFct2, number time)
constructor
Definition time_extrapolation.h:442
void evaluate(number vValue[], const MathVector< worldDim > vGlobIP[], GridObject *pElem, const MathVector< worldDim > vCornerCoords[], const MathVector< elemDim > vLocIP[], const MathMatrix< elemDim, worldDim > vJT[], const size_t numIP)
Definition time_extrapolation.h:511
bool update(SmartPtr< TVector > vUpdate, number alpha, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)
apply w/ rel norm
Definition time_extrapolation.h:725
std::string config_string() const
print config string
Definition time_extrapolation.h:781
void add(SmartPtr< subspace_type > spSubspace)
add sub-space component
Definition time_extrapolation.h:717
Interface for sub-diagonal error estimator (w.r.t time in Aitken-Neville scheme)
Definition time_extrapolation.h:144
number get_current_estimate()
get estimate
Definition time_extrapolation.h:156
virtual bool update(SmartPtr< TVector > vUpdate, number alpha2, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)=0
compute update vUpdate = vFine + alpha * (vFine- vCoarse) AND estimate error | alpha * (vFine- vCoars...
Evaluate using (algebraic) L2 norm.
Definition time_extrapolation.h:205
bool update(SmartPtr< TVector > vUpdate, number alpha2, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)
compute update vUpdate = vFine + alpha * (vFine- vCoarse) AND estimate error | alpha * (vFine- vCoars...
Definition time_extrapolation.h:221
bool update(SmartPtr< TVector > vUpdate, number alpha2, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)
compute update vUpdate = vFine + alpha * (vFine- vCoarse) AND estimate error | alpha * (vFine- vCoars...
Definition time_extrapolation.h:184
bool update(SmartPtr< TVector > vUpdate, number alpha2, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)
compute update vUpdate = vFine + alpha * (vFine- vCoarse) AND estimate error | alpha * (vFine- vCoars...
Definition time_extrapolation.h:258
bool update(SmartPtr< TVector > vUpdate, number alpha, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)
compute update vUpdate = vFine + alpha * (vFine- vCoarse) AND estimate error | alpha * (vFine- vCoars...
Definition time_extrapolation.h:827
std::string config_string() const
print config string
Definition time_extrapolation.h:857