Skip to content

Commit b85cb37

Browse files
committed
Limex: strict relative norms can be set by int (0-4) or bool(false=0,true=1). 3 is relative max norm for each cmp on whole domain.
1 parent 30a5085 commit b85cb37

2 files changed

Lines changed: 63 additions & 13 deletions

File tree

limex_plugin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ static void DomainAlgebra(TRegistry& reg, string grp)
212212
.add_method("add", static_cast<void (T::*)(SmartPtr<TCompSpace>) > (&T::add))
213213
.add_method("add", static_cast<void (T::*)(SmartPtr<TCompositeSpace>) > (&T::add))
214214
.add_method("config_string", &T::config_string)
215-
.add_method("use_strict_relative_norms", &T::use_strict_relative_norms)
215+
//.add_method("use_strict_relative_norms", &T::use_strict_relative_norms)
216+
.add_method("use_strict_relative_norms",OVERLOADED_METHOD_PTR(void, T, use_strict_relative_norms, (bool)), "", "", "Use relative norm?")
217+
.add_method("use_strict_relative_norms",OVERLOADED_METHOD_PTR(void, T, use_strict_relative_norms, (int)), "", "", "Which norm model? 0:abs,1:rel(add),2:rel(sqrt),3:rel(add,cmp),4:(sqrt,cmp)")
216218
.set_construct_as_smart_pointer(true);
217219
reg.add_class_to_group(name, "CompositeGridFunctionEstimator", tag);
218220
}

time_disc/time_extrapolation.h

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -889,11 +889,19 @@ class CompositeGridFunctionEstimator :
889889
typedef CompositeSpace<grid_function_type> composite_type;
890890

891891
// constructor
892-
CompositeGridFunctionEstimator() : base_type(), m_strictRelativeError(false) {}
892+
CompositeGridFunctionEstimator() : base_type(), m_strictRelativeError(0) {}
893893

894-
void use_strict_relative_norms(bool b)
894+
void use_strict_relative_norms(int b)//bool b)
895895
{ m_strictRelativeError = b; }
896896

897+
void use_strict_relative_norms(bool b){
898+
if(b){
899+
m_strictRelativeError=1;
900+
}else{
901+
m_strictRelativeError=0;
902+
}
903+
}
904+
897905
// add (single subspace)
898906
void add(SmartPtr<subspace_type> spSubspace)
899907
{ m_spSubspaces.push_back(spSubspace); }
@@ -919,40 +927,79 @@ class CompositeGridFunctionEstimator :
919927
SmartPtr<grid_function_type> uCoarse = vCoarse.template cast_dynamic<grid_function_type>();
920928
if (uFine.invalid() || uCoarse.invalid()) return false;
921929

930+
size_t numFct=uFine->num_fct();
931+
std::vector<double> vcmp_e2, vcmp_u2;
932+
vcmp_e2.resize(numFct, 0);
933+
vcmp_u2.resize(numFct, 0);
934+
922935
// error estimate
923936
double enorm2 = 0.0;
924937
double unorm2 = 0.0;
925938
const double SMALL = 1e-10;
926939

940+
double cmp_rel=0.0;
941+
double cmp_rel4=0.0;
927942
double max_rel = 0.0;
928-
929-
943+
double max_rel_e4=0.0;
930944

931945
for (typename std::vector<SmartPtr<subspace_type> >::iterator it = m_spSubspaces.begin();
932946
it!= m_spSubspaces.end(); ++it)
933947
{
934948
// use sub-diagonal error estimator (i.e. multiply with alpha)
949+
std::string cmp=(*it)->function_name();
950+
size_t cmp_id= uFine->fct_id_by_name(cmp.c_str());
935951
double cmp_e2 = (alpha*alpha) * (*it)->distance2(*uFine, *uCoarse);
936952
double cmp_u2 = (*it)->norm2(*uFine);
953+
vcmp_e2[cmp_id]+=cmp_e2;
954+
vcmp_u2[cmp_id]+=cmp_u2;
955+
cmp_rel=std::max(cmp_rel,(cmp_e2==0)?0:cmp_e2/(cmp_u2 + SMALL/ (1.0+cmp_e2+cmp_u2)));
956+
cmp_rel4=std::max(cmp_rel4,(cmp_e2==0)?0:cmp_e2/std::sqrt(cmp_u2*cmp_u2+SMALL*SMALL));
957+
UG_LOGN("cmp=" << cmp << "(id=" << cmp_id << "):\tui-2=" << cmp_u2 << "\tei-2=" << cmp_e2<<
958+
"\tratio2="<< (vcmp_e2[cmp_id])/(vcmp_u2[cmp_id]) <<
959+
"\tmax.rel(squared)="<< cmp_rel<<"\tmax.rel(ei4)="<<cmp_rel4
960+
);
961+
}
937962

