/[escript]/branches/domexper/dudley/src/Mesh_resolveNodeIds.c
ViewVC logotype

Annotation of /branches/domexper/dudley/src/Mesh_resolveNodeIds.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3114 - (hide annotations)
Fri Aug 27 05:26:25 2010 UTC (9 years, 5 months ago) by jfenwick
File MIME type: text/plain
File size: 5437 byte(s)
It doesn't pass all tests but this is major progress

1 jgs 150
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 jgs 82 /**************************************************************/
16    
17 jfenwick 3086 /* Dudley: Mesh */
18 jgs 82
19 ksteube 1312 /* at input the element nodes refers to the numbering defined the global Id assigned to the nodes in the */
20     /* NodeFile. It is also not ensured that all nodes refered by an element is actually available */
21     /* on the process. At the output, a local node labeling is used and all nodes are available */
22     /* In particular the numbering of the element nodes is between 0 and in->NodeFile->numNodes */
23     /* The function does not create a distribution of the degrees of freedom. */
24 jgs 82
25     /**************************************************************/
26    
27     #include "Mesh.h"
28 jgs 123 #include "Util.h"
29 jgs 82
30     /**************************************************************/
31    
32 jfenwick 3086 void Dudley_Mesh_resolveNodeIds(Dudley_Mesh* in) {
33 ksteube 1312
34     index_t min_id, max_id, min_id2, max_id2, global_min_id, global_max_id,
35     *globalToNewLocalNodeLabels=NULL, *newLocalToGlobalNodeLabels=NULL;
36     dim_t len, n, newNumNodes, numDim;
37 jfenwick 3086 Dudley_NodeFile *newNodeFile=NULL;
38 ksteube 1312 #ifdef PASO_MPI
39     index_t id_range[2], global_id_range[2];
40     #endif
41 jfenwick 3086 numDim=Dudley_Mesh_getDim(in);
42 ksteube 1312 /* find the minimum and maximum id used by elements: */
43 jgs 123 min_id=INDEX_T_MAX;
44     max_id=-INDEX_T_MAX;
45 jfenwick 3114 //printf("Trying Elements:\n");
46 jfenwick 3086 Dudley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Elements);
47 jgs 82 max_id=MAX(max_id,max_id2);
48     min_id=MIN(min_id,min_id2);
49 jfenwick 3114 //printf("Trying FaceElements:\n");
50 jfenwick 3086 Dudley_ElementFile_setNodeRange(&min_id2,&max_id2,in->FaceElements);
51 jgs 82 max_id=MAX(max_id,max_id2);
52     min_id=MIN(min_id,min_id2);
53 jfenwick 3114 //printf("Trying ContactElements:\n");
54 jfenwick 3086 Dudley_ElementFile_setNodeRange(&min_id2,&max_id2,in->ContactElements);
55 jgs 82 max_id=MAX(max_id,max_id2);
56     min_id=MIN(min_id,min_id2);
57 jfenwick 3086 Dudley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Points);
58 jgs 82 max_id=MAX(max_id,max_id2);
59     min_id=MIN(min_id,min_id2);
60 ksteube 1312 #ifdef PASO_MPI
61     id_range[0]=-min_id;
62     id_range[1]=max_id;
63     MPI_Allreduce( id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm );
64     global_min_id=-global_id_range[0];
65     global_max_id=global_id_range[1];
66     #else
67     global_min_id=min_id;
68     global_max_id=max_id;
69     #endif
70 jfenwick 3086 #ifdef Dudley_TRACE
71 ksteube 1312 printf("Node id range used by elements is %d:%d\n",global_min_id,global_max_id);
72 jgs 82 #endif
73 gross 1739 if (min_id>max_id) {
74     max_id=-1;
75     min_id=0;
76     }
77 jgs 82
78 ksteube 1312 /* allocate mappings for new local node labeling to global node labeling (newLocalToGlobalNodeLabels)
79     and global node labeling to the new local node labeling (globalToNewLocalNodeLabels[i-min_id] is the
80     new local id of global node i) */
81 gross 2385 len=(max_id>=min_id) ? max_id-min_id+1 : 0 ;
82 ksteube 1312 globalToNewLocalNodeLabels=TMPMEMALLOC(len,index_t); /* local mask for used nodes */
83     newLocalToGlobalNodeLabels=TMPMEMALLOC(len,index_t);
84 jfenwick 3086 if (! ( (Dudley_checkPtr(globalToNewLocalNodeLabels) && Dudley_checkPtr(newLocalToGlobalNodeLabels) ) ) ) {
85 jgs 82
86 ksteube 1312 #pragma omp parallel
87     {
88     #pragma omp for private(n) schedule(static)
89     for (n=0;n<len;n++) newLocalToGlobalNodeLabels[n]=-1;
90     #pragma omp for private(n) schedule(static)
91     for (n=0;n<len;n++) globalToNewLocalNodeLabels[n]=-1;
92     }
93 jgs 82
94 ksteube 1312 /* mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */
95 jfenwick 3086 Dudley_Mesh_markNodes(globalToNewLocalNodeLabels,min_id,in,FALSE);
96 jgs 82
97 ksteube 1312 /* create a local labeling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels*/
98 jgs 82
99 jfenwick 3086 newNumNodes=Dudley_Util_packMask(len,globalToNewLocalNodeLabels,newLocalToGlobalNodeLabels);
100 bcumming 730
101 ksteube 1312 /* invert the new labeling and shift the index newLocalToGlobalNodeLabels to global node ids */
102     #pragma omp parallel for private(n) schedule(static)
103     for (n=0;n<newNumNodes;n++) {
104 gross 1765 #ifdef BOUNDS_CHECK
105     if (n >= len || n < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
106     if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
107     #endif
108 ksteube 1312 globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]]=n;
109     newLocalToGlobalNodeLabels[n]+=min_id;
110     }
111     /* create a new table */
112 jfenwick 3086 newNodeFile=Dudley_NodeFile_alloc(numDim,in->MPIInfo);
113     if (Dudley_noError()) {
114     Dudley_NodeFile_allocTable(newNodeFile,newNumNodes);
115 ksteube 1312 }
116 jfenwick 3086 if (Dudley_noError()) {
117     Dudley_NodeFile_gather_global(newLocalToGlobalNodeLabels,in->Nodes, newNodeFile);
118 gross 1765 }
119 jfenwick 3086 if (Dudley_noError()) {
120     Dudley_NodeFile_free(in->Nodes);
121 ksteube 1312 in->Nodes=newNodeFile;
122     /* relable nodes of the elements: */
123 jfenwick 3086 Dudley_Mesh_relableElementNodes(globalToNewLocalNodeLabels,min_id,in);
124 ksteube 1312 }
125 jgs 82 }
126 ksteube 1312 TMPMEMFREE(globalToNewLocalNodeLabels);
127     TMPMEMFREE(newLocalToGlobalNodeLabels);
128 jfenwick 3086 if (! Dudley_noError()) {
129     Dudley_NodeFile_free(newNodeFile);
130 ksteube 1312 }
131 jgs 82 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26