Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

HL_SignedDistLevels.cc 35.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


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
#include "HL_SignedDistLevels.h"

#include "VelocityExtFromVelocityField.h"

void 
HL_SignedDistLevels::initializeBoundary() 
{
  FUNCNAME("HL_SignedDistLevels::initializeBoundary()");
  
  TraverseStack stack;
  FixVec<double, VERTEX> distVec(dim, NO_INIT);
  int elStatus;
  const int *elVertStatusVec;
  int NumVertIntPoints;
  int ElNum;
  clock_t time1;
  clock_t time2;
  double TIME;
  
  //=== transvering Mesh to SMI and add quantities
  time1 = clock();
  Mesh_to_SMI_and_quantity();
  time2 = clock();
  TIME = TIME_USED(time1, time2);
  
  cout <<"Zeit zum Transformieren nach SMI: "<<TIME<<" sec.\n";
  
  // ===== All non-boundary vertices are initialized with "infinity". =====
  sD_DOF->set(inftyValue);
  
  // ===== Traverse mesh and initialize boundary elements. =====
  const int nBasFcts = feSpace->getBasisFcts()->getNumber();
  DegreeOfFreedom *locInd = GET_MEMORY(DegreeOfFreedom, nBasFcts);

  ElInfo *elInfo;
  if (velExt && velExtType.isSet(VEL_EXT_FROM_VEL_FIELD)) {
    elInfo = stack.traverseFirst(feSpace->getMesh(),
				 -1, 
				 Mesh::CALL_LEAF_EL | 
				 Mesh::FILL_BOUND |
				 Mesh::FILL_COORDS |
				 Mesh::FILL_GRD_LAMBDA);
  } 
  else {
    elInfo = stack.traverseFirst(feSpace->getMesh(),
				 -1, 
				 Mesh::CALL_LEAF_EL | 
				 Mesh::FILL_BOUND |
				 Mesh::FILL_COORDS);
  }
  while(elInfo) {

    // Set elInfo in case velocity extension from velocity field is used.
    if (velExt && velExtType.isSet(VEL_EXT_FROM_VEL_FIELD)) {
      ((VelocityExtFromVelocityField *)velExt)->setElInfo(elInfo);
    }  
    
    // Get local indices of vertices.
    feSpace->getBasisFcts()->getLocalIndices(
			     const_cast<Element *>(elInfo->getElement()),
			     const_cast<DOFAdmin *>(feSpace->getAdmin()),
			     locInd); 
    
    // Get element status.
    elStatus = elLS->createElementLevelSet(elInfo);
    
    //Get some information for creating the first list
    
    elVertStatusVec = elLS->getElVertStatusVec();
    
    //Beginn creating the first list
    
    NumVertIntPoints = elLS->getNumVertIntPoints();
    ElNum = elInfo->getElement()->getIndex();
    
    createFirstList( elStatus, elVertStatusVec, ElNum, NumVertIntPoints);

    //end creating the first list
    
    // Is element cut by the interface ?
    if (elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY) {
      
      // Reset element distance vector.
      for (int i=0; i<=dim; ++i) {
	distVec[i] = inftyValue;
      }
      
      // Mark all vertices as boundary vertices.
      for (int i=0; i<=dim; ++i) {
	(*bound_DOF)[locInd[i]] = 1.0;
      }
      
      // Calculate distance for all vertices.
      if (bndElDist->calcDistOnBoundaryElement(elInfo, distVec) !=
	  ElementLevelSet::LEVEL_SET_BOUNDARY) {
	ERROR_EXIT("error in distance calculation !\n");
	}
      else {
	
	// If distance is smaller, correct to new distance.
	for (int i=0; i<=dim; ++i) {
	  if ((*sD_DOF)[locInd[i]] > distVec[i]) {
	    (*sD_DOF)[locInd[i]] = distVec[i];
	    //If distance is corrected, calculate new velocity.
	    if(velExt != NULL)
	      {
		velExt->calcVelocityBoundary(locInd, i);
	      }
	  }
	}
      }
    }  // end of: elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY
    
    else if (elLS->getNumVertIntPoints() != 0){
//       // Interface cuts element only in vertices.
//       elVertStatusVec = elLS->getElVertStatusVec();
      
//       for (int i=0; i<=dim; ++i) {
// 	if (elVertStatusVec[i] == ElementLevelSet::LEVEL_SET_BOUNDARY) {
// 	  (*bound_DOF)[locInd[i]] = 1.0;
// 	  (*sD_DOF)[locInd[i]] = 0.0;
// 	  }
//       }

      ERROR_EXIT("intersection point is element vertex. should never happen !\n");
    } 
    
    elInfo = stack.traverseNext(elInfo);
  }  // end of: mesh traverse
  
  FREE_MEMORY(locInd, DegreeOfFreedom, nBasFcts);
  
  return;
}

