#NEWLINE# def c_addto( self , i , j , buf_name , tmp_name , tmp_decl , extruded = None , is_facet = False , applied_blas = False ) : #NEWLINE# #INDENT# maps = as_tuple ( self . map , Map ) #NEWLINE# nrows = maps [ 0 ] . split [ i ] . arity #NEWLINE# ncols = maps [ 1 ] . split [ j ] . arity #NEWLINE# rows_str = ( '%s + i * %s' % ( self . c_map_name ( 0 , i ) , nrows ) ) #NEWLINE# cols_str = ( '%s + i * %s' % ( self . c_map_name ( 1 , j ) , ncols ) ) #NEWLINE# if ( extruded is not None ) : #NEWLINE# #INDENT# rows_str = ( extruded + self . c_map_name ( 0 , i ) ) #NEWLINE# cols_str = ( extruded + self . c_map_name ( 1 , j ) ) #NEWLINE# #UNINDENT# if is_facet : #NEWLINE# #INDENT# nrows *= 2 #NEWLINE# ncols *= 2 #NEWLINE# #UNINDENT# ret = [ ] #NEWLINE# ( rbs , cbs ) = self . data . sparsity [ ( i , j ) ] . dims [ 0 ] [ 0 ] #NEWLINE# rdim = ( rbs * nrows ) #NEWLINE# addto_name = buf_name #NEWLINE# addto = 'MatSetValuesLocal' #NEWLINE# if self . data . _is_vector_field : #NEWLINE# #INDENT# addto = 'MatSetValuesBlockedLocal' #NEWLINE# if self . _flatten : #NEWLINE# #INDENT# if applied_blas : #NEWLINE# #INDENT# idx = ( '[(%%(ridx)s)*%d + (%%(cidx)s)]' % rdim ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# idx = '[%(ridx)s][%(cidx)s]' #NEWLINE# #UNINDENT# ret = [ ] #NEWLINE# idx_l = ( idx % { #NEWLINE# #INDENT# 'ridx' : ( '%d*j + k' % rbs ) , #NEWLINE# 'cidx' : ( '%d*l + m' % cbs ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# idx_r = ( idx % { #NEWLINE# #INDENT# 'ridx' : ( 'j + %d*k' % nrows ) , #NEWLINE# 'cidx' : ( 'l + %d*m' % ncols ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# ret = [ ( '\n                %(tmp_decl)s;\n                for ( int j = 0; j < %(nrows)d; j++ ) {\n                   for ( int k = 0; k < %(rbs)d; k++ ) {\n                      for ( int l = 0; l < %(ncols)d; l++ ) {\n                         for ( int m = 0; m < %(cbs)d; m++ ) {\n                            %(tmp_name)s%(idx_l)s = %(buf_name)s%(idx_r)s;\n                         }\n                      }\n                   }\n                }' % { #NEWLINE# #INDENT# 'nrows' : nrows , #NEWLINE# 'ncols' : ncols , #NEWLINE# 'rbs' : rbs , #NEWLINE# 'cbs' : cbs , #NEWLINE# 'idx_l' : idx_l , #NEWLINE# 'idx_r' : idx_r , #NEWLINE# 'buf_name' : buf_name , #NEWLINE# 'tmp_decl' : tmp_decl , #NEWLINE# 'tmp_name' : tmp_name , #NEWLINE# #UNINDENT# } ) ] #NEWLINE# addto_name = tmp_name #NEWLINE# #UNINDENT# ( rmap , cmap ) = maps #NEWLINE# ( rdim , cdim ) = self . data . dims [ i ] [ j ] #NEWLINE# if ( ( rmap . vector_index is not None ) or ( cmap . vector_index is not None ) ) : #NEWLINE# #INDENT# rows_str = 'rowmap' #NEWLINE# cols_str = 'colmap' #NEWLINE# addto = 'MatSetValuesLocal' #NEWLINE# fdict = { #NEWLINE# #INDENT# 'nrows' : nrows , #NEWLINE# 'ncols' : ncols , #NEWLINE# 'rdim' : rdim , #NEWLINE# 'cdim' : cdim , #NEWLINE# 'rowmap' : self . c_map_name ( 0 , i ) , #NEWLINE# 'colmap' : self . c_map_name ( 1 , idx ) , #NEWLINE# 'drop_full_row' : ( 0 if ( rmap . vector_index is not None ) else 1 ) , #NEWLINE# 'drop_full_col' : ( 0 if ( cmap . vector_index is not None ) else 1 ) , #NEWLINE# #UNINDENT# } #NEWLINE# ret . append ( ( '\n                PetscInt rowmap[%(nrows)d*%(rdim)d];\n                PetscInt colmap[%(ncols)d*%(cdim)d];\n                int discard, tmp, block_row, block_col;\n                for ( int j = 0; j < %(nrows)d; j++ ) {\n                    block_row = %(rowmap)s[i*%(nrows)d + j];\n                    discard = 0;\n                    if ( block_row < 0 ) {\n                        tmp = -(block_row + 1);\n                        discard = 1;\n                        block_row = tmp & ~0x70000000;\n                    }\n                    for ( int k = 0; k < %(rdim)d; k++ ) {\n                        if ( discard && (%(drop_full_row)d || ((tmp & (1 << (30 - k))) != 0)) ) {\n                            rowmap[j*%(rdim)d + k] = -1;\n                        } else {\n                            rowmap[j*%(rdim)d + k] = (block_row)*%(rdim)d + k;\n                        }\n                    }\n                }\n                for ( int j = 0; j < %(ncols)d; j++ ) {\n                    discard = 0;\n                    block_col = %(colmap)s[i*%(ncols)d + j];\n                    if ( block_col < 0 ) {\n                        tmp = -(block_col + 1);\n                        discard = 1;\n                        block_col = tmp & ~0x70000000;\n                    }\n                    for ( int k = 0; k < %(cdim)d; k++ ) {\n                        if ( discard && (%(drop_full_col)d || ((tmp & (1 << (30 - k))) != 0)) ) {\n                            colmap[j*%(rdim)d + k] = -1;\n                        } else {\n                            colmap[j*%(cdim)d + k] = (block_col)*%(cdim)d + k;\n                        }\n                    }\n                }\n                ' % fdict ) ) #NEWLINE# nrows *= rdim #NEWLINE# ncols *= cdim #NEWLINE# #UNINDENT# #UNINDENT# ret . append ( ( '%(addto)s(%(mat)s, %(nrows)s, %(rows)s,\n                                         %(ncols)s, %(cols)s,\n                                         (const PetscScalar *)%(vals)s,\n                                         %(insert)s);' % { #NEWLINE# #INDENT# 'mat' : self . c_arg_name ( i , j ) , #NEWLINE# 'vals' : addto_name , #NEWLINE# 'addto' : addto , #NEWLINE# 'nrows' : nrows , #NEWLINE# 'ncols' : ncols , #NEWLINE# 'rows' : rows_str , #NEWLINE# 'cols' : cols_str , #NEWLINE# 'insert' : ( 'INSERT_VALUES' if ( self . access == WRITE ) else 'ADD_VALUES' ) , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# return '\n' . join ( ret )