This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mk_dm.c
514 lines (433 loc) · 11.9 KB
/
mk_dm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/************************************************************************ *
* Goma - Multiphysics finite element software *
* Sandia National Laboratories *
* *
* Copyright (c) 2014 Sandia Corporation. *
* *
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, *
* the U.S. Government retains certain rights in this software. *
* *
* This software is distributed under the GNU General Public License. *
\************************************************************************/
/* make_goma_dofmap.c -- make goma dofmap
*
* Given some rudimentary descriptions of the problem and the mesh, concoct the
*
* Notes:
* [1] Make up a goma-like degree of freedom map.
*
* [2] Every dof must be associated with a node.
*
* [3] Nodes are traversed in global order.
*
* [4] Degrees of freedom begin with the variable with the
* lowest integer identifier and move upward.
*
* [5] Variables with multiple degrees of freedom at a
* node are lumped together.
*
* [6] Since there are likely to be only a handful of different
* kinds of nodes, we employ a catalog of node types. Each
* node type has different numbers and kinds of variables
* associated with it.
*
* Created: 1997/05/08 10:48 MDT [email protected]
*
* Revised:
*/
#define _MK_DM_C
#include <config.h>
#include <stdio.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif
#include "map_names.h"
#include "std.h"
#include "aalloc.h"
#include "eh.h"
#include "exo_struct.h"
#include "brkfix_types.h"
#include "nodesc.h"
#include "mk_dm.h"
/*
* Function prototypes for functions defined in other files...
*/
extern int in_list /* utils.c */
PROTO((int , /* val - what integer value to seek */
int *, /* start - where to begin looking */
int )); /* length - how far to search from start */
extern int fence_post /* utils.c */
PROTO((int , /* val - integer whose category we seek */
int *, /* array - where to look */
int )); /* length - how far to search in array */
/*
* Function prototypes for functions defined in this file...
*/
void
make_goma_dofmap(Exo_DB *x,
Bevm ***mult,
int ***evd,
int ***Lucky,
int *num_basic_eqnvars,
int *node_kind,
int *node_dof0,
Node_Description **pnd,
int *nkn)
{
int current_dof;
int num_kinds_nodes;
int d;
int e;
int eb_index;
int *ev_ids;
int evid;
int **ev_wts;
int found_matching_node_type;
int i;
int index_min;
int j;
int l;
int loc;
int look;
int m;
int m2;
int matching_node_type_index = 0;
int min;
int n;
/* int ne;*/
int neb;
int nn;
/* int nns;*/
/* int nss;*/
int num_abevs; /* number of active basic eqnvars this node */
int where;
int *ep = x->elem_node_pntr;
int *nl = x->elem_node_list;
int *ebl = x->eb_ptr;
int *np = x->node_elem_pntr;
int *el = x->node_elem_list;
char err_msg[MAX_CHAR_ERR_MSG];
Node_Description *tnd; /* temporary pointer */
Spfrtn sr=0;
/*
* Convenience variables...
*/
/*
* ne = x->num_elems;
*/
nn = x->num_nodes;
neb = x->num_elem_blocks;
/*
* nns = x->num_node_sets;
* nss = x->num_side_sets;
*/
num_kinds_nodes = 0;
/*
* Round One; Determine how many total degrees of freedom there are in the
* problem. For each node, examine every surrounding element,
* determining how many degrees of freedom contribute from
* that element's corresponding local node number.
*/
/*
* Local information for the node under scrutiny. How many distinct
* basic eqn/vars are active? What are their names? For each active
* variable, what are the weights associated with the multipliers?
*/
ev_ids = (int *) smalloc(MAX_EQNVARS * SZ_INT);
INIT_IVEC(ev_ids, MAX_EQNVARS, UNDEFINED_EQNVARID);
ev_wts = (int **) smalloc(MAX_EQNVARS * sizeof(int *));
ev_wts[0] = (int *) smalloc(MAX_EQNVARS * 3 * sizeof(int));
for ( i=1; i<MAX_EQNVARS; i++)
{
ev_wts[i] = ev_wts[i-1] + 3;
}
for ( i=0; i<MAX_EQNVARS; i++)
{
for ( j=0; j<3; j++)
{
ev_wts[i][j] = 0;
}
}
/*
* Main loop over each node in the entire mesh.
*/
current_dof = 0;
node_dof0[0] = 0; /* beginning of first nodes dof list */
for ( n=0; n<nn; n++)
{
#ifdef DEBUG
fprintf(stderr, "\n\nglobal node [%d]\n\n", n);
#endif
/*
* Clean out lists of valid variables and their dof contributions
* at the current node. These little arrays are catalogs of the
* active variables at the current node that list their IDs as well as
* their 3 different kinds of weights.
*/
for ( i=0; i<MAX_EQNVARS; i++)
{
ev_ids[i] = UNDEFINED_EQNVARID;
for ( j=0; j<3; j++)
{
ev_wts[i][j] = 0;
}
}
/*
* Initialize counter of number of active basic eqnvars at this node.
*/
num_abevs = 0;
/*
* Loop over each element that contains this node.
*/
for (l=np[n]; l<np[n+1]; l++)
{
e = el[l];
/*
* Which *local* node number in the element corresponds to the node
* whose global name is "n"?
*/
loc = 0;
while ( nl[ep[e]+loc] != n && (ep[e]+loc) < ep[e+1] )
{
loc++;
}
#ifdef DEBUG
fprintf(stderr, "node (%d) is aka elem (%d), local node (%d)\n",
n+1, e+1, loc+1);
#endif
if ( ep[e]+loc >= ep[e+1] )
{
sr = sprintf(err_msg,
"Difficulty finding local node in n=%d, e=%d",
n, e);
EH(-1, err_msg);
}
eb_index = fence_post(e, ebl, neb+1);
/*
* For this element, in this element block, at this local node,
* what kinds of variables contribute how much to the dof load?
*/
/*
* Look through catalog variables. If the variables at this
* local node in this element are already in the catalog, fine.
* If they are not in the catalog, add them.
*/
for ( j=0; j<num_basic_eqnvars[eb_index]; j++)
{
if ( Lucky[eb_index][loc][j] != 0 )
{
/*
* Then, in this element block at this local node, the
* eqnvar with index j is active!
*/
evid = mult[eb_index][j]->eqnvar_id;
where = in_list(evid, ev_ids, MAX_EQNVARS);
}
else
{
/*
* The eqnvar with index j is not active at this local
* node.
*/
evid = UNDEFINED_EQNVARID;
where = -1;
}
if ( where == -1 && evid != UNDEFINED_EQNVARID )
{
ev_ids[num_abevs] = evid;
ev_wts[num_abevs][0] = mult[eb_index][j]->vect_mult;
ev_wts[num_abevs][1] = mult[eb_index][j]->conc_mult;
ev_wts[num_abevs][2] = mult[eb_index][j]->ndof_mult;
num_abevs++;
#ifdef DEBUG
fprintf(stderr,
"\tevid not in this nodes catalog. adding...\n");
fprintf(stderr,
"\t\teqnvar ID, wts = %d ( %d %d %d )\n", evid,
mult[eb_index][j]->vect_mult,
mult[eb_index][j]->conc_mult,
mult[eb_index][j]->ndof_mult);
#endif
}
}
}
/*
* Now that each element has been researched for the appropriate
* contribution, re-order the ev_ids so that they appear in ascending
* numerical order (sort weights, too.)
*/
if ( num_abevs > MAX_EQNVARS )
{
EH(-1, "Too many active eqnvars this node");
}
for ( m=0; m<num_abevs; m++)
{
index_min = m;
min = ev_ids[m];
for ( m2=m; m2<num_abevs; m2++)
{
if ( ev_ids[m2] < min )
{
min = ev_ids[m2];
index_min = m2;
}
}
if ( index_min != m )
{
ISWAP(ev_ids[m], ev_ids[index_min]);
for ( j=0; j<3; j++ )
{
ISWAP(ev_wts[m][j], ev_wts[index_min][j]);
}
}
}
#ifdef DEBUG
fprintf(stderr, "Sorted list of basic eqnvars at node (%d)\n", n+1);
for ( i=0; i<num_abevs; i++)
{
fprintf(stderr, "eqnvar[%d] ID=%d wts = %d %d %d\n",
i, ev_ids[i], ev_wts[i][0], ev_wts[i][1], ev_wts[i][2]);
}
#endif
/*
* A complete sorted list of the active eqnvars for this node has been
* obtained. Now,
*
* Look through the catalog of existing Prototype Node Descriptions
* to see if this one is like an earlier one. If it is, then good.
* If it's not, then make up a new Prototype Node Description like
* this one!
*/
found_matching_node_type = FALSE;
d = 0;
#ifdef DEBUG
fprintf(stderr, "\nCurrently, num_kinds_nodes = %d\n",
num_kinds_nodes);
#endif
while ( !found_matching_node_type && d<num_kinds_nodes )
{
#ifdef DEBUG
fprintf(stderr, "while checking for equiv old nodedescs\n");
#endif
if ( pnd[d]->num_basic_eqnvars == num_abevs ) /* maybe... */
{
look=0;
while ( ( pnd[d]->eqnvar_ids[look] == ev_ids[look] ) &&
( look < num_abevs ) )
{
look++;
}
if ( look == num_abevs )
{
found_matching_node_type = TRUE;
matching_node_type_index = d;
}
}
d++;
}
if ( found_matching_node_type )
{
/*
* Great, use an old node description for *this* node description!
*/
node_kind[n] = matching_node_type_index;
tnd = pnd[matching_node_type_index];
#ifdef DEBUG
fprintf(stderr, "Hey, old description %d fits this node!\n",
matching_node_type_index);
#endif
}
else
{
/*
* Hmmm. Need to allocate and setup a new node description.
*/
node_kind[n] = num_kinds_nodes;
#ifdef DEBUG
fprintf(stderr, "\ncreating new node description %d\n",
num_kinds_nodes);
#endif
tnd = pnd[num_kinds_nodes];
/*
* Initialize structure before tailoring it to describe
* this new node type.
*/
tnd->num_basic_eqnvars = -1;
for ( i=0; i<MAX_EQNVARS; i++)
{
tnd->eqnvar_ids[i] = UNDEFINED_EQNVARID;
tnd->eqnvar_wts[i][0] = 0;
tnd->eqnvar_wts[i][1] = 0;
tnd->eqnvar_wts[i][2] = 0;
}
tnd->num_basic_eqnvars = num_abevs;
for ( i=0; i<num_abevs; i++ )
{
tnd->eqnvar_ids[i] = ev_ids[i];
for ( j=0; j<3; j++ )
{
tnd->eqnvar_wts[i][j] = ev_wts[i][j];
}
}
num_kinds_nodes++; /* there is a new one now! */
#ifdef DEBUG
fprintf(stderr, "\n\tNew node description:\n" );
fprintf(stderr, "\t\ttnd->num_basic_eqnvars = %d\n",
tnd->num_basic_eqnvars);
fprintf(stderr, "\t\ttnd->eqnvar_ids[] = ");
for ( i=0; i<num_abevs; i++)
{
fprintf(stderr, "%5d", tnd->eqnvar_ids[i]);
}
fprintf(stderr, "\n");
fprintf(stderr, "\t\ttnd->eqnvar_wts[][] = ");
for ( i=0; i<num_abevs; i++)
{
fprintf(stderr, "\t\t\t%d wt=(", tnd->eqnvar_ids[i]);
for ( j=0; j<3; j++ )
{
fprintf(stderr, "%d", tnd->eqnvar_wts[i][j]);
}
fprintf(stderr, ")\n");
}
#endif
if ( num_kinds_nodes >= MAX_NODE_KINDS )
{
sr = sprintf(err_msg,
"@ node (%d) num_kinds_nodes >= MAX_NODE_KINDS",
n+1);
EH(-1, err_msg);
}
}
/*
* With this node's repertoire of basic eqnvars established, we can
* determine the initial dof of the next node.
*/
for ( i=0; i<tnd->num_basic_eqnvars; i++)
{
current_dof += ( tnd->eqnvar_wts[i][0] *
tnd->eqnvar_wts[i][1] *
tnd->eqnvar_wts[i][2] );
}
node_dof0[n+1] = current_dof;
}
#ifdef DEBUG
fprintf(stderr, "Number of node kinds = %d\n", num_kinds_nodes);
fprintf(stderr, "Dump of node_dof0 pointers:\n");
for ( i=0; i<nn; i++)
{
fprintf(stderr, "node (%d) dofs: %d <= dof < %d\n", i+1, node_dof0[i],
node_dof0[i+1]);
}
for ( i=0; i<nn; i++)
{
fprintf(stderr, "node (%d) is kind %d\n", i+1, node_kind[i]);
}
#endif
*nkn = num_kinds_nodes;
free(ev_ids);
free(ev_wts[0]);
free(ev_wts);
if ( sr < 0 ) exit(2);
return;
}