Debian Codegraph @

dune/uggrid/gm/gmcheck.cc

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 /****************************************************************************/
4 /* */
5 /* File: gmcheck.c */
6 /* */
7 /* Purpose: checks of the data structure */
8 /* */
9 /* Author: Stefan Lang */
10 /* Institut fuer Computeranwendungen III */
11 /* Universitaet Stuttgart */
12 /* Pfaffenwaldring 27 */
13 /* 70569 Stuttgart */
14 /* email: [email protected] */
15 /* */
16 /* History: Juli 1, 1997 moved from ugm.c */
17 /* */
18 /* Remarks: */
19 /* */
20 /****************************************************************************/
21
22 /****************************************************************************/
23 /* */
24 /* defines to exclude functions */
25 /* */
26 /****************************************************************************/
27
28 /****************************************************************************/
29 /* */
30 /* include files */
31 /* system include files */
32 /* application include files */
33 /* */
34 /****************************************************************************/
35
36 #include <config.h>
37 #include <cstdlib>
38 #include <cstddef>
39 #include <cstdio>
40 #include <cstring>
41 #include <cmath>
42 #include <cassert>
43 #include <errno.h>
44
45 #include <dune/uggrid/low/debug.h>
46 #include <dune/uggrid/low/fifo.h>
47 #include <dune/uggrid/low/heaps.h>
48 #include <dune/uggrid/low/misc.h>
49 #include <dune/uggrid/low/ugenv.h>
50 #include <dune/uggrid/low/ugtypes.h>
51
52 #include <dune/uggrid/ugdevices.h>
53
54 #include "evm.h"
55 #include "gm.h"
56 #include "rm.h"
57 #include "dlmgr.h"
58 #include "algebra.h"
59 #include "ugm.h"
60 #include "elements.h"
61 #include "shapes.h"
62 #include "refine.h"
63 #include <dune/uggrid/domain/std_domain.h>
64
65 #ifdef ModelP
66 #include <dune/uggrid/parallel/dddif/parallel.h>
67 #endif
68
69 #include "cw.h"
70
71 USING_UG_NAMESPACES
72 using namespace PPIF;
73
74 /****************************************************************************/
75 /* */
76 /* data structures used in this source file (exported data structures are */
77 /* in the corresponding include file!) */
78 /* */
79 /****************************************************************************/
80
81 /****************************************************************************/
82 /* */
83 /* definition of exported global variables */
84 /* */
85 /****************************************************************************/
86
87
88 /****************************************************************************/
89 /* */
90 /* definition of variables global to this source file only (static!) */
91 /* */
92 /****************************************************************************/
93
94 #ifdef ModelP
95 #if defined(UG_DIM_2)
96 static DOUBLE hghost_overlap = 1.0;
97 #endif
98 #endif
99
100 /****************************************************************************/
101 /* */
102 /* forward declarations of functions used before they are defined */
103 /* */
104 /****************************************************************************/
105
106 static INT CheckVertex (ELEMENT *theElement, NODE* theNode, VERTEX *theVertex)
107 {
108 ELEMENT *theFather = VFATHER(theVertex);
109 EDGE *theEdge;
110 INT i,nerrors,n;
111 DOUBLE diff;
112 DOUBLE_VECTOR global1;
113 DOUBLE *x[MAX_CORNERS_OF_ELEM];
114
115 nerrors = 0;
116 if (SONNODE(theNode) == NULL)
117 {
118 INT cnt = NOOFNODE(theVertex);
119 NODE *Node = theNode;
120
121 while (Node!=NULL && CORNERTYPE(Node)) {
122 cnt--;
123 Node = (NODE*) NFATHER(Node);
124 }
125 if (cnt != 1) {
126 UserWriteF("elem=" EID_FMTX " node=" ID_FMTX
127 " vertex=" VID_FMTX
128 " NOOFNODE %d wrong\n",
129 EID_PRTX(theElement),ID_PRTX(theNode),
130 VID_PRTX(theVertex), NOOFNODE(theVertex));
131 nerrors = 1;
132 }
133 }
134
135 if (theFather==NULL && MASTER(theNode) && LEVEL(theVertex)>0)
136 {
137 #ifdef ModelP
138 if (!CORNERTYPE(theNode))
139 {
140 nerrors = 0;
141 IFDEBUG(gm,1)
142 nerrors = 1;
143 ENDDEBUG
144 }
145 if (nerrors == 0) return(nerrors);
146 #endif
147 UserWriteF("elem=" EID_FMTX " node=" ID_FMTX " vertex=" VID_FMTX
148 " VFATHER=NULL vertex needs VFATHER\n",EID_PRTX(theElement),ID_PRTX(theNode),
149 VID_PRTX(theVertex));
150 return(nerrors++);
151 }
152
153 if (theFather!=NULL && MASTER(theNode) && EPRIO(theFather)==PrioHGhost)
154 {
155 #ifdef ModelP
156 if (!CORNERTYPE(theNode))
157 {
158 nerrors = 0;
159 IFDEBUG(gm,1)
160 nerrors = 1;
161 ENDDEBUG
162 }
163 #endif
164 if (nerrors == 0) return(nerrors);
165 UserWriteF("elem=" EID_FMTX " node=" ID_FMTX " vertex=" VID_FMTX
166 " VFATHER=" EID_FMTX " vertex needs VFATHER with prio master or vghost\n",
167 EID_PRTX(theElement),ID_PRTX(theNode),VID_PRTX(theVertex),EID_PRTX(theFather));
168 return(nerrors++);
169 }
170
171 if (theFather != NULL) {
172 CORNER_COORDINATES(theFather,n,x);
173 const Dune::FieldVector<DOUBLE,DIM>& global = CVECT(theVertex);
174 const Dune::FieldVector<DOUBLE,DIM>& local = LCVECT(theVertex);
175 LOCAL_TO_GLOBAL(n,x,local,global1);
176 V_DIM_EUKLIDNORM_OF_DIFF(global1,global,diff);
177 if (diff > MAX_PAR_DIST) {
178 nerrors++;
179 #ifdef ModelP
180 if (CORNERTYPE(theNode) || GHOST(theNode))
181 {
182 nerrors = 0;
183 IFDEBUG(gm,1)
184 nerrors = 1;
185 ENDDEBUG
186 }
187 #endif
188 if (nerrors >= 1)
189 {
190 UserWriteF("elem=" EID_FMTX " node=" ID_FMTX "/%d vertex=" VID_FMTX
191 " WARNING VFATHER=%x WARNING diff %f local and global coordinates don't match\n",
192 EID_PRTX(theElement),ID_PRTX(theNode),
193 NTYPE(theNode),VID_PRTX(theVertex),theFather,diff);
194 }
195 }
196 }
197
198 switch (NTYPE(theNode))
199 {
200 case (CORNER_NODE) :
201 if (LEVEL(theVertex)==0 && theFather != NULL)
202 {
203 UserWriteF("EID=" EID_FMTX " NID=" ID_FMTX
204 " VID=" VID_FMTX " CORNER_NODE has VFATHER\n",
205 EID_PRTX(theElement),ID_PRTX(theNode),VID_PRTX(theVertex));
206 }
207
208 #ifdef ModelP
209 IFDEBUG(gm,0)
210 /* break for ghost nodes if debugging off */
211 if (GHOST(theNode)) break;
212 ENDDEBUG
213 #endif
214
215 if (LEVEL(theVertex)>0 && theFather == NULL)
216 {
217 UserWriteF("EID=" EID_FMTX " NID=" ID_FMTX
218 " VID=" VID_FMTX " CORNER_NODE has no VFATHER\n",
219 EID_PRTX(theElement),ID_PRTX(theNode),VID_PRTX(theVertex));
220 }
221 break;
222
223 case (MID_NODE) :
224 /* check ONEDGE and VFATHER */
225 if (theFather == NULL)
226 {
227 #ifdef ModelP
228 IFDEBUG(gm,0)
229 /* break for ghost nodes if debugging off */
230 if (GHOST(theNode)) break;
231 ENDDEBUG
232 #endif
233
234 UserWriteF("EID=" EID_FMTX " NID=" ID_FMTX
235 " VID=" VID_FMTX " MID_NODE VFATHER=NULL\n",
236 EID_PRTX(theElement),ID_PRTX(theNode),VID_PRTX(theVertex));
237 nerrors++;
238 break;
239 }
240 i = ONEDGE(theVertex);
241 theEdge = GetEdge(CORNER(theFather,CORNER_OF_EDGE(theFather,i,0)),
242 CORNER(theFather,CORNER_OF_EDGE(theFather,i,1)));
243
244 if (theEdge==NULL || theNode!=MIDNODE(theEdge))
245 {
246 nerrors++;
247 #ifdef ModelP
248 if (EGHOST(theElement)) {
249 nerrors = 0;
250 IFDEBUG(gm,1)
251 nerrors = 1;
252 ENDDEBUG
253 }
254 #endif
255 if (nerrors == 0) break;
256 UserWriteF("EID=" EID_FMTX " NID=" ID_FMTX " VID=" VID_FMTX
257 " ONEDGE and VFATHER incompatible edgeptr=%08x\n",
258 EID_PRTX(theElement),ID_PRTX(theNode),
259 VID_PRTX(theVertex),theEdge);
260 }
261 break;
262
263 #ifdef UG_DIM_3
264 case (SIDE_NODE) :
265 if (theFather == NULL)
266 {
267 nerrors++;
268 #ifdef ModelP
269 if (EPRIO(theElement)==PrioHGhost) {
270 nerrors = 0;
271 IFDEBUG(gm,1)
272 nerrors = 1;
273 ENDDEBUG
274 }
275 #endif
276 if (nerrors == 0) break;
277 UserWriteF("EID=" EID_FMTX " NID=" ID_FMTX
278 " VID=" VID_FMTX " SIDE_NODE VFATHER=NULL\n",
279 EID_PRTX(theElement),ID_PRTX(theNode),VID_PRTX(theVertex));
280 break;
281 }
282 else {
283 if (GetSideNode(theFather,ONSIDE(theVertex)) != theNode) {
284 nerrors = 1;
285 UserWriteF("EID=" EID_FMTX " NID=" ID_FMTX
286 " VID=" VID_FMTX " inconsistent ONSIDE entry\n",
287 EID_PRTX(theElement),ID_PRTX(theNode),
288 VID_PRTX(theVertex));
289 }
290 }
291 break;
292 #endif
293
294 case (CENTER_NODE) :
295 if (theFather == NULL)
296 {
297 nerrors++;
298 #ifdef ModelP
299 if (EGHOST(theElement)) {
300 nerrors = 0;
301 IFDEBUG(gm,1)
302 nerrors = 1;
303 ENDDEBUG
304 }
305 #endif
306 if (nerrors == 0) break;
307 UserWriteF("EID=" EID_FMTX " NID=" ID_FMTX
308 " VID=" VID_FMTX " CENTER_NODE VFATHER=NULL\n",
309 EID_PRTX(theElement),ID_PRTX(theNode),VID_PRTX(theVertex));
310 break;
311 }
312 break;
313 }
314
315 return(nerrors);
316 }
317
318 static INT CheckNode (ELEMENT *theElement, NODE* theNode, INT i)
319 {
320 VERTEX *theVertex = MYVERTEX(theNode);
321 NODE *FatherNode;
322 EDGE *FatherEdge;
323 INT nerrors = 0;
324
325 SETUSED(theNode,1);
326
327 if (OBJT(theNode) != NDOBJ)
328 {
329 UserWriteF(" node=" ID_FMTX " has wrong OBJ=%d\n",
330 ID_PRTX(theNode),OBJT(theNode));
331 return(nerrors++);
332 }
333
334 switch (NTYPE(theNode))
335 {
336 case (LEVEL_0_NODE) :
337 if (LEVEL(theNode) > 0) {
338 UserWriteF(" node=" ID_FMTX " has NTYPE=LEVEL_0_NODE"
339 " but is on level=%d\n",
340 ID_PRTX(theNode),LEVEL(theNode));
341 return(nerrors++);
342 }
343 break;
344 case (CORNER_NODE) :
345 {
346 FatherNode = (NODE *)NFATHER(theNode);
347 if (0) /* this code is for special debugging (980204 s.l.) */
348 if (GID(theNode)==0x11011 && FatherNode!=NULL)
349 {
350 UserWriteF(" cornernode=" ID_FMTX " has father=" ID_FMTX "\n",
351 ID_PRTX(theNode),ID_PRTX(FatherNode));
352 }
353
354 if (FatherNode == NULL)
355 {
356 #ifdef ModelP
357 if (MASTER(theNode))
358 {
359 #endif
360 UserWriteF(" ERROR cornernode=" ID_FMTX " has no father level=%d\n",
361 ID_PRTX(theNode),LEVEL(theNode));
362 UserWriteF(" elem=" EID_FMTX, EID_PRTX(theElement));
363 if (EFATHER(theElement) != NULL)
364 {
365 ELEMENT *theFather = EFATHER(theElement);
366
367 UserWriteF(" father=" EID_FMTX "\n",EID_PRTX(theFather));
368 for (int j=0; j < CORNERS_OF_ELEM(theFather); j++)
369 {
370 UserWriteF("son[%d]=" ID_FMTX "\n",j,ID_PRTX(CORNER(theFather,j)));
371 }
372 }
373 else
374 UserWriteF(" father=NULL\n");
375
376 nerrors++;
377 #ifdef ModelP
378 }
379 else
380 {
381 INT print = 0;
382 IFDEBUG(gm,1)
383 print = 1;
384 ENDDEBUG
385 if (print)
386 UserWriteF(" WARN cornernode=" ID_FMTX " has no father level=%d\n",
387 ID_PRTX(theNode),LEVEL(theNode));
388 }
389 #endif
390 }
391 if (FatherNode != NULL)
392 {
393 if (OBJT(FatherNode) != NDOBJ)
394 {
395 UserWriteF(" cornernode=" ID_FMTX
396 " has father of wrong type=%d\n",
397 ID_PRTX(theNode),OBJT(FatherNode));
398 nerrors++;
399 }
400 else
401 {
402 if (SONNODE(FatherNode) != theNode)
403 {
404 UserWriteF(" cornernode=" ID_FMTX
405 " has node father=" ID_FMTX " with wrong backptr=%x\n",
406 ID_PRTX(theNode),ID_PRTX(FatherNode),SONNODE(FatherNode));
407 /* TODO: this should be deleted */
408 if (0) SONNODE(FatherNode) = theNode;
409 else nerrors++;
410 }
411 }
412 }
413 }
414 break;
415
416 case (MID_NODE) :
417 if (LEVEL(theNode)>0)
418 {
419 FatherEdge = (EDGE *)NFATHER(theNode);
420 if (FatherEdge == NULL)
421 {
422 #ifdef ModelP
423 if (MASTER(theNode))
424 {
425 #endif
426 UserWriteF(" ERROR midnode=" ID_FMTX " has no father level=%d\n",
427 ID_PRTX(theNode),LEVEL(theNode));
428 UserWriteF(" elem=" EID_FMTX, EID_PRTX(theElement));
429 if (EFATHER(theElement) != NULL)
430 UserWriteF(" father=" EID_FMTX "\n",EID_PRTX(EFATHER(theElement)));
431 else
432 UserWriteF(" father=NULL\n");
433 nerrors++;
434 #ifdef ModelP
435 }
436 else
437 {
438 IFDEBUG(gm,1)
439 UserWriteF(" WARN midnode=" ID_FMTX " has no father level=%d\n",
440 ID_PRTX(theNode),LEVEL(theNode));
441 ENDDEBUG
442 }
443 #endif
444 }
445 if (FatherEdge != NULL)
446 {
447 if (OBJT(FatherEdge) != EDOBJ)
448 {
449 UserWriteF(" midnode=" ID_FMTX
450 " has father of wrong type=%d obj=\n",
451 ID_PRTX(theNode),OBJT(FatherEdge));
452 nerrors++;
453 }
454 else
455 {
456
457 if (MIDNODE(FatherEdge) != theNode)
458 {
459 UserWriteF(" midnode=" ID_FMTX
460 " has edge father=" ID_FMTX " with wrong backptr=%x\n",
461 ID_PRTX(theNode),ID_PRTX(FatherEdge),MIDNODE(FatherEdge));
462 /* TODO: this should be deleted */
463 if (0) MIDNODE(FatherEdge) = theNode;
464 else nerrors++;
465 /*nerrors++; temp. auskommentiert, um Reperaturwirkung wirklich nutzen zu koennen */
466 }
467 }
468 }
469 }
470 else
471 {
472 UserWriteF(" node=" ID_FMTX " is midnode BUT on level=%d\n",
473 ID_PRTX(theNode),LEVEL(theNode));
474 nerrors++;
475 }
476 break;
477
478 case (SIDE_NODE) :
479 break;
480
481 case (CENTER_NODE) :
482 break;
483
484 default :
485 UserWriteF(" node=" ID_FMTX " has unrecognized NTYPE=%d\n",
486 ID_PRTX(theNode),NTYPE(theNode));
487 break;
488 }
489
490 if (theVertex != NULL)
491 {
492 CheckVertex(theElement,theNode,theVertex);
493 }
494 else
495 {
496 UserWriteF("elem=" EID_FMTX " node[%d]=" ID_FMTX " vertex=NULL\n",
497 EID_PRTX(theElement),i,ID_PRTX(theNode));
498 nerrors++;
499 }
500
501 return(nerrors);
502 }
503
504 static INT CheckEdge (ELEMENT *theElement, EDGE* theEdge, UINT i)
505 {
506 INT nerrors = 0;
507 NODE *theNode;
508 VERTEX *theVertex;
509
510 SETUSED(theEdge,1);
511
512 /** \todo Commented out because it uses GetElemLink, which does not exist */
513 #if 0
514 # if defined(UG_DIM_2)
515 {
516 int elemlink,no_of_elem,No_Of_Elem;
517 NODE *n0,*n1;
518 LINK *l0,*l1;
519 ELEMENT *e0,*e1;
520
521 n0 = CORNER_OF_EDGE_PTR(theElement,i,0);
522 n1 = CORNER_OF_EDGE_PTR(theElement,i,1);
523
524 elemlink = GetElemLink(n0,n1,theElement);
525
526 l0 = LINK0(theEdge);
527 l1 = LINK1(theEdge);
528 e0 = LELEM(l0);
529 e1 = LELEM(l1);
530
531 /* check number of edge neighbor elements */
532 no_of_elem = 0;
533 if (e0 != NULL)
534 {
535 no_of_elem++;
536 HEAPFAULT(e0);
537 }
538 if (e1 != NULL)
539 {
540 no_of_elem++;
541 HEAPFAULT(e1);
542 }
543
544 No_Of_Elem = NO_OF_ELEM(theEdge);
545
546 if (no_of_elem==0 || No_Of_Elem!=no_of_elem)
547 {
548 UserWriteF("elem=" EID_FMTX " edge%d=" EDID_FMTX " NO_OF_ELEM wrong"
549 "NO_OF_ELEM=%d no_of_elem=%d\n",
550 EID_PRTX(theElement),i,EDID_PRTX(theEdge),No_Of_Elem,no_of_elem);
551 }
552
553 if (elemlink == 0)
554 {
555 if (e0 != theElement)
556 {
557 UserWriteF("elem=" EID_FMTX " edge%d=" EDID_FMTX " LELEM0 wrong"
558 "elemlink=%d LELEM0=%08x\n",
559 EID_PRTX(theElement),i,EDID_PRTX(theEdge),elemlink,
560 (e0!=NULL) ? EGID(e0) : 0);
561 nerrors++;
562 }
563 }
564 else
565 {
566 if (e1 != theElement)
567 {
568 UserWriteF("elem=" EID_FMTX " edge%d=" EDID_FMTX " LELEM0 wrong"
569 "elemlink=%d LELEM0=%08x\n",
570 EID_PRTX(theElement),i,EDID_PRTX(theEdge),elemlink,
571 (e1!=NULL) ? EGID(e1) : 0);
572 nerrors++;
573 }
574 }
575 }
576 # endif
577 #endif
578
579 theNode = MIDNODE(theEdge);
580 if (theNode == NULL)
581 {
582 #ifdef DUNE_UGGRID_TET_RULESET
583 if (((REFINE(theElement) == RED) && (TAG(theElement) != TETRAHEDRON))
584 || ((TAG(theElement) == TETRAHEDRON) && (NSONS(theElement) == 8)))
585 #else
586 if (REFINE(theElement) == RED)
587 #endif
588 {
589
590 #ifdef ModelP
591 IFDEBUG(gm,1)
592 #endif
593 UserWriteF("elem=" EID_FMTX " edge%d=" EDID_FMTX " midnode NID=NULL"
594 " BUT REFINE(elem)=RED\n",EID_PRTX(theElement),i,EDID_PRTX(theEdge));
595 nerrors++;
596 #ifdef ModelP
597 ENDDEBUG
598 #endif
599 return(nerrors);
600 }
601 else
602 return(nerrors);
603 }
604
605 theVertex = MYVERTEX(theNode);
606 if (theVertex == NULL)
607 {
608 UserWriteF("elem=" EID_FMTX " edge=%d/%x midnode NID=" ID_FMTX " vertex=NULL\n",
609 EID_PRTX(theElement),i,theEdge,ID_PRTX(theNode));
610 return(nerrors++);
611 }
612
613 if (VFATHER(theVertex) != theElement)
614 return(nerrors);
615
616 if (i != ONEDGE(theVertex))
617 {
618 if (EGHOST(theElement))
619 {
620 IFDEBUG(gm,1)
621 UserWriteF("EID=" EID_FMTX " VID=" VID_FMTX
622 " WARNING edgenumber of vertex wrong\n",
623 EID_PRTX(theElement),VID_PRTX(theVertex));
624 ENDDEBUG
625 }
626 else
627 {
628 UserWriteF("EID=" EID_FMTX " VID=" VID_FMTX
629 " ERROR edgenumber of vertex wrong\n",
630 EID_PRTX(theElement),VID_PRTX(theVertex));
631 /*nerrors++; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
632 }
633 return(nerrors);
634 }
635
636 return(nerrors);
637 }
638
639 #ifdef ModelP
640 int EdgeHasTMasterCopy (DDD::DDDContext& context, ELEMENT *e, int i)
641 {
642 EDGE* edge = GetEdge(CORNER_OF_EDGE_PTR(e,i,0),CORNER_OF_EDGE_PTR(e,i,1));
643 assert(edge != NULL);
644
645 const auto& proclist = DDD_InfoProcListRange(context, PARHDR(edge));
646 const int nmaster = CheckProcListCons(proclist, PrioMaster);
647 const int nborder = CheckProcListCons(proclist, PrioBorder);
648 const int nall = nmaster + nborder;
649 if (0)
650 assert(nall==1 || nall==2);
651
652 if (nall > 2)
653 {
654 UserWriteF("EID=" EID_FMTX " EDID=" EDID_FMTX
655 " ERROR edge%d has mastertype prios=%d\n",
656 EID_PRTX(e),EDID_PRTX(edge),i,nall);
657 }
658
659 return(nall-1);
660 }
661 #endif
662
663 static INT CheckElement (GRID *theGrid, ELEMENT *theElement, INT *SideError, INT *EdgeError,
664 INT *NodeError, INT *ESonError, INT *NSonError, INT *errors)
665 {
666 INT j,k,l,n,nsons,bserror,nerrors;
667 NODE *theNode,*theNode1;
668 EDGE *theEdge;
669 ELEMENT *NbElement,*theFather;
670 ELEMENT *SonList[MAX_SONS];
671 VERTEX *theVertex,*Vertices[MAX_CORNERS_OF_ELEM];
672
673 #if defined(ModelP) && defined(UG_DIM_2)
674 auto& dddContext = theGrid->dddContext();
675 #endif
676
677 *SideError = 0;
678 *NodeError = 0;
679 *EdgeError = 0;
680 *ESonError = 0;
681 *NSonError = 0;
682 nerrors = 0;
683
684 bserror = 0;
685
686 /* check level */
687 if (GLEVEL(theGrid) != LEVEL(theElement))
688 {
689 UserWriteF("elem=" EID_FMTX " ERROR level=%2d but gridlevel=%2d\n",
690 EID_PRTX(theElement),LEVEL(theElement),GLEVEL(theGrid));
691 nerrors++;
692 }
693
694 /* check side information */
695 for (INT i=0; i<SIDES_OF_ELEM(theElement); i++)
696 {
697 if (OBJT(theElement) == BEOBJ)
698 if (ELEM_BNDS(theElement,i) != NULL) {
699 for (j=0; j<CORNERS_OF_SIDE(theElement,i); j++) {
700 k = CORNER_OF_SIDE(theElement,i,j);
701 theNode = CORNER(theElement,k);
702 if (NSUBDOM(theNode) != 0) {
703 UserWriteF("wrong subdomain id(%d) on boundary node,"
704 "el = " EID_FMTX ", side = %d, corner = %d, node = " ID_FMTX "\n",
705 NSUBDOM(theNode),EID_PRTX(theElement),i,k,ID_PRTX(theNode));
706 bserror |= (1<<i);
707 nerrors++;
708 }
709 }
710 for (j=0; j<EDGES_OF_SIDE(theElement,i); j++) {
711 k = EDGE_OF_SIDE(theElement,i,j);
712 theEdge = GetEdge(CORNER(theElement,
713 CORNER_OF_EDGE(theElement,k,0)),
714 CORNER(theElement,
715 CORNER_OF_EDGE(theElement,k,1)));
716 ASSERT(theEdge != NULL);
717 if (EDSUBDOM(theEdge) != 0) {
718 UserWriteF("wrong subdomain id(%d) on boundary edge %d,"
719 "el = " EID_FMTX ", side = %d, edge = %d, corner0 = " ID_FMTX ", corner1 = " ID_FMTX "\n",
720 EDSUBDOM(theEdge),k,EID_PRTX(theElement), i, j,
721 ID_PRTX(CORNER(theElement,CORNER_OF_EDGE(theElement,k,0))),
722 ID_PRTX(CORNER(theElement,CORNER_OF_EDGE(theElement,k,1))));
723 bserror |= (1<<i);
724 nerrors++;
725 }
726 }
727 }
728
729 /* TODO remove self healing */
730 if (0)
731 if (NBELEM(theElement,i)!=NULL)
732 if (ID(NBELEM(theElement,i)) == -1)
733 {
734 if (EGHOST(theElement))
735 {
736 SET_NBELEM(theElement,i,NULL);
737 UserWriteF("elem=" EID_FMTX " correcting nb error\n",
738 EID_PRTX(theElement));
739 }
740 }
741
742 NbElement = NBELEM(theElement,i);
743 if (NbElement != NULL)
744 {
745 /* lets see if NbElement has the neighbor theElement */
746 for (j=0; j<SIDES_OF_ELEM(NbElement); j++)
747 if (NBELEM(NbElement,j) == theElement)
748 break;
749 if (j == SIDES_OF_ELEM(NbElement))
750 {
751 *SideError |= (1<<i);
752 UserWriteF("elem=" EID_FMTX " has side error\n",
753 EID_PRTX(theElement));
754 nerrors++;
755 }
756 else
757 {
758 /* if this is a boundary side it has to be an inner boundary
759 and the neighbor side is also a boundary side */
760 /* TODO: check boundary side for NbElement==NULL */
761 if (OBJT(theElement) == BEOBJ)
762 if (SIDE_ON_BND(theElement,i))
763 {
764 INT err,id,nbid,id_nb,nbid_nb;
765
766 err = BNDS_BndSDesc(ELEM_BNDS(theElement,i),&id,&nbid);
767 if (err)
768 {
769 bserror |= (1<<i);
770 UserWriteF("elem=" EID_FMTX " ERROR BNDS_BndSDesc(%d) returned err=%d\n",
771 EID_PRTX(theElement),i,err);
772 }
773 else
774 {
775 if ((id==0) || (nbid==0))
776 {
777 /* no interior boundary */
778 UserWriteF("elem=" EID_FMTX " ERROR BNDS_BndSDesc(%d) returned id=%d nbid=%d\n",
779 EID_PRTX(theElement),i,id,nbid);
780 bserror |= (1<<i);
781 }
782 if (id==nbid)
783 {
784 /* should be avoided */
785 UserWriteF("elem=" EID_FMTX " ERROR BNDS_BndSDesc(%d) returned id=%d nbid=%d\n",
786 EID_PRTX(theElement),i,id,nbid);
787 bserror |= (1<<i);
788 }
789
790 /* check neighbour */
791 if (!SIDE_ON_BND(NbElement,j))
792 {
793 UserWriteF("elem=" EID_FMTX " ERROR nb=" EID_FMTX " nbside=%d not on boundary id=%d nbid=%d\n",
794 EID_PRTX(theElement),EID_PRTX(theElement),j,id,nbid);
795 bserror |= (1<<i);
796 }
797 else
798 {
799 if (BNDS_BndSDesc(ELEM_BNDS(NbElement,j),&id_nb,&nbid_nb))
800 {
801 UserWriteF("nb=" EID_FMTX " ERROR BNDS_BndSDesc(%d) returned id=%d nbid=%d\n",
802 EID_PRTX(NbElement),j,id,nbid);
803 bserror |= (1<<i);
804 }
805 else
806 {
807 if (id!=nbid_nb)
808 {
809 UserWriteF("nb=" EID_FMTX " ERROR nbside=%d id=%d unequal nbid_nb=%d\n",
810 EID_PRTX(NbElement),j,id,nbid);
811 bserror |= (1<<i);
812 }
813 if (nbid!=id_nb)
814 {
815 UserWriteF("nb=" EID_FMTX " ERROR nbside=%d nbid=%d unequal id_nb=%d\n",
816 EID_PRTX(NbElement),j,id,nbid);
817 bserror |= (1<<i);
818 }
819 }
820 }
821 }
822 if (bserror)
823 {
824 UserWriteF("elem=" EID_FMTX " nb=" EID_FMTX
825 " elemsubdom=%d nbsubdom=%d\n",
826 EID_PRTX(theElement),EID_PRTX(NbElement),
827 SUBDOMAIN(theElement),SUBDOMAIN(NbElement));
828 }
829 }
830 }
831
832 if( ECLASS(theElement)==NO_CLASS)
833 {
834 UserWriteF("Element has no ECLASS set, el = " EID_FMTX "\n",
835 EID_PRTX(theElement));
836 nerrors++;
837 }
838
839 if (ECLASS(theElement)!=YELLOW_CLASS)
840 {
841 n = CORNERS_OF_SIDE(theElement,i);
842 for (k=0; k<n; k++)
843 if (CORNER(theElement,CORNER_OF_SIDE(theElement,i,k))
844 == CORNER(NbElement,CORNER_OF_SIDE(NbElement,j,0)))
845 break;
846 if (k == n)
847 {
848 *SideError |= (1<<i);
849 UserWriteF("no matching corner for CORNER_OF_SIDE(NbElement,j,0)=" ID_FMTX "\n",
850 ID_PRTX(CORNER(NbElement,CORNER_OF_SIDE(NbElement,j,0))));
851 }
852 if (TAG(theElement)!=TETRAHEDRON
853 #ifdef Debug
854 || Debuggm>=1
855 #endif
856 )
857 for (l=1; l<n; l++)
858 if (CORNER(theElement,
859 CORNER_OF_SIDE(theElement,i,(n+k-l)%n))
860 != CORNER(NbElement,CORNER_OF_SIDE(NbElement,j,l)))
861 {
862 *SideError |= (1<<i);
863 UserWriteF("corner mismatch side=%d cos=%d corner_el=" ID_FMTX " side=%d cos=%d corner_nb=" ID_FMTX " el = " EID_FMTX "\n",
864 i,(n+k-l)%n,
865 ID_PRTX(CORNER(theElement,CORNER_OF_SIDE(theElement,i,(n+k-l)%n))),
866 j,l,
867 ID_PRTX(CORNER(NbElement,CORNER_OF_SIDE(NbElement,j,l))),EID_PRTX(theElement));
868 }
869 }
870 }
871 else
872 {
873 if (ECLASS(theElement)!=YELLOW_CLASS)
874 if (OBJT(theElement) == IEOBJ)
875 #ifdef ModelP
876 if (EMASTER(theElement))
877 #if defined(UG_DIM_2)
878 if (hghost_overlap!=0.0 || EdgeHasTMasterCopy(dddContext, theElement,i)==0)
879 #endif
880 #endif
881 *SideError |= (1<<(i+MAX_SIDES_OF_ELEM));
882
883 if (OBJT(theElement) == BEOBJ)
884 {
885 if (SIDE_ON_BND(theElement,i))
886 {
887 #ifdef ModelP
888 if (EMASTER(theElement))
889 #if defined(UG_DIM_2)
890 if (hghost_overlap!=0.0 || EdgeHasTMasterCopy(dddContext, theElement,i)==0)
891 #endif
892 #endif
893 if (INNER_SIDE(theElement,i)) {
894 *SideError |= (1<<(i+2*MAX_SIDES_OF_ELEM));
895 UserWriteF("no nb Element for inner boundary, el = " EID_FMTX "\n",
896 EID_PRTX(theElement));
897 nerrors++;
898 }
899 for (j=0; j<CORNERS_OF_SIDE(theElement,i); j++)
900 {
901 theVertex = MYVERTEX(CORNER(theElement,(k=CORNER_OF_SIDE(theElement,i,j))));
902 if (OBJT(theVertex) == IVOBJ)
903 *NodeError |= (1<<(k+MAX_CORNERS_OF_ELEM));
904 }
905 }
906 else if (ECLASS(theElement)!=YELLOW_CLASS)
907 #ifdef ModelP
908 if (EMASTER(theElement))
909 #if defined(UG_DIM_2)
910 if (hghost_overlap!=0.0 || EdgeHasTMasterCopy(dddContext, theElement,i)==0)
911 #endif
912 #endif
913 *SideError |= (1<<(i+2*MAX_SIDES_OF_ELEM));
914 }
915 }
916 }
917
918 /* check node information */
919 for (INT i=0; i<CORNERS_OF_ELEM(theElement); i++)
920 {
921 theNode = CORNER(theElement,i);
922
923 if (theNode != NULL)
924 nerrors += CheckNode(theElement,theNode,i);
925 else
926 {
927 UserWriteF("elem=" EID_FMTX " corner=%d nodeptr=NULL\n",
928 EID_PRTX(theElement),i);
929 nerrors++;
930 }
931 }
932
933 /* check edge information */
934 for (INT i=0; i<EDGES_OF_ELEM(theElement); i++)
935 {
936 theNode = CORNER(theElement,CORNER_OF_EDGE(theElement,i,0));
937 theNode1 = CORNER(theElement,CORNER_OF_EDGE(theElement,i,1));
938
939 if (theNode == NULL || theNode1 == NULL)
940 {
941 UserWriteF("elem=" EID_FMTX " edge=%d n0ptr=NULL or n1ptr=NULL\n",
942 EID_PRTX(theElement),i,theNode,theNode1);
943 nerrors++;
944 continue;
945 }
946
947 theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)),
948 CORNER(theElement,CORNER_OF_EDGE(theElement,i,1)));
949
950 if (theEdge != NULL)
951 nerrors += CheckEdge(theElement,theEdge,i);
952 else
953 {
954 UserWriteF("elem=" EID_FMTX " edge=%d n0=" ID_FMTX " n1="
955 ID_FMTX " edgeptr=NULL\n",
956 EID_PRTX(theElement),i,ID_PRTX(theNode),ID_PRTX(theNode1));
957 nerrors++;
958 }
959 }
960
961 /* check orientation */
962 for (INT i=0; i<CORNERS_OF_ELEM(theElement); i++)
963 Vertices[i] = MYVERTEX(CORNER(theElement,i));
964 if (0)
965 if (!CheckOrientation(CORNERS_OF_ELEM(theElement),Vertices))
966 {
967 UserWriteF("elem=" EID_FMTX " wrong orientation",EID_PRTX(theElement));
968 nerrors++;
969 }
970
971 /* check father information */
972 theFather = EFATHER(theElement);
973 if (theFather != NULL)
974 {
975 /* check MIDNODE information of father */
976 for (INT i=0; i<CORNERS_OF_ELEM(theElement); i++)
977 {
978 theNode = CORNER(theElement,i);
979 if (NTYPE(theNode) == MID_NODE)
980 {
981 for (j=0; j<EDGES_OF_ELEM(theFather); j++)
982 {
983 theEdge = GetEdge(CORNER(theFather,
984 CORNER_OF_EDGE(theFather,j,0)),
985 CORNER(theFather,
986 CORNER_OF_EDGE(theFather,j,1)));
987 if (MIDNODE(theEdge) == theNode) break;
988 }
989 if (j >= EDGES_OF_ELEM(theFather))
990 {
991 #ifdef ModelP
992 if (EMASTER(theFather)) {
993 IFDEBUG(gm,1)
994 UserWriteF("ELEM(" EID_FMTX ") WARNING MIDNODE=NULL"
995 " for mid node[%d]" ID_FMTX "\n",
996 EID_PRTX(theFather),i,ID_PRTX(theNode));
997 ENDDEBUG
998 }
999 #else
1000 UserWriteF("ELEM(" EID_FMTX ") ERROR MIDNODE=NULL"
1001 " for mid node[%d]=" ID_FMTX "\n",
1002 EID_PRTX(theFather),i,ID_PRTX(theNode));
1003 nerrors++;
1004 #endif
1005 }
1006 }
1007 }
1008
1009 /* check son information of father */
1010 if (GetAllSons(theFather,SonList))
1011 {
1012 UserWrite("cannot get sons\n");
1013 return (1);
1014 }
1015 UINT i;
1016 for (i=0; i<NSONS(theFather); i++)
1017 {
1018 if (SonList[i] == theElement) break;
1019 }
1020 if (i == NSONS(theFather))
1021 {
1022 UserWriteF("ELEM(" EID_FMTX ") FATHER(" EID_FMTX
1023 ")element is not in SonList NSONS=%d\n",
1024 EID_PRTX(theElement),EID_PRTX(theFather),
1025 NSONS(theFather));
1026 /** \todo activate if NSONS is consistent */
1027 if (0) nerrors++;
1028 }
1029 }
1030 #ifdef ModelP
1031 else
1032 {
1033 if (LEVEL(theElement) > 0)
1034 {
1035 if (EMASTER(theElement))
1036 {
1037 UserWriteF("ELEM(" EID_FMTX ") ERROR father=NULL\n",
1038 EID_PRTX(theElement));
1039 nerrors++;
1040 }
1041 }
1042 }
1043 #endif
1044
1045 /* check son information */
1046 if (NSONS(theElement)!=0)
1047 {
1048 nsons = NSONS(theElement);
1049
1050 if (GetAllSons(theElement,SonList))
1051 {
1052 UserWrite("cannot get sons\n");
1053 return (1);
1054 }
1055 for (INT i=0; (SonList[i]!=NULL || i<nsons) && i<MAX_SONS; i++)
1056 {
1057 IFDEBUG(gm,1)
1058 if (REFINE(theElement)==0)
1059 {
1060 UserWriteF("ELEM(" EID_FMTX "): element is not refined "
1061 "but has NSONS=%d\n",EID_PRTX(theElement),nsons);
1062 }
1063 ENDDEBUG
1064
1065 if (i >= nsons)
1066 {
1067 UserWriteF("ELEM(" EID_FMTX "): element has nsons=%d but "
1068 " son[%d]=" EID_FMTX " exists\n", EID_PRTX(theElement),
1069 NSONS(theElement),i,EID_PRTX(SonList[i]));
1070 /* TODO: activate if NSONS is consistent */
1071 if (0) nerrors++;
1072 }
1073
1074 if (SonList[i] == NULL)
1075 {
1076 UserWriteF("ELEM(" EID_FMTX "): element has nsons=%d but "
1077 " son[%d]=NULL\n", EID_PRTX(theElement),nsons,i);
1078 *ESonError |= (1<<i);
1079 nerrors++;
1080 continue;
1081 }
1082 if (EFATHER(SonList[i])!=theElement)
1083 {
1084 UserWriteF("i=%d theElement=" EID_FMTX
1085 " SonList[i]=" EID_FMTX "\n",
1086 i,EID_PRTX(theElement),EID_PRTX(SonList[i]));
1087 *ESonError |= (1<<i);
1088 nerrors++;
1089 }
1090 }
1091 }
1092
1093 if (bserror)
1094 {
1095 UserWriteF("theElement=" EID_FMTX
1096 " bserror=%d\n",
1097 EID_PRTX(theElement),bserror);
1098 nerrors++;
1099 }
1100 if (nerrors > 0)
1101 {
1102 UserWriteF("ELEM(" EID_FMTX "): element has %d errors\n",
1103 EID_PRTX(theElement),nerrors);
1104 *errors = nerrors;
1105 }
1106
1107 if (*SideError || *EdgeError || *NodeError || *ESonError || *NSonError)
1108 return (1);
1109
1110 return (0);
1111 }
1112
1113 #if defined(UG_DIM_2) || defined(ModelP)
1114
1115 INT CheckSubdomains (const MULTIGRID *theMG)
1116 {
1117 return (0);
1118 }
1119
1120 #else
1121
1122 static INT CheckElementSubdomains (GRID *theGrid, ELEMENT *theElement, INT *NodeError, INT *EdgeError, INT *NbError, INT *FatherError, INT *errors)
1123 {
1124 INT side,found,i,j,k,nerrors,sdid,sc;
1125 NODE *theNode,*n1,*n2,*nbn1,*nbn2,*nbn3,*nbn4;
1126 EDGE *theEdge,*father_edge;
1127 ELEMENT *theFather;
1128 VERTEX *theVertex;
1129
1130 *NodeError = 0;
1131 *EdgeError = 0;
1132 *NbError = 0;
1133 *FatherError = 0;
1134 nerrors = 0;
1135
1136 /* check side information */
1137 for (i=0; i<SIDES_OF_ELEM(theElement); i++)
1138 {
1139 if (OBJT(theElement)==BEOBJ && ELEM_BNDS(theElement,i)!=NULL)
1140 {
1141 for (j=0; j<CORNERS_OF_SIDE(theElement,i); j++)
1142 {
1143 k = CORNER_OF_SIDE(theElement,i,j);
1144 theNode = CORNER(theElement,k);
1145 if (NSUBDOM(theNode)!=0)
1146 {
1147 UserWriteF("wrong subdomain id(%d) on boundary node," "el = " EID_FMTX ", side = %d, corner = %d, node = " ID_FMTX "\n",
1148 NSUBDOM(theNode),EID_PRTX(theElement),i,k,ID_PRTX(theNode));
1149 *NodeError |= (1<<k);
1150 nerrors++;
1151 }
1152 }
1153 for (j=0; j<EDGES_OF_SIDE(theElement,i); j++)
1154 {
1155 k = EDGE_OF_SIDE(theElement,i,j);
1156 theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,k,0)),CORNER(theElement,CORNER_OF_EDGE(theElement,k,1)));
1157 ASSERT(theEdge!=NULL);
1158 if (EDSUBDOM(theEdge)!=0)
1159 {
1160 UserWriteF("wrong subdomain id(%d) on boundary edge %d,"
1161 "el = " EID_FMTX ", side = %d, edge = %d, corner0 = " ID_FMTX ", corner1 = " ID_FMTX "\n",
1162 EDSUBDOM(theEdge),k,EID_PRTX(theElement), i, j,
1163 ID_PRTX(CORNER(theElement,CORNER_OF_EDGE(theElement,k,0))),
1164 ID_PRTX(CORNER(theElement,CORNER_OF_EDGE(theElement,k,1))));
1165 *EdgeError |= (1<<j);
1166 nerrors++;
1167 }
1168 }
1169 }
1170
1171 if (NBELEM(theElement,i)!=NULL)
1172 {
1173 if (OBJT(theElement)==BEOBJ && ELEM_BNDS(theElement,i)!=NULL)
1174 {
1175 if (SUBDOMAIN(theElement)==SUBDOMAIN(NBELEM(theElement,i)))
1176 {
1177 UserWriteF("wrong subdomain id(%d)[==%d] of neighbor element," "el = " EID_FMTX ", side = %d, nb = EID_FMTX\n",
1178 SUBDOMAIN(NBELEM(theElement,i)),SUBDOMAIN(theElement),EID_PRTX(theElement),i,EID_PRTX(NBELEM(theElement,i)));
1179 *NbError |= (1<<i);
1180 nerrors++;
1181 }
1182 }
1183 else
1184 {
1185 if (SUBDOMAIN(theElement)!=SUBDOMAIN(NBELEM(theElement,i)))
1186 {
1187 UserWriteF("wrong subdomain id(%d)[!=%d] of neighbor element," "el = " EID_FMTX ", side = %d, nb = EID_FMTX\n",
1188 SUBDOMAIN(NBELEM(theElement,i)),SUBDOMAIN(theElement),EID_PRTX(theElement),i,EID_PRTX(NBELEM(theElement,i)));
1189 *NbError |= (1<<i);
1190 nerrors++;
1191 }
1192 }
1193 }
1194 }
1195
1196 for (i=0; i<CORNERS_OF_ELEM(theElement); i++)
1197 {
1198 theNode = CORNER(theElement,i);
1199 if (OBJT(MYVERTEX(theNode))==BVOBJ) continue;
1200 if (NSUBDOM(theNode)==SUBDOMAIN(theElement)) continue;
1201 UserWriteF("wrong subdomain id(%d)[==%d] of node," "el = " EID_FMTX ", nd = " ID_FMTX "\n",
1202 NSUBDOM(theNode),SUBDOMAIN(theElement),EID_PRTX(theElement),ID_PRTX(theNode));
1203 *NodeError |= (1<<i);
1204 nerrors++;
1205 }
1206
1207 if (EFATHER(theElement)!=NULL)
1208 if (SUBDOMAIN(EFATHER(theElement))!=SUBDOMAIN(theElement))
1209 {
1210 UserWriteF("wrong subdomain id(%d)[==%d] of father," "el = " EID_FMTX ", fa = " EID_FMTX "\n",
1211 SUBDOMAIN(EFATHER(theElement)),SUBDOMAIN(theElement),EID_PRTX(theElement),EID_PRTX(EFATHER(theElement)));
1212 *FatherError = 1;
1213 nerrors++;
1214 }
1215
1216 if (GLEVEL(theGrid)==0)
1217 {
1218 /* extended check on level 0 */
1219 for (i=0; i<EDGES_OF_ELEM(theElement); i++)
1220 {
1221 theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)),CORNER(theElement,CORNER_OF_EDGE(theElement,i,1)));
1222 ASSERT(theEdge!=NULL);
1223 if (USED(theEdge))
1224 {
1225 if (EDSUBDOM(theEdge)!=SUBDOMAIN(theElement))
1226 {
1227 UserWriteF("wrong subdomain id(%d)[!=%d] of edge," "el = " EID_FMTX ", ed = %d \n",
1228 EDSUBDOM(theEdge),SUBDOMAIN(theElement),EID_PRTX(theElement),i);
1229 *EdgeError = (1<<i);
1230 nerrors++;
1231 }
1232 }
1233 else
1234 {
1235 if (EDSUBDOM(theEdge)!=0)
1236 {
1237 UserWriteF("wrong subdomain id(%d)[!=0] of edge," "el = " EID_FMTX ", ed = %d \n",
1238 EDSUBDOM(theEdge),EID_PRTX(theElement),i);
1239 *EdgeError = (1<<i);
1240 nerrors++;
1241 }
1242 }
1243 }
1244 }
1245 else if (EFATHER(theElement)!=NULL)
1246 {
1247 theFather = EFATHER(theElement);
1248
1249 /* extended check on higher levels */
1250 for (i=0; i<EDGES_OF_ELEM(theElement); i++)
1251 {
1252 sdid=EDSUBDOM(EFATHER(theElement));
1253 n1 = CORNER(theElement,CORNER_OF_EDGE(theElement,i,0));
1254 n2 = CORNER(theElement,CORNER_OF_EDGE(theElement,i,1));
1255 if (NTYPE(n1)>NTYPE(n2)) {theNode=n1; n1=n2; n2=theNode;}
1256 switch (NTYPE(n1)|(NTYPE(n2)<<4))
1257 {
1258 case (CORNER_NODE | (CORNER_NODE<<4)) :
1259 father_edge = GetEdge(NFATHER(n1),NFATHER(n2));
1260 if (father_edge!=NULL) sdid=EDSUBDOM(father_edge);
1261 else
1262 {
1263 /* do fathers of n1, n2 lies on a side (of the father) which has BNDS? */
1264 for (j=0; j<SIDES_OF_ELEM(theFather); j++)
1265 {
1266 found=0;
1267 for (k=0; k<CORNERS_OF_SIDE(theFather,j); k++)
1268 {
1269 sc = CORNER_OF_SIDE(theFather,j,k);
1270 if (CORNER(theFather,sc)==NFATHER(n1) || CORNER(theFather,sc)==NFATHER(n2)) found++;
1271 }
1272 if (found==2 && (OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,j))
1273 {
1274 sdid=0;
1275 break;
1276 }
1277 }
1278 }
1279 break;
1280 case (CORNER_NODE | (MID_NODE<<4)) :
1281 father_edge = NFATHEREDGE(n2);
1282 assert(father_edge!=NULL);
1283 nbn1 = NBNODE(LINK0(father_edge));
1284 nbn2 = NBNODE(LINK1(father_edge));
1285 if (nbn1==NFATHER(n1) || nbn2==NFATHER(n1)) sdid=EDSUBDOM(father_edge);
1286 else
1287 {
1288 /* do all nodes n1, nbn1, nbn2 ly on the same side of father? */
1289 side=-1;
1290 for (j=0; j<SIDES_OF_ELEM(theFather); j++)
1291 {
1292 found=0;
1293 for (k=0; k<CORNERS_OF_SIDE(theFather,j); k++)
1294 {
1295 sc = CORNER_OF_SIDE(theFather,j,k);
1296 if (CORNER(theFather,sc)==NFATHER(n1) || CORNER(theFather,sc)==nbn1 || CORNER(theFather,sc)==nbn2) found++;
1297 }
1298 if (found==3)
1299 {
1300 side = j;
1301 break;
1302 }
1303 }
1304 if (side>=0 && (OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,side)) sdid=0;
1305 }
1306 break;
1307 case (MID_NODE | (MID_NODE<<4)) :
1308 father_edge = NFATHEREDGE(n1);
1309 assert(father_edge!=NULL);
1310 nbn1 = NBNODE(LINK0(father_edge));
1311 nbn2 = NBNODE(LINK1(father_edge));
1312 father_edge = NFATHEREDGE(n2);
1313 assert(father_edge!=NULL);
1314 nbn3 = NBNODE(LINK0(father_edge));
1315 nbn4 = NBNODE(LINK1(father_edge));
1316
1317 /* do all nodes nbn1, nbn2, nbn3, nbn4 ly on the same side of father? */
1318 side=-1;
1319 for (j=0; j<SIDES_OF_ELEM(theFather); j++)
1320 {
1321 found=0;
1322 for (k=0; k<CORNERS_OF_SIDE(theFather,j); k++)
1323 {
1324 sc = CORNER_OF_SIDE(theFather,j,k);
1325 if (CORNER(theFather,sc)==nbn1) found++;
1326 if (CORNER(theFather,sc)==nbn2) found++;
1327 if (CORNER(theFather,sc)==nbn3) found++;
1328 if (CORNER(theFather,sc)==nbn4) found++;
1329 }
1330 if (found==4)
1331 {
1332 side = j;
1333 break;
1334 }
1335 }
1336 if (side>=0 && (OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,side)) sdid=0;
1337 break;
1338 case (CORNER_NODE | (SIDE_NODE<<4)) :
1339 theVertex = MYVERTEX(n2);
1340 if (VFATHER(theVertex)==theFather) side = ONSIDE(theVertex);
1341 else side = ONNBSIDE(theVertex);
1342 if ((OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,side))
1343 for (k=0; k<CORNERS_OF_SIDE(theFather,side); k++)
1344 if (CORNER(theFather,CORNER_OF_SIDE(theFather,side,k))==NFATHER(n1))
1345 {
1346 sdid=0;
1347 break;
1348 }
1349 break;
1350 case (MID_NODE | (SIDE_NODE<<4)) :
1351 theVertex = MYVERTEX(n2);
1352 if (VFATHER(theVertex)==theFather) side = ONSIDE(theVertex);
1353 else side = ONNBSIDE(theVertex);
1354 if ((OBJT(theFather)==BEOBJ) && SIDE_ON_BND(theFather,side))
1355 {
1356 found=0;
1357 father_edge = NFATHEREDGE(n1);
1358 assert(father_edge!=NULL);
1359 nbn1 = NBNODE(LINK0(father_edge));
1360 nbn2 = NBNODE(LINK1(father_edge));
1361 for (k=0; k<CORNERS_OF_SIDE(theFather,side); k++)
1362 if (CORNER(theFather,CORNER_OF_SIDE(theFather,side,k))==nbn1 || CORNER(theFather,CORNER_OF_SIDE(theFather,side,k))==nbn2)
1363 found++;
1364 if (found==2) sdid=0;
1365 }
1366 break;
1367 default :
1368 break;
1369 }
1370 if (EDSUBDOM(GetEdge(n1,n2))!=sdid)
1371 {
1372 *EdgeError |= (1<<i);
1373 nerrors++;
1374 }
1375 }
1376 }
1377
1378 if (nerrors>0)
1379 {
1380 UserWriteF("ELEM(" EID_FMTX "): element has %d errors\n",EID_PRTX(theElement),nerrors);
1381 *errors = nerrors;
1382 }
1383
1384 if (*NodeError || *EdgeError || *NbError || *FatherError)
1385 return (1);
1386
1387 return (0);
1388 }
1389
1390 INT CheckSubdomains (MULTIGRID *theMG)
1391 {
1392 GRID *theGrid;
1393 NODE *theNode;
1394 EDGE *theEdge;
1395 LINK *theLink;
1396 ELEMENT *theElement;
1397 INT i,j,k,nerror,NodeError,EdgeError,NbError,FatherError,sd_errors;
1398
1399 /* init */
1400 nerror=0;
1401
1402 /* first level 0 */
1403 theGrid = GRID_ON_LEVEL(theMG,0);
1404 for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
1405 for (theLink=START(theNode); theLink!=NULL; theLink=NEXT(theLink))
1406 SETUSED(MYEDGE(theLink),1);
1407 for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement))
1408 if (OBJT(theElement)==BEOBJ)
1409 for (i=0; i<SIDES_OF_ELEM(theElement); i++)
1410 if (ELEM_BNDS(theElement,i)!=NULL)
1411 for (j=0; j<EDGES_OF_SIDE(theElement,i); j++)
1412 {
1413 k = EDGE_OF_SIDE(theElement,i,j);
1414 theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,k,0)),CORNER(theElement,CORNER_OF_EDGE(theElement,k,1)));
1415 ASSERT(theEdge!=NULL);
1416 SETUSED(theEdge,0);
1417 }
1418
1419 for (i=0; i<=TOPLEVEL(theMG); i++)
1420 {
1421 for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement))
1422 if (CheckElementSubdomains (theGrid,theElement,&NodeError,&EdgeError,&NbError,&FatherError,&sd_errors))
1423 nerror++;
1424
1425 if (nerror) UserWriteF("[%d: subdom-ids: %d errors] ",(int)i,(int)nerror);
1426 else UserWriteF("[%d: subdom-ids: ok] ",(int)i);
1427 if (nerror && i<TOPLEVEL(theMG)) UserWrite("[check aborted] ");
1428 }
1429 UserWrite("\n");
1430
1431 /* return */
1432 return (nerror);
1433 }
1434 #endif
1435
1436 static INT CheckGeometry (GRID *theGrid)
1437 {
1438 NODE *theNode;
1439 ELEMENT *theElement;
1440 EDGE *theEdge;
1441 LINK *theLink;
1442 INT SideError, EdgeError, NodeError, ESonError, NSonError, count;
1443 INT errors = 0;
1444
1445 /* reset used flags */
1446 for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
1447 {
1448 SETUSED(theNode,0);
1449 for (theLink=START(theNode); theLink!=NULL; theLink=NEXT(theLink))
1450 SETUSED(MYEDGE(theLink),0);
1451 }
1452
1453 /* check elements */
1454 for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL;
1455 theElement=SUCCE(theElement))
1456 {
1457 if (CheckElement(theGrid,theElement,&SideError,&EdgeError,
1458 &NodeError,&ESonError,&NSonError,&errors)==0) continue;
1459
1460 UserWriteF("ELEM=" EID_FMTX "\n",EID_PRTX(theElement));
1461
1462 /* evaluate side information */
1463 if (SideError)
1464 for (INT i=0; i<SIDES_OF_ELEM(theElement); i++)
1465 {
1466 /* back pointer failure */
1467 if (SideError & 1<<i)
1468 {
1469 UserWriteF(" SIDE[%d]=(",i);
1470 for (INT j=0; j<CORNERS_OF_SIDE(theElement,i); j++)
1471 {
1472 UserWriteF(ID_FMTX,ID_PRTX(CORNER(theElement,
1473 CORNER_OF_SIDE(theElement,i,j))));
1474
1475 if (j<CORNERS_OF_SIDE(theElement,i)-1) UserWrite(",");
1476 }
1477 UserWriteF(") has neighbour=" EID_FMTX " but a backPtr does not exist\n",
1478 EID_PRTX(NBELEM(theElement,i)));
1479
1480 errors++;
1481 }
1482
1483 /* neighbor pointer failure */
1484 if (SideError & 1<<(i+MAX_SIDES_OF_ELEM))
1485 {
1486 errors++;
1487
1488 UserWriteF(" SIDE[%d]=(",i);
1489 for (INT j=0; j<CORNERS_OF_SIDE(theElement,i); j++)
1490 {
1491 UserWriteF(ID_FMTX,ID_PRTX(CORNER(theElement,
1492 CORNER_OF_SIDE(theElement,i,j))));
1493
1494 if (j<CORNERS_OF_SIDE(theElement,i)-1) UserWrite(",");
1495 }
1496 UserWrite(") ERROR: has no neighbor but element is IEOBJ\n");
1497
1498 UserWriteF(" Eclass=%d Efather=" EID_FMTX "FECLASS=%d FREFINE=%d\n",
1499 ECLASS(theElement),EID_PRTX(EFATHER(theElement)),
1500 ECLASS(EFATHER(theElement)),REFINE(EFATHER(theElement)));
1501 {
1502 ELEMENT *theFather = EFATHER(theElement);
1503 ELEMENT *theNeighbor;
1504
1505 for (int k=0; k < SIDES_OF_ELEM(theFather); k++)
1506 {
1507 theNeighbor = NBELEM(theFather,k);
1508 if (theNeighbor != NULL)
1509 {
1510 UserWriteF("NB[%d]=" EID_FMTX " NBREFINE=%d\n",
1511 k,EID_PRTX(theNeighbor),REFINE(theNeighbor));
1512
1513 }
1514 }
1515 }
1516
1517 }
1518
1519 /* boundary failure */
1520 if (SideError & 1<<(i+2*MAX_SIDES_OF_ELEM))
1521 {
1522 errors++;
1523
1524 UserWriteF(" SIDE[%d]=(",i);
1525 for (INT j=0; j<CORNERS_OF_SIDE(theElement,i); j++)
1526 {
1527 UserWriteF(ID_FMTX,ID_PRTX(CORNER(theElement,
1528 CORNER_OF_SIDE(theElement,i,j))));
1529
1530 if (j<CORNERS_OF_SIDE(theElement,i)-1) UserWrite(",");
1531 }
1532 UserWrite(") ERROR: has no neighbor, element is BEOBJ "
1533 "but there is no SIDE\n");
1534 }
1535 }
1536
1537 /* evaluate edge information */
1538 if (EdgeError)
1539 for (INT i=0; i<EDGES_OF_ELEM(theElement); i++)
1540 {
1541 if (!(EdgeError & 1<<i)) continue;
1542
1543 errors++;
1544 UserWriteF(" EDGE(" ID_FMTX " , " ID_FMTX ") is missing\n",
1545 ID_PRTX(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0))),
1546 ID_PRTX(CORNER(theElement,CORNER_OF_EDGE(theElement,i,1))));
1547 }
1548
1549 /* evaluate node information */
1550 if (NodeError)
1551 for (INT i=0; i<CORNERS_OF_ELEM(theElement); i++)
1552 {
1553 if (NodeError & (1<<i))
1554 {
1555 errors++;
1556 UserWriteF(" CORNER=" ID_FMTX " is BVOBJ,"
1557 " ids from elementside "
1558 "and vertexsegment are not consistent\n",
1559 ID_PRTX(CORNER(theElement,i)));
1560 }
1561 if (NodeError & (1<<(i+MAX_CORNERS_OF_ELEM)))
1562 {
1563 errors++;
1564 UserWriteF(" CORNER " ID_FMTX " is IVOBJ, but lies on "
1565 "elementside\n",ID_PRTX(CORNER(theElement,i)));
1566 }
1567 }
1568
1569 /* evaluate son information */
1570 if (ESonError)
1571 {
1572 for (UINT i=0; i<NSONS(theElement); i++)
1573 {
1574 if ((ESonError & 1<<i))
1575 {
1576 errors++;
1577 UserWriteF(" ESON(%d) has wrong EFATHER "
1578 "pointer\n",i);
1579 }
1580 }
1581 }
1582
1583 if (NSonError)
1584 {
1585 for (INT i=0; i<MAX_CORNERS_OF_ELEM; i++)
1586 {
1587 if (NSonError & (1<<i))
1588 {
1589 errors++;
1590 UserWriteF(" SONNODE(CORNER %d) != CORNER(ESON)\n",i);
1591 }
1592 if (NSonError & (1<<(i+MAX_CORNERS_OF_ELEM)))
1593 {
1594 errors++;
1595 UserWriteF(" CORNER %d != EFATHER(CORNER(ESON))\n",i);
1596 }
1597 }
1598
1599 for (INT i=0; i<MAX_EDGES_OF_ELEM; i++)
1600 {
1601
1602 if (NSonError & (1<<(i+MAX_CORNERS_OF_ELEM)))
1603 {
1604 errors++;
1605 UserWriteF(" MIDNODE(edge %d) != CORNER(ESON)\n",i);
1606 }
1607 }
1608
1609 if (NSonError & (1<<(MAX_EDGES_OF_ELEM+2*MAX_CORNERS_OF_ELEM)))
1610 {
1611 errors++;
1612 UserWriteF(" NFATHER(CENTERNODE(ESON)) != NULL\n");
1613 }
1614 }
1615 }
1616
1617 /* look for dead edges */
1618 for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
1619 {
1620 for (theLink=START(theNode); theLink!=NULL; theLink=NEXT(theLink))
1621 {
1622 theEdge = MYEDGE(theLink);
1623 if (!USED(theEdge))
1624 {
1625 errors++;
1626 UserWriteF("edge"
1627 ID_FMTX
1628 " between " ID_FMTX " and " ID_FMTX
1629 " has no element, NO_OF_ELEM=%d \n",
1630 ID_PRTX(theEdge),
1631 ID_PRTX(theNode),ID_PRTX(NBNODE(theLink)),
1632 NO_OF_ELEM(theEdge));
1633
1634 #ifdef Debug
1635 {
1636 NODE *nb;
1637 LINK *theLink1;
1638
1639 nb = NBNODE(theLink);
1640 UserWriteF("linklist of nbnode %d:",ID(nb));
1641
1642 for (theLink1=START(nb); theLink1!=NULL;
1643 theLink1=NEXT(theLink1))
1644 UserWriteF(" %d-%d",ID(NBNODE(theLink1)),
1645 ID(NBNODE(REVERSE(theLink1))));
1646 UserWrite("\n");
1647 }
1648 #endif
1649 }
1650 }
1651 }
1652
1653 /* look for dead nodes */
1654 for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
1655 {
1656 if (!USED(theNode))
1657 {
1658 errors++;
1659 UserWriteF("node=" ID_FMTX " is dead\n",ID_PRTX(theNode));
1660 }
1661 else
1662 SETUSED(theNode,0);
1663 }
1664
1665 /* check number of elem and their pointers */
1666 count = 0;
1667 for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL;
1668 theElement=SUCCE(theElement))
1669 {
1670 if (SUCCE(theElement)!=NULL)
1671 {
1672 if (OBJT(SUCCE(theElement))!=IEOBJ &&
1673 OBJT(SUCCE(theElement))!=BEOBJ)
1674 {
1675 errors++;
1676 UserWriteF("pointer of ELEM(" EID_FMTX ") (number %ld) "
1677 "to next element is no pointer to an element\n",
1678 EID_PRTX(theElement),(long)count);
1679 break;
1680 }
1681 if (PREDE(SUCCE(theElement))!=NULL)
1682 {
1683 if (PREDE(SUCCE(theElement))!=theElement)
1684 {
1685 errors++;
1686 UserWriteF("pointer of ELEM(" EID_FMTX ") (number %ld) "
1687 "to previous element is not the previous element\n",
1688 EID_PRTX(SUCCE(theElement)),(long)(count+1));
1689 }
1690 }
1691 #ifndef ModelP
1692 else
1693 {
1694 errors++;
1695 UserWriteF("pointer of ELEM(" EID_FMTX ") (number %ld) "
1696 "to previous element is NULL\n",
1697 EID_PRTX(SUCCE(theElement)),(long)(count+1));
1698 }
1699 #endif
1700 }
1701 count++;
1702 }
1703
1704 if (FIRSTELEMENT(theGrid) != NULL)
1705 if (PREDE(FIRSTELEMENT(theGrid)) != NULL)
1706 {
1707 errors++;
1708 UserWriteF("first element of the grid has a previous 'element'\n");
1709 }
1710
1711 if (LASTELEMENT(theGrid) != NULL)
1712 if (SUCCE(LASTELEMENT(theGrid)) != NULL)
1713 {
1714 errors++;
1715 UserWriteF("last element of the grid has a following 'element'\n");
1716 }
1717
1718 if (count != NT(theGrid))
1719 {
1720 errors++;
1721 UserWriteF("there are %ld elements but %ld expected\n",(long)(count),
1722 (long)NT(theGrid));
1723 }
1724
1725 return(errors);
1726 }
1727
1728 static INT CheckElementList (const GRID *theGrid)
1729 {
1730 ELEMENT *theElement;
1731
1732 if (GLEVEL(theGrid) <= 0) return(0);
1733
1734 for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL;
1735 theElement=SUCCE(theElement))
1736 {
1737 ELEMENT *Father = EFATHER(theElement);
1738 PAR( INT prio = EPRIO(theElement); ) ENDPAR
1739
1740 if (EMASTER(theElement) && Father==NULL)
1741 {
1742 UserWriteF("ERROR: element=" EID_FMTX " has no father\n",
1743 EID_PRTX(theElement));
1744 }
1745 if (Father == NULL) continue;
1746 if (theElement == SON(Father,PRIO2INDEX(prio)))
1747 {
1748 if (PREDE(theElement) != NULL)
1749 if (EFATHER(PREDE(theElement))==Father
1750 PAR( && EPRIO(theElement)==EPRIO(PREDE(theElement)) ) ENDPAR )
1751 {
1752 UserWriteF(" ERROR element=" EID_FMTX " is not first"
1753 "son in list pred elem=" EID_FMTX " father=" EID_FMTX
1754 "\n", EID_PRTX(theElement),EID_PRTX(PREDE(theElement)),
1755 EID_PRTX(Father));
1756 }
1757 }
1758 else
1759 {
1760 if (PREDE(theElement)==NULL ||
1761 EFATHER(PREDE(theElement))!=Father)
1762 {
1763 UserWriteF(" ERROR element=" EID_FMTX " has no"
1764 "PREDE with same father=" EID_FMTX
1765 "\n", EID_PRTX(theElement),EID_PRTX(Father));
1766 }
1767 }
1768 }
1769 return (0);
1770 }
1771
1772 INT NS_DIM_PREFIX CheckLists (GRID *theGrid)
1773 {
1774 /* perform gm dependent check */
1775 CheckElementList(theGrid);
1776
1777 /* perform standard list check */
1778 GRID_CHECK_ELEMENT_LIST(theGrid);
1779 GRID_CHECK_NODE_LIST(theGrid);
1780 GRID_CHECK_VERTEX_LIST(theGrid);
1781 GRID_CHECK_VECTOR_LIST(theGrid);
1782
1783 return(GM_OK);
1784 }
1785
1786 /****************************************************************************/
1787 /*D
1788 CheckGrid - Check consistency of data structure
1789
1790 SYNOPSIS:
1791 INT CheckGrid (GRID *theGrid, INT checkgeom, INT checkalgebra, INT checklists, INT checkif)
1792
1793 PARAMETERS:
1794 . theGrid - grid to check
1795 . checkgeom - check geometry
1796 . checkalgebra - check algebra
1797 . checklists - checklists
1798 . checkif - check the processor interfaces
1799
1800 DESCRIPTION:
1801 This function checks the consistency of data structure.
1802
1803 RETURN VALUE:
1804 INT
1805 .n GM_OK if ok
1806 .n GM_ERROR if an error occurred.
1807 D*/
1808 /****************************************************************************/
1809
1810 #ifndef ModelP
1811 INT NS_DIM_PREFIX CheckGrid (GRID *theGrid, INT checkgeom, INT checkalgebra, INT checklists)
1812 #else
1813 INT NS_DIM_PREFIX CheckGrid (GRID *theGrid, INT checkgeom, INT checkalgebra, INT checklists,
1814 INT checkif)
1815 #endif
1816 {
1817 INT error = 0;
1818 INT errors = 0;
1819 INT totalerrors = 0;
1820
1821 /* check geometrical data structures */
1822 if (checkgeom)
1823 {
1824 UserWrite(" geometry:");
1825
1826 errors = CheckGeometry(theGrid);
1827 #ifdef ModelP
1828 errors = UG_GlobalSumINT(theGrid->ppifContext(), errors);
1829 #endif
1830 if (errors != GM_OK)
1831 {
1832 totalerrors += errors;
1833 error++;
1834 UserWriteF(" geometry BAD: %d errors",errors);
1835 }
1836 else
1837 UserWrite(" ok");
1838 }
1839
1840 /* check algebraic data structures */
1841 if (checkalgebra)
1842 {
1843 UserWrite(", algebra:");
1844
1845 errors = CheckAlgebra(theGrid);
1846 #ifdef ModelP
1847 errors = UG_GlobalSumINT(theGrid->ppifContext(), errors);
1848 #endif
1849 if (errors != GM_OK)
1850 {
1851 totalerrors += errors;
1852 error++;
1853 UserWriteF(" algebra BAD: %d errors",errors);
1854 }
1855 else
1856 UserWrite(" ok");
1857 }
1858
1859 /* check lists and counters */
1860 if (checklists)
1861 {
1862 UserWrite(", lists:");
1863
1864 errors = CheckLists(theGrid);
1865 #ifdef ModelP
1866 errors = UG_GlobalSumINT(theGrid->ppifContext(), errors);
1867 #endif
1868 if (errors != GM_OK)
1869 {
1870 totalerrors += errors;
1871 error++;
1872 UserWriteF(" lists BAD: %d errors",errors);
1873 }
1874 else
1875 UserWrite(" ok");
1876 }
1877
1878 #ifdef ModelP
1879 /* check interfaces to other procs */
1880 if (checkif)
1881 {
1882 UserWrite(", interface:");
1883
1884 errors = CheckInterfaces(theGrid);
1885 #ifdef ModelP
1886 errors = UG_GlobalSumINT(theGrid->ppifContext(), errors);
1887 #endif
1888 if (errors != GM_OK)
1889 {
1890 totalerrors += errors;
1891 error++;
1892 UserWriteF(" interfaces BAD: %d errors",errors);
1893 }
1894 else
1895 UserWrite(" ok");
1896 }
1897 #endif
1898
1899 if (totalerrors)
1900 UserWriteF(", grid BAD: %d check(s) with %d totalerror(s)",
1901 error,totalerrors);
1902 else
1903 UserWrite(", grid ok");
1904
1905 return(error);
1906 }