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: mgio.c */
6 /* */
7 /* Purpose: input/output of loc ref mg */
8 /* */
9 /* Author: Klaus Johannsen */
10 /* Institut fuer Computeranwendungen III */
11 /* Universitaet Stuttgart */
12 /* Pfaffenwaldring 27 */
13 /* 70550 Stuttgart */
14 /* email: ug@ica3.uni-stuttgart.de */
15 /* */
16 /* History: 18.11.96 begin, */
17 /* */
18 /* Remarks: */
19 /* */
20 /****************************************************************************/
21
22 /****************************************************************************/
23 /* */
24 /* include files */
25 /* system include files */
26 /* application include files */
27 /* */
28 /****************************************************************************/
29
30 #include <config.h>
31
32 #include <cstdio>
33 #include <cstdlib>
34 #include <cstring>
35 #include <cassert>
36
37 #include <dune/uggrid/low/bio.h>
38 #include "mgio.h"
39
40 #ifdef __MGIO_USE_IN_UG__
41
42 #include <dune/uggrid/domain/domain.h>
43 #include <dune/uggrid/low/debug.h>
44 #include <dune/uggrid/low/fileopen.h>
45
46 #endif
47
48
49 USING_UG_NAMESPACE
50 USING_UGDIM_NAMESPACE
51
52 /****************************************************************************/
53 /* */
54 /* defines in the following order */
55 /* */
56 /* compile time constants defining static data size (i.e. arrays) */
57 /* other constants */
58 /* macros */
59 /* */
60 /****************************************************************************/
61
62 #define MGIO_TITLE_LINE "####.sparse.mg.storage.format.####"
63
64 #define MGIO_INTSIZE 1000 /* minimal 497 !!! */
65 #define MGIO_DOUBLESIZE 200
66 #define MGIO_BUFFERSIZE 1024
67
68 #define MGIO_CHECK_INTSIZE(n) if ((n)>MGIO_INTSIZE) assert(0) /*return (1)*/
69 #define MGIO_CHECK_DOUBLESIZE(n) if ((n)>MGIO_DOUBLESIZE) return (1)
70 #define MGIO_CHECK_BUFFERIZE(s) if (strlen(s)>MGIO_BUFFERSIZE) return (1)
71
72 #define MGIO_ECTRL_NF_LEN 5
73 #define MGIO_ECTRL_NM_LEN 5
74 #define MGIO_ECTRL_RF_LEN 18
75 #define MGIO_ECTRL_RC_LEN 3
76 #define MGIO_ECTRL_ON_LEN 1
77
78 #define MGIO_ECTRL_NF_SHIFT 0
79 #define MGIO_ECTRL_NM_SHIFT (MGIO_ECTRL_NF_SHIFT + MGIO_ECTRL_NF_LEN)
80 #define MGIO_ECTRL_RF_SHIFT (MGIO_ECTRL_NM_SHIFT + MGIO_ECTRL_NM_LEN)
81 #define MGIO_ECTRL_RC_SHIFT (MGIO_ECTRL_RF_SHIFT + MGIO_ECTRL_RF_LEN)
82 #define MGIO_ECTRL_ON_SHIFT (MGIO_ECTRL_RC_SHIFT + MGIO_ECTRL_RC_LEN)
83
84 #define MGIO_ECTRL(rf,nf,nm,rc,on) ((((nf)&((1<<MGIO_ECTRL_NF_LEN)-1))<<MGIO_ECTRL_NF_SHIFT) | \
85 (((nm)&((1<<MGIO_ECTRL_NM_LEN)-1))<<MGIO_ECTRL_NM_SHIFT) | \
86 (((rf)&((1<<MGIO_ECTRL_RF_LEN)-1))<<MGIO_ECTRL_RF_SHIFT) | \
87 (((rc)&((1<<MGIO_ECTRL_RC_LEN)-1))<<MGIO_ECTRL_RC_SHIFT) | \
88 (((on)&((1<<MGIO_ECTRL_ON_LEN)-1))<<MGIO_ECTRL_ON_SHIFT))
89
90 #define MGIO_ECTRL_NF(ctrl) (((ctrl)>>MGIO_ECTRL_NF_SHIFT)&((1<<MGIO_ECTRL_NF_LEN)-1))
91 #define MGIO_ECTRL_NM(ctrl) (((ctrl)>>MGIO_ECTRL_NM_SHIFT)&((1<<MGIO_ECTRL_NM_LEN)-1))
92 #define MGIO_ECTRL_RF(ctrl) (((ctrl)>>MGIO_ECTRL_RF_SHIFT)&((1<<MGIO_ECTRL_RF_LEN)-1))
93 #define MGIO_ECTRL_RC(ctrl) (((ctrl)>>MGIO_ECTRL_RC_SHIFT)&((1<<MGIO_ECTRL_RC_LEN)-1))
94 #define MGIO_ECTRL_ON(ctrl) (((ctrl)>>MGIO_ECTRL_ON_SHIFT)&((1<<MGIO_ECTRL_ON_LEN)-1))
95
96 /****************************************************************************/
97 /* */
98 /* data structures used in this source file (exported data structures are */
99 /* in the corresponding include file!) */
100 /* */
101 /****************************************************************************/
102
103 /****************************************************************************/
104 /* */
105 /* definition of exported global variables */
106 /* */
107 /****************************************************************************/
108
109 int NS_DIM_PREFIX mgpathes_set; /* pathes used in ug */
110
111
112 /****************************************************************************/
113 /* */
114 /* definition of variables global to this source file only (static!) */
115 /* */
116 /****************************************************************************/
117
118 static FILE *stream; /* file */
119 static char buffer[MGIO_BUFFERSIZE]; /* general purpose buffer */
120 static int intList[MGIO_INTSIZE]; /* general purpose integer list */
121 static double doubleList[MGIO_DOUBLESIZE]; /* general purpose double list*/
122 static int nparfiles; /* nb of parallel files */
123
124 /* local storage of general elements */
125 static MGIO_GE_ELEMENT lge[MGIO_TAGS];
126
127
128 /****************************************************************************/
129 /* */
130 /* forward declarations of functions used before they are defined */
131 /* */
132 /****************************************************************************/
133
134 /****************************************************************************/
135 /*D
136 MGIO_dircreate - create a directory for multigrid files
137
138 SYNOPSIS:
139 int MGIO_dircreate (char *filename, int rename);
140
141 PARAMETERS:
142 . filename - name of directory
143 . rename - renaming option
144
145 DESCRIPTION:
146 Create a directory with specified name incl. renaming option.
147 The considered path entry is "mgpaths".
148
149 RETURN VALUE:
150 int
151 .n 0 if ok
152 .n 1 when error occured.
153
154 SEE ALSO:
155 D*/
156 /****************************************************************************/
157
158 #ifdef __MGIO_USE_IN_UG__
MGIO_dircreate(char * filename,int rename)159 int NS_DIM_PREFIX MGIO_dircreate (char *filename, int rename)
160 {
161
162 if (mgpathes_set) return(DirCreateUsingSearchPaths_r(filename,"mgpaths",rename));
163 else return(DirCreateUsingSearchPaths_r(filename,NULL,rename));
164 }
165 #endif
166
167 /****************************************************************************/
168 /*D
169 MGIO_filetype - test for type of multigrid file
170
171 SYNOPSIS:
172 INT MGIO_filetype (char *filename);
173
174 PARAMETERS:
175 . filename - name of file
176
177 DESCRIPTION:
178 Test for type of multigrid file with name filename in searching pathes if exist.
179 The considered path entry is "mgpaths".
180
181 RETURN VALUE:
182 int
183 .n FT_FILE if regular file
184 .n FT_DIR if directory
185 .n FT_LINK if link and #define S_IFLNK
186 .n FT_UNKNOWN else
187
188 SEE ALSO:
189 D*/
190 /****************************************************************************/
191
192 #ifdef __MGIO_USE_IN_UG__
MGIO_filetype(char * filename)193 int NS_DIM_PREFIX MGIO_filetype (char *filename)
194 {
195
196 if (mgpathes_set) return(FileTypeUsingSearchPaths(filename,"mgpaths"));
197 else return(filetype(filename));
198 }
199 #endif
200
201 /****************************************************************************/
202 /*D
203 Read_OpenMGFile - opens multigrid file for reading
204
205 SYNOPSIS:
206 int Read_OpenMGFile (char *filename);
207
208 PARAMETERS:
209 . filename - name of file
210
211 DESCRIPTION:
212 Opens a multigrid file with specified name for reading.
213 The considered path entry is "mgpaths".
214
215 RETURN VALUE:
216 int
217 .n 0 if ok
218 .n 1 when error occured.
219
220 SEE ALSO:
221 D*/
222 /****************************************************************************/
223
Read_OpenMGFile(char * filename)224 int NS_DIM_PREFIX Read_OpenMGFile (char *filename)
225 {
226
227 #ifdef __MGIO_USE_IN_UG__
228 if (mgpathes_set) stream = FileOpenUsingSearchPaths(filename,"r","mgpaths");
229 else stream = fileopen(filename,"r");
230 #else
231 stream = fopen(filename,"r");
232 #endif
233
234 if (stream==NULL) return (1);
235
236 return (0);
237 }
238
239 /****************************************************************************/
240 /*D
241 Write_OpenMGFile - opens multigrid file for writing
242
243 SYNOPSIS:
244 int Write_OpenMGFile (char *filename, int rename);
245
246 PARAMETERS:
247 . filename - name of file
248 . rename - renaming option
249
250 DESCRIPTION:
251 Opens a multigrid file with specified name for writing incl. renaming option.
252 The considered path entry is "mgpaths".
253
254 RETURN VALUE:
255 int
256 .n 0 if ok
257 .n 1 when error occured.
258
259 SEE ALSO:
260 D*/
261 /****************************************************************************/
262
Write_OpenMGFile(char * filename,int rename)263 int NS_DIM_PREFIX Write_OpenMGFile (char *filename, int rename)
264 {
265
266 #ifdef __MGIO_USE_IN_UG__
267 if (mgpathes_set) stream = FileOpenUsingSearchPaths_r(filename,"w","mgpaths",rename);
268 else stream = fileopen_r(filename,"w",rename);
269 #else
270 stream = fopen(filename,"w");
271 #endif
272
273 if (stream==NULL) return (1);
274 return (0);
275 }
276
277 /****************************************************************************/
278 /*
279 Read_MG_General - reads general information about mg
280
281 SYNOPSIS:
282 int Read_MG_General (MGIO_MG_GENERAL *mg_general);
283
284 PARAMETERS:
285 . mg_general - general information about mg
286
287 DESCRIPTION:
288 function reads general information about the mg
289
290 RETURN VALUE:
291 INT
292 .n 0 if ok
293 .n 1 if read error.
294
295 SEE ALSO:
296 */
297 /****************************************************************************/
298
Read_MG_General(MGIO_MG_GENERAL * mg_general)299 int NS_DIM_PREFIX Read_MG_General (MGIO_MG_GENERAL *mg_general)
300 {
301 /* initialize basic i/o */
302 if (Bio_Initialize(stream,BIO_ASCII,'r')) return (1);
303
304 /* head always in ACSII */
305 if (Bio_Read_string(buffer)) return (1);
306 if (strcmp(buffer,MGIO_TITLE_LINE)!=0) return (1);
307 if (Bio_Read_mint(1,intList)) return (1);
308 mg_general->mode = intList[0];
309
310 /* re-initialize basic i/o */
311 if (Bio_Initialize(stream,mg_general->mode,'r')) return (1);
312
313 /* now special mode */
314 if (Bio_Read_string(mg_general->version)) return (1);
315 if (strcmp(mg_general->version,"UG_IO_2.2")==0)
316 {
317 strcpy(mg_general->version,"UG_IO_2.3");
318 }
319 if (Bio_Read_string(mg_general->ident)) return (1);
320 if (Bio_Read_string(mg_general->DomainName)) return (1);
321 if (Bio_Read_string(mg_general->MultiGridName)) return (1);
322 if (Bio_Read_string(mg_general->Formatname)) return (1);
323 if (Bio_Read_mint(11,intList)) return (1);
324 mg_general->dim = intList[0];
325 mg_general->magic_cookie= intList[1];
326 mg_general->heapsize = intList[2];
327 mg_general->nLevel = intList[3];
328 mg_general->nNode = intList[4];
329 mg_general->nPoint = intList[5];
330 mg_general->nElement = intList[6];
331 mg_general->VectorTypes = intList[7];
332 mg_general->me = intList[8];
333 mg_general->nparfiles = intList[9];
334 if (intList[10]!=MGIO_DEBUG)
335 RETURN (1); /* check debug-level of file: 0: no debug information */
336
337 /* init global parameters */
338 nparfiles = mg_general->nparfiles;
339
340 return (0);
341 }
342
343 /****************************************************************************/
344 /*
345 Write_MG_General - writes general information about mg
346
347 SYNOPSIS:
348 int Write_MG_General (MGIO_MG_GENERAL *mg_general);
349
350 PARAMETERS:
351 . mg_general - general information about mg
352
353 DESCRIPTION:
354 function writes general information about the mg
355
356 RETURN VALUE:
357 INT
358 .n 0 if ok
359 .n 1 if read error.
360
361 SEE ALSO:
362 */
363 /****************************************************************************/
364
Write_MG_General(MGIO_MG_GENERAL * mg_general)365 int NS_DIM_PREFIX Write_MG_General (MGIO_MG_GENERAL *mg_general)
366 {
367 /* initialize basic i/o */
368 if (Bio_Initialize(stream,BIO_ASCII,'w')) return (1);
369
370 /* head always in ACSII */
371 if (Bio_Write_string(MGIO_TITLE_LINE)) return (1);
372 intList[0] = mg_general->mode;
373 if (Bio_Write_mint(1,intList)) return (1);
374
375 /* initialize basic i/o */
376 if (Bio_Initialize(stream,mg_general->mode,'w')) return (1);
377
378 /* now special mode */
379 if (Bio_Write_string(mg_general->version)) return (1);
380 if (Bio_Write_string(mg_general->ident)) return (1);
381 if (Bio_Write_string(mg_general->DomainName)) return (1);
382 if (Bio_Write_string(mg_general->MultiGridName)) return (1);
383 if (Bio_Write_string(mg_general->Formatname)) return (1);
384 intList[0] = mg_general->dim;
385 intList[1] = mg_general->magic_cookie;
386 intList[2] = mg_general->heapsize;
387 intList[3] = mg_general->nLevel;
388 intList[4] = mg_general->nNode;
389 intList[5] = mg_general->nPoint;
390 intList[6] = mg_general->nElement;
391 intList[7] = mg_general->VectorTypes;
392 intList[8] = mg_general->me;
393 intList[9] = mg_general->nparfiles;
394 intList[10]= MGIO_DEBUG;
395 if (Bio_Write_mint(11,intList)) return (1);
396
397 /* init global parameters */
398 nparfiles = mg_general->nparfiles;
399
400 return (0);
401 }
402
403 /****************************************************************************/
404 /*
405 Read_GE_General - reads general information about general elements
406
407 SYNOPSIS:
408 int Read_GE_General (MGIO_GE_GENERAL *ge_general);
409
410 PARAMETERS:
411 . ge_general - general information about general elements
412
413 DESCRIPTION:
414 function reads general information about general elements
415
416 RETURN VALUE:
417 INT
418 .n 0 if ok
419 .n 1 if read error.
420
421 SEE ALSO:
422 */
423 /****************************************************************************/
424
Read_GE_General(MGIO_GE_GENERAL * ge_general)425 int NS_DIM_PREFIX Read_GE_General (MGIO_GE_GENERAL *ge_general)
426 {
427 if (Bio_Read_mint(1,intList)) return (1);
428 ge_general->nGenElement = intList[0];
429
430 return (0);
431 }
432
433 /****************************************************************************/
434 /*
435 Write_GE_General - writes general information about general elements
436
437 SYNOPSIS:
438 int Write_GE_General (MGIO_GE_GENERAL *ge_general);
439
440 PARAMETERS:
441 . ge_general - general information about general elements
442
443 DESCRIPTION:
444 function writes general information about general elements
445
446 RETURN VALUE:
447 INT
448 .n 0 if ok
449 .n 1 if read error.
450
451 SEE ALSO:
452 */
453 /****************************************************************************/
454
Write_GE_General(MGIO_GE_GENERAL * ge_general)455 int NS_DIM_PREFIX Write_GE_General (MGIO_GE_GENERAL *ge_general)
456 {
457 intList[0] = ge_general->nGenElement;
458 if (Bio_Write_mint(1,intList)) return (1);
459
460 return (0);
461 }
462
463 /****************************************************************************/
464 /*
465 Read_GE_Elements - reads general elements
466
467 SYNOPSIS:
468 int Read_GE_Elements (int n, MGIO_GE_ELEMENT *ge_element);
469
470 PARAMETERS:
471 . n - nb of general elements to read
472 . ge_element - first general elements
473
474 DESCRIPTION:
475 function reads general elements
476
477 RETURN VALUE:
478 INT
479 .n 0 if ok
480 .n 1 if read error.
481
482 SEE ALSO:
483 */
484 /****************************************************************************/
485
Read_GE_Elements(int n,MGIO_GE_ELEMENT * ge_element)486 int NS_DIM_PREFIX Read_GE_Elements (int n, MGIO_GE_ELEMENT *ge_element)
487 {
488 int i,j,s;
489 MGIO_GE_ELEMENT *pge;
490
491 pge = ge_element;
492 for (i=0; i<n; i++)
493 {
494 if (Bio_Read_mint(4,intList))
495 return 1;
496
497 s=0;
498
499 pge->tag = lge[i].tag = intList[s++];
500 pge->nCorner = lge[i].nCorner = intList[s++];
501 pge->nEdge = lge[i].nEdge = intList[s++];
502 pge->nSide = lge[i].nSide = intList[s++];
503 if (pge->nEdge>0 || pge->nSide>0)
504 {
505 if (Bio_Read_mint(2*pge->nEdge+4*pge->nSide,intList))
506 return 1;
507
508 s=0;
509
510 for (j=0; j<pge->nEdge; j++)
511 {
512 pge->CornerOfEdge[j][0] = lge[i].CornerOfEdge[j][0] = intList[s++];
513 pge->CornerOfEdge[j][1] = lge[i].CornerOfEdge[j][1] = intList[s++];
514 }
515 for (j=0; j<pge->nSide; j++)
516 {
517 pge->CornerOfSide[j][0] = lge[i].CornerOfSide[j][0] = intList[s++];
518 pge->CornerOfSide[j][1] = lge[i].CornerOfSide[j][1] = intList[s++];
519 pge->CornerOfSide[j][2] = lge[i].CornerOfSide[j][2] = intList[s++];
520 pge->CornerOfSide[j][3] = lge[i].CornerOfSide[j][3] = intList[s++];
521 }
522 }
523 pge++;
524 }
525
526 return 0;
527 }
528
529 /****************************************************************************/
530 /*
531 Write_GE_Elements - writes general elements
532
533 SYNOPSIS:
534 int Write_GE_Elements (int n, MGIO_GE_ELEMENT *ge_element);
535
536 PARAMETERS:
537 . n - nb of general elements to write
538 . ge_element - first general elements
539
540 DESCRIPTION:
541 function writes general elements
542
543 RETURN VALUE:
544 INT
545 .n 0 if ok
546 .n 1 if read error.
547
548 SEE ALSO:
549 */
550 /****************************************************************************/
551
Write_GE_Elements(int n,MGIO_GE_ELEMENT * ge_element)552 int NS_DIM_PREFIX Write_GE_Elements (int n, MGIO_GE_ELEMENT *ge_element)
553 {
554 int i,j,s;
555 MGIO_GE_ELEMENT *pge;
556
557 pge = ge_element;
558 for (i=0; i<n; i++)
559 {
560 s=0;
561 intList[s++] = lge[i].tag = pge->tag;
562 intList[s++] = lge[i].nCorner = pge->nCorner;
563 intList[s++] = lge[i].nEdge = pge->nEdge;
564 intList[s++] = lge[i].nSide = pge->nSide;
565 for (j=0; j<pge->nEdge; j++)
566 {
567 intList[s++] = lge[i].CornerOfEdge[j][0] = pge->CornerOfEdge[j][0];
568 intList[s++] = lge[i].CornerOfEdge[j][1] = pge->CornerOfEdge[j][1];
569 }
570 for (j=0; j<pge->nSide; j++)
571 {
572 intList[s++] = lge[i].CornerOfSide[j][0] = pge->CornerOfSide[j][0];
573 intList[s++] = lge[i].CornerOfSide[j][1] = pge->CornerOfSide[j][1];
574 intList[s++] = lge[i].CornerOfSide[j][2] = pge->CornerOfSide[j][2];
575 intList[s++] = lge[i].CornerOfSide[j][3] = pge->CornerOfSide[j][3];
576 }
577 MGIO_CHECK_INTSIZE(s);
578 if (Bio_Write_mint(s,intList)) return (1);
579 pge++;
580 }
581
582 return (0);
583 }
584
585 /****************************************************************************/
586 /*
587 Read_RR_General - reads general information about refinement rules
588
589 SYNOPSIS:
590 int Read_RR_General (MGIO_RR_GENERAL *mgio_rr_general);
591
592 PARAMETERS:
593 . mgio_rr_general - general information about refinement rules
594
595 DESCRIPTION:
596 function reads general information about refinement rules
597
598 RETURN VALUE:
599 INT
600 .n 0 if ok
601 .n 1 if read error.
602
603 SEE ALSO:
604 */
605 /****************************************************************************/
606
Read_RR_General(MGIO_RR_GENERAL * mgio_rr_general)607 int NS_DIM_PREFIX Read_RR_General (MGIO_RR_GENERAL *mgio_rr_general)
608 {
609 int i,s;
610
611 if (Bio_Read_mint(1+MGIO_TAGS,intList)) return (1);
612 s=0;
613 mgio_rr_general->nRules = intList[s++];
614 for (i=0; i<MGIO_TAGS; i++)
615 mgio_rr_general->RefRuleOffset[i] = intList[s++];
616
617 return (0);
618 }
619
620 /****************************************************************************/
621 /*
622 Write_GE_General - writes general information about refinement rules
623
624 SYNOPSIS:
625 int Write_RR_General (MGIO_RR_GENERAL *mgio_rr_general);
626
627 PARAMETERS:
628 . mgio_rr_general - general information about refinement rules
629
630 DESCRIPTION:
631 function writes general information about refinement rules
632
633 RETURN VALUE:
634 INT
635 .n 0 if ok
636 .n 1 if read error.
637
638 SEE ALSO:
639 */
640 /****************************************************************************/
641
Write_RR_General(MGIO_RR_GENERAL * mgio_rr_general)642 int NS_DIM_PREFIX Write_RR_General (MGIO_RR_GENERAL *mgio_rr_general)
643 {
644 int i,s;
645
646 s=0;
647 intList[s++] = mgio_rr_general->nRules;
648 for (i=0; i<MGIO_TAGS; i++)
649 intList[s++] = mgio_rr_general->RefRuleOffset[i];
650 if (Bio_Write_mint(s,intList)) return (1);
651
652 return (0);
653 }
654
655 /****************************************************************************/
656 /*
657 Read_RR_Rules - reads refinement rules
658
659 SYNOPSIS:
660 int Read_RR_Rules (int n, MGIO_RR_RULE *rr_rules);
661
662 PARAMETERS:
663 . n - nb of refinement rules to read
664 . rr_rules - first refinement rule
665
666 DESCRIPTION:
667 function reads refinement rules
668
669 RETURN VALUE:
670 INT
671 .n 0 if ok
672 .n 1 if read error.
673
674 SEE ALSO:
675 */
676 /****************************************************************************/
677
Read_RR_Rules(int n,MGIO_RR_RULE * rr_rules)678 int NS_DIM_PREFIX Read_RR_Rules (int n, MGIO_RR_RULE *rr_rules)
679 {
680 int i,j,k,m,s;
681 MGIO_RR_RULE *prr;
682
683 prr = rr_rules;
684 for (i=0; i<n; i++)
685 {
686 if (Bio_Read_mint(2,intList)) return (1);
687 prr->rclass = intList[0];
688 prr->nsons = intList[1];
689 m = MGIO_MAX_NEW_CORNERS+2*MGIO_MAX_NEW_CORNERS+prr->nsons*(1+MGIO_MAX_CORNERS_OF_ELEM+MGIO_MAX_SIDES_OF_ELEM+1);
690 if (Bio_Read_mint(m,intList)) return (1);
691 s=0;
692 for (j=0; j<MGIO_MAX_NEW_CORNERS; j++)
693 prr->pattern[j] = intList[s++];
694 for (j=0; j<MGIO_MAX_NEW_CORNERS; j++)
695 {
696 prr->sonandnode[j][0] = intList[s++];
697 prr->sonandnode[j][1] = intList[s++];
698 }
699 for (j=0; j<prr->nsons; j++)
700 {
701 prr->sons[j].tag = intList[s++];
702 for (k=0; k<MGIO_MAX_CORNERS_OF_ELEM; k++)
703 prr->sons[j].corners[k] = intList[s++];
704 for (k=0; k<MGIO_MAX_SIDES_OF_ELEM; k++)
705 prr->sons[j].nb[k] = intList[s++];
706 prr->sons[j].path = intList[s++];
707 }
708 prr++;
709 }
710
711 return (0);
712 }
713
714 /****************************************************************************/
715 /*
716 Write_RR_Rules - writes refinement rules
717
718 SYNOPSIS:
719 int Write_RR_Rules (int n, MGIO_RR_RULE *rr_rules);
720
721 PARAMETERS:
722 . n - nb of refinement rules to write
723 . rr_rules - first refinement rule
724
725 DESCRIPTION:
726 function writes refinement rules
727
728 RETURN VALUE:
729 INT
730 .n 0 if ok
731 .n 1 if read error.
732
733 SEE ALSO:
734 */
735 /****************************************************************************/
736
Write_RR_Rules(int n,MGIO_RR_RULE * rr_rules)737 int NS_DIM_PREFIX Write_RR_Rules (int n, MGIO_RR_RULE *rr_rules)
738 {
739 int i,j,k,s;
740 MGIO_RR_RULE *prr;
741
742 prr = rr_rules;
743 for (i=0; i<n; i++)
744 {
745 s=0;
746 intList[s++] = prr->rclass;
747 intList[s++] = prr->nsons;
748 for (j=0; j<MGIO_MAX_NEW_CORNERS; j++)
749 intList[s++] = prr->pattern[j];
750 for (j=0; j<MGIO_MAX_NEW_CORNERS; j++)
751 {
752 intList[s++] = prr->sonandnode[j][0];
753 intList[s++] = prr->sonandnode[j][1];
754 }
755 for (j=0; j<prr->nsons; j++)
756 {
757 intList[s++] = prr->sons[j].tag;
758 for (k=0; k<MGIO_MAX_CORNERS_OF_ELEM; k++)
759 intList[s++] = prr->sons[j].corners[k];
760 for (k=0; k<MGIO_MAX_SIDES_OF_ELEM; k++)
761 intList[s++] = prr->sons[j].nb[k];
762 intList[s++] = prr->sons[j].path;
763 }
764 MGIO_CHECK_INTSIZE(s);
765 if (Bio_Write_mint(s,intList)) return (1);
766 prr++;
767 }
768
769 return (0);
770 }
771
772 /****************************************************************************/
773 /*
774 Read_CG_General - reads general information about coarse grid
775
776 SYNOPSIS:
777 int Read_CG_General (MGIO_CG_GENERAL *cg_general);
778
779 PARAMETERS:
780 . cg_general - general information about coarse grid
781
782 DESCRIPTION:
783 function reads general information about coarse grid
784
785 RETURN VALUE:
786 INT
787 .n 0 if ok
788 .n 1 if read error.
789
790 SEE ALSO:
791 */
792 /****************************************************************************/
793
Read_CG_General(MGIO_CG_GENERAL * cg_general)794 int NS_DIM_PREFIX Read_CG_General (MGIO_CG_GENERAL *cg_general)
795 {
796 if (Bio_Read_mint(6,intList)) return (1);
797 cg_general->nPoint = intList[0];
798 cg_general->nBndPoint = intList[1];
799 cg_general->nInnerPoint = intList[2];
800 cg_general->nElement = intList[3];
801 cg_general->nBndElement = intList[4];
802 cg_general->nInnerElement = intList[5];
803
804 return (0);
805 }
806
807 /****************************************************************************/
808 /*
809 Write_CG_General - writes general information about coarse grid
810
811 SYNOPSIS:
812 int Write_CG_General (MGIO_CG_GENERAL *cg_general);
813
814 PARAMETERS:
815 . cg_general - general information about coarse grid
816
817 DESCRIPTION:
818 function writes general information about coarse grid
819
820 RETURN VALUE:
821 INT
822 .n 0 if ok
823 .n 1 if read error.
824
825 SEE ALSO:
826 */
827 /****************************************************************************/
828
Write_CG_General(MGIO_CG_GENERAL * cg_general)829 int NS_DIM_PREFIX Write_CG_General (MGIO_CG_GENERAL *cg_general)
830 {
831 intList[0] = cg_general->nPoint;
832 intList[1] = cg_general->nBndPoint;
833 intList[2] = cg_general->nInnerPoint;
834 intList[3] = cg_general->nElement;
835 intList[4] = cg_general->nBndElement;
836 intList[5] = cg_general->nInnerElement;
837 if (Bio_Write_mint(6,intList)) return (1);
838
839 return (0);
840 }
841
842 /****************************************************************************/
843 /*
844 Read_CG_Points - reads coarse grid points
845
846 SYNOPSIS:
847 int Read_CG_Points (MGIO_CG_POINT *cg_point);
848
849 PARAMETERS:
850 . n - nb of coarse grid points to read
851 . cg_point - first coarse grid point
852
853 DESCRIPTION:
854 function reads coarse grid points
855
856 RETURN VALUE:
857 INT
858 .n 0 if ok
859 .n 1 if read error.
860
861 SEE ALSO:
862 */
863 /****************************************************************************/
864
Read_CG_Points(int n,MGIO_CG_POINT * cg_point)865 int NS_DIM_PREFIX Read_CG_Points (int n, MGIO_CG_POINT *cg_point)
866 {
867 int i,j;
868 MGIO_CG_POINT *cgp;
869
870 for(i=0; i<n; i++)
871 {
872 if (Bio_Read_mdouble(MGIO_DIM,doubleList)) return (1);
873 cgp = MGIO_CG_POINT_PS(cg_point,i);
874 for(j=0; j<MGIO_DIM; j++)
875 cgp->position[j] = doubleList[j];
876 if (MGIO_PARFILE)
877 {
878 if (Bio_Read_mint(2,intList)) return (1);
879 cgp->level = intList[0];
880 cgp->prio = intList[1];
881 }
882 }
883
884 return (0);
885 }
886
887 /****************************************************************************/
888 /*
889 Write_CG_Points - writes coarse grid points
890
891 SYNOPSIS:
892 int Write_CG_Points (MGIO_CG_POINT *cg_point);
893
894 PARAMETERS:
895 . n - nb of coarse grid points to write
896 . cg_point - first coarse grid point
897
898 DESCRIPTION:
899 function writes coarse grid points
900
901 RETURN VALUE:
902 INT
903 .n 0 if ok
904 .n 1 if read error.
905
906 SEE ALSO:
907 */
908 /****************************************************************************/
909
Write_CG_Points(int n,MGIO_CG_POINT * cg_point)910 int NS_DIM_PREFIX Write_CG_Points (int n, MGIO_CG_POINT *cg_point)
911 {
912 int i,j;
913 MGIO_CG_POINT *cgp;
914
915 for(i=0; i<n; i++)
916 {
917 cgp = MGIO_CG_POINT_PS(cg_point,i);
918 for(j=0; j<MGIO_DIM; j++)
919 doubleList[j] = cgp->position[j];
920 if (Bio_Write_mdouble(MGIO_DIM,doubleList)) return (1);
921 if (MGIO_PARFILE)
922 {
923 intList[0] = cgp->level;
924 intList[1] = cgp->prio;
925 if (Bio_Write_mint(2,intList)) return (1);
926 }
927 }
928
929 return (0);
930 }
931
932 /****************************************************************************/
933 /*
934 Read_pinfo - reads parallel-info for an element
935
936 SYNOPSIS:
937 static int Read_pinfo (MGIO_CG_ELEMENT *pe);
938 */
939 /****************************************************************************/
940
Read_pinfo(int ge,MGIO_PARINFO * pinfo)941 int NS_DIM_PREFIX Read_pinfo (int ge, MGIO_PARINFO *pinfo)
942 {
943 int i,m,s,np;
944 #if (MGIO_DEBUG>0)
945 char buffer[28];
946 static int nb=0;
947
948 if (Bio_Read_string(buffer)) return (1);
949 if(strcmp(buffer,"PINFO_BEGIN")!=0)
950 {
951 printf("proc=%d, nb=%d\n",me,nb);
952 fflush(stdout);
953 assert(0);
954 }
955 nb++;
956 #endif
957
958 s=0;
959 m = 3+6*lge[ge].nCorner;
960 if (Bio_Read_mint(m,intList)) return (1);
961 pinfo->prio_elem = intList[s++];
962 assert(pinfo->prio_elem<32);
963 pinfo->ncopies_elem = intList[s++];
964 np = pinfo->ncopies_elem;
965 pinfo->e_ident = intList[s++];
966 for (i=0; i<lge[ge].nCorner; i++)
967 {
968 pinfo->prio_node[i] = intList[s++];
969 assert(pinfo->prio_node[i]<32);
970 pinfo->ncopies_node[i] = intList[s++];
971 np+= pinfo->ncopies_node[i];
972 pinfo->n_ident[i] = intList[s++];
973 }
974 for (i=0; i<lge[ge].nCorner; i++)
975 {
976 pinfo->prio_vertex[i] = intList[s++];
977 assert(pinfo->prio_vertex[i]<32);
978 pinfo->ncopies_vertex[i] = intList[s++];
979 np+= pinfo->ncopies_vertex[i];
980 pinfo->v_ident[i] = intList[s++];
981 }
982 s=0;
983 m = 3*lge[ge].nEdge;
984 if (Bio_Read_mint(m,intList)) return (1);
985 for (i=0; i<lge[ge].nEdge; i++)
986 {
987 pinfo->prio_edge[i] = intList[s++];
988 assert(pinfo->prio_edge[i]<32);
989 pinfo->ncopies_edge[i] = intList[s++];
990 np+= pinfo->ncopies_edge[i];
991 pinfo->ed_ident[i] = intList[s++];
992 }
993 if (np > 0) if (Bio_Read_mint(np,intList)) return (1);
994 for (i=0; i<np; i++)
995 {
996 pinfo->proclist[i] = intList[i];
997 ASSERT(pinfo->proclist[i]<nparfiles);
998 }
999
1000 return (0);
1001 }
1002
1003 /****************************************************************************/
1004 /*
1005 Write_pinfo - writes parallel-info for an element
1006
1007 SYNOPSIS:
1008 static int Write_pinfo (MGIO_CG_ELEMENT *pe);
1009 */
1010 /****************************************************************************/
1011
Write_pinfo(int ge,MGIO_PARINFO * pinfo)1012 int NS_DIM_PREFIX Write_pinfo (int ge, MGIO_PARINFO *pinfo)
1013 {
1014 int i,s,np;
1015
1016 #if (MGIO_DEBUG>0)
1017 if (Bio_Write_string("PINFO_BEGIN")) return (1);
1018 #endif
1019
1020 s=0;
1021 intList[s++] = pinfo->prio_elem;
1022 intList[s++] = np = pinfo->ncopies_elem;
1023 intList[s++] = pinfo->e_ident;
1024 for (i=0; i<lge[ge].nCorner; i++)
1025 {
1026 intList[s++] = pinfo->prio_node[i];
1027 intList[s++] = pinfo->ncopies_node[i];
1028 np+= pinfo->ncopies_node[i];
1029 intList[s++] = pinfo->n_ident[i];
1030 }
1031 for (i=0; i<lge[ge].nCorner; i++)
1032 {
1033 intList[s++] = pinfo->prio_vertex[i];
1034 intList[s++] = pinfo->ncopies_vertex[i];
1035 np+= pinfo->ncopies_vertex[i];
1036 intList[s++] = pinfo->v_ident[i];
1037 }
1038 if (Bio_Write_mint(s,intList)) RETURN (1);
1039 s=0;
1040 for (i=0; i<lge[ge].nEdge; i++)
1041 {
1042 intList[s++] = pinfo->prio_edge[i];
1043 intList[s++] = pinfo->ncopies_edge[i];
1044 np+= pinfo->ncopies_edge[i];
1045 intList[s++] = pinfo->ed_ident[i];
1046 }
1047 if (Bio_Write_mint(s,intList)) RETURN (1);
1048 for (i=0; i<np; i++)
1049 {
1050 intList[i] = pinfo->proclist[i];
1051 ASSERT(intList[i]<nparfiles);
1052 }
1053 if (np > 0) if (Bio_Write_mint(np,intList)) RETURN (1);
1054
1055 return (0);
1056 }
1057
1058 /****************************************************************************/
1059 /*
1060 Read_CG_Elements - reads coarse grid elements
1061
1062 SYNOPSIS:
1063 int Read_CG_Elements (int n, MGIO_CG_ELEMENT *cg_element);
1064
1065 PARAMETERS:
1066 . n - nb of coarse grid elements to read
1067 . cg_element - first coarse grid element
1068
1069 DESCRIPTION:
1070 function reads coarse grid elements
1071
1072 RETURN VALUE:
1073 INT
1074 .n 0 if ok
1075 .n 1 if read error.
1076
1077 SEE ALSO:
1078 */
1079 /****************************************************************************/
1080
Read_CG_Elements(int n,MGIO_CG_ELEMENT * cg_element)1081 int NS_DIM_PREFIX Read_CG_Elements (int n, MGIO_CG_ELEMENT *cg_element)
1082 {
1083 int i,j,m,s;
1084 MGIO_CG_ELEMENT *pe;
1085
1086 for (i=0; i<n; i++)
1087 {
1088 pe = MGIO_CG_ELEMENT_PS(cg_element,i);
1089
1090 /* coarse grid part */
1091 if (Bio_Read_mint(1,&pe->ge)) return (1);
1092 m=lge[pe->ge].nCorner+lge[pe->ge].nSide+3;
1093 if (Bio_Read_mint(m,intList)) return (1);
1094 s=0;
1095 pe->nref = intList[s++];
1096 for (j=0; j<lge[pe->ge].nCorner; j++)
1097 pe->cornerid[j] = intList[s++];
1098 for (j=0; j<lge[pe->ge].nSide; j++)
1099 pe->nbid[j] = intList[s++];
1100 pe->se_on_bnd = intList[s++];
1101 pe->subdomain = intList[s++];
1102
1103 if (MGIO_PARFILE)
1104 {
1105 if (Bio_Read_mint(1,intList)) return (1);
1106 s=0;
1107 pe->level = intList[s++];
1108 }
1109
1110 #if (MGIO_DEBUG>0)
1111 /* read debug extension */
1112 m = 1 + lge[pe->ge].nCorner + lge[pe->ge].nSide;
1113 if (Bio_Read_mint(m,intList)) return (1);
1114 s=0;
1115 pe->mykey = intList[s++];
1116 for (j=0; j<lge[pe->ge].nCorner; j++)
1117 pe->nodekey[j] = intList[s++];
1118 for (j=0; j<lge[pe->ge].nSide; j++)
1119 pe->neighborkey[j] = intList[s++];
1120 #endif
1121
1122 }
1123
1124 return (0);
1125 }
1126
1127 /****************************************************************************/
1128 /*
1129 Write_CG_Elements - writes coarse grid elements
1130
1131 SYNOPSIS:
1132 int Write_CG_Elements (int n, MGIO_CG_ELEMENT *cg_element);
1133
1134 PARAMETERS:
1135 . n - nb of coarse grid elements to write
1136 . rr_rules - first coarse grid element
1137
1138 DESCRIPTION:
1139 function writes coarse grid elements
1140
1141 RETURN VALUE:
1142 INT
1143 .n 0 if ok
1144 .n 1 if read error.
1145
1146 SEE ALSO:
1147 */
1148 /****************************************************************************/
1149
Write_CG_Elements(int n,MGIO_CG_ELEMENT * cg_element)1150 int NS_DIM_PREFIX Write_CG_Elements (int n, MGIO_CG_ELEMENT *cg_element)
1151 {
1152 int i,j,s;
1153 MGIO_CG_ELEMENT *pe;
1154
1155 for (i=0; i<n; i++)
1156 {
1157 pe = MGIO_CG_ELEMENT_PS(cg_element,i);
1158
1159 /* coarse grid part */
1160 s=0;
1161 intList[s++] = pe->ge;
1162 intList[s++] = pe->nref;
1163 for (j=0; j<lge[pe->ge].nCorner; j++)
1164 intList[s++] = pe->cornerid[j];
1165 for (j=0; j<lge[pe->ge].nSide; j++)
1166 intList[s++] = pe->nbid[j];
1167 intList[s++] = pe->se_on_bnd;
1168 intList[s++] = pe->subdomain;
1169 MGIO_CHECK_INTSIZE(s);
1170 if (Bio_Write_mint(s,intList)) return (1);
1171
1172 if (MGIO_PARFILE)
1173 {
1174 s=0;
1175 intList[s++] = pe->level;
1176 if (Bio_Write_mint(s,intList)) return (1);
1177 }
1178
1179 #if (MGIO_DEBUG>0)
1180 /* write debug extension */
1181 s=0;
1182 intList[s++] = pe->mykey;
1183 for (j=0; j<lge[pe->ge].nCorner; j++)
1184 intList[s++] = pe->nodekey[j];
1185 for (j=0; j<lge[pe->ge].nSide; j++)
1186 intList[s++] = pe->neighborkey[j];
1187 if (Bio_Write_mint(s,intList)) return (1);
1188 #endif
1189
1190 }
1191
1192 return (0);
1193 }
1194
1195 /****************************************************************************/
1196 /*
1197 Read_HE_Refinement - reads hierarchical elements
1198
1199 SYNOPSIS:
1200 int Read_HE_Refinement (MGIO_HE_ELEMENT *he_element);
1201
1202 PARAMETERS:
1203 . n - nb of hierarchical elements to read
1204 . he_element - hierarchical element
1205
1206 DESCRIPTION:
1207 function reads hierarchical elements
1208
1209 RETURN VALUE:
1210 INT
1211 .n 0 if ok
1212 .n 1 if read error.
1213
1214 SEE ALSO:
1215 */
1216 /****************************************************************************/
1217
Read_Refinement(MGIO_REFINEMENT * pr,MGIO_RR_RULE * rr_rules)1218 int NS_DIM_PREFIX Read_Refinement (MGIO_REFINEMENT *pr, MGIO_RR_RULE *rr_rules)
1219 {
1220 int j,k,s,tag;
1221 unsigned int ctrl;
1222
1223 #if (MGIO_DEBUG>0)
1224 char buffer[128];
1225 if (Bio_Read_string(buffer)) assert(0); /*return (1);*/
1226 if(strcmp(buffer,"REFINEMENT_BEGIN")!=0) assert(0); /*return (1);*/
1227 if (Bio_Read_mint(1,intList)) assert(0); /*return (1);*/
1228 #endif
1229
1230 if (Bio_Read_mint(2,intList)) assert(0); /*return (1);*/
1231 ctrl = intList[0];
1232 pr->sonref = intList[1];
1233 pr->refrule = MGIO_ECTRL_RF(ctrl)-1;
1234 if (pr->refrule>-1)
1235 {
1236 pr->nnewcorners = MGIO_ECTRL_NF(ctrl);
1237 pr->nmoved = MGIO_ECTRL_NM(ctrl);
1238 pr->refclass = MGIO_ECTRL_RC(ctrl);
1239 if (pr->nnewcorners+pr->nmoved>0)
1240 if (Bio_Read_mint(pr->nnewcorners+pr->nmoved,intList)) assert(0); /*return (1);*/
1241 s=0;
1242 for (j=0; j<pr->nnewcorners; j++)
1243 pr->newcornerid[j] = intList[s++];
1244 for (j=0; j<pr->nmoved; j++)
1245 pr->mvcorner[j].id = intList[s++];
1246 if (pr->nmoved>0)
1247 {
1248 if (Bio_Read_mdouble(MGIO_DIM*pr->nmoved,doubleList)) assert(0); /*return (1);*/
1249 s=0;
1250 for (j=0; j<pr->nmoved; j++)
1251 for (k=0; k<MGIO_DIM; k++)
1252 pr->mvcorner[j].position[k] = doubleList[s++];
1253 }
1254 }
1255
1256 if (MGIO_PARFILE)
1257 {
1258 pr->orphanid_ex = MGIO_ECTRL_ON(ctrl);
1259 s=2; if (pr->orphanid_ex) s+= pr->nnewcorners;
1260 if (Bio_Read_mint(s,intList)) assert(0); /*return (1);*/
1261 s=0;
1262 pr->sonex = intList[s++];
1263 pr->nbid_ex = intList[s++];
1264 if (pr->orphanid_ex)
1265 for (j=0; j<pr->nnewcorners; j++)
1266 pr->orphanid[j] = intList[s++];
1267 for (k=0; k<MGIO_MAX_SONS_OF_ELEM; k++)
1268 if ((pr->sonex>>k)&1)
1269 {
1270 tag = rr_rules[pr->refrule].sons[k].tag;
1271 if (Read_pinfo(tag,&pr->pinfo[k])) assert(0); /*return (1);*/
1272 if ((pr->nbid_ex>>k)&1)
1273 {
1274 if (Bio_Read_mint(lge[tag].nSide,intList)) assert(0); /*return (1);*/
1275 for (j=0; j<lge[tag].nSide; j++)
1276 pr->nbid[k][j] = intList[j];
1277 }
1278 }
1279 }
1280
1281 #if (MGIO_DEBUG>0)
1282 /* read debug extension */
1283
1284 /* read mykey */
1285 if (Bio_Read_mint(1,&(pr->mykey))) assert(0); /*return (1);*/
1286
1287 /* read myfatherkey */
1288 if (Bio_Read_mint(1,&(pr->myfatherkey))) assert(0); /*return (1);*/
1289
1290 /* read nbkey[] */
1291 if (Bio_Read_mint(MGIO_MAX_SIDES_OF_ELEM,pr->nbkey)) assert(0); /*return (1);*/
1292
1293 /* read mycorners */
1294 if (Bio_Read_mint(1,&(pr->mycorners))) assert(0); /*return (1);*/
1295 assert(pr->mycorners>0);
1296
1297 if (Bio_Read_mint(3*pr->mycorners,intList)) assert(0); /*return (1);*/
1298 s=0;
1299 for (j=0; j<pr->mycorners; j++)
1300 {
1301 pr->mycornerkey[j] = intList[s++];
1302 pr->mycornerfatherkey[j] = intList[s++];
1303 pr->mycornersonkey[j] = intList[s++];
1304 }
1305
1306 if (pr->refrule>-1)
1307 {
1308 if (MGIO_PARFILE)
1309 {
1310 /* read sonskey[], sonsnbkey[][] and nbkey[][] */
1311 for (k=0; k<MGIO_MAX_SONS_OF_ELEM; k++)
1312 if ((pr->sonex>>k)&1)
1313 {
1314 tag = rr_rules[pr->refrule].sons[k].tag;
1315 s = 1+lge[tag].nSide;
1316 if (Bio_Read_mint(s,intList)) assert(0); /*return (1);*/
1317
1318 s=0;
1319 pr->sonskey[k] = intList[s++];
1320 for (j=0; j<lge[tag].nSide; j++)
1321 pr->sonsnbkey[k][j] = intList[s++];
1322 }
1323 else
1324 pr->sonskey[k] = -1 ;
1325 }
1326
1327 }
1328 #endif
1329 return (0);
1330 }
1331
1332 /****************************************************************************/
1333 /*
1334 Write_HE_Refinement - writes hierarchical elements
1335
1336 SYNOPSIS:
1337 int Write_HE_Refinement (int n, MGIO_HE_ELEMENT *he_element);
1338
1339 PARAMETERS:
1340 . n - nb of hierarchical elements to write
1341 . he_element - hierarchical element
1342
1343 DESCRIPTION:
1344 function writes hierarchical elements
1345
1346 RETURN VALUE:
1347 INT
1348 .n 0 if ok
1349 .n 1 if read error.
1350
1351 SEE ALSO:
1352 */
1353 /****************************************************************************/
1354
Write_Refinement(MGIO_REFINEMENT * pr,MGIO_RR_RULE * rr_rules)1355 int NS_DIM_PREFIX Write_Refinement (MGIO_REFINEMENT *pr, MGIO_RR_RULE *rr_rules)
1356 {
1357 int j,k,s,t,tag;
1358
1359 #if (MGIO_DEBUG>0)
1360 static int g_count;
1361 if (Bio_Write_string("REFINEMENT_BEGIN")) return (1);
1362 if (Bio_Write_mint(1,&g_count)) return (1);
1363 g_count++;
1364 #endif
1365
1366 s=t=0;
1367 if (MGIO_PARFILE)
1368 {
1369 intList[s++] = MGIO_ECTRL(pr->refrule+1,pr->nnewcorners,pr->nmoved,pr->refclass,pr->orphanid_ex);
1370 }
1371 else
1372 {
1373 intList[s++] = MGIO_ECTRL(pr->refrule+1,pr->nnewcorners,pr->nmoved,pr->refclass,0);
1374 }
1375 intList[s++] = pr->sonref;
1376 if (pr->refrule>-1)
1377 {
1378 for (j=0; j<pr->nnewcorners; j++)
1379 intList[s++] = pr->newcornerid[j];
1380 for (j=0; j<pr->nmoved; j++)
1381 intList[s++] = pr->mvcorner[j].id;
1382 for (j=0; j<pr->nmoved; j++)
1383 for (k=0; k<MGIO_DIM; k++)
1384 doubleList[t++] = pr->mvcorner[j].position[k];
1385 }
1386
1387 MGIO_CHECK_INTSIZE(s);
1388 if (Bio_Write_mint(s,intList)) return (1);
1389 MGIO_CHECK_DOUBLESIZE(t);
1390 if (t>0) if (Bio_Write_mdouble(t,doubleList)) return (1);
1391
1392 if (MGIO_PARFILE)
1393 {
1394 s=0;
1395 intList[s++] = pr->sonex;
1396 intList[s++] = pr->nbid_ex;
1397 if (pr->orphanid_ex)
1398 for (j=0; j<pr->nnewcorners; j++)
1399 intList[s++] = pr->orphanid[j];
1400 if (Bio_Write_mint(s,intList)) return (1);
1401 for (k=0; k<MGIO_MAX_SONS_OF_ELEM; k++)
1402 if ((pr->sonex>>k)&1)
1403 {
1404 tag = rr_rules[pr->refrule].sons[k].tag;
1405 if (Write_pinfo(tag,&pr->pinfo[k])) return (1);
1406 if ((pr->nbid_ex>>k)&1)
1407 {
1408 for (j=0; j<lge[tag].nSide; j++)
1409 intList[j] = pr->nbid[k][j];
1410 if (Bio_Write_mint(lge[tag].nSide,intList)) return (1);
1411 }
1412 }
1413 }
1414
1415 #if (MGIO_DEBUG>0)
1416 /* write debug extension */
1417
1418 /* write mykey */
1419 if (Bio_Write_mint(1,&(pr->mykey))) assert(0); /*return (1);*/
1420
1421 /* write myfatherkey */
1422 if (Bio_Write_mint(1,&(pr->myfatherkey))) assert(0); /*return (1);*/
1423
1424 /* write nbkey[] */
1425 MGIO_CHECK_INTSIZE(MGIO_MAX_SIDES_OF_ELEM);
1426 if (Bio_Write_mint(MGIO_MAX_SIDES_OF_ELEM,pr->nbkey)) assert(0); /*return (1);*/
1427
1428 /* write mycorners */
1429 if (Bio_Write_mint(1,&(pr->mycorners))) assert(0); /*return (1);*/
1430 assert(pr->mycorners > 0);
1431
1432 s=0;
1433 for (j=0; j<pr->mycorners; j++)
1434 {
1435 intList[s++] = pr->mycornerkey[j];
1436 intList[s++] = pr->mycornerfatherkey[j];
1437 intList[s++] = pr->mycornersonkey[j];
1438 }
1439 MGIO_CHECK_INTSIZE(s);
1440 if (Bio_Write_mint(s,intList)) assert(0); /*return (1);*/
1441
1442 if (pr->refrule>-1)
1443 {
1444 if (MGIO_PARFILE)
1445 {
1446 /* write sonskey[], sonsnbkey[][] and nbkey[][] */
1447 for (k=0; k<MGIO_MAX_SONS_OF_ELEM; k++)
1448 if ((pr->sonex>>k)&1)
1449 {
1450 s=0;
1451 tag = rr_rules[pr->refrule].sons[k].tag;
1452 intList[s++] = pr->sonskey[k];
1453
1454 for (j=0; j<lge[tag].nSide; j++)
1455 intList[s++] = pr->sonsnbkey[k][j];
1456
1457 MGIO_CHECK_INTSIZE(s);
1458 if (Bio_Write_mint(s,intList)) assert(0); /*return (1);*/
1459 }
1460 }
1461 }
1462
1463 #endif
1464
1465 return (0);
1466 }
1467
1468 /****************************************************************************/
1469 /*
1470 Read_BD_General - reads general information about boundary description
1471
1472 SYNOPSIS:
1473 int Read_BD_General (MGIO_BD_GENERAL *bd_general);
1474
1475 PARAMETERS:
1476 . bd_general - information about boundary description
1477
1478 DESCRIPTION:
1479 function reads general information about boundary description
1480
1481 RETURN VALUE:
1482 INT
1483 .n 0 if ok
1484 .n 1 if read error.
1485
1486 SEE ALSO:
1487 */
1488 /****************************************************************************/
1489
Read_BD_General(MGIO_BD_GENERAL * bd_general)1490 int NS_DIM_PREFIX Read_BD_General (MGIO_BD_GENERAL *bd_general)
1491 {
1492 if (Bio_Read_mint(1,intList)) return (1);
1493 bd_general->nBndP = intList[0];
1494
1495 return (0);
1496 }
1497
1498 /****************************************************************************/
1499 /*
1500 Write_BD_General - writes general information about boundary description
1501
1502 SYNOPSIS:
1503 int Write_BD_General (MGIO_BD_GENERAL *bd_general);
1504
1505 PARAMETERS:
1506 . bd_general - information about boundary description
1507
1508 DESCRIPTION:
1509 function writes general information about boundary description
1510
1511 RETURN VALUE:
1512 INT
1513 .n 0 if ok
1514 .n 1 if read error.
1515
1516 SEE ALSO:
1517 */
1518 /****************************************************************************/
1519
Write_BD_General(MGIO_BD_GENERAL * bd_general)1520 int NS_DIM_PREFIX Write_BD_General (MGIO_BD_GENERAL *bd_general)
1521 {
1522 intList[0] = bd_general->nBndP;
1523 if (Bio_Write_mint(1,intList)) return (1);
1524
1525 return (0);
1526 }
1527
1528 /****************************************************************************/
1529 /*
1530 Read_PBndDesc - reads BNDPs
1531
1532 SYNOPSIS:
1533 int Read_PBndDesc (MGIO_HEAP *theHeap, int n, BNDP **BndPList);
1534
1535 PARAMETERS:
1536 . theHeap - heap
1537 . n - nb of BndP to read
1538 . BndPList - list of ptrs to BndP
1539
1540 DESCRIPTION:
1541 function reads BNDPs
1542
1543 RETURN VALUE:
1544 INT
1545 .n 0 if ok
1546 .n 1 if read error.
1547
1548 SEE ALSO:
1549 */
1550 /****************************************************************************/
1551
1552 #ifdef __MGIO_USE_IN_UG__
1553
Read_PBndDesc(BVP * theBVP,HEAP * theHeap,int n,BNDP ** BndPList)1554 int NS_DIM_PREFIX Read_PBndDesc (BVP *theBVP, HEAP *theHeap, int n, BNDP **BndPList)
1555 {
1556 int i;
1557
1558 if (theBVP!=NULL && theHeap==NULL) return (1);
1559 if (theBVP!=NULL)
1560 {
1561 for (i=0; i<n; i++)
1562 {
1563 BndPList[i] = BNDP_LoadBndP (theBVP,theHeap);
1564 if (BndPList[i]==NULL) return (1);
1565 }
1566 }
1567 else
1568 {
1569 for (i=0; i<n; i++)
1570 {
1571 BndPList[i] = BNDP_LoadBndP_Ext ();
1572 if (BndPList[i]==NULL) return (1);
1573 }
1574 }
1575 return (0);
1576 }
1577
1578 #endif
1579
1580 /****************************************************************************/
1581 /*
1582 Write_PBndDesc - write BNDPs
1583
1584 SYNOPSIS:
1585 int Write_PBndDesc (int n, BNDP **BndPList);
1586
1587 PARAMETERS:
1588 . n - nb of BndP to write
1589 . BndPList - list of ptrs to BndP
1590
1591 DESCRIPTION:
1592 function writes BNDPs
1593
1594 RETURN VALUE:
1595 INT
1596 .n 0 if ok
1597 .n 1 if read error.
1598
1599 SEE ALSO:
1600 */
1601 /****************************************************************************/
1602
1603 #ifdef __MGIO_USE_IN_UG__
1604
Write_PBndDesc(int n,BNDP ** BndPList)1605 int NS_DIM_PREFIX Write_PBndDesc (int n, BNDP **BndPList)
1606 {
1607 int i;
1608
1609 if (n>0)
1610 {
1611 for (i=0; i<n; i++)
1612 if (BNDP_SaveBndP (BndPList[i])) return (1);
1613 }
1614 else
1615 {
1616 n=-n;
1617 for (i=0; i<n; i++)
1618 if (BNDP_SaveBndP_Ext (BndPList[i])) return (1);
1619 }
1620 return (0);
1621 }
1622
1623 #endif
1624
1625 /****************************************************************************/
1626 /*
1627 CloseMGFile - close the file
1628
1629 SYNOPSIS:
1630 int CloseMGFile ();
1631
1632 PARAMETERS:
1633
1634 DESCRIPTION:
1635 close the file
1636
1637 RETURN VALUE:
1638 INT
1639 .n 0 if ok
1640 .n 1 if read error.
1641
1642 SEE ALSO:
1643 */
1644 /****************************************************************************/
1645
CloseMGFile(void)1646 int NS_DIM_PREFIX CloseMGFile (void)
1647 {
1648 if (fclose(stream)!=0) return (1);
1649 return (0);
1650 }
1651
1652 /****************************************************************************/
1653 /*
1654 MGIO_Init - init input/output for mg
1655
1656 SYNOPSIS:
1657 int MGIO_Init (void);
1658
1659 PARAMETERS:
1660
1661 DESCRIPTION:
1662 init the i/o of mg
1663
1664 RETURN VALUE:
1665 INT
1666 .n 0 if ok
1667 .n 1 if read error.
1668
1669 SEE ALSO:
1670 */
1671 /****************************************************************************/
1672
MGIO_Init()1673 int NS_DIM_PREFIX MGIO_Init ()
1674 {
1675
1676 #ifdef __MGIO_USE_IN_UG__
1677
1678 /* check consistency with output macros */
1679 MGIO_CHECKEXTMACROS;
1680
1681 /* path to grid-dirs */
1682 mgpathes_set = 0;
1683 if (ReadSearchingPaths("defaults","mgpaths")==0)
1684 mgpathes_set = 1;
1685
1686 #endif
1687
1688 return (0);
1689 }
1690