void 
HL_SignedDistLevels::Mesh_to_SMI_and_quantity()
{
  if(!smiAdapter)
    {
      smiAdapter = NEW SMIAdapter(1, 1,
				  const_cast<FiniteElemSpace*>(feSpace),
				  1, -1);
    }
  
  // cout << "\n\n\tSMI-Adapter angelegt !\n\n";
  
  //====== transfer Mesh to SMI ======================
  
  smiAdapter->addNeighbourInfo();
  
  // cout << "\n\n\tNachbarschafts-Infos in SMI ergaenzt !\n\n";
  
  smiAdapter-> transferMeshToSMI();
  
  //   cout << "\n\n\tGitter nach SMI geschrieben !\n\n";
  
  int smiError = SMI_Begin_write_transaction(1,1);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Begin_write_transaction() failed with error %d\n", smiError);
  
  int nul = 0;
  int *null = new int [dim+1];
  for (int i=0; i<=dim; i++)
    {
      null[i] = nul;
    }

  //which pair of element and node is saved in list
  smiError = 
    SMI_Add_quantity(1, 1, 1, SMI_LOC_ELEM, SMI_TYPE_INT, dim+1, null);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Add_quantity() failed with error %d\n", smiError);

  //which node is a boundary-node
  smiError = SMI_Add_quantity(1, 1, 2, SMI_LOC_NODE, SMI_TYPE_INT, 1, &nul);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Add_quantity() failed with error %d\n", smiError);

  //saves the number of tried updates
  smiError = SMI_Add_quantity(1, 1, 3, SMI_LOC_NODE, SMI_TYPE_INT, 1, &nul);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Add_quantity() failed with error %d\n", smiError);

  //saves the number of updates
  smiError = SMI_Add_quantity(1, 1, 4, SMI_LOC_NODE, SMI_TYPE_INT, 1, &nul);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Add_quantity() failed with error %d\n", smiError);

  //how often a node is saved in the second list
  smiError = SMI_Add_quantity(1, 1, 5, SMI_LOC_NODE, SMI_TYPE_INT, 1, &nul);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Add_quantity() failed with error %d\n", smiError);

  //saves the level of an element
  smiError = SMI_Add_quantity(1, 1, 6, SMI_LOC_ELEM, SMI_TYPE_INT, 1, 
			      &inftyValue);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Add_quantity() failed with error %d\n", smiError);

  // cout << "\n\n\tQuantities in SMI ergaenzt !\n\n";

  delete [] null;
}

void 
HL_SignedDistLevels::createFirstList(const int elStatus, 
				     const int *elVertStatusVec, 
				     int ElNum, 
				     const int NumVertIntPoints)
{
  int *sv = new int[dim+1];
  int *nodeIndices;
  int nul = 0;
  int smiError;
  
  if (elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY)
    {
      List_Element.push(ElNum);

      smiError = 
	SMI_Set_quantity_values(1, 1, 6, SMI_TYPE_INT, 1, 1, &ElNum, &nul);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Set_quantity_values() failed with error %d\n", smiError);

      //saving which nodes are boundary-nodes
      for (int i=0; i<=dim; i++)
	{
	  sv[i] = 1;
	}

      smiError =
	SMI_Get_elems(1, 1, 1, const_cast<DegreeOfFreedom*>(&ElNum),
		      NULL, &nodeIndices, NULL, NULL);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_elems() failed with error %d\n", smiError);
      
      smiError = 
	SMI_Set_quantity_values(1, 1, 2, SMI_TYPE_INT, 1, 3, nodeIndices, sv);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Set_quantity_values() failed with error %d\n", smiError);
    }
  //if the elemet isn't a boundary-element, but the interface cuts the FE in two nodes
//   else if (NumVertIntPoints == dim)
//     {
//       List_Element.push( ElNum );           

//       smiError = 
// 	SMI_Set_quantity_values(1, 1, 6, SMI_TYPE_INT, 1, 1, &ElNum, &nul);
//       TEST_EXIT(smiError == SMI_OK)
// 	("SMI_Set_quantity_values() failed with error %d\n", smiError);
      
//       //saving which nodes are boundary-nodes
//       for (int i=0; i<=dim; i++)
// 	{
// 	  if(elVertStatusVec[i] == ElementLevelSet::LEVEL_SET_BOUNDARY)
// 	    {
// 	      sv[i] = 1;
// 	    }
// 	  else
// 	    {
// 	      sv[i] = 0;
// 	    }

// 	  smiError = 
// 	    SMI_Get_elems(1, 1, 1, const_cast<DegreeOfFreedom*>(&ElNum),
// 			  NULL, &nodeIndices, NULL, NULL);
// 	  TEST_EXIT(smiError == SMI_OK)
// 	    ("SMI_Get_elems() failed with error %d\n", smiError);

// 	  smiError = 
// 	    SMI_Set_quantity_values(1, 1, 2, SMI_TYPE_INT, 1, 3,
// 				    nodeIndices, sv);
// 	  TEST_EXIT(smiError == SMI_OK)
// 	    ("SMI_Set_quantity_values() failed with error %d\n", smiError);
// 	}
//     }
  
  delete [] sv;
}
  
