/[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 1765 - (show annotations)
Mon Sep 8 02:49:57 2008 UTC (10 years, 7 months ago) by gross
File MIME type: text/plain
File size: 5364 byte(s)
some fixes for the case of empty processor
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 /**************************************************************/
17
18 /* Finley: Mesh */
19
20 /* at input the element nodes refers to the numbering defined the global Id assigned to the nodes in the */
21 /* NodeFile. It is also not ensured that all nodes refered by an element is actually available */
22 /* on the process. At the output, a local node labeling is used and all nodes are available */
23 /* In particular the numbering of the element nodes is between 0 and in->NodeFile->numNodes */
24 /* The function does not create a distribution of the degrees of freedom. */
25
26 /**************************************************************/
27
28 #include "Mesh.h"
29 #include "Util.h"
30
31 /**************************************************************/
32
33 void Finley_Mesh_resolveNodeIds(Finley_Mesh* in) {
34
35 index_t min_id, max_id, min_id2, max_id2, global_min_id, global_max_id,
36 *globalToNewLocalNodeLabels=NULL, *newLocalToGlobalNodeLabels=NULL;
37 dim_t len, n, newNumNodes, numDim;
38 Finley_NodeFile *newNodeFile=NULL;
39 #ifdef PASO_MPI
40 index_t id_range[2], global_id_range[2];
41 #endif
42 numDim=Finley_Mesh_getDim(in);
43 /* find the minimum and maximum id used by elements: */
44 min_id=INDEX_T_MAX;
45 max_id=-INDEX_T_MAX;
46 Finley_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 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->FaceElements);
50 max_id=MAX(max_id,max_id2);
51 min_id=MIN(min_id,min_id2);
52 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->ContactElements);
53 max_id=MAX(max_id,max_id2);
54 min_id=MIN(min_id,min_id2);
55 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Points);
56 max_id=MAX(max_id,max_id2);
57 min_id=MIN(min_id,min_id2);
58 #ifdef PASO_MPI
59 id_range[0]=-min_id;
60 id_range[1]=max_id;
61 MPI_Allreduce( id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm );
62 global_min_id=-global_id_range[0];
63 global_max_id=global_id_range[1];
64 #else
65 global_min_id=min_id;
66 global_max_id=max_id;
67 #endif
68 #ifdef Finley_TRACE
69 printf("Node id range used by elements is %d:%d\n",global_min_id,global_max_id);
70 #endif
71 if (min_id>max_id) {
72 max_id=-1;
73 min_id=0;
74 }
75
76 /* allocate mappings for new local node labeling to global node labeling (newLocalToGlobalNodeLabels)
77 and global node labeling to the new local node labeling (globalToNewLocalNodeLabels[i-min_id] is the
78 new local id of global node i) */
79 len=(max_id>min_id) ? max_id-min_id+1 : 0 ;
80 globalToNewLocalNodeLabels=TMPMEMALLOC(len,index_t); /* local mask for used nodes */
81 newLocalToGlobalNodeLabels=TMPMEMALLOC(len,index_t);
82 if (! ( (Finley_checkPtr(globalToNewLocalNodeLabels) && Finley_checkPtr(newLocalToGlobalNodeLabels) ) ) ) {
83
84 #pragma omp parallel
85 {
86 #pragma omp for private(n) schedule(static)
87 for (n=0;n<len;n++) newLocalToGlobalNodeLabels[n]=-1;
88 #pragma omp for private(n) schedule(static)
89 for (n=0;n<len;n++) globalToNewLocalNodeLabels[n]=-1;
90 }
91
92 /* mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */
93 Finley_Mesh_markNodes(globalToNewLocalNodeLabels,min_id,in,FALSE);
94
95 /* create a local labeling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels*/
96
97 newNumNodes=Finley_Util_packMask(len,globalToNewLocalNodeLabels,newLocalToGlobalNodeLabels);
98
99 /* invert the new labeling and shift the index newLocalToGlobalNodeLabels to global node ids */
100 #pragma omp parallel for private(n) schedule(static)
101 for (n=0;n<newNumNodes;n++) {
102 #ifdef BOUNDS_CHECK
103 if (n >= len || n < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
104 if (newLocalToGlobalNodeLabels[n] >= len || newLocalToGlobalNodeLabels[n] < 0) { printf("BOUNDS_CHECK %s %d n=%d\n", __FILE__, __LINE__, n); exit(1); }
105 #endif
106 globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]]=n;
107 newLocalToGlobalNodeLabels[n]+=min_id;
108 }
109 /* create a new table */
110 newNodeFile=Finley_NodeFile_alloc(numDim,in->MPIInfo);
111 if (Finley_noError()) {
112 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
113 }
114 if (Finley_noError()) {
115 Finley_NodeFile_gather_global(newLocalToGlobalNodeLabels,in->Nodes, newNodeFile);
116 }
117 if (Finley_noError()) {
118 Finley_NodeFile_free(in->Nodes);
119 in->Nodes=newNodeFile;
120 /* relable nodes of the elements: */
121 Finley_Mesh_relableElementNodes(globalToNewLocalNodeLabels,min_id,in);
122 }
123 }
124 TMPMEMFREE(globalToNewLocalNodeLabels);
125 TMPMEMFREE(newLocalToGlobalNodeLabels);
126 if (! Finley_noError()) {
127 Finley_NodeFile_free(newNodeFile);
128 }
129 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26