00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "Ifpack_ConfigDefs.h"
00044 #include "Ifpack_Partitioner.h"
00045 #include "Ifpack_OverlappingPartitioner.h"
00046 #include "Ifpack_LinePartitioner.h"
00047 #include "Ifpack_Graph.h"
00048 #include "Epetra_Util.h"
00049
00050
00051 inline void Ifpack_LinePartitioner::local_automatic_line_search(int NumEqns, int * blockIndices, int last, int next, int LineID, double tol, int *itemp, double * dtemp) const {
00052 double *xvals=xcoord_, *yvals=ycoord_, *zvals=zcoord_;
00053
00054 int N = NumMyRows();
00055
00056 int allocated_space = MaxNumEntries();
00057 int * cols = itemp;
00058 int * indices = &itemp[allocated_space];
00059 double * dist = dtemp;
00060
00061
00062 while (blockIndices[next] == -1) {
00063
00064 int n=0;
00065 int neighbors_in_line=0;
00066
00067 Graph_->ExtractMyRowCopy(next,allocated_space,n,cols);
00068 double x0 = (xvals) ? xvals[next/NumEqns] : 0.0;
00069 double y0 = (yvals) ? yvals[next/NumEqns] : 0.0;
00070 double z0 = (zvals) ? zvals[next/NumEqns] : 0.0;
00071
00072
00073 int neighbor_len=0;
00074 for(int i=0; i<n; i+=NumEqns) {
00075 double mydist = 0.0;
00076 if(cols[i] >=N) continue;
00077 int nn = cols[i] / NumEqns;
00078 if(blockIndices[nn]==LineID) neighbors_in_line++;
00079 if(xvals) mydist += (x0 - xvals[nn]) * (x0 - xvals[nn]);
00080 if(yvals) mydist += (y0 - yvals[nn]) * (y0 - yvals[nn]);
00081 if(zvals) mydist += (z0 - zvals[nn]) * (z0 - zvals[nn]);
00082 dist[neighbor_len] = sqrt(mydist);
00083 indices[neighbor_len]=cols[i];
00084 neighbor_len++;
00085 }
00086
00087
00088 if(neighbors_in_line > 1) break;
00089
00090
00091 for(int k=0; k<NumEqns; k++)
00092 blockIndices[next + k] = LineID;
00093
00094
00095 Epetra_Util::Sort(true,neighbor_len,dist,0,0,1,&indices,0,0);
00096
00097 if(neighbor_len > 2 && indices[1] != last && blockIndices[indices[1]] == -1 && dist[1]/dist[neighbor_len-1] < tol) {
00098 last=next;
00099 next=indices[1];
00100 }
00101 else if(neighbor_len > 3 && indices[2] != last && blockIndices[indices[2]] == -1 && dist[2]/dist[neighbor_len-1] < tol) {
00102 last=next;
00103 next=indices[2];
00104 }
00105 else {
00106
00107 break;
00108 }
00109 }
00110 }
00111
00112
00113 int Ifpack_LinePartitioner::Compute_Blocks_AutoLine(int * blockIndices) const {
00114 double *xvals=xcoord_, *yvals=ycoord_, *zvals=zcoord_;
00115 int NumEqns = NumEqns_;
00116 double tol = threshold_;
00117 int N = NumMyRows();
00118 int allocated_space = MaxNumEntries();
00119
00120 int * cols = new int[2*allocated_space];
00121 int * indices = &cols[allocated_space];
00122 double * dist = new double[allocated_space];
00123
00124 int * itemp = new int[2*allocated_space];
00125 double *dtemp = new double[allocated_space];
00126
00127 int num_lines = 0;
00128
00129 for(int i=0; i<N; i+=NumEqns) {
00130 int nz=0;
00131
00132 if(blockIndices[i] !=-1) continue;
00133
00134
00135 Graph_->ExtractMyRowCopy(i,allocated_space,nz,cols);
00136 double x0 = (xvals) ? xvals[i/NumEqns] : 0.0;
00137 double y0 = (yvals) ? yvals[i/NumEqns] : 0.0;
00138 double z0 = (zvals) ? zvals[i/NumEqns] : 0.0;
00139
00140 int neighbor_len=0;
00141 for(int j=0; j<nz; j+=NumEqns) {
00142 double mydist = 0.0;
00143 int nn = cols[j] / NumEqns;
00144 if(cols[j] >=N) continue;
00145 if(xvals) mydist += (x0 - xvals[nn]) * (x0 - xvals[nn]);
00146 if(yvals) mydist += (y0 - yvals[nn]) * (y0 - yvals[nn]);
00147 if(zvals) mydist += (z0 - zvals[nn]) * (z0 - zvals[nn]);
00148 dist[neighbor_len] = sqrt(mydist);
00149 indices[neighbor_len]=cols[j];
00150 neighbor_len++;
00151 }
00152
00153 Epetra_Util::Sort(true,neighbor_len,dist,0,0,1,&indices,0,0);
00154
00155
00156 for(int k=0; k<NumEqns; k++)
00157 blockIndices[i + k] = num_lines;
00158
00159
00160 if(neighbor_len > 2 && dist[1]/dist[neighbor_len-1] < tol) {
00161 local_automatic_line_search(NumEqns,blockIndices,i,indices[1],num_lines,tol,itemp,dtemp);
00162 }
00163
00164 if(neighbor_len > 3 && dist[2]/dist[neighbor_len-1] < tol) {
00165 local_automatic_line_search(NumEqns,blockIndices,i,indices[2],num_lines,tol,itemp,dtemp);
00166 }
00167
00168 num_lines++;
00169 }
00170
00171
00172 delete [] cols;
00173 delete [] dist;
00174 delete [] itemp;
00175 delete [] dtemp;
00176
00177 return num_lines;
00178 }
00179
00180 int Ifpack_LinePartitioner::ComputePartitions()
00181 {
00182
00183 if(!xcoord_ && !ycoord_ && !zcoord_) IFPACK_CHK_ERR(-1);
00184 if((int)Partition_.size() != NumMyRows()) IFPACK_CHK_ERR(-2);
00185
00186
00187 if(Partition_.size() == 0) {NumLocalParts_ = 0; return 0;}
00188
00189
00190 for(int i=0; i<NumMyRows(); i++)
00191 Partition_[i] = -1;
00192
00193
00194 NumLocalParts_ = Compute_Blocks_AutoLine(&Partition_[0]);
00195
00196
00197 Parts_.resize(NumLocalParts_);
00198 return(0);
00199 }