/[escript]/branches/doubleplusgood/finley/src/Mesh_resolveNodeIds.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/finley/src/Mesh_resolveNodeIds.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26