1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 /****************************************************************************/
4 /*																			*/
5 /* File:	  initddd.c														*/
6 /*																			*/
7 /* Purpose:   register ug structs for handling them by ddd					*/
8 /*																			*/
9 /* Author:	  Stefan Lang, Klaus Birken										*/
10 /*			  Institut fuer Computeranwendungen III                                                 */
11 /*			  Universitaet Stuttgart										*/
12 /*			  Pfaffenwaldring 27											*/
13 /*			  70550 Stuttgart												*/
14 /*																			*/
15 /* History:   09.05.95 begin, ugp version 3.0								*/
16 /*																			*/
17 /* Remarks:                                                                                                                             */
18 /*																			*/
19 /****************************************************************************/
20 
21 #ifdef ModelP
22 
23 /****************************************************************************/
24 /*																			*/
25 /* include files															*/
26 /*			  system include files											*/
27 /*			  application include files                                                                     */
28 /*																			*/
29 /****************************************************************************/
30 
31 #include <config.h>
32 #include <cstddef>
33 #include <cstdlib>
34 
35 #include "parallel.h"
36 #include <dune/uggrid/low/debug.h>
37 #include <dune/uggrid/low/namespace.h>
38 #include <dune/uggrid/gm/ugm.h>      /* for GetFreeOBJT() */
39 #include <dune/uggrid/parallel/ddd/include/memmgr.h>
40 #include <dune/uggrid/ugdevices.h>
41 
42 /* UG namespaces: */
43 USING_UG_NAMESPACES
44 
45 /* PPIF namespace: */
46 using namespace PPIF;
47 
48 /****************************************************************************/
49 /*																			*/
50 /* defines in the following order											*/
51 /*																			*/
52 /*		  compile time constants defining static data size (i.e. arrays)	*/
53 /*		  other constants													*/
54 /*		  macros															*/
55 /*																			*/
56 /****************************************************************************/
57 
58 
59 /* macro for easier definition of DDD_TYPEs */
60 #define ELDEF(type,member)   offsetof(type,member), sizeof(type :: member)
61 
62 /* macro for easy definition of type mapping UG<->DDD */
63 #define MAP_TYPES(ugt,dddt)   { int _ugt=(ugt); \
64                                 ddd_ctrl(context).ugtypes[(dddt)] = _ugt;     \
65                                 ddd_ctrl(context).types[_ugt] = (dddt);       \
66 }
67 
68 
69 /****************************************************************************/
70 /*																			*/
71 /* data structures used in this source file (exported data structures are	*/
72 /*		  in the corresponding include file!)								*/
73 /*																			*/
74 /****************************************************************************/
75 
76 
77 
78 /****************************************************************************/
79 /*																			*/
80 /* definition of exported global variables									*/
81 /*																			*/
82 /****************************************************************************/
83 
84 /* DDD interfaces needed for distributed computation */
85 DDD_IF NS_DIM_PREFIX ElementIF, NS_DIM_PREFIX ElementSymmIF, NS_DIM_PREFIX ElementVIF, NS_DIM_PREFIX ElementSymmVIF,
86 NS_DIM_PREFIX ElementVHIF, NS_DIM_PREFIX ElementSymmVHIF;
87 DDD_IF NS_DIM_PREFIX BorderNodeIF, NS_DIM_PREFIX BorderNodeSymmIF, NS_DIM_PREFIX OuterNodeIF, NS_DIM_PREFIX NodeVIF,
88 NS_DIM_PREFIX NodeIF, NS_DIM_PREFIX NodeAllIF;
89 DDD_IF NS_DIM_PREFIX BorderVectorIF, NS_DIM_PREFIX BorderVectorSymmIF,
90 NS_DIM_PREFIX OuterVectorIF, NS_DIM_PREFIX OuterVectorSymmIF,
91 NS_DIM_PREFIX VectorVIF, NS_DIM_PREFIX VectorVAllIF, NS_DIM_PREFIX VectorIF;
92 /* DDD interfaces for node communication */
93 DDD_IF NS_DIM_PREFIX Node_InteriorBorder_All_IF;
94 /* DDD interfaces for facet (side vector) communication */
95 DDD_IF NS_DIM_PREFIX Facet_InteriorBorder_All_IF;
96 
97 /* DDD interfaces for edge communication */
98 DDD_IF NS_DIM_PREFIX EdgeIF, NS_DIM_PREFIX BorderEdgeSymmIF, NS_DIM_PREFIX EdgeHIF, NS_DIM_PREFIX EdgeVHIF,
99 NS_DIM_PREFIX EdgeSymmVHIF;
100 
101 
102 /****************************************************************************/
103 /*																			*/
104 /* definition of variables global to this source file only (static!)		*/
105 /*																			*/
106 /****************************************************************************/
107 
108 
109 /****************************************************************************/
110 /*																			*/
111 /* forward declarations of functions used before they are defined			*/
112 /*																			*/
113 /****************************************************************************/
114 
115 enum ElemTypeFlag { Inside, Boundary };
116 
117 
118 /****************************************************************************/
119 /*
120    void ddd_InitGenericElement -
121 
122    SYNOPSIS:
123    static void ddd_InitGenericElement (INT tag, DDD_TYPE dddType, int etype);
124 
125    PARAMETERS:
126    .  tag
127    .  dddType
128    .  etype
129 
130    DESCRIPTION:
131 
132    RETURN VALUE:
133    void
134  */
135 /****************************************************************************/
136 
ddd_InitGenericElement(DDD::DDDContext & context,INT tag,DDD_TYPE dddType,int etype)137 static void ddd_InitGenericElement(DDD::DDDContext& context, INT tag, DDD_TYPE dddType, int etype)
138 {
139   auto& dddctrl = ddd_ctrl(context);
140   GENERAL_ELEMENT                 *desc = element_descriptors[tag];
141   UINT gbits = 0;
142 
143   size_t ps  = sizeof(void *);
144   size_t r = offsetof(generic_element,refs);
145 
146   /* compute global fields of control word entry */
147   gbits = ~(((1<<NSONS_LEN)-1)<<NSONS_SHIFT);
148   PRINTDEBUG(dddif,1,("ddd_InitGenericElement(): gbits=%08x size=%d\n",
149                       gbits,sizeof(generic_element::control)));
150 
151   /* initialize base part (valid for all elements) */
152   DDD_TypeDefine(context, dddType,
153                  EL_DDDHDR, offsetof(generic_element,ddd),
154                  /* TODO: delete this					*/
155                  /*		EL_GDATA,  ELDEF(generic_element,control),	*/
156                  EL_GBITS,  ELDEF(generic_element,control), &gbits,
157 
158                  /* TODO: id muss umgerechnet werden! (?) */
159                  EL_GDATA,  ELDEF(generic_element,id),
160                  EL_GDATA,  ELDEF(generic_element,flag),
161                  EL_GDATA,  ELDEF(generic_element,property),
162 
163                  /* LDATA, because Dune indices are local */
164                  EL_LDATA,  ELDEF(generic_element,levelIndex),
165                  EL_LDATA,  ELDEF(generic_element,leafIndex),
166 
167                  EL_GDATA,  ELDEF(generic_element,lb1),
168                  EL_LDATA,  ELDEF(generic_element,pred),
169                  EL_LDATA,  ELDEF(generic_element,succ),
170                  EL_CONTINUE);
171 
172 
173   /* initialize generic part */
174   /* NOTE: references to 'union element' are denoted by the ref-type
175      dddType (i.e., the DDD_TYPE of the currently defined element itself).
176      TODO: this should be replaced by a more explicit TypeGenericElement in
177      later versions (code would be more readable). */
178 
179   DDD_TypeDefine(context, dddType,
180                  EL_OBJPTR, r+n_offset[tag]*sizeof(void*),       ps*desc->corners_of_elem, dddctrl.TypeNode,
181                  EL_OBJPTR, r+father_offset[tag]*sizeof(void*),  ps,                       dddType,
182                  /* TODO: delete
183                     #ifdef __TWODIM__
184                                  EL_LDATA, r+sons_offset[tag]*sizeof(void*),    ps*desc->max_sons_of_elem,
185                     #endif
186                     #ifdef __THREEDIM__
187                                  EL_LDATA, r+sons_offset[tag]*sizeof(void*),    ps*1,
188                     #endif
189                   */
190                  EL_LDATA, r+sons_offset[tag]*sizeof(void*),     ps*2,
191                  EL_OBJPTR, r+nb_offset[tag]*sizeof(void*),      ps*desc->sides_of_elem,   dddType,
192                  EL_CONTINUE);
193 
194 
195   /* optional components */
196 
197   if (ddd_ctrl(context).elemData)
198     DDD_TypeDefine(context, dddType,
199                    EL_OBJPTR, r+evector_offset[tag]*sizeof(void*), ps*1,     dddctrl.TypeVector,
200                    EL_CONTINUE);
201 
202         #ifdef __THREEDIM__
203   if (ddd_ctrl(context).sideData)
204     DDD_TypeDefine(context, dddType,
205                    EL_OBJPTR, r+svector_offset[tag]*sizeof(void*), ps*desc->sides_of_elem, dddctrl.TypeVector,
206                    EL_CONTINUE);
207         #endif
208 
209   if (etype==Inside)
210   {
211     DDD_TypeDefine(context, dddType, EL_END, static_cast<size_t>(desc->inner_size));
212 
213     /* init type mapping arrays */
214     MAP_TYPES(MAPPED_INNER_OBJT_TAG(tag), dddType);
215     ddd_ctrl(context).dddObj[MAPPED_INNER_OBJT_TAG(tag)] = true;
216   }
217   else
218   {
219     DDD_TypeDefine(context, dddType,
220                    EL_LDATA, r+side_offset[tag]*sizeof(void*),  ps*desc->sides_of_elem,
221                    EL_END, static_cast<size_t>(desc->bnd_size));
222 
223     /* init type mapping arrays */
224     MAP_TYPES(MAPPED_BND_OBJT_TAG(tag), dddType);
225     ddd_ctrl(context).dddObj[MAPPED_BND_OBJT_TAG(tag)] = true;
226   }
227 
228   /* set mergemode to maximum */
229   DDD_PrioMergeDefault(context, dddType, PRIOMERGE_MAXIMUM);
230   /* TODO: set prios
231           DDD_PrioMergeDefine(context, dddType, PrioHGhost, PrioVGhost, PrioVHGhost);
232           DDD_PrioMergeDefine(context, dddType, PrioHGhost, PrioVHGhost, PrioVHGhost);
233           DDD_PrioMergeDefine(context, dddType, PrioVGhost, PrioVHGhost, PrioVHGhost);
234           DDD_PrioMergeDefine(context, dddType, PrioHGhost, PrioMaster, PrioMaster);
235           DDD_PrioMergeDefine(context, dddType, PrioVGhost, PrioMaster, PrioMaster);
236           DDD_PrioMergeDefine(context, dddType, PrioVHGhost, PrioMaster, PrioMaster);
237    */
238 
239 }
240 
241 
242 /****************************************************************************/
243 /*																			*/
244 /* Function:  ddd_DeclareTypes												*/
245 /*																			*/
246 /* Purpose:   declare ug data structures as DDD_TYPES						*/
247 /*																			*/
248 /* Input:     void                                                              */
249 /*																			*/
250 /* Output:    void                                                                                                              */
251 /*																			*/
252 /*																			*/
253 /****************************************************************************/
254 
255 
256 /****************************************************************************/
257 /*
258    void ddd_DeclareTypes - declare ug data structures as DDD_TYPES
259 
260    SYNOPSIS:
261    static void ddd_DeclareTypes (void);
262 
263    PARAMETERS:
264    .  void
265 
266    DESCRIPTION:
267    This function declares ug data structures as DDD_TYPES
268 
269    RETURN VALUE:
270    void
271  */
272 /****************************************************************************/
273 
ddd_DeclareTypes(DDD::DDDContext & context)274 static void ddd_DeclareTypes(DDD::DDDContext& context)
275 {
276   /* NOTE: (960410 KB)
277 
278           - handling of Vector and Matrix types may be
279             wrong, types array entries might be used differently
280             by ug (e.g., during allocation/deallocation). TODO ueberpruefen!
281             (beziehung algebra.c <-> ugm.c)
282 
283           - UGTypes for elements will be computed later. therefore the
284             initialization of types[] entries for elements
285             is done (after the UGTypes are known) during ddd_InitGenericElement.
286             TODO remove this clumsy exception! how?
287 
288           - variables TypeXXXX containing the proper DDD_TYPEs may be
289             superfluous. it would be possible to replace all occurences
290             by macros like DDDType(VEOBJ), which would be implemented as
291      #define DDDType(ugtype)  (ddd_ctrl(context).types[ugtype])
292             TODO check this!
293             pros: no double information. currently, TypeXXX may differ
294                   from corresponding ddd_ctrl(context).types[] entry.
295             cons: will this be compatible with alloc/dealloc and TypeDefine
296                   of ug-general-elements?
297    */
298 
299 
300   auto& dddctrl = ddd_ctrl(context);
301 
302   /* 1. DDD objects (with DDD_HEADER) */
303 
304   dddctrl.TypeVector = DDD_TypeDeclare(context, "Vector");
305   MAP_TYPES(VEOBJ, dddctrl.TypeVector);
306   dddctrl.dddObj[VEOBJ] = true;
307 
308   dddctrl.TypeIVertex = DDD_TypeDeclare(context, "IVertex");
309   MAP_TYPES(IVOBJ, dddctrl.TypeIVertex);
310   dddctrl.dddObj[IVOBJ] = true;
311 
312   dddctrl.TypeBVertex = DDD_TypeDeclare(context, "BVertex");
313   MAP_TYPES(BVOBJ, dddctrl.TypeBVertex);
314   dddctrl.dddObj[BVOBJ] = true;
315 
316   dddctrl.TypeNode = DDD_TypeDeclare(context, "Node");
317   MAP_TYPES(NDOBJ, dddctrl.TypeNode);
318   dddctrl.dddObj[NDOBJ] = true;
319 
320         #ifdef __TWODIM__
321   dddctrl.TypeTrElem  = DDD_TypeDeclare(context, "TrElem");
322   dddctrl.TypeTrBElem = DDD_TypeDeclare(context, "TrBElem");
323   dddctrl.TypeQuElem  = DDD_TypeDeclare(context, "QuElem");
324   dddctrl.TypeQuBElem = DDD_TypeDeclare(context, "QuBElem");
325         #endif /* TWODIM */
326 
327         #ifdef __THREEDIM__
328   dddctrl.TypeTeElem  = DDD_TypeDeclare(context, "TeElem");
329   dddctrl.TypeTeBElem = DDD_TypeDeclare(context, "TeBElem");
330   dddctrl.TypePyElem  = DDD_TypeDeclare(context, "PyElem");
331   dddctrl.TypePyBElem = DDD_TypeDeclare(context, "PyBElem");
332   dddctrl.TypePrElem  = DDD_TypeDeclare(context, "PrElem");
333   dddctrl.TypePrBElem = DDD_TypeDeclare(context, "PrBElem");
334   dddctrl.TypeHeElem  = DDD_TypeDeclare(context, "HeElem");
335   dddctrl.TypeHeBElem = DDD_TypeDeclare(context, "HeBElem");
336         #endif /* THREEDIM */
337 
338   /* edge type not unique:                    */
339   /* edge is DDD object for 2D and 3D         */
340   /* edge is DDD data object for 2D           */
341   dddctrl.TypeEdge = DDD_TypeDeclare(context, "Edge");
342   MAP_TYPES(EDOBJ, dddctrl.TypeEdge);
343   dddctrl.dddObj[EDOBJ] = true;
344 
345   /* 2. DDD data objects (without DDD_HEADER) */
346 
347   dddctrl.TypeMatrix = DDD_TypeDeclare(context, "Matrix");
348   MAP_TYPES(MAOBJ, dddctrl.TypeMatrix);
349 
350   dddctrl.TypeBndP = DDD_TypeDeclare(context, "BndP");
351   static const INT objtBndP = GetFreeOBJT();
352   MAP_TYPES(objtBndP, dddctrl.TypeBndP);
353 
354   dddctrl.TypeBndS = DDD_TypeDeclare(context, "BndS");
355   static const INT objtBndS = GetFreeOBJT();
356   MAP_TYPES(objtBndS, dddctrl.TypeBndS);
357 }
358 
359 
360 /****************************************************************************/
361 /*
362    ddd_DefineTypes - define previously declared DDD_TYPES
363 
364    SYNOPSIS:
365    static void ddd_DefineTypes (void);
366 
367    PARAMETERS:
368    .  void
369 
370    DESCRIPTION:
371    This function defines previously declared DDD_TYPES
372    Note: this function depends on previous definition of all necessary ug-generic-elements.
373 
374    RETURN VALUE:
375    void
376  */
377 /****************************************************************************/
378 
ddd_DefineTypes(DDD::DDDContext & context)379 static void ddd_DefineTypes(DDD::DDDContext& context)
380 {
381   auto& dddctrl = ddd_ctrl(context);
382   INT size;
383   UINT gbits = 0;
384 
385   /* 1. DDD objects (with DDD_HEADER) */
386 
387   /*
388    * A side vector's `VECTORSIDE` depends on which of the `objects` is used
389    * as a representative. To ensure consistency, both are handled in the same
390    * place (`ElementObjMkCons`).
391    */
392   gbits = ~(((1 << VECTORSIDE_LEN)-1) << VECTORSIDE_SHIFT);
393   DDD_TypeDefine(context, dddctrl.TypeVector,
394                  EL_DDDHDR, offsetof(VECTOR,ddd),
395                  EL_GBITS,  ELDEF(VECTOR,control), &gbits,
396 
397                  /* object must be LDATA, because reftype may be a non-DDD-object */
398                  /* (e.g., edge). therefore, 'object' must be updated by MKCONS-  */
399                  /* handler of associated object. 960404 KB */
400                  /* TODO: decide whether LDATA or OBJPTR for different VectorTypes*/
401                  /* EL_OBJPTR, ELDEF(VECTOR,object), TypeNode, */
402                  EL_LDATA,  ELDEF(VECTOR,object),
403                  EL_LDATA,  ELDEF(VECTOR,pred),
404                  EL_LDATA,  ELDEF(VECTOR,succ),
405                  EL_GDATA,  ELDEF(VECTOR,index),
406                  EL_GDATA,  ELDEF(VECTOR,leafIndex),
407                  EL_LDATA,  ELDEF(VECTOR,start),
408 
409                  /* TODO: value wird noch ausgelassen. feld variabler laenge? */
410                  /* bei entscheidung 'value': kein weiteres feld
411                          bei ent. 'userdata *': EL_GDATA-feld        */
412                  EL_GDATA,  ELDEF(VECTOR,value),
413                  EL_END,    sizeof(VECTOR)
414                  );
415 
416   /* set mergemode to maximum */
417   DDD_PrioMergeDefault(context, dddctrl.TypeVector, PRIOMERGE_MAXIMUM);
418 
419   /* compute global fields it control word entry */
420   gbits = ~((((1<<ONEDGE_LEN)-1)<<ONEDGE_SHIFT) |
421             (((1<<NOOFNODE_LEN)-1)<<NOOFNODE_SHIFT));
422   PRINTDEBUG(dddif,1,("ddd_DefineTypes(): TypeI/BVertex gbits=%08x size=%d\n",
423                       gbits,sizeof(ivertex::control)));
424 
425   DDD_TypeDefine(context, dddctrl.TypeIVertex,
426                  EL_DDDHDR, offsetof(ivertex,ddd),
427                  /* TODO: delete
428                                  EL_GDATA,  ELDEF(ivertex,control),
429                   */
430                  EL_GBITS,  ELDEF(ivertex,control), &gbits,
431 
432                  /* TODO: muss umgerechnet werden! */
433                  EL_GDATA,  ELDEF(ivertex,id),
434                  EL_GDATA,  ELDEF(ivertex,x),
435                  EL_GDATA,  ELDEF(ivertex,xi),
436                  EL_LDATA,  ELDEF(ivertex,leafIndex),
437                  EL_LDATA,  ELDEF(ivertex,pred),
438                  EL_LDATA,  ELDEF(ivertex,succ),
439                  EL_LDATA,  ELDEF(ivertex,data),
440 
441                  /* TODO muss father LDATA oder OBJPTR sein?     */
442                  /* LDATA, father ist nur lokal gueltig und      */
443                  /* ist abhaengig von vertikaler Lastverteilung  */
444                 #ifdef __TWODIM__
445                  /* TODO: ref-typ muss eigentlich {TypeTrElem,TypeTrBElem} sein! */
446                  EL_OBJPTR, ELDEF(ivertex,father), dddctrl.TypeTrElem,
447                 #endif
448                 #ifdef __THREEDIM__
449                  EL_LDATA,  ELDEF(ivertex,father),
450                 #endif
451 
452                 #ifdef TOPNODE
453                  /* TODO topnode wirklich OBJPTR? */
454                  EL_LDATA,  ELDEF(ivertex,topnode),
455                 #endif
456                  EL_END,    sizeof(ivertex)
457                  );
458 
459   /* set mergemode to maximum */
460   DDD_PrioMergeDefault(context, dddctrl.TypeIVertex, PRIOMERGE_MAXIMUM);
461 
462 
463   DDD_TypeDefine(context, dddctrl.TypeBVertex,
464                  EL_DDDHDR, offsetof(bvertex,ddd),
465                  /* TODO: delete
466                                  EL_GDATA,  ELDEF(bvertex,control),
467                   */
468                  EL_GBITS,  ELDEF(bvertex,control), &gbits,
469 
470                  /* TODO: muss umgerechnet werden! Nooeee! */
471                  EL_GDATA,  ELDEF(bvertex,id),
472                  EL_GDATA,  ELDEF(bvertex,x),
473                  EL_GDATA,  ELDEF(bvertex,xi),
474                  EL_LDATA,  ELDEF(bvertex,leafIndex),
475                  EL_LDATA,  ELDEF(bvertex,pred),
476                  EL_LDATA,  ELDEF(bvertex,succ),
477                  EL_LDATA,  ELDEF(bvertex,data),
478 
479                  /* TODO muss father LDATA oder OBJPTR sein?     */
480                  /* LDATA, father ist nur lokal gueltig und      */
481                  /* ist abhaengig von vertikaler Lastverteilung  */
482                 #ifdef __TWODIM__
483                  /* TODO: ref-typ muss eigentlich {TypeTrElem,TypeTrBElem} sein! */
484                  EL_OBJPTR, ELDEF(bvertex,father), dddctrl.TypeTrElem,
485                 #endif
486                 #ifdef __THREEDIM__
487                  EL_LDATA,  ELDEF(bvertex,father),
488                 #endif
489 
490                 #ifdef TOPNODE
491                  /* TODO topnode wirklich OBJPTR?, Nooeee! */
492                  EL_LDATA,  ELDEF(bvertex,topnode),
493                 #endif
494                  EL_LDATA,  ELDEF(bvertex,bndp),     /* different from IVertex */
495                  EL_END,    sizeof(bvertex)
496                  );
497 
498   /* set mergemode to maximum */
499   DDD_PrioMergeDefault(context, dddctrl.TypeBVertex, PRIOMERGE_MAXIMUM);
500 
501 
502   DDD_TypeDefine(context, dddctrl.TypeNode,
503                  EL_DDDHDR, offsetof(NODE,ddd),
504                  EL_GDATA,  ELDEF(NODE,control),
505 
506                  /* TODO: muss umgerechnet werden! */
507                  EL_GDATA,  ELDEF(NODE,id),
508                  EL_LDATA,  ELDEF(NODE,levelIndex),
509                  EL_GDATA,  ELDEF(NODE,isLeaf),
510                  EL_LDATA,  ELDEF(NODE,pred),
511                  EL_LDATA,  ELDEF(NODE,succ),
512 
513                  /* TODO was ist start? */
514                  EL_LDATA,  ELDEF(NODE,start),
515 
516                  /* father may be one of node or edge */
517                  EL_OBJPTR, ELDEF(NODE,father),   DDD_TYPE_BY_HANDLER, NFatherObjType,
518 
519                  EL_OBJPTR, ELDEF(NODE,son),      dddctrl.TypeNode,
520 
521                  /* TODO: ref-typ muss eigentlich {TypeIVertex,TypeBVertex} sein! */
522                  EL_OBJPTR, ELDEF(NODE,myvertex), dddctrl.TypeIVertex,
523                  EL_CONTINUE);
524 
525   if (ddd_ctrl(context).nodeData)
526     DDD_TypeDefine(context, dddctrl.TypeNode,
527                    EL_OBJPTR, ELDEF(NODE,vector), dddctrl.TypeVector,
528                    EL_CONTINUE);
529 
530   /* The size of a NODE object may be less than sizeof(NODE).
531    * Indeed, if the format does not contain node data, then the corresponding VECTOR*
532    * data member that stores this data is removed from the NODE object.  Hence the
533    * size of the NODE decreases by the size of one VECTOR*.
534    * Compare the corresponding computation in the method CreateNode (in ugm.c)
535    */
536   size = sizeof(NODE) - (dddctrl.nodeData ? 0 : sizeof(VECTOR*));
537   DDD_TypeDefine(context, dddctrl.TypeNode,
538                  EL_END, size);
539 
540   /* set mergemode to maximum */
541   DDD_PrioMergeDefault(context, dddctrl.TypeNode, PRIOMERGE_MAXIMUM);
542 
543 
544         #ifdef __TWODIM__
545   ddd_InitGenericElement(context, TRIANGLE,      dddctrl.TypeTrElem,  Inside);
546   ddd_InitGenericElement(context, TRIANGLE,      dddctrl.TypeTrBElem, Boundary);
547   ddd_InitGenericElement(context, QUADRILATERAL, dddctrl.TypeQuElem,  Inside);
548   ddd_InitGenericElement(context, QUADRILATERAL, dddctrl.TypeQuBElem, Boundary);
549         #endif /* TWODIM */
550 
551         #ifdef __THREEDIM__
552   ddd_InitGenericElement(context, TETRAHEDRON, dddctrl.TypeTeElem,  Inside);
553   ddd_InitGenericElement(context, TETRAHEDRON, dddctrl.TypeTeBElem, Boundary);
554   ddd_InitGenericElement(context, PYRAMID,     dddctrl.TypePyElem,  Inside);
555   ddd_InitGenericElement(context, PYRAMID,     dddctrl.TypePyBElem, Boundary);
556   ddd_InitGenericElement(context, PRISM,       dddctrl.TypePrElem,  Inside);
557   ddd_InitGenericElement(context, PRISM,       dddctrl.TypePrBElem, Boundary);
558   ddd_InitGenericElement(context, HEXAHEDRON,  dddctrl.TypeHeElem,  Inside);
559   ddd_InitGenericElement(context, HEXAHEDRON,  dddctrl.TypeHeBElem, Boundary);
560         #endif /* THREEDIM */
561 
562   /* 2. DDD data objects (without DDD_HEADER) */
563 
564   /* NOTE: the size of matrix objects computed by the DDD Typemanager
565      will not be the real size ued by DDD. this size has to be computed
566      by UG_MSIZE(mat). this is relevant only in gather/scatter of matrices
567      in handler.c. */
568   DDD_TypeDefine(context, dddctrl.TypeMatrix,
569                  EL_GDATA,  ELDEF(MATRIX,control),
570                  EL_LDATA,  ELDEF(MATRIX,next),
571                  EL_OBJPTR, ELDEF(MATRIX,vect),   dddctrl.TypeVector,
572                  /* TODO: not needed
573                     EL_LDATA,  ELDEF(MATRIX,value), */
574                  EL_END,    sizeof(MATRIX)
575                  );
576 
577   /* compute global fields it control word entry */
578   gbits = ~(((1<<NO_OF_ELEM_LEN)-1)<<NO_OF_ELEM_SHIFT);
579   PRINTDEBUG(dddif,1,("ddd_DefineTypes(): TypeEdge gbits=%08x size=%d\n",
580                       gbits,sizeof(link::control)));
581 
582   DDD_TypeDefine(context, dddctrl.TypeEdge,
583                  /* link 0 data */
584                  /*TODO: now unique
585                     #ifdef __TWODIM__
586                                  EL_GDATA,  ELDEF(EDGE,links[0].control),
587                     #endif
588                     #ifdef __THREEDIM__
589                                  EL_LDATA,  ELDEF(EDGE,links[0].control),
590                     #endif
591                   */
592                  EL_GBITS,  ELDEF(EDGE,links[0].control), &gbits,
593                  EL_LDATA,  ELDEF(EDGE,links[0].next),
594                  EL_OBJPTR, ELDEF(EDGE,links[0].nbnode), dddctrl.TypeNode,
595 
596                  /* link 1 data */
597                  EL_GDATA,  ELDEF(EDGE,links[1].control),
598                  EL_LDATA,  ELDEF(EDGE,links[1].next),
599                  EL_OBJPTR, ELDEF(EDGE,links[1].nbnode), dddctrl.TypeNode,
600 
601                  EL_LDATA,  ELDEF(EDGE,levelIndex),
602                  EL_LDATA,  ELDEF(EDGE,leafIndex),
603                  EL_GDATA,  ELDEF(EDGE,id),
604                  EL_DDDHDR, offsetof(EDGE,ddd),
605 
606                  EL_OBJPTR, ELDEF(EDGE,midnode),  dddctrl.TypeNode,
607                  EL_CONTINUE);
608 
609   if (dddctrl.edgeData)
610     DDD_TypeDefine(context, dddctrl.TypeEdge,
611                    EL_OBJPTR, ELDEF(EDGE,vector), dddctrl.TypeVector,
612                    EL_CONTINUE);
613 
614   /* See the corresponding line for TypeNode for an explanation of why
615    * the object size is modified here. */
616   size = sizeof(EDGE) - ((ddd_ctrl(context).edgeData) ? 0 : sizeof(VECTOR*));
617   DDD_TypeDefine(context, dddctrl.TypeEdge, EL_END, size);
618 
619   /* set mergemode to maximum */
620   DDD_PrioMergeDefault(context, dddctrl.TypeEdge, PRIOMERGE_MAXIMUM);
621 
622 }
623 
624 
625 /****************************************************************************/
626 /*
627    ddd_IfInit - define the communication interfaces needed in ug for management by DDD
628 
629    SYNOPSIS:
630    static void ddd_IfInit(DDD::DDDContext& context);
631 
632    PARAMETERS:
633    .  context
634 
635    DESCRIPTION:
636    This function defines the communication interfaces needed in ug for management by DDD
637 
638    RETURN VALUE:
639    void
640 
641    \note Not all of these interfaces are actually needed by Dune.
642      Those can be removed.
643  */
644 /****************************************************************************/
645 
ddd_IfInit(DDD::DDDContext & context)646 static void ddd_IfInit(DDD::DDDContext& context)
647 {
648   auto& dddctrl = ddd_ctrl(context);
649 
650   DDD_TYPE O[8];
651   int nO;
652   DDD_PRIO A[8];
653   DDD_PRIO B[8];
654 
655 
656   /* define element interfaces */
657 #ifdef __TWODIM__
658   O[0] = dddctrl.TypeTrElem; O[1] = dddctrl.TypeTrBElem;
659   O[2] = dddctrl.TypeQuElem; O[3] = dddctrl.TypeQuBElem;
660   nO = 4;
661 #endif
662 
663 #ifdef __THREEDIM__
664   O[0] = dddctrl.TypeTeElem; O[1] = dddctrl.TypeTeBElem;
665   O[2] = dddctrl.TypePyElem; O[3] = dddctrl.TypePyBElem;
666   O[4] = dddctrl.TypePrElem; O[5] = dddctrl.TypePrBElem;
667   O[6] = dddctrl.TypeHeElem; O[7] = dddctrl.TypeHeBElem;
668   nO = 8;
669 #endif
670 
671   A[0] = PrioMaster;
672   B[0] = PrioHGhost; B[1] = PrioVHGhost;
673   dddctrl.ElementIF = DDD_IFDefine(context, nO,O,1,A,2,B);
674   DDD_IFSetName(context, dddctrl.ElementIF, "ElementIF: Master->HGhost/VHGhost");
675 
676   A[0] = PrioMaster; A[1] = PrioHGhost; A[2] = PrioVHGhost;
677   B[0] = PrioMaster; B[1] = PrioHGhost; B[2] = PrioVHGhost;
678   dddctrl.ElementSymmIF = DDD_IFDefine(context, nO,O,3,A,3,B);
679   DDD_IFSetName(context, dddctrl.ElementSymmIF, "ElementSymmIF: Master/HGhost/VHGhost");
680 
681   A[0] = PrioMaster;
682   B[0] = PrioVGhost; B[1] = PrioVHGhost;
683   dddctrl.ElementVIF = DDD_IFDefine(context, nO,O,1,A,2,B);
684   DDD_IFSetName(context, dddctrl.ElementVIF, "ElementVIF: Master->VGhost/VHGhost");
685 
686   A[0] = PrioMaster; A[1] = PrioVGhost; A[2] = PrioVHGhost;
687   B[0] = PrioMaster; B[1] = PrioVGhost; B[2] = PrioVHGhost;
688   dddctrl.ElementSymmVIF = DDD_IFDefine(context, nO,O,3,A,3,B);
689   DDD_IFSetName(context, dddctrl.ElementSymmVIF, "ElementSymmVIF: Master/VGhost/VHGhost");
690 
691   A[0] = PrioMaster;
692   B[0] = PrioVGhost; B[1] = PrioHGhost; B[2] = PrioVHGhost;
693   dddctrl.ElementVHIF = DDD_IFDefine(context, nO,O,1,A,3,B);
694   DDD_IFSetName(context, dddctrl.ElementVHIF, "ElementVHIF: Master->VGhost/HGhost/VHGhost");
695 
696   A[0] = PrioMaster; A[1] = PrioVGhost; A[2] = PrioHGhost; A[3] = PrioVHGhost;
697   B[0] = PrioMaster; B[1] = PrioVGhost; B[2] = PrioHGhost; B[3] = PrioVHGhost;
698   dddctrl.ElementSymmVHIF = DDD_IFDefine(context, nO,O,4,A,4,B);
699   DDD_IFSetName(context, dddctrl.ElementSymmVHIF, "ElementSymmVHIF: Master/VGhost/HGhost/VHGhost");
700 
701 
702   /* define node interfaces */
703   O[0] = dddctrl.TypeNode;
704 
705   A[0] = PrioBorder;
706   B[0] = PrioMaster;
707   dddctrl.BorderNodeIF = DDD_IFDefine(context, 1,O,1,A,1,B);
708   DDD_IFSetName(context, dddctrl.BorderNodeIF, "BorderNodeIF: Border->Master");
709 
710   A[0] = PrioMaster; A[1] = PrioBorder;
711   B[0] = PrioMaster; B[1] = PrioBorder;
712   dddctrl.BorderNodeSymmIF = DDD_IFDefine(context, 1,O,2,A,2,B);
713   DDD_IFSetName(context, dddctrl.BorderNodeSymmIF, "BorderNodeSymmIF: Border/Master");
714 
715   A[0] = PrioMaster;
716   B[0] = PrioHGhost; B[1] = PrioVHGhost;
717   dddctrl.OuterNodeIF = DDD_IFDefine(context, 1,O,1,A,2,B);
718   DDD_IFSetName(context, dddctrl.OuterNodeIF, "OuterNodeIF: Master->HGhost/VGhost");
719 
720   A[0] = PrioMaster;
721   B[0] = PrioVGhost; B[1] = PrioVHGhost;
722   dddctrl.NodeVIF = DDD_IFDefine(context, 1,O,1,A,2,B);
723   DDD_IFSetName(context, dddctrl.NodeVIF, "NodeVIF: Master->VGhost/VHGhost");
724 
725   A[0] = PrioMaster;
726   B[0] = PrioVGhost; B[1] = PrioHGhost; B[2] = PrioVHGhost;
727   dddctrl.NodeIF = DDD_IFDefine(context, 1,O,1,A,3,B);
728   DDD_IFSetName(context, dddctrl.NodeIF, "NodeIF: Master->VGhost/HGhost/VHGhost");
729 
730   A[0] = PrioMaster; A[1] = PrioBorder; A[2] = PrioVGhost; A[3] = PrioHGhost; A[4] = PrioVHGhost;
731   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioVGhost; B[3] = PrioHGhost; B[4] = PrioVHGhost;
732   dddctrl.NodeAllIF = DDD_IFDefine(context, 1,O,5,A,5,B);
733   DDD_IFSetName(context, dddctrl.NodeAllIF, "NodeAllIF: All/All");
734 
735   // The Dune InteriorBorder_All_Interface for nodes
736   A[0] = PrioMaster; A[1] = PrioBorder;
737   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioVGhost; B[3] = PrioHGhost; B[4] = PrioVHGhost;
738   dddctrl.Node_InteriorBorder_All_IF = DDD_IFDefine(context, 1,O,2,A,5,B);
739   DDD_IFSetName(context, dddctrl.Node_InteriorBorder_All_IF, "Node_InteriorBorder_All_IF: Master/Border->Master/Border/VGhost/HGhost/VHGhost");
740 
741   /* define vector interfaces */
742   O[0] = dddctrl.TypeVector;
743 
744   A[0] = PrioBorder;
745   B[0] = PrioMaster;
746   dddctrl.BorderVectorIF = DDD_IFDefine(context, 1,O,1,A,1,B);
747   DDD_IFSetName(context, dddctrl.BorderVectorIF, "BorderVectorIF: Border->Master");
748 
749   A[0] = PrioMaster; A[1] = PrioBorder;
750   B[0] = PrioMaster; B[1] = PrioBorder;
751   dddctrl.BorderVectorSymmIF = DDD_IFDefine(context, 1,O,2,A,2,B);
752   DDD_IFSetName(context, dddctrl.BorderVectorSymmIF, "BorderVectorSymmIF: Master/Border");
753 
754   A[0] = PrioMaster;
755   B[0] = PrioHGhost; B[1] = PrioVHGhost;
756   dddctrl.OuterVectorIF = DDD_IFDefine(context, 1,O,1,A,2,B);
757   DDD_IFSetName(context, dddctrl.OuterVectorIF, "OuterVectorIF: Master->HGhost/VHGhost");
758 
759   A[0] = PrioMaster; A[1] = PrioBorder; A[2] = PrioHGhost; A[3] = PrioVHGhost;
760   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioHGhost; B[3] = PrioVHGhost;
761   dddctrl.OuterVectorSymmIF = DDD_IFDefine(context, 1,O,4,A,4,B);
762   DDD_IFSetName(context, dddctrl.OuterVectorSymmIF, "OuterVectorSymmIF: Master/Border/HGhost/VHGhost");
763 
764   A[0] = PrioMaster;
765   B[0] = PrioVGhost; B[1] = PrioVHGhost;
766   dddctrl.VectorVIF = DDD_IFDefine(context, 1,O,1,A,2,B);
767   DDD_IFSetName(context, dddctrl.VectorVIF, "VectorVIF: Master->VGhost/VHGhost");
768 
769   A[0] = PrioMaster; A[1] = PrioBorder; A[2] = PrioVGhost; A[3] = PrioVHGhost;
770   B[0] = PrioMaster; B[1] = PrioBorder;
771   dddctrl.VectorVAllIF = DDD_IFDefine(context, 1,O,4,A,2,B);
772   DDD_IFSetName(context, dddctrl.VectorVAllIF, "VectorVAllIF: Master/Border/VGhost/VHGhost->Master/Border");
773 
774   A[0] = PrioMaster;
775   B[0] = PrioVGhost; B[1] = PrioVHGhost; B[2] = PrioHGhost;
776   dddctrl.VectorIF = DDD_IFDefine(context, 1,O,1,A,3,B);
777   DDD_IFSetName(context, dddctrl.VectorIF, "VectorIF: Master->VGhost/VHGhost/HGhost");
778 
779   // The Dune InteriorBorder_All_Interface for facets
780   A[0] = PrioMaster; A[1] = PrioBorder;
781   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioVGhost; B[3] = PrioHGhost; B[4] = PrioVHGhost;
782   dddctrl.Facet_InteriorBorder_All_IF = DDD_IFDefine(context, 1,O,2,A,5,B);
783   DDD_IFSetName(context, dddctrl.Facet_InteriorBorder_All_IF, "Facet_InteriorBorder_All_IF: Master/Border->Master/Border/VGhost/HGhost/VHGhost");
784 
785   // The Dune All_All_Interface for facets
786   A[0] = PrioMaster; A[1] = PrioBorder; A[2] = PrioVGhost; A[3] = PrioHGhost; A[4] = PrioVHGhost;
787   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioVGhost; B[3] = PrioHGhost; B[4] = PrioVHGhost;
788   dddctrl.Facet_All_All_IF = DDD_IFDefine(context, 1,O,5,A,5,B);
789   DDD_IFSetName(context, dddctrl.Facet_All_All_IF, "Facet_All_All_IF: Master/Border/VGhost/HGhost/VHGhost->Master/Border/VGhost/HGhost/VHGhost");
790 
791   /* define vertex interfaces */
792   O[0] = dddctrl.TypeIVertex; O[1] = dddctrl.TypeBVertex;
793 
794   A[0] = PrioMaster;
795   B[0] = PrioMaster;
796   dddctrl.VertexIF = DDD_IFDefine(context, 2,O,1,A,1,B);
797   DDD_IFSetName(context, dddctrl.VertexIF, "VertexIF: Master<->Master");
798 
799 
800   /* define edge interfaces */
801   O[0] = dddctrl.TypeEdge;
802 
803   A[0] = PrioMaster;
804   B[0] = PrioMaster;
805   dddctrl.EdgeIF = DDD_IFDefine(context, 1,O,1,A,1,B);
806   DDD_IFSetName(context, dddctrl.EdgeIF, "EdgeIF: Master<->Master");
807 
808   A[0] = PrioMaster; A[1] = PrioBorder;
809   B[0] = PrioMaster; B[1] = PrioBorder;
810   dddctrl.BorderEdgeSymmIF = DDD_IFDefine(context, 1,O,2,A,2,B);
811   DDD_IFSetName(context, dddctrl.BorderEdgeSymmIF, "BorderEdgeSymmIF: Master/Border");
812 
813   A[0] = PrioMaster; A[1] = PrioBorder;
814   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioHGhost; B[3] = PrioVHGhost;
815   dddctrl.EdgeHIF = DDD_IFDefine(context, 1,O,2,A,4,B);
816   DDD_IFSetName(context, dddctrl.EdgeHIF, "EdgeHIF: Master/Border->Master/Border/PrioHGhost/PrioVHGhost");
817 
818   A[0] = PrioMaster; A[1] = PrioBorder;
819   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioVGhost; B[3] = PrioHGhost; B[4] = PrioVHGhost;
820   dddctrl.EdgeVHIF = DDD_IFDefine(context, 1,O,2,A,5,B);
821   DDD_IFSetName(context, dddctrl.EdgeVHIF, "EdgeVHIF: Master/Border->Master/Border/VGhost/HGhost/VHGhost");
822 
823   A[0] = PrioMaster; A[1] = PrioBorder; A[2] = PrioVGhost; A[3] = PrioHGhost; A[4] = PrioVHGhost;
824   B[0] = PrioMaster; B[1] = PrioBorder; B[2] = PrioVGhost; B[3] = PrioHGhost; B[4] = PrioVHGhost;
825   dddctrl.EdgeSymmVHIF = DDD_IFDefine(context, 1,O,5,A,5,B);
826   DDD_IFSetName(context, dddctrl.EdgeSymmVHIF, "EdgeSymmVHIF: Master/Border/VGhost/HGhost/VHGhost");
827 
828 }
829 
830 
831 /****************************************************************************/
832 /*
833    InitDDDTypes - define DDD_TYPEs
834 
835    SYNOPSIS:
836    static void InitDDDTypes (DDD::DDDContext& context);
837 
838    PARAMETERS:
839    .  context
840 
841    DESCRIPTION:
842    This function must be called once before creation of DDD-objects. It depends on correct and complete initialization of all ug-generic-elements, therefore it must be called after completion of InitElementTypes(). As InitElementTypes() will be called whenever new Multigrids are created/opened, an execution guard prevents this function from multiple execution.
843 
844    RETURN VALUE:
845    void
846  */
847 /****************************************************************************/
848 
InitDDDTypes(DDD::DDDContext & context)849 static void InitDDDTypes(DDD::DDDContext& context)
850 {
851   auto& dddctrl = ddd_ctrl(context);
852 
853   /* prevent from multiple execution */
854   if (dddctrl.allTypesDefined)
855     return;
856   dddctrl.allTypesDefined = true;
857 
858   ddd_DefineTypes(context);
859 
860 
861   /* display ddd types */
862   IFDEBUG(dddif,1)
863   DDD_TypeDisplay(context, dddctrl.TypeVector);
864   DDD_TypeDisplay(context, dddctrl.TypeIVertex);
865   DDD_TypeDisplay(context, dddctrl.TypeBVertex);
866   DDD_TypeDisplay(context, dddctrl.TypeNode);
867   DDD_TypeDisplay(context, dddctrl.TypeEdge);
868 
869         #ifdef __TWODIM__
870   DDD_TypeDisplay(context, dddctrl.TypeTrElem);
871   DDD_TypeDisplay(context, dddctrl.TypeTrBElem);
872   DDD_TypeDisplay(context, dddctrl.TypeQuElem);
873   DDD_TypeDisplay(context, dddctrl.TypeQuBElem);
874         #endif
875 
876         #ifdef __THREEDIM__
877   DDD_TypeDisplay(context, dddctrl.TypeTeElem);
878   DDD_TypeDisplay(context, dddctrl.TypeTeBElem);
879   DDD_TypeDisplay(context, dddctrl.TypePyElem);
880   DDD_TypeDisplay(context, dddctrl.TypePyBElem);
881   DDD_TypeDisplay(context, dddctrl.TypePrElem);
882   DDD_TypeDisplay(context, dddctrl.TypePrBElem);
883   DDD_TypeDisplay(context, dddctrl.TypeHeElem);
884   DDD_TypeDisplay(context, dddctrl.TypeHeBElem);
885         #endif
886 
887   /* display dependent types */
888   DDD_TypeDisplay(context, dddctrl.TypeMatrix);
889         #ifdef __TWODIM__
890   DDD_TypeDisplay(context, dddctrl.TypeEdge);
891         #endif
892   ENDDEBUG
893 
894   ddd_HandlerInit(context, HSET_XFER);
895 }
896 
897 
898 
899 /****************************************************************************/
900 /*
901    InitCurrMG - initialize the current multigrid which is handled by DDD
902 
903    SYNOPSIS:
904    void InitCurrMG (MULTIGRID *MG);
905 
906    PARAMETERS:
907    .  MG
908 
909    DESCRIPTION:
910    This function initializes the current multigrid which is handled by DDD
911 
912    RETURN VALUE:
913    void
914  */
915 /****************************************************************************/
916 
917 
InitCurrMG(MULTIGRID * MG)918 void NS_DIM_PREFIX InitCurrMG (MULTIGRID *MG)
919 {
920   auto& dddctrl = ddd_ctrl(MG->dddContext());
921   dddctrl.currMG = MG;
922 
923   dddctrl.nodeData = VEC_DEF_IN_OBJ_OF_MG(dddctrl.currMG,NODEVEC);
924   dddctrl.edgeData = VEC_DEF_IN_OBJ_OF_MG(dddctrl.currMG,EDGEVEC);
925   dddctrl.elemData = VEC_DEF_IN_OBJ_OF_MG(dddctrl.currMG,ELEMVEC);
926   dddctrl.sideData = VEC_DEF_IN_OBJ_OF_MG(dddctrl.currMG,SIDEVEC);
927 
928   if (dddctrl.currFormat == NULL)
929   {
930     /* InitCurrMG was called for the first time, init
931        DDD-types now. */
932     InitDDDTypes(MG->dddContext());
933     dddctrl.currFormat = MG->theFormat.get();
934   }
935   else
936   {
937     /* InitCurrMG has been called before. This is not allowed,
938        cf. comment in ugm.c(DisposeMultiGrid()). */
939     PrintErrorMessage('E',"InitCurrMG",
940                       "opening more than one MG is not allowed in parallel");
941     ASSERT(0); exit(1);
942   }
943 }
944 
945 
946 /****************************************************************************/
947 /*
948    CheckInitParallel - check for correct initialization of dddif subsystem
949 
950    SYNOPSIS:
951    static int CheckInitParallel (void);
952 
953    PARAMETERS:
954    .  void
955 
956    DESCRIPTION:
957    This function performs checks for correct initialization of dddif subsystem
958 
959    RETURN VALUE:
960    int
961      error value
962  */
963 /****************************************************************************/
964 
965 
CheckInitParallel(const DDD::DDDContext & context)966 static int CheckInitParallel(const DDD::DDDContext& context)
967 {
968   int i;
969 
970   /* check for valid UGTYPE for given DDD_TYPE */
971   if (OBJT_MAX == MAXOBJECTS)
972   {
973     printf("ERROR in InitParallel: OBJT_MAX!=MAXOBJECTS\n");
974     return(__LINE__);
975   }
976 
977   for(i=1; i<MAXDDDTYPES && UGTYPE(context, i)>=0; i++)
978   {
979     /* check for valid UGTYPE for given DDD_TYPE */
980     if (UGTYPE(context, i) > OBJT_MAX)
981     {
982       printf("ERROR in InitParallel: OBJT=%d > OBJT_MAX=%d\n",
983              UGTYPE(context, i), OBJT_MAX);
984       return(__LINE__);
985     }
986 
987     /* check for correct mapping and re-mapping */
988     if (DDDTYPE(context, UGTYPE(context, i))!=i)
989     {
990       printf("ERROR in InitParallel: invalid type mapping for OBJT=%d\n",
991              UGTYPE(context, i));
992       return(__LINE__);
993     }
994   }
995 
996   /* no errors */
997   return(0);
998 }
999 
1000 
1001 
1002 /****************************************************************************/
1003 /*
1004    InitDDD - initialize the ddd library
1005 
1006    SYNOPSIS:
1007    int InitDDD (int *argc, char ***argv);
1008 
1009    PARAMETERS:
1010    .  argc - pointer to number of arguments
1011    .  argv - pointer to list of argument pointers
1012 
1013    DESCRIPTION:
1014    This function initializes the ddd library by defining the ug internal issues: format of handled structs, description of handlers, definition of interfaces
1015 
1016    RETURN VALUE:
1017    int
1018  */
1019 /****************************************************************************/
1020 
InitDDD(DDD::DDDContext & context)1021 int NS_DIM_PREFIX InitDDD(DDD::DDDContext& context)
1022 {
1023   auto& dddctrl = ddd_ctrl(context);
1024 
1025   INT err;
1026   int i;
1027 
1028   /* init DDD and set options */
1029   DDD_Init(context);
1030 
1031   /* we are using varsized DDD objects, turn warnings off */
1032   DDD_SetOption(context, OPT_WARNING_VARSIZE_OBJ, OPT_OFF);
1033   DDD_SetOption(context, OPT_WARNING_SMALLSIZE, OPT_OFF);
1034 
1035   /* no internal free list */
1036   DDD_SetOption(context, OPT_CPLMGR_USE_FREELIST, OPT_OFF);
1037 
1038   /* show messages during transfer, for debugging */
1039   DDD_SetOption(context, OPT_DEBUG_XFERMESGS, OPT_OFF);
1040 
1041   /* TODO: remove this, reference collision with Edge orientation
1042      in 3D */
1043   DDD_SetOption(context, OPT_WARNING_REF_COLLISION, OPT_OFF);
1044 
1045   /* treat identify tokens for one object as set */
1046   DDD_SetOption(context, OPT_IDENTIFY_MODE, IDMODE_SETS);
1047 
1048   /* dont delete objects when another copy comes in during Xfer */
1049   DDD_SetOption(context, OPT_XFER_PRUNE_DELETE, OPT_ON);
1050 
1051   /* initialize type mapping arrays */
1052   for(i=0; i<MAXOBJECTS; i++)
1053   {
1054     dddctrl.types[i] = -1;
1055     dddctrl.dddObj[i] = false;
1056   }
1057   for(i=0; i<MAXDDDTYPES; i++)
1058   {
1059     dddctrl.ugtypes[i] = -1;
1060   }
1061   dddctrl.currFormat = NULL;
1062 
1063   /* declare DDD_TYPES, definition must be done later */
1064   ddd_DeclareTypes(context);
1065   dddctrl.allTypesDefined = false;
1066 
1067   DomInitParallel(dddctrl.TypeBndP,dddctrl.TypeBndS);
1068 
1069   ddd_IfInit(context);
1070 
1071   /* check for correct initialization */
1072   if ((err=CheckInitParallel(context))!=0)
1073   {
1074     SetHiWrd(err,__LINE__);
1075     return(err);
1076   }
1077 
1078   return 0;          /* no error */
1079 }
1080 
1081 
1082 
1083 /****************************************************************************/
1084 /*
1085    ExitDDD - exit the parallel application on ddd level
1086 
1087    SYNOPSIS:
1088    int ExitDDD (void);
1089 
1090    PARAMETERS:
1091    .  void
1092 
1093    DESCRIPTION:
1094    This function exits the parallel application on ddd level
1095 
1096    RETUR
1097    N VALUE:
1098    void
1099  */
1100 /****************************************************************************/
1101 
ExitDDD(DDD::DDDContext & context)1102 int NS_DIM_PREFIX ExitDDD(DDD::DDDContext& context)
1103 {
1104   DDD_Exit(context);
1105 
1106   return 0;          /* no error */
1107 }
1108 
1109 #endif /* ModelP */
1110