1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 // vi: set et ts=4 sw=2 sts=2: 3 /*! \file mgio.h 4 * \ingroup gm 5 */ 6 7 8 /****************************************************************************/ 9 /* */ 10 /* File: mgio.h */ 11 /* */ 12 /* Purpose: header file for mgio.c */ 13 /* */ 14 /* Author: Klaus Johannsen */ 15 /* Institut fuer Computeranwendungen III */ 16 /* Universitaet Stuttgart */ 17 /* Pfaffenwaldring 27 */ 18 /* 70550 Stuttgart */ 19 /* email: ug@ica3.uni-stuttgart.de */ 20 /* */ 21 /* History: 13.11.96 begin */ 22 /* */ 23 /* Remarks: */ 24 /* */ 25 /****************************************************************************/ 26 27 28 /* switch */ 29 #define __MGIO_USE_IN_UG__ 30 31 /****************************************************************************/ 32 /* */ 33 /* auto include mechanism and other include files */ 34 /* */ 35 /****************************************************************************/ 36 37 #ifndef __MGIO__ 38 #define __MGIO__ 39 40 #include <cstdio> 41 #include <dune/uggrid/domain/domain.h> 42 43 #ifdef __MGIO_USE_IN_UG__ 44 45 #include <dune/uggrid/low/heaps.h> 46 #include "gm.h" 47 #include "rm.h" 48 #include <dune/uggrid/domain/domain.h> 49 50 #endif 51 52 #include <dune/uggrid/low/namespace.h> 53 54 START_UGDIM_NAMESPACE 55 56 /****************************************************************************/ 57 /* */ 58 /* configuration of interface */ 59 /* */ 60 /****************************************************************************/ 61 62 #define MGIO_VERSION "UG_IO_2.5" 63 64 #define __MGIO_USE_IN_UG__ 65 #define MGIO_DIM 3 66 67 /****************************************************************************/ 68 /* */ 69 /* defines in the following order */ 70 /* */ 71 /* compile time constants defining static data size (i.e. arrays) */ 72 /* other constants */ 73 /* macros */ 74 /* */ 75 /****************************************************************************/ 76 77 #ifdef __MGIO_USE_IN_UG__ 78 79 #define MGIO_PARFILE (nparfiles>1) 80 #define MGIO_DEBUG 0 81 82 #define MGIO_BNDP BNDP 83 #define MGIO_BNDS BNDS 84 85 #undef MGIO_DIM 86 #define MGIO_DIM DIM 87 #define MGIO_MAX_SONS_OF_ELEM MAX_SONS 88 #define MGIO_MAX_EDGES_OF_ELEM MAX_EDGES_OF_ELEM 89 #define MGIO_MAX_CORNERS_OF_ELEM MAX_CORNERS_OF_ELEM 90 #define MGIO_MAX_SIDES_OF_ELEM MAX_SIDES_OF_ELEM 91 #define MGIO_MAX_NEW_CORNERS MAX_NEW_CORNERS_DIM 92 #define MGIO_MAX_CORNERS_OF_SIDE MAX_CORNERS_OF_SIDE 93 94 #define MGIO_FATHER_SIDE_OFFSET FATHER_SIDE_OFFSET 95 96 #define MGIO_MAXLEVEL MAXLEVEL 97 #define MGIO_TAGS TAGS 98 #define MGIO_REFINEMENT_SIZE (MGIO_PARFILE ? sizeof(MGIO_REFINEMENT) : sizeof(struct mgio_refinement_seq)) 99 #define MGIO_CG_POINT_SIZE (MGIO_PARFILE ? (sizeof(MGIO_CG_POINT)) : (sizeof(struct mgio_cg_point_seq))) 100 #define MGIO_CG_ELEMENT_SIZE (MGIO_PARFILE ? (sizeof(MGIO_CG_ELEMENT)) : (sizeof(struct mgio_cg_element_seq))) 101 102 #define MGIO_REFINEMENT_PS(r,n) (MGIO_PARFILE ? ((r)+(n)) : ((MGIO_REFINEMENT*)(((struct mgio_refinement_seq*)(r))+(n)))) 103 #define MGIO_CG_POINT_PS(p,n) (MGIO_PARFILE ? ((p)+(n)) : ((MGIO_CG_POINT*)(((struct mgio_cg_point_seq*)(p))+(n)))) 104 #define MGIO_CG_ELEMENT_PS(e,n) (MGIO_PARFILE ? ((e)+(n)) : ((MGIO_CG_ELEMENT*)(((struct mgio_cg_element_seq*)(e))+(n)))) 105 106 #if (MGIO_DIM==2) 107 #define MGIO_CHECKEXTMACROS {assert(MGIO_MAXLEVEL==32); \ 108 assert(MGIO_TAGS==8); \ 109 assert(MGIO_MAX_SONS_OF_ELEM==30); \ 110 assert(MGIO_MAX_EDGES_OF_ELEM==12); \ 111 assert(MGIO_MAX_CORNERS_OF_ELEM==8); \ 112 assert(MGIO_MAX_SIDES_OF_ELEM==6); \ 113 assert(MGIO_MAX_NEW_CORNERS==5); \ 114 assert(MGIO_MAX_CORNERS_OF_SIDE==4);} 115 #endif 116 #if (MGIO_DIM==3) 117 #define MGIO_CHECKEXTMACROS {assert(MGIO_MAXLEVEL==32); \ 118 assert(MGIO_TAGS==8); \ 119 assert(MGIO_MAX_SONS_OF_ELEM==30); \ 120 assert(MGIO_MAX_EDGES_OF_ELEM==12); \ 121 assert(MGIO_MAX_CORNERS_OF_ELEM==8); \ 122 assert(MGIO_MAX_SIDES_OF_ELEM==6); \ 123 assert(MGIO_MAX_NEW_CORNERS==19); \ 124 assert(MGIO_MAX_CORNERS_OF_SIDE==4);} 125 #endif 126 127 #else 128 129 #define MGIO_DEBUG 0 /* DO NOT TOUCH !!!!! */ 130 #define MGIO_PAR 0 131 #define MGIO_MAXLEVEL 32 132 #define MGIO_TAGS 8 133 134 #if (MGIO_DIM==2) 135 #define MGIO_MAX_SONS_OF_ELEM 30 136 #define MGIO_MAX_EDGES_OF_ELEM 12 137 #define MGIO_MAX_CORNERS_OF_ELEM 8 138 #define MGIO_MAX_SIDES_OF_ELEM 6 139 #define MGIO_MAX_NEW_CORNERS 5 140 #define MGIO_MAX_CORNERS_OF_SIDE 4 141 #endif 142 #if (MGIO_DIM==3) 143 #define MGIO_MAX_SONS_OF_ELEM 30 144 #define MGIO_MAX_EDGES_OF_ELEM 12 145 #define MGIO_MAX_CORNERS_OF_ELEM 8 146 #define MGIO_MAX_SIDES_OF_ELEM 6 147 #define MGIO_MAX_NEW_CORNERS 19 148 #define MGIO_MAX_CORNERS_OF_SIDE 4 149 #endif 150 151 #endif 152 153 /* defines for MGIO_MG_GENERAL */ 154 #define MGIO_NAMELEN 128 155 #define MGIO_IDENTLEN 4096 156 #define MGIO_NODEVECTOR 1 157 #define MGIO_EDGEVECTOR 2 158 #define MGIO_SIDEVECTOR 4 159 #define MGIO_ELEMVECTOR 8 160 161 /* macros for MGIO_MG_GENERAL */ 162 #define MGIO_SET_VECTYPE(p,i) (p)->VectorTypes=(i) 163 #define MGIO_ADD_VECTYPE(p,i) (p)->VectorTypes|=(i) 164 #define MGIO_IS_VECTYPE(p,i) (p)->VectorTypes==(i) 165 #define MGIO_CONT_VECTYPE(p,i) (p)->VectorTypes&(i) 166 167 /****************************************************************************/ 168 /* */ 169 /* data structures exported by the corresponding source file */ 170 /* */ 171 /****************************************************************************/ 172 173 struct mgio_mg_general { 174 175 /* information about the file */ 176 int mode; /* macros see above */ 177 char version[MGIO_NAMELEN]; /* version of i/o */ 178 int magic_cookie; /* identification number */ 179 char ident[MGIO_IDENTLEN]; /* identification string from input file */ 180 181 /* parallel part */ 182 int nparfiles; /* number of processors */ 183 int me; /* id of my processor */ 184 185 /* number of objects */ 186 int nLevel; /* nb of levels of the mg */ 187 int nNode; /* nb of nodes, i.e. corners of elements */ 188 int nPoint; /* nb of points, i.e. diff node locations in mg */ 189 int nElement; /* nb of elements in mg */ 190 191 /* information on geometry */ 192 int dim; /* dimension */ 193 char DomainName[MGIO_NAMELEN]; /* name of domain in ug */ 194 char MultiGridName[MGIO_NAMELEN]; /* name of multigrid */ 195 196 /* information on algebraic structure */ 197 char Formatname[MGIO_NAMELEN]; /* name of format used in ug */ 198 int heapsize; /* heapsize in kbyte, used in ug */ 199 int VectorTypes; /* macros see above */ 200 }; 201 202 struct mgio_ge_general { 203 204 int nGenElement; /* nb of general elements used */ 205 }; 206 207 struct mgio_ge_element { 208 209 int tag; /* identification of general element in ug */ 210 int nCorner; /* nb of corners */ 211 int nEdge; /* nb of edges */ 212 int nSide; /* nb of sides */ 213 int CornerOfEdge[MGIO_MAX_EDGES_OF_ELEM][2]; /* corners of edge */ 214 int CornerOfSide[MGIO_MAX_SIDES_OF_ELEM][4]; /* corners of side */ 215 }; 216 217 struct mgio_rr_general { 218 219 int nRules; /* nb of rules used */ 220 int RefRuleOffset[MGIO_TAGS]; /* offsets used in ug */ 221 }; 222 223 struct mgio_sondata { 224 SHORT tag; /* which element type is the son */ 225 SHORT corners[MGIO_MAX_CORNERS_OF_ELEM]; /* corners of the son */ 226 SHORT nb[MGIO_MAX_SIDES_OF_ELEM]; /* neighbors of this son */ 227 /* < 20 if neighbor has same father */ 228 /* >= 20 if neighbor has other father */ 229 INT path; /* path used in GetSons() for ug */ 230 }; 231 232 struct mgio_rr_rule { 233 234 int rclass; /* class of rule:3bits for COPY, IREG, REG */ 235 int nsons; /* number of sons rule creates */ 236 int pattern[MGIO_MAX_NEW_CORNERS]; /* stores which edges are refined */ 237 int sonandnode[MGIO_MAX_NEW_CORNERS][2]; /* for each new node the number of the son */ 238 /* and the local node number of the node */ 239 struct mgio_sondata sons[MGIO_MAX_SONS_OF_ELEM]; /* for all new sons */ 240 }; 241 242 struct mgio_cg_general { 243 244 int nPoint; /* nb of points on coarse grid, sum of next two */ 245 int nBndPoint; /* nb of bnd points on coarse grid */ 246 int nInnerPoint; /* nb of inner points on coarse grid */ 247 int nElement; /* nb of elements on coarse grid, sum of next two */ 248 int nBndElement; /* nb of bnd elements on coarse grid */ 249 int nInnerElement; /* nb of inner elements on coarse grid */ 250 }; 251 252 struct mgio_cg_point_seq { 253 254 double position[MGIO_DIM]; /* position of the point */ 255 }; 256 257 struct mgio_cg_point { 258 259 double position[MGIO_DIM]; /* position of the point */ 260 int level; /* level of creation */ 261 int prio; /* priority */ 262 }; 263 264 struct mgio_movedcorner { 265 266 int id; /* local id of moved node */ 267 double position[MGIO_DIM]; /* position of the point */ 268 }; 269 270 271 struct mgio_parinfo { 272 unsigned short *proclist; /* NULL for elements without copies */ 273 unsigned short prio_elem; 274 unsigned short ncopies_elem; 275 int e_ident; /* identification of element */ 276 unsigned short prio_node[MGIO_MAX_CORNERS_OF_ELEM]; 277 unsigned short ncopies_node[MGIO_MAX_CORNERS_OF_ELEM]; 278 int n_ident[MGIO_MAX_CORNERS_OF_ELEM]; /* identification of nodes of elem */ 279 unsigned short prio_vertex[MGIO_MAX_CORNERS_OF_ELEM]; 280 unsigned short ncopies_vertex[MGIO_MAX_CORNERS_OF_ELEM]; 281 int v_ident[MGIO_MAX_CORNERS_OF_ELEM]; /* identification of vertices of elem */ 282 unsigned short prio_edge[MGIO_MAX_EDGES_OF_ELEM]; 283 unsigned short ncopies_edge[MGIO_MAX_EDGES_OF_ELEM]; 284 int ed_ident[MGIO_MAX_EDGES_OF_ELEM]; /* identification of edges of element */ 285 }; 286 287 struct mgio_cg_element_seq { 288 289 int ge; /* id of general element */ 290 int cornerid[MGIO_MAX_CORNERS_OF_ELEM]; /* ids of nodes (data reference) */ 291 int nbid[MGIO_MAX_SIDES_OF_ELEM]; /* ids of neighbor elements */ 292 int se_on_bnd; /* side/edge lies on bnd (used bitwise) */ 293 int nref; /* nb of refinements for this element */ 294 /* if 0 element not refined */ 295 int subdomain; /* id of subdomain */ 296 297 #if (MGIO_DEBUG>0) 298 /* debug extension */ 299 int mykey; /* keys of mine */ 300 int nodekey[MGIO_MAX_CORNERS_OF_ELEM]; /* keys of nodes */ 301 int neighborkey[MGIO_MAX_SIDES_OF_ELEM]; /* keys of neighbors */ 302 #endif 303 }; 304 305 struct mgio_cg_element { 306 307 int ge; /* id of general element */ 308 int cornerid[MGIO_MAX_CORNERS_OF_ELEM]; /* ids of nodes (data reference) */ 309 int nbid[MGIO_MAX_SIDES_OF_ELEM]; /* ids of neighbor elements */ 310 int se_on_bnd; /* side/edge lies on bnd (used bitwise) */ 311 int nref; /* nb of refinements for this element */ 312 /* if 0 element not refined */ 313 int subdomain; /* id of subdomain */ 314 315 #if (MGIO_DEBUG>0) 316 /* debug extension */ 317 int mykey; /* keys of mine */ 318 int nodekey[MGIO_MAX_CORNERS_OF_ELEM]; /* keys of nodes */ 319 int neighborkey[MGIO_MAX_SIDES_OF_ELEM]; /* keys of neighbors */ 320 #endif 321 322 /* (procs>1)-extension */ 323 int level; 324 325 }; 326 327 struct mgio_refinement_seq { /* used only for sizeof */ 328 329 int refrule; /* id of refinement rule */ 330 int sonref; /* 1 if sons are refined, bitwise */ 331 int refclass; /* refinement class */ 332 int nnewcorners; /* nb of new corners on next level */ 333 int newcornerid[MGIO_MAX_CORNERS_OF_ELEM+MGIO_MAX_NEW_CORNERS]; /* ids of new vert.or -1 */ 334 int nmoved; /* nmoved new vertices moved */ 335 struct mgio_movedcorner mvcorner[MGIO_MAX_NEW_CORNERS]; /* array of moved node */ 336 }; 337 338 struct mgio_refinement { 339 340 int refrule; /* id of refinement rule */ 341 int sonref; /* 1 if sons are refined, bitwise */ 342 int refclass; /* refinement class */ 343 int nnewcorners; /* nb of new corners on next level */ 344 int newcornerid[MGIO_MAX_CORNERS_OF_ELEM+MGIO_MAX_NEW_CORNERS]; /* ids of new vert.or -1 */ 345 int nmoved; /* nmoved new vertices moved */ 346 struct mgio_movedcorner mvcorner[MGIO_MAX_NEW_CORNERS]; /* array of moved node */ 347 348 /* (procs>1)-extension */ 349 int sonex; /* used bitwise */ 350 int orphanid_ex; /* 1 if exists */ 351 int orphanid[MGIO_MAX_CORNERS_OF_ELEM+MGIO_MAX_NEW_CORNERS]; /* ids of orphan node or -1 */ 352 int nbid_ex; /* used bitwise: nbid exists for son ... */ 353 int nbid[MGIO_MAX_SONS_OF_ELEM][MGIO_MAX_SIDES_OF_ELEM]; /* nb-elem-ids of non-orphan */ 354 /* elems referring to orphan elems if nec. */ 355 struct mgio_parinfo pinfo[MGIO_MAX_SONS_OF_ELEM]; 356 357 #if (MGIO_DEBUG>0) 358 /* debug extension */ 359 int mykey; /* key of the element itself */ 360 int myfatherkey; /* keys of my father */ 361 int mycorners; /* number of element corners */ 362 int mycornerkey[MGIO_MAX_CORNERS_OF_ELEM]; /* keys of the element's corners */ 363 int mycornerfatherkey[MGIO_MAX_CORNERS_OF_ELEM]; /* keys of the element's corners fathers*/ 364 int mycornersonkey[MGIO_MAX_CORNERS_OF_ELEM]; /* keys of the element's corners sons*/ 365 int nbkey[MGIO_MAX_SIDES_OF_ELEM]; /* nb-elem-keys element */ 366 367 /* (procs>1)-extension */ 368 int sonskey[MGIO_MAX_SONS_OF_ELEM]; /* keys of sons of element */ 369 int sonsnbkey[MGIO_MAX_SONS_OF_ELEM][MGIO_MAX_SIDES_OF_ELEM]; /* keys of neighbors of 370 sons of element */ 371 #endif 372 }; 373 374 struct mgio_bd_general { 375 376 int nBndP; /* n BNDP in mg, only ug */ 377 }; 378 379 typedef struct mgio_mg_general MGIO_MG_GENERAL; 380 typedef struct mgio_ge_general MGIO_GE_GENERAL; 381 typedef struct mgio_ge_element MGIO_GE_ELEMENT; 382 typedef struct mgio_rr_general MGIO_RR_GENERAL; 383 typedef struct mgio_rr_rule MGIO_RR_RULE; 384 typedef struct mgio_cg_general MGIO_CG_GENERAL; 385 typedef struct mgio_cg_point MGIO_CG_POINT; 386 typedef struct mgio_cg_element MGIO_CG_ELEMENT; 387 typedef struct mgio_refinement MGIO_REFINEMENT; 388 typedef struct mgio_bd_general MGIO_BD_GENERAL; 389 typedef struct mgio_parinfo MGIO_PARINFO; 390 391 /****************************************************************************/ 392 /* */ 393 /* definition of exported global variables */ 394 /* */ 395 /****************************************************************************/ 396 397 extern int mgpathes_set; 398 399 /****************************************************************************/ 400 /* */ 401 /* function declarations */ 402 /* */ 403 /****************************************************************************/ 404 405 /* read functions */ 406 int Read_OpenMGFile (char *filename); 407 int Read_MG_General (MGIO_MG_GENERAL *mg_general); 408 int Read_GE_General (MGIO_GE_GENERAL *ge_general); 409 int Read_GE_Elements (int n, MGIO_GE_ELEMENT *ge_element); 410 int Read_RR_General (MGIO_RR_GENERAL *rr_general); 411 int Read_RR_Rules (int n, MGIO_RR_RULE *rr_rules); 412 int Read_CG_General (MGIO_CG_GENERAL *cg_general); 413 int Read_CG_Points (int n, MGIO_CG_POINT *cg_point); 414 int Read_CG_Elements (int n, MGIO_CG_ELEMENT *cg_element); 415 int Read_Refinement (MGIO_REFINEMENT *refinement, MGIO_RR_RULE *rr_rules); 416 int Read_BD_General (MGIO_BD_GENERAL *bd_general); 417 418 /* write functions */ 419 int Write_OpenMGFile (char *filename, int rename); 420 int Write_MG_General (MGIO_MG_GENERAL *mg_general); 421 int Write_GE_General (MGIO_GE_GENERAL *ge_general); 422 int Write_GE_Elements (int n, MGIO_GE_ELEMENT *ge_element); 423 int Write_RR_General (MGIO_RR_GENERAL *rr_general); 424 int Write_RR_Rules (int n, MGIO_RR_RULE *rr_rules); 425 int Write_CG_General (MGIO_CG_GENERAL *cg_general); 426 int Write_CG_Points (int n, MGIO_CG_POINT *cg_point); 427 int Write_CG_Elements (int n, MGIO_CG_ELEMENT *cg_element); 428 int Write_Refinement (MGIO_REFINEMENT *refinement, MGIO_RR_RULE *rr_rules); 429 int Write_BD_General (MGIO_BD_GENERAL *bd_general); 430 431 #ifdef __MGIO_USE_IN_UG__ 432 int Read_pinfo (int ge, MGIO_PARINFO *pinfo); 433 int Write_pinfo (int ge, MGIO_PARINFO *pinfo); 434 int MGIO_filetype (char *filename); 435 int Read_PBndDesc (BVP *theBVP, NS_PREFIX HEAP *theHeap, int n, BNDP **BndPList); 436 int Write_PBndDesc (int n, BNDP **BndPList); 437 #endif 438 439 /* general functions */ 440 int CloseMGFile (void); 441 int MGIO_Init (void); 442 int MGIO_dircreate (char *filename, int rename); 443 444 END_UGDIM_NAMESPACE 445 446 #endif 447