// ====================================================================== int GetAggregates(Epetra_RowMatrix& A, Teuchos::ParameterList& List, double* thisns, Epetra_IntVector& aggrinfo) { if (!A.RowMatrixRowMap().SameAs(aggrinfo.Map())) ML_THROW("map of aggrinfo must match row map of operator", -1); std::string CoarsenType = List.get("aggregation: type", "Uncoupled"); double Threshold = List.get("aggregation: threshold", 0.0); int NumPDEEquations = List.get("PDE equations", 1); int nsdim = List.get("null space: dimension",-1); if (nsdim==-1) ML_THROW("dimension of nullspace not set", -1); int size = A.RowMatrixRowMap().NumMyElements(); ML_Aggregate* agg_object; ML_Aggregate_Create(&agg_object); ML_Aggregate_KeepInfo(agg_object,1); ML_Aggregate_Set_MaxLevels(agg_object,2); ML_Aggregate_Set_StartLevel(agg_object,0); ML_Aggregate_Set_Threshold(agg_object,Threshold); //agg_object->curr_threshold = 0.0; ML_Operator* ML_Ptent = 0; ML_Ptent = ML_Operator_Create(GetML_Comm()); if (!thisns) ML_THROW("nullspace is NULL", -1); ML_Aggregate_Set_NullSpace(agg_object, NumPDEEquations, nsdim, thisns,size); if (CoarsenType == "Uncoupled") agg_object->coarsen_scheme = ML_AGGR_UNCOUPLED; else if (CoarsenType == "Uncoupled-MIS") agg_object->coarsen_scheme = ML_AGGR_HYBRIDUM; else if (CoarsenType == "MIS") { /* needed for MIS, otherwise it sets the number of equations to * the null space dimension */ agg_object->max_levels = -7; agg_object->coarsen_scheme = ML_AGGR_MIS; } else if (CoarsenType == "METIS") agg_object->coarsen_scheme = ML_AGGR_METIS; else { ML_THROW("Requested aggregation scheme (" + CoarsenType + ") not recognized", -1); } ML_Operator* ML_A = ML_Operator_Create(GetML_Comm()); ML_Operator_WrapEpetraMatrix(&A,ML_A); int NextSize = ML_Aggregate_Coarsen(agg_object, ML_A, &ML_Ptent, GetML_Comm()); int* aggrmap = NULL; ML_Aggregate_Get_AggrMap(agg_object,0,&aggrmap); if (!aggrmap) ML_THROW("aggr_info not available", -1); #if 0 // debugging fflush(stdout); for (int proc=0; proc<A.GetRowMatrix()->Comm().NumProc(); ++proc) { if (A.GetRowMatrix()->Comm().MyPID()==proc) { std::cout << "Proc " << proc << ":" << std::endl; std::cout << "aggrcount " << aggrcount << std::endl; std::cout << "NextSize " << NextSize << std::endl; for (int i=0; i<size; ++i) std::cout << "aggrmap[" << i << "] = " << aggrmap[i] << std::endl; fflush(stdout); } A.GetRowMatrix()->Comm().Barrier(); } #endif assert (NextSize * nsdim != 0); for (int i=0; i<size; ++i) aggrinfo[i] = aggrmap[i]; ML_Aggregate_Destroy(&agg_object); return (NextSize/nsdim); }