33#ifndef __H__UG__LIB_DISC__FUNCTION_SPACES__INTERPOLATE__
34#define __H__UG__LIB_DISC__FUNCTION_SPACES__INTERPOLATE__
72template <
typename TGr
idFunction>
82 typedef typename TGridFunction::domain_type domain_type;
83 typedef typename domain_type::position_type position_type;
88 const typename domain_type::position_accessor_type& aaPos
89 = spGridFct->domain()->position_accessor();
92 std::vector<DoFIndex> ind;
93 typename TGridFunction::template dim_traits<0>::const_iterator iterEnd, iter;
95 for(
size_t i = 0; i < ssGrp.
size(); ++i)
98 const int si = ssGrp[i];
101 if(!spGridFct->is_def_in_subset(fct, si))
continue;
104 iterEnd = spGridFct->template end<Vertex>(si);
105 iter = spGridFct->template begin<Vertex>(si);
106 for(; iter != iterEnd; ++iter)
112 position_type glob_pos = aaPos[vrt];
113 position_type rel_pos=glob_pos;
118 (*spInterpolFunction)(val, rel_pos, time, si);
121 spGridFct->dof_indices(vrt, fct, ind);
124 for(
size_t i = 0; i < ind.size(); ++i)
127 DoFRef(*spGridFct, ind[i]) = val;
135template <
typename TGr
idFunction>
137 typename TGridFunction::domain_type::position_type pos,
142 (*spInterpolFunction)(val, pos, time, si);
159template <
typename TGr
idFunction>
167 const int dim = TGridFunction::dim;
170 InterpolateOnDiffVertices<TGridFunction>(spInterpolFunction, spGridFct, fct, time, ssGrp, diff_pos);
190template <
typename TElem,
typename TGr
idFunction>
201 const int dim = ref_elem_type::dim;
205 typedef typename TGridFunction::domain_type domain_type;
206 typedef typename domain_type::position_type position_type;
209 typename TGridFunction::template traits<TElem>::const_iterator iterEnd, iter;
210 iterEnd = spGridFct->template end<TElem>(si);
211 iter = spGridFct->template begin<TElem>(si);
214 if(iter == iterEnd)
return;
217 LFEID id = spGridFct->local_finite_element_id(fct);
221 LocalFiniteElementProvider::get<dim>(roid,
id);
224 const size_t nsh = trialSpace.
num_sh();
227 std::vector<MathVector<dim> > loc_pos(nsh);
228 for(
size_t i = 0; i < nsh; ++i)
229 if(!trialSpace.
position(i, loc_pos[i]))
230 UG_THROW(
"InterpolateOnElem: Cannot find meaningful"
231 " local positions of dofs.");
237 for( ; iter != iterEnd; ++iter)
243 std::vector<position_type> vCorner;
247 mapping.
update(&vCorner[0]);
250 std::vector<DoFIndex> ind;
251 spGridFct->dof_indices(elem, fct, ind);
254 if(ind.size() != nsh)
255 UG_THROW(
"InterpolateOnElem: On subset "<<si<<
": Number of shapes is "
256 <<nsh<<
", but got "<<ind.size()<<
" multi indices.");
259 for(
size_t i = 0; i < nsh; ++i)
262 position_type glob_pos;
268 position_type rel_pos=glob_pos;
273 (*spInterpolFunction)(val, rel_pos, time, si);
276 DoFRef(*spGridFct, ind[i]) = val;
292template <
typename TGr
idFunction>
300 for(
size_t i = 0; i < ssGrp.
size(); ++i)
303 const int si = ssGrp[i];
306 if(!spGridFct->is_def_in_subset(fct, si))
continue;
311 const int dim = ssGrp.
dim(i);
313 if(dim > TGridFunction::dim)
314 UG_THROW(
"InterpolateOnElements: Dimension of subset is "<<dim<<
", but "
315 " World Dimension is "<<TGridFunction::dim<<
". Cannot interpolate this.");
331 InterpolateOnDiffElements<RegularEdge, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time,diff_pos);
334 InterpolateOnDiffElements<Triangle, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time, diff_pos);
335 InterpolateOnDiffElements<Quadrilateral, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time, diff_pos);
338 InterpolateOnDiffElements<Tetrahedron, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time, diff_pos);
339 InterpolateOnDiffElements<Hexahedron, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time, diff_pos);
340 InterpolateOnDiffElements<Prism, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time, diff_pos);
341 InterpolateOnDiffElements<Pyramid, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time, diff_pos);
342 InterpolateOnDiffElements<Octahedron, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time, diff_pos);
344 default:
UG_THROW(
"InterpolateOnElements: Dimension " <<dim<<
345 " not possible for world dim "<<3<<
".");
348 UG_CATCH_THROW(
"InterpolateOnElements: Cannot interpolate on elements.");
363template <
typename TElem,
typename TGr
idFunction>
369 const int dim = TGridFunction::dim;
372 InterpolateOnDiffElements<TElem,TGridFunction>(spInterpolFunction, spGridFct, fct, si,time, diff_pos);
386template <
typename TGr
idFunction>
394 for(
size_t i = 0; i < ssGrp.
size(); ++i)
397 const int si = ssGrp[i];
400 if(!spGridFct->is_def_in_subset(fct, si))
continue;
405 const int dim = ssGrp.
dim(i);
407 if(dim > TGridFunction::dim)
408 UG_THROW(
"InterpolateOnElements: Dimension of subset is "<<dim<<
", but "
409 " World Dimension is "<<TGridFunction::dim<<
". Cannot interpolate this.");
425 InterpolateOnElements<RegularEdge, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
428 InterpolateOnElements<Triangle, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
429 InterpolateOnElements<Quadrilateral, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
432 InterpolateOnElements<Tetrahedron, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
433 InterpolateOnElements<Hexahedron, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
434 InterpolateOnElements<Prism, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
435 InterpolateOnElements<Pyramid, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
436 InterpolateOnElements<Octahedron, TGridFunction>(spInterpolFunction, spGridFct, fct, si, time);
438 default:
UG_THROW(
"InterpolateOnElements: Dimension " <<dim<<
439 " not possible for world dim "<<3<<
".");
442 UG_CATCH_THROW(
"InterpolateOnElements: Cannot interpolate on elements.");
461template <
typename TGr
idFunction>
464 const char* subsets,
number time)
467 const int dim = TGridFunction::dim;
469 Interpolate(spInterpolFunction, spGridFct, cmp, subsets, time, diff_pos);
483template <
typename TGr
idFunction>
490 if(spInterpolFunction->requires_grid_fct())
491 UG_THROW(
"Interpolate: The interpolation values depend on a grid function."
492 " This is not allowed in the current implementation. Use constant,"
493 " lua-callback or vrl-callback user data only (even within linkers).");
497 bool bUseP1Interpolation =
false;
498 if(spGridFct->local_finite_element_id(fct).type() ==
LFEID::LAGRANGE &&
499 spGridFct->local_finite_element_id(fct).order() == 1)
500 bUseP1Interpolation =
true;
503 if(bUseP1Interpolation){
504 InterpolateOnDiffVertices<TGridFunction>(spInterpolFunction, spGridFct, fct, time, ssGrp, diff_pos);
506 InterpolateOnDiffElements<TGridFunction>(spInterpolFunction, spGridFct, fct, time, ssGrp, diff_pos);
525template <
typename TGr
idFunction>
533 const size_t fct = spGridFct->fct_id_by_name(cmp);
536 if(fct > spGridFct->num_fct())
537 UG_THROW(
"Interpolate: Name of component '"<<cmp<<
"' not found.");
539 Interpolate(spInterpolFunction, spGridFct, fct, subsets, time, diff_pos);
554template <
typename TGr
idFunction>
559 const bool bAllowManyfoldInterpolation =
563 SubsetGroup ssGrp(spGridFct->domain()->subset_handler());
567 if(!bAllowManyfoldInterpolation)
569 UG_THROW(
"Interpolate: Subsets '"<<subsets<<
"' do not have same dimension."
570 "Can not integrate on subsets of different dimensions.");
576 if(!bAllowManyfoldInterpolation)
580 Interpolate(spInterpolFunction, spGridFct, fct, ssGrp, time, diff_pos);
584template <
typename TGr
idFunction>
589 Interpolate(spInterpolFunction, spGridFct, cmp, NULL, time);
591template <
typename TGr
idFunction>
596 Interpolate(spInterpolFunction, spGridFct, cmp, subsets, 0.0);
598template <
typename TGr
idFunction>
602 Interpolate(spInterpolFunction, spGridFct, cmp, NULL, 0.0);
605template <
typename TGr
idFunction>
609 Interpolate(spInterpolFunction, spGridFct, cmp, NULL, 0.0, m_diff_pos);
616template <
typename TGr
idFunction>
619 const char* subsets,
number time)
621 static const int dim = TGridFunction::dim;
626template <
typename TGr
idFunction>
631template <
typename TGr
idFunction>
636template <
typename TGr
idFunction>
642template <
typename TGr
idFunction>
647 static const int dim = TGridFunction::dim;
651 InterpolateDiff(sp, spGridFct, cmp, subsets, time,m_diff_pos);
662template <
typename TGr
idFunction>
665 const char* subsets,
number time)
667 static const int dim = TGridFunction::dim;
672template <
typename TGr
idFunction>
676{
Interpolate(LuaFunction, spGridFct, cmp, NULL, time);}
677template <
typename TGr
idFunction>
681{
Interpolate(LuaFunction, spGridFct, cmp, subsets, 0.0);}
682template <
typename TGr
idFunction>
685{
Interpolate(LuaFunction, spGridFct, cmp, NULL, 0.0);}
688template <
typename TGr
idFunction>
691 const char* subsets,
number time)
693 static const int dim = TGridFunction::dim;
695 make_sp(
new LuaUserData<number, dim>(LuaFunction));
698template <
typename TGr
idFunction>
702{
Interpolate(LuaFunction, spGridFct, cmp, NULL, time);}
703template <
typename TGr
idFunction>
707{
Interpolate(LuaFunction, spGridFct, cmp, subsets, 0.0);}
708template <
typename TGr
idFunction>
711{
Interpolate(LuaFunction, spGridFct, cmp, NULL, 0.0);}
714template <
typename TGr
idFunction>
715void InterpolateDiff(
const char* LuaFunction,
717 const char* subsets,
number time,
SmartPtr<CplUserData<MathVector<TGridFunction::dim>, TGridFunction::dim> > m_diff_pos )
719 static const int dim = TGridFunction::dim;
722 InterpolateDiff(sp, spGridFct, cmp,subsets, time, m_diff_pos);
725template <
typename TGr
idFunction>
726void InterpolateDiff(LuaFunctionHandle LuaFunction,
728 const char* subsets,
number time,
SmartPtr<CplUserData<MathVector<TGridFunction::dim>, TGridFunction::dim> > m_diff_pos)
730 static const int dim = TGridFunction::dim;
732 make_sp(
new LuaUserData<number, dim>(LuaFunction));
733 InterpolateDiff(sp, spGridFct, cmp, subsets, time, m_diff_pos);
735template <
typename TGr
idFunction>
738{InterpolateDiff(LuaFunction, spGridFct, cmp, NULL, 0.0, m_diff_pos);}
754 template <
typename TGr
idFunction>
761 static const int dim = TGridFunction::dim;
770 typedef typename TGridFunction::domain_type domain_type;
771 typedef typename domain_type::position_type position_type;
775 const typename domain_type::position_accessor_type& aaPos
776 = spGfTarget->domain()->position_accessor();
779 std::vector<DoFIndex> ind;
780 typename TGridFunction::template dim_traits<0>::const_iterator iterEnd, iter;
781 const size_t fct = spGfSource->fct_id_by_name(cmp);
788 position_type glob_pos;
789 bool finished =
false;
792 iterEnd = spGfTarget->template end<Vertex>();
793 iter = spGfTarget->template begin<Vertex>();
794 for(; iter != iterEnd; )
801 glob_pos = aaPos[vrt];
811 data->evaluate_global(val, glob_pos);
815 spGfTarget->dof_indices(vrt, fct, ind);
818 for(
size_t i = 0; i < ind.size(); ++i)
821 DoFRef(*spGfTarget, ind[i]) = val;
825 finished = (iter == iterEnd);
840 data->evaluate_global(val, glob_pos);
853template <
typename TGr
idFunction>
Definition smart_pointer.h:108
Definition pcl_process_communicator.h:70
void broadcast(void *v, size_t size, DataType type, int root=0) const
Definition pcl_process_communicator.cpp:685
constant scalar user data
Definition const_user_data.h:153
Type based UserData.
Definition user_data.h:501
virtual bool position(size_t i, MathVector< TDim > &pos) const =0
local position of DoF i
Definition grid_function_global_user_data.h:58
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
a mathematical Vector with N entries.
Definition math_vector.h:97
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
int ProcRank()
returns the rank of the process
Definition pcl_base.cpp:83
int NumProcs()
returns the number of processes
Definition pcl_base.cpp:91
#define UG_CATCH_THROW(msg)
Definition error.h:64
#define UG_THROW(msg)
Definition error.h:57
double number
Definition types.h:124
void InterpolateOnDiffVertices(SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, size_t fct, number time, const SubsetGroup &ssGrp, const MathVector< TGridFunction::dim > diff_pos)
Definition interpolate.h:73
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition grid_base_objects.h:74
void InterpolateGlobalGridFunctionAcrossProcesses(SmartPtr< TGridFunction > spGfSource, SmartPtr< TGridFunction > spGfTarget, const char *cmp, number time)
Definition interpolate.h:755
void InterpolateOnElements(SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, size_t fct, int si, number time)
Definition interpolate.h:364
void Interpolate(SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, const char *cmp, const char *subsets, number time)
interpolates a function on a subset
Definition interpolate.h:462
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 InterpolateOnVertices(SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, size_t fct, number time, const SubsetGroup &ssGrp)
Definition interpolate.h:160
void RemoveLowerDimSubsets(SubsetGroup &subsetGroup)
Definition subset_group.cpp:315
void InterpolateOnDiffElements(SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, SmartPtr< TGridFunction > spGridFct, size_t fct, int si, number time, const MathVector< TGridFunction::dim > diff_pos)
Definition interpolate.h:191
number get_number_on_coords(SmartPtr< UserData< number, TGridFunction::dim > > spInterpolFunction, typename TGridFunction::domain_type::position_type pos, number time, const int si)
Definition interpolate.h:136
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition multi_index.h:276
@ 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