Exemplo n.º 1
0
void CopySubsetIndicesToSides(ISubsetHandler& sh, TIterator elemsBegin,
							TIterator elemsEnd, bool toUnassignedOnly)
{
	typedef typename PtrToValueType<typename TIterator::value_type>::base_type TElem;
	typedef typename TElem::side TSide;

	if(!TElem::HAS_SIDES)
		return;

	UG_ASSERT(sh.grid(), "No grid assigned to subset-handler");

	Grid& grid = *sh.grid();

	typename Grid::traits<TSide>::secure_container	sides;
	for(TIterator iter = elemsBegin; iter != elemsEnd; ++iter){
		TElem* e = *iter;

		int si = sh.get_subset_index(e);

		grid.associated_elements(sides, e);
		for(size_t i = 0; i < sides.size(); ++i){
			TSide* s = sides[i];
			if(toUnassignedOnly){
				if(sh.get_subset_index(s) == -1)
					sh.assign_subset(s, si);
			}
			else
				sh.assign_subset(s, si);
		}
	}
}
Exemplo n.º 2
0
void CopyGridLevel(MultiGrid& srcMG, Grid& destGrid,
				   ISubsetHandler& srcSH, ISubsetHandler& destSH,
				   int lvl, TAPos aPos)
{
	Grid::VertexAttachmentAccessor<TAPos> aaPos(destGrid, aPos);
	Grid::VertexAttachmentAccessor<TAPos> aaSrcPos(srcMG, aPos);
	GridObjectCollection goc = srcMG.get_grid_objects();

	AVertex aNewVrt;
	srcMG.attach_to_vertices(aNewVrt);
	Grid::VertexAttachmentAccessor<AVertex> aaNewVrt(srcMG, aNewVrt);

	for(int si = destSH.num_subsets(); si < srcSH.num_subsets(); ++si)
	{
		destSH.subset_info(si) = srcSH.subset_info(si);
	}

	for(VertexIterator vrtIter = goc.begin<Vertex>(lvl); vrtIter != goc.end<Vertex>(lvl); ++vrtIter)
	{
		Vertex* srcVrt  = *vrtIter;
		Vertex* destVrt = *destGrid.create_by_cloning(srcVrt);

		aaNewVrt[srcVrt] = destVrt;
		aaPos[destVrt] = aaSrcPos[srcVrt];
		destSH.assign_subset(destVrt, srcSH.get_subset_index(srcVrt));
	}

	CopyGridLevelElements<Edge>(srcMG, destGrid, srcSH, destSH, lvl, aNewVrt);
	CopyGridLevelElements<Face>(srcMG, destGrid, srcSH, destSH, lvl, aNewVrt);
	CopyGridLevelElements<Volume>(srcMG, destGrid, srcSH, destSH, lvl, aNewVrt);

	srcMG.detach_from_vertices(aNewVrt);
}
Exemplo n.º 3
0
void SelectInterfaceElements(ISelector& sel, ISubsetHandler& sh,
							 const TIter begin, const TIter end,
							 bool regardSelectedNbrsOnly)
{
	typedef typename Pointer2Value<typename TIter::value_type>::type	TElem;
	typedef typename TElem::sideof										TNbr;

	if(!TElem::CAN_BE_SIDE)
		return;

	if(!sel.grid())
		return;

	Grid& grid = *sel.grid();

	std::vector<TNbr*> nbrs;

	for(TIter iter = begin; iter != end;){
		TElem* elem = *iter;
		++iter;

		CollectAssociated(nbrs, grid, elem);

		int si = -2;
		for(size_t i = 0; i < nbrs.size(); ++i){
			if(!regardSelectedNbrsOnly || sel.is_selected(nbrs[i])){
				if(sh.get_subset_index(nbrs[i]) != si){
					if(si == -2)
						si = sh.get_subset_index(nbrs[i]);
					else{
					//	elem is an interface element
						sel.select(elem);
						break;
					}
				}
			}
		}
	}
}
Exemplo n.º 4
0
void AssignAssociatedVerticesToSubsets(TSubsetHandler& sh,
									const ISubsetHandler& srcIndHandler)
{
	typedef typename geometry_traits<TElem>::const_iterator iterator;
	for(size_t l  = 0; l < sh.num_levels(); ++l){
		for(int si = 0; si < sh.num_subsets(); ++si){
			for(iterator iter = sh.template begin<TElem>(si, l);
				iter != sh.template end<TElem>(si, l); ++iter)
			{
				TElem* e = *iter;
				for(size_t i = 0; i < e->num_vertices(); ++i)
				{
					Vertex* vrt = e->vertex(i);
					sh.assign_subset(vrt, srcIndHandler.get_subset_index(vrt));
				}
			}
		}
	}
}
Exemplo n.º 5
0
void AssignAssociatedFacesToSubsets(TSubsetHandler& sh,
									const ISubsetHandler& srcIndHandler)
{
	typedef typename geometry_traits<TElem>::const_iterator iterator;
	std::vector<Face*> vFaces;

	for(size_t l  = 0; l < sh.num_levels(); ++l){
		for(int si = 0; si < sh.num_subsets(); ++si){
			for(iterator iter = sh.template begin<TElem>(si, l);
				iter != sh.template end<TElem>(si, l); ++iter)
			{
				TElem* e = *iter;
				CollectFaces(vFaces, *sh.grid(), e);

				for(size_t i = 0; i < vFaces.size(); ++i)
				{
					Face* f = vFaces[i];
					sh.assign_subset(f, srcIndHandler.get_subset_index(f));
				}
			}
		}
	}
}
Exemplo n.º 6
0
void CopyGridLevelElements(MultiGrid& srcMG, Grid& destGrid,
				           ISubsetHandler& srcSH, ISubsetHandler& destSH,
						   int lvl, AVertex& aNewVrt)
{
	Grid::VertexAttachmentAccessor<AVertex> aaNewVrt(srcMG, aNewVrt);
	GridObjectCollection goc = srcMG.get_grid_objects();
	CustomVertexGroup vrts;

	typedef typename Grid::traits<TElem>::iterator iter_t;

	for(iter_t eIter = goc.begin<TElem>(lvl); eIter != goc.end<TElem>(lvl); ++eIter)
	{
		TElem* e = *eIter;
		vrts.resize(e->num_vertices());

		for(size_t iv = 0; iv < e->num_vertices(); ++iv)
		{
			vrts.set_vertex(iv, aaNewVrt[e->vertex(iv)]);
		}

		TElem* ne = *destGrid.create_by_cloning(e, vrts);
		destSH.assign_subset(ne, srcSH.get_subset_index(e));
	}
}
Exemplo n.º 7
0
void FindSubsetGroups
(
	std::vector<int> & minCondInd,
	const std::vector<bool> & isMarked,
	const ISubsetHandler & sh,
	const NeighborhoodType nbhType
)
{
	typedef typename geometry_traits<TBaseObj>::const_iterator elem_iterator;
	
	UG_ASSERT (((int) isMarked.size ()) == sh.num_subsets (), "FindSubsetGroups: array size mismatch");
	
	std::vector<TBaseObj*> neighbours;
	
//	Prepare minCondInd
	minCondInd.resize (sh.num_subsets ());
	for (size_t si = 0; si < minCondInd.size (); si++)
		minCondInd [si] = (isMarked [si])? si : -1;
	
//	Loop over the subsets:
	for (size_t si = 0; si < minCondInd.size (); si++)
	{
		int min_si;
		
	//	Marked subset?
		if ((min_si = minCondInd [si]) < 0)
			continue; // no, we do not treat this subset
		
	//	Yes, loop over the elements in the subdomain (in the grid level 0):
		GridObjectCollection goc = sh.get_grid_objects_in_subset (si);
		elem_iterator e_end = goc.end<TBaseObj> (0);
		bool is_empty = true;
		for (elem_iterator e_iter = goc.begin<TBaseObj> (0); e_iter != e_end; ++e_iter)
		{
			is_empty = false;
		//	Loop over the neighbours:
			CollectNeighbors (neighbours, *e_iter, *sh.grid(), nbhType);
			for (size_t k = 0; k < neighbours.size (); k++)
			{
				int min_nbr_si;
				int nbr_si = sh.get_subset_index (neighbours [k]);
				
				if (nbr_si < 0 || nbr_si >= (int) minCondInd.size ())
					UG_THROW ("FindSubsetGroups: Illegal neighbour subset index.");
				if ((min_nbr_si = minCondInd [nbr_si]) < 0)
					continue; // we do not treat this subset
				
			//	Set the same smallest index to both groups of the subsets:
				if (min_nbr_si < min_si)
				{
					for (size_t l = 0; l < minCondInd.size (); l++)
						if (minCondInd [l] == min_si)
							minCondInd [l] = min_nbr_si;
				}
				else if (min_nbr_si > min_si)
				{
					for (size_t l = 0; l < minCondInd.size (); l++)
						if (minCondInd [l] == min_nbr_si)
							minCondInd [l] = min_si;
				}
			}
		}
		if (is_empty) minCondInd [si] = -2;
	}
}