void 
HL_SignedDistLevels::HL_updateIteration()
{
  int numNodes;
  int *nodeIndices;
  int max_q3 = 0;
  int max_q4 = 0;
  int sum_q3 = 0;
  int sum_q4 = 0;
  clock_t time1;
  clock_t time2;
  double TIME;
  int control;
  
  int smiError = 
    SMI_Get_all_nodes(1, 1, const_cast<DegreeOfFreedom*>(&numNodes),
		      &nodeIndices);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_all_nodes() failed with error %d\n", smiError);

  int *values_q3 = new int [numNodes];
  int *values_q4 = new int [numNodes];
  
  GET_PARAMETER(0,"SignedDist->count updates", "%d", &count_updates);
  
  time1 = clock();
  control = traverseListElement();
  time2 = clock();
  TIME = TIME_USED(time1, time2);
  
  cout<<"Zeit zum durchlaufen der ersten (Elementen-) Liste: "<<TIME<<" sec.\n\n";
  if(control == 1)
    {
      createLevels ();
    }
  
  /////////////////////////////////
  
  
  //print chosen level in a file
  if (print_level == 1)
    {
336
      DOFVector<double> *level_DOF = NEW DOFVector<double>(sD_DOF->getFeSpace(), 
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
							   "level_DOF");
      
      int numElems;
      int *elemIndices;
      int *NodeIndices;
      
      smiError = SMI_Get_all_elems(1, 1, &numElems, &elemIndices);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_all_elems() failed with error %d\n", smiError);
      
      int *value_q6 = new int [numElems];
      
      smiError =
	SMI_Get_quantity_values(1, 1, 6, SMI_TYPE_INT, 1, numElems,
				elemIndices, value_q6);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_quantity_values() failed with error %d\n", smiError);
      
      for(int i=0; i<numElems; i++)
	{	  
	  smiError = 
	    SMI_Get_elems(1, 1, 1, &elemIndices[i], NULL, &NodeIndices, 
			  NULL, NULL);
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Get_elems() failed with error %d\n", smiError);

	  for(int j=0; j<=dim; j++)
	    {
	      (*level_DOF)[NodeIndices[j]] = -1;
	    }
	}
      for(int i=0; i<numElems; i++)
	{	  
	  smiError = 
	    SMI_Get_elems(1, 1, 1, &elemIndices[i], NULL, &NodeIndices, 
			  NULL, NULL);
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Get_elems() failed with error %d\n", smiError);

	  if (value_q6[i] == chosen_level)
	    {
	      for(int j=0; j<dim+1; j++)
		{
		  (*level_DOF)[NodeIndices[j]] = 0;
		}
	    }
	}
      
      FileWriter *levelFileWriter = 
	NEW FileWriter("level->output",
387
		       level_DOF->getFeSpace()->getMesh(),
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 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 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 608 609 610 611 612 613 614 615 616 617 618 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 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 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 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 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 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 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 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372
		       level_DOF);
      levelFileWriter->writeFiles (adaptInfo, false);
      
      DELETE levelFileWriter;
    }
  
  //end of the part for printing chosen levels
  
  
  time1 = clock();
  traversingListLevel_ ( sD_DOF );
  time2 = clock();
  TIME = TIME_USED(time1,time2);
  
  cout<<"Zeit zum Durchlaufen der zweiten  Liste (Liste von Listen): "<<TIME<<" sec.\n\n";
  
  std::string smiOutFile;
  GET_PARAMETER(0, "SignedDist->count updates->output->filename", &smiOutFile);
  cout << "count updates Ausgabe-Datei:  " << smiOutFile.c_str() << "\n\n";
  
  ofstream out (smiOutFile.c_str());
  
  smiError = 
    SMI_Get_quantity_values(1, 1, 3, SMI_TYPE_INT, 1, numNodes, nodeIndices,
			    values_q3);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_quantity_values() failed with error %d\n", smiError);

  smiError =
    SMI_Get_quantity_values(1, 1, 4, SMI_TYPE_INT, 1, numNodes, nodeIndices,
			    values_q4);  
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_quantity_values() failed with error %d\n", smiError);
  
  for (int i=0; i<numNodes; i++)
    {
      out<<nodeIndices[i]<<" "<<values_q3[i]<<" "<<values_q4[i]<<"\n";
      
      if(max_q3 < values_q3[i])
	{
	  max_q3 = values_q3[i];
	}
      if(max_q4 < values_q4[i])
	{
	  max_q4 = values_q4[i];
	}
      sum_q3 = sum_q3 + values_q3[i];
      sum_q4 = sum_q4 + values_q4[i];
    }
  
  out<<"\n\n maximale Anzahl an versuchten Updates auf einem Knoten: "<<max_q3<<"\n maximale Anzahl an durchgefuehrten Updates auf einem Knoten:  "<<max_q4<<"\n";
  out<<"\n Summe aller versuchten Updates: "<<sum_q3<<"\n Summe aller durchgefuehrten updates: "<<sum_q4<<"\n";
  
  out<<"Anzahl an Knoten: "<<numNodes<<"\n";
  
  out.close();
  
  smiError = SMI_End_write_transaction(1, 1);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_End_write_transaction() failed with error %d\n", smiError);
  
  return;
}
 
int 
HL_SignedDistLevels::traverseListElement()
{
  int Element;
  
  bool neighboursExist;
  bool neighbourInNewListSet = false;
  
  while (List_Element.size() != 0)
    {
      Element = List_Element.front();
      
      neighboursExist =  collectNeighbours_setLevels (Element, 0, &neighbourInNewListSet);
      
      List_Element.pop();
    }
  
  //within the function "collectNeighbours_setLevels" the new pairs are saved in the list "level"
  //this list will be one entry of the list "Level_"
  if (neighbourInNewListSet)
    {
      Level_.push_back (Level);
    }
  
  while (Level.size() != 0)
    {
      Level.pop();
    }
  if (!neighbourInNewListSet)
    {
      return 0;
    }
  else
    {
      return 1;
    }
  
}

