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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3126 - (show annotations)
Wed Sep 1 00:37:53 2010 UTC (8 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 5264 byte(s)
Updated referenceElements and enums
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * 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
14
15 /**************************************************************/
16
17 /* Dudley: Mesh */
18
19 /* 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
25 /**************************************************************/
26
27 #include "Mesh.h"
28 #include "Util.h"
29
30 /**************************************************************/
31
32 void Dudley_Mesh_resolveNodeIds(Dudley_Mesh* in) {
33
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 Dudley_NodeFile *newNodeFile=NULL;
38 #ifdef PASO_MPI
39 index_t id_range[2], global_id_range[2];
40 #endif
41 numDim=Dudley_Mesh_getDim(in);
42 /* find the minimum and maximum id used by elements: */
43 min_id=INDEX_T_MAX;
44 max_id=-INDEX_T_MAX;
45 //printf("Trying Elements:\n");
46 Dudley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Elements);
47 max_id=MAX(max_id,max_id2);
48 min_id=MIN(min_id,min_id2);
49 //printf("Trying FaceElements:\n");
50 Dudley_ElementFile_setNodeRange(&min_id2,&max_id2,in->FaceElements);
51 max_id=MAX(max_id,max_id2);
52 min_id=MIN(min_id,min_id2);
53 Dudley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Points);
54 max_id=MAX(max_id,max_id2);
55 min_id=MIN(min_id,min_id2);
56 #ifdef PASO_MPI
57 id_range[0]=-min_id;
58 id_range[1]=max_id;
59 MPI_Allreduce( id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm );
60 global_min_id=-global_id_range[0];
61 global_max_id=global_id_range[1];
62 #else
63 global_min_id=min_id;
64 global_max_id=max_id;
65 #endif
66 #ifdef Dudley_TRACE
67 printf("Node id range used by elements is %d:%d\n",global_min_id,global_max_id);
68 #endif
69 if (min_id>max_id) {
70 max_id=-1;
71 min_id=0;
72 }
73
74 /* allocate mappings for new local node labeling to global node labeling (newLocalToGlobalNodeLabels)
75 and global node labeling to the new local node labeling (globalToNewLocalNodeLabels[i-min_id] is the
76 new local id of global node i) */
77 len=(max_id>=min_id) ? max_id-min_id+1 : 0 ;
78 globalToNewLocalNodeLabels=TMPMEMALLOC(len,index_t); /* local mask for used nodes */
79 newLocalToGlobalNodeLabels=TMPMEMALLOC(len,index_t);
80 if (! ( (Dudley_checkPtr(globalToNewLocalNodeLabels) && Dudley_checkPtr(newLocalToGlobalNodeLabels) ) ) ) {
81
82 #pragma omp parallel
83 {
84 #pragma omp for private(n) schedule(static)
85 for (n=0;n<len;n++) newLocalToGlobalNodeLabels[n]=-1;
86 #pragma omp for private(n) schedule(static)
87 for (n=0;n<len;n++) globalToNewLocalNodeLabels[n]=-1;
88 }
89
90 /* mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */
91 Dudley_Mesh_markNodes(globalToNewLocalNodeLabels,min_id,in,FALSE);
92
93 /* create a local labeling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels*/
94
95 newNumNodes=Dudley_Util_packMask(len,globalToNewLocalNodeLabels,newLocalToGlobalNodeLabels);
96
97 /* invert the new labeling and shift the index newLocalToGlobalNodeLabels to global node ids */
98 #pragma omp parallel for private(n) schedule(static)
99 for (n=0;n<newNumNodes;n++) {
100 #ifdef BOUNDS_CHECK
101 if (n >= len || n < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
102 if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
103 #endif
104 globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]]=n;
105 newLocalToGlobalNodeLabels[n]+=min_id;
106 }
107 /* create a new table */
108 newNodeFile=Dudley_NodeFile_alloc(numDim,in->MPIInfo);
109 if (Dudley_noError()) {
110 Dudley_NodeFile_allocTable(newNodeFile,newNumNodes);
111 }
112 if (Dudley_noError()) {
113 Dudley_NodeFile_gather_global(newLocalToGlobalNodeLabels,in->Nodes, newNodeFile);
114 }
115 if (Dudley_noError()) {
116 Dudley_NodeFile_free(in->Nodes);
117 in->Nodes=newNodeFile;
118 /* relable nodes of the elements: */
119 Dudley_Mesh_relableElementNodes(globalToNewLocalNodeLabels,min_id,in);
120 }
121 }
122 TMPMEMFREE(globalToNewLocalNodeLabels);
123 TMPMEMFREE(newLocalToGlobalNodeLabels);
124 if (! Dudley_noError()) {
125 Dudley_NodeFile_free(newNodeFile);
126 }
127 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26