37 #ifndef __H__UG__LIB_DISC__MAX__ERROR__
38 #define __H__UG__LIB_DISC__MAX__ERROR__
74 template <
typename TGr
idFunction>
82 typedef typename TGridFunction::domain_type domain_type;
83 typedef typename domain_type::position_type position_type;
86 const typename domain_type::position_accessor_type& aaPos
87 = spGridFct->domain()->position_accessor();
89 std::vector<DoFIndex> ind;
90 typename TGridFunction::template dim_traits<0>::const_iterator iterEnd, iter;
92 for(
size_t i = 0; i < ssGrp.
size(); ++i)
95 const int si = ssGrp[i];
98 if(!spGridFct->is_def_in_subset(fct, si))
continue;
101 iterEnd = spGridFct->template end<Vertex>(si);
102 iter = spGridFct->template begin<Vertex>(si);
103 for(; iter != iterEnd; ++iter)
109 position_type glob_pos = aaPos[vrt];
113 (*spInterpolFunction)(val, glob_pos, time, si);
116 spGridFct->dof_indices(vrt, fct, ind);
119 for(
size_t i = 0; i < ind.size(); ++i)
122 number localError = std::abs(
DoFRef((*spGridFct), ind[i])-val);
123 if (localError>globalMaxError) globalMaxError=localError;
143 template <
typename TElem,
typename TGr
idFunction>
158 typedef typename TGridFunction::domain_type domain_type;
159 typedef typename domain_type::position_type position_type;
162 typename TGridFunction::template traits<TElem>::const_iterator iterEnd, iter;
163 iterEnd = spGridFct->template end<TElem>(si);
164 iter = spGridFct->template begin<TElem>(si);
167 if(iter == iterEnd)
return;
170 LFEID id = spGridFct->local_finite_element_id(fct);
174 LocalFiniteElementProvider::get<dim>(roid,
id);
177 const size_t nsh = trialSpace.
num_sh();
180 std::vector<MathVector<dim> > loc_pos(nsh);
181 for(
size_t i = 0; i < nsh; ++i)
182 if(!trialSpace.
position(i, loc_pos[i]))
183 UG_THROW(
"MaxErrorOnElem: Cannot find meaningful"
184 " local positions of dofs.");
190 for( ; iter != iterEnd; ++iter)
196 std::vector<position_type> vCorner;
200 mapping.
update(&vCorner[0]);
203 std::vector<DoFIndex> ind;
204 spGridFct->dof_indices(elem, fct, ind);
207 if(ind.size() != nsh)
208 UG_THROW(
"MaxErrorOnElem: On subset "<<si<<
": Number of shapes is "
209 <<nsh<<
", but got "<<ind.size()<<
" multi indices.");
212 for(
size_t i = 0; i < nsh; ++i)
215 position_type glob_pos;
222 (*spInterpolFunction)(val, glob_pos, time, si);
225 number localError = std::abs(
DoFRef((*spGridFct), ind[i])-val);
226 if (localError>globalMaxError) globalMaxError=localError;
241 template <
typename TGr
idFunction>
251 for(
size_t i = 0; i < ssGrp.
size(); ++i)
254 const int si = ssGrp[i];
257 if(!spGridFct->is_def_in_subset(fct, si))
continue;
262 const int dim = ssGrp.
dim(i);
265 UG_THROW(
"MaxErrorOnElements: Dimension of subset is "<<
dim<<
", but "
273 MaxErrorOnElements<RegularEdge, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
276 MaxErrorOnElements<Triangle, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
277 MaxErrorOnElements<Quadrilateral, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
280 MaxErrorOnElements<Tetrahedron, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
281 MaxErrorOnElements<Hexahedron, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
282 MaxErrorOnElements<Prism, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
283 MaxErrorOnElements<Pyramid, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
284 MaxErrorOnElements<Octahedron, TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, si, time);
286 default:
UG_THROW(
"MaxErrorOnElements: Dimension " <<
dim<<
287 " not possible for world dim "<<3<<
".");
290 UG_CATCH_THROW(
"MaxErrorOnElements: Cannot interpolate on elements.");
310 template <
typename TGr
idFunction>
314 const char* subsets,
number time)
318 if(spInterpolFunction->requires_grid_fct())
319 UG_THROW(
"MaxError: The interpolation values depend on a grid function."
320 " This is not allowed in the current implementation. Use constant,"
321 " lua-callback or vrl-callback user data only (even within linkers).");
324 const size_t fct = spGridFct->fct_id_by_name(cmp);
327 if(fct > spGridFct->num_fct())
328 UG_THROW(
"MaxError: Name of component '"<<cmp<<
"' not found.");
332 bool bUseP1Interpolation =
false;
333 if(spGridFct->local_finite_element_id(fct).type() ==
LFEID::LAGRANGE &&
334 spGridFct->local_finite_element_id(fct).order() == 1)
335 bUseP1Interpolation =
true;
336 const bool bAllowManyfoldInterpolation =
340 SubsetGroup ssGrp(spGridFct->domain()->subset_handler());
344 if(!bAllowManyfoldInterpolation)
346 UG_THROW(
"MaxError: Subsets '"<<subsets<<
"' do not have same dimension."
347 "Can not integrate on subsets of different dimensions.");
353 if(!bAllowManyfoldInterpolation)
358 if(bUseP1Interpolation)
359 MaxErrorOnVertices<TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, time, ssGrp);
361 MaxErrorOnElements<TGridFunction>(globalMaxError,spInterpolFunction, spGridFct, fct, time, ssGrp);
367 return globalMaxError;
370 template <
typename TGr
idFunction>
375 return MaxError(spInterpolFunction, spGridFct, cmp, NULL, time);
377 template <
typename TGr
idFunction>
382 return MaxError(spInterpolFunction, spGridFct, cmp, subsets, 0.0);
384 template <
typename TGr
idFunction>
388 return MaxError(spInterpolFunction, spGridFct, cmp, NULL, 0.0);
395 template <
typename TGr
idFunction>
398 const char* subsets,
number time)
403 return MaxError(sp, spGridFct, cmp, subsets, time);
405 template <
typename TGr
idFunction>
410 return MaxError(val, spGridFct, cmp, NULL, time);
412 template <
typename TGr
idFunction>
417 return MaxError(val, spGridFct, cmp, subsets, 0.0);
419 template <
typename TGr
idFunction>
423 return MaxError(val, spGridFct, cmp, NULL, 0.0);
431 template <
typename TGr
idFunction>
434 const char* subsets,
number time)
439 return MaxError(sp, spGridFct, cmp, subsets, time);
441 template <
typename TGr
idFunction>
446 return MaxError(LuaFunction, spGridFct, cmp, NULL, time);
449 template <
typename TGr
idFunction>
454 return MaxError(LuaFunction, spGridFct, cmp, subsets, 0.0);
456 template <
typename TGr
idFunction>
460 return MaxError(LuaFunction, spGridFct, cmp, NULL, 0.0);
Definition: smart_pointer.h:108
constant scalar user data
Definition: const_user_data.h:153
virtual bool position(size_t i, MathVector< TDim > &pos) const =0
local position of DoF i
Identifier for Local Finite Elements.
Definition: local_finite_element_id.h:98
@ LAGRANGE
Definition: local_finite_element_id.h:104
virtual size_t num_sh() const
Definition: local_dof_set.cpp:46
virtual base class for local shape function sets
Definition: local_shape_function_set.h:70
static SmartPtr< LuaUserData< TData, dim, TRet > > create(const std::string &name)
Definition: lua_user_data.h:223
Definition: reference_mapping.h:65
void local_to_global(MathVector< worldDim > &globPos, const MathVector< dim > &locPos) const
map local coordinate to global coordinate
void update(const MathVector< worldDim > *vCornerCoord)
refresh mapping for new set of corners
Group of subsets.
Definition: subset_group.h:51
size_t size() const
number of subsets in this group
Definition: subset_group.h:122
void add_all()
select all subsets of underlying subset handler
Definition: subset_group.cpp:133
int dim(size_t i) const
dimension of subset
Definition: subset_group.cpp:237
void add(int si)
adds a subset by number to this group
Definition: subset_group.cpp:64
Type based UserData.
Definition: user_data.h:143
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
void CollectCornerCoordinates(std::vector< typename TAAPos::ValueType > &vCornerCoordsOut, const TElem &elem, const TAAPos &aaPos, bool clearContainer=true)
returns the corner coordinates of a geometric object
Definition: domain_util_impl.h:75
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
void MaxErrorOnVertices(number &globalMaxError, SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, size_t fct, number time, const SubsetGroup &ssGrp)
Definition: max_error.h:75
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition: grid_base_objects.h:74
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition: multi_index.h:276
void TokenizeString(const string &str, vector< string > &vToken, const char delimiter)
Definition: string_util.cpp:56
bool SameDimensionsInAllSubsets(const SubsetGroup &subsetGroup)
Definition: subset_group.cpp:299
void RemoveLowerDimSubsets(SubsetGroup &subsetGroup)
Definition: subset_group.cpp:315
void MaxErrorOnElements(number &globalMaxError, SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, size_t fct, int si, number time)
Definition: max_error.h:144
number MaxError(SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, const char *cmp, const char *subsets, number time)
computes maximum error of a grid function on a subset
Definition: max_error.h:311
@ DIM_SUBSET_EMPTY_GRID
Definition: subset_dim_util.h:92
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
traits for reference elements
Definition: reference_element_traits.h:48