void 
HL_SignedDistLevels::createLevels ()
{
  bool neighbourExists = true;
  bool stop = false;
  Vert_Struct vertStruct;
  int i = 0;
  bool elementInNextListSet = true;
  int value_q2;
  int smiError;
  
  while(elementInNextListSet)
    {
      stop = false;
      neighbourExists = false;
      elementInNextListSet = false;
      
      while(Level_[i].size() != 0) 
	{
	  vertStruct =  Level_[i].front();
	  
	  neighbourExists = collectNeighbours_setLevels (vertStruct.ElNum, i+1, &elementInNextListSet);
	  
	  smiError = 
	    SMI_Get_quantity_values(1, 1, 2, SMI_TYPE_INT, 1, 1, 
				    &vertStruct.VertNum, &value_q2);
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Get_quantity_values() failed with error %d\n", smiError);

	  if(value_q2 == 0)
	    {
	      helpLevel.push (vertStruct);
	    }
	  Level_[i].pop();
	}
      
      Level_[i] = helpLevel;
      while (helpLevel.size() != 0)
	{
	  helpLevel.pop();
	}
      
      if(elementInNextListSet)
	{
	  Level_.push_back (Level);
	}
      
      while (Level.size() != 0)
	{
	  Level.pop();
	}
      i++;
    }
}

bool 
HL_SignedDistLevels::collectNeighbours_setLevels (const int Element,
						  const int currentIndex,
						  bool *elementInNewListSet)
{
  Vert_Struct vertStruct;
  
  int *neighbour=new int[dim+1];
  int *oppVertices=new int[dim+1];
  int *value = new int [dim+1];
  int saved_level;
  int value_q5;
  int *nodeIndices;
  int *nodeIndicesOfElem;
  int smiError;

  bool neighbourExists = false;
  
  smiAdapter->getNeighbourInfo(Element, neighbour, oppVertices);
  
  for ( int i=0; i<=dim; i++)
    {
      //if this neighbour exists it will be saved in a list according to it's level
      if(neighbour[i] != -1)
	{
	  neighbourExists = true;

	  //calling old level and saving new level if necessary
	  smiError =
	    SMI_Get_quantity_values(1, 1, 6, SMI_TYPE_INT, 1, 1, 
				    &neighbour[i], &saved_level);
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Get_quantity_values() failed with error %d\n", smiError);

	  if(saved_level > currentIndex)
	    {
	      saved_level = currentIndex+1;

	      smiError =
		SMI_Set_quantity_values (1, 1, 6, SMI_TYPE_INT, 1, 1, 
					 &neighbour[i], &saved_level);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Set_quantity_values() failed with error %d\n", 
		 smiError);
	      
	      smiError =
		SMI_Get_elems(1, 1, 1, &neighbour[i], NULL, &nodeIndices, 
			      NULL,NULL);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Get_elems() failed with error %d\n", 
		 smiError);
	      
	      smiError = 
		SMI_Get_quantity_values(1, 1, 1, SMI_TYPE_INT, dim+1, 1,
					&neighbour[i], value);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Get_quantity_values() failed with error %d\n", 
		 smiError);

	      if (value[oppVertices[i]] == 0)
		{
		  vertStruct.ElNum = neighbour[i] ;
		  vertStruct.VertNum = oppVertices[i];                           
		  Level.push( vertStruct );
		  value[oppVertices[i]] = 1;
		  (*elementInNewListSet) = true;
		  
		  //counts how often a node is saved in the list of lists
		  if(count_in_list == 1)
		    {
		      smiError = 
			SMI_Get_elems(1, 1, 1,
				      const_cast<DegreeOfFreedom*>(&(vertStruct.ElNum)), 
				      NULL, &nodeIndicesOfElem, NULL, NULL);
		      TEST_EXIT(smiError == SMI_OK)
			("SMI_Get_elems() failed with error %d\n", smiError);

		      smiError = 
			SMI_Get_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
						const_cast<DegreeOfFreedom*>(& nodeIndicesOfElem[vertStruct.VertNum]),
						&value_q5);
		      TEST_EXIT(smiError == SMI_OK)
			("SMI_Get_quantity_values() failed with error %d\n", 
			 smiError);

		      value_q5 = value_q5 + 1;

		      smiError =
			SMI_Set_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
						const_cast<DegreeOfFreedom*>(& nodeIndicesOfElem[vertStruct.VertNum]),
						&value_q5);
		      TEST_EXIT(smiError == SMI_OK)
			("SMI_Set_quantity_values() failed with error %d\n", 
			 smiError);
		    }
		}
	      //save which pairs of elements and nodes is saved in a list
	      smiError = 
		SMI_Set_quantity_values(1, 1, 1, SMI_TYPE_INT, dim+1, 1,
// 					&neighbour[i], value);
					neighbour+i, value);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Set_quantity_values() failed with error %d\n", 
		 smiError);
	    }
	}
    }
  
  delete [] neighbour;
  delete [] oppVertices;
  delete [] value;
  
  return neighbourExists;
  
  
}

