33 #ifndef TIME_EXTRAPOLATION_H_
34 #define TIME_EXTRAPOLATION_H_
81 inline void VecScaleAddWithNormRel(
double &vUpdate,
double alpha2,
const double &vFine,
double alpha3,
const double &vCoarse,
double &norm)
83 const double update = alpha2*vFine + alpha3*vCoarse;
84 vUpdate = vUpdate + update;
85 norm = std::max(norm, 0.5*fabs(update)/(1.0+fabs(vFine)+fabs(vCoarse)));
89 template<
typename vector_t,
template <
class T>
class TE_VEC>
90 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)
92 for(
size_t i=0; i<vUpdate.size(); i++)
97 inline void VecScaleAddWithNormInf(
double &vUpdate,
double alpha2,
const double &vFine,
double alpha3,
const double &vCoarse,
double &norm)
99 const double update = alpha2*vFine + alpha3*vCoarse;
100 vUpdate = vUpdate + update;
101 norm = std::max(norm, fabs(update));
105 template<
typename vector_t,
template <
class T>
class TE_VEC>
106 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)
109 for(
size_t i=offset; i<vUpdate.size(); i+=delta)
117 inline void VecScaleAddWithNorm2(
double &vUpdate,
double alpha2,
const double &vFine,
double alpha3,
const double &vCoarse,
double &norm)
119 const double update = alpha2*vFine + alpha3*vCoarse;
120 vUpdate = vUpdate+ update;
121 norm += update*update;
125 template<
typename vector_t,
template <
class T>
class TE_VEC>
126 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)
128 for(
size_t i=offset; i<vUpdate.size(); i+=delta)
140 template <
class TVector>
167 template <
class TVector>
201 template <
class TVector>
245 template <
class TVector>
293 template <
typename TGr
idFunction>
311 {
return norm(*uFine); }
313 double norm(TGridFunction& uFine)
316 SubsetGroup ssGrp(uFine.domain()->subset_handler());
325 for (
size_t i = 0; i < ssGrp.
size(); ++i)
328 const int si = ssGrp[i];
331 switch (ssGrp.
dim(i))
334 case 0: maxVal = std::max(maxVal, findFctMaxOnSubset<Vertex>(uFine, si));
break;
335 case 1: maxVal = std::max(maxVal, findFctMaxOnSubset<Edge>(uFine, si));
break;
336 case 2: maxVal = std::max(maxVal, findFctMaxOnSubset<Face>(uFine, si));
break;
337 case 3: maxVal = std::max(maxVal, findFctMaxOnSubset<Volume>(uFine, si));
break;
338 default:
UG_THROW(
"SupErrorEvaluator::norm: Dimension " << ssGrp.
dim(i) <<
" not supported.");
357 {
double norm1 =
norm(uFine);
return norm1*norm1;}
359 double distance(TGridFunction& uFine, TGridFunction& uCoarse)
361 UG_COND_THROW(uFine.dof_distribution().get() != uCoarse.dof_distribution().get(),
362 "Coarse and fine solutions do not have the same underlying dof distro.");
365 uErr->operator-=(uFine);
369 double distance2(TGridFunction& uFine, TGridFunction& uCoarse)
370 {
double dist =
distance(uFine, uCoarse);
return dist*dist;}
373 template <
typename TBaseElem>
381 "Bear in mind that only one function can be evaluated in this error evaluator.");
386 for (; it != itEnd; ++it)
388 std::vector<DoFIndex> vInd;
393 size_t nInd = dd->dof_indices(*it, fct, vInd,
false,
false);
394 for (
size_t i = 0; i < nInd; ++i)
395 maxVal = std::max(maxVal, fabs(
DoFRef(u, vInd[i])));
408 template <
typename TDataIn,
typename TGr
idFunction>
410 :
public StdIntegrand<number, TGridFunction::dim, DeltaSquareIntegrand<TDataIn, TGridFunction> >
441 const TGridFunction* pGridFct1,
const TGridFunction* pGridFct2,
445 m_spData->set_function_pattern(pGridFct1->function_pattern());
453 UG_THROW(
"UserDataDeltaIntegrand: Missing GridFunction, but "
454 " data requires grid function.")
460 template <
int elemDim>
463 const TGridFunction& gridFct,
472 if(spData->requires_grid_fct())
479 gridFct.indices(pElem, ind);
486 std::cout << u << std::endl;
490 (*spData)(vValue, vGlobIP,
m_time, this->
m_si, pElem,
491 vCornerCoords, vLocIP, numIP, &u, &vJT[0]);
499 (*spData)(vValue, vGlobIP,
m_time, this->
m_si, numIP);
508 template <
int elemDim>
517 std::vector<TDataIn> v1(numIP);
519 get_values<elemDim>(&v1[0],
m_spData, *
m_pGridFct1, vGlobIP, pElem, vCornerCoords, vLocIP, vJT, numIP);
520 std::cout <<
"--- got v1!" << std::endl;
524 std::vector<TDataIn> v2(numIP);
527 get_values<elemDim>(&v2[0],
m_spData, *
m_pGridFct2, vGlobIP, pElem, vCornerCoords, vLocIP, vJT, numIP);
528 std::cout <<
"--- got v2!" << std::endl;
530 for (
size_t ip=0; ip<numIP; ++ip)
533 std::cout << std::setprecision(12) << v1[ip] <<
" "<< std::setprecision(12) << v2[ip] << std::endl;
535 vValue[ip] = this->
product(v1[ip], v1[ip]);
540 for (
size_t ip=0; ip<numIP; ++ip)
541 { vValue[ip] = this->
product(v1[ip], v1[ip]); }
549 template <
typename TGr
idFunction,
typename TDataInput>
574 double distance2(TGridFunction& uFine, TGridFunction& uCoarse)
577 std::cerr <<
"uFine="<<(
void*) (&uFine) <<
", uCoarse="<< (
void*) (&uCoarse) << std::endl;
687 template <
class TDomain,
class TAlgebra>
753 const double sigma = it->second;
754 const double norm2 = it->first->norm2(*uFine);
755 const double dist2 = alpha * alpha * (it->first->distance2(*uFine, *uCoarse));
756 unorm2 += sigma * norm2;
757 enorm2 += sigma * dist2;
759 UG_LOG(
"unorm=" << norm2 <<
"\tenorm=" << dist2 <<
"\tsigma=" << sigma << std::endl);
771 const double sigma = it->second;
772 const double dist2 = alpha * alpha * (it->first->distance2(*uFine, *uCoarse));
773 enorm2 += sigma*dist2;
781 VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
792 std::stringstream ss;
793 ss <<
"GridFunctionEstimator:\n";
796 ss << it->second <<
"*" << it->first->config_string();
803 template <
class TDomain,
class TAlgebra>
827 const std::vector<weighted_obj_type> &spaces = spCompositeSpace->get_subspaces();
828 for (
typename std::vector<weighted_obj_type>::const_iterator it = spaces.begin(); it != spaces.end(); ++it)
850 double enorm2 = (alpha*alpha) * (*it)->distance2(*uFine, *uCoarse);
851 double unorm2 = std::max((*it)->norm2(*uFine), 1e-10*enorm2);
852 est += (enorm2)/(unorm2);
853 UG_LOGN(
"unorm2=" << unorm2 <<
"\tenorm2=" << enorm2 <<
"\tratio2="<< (enorm2)/(unorm2) <<
"est2=" << est);
860 VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
868 std::stringstream ss;
869 ss <<
"ScaledGridFunctionEstimator:\n";
873 ss << (*it)->config_string();
887 template <
class TDomain,
class TAlgebra>
911 const std::vector<weighted_obj_type> &spaces = spCompositeSpace->get_subspaces();
912 for (
typename std::vector<weighted_obj_type>::const_iterator it = spaces.begin(); it != spaces.end(); ++it)
935 enorm2 += (alpha*alpha) * (*it)->distance2(*uFine, *uCoarse);
936 unorm2 += (*it)->norm2(*uFine);
937 UG_LOGN(
"unorm2=" << unorm2 <<
"\tenorm2=" << enorm2 <<
"\t(ratio2="<< (enorm2)/(unorm2) <<
")");
945 VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
953 std::stringstream ss;
954 ss <<
"CompositeGridFunctionEstimator:\n";
958 ss << (*it)->config_string();
971 template <
typename TVector>
1052 void apply(
size_t nstages,
bool with_error=
true)
1055 "Dimensions do not match:" << nstages <<
">" <<
m_solution.size());
1066 for (
size_t k=1; k<nstages; ++k)
1070 for (
size_t i=nstages-1; i>=k; --i)
1081 UG_LOG(
"scaling="<<i <<
","<< k <<
1083 "ns2["<<i-k<<
"]=" <<
m_num_steps[i-k] <<
"=" << scaling << std::endl);
1085 if (with_error && (i==k))
1088 m_subdiag->update(solfine, (1.0/scaling), solfine, solcoarse);
1099 VecScaleAdd(*solfine, (1.0+1.0/scaling), *solfine,
1100 -(1.0/scaling), *solcoarse);
size_t allreduce(const size_t &t, pcl::ReduceOperation op) const
Definition: time_extrapolation.h:973
static const int m_order
Definition: time_extrapolation.h:1125
void apply()
apply for all stages
Definition: time_extrapolation.h:1110
void set_error_estimate(SmartPtr< ISubDiagErrorEst< vector_type > > subdiag)
set error estimator
Definition: time_extrapolation.h:1011
void apply(size_t nstages, bool with_error=true)
best error estimate
Definition: time_extrapolation.h:1052
number m_stepsize
Definition: time_extrapolation.h:1124
void set_solution(SmartPtr< vector_type > soli, int i)
set solution (for stage i)
Definition: time_extrapolation.h:1003
const std::vector< number > & get_error_estimates() const
Definition: time_extrapolation.h:1017
std::vector< number > m_subdiag_error_est
Definition: time_extrapolation.h:1137
SmartPtr< ISubDiagErrorEst< vector_type > > m_subdiag
Definition: time_extrapolation.h:1128
std::vector< size_t > m_num_steps
Definition: time_extrapolation.h:1131
SmartPtr< vector_type > get_solution(size_t i)
get solution (on stage i)
Definition: time_extrapolation.h:1007
std::vector< SmartPtr< vector_type > > m_solution
Definition: time_extrapolation.h:1134
AitkenNevilleTimex(std::vector< size_t > nsteps)
Definition: time_extrapolation.h:981
number get_global_stepsize()
Definition: time_extrapolation.h:1000
virtual ~AitkenNevilleTimex()
Definition: time_extrapolation.h:997
number get_error_estimate(int k) const
error estimate on stage k
Definition: time_extrapolation.h:1021
TVector vector_type
vector type of solutions
Definition: time_extrapolation.h:976
number substep(size_t i)
Definition: time_extrapolation.h:1120
void set_global_stepsize(number H)
Definition: time_extrapolation.h:999
AitkenNevilleTimex(std::vector< size_t > nsteps, SmartPtr< ISubDiagErrorEst< vector_type > > error)
Definition: time_extrapolation.h:989
Evaluate difference between two functions (w.r.t various norms)
Definition: time_extrapolation.h:890
GridFunction< TDomain, TAlgebra > grid_function_type
Definition: time_extrapolation.h:896
std::vector< SmartPtr< subspace_type > > m_spSubspaces
Definition: time_extrapolation.h:965
void add(SmartPtr< subspace_type > spSubspace)
Definition: time_extrapolation.h:904
ISubDiagErrorEst< TVector > base_type
Definition: time_extrapolation.h:895
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:920
void add(SmartPtr< composite_type > spCompositeSpace)
Definition: time_extrapolation.h:908
CompositeGridFunctionEstimator()
Definition: time_extrapolation.h:901
IComponentSpace< grid_function_type > subspace_type
Definition: time_extrapolation.h:897
TAlgebra::vector_type TVector
Definition: time_extrapolation.h:892
CompositeSpace< grid_function_type > composite_type
Definition: time_extrapolation.h:898
std::string config_string() const
print config string
Definition: time_extrapolation.h:951
std::pair< SmartPtr< obj_type >, number > weighted_obj_type
Definition: time_extrapolation.h:411
SmartPtr< UserData< TDataIn, worldDim > > m_spData
Definition: time_extrapolation.h:429
static number product(const MathVector< worldDim > &x, const MathVector< worldDim > &y)
Definition: time_extrapolation.h:424
const TGridFunction * m_pGridFct2
Definition: time_extrapolation.h:433
number m_time
Definition: time_extrapolation.h:436
DeltaSquareIntegrand(SmartPtr< UserData< TDataIn, worldDim > > spData, number time)
constructor
Definition: time_extrapolation.h:449
static number product(const number &x, const number &y)
Definition: time_extrapolation.h:421
DeltaSquareIntegrand(SmartPtr< UserData< TDataIn, worldDim > > spData, const TGridFunction *pGridFct1, const TGridFunction *pGridFct2, number time)
constructor
Definition: time_extrapolation.h:440
static const int worldDim
Definition: time_extrapolation.h:414
void get_values(TDataIn vValue[], ConstSmartPtr< UserData< TDataIn, worldDim > > spData, const TGridFunction &gridFct, 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:461
TDataIn data_type
Definition: time_extrapolation.h:417
const TGridFunction * m_pGridFct1
Definition: time_extrapolation.h:432
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:509
Evaluate using continuous norms.
Definition: time_extrapolation.h:690
bool update(SmartPtr< TVector > vUpdate, number alpha, SmartPtr< TVector > vFine, SmartPtr< TVector > vCoarse)
apply w/ rel norm
Definition: time_extrapolation.h:734
ISubDiagErrorEst< TVector > base_type
Definition: time_extrapolation.h:694
void set_reference_norm(number norm)
Definition: time_extrapolation.h:785
TAlgebra::vector_type TVector
Definition: time_extrapolation.h:692
GridFunctionEstimator()
Definition: time_extrapolation.h:707
IGridFunctionSpace< grid_function_type > subspace_type
Definition: time_extrapolation.h:696
std::pair< SmartPtr< subspace_type >, number > weighted_obj_type
Definition: time_extrapolation.h:700
std::vector< weighted_obj_type > m_spWeightedSubspaces
Definition: time_extrapolation.h:703
std::string config_string() const
print config string
Definition: time_extrapolation.h:790
void add(SmartPtr< subspace_type > spSubspace, number sigma)
Definition: time_extrapolation.h:718
GridFunction< TDomain, TAlgebra > grid_function_type
Definition: time_extrapolation.h:695
GridFunctionEstimator(double ref)
Definition: time_extrapolation.h:711
void add(SmartPtr< subspace_type > spSubspace)
add sub-space component
Definition: time_extrapolation.h:715
number m_refNormValue
Definition: time_extrapolation.h:702
Interface for sub-diagonal error estimator (w.r.t time in Aitken-Neville scheme)
Definition: time_extrapolation.h:142
number m_est
Definition: time_extrapolation.h:160
virtual std::string config_string() const
Definition: time_extrapolation.h:157
number get_current_estimate()
get estimate
Definition: time_extrapolation.h:154
void reset_estimate()
Definition: time_extrapolation.h:155
virtual ~ISubDiagErrorEst()
Definition: time_extrapolation.h:148
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...
ISubDiagErrorEst()
Definition: time_extrapolation.h:145
void resize(const LocalIndices &ind)
Evaluate using (algebraic) L2 norm.
Definition: time_extrapolation.h:203
int m_offset
Definition: time_extrapolation.h:207
int m_stride
Definition: time_extrapolation.h:206
ISubDiagErrorEst< TVector > base_type
Definition: time_extrapolation.h:205
void set_stride(int delta)
Definition: time_extrapolation.h:239
void set_offset(int offset)
Definition: time_extrapolation.h:236
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:219
Norm2Estimator(int delta, int offset)
Definition: time_extrapolation.h:215
Norm2Estimator()
Definition: time_extrapolation.h:211
Norm2Estimator(int stride)
Definition: time_extrapolation.h:213
Evaluate using (algebraic) infinity norm.
Definition: time_extrapolation.h:169
ISubDiagErrorEst< TVector > base_type
Definition: time_extrapolation.h:171
NormInfEstimator()
Definition: time_extrapolation.h:177
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:182
int m_stride
Definition: time_extrapolation.h:172
void set_offset(int offset)
Definition: time_extrapolation.h:192
int m_offset
Definition: time_extrapolation.h:173
void set_stride(int delta)
Definition: time_extrapolation.h:195
Evaluate using (algebraic) L2 norm.
Definition: time_extrapolation.h:247
NormRelEstimator()
Definition: time_extrapolation.h:253
ISubDiagErrorEst< TVector > base_type
Definition: time_extrapolation.h:249
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:256
Evaluate difference between two functions (w.r.t various norms)
Definition: time_extrapolation.h:806
CompositeSpace< grid_function_type > composite_type
Definition: time_extrapolation.h:814
void add(SmartPtr< composite_type > spCompositeSpace)
Definition: time_extrapolation.h:824
IComponentSpace< grid_function_type > subspace_type
Definition: time_extrapolation.h:813
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:836
TAlgebra::vector_type TVector
Definition: time_extrapolation.h:808
ISubDiagErrorEst< TVector > base_type
Definition: time_extrapolation.h:811
GridFunction< TDomain, TAlgebra > grid_function_type
Definition: time_extrapolation.h:812
std::vector< SmartPtr< subspace_type > > m_spSubspaces
Definition: time_extrapolation.h:880
void add(SmartPtr< subspace_type > spSubspace)
Definition: time_extrapolation.h:820
ScaledGridFunctionEstimator()
Definition: time_extrapolation.h:817
std::string config_string() const
print config string
Definition: time_extrapolation.h:866
void add(const char *name)
Definition: time_extrapolation.h:296
IComponentSpace< TGridFunction > base_type
Definition: time_extrapolation.h:298
double norm2(TGridFunction &uFine)
Definition: time_extrapolation.h:356
~SupErrorEvaluator()
Definition: time_extrapolation.h:304
SupErrorEvaluator(const char *fctNames, const char *ssNames)
Definition: time_extrapolation.h:302
double distance(TGridFunction &uFine, TGridFunction &uCoarse)
Definition: time_extrapolation.h:359
number findFctMaxOnSubset(const TGridFunction &u, int si) const
Definition: time_extrapolation.h:374
SupErrorEvaluator(const char *fctNames)
Definition: time_extrapolation.h:300
double distance2(TGridFunction &uFine, TGridFunction &uCoarse)
Definition: time_extrapolation.h:369
double norm(TGridFunction &uFine)
Definition: time_extrapolation.h:313
double norm(SmartPtr< TGridFunction > uFine)
Definition: time_extrapolation.h:310
Evaluate the difference for a (dependent) UserData type induced by different grid functions.
Definition: time_extrapolation.h:551
void set_user_data(SmartPtr< input_user_data_type > spData)
Definition: time_extrapolation.h:560
UserDataSpace(const char *fctNames)
Definition: time_extrapolation.h:556
double norm2(TGridFunction &uFine)
Definition: time_extrapolation.h:568
IComponentSpace< TGridFunction > base_type
Definition: time_extrapolation.h:553
SmartPtr< input_user_data_type > m_userData
Definition: time_extrapolation.h:582
~UserDataSpace()
Definition: time_extrapolation.h:558
UserDataSpace(const char *fctNames, int order)
Definition: time_extrapolation.h:557
double distance2(TGridFunction &uFine, TGridFunction &uCoarse)
Definition: time_extrapolation.h:574
UserData< TDataInput, TGridFunction::dim > input_user_data_type
Definition: time_extrapolation.h:554
ParallelVector< Vector< double > > vector_type
vector< string > TokenizeString(const char *str, const char delimiter=',')
#define UG_ASSERT(expr, msg)
#define UG_CATCH_THROW(msg)
#define UG_COND_THROW(cond, msg)
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
int local(bglp_vertex_descriptor p)
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
number IntegrateSubsets(IIntegrand< number, TGridFunction::dim > &spIntegrand, TGridFunction &spGridFct, const char *subsets, int quadOrder, std::string quadType=std::string())
void GetLocalVector(LocalVector &lvec, const TVector &vec)
void VecScaleAdd(double &dest, double alpha1, const double &v1, double alpha2, const double &v2)
SmartPtr< T, FreePolicy > make_sp(T *inst)
SurfaceView::traits< TElem >::const_iterator const_iterator
function ProblemDisc new(problemDesc, dom)