--- trunk/esys2/finley/src/finleyC/IndexList.c 2004/12/15 07:08:39 102 +++ trunk/finley/src/IndexList.c 2008/07/11 13:12:46 1628 @@ -1,71 +1,109 @@ -/* \$Id\$ */ -/**************************************************************/ +/* \$Id\$ */ -/* Finley: Converting an element list into a matrix shape */ +/******************************************************* + * + * Copyright 2003-2007 by ACceSS MNRF + * Copyright 2007 by University of Queensland + * + * http://esscc.uq.edu.au + * Primary Business: Queensland, Australia + * Licensed under the Open Software License version 3.0 + * http://www.opensource.org/licenses/osl-3.0.php + * + *******************************************************/ /**************************************************************/ -/* Copyrights by ACcESS Australia 2003,2004 */ -/* Author: gross@access.edu.au */ +/* Finley: Converting an element list into a matrix shape */ /**************************************************************/ -#include "Finley.h" -#include "ElementFile.h" -#include "System.h" #include "IndexList.h" +/* Translate from distributed/local array indices to global indices */ + /**************************************************************/ /* inserts the contributions from the element matrices of elements into the row index col. If symmetric is set, only the upper triangle of the matrix is stored. */ void Finley_IndexList_insertElements(Finley_IndexList* index_list, Finley_ElementFile* elements, - int reduce_row_order, maybelong* row_Label, - int reduce_col_order, maybelong* col_Label) { - maybelong e,kr,kc,NN_row,NN_col,i,icol,irow,color; - + bool_t reduce_row_order, index_t* row_map, + bool_t reduce_col_order, index_t* col_map) { + /* index_list is an array of linked lists. Each entry is a row (DOF) and contains the indices to the non-zero columns */ + index_t color, *id=NULL; + dim_t e,kr,kc,NN_row,NN_col,i,icol,irow, NN, *row_node=NULL,*col_node=NULL; if (elements!=NULL) { - maybelong NN=elements->ReferenceElement->Type->numNodes; - maybelong id[NN],*row_node,*col_node; - for (i=0;iReferenceElement->Type->linearNodes; - NN_col=elements->LinearReferenceElement->Type->numNodes; - } else { - col_node=id; - NN_col=elements->ReferenceElement->Type->numNodes; + NN=elements->numNodes; + id=TMPMEMALLOC(NN, index_t); + if (! Finley_checkPtr(id) ) { + for (i=0;iReferenceElement->Type->linearNodes; + NN_col=elements->LinearReferenceElement->Type->numNodes; + } else { + col_node=id; + NN_col=elements->ReferenceElement->Type->numNodes; + } + if (reduce_row_order) { + row_node=elements->ReferenceElement->Type->linearNodes; + NN_row=elements->LinearReferenceElement->Type->numNodes; + } else { + row_node=id; + NN_row=elements->ReferenceElement->Type->numNodes; + } + for (color=elements->minColor;color<=elements->maxColor;color++) { + #pragma omp for private(e,irow,kr,kc,icol) schedule(static) + for (e=0;enumElements;e++) { + if (elements->Color[e]==color) { + for (kr=0;krNodes[INDEX2(row_node[kr],e,NN)]]; + for (kc=0;kcNodes[INDEX2(col_node[kc],e,NN)]]; + Finley_IndexList_insertIndex(&(index_list[irow]),icol); + } + } + } + } + } + TMPMEMFREE(id); } - if (reduce_row_order) { - row_node=elements->ReferenceElement->Type->linearNodes; - NN_row=elements->LinearReferenceElement->Type->numNodes; - } else { - row_node=id; - NN_row=elements->ReferenceElement->Type->numNodes; - } - for (color=0;colornumColors;color++) { - #pragma omp for private(e,irow,kr,kc,icol) schedule(static) - for (e=0;enumElements;e++) { - if (elements->Color[e]==color) { - for (kr=0;krNodes[INDEX2(row_node[kr],e,NN)]]; - for (kc=0;kcNodes[INDEX2(col_node[kc],e,NN)]]; - Finley_IndexList_insertIndex(&(index_list[irow]),icol); - } - } - } - } - } } return; } +void Finley_IndexList_insertElementsWithRowRange(Finley_IndexList* index_list, index_t firstRow, index_t lastRow, + Finley_ElementFile* elements, index_t* row_map, index_t* col_map) +{ + index_t color; + dim_t e,kr,kc,icol,irow, NN; + if (elements!=NULL) { + NN=elements->numNodes; + for (color=elements->minColor;color<=elements->maxColor;color++) { + #pragma omp for private(e,irow,kr,kc,icol) schedule(static) + for (e=0;enumElements;e++) { + if (elements->Color[e]==color) { + for (kr=0;krNodes[INDEX2(kr,e,NN)]]; + if ((firstRow<=irow) && (irow < lastRow)) { + irow-=firstRow; + for (kc=0;kcNodes[INDEX2(kc,e,NN)]]; + Finley_IndexList_insertIndex(&(index_list[irow]),icol); + } + } + } + } + } + } + } +} + /* inserts row index row into the Finley_IndexList in if it does not exist */ -void Finley_IndexList_insertIndex(Finley_IndexList* in, maybelong index) { - int i; +void Finley_IndexList_insertIndex(Finley_IndexList* in, index_t index) { + dim_t i; /* is index in in? */ for (i=0;in;i++) { if (in->index[i]==index) return; @@ -89,21 +127,37 @@ /* counts the number of row indices in the Finley_IndexList in */ -int Finley_IndexList_count(Finley_IndexList* in) { +dim_t Finley_IndexList_count(Finley_IndexList* in, index_t range_min,index_t range_max) { + dim_t i; + dim_t out=0; + register index_t itmp; if (in==NULL) { return 0; } else { - return (in->n)+Finley_IndexList_count(in->extension); + for (i=0;in;i++) { + itmp=in->index[i]; + if ((itmp>=range_min) && (range_max>itmp)) ++out; + } + return out+Finley_IndexList_count(in->extension, range_min,range_max); } } /* count the number of row indices in the Finley_IndexList in */ -void Finley_IndexList_toArray(Finley_IndexList* in, maybelong* array) { - int i; +void Finley_IndexList_toArray(Finley_IndexList* in, index_t* array, index_t range_min,index_t range_max, index_t index_offset) { + dim_t i, ptr; + register index_t itmp; if (in!=NULL) { - for (i=0;in;i++) array[i]=in->index[i]+INDEX_OFFSET; - Finley_IndexList_toArray(in->extension,&(array[in->n])); + ptr=0; + for (i=0;in;i++) { + itmp=in->index[i]; + if ((itmp>=range_min) && (range_max>itmp)) { + array[ptr]=itmp+index_offset; + ptr++; + } + + } + Finley_IndexList_toArray(in->extension,&(array[ptr]), range_min, range_max, index_offset); } } @@ -116,11 +170,43 @@ } } -/* - * \$Log\$ - * Revision 1.4 2004/12/15 07:08:32 jgs - * *** empty log message *** - * - * - * - */ +/* creates a Paso_pattern from a range of indices */ +Paso_Pattern* Finley_IndexList_createPattern(dim_t n0, dim_t n,Finley_IndexList* index_list,index_t range_min,index_t range_max,index_t index_offset) +{ + dim_t *ptr=NULL; + register dim_t s,i,itmp; + index_t *index=NULL; + Paso_Pattern* out=NULL; + + ptr=MEMALLOC(n+1-n0,index_t); + if (! Finley_checkPtr(ptr) ) { + /* get the number of connections per row */ + #pragma omp parallel for schedule(static) private(i) + for(i=n0;i