void 
HL_SignedDistLevels::traversingListLevel_ ( DOFVector<double> *boundVal_DOF )
{
  bool Continue = true;
  
  Vert_Struct El_Vert;
  
  int Vert;
  
  int locVert;
  int value_q3;
  int value_q4;
  int value_q5;
  int counter = 0;
  int *nodeIndices;
  int *nodeIndicesOfElem;
  double *coords = new double [(dim+1)*dim];
  int *valuesINT=new int[dim+1];
  double update;
  int counter_list = 0;
  int counter_lists_of_lists = 0;
  FixVec<WorldVector<double> *, VERTEX> coordsOfNodes(dim);
  for ( int i=0; i<=dim; i++)
    {
      coordsOfNodes[i] = new WorldVector<double>;
    }
  FixVec<double,VERTEX> boundVal(dim,NO_INIT);
  WorldVector<double> helpVec;
  int smiError;
  
  //for repeating the traverse of the list "Level_"
  while (Continue == true)
    {
      Continue = false;
      
      //for traversing of the list "Level_"
      for (int j=0; j < (signed int) Level_.size();j++)
	{ 
	  //for traversing the entries of the List "Level_"                    

	  while (Level_[j].size() != 0)
	    {
	      El_Vert = Level_[j].front();
	      Vert = El_Vert.VertNum;
	      
	      smiError = 
		SMI_Get_elems (1, 1, 1, &(El_Vert.ElNum), NULL, 
			       &(nodeIndices), NULL, NULL);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Get_elems() failed with error %d\n", smiError);

	      smiError =
		SMI_Get_nodes (1, 1, 3, dim, nodeIndices, coords);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Get_nodes() failed with error %d\n", smiError);
	      
	      //sorting of the nodes for calculating the update
	      counter = 0;
	      for (int i=0; i<=dim; i++)
		{
		  if (i == El_Vert.VertNum)      
		    {
		      (*(coordsOfNodes[dim]))[0]=coords[i*2];
		      (*(coordsOfNodes[dim]))[1]=coords[i*2+1];
		      boundVal[dim] = (*boundVal_DOF)[nodeIndices[i]];
		      locVert = i;
		    }
		  else
		    {
		      (*(coordsOfNodes[counter]))[0]=coords[i*2];
		      (*(coordsOfNodes[counter]))[1]=coords[i*2+1];
		      boundVal[counter] = (*boundVal_DOF)[nodeIndices[i]];
		      counter = counter+1;
		    }
		}
	      
	      //save permutation of vertexes for calculation of the velocity
	      if(velExt != NULL)
		{
		  velExt->setPermutation(locVert, 0);
		}
	      update = elUpdate->calcElementUpdate( coordsOfNodes, boundVal );
	      
	      //for counting tried updates
	      if(count_updates == 1)
		{
		  smiError =
		    SMI_Get_quantity_values(1, 1, 3, SMI_TYPE_INT, 1, 1,
					    &nodeIndices[locVert], &value_q3);
		  TEST_EXIT(smiError == SMI_OK)
		    ("SMI_Get_quantity_values() failed with error %d\n", 
		     smiError);

		  value_q3 = value_q3 + 1;

		  smiError = 
		    SMI_Set_quantity_values(1, 1, 3, SMI_TYPE_INT, 1, 1,
					    const_cast<DegreeOfFreedom*>(&nodeIndices[locVert]),
					    &value_q3);
		  TEST_EXIT(smiError == SMI_OK)
		    ("SMI_Set_quantity_values() failed with error %d\n", 
		     smiError);
		}
	      
	      //checking whether the calculated update will be set as new distance
	      if (update < (*boundVal_DOF)[nodeIndices[locVert]] && ((*boundVal_DOF)[nodeIndices[locVert]]-update) > tol)
		{
		  (*boundVal_DOF)[nodeIndices[locVert]] = update;
		  //If distance is corrected, calculate new velocity.
		  if(velExt != NULL)
		    {
		      velExt->calcVelocity(nodeIndices, locVert);
		    }

		  //for counting successful updates
		  if(count_updates == 1)
		    {
		      smiError =
			SMI_Get_quantity_values(1, 1, 4, SMI_TYPE_INT, 1, 1,
						&nodeIndices[locVert],
						&value_q4); 
		      TEST_EXIT(smiError == SMI_OK)
			("SMI_Get_quantity_values() failed with error %d\n", 
			 smiError);

		      value_q4 = value_q4 + 1;

		      smiError =
			SMI_Set_quantity_values(1, 1, 4, SMI_TYPE_INT, 1, 1,
						const_cast<DegreeOfFreedom*>(&nodeIndices[locVert]),
						&value_q4);
		      TEST_EXIT(smiError == SMI_OK)
			("SMI_Set_quantity_values() failed with error %d\n", 
			 smiError);
		    }
		  //??
		  Continue = search_and_include_comb(El_Vert.ElNum, 
						     Vert, nodeIndices, j);
		} 
	      
	      smiError =
		SMI_Get_quantity_values(1, 1, 1, SMI_TYPE_INT, dim+1, 1,
					&El_Vert.ElNum, valuesINT);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Get_quantity_values() failed with error %d\n", 
		 smiError);

	      Level_[j].pop();
	      valuesINT[locVert] = 0;

	      smiError =
		SMI_Set_quantity_values(1, 1, 1, SMI_TYPE_INT, dim+1, 1,
					&El_Vert.ElNum, valuesINT);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Set_quantity_values() failed with error %d\n", 
		 smiError);
	      
	      //counts how often a node is saved in the list of lists
	      if(count_in_list == 1)
		{
		  smiError =
		    SMI_Get_elems(1, 1, 1, 
				  const_cast<DegreeOfFreedom*>(&(El_Vert.ElNum)), 
				  NULL, &nodeIndicesOfElem, NULL, NULL);
		  TEST_EXIT(smiError == SMI_OK)
		    ("SMI_Get_elems() failed with error %d\n", smiError);
		  
		  smiError =
		    SMI_Get_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
					    const_cast<DegreeOfFreedom*>(& nodeIndicesOfElem[El_Vert.VertNum]),
					    &value_q5);
		  TEST_EXIT(smiError == SMI_OK)
		    ("SMI_Get_quantity_values() failed with error %d\n", 
		     smiError);

		  value_q5 = value_q5 - 1;

		  smiError =
		    SMI_Set_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
					    const_cast<DegreeOfFreedom*>(& nodeIndicesOfElem[El_Vert.VertNum]),
					    &value_q5);
		  TEST_EXIT(smiError == SMI_OK)
		    ("SMI_Set_quantity_values() failed with error %d\n", 
		     smiError);
		}
	      
	      //for printing which node is how often saved in a list after a special number of tried updates
	      if(count_in_list == 1)
		{
		  counter_list++;
		  if(counter_list % print_in_list == 0)
		    {
		      print_quantity_5(counter_list);
		    }
		}	 
	    }
	}
      //for printing which node is how often saved in a list at the end of the ..th traverse of the list "Level_"
      if(count_in_list == 1)
	{
	  counter_lists_of_lists++;
	  if(counter_lists_of_lists == print_in_list_2)
	    {
	      print_quantity_5(counter_lists_of_lists);
	    }
	}
      
    }
  
  delete [] coords;
  delete [] valuesINT;
  for ( int i=0; i<Global::getGeo(VERTEX,dim); i++)
    {
      delete coordsOfNodes[i];
    }
}

