Debian Codegraph @

dune/uggrid/parallel/dddif/handler.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: handler.c */
8 /* */
9 /* Purpose: defines the handlers used by ddd during data management. */
10 /* */
11 /* */
12 /* Author: Stefan Lang */
13 /* Institut fuer Computeranwendungen III */
14 /* Universitaet Stuttgart */
15 /* Pfaffenwaldring 27 */
16 /* 70550 Stuttgart */
17 /* email: [email protected] */
18 /* phone: 0049-(0)711-685-7003 */
19 /* fax : 0049-(0)711-685-7000 */
20 /* */
21 /* History: 10.05.95 begin, ugp version 3.0 */
22 /* */
23 /* Remarks: */
24 /* */
25 /****************************************************************************/
26
27 #ifdef ModelP
28
29 /****************************************************************************/
30 /* */
31 /* include files */
32 /* system include files */
33 /* application include files */
34 /* */
35 /****************************************************************************/
36
37 #include <config.h>
38 #include <cstdio>
39 #include <cstdlib>
40 #include <cstring>
41 #include <cassert>
42
43 #include <dune/uggrid/ugdevices.h>
44 #include <dune/uggrid/domain/std_domain.h>
45 #include "parallel.h"
46 #include <dune/uggrid/gm/algebra.h>
47 #include <dune/uggrid/gm/evm.h>
48 #include <dune/uggrid/gm/pargm.h>
49 #include <dune/uggrid/gm/rm.h>
50 #include <dune/uggrid/gm/refine.h>
51 #include <dune/uggrid/gm/shapes.h>
52 #include <dune/uggrid/gm/ugm.h>
53 #include <dune/uggrid/low/architecture.h>
54 #include <dune/uggrid/low/debug.h>
55 #include <dune/uggrid/low/heaps.h>
56 #include <dune/uggrid/low/namespace.h>
57 #include <dune/uggrid/low/ugtypes.h>
58
59 /* UG namespaces: */
60 USING_UG_NAMESPACES
61
62 /* PPIF namespace */
63 using namespace PPIF;
64
65 /****************************************************************************/
66 /* */
67 /* defines in the following order */
68 /* */
69 /* compile time constants defining static data size (i.e. arrays) */
70 /* other constants */
71 /* macros */
72 /* */
73 /****************************************************************************/
74
75 #ifdef Debug
76 #define DEBUGNSONS(e,f,m) { \
77 if (f!=NULL) \
78 { \
79 if (CheckNSons(f,m)) \
80 UserWriteF(PFMT "inserted elem=" EID_FMTX\
81 "\n",me,EID_PRTX(e)); \
82 } \
83 }
84 #else
85 #define DEBUGNSONS(pe,f,m)
86 #endif
87
88 #define CEIL(n) ((n)+((ALIGNMENT-((n)&(ALIGNMENT-1)))&(ALIGNMENT-1)))
89
90
91 /****************************************************************************/
92 /* */
93 /* data structures used in this source file (exported data structures are */
94 /* in the corresponding include file!) */
95 /* */
96 /****************************************************************************/
97
98
99
100 /****************************************************************************/
101 /* */
102 /* definition of exported global variables */
103 /* */
104 /****************************************************************************/
105
106
107 /****************************************************************************/
108 /* */
109 /* definition of variables global to this source file only (static!) */
110 /* */
111 /****************************************************************************/
112
113
114
115
116 /****************************************************************************/
117 /* */
118 /* forward declarations of functions used before they are defined */
119 /* */
120 /****************************************************************************/
121
122 static void PrintSons (ELEMENT *theElement)
123 {
124 ELEMENT *SonList[MAX_SONS];
125 int i;
126
127 if (GetAllSons(theElement,SonList)) ASSERT(0);
128 for (i=0; i<MAX_SONS && SonList[i] != NULL; )
129 {
130 UserWriteF("elem=" EID_FMTX " son[%d]=" EID_FMTX "\n",
131 EID_PRTX(theElement),i,EID_PRTX(SonList[i]));
132 i++;
133 }
134 }
135
136 static int CheckNSons (ELEMENT *theElement, char *buffer)
137 {
138 ELEMENT *SonList[MAX_SONS];
139 int i,nsons;
140
141 if (GetAllSons(theElement,SonList)) ASSERT(0);
142 for (i=0; i<MAX_SONS && SonList[i] != NULL; ) i++;
143
144 nsons = NSONS(theElement);
145 if(i != nsons)
146 {
147 UserWriteF("%s: elem=" EID_FMTX " ERROR nsons=%d NSONS=%d\n\n",
148 buffer,EID_PRTX(theElement),i,nsons);
149 if (1) PrintSons(theElement);
150 fflush(stdout);
151 return(1);
152 }
153 return (0);
154 }
155
156 static GRID *GetGridOnDemand (MULTIGRID *mg, int level)
157 {
158 while (level > TOPLEVEL(mg))
159 {
160 PRINTDEBUG(dddif,1,(PFMT " CreateNewLevel toplevel=%d level=%d",me,TOPLEVEL(mg),level));
161 if (CreateNewLevel(mg)==NULL) assert(0);
162 }
163
164 return GRID_ON_LEVEL(mg,level);
165 }
166
167
168
169
170 /****************************************************************************/
171 /* */
172 /* For data management during redistribution and communication */
173 /* DDD needs for each DDD (data) object several handlers. */
174 /* These are: */
175 /* HANDLER_LDATACONSTRUCTOR, handler: init object's LDATA parts */
176 /* HANDLER_UPDATE, handler: update objects internals */
177 /* HANDLER_OBJMKCONS, handler: make obj consistent */
178 /* HANDLER_DESTRUCTOR, handler: destruct object */
179 /* HANDLER_XFERCOPY, handler: copy cmd during xfer */
180 /* HANDLER_XFERDELETE, handler: delete cmd during xfer */
181 /* HANDLER_XFERGATHER, handler: send additional data */
182 /* HANDLER_XFERSCATTER, handler: recv additional data */
183 /* */
184 /* */
185 /* For each of the ddd (data) objects the handlers needed for the */
186 /* specific object are defined below in the order handlers for */
187 /* */
188 /* DDD objects: */
189 /* *dimension independent */
190 /* TypeVector, TypeIVertex, TypeBVertex, TypeNode */
191 /* *dimension dependent */
192 /* 2-Dim: */
193 /* TypeTrElem, TypeTrBElem, */
194 /* TypeQuElem, TypeQuBElem */
195 /* 3-Dim: */
196 /* TypeTeElem, TypeTeBElem */
197 /* TypePyElem, TypePyBElem */
198 /* TypePrElem, TypePrBElem */
199 /* TypeHeElem, TypeHeBElem */
200 /* TypeEdge */
201 /* */
202 /* DDD data objects: */
203 /* 2-Dim: */
204 /* TypeEdge */
205 /* */
206 /* NOT all handlers are to be specified for each object! */
207 /* */
208 /****************************************************************************/
209
210 /****************************************************************************/
211 /****************************************************************************/
212 /* */
213 /* handlers for typevector */
214 /* */
215 /****************************************************************************/
216 /****************************************************************************/
217
218 static void VectorUpdate (DDD::DDDContext& context, DDD_OBJ obj)
219 {
220 VECTOR *pv = (VECTOR *)obj;
221 INT level = ATTR_TO_GLEVEL(DDD_InfoAttr(PARHDR(pv)));
222 GRID *theGrid = GRID_ON_LEVEL(ddd_ctrl(context).currMG,level);
223 const DDD_PRIO prio = PRIO(pv);
224
225 PRINTDEBUG(dddif,1,(PFMT " VectorUpdate(): v=" VINDEX_FMTX
226 " VEOBJ=%d\n",me,VINDEX_PRTX(pv),OBJT(pv)))
227
228 /* insert in vector list */
229 GRID_LINK_VECTOR(theGrid,pv,prio);
230 }
231
232
233
234 static void VectorXferCopy(DDD::DDDContext& context, DDD_OBJ obj, DDD_PROC proc, DDD_PRIO prio)
235 {
236 VECTOR *pv = (VECTOR *)obj;
237 INT level = ATTR_TO_GLEVEL(DDD_InfoAttr(PARHDR(pv)));
238 INT flag;
239
240 PRINTDEBUG(dddif,1,(PFMT " VectorXferCopy(): v=" VINDEX_FMTX " proc=%d "
241 "prio=%d\n",me,VINDEX_PRTX(pv),proc,prio))
242
243 flag = (!GHOSTPRIO(prio));
244 #ifndef __EXCHANGE_CONNECTIONS__
245 flag = (flag && (level < 0));
246 #endif
247
248 /*
249 else
250 {
251 GRID *theGrid = GRID_ON_LEVEL(ddd_ctrl(context).currMG,level);
252 MATRIX *theMatrix,*next;
253
254 for (theMatrix=VSTART(pv); theMatrix!=NULL; theMatrix = next) {
255 next = MNEXT(theMatrix);
256 if (DisposeConnection(theGrid,MMYCON(theMatrix)))
257 ASSERT(0);
258 }
259 }
260 */
261 }
262
263
264 static void VectorPriorityUpdate (DDD::DDDContext& context, DDD_OBJ obj, DDD_PRIO isnew)
265 {
266 VECTOR *pv = (VECTOR *)obj;
267 INT level = ATTR_TO_GLEVEL(DDD_InfoAttr(PARHDR(pv)));
268 GRID *theGrid = GRID_ON_LEVEL(ddd_ctrl(context).currMG,level);
269 DDD_PRIO old = PRIO(pv);
270
271 PRINTDEBUG(dddif,2,(PFMT " VectorPriorityUpdate(): v=" VINDEX_FMTX
272 " old=%d new=%d level=%d attr=%d\n",
273 me,VINDEX_PRTX(pv),old,isnew,level,
274 (int)DDD_InfoAttr(PARHDR(pv))));
275
276 if (pv == NULL) return;
277 if (old == isnew) return;
278
279 if (old == PrioNone) {
280 /* only valid for masters */
281 ASSERT(isnew == PrioMaster);
282 return;
283 }
284
285 if (isnew == PrioNone) {
286 /* only valid when prio undefined */
287 printf("prio=%d\n",old);
288 fflush(stdout);
289 ASSERT(old <= 0);
290 return;
291 }
292
293 #ifdef __EXCHANGE_CONNECTIONS__
294 IFDEBUG(dddif,1)
295 if (isnew == PrioMaster)
296 {
297 if (VSTART(pv) == NULL)
298 {
299 PRINTDEBUG(dddif,0,(PFMT " VectorPriorityUpdate(): ERROR v="
300 VINDEX_FMTX " old=%d new=%d matrix list empty\n",
301 me,VINDEX_PRTX(pv),old,isnew))
302 }
303 }
304 ENDDEBUG
305 #endif
306
307 GRID_UNLINK_VECTOR(theGrid,pv);
308
309 GRID_LINK_VECTOR(theGrid,pv,isnew);
310 }
311
312 /****************************************************************************/
313 /****************************************************************************/
314 /* */
315 /* handlers for typeivertex */
316 /* */
317 /****************************************************************************/
318 /****************************************************************************/
319
320 /****************************************************************************/
321 /****************************************************************************/
322 /* */
323 /* handlers for typebvertex */
324 /* */
325 /****************************************************************************/
326 /****************************************************************************/
327
328
329 static void BVertexLDataConstructor (DDD::DDDContext&, DDD_OBJ obj)
330 {
331 VERTEX *theVertex = (VERTEX *) obj;
332
333 PRINTDEBUG(dddif,1,(PFMT " BVertexLDataConstructor(): v=" VID_FMTX
334 " I/BVOBJ=%d\n",me,VID_PRTX(theVertex),OBJT(theVertex)))
335
336 V_BNDP(theVertex) = NULL;
337 }
338
339
340 static void VertexUpdate (DDD::DDDContext& context, DDD_OBJ obj)
341 {
342 VERTEX *theVertex = (VERTEX *) obj;
343 INT level = LEVEL(theVertex);
344 GRID *theGrid = GRID_ON_LEVEL(ddd_ctrl(context).currMG,level);
345 INT prio = VXPRIO(theVertex);
346
347 PRINTDEBUG(dddif,1,(PFMT " VertexUpdate(): v=" VID_FMTX " I/BVOBJ=%d\n",
348 me,VID_PRTX(theVertex),OBJT(theVertex)))
349
350 GRID_LINK_VERTEX(theGrid,theVertex,prio);
351
352
353 /* this assertion is not correct, since there may be an arbitrary number of */
354 /* calls to NodeUpdate(), which increments NOOFNODE */
355 /* ASSERT(NOOFNODE(theVertex) == 0); */
356
357 /* update ID of vertex */
358 /* TODO: change to global id */
359 /* TODO: delete
360 ID(theVertex) = (theGrid->mg->vertIdCounter)++;
361 */
362 }
363
364 static void VertexObjMkCons (DDD::DDDContext&, DDD_OBJ obj, int newness)
365 {
366 [[maybe_unused]] VERTEX *theVertex = (VERTEX *) obj;
367
368 PRINTDEBUG(dddif,1,(PFMT " VertexObjMkCons(): v=" VID_FMTX
369 " I/BVOBJ=%d newness=%d\n",
370 me,VID_PRTX(theVertex),OBJT(theVertex),newness))
371 }
372
373
374 static void BVertexXferCopy (DDD::DDDContext& context, DDD_OBJ obj, DDD_PROC proc, DDD_PRIO prio)
375 {
376 VERTEX *theVertex = (VERTEX *) obj;
377
378 PRINTDEBUG(dddif,1,(PFMT " BVertexXferCopy(): v=" VID_FMTX
379 " I/BVOBJ=%d proc=%d prio=%d \n",
380 me,VID_PRTX(theVertex),OBJT(theVertex),proc,prio))
381
382 BVertexXferBndP(context, V_BNDP(theVertex),proc,prio);
383 }
384
385
386 static void BVertexGather (DDD::DDDContext&, DDD_OBJ obj, int cnt, DDD_TYPE type_id, void *Data)
387 {
388 BVertexGatherBndP (V_BNDP((VERTEX *)obj),cnt,(char*)Data);
389 }
390
391 /* Handlers used by Dune to implement dynamic load balancing:
392 * Dune writes the data into the objects' 'message_buffer'
393 * variable, then we take it from there.
394 * The first sizeof(int) bytes of the message_buffer is the length of
395 * the message (without the size of the int).
396 */
397 template<typename Entity>
398 static void DuneEntityGather (DDD::DDDContext&, DDD_OBJ obj, int cnt, DDD_TYPE type_id, void *Data)
399 {
400 char* data = static_cast<char*>(Data);
401 const Entity* entity = reinterpret_cast<Entity*>(obj);
402 const auto size = entity->message_buffer_size();
403
404 std::memcpy(data, &size, sizeof size);
405 data += sizeof size;
406
407 std::memcpy(data, entity->message_buffer(), size);
408 }
409
410 template<typename Entity>
411 static void DuneEntityScatter (DDD::DDDContext&, DDD_OBJ obj, int cnt, DDD_TYPE type_id, void *Data, int newness)
412 {
413 const char* data = static_cast<const char*>(Data);
414 Entity* entity = reinterpret_cast<Entity*>(obj);
415
416 std::size_t size;
417 std::memcpy(&size, data, sizeof size);
418 data += sizeof size;
419
420 char* buffer = static_cast<char*>(std::malloc(size));
421 std::memcpy(buffer, data, size);
422 entity->message_buffer(buffer, size);
423 }
424
425 static void BVertexScatter (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TYPE type_id, void *Data, int newness)
426 {
427 BVertexScatterBndP(context, &(V_BNDP((VERTEX *)obj)),cnt,(char*)Data);
428 }
429
430
431 static void VertexPriorityUpdate (DDD::DDDContext& context, DDD_OBJ obj, DDD_PRIO new_)
432 {
433 VERTEX *theVertex = (VERTEX *)obj;
434 INT level = LEVEL(theVertex);
435 GRID *theGrid = GetGridOnDemand(ddd_ctrl(context).currMG,level);
436 DDD_PRIO old = VXPRIO(theVertex);
437
438 PRINTDEBUG(dddif,2,(PFMT " VertexPriorityUpdate(): v=" VID_FMTX
439 " old=%d new=%d level=%d\n",me,VID_PRTX(theVertex),old,new_,level))
440
441 if (theVertex == NULL) return;
442 if (old == new_) return;
443
444 if (old == PrioNone) {
445 /* only valid for masters */
446 ASSERT(new_ == PrioMaster);
447 return;
448 }
449
450 if (new_ == PrioNone) {
451 /* only valid when prio undefined */
452 printf("prio=%d\n",old);
453 fflush(stdout);
454 ASSERT(old <= 0);
455 return;
456 }
457
458 GRID_UNLINK_VERTEX(theGrid,theVertex);
459
460 GRID_LINK_VERTEX(theGrid,theVertex,new_);
461 }
462
463 /****************************************************************************/
464 /****************************************************************************/
465 /* */
466 /* handlers for typenode */
467 /* */
468 /****************************************************************************/
469 /****************************************************************************/
470
471
472 static void NodeDestructor(DDD::DDDContext&, DDD_OBJ obj)
473 {
474 NODE *node = (NODE *) obj;
475
476 node->message_buffer_free();
477
478 PRINTDEBUG(dddif,2,(PFMT " NodeDestructor(): n=" ID_FMTX " NDOBJ=%d\n",
479 me,ID_PRTX(node),OBJT(node)))
480 }
481
482 static void NodeObjInit(DDD::DDDContext&, DDD_OBJ obj)
483 {
484 NODE *node = (NODE *) obj;
485
486 node->message_buffer(nullptr, 0);
487
488 PRINTDEBUG(dddif,2,(PFMT " NodeObjInit(): n=" ID_FMTX " NDOBJ=%d\n",
489 me,ID_PRTX(node),OBJT(node)))
490 }
491
492
493 static void NodeObjMkCons (DDD::DDDContext& context, DDD_OBJ obj, int newness)
494 {
495 #if defined(Debug) || defined(TOPNODE) || defined(UG_DIM_2)
496 NODE *theNode = (NODE *) obj;
497 #endif
498
499 PRINTDEBUG(dddif,2,(PFMT " NodeObjMkCons(): n=" ID_FMTX " NDOBJ=%d\n",
500 me,ID_PRTX(theNode),OBJT(theNode)))
501
502 #ifdef TOPNODE
503 /* set topnode pointer of vertex */
504 if (TOPNODE(MYVERTEX(theNode)) == NULL)
505 TOPNODE(MYVERTEX(theNode)) = theNode;
506 else
507 {
508 NODE *TopNode = TOPNODE(MYVERTEX(theNode));
509 INT level = LEVEL(TopNode);
510
511 if (level < LEVEL(theNode))
512 TOPNODE(MYVERTEX(theNode)) = theNode;
513 }
514 #endif
515
516 /* TODO: this needs to be done here not in NodeUpdate() for 2D, */
517 /* since father would be overwritten by ElemScatterEdge() */
518 #ifdef UG_DIM_2
519 if (NFATHER(theNode) != NULL)
520 {
521 switch (NTYPE(theNode))
522 {
523 case (CORNER_NODE) :
524 ASSERT(OBJT(NFATHER(theNode)) == NDOBJ);
525 SONNODE((NODE *)NFATHER(theNode)) = theNode;
526 break;
527
528 case (MID_NODE) :
529 ASSERT(OBJT(NFATHER(theNode)) == EDOBJ);
530 MIDNODE((EDGE *)NFATHER(theNode)) = theNode;
531 break;
532
533 default :
534 ASSERT(0);
535 break;
536 }
537 }
538 #endif
539 }
540
541
542 /****************************************************************************/
543 /* */
544 /* Function: NodeUpdate */
545 /* */
546 /* Purpose: update information related to a node. */
547 /* current implementation only for level 0 grids */
548 /* */
549 /* Input: DDD_OBJ obj: the node to handle */
550 /* */
551 /* Output: void */
552 /* */
553 /****************************************************************************/
554
555 static void NodeUpdate (DDD::DDDContext& context, DDD_OBJ obj)
556 {
557 NODE *theNode = (NODE *)obj;
558 VERTEX *theVertex = MYVERTEX(theNode);
559 INT level = LEVEL(theNode);
560 GRID *theGrid = GRID_ON_LEVEL(ddd_ctrl(context).currMG,level);
561 INT prio = PRIO(theNode);
562
563 PRINTDEBUG(dddif,1,(PFMT " NodeUpdate(): n=" ID_FMTX " NDOBJ=%d\n",
564 me,ID_PRTX(theNode),OBJT(theNode)))
565
566 /* insert in listpart */
567 GRID_LINK_NODE(theGrid,theNode,prio);
568
569 /* TODO: can this be done in NodeObjMkCons() also */
570 /* to unify 2 and 3D case */
571 #ifdef UG_DIM_3
572 if (NFATHER(theNode) != NULL)
573 {
574 switch (NTYPE(theNode))
575 {
576 case (CORNER_NODE) :
577 ASSERT(OBJT(NFATHER(theNode)) == NDOBJ);
578 SONNODE((NODE *)NFATHER(theNode)) = theNode;
579 break;
580
581 case (MID_NODE) :
582 ASSERT(OBJT((EDGE *)NFATHER(theNode)) == EDOBJ);
583 MIDNODE((EDGE *)NFATHER(theNode)) = theNode;
584 break;
585
586 default :
587 ASSERT(0);
588 break;
589 }
590 }
591 #endif
592
593 if (NOOFNODE(theVertex)<NOOFNODEMAX-1)
594 INCNOOFNODE(theVertex);
595 else
596 ASSERT(0);
597
598 /* TODO: change to global id */
599 /* TODO: delete
600 ID(node) = (theGrid->mg->nodeIdCounter)++;
601 */
602 }
603
604 /****************************************************************************/
605 /* */
606 /* Function: NodeXferCopy */
607 /* */
608 /* Purpose: initiate dependent copy of data related to a node. */
609 /* */
610 /* Input: DDD_OBJ obj: the object which is transferred to proc */
611 /* int proc: destination processor for that object */
612 /* int prio: priority of object new local object */
613 /* */
614 /* Output: void */
615 /* */
616 /****************************************************************************/
617
618 static void NodeXferCopy (DDD::DDDContext& context, DDD_OBJ obj, DDD_PROC proc, DDD_PRIO prio)
619 {
620 NODE *theNode = (NODE *)obj;
621
622 PRINTDEBUG(dddif,1,(PFMT " NodeXferCopy(): n=" ID_FMTX
623 " proc=%d prio=%d\n",
624 me,ID_PRTX(theNode),proc,prio));
625
626 /* copy vertex */
627 PRINTDEBUG(dddif,2,(PFMT " NodeXferCopy(): n=" ID_FMTX " Xfer v="
628 VID_FMTX "\n",me,ID_PRTX(theNode),VID_PRTX(MYVERTEX(theNode))))
629
630 #ifdef Debug
631 if (NFATHER(theNode) != NULL)
632 {
633 PRINTDEBUG(dddif,1,(PFMT " NodeXferCopy(): n=" ID_FMTX
634 " NTYPE=%d OBJT=%d\n",
635 me,ID_PRTX(theNode),NTYPE(theNode),
636 OBJT(NFATHER(theNode))));
637
638 switch (NTYPE(theNode))
639 {
640 case (CORNER_NODE) :
641 ASSERT(OBJT(NFATHER(theNode)) == NDOBJ);
642 break;
643
644 case (MID_NODE) :
645 ASSERT(OBJT(NFATHER(theNode)) == EDOBJ);
646 break;
647
648 default :
649 ASSERT(0);
650 break;
651 }
652 }
653 #endif
654
655 if (DDD_XferWithAddData(context)) {
656 /* Extra data for Dune */
657 DDD_XferAddData(context, sizeof(theNode->message_buffer_size()) + theNode->message_buffer_size(), DDD_USER_DATA);
658 }
659
660 DDD_XferCopyObj(context, PARHDRV(MYVERTEX(theNode)), proc, prio);
661 }
662
663
664 static void NodePriorityUpdate (DDD::DDDContext& context, DDD_OBJ obj, DDD_PRIO new_)
665 {
666 NODE *pn = (NODE *)obj;
667 INT level = LEVEL(pn);
668 GRID *theGrid = GetGridOnDemand(ddd_ctrl(context).currMG,level);
669 const DDD_PRIO old = PRIO(pn);
670
671 PRINTDEBUG(dddif,2,(PFMT " NodePriorityUpdate(): n=" ID_FMTX " old=%d new=%d "
672 "level=%d\n",me,ID_PRTX(pn),old,new_,level))
673
674 if (pn == NULL) return;
675 if (old == new_) return;
676
677 if (old == PrioNone)
678 {
679 /* only valid for masters */
680 ASSERT(new_ == PrioMaster);
681 return;
682 }
683
684 if (new_ == PrioNone)
685 {
686 /* only valid when prio undefined */
687 printf("prio=%d\n",old);
688 fflush(stdout);
689 ASSERT(old <= 0);
690 return;
691 }
692
693 /* insert in new list part */
694 GRID_UNLINK_NODE(theGrid,pn);
695 GRID_LINK_NODE(theGrid,pn,new_);
696 }
697
698 DDD_TYPE NS_DIM_PREFIX NFatherObjType(DDD::DDDContext& context, DDD_OBJ obj, DDD_OBJ ref)
699 {
700 const auto& dddctrl = ddd_ctrl(context);
701 NODE *theNode = (NODE *)obj;
702
703 switch (NTYPE(theNode))
704 {
705 case (CORNER_NODE) :
706 #ifdef Debug
707 if (OBJT((NODE *)ref) != NDOBJ)
708 UserWriteF("NFatherObjType(): wrong OBJT=%d\n",OBJT((NODE *)ref));
709 #endif
710
711 ASSERT(OBJT((NODE *)ref) == NDOBJ);
712 return(dddctrl.TypeNode);
713
714 case (MID_NODE) :
715 #ifdef Debug
716 if (OBJT((EDGE *)ref) != EDOBJ)
717 UserWriteF("NFatherObjType(): wrong OBJT=%d\n",OBJT((EDGE *)ref));
718 #endif
719
720 ASSERT(OBJT((EDGE *)ref) == EDOBJ);
721 return(dddctrl.TypeEdge);
722
723 default :
724 abort();
725 }
726 }
727
728 /****************************************************************************/
729 /****************************************************************************/
730 /* */
731 /* handlers for typeelement */
732 /* */
733 /****************************************************************************/
734 /****************************************************************************/
735
736 /****************************************************************************/
737 /* */
738 /* Function: ElementLDataConstructor */
739 /* */
740 /* Purpose: update information related to an element. */
741 /* current implementation only for level 0 grids */
742 /* */
743 /* Input: DDD_OBJ obj: the element to handle */
744 /* */
745 /* Output: void */
746 /* */
747 /****************************************************************************/
748
749 static void ElementLDataConstructor (DDD::DDDContext& context, DDD_OBJ obj)
750 {
751 INT i;
752 ELEMENT *pe = (ELEMENT *)obj;
753 [[maybe_unused]] INT level = LEVEL(pe);
754 /* TODO: delete
755 GRID *theGrid = GetGridOnDemand(ddd_ctrl(context).currMG,level);
756 INT prio = EPRIO(pe); */
757
758 pe->message_buffer(nullptr, 0);
759
760 PRINTDEBUG(dddif,2,(PFMT " ElementLDataConsX(): pe=" EID_FMTX
761 " EOBJ=%d l=%d\n",me,EID_PRTX(pe),OBJT(pe),level))
762
763 /* TODO: delete
764 GRID_LINK_ELEMENT(theGrid,pe,prio); */
765
766 if (OBJT(pe)==BEOBJ)
767 {
768 for (i=0; i<SIDES_OF_ELEM(pe); i++)
769 SET_BNDS(pe,i,NULL);
770 }
771
772 /* TODO: in global id umrechnen */
773 /* TODO: delete
774 ID(pe) = (theGrid->mg->elemIdCounter)++;
775 */
776 }
777
778 /****************************************************************************/
779 /* */
780 /* Function: ElementUpdate */
781 /* */
782 /* Purpose: update information related to an element. */
783 /* current implementation only for level 0 grids */
784 /* */
785 /* Input: DDD_OBJ obj: the element to handle */
786 /* */
787 /* Output: void */
788 /* */
789 /****************************************************************************/
790
791 static void ElementUpdate (DDD::DDDContext&, DDD_OBJ obj)
792 {
793 [[maybe_unused]] ELEMENT *pe = (ELEMENT *)obj;
794
795 PRINTDEBUG(dddif,1,(PFMT " ElementUpdate(): pe=" EID_FMTX
796 " EOBJ=%d\n",me,EID_PRTX(pe),OBJT(pe)))
797
798 /* TODO: delete this
799 SETNSONS(pe,0); */
800
801 /* TODO: this is not true any more, since elements pe, which are new and
802 have local non-new sons, have already gotten their NSONS through
803 ElementrPriorityUpdate() of the sons!!!
804 ASSERT(NSONS(pe) == 0);
805 */
806 }
807
808 /****************************************************************************/
809 /* */
810 /* Function: ElementDelete */
811 /* */
812 /* Purpose: remove element from UG data structure. */
813 /* current implementation only for level 0 grids */
814 /* */
815 /* Input: DDD_OBJ obj: the element to handle */
816 /* */
817 /* Output: void */
818 /* */
819 /****************************************************************************/
820
821 static void ElementDelete (DDD::DDDContext& context, DDD_OBJ obj)
822 {
823 ELEMENT *pe = (ELEMENT *)obj;
824 INT level = LEVEL(pe);
825 GRID *theGrid = GRID_ON_LEVEL(ddd_ctrl(context).currMG,level);
826
827 /* dispose element without connections (false) */
828 if (DisposeElement(theGrid, pe))
829 ASSERT(0);
830 }
831
832
833 /****************************************************************************/
834 /* */
835 /* Function: ElementXferCopy */
836 /* */
837 /* Purpose: initiate dependent copy of data related to an element. */
838 /* this handler is implemented for an arbitrary element type. */
839 /* */
840 /* Input: DDD_OBJ obj: the object which is transferred to proc */
841 /* int proc: destination processor for that object */
842 /* int prio: priority of object new local object */
843 /* */
844 /* Output: void */
845 /* */
846 /****************************************************************************/
847
848 static void ElementXferCopy (DDD::DDDContext& context, DDD_OBJ obj, DDD_PROC proc, DDD_PRIO prio)
849 {
850 auto& dddctrl = ddd_ctrl(context);
851
852 INT i,nsides;
853 ELEMENT *pe = (ELEMENT *)obj;
854 NODE *node;
855 BNDS *bnds[MAX_SIDES_OF_ELEM];
856
857 PRINTDEBUG(dddif,1,(PFMT " ElementXferCopy(): "
858 "pe=" EID_FMTX " proc=%d prio=%d EOBJT=%d\n",
859 me,EID_PRTX(pe),proc,prio,OBJT(pe)))
860
861 /* add element sides */
862 /* must be done before any XferCopyObj-call! herein */
863 /* or directly after XferCopyObj-call */
864
865 if (OBJT(pe)==BEOBJ) {
866 nsides = SIDES_OF_ELEM(pe);
867 for (i=0; i<nsides; i++)
868 bnds[i] = ELEM_BNDS(pe,i);
869
870 PRINTDEBUG(dddif,3,(PFMT " ElementXferCopy(): "
871 "pe=" EID_FMTX " BElementXferBndS nsides=%d\n",
872 me,EID_PRTX(pe),nsides))
873
874 BElementXferBndS(context, bnds,nsides,proc,prio);
875 }
876
877 if (DDD_XferWithAddData(context)) {
878 DDD_XferAddData(context, sizeof(pe->message_buffer_size()) + pe->message_buffer_size(), DDD_USER_DATA);
879
880 /* add edges of element */
881 /* must be done before any XferCopyObj-call! herein */
882 /* or directly after XferCopyObj-call for this element */
883 #ifdef UG_DIM_2
884 DDD_XferAddData(context, EDGES_OF_ELEM(pe), dddctrl.TypeEdge);
885 #endif
886 }
887
888 /* copy corner nodes */
889 for(i=0; i<CORNERS_OF_ELEM(pe); i++)
890 {
891 node = CORNER(pe,i);
892
893 PRINTDEBUG(dddif,2,(PFMT " ElementXferCopy(): e=" EID_FMTX
894 " Xfer n=" ID_FMTX " i=%d\n",
895 me,EID_PRTX(pe),ID_PRTX(node),i))
896
897 DDD_XferCopyObj(context, PARHDR(node), proc, prio);
898 }
899
900 /* send edge and edge vectors */
901 for (i=0; i<EDGES_OF_ELEM(pe); i++)
902 {
903 EDGE* edge = GetEdge(CORNER(pe,CORNER_OF_EDGE(pe,i,0)),
904 CORNER(pe,CORNER_OF_EDGE(pe,i,1)));
905 ASSERT(edge != NULL);
906 ASSERT(OBJT(edge) == EDOBJ);
907
908 PRINTDEBUG(dddif,2,(PFMT " ElementXferCopy(): e=" EID_FMTX
909 " EDGE=%x/%08x proc=%d prio=%d\n",
910 me,EID_PRTX(pe),edge,DDD_InfoGlobalId(PARHDR(edge)),
911 proc,prio))
912
913 DDD_XferCopyObj(context, PARHDR(edge), proc, prio);
914
915 if (dddctrl.edgeData) {
916 VECTOR *vec = EDVECTOR(edge);
917
918 if (vec != NULL) {
919 #ifdef UG_DIM_2
920 int Size = sizeof(VECTOR)-sizeof(DOUBLE);
921 #else
922 int Size = sizeof(VECTOR);
923 #endif
924 PRINTDEBUG(dddif,3,(PFMT " ElementXferCopy(): e=" EID_FMTX
925 " EDGEVEC=" VINDEX_FMTX " size=%d\n",
926 me,EID_PRTX(pe),VINDEX_PRTX(vec),Size))
927 DDD_XferCopyObjX(context, PARHDR(vec), proc, prio, Size);
928 }
929 }
930 }
931
932
933
934 /* copy element vector */
935 if (ddd_ctrl(context).elemData)
936 {
937 VECTOR *vec = EVECTOR(pe);
938
939 if (vec != NULL) {
940 INT Size = sizeof(VECTOR)-sizeof(DOUBLE);
941
942 PRINTDEBUG(dddif,2,(PFMT " ElementXferCopy(): e=" EID_FMTX
943 " ELEMVEC=" VINDEX_FMTX " size=%d\n",
944 me,EID_PRTX(pe),VINDEX_PRTX(vec),Size))
945
946 DDD_XferCopyObjX(context, PARHDR(vec), proc, prio, Size);
947 }
948 }
949
950 /* copy sidevectors */
951 #ifdef UG_DIM_3
952 if (dddctrl.sideData)
953 {
954 for (i=0; i<SIDES_OF_ELEM(pe); i++)
955 {
956 VECTOR *vec = SVECTOR(pe,i);
957
958 if (vec != NULL) {
959 INT Size = sizeof(VECTOR);
960
961 PRINTDEBUG(dddif,2,(PFMT " ElementXferCopy(): e=" EID_FMTX
962 " SIDEVEC=" VINDEX_FMTX " size=%d\n",
963 me,EID_PRTX(pe),VINDEX_PRTX(vec),Size))
964 DDD_XferCopyObjX(context, PARHDR(vec), proc, prio, Size);
965 }
966 }
967 }
968 #endif
969 }
970
971
972 /****************************************************************************/
973
974 #ifdef UG_DIM_2
975 static void ElemGatherEdge (DDD::DDDContext& context, ELEMENT *pe, int cnt, char *data)
976 {
977 INT i;
978 INT size = sizeof(EDGE) - ((ddd_ctrl(context).edgeData) ? 0 : sizeof(VECTOR*));
979
980 PRINTDEBUG(dddif,3,(PFMT " ElemGatherEdge(): pe=" EID_FMTX " cnt=%d size=%d\n",
981 me,EID_PRTX(pe),cnt,size))
982
983 /* copy edges into message */
984 for (i=0; i<EDGES_OF_ELEM(pe); i++)
985 {
986 EDGE *edge = GetEdge(CORNER(pe,CORNER_OF_EDGE(pe,i,0)),
987 CORNER(pe,CORNER_OF_EDGE(pe,i,1)));
988 ASSERT(edge!=NULL);
989 memcpy(data, (char *)edge, size);
990 data += CEIL(size);
991
992
993 PRINTDEBUG(dddif,2,(PFMT " ElemGatherEdge(): pe=" EID_FMTX " i=%d n1="
994 ID_FMTX " n2=" ID_FMTX " nmid=%08x\n",me,EID_PRTX(pe),i,
995 ID_PRTX(NBNODE(LINK0(edge))),ID_PRTX(NBNODE(LINK1(edge))),
996 MIDNODE(edge)))
997 }
998 }
999
1000
1001 static void ElemScatterEdge (DDD::DDDContext& context, ELEMENT *pe, int cnt, char *data, int newness)
1002 {
1003 INT i;
1004 INT size = sizeof(EDGE) - ((ddd_ctrl(context).edgeData) ? 0 : sizeof(VECTOR*));
1005 INT level = LEVEL(pe);
1006 GRID *theGrid = GetGridOnDemand(ddd_ctrl(context).currMG,level);
1007
1008 PRINTDEBUG(dddif,3,(PFMT " ElemScatterEdge(): pe=" EID_FMTX
1009 " cnt=%d newness=%d\n",
1010 me,EID_PRTX(pe),cnt,newness))
1011
1012 /* XFER_REJECT: only case where edges must not be unpacked */
1013 /* this is not correct, since newness XFER_REJECT might have */
1014 /* non NULL midnode pointers in the edges (971007 s.l.) */
1015 /* XFER_REJECT: new MIDNODE pointers might be non NULL */
1016 /* XFER_NEW: there are still no edges -> unpack */
1017 /* XFER_UPGRADE: new MIDNODE pointers might be non NULL */
1018 /* if (newness == XFER_REJECT) return; */
1019
1020 /* retrieve edges from message */
1021 for (i=0; i<cnt; i++)
1022 {
1023 EDGE *enew, *ecopy = (EDGE *)data;
1024 data += CEIL(size);
1025
1026 PRINTDEBUG(dddif,2,(PFMT " ElemScatterEdge(): elem=" EID_FMTX
1027 " i=%d n1=" ID_FMTX " n2=" ID_FMTX " midnode=%x\n",
1028 me,pe,EID_PRTX(pe),i,
1029 ID_PRTX(NBNODE(LINK0(ecopy))),
1030 ID_PRTX(NBNODE(LINK1(ecopy))),
1031 ecopy->midnode))
1032
1033 /* this is the 2D case for edge creation: */
1034 /* CreateEdge increments the NO_OF_ELEM count */
1035 /* NO_OF_ELEM counter gets wrong if an element */
1036 /* is unpacked several times. */
1037 ASSERT(NBNODE(LINK0(ecopy)) != NULL);
1038 ASSERT(NBNODE(LINK1(ecopy)) != NULL);
1039 if (newness == XFER_NEW) {
1040 enew = CreateEdge(theGrid,pe,i, false);
1041 SETEDSUBDOM(enew,EDSUBDOM(ecopy));
1042 }
1043 else {
1044 enew = GetEdge(NBNODE(LINK0(ecopy)),
1045 NBNODE(LINK1(ecopy)));
1046 if (enew == NULL) {
1047 enew = CreateEdge(theGrid,pe,i,false);
1048 SETEDSUBDOM(enew,EDSUBDOM(ecopy));
1049 /* TODO: remove this check if the first call is with XFER_NEW */
1050 ASSERT(0);
1051 DEC_NO_OF_ELEM(enew);
1052 }
1053 }
1054 PRINTDEBUG(dddif,2,(PFMT " ElemScatterEdge(): elem=" EID_FMTX
1055 " create edge=%x for n0=" EID_FMTX " n1=" ID_FMTX "\n",
1056 me,EID_PRTX(pe),enew,
1057 ID_PRTX(NBNODE(LINK0(ecopy))),
1058 ID_PRTX(NBNODE(LINK1(ecopy)))));
1059
1060 if (enew == NULL)
1061 {
1062 PRINTDEBUG(dddif,1,(PFMT " ElemScatterEdge(): ERROR pe=" EID_FMTX
1063 " i=%d %s returned NULL\n",
1064 me,EID_PRTX(pe),i,(newness==XFER_NEW) ? "CreateEdge()" : "GetEdge()"));
1065 ASSERT(0);
1066 }
1067 #ifdef Debug
1068 {
1069 EDGE *edge0,*edge1;
1070
1071 edge0 = GetEdge(NBNODE(LINK0(ecopy)),NBNODE(LINK1(ecopy)));
1072 edge1 = GetEdge(NBNODE(LINK1(ecopy)),NBNODE(LINK0(ecopy)));
1073 if (edge0 != edge1)
1074 {
1075 PRINTDEBUG(dddif,1,(PFMT " ElemScatterEdge(): n0=" ID_FMTX
1076 " n1=" ID_FMTX " edge0=%08x BUT edge1=%08x\n",me,
1077 ID_PRTX(NBNODE(LINK0(ecopy))),
1078 ID_PRTX(NBNODE(LINK1(ecopy))),
1079 edge0,edge1));
1080 ASSERT(0);
1081 }
1082 }
1083 #endif
1084
1085 /* copy midnode pointer */
1086 if (MIDNODE(ecopy) != NULL)
1087 {
1088 VERTEX *theVertex;
1089 INT co0,co1;
1090
1091 MIDNODE(enew) = MIDNODE(ecopy);
1092 theVertex = MYVERTEX(MIDNODE(enew));
1093
1094 /* reconstruct local coordinates of vertex */
1095 co0 = CORNER_OF_EDGE(pe,i,0);
1096 co1 = CORNER_OF_EDGE(pe,i,1);
1097
1098 ASSERT(theVertex != NULL);
1099
1100 /* local coordinates have to be local towards pe */
1101 if (EMASTER(pe)) {
1102 if (MOVED(theVertex))
1103 {
1104 DOUBLE *x[MAX_CORNERS_OF_ELEM];
1105 INT n;
1106
1107 CORNER_COORDINATES(pe,n,x);
1108 UG_GlobalToLocal(n,(const DOUBLE **)x,
1109 CVECT(theVertex),LCVECT(theVertex));
1110 }
1111 else
1112 V_DIM_LINCOMB(0.5, LOCAL_COORD_OF_ELEM(pe,co0),
1113 0.5, LOCAL_COORD_OF_ELEM(pe,co1),
1114 LCVECT(theVertex));
1115 /* make vertex information consistent */
1116 VFATHER(theVertex) = pe;
1117 SETONEDGE(theVertex,i);
1118 }
1119
1120 /* set nfather pointer of midnode */
1121 ASSERT(enew != NULL);
1122 ASSERT(ID(MIDNODE(enew)) != -1);
1123 SETNFATHER(MIDNODE(enew),(GEOM_OBJECT *)enew);
1124
1125 PRINTDEBUG(dddif,1,(PFMT " ElemScatterEdge(): n=" ID_FMTX
1126 " NTYPE=%d OBJT=%d father " ID_FMTX " \n",
1127 me,ID_PRTX(MIDNODE(enew)),NTYPE(MIDNODE(enew)),
1128 OBJT(NFATHER(MIDNODE(enew))),
1129 NFATHER(MIDNODE(enew))));
1130 }
1131
1132 /* copy edge vector pointer */
1133 if (newness == XFER_NEW)
1134 if (ddd_ctrl(context).edgeData)
1135 if (EDVECTOR(ecopy) != NULL) {
1136 EDVECTOR(enew) = EDVECTOR(ecopy);
1137 VOBJECT(EDVECTOR(enew)) = (GEOM_OBJECT *)enew;
1138 }
1139 }
1140 }
1141 #endif /* end UG_DIM_2 */
1142
1143
1144 /****************************************************************************/
1145
1146
1147 static void ElemGatherI (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TYPE type_id, void *data)
1148 {
1149 if (type_id == DDD_USER_DATA)
1150 {
1151 DuneEntityGather<union element>(context, obj, cnt, type_id, data);
1152 return;
1153 }
1154
1155 #ifdef UG_DIM_2
1156 /* now: type_id is always TypeEdge */
1157 ElemGatherEdge(context, (ELEMENT *)obj, cnt, (char *)data);
1158 #endif
1159 }
1160
1161
1162 static void ElemScatterI (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TYPE type_id,
1163 void *data, int newness)
1164 {
1165 if (type_id == DDD_USER_DATA)
1166 {
1167 DuneEntityScatter<union element>(context, obj, cnt, type_id, data, newness);
1168 return;
1169 }
1170
1171 #ifdef UG_DIM_2
1172 /* type_id is always TypeEdge */
1173 ElemScatterEdge(context, (ELEMENT *)obj, cnt, (char *)data, newness);
1174 #endif
1175 }
1176
1177 static void ElemGatherB (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TYPE type_id, void *data)
1178 {
1179 INT i,nsides;
1180 BNDS *bnds[MAX_SIDES_OF_ELEM];
1181 ELEMENT *pe = (ELEMENT *)obj;
1182
1183 if (type_id == DDD_DOMAIN_DATA)
1184 {
1185 nsides = SIDES_OF_ELEM(pe);
1186 for (i=0; i<nsides; i++)
1187 bnds[i] = ELEM_BNDS(pe,i);
1188 BElementGatherBndS(bnds, nsides, cnt, (char *)data);
1189 return;
1190 }
1191 if (type_id == DDD_USER_DATA)
1192 {
1193 DuneEntityGather<union element>(context, obj, cnt, type_id, data);
1194 return;
1195 }
1196
1197 /* now: type_id is TypeEdge or other */
1198 #ifdef UG_DIM_2
1199 if (type_id==ddd_ctrl(context).TypeEdge)
1200 {
1201 ElemGatherEdge(context, pe, cnt, (char *)data);
1202 }
1203 #endif
1204 }
1205
1206
1207 static void ElemScatterB (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TYPE type_id,
1208 void *data, int newness)
1209 {
1210 INT i,nsides;
1211 BNDS *bnds[MAX_SIDES_OF_ELEM];
1212 ELEMENT *pe = (ELEMENT *)obj;
1213
1214 if (type_id == DDD_DOMAIN_DATA)
1215 {
1216 nsides = SIDES_OF_ELEM(pe);
1217 for (i=0; i<nsides; i++)
1218 bnds[i] = ELEM_BNDS(pe,i);
1219 BElementScatterBndS(context, bnds, nsides, cnt, (char *)data);
1220 for (i=0; i<nsides; i++)
1221 SET_BNDS(pe,i,bnds[i]);
1222 return;
1223 }
1224 if (type_id == DDD_USER_DATA)
1225 {
1226 DuneEntityScatter<union element>(context, obj, cnt, type_id, data, newness);
1227 return;
1228 }
1229
1230 /* now: type_id is TypeEdge or other */
1231 #ifdef UG_DIM_2
1232 if (type_id==ddd_ctrl(context).TypeEdge)
1233 {
1234 ElemScatterEdge(context, pe, cnt, (char *)data, newness);
1235 }
1236 #endif
1237 }
1238
1239
1240 /****************************************************************************/
1241
1242
1243 static void ElementObjMkCons (DDD::DDDContext& context, DDD_OBJ obj, int newness)
1244 {
1245 INT lostson = 0;
1246 ELEMENT *pe = (ELEMENT *)obj;
1247 ELEMENT *succe = SUCCE(pe);
1248 ELEMENT *Next = NULL;
1249 INT prio = EPRIO(pe);
1250 ELEMENT *theFather = EFATHER(pe);
1251 ELEMENT *NbElement;
1252 INT level = LEVEL(pe);
1253 GRID *theGrid = GetGridOnDemand(ddd_ctrl(context).currMG,level);
1254
1255
1256 PRINTDEBUG(dddif,1,(PFMT " ElementObjMkCons(): pe=" EID_FMTX
1257 " newness=%d\n",
1258 me,EID_PRTX(pe),newness))
1259
1260 DEBUGNSONS(pe,theFather,"ElementObjMkCons begin:");
1261
1262 /* correct nb relationships between ghostelements */
1263 if (EGHOST(pe))
1264 {
1265 for (INT i = 0; i < SIDES_OF_ELEM(pe); i++)
1266 {
1267 NbElement = NBELEM(pe,i);
1268 if (NbElement!=NULL && EGHOST(NbElement))
1269 {
1270 INT j = 0;
1271 for (j = 0; j < SIDES_OF_ELEM(NbElement); j++)
1272 if (NBELEM(NbElement,j) == pe) break;
1273 /* no backptr reset nb pointer */
1274 if (j >= SIDES_OF_ELEM(NbElement)) SET_NBELEM(pe,i,NULL);
1275 }
1276 }
1277 }
1278
1279 /* reconstruct pointer from vectors */
1280 if (ddd_ctrl(context).elemData) VOBJECT(EVECTOR(pe)) = (GEOM_OBJECT*)pe;
1281
1282 #ifdef UG_DIM_3
1283 if (ddd_ctrl(context).sideData)
1284 for (INT i = 0; i < SIDES_OF_ELEM(pe); i++) {
1285 VOBJECT(SVECTOR(pe,i)) = (GEOM_OBJECT*)pe;
1286 SETVECTORSIDE(SVECTOR(pe,i), i);
1287 }
1288 #endif
1289
1290 /* if called with prio old=ghost and new=ghost,
1291 then you have eventually to unlink and link
1292 an element again to avoid
1293 decoupling of element and its father.
1294 Sample scenario:
1295 father=a son=x are on proc p.
1296 father is deleted and removes his reference in son,
1297 but father and son are sent again to p. Son x gets
1298 his father pointer again. Son needs to be
1299 rearranged in element list to be surely a son of father.
1300 This applies only for ghost sons, since master sons
1301 avoid deleting of their fathers?!
1302 */
1303 if (newness != XFER_NEW)
1304 {
1305 if (prio == PrioMaster)
1306 return;
1307 else if (theFather != NULL)
1308 {
1309 ELEMENT *SonList[MAX_SONS];
1310
1311 /* check whether NSONS of father must be incremented */
1312 if (GetAllSons(theFather,SonList)) ASSERT(0);
1313 int i = 0;
1314 while (i<MAX_SONS && SonList[i] != NULL)
1315 {
1316 if (SonList[i] == pe) return;
1317 i++;
1318 }
1319 PRINTDEBUG(dddif,1,(PFMT " ElementObjMkCons(): father: f="
1320 EID_FMTX " lost son=" EID_FMTX " nsons=%d\n",me,
1321 EID_PRTX(theFather),EID_PRTX(pe),NSONS(theFather)));
1322
1323 lostson = 1;
1324 GRID_UNLINK_ELEMENT(theGrid,pe);
1325
1326 if (SON(theFather,PRIO2INDEX(prio)) == pe)
1327 {
1328 if (succe != NULL)
1329 {
1330 if (EFATHER(succe)==theFather)
1331 #ifdef ModelP
1332 if (PRIO2INDEX(EPRIO(succe)) == PRIO2INDEX(prio))
1333 #endif
1334 {
1335 Next = succe;
1336 }
1337 }
1338 SET_SON(theFather,PRIO2INDEX(prio),Next);
1339 }
1340 }
1341 }
1342
1343 if (newness == XFER_NEW || lostson)
1344 {
1345 /* link element into list according to prio */
1346 INT where = PRIO2INDEX(prio);
1347 ELEMENT *after;
1348
1349 if (theFather != NULL)
1350 {
1351 /* link element with father */
1352 after = SON(theFather,where);
1353
1354 PRINTDEBUG(dddif,1,(PFMT " ElementObjMkCons(): GRID_LINKX_ELEMENT "
1355 "pe=" EID_FMTX " prio=%d where=%d after=%x father= " EID_FMTX
1356 "\n", me,EID_PRTX(pe),prio,where,after,EID_PRTX(theFather)))
1357
1358 GRID_LINKX_ELEMENT(theGrid,pe,prio,after);
1359
1360 /* construct son information */
1361 if (after == NULL)
1362 {
1363 ELEMENT *next;
1364
1365 SET_SON(theFather,where,pe);
1366
1367 /* every successor of pe was decoupled before */
1368 /* -> correct NSONS */
1369 next = SUCCE(pe);
1370 while (next!=NULL && PRIO2INDEX(EPRIO(next))==PRIO2INDEX(prio)
1371 && theFather==EFATHER(next))
1372 {
1373 SETNSONS(theFather,NSONS(theFather)+1);
1374 next = SUCCE(next);
1375 }
1376 }
1377 SETNSONS(theFather,NSONS(theFather)+1);
1378 }
1379 else
1380 {
1381 /* link coarse grid element or ghost element */
1382 GRID_LINK_ELEMENT(theGrid,pe,prio);
1383
1384 #ifdef Debug
1385 if (level > 0)
1386 /* only ghost elements may have no father */
1387 assert(EGHOST(pe));
1388 #endif
1389 }
1390 }
1391
1392 #ifdef UG_DIM_3
1393 /* update element count of edges for new created elements */
1394 if (newness == XFER_NEW)
1395 /* increment elem counter in edges */
1396 for (INT i = 0; i < EDGES_OF_ELEM(pe); i++)
1397 {
1398 EDGE *theEdge;
1399 NODE *theNode0 = CORNER(pe,CORNER_OF_EDGE(pe,i,0));
1400 NODE *theNode1 = CORNER(pe,CORNER_OF_EDGE(pe,i,1));
1401
1402 ASSERT(theNode0!=NULL && theNode1!=NULL);
1403
1404 PRINTDEBUG(dddif,4,(PFMT " ElementObjMkCons(): pe=" EID_FMTX
1405 " INC_NO_OF_ELEM for n0=" ID_FMTX " n1=" ID_FMTX "\n",
1406 me,EID_PRTX(pe),ID_PRTX(theNode0),ID_PRTX(theNode1)))
1407
1408 theEdge = GetEdge(theNode0,theNode1);
1409 if (theEdge == NULL)
1410 {
1411 PRINTDEBUG(dddif,0,(PFMT " ElementObjMkCons(): pe=" EID_FMTX
1412 "/%d/%d INC_NO_OF_ELEM for n0=" ID_FMTX " n1=" ID_FMTX " FAILED\n",
1413 me,EID_PRTX(pe),ECLASS(pe),REFINE(EFATHER(pe)),
1414 ID_PRTX(theNode0),ID_PRTX(theNode1)))
1415 assert(0);
1416 }
1417
1418 INC_NO_OF_ELEM(theEdge);
1419 }
1420 #endif
1421
1422 DEBUGNSONS(pe,theFather,"end ElementObjMkCons");
1423 }
1424
1425
1426 static void ElementPriorityUpdate (DDD::DDDContext& context, DDD_OBJ obj, DDD_PRIO new_)
1427 {
1428 ELEMENT *pe = (ELEMENT *)obj;
1429 ELEMENT *theFather = EFATHER(pe);
1430 ELEMENT *succe = SUCCE(pe);
1431 INT level = LEVEL(pe);
1432 GRID *theGrid = GetGridOnDemand(ddd_ctrl(context).currMG,level);
1433 const DDD_PRIO old = EPRIO(pe);
1434 INT lostson = 1;
1435
1436 PRINTDEBUG(dddif,1,(PFMT " ElementPriorityUpdate(): e=" EID_FMTX
1437 " old=%d new=%d level=%d\n",me,EID_PRTX(pe),old,new_,level))
1438
1439 if (pe == NULL) return;
1440
1441 /* if called with prio old=ghost and new=ghost,
1442 then you have to unlink and link again to avoid
1443 decoupling of son and father.
1444 Sample scenario:
1445 father=a son=x are on proc p.
1446 father is deleted and removes his reference in son,
1447 but father and son are sent again to p. Son x gets
1448 his father pointer again. Son needs to be
1449 rearranged in element to list be surely a son of father.
1450 This applies only for ghost sons, since master sons
1451 avoid deleting of their fathers?!
1452 */
1453
1454 if (old == PrioNone) {
1455 /* only valid for masters */
1456 ASSERT(new_ == PrioMaster);
1457 return;
1458 }
1459
1460 if (new_ == PrioNone) {
1461 /* only valid when prio undefined */
1462 printf("prio=%d\n",old);
1463 fflush(stdout);
1464 ASSERT(old <= 0);
1465 return;
1466 }
1467
1468 /* check whether element and father are decoupled */
1469 if (theFather != NULL)
1470 {
1471 ELEMENT *SonList[MAX_SONS];
1472 int i;
1473
1474 if (GetAllSons(theFather,SonList)) ASSERT(0);
1475 i = 0;
1476 while (i<MAX_SONS && SonList[i] != NULL)
1477 {
1478 if (SonList[i] == pe) lostson = 0;
1479 i++;
1480 }
1481
1482 PRINTDEBUG(dddif,1,(PFMT " ElementPriorityUpdate(): father: f="
1483 EID_FMTX " lost son=" EID_FMTX " nsons=%d\n",me,
1484 EID_PRTX(theFather),EID_PRTX(pe),NSONS(theFather)));
1485
1486 if (lostson == 1)
1487 SETNSONS(theFather,NSONS(theFather)+1);
1488 else if (old == new_)
1489 return;
1490 }
1491
1492 GRID_UNLINK_ELEMENT(theGrid,pe);
1493
1494 /* link element into list according to prio */
1495 {
1496 INT where = PRIO2INDEX(new_);
1497
1498 if (theFather != NULL)
1499 {
1500 ELEMENT *Next = NULL;
1501 INT oldwhere = PRIO2INDEX(old);
1502
1503 /* update son information for old prio */
1504 if (pe == SON(theFather,oldwhere))
1505 {
1506 if (succe != NULL)
1507 if (EFATHER(succe)==theFather && PRIO2INDEX(EPRIO(succe))==PRIO2INDEX(old))
1508 Next = succe;
1509
1510 SET_SON(theFather,oldwhere,Next);
1511 }
1512
1513 /* link elements with father */
1514 ELEMENT *after = SON(theFather,where);
1515
1516 PRINTDEBUG(dddif,2,(PFMT " ElementPriorityUpdate(): GRID_LINKX_ELEMENT "
1517 "pe=" EID_FMTX " prio=%d after=%x\n",me,EID_PRTX(pe),new_,after))
1518
1519 GRID_LINKX_ELEMENT(theGrid,pe,new_,after);
1520
1521 /* update son information for new prio */
1522 if (after == NULL)
1523 {
1524 ELEMENT *next;
1525
1526 SET_SON(theFather,where,pe);
1527
1528 /* add successor elements which were decoupled before */
1529 next = SUCCE(pe);
1530 while (next!=NULL && PRIO2INDEX(EPRIO(next))==PRIO2INDEX(new_)
1531 && theFather==EFATHER(next))
1532 {
1533 SETNSONS(theFather,NSONS(theFather)+1);
1534 next = SUCCE(next);
1535 }
1536 }
1537 }
1538 else
1539 {
1540 PRINTDEBUG(dddif,2,(PFMT " ElementPriorityUpdate(): GRID_LINK_ELEMENT "
1541 "pe=" EID_FMTX " prio=%d",me,EID_PRTX(pe),new_))
1542
1543 /* link coarse grid element */
1544 GRID_LINK_ELEMENT(theGrid,pe,new_);
1545
1546 /* only GhostElements may have no father */
1547 /*
1548 if (level > 0)
1549 {
1550 assert(EGHOSTPRIO(new_));
1551 assert(EGHOST(pe));
1552 }
1553 */
1554 }
1555 }
1556 }
1557
1558 /****************************************************************************/
1559 /****************************************************************************/
1560 /* */
1561 /* handlers for typeedge */
1562 /* */
1563 /****************************************************************************/
1564 /****************************************************************************/
1565
1566 static void EdgeUpdate (DDD::DDDContext& context, DDD_OBJ obj)
1567 {
1568 EDGE *pe = (EDGE *)obj;
1569 INT level = LEVEL(NBNODE(LINK0(pe)));
1570 GRID *theGrid = GetGridOnDemand(ddd_ctrl(context).currMG,level);
1571
1572 PRINTDEBUG(dddif,1,(PFMT " EdgeUpdate(): edge=%x/%08x EDOBJT=%d "
1573 " NO_OF_ELEM=%d\n",
1574 me,pe,DDD_InfoGlobalId(PARHDR(pe)),OBJT(pe),NO_OF_ELEM(pe)))
1575
1576 {
1577 /* insert in link lists of nodes */
1578 LINK* link0 = LINK0(pe);
1579 LINK* link1 = LINK1(pe);
1580
1581 PRINTDEBUG(dddif,2,(PFMT " EdgeUpdate(): edge=%x/%08x node0="
1582 ID_FMTX " node1=" ID_FMTX "\n",
1583 me,pe,DDD_InfoGlobalId(PARHDR(pe)),
1584 ID_PRTX(NBNODE(link1)),ID_PRTX(NBNODE(link0))))
1585
1586 NODE* node0 = NBNODE(link1);
1587 NODE* node1 = NBNODE(link0);
1588
1589 NEXT(link0) = START(node0);
1590 START(node0) = link0;
1591 NEXT(link1) = START(node1);
1592 START(node1) = link1;
1593
1594 /* reset element counter
1595 SET_NO_OF_ELEM(pe,0); */
1596 }
1597
1598 /* set nfather pointer of midnode */
1599 if (MIDNODE(pe) != NULL)
1600 {
1601 ASSERT(ID(MIDNODE(pe)) != -1);
1602 ASSERT(NTYPE((MIDNODE(pe))) == MID_NODE);
1603 SETNFATHER(MIDNODE(pe),(GEOM_OBJECT *)pe);
1604 }
1605
1606 ASSERT(OBJT(pe) == EDOBJ);
1607
1608 /* increment counter */
1609 NE(theGrid)++;
1610 }
1611
1612 static void EdgePriorityUpdate (DDD::DDDContext& context, DDD_OBJ obj, DDD_PRIO new_)
1613 {
1614 EDGE *theEdge = (EDGE *)obj;
1615 INT level = LEVEL(theEdge);
1616 [[maybe_unused]] INT old = PRIO(theEdge);
1617
1618 GetGridOnDemand(ddd_ctrl(context).currMG,level);
1619
1620 PRINTDEBUG(dddif,2,(PFMT " EdgePriorityUpdate(): n=" ID_FMTX " old=%d new_=%d "
1621 "level=%d\n",me,ID_PRTX(theEdge),old,new_,level))
1622 }
1623
1624 static void EdgeObjMkCons (DDD::DDDContext& context, DDD_OBJ obj, int newness)
1625 {
1626 EDGE *theEdge = (EDGE *) obj;
1627
1628 PRINTDEBUG(dddif,2,(PFMT " EdgeObjMkCons(): n=" ID_FMTX " EDOBJ=%d\n",
1629 me,ID_PRTX(theEdge),OBJT(theEdge)))
1630
1631 /* set pointer of vector to its edge */
1632 if (ddd_ctrl(context).edgeData && EDVECTOR(theEdge))
1633 VOBJECT(EDVECTOR(theEdge)) = (GEOM_OBJECT*)theEdge;
1634
1635 ASSERT(OBJT(theEdge) == EDOBJ);
1636 }
1637
1638 static void EdgeXferCopy (DDD::DDDContext& context, DDD_OBJ obj, DDD_PROC proc, DDD_PRIO prio)
1639 {
1640 [[maybe_unused]] EDGE *pe = (EDGE *)obj;
1641
1642 PRINTDEBUG(dddif,1,(PFMT " EdgeXferCopy(): edge=%x/%08x proc=%d prio=%d\n",
1643 me,pe,DDD_InfoGlobalId(PARHDR(pe)),proc,prio));
1644
1645 ASSERT(OBJT(pe) == EDOBJ);
1646 }
1647
1648 /****************************************************************************/
1649 /****************************************************************************/
1650 /* */
1651 /* general handlers */
1652 /* */
1653 /****************************************************************************/
1654 /****************************************************************************/
1655
1656 void NS_DIM_PREFIX ObjectPriorityUpdate (DDD::DDDContext& context, DDD_OBJ obj, DDD_PRIO new_)
1657 {
1658 char type = OBJT(obj);
1659
1660 switch(type)
1661 {
1662 case VEOBJ :
1663 VectorPriorityUpdate(context, obj,new_);
1664 break;
1665 case IVOBJ :
1666 case BVOBJ :
1667 VertexPriorityUpdate(context, obj,new_);
1668 break;
1669 case NDOBJ :
1670 NodePriorityUpdate(context, obj,new_);
1671 break;
1672 case IEOBJ :
1673 case BEOBJ :
1674 ElementPriorityUpdate(context, obj,new_);
1675 break;
1676 case EDOBJ :
1677 EdgePriorityUpdate(context, obj,new_);
1678 break;
1679 default : std::abort();
1680 }
1681 }
1682
1683 /****************************************************************************/
1684
1685
1686 /* init handlers for all element */
1687 static void ElemHandlerInit (DDD::DDDContext& context, DDD_TYPE etype, INT handlerSet)
1688 {
1689 DDD_SetHandlerLDATACONSTRUCTOR(context, etype, ElementLDataConstructor);
1690 DDD_SetHandlerDELETE (context, etype, ElementDelete);
1691 DDD_SetHandlerXFERCOPY (context, etype, ElementXferCopy);
1692 DDD_SetHandlerSETPRIORITY (context, etype, ElementPriorityUpdate);
1693
1694 #ifdef UG_DIM_3
1695 DDD_SetHandlerUPDATE (context, etype, ElementUpdate);
1696 #endif
1697
1698
1699 switch (handlerSet)
1700 {
1701 /* TODO: not needed any more ??
1702 case HSET_XFER:
1703 DDD_SetHandlerOBJMKCONS(context, etype, ElementObjMkCons_Xfer);
1704 break;
1705
1706 case HSET_REFINE:
1707 DDD_SetHandlerOBJMKCONS(context, etype, ElementObjMkCons_Refine);
1708 break;
1709 */
1710 default :
1711 DDD_SetHandlerOBJMKCONS(context, etype, ElementObjMkCons);
1712 break;
1713 }
1714 }
1715
1716
1717 /* init handlers for inner element */
1718 static void IElemHandlerInit (DDD::DDDContext& context, DDD_TYPE etype, INT handlerSet)
1719 {
1720 /* init standard elem handlers */
1721 ElemHandlerInit(context, etype, handlerSet);
1722
1723 /* init additional handlers, necessary for inside management */
1724 DDD_SetHandlerXFERGATHER (context, etype, ElemGatherI);
1725 DDD_SetHandlerXFERSCATTER(context, etype, ElemScatterI);
1726 }
1727
1728
1729 /* init handlers for boundary element */
1730 static void BElemHandlerInit (DDD::DDDContext& context, DDD_TYPE etype, INT handlerSet)
1731 {
1732 /* init standard elem handlers */
1733 ElemHandlerInit(context, etype, handlerSet);
1734
1735 /* init additional handlers, necessary for boundary management */
1736 DDD_SetHandlerXFERGATHER (context, etype, ElemGatherB);
1737 DDD_SetHandlerXFERSCATTER(context, etype, ElemScatterB);
1738 }
1739
1740
1741 /****************************************************************************/
1742
1743 /* init all handlers necessary for grid xfer */
1744 void NS_DIM_PREFIX ddd_HandlerInit (DDD::DDDContext& context, INT handlerSet)
1745 {
1746 auto& dddctrl = ddd_ctrl(context);
1747
1748 DDD_SetHandlerUPDATE (context, dddctrl.TypeVector, VectorUpdate);
1749 DDD_SetHandlerXFERCOPY (context, dddctrl.TypeVector, VectorXferCopy);
1750 DDD_SetHandlerSETPRIORITY (context, dddctrl.TypeVector, VectorPriorityUpdate);
1751 /* TODO: not used
1752 DDD_SetHandlerDELETE (context, dddctrl.TypeVector, VectorDelete);
1753 */
1754
1755 DDD_SetHandlerUPDATE (context, dddctrl.TypeIVertex, VertexUpdate);
1756 DDD_SetHandlerSETPRIORITY (context, dddctrl.TypeIVertex, VertexPriorityUpdate);
1757
1758 DDD_SetHandlerLDATACONSTRUCTOR (context, dddctrl.TypeBVertex, BVertexLDataConstructor);
1759 DDD_SetHandlerUPDATE (context, dddctrl.TypeBVertex, VertexUpdate);
1760 DDD_SetHandlerXFERCOPY (context, dddctrl.TypeBVertex, BVertexXferCopy);
1761 DDD_SetHandlerXFERGATHER (context, dddctrl.TypeBVertex, BVertexGather);
1762 DDD_SetHandlerXFERSCATTER (context, dddctrl.TypeBVertex, BVertexScatter);
1763 DDD_SetHandlerSETPRIORITY (context, dddctrl.TypeBVertex, VertexPriorityUpdate);
1764
1765 DDD_SetHandlerXFERGATHER (context, dddctrl.TypeNode, DuneEntityGather<NODE>);
1766 DDD_SetHandlerXFERSCATTER (context, dddctrl.TypeNode, DuneEntityScatter<NODE>);
1767
1768 DDD_SetHandlerLDATACONSTRUCTOR (context, dddctrl.TypeNode, NodeObjInit);
1769 DDD_SetHandlerDESTRUCTOR (context, dddctrl.TypeNode, NodeDestructor);
1770 DDD_SetHandlerOBJMKCONS (context, dddctrl.TypeNode, NodeObjMkCons);
1771 DDD_SetHandlerUPDATE (context, dddctrl.TypeNode, NodeUpdate);
1772 DDD_SetHandlerXFERCOPY (context, dddctrl.TypeNode, NodeXferCopy);
1773 DDD_SetHandlerSETPRIORITY (context, dddctrl.TypeNode, NodePriorityUpdate);
1774
1775
1776
1777 #ifdef UG_DIM_2
1778 IElemHandlerInit(context, dddctrl.TypeTrElem, handlerSet);
1779 BElemHandlerInit(context, dddctrl.TypeTrBElem, handlerSet);
1780
1781 IElemHandlerInit(context, dddctrl.TypeQuElem, handlerSet);
1782 BElemHandlerInit(context, dddctrl.TypeQuBElem, handlerSet);
1783 #endif
1784
1785 #ifdef UG_DIM_3
1786 IElemHandlerInit(context, dddctrl.TypeTeElem, handlerSet);
1787 BElemHandlerInit(context, dddctrl.TypeTeBElem, handlerSet);
1788
1789 IElemHandlerInit(context, dddctrl.TypePyElem, handlerSet);
1790 BElemHandlerInit(context, dddctrl.TypePyBElem, handlerSet);
1791
1792 IElemHandlerInit(context, dddctrl.TypePrElem, handlerSet);
1793 BElemHandlerInit(context, dddctrl.TypePrBElem, handlerSet);
1794
1795 IElemHandlerInit(context, dddctrl.TypeHeElem, handlerSet);
1796 BElemHandlerInit(context, dddctrl.TypeHeBElem, handlerSet);
1797 #endif
1798
1799 DDD_SetHandlerUPDATE (context, dddctrl.TypeEdge, EdgeUpdate);
1800 DDD_SetHandlerOBJMKCONS (context, dddctrl.TypeEdge, EdgeObjMkCons);
1801 DDD_SetHandlerXFERCOPY (context, dddctrl.TypeEdge, EdgeXferCopy);
1802 DDD_SetHandlerSETPRIORITY (context, dddctrl.TypeEdge, EdgePriorityUpdate);
1803
1804 DomHandlerInit(handlerSet);
1805 }
1806
1807 #endif /* ModelP */