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

Contents of /trunk/finley/src/Mesh_resolveNodeIds.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100 - (show annotations)
Wed Dec 15 03:48:48 2004 UTC (14 years, 10 months ago) by jgs
Original Path: trunk/esys2/finley/src/finleyC/Mesh_resolveNodeIds.c
File MIME type: text/plain
File size: 5046 byte(s)
*** empty log message ***

1 /**************************************************************/
2
3 /* Finley: Mesh */
4
5 /* at input the element nodes refers to the numbering defined the Id assigned to the nodes in the */
6 /* NodeFile. At the output, the numbering of the element nodes is between 0 and numNodes */
7 /* degreesOfFreedom are not neccessarily referening to a dense numbering */
8
9 /**************************************************************/
10
11 /* Copyrights by ACcESS Australia 2003 */
12 /* Author: gross@access.edu.au */
13 /* Version: $Id$ */
14
15 /**************************************************************/
16
17 #include "Finley.h"
18 #include "Mesh.h"
19
20 /**************************************************************/
21
22 void Finley_Mesh_resolveNodeIds(Finley_Mesh* in) {
23 maybelong k,min_id,max_id,min_id2,max_id2,len,numDim,newNumNodes,n;
24 maybelong *maskNodes=NULL,*maskElements=NULL,*index=NULL;
25 Finley_NodeFile *newNodeFile=NULL;
26 Finley_ErrorCode=NO_ERROR;
27 numDim=Finley_Mesh_getDim(in);
28
29 /* find the minimum and maximum id used: */
30
31 min_id=MAYBELONG_MAX;
32 max_id=-MAYBELONG_MAX;
33 Finley_NodeFile_setIdRange(&min_id2,&max_id2,in->Nodes);
34 if (min_id2==MAYBELONG_MAX || max_id2==-MAYBELONG_MAX) {
35 Finley_ErrorCode=VALUE_ERROR;
36 sprintf(Finley_ErrorMsg,"Mesh has not been defined completely.");
37 goto clean;
38 }
39
40 max_id=MAX(max_id,max_id2);
41 min_id=MIN(min_id,min_id2);
42 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Elements);
43 max_id=MAX(max_id,max_id2);
44 min_id=MIN(min_id,min_id2);
45 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->FaceElements);
46 max_id=MAX(max_id,max_id2);
47 min_id=MIN(min_id,min_id2);
48 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->ContactElements);
49 max_id=MAX(max_id,max_id2);
50 min_id=MIN(min_id,min_id2);
51 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Points);
52 max_id=MAX(max_id,max_id2);
53 min_id=MIN(min_id,min_id2);
54 #ifdef Finley_TRACE
55 printf("Node id range is %d:%d\n",min_id,max_id);
56 #endif
57
58 /* allocate a new node file used to gather existing node file: */
59
60 len=max_id-min_id+1;
61 newNodeFile=Finley_NodeFile_alloc(numDim);
62 if (Finley_ErrorCode!=NO_ERROR) goto clean;
63
64 maskNodes=(maybelong*)TMPMEMALLOC(len*sizeof(maybelong));
65 if (Finley_checkPtr(maskNodes)) goto clean;
66
67 maskElements=(maybelong*)TMPMEMALLOC(len*sizeof(maybelong));
68 if (Finley_checkPtr(maskElements)) goto clean;
69
70 index=(maybelong*)TMPMEMALLOC(in->Nodes->numNodes*sizeof(maybelong));
71 if (Finley_checkPtr(maskElements)) goto clean;
72
73 Finley_NodeFile_allocTable(newNodeFile,len);
74 if (Finley_ErrorCode!=NO_ERROR) goto clean;
75
76 #pragma omp parallel for private(n) schedule(static)
77 for (n=0;n<in->Nodes->numNodes;n++) index[n]=-1;
78 #pragma omp parallel for private(n) schedule(static)
79 for (n=0;n<len;n++) {
80 maskNodes[n]=-1;
81 maskElements[n]=-1;
82 }
83 /* mark the nodes referred by elements in maskElements: */
84
85 Finley_Mesh_markNodes(maskElements,min_id,in,FALSE);
86
87 /* mark defined nodes */
88
89 #pragma omp parallel for private(k) schedule(static)
90 for (k=0;k<in->Nodes->numNodes;k++) maskNodes[in->Nodes->Id[k]-min_id]=1;
91
92 /* check if all referenced nodes are actually defined: */
93
94 #pragma omp parallel for private(k) schedule(static)
95 for (k=0;k<len;k++) {
96 /* if a node is refered by an element is there a node defined ?*/
97 if (maskElements[k]>=0 && maskNodes[k]<0) {
98 Finley_ErrorCode=VALUE_ERROR;
99 sprintf(Finley_ErrorMsg,"Node id %d is referenced by element but is not defined.",k+min_id);
100 }
101 }
102
103 if (Finley_ErrorCode==NO_ERROR) {
104
105 /* scatter the nodefile in->nodes into newNodeFile using index; */
106 #pragma omp parallel for private(k) schedule(static)
107 for (k=0;k<in->Nodes->numNodes;k++) index[k]=in->Nodes->Id[k]-min_id;
108 Finley_NodeFile_scatter(index,in->Nodes,newNodeFile);
109
110 /* relable used nodes: */
111 /* index maps the new node labeling onto the old one */
112 newNumNodes=Finley_Util_packMask(len,maskElements,index);
113 #pragma omp parallel for private(k) schedule(static)
114 for (k=0;k<newNumNodes;k++) maskElements[index[k]]=k;
115
116 /* create a new table of nodes: */
117 Finley_NodeFile_deallocTable(in->Nodes);
118 Finley_NodeFile_allocTable(in->Nodes,newNumNodes);
119 if (Finley_ErrorCode!=NO_ERROR) goto clean;
120
121 /* gather the new nodefile into in->Nodes */
122 Finley_NodeFile_gather(index,newNodeFile,in->Nodes);
123
124 /* relable nodes of the elements: */
125 Finley_Mesh_relableElementNodes(maskElements,min_id,in);
126
127 }
128
129 /* clean-up: */
130
131 clean: TMPMEMFREE(maskNodes);
132 TMPMEMFREE(maskElements);
133 TMPMEMFREE(index);
134 Finley_NodeFile_deallocTable(newNodeFile);
135 Finley_NodeFile_dealloc(newNodeFile);
136 }
137
138 /*
139 * $Log$
140 * Revision 1.3 2004/12/15 03:48:45 jgs
141 * *** empty log message ***
142 *
143 * Revision 1.1.1.1 2004/10/26 06:53:57 jgs
144 * initial import of project esys2
145 *
146 * Revision 1.1.1.1 2004/06/24 04:00:40 johng
147 * Initial version of eys using boost-python.
148 *
149 *
150 */
151

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26