bool 
HL_SignedDistLevels::search_and_include_comb(int ElNum, 
					     int Vert, 
					     int *nodeIndices, 
					     const int Index)
{
  bool stop_l = false;
  bool stop_r = false;
  bool Continue = false;
  bool continue_out = false;
  int neighbour_l;
  int neighbour_r;
  int Vert_1_l;
  int Vert_2_l;
  int Vert_1_r;
  int Vert_2_r;
  int counter;
  int elem_l;
  int elem_r;
  int node_l;
  int node_r;
  int VertGlobal;
  int *nodeIndicesOfElem;
  
  int smiError = 
    SMI_Get_elems(1, 1, 1, const_cast<DegreeOfFreedom*>(&(ElNum)), NULL, 
		  &nodeIndicesOfElem, NULL, NULL);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_elems() failed with error %d\n", smiError);

  VertGlobal = nodeIndicesOfElem[Vert];
  
  //here the process of including elements/nodes into the second list
  stop_l = false;
  stop_r = false;	      
  
  elem_l = ElNum;
  if (elem_l == -1)
    {
      stop_l = true;
    }
  elem_r = ElNum;
  if (elem_r == -1)
    {
      stop_r = true;
    }
  
  counter = 0;
  for (int i=0; i<=dim; i++)
    {
      if(i != Vert && counter == 1)  
	{
	  node_r = i;                
	  counter = counter + 1;
	}
      if(i != Vert && counter == 0)  
	{
	  node_l = i;                
	  counter = counter + 1;
	}
      
    }
  
  while (!stop_l || !stop_r)
    {
      //get next neighbour
      if (!stop_l)
	{
	  stop_l = getNextNeighbour (elem_l, VertGlobal, node_l, neighbour_l, Vert_1_l, Vert_2_l);
	}
      if(!stop_r)
	{
	  stop_r = getNextNeighbour (elem_r, VertGlobal, node_r, neighbour_r, Vert_1_r, Vert_2_r);
	}
      
      if(neighbour_l == elem_r)
	{
	  break;
	}
      
      //indclude into the second list (only if possible)
      if (!stop_l)
	{
	  Continue = includeIntoList (neighbour_l, Vert_1_l, Vert_2_l, Index);
	  if(Continue == true)
	    {
	      continue_out = Continue;
	    }
	  if(neighbour_l == neighbour_r)
	    {
	      break;
	    }
	  //"elem_l", "node_l", "elem_r", "node_r" have to be set on the next elements
	  node_l = getNext_node_l_r(elem_l,neighbour_l, node_l,VertGlobal);
	  elem_l = neighbour_l;
	  
	}
      if (!stop_r && neighbour_l != neighbour_r)
	{
	  Continue = includeIntoList (neighbour_r, Vert_1_r, Vert_2_r, Index);
	  if(Continue == true)
	    {
	      continue_out = Continue;
	    }
	  //"elem_l", "node_l", "elem_r", "node_r" have to be set on the next elements
	  node_r = getNext_node_l_r(elem_r,neighbour_r, node_r, VertGlobal);
	  elem_r = neighbour_r;
	}
    }
  return continue_out;                  
}

