Debian Codegraph @

dune/uggrid/gm/mgio.h

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