Skip to content
Snippets Groups Projects
filters.h 4.87 KiB
Newer Older
Éric Béchet's avatar
Éric Béchet committed
//
Boris Sedji's avatar
Boris Sedji committed
// Description : Filters for function space dof selection
Éric Béchet's avatar
Éric Béchet committed
//
//
// Author:  <Eric Bechet>::<Boris Sedji>,  02/2010
//
// Copyright: See COPYING file that comes with this distribution
//
//

#ifndef _FILTERS_H_
#define _FILTERS_H_
Éric Béchet's avatar
Éric Béchet committed

#include "simpleFunction.h"
#include "dofManager.h"
#include "GModel.h"
#include "groupOfElements.h"
Boris Sedji's avatar
Boris Sedji committed
#include "DILevelset.h"
Éric Béchet's avatar
Éric Béchet committed

class FilterNodeEnriched
{

  private :

    std::set<int> *_TagEnrichedVertex;
    std::set<int> * _EnrichComp;

  public :

    FilterNodeEnriched(std::set<int > * TagEnrichedVertex , std::set<int> * EnrichComp)
    {
      _TagEnrichedVertex = TagEnrichedVertex;
      _EnrichComp = EnrichComp;
    }

    virtual bool operator () (Dof & key) const
    {
      std::set<int>::iterator it1;
      std::set<int>::iterator it2;
      int i1,i2;
      Dof::getTwoIntsFromType(key.getType(), i1,i2);
       it2 = _EnrichComp->find(i1);
      it1 = _TagEnrichedVertex->find(key.getEntity());
      if (it1!=_TagEnrichedVertex->end() & it2 != _EnrichComp->end())
      {
        return true;
      }
      else return false;
    }

    //std::vector<int> * getEnrichComp(){return _EnrichComp;}

//    void SetEnrichedVertex(MElement *elep, std::vector<int> & EnrichedVertex,int &nbdofs)
//    {
//      EnrichedVertex.clear();
//      nbdofs = 0;
//      for (int i=0 ;i<elep->getNumVertices();i++)
//      {
//        std::set<int>::iterator it;
//        it = _TagEnrichedVertex->find(elep->getVertex(i)->getNum());
//        if (it!=_TagEnrichedVertex->end())
//        {
//            EnrichedVertex.push_back(i);
//            nbdofs = nbdofs + 1*_EnrichComp->size(); // enriched dof
//        }
//      }
//    }
};

class FilterElementsCutByLevelSet
{

  private :

		std::set<int> _TagEnrichedVertex;
    std::pair<int,int> _LevelSetEntity;
    std::set<int> *_EnrichComp;

  public :

    FilterElementsCutByLevelSet(std::pair<int,int> LevelSetEntity , std::set<int> * EnrichComp)
    {
			
			_EnrichComp = EnrichComp;
      _LevelSetEntity = LevelSetEntity;
			
			// groupOfElements to get all the elements associate with the level set -- (work with *current GModel)
			groupOfElements *LevelSetElements = new groupOfElements (_LevelSetEntity.first, _LevelSetEntity.second);
		
			// tag enriched vertex determination
			std::set<MElement*>::const_iterator it = LevelSetElements->begin();
			for (; it != LevelSetElements->end(); it++)
			{
				MElement *e = *it;
				if (e->getParent()) // if element got parents
				{
					for (int k = 0; k < e->getParent()->getNumVertices(); ++k)
					{  // for all vertices in the element parent
						_TagEnrichedVertex.insert(e->getParent()->getVertex(k)->getNum());
					}
				}
			}
			
    }

    virtual bool operator () (Dof & key) const
    {
      std::set<int>::iterator it1;
      std::set<int>::iterator it2;
      int i1,i2;
      Dof::getTwoIntsFromType(key.getType(), i1,i2);
       it2 = _EnrichComp->find(i1);
      it1 = _TagEnrichedVertex.find(key.getEntity());
      if (it1!=_TagEnrichedVertex.end() & it2 != _EnrichComp->end())
      {
        return true;
      }
      else return false;
    }


};


Boris Sedji's avatar
Boris Sedji committed
class FilterLevelSetForLagMultSpace
{

Boris Sedji's avatar
Boris Sedji committed
	private :
		
		typedef MVertex * NodeType;
		typedef std::pair <NodeType , NodeType > EdgeType;
		typedef std::pair <EdgeType , double > EdgeScoreType;

	
Boris Sedji's avatar
Boris Sedji committed
  private :

Boris Sedji's avatar
Boris Sedji committed
		groupOfElements * _LevelSetElements;
Boris Sedji's avatar
Boris Sedji committed
		std::pair<int,int> _LevelSetEntity;
Boris Sedji's avatar
Boris Sedji committed
		std::set< NodeType > _winner_nodes;
		std::set< NodeType > _looser_nodes;
		gLevelset *_ls;
Boris Sedji's avatar
Boris Sedji committed
		
	private :
		
Boris Sedji's avatar
Boris Sedji committed
		// decimation algorithm result in _winner_nodes set
Boris Sedji's avatar
Boris Sedji committed
		void SortNodes (void) ;
Boris Sedji's avatar
Boris Sedji committed
		// initialisation of needed sets
		void fillNodeToEdgeMap(std::map < NodeType , EdgeType > & NodeToEdgeMap, std::set< EdgeType > & Se , std::set< NodeType > & Sn) ;
		// find edge in the element associate with node
		EdgeType findEdge(NodeType v, MElement * e);
		// verify if node belong to edge  // ...normaly has to be done when cutting model ...
		bool NodeBelongToEdge(NodeType v, EdgeType edge);
		// compute score
		void ComputeScore(std::map < NodeType , EdgeType > & NodeToEdgeMap, std::set< EdgeType > & Se, std::set< NodeType > & Sn, std::map < NodeType , int > & NodesScore);
		// compute number of incident edges in Se to node v
		int ComputeIncidentEdges(std::set< EdgeType > & Se, NodeType & v);
		// get lowest  (no need to sort just get the lowest)
		NodeType getNodeWithLowestScore(std::map < NodeType , int > & NodesScore);
		// kill connected edges
		void killConnectedEdges (std::map < NodeType , EdgeType > & NodeToEdgeMap, std::set< EdgeType > & Se , std::set< NodeType > & Sn, NodeType v);
Boris Sedji's avatar
Boris Sedji committed

  public :

Boris Sedji's avatar
Boris Sedji committed
    FilterLevelSetForLagMultSpace(std::pair<int,int> LevelSetEntity , gLevelset *ls) : _LevelSetEntity(LevelSetEntity), _ls(ls)
Boris Sedji's avatar
Boris Sedji committed
    {
Boris Sedji's avatar
Boris Sedji committed
			  groupOfElements *_LevelSetElements = new groupOfElements (_LevelSetEntity.first, _LevelSetEntity.second);
Boris Sedji's avatar
Boris Sedji committed
				SortNodes();
    }

    virtual bool operator () (Dof & key) const
    {
				;
    }

};


Éric Béchet's avatar
Éric Béchet committed

#endif