33 #ifndef __H__LIB_GRID__SUBSET_UTIL_IMPL__
34 #define __H__LIB_GRID__SUBSET_UTIL_IMPL__
46 template <
class TElem>
65 template <
class TElem>
96 template <
class TElem>
100 SeparateSubsetsByLowerDimSeparators<TElem>(grid, sh, appendAtEnd,
104 template <
class TElem>
108 SeparateSubsetsByLowerDimSeparators<TElem>(grid, sh, appendAtEnd,
112 template <
class TElem>
115 boost::function<
bool (
typename TElem::lower_dim_base_object*)>
122 typedef typename TElem::lower_dim_base_object TSide;
132 vector<TSide*> vSides;
133 vector<TElem*> vElems;
136 stack<TElem*> stkElems;
148 stkElems.push(*sel.
begin<TElem>());
149 while(!stkElems.empty())
151 TElem* elem = stkElems.top();
163 for(
uint i = 0; i < elem->num_sides(); ++i)
166 TSide* side = grid.
get_side(elem, i);
170 if(!cbIsSeparator(side))
175 for(
uint j = 0; j < vElems.size(); ++j)
178 stkElems.push(vElems[j]);
190 template <
class TIterator>
192 TIterator elemsEnd,
bool toUnassignedOnly)
195 typedef typename TElem::side TSide;
197 if(!TElem::HAS_SIDES)
205 for(TIterator iter = elemsBegin; iter != elemsEnd; ++iter){
211 for(
size_t i = 0; i < sides.
size(); ++i){
213 if(toUnassignedOnly){
225 template <
class TElem,
class TSubsetHandler>
234 Grid& grid = *sh.grid();
241 for(ElemIter iter = grid.
begin<TElem>();
242 iter != grid.
end<TElem>(); ++iter)
244 if(sh.get_subset_index(*iter) == -1)
245 sh.assign_subset(*iter, si);
251 template <
class TSubsetHandler>
253 bool preserveExistingSubsets)
259 Grid& grid = *sh.grid();
265 if(!preserveExistingSubsets){
295 if(!preserveExistingSubsets){
312 if(!preserveExistingSubsets){
328 template <
class TAAPosVRT>
335 UG_WARNING(
"WARNING: Given subset doesn't contain any faces on given level.");
348 template <
class TIterator>
350 TIterator elemsEnd,
int subsetIndex)
353 for(;elemsBegin != elemsEnd; elemsBegin++)
356 uint numVrts = elem->num_vertices();
358 for(
uint i = 0; i < numVrts; ++i)
364 template <
class TElem,
class TSubsetHandler>
369 for(
size_t l = 0; l < sh.num_levels(); ++l){
370 for(
int si = 0; si < sh.num_subsets(); ++si){
371 for(iterator iter = sh.template begin<TElem>(si, l);
372 iter != sh.template end<TElem>(si, l); ++iter)
375 for(
size_t i = 0; i < e->num_vertices(); ++i)
377 Vertex* vrt = e->vertex(i);
386 template <
class TElem,
class TSubsetHandler>
391 std::vector<Edge*> vEdges;
393 for(
size_t l = 0; l < sh.num_levels(); ++l){
394 for(
int si = 0; si < sh.num_subsets(); ++si){
395 for(iterator iter = sh.template begin<TElem>(si, l);
396 iter != sh.template end<TElem>(si, l); ++iter)
401 for(
size_t i = 0; i < vEdges.size(); ++i)
403 Edge* edge = vEdges[i];
412 template <
class TElem,
class TSubsetHandler>
417 std::vector<Face*> vFaces;
419 for(
size_t l = 0; l < sh.num_levels(); ++l){
420 for(
int si = 0; si < sh.num_subsets(); ++si){
421 for(iterator iter = sh.template begin<TElem>(si, l);
422 iter != sh.template end<TElem>(si, l); ++iter)
427 for(
size_t i = 0; i < vFaces.size(); ++i)
437 template <
class TElem,
class TSubsetHandlerDest,
class TSubsetHandlerSrc>
439 const TSubsetHandlerSrc& srcIndHandler)
442 typedef typename TElem::lower_dim_base_object Side;
443 std::vector<Side*> vSides;
444 Grid& grid = *sh.grid();
446 for(
size_t l = 0; l < sh.num_levels(); ++l){
447 for(
int si = 0; si < sh.num_subsets(); ++si){
448 for(iterator iter = sh.template begin<TElem>(si, l);
449 iter != sh.template end<TElem>(si, l); ++iter)
454 for(
size_t i = 0; i < vSides.size(); ++i)
457 sh.assign_subset(
s, srcIndHandler.get_subset_index(
s));
465 template <
class TElem,
class TSubsetHandlerDest,
class TSubsetHandlerSrc>
467 const TSubsetHandlerSrc& srcIndHandler,
471 if(srcIndHandler.template num<Face>() > 0)
472 AssignAssociatedFacesToSubsets<TElem>(sh, srcIndHandler);
473 if(srcIndHandler.template num<Edge>() > 0)
474 AssignAssociatedEdgesToSubsets<TElem>(sh, srcIndHandler);
475 if(srcIndHandler.template num<Vertex>() > 0)
476 AssignAssociatedVerticesToSubsets<TElem>(sh, srcIndHandler);
480 template <
class TElem,
class TSubsetHandlerDest,
class TSubsetHandlerSrc>
482 const TSubsetHandlerSrc& srcIndHandler,
486 if(srcIndHandler.template num<Edge>() > 0)
487 AssignAssociatedEdgesToSubsets<TElem>(sh, srcIndHandler);
488 if(srcIndHandler.template num<Vertex>() > 0)
489 AssignAssociatedVerticesToSubsets<TElem>(sh, srcIndHandler);
493 template <
class TElem,
class TSubsetHandlerDest,
class TSubsetHandlerSrc>
495 const TSubsetHandlerSrc& srcIndHandler,
499 if(srcIndHandler.template num<Vertex>() > 0)
500 AssignAssociatedVerticesToSubsets<TElem>(sh, srcIndHandler);
504 template <
class TElem,
class TSubsetHandlerDest,
class TSubsetHandlerSrc>
506 const TSubsetHandlerSrc& srcIndHandler)
508 AssignAssociatedLowerDimElemsToSubsets<TElem>(sh,
509 srcIndHandler, TElem());
513 template <
typename TBaseObj>
516 std::vector<int> & minCondInd,
517 const std::vector<bool> & isMarked,
524 UG_ASSERT (((
int) isMarked.size ()) == sh.
num_subsets (),
"FindSubsetGroups: array size mismatch");
526 std::vector<TBaseObj*> neighbours;
530 for (
size_t si = 0; si < minCondInd.size (); si++)
531 minCondInd [si] = (isMarked [si])? si : -1;
534 for (
size_t si = 0; si < minCondInd.size (); si++)
539 if ((min_si = minCondInd [si]) < 0)
544 elem_iterator e_end = goc.
end<TBaseObj> (0);
545 bool is_empty =
true;
546 for (elem_iterator e_iter = goc.
begin<TBaseObj> (0); e_iter != e_end; ++e_iter)
551 for (
size_t k = 0; k < neighbours.size (); k++)
556 if (nbr_si < 0 || nbr_si >= (
int) minCondInd.size ())
557 UG_THROW (
"FindSubsetGroups: Illegal neighbour subset index.");
558 if ((min_nbr_si = minCondInd [nbr_si]) < 0)
562 if (min_nbr_si < min_si)
564 for (
size_t l = 0; l < minCondInd.size (); l++)
565 if (minCondInd [l] == min_si)
566 minCondInd [l] = min_nbr_si;
568 else if (min_nbr_si > min_si)
570 for (
size_t l = 0; l < minCondInd.size (); l++)
571 if (minCondInd [l] == min_nbr_si)
572 minCondInd [l] = min_si;
576 if (is_empty) minCondInd [si] = -2;
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
size_t num_volumes() const
Definition: grid.h:554
size_t num_faces() const
Definition: grid.h:553
Vertex::side * get_side(Vertex *obj, size_t side)
This method returns the i-th side of an Edge, Face or Volume.
Definition: grid.cpp:1170
geometry_traits< TGeomObj >::iterator begin()
Definition: grid_impl.hpp:164
void associated_elements(traits< Vertex >::secure_container &elemsOut, TElem *e)
Puts all elements of type TAss which are contained in 'e' or which contain 'e' into elemsOut.
Definition: grid_impl.hpp:466
size_t num_edges() const
Definition: grid.h:552
geometry_traits< TGeomObj >::iterator end()
Definition: grid_impl.hpp:175
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition: grid_object_collection.h:96
geometry_traits< TGeomObj >::iterator begin(size_t level=0)
Definition: grid_object_collection_impl.hpp:95
geometry_traits< TGeomObj >::iterator end(size_t level=0)
Definition: grid_object_collection_impl.hpp:106
size_t num() const
Definition: grid_object_collection_impl.hpp:130
FaceIterator faces_end(size_t level=0)
Definition: grid_object_collection.h:152
FaceIterator faces_begin(size_t level=0)
Definition: grid_object_collection.h:151
Partitions elements of a grid into several subsets.
Definition: subset_handler_grid.h:53
void assign_subset(Vertex *elem, int subsetIndex)
assigns a vertex to a subset.
Definition: subset_handler_grid.cpp:204
uint num_elements(int subsetIndex) const
returns the number of elements in the given subset
Definition: subset_handler_grid_impl.hpp:147
bool is_selected(TElem *elem) const
returns true if an element is selected
Definition: selector_interface.h:215
void select(GridObject *elem, byte status)
selects an element
Definition: selector_interface_impl.hpp:56
void deselect(GridObject *elem)
Definition: selector_interface_impl.hpp:96
Definition: subset_handler_interface.h:223
void move_subset(int indexFrom, int indexTo)
Moves the subset from index From to index To. Moves all subsets between indexFrom+1 and indexTo in th...
Definition: subset_handler_interface.cpp:696
void assign_subset(TIterator iterBegin, TIterator iterEnd, int subsetIndex)
Definition: subset_handler_interface_impl.hpp:170
Grid * grid() const
returns a pointer to the grid on which the subset-handler works.
Definition: subset_handler_interface.cpp:304
int get_subset_index(GridObject *elem) const
Definition: subset_handler_interface.cpp:560
virtual GridObjectCollection get_grid_objects_in_subset(int subsetInd) const =0
Returns the geometric object collection for the given subset.
int num_subsets() const
returns the number of subset-infos (return value is int, since SubsetIndices are of type int)
Definition: subset_handler_interface.h:317
Element callback that returns true, if an element is not contained in a subset.
Definition: subset_callbacks.h:68
Element callback that returns true, if an element is selected.
Definition: selection_callbacks.h:45
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
specialization of ISelector for a grid of class Grid.
Definition: selector_grid.h:96
geometry_traits< TElem >::iterator end()
Definition: selector_grid_impl.hpp:134
bool empty() const
Definition: selector_grid_impl.hpp:91
virtual void clear()
Definition: selector_grid.cpp:155
geometry_traits< TElem >::iterator begin()
Definition: selector_grid_impl.hpp:106
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
Definition: grid_base_object_traits.h:68
static number FaceArea(TDomain &dom, ISubsetHandler &sh, int si, size_t lvl)
Definition: domain_bridge.cpp:262
void CollectEdges(std::vector< Edge * > &vEdgesOut, Grid &grid, Vertex *vrt, bool clearContainer)
Collects all edges which exist in the given grid and which are part of the given vertex.
Definition: grid_util.cpp:295
NeighborhoodType
Constants to specify a neighborhood.
Definition: neighborhood.h:53
void CollectNeighbors(std::vector< Vertex * > &vNeighborsOut, Grid &grid, Vertex *vrt, uint nbhType, Grid::edge_traits::callback considerEdge, Grid::face_traits::callback considerFace, Grid::volume_traits::callback considerVol)
Collects all vertices that are connected by elements of the specified type.
Definition: neighborhood.cpp:43
void CollectFaces(std::vector< Face * > &vFacesOut, Grid &grid, Vertex *vrt, bool clearContainer)
Collects all faces that exist in the given grid which contain the given vertex.
Definition: grid_util.cpp:458
UG_API void CollectAssociated(std::vector< Vertex * > &vVertexOut, Grid &grid, GridObject *obj, bool clearContainer=true)
Definition: grid_util_impl.hpp:169
void SelectAssociatedVertices(TSelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd, ISelector::status_t status=ISelector::SELECTED)
selects all associated vertices of the elements between elemsBegin and elemsEnd
Definition: selection_util_impl.hpp:229
void SelectInterfaceElements(ISelector &sel, ISubsetHandler &sh, const TIter begin, const TIter end, bool regardSelectedNbrsOnly=false)
Selects elements which are adjacent to higher dimensional elements of different subsets.
Definition: selection_util_impl.hpp:588
void SelectBoundaryElements(ISelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd)
selects elements that lie on the associated grid's boundary
Definition: selection_util_impl.hpp:326
void SelectAssociatedEdges(TSelector &sel, TElemIterator elemsBegin, TElemIterator elemsEnd, ISelector::status_t status=ISelector::SELECTED)
selects all associated edges of the elements between elemsBegin and elemsEnd
Definition: selection_util_impl.hpp:244
void AdjustSubsetsForSimulation(TSubsetHandler &sh, bool preserveExistingSubsets)
Adjust the grid so that it is ready for simulation with ug4.
Definition: subset_util_impl.hpp:252
void SeparateSubsetsByLowerDimSubsets(Grid &grid, SubsetHandler &sh, bool appendAtEnd=false)
Assigns all elements of the given type to subsets.
Definition: subset_util_impl.hpp:97
void CopySubsetIndicesToSides(ISubsetHandler &sh, GridObjectCollection goc, bool toUnassignedOnly)
copies subset-indices to sides of the specified elements
Definition: subset_util.cpp:306
void AssignAssociatedVerticesToSubsets(TSubsetHandler &sh, const ISubsetHandler &srcIndHandler)
Assigns associated vertices of elements of type TElem in sh to sh.
Definition: subset_util_impl.hpp:365
void SeparateSubsetsByLowerDimSeparators(Grid &grid, SubsetHandler &sh, bool appendAtEnd, boost::function< bool(typename TElem::lower_dim_base_object *)> cbIsSeparator)
Assigns all elements of the given type to subsets.
Definition: subset_util_impl.hpp:113
void AssignUnassignedElemsToSubset(TSubsetHandler &sh, int si)
Assigns all elements of type TElem with subset index -1 to subset at index si.
Definition: subset_util_impl.hpp:226
void MakeSubsetsConsecutive(SubsetHandler &sh)
moves subsets so that no empty subset of type TElem is between filled ones.
Definition: subset_util_impl.hpp:66
void SeparateSubsetsByLowerDimSelection(Grid &grid, SubsetHandler &sh, Selector &sel, bool appendAtEnd=false)
Assigns all elements of the given type to subsets.
Definition: subset_util_impl.hpp:105
void AssignAssociatedFacesToSubsets(TSubsetHandler &sh, const ISubsetHandler &srcIndHandler)
Assigns associated faces of elements of type TElem in sh to sh.
Definition: subset_util_impl.hpp:413
void AssignAssociatedEdgesToSubsets(TSubsetHandler &sh, const ISubsetHandler &srcIndHandler)
Assigns associated edges of elements of type TElem in sh to sh.
Definition: subset_util_impl.hpp:387
void AssignAssociatedSidesToSubsets(TSubsetHandlerDest &sh, const TSubsetHandlerSrc &srcIndHandler)
Assigns associated sides of elements of type TElem in sh to sh.
Definition: subset_util_impl.hpp:438
void AssignAssociatedLowerDimElemsToSubsets(TSubsetHandlerDest &sh, const TSubsetHandlerSrc &srcIndHandler)
Assigns associated elements of elements of type TElem in sh to sh.
Definition: subset_util_impl.hpp:505
void AssignAssociatedVerticesToSubset(ISubsetHandler &sh, TIterator elemsBegin, TIterator elemsEnd, int subsetIndex)
assigns vertices of the given elements to the subset at subsetIndex
Definition: subset_util_impl.hpp:349
int GetMaxSubsetIndex(SubsetHandler &sh)
returns the index of the last subset, that contains elements of type TElem.
Definition: subset_util_impl.hpp:47
void FindSubsetGroups(std::vector< int > &minCondInd, const std::vector< bool > &isMarked, const ISubsetHandler &sh, const NeighborhoodType nbhType=NHT_VERTEX_NEIGHBORS)
Definition: subset_util_impl.hpp:515
int GetFirstFreeSubset(const ISubsetHandler &sh)
returns the first subset, which does not contain any elements at all
Definition: subset_util.cpp:49
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
unsigned int uint
Definition: types.h:114
#define UG_WARNING(msg)
Definition: log.h:328
double number
Definition: types.h:124
Definition: smart_pointer.h:814
template void AssignSidesToSubsets< Edge >(ISubsetHandler &, ISelector *)
template void AssignSidesToSubsets< Volume >(ISubsetHandler &, ISelector *)
template void AssignSidesToSubsets< Face >(ISubsetHandler &, ISelector *)
void EraseEmptySubsets(ISubsetHandler &sh)
Erases all subsets which do not contain any geometric objects.
Definition: subset_util.cpp:66
T value_type
Definition: sparsematrix_interface.h:2
void base_type
Definition: grid_base_objects.h:1011