~ubuntu-branches/ubuntu/trusty/scotch/trusty

« back to all changes in this revision

Viewing changes to src/libscotch/mesh_check.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-01-25 09:13:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080125091353-zghdao60dfsyc2bt
Tags: upstream-5.0.1.dfsg
ImportĀ upstreamĀ versionĀ 5.0.1.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2004,2007 ENSEIRB, INRIA & CNRS
 
2
**
 
3
** This file is part of the Scotch software package for static mapping,
 
4
** graph partitioning and sparse matrix ordering.
 
5
**
 
6
** This software is governed by the CeCILL-C license under French law
 
7
** and abiding by the rules of distribution of free software. You can
 
8
** use, modify and/or redistribute the software under the terms of the
 
9
** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
 
10
** URL: "http://www.cecill.info".
 
11
** 
 
12
** As a counterpart to the access to the source code and rights to copy,
 
13
** modify and redistribute granted by the license, users are provided
 
14
** only with a limited warranty and the software's author, the holder of
 
15
** the economic rights, and the successive licensors have only limited
 
16
** liability.
 
17
** 
 
18
** In this respect, the user's attention is drawn to the risks associated
 
19
** with loading, using, modifying and/or developing or reproducing the
 
20
** software by the user in light of its specific status of free software,
 
21
** that may mean that it is complicated to manipulate, and that also
 
22
** therefore means that it is reserved for developers and experienced
 
23
** professionals having in-depth computer knowledge. Users are therefore
 
24
** encouraged to load and test the software's suitability as regards
 
25
** their requirements in conditions enabling the security of their
 
26
** systems and/or data to be ensured and, more generally, to use and
 
27
** operate it in the same conditions as regards security.
 
28
** 
 
29
** The fact that you are presently reading this means that you have had
 
30
** knowledge of the CeCILL-C license and that you accept its terms.
 
31
*/
 
32
/************************************************************/
 
33
/**                                                        **/
 
34
/**   NAME       : mesh_check.c                            **/
 
35
/**                                                        **/
 
36
/**   AUTHOR     : Francois PELLEGRINI                     **/
 
37
/**                                                        **/
 
38
/**   FUNCTION   : This module handles the source mesh     **/
 
39
/**                functions.                              **/
 
40
/**                                                        **/
 
41
/**   DATES      : # Version 4.0  : from : 29 dec 2001     **/
 
42
/**                                 to     11 may 2004     **/
 
43
/**                                                        **/
 
44
/************************************************************/
 
45
 
 
46
/*
 
47
**  The defines and includes.
 
48
*/
 
49
 
 
50
#define MESH
 
51
 
 
52
#include "module.h"
 
53
#include "common.h"
 
54
#include "graph.h"
 
55
#include "mesh.h"
 
56
 
 
57
/****************************************/
 
58
/*                                      */
 
59
/* These routines handle source meshes. */
 
60
/*                                      */
 
61
/****************************************/
 
62
 
 
63
/* This routine checks the consistency
 
64
** of the given mesh.
 
65
** It returns:
 
66
** - 0   : if mesh data are consistent.
 
67
** - !0  : on error.
 
68
*/
 
69
 
 
70
int
 
71
meshCheck (
 
72
const Mesh * const          meshptr)
 
