33 #ifndef __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FVCR__CR_REORDER__
34 #define __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FVCR__CR_REORDER__
39 #include <boost/graph/adjacency_list.hpp>
64 void computeDegree(std::vector<size_t>& degree,std::vector<std::vector<size_t> >& vvConnections,
size_t minpind);
67 template <
typename TElem,
typename TGr
idFunction>
70 typedef typename TGridFunction::domain_type domain_type;
82 vvConnection.resize(num_dd_ind);
86 for (
int si=0;si<u.num_subsets();si++){
87 iterBegin = dd.
begin<TElem>(si);
88 iterEnd = dd.
end<TElem>(si);
90 if(iterBegin == iterEnd)
continue;
92 for(iter = iterBegin; iter != iterEnd; ++iter)
98 size_t num_sides = elem->num_sides();
99 size_t num_ind = num_sides *
dim + 1;
100 std::vector<size_t> globind(num_ind);
102 for (
size_t side=0;side<num_sides;side++)
103 for (
int d=0;d<
dim;d++)
104 globind[
dim*side+d]=ind.
index(d,side);
107 globind[num_ind-1]=pind;
108 if (pind<minpind) minpind=pind;
110 std::vector<size_t>::iterator it;
111 for (
size_t i=0;i<num_ind;i++){
112 size_t iIndex = globind[i];
113 for (
size_t j=0;j<num_ind;j++){
114 size_t jIndex = globind[j];
116 it =
find(vvConnection[iIndex].begin(), vvConnection[iIndex].end(), jIndex);
117 if(it == vvConnection[iIndex].end()) vvConnection[iIndex].push_back(jIndex);
119 it =
find(vvConnection[jIndex].begin(), vvConnection[jIndex].end(), iIndex);
120 if(it == vvConnection[jIndex].end()) vvConnection[jIndex].push_back(iIndex);
124 std::vector<size_t>
degree;
128 for (
size_t i=0;i<vvConnection.size();i++){
129 std::sort(vvConnection[i].begin(),vvConnection[i].end(),myCompDegree);
135 template <
class TGraph>
136 void extractPGraph(TGraph& G,std::vector<std::vector<size_t> >& vvConnection,
size_t pmin,
size_t dim,
bool directed){
137 for (
size_t i=0;i<pmin;i=i+
dim){
138 size_t s=vvConnection[i].size();
139 int ind1 = vvConnection[i][
s-2]-pmin;
140 if (ind1<0)
continue;
141 int ind2 = vvConnection[i][
s-1]-pmin;
142 boost::add_edge(ind1,ind2,G);
143 if (directed==
true) boost::add_edge(ind2,ind1,G);
148 template <
class TGraph>
149 void extractVGraph(TGraph& G,std::vector<std::vector<size_t> >& vvConnection,
size_t pmin,
size_t dim,
bool directed){
150 for (
size_t i=0;i<pmin;i=i+
dim){
151 size_t ind1 = (size_t)round((
number)i/
dim);
152 size_t s = vvConnection[i].size();
153 for (
size_t j=0;j<
s-1;j=j+2){
154 size_t ind2 = (size_t)round((
number)vvConnection[i][j]/
dim);
155 if (
dim*ind2>=pmin)
break;
156 if (ind1==ind2)
continue;
157 boost::add_edge(ind1,ind2,G);
158 if (directed==
true) boost::add_edge(ind2,ind1,G);
163 void CRCuthillMcKee(std::vector<size_t>& newIndex,std::vector<std::vector<size_t> >& vvConnection,
size_t dim,
164 size_t minpind,
bool bReverse,
bool bseparate,
bool orderp,
bool orderv);
167 template <
typename TDomain,
typename TGr
idFunction>
169 bool bReverse,
bool bseparate,
bool orderp,
bool orderv)
172 typedef typename TGridFunction::domain_type domain_type;
178 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object elem_type;
180 std::vector<std::vector<size_t> > vvConnection;
183 for (
int si=0;si<u.num_subsets();++si){
184 if (u.num_fct(si)<2){
185 if (u.num_fct(si)!=
dim+1){
186 UG_THROW(
"Wrong number of components in approximation space. Needed " <<
dim+1 <<
", given " << u.num_fct(si) <<
".\n");
189 for (
int d=0;d<
dim;d++){
191 UG_THROW(
"Component " << d <<
" in approximation space must be of Crouzeix-Raviart type.");
195 UG_THROW(
"Component dim in approximation space must be of piecewise constant type.");
202 for(
size_t i = 0; i < vDD.size(); ++i){
203 std::vector<size_t> newIndex;
204 cr_get_connections<elem_type,TGridFunction>(vvConnection,minpind,*vDD[i],u);
205 CRCuthillMcKee(newIndex,vvConnection,
dim,minpind,bReverse,bseparate,orderp,orderv);
206 vDD[i]->permute_indices(newIndex);
210 void CRSloan(std::vector<size_t>& newIndex,std::vector<std::vector<size_t> >& vvConnection,
size_t dim,
211 size_t minpind,
bool bseparate,
bool orderp,
bool orderv);
214 template <
typename TDomain,
typename TGr
idFunction>
216 bool bseparate,
bool orderp,
bool orderv)
219 typedef typename TGridFunction::domain_type domain_type;
225 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object elem_type;
227 std::vector<std::vector<size_t> > vvConnection;
230 for (
int si=0;si<u.num_subsets();++si){
231 if (u.num_fct(si)<2){
232 if (u.num_fct(si)!=
dim+1){
233 UG_THROW(
"Wrong number of components in approximation space. Needed " <<
dim+1 <<
", given " << u.num_fct(si) <<
".\n");
236 for (
int d=0;d<
dim;d++){
238 UG_THROW(
"Component " << d <<
" in approximation space must be of Crouzeix-Raviart type.");
242 UG_THROW(
"Component dim in approximation space must be of piecewise constant type.");
247 for(
size_t i = 0; i < vDD.size(); ++i){
248 std::vector<size_t> newIndex;
249 cr_get_connections<elem_type,TGridFunction>(vvConnection,minpind,*vDD[i],u);
250 CRSloan(newIndex,vvConnection,
dim,minpind,bseparate,orderp,orderv);
251 vDD[i]->permute_indices(newIndex);
255 void CRKing(std::vector<size_t>& newIndex,std::vector<std::vector<size_t> >& vvConnection,
size_t dim,
256 size_t minpind,
bool bReverse,
bool bseparate,
bool orderp,
bool orderv);
259 template <
typename TDomain,
typename TGr
idFunction>
261 bool bReverse,
bool bseparate,
bool orderp,
bool orderv)
264 typedef typename TGridFunction::domain_type domain_type;
270 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object elem_type;
272 std::vector<std::vector<size_t> > vvConnection;
275 for (
int si=0;si<u.num_subsets();++si){
276 if (u.num_fct(si)<2){
277 if (u.num_fct(si)!=
dim+1){
278 UG_THROW(
"Wrong number of components in approximation space. Needed " <<
dim+1 <<
", given " << u.num_fct(si) <<
".\n");
281 for (
int d=0;d<
dim;d++){
283 UG_THROW(
"Component " << d <<
" in approximation space must be of Crouzeix-Raviart type.");
287 UG_THROW(
"Component dim in approximation space must be of piecewise constant type.");
292 for(
size_t i = 0; i < vDD.size(); ++i){
293 std::vector<size_t> newIndex;
294 cr_get_connections<elem_type,TGridFunction>(vvConnection,minpind,*vDD[i],u);
295 CRKing(newIndex,vvConnection,
dim,minpind,bReverse,bseparate,orderp,orderv);
296 vDD[i]->permute_indices(newIndex);
300 void CRMinimumDegree(std::vector<size_t>& newIndex,std::vector<std::vector<size_t> >& vvConnection,
size_t dim,
301 size_t minpind,
bool bseparate,
bool orderp,
bool orderv);
304 template <
typename TDomain,
typename TGr
idFunction>
306 bool bseparate,
bool orderp,
bool orderv)
309 typedef typename TGridFunction::domain_type domain_type;
315 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object elem_type;
317 std::vector<std::vector<size_t> > vvConnection;
320 for (
int si=0;si<u.num_subsets();++si){
321 if (u.num_fct(si)<2){
322 if (u.num_fct(si)!=
dim+1){
323 UG_THROW(
"Wrong number of components in approximation space. Needed " <<
dim+1 <<
", given " << u.num_fct(si) <<
".\n");
326 for (
int d=0;d<
dim;d++){
328 UG_THROW(
"Component " << d <<
" in approximation space must be of Crouzeix-Raviart type.");
332 UG_THROW(
"Component dim in approximation space must be of piecewise constant type.");
337 for(
size_t i = 0; i < vDD.size(); ++i){
338 std::vector<size_t> newIndex;
339 cr_get_connections<elem_type,TGridFunction>(vvConnection,minpind,*vDD[i],u);
341 vDD[i]->permute_indices(newIndex);
347 std::vector<std::vector<size_t> >& vvConnections,
352 template <
typename TDomain,
typename TGr
idFunction>
357 typedef typename TGridFunction::domain_type domain_type;
363 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object elem_type;
365 for (
int si=0;si<u.num_subsets();++si){
366 if (u.num_fct(si)<2){
367 if (u.num_fct(si)!=
dim+1){
368 UG_THROW(
"Wrong number of components in approximation space. Needed " <<
dim+1 <<
", given " << u.num_fct(si) <<
".\n");
371 for (
int d=0;d<
dim;d++){
373 UG_THROW(
"Component " << d <<
" in approximation space must be of Crouzeix-Raviart type.");
377 UG_THROW(
"Component dim in approximation space must be of piecewise constant type.");
382 for(
size_t i = 0; i < vDD.size(); ++i){
384 std::vector<std::vector<size_t> > vvConnection;
386 cr_get_connections<elem_type,TGridFunction>(vvConnection,minpind,*vDD[i],u);
388 std::vector<size_t> vNewIndex;
391 vDD[i]->permute_indices(vNewIndex);
void indices(GridObject *elem, LocalIndices &ind, bool bHang=false) const
traits< TElem >::iterator begin()
size_t num_indices() const
traits< TElem >::iterator end()
std::vector< SmartPtr< DoFDistribution > > dof_distributions() const
index_type & index(size_t fct, size_t dof)
int degree(int v, ug::BidirectionalMatrix< T > const &M)
IndexLayout::Interface::iterator find(IndexLayout::Interface &interface, size_t i)
void CRKing(std::vector< size_t > &newIndex, std::vector< std::vector< size_t > > &vvConnection, size_t dim, size_t minpind, bool bReverse, bool bseparate, bool orderp, bool orderv)
orders the dof distribution using King
Definition: cr_reorder.cpp:362
void CRCuthillMcKee(std::vector< size_t > &newIndex, std::vector< std::vector< size_t > > &vvConnection, size_t dim, size_t minpind, bool bReverse, bool bseparate, bool orderp, bool orderv)
orders the dof distribution using Cuthill-McKee
Definition: cr_reorder.cpp:195
void CROrderKing(ApproximationSpace< TDomain > &approxSpace, TGridFunction &u, bool bReverse, bool bseparate, bool orderp, bool orderv)
orders the all DofDistributions of the ApproximationSpace using Cuthill-McKee
Definition: cr_reorder.h:260
void CRSloan(std::vector< size_t > &newIndex, std::vector< std::vector< size_t > > &vvConnection, size_t dim, size_t minpind, bool bseparate, bool orderp, bool orderv)
orders the dof distribution using Sloan
Definition: cr_reorder.cpp:254
void cr_get_connections(std::vector< std::vector< size_t > > &vvConnection, size_t &minpind, DoFDistribution &dd, TGridFunction &u)
Definition: cr_reorder.h:68
void CROrderMinimumDegree(ApproximationSpace< TDomain > &approxSpace, TGridFunction &u, bool bseparate, bool orderp, bool orderv)
orders the all DofDistributions of the ApproximationSpace using minimum degree algorithm
Definition: cr_reorder.h:305
void ComputeCRCuthillMcKeeOrder(std::vector< size_t > &vNewIndex, std::vector< std::vector< size_t > > &vvConnections, size_t minpind, bool bReverse)
Definition: cr_reorder.cpp:510
void CRMinimumDegree(std::vector< size_t > &newIndex, std::vector< std::vector< size_t > > &vvConnection, size_t dim, size_t minpind, bool bseparate, bool orderp, bool orderv)
orders the dof distribution using minimum degree algorithm
Definition: cr_reorder.cpp:422
void CROrderSloan(ApproximationSpace< TDomain > &approxSpace, TGridFunction &u, bool bseparate, bool orderp, bool orderv)
orders the all DofDistributions of the ApproximationSpace using Sloan
Definition: cr_reorder.h:215
void CROrderCuthillMcKee(ApproximationSpace< TDomain > &approxSpace, TGridFunction &u, bool bReverse, bool bseparate, bool orderp, bool orderv)
orders the all DofDistributions of the ApproximationSpace using Cuthill-McKee
Definition: cr_reorder.h:168
void extractVGraph(TGraph &G, std::vector< std::vector< size_t > > &vvConnection, size_t pmin, size_t dim, bool directed)
Definition: cr_reorder.h:149
void OrderCRCuthillMcKee(ApproximationSpace< TDomain > &approxSpace, TGridFunction &u, bool bReverse)
orders the all DofDistributions of the ApproximationSpace using Cuthill-McKee
Definition: cr_reorder.h:353
void computeDegree(std::vector< size_t > °ree, std::vector< std::vector< size_t > > &vvConnections, size_t minpind)
Definition: cr_reorder.cpp:180
void extractPGraph(TGraph &G, std::vector< std::vector< size_t > > &vvConnection, size_t pmin, size_t dim, bool directed)
Definition: cr_reorder.h:136
Definition: cr_reorder.h:49
const std::vector< size_t > & m_degree
storage field of connections of each index
Definition: cr_reorder.h:61
bool operator()(size_t i, size_t j)
comparison operator
Definition: cr_reorder.h:54
CompareDeg(const std::vector< size_t > &vInfo)
constructor, passing field with connections for each index
Definition: cr_reorder.h:51
SurfaceView::traits< TElem >::const_iterator const_iterator