dune-istl  2.2.0
graphcreator.hh
Go to the documentation of this file.
00001 #ifndef DUNE_AMG_GRAPHCREATOR_HH
00002 #define DUNE_AMG_GRAPHCREATOR_HH
00003 
00004 #include"graph.hh"
00005 #include"dependency.hh"
00006 #include"pinfo.hh"
00007 #include<dune/istl/operators.hh>
00008 #include<dune/istl/bcrsmatrix.hh>
00009 #include<dune/common/tuples.hh>
00010 
00011 namespace Dune
00012 {
00013   namespace Amg
00014   {
00015     template<class M, int cat=M::category>
00016     struct PropertiesGraphCreator
00017     {
00018     };
00019     
00020     template<class M>
00021     struct PropertiesGraphCreator<M,SolverCategory::sequential>
00022     {
00023       typedef typename M::matrix_type Matrix;
00024       
00025       typedef Dune::Amg::MatrixGraph<const Matrix> MatrixGraph;
00026       
00027       typedef Dune::Amg::PropertiesGraph<MatrixGraph,
00028                               VertexProperties,
00029                               EdgeProperties,
00030                               IdentityMap,
00031                               IdentityMap> PropertiesGraph;
00032       
00033       typedef Dune::tuple<MatrixGraph*,PropertiesGraph*> GraphTuple;
00034       
00035       template<class OF, class T>
00036       static GraphTuple create(const M& matrix, T& excluded,
00037                                const SequentialInformation& pinfo,
00038                                const OF&)
00039       {
00040         MatrixGraph* mg = new MatrixGraph(matrix.getmat());
00041         PropertiesGraph* pg = new PropertiesGraph(*mg, IdentityMap(), IdentityMap());
00042         return GraphTuple(mg,pg);
00043       }
00044       
00045       static void free(GraphTuple& graphs)
00046       {
00047         delete get<1>(graphs);
00048       }
00049       
00050     };
00051 
00052     template<class M>
00053     struct PropertiesGraphCreator<M,SolverCategory::overlapping>
00054     {
00055       typedef typename M::matrix_type Matrix;
00056       typedef Dune::Amg::MatrixGraph<const Matrix> MatrixGraph;
00057       typedef Dune::Amg::SubGraph<MatrixGraph,
00058                        std::vector<bool> > SubGraph;
00059       typedef Dune::Amg::PropertiesGraph<SubGraph,
00060                               VertexProperties,
00061                               EdgeProperties,
00062                               IdentityMap,
00063                               typename SubGraph::EdgeIndexMap>
00064       PropertiesGraph;
00065     
00066       typedef Dune::tuple<MatrixGraph*,PropertiesGraph*,SubGraph*> GraphTuple;
00067       
00068       template<class OF, class T, class PI>
00069       static GraphTuple create(const M& matrix, T& excluded, 
00070                                PI& pinfo, const OF& of)
00071       {
00072         typedef OF OverlapFlags;
00073         MatrixGraph* mg = new MatrixGraph(matrix.getmat());
00074         typedef typename PI::ParallelIndexSet ParallelIndexSet;
00075         typedef typename ParallelIndexSet::const_iterator IndexIterator;
00076         IndexIterator iend = pinfo.indexSet().end();
00077         
00078         for(IndexIterator index = pinfo.indexSet().begin(); index != iend; ++index)
00079           excluded[index->local()] = of.contains(index->local().attribute());
00080         
00081         SubGraph* sg= new SubGraph(*mg, excluded);
00082         PropertiesGraph* pg = new PropertiesGraph(*sg, IdentityMap(), sg->getEdgeIndexMap());
00083         return GraphTuple(mg,pg,sg);
00084       }
00085 
00086       static void free(GraphTuple& graphs)
00087       {
00088         delete get<2>(graphs);
00089         delete get<1>(graphs);
00090       }
00091     };
00092 
00093     template<class M>
00094     struct PropertiesGraphCreator<M,SolverCategory::nonoverlapping>
00095     {
00096       typedef typename M::matrix_type Matrix;
00097       typedef Dune::Amg::MatrixGraph<const Matrix> MatrixGraph;
00098       typedef Dune::Amg::SubGraph<MatrixGraph,
00099                        std::vector<bool> > SubGraph;
00100       typedef Dune::Amg::PropertiesGraph<SubGraph,
00101                               VertexProperties,
00102                               EdgeProperties,
00103                               IdentityMap,
00104                               typename SubGraph::EdgeIndexMap>
00105       PropertiesGraph;
00106     
00107       typedef Dune::tuple<MatrixGraph*,PropertiesGraph*,SubGraph*> GraphTuple;
00108       
00109       template<class OF, class T, class PI>
00110       static GraphTuple create(const M& matrix, T& excluded, 
00111                                PI& pinfo, const OF& of)
00112       {
00113         typedef OF OverlapFlags;
00114         MatrixGraph* mg = new MatrixGraph(matrix.getmat());
00115         typedef typename PI::ParallelIndexSet ParallelIndexSet;
00116         typedef typename ParallelIndexSet::const_iterator IndexIterator;
00117         IndexIterator iend = pinfo.indexSet().end();
00118         
00119         for(IndexIterator index = pinfo.indexSet().begin(); index != iend; ++index)
00120           excluded[index->local()] = of.contains(index->local().attribute());
00121         
00122         SubGraph* sg= new SubGraph(*mg, excluded);
00123         PropertiesGraph* pg = new PropertiesGraph(*sg, IdentityMap(), sg->getEdgeIndexMap());
00124         return GraphTuple(mg,pg,sg);
00125       }
00126 
00127       static void free(GraphTuple& graphs)
00128       {
00129         delete get<2>(graphs);
00130         delete get<1>(graphs);
00131       }
00132     };
00133     
00134   }//namespace Amg
00135 } // namespace Dune
00136 #endif