73
{
 
74
  Gnum                vertnnd;                    /* Maximum vertex index                */
 
75
  Gnum                vertnum;                    /* Number of current vertex            */
 
76
  Gnum                veisnbr;                    /* Number of isolated element vertices */
 
77
  Gnum                velosum;                    /* Vertex element load sum             */
 
78
  Gnum                vnlosum;                    /* Vertex node load sum                */
 
79
  Gnum                degrmax;                    /* Maximum degree                      */
 
80
 
 
81
  if ((meshptr->velmbas > meshptr->velmnnd) ||
 
82
      (meshptr->vnodbas > meshptr->vnodnnd) ||
 
83
      ((meshptr->velmnnd != meshptr->vnodbas) &&
 
84
       (meshptr->vnodnnd != meshptr->velmbas))) {
 
85
    errorPrint ("meshCheck: invalid node and element numbers");
 
86
    return     (1);
 
87
  }
 
88
 
 
89
  vertnnd = meshptr->velmnbr + meshptr->vnodnbr + meshptr->baseval;
 
90
  degrmax = 0;
 
91
  veisnbr = 0;
 
92
  for (vertnum = meshptr->velmbas; vertnum < meshptr->velmnnd; vertnum ++) { /* For all element vertices */
 
93
    Gnum                degrval;
 
94
    Gnum                edgenum;
 
95
 
 
96
    if ((meshptr->verttax[vertnum] < meshptr->baseval)          ||
 
97
        (meshptr->vendtax[vertnum] < meshptr->verttax[vertnum])) {
 
98
      errorPrint ("meshCheck: invalid vertex arrays (1)");
 
99
      return     (1);
 
100
    }
 
101
 
 
102
    degrval = meshptr->vendtax[vertnum] - meshptr->verttax[vertnum];
 
103
    if (degrval > degrmax)
 
104
      degrmax = degrval;
 
105
    else if (degrval == 0)
 
106
      veisnbr ++;
 
107
 
 
108
    for (edgenum = meshptr->verttax[vertnum]; edgenum < meshptr->vendtax[vertnum]; edgenum ++) {
 
109
      Gnum                vertend;                /* Number of end vertex      */
 
110
      Gnum                edgeend;                /* Number of end vertex edge */
 
111
 
 
112
      vertend = meshptr->edgetax[edgenum];
 
113
 
 
114
      if ((vertend < meshptr->baseval) || (vertend >= vertnnd)) { /* If invalid edge end */
 
115
        errorPrint ("meshCheck: invalid edge array (1)");
 
116
        return     (1);
 
117
      }
 
118
      if ((vertend >= meshptr->velmbas) &&
 
119
          (vertend <  meshptr->velmnnd)) {
 
120
        errorPrint ("meshCheck: element vertices must not be connected together");
 
121
        return     (1);
 
122
      }
 
123
 
 
124
      for (edgeend = meshptr->verttax[vertend];   /* Search for matching arc */
 
125
           (edgeend < meshptr->vendtax[vertend]) && (meshptr->edgetax[edgeend] != vertnum);
 
126
           edgeend ++) ;
 
127
      if (edgeend >= meshptr->vendtax[vertend]) {
 
128
        errorPrint ("meshCheck: arc data do not match (1)");
 
129
        return     (1);
 
130
      }
 
131
      for (edgeend ++;                            /* Search for duplicate arcs */
 
132
           (edgeend < meshptr->vendtax[vertend]) && (meshptr->edgetax[edgeend] != vertnum);
 
133
           edgeend ++) ;
 
134
      if (edgeend < meshptr->vendtax[vertend]) {
 
135
        errorPrint ("meshCheck: duplicate arc (1)");
 
136
        return     (1);
 
137
      }
 
138
    }
 
139
  }
 
140
  if (veisnbr != meshptr->veisnbr) {
 
141
    errorPrint ("meshCheck: invalid number of isolated element vertices (1)");
 
142
    return     (1);
 
143
  }
 
144
 
 
145
  for (vertnum = meshptr->vnodbas; vertnum < meshptr->vnodnnd; vertnum ++) { /* For all node vertices */
 
146
    Gnum                edgenum;
 
147
 
 
148
    if ((meshptr->verttax[vertnum] < meshptr->baseval)          ||
 
149
        (meshptr->vendtax[vertnum] < meshptr->verttax[vertnum])) {
 
150
      errorPrint ("meshCheck: invalid vertex arrays (2)");
 
151
      return     (1);
 
152
    }
 
153
    if ((meshptr->vendtax[vertnum] - meshptr->verttax[vertnum]) > degrmax)
 
154
      degrmax = meshptr->vendtax[vertnum] - meshptr->verttax[vertnum];
 
155
 
 
156
    for (edgenum = meshptr->verttax[vertnum]; edgenum < meshptr->vendtax[vertnum]; edgenum ++) {
 
157
      Gnum                vertend;                /* Number of end vertex      */
 
158
      Gnum                edgeend;                /* Number of end vertex edge */
 
159
 
 
160
      vertend = meshptr->edgetax[edgenum];
 
161
 
 
162
      if ((vertend < meshptr->baseval) || (vertend >= vertnnd)) { /* If invalid edge end */
 
163
        errorPrint ("meshCheck: invalid edge array (2)");
 
164
        return     (1);
 
165
      }
 
166
      if ((vertend >= meshptr->vnodbas) &&
 
167
          (vertend <  meshptr->vnodnnd)) {
 
168
        errorPrint ("meshCheck: node vertices must not be connected together");
 
169
        return     (1);
 
170
      }
 
171
 
 
172
      for (edgeend = meshptr->verttax[vertend];   /* Search for matching arc */
 
173
           (edgeend < meshptr->vendtax[vertend]) && (meshptr->edgetax[edgeend] != vertnum);
 
174
           edgeend ++) ;
 
175
      if (edgeend >= meshptr->vendtax[vertend]) {
 
176
        errorPrint ("meshCheck: arc data do not match (2)");
 
177
        return     (1);
 
178
      }
 
179
      for (edgeend ++;                            /* Search for duplicate arcs */
 
180
           (edgeend < meshptr->vendtax[vertend]) && (meshptr->edgetax[edgeend] != vertnum);
 
181
           edgeend ++) ;
 
182
      if (edgeend < meshptr->vendtax[vertend]) {
 
183
        errorPrint ("meshCheck: duplicate arc (2)");
 
184
        return     (1);
 
185
      }
 
186
    }
 
187
  }
 
188
 
 
189
  if (meshptr->velotax == NULL)                   /* Recompute node vertex load sum */
 
190
    velosum = meshptr->velmnnd - meshptr->velmbas;
 
191
  else {
 
192
    for (vertnum = meshptr->velmbas, velosum = 0;
 
193
         vertnum < meshptr->velmnnd; vertnum ++) {
 
194
      if (meshptr->velotax[vertnum] < 1) {
 
195
        errorPrint ("meshCheck: invalid element vertex load");
 
196
        return     (1);
 
197
      }
 
198
      velosum += meshptr->velotax[vertnum];
 
199
    }
 
200
  }
 
201
  if (velosum != meshptr->velosum) {
 
202
    errorPrint ("meshCheck: invalid element vertex load sum");
 
203
    return     (1);
 
204
  }
 
205
 
 
206
  if (meshptr->vnlotax == NULL)                   /* Recompute node vertex load sum */
 
207
    vnlosum = meshptr->vnodnnd - meshptr->vnodbas;
 
208
  else {
 
209
    for (vertnum = meshptr->vnodbas, vnlosum = 0;
 
210
         vertnum < meshptr->vnodnnd; vertnum ++) {
 
211
      if (meshptr->vnlotax[vertnum] < 1) {
 
212
        errorPrint ("meshCheck: invalid node vertex load");
 
213
        return     (1);
 
214
      }
 
215
      vnlosum += meshptr->vnlotax[vertnum];
 
216
    }
 
217
  }
 
218
  if (vnlosum != meshptr->vnlosum) {
 
219
    errorPrint ("meshCheck: invalid node vertex load sum");
 
220
    return     (1);
 
221
  }
 
222
 
 
223
  if (meshptr->degrmax < degrmax) {
 
224
    errorPrint ("meshCheck: invalid maximum degree");
 
225
    return     (1);
 
226
  }
 
227
 
 
228
  return (0);
 
229
}