bool 
HL_SignedDistLevels::includeIntoList (int ElNum_in, 
				      int VertNum_1_in, 
				      int VertNum_2_in, 
				      const int Index)
{
  Vert_Struct vertStruct_0;
  Vert_Struct vertStruct_1;
  
  int *nodeIndices;
  int *valuesINT = new int[dim+1];
  int *locVert = new int[dim];
  int value_q2;
  int value_q5;
  int value_q6;
  int smiError;
  
  bool Continue = false;
  
  if(ElNum_in != -1)
    {
      smiError = 
	SMI_Get_elems(1, 1, 1, &ElNum_in, NULL, &nodeIndices, NULL, NULL); 
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_elems() failed with error %d\n", smiError);
      
      smiError =
	SMI_Get_quantity_values(1, 1, 1, SMI_TYPE_INT, dim+1, 1,
				const_cast<DegreeOfFreedom*>(&ElNum_in),
				valuesINT);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_quantity_values() failed with error %d\n", smiError);
      
      //if the pair of element and node isn't saved in any List and if it isn't a boundary-node include into adapting list
      smiError = SMI_Get_quantity_values(1, 1, 2, SMI_TYPE_INT, 1, 1, 
					 &nodeIndices[VertNum_1_in], 
					 &value_q2);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_quantity_values() failed with error %d\n", smiError);

      if(valuesINT[VertNum_1_in] == 0 && value_q2 == 0)
	{
	  vertStruct_0.ElNum = ElNum_in;
	  vertStruct_0.VertNum = VertNum_1_in;

	  smiError =
	    SMI_Get_quantity_values (1, 1, 6, SMI_TYPE_INT, 1, 1, &ElNum_in,
				     &value_q6); 
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Get_quantity_values() failed with error %d\n", smiError);

	  Level_[value_q6-1].push( vertStruct_0 );
	  
	  //counts how often a node is saved in the list of lists
	  if(count_in_list == 1)
	    {
	      smiError =
		SMI_Get_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
					const_cast<DegreeOfFreedom*>(& nodeIndices[vertStruct_0.VertNum]),
					&value_q5);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Get_quantity_values() failed with error %d\n", 
		 smiError);

	      value_q5 = value_q5 + 1;

	      smiError =
		SMI_Set_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
					const_cast<DegreeOfFreedom*>(& nodeIndices[vertStruct_0.VertNum]),
					&value_q5);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Set_quantity_values() failed with error %d\n", 
		 smiError);
	    }
	  
	  if(value_q6-1 < Index)
	    {
	      Continue = true;
	    }
	  
	  valuesINT[VertNum_1_in] = 1;

	  smiError =
	    SMI_Set_quantity_values(1, 1, 1, SMI_TYPE_INT, dim+1, 1,
// 				    &ElNum_in, &valuesINT);
				    &ElNum_in, valuesINT);
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Set_quantity_values() failed with error %d\n", smiError);
	}
      
      smiError =
	SMI_Get_quantity_values(1, 1, 2, SMI_TYPE_INT, 1, 1, 
				&nodeIndices[VertNum_2_in], &value_q2);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_quantity_values() failed with error %d\n", smiError);

      if(valuesINT[VertNum_2_in] == 0 && value_q2 == 0)
	{
	  vertStruct_1.ElNum = ElNum_in;
	  vertStruct_1.VertNum = VertNum_2_in;

	  smiError =
	    SMI_Get_quantity_values(1, 1, 6, SMI_TYPE_INT, 1, 1, &ElNum_in,
				    &value_q6); 
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Get_quantity_values() failed with error %d\n", smiError);

	  Level_[value_q6-1].push( vertStruct_1 );
	  
	  //counts how often a node is saved in the list of lists
	  if(count_in_list == 1)
	    {
	      smiError =
		SMI_Get_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
					const_cast<DegreeOfFreedom*>(& nodeIndices[vertStruct_1.VertNum]),
					&value_q5);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Get_quantity_values() failed with error %d\n", 
		 smiError);

	      value_q5 = value_q5 + 1;

	      smiError =
		SMI_Set_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, 1,
					const_cast<DegreeOfFreedom*>(& nodeIndices[vertStruct_1.VertNum]),
					&value_q5);
	      TEST_EXIT(smiError == SMI_OK)
		("SMI_Set_quantity_values() failed with error %d\n", 
		 smiError);
	    }
	  
	  if(value_q6-1 < Index)
	    {
	      Continue = true;
	    }
	  
	  valuesINT[VertNum_2_in] = 1;
	  
	  smiError =
	    SMI_Set_quantity_values(1, 1, 1, SMI_TYPE_INT, dim+1, 1, 
				    &ElNum_in,
				    //&valuesINT);
				    valuesINT); 
	  TEST_EXIT(smiError == SMI_OK)
	    ("SMI_Set_quantity_values() failed with error %d\n", smiError);
	}
    }
  
  delete [] valuesINT;
  delete [] locVert;
  
  return Continue;
}

bool 
HL_SignedDistLevels::getNextNeighbour (const int ElNum_in, 
				       const int Vert_Up_in, 
				       const int VertNum_in, 
				       int &ElNum_out, 
				       int &VertNum_1_out, 
				       int &VertNum_2_out)
{
  int *neighbour = new int[dim+1];
  int *oppVertices = new int[dim+1];
  int *nodeIndicesOfElem;
  int smiError;
  
  smiAdapter->getNeighbourInfo(ElNum_in, neighbour,oppVertices);
  
  ElNum_out = neighbour [VertNum_in];
  
  if(ElNum_out != -1)
    {
      smiError =
	SMI_Get_elems(1, 1, 1, const_cast<DegreeOfFreedom*>(&(ElNum_out)),
		      NULL, &nodeIndicesOfElem, NULL, NULL);
      TEST_EXIT(smiError == SMI_OK)
	("SMI_Get_elems() failed with error %d\n", smiError);

      VertNum_1_out = oppVertices[VertNum_in];
      for (int i=0; i<=dim; i++)
	{
	  if (nodeIndicesOfElem[i] != Vert_Up_in && i != VertNum_1_out)  
	    {  
	      VertNum_2_out = i;    
	    }
	}
    }
  
  delete [] neighbour;
  delete [] oppVertices;
  
  if (ElNum_out == -1)
    {
      return true;
    }
  
  return false;
  
} 

int 
HL_SignedDistLevels::getNext_node_l_r (int elem_l_r_in,
				       int neighbour_l_r_in, 
				       int node_l_r_in, 
				       const int Vert)
{
  FUNCNAME("getNext_node_l_r()");

  int *nodeIndicesOfElem;
  int *nodeIndicesOfNeighbour = new int[dim+1];
  int globalNextNode_l_r_out;
  
  int smiError =
    SMI_Get_elems(1, 1, 1, const_cast<DegreeOfFreedom*>(&neighbour_l_r_in),
		  NULL, &nodeIndicesOfElem, NULL, NULL);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_elems() failed with error %d\n", smiError);

  for(int i=0; i<=dim; i++)
    {
      nodeIndicesOfNeighbour[i] = nodeIndicesOfElem[i];
    }

  smiError =
    SMI_Get_elems(1, 1, 1, const_cast<DegreeOfFreedom*>(&elem_l_r_in),
		  NULL, &nodeIndicesOfElem, NULL, NULL);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_elems() failed with error %d\n", smiError);
  
  for (int i=0; i<=dim; i++)
    {
      if(nodeIndicesOfElem[i] != Vert && i != node_l_r_in) 
	{
	  globalNextNode_l_r_out = nodeIndicesOfElem[i];
	}
    }
  for (int i=0; i<=dim; i++)
    {
      if(nodeIndicesOfNeighbour[i] == globalNextNode_l_r_out) 
	{
	  return i;
	}
    }

  ERROR_EXIT("should never be reached !\n");
  return 0;
}