963+
for(size_t cmp_id=0; cmp_id<numFct; ++cmp_id){
964+
double cmp_e2=vcmp_e2[cmp_id];
965+
double cmp_u2=vcmp_u2[cmp_id];
938966
// |delta_i|/|u_i|
939-
max_rel = std::max(max_rel, cmp_e2/
967+
max_rel = std::max(max_rel, (cmp_e2==0)?0:cmp_e2/
940968
(cmp_u2 + SMALL/ (1.0+cmp_e2+cmp_u2)));
941969
//std::max(cmp_u2, SMALL*cmp_e2));
970+
max_rel_e4=std::max(max_rel_e4, (cmp_e2==0)?0:cmp_e2/std::sqrt(cmp_u2*cmp_u2+SMALL*SMALL));
942971

943972
enorm2 += cmp_e2;
944973
unorm2 += cmp_u2;
945974

946-
UG_LOGN("ui-2=" << cmp_u2 << "\tei-2=" << cmp_e2<<
947-
"\tunorm2=" << unorm2 << "\tenorm2=" << enorm2 <<
975+
UG_LOGN("summe by cmp_id=" << cmp_id << ":\tui-2=" << cmp_u2 << "\tei-2=" << cmp_e2<<
948976
"\tratio2="<< (enorm2)/(unorm2) <<
949-
"\tmax. rel (squared) ="<< max_rel);
977+
"\tmax.rel(squared)="<< max_rel<<"\tmax.rel(ei4)="<<max_rel_e4);
950978
}
951979

952980
//prevent division by zero
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);
981+
/*base_type::m_est = (m_strictRelativeError) ? sqrt(max_rel) :
982+
sqrt(enorm2/std::max(unorm2, SMALL*enorm2));*/
983+
984+
switch(m_strictRelativeError)
985+
{
986+
case 0:
987+
base_type::m_est=sqrt(enorm2/std::max(unorm2, SMALL*enorm2)); /* absolute: */
988+
break;
989+
case 1:
990+
base_type::m_est=sqrt(cmp_rel); /* relative max: max(e2/(u2+SMALL/(1+e2+u2))) for each cmp on each subset */
991+
break;
992+
case 2:
993+
base_type::m_est=sqrt(cmp_rel4); /* relative max: max(e2/sqrt(u2*u2+SMALL*SMALL)) for each cmp on each subset*/
994+
break;
995+
case 3:
996+
base_type::m_est=sqrt(max_rel); /* relative max based on cmp: max(sum_si e2/( sum_si u2+SMALL/(1+sum_si e2+ sum_si u2))) for each cmp on whole domain.*/
997+
break;
998+
case 4:
999+
base_type::m_est=sqrt(max_rel_e4); /* relative max based on cmp: max(sum_si e2/sqrt( sum_si u2* sum_si u2+SMALL*SMALL)) for each cmp on whole domain.*/
1000+
break;
1001+
}
1002+
UG_LOGN("eps="<< base_type::m_est<<" with strictRelativeError="<<m_strictRelativeError);
9561003

9571004
// update
9581005
VecScaleAdd(*vUpdate, 1.0+alpha, *vFine, -alpha, *vCoarse);
@@ -976,7 +1023,8 @@ class CompositeGridFunctionEstimator :
9761023
protected:
9771024

9781025
std::vector<SmartPtr<subspace_type> > m_spSubspaces;
979-
bool m_strictRelativeError;
1026+
//bool m_strictRelativeError;
1027+
int m_strictRelativeError;
9801028
};
9811029

9821030

0 commit comments

Comments
 (0)