MacroReader.cc 61.9 KB
Newer Older
1
2
3
4
5
6
#include "MacroReader.h"
#include "MacroWriter.h"
#include "MacroElement.h"
#include "Boundary.h"
#include "FiniteElemSpace.h"
#include "Mesh.h"
7
#include <string.h>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "FixVec.h"
#include "FixVecConvert.h"
#include "PeriodicMap.h"
#include "ElInfo.h"
#include "Parameters.h"
#include "DOFIterator.h"
#include "SurfaceRegion_ED.h"
#include "ElementRegion_ED.h"
#include "LeafData.h"
#include "VertexVector.h"
#include <map>
#include <iostream>
#include <fstream>

namespace AMDiS {

  MacroInfo* MacroReader::readMacro(const char *filename, 
				    Mesh* mesh,
				    const char *periodicFile,
				    int check)
  {
    FUNCNAME("Mesh::readMacro()");

    TEST_EXIT(filename)("no file specified; filename NULL pointer\n");
32
   
Thomas Witkowski's avatar
Thomas Witkowski committed
33
    MacroInfo *macroInfo = new MacroInfo();
34
35
    macroInfo->readAMDiSMacro(filename, mesh);

36
    std::deque<MacroElement*>::iterator mel = macroInfo->mel.begin();
37
38
39
    int **melVertex = macroInfo->mel_vertex;
    WorldVector<double> *coords = macroInfo->coords;
    DegreeOfFreedom **dof = macroInfo->dof;
40
41

    // === read periodic data =================================
42
    if (periodicFile && (strcmp(periodicFile, "") != 0)) {
43
44
45
46
47
48
49
50
51
      WARNING("periodic boundaries may lead to errors in small meshes if element neighbours not set\n");
    
      FILE *file = fopen(periodicFile, "r");
      TEST_EXIT(file)("can't open file %s\n", periodicFile);

      int n;
      int dim = mesh->getDim();

      int el1, el2;
Thomas Witkowski's avatar
Thomas Witkowski committed
52
53
      int *verticesEl1 = new int[dim];
      int *verticesEl2 = new int[dim];
54
      int mode = -1; // 0: drop dofs, 1: associate dofs
55
      int result;
56
57
58
59
60
61
62
63
      BoundaryType boundaryType;

      fscanf(file, "%*s %d", &n);

      fscanf(file, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s");

      PeriodicMap periodicMap;
    
64
      for (int i = 0; i < n; i++) {
65
66
	std::map<int, int> vertexMapEl1;
	std::map<int, int> vertexMapEl2;
67

68
69
	result = fscanf(file, "%d", &mode);
	TEST_EXIT(result == 1)("mode?\n");
70
      
71
72
	result = fscanf(file, "%d", &boundaryType);
	TEST_EXIT(result == 1)("boundaryType?\n");
73
      
74
75
76
	result = fscanf(file, "%d", &el1);
	TEST_EXIT(result == 1)("el1?\n");

77
	for (int j = 0; j < dim; j++) {
78
79
	  result = fscanf(file, "%d", &verticesEl1[j]);
	  TEST_EXIT(result == 1)("vertEl1[%d]\n", j);
80
	}
81
82
	result = fscanf(file, "%d", &el2);
	TEST_EXIT(result == 1)("el2?\n");
83
	for (int j = 0; j < dim; j++) {
84
85
	  result = fscanf(file, "%d", &verticesEl2[j]);
	  TEST_EXIT(result == 1)("vertEl2[%d]\n", j);
86
	}
87
	for (int j = 0; j < dim; j++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
88
	  if (mode == 0)
89
	    periodicMap.setEntry(melVertex[el1][verticesEl1[j]], 
Thomas Witkowski's avatar
Thomas Witkowski committed
90
				 melVertex[el2][verticesEl2[j]]);	  
91
92
93
94
95
96
	  vertexMapEl1[verticesEl1[j]] = verticesEl2[j];
	  vertexMapEl2[verticesEl2[j]] = verticesEl1[j];
	}

	// calculate sides of periodic vertices
	int sideEl1 = 0, sideEl2 = 0;
97
	if (dim == 1) {
98
99
100
	  sideEl1 = verticesEl1[0];
	  sideEl2 = verticesEl2[0];
	} else {
101
	  for (int j = 0; j < dim + 1; j++) {
102
103
104
	    sideEl1 += j;
	    sideEl2 += j;
	  }
105
	  for (int j = 0; j < dim; j++) {
106
107
108
109
110
111
	    sideEl1 -= verticesEl1[j];
	    sideEl2 -= verticesEl2[j];
	  }
	}
	
	// create periodic info
112
113
	DimVec<WorldVector<double> > periodicCoordsEl1(dim - 1, NO_INIT);
	DimVec<WorldVector<double> > periodicCoordsEl2(dim - 1, NO_INIT);
114

115
116
	Element *element1 = const_cast<Element*>((*(mel + el1))->getElement());
	Element *element2 = const_cast<Element*>((*(mel + el2))->getElement());
117
118
      
	// for all vertices of this side
119
	for (int j = 0; j < dim; j++) {
120
121
122
123
124
125
126
127
128
129
130
131
132
133
	  periodicCoordsEl1[element1->getPositionOfVertex(sideEl1, verticesEl1[j])] = 
	    coords[melVertex[el2][vertexMapEl1[verticesEl1[j]]]];
	  periodicCoordsEl2[element2->getPositionOfVertex(sideEl2, verticesEl2[j])] =
	    coords[melVertex[el1][vertexMapEl2[verticesEl2[j]]]];
	}
      
	// decorate leaf data
	ElementData *ld1 = element1->getElementData();
	ElementData *ld2 = element2->getElementData();

	LeafDataPeriodic *ldp1 = dynamic_cast<LeafDataPeriodic*>(ld1->getElementData(PERIODIC));
	LeafDataPeriodic *ldp2 = dynamic_cast<LeafDataPeriodic*>(ld2->getElementData(PERIODIC));

	if (!ldp1) {
Thomas Witkowski's avatar
Thomas Witkowski committed
134
	  ldp1 = new LeafDataPeriodic(ld1);
135
136
137
138
	  element1->setElementData(ldp1);
	}

	if (!ldp2) {
Thomas Witkowski's avatar
Thomas Witkowski committed
139
	  ldp2 = new LeafDataPeriodic(ld2);
140
141
142
	  element2->setElementData(ldp2);
	}

143
144
	ldp1->addPeriodicInfo(mode, boundaryType, sideEl1, &periodicCoordsEl1);
	ldp2->addPeriodicInfo(mode, boundaryType, sideEl2, &periodicCoordsEl2);
145
146
147

	if (mode != 0) {
	  VertexVector *associated = mesh->periodicAssociations[boundaryType];
148

149
	  if (!associated) {
Thomas Witkowski's avatar
Thomas Witkowski committed
150
	    associated = new VertexVector(mesh->getVertexAdmin(), "vertex vector");
151
152
	    mesh->periodicAssociations[boundaryType] = associated;
	    VertexVector::Iterator it(associated, ALL_DOFS);
153
	    for (it.reset2(); !it.end(); ++it)
154
155
156
	      *it = it.getDOFIndex();
	  }

157
	  for (int j = 0; j < dim; j++) {
158
159
160
161
162
163
164
165
	    (*associated)[melVertex[el1][verticesEl1[j]]] =
	      melVertex[el2][vertexMapEl1[verticesEl1[j]]];
	    (*associated)[melVertex[el2][verticesEl2[j]]] =
	      melVertex[el1][vertexMapEl2[verticesEl2[j]]];
	  }
	}
      }    

Thomas Witkowski's avatar
Thomas Witkowski committed
166
167
      delete [] verticesEl1;
      delete [] verticesEl2;
168
169

      // change periodic vertex dofs
170
      for (int i = 0; i < mesh->getNumberOfVertices(); i++) {
171
172
173
174
	if (periodicMap.getEntry(i) != -1) {
	  mesh->freeDOF(dof[i], VERTEX);
	  dof[i] = dof[periodicMap.getEntry(i)];

175
176
	  std::map<BoundaryType, VertexVector*>::iterator assoc;
	  std::map<BoundaryType, VertexVector*>::iterator assocEnd =
177
	    mesh->periodicAssociations.end();
178

179
	  for (assoc = mesh->periodicAssociations.begin(); assoc != assocEnd; ++assoc) {
180
181
182
183
184

	    DegreeOfFreedom a = (*(assoc->second))[i];
	    if (a != i) {
	      (*(assoc->second))[i] = i;
	      (*(assoc->second))[a] = periodicMap.getEntry(i);
185
	    }
186
187
	  }

188
189
190
	}
      }

191
192
      std::map<BoundaryType, VertexVector*>::iterator assoc;
      std::map<BoundaryType, VertexVector*>::iterator assocEnd =
193
	mesh->periodicAssociations.end();
194
      for (assoc = mesh->periodicAssociations.begin(); assoc != assocEnd; ++assoc) {
Thomas Witkowski's avatar
Thomas Witkowski committed
195
	for (int i = 0; i < mesh->getNumberOfVertices(); i++)
196
197
	  if (i != (*(assoc->second))[i])
	    MSG("association %d: vertex %d -> vertex %d\n", 
Thomas Witkowski's avatar
Thomas Witkowski committed
198
		assoc->first, i, (*(assoc->second))[i]);	
199
200
      }

201
202
203
204
      for (int i = 0; i < mesh->getNumberOfVertices(); i++)
	if (periodicMap.getEntry(i) != -1)
	  MSG("identification : vertex %d is now vertex %d\n", 
	      i, periodicMap.getEntry(i));
205
    }
206

207
208
    // =========================================================

209
210
211
    for (int i = 0; i < mesh->getNumberOfMacros(); i++) {
      for (int k = 0; k < mesh->getGeo(VERTEX); k++) {
	(*(mel + i))->setCoord(k, coords[melVertex[i][k]]);
212

213
	const_cast<Element*>((*(mel + i))->getElement())->
214
	  setDOF(k, dof[melVertex[i][k]]);
215
      }
216
    }
217

218
219
220
    if (!macroInfo->neigh_set) {
      TEST_EXIT(!periodicFile)
	("periodic boundary condition => element neighbours must be set\n");
221
      computeNeighbours(mesh);
222
    } else {
223
224
225
      /****************************************************************************/
      /* fill MEL oppVertex values when reading neighbour information form file  */
      /****************************************************************************/
226

227
228
229
230
231
      for (int i = 0; i < mesh->getNumberOfMacros(); i++) {
	for (int k = 0; k < mesh->getGeo(NEIGH); k++) {
	  MacroElement *neigh = const_cast<MacroElement*>(mel[i]->getNeighbour(k));

	  if (neigh) {
232
233
	    int j = 0;
	    for (; j < mesh->getGeo(NEIGH); j++)
234
235
	      if (neigh->getNeighbour(j) == *(mel + i))  
		break;
236
	
237
238
239
240
241
	    TEST_EXIT(j < mesh->getGeo(NEIGH))("el %d no neighbour of neighbour %d\n", 
					       mel[i]->getIndex(), neigh->getIndex());
	    mel[i]->setOppVertex(k, j);
	  } else {
	    mel[i]->setOppVertex(k, -1);
242
	  }
243
	}
244
      }
245
    }
246
247
248
249
250

    if (!macroInfo->bound_set) {
      macroInfo->dirichletBoundary();
    }
  
251
    if (mesh->getDim() > 1)
252
253
254
255
256
257
      boundaryDOFs(mesh);

    // initial boundary projections
    int numFaces = mesh->getGeo(FACE);
    int dim = mesh->getDim();
    mel = mesh->firstMacroElement();
258
    for (int i = 0; i < mesh->getNumberOfLeaves(); i++) {
259
260
      MacroElement *macroEl = *(mel+i);
      Projection *projector = macroEl->getProjection(0);
261
      if (projector && projector->getType() == VOLUME_PROJECTION) {
Thomas Witkowski's avatar
Thomas Witkowski committed
262
263
	for (int j = 0; j <= dim; j++)
	  projector->project(macroEl->getCoord(j));	
264
      } else {
265
	for (int j = 0; j < mesh->getGeo(EDGE); j++) {
266
	  projector = macroEl->getProjection(numFaces + j);
267
	  if (projector) {
268
269
270
271
272
273
274
275
276
277
278
279
	    int vertex0 = Global::getReferenceElement(dim)->getVertexOfEdge(j, 0);
	    int vertex1 = Global::getReferenceElement(dim)->getVertexOfEdge(j, 1);
	    projector->project(macroEl->getCoord(vertex0));
	    projector->project(macroEl->getCoord(vertex1));
	  }
	}
      }
    }

    macroInfo->fillBoundaryInfo(mesh);

    if (mesh->getNumberOfDOFs(CENTER)) {
280
      for (int i = 0; i < mesh->getNumberOfMacros(); i++)
281
	const_cast<Element*>(mel[i]->getElement())->
282
	  setDOF(mesh->getNode(CENTER), mesh->getDOF(CENTER));
283
284
285
286
287
288
    }

    /****************************************************************************/
    /* domain size                                                              */
    /****************************************************************************/

289
    WorldVector<double> x_min, x_max;
290

291
292
293
294
295
296
297
    for (int j = 0; j < Global::getGeo(WORLD); j++) {
      x_min[j] =  1.E30;
      x_max[j] = -1.E30;
    }

    for (int i = 0; i < mesh->getNumberOfVertices(); i++) {
      for (int j = 0; j < Global::getGeo(WORLD); j++) {
298
299
	x_min[j] = std::min(x_min[j], coords[i][j]);
	x_max[j] = std::max(x_max[j], coords[i][j]);
300
301
      }
    }
302

303
    for (int j = 0; j < Global::getGeo(WORLD); j++)
304
305
306
307
308
309
      mesh->setDiameter(j, x_max[j] - x_min[j]);

    if (check) {
      checkMesh(mesh);

      if (mesh->getDim() > 1) {
310
311
312
313
314
	char filenew[128];
	strncpy(filenew, filename, 128); 
	filenew[127] = 0;
	strncat(filenew, ".new", 128);   
	filenew[127] = 0;
315
316
317
318
	macroTest(mesh, filenew);
      }
    }

319
    return macroInfo;
320
321
322
323
324
325
326
327
  }

  /****************************************************************************/
  /*  fill macro info structure and some pointers in mesh ...                 */
  /****************************************************************************/

  void MacroInfo::fill(Mesh *pmesh, int ne, int nv)
  {
328
329
    FUNCNAME("MacroInfo::fill()");

330
331
    TEST_EXIT(pmesh)("no mesh\n");

332
    int dim = pmesh->getDim(); 
333
    mesh = pmesh;
334
335
336
337
338

    mesh->setNumberOfElements(ne);
    mesh->setNumberOfLeaves(ne);
    mesh->setNumberOfVertices(nv);

339
    for (int i = 0; i < ne; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
340
      MacroElement *newMacro = new MacroElement(mesh->getDim());
341
342
343
344
      mel.push_back(newMacro);
      mesh->addMacroElement(mel[i]);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
345
346
347
    dof = new DegreeOfFreedom*[nv];
    coords = new WorldVector<double>[nv];
    mel_vertex = new int*[ne];
348

Thomas Witkowski's avatar
Thomas Witkowski committed
349
350
    for (int i = 0; i < ne; i++)
      mel_vertex[i] = new int[mesh->getGeo(VERTEX)];
351

Thomas Witkowski's avatar
Thomas Witkowski committed
352
    for (int i = 0; i < nv; i++)
353
354
      dof[i] = mesh->getDOF(VERTEX);

355
    for (int i = 0; i < ne; i++) {
356
      mel[i]->element = mesh->createNewElement();
Thomas Witkowski's avatar
Thomas Witkowski committed
357
      mel[i]->index = i;
358

Thomas Witkowski's avatar
Thomas Witkowski committed
359
      if (dim == 3)
Thomas Witkowski's avatar
Thomas Witkowski committed
360
	mel[i]->elType = 0;
361
362
363
364
365
    }
    neigh_set = false;
    bound_set = false;
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
366
  void MacroInfo::clear()
367
368
  {
    for (int i = 0; i < mesh->getNumberOfMacros(); i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
369
      delete [] mel_vertex[i];
370

Thomas Witkowski's avatar
Thomas Witkowski committed
371
372
    delete [] mel_vertex;
    delete [] coords;
373
    coords = NULL;  
Thomas Witkowski's avatar
Thomas Witkowski committed
374
    delete [] dof;
375
    dof = NULL;
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

    mesh = NULL;
    neigh_set = false;
  }

  /****************************************************************************/
  /****************************************************************************/
  /*  tool for reading macro triangulations in ALBERT-format                  */
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  /*  read_indices()  reads dim+1 indices from  file  into  id[0-dim],        */
  /*    returns true if dim+1 inputs arguments could be read successfully by  */
  /*    fscanf(), else false                                                  */
  /****************************************************************************/

  int  MacroInfo::read_indices(FILE *file, DimVec<int> &id)
  {
    int dim = mesh->getDim();

Thomas Witkowski's avatar
Thomas Witkowski committed
397
    for (int i = 0; i <= dim; i++)
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
      if (fscanf(file, "%d", &id[i]) != 1)
	return(false);

    return(true);
  }

#define N_KEYS      14
#define N_MIN_KEYS  7
  static const char *keys[N_KEYS] = {
    "DIM",                   //  0 
    "DIM_OF_WORLD",          //  1
    "number of vertices",    //  2
    "number of elements",    //  3
    "vertex coordinates",    //  4
    "element vertices",      //  5
    "element boundaries",    //  6
    "element neighbours",    //  7
    "element type",          //  8
    "projections",           //  9
    "element region",        // 10
    "surface region",        // 11
    "mesh name",             // 12
    "time"                   // 13
  };

  static int get_key_no(const char *key)
  {
425
426
    for (int i = 0; i < N_KEYS; i++)
      if (!strcmp(keys[i], key))  
427
	return i;
428

429
    return -1;
430
431
432
433
434
435
  }

#include <ctype.h>

  static const char *read_key(const char *line)
  {
436
437
    static char key[100];
    char *k = key;
438
439

    while (isspace(*line)) 
440
      line++;
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
    while ((*k++ = *line++) != ':');
    *--k = '\0';
  
    return(const_cast<const char *>( key));
  }

  /****************************************************************************/
  /*  read_albert_macro():                                                    */
  /*    read macro triangulation from ascii file in ALBERT format             */
  /*    fills macro_info structure                                            */
  /*    called by read_macro(), fills missing information                     */
  /****************************************************************************/


  void MacroInfo::readAMDiSMacro(const char *filename, Mesh* mesh)
  {
457
458
459
460
461
    FUNCNAME("MacroInfo::readAMDiSMacro()");

    int dim;
    int dow, nv, ne, j, k;
    double dbl;
462
463
    char line[256];
    int line_no, n_keys, sort_key[N_KEYS], nv_key, ne_key;
464
    int key_def[N_KEYS] = {0,0,0,0,0,0,0,0,0,0,0,0};
465
466
467
468
469
470
471
    const char *key;
    DimVec<int> *ind = NULL;

    TEST_EXIT(filename)("no file specified; filename NULL pointer\n");
    TEST_EXIT(strlen(filename) < static_cast<unsigned int>(127))
      ("can only handle filenames up to 127 characters\n");

Thomas Witkowski's avatar
Thomas Witkowski committed
472
    FILE *file = fopen(filename, "r");
473
    TEST_EXIT(file)("cannot open file %s\n", filename);
474
475
476
477
478
479
480

    /****************************************************************************/
    /*  looking for all keys in the macro file ...                              */
    /****************************************************************************/

    line_no = n_keys = 0;
    while (fgets(line, 255, file)) {
481
      line_no++;
Thomas Witkowski's avatar
Thomas Witkowski committed
482
483
      if (!strchr(line, ':'))  
	continue;
484
485
486
487
488
489
490
491
492
      key = read_key(line);
      int i_key = get_key_no(key);
      TEST_EXIT(i_key >= 0)
	("macro file %s must not contain key %s on line %d\n",
	 filename, key, line_no);
      TEST_EXIT(!key_def[i_key])("key %s defined second time on line %d in file %s\n");

      sort_key[n_keys++] = i_key;
      key_def[i_key] = true;
493
494
    }
    fclose(file);
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512


    /*******************************************************************************/
    /*  Test, if there is data for every key and if all is defined in right order. */
    /*******************************************************************************/

    for (int i_key = 0; i_key < N_MIN_KEYS; i_key++) {
      for (j = 0; j < n_keys; j++)
	if (sort_key[j] == i_key)  break;
      TEST_EXIT(j < n_keys)("You do not have specified data for %s in %s\n",
			    keys[i_key], filename);

      for (j = 0; j < n_keys; j++)
	if (sort_key[j] == 2)  break;
      nv_key = j;
      for (j = 0; j < n_keys; j++)
	if (sort_key[j] == 3)  break;
      ne_key = j;
513
    
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
      switch (i_key) {
      case 0:
      case 1:
	TEST_EXIT(sort_key[i_key] < 2)
	  ("You have to specify DIM or mesh->getGeo(WORLD) before all other data\n");
	break;
      case 4: 
	TEST_EXIT(nv_key < i_key)
	  ("Before reading data for %s, you have to specify the %s in file\n",
	   keys[4], keys[2], filename);
	break;
      case 5: 
	TEST_EXIT(nv_key < i_key  &&  ne_key < i_key)
	  ("Before reading data for %s, you have to specify the %s and %s in file %s\n",
	   keys[5], keys[3], keys[2], filename);
      case 6:
      case 7:
      case 8:
	TEST_EXIT(ne_key < i_key)
	  ("Before reading data for %s, you have to specify the %s in file %s\n",
	   keys[i_key], keys[3], filename);
      }
536
537
    }

538
    for (int i_key = 0; i_key < N_KEYS; i_key++)
539
540
541
542
543
544
      key_def[i_key] = false;

    /****************************************************************************/
    /*  and now, reading data ...                                               */
    /****************************************************************************/
	
545
546
    file = fopen(filename, "r");
    TEST_EXIT(file)("cannot open file %s\n", filename);
547
548

    int result;
549

550
    for (int i_key = 0; i_key < n_keys; i_key++) {
551

552
553
554
555
556
557
      switch (sort_key[i_key]) {
	
      case 0:
	// line "DIM"
	result = fscanf(file, "%*s %d", &dim);
	TEST_EXIT(result == 1)("cannot read DIM correctly in file %s\n", filename);
558

559
	ind = new DimVec<int>(dim, NO_INIT);
560

561
562
	key_def[0] = true;
	break;
563

564
565
566
567
568
569
570
571
      case 1:
	// line "DIM_OF_WORLD"
	result = fscanf(file, "%*s %d", &dow);
	TEST_EXIT(result == 1)
	  ("cannot read Global::getGeo(WORLD) correctly in file %s\n", filename);
	TEST_EXIT(dow == Global::getGeo(WORLD))
	  ("dimension of world = %d != Global::getGeo(WORLD) = %d\n", 
	   dow, Global::getGeo(WORLD));
572

573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
	key_def[1] = true;
	break;

      case 2:
	// line "number of vertices"
	result = fscanf(file, "%*s %*s %*s %d", &nv);
	TEST_EXIT(result == 1)
	  ("cannot read number of vertices correctly in file %s\n", filename);
	TEST_EXIT(nv > 0)
	  ("number of vertices = %d must be bigger than 0\n", nv);

	key_def[2] = true;
	if (key_def[3])
	  fill(mesh, ne, nv);
	break;

      case 3:
	// line "number of elements"
	result = fscanf(file, "%*s %*s %*s %d", &ne);
	TEST_EXIT(result == 1)
	  ("cannot read number of elements correctly in file %s\n", filename);
	TEST_EXIT(ne > 0)
	  ("number of elements = %d must be bigger than 0\n", ne);

	key_def[3] = true;
	if (key_def[2])
	  fill(mesh, ne, nv);
	break;

      case 4:
	// block "vertex coordinates"
	fscanf(file, "%*s %*s");
	for (int i = 0; i < nv; i++) {
	  for (j = 0; j <Global::getGeo(WORLD) ; j++) {
	    result = fscanf(file, "%lf", &dbl);
608
	    TEST_EXIT(result == 1)
609
610
611
612
613
614
	      ("error while reading coordinates, check file %s\n", filename);
	    coords[i][j] = dbl;
	  }
	}
	key_def[4] = true;
	break;
615

616
617
618
      case 5:
	// block "element vertices"
	fscanf(file, "%*s %*s");
619

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
	/****************************************************************************/
	/* global number of vertices on a single element                            */
	/****************************************************************************/

	for (int i = 0; i < ne; i++) {
	  result = read_indices(file, *ind);
	  TEST_EXIT(result)
	    ("cannot read vertex indices of element %d in file %s\n",  i, filename);

	  for (k = 0; k < mesh->getGeo(VERTEX); k++)
	    mel_vertex[i][k] = (*ind)[k];
	}

	key_def[5] = true;
	break;

      case 6:
	// block "element boundaries"
	fscanf(file, "%*s %*s");

	/****************************************************************************/
	/* MEL boundary pointers                                                    */
	/****************************************************************************/
	for (int i = 0; i < ne; i++) {  
	  // boundary information of ith element 
645

646
647
648
649
650
651
652
653
654
655
656
	  result = read_indices(file, *ind);
	  TEST_EXIT(result)
	    ("cannot read boundary type of element %d in file %s\n", i, filename);

	  // fill boundary of macro-element
	  MacroReader::fillMelBoundary(mesh, 
				       mel[i], 
				       VecConv<int,NEIGH,PARTS>::convertVec((*ind), mesh));
	}

	this->fillBoundaryInfo(mesh);
657
                   
658
659
660
	bound_set = true;
	key_def[6] = true;
	break;
661

662
663
664
      case 7:
	// block "element neighbours"
	fscanf(file, "%*s %*s");
665

666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
	/****************************************************************************/
	/* fill MEL neighbour pointers:                                             */
	/*   if they are specified in the file: read them from file,                */
	/*   else init them by a call of fill_mel_neighbour()                       */
	/****************************************************************************/
	neigh_set = true;
	for (int i = 0; i < ne; i++) {
	  //  neighbour information about ith element

	  if (read_indices(file, *ind)) {
	    MacroReader::fillMelNeigh(mel[i], mel, 
				      VecConv<int,NEIGH,PARTS>::convertVec((*ind), 
									   mesh));
	  } else {
	    neigh_set = false; /* setting of neighbours fails :-( */
681
	    break;
682
683
	  }
	}
684

685
686
	key_def[7] = true;
	break;
687

688
689
690
691
692
693
      case 8:
	// block "element type"
	fscanf(file, "%*s %*s");
	/****************************************************************************/
	/* MEL elType                                                               */
	/****************************************************************************/
694

695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
	if (dim == 2 || dim == 1)
	  ERROR("there is no element type in 2d and 2d; ignoring data for elType\n");

	for (int i = 0; i < ne; i++) {
	  result = fscanf(file, "%d", &j);
	  TEST_EXIT(result == 1)
	    ("cannot read elType of element %d in file %s\n", i, filename);
	  if (dim == 3)
	    (mel)[i]->elType = j;
	}

	key_def[8] = true;
	break;

      case 9:
	// block "projections"
	{
	  fscanf(file, "%*s");

	  int numFaces = mesh->getGeo(FACE);
	  int numEdgesAtBoundary = 0;

	  for (k = 1; k < dim; k++)
	    numEdgesAtBoundary += k;

	  for (int i = 0; i < ne; i++) {
	    result = read_indices(file, *ind);
	    TEST_EXIT(result)
	      ("cannot read boundary projector of element %d in file %s\n", i, filename);
724
	
725
726
727
728
729
	    Projection *projector = Projection::getProjection((*ind)[0]);

	    if (projector && projector->getType() == VOLUME_PROJECTION) {
	      mel[i]->setProjection(0, projector);
	    } else { // boundary projection
730
	      for (j = 0; j < mesh->getGeo(NEIGH); j++) {
731
		projector = Projection::getProjection((*ind)[j]);
732
		if (projector) {
733
		  mel[i]->setProjection(j, projector);
734
735
		  if (dim > 2) {
		    for (k = 0; k < numEdgesAtBoundary; k++) {
736
737
		      int edgeNr = Global::getReferenceElement(dim)->getEdgeOfFace(j, k);
		      mel[i]->setProjection(numFaces + edgeNr, projector);
738
739
740
741
742
		    }
		  }
		}
	      }
	    }
743
744
745
746
	  }
	}
	key_def[9] = true;
	break;
747

748
749
750
751
752
753
      case 10:
	// block "element region"
	fscanf(file, "%*s %*s");
	/****************************************************************************/
	/* MEL regions                                                              */
	/****************************************************************************/
754

755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
	for (int i = 0; i < ne; i++) {
	  result = fscanf(file, "%d", &j);
	  TEST_EXIT(result == 1)
	    ("cannot read region of element %d in file %s\n", i, filename);
	  if (j >= 0) {
	    Element *el = mel[i]->getElement();
	    ElementRegion_ED *elementRegion = 
	      new ElementRegion_ED(el->getElementData());
	    elementRegion->setRegion(j);
	    el->setElementData(elementRegion);
	  }
	}
	key_def[10] = true;
	break;

      case 11:
	// block "surface region"
	fscanf(file, "%*s %*s");
	for (int i = 0; i < ne; i++) {
	  result = read_indices(file, *ind);
	  TEST_EXIT(result)
	    ("cannot read surface regions of element %d in file %s\n", i, filename);

	  Element *el = mel[i]->getElement();

	  for (j = 0; j < mesh->getGeo(NEIGH); j++) {
	    if ((*ind)[j] >= 0) {
	      SurfaceRegion_ED *surfaceRegion = 
		new SurfaceRegion_ED(el->getElementData());
	      surfaceRegion->setSide(j);
	      surfaceRegion->setRegion((*ind)[j]);
	      el->setElementData(surfaceRegion);
787
788
	    }
	  }
789
790
791
792
793
794
795
796
797
798
799
800
801
	}
	key_def[11] = true;
	break;

      case 12:
	// line "mesh name"
	fscanf(file, "%*s %*s %*s");
	break;

      case 13:
	// line "time"
	fscanf(file, "%*s %*s");
	break;
802
      }
803
    }
804

805
    if (ind)
Thomas Witkowski's avatar
Thomas Witkowski committed
806
      delete ind;
807

808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
    fclose(file);
  }


  int macro_type(const char *filename, const char *type)
  {
    const char *fn, *t;
  
    if (strlen(filename) <= strlen(type))
      return(false);
  
    fn = filename;
    while (*fn) fn++;
    t = type;
    while (*t) t++;
  
    while (t != type  &&  *t == *fn) t--;
  
    return(t == type);
  }


  /****************************************************************************/
  /*  sets the boundary of all edges/faces with no neigbour to a straight     */
  /*  line/face with Dirichlet boundary type                                  */
  /****************************************************************************/

  void MacroInfo::dirichletBoundary()
  {
837
838
    for (int i = 0; i < static_cast<int>( mel.size()); i++) {
      for (int k = 0; k < mesh->getGeo(NEIGH); k++) {
839
840
841
842
843
844
845
846
847
848
849
	if (mel[i]->neighbour[k])
	  mel[i]->boundary[k] = INTERIOR;
	else
	  mel[i]->boundary[k] = DIRICHLET;
      }
    }
  }


  void MacroInfo::fillBoundaryInfo(Mesh *mesh)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
850
    int i, j, k, nv = mesh->getNumberOfVertices();
851

852
    std::deque<MacroElement*>::iterator melIt;
853

Thomas Witkowski's avatar
Thomas Witkowski committed
854
    BoundaryType *bound = new BoundaryType[nv];
855
856
857
858
859
860
861
862
863
864

    int dim = mesh->getDim();

    switch(dim) {
    case 1:
      break;
    case 2:
      for (i = 0; i < nv; i++)
	bound[i] = INTERIOR;

Thomas Witkowski's avatar
Thomas Witkowski committed
865
      for (i = 0, melIt = mesh->firstMacroElement(); 
866
	   melIt != mesh->endOfMacroElements(); 
Thomas Witkowski's avatar
Thomas Witkowski committed
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
	   ++melIt, i++) {
	for (j = 0; j < mesh->getGeo(NEIGH); j++) {
	  if ((*melIt)->getBoundary(j) != INTERIOR) {
	    if ((*melIt)->getBoundary(j) >= DIRICHLET) {
	      int j1 = mel_vertex[i][(j+1)%3];
	      int j2 = mel_vertex[i][(j+2)%3];
	      
	      bound[j1] = max(bound[j1], (*melIt)->getBoundary(j));
	      bound[j2] = max(bound[j2], (*melIt)->getBoundary(j));
	    } else if ((*melIt)->getBoundary(j) <= NEUMANN) {
	      int j1 = mel_vertex[i][(j+1)%3];
	      int j2 = mel_vertex[i][(j+2)%3];
	      
	      if (bound[j1] != INTERIOR)
		bound[j1] = max(bound[j1], (*melIt)->getBoundary(j));
	      else
		bound[j1] = (*melIt)->getBoundary(j);
	      
	      if (bound[j2] != INTERIOR)
		bound[j2] = max(bound[j2], (*melIt)->getBoundary(j));
	      else
		bound[j2] = (*melIt)->getBoundary(j);
889
890
891
	    }
	  }
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
892
      }
893

Thomas Witkowski's avatar
Thomas Witkowski committed
894
      for (i = 0, melIt = mesh->firstMacroElement(); 
895
896
	   melIt != mesh->endOfMacroElements(); 
	   ++melIt, i++) 
Thomas Witkowski's avatar
Thomas Witkowski committed
897
898
899
	for (j = 0; j < mesh->getGeo(VERTEX); j++)
	  (*melIt)->setBoundary(3 + j, bound[mel_vertex[i][j]]);
	
900
901
902
903
904
      break;
    case 3:
      for (i = 0; i < nv; i++)
	bound[i] = INTERIOR;

Thomas Witkowski's avatar
Thomas Witkowski committed
905
      for (i = 0, melIt = mesh->firstMacroElement(); 
906
	   melIt != mesh->endOfMacroElements(); 
Thomas Witkowski's avatar
Thomas Witkowski committed
907
908
909
910
911
912
913
914
	   ++melIt, i++) {
	for (j = 0; j < mesh->getGeo(NEIGH); j++) {
	  for (k = 1; k < 4; k++)
	    bound[mel_vertex[i][(j+k)%4]] =
	      ((*melIt)->getBoundary(j) != INTERIOR) ?
	      newBound((*melIt)->getBoundary(j),
		       bound[mel_vertex[i][(j+k)%4]]) :
	      bound[mel_vertex[i][(j+k)%4]];
915
	}
Thomas Witkowski's avatar
Thomas Witkowski committed
916
      }
917
918
919

      for (i = 0, melIt = mesh->firstMacroElement(); 
	   melIt != mesh->endOfMacroElements(); 
Thomas Witkowski's avatar
Thomas Witkowski committed
920
921
922
923
	   ++melIt, i++) 	
	for (j = 0; j < mesh->getGeo(VERTEX); j++)
	  (*melIt)->setBoundary(10 + j, bound[mel_vertex[i][j]]);
      
924
      break;
Thomas Witkowski's avatar
Thomas Witkowski committed
925
926
    default: 
      ERROR_EXIT("invalid dim\n");
927
928
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
929
    delete [] bound;
930
931
932
933
  }

  void MacroReader::computeNeighbours(Mesh *mesh)
  {
934
    FUNCNAME("MacroReader::computeNeighbours()");
935

936
    int dim = mesh->getDim();
937
    FixVec<DegreeOfFreedom*, DIMEN> dof(dim, NO_INIT);
938

939
940
941
942
    for (int i = 0; i < mesh->getNumberOfLeaves(); i++) {
      for (int k = 0; k < mesh->getGeo(NEIGH); k++) {
	mesh->getMacroElement(i)->setOppVertex(k, AMDIS_UNDEFINED);
	mesh->getMacroElement(i)->setNeighbour(k, NULL);
943
      }
944
    }
945

946
947
948
949
950
951
952
    for (int i = 0; i < mesh->getNumberOfLeaves(); i++) {
      for (int k = 0; k < mesh->getGeo(NEIGH); k++) {
	if (mesh->getMacroElement(i)->getBoundary(k) != INTERIOR) {
	  mesh->getMacroElement(i)->setNeighbour(k, NULL);
	  mesh->getMacroElement(i)->setOppVertex(k, -1);
	  continue;
	}
953

954
955
956
957
958
959
960
961
	if (mesh->getMacroElement(i)->getOppVertex(k) == AMDIS_UNDEFINED) {
	  if (dim == 1) {
	    dof[0] = const_cast<DegreeOfFreedom*>(mesh->getMacroElement(i)->
						  getElement()->getDOF(k));
	  } else {
	    for (int l = 0; l < dim; l++)
	      dof[l] = const_cast<DegreeOfFreedom*>(mesh->getMacroElement(i)->
						    getElement()->
962
						    getDOF((k + l + 1) % (dim + 1)));
963
	  }
964
965
966
967
968
969
970
971
972
973
974
975
976
	  
	  int j = 0;
	  for (j = i + 1; j < mesh->getNumberOfLeaves(); j++) {
	    int m = mesh->getMacroElement(j)->getElement()->oppVertex(dof);
	    if (m != -1) {
	      mesh->getMacroElement(i)->setNeighbour(k, mesh->getMacroElement(j));
	      mesh->getMacroElement(j)->setNeighbour(m, mesh->getMacroElement(i));
	      mesh->getMacroElement(i)->setOppVertex(k, m);
	      mesh->getMacroElement(j)->setOppVertex(m, k);
	      break;
	    }
	  }

977
978
979
980
981
982
983
	  if (j >= mesh->getNumberOfLeaves()) {
	    std::cout << "----------- ERROR ------------" << std::endl;
	    std::cout << "Cannot find neighbour " << k << " of element " << i << std::endl;
	    std::cout << "  dim = " << dim << std::endl;
	    std::cout << "  coords of element = ";
	    for (int l = 0; l <= dim; l++) {
	      std::cout << mesh->getMacroElement(i)->getCoord(l);
984
985
	      if (l < dim)
		std::cout << " / ";	      
986
987
988
	    }
	    std::cout << std::endl;
	    std::cout << "  dofs = ";
989
990
	    for (int l = 0; l < dim; l++)
	      std::cout << *(dof[l]) << " ";	    
991
992
993
994
	    std::cout << std::endl;

	    ERROR_EXIT("\n");
	  }    
995
	}
996
      }
997
    }
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
  }


  /****************************************************************************/
  /*  boundaryDOFs:                                                           */
  /*  adds dof's at the edges of a given macro triangulation and calculates   */
  /*  the number of edges                                                     */
  /****************************************************************************/

  void MacroReader::boundaryDOFs(Mesh *mesh)
  {
1009
1010
1011
1012
1013
    FUNCNAME("Mesh::boundaryDOFs()");

    int lnode = mesh->getNode(EDGE);
    int k, lne = mesh->getNumberOfLeaves();
    int max_n_neigh = 0, n_neigh, ov;
1014
    std::deque<MacroElement*>::iterator mel;
1015
    const MacroElement* neigh;
1016
    DegreeOfFreedom *dof;
1017
1018
1019
1020
1021
1022

    mesh->setNumberOfEdges(0);
    mesh->setNumberOfFaces(0);

    int dim = mesh->getDim();

Thomas Witkowski's avatar
Thomas Witkowski committed
1023
    switch (dim) {
1024
    case 2:
1025
      for (mel = mesh->firstMacroElement(); mel != mesh->endOfMacroElements(); mel++) {
1026
1027
1028
1029
1030
1031
	// check for periodic boundary
	Element *el = const_cast<Element*>((*mel)->getElement());
	ElementData *ed = el->getElementData(PERIODIC);

	DimVec<bool> periodic(dim, DEFAULT_VALUE, false);

1032
	if (ed) {
1033
	  std::list<LeafDataPeriodic::PeriodicInfo> &periodicInfos = 
1034
	    dynamic_cast<LeafDataPeriodic*>(ed)->getInfoList();
1035
1036
	  std::list<LeafDataPeriodic::PeriodicInfo>::iterator it;
	  std::list<LeafDataPeriodic::PeriodicInfo>::iterator end = periodicInfos.end();
Thomas Witkowski's avatar
Thomas Witkowski committed
1037
1038
	  for (it = periodicInfos.begin(); it != end; ++it)
	    if (it->type != 0)
1039
1040
1041
	      periodic[it->elementSide] = true;
	}

1042
	for (int i = 0; i < mesh->getGeo(NEIGH); i++) {
1043
	  if (!(*mel)->getNeighbour(i) || 
1044
1045
1046
1047
1048
1049
1050
1051
	      ((*mel)->getNeighbour(i)->getIndex() < (*mel)->getIndex())) {

	    mesh->incrementNumberOfEdges(1);

	    if (mesh->getNumberOfDOFs(EDGE)) {
	      dof = el->setDOF(lnode + i, mesh->getDOF(EDGE));
      
	      if ((*mel)->getNeighbour(i)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1052
1053
		Element *neigh = 
		  const_cast<Element*>((*mel)->getNeighbour(i)->getElement());
1054

Thomas Witkowski's avatar
Thomas Witkowski committed
1055
		if (periodic[i])
1056
		  neigh->setDOF(lnode + (*mel)->getOppVertex(i), mesh->getDOF(EDGE));
Thomas Witkowski's avatar
Thomas Witkowski committed
1057
1058
		else
		  neigh->setDOF(lnode + (*mel)->getOppVertex(i), dof);		
1059
	      }
1060
1061
	    }
	  }  
1062
1063
1064
1065
1066
1067
	}
      }
      break;
    case 3:
      lnode = mesh->getNode(FACE);
      mel = mesh->firstMacroElement();
1068
      for (int i = 0; i < lne; i++) {
1069
1070
1071
1072
1073
1074
1075

	// check for periodic boundary
	Element *el = const_cast<Element*>((*(mel+i))->getElement());
	ElementData *ed = el->getElementData(PERIODIC);

	DimVec<bool> periodic(dim, DEFAULT_VALUE, false);
      
1076
	if (ed) {
1077
	  std::list<LeafDataPeriodic::PeriodicInfo> &periodicInfos = 
1078
	    dynamic_cast<LeafDataPeriodic*>(ed)->getInfoList();
1079
1080
	  std::list<LeafDataPeriodic::PeriodicInfo>::iterator it;
	  std::list<LeafDataPeriodic::PeriodicInfo>::iterator end = periodicInfos.end();
1081
1082
	  for (it = periodicInfos.begin(); it != end; ++it)
	    if (it->type != 0)
1083
1084
1085
1086
1087
1088
1089
1090
1091
	      periodic[it->elementSide] = true;
	}

	for (k = 0; k < mesh->getGeo(EDGE); k++) {      
	  /*********************************************************************/
	  /* check for not counted edges                                       */
	  /*********************************************************************/
	  n_neigh = 1;

Thomas Witkowski's avatar
Thomas Witkowski committed
1092
	  if (newEdge(mesh, (*(mel + i)), k, &n_neigh)) {
1093
1094
1095
1096
1097
1098
	    mesh->incrementNumberOfEdges(1);
	    max_n_neigh = max(max_n_neigh, n_neigh);
	  }
	}
      
	for (k = 0; k < mesh->getGeo(NEIGH); k++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1099
	  neigh = (*(mel + i))->getNeighbour(k);
1100
1101
1102
	  /*********************************************************************/
	  /* face is counted and dof is added by the element with bigger index */
	  /*********************************************************************/
Thomas Witkowski's avatar
Thomas Witkowski committed
1103
1104
	  if (neigh && (neigh->getIndex() > (*(mel + i))->getIndex()))  
	    continue;
1105
1106
1107
1108
	
	  mesh->incrementNumberOfFaces(1);
	
	  if (mesh->getNumberOfDOFs(FACE)) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1109
	    TEST_EXIT(!(*(mel + i))->getElement()->getDOF(lnode + k))
1110
	      ("dof %d on element %d already set\n", 
Thomas Witkowski's avatar
Thomas Witkowski committed
1111
	       lnode + k, (*(mel + i))->getIndex());
1112
	  
Thomas Witkowski's avatar
Thomas Witkowski committed
1113
1114
	    const_cast<Element*>((*(mel + i))->getElement())->setDOF(lnode + k,
								     mesh->getDOF(FACE));
1115
1116

	    if (neigh) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1117
1118
	      ov = (*(mel + i))->getOppVertex(k);
	      TEST_EXIT(!neigh->getElement()->getDOF(lnode + ov))
1119
		("dof %d on neighbour %d already set\n", 
Thomas Witkowski's avatar
Thomas Witkowski committed
1120
		 lnode + ov, neigh->getIndex());
1121
1122
	    
	      Element *neighEl = 
Thomas Witkowski's avatar
Thomas Witkowski committed
1123
		const_cast<Element*>((*(mel + i))->getNeighbour(k)->getElement());
1124

Thomas Witkowski's avatar
Thomas Witkowski committed
1125
	      if (periodic[k])
1126
		neighEl->setDOF(lnode+ov, mesh->getDOF(FACE));
Thomas Witkowski's avatar
Thomas Witkowski committed
1127
1128
1129
	      else
		neighEl->setDOF(lnode+ov, const_cast<int*>((*(mel + i))->getElement()->
							   getDOF(lnode + k)));	      
1130
1131
1132
1133
1134
	    }
	  }
	}
      }
      break;
Thomas Witkowski's avatar
Thomas Witkowski committed
1135
1136
    default: 
      ERROR_EXIT("invalid dim\n");
1137
1138
    }
    
1139
    if (3 == dim)
Thomas Witkowski's avatar
Thomas Witkowski committed
1140
      mesh->setMaxEdgeNeigh(std::max(8, 2 * max_n_neigh));
1141
    else
Thomas Witkowski's avatar
Thomas Witkowski committed
1142
      mesh->setMaxEdgeNeigh(dim - 1);    
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
  }

  /* 
     testet mesh auf auftretende Zyklen
  
     wenn Zyklus auftritt:
     ordnet Eintraege in MacroElement-Struktur um, so dass kein Zyklus auftritt
     erzeugt neue Macro-Datei nameneu mit umgeordnetem Netz 
     (wenn nameneu=NULL wird keine MAcro-Datei erzeugt)
  */      

  void MacroReader::macroTest(Mesh *mesh, const char *nameneu)
  {
1156
    FUNCNAME("MacroReader::macroTest()");
1157
   
1158
1159
1160
1161
1162
1163
1164
    int i = macrotest(mesh);

    if (i >= 0) {
      ERROR("There is a cycle beginning in macro element %d\n", i);
      ERROR("Entries in MacroElement structures get reordered\n");
      umb(NULL, mesh, umbVkantMacro);

Thomas Witkowski's avatar
Thomas Witkowski committed
1165
      if (nameneu)
1166
1167
	ERROR_EXIT("mesh->feSpace\n");
    }
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
  }
  
  /****************************************************************************/
  /*  macro_test():                              Author: Thomas Kastl (1998)  */
  /****************************************************************************/
  /*
    testet mesh auf auftretende Zyklen
  
    wenn mesh zyklenfrei -> -1
    sonst ->  globaler Index des Macroelementes bei dem ein Zyklus beginnt 
  */<