Debian Codegraph @

dune/uggrid/gm/er.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 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 /****************************************************************************/
6 /* */
7 /* File: er.c */
8 /* */
9 /* Purpose: extract rules realized in a multigrid */
10 /* */
11 /* Author: Henrik Rentz-Reichert */
12 /* Institut fuer Computeranwendungen III */
13 /* Universitaet Stuttgart */
14 /* Pfaffenwaldring 27 */
15 /* 70550 Stuttgart */
16 /* email: [email protected] */
17 /* */
18 /* History: 06.12.97 begin, ug version 3.7 */
19 /* */
20 /* Remarks: */
21 /* */
22 /****************************************************************************/
23
24 #undef __DEBUG_ER__
25 #undef __PATCH_UG_RULES__
26
27 /****************************************************************************/
28 /*
29 storage allocation stages:
30
31 Notation: M - Mark(Tmp)Mem
32 G - Get(Tmp)Mem
33 R - Release(Tmp)Mem
34
35
36 ------------------------+-+-+-+-+---+-+-+-+-+
37 |BOTTOM | | TOP |
38 ------------------------+-+-+-+-+---+-+-+-+-+
39 stack level |0|1|2|3| |0|1|2|3|
40 ------------------------+-+-+-+-+---+-+-+-+-+
41 (1) for hrules |M| | | | | | | | |
42 (2) hash table | | | | | | |M| | |
43 | | | | | | |G| | |
44 (3) interface rules | | | | | | | |M| |
45 | | | | | | | |G| |
46 (4) hrules |G| | | | | | | | |
47 (5) free (3) | | | | | | | |R| |
48 (6) further hrules |G| | | | | | | | |
49 (6) hrule table |G| | | | | | | | |
50 (7) free (2) | | | | | | |R| | |
51 (7) mrule table (rm+er) | | | | | |G| | | |
52 (9) free hrules |R| | | | | | | | |
53 ------------------------+-+-+-+-+---+-+-+-+-+
54 */
55 /****************************************************************************/
56
57 /****************************************************************************/
58 /* */
59 /* include files */
60 /* system include files */
61 /* application include files */
62 /* */
63 /****************************************************************************/
64
65 #include <config.h>
66 #include <cstring>
67
68 #include <algorithm>
69 #include <array>
70
71 /* gm */
72 #include "rm.h"
73 #include "mgio.h"
74 #include "ugm.h"
75 #include "cw.h"
76 #include "elements.h"
77
78 /* own header */
79 #include "er.h"
80
81
82 USING_UG_NAMESPACES
83
84 /****************************************************************************/
85 /* */
86 /* defines in the following order */
87 /* */
88 /* compile time constants defining static data size (i.e. arrays) */
89 /* other constants */
90 /* macros */
91 /* */
92 /****************************************************************************/
93
94 /* TODO (HRR 971207): increase REFINE_LEN by shifting REFINE-ce to flag cw */
95 #define MAX_HRID (1<<REFINE_LEN)
96 #define MAX_IFID MAX_HRID
97
98 #ifdef __PATCH_UG_RULES__
99 /* CAUTION: save/load ok but REFINE(e) will not be consistent with rm anymore */
100 #define UGMAXRULE(tag) ((MaxRules[tag]>0) ? 1 : 0) /* include NO_REFINEMENT from ug */
101 #define HAS_NO_RULE(e) (REFINE(e)>=UGMAXRULE(TAG(e)))
102 #else
103 #define UGMAXRULE(tag) (MaxRules[tag])
104 #define HAS_NO_RULE(e) (REFINE(e)==COPY && REFINECLASS(e)==GREEN_CLASS)
105 #endif
106
107 #define BEYOND_UG_RULES(e) (REFINE(e)>=UGMAXRULE(TAG(e)))
108
109 #define NOTDONE -1
110
111 /* for computing son paths */
112 enum NB_STATUS {
113
114 NB_DONE,
115 NB_NOTDONE,
116 NB_TOUCHED
117 };
118
119 /* debug levels of extract rule module */
120 enum ER_DBG {
121
122 ER_DBG_GENERAL = 1,
123 ER_DBG_RULES = 2,
124 ER_DBG_RULE_VERBOSE = 3,
125 ER_DBG_ELEM = 3
126 };
127
128 #define HASH_SIZE 1000
129 #define HASH_FACTOR .61803398874989 /* golden section: 0.5*(sqrt(5)-1) */
130 #define HASH_ADDRESS(k) floor(HASH_SIZE*(k*HASH_FACTOR-floor(k*HASH_FACTOR)))
131
132 #define ER_NSONS(p) ((p)->nsons)
133 #define ER_NCO(p,i) ((p)->nco[i])
134 #define ER_DCO(p,i) ((p)->dco[i])
135
136 #define HR_ID(p) ((p)->id)
137 #define HR_KEY(p) ((p)->key)
138 #define HR_TAG(p) ((p)->tag)
139 #define HR_NEXT(p) ((p)->next)
140 #define HR_ERULE(p) (&((p)->erule))
141 #define HR_NSONS(p) ((p)->erule.nsons)
142 #define HR_NCO(p,i) ((p)->erule.nco[i])
143 #define HR_DCO(p,i) ((p)->erule.dco[i])
144 #define HR_OCOPTR(p) ((p)->erule.dco+HR_NSONS(p))
145 #define HR_OCO(p,i) ((p)->erule.dco[HR_NSONS(p)+i])
146
147 /* debug macros */
148 #define ELEM_INFO(f,c,e,ns) f ": %sconsiderd elem%ld tag%d refine%ld nsons%d (actually %d)\n", \
149 (c) ? "not " : "", \
150 (long)ID(e), \
151 (int)TAG(e), \
152 (long)REFINE(e), \
153 (int)NSONS(e), \
154 (int)ns
155
156 #ifdef Debug
157 #define PD_ERR(l,x,e) {PRINTDEBUG(gm,l,x); e++; /* ASSERT(false);*/}
158 #define PD(x) {PrintDebug x;}
159 #else
160 #define PD_ERR(l,x,e) /* no debug */
161 #define PD(x) /* no debug */
162 #ifdef PrintDebug
163 #undef PrintDebug
164 #define PrintDebug printf
165 #endif
166 #endif
167
168 /****************************************************************************/
169 /* */
170 /* data structures used in this source file (exported data structures are */
171 /* in the corresponding include file!) */
172 /* */
173 /****************************************************************************/
174
175 typedef struct {
176
177 SHORT nsons; /* number of son elements */
178 SHORT nco[MAX_SONS]; /* number of son corners */
179 DOUBLE dco[MAX_SONS]; /* corners coded as digits to base */
180 /* MAX_REFINED_CORNERS_DIM */
181
182 } ERULE;
183
184 typedef INT HRID;
185
186 struct hashed_rule {
187
188 HRID id; /* rule id will continue tag-wise rm-rules */
189 DOUBLE key; /* hash key */
190 SHORT tag; /* tag of element */
191 struct hashed_rule *next; /* list of rules per hash entry */
192
193 ERULE erule; /* refinement rule */
194 /* will be allocated with additional doubles for ordered sons */
195 /* CAUTION: storage occupied may be < sizeof(HRULE) */
196 };
197
198 /* HRULE example for 3 sons:
199 id
200 key
201 tag
202 next
203 nsons // begin of ERULE
204 nco[MAX_SONS]
205 dco[3]
206 oco[3] // corners in ascending order
207 */
208
209 typedef struct hashed_rule HRULE;
210 typedef REFRULE URULE;
211
212 /****************************************************************************/
213 /* */
214 /* definition of exported global variables */
215 /* */
216 /****************************************************************************/
217
218
219
220 /****************************************************************************/
221 /* */
222 /* definition of variables global to this source file only (static!) */
223 /* */
224 /****************************************************************************/
225
226 static struct {
227
228 HEAP *heap; /* multigrid heap */
229
230 HRULE **hash_table; /* hash table */
231 std::array<HRULE**, TAGS> hrule; /* tables with hrules sorted by id */
232
233 std::array<long, TAGS> maxrule; /* max rule id per tag (rm+er) */
234 long maxrules; /* max rule id (rm+er) */
235 std::array<long, TAGS> nelem_inspected; /* elements getting er-rules per tag */
236 long nelems_inspected; /* elements getting er-rules */
237 std::array<long, TAGS> nelem_not_inspected; /* elements having rm-rules per tag */
238 long nelems_not_inspected; /* elements having rm-rules */
239
240 #ifdef ModelP
241 long if_elems; /* number of elements getting er-rules */
242 ERULE *interface_rules; /* table of interface rules */
243 #endif
244
245 } global; /* static globals of this module */
246
247 /****************************************************************************/
248 /* */
249 /* forward declarations of functions used before they are defined */
250 /* */
251 /****************************************************************************/
252
253
254 /****************************************************************************/
255 /*doctext_disabled
256 Corner2DCorners - map corner array to DOUBLE
257
258 SYNOPSIS:
259 static DOUBLE Corner2DCorners (INT n, SHORT corners[])
260
261 PARAMETERS:
262 . n - number of corners
263 . corners - array of corner IDs
264
265 DESCRIPTION:
266 Convert list of corner IDs into one DOUBLE value. Corner IDs are digits
267 in a MAX_REFINED_CORNERS_DIM base.
268
269 RETURN VALUE:
270 DOUBLE
271 .n coded corners
272 doctext_disabled*/
273 /****************************************************************************/
274
275 static DOUBLE Corner2DCorners (INT n, const SHORT corners[])
276 {
277 DOUBLE dco = corners[0];
278
279 for (int i = 1; i < n; i++)
280 {
281 dco *= MAX_REFINED_CORNERS_DIM;
282 dco += corners[i];
283 }
284 return (dco);
285 }
286
287 /****************************************************************************/
288 /*doctext_disabled
289 DCorners2Corners - convert DOUBLE into array of corner IDs
290
291 SYNOPSIS:
292 static void DCorners2Corners (INT n, DOUBLE dco, SHORT corners[])
293
294 PAAMETERS:
295 . n - number of corners
296 . dco - corners coded on DOUBLE
297 . corners - array of corner IDs
298
299 DESCRIPTION:
300 Convert DOUBLE into array of corner IDs. For encoding see 'Corner2DCorners'.
301
302 RETURN VALUE:
303 void
304 .n none
305
306 SEE_ASLO:
307 Corner2DCorners
308 doctext_disabled*/
309 /****************************************************************************/
310
311 static void DCorners2Corners (INT n, DOUBLE dco, SHORT corners[])
312 {
313 for (int i = n-1; i >= 0; i--)
314 {
315 DOUBLE x = floor(dco/((DOUBLE)MAX_REFINED_CORNERS_DIM));
316 corners[i] = (SHORT)(dco-x*MAX_REFINED_CORNERS_DIM);
317 dco = x;
318 }
319 }
320
321 /****************************************************************************/
322 /*doctext_disabled
323 FillOrderedSons - fill array with ordered sons
324
325 SYNOPSIS:
326 static void FillOrderedSons (const ERULE *er, DOUBLE oco[])
327
328 PAAMETERS:
329 . er - rule
330 . oco - array of ordered sons
331
332 DESCRIPTION:
333 Fill array with sons in ascending order whose ordered corners are coded as DOUBLEs.
334
335 RETURN VALUE:
336 void
337 .n none
338 doctext_disabled*/
339 /****************************************************************************/
340
341 static void FillOrderedSons (const ERULE *er, DOUBLE oco[])
342 {
343 SHORT corners[MAX_CORNERS_OF_ELEM_DIM];
344
345 /* sort corners of each son */
346 for (int s = 0; s < ER_NSONS(er); s++)
347 {
348 DCorners2Corners(ER_NCO(er,s),ER_DCO(er,s),corners);
349 std::sort(corners, corners + ER_NCO(er,s));
350 oco[s] = Corner2DCorners(ER_NCO(er,s),corners);
351 }
352
353 /* sort sons in ascending order coded on a DOUBLE (cf. `Corner2DCorners`) */
354 std::sort(oco, oco + ER_NSONS(er));
355 }
356
357 /****************************************************************************/
358 /*doctext_disabled
359 Hash_Init - allocate and initialize hash table
360
361 SYNOPSIS:
362 static INT Hash_Init (int MarkKey)
363
364 PAAMETERS:
365 . MarkKey - mark key for memory allocation
366
367 DESCRIPTION:
368 Allocate and initialize hash table
369
370 RETURN VALUE:
371 INT
372 .n 0: ok
373 .n 1: no memory
374 doctext_disabled*/
375 /****************************************************************************/
376
377 #if (defined UG_DIM_3) || (defined __DEBUG_ER__)
378 static INT Hash_Init (int MarkKey)
379 {
380 global.hash_table = (HRULE**) GetTmpMem(global.heap,HASH_SIZE*sizeof(HRULE*),MarkKey);
381 if (global.hash_table==NULL)
382 REP_ERR_RETURN(1);
383
384 for (int i = 0; i < HASH_SIZE; i++)
385 global.hash_table[i] = NULL;
386
387 return (0);
388 }
389 #endif
390
391 /****************************************************************************/
392 /*doctext_disabled
393 Hash_InsertRule - insert a rule into the hash table
394
395 SYNOPSIS:
396 static HRID Hash_InsertRule (INT etag, INT key, const ERULE *er, const DOUBLE oco[], HRULE **next_handle)
397
398 PAAMETERS:
399 . etag - element tag
400 . key - hash key
401 . er - rule
402 . oco - ordered corners
403 . next_handle - insert here into linked list of rules in hash table
404
405 DESCRIPTION:
406 Make an HRULE from an ERULE and insert it into the hash table.
407
408 RETURN VALUE:
409 HRID
410 .n >=0: ok
411 .n -1: no memory for HRULE
412 doctext_disabled*/
413 /****************************************************************************/
414
415 static HRID Hash_InsertRule (INT etag, INT key, const ERULE *er, const DOUBLE oco[], HRULE **next_handle)
416 {
417 size_t size = sizeof(HRULE) /* full HRULE */
418 +sizeof(DOUBLE)*
419 (2*ER_NSONS(er) /* #DOUBLEs needed */
420 -MAX_SONS); /* #DOUBLEs at end of HRULE */
421 // I think that nullptr can replace the call to GetCurrentMultigrid, because that method
422 // has been returning nullptr for a long time.
423 // In other words: it seems the method we are in is never called.
424 HRULE *hr = (HRULE*) GetMemoryForObject(nullptr/*GetCurrentMultigrid()*/,size,NOOBJ);
425 HRID id = global.maxrule[etag]++;
426
427
428
429
430 if (hr==NULL)
431 REP_ERR_RETURN (-1);
432
433 /* insert in list */
434 HR_NEXT(hr) = *next_handle;
435 *next_handle = hr;
436
437 /* init */
438 HR_ID(hr) = id;
439 HR_KEY(hr) = key;
440 HR_TAG(hr) = etag;
441 memcpy(HR_ERULE(hr), er, sizeof(ERULE)+sizeof(DOUBLE)*(ER_NSONS(er)-MAX_SONS));
442 memcpy(HR_OCOPTR(hr), oco, sizeof(DOUBLE)*ER_NSONS(er));
443
444 return (id);
445 }
446
447 /****************************************************************************/
448 /*doctext_disabled
449 SonsAreEqual - compare sons of rule with array of ordered sons
450
451 SYNOPSIS:
452 static INT SonsAreEqual (INT nsons, const DOUBLE oco[], const HRULE *hr)
453
454 PAAMETERS:
455 . nsons - number of sons
456 . oco - array of ordered sons
457 . hr - rule
458
459 DESCRIPTION:
460 Compare sons of rule with array of ordered sons
461
462 RETURN VALUE:
463 INT
464 .n YES: sons are equal
465 .n NO: sons are not equal
466 doctext_disabled*/
467 /****************************************************************************/
468
469 static bool SonsAreEqual (INT nsons, const DOUBLE oco[], const HRULE *hr)
470 {
471 if (nsons!=HR_NSONS(hr))
472 return false;
473
474 for (int s = 0; s < nsons; s++)
475 {
476 if (oco[s] != HR_OCO(hr, s))
477 return false;
478 }
479 return true;
480 }
481
482 /****************************************************************************/
483 /*doctext_disabled
484 GetRuleID - insert in hash table if not found there and return rule id for element
485
486 SYNOPSIS:
487 static HRID GetRuleID (ELEMENT *elem, INT etag, const ERULE *er)
488
489 PAAMETERS:
490 . elem - element (only in debug mode)
491 . etag - element tag
492 . er - rule
493
494 DESCRIPTION:
495 Insert in hash table if not found there and return rule id for element.
496
497 RETURN VALUE:
498 HRID
499 .n rule id (starting after rm IDs per tag)
500 doctext_disabled*/
501 /****************************************************************************/
502
503 #if (defined UG_DIM_3) || (defined __DEBUG_ER__)
504 static HRID GetRuleID
505 (
506 #ifdef Debug
507 ELEMENT *elem,
508 #endif
509 INT etag,
510 const ERULE *er
511 )
512 {
513 DOUBLE key = 0;
514 DOUBLE oco[MAX_SONS];
515
516 global.nelem_inspected[etag]++;
517 global.nelems_inspected++;
518
519 PRINTDEBUG(gm,ER_DBG_ELEM,(ELEM_INFO("GetRuleID",true,elem,ER_NSONS(er))));
520
521 FillOrderedSons(er,oco);
522
523 for (int s = 0; s < ER_NSONS(er); s++)
524 key += oco[s];
525
526 /** \todo (HRR 971211): use tag also for key? */
527
528 int h = HASH_ADDRESS(key);
529
530 HRULE *hr = global.hash_table[h];
531 if (hr==NULL)
532 return (Hash_InsertRule(etag,key,er,oco,&(global.hash_table[h])));
533
534 for (; hr!=NULL; hr=HR_NEXT(hr))
535 if (key==HR_KEY(hr) && etag==HR_TAG(hr) && SonsAreEqual(ER_NSONS(er),oco,hr))
536 return (HR_ID(hr));
537 else if ((HR_NEXT(hr)==NULL) || (key<HR_KEY(HR_NEXT(hr))))
538 break;
539
540 return (Hash_InsertRule(etag,key,er,oco,&HR_NEXT(hr)));
541 }
542 #endif
543
544 /****************************************************************************/
545 /*doctext_disabled
546 RuleCompare - compare er-rule with existing rm-rule
547
548 SYNOPSIS:
549 static INT RuleCompare (int id, const URULE *ur, const ERULE *er)
550
551 PAAMETERS:
552 . id - element id
553 . ur - rm rule
554 . er - er rule
555
556 DESCRIPTION:
557 Compare er-rule with existing rm-rule (used in __PATCH_UG_RULES__ mode).
558
559 RETURN VALUE:
560 INT
561 .n YES: rules are equal
562 .n NO: rules are not equal
563 doctext_disabled*/
564 /****************************************************************************/
565 #ifdef __DEBUG_ER__
566 static INT RuleCompare (int id, const URULE *ur, const ERULE *er)
567 {
568 const int ns0 = NSONS_OF_RULE(ur);
569 const int ns1 = ER_NSONS(er);
570
571 if (ns0!=ns1)
572 {
573 PrintDebug("CompareRules: rules not equal: elem%d (ns0=%d != ns1=%d)\n",id,ns0,ns1);
574 return (NO);
575 }
576
577 /* compare sons */
578 for (int s0 = 0; s0 < ns0; s0++)
579 {
580 const SONDATA *son0 = SON_OF_RULE(ur,s0);
581 int nco0 = CORNERS_OF_TAG(SON_TAG(son0));
582
583 int s1;
584 for (s1 = 0; s1 < ns1; s1++)
585 {
586 int nco1 = ER_NCO(er,s1);
587
588 if (nco0==nco1)
589 {
590 int corners_match = true;
591 int i;
592
593 for (i=0; i<nco0; i++)
594 {
595 int co0 = SON_CORNER(son0,i);
596 SHORT corners[MAX_CORNERS_OF_ELEM_DIM];
597 int j;
598
599 DCorners2Corners(ER_NCO(er,s1),ER_DCO(er,s1),corners);
600
601 for (j=0; j<nco1; j++)
602 if (co0==corners[j])
603 break;
604 if (j>=nco1)
605 {
606 corners_match = false;
607 break;
608 }
609 }
610 if (corners_match)
611 break;
612 }
613 }
614 if (s1>=ns1)
615 {
616 PrintDebug("CompareRules: rules not equal: elem%d (son=%d of urule not in erule)\n",id,s0);
617 return (NO);
618 }
619 }
620 return (YES);
621 }
622 #endif
623 /****************************************************************************/
624 /*doctext_disabled
625 ExtractERule - extract rule from element
626
627 SYNOPSIS:
628 static INT ExtractERule (ELEMENT *elem, ERULE *er)
629
630 PAAMETERS:
631 . elem - element
632 . er - extracted rule
633
634 DESCRIPTION:
635 Extract rule from element (rule may be incomplete in parallel)
636
637 RETURN VALUE:
638 INT
639 .n 0: ok
640 .n >0: error
641 doctext_disabled*/
642 /****************************************************************************/
643
644 static INT ExtractERule (ELEMENT *elem, ERULE *er)
645 {
646 int nsons = NSONS(elem);
647 ELEMENT *sons[MAX_SONS];
648 NODE *nodes[MAX_REFINED_CORNERS_DIM];
649
650 if (GetNodeContext(elem,nodes))
651 REP_ERR_RETURN(1);
652
653 /* get sons with master priority */
654 if (GetAllSons(elem,sons))
655 REP_ERR_RETURN(1);
656
657 ER_NSONS(er) = 0;
658 for (int s = 0; s < nsons; s++)
659 {
660 ELEMENT *son = sons[s];
661 int coe = CORNERS_OF_ELEM(son);
662 SHORT corners[MAX_CORNERS_OF_ELEM_DIM];
663
664 if (EGHOST(son)) continue;
665
666 ER_NSONS(er)++;
667
668 /* corners and dcorners */
669 ER_NCO(er,s) = coe;
670 for (int j = 0; j < coe; j++)
671 {
672 const NODE *node = CORNER(son,j);
673
674 int k;
675 for (k = 0; k < MAX_REFINED_CORNERS_DIM; k++)
676 if (node==nodes[k])
677 break;
678 ASSERT(k<MAX_REFINED_CORNERS_DIM);
679 corners[j] = k;
680 }
681 ER_DCO(er,s) = Corner2DCorners(CORNERS_OF_ELEM(son),corners);
682 }
683
684 #ifdef __DEBUG_ER__
685 if (!(REFINE(elem)==COPY && NSONS(elem)>1))
686 {
687 URULE *ur = MARK2RULEADR(elem,REFINE(elem));
688
689 RuleCompare(ID(elem),ur,er);
690 }
691 #endif
692
693 return (0);
694 }
695
696 /****************************************************************************/
697 /*
698 functions for parallel mode only
699 */
700 /****************************************************************************/
701
702 #ifdef ModelP
703
704 /****************************************************************************/
705 /*doctext_disabled
706 CountIFElements - count interface elements having no rm-rule
707
708 SYNOPSIS:
709 static int CountIFElements (DDD_OBJ obj)
710
711 PAAMETERS:
712 . obj - element
713
714 DESCRIPTION:
715 Count interface elements having no rm-rule (masters and VH-hgosts).
716 Those elements are flagged true.
717
718 RETURN VALUE:
719 int
720 .n 0: ok
721
722 SEE ALSO:
723 ExtractInterfaceRules
724 doctext_disabled*/
725 /****************************************************************************/
726
727 #if (defined UG_DIM_3) || (defined __DEBUG_ER__)
728 static int CountIFElements (DDD::DDDContext&, DDD_OBJ obj)
729 {
730 ELEMENT *elem = (ELEMENT*) obj;
731
732 if (HAS_NO_RULE(elem))
733 {
734 SETTHEFLAG(elem,true);
735
736 ASSERT(global.if_elems<MAX_IFID);
737
738 SETREFINE(elem,global.if_elems);
739 global.if_elems++;
740 }
741 else
742 {
743 SETTHEFLAG(elem,false);
744 }
745
746 return (0);
747 }
748
749 /****************************************************************************/
750 /*doctext_disabled
751 InitMasterRules - init rules of master elements
752
753 SYNOPSIS:
754 static int InitMasterRules (DDD_OBJ obj)
755
756 PAAMETERS:
757 . obj - element
758
759 DESCRIPTION:
760 Init rules of master elements at processor interface with sons of master.
761
762 RETURN VALUE:
763 int
764 .n 0: ok
765 .n >0: error
766
767 SEE ALSO:
768 ExtractInterfaceRules
769 doctext_disabled*/
770 /****************************************************************************/
771
772 static int InitMasterRules (DDD::DDDContext&, DDD_OBJ obj)
773 {
774 ELEMENT *elem = (ELEMENT*) obj;
775
776 if (THEFLAG(elem))
777 {
778 ERULE *er = global.interface_rules+REFINE(elem);
779 return (ExtractERule((ELEMENT*)obj,er));
780 }
781 else
782 return (0);
783 }
784
785 /****************************************************************************/
786 /*doctext_disabled
787 Gather_ERULE - extract rules from interface elements
788
789 SYNOPSIS:
790 static int Gather_ERULE (DDD_OBJ obj, void *data)
791
792 PAAMETERS:
793 . obj - element
794 . data - rule
795
796 DESCRIPTION:
797 Extract rules from interface elements (masters and VH-ghosts)
798
799 RETURN VALUE:
800 int
801 .n 0: ok
802 .n >0: error
803
804 SEE ALSO:
805 ExtractInterfaceRules
806 doctext_disabled*/
807 /****************************************************************************/
808
809 static int Gather_ERULE (DDD::DDDContext&, DDD_OBJ obj, void *data)
810 {
811 ELEMENT *elem = (ELEMENT*) obj;
812
813 if (THEFLAG(elem))
814 return (ExtractERule(elem,(ERULE*)data));
815 else
816 return (0);
817 }
818
819 /****************************************************************************/
820 /*doctext_disabled
821 Scatter_ERULE - write completed rule for VH-ghosts
822
823 SYNOPSIS:
824 static int Scatter_ERULE (DDD_OBJ obj, void *data)
825
826 PAAMETERS:
827 . obj - element
828 . data - rule previously completed by master
829
830 DESCRIPTION:
831 Write completed rule for VH-ghosts.
832
833 RETURN VALUE:
834 int
835 .n 0: ok
836
837 SEE ALSO:
838 ExtractInterfaceRules
839 doctext_disabled*/
840 /****************************************************************************/
841
842 static int Scatter_ERULE (DDD::DDDContext&, DDD_OBJ obj, void *data)
843 {
844 ELEMENT *elem = (ELEMENT*)obj;
845
846 if (THEFLAG(elem))
847 {
848 ERULE *er = global.interface_rules+REFINE(elem);
849 memcpy(er,data,sizeof(ERULE));
850 }
851
852 return (0);
853 }
854
855 /****************************************************************************/
856 /*doctext_disabled
857 Scatter_partial_ERULE - add son-info from VH-ghosts to master rule
858
859 SYNOPSIS:
860 static int Scatter_partial_ERULE (DDD_OBJ obj, void *data)
861
862 PAAMETERS:
863 . obj - element
864 . data - rule
865
866 DESCRIPTION:
867 Add son-info from VH-ghosts to master rule.
868
869 RETURN VALUE:
870 int
871 .n 0: ok
872
873 SEE ALSO:
874 ExtractInterfaceRules
875 doctext_disabled*/
876 /****************************************************************************/
877
878 static int Scatter_partial_ERULE (DDD::DDDContext&, DDD_OBJ obj, void *data)
879 {
880 ELEMENT *elem = (ELEMENT*)obj;
881
882 if (THEFLAG(elem))
883 {
884 ERULE *er_ma = global.interface_rules+REFINE(elem);
885 ERULE *er_gh = (ERULE*)data;
886 int s_ma = ER_NSONS(er_ma);
887 int s_gh;
888
889 /* put sons at and of rule */
890 for (s_gh=0; s_gh<ER_NSONS(er_gh); s_gh++)
891 {
892 ASSERT(s_ma<MAX_SONS);
893
894 ER_NCO(er_ma,s_ma) = ER_NCO(er_gh,s_gh);
895 ER_DCO(er_ma,s_ma) = ER_DCO(er_gh,s_gh);
896 s_ma++;
897 }
898 ER_NSONS(er_ma) = s_ma;
899 }
900
901 return (0);
902 }
903
904 /****************************************************************************/
905 /*doctext_disabled
906 ExtractInterfaceERule - extract rule from interface element
907
908 SYNOPSIS:
909 static int ExtractInterfaceERule (DDD_OBJ obj)
910
911 PAAMETERS:
912 . obj - element
913
914 DESCRIPTION:
915 Extract rule from interface element and get id from hash table (if there
916 is no rm-rule for this element).
917
918 RETURN VALUE:
919 int
920 .n 0: ok
921
922 SEE ALSO:
923 ExtractInterfaceRules
924 doctext_disabled*/
925 /****************************************************************************/
926
927 static int ExtractInterfaceERule (DDD::DDDContext&, DDD_OBJ obj)
928 {
929 ELEMENT *elem = (ELEMENT*)obj;
930
931 if (THEFLAG(elem))
932 {
933 const ERULE *er = global.interface_rules + REFINE(elem);
934 int id = GetRuleID(
935 #ifdef Debug
936 elem,
937 #endif
938 TAG(elem),er);
939
940 ASSERT(id<MAX_HRID);
941
942 SETREFINE(elem,id);
943 }
944 else
945 {
946 global.nelem_not_inspected[TAG(elem)]++;
947 global.nelems_not_inspected++;
948
949 IFDEBUG(gm,ER_DBG_ELEM)
950 int nsons;
951 ELEMENT *sons[MAX_SONS];
952
953 if (GetSons(elem,sons))
954 REP_ERR_RETURN(1);
955 for (nsons=0; nsons<MAX_SONS; nsons++)
956 if (sons[nsons]==NULL)
957 break;
958 PrintDebug(ELEM_INFO("ExtractInterfaceERule",false,elem,nsons));
959 ENDDEBUG
960 }
961
962 SETUSED(elem,true);
963
964 return (0);
965 }
966
967 /****************************************************************************/
968 /*doctext_disabled
969 ExtractInterfaceRules - extract all rules from interface elements without rm-rule
970
971 SYNOPSIS:
972 static INT ExtractInterfaceRules (MULTIGRID *mg)
973
974 PAAMETERS:
975 . mg - multigrid
976
977 DESCRIPTION:
978 Extract all rules from interface elements without rm-rule.
979
980 RETURN VALUE:
981 INT
982 .n 0: ok
983 .n >0: error in storage allocation
984 doctext_disabled*/
985 /****************************************************************************/
986
987 static INT ExtractInterfaceRules (MULTIGRID *mg)
988 {
989 auto& context = mg->dddContext();
990 const auto& dddctrl = ddd_ctrl(context);
991
992 /* TODO (HRR 971211): don't include TOPLEVEL (no elem refined there) */
993 for (int lev = 0; lev <= TOPLEVEL(mg); lev++)
994 {
995 GRID *grid = GRID_ON_LEVEL(mg,lev);
996
997 /* count interface master and vhghost elements */
998 global.if_elems = 1;
999 DDD_IFAExecLocal(context, dddctrl.ElementVHIF, GRID_ATTR(grid), CountIFElements);
1000
1001 if (global.if_elems>1)
1002 {
1003 INT MarkKey;
1004
1005 PRINTDEBUG(gm,ER_DBG_GENERAL,("ExtractInterfaceRules: interface elements to consider on level %d: %ld\n",lev,global.if_elems));
1006
1007 if (MarkTmpMem(global.heap,&MarkKey))
1008 REP_ERR_RETURN(1);
1009
1010 /* REMARK (HRR 971207): storage could be Marked and Released in pieces if necessary
1011 to allow BOTTOM-storage to grow */
1012 global.interface_rules = (ERULE*)GetTmpMem(global.heap,(global.if_elems+1)*sizeof(ERULE),MarkKey);
1013 if (global.interface_rules==NULL)
1014 REP_ERR_RETURN(1);
1015
1016 /* init rules of masters */
1017 DDD_IFAExecLocal(context, dddctrl.ElementIF, GRID_ATTR(grid), InitMasterRules);
1018
1019 /* communicate VHghosts --> master */
1020 DDD_IFAOneway(context, dddctrl.ElementVHIF, GRID_ATTR(grid), IF_BACKWARD, sizeof(ERULE),
1021 Gather_ERULE, Scatter_partial_ERULE);
1022
1023 /* communicate master --> VHghosts */
1024 DDD_IFAOneway(context, dddctrl.ElementVHIF, GRID_ATTR(grid), IF_FORWARD, sizeof(ERULE),
1025 Gather_ERULE, Scatter_ERULE);
1026
1027 /* extract rules from interface elements */
1028 DDD_IFAExecLocal(context, dddctrl.ElementVHIF, GRID_ATTR(grid), ExtractInterfaceERule);
1029
1030 IFDEBUG(gm,ER_DBG_GENERAL)
1031 long N_er = 0;
1032
1033 PrintDebug("ExtractInterfaceRules: number of refrules extracted from interface on level %d:\n",lev);
1034 for (int tag = 0; tag < TAGS; tag++)
1035 {
1036 long n_er = global.maxrule[tag] - UGMAXRULE(tag);
1037 N_er += n_er;
1038 PrintDebug("tag %d: %ld extracted rules\n",tag,n_er);
1039 }
1040 PrintDebug("total: %ld extracted rules\n",N_er);
1041 ENDDEBUG
1042
1043 if (ReleaseTmpMem(global.heap,MarkKey))
1044 REP_ERR_RETURN(1);
1045 }
1046 }
1047
1048 return (0);
1049 }
1050 #endif
1051 #endif /* ModelP */
1052
1053 /****************************************************************************/
1054 /*doctext_disabled
1055 ExtractRules - extract all realized rules that have no rm-rule
1056
1057 SYNOPSIS:
1058 static INT ExtractRules (MULTIGRID *mg)
1059
1060 PAAMETERS:
1061 . mg - multigrid
1062
1063 DESCRIPTION:
1064 Extract all realized rules of the mg that have no rm-rule.
1065
1066 RETURN VALUE:
1067 INT
1068 .n 0: ok
1069 .n >0: error
1070 doctext_disabled*/
1071 /****************************************************************************/
1072
1073 #if (defined UG_DIM_3) || (defined __DEBUG_ER__)
1074 static INT ExtractRules (MULTIGRID *mg)
1075 {
1076 ERULE er;
1077 INT MarkKey;
1078 int maxrules;
1079
1080 /* for hash table */
1081 if (MarkTmpMem(global.heap,&MarkKey))
1082 REP_ERR_RETURN(1);
1083
1084 if (Hash_Init(MarkKey))
1085 REP_ERR_RETURN(1);
1086
1087 global.nelems_inspected = global.nelems_not_inspected = 0;
1088 for (int tag = 0; tag < TAGS; tag++)
1089 global.nelem_inspected[tag] = global.nelem_not_inspected[tag] = 0;
1090
1091 /* loop elements and extract rules */
1092 #ifdef ModelP
1093 /* TODO (HRR 971211): don't include TOPLEVEL (no elem refined there) */
1094 for (int l = 0; l <= TOPLEVEL(mg); l++)
1095 for (ELEMENT *elem = FIRSTELEMENT(GRID_ON_LEVEL(mg, l)); elem != NULL; elem = SUCCE(elem))
1096 SETUSED(elem,false);
1097 if (ExtractInterfaceRules(mg))
1098 REP_ERR_RETURN(1);
1099 #endif
1100
1101 /* TODO (HRR 971211): don't include TOPLEVEL (no elem refined there) */
1102 for (int l = 0; l <= TOPLEVEL(mg); l++)
1103 for (ELEMENT *elem = FIRSTELEMENT(GRID_ON_LEVEL(mg, l)); elem != NULL; elem = SUCCE(elem))
1104 #ifdef ModelP
1105 if (!USED(elem))
1106 {
1107 #endif
1108 if (HAS_NO_RULE(elem))
1109 {
1110 if (ExtractERule(elem,&er))
1111 REP_ERR_RETURN(1);
1112 HRID id = GetRuleID(
1113 #ifdef Debug
1114 elem,
1115 #endif
1116 TAG(elem),&er);
1117 ASSERT(id<MAX_HRID);
1118 SETREFINE(elem,id);
1119 }
1120 else
1121 {
1122 global.nelem_not_inspected[TAG(elem)]++;
1123 global.nelems_not_inspected++;
1124 IFDEBUG(gm,ER_DBG_ELEM)
1125 int nsons;
1126 ELEMENT *sons[MAX_SONS];
1127
1128 if (GetSons(elem,sons))
1129 REP_ERR_RETURN(1);
1130 for (nsons=0; nsons<MAX_SONS; nsons++)
1131 if (sons[nsons]==NULL)
1132 break;
1133 PrintDebug(ELEM_INFO("ExtractRules",false,elem,nsons));
1134 if (NSONS(elem)!=nsons)
1135 PrintDebug("------ ERROR: NSONS!=nsons -------\n");
1136 ENDDEBUG
1137 }
1138 #ifdef ModelP
1139 }
1140 #endif
1141
1142 global.maxrules = maxrules = 0;
1143 for (int tag = 0; tag < TAGS; tag++)
1144 {
1145 global.maxrules += global.maxrule[tag];
1146 maxrules += global.maxrule[tag] - UGMAXRULE(tag);
1147 }
1148
1149 if (maxrules>0)
1150 {
1151 #ifdef Debug
1152 int n = 0;
1153 #endif
1154 int max_list_len = 0;
1155
1156 /* make tables of subsequent IDs */
1157 // I think that nullptr can replace the call to GetCurrentMultigrid, because that method
1158 // has been returning nullptr for a long time.
1159 // In other words: it seems the method we are in is never called.
1160 global.hrule[0] = (HRULE**)
1161 GetMemoryForObject(nullptr/*GetCurrentMultigrid()*/,
1162 global.maxrules*sizeof(HRULE*),NOOBJ);
1163 if (global.hrule[0]==NULL)
1164 REP_ERR_RETURN(1);
1165 for (int tag = 1; tag < TAGS; tag++)
1166 global.hrule[tag] = global.hrule[tag-1]+global.maxrule[tag-1];
1167
1168 for (int h = 0; h < HASH_SIZE; h++)
1169 {
1170 int list_len = 0;
1171 HRULE *hr;
1172
1173 for (hr=global.hash_table[h]; hr!=NULL; hr=HR_NEXT(hr))
1174 {
1175 global.hrule[HR_TAG(hr)][HR_ID(hr)] = hr;
1176 list_len++;
1177 #ifdef Debug
1178 n++;
1179 #endif
1180 }
1181 max_list_len = std::max(max_list_len,list_len);
1182 }
1183 ASSERT(maxrules==n);
1184
1185 PRINTDEBUG(gm,ER_DBG_GENERAL,("ExtractRules: max members of hash table entries is %d\n",max_list_len));
1186 }
1187 else
1188 PRINTDEBUG(gm,ER_DBG_GENERAL,("ExtractRules: realized rules were completely covered by rm rules\n"));
1189
1190 if (ReleaseTmpMem(global.heap,MarkKey))
1191 REP_ERR_RETURN(1);
1192
1193 return (0);
1194 }
1195 #endif
1196
1197 /****************************************************************************/
1198 /*doctext_disabled
1199 FindPathForNeighbours - recursive function computing path infos
1200
1201 SYNOPSIS:
1202 static void FindPathForNeighbours (MGIO_RR_RULE *rule, SHORT myID, SHORT Status[MAX_SONS])
1203
1204 PAAMETERS:
1205 . rule - mrule
1206 . myID - son ID
1207 . Status - status (see 'enum NB_STATUS' in er.c)
1208
1209 DESCRIPTION:
1210 Recursive function computing path infos for sons.
1211
1212 RETURN VALUE:
1213 void
1214 .n none
1215 doctext_disabled*/
1216 /****************************************************************************/
1217
1218 static void FindPathForNeighbours (MGIO_RR_RULE *rule, SHORT myID, SHORT Status[MAX_SONS])
1219 {
1220 for (SHORT i = 0; i < MAX_SIDES_OF_ELEM; i++) {
1221 SHORT nbID = rule->sons[myID].nb[i];
1222 if ((nbID < FATHER_SIDE_OFFSET) && (Status[nbID] == NB_NOTDONE))
1223 {
1224 /* copy myPath to nbPath */
1225 INT nbPath = rule->sons[myID].path;
1226
1227 /* complete nbPath */
1228 SHORT nbPathDepth = PATHDEPTH(nbPath);
1229 SETNEXTSIDE(nbPath,nbPathDepth,i);
1230 SETPATHDEPTH(nbPath,++nbPathDepth);
1231 Status[nbID] = NB_TOUCHED;
1232 }
1233 }
1234
1235 /* recursive call for NB_TOUCHED sons */
1236 for (SHORT nbID = 1; nbID < rule->nsons; nbID++)
1237 if (Status[nbID]==NB_TOUCHED)
1238 {
1239 Status[nbID] = NB_DONE;
1240 FindPathForNeighbours(rule,nbID,Status);
1241 }
1242 }
1243
1244 /****************************************************************************/
1245 /*doctext_disabled
1246 FillSonPaths - fill son path components in mrule
1247
1248 SYNOPSIS:
1249 static void FillSonPaths (MGIO_RR_RULE *rule)
1250
1251 PAAMETERS:
1252 . rule - mrule
1253
1254 DESCRIPTION:
1255 Fill son path components in mrule by recursion (using 'FindPathForNeighbours').
1256
1257 RETURN VALUE:
1258 void
1259 .n none
1260 doctext_disabled*/
1261 /****************************************************************************/
1262 #ifdef UG_DIM_3
1263 static void FillSonPaths (MGIO_RR_RULE *rule)
1264 {
1265 SHORT Status[MAX_SONS];
1266
1267 /* TODO (HRR 971211): debug recursive path construction
1268 (taken from GenerateRules but not used by ugio) */
1269
1270 /* son 0 has trivial path */
1271 Status[0] = NB_DONE;
1272 rule->sons[0].path = 0;
1273 for (int i = 1; i < rule->nsons; i++)
1274 Status[i] = NB_NOTDONE;
1275
1276 /* start recursion with son 0 */
1277 FindPathForNeighbours(rule,0,Status);
1278 }
1279 #endif
1280 /****************************************************************************/
1281 /*doctext_disabled
1282 GetFSidesOfCorners - fill array for father side the given side corners belong to
1283
1284 SYNOPSIS:
1285 static INT GetFSidesOfCorners (int tag, int n, SHORT corners[MAX_CORNERS_OF_SIDE], SHORT corner_on_side[MAX_CORNERS_OF_SIDE][MAX_SIDES_OF_ELEM])
1286
1287 PAAMETERS:
1288 . tag - father tag
1289 . n - number of side nodes
1290 . corners - side node local IDs
1291 . corner_on_side - YES/NO indicating corner lying on father side
1292
1293 DESCRIPTION:
1294 Fill array for father side the given side corners belong to.
1295
1296 RETURN VALUE:
1297 INT
1298 .n true: ok, maybe there is a common father side
1299 .n false: sorry, center node definitely not on a father side
1300 doctext_disabled*/
1301 /****************************************************************************/
1302
1303 static bool GetFSidesOfCorners (int tag, int n, const SHORT corners[MAX_CORNERS_OF_SIDE], SHORT corner_on_side[MAX_CORNERS_OF_SIDE][MAX_SIDES_OF_ELEM])
1304 {
1305 int coe = CORNERS_OF_TAG(tag);
1306 int eoe = EDGES_OF_TAG(tag);
1307 int soe = SIDES_OF_TAG(tag);
1308
1309 for (int co = 0; co < n; co++)
1310 for (int side = 0; side < soe; side++)
1311 corner_on_side[co][side] = false;
1312
1313 for (int co = 0; co < n; co++)
1314 if (corners[co]==coe+CENTER_NODE_INDEX_TAG(tag))
1315 {
1316 /* center node: can not be part of a father side */
1317 return false;
1318 }
1319 else if (corners[co]<coe)
1320 {
1321 /* father corner */
1322 int fco = corners[co];
1323
1324 for (int side = 0; side < soe; side++)
1325 if (CORNER_OF_SIDE_INV_TAG(tag,side,fco)>=0)
1326 corner_on_side[co][side] = true;
1327 }
1328 else if (corners[co]<(coe+eoe))
1329 {
1330 /* edge mid node */
1331 int ed = corners[co]-coe;
1332
1333 #ifdef UG_DIM_2
1334 corner_on_side[co][ed] = true;
1335 #else
1336 for (int i = 0; i < MAX_SIDES_OF_EDGE; i++)
1337 {
1338 int sd = SIDE_WITH_EDGE_TAG(tag,ed,i);
1339 if (sd>=0)
1340 corner_on_side[co][sd] = true;
1341 }
1342 #endif
1343 }
1344 #ifdef UG_DIM_3
1345 else if (corners[co]<(coe+eoe+soe))
1346 {
1347 /* side mid */
1348 int sd = corners[co]-(coe+eoe);
1349 corner_on_side[co][sd] = true;
1350 }
1351 #endif
1352 else
1353 ASSERT(false); /* Huh??? */
1354
1355 return true;
1356 }
1357
1358 /****************************************************************************/
1359 /*doctext_disabled
1360 GetCommonFSide - return common father element side iff
1361
1362 SYNOPSIS:
1363 static INT GetCommonFSide (int nco, int nsi, SHORT corner_on_side[MAX_CORNERS_OF_SIDE][MAX_SIDES_OF_ELEM])
1364
1365 PAAMETERS:
1366 . nco - number of corners on side
1367 . nsi - number of sides
1368 . corner_on_side - array filled by 'GetFSidesOfCorners'
1369
1370 DESCRIPTION:
1371 Return common father element side iff.
1372
1373 RETURN VALUE:
1374 INT
1375 .n father side if common for all side corners
1376 .n nsi else
1377 doctext_disabled*/
1378 /****************************************************************************/
1379
1380 static INT GetCommonFSide (int nco, int nsi, SHORT corner_on_side[MAX_CORNERS_OF_SIDE][MAX_SIDES_OF_ELEM])
1381 {
1382 for (int side = 0; side < nsi; side++)
1383 {
1384 int i;
1385 for (i = 0; i < nco; i++)
1386 if (!corner_on_side[i][side])
1387 break;
1388 if (i>=nco)
1389 return (side);
1390 }
1391 return (nsi);
1392 }
1393
1394 /****************************************************************************/
1395 /*doctext_disabled
1396 IsOnFatherSide - determine whether son side lies on father side
1397
1398 SYNOPSIS:
1399 static INT IsOnFatherSide (int tag, int nsco, SHORT sco[], SHORT *nb)
1400
1401 PAAMETERS:
1402 . tag - father tag
1403 . nsco - number of side corners
1404 . sco - side corner array
1405 . nb - fill nb component with FATHER_SIDE_OFFSET+fside iff common father side
1406
1407 DESCRIPTION:
1408 Determine whether son side lies on father side.
1409
1410 RETURN VALUE:
1411 INT
1412 .n true: there is a common father side
1413 .n false: there is no common father side
1414 doctext_disabled*/
1415 /****************************************************************************/
1416
1417 static bool IsOnFatherSide (int tag, int nsco, SHORT sco[], SHORT *nb)
1418 {
1419 SHORT sco_on_side[MAX_CORNERS_OF_SIDE][MAX_SIDES_OF_ELEM];
1420
1421 if (GetFSidesOfCorners(tag,nsco,sco,sco_on_side))
1422 {
1423 int fside = GetCommonFSide(nsco,SIDES_OF_TAG(tag),sco_on_side);
1424
1425 if (fside<SIDES_OF_TAG(tag))
1426 {
1427 *nb = FATHER_SIDE_OFFSET+fside;
1428 return true;
1429 }
1430 }
1431 return false;
1432 }
1433
1434 /****************************************************************************/
1435 /*doctext_disabled
1436 SidesMatch - check whether two son sides match
1437
1438 SYNOPSIS:
1439 static INT SidesMatch (int nsco, SHORT sco0[], SHORT sco1[])
1440
1441 PAAMETERS:
1442 . nsco - number of side corners
1443 . sco0 - side corners of first son
1444 . sco1 - side corners of second son
1445
1446 DESCRIPTION:
1447 Check whether two son sides match.
1448
1449 RETURN VALUE:
1450 INT
1451 .n true: son sides are matching
1452 .n false: son sides are not matching
1453 doctext_disabled*/
1454 /****************************************************************************/
1455
1456 static bool SidesMatch (int nsco, const SHORT sco0[], const SHORT sco1[])
1457 {
1458 /* try each permutation of first with reverse order of second */
1459 for (int i = 0; i < nsco; i++)
1460 {
1461 int match = true;
1462
1463 for (int j = 0; j < nsco; j++)
1464 if (sco0[(i+j)%nsco]!=sco1[nsco-j-1])
1465 {
1466 match = false;
1467 break;
1468 }
1469 if (match)
1470 return true;
1471 }
1472 return false;
1473 }
1474
1475 /****************************************************************************/
1476 /*doctext_disabled
1477 HRule2Mrule - convert rule to MGIO_RR_RULE
1478
1479 SYNOPSIS:
1480 static void HRule2Mrule (const HRULE *hr, MGIO_RR_RULE *mr)
1481
1482 PAAMETERS:
1483 . hr - hashed rule
1484 . mr - mgio rule
1485
1486 DESCRIPTION:
1487 Convert local rule type HRULE (hashed rule) to MGIO_RR_RULE.
1488
1489 RETURN VALUE:
1490 void
1491 .n
1492 doctext_disabled*/
1493 /****************************************************************************/
1494
1495 static void HRule2Mrule (const HRULE *hr, MGIO_RR_RULE *mr)
1496 {
1497 int coe = CORNERS_OF_TAG(HR_TAG(hr));
1498
1499 /* extracted rules are always irregular */
1500 /* TODO (HRR 971208): is that really ok (actually not used)? */
1501 mr->rclass = GREEN_CLASS;
1502 mr->nsons = HR_NSONS(hr);
1503
1504 for (int i = 0; i < MGIO_MAX_NEW_CORNERS; i++)
1505 mr->pattern[i] = 0;
1506
1507 /* son tags, corners, sonandnode, pattern */
1508 for (int s = 0; s < mr->nsons; s++)
1509 {
1510 struct mgio_sondata *sonData = &(mr->sons[s]);
1511 int nco = HR_NCO(hr,s);
1512 int j;
1513 int sd0;
1514
1515 for (sd0=0; sd0<MAX_SIDES_OF_ELEM; sd0++)
1516 sonData->nb[sd0] = NOTDONE;
1517
1518 sonData->tag = REF2TAG(nco);
1519 DCorners2Corners(nco,HR_DCO(hr,s),sonData->corners);
1520 for (j=0; j<nco; j++)
1521 {
1522 int newco = sonData->corners[j]-coe;
1523
1524 if (newco<0)
1525 continue;
1526
1527 /* TODO (HRR 971208): what about center node pattern for tets? */
1528 mr->pattern[newco] = 1;
1529 mr->sonandnode[newco][0] = s;
1530 mr->sonandnode[newco][1] = j;
1531 }
1532 }
1533
1534 /* son nb */
1535 for (int s0 = 0; s0 < mr->nsons; s0++)
1536 {
1537 struct mgio_sondata *sonData0 = mr->sons+s0;
1538
1539 for (int sd0 = 0; sd0 < MAX_SIDES_OF_ELEM; sd0++)
1540 if (sonData0->nb[sd0] == NOTDONE)
1541 {
1542 int stag0 = sonData0->tag;
1543 int nsco0 = CORNERS_OF_SIDE_TAG(stag0,sd0);
1544 SHORT sco0[MAX_CORNERS_OF_SIDE];
1545
1546 for (int j = 0; j < nsco0; j++)
1547 sco0[j] = sonData0->corners[CORNER_OF_SIDE_TAG(stag0,sd0,j)];
1548
1549 if (!IsOnFatherSide(HR_TAG(hr),nsco0,sco0,&(sonData0->nb[sd0])))
1550 {
1551 bool found = false;
1552
1553 /* find matching side of other son */
1554 for (int s1 = s0+1; s1 < mr->nsons; s1++)
1555 {
1556 struct mgio_sondata *sonData1 = mr->sons+s1;
1557
1558 for (int sd1 = 0; sd1 < MAX_SIDES_OF_ELEM; sd1++)
1559 {
1560 int stag1 = sonData1->tag;
1561 int nsco1 = CORNERS_OF_SIDE_TAG(stag1,sd1);
1562
1563 if (nsco0==nsco1)
1564 {
1565 SHORT sco1[MAX_CORNERS_OF_SIDE];
1566
1567 {int j; for (j=0; j<nsco1; j++)
1568 sco1[j] = sonData1->corners[CORNER_OF_SIDE_TAG(stag1,sd1,j)];}
1569
1570 if (SidesMatch(nsco0,sco0,sco1))
1571 {
1572 /* neighbour found */
1573 sonData0->nb[sd0] = s1;
1574 sonData1->nb[sd1] = s0;
1575
1576 found = true;
1577 break;
1578 }
1579 }
1580 }
1581 if (found)
1582 break;
1583 }
1584 ASSERT(found);
1585 }
1586 }
1587 }
1588
1589 #ifdef UG_DIM_3
1590 /* 2D: not even in rm */
1591 /* son path */
1592 FillSonPaths(mr);
1593 #endif
1594 }
1595
1596 /****************************************************************************/
1597 /*doctext_disabled
1598 URule2Mrule - convert rule manager rule to MGIO_RR_RULE
1599
1600 SYNOPSIS:
1601 static void URule2Mrule (const URULE *ur, MGIO_RR_RULE *mr)
1602
1603 PAAMETERS:
1604 . ur - rule manager rule
1605 . mr - mgio rule
1606
1607 DESCRIPTION:
1608 Convert rule manager rule to mgio rule.
1609
1610 RETURN VALUE:
1611 void
1612 .n
1613 doctext_disabled*/
1614 /****************************************************************************/
1615
1616 static void URule2Mrule (const URULE *ur, MGIO_RR_RULE *mr)
1617 {
1618 mr->rclass = ur->rclass;
1619 mr->nsons = ur->nsons;
1620 for (int j = 0; j < MGIO_MAX_NEW_CORNERS; j++)
1621 mr->pattern[j] = ur->pattern[j];
1622 for (int j = 0; j < MGIO_MAX_NEW_CORNERS; j++)
1623 {
1624 mr->sonandnode[j][0] = ur->sonandnode[j][0];
1625 mr->sonandnode[j][1] = ur->sonandnode[j][1];
1626 }
1627 for (int j = 0; j < mr->nsons; j++)
1628 {
1629 struct mgio_sondata *sonData = &(mr->sons[j]);
1630
1631 sonData->tag = ur->sons[j].tag;
1632 for (int k = 0; k < MGIO_MAX_CORNERS_OF_ELEM; k++)
1633 sonData->corners[k] = ur->sons[j].corners[k];
1634 for (int k = 0; k < MGIO_MAX_SIDES_OF_ELEM; k++)
1635 sonData->nb[k] = ur->sons[j].nb[k];
1636 sonData->path = ur->sons[j].path;
1637 }
1638 }
1639
1640 static void WriteDebugInfo (void)
1641 {
1642 long N_rm=0,N_er=0;
1643 long Nelem_inspected = 0;
1644 long Nelem_not_inspected = 0;
1645
1646 /* number of rules (rm+er) */
1647 PrintDebug("------------- Write_RefRules statistics --------------\n");
1648 PrintDebug("number of refrules:\n");
1649 for (int tag = 0; tag < TAGS; tag++)
1650 {
1651 long n_rm = UGMAXRULE(tag);
1652 long n_er = global.maxrule[tag]-UGMAXRULE(tag);
1653 N_rm += n_rm;
1654 N_er += n_er;
1655 Nelem_inspected = global.nelem_inspected[tag];
1656 Nelem_not_inspected += global.nelem_not_inspected[tag];
1657 PrintDebug("tag %d: %3ld rm rules, %4ld extracted rules (elems inspected: %6ld yes %6ld no)\n",
1658 tag,
1659 n_rm,
1660 n_er,
1661 global.nelem_inspected[tag],
1662 global.nelem_not_inspected[tag]);
1663 }
1664 PrintDebug("total: %3ld rm rules, %4ld extracted rules (elems inspected: %6ld yes %6ld no)\n",
1665 N_rm,
1666 N_er,
1667 Nelem_inspected,
1668 Nelem_not_inspected);
1669
1670 PrintDebug("------------------------------------------------------\n");
1671 }
1672
1673 INT NS_DIM_PREFIX GetOrderedSons (ELEMENT *theElement, MGIO_RR_RULE *theRule, NODE **NodeContext, ELEMENT **SonList, INT *nmax)
1674 {
1675 ELEMENT *NonorderedSonList[MAX_SONS];
1676
1677 *nmax = 0;
1678
1679 if (GetAllSons(theElement,NonorderedSonList)) REP_ERR_RETURN(1);
1680 for (INT i = 0; i < theRule->nsons; i++)
1681 {
1682 INT found = 1;
1683 for (INT j = 0; j < CORNERS_OF_TAG(theRule->sons[i].tag); j++)
1684 if (NodeContext[theRule->sons[i].corners[j]] == NULL)
1685 {
1686 found=0;
1687 break;
1688 }
1689 if (!found)
1690 {
1691 SonList[i] = NULL;
1692 continue;
1693 }
1694
1695 /* identify (hopefully) an element of SonList */
1696 for (INT j = 0; NonorderedSonList[j] != NULL; j++)
1697 {
1698 found=0;
1699 for (INT l = 0; l < CORNERS_OF_TAG(theRule->sons[i].tag); l++)
1700 {
1701 const NODE *theNode = NodeContext[theRule->sons[i].corners[l]];
1702 for (INT k = 0; k < CORNERS_OF_ELEM(NonorderedSonList[j]); k++)
1703 if (theNode==CORNER(NonorderedSonList[j],k))
1704 {
1705 found++;
1706 break;
1707 }
1708 }
1709 if (found==CORNERS_OF_TAG(theRule->sons[i].tag))
1710 {
1711 SonList[i] = NonorderedSonList[j];
1712 *nmax = i+1;
1713 break;
1714 }
1715 else
1716 SonList[i] = NULL;
1717 }
1718 }
1719
1720 return (0);
1721 }
1722
1723 static int CheckNBrelations (MGIO_RR_RULE *mr, int rule, int tag)
1724 {
1725 int n = mr->nsons;
1726 int err=0;
1727
1728 for (int s = 0; s < n; s++)
1729 {
1730 struct mgio_sondata *son = &(mr->sons[s]);
1731 int ns = SIDES_OF_TAG(son->tag);
1732
1733 for (int i = 0; i < ns; i++)
1734 {
1735 int nb = son->nb[i];
1736 if (nb<FATHER_SIDE_OFFSET)
1737 {
1738 const struct mgio_sondata *nbson = &(mr->sons[nb]);
1739 int nnbs = SIDES_OF_TAG(nbson->tag);
1740 int j;
1741
1742 for (j=0; j<nnbs; j++)
1743 if (nbson->nb[j]==s)
1744 break;
1745 if (j>=nnbs)
1746 {
1747 PrintDebug("ERROR: rule %d of %d, asym in son %d, nb %d\n",rule,tag,s,i);
1748 err++;
1749 }
1750 }
1751 }
1752 }
1753 return (err);
1754 }
1755
1756 static void CheckMRules (MULTIGRID *mg, INT RefRuleOffset[], MGIO_RR_RULE *mrules)
1757 {
1758 int max_path_depth = 0;
1759 int use_bug_in_rule = true;
1760 short *bug_in_rule[TAGS];
1761 INT MarkKey;
1762
1763 if (MarkTmpMem(global.heap,&MarkKey))
1764 use_bug_in_rule = false;
1765 else
1766 {
1767 bug_in_rule[0] = (short*) GetTmpMem(global.heap,global.maxrules*sizeof(short),MarkKey);
1768 if (bug_in_rule[0]==NULL)
1769 use_bug_in_rule = false;
1770 else
1771 {
1772 for (int t = 0; t < TAGS; t++)
1773 {
1774 bug_in_rule[t] = bug_in_rule[0] + RefRuleOffset[t];
1775 for (int i = 0; i < global.maxrule[t]; i++)
1776 bug_in_rule[t][i] = false;
1777 }
1778 }
1779 }
1780
1781 /* check symmetry of nb relations */
1782 for (int tg = 0; tg < TAGS; tg++)
1783 {
1784 for (int i = 0; i < global.maxrule[tg]; i++)
1785 if (CheckNBrelations(mrules+RefRuleOffset[tg]+i,i,tg))
1786 if (use_bug_in_rule)
1787 bug_in_rule[tg][i] = true;
1788 }
1789
1790 for (int l = 0; l < TOPLEVEL(mg); l++)
1791 for (ELEMENT *elem = PFIRSTELEMENT(GRID_ON_LEVEL(mg,l )); elem != NULL; elem = SUCCE(elem))
1792 if (NSONS(elem)>0)
1793 {
1794 int refi = REFINE(elem);
1795 int tag = TAG(elem);
1796 MGIO_RR_RULE *mr = mrules + RefRuleOffset[tag] + refi;
1797 long id = ID(elem);
1798 int nsons = mr->nsons;
1799 int coe = CORNERS_OF_TAG(tag);
1800 int soe = SIDES_OF_TAG(tag);
1801 NODE *nodes[MAX_REFINED_CORNERS_DIM];
1802 NODE **newnodes = nodes+coe;
1803 INT maxsonex = 0;
1804 ELEMENT *sons[MAX_SONS];
1805 int error = 0;
1806
1807 /* check nsons */
1808 if (NSONS(elem)!=nsons)
1809 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: NSONS(elem)!=mr->nsons\n",id),error);
1810
1811 if (GetNodeContext(elem,nodes))
1812 ASSERT(false);
1813
1814 /* check pattern */
1815 for (int i = 0; i < MAX_NEW_CORNERS_DIM; i++)
1816 if (mr->pattern[i])
1817 {
1818 #ifndef ModelP
1819 if (newnodes[i]==NULL)
1820 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: pattern %d inconsistent (says ex but doesn't)\n",id,i),error);
1821 #endif
1822 }
1823 else
1824 {
1825 if (newnodes[i]!=NULL)
1826 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: pattern %d inconsistent (says nonex but does)\n",id,i),error);
1827 }
1828
1829 /* check sons */
1830 if (GetOrderedSons(elem,mr,nodes,sons,&maxsonex))
1831 ASSERT(false);
1832 #ifndef ModelP
1833 if (maxsonex!=nsons)
1834 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: wrong number of sons (%d vs %d)\n",id,maxsonex,nsons),error);
1835 #endif
1836 for (int s = 0; s < maxsonex; s++)
1837 {
1838 ELEMENT *son = sons[s];
1839 if (son!=NULL)
1840 {
1841 struct mgio_sondata *rson = &(mr->sons[s]);
1842 int nco = CORNERS_OF_ELEM(son);
1843 int nsi = SIDES_OF_ELEM(son);
1844
1845 if (rson->tag!=TAG(son))
1846 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: wrong tag of son %d (%d vs %d)\n",id,s,rson->tag,TAG(son)),error);
1847
1848 /* check corners */
1849 for (int co = 0; co < nco; co++)
1850 if (CORNER(son,co)!=nodes[rson->corners[co]])
1851 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: corner %d of son %d inconsistent\n",id,co,s),error);
1852
1853 /* check neighbours */
1854 for (int si = 0; si < nsi; si++)
1855 {
1856 const ELEMENT *nb = NBELEM(son,si);
1857 if (nb!=NULL)
1858 {
1859 const ELEMENT *nbf = EFATHER(nb);
1860
1861 if (nbf==elem)
1862 {
1863 /* check inner side */
1864 #ifdef ModelP
1865 if (sons[rson->nb[si]]!=NULL)
1866 #endif
1867 if (nb!=sons[rson->nb[si]])
1868 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: inner nb %d of son %d inconsistent\n",id,si,s),error);
1869 }
1870 else if (nbf!=NULL)
1871 {
1872 int j;
1873
1874 /* check father side */
1875 for (j=0; j<soe; j++)
1876 if (NBELEM(elem,j)==nbf)
1877 break;
1878 if (j!=(rson->nb[si]-FATHER_SIDE_OFFSET))
1879 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: outer nb %d of son %d inconsistent\n",id,si,s),error);
1880 }
1881 }
1882 else
1883 {
1884 #ifndef ModelP
1885 if (rson->nb[si]<FATHER_SIDE_OFFSET)
1886 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: son %d has no nb but %d no fatherside\n",id,s,si),error);
1887 #endif
1888 }
1889 }
1890 #ifndef ModelP
1891 #ifdef UG_DIM_3
1892 /* check path
1893 NOT CONSISTENT in rm since not used (says Stefan, 971219)
1894 if (s>0)
1895 {
1896 ELEMENT *nson = sons[0];
1897 int path = rson->path;
1898 int pd = PATHDEPTH(path);
1899 int son_path_ok = false;
1900 int j;
1901
1902 max_path_depth = MAX(max_path_depth,pd);
1903
1904 for (j=0; j<pd; j++)
1905 {
1906 int ns = NEXTSIDE(path,j);
1907
1908 if (nson==NULL)
1909 {
1910 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: nson==NULL for son %d at %d\n",id,s,j),error);
1911 break;
1912 }
1913 if (ns>=SIDES_OF_ELEM(nson))
1914 {
1915 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: path of son %d at %d has invalid side %s\n",id,s,j,ns),error);
1916 break;
1917 }
1918 nson = NBELEM(nson,ns);
1919 }
1920 if (nson!=son)
1921 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: wrong path of son %d\n",id,s),error)
1922 else
1923 son_path_ok = true;
1924 if (!son_path_ok)
1925 some_path_wrong = true;
1926 }*/
1927 #endif
1928 #endif
1929 }
1930 }
1931 /*if (!some_path_wrong)
1932 PD_ERR(ER_DBG_RULE_VERBOSE,("FINE in CheckMRules (%c-rule), elem %ld: all paths ok\n",(refi<UGMAXRULE(tag))?'r':'e',id),error);*/
1933
1934 /* check sonandnode
1935 NOT CONSISTENT in rm since not used (says Stefan, 971219)
1936 for (i=0; i<MAX_NEW_CORNERS_DIM; i++)
1937 if (newnodes[i]!=NULL)
1938 if (sons[mr->sonandnode[i][0]]!=NULL)
1939 if (CORNER(sons[mr->sonandnode[i][0]],mr->sonandnode[i][1]) != newnodes[i])
1940 PD_ERR(ER_DBG_RULE_VERBOSE,("ERROR in CheckMRules, elem %ld: sonandnode %d inconsistent\n",id,i),error);*/
1941
1942 /* summary */
1943 if (error)
1944 {
1945 PD(("in total %3d ERRORS in CheckMRules (%c-rule %3d of %d), elem %ld\n",error,(refi<UGMAXRULE(tag)) ? 'r' : 'e',refi,tag,id));
1946 if (use_bug_in_rule)
1947 bug_in_rule[tag][refi] = true;
1948 }
1949 else
1950 PrintDebug("FINE in CheckMRules (%c-rule %4d of %d), elem %ld: everything ok\n",(refi<UGMAXRULE(tag)) ? 'r' : 'e',refi,tag,id);
1951 }
1952 PrintDebug("CheckMRules: max_path_depth %d\n",max_path_depth);
1953
1954 if (use_bug_in_rule)
1955 {
1956 PrintDebug("--------------- CheckMRules: rules with bugs ---------------\n");
1957
1958 for (int t = 0; t < TAGS; t++)
1959 for (int i = 0; i < global.maxrule[t]; i++)
1960 if (bug_in_rule[t][i])
1961 {
1962 PrintDebug("-- rule %4d of %d\n",i,t);
1963 if (i<UGMAXRULE(t))
1964 ShowRefRuleX(t,i,PrintDebug);
1965 else
1966 PrintDebug("sorry, no ShowRefRule for mgio-rules\n");
1967 }
1968
1969 PrintDebug("------------------------------------------------------------\n");
1970
1971 if (ReleaseTmpMem(global.heap,MarkKey))
1972 ASSERT(false);
1973 }
1974 else
1975 PrintDebug("sorry, no storage available for use_bug_in_rule\n");
1976 }
1977
1978 /****************************************************************************/
1979 /*D
1980 NEW_Write_RefRules - write refinement rules of multigrid to file
1981
1982 SYNOPSIS:
1983 INT NEW_Write_RefRules (MULTIGRID *mg, INT RefRuleOffset[], INT MarkKey, MGIO_RR_RULE **mrule_handle)
1984
1985 PAAMETERS:
1986 . mg - multigrid
1987 . RefRuleOffset - tag-wise offsets for refrules
1988 . MarkKey - mark key for temporary storage of ugio
1989 . mrule_handle - pointer to mgio rules allocated on temporary storage of ugio
1990
1991 DESCRIPTION:
1992 Write refinement rules of multigrid to file (rm rules as far as available, the remainder
1993 is covered by rules extracted by the er module).
1994
1995 RETURN VALUE:
1996 INT
1997 .n 0: ok
1998 .n >0: error
1999 D*/
2000 /****************************************************************************/
2001
2002 INT NS_DIM_PREFIX NEW_Write_RefRules (MULTIGRID *mg, INT RefRuleOffset[], INT MarkKey, MGIO_RR_RULE **mrule_handle)
2003 {
2004 MGIO_RR_GENERAL rr_general;
2005 MGIO_RR_RULE *mrule;
2006 INT BotMarkKey;
2007
2008 if (mg==NULL)
2009 REP_ERR_RETURN(1);
2010
2011 global.heap = MGHEAP(mg);
2012 if (MarkTmpMem(global.heap,&BotMarkKey))
2013 REP_ERR_RETURN(1);
2014
2015 /* init rule counters (continue with last rule IDs of rm) */
2016 /* TODO (HRR 971207): this is important for matching existing rules after loading a grid (coarsening)
2017 but CAUTION: refine should never address a rule beyond rm rules! */
2018 for (int tag = 0; tag < TAGS; tag++)
2019 global.maxrule[tag] = UGMAXRULE(tag);
2020
2021 #if (defined UG_DIM_3) || (defined __DEBUG_ER__)
2022 /* incomplete refrule set: extract non-existing rules that are realized in mg */
2023 if (ExtractRules(mg))
2024 REP_ERR_RETURN(1);
2025 #endif
2026
2027 global.maxrules = 0;
2028 for (int tag = 0; tag < TAGS; tag++)
2029 global.maxrules += global.maxrule[tag];
2030
2031 /* write refrules general */
2032 RefRuleOffset[0] = 0;
2033 for (int tag = 0; tag < TAGS; tag++)
2034 {
2035 if (tag>0) RefRuleOffset[tag] = RefRuleOffset[tag-1] + global.maxrule[tag-1];
2036 rr_general.RefRuleOffset[tag] = RefRuleOffset[tag];
2037 }
2038 rr_general.nRules = global.maxrules;
2039 if (Write_RR_General(&rr_general))
2040 REP_ERR_RETURN(1);
2041
2042 /* allocate MGIO_RR_RULE table (will stay in scope beyond this module) */
2043 *mrule_handle = (MGIO_RR_RULE*) GetTmpMem(global.heap,global.maxrules*sizeof(MGIO_RR_RULE),MarkKey);
2044 if (*mrule_handle==NULL)
2045 REP_ERR_RETURN(1);
2046
2047 /* write refrules */
2048 mrule = *mrule_handle;
2049 for (int tag = 0; tag < TAGS; tag++)
2050 {
2051 int i;
2052
2053 /* rm rules */
2054 for (i=0; i<UGMAXRULE(tag); i++)
2055 {
2056 ASSERT(RefRules[tag]+i!=NULL);
2057 URule2Mrule(RefRules[tag]+i,mrule);
2058 mrule++;
2059 }
2060
2061 /* er rules */
2062 for (; i<global.maxrule[tag]; i++)
2063 {
2064 ASSERT(global.hrule[tag][i]!=NULL);
2065 HRule2Mrule(global.hrule[tag][i],mrule);
2066 mrule++;
2067 }
2068
2069 }
2070 Write_RR_Rules(global.maxrules,*mrule_handle);
2071
2072 /* free hrules and hrule table */
2073 if (ReleaseTmpMem(global.heap,BotMarkKey))
2074 REP_ERR_RETURN(1);
2075
2076 IFDEBUG(gm,ER_DBG_GENERAL)
2077 WriteDebugInfo();
2078 ENDDEBUG
2079
2080 IFDEBUG(gm,ER_DBG_RULES)
2081 CheckMRules(mg,RefRuleOffset,*mrule_handle);
2082 ENDDEBUG
2083
2084 return (0);
2085 }
2086
2087 /****************************************************************************/
2088 /*D
2089 ResetRefineTagsBeyondRuleManager - reset refine tags to what refine expects there
2090
2091 SYNOPSIS:
2092 INT ResetRefineTagsBeyondRuleManager (MULTIGRID *mg)
2093
2094 PARAMETERS:
2095 . mg - multigrid
2096
2097 DESCRIPTION:
2098 Reset refine tags to what refine expects there.
2099
2100 RETURN VALUE:
2101 INT
2102 .n 0: ok
2103 D*/
2104 /****************************************************************************/
2105
2106 INT NS_DIM_PREFIX ResetRefineTagsBeyondRuleManager (MULTIGRID *mg)
2107 {
2108 #ifdef Debug
2109 int n = 0;
2110 #endif
2111
2112 /** \todo (HRR 971211): don't include TOPLEVEL (no elem refined there) */
2113 for (int l=0; l<=TOPLEVEL(mg); l++)
2114 for (ELEMENT *elem = PFIRSTELEMENT(GRID_ON_LEVEL(mg, l)); elem != NULL; elem = SUCCE(elem))
2115 if (BEYOND_UG_RULES(elem))
2116 {
2117 SETREFINE(elem,COPY);
2118 #ifdef Debug
2119 n++;
2120 #endif
2121 }
2122 PRINTDEBUG(gm,ER_DBG_GENERAL,("ResetRefineTags: done (for %d elements)\n",n));
2123
2124 return (0);
2125 }