/[escript]/trunk/finley/src/NodeDistribution_add.c
ViewVC logotype

Annotation of /trunk/finley/src/NodeDistribution_add.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 787 - (hide annotations)
Wed Jul 26 01:46:45 2006 UTC (13 years, 3 months ago) by bcumming
File MIME type: text/plain
File size: 4586 byte(s)
MPI update
Each element (normal elements, faceElements, ContactElements and points)
are now assigned a unique global id to streamline per-element
calculations and file IO of element data.



1 bcumming 731 /* created by Ben Cumming on 2/5/2006 */
2    
3 bcumming 787 /* Add degrees of freedom to the forward and backward lists for the edge associated with
4     a neighbour sub-domain in a Finley_NodeDistribution */
5 bcumming 731 #include "Distribution.h"
6    
7     #ifdef PASO_MPI
8    
9     /* returns position of first occurence of val in list of lenght len
10     returns -1 if val is not in list */
11     static index_t findInList( index_t val, index_t* list, dim_t len )
12     {
13     index_t i;
14    
15     for( i=0; i<len; i++ )
16     if( list[i]==val )
17     return i;
18     return -1;
19     }
20    
21 bcumming 787 /*
22     in : the NodeDistribution to update
23     domain : the process rank of the domain for which to add
24     the edge data
25     numForward : the number of degrees of freedom that are being added
26     to the edge
27     indexLocal : the local indices of the degrees of freedom to add
28     */
29 bcumming 731 void Finley_NodeDistribution_addForward( Finley_NodeDistribution *in, index_t domain, dim_t numForward, index_t* indexLocal )
30     {
31     index_t posDomain=0;
32    
33     if( !numForward )
34     return;
35    
36     if( Finley_checkPtr(in) || Finley_checkPtr( indexLocal ) )
37     return;
38    
39     /* determine if we already share DOF with this domain */
40     posDomain = findInList( domain, in->neighbours, in->numNeighbours );
41    
42     /* we do */
43     if( posDomain>=0 )
44     {
45     MEMREALLOC( in->edges[posDomain]->indexForward, in->edges[posDomain]->numForward + numForward, index_t );
46     if( Finley_checkPtr(in->edges[posDomain]->indexForward) )
47     {
48     Finley_setError( PASO_MPI_ERROR, "Finley_NodeDistribution_addForward() : unable to realloc() memory for aditional degrees of freedom" );
49     return;
50     }
51     memcpy( in->edges[posDomain]->indexForward + in->edges[posDomain]->numForward, indexLocal, sizeof(index_t)*numForward );
52     in->edges[posDomain]->numForward += numForward;
53     }
54     /* we don't */
55     else
56     {
57     posDomain = findInList( -1, in->neighbours, in->numNeighbours );
58     if( posDomain==-1 )
59     {
60     posDomain = in->numNeighbours++;
61 bcumming 782 MEMREALLOC( in->edges, in->numNeighbours, Finley_NodeGhostEdge* );
62     MEMREALLOC( in->neighbours, in->numNeighbours, index_t );
63 bcumming 731 if( Finley_checkPtr( in->edges ) || Finley_checkPtr( in->neighbours ) )
64     return;
65     in->edges[posDomain] = NULL;
66     }
67     in->neighbours[posDomain] = domain;
68     in->edges[posDomain] = Finley_NodeGhostEdge_alloc();
69     if( Finley_checkPtr(in->edges[posDomain]) )
70     {
71     Finley_setError( MEMORY_ERROR, "Finley_NodeDistribution_addForward() : invalid pointer to ghost edge" );
72     return;
73     }
74     Finley_NodeGhostEdge_allocTable( in->edges[posDomain], numForward, 0 );
75     memcpy( in->edges[posDomain]->indexForward, indexLocal, sizeof(index_t)*numForward );
76     }
77     }
78    
79 bcumming 787 /*
80     see comments for Finley_NodeDistribtion_addForward
81     */
82 bcumming 731 void Finley_NodeDistribution_addBackward( Finley_NodeDistribution *in, index_t domain, dim_t numBackward, index_t* indexLocal )
83     {
84     index_t posDomain=0;
85    
86     if( !numBackward )
87     return;
88    
89     if( Finley_checkPtr(in) || Finley_checkPtr( indexLocal ) )
90     return;
91    
92     /* determine if we already share DOF with this domain */
93     posDomain = findInList( domain, in->neighbours, in->numNeighbours );
94    
95     /* we do */
96     if( posDomain>=0 )
97     {
98     MEMREALLOC( in->edges[posDomain]->indexBackward, in->edges[posDomain]->numBackward + numBackward, index_t );
99     if( Finley_checkPtr(in->edges[posDomain]->indexBackward) )
100     return;
101     memcpy( in->edges[posDomain]->indexBackward + in->edges[posDomain]->numBackward, indexLocal, sizeof(index_t)*numBackward );
102     in->edges[posDomain]->numBackward += numBackward;
103     }
104     /* we don't */
105     else
106     {
107 bcumming 782 posDomain = findInList( -1, in->neighbours, in->numNeighbours );
108 bcumming 731 if( posDomain==-1 )
109     {
110     posDomain = in->numNeighbours++;
111 bcumming 782 MEMREALLOC( in->edges, in->numNeighbours, Finley_NodeGhostEdge* );
112     MEMREALLOC( in->neighbours, in->numNeighbours, index_t );
113 bcumming 731 if( Finley_checkPtr( in->edges ) || Finley_checkPtr( in->neighbours ) )
114     return;
115     in->edges[posDomain] = NULL;
116     }
117     in->neighbours[posDomain] = domain;
118     in->edges[posDomain] = Finley_NodeGhostEdge_alloc();
119     if( Finley_checkPtr(in->edges[posDomain]))
120     {
121 bcumming 787 Finley_setError( MEMORY_ERROR, "Finley_NodeDistribution_addBackward() : invalid pointer to ghost edge" );
122 bcumming 731 return;
123     }
124     Finley_NodeGhostEdge_allocTable( in->edges[posDomain], 0, numBackward );
125     memcpy( in->edges[posDomain]->indexBackward, indexLocal, sizeof(index_t)*numBackward );
126     }
127     }
128    
129     #endif

  ViewVC Help
Powered by ViewVC 1.1.26