void 
HL_SignedDistLevels::print_quantity_5 (int cntr)
{
  int numNodes;
  int*nodeIndices;
  double *coords = new double[dim];

  int smiError =
    SMI_Get_all_nodes(1, 1, const_cast<DegreeOfFreedom*>(&numNodes),
		      &nodeIndices);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_alls() failed with error %d\n", smiError);

  int *values_q5 = new int [numNodes];
  
  std::string q5_OutFile_0;
  std::string q5_OutFile_1;
  std::string q5_OutFile_2;
  std::string q5_OutFile_3;
  std::string q5_OutFile_4;
  
  GET_PARAMETER(0, "SignedDist->count saving->output->filename_0", &q5_OutFile_0);
  GET_PARAMETER(0, "SignedDist->count saving->output->filename_1", &q5_OutFile_1);
  GET_PARAMETER(0, "SignedDist->count saving->output->filename_2", &q5_OutFile_2);
  GET_PARAMETER(0, "SignedDist->count saving->output->filename_3", &q5_OutFile_3);
  GET_PARAMETER(0, "SignedDist->count saving->output->filename_4", &q5_OutFile_4);
  
  
  char cntrStr[20];
  sprintf(cntrStr, "%d", cntr);
  q5_OutFile_0 += cntrStr;
  q5_OutFile_1 += cntrStr;
  q5_OutFile_2 += cntrStr;
  q5_OutFile_3 += cntrStr;
  q5_OutFile_4 += cntrStr;
  
  cout << "count saving Ausgabe-Datei_0:  " << q5_OutFile_0.c_str() << "\n\n";
  cout << "count saving Ausgabe-Datei_1:  " << q5_OutFile_1.c_str() << "\n\n";
  cout << "count saving Ausgabe-Datei_2:  " << q5_OutFile_2.c_str() << "\n\n";
  cout << "count saving Ausgabe-Datei_3:  " << q5_OutFile_3.c_str() << "\n\n";
  cout << "count saving Ausgabe-Datei_4:  " << q5_OutFile_4.c_str() << "\n\n";
  
  ofstream out_0 (q5_OutFile_0.c_str());
  ofstream out_1 (q5_OutFile_1.c_str());
  ofstream out_2 (q5_OutFile_2.c_str());
  ofstream out_3 (q5_OutFile_3.c_str());
  ofstream out_4 (q5_OutFile_4.c_str());

  smiError =  
    SMI_Get_quantity_values(1, 1, 5, SMI_TYPE_INT, 1, numNodes, nodeIndices,
			    values_q5);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_quantity_values() failed with error %d\n", smiError);
  
  for (int i=0; i<numNodes; i++)
    {
      smiError =
	SMI_Get_nodes (1, 1, 1, dim, 
		       const_cast<DegreeOfFreedom*>(&nodeIndices[i]),
		       coords);
      
      if(values_q5[i] == 0)
	{
	  out_0<<coords[0]<<" "<<coords[1]<<"\n";
	}
      if(values_q5[i] == 1)
	{
	  out_1<<coords[0]<<" "<<coords[1]<<"\n";
	}
      if(values_q5[i] == 2)
	{
	  out_2<<coords[0]<<" "<<coords[1]<<"\n";
	}
      if(values_q5[i] == 3)
	{
	  out_3<<coords[0]<<" "<<coords[1]<<"\n";
	}
      if(values_q5[i] >= 4)
	{
	  out_4<<coords[0]<<" "<<coords[1]<<"\n";
	}
      
      
    }
  
  out_0.close();
  out_1.close();
  out_2.close();
  out_3.close();
  out_4.close();
  
  delete [] coords;
  delete [] values_q5;
}

void 
HL_SignedDistLevels::print_quantity_6 ()
{
  std::string smiOutFile2;
  GET_PARAMETER(0, "SignedDist->print levels->filename2", &smiOutFile2);
  cout << "count levels Ausgabe-Datei:  " << smiOutFile2.c_str() << "\n\n";
  
  ofstream out2 (smiOutFile2.c_str());
  
  int numElems;
  int *elemIndices;
  
  int smiError = SMI_Get_all_elems(1, 1, &numElems, &elemIndices);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_all_elems() failed with error %d\n", smiError);
  
  int *value_q6 = new int [numElems];
  
  smiError =
    SMI_Get_quantity_values(1, 1, 6, SMI_TYPE_INT, 1, numElems, elemIndices,
			    value_q6);
  TEST_EXIT(smiError == SMI_OK)
    ("SMI_Get_quantity_values() failed with error %d\n", smiError);

  int cl=0;
  for (int i=0; i<numElems; i++)
    {
      out2<<elemIndices[i]<<" "<<value_q6[i]<<"\n";
      
      if(value_q6[i] == 100000)
	{
	  cl=cl +1;
	}
    }
  
  out2.close();
}