1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 /*! \file refine.h
4  * \ingroup gm
5  */
6 
7 
8 /****************************************************************************/
9 /*                                                                                                                                                      */
10 /* File:          refine.h                                                                                                              */
11 /*                                                                                                                                                      */
12 /* Purpose:   definitions for two AND three dimensional refinement                      */
13 /*                                                                                                                                                      */
14 /* Author:        Peter Bastian                                                                                                 */
15 /*                        Interdisziplinaeres Zentrum fuer Wissenschaftliches Rechnen   */
16 /*                        Universitaet Heidelberg                                                                               */
17 /*                        Im Neuenheimer Feld 368                                                                               */
18 /*                        6900 Heidelberg                                                                                               */
19 /*                        internet: bastian@iwr1.iwr.uni-heidelberg.de                                  */
20 /*                                                                                                                                                      */
21 /* History:   09.03.92 begin, ug version 2.0                                                            */
22 /*                                                                                                                                                      */
23 /* Remarks:                                                                                                                             */
24 /*                                                                                                                                                      */
25 /****************************************************************************/
26 
27 
28 /****************************************************************************/
29 /*                                                                                                                                                      */
30 /* auto include mechanism and other include files                                                       */
31 /*                                                                                                                                                      */
32 /****************************************************************************/
33 
34 #ifndef __REFINE__
35 #define __REFINE__
36 
37 #include <dune/uggrid/low/namespace.h>
38 #include <dune/uggrid/low/ugtypes.h>
39 #include "gm.h"
40 #include "algebra.h"            /* just for ALGEBRA_N_CE */
41 
42 START_UGDIM_NAMESPACE
43 
44 /****************************************************************************/
45 /*                                                                          */
46 /* defines in the following order                                           */
47 /*                                                                          */
48 /*        compile time constants defining static data size (i.e. arrays)    */
49 /*        other constants                                                   */
50 /*        macros                                                            */
51 /*                                                                          */
52 /****************************************************************************/
53 
54 #define NOTUSED    -1                      /* SHORT has to be signed!       */
55 #define NO_CENTER_NODE     NOTUSED
56 
57 #ifdef ModelP
58 /* undefine if all son objects shall be identified */
59 #define IDENT_ONLY_NEW
60 #endif
61 
62 /* define this if you want to apply anistropic rules */
63 /* #define __ANISOTROPIC__ */
64 
65 
66 /****************************************************************************/
67 /*                                                                          */
68 /* control word definitions                                                 */
69 /*                                                                          */
70 /****************************************************************************/
71 
72 enum REFINE_CE {
73 
74   PATTERN_CE = ALGEBRA_N_CE,            /* continue after algebra.h entries             */
75   ADDPATTERN_CE,
76   REFINE_CE,
77   MARK_CE,
78   COARSEN_CE,
79   DECOUPLED_CE,
80   REFINECLASS_CE,
81   UPDATE_GREEN_CE,
82   SIDEPATTERN_CE,
83   MARKCLASS_CE,
84 
85   REFINE_N_CE
86 };
87 
88 /* edges */
89 #define PATTERN_SHIFT                           10
90 #define PATTERN_LEN                             1
91 #define PATTERN(p)                                      CW_READ(p,PATTERN_CE)
92 #define SETPATTERN(p,n)                         CW_WRITE(p,PATTERN_CE,n)
93 
94 #define ADDPATTERN_SHIFT                        11
95 #define ADDPATTERN_LEN                          1
96 #define ADDPATTERN(p)                           CW_READ(p,ADDPATTERN_CE)
97 #define SETADDPATTERN(p,n)                      CW_WRITE(p,ADDPATTERN_CE,n)
98 
99 
100 /* element */
101 #define REFINE_SHIFT                                    0
102 #define REFINE_LEN                                              8
103 #define REFINE(p)                                               CW_READ(p,REFINE_CE)
104 #define SETREFINE(p,n)                                  CW_WRITE(p,REFINE_CE,n)
105 
106 #define MARK_SHIFT                                              0
107 #define MARK_LEN                                                8
108 #define MARK(p)                                                 CW_READ(p,MARK_CE)
109 #define SETMARK(p,n)                                    CW_WRITE(p,MARK_CE,n)
110 
111 #define COARSEN_SHIFT                                   10
112 #define COARSEN_LEN                                     1
113 #define COARSEN(p)                                              CW_READ(p,COARSEN_CE)
114 #define SETCOARSEN(p,n)                                 CW_WRITE(p,COARSEN_CE,n)
115 
116 #define DECOUPLED_SHIFT                                 12
117 #define DECOUPLED_LEN                                   1
118 #define DECOUPLED(p)                                    CW_READ(p,DECOUPLED_CE)
119 #define SETDECOUPLED(p,n)                               CW_WRITE(p,DECOUPLED_SHIFT,n)
120 
121 #define REFINECLASS_SHIFT                               15
122 #define REFINECLASS_LEN                                 2
123 #define REFINECLASS(p)                                  CW_READ(p,REFINECLASS_CE)
124 #define SETREFINECLASS(p,n)                     CW_WRITE(p,REFINECLASS_CE,n)
125 
126 #define UPDATE_GREEN_SHIFT                              8
127 #define UPDATE_GREEN_LEN                                1
128 #define UPDATE_GREEN(p)                                 CW_READ(p,UPDATE_GREEN_CE)
129 #define SETUPDATE_GREEN(p,n)                    CW_WRITE(p,UPDATE_GREEN_CE,n)
130 
131 #define SIDEPATTERN_SHIFT                               0
132 #define SIDEPATTERN_LEN                                 6
133 #define SIDEPATTERN(p)                                  CW_READ(p,SIDEPATTERN_CE)
134 #define SETSIDEPATTERN(p,n)                     CW_WRITE(p,SIDEPATTERN_CE,n)
135 
136 #define MARKCLASS_SHIFT                                 13
137 #define MARKCLASS_LEN                                   2
138 #define MARKCLASS(p)                                    CW_READ(p,MARKCLASS_CE)
139 #define SETMARKCLASS(p,n)                               CW_WRITE(p,MARKCLASS_CE,n)
140 
141 #ifdef ModelP
142 #define NEW_NIDENT_LEN                 2
143 #define NEW_NIDENT(p)                  CW_READ(p,ce_NEW_NIDENT)
144 #define SETNEW_NIDENT(p,n)             CW_WRITE(p,ce_NEW_NIDENT,n)
145 
146 #define NEW_EDIDENT_LEN                2
147 #define NEW_EDIDENT(p)                 CW_READ(p,ce_NEW_EDIDENT)
148 #define SETNEW_EDIDENT(p,n)            CW_WRITE(p,ce_NEW_EDIDENT,n)
149 #endif
150 
151 /* macros for refineinfo */
152 #define RINFO_MAX                                               100
153 #define REFINEINFO(mg)                                  refine_info
154 #define REFINESTEP(r)                                   (r).step
155 #define SETREFINESTEP(r,s)                              (r).step = ((s)%RINFO_MAX)
156 #define MARKCOUNT(r)                                    (r).markcount[(r).step]
157 #define SETMARKCOUNT(r,n)                               (r).markcount[(r).step] = (n)
158 #define PREDNEW0(r)                                             (r).predicted_new[(r).step][0]
159 #define SETPREDNEW0(r,n)                                (r).predicted_new[(r).step][0] = (n)
160 #define PREDNEW1(r)                                             (r).predicted_new[(r).step][1]
161 #define SETPREDNEW1(r,n)                                (r).predicted_new[(r).step][1] = (n)
162 #define PREDNEW2(r)                                             (r).predicted_new[(r).step][2]
163 #define SETPREDNEW2(r,n)                                (r).predicted_new[(r).step][2] = (n)
164 #define REAL(r)                                                 (r).real[(r).step]
165 #define SETREAL(r,n)                                    (r).real[(r).step] = (n)
166 #define PREDMAX(r)                                              (r).predicted_max[(r).step]
167 #define SETPREDMAX(r,n)                                 (r).predicted_max[(r).step] = (n)
168 
169 /* macros for listing */
170 #define REFINE_ELEMENT_LIST(d,e,s)                                           \
171   IFDEBUG(gm,d)                                                            \
172   if (e!=NULL)                                                             \
173     UserWriteF( s " ID=%d/%08x PRIO=%d TAG=%d BE=%d ECLASS=%d LEVEL=%d"  \
174                 " REFINECLASS=%d MARKCLASS=%d REFINE=%d MARK=%d COARSE=%d"           \
175                 " USED=%d NSONS=%d EFATHERID=%d SIDEPATTERN=%d\n",                   \
176                 ID(e),EGID(e),EPRIO(e),TAG(e),(OBJT(e)==BEOBJ),ECLASS(e),LEVEL(e),   \
177                 REFINECLASS(e),MARKCLASS(e),REFINE(e),MARK(e),COARSEN(e),            \
178                 USED(e),NSONS(e),(EFATHER(e)!=NULL) ? ID(EFATHER(e)) : 0,SIDEPATTERN(e));\
179   ENDDEBUG
180 
181 
182 #define REFINE_GRID_LIST(d,mg,k,s1,s2)                                       \
183   IFDEBUG(gm,d)                                                            \
184   {                                                                        \
185     GRID    *grid = GRID_ON_LEVEL(mg,k);                                 \
186     ELEMENT *theElement;                                                 \
187                                                                              \
188     UserWriteF s1 ;                                                      \
189     for (theElement=PFIRSTELEMENT(grid);                                 \
190          theElement!=NULL;                                               \
191          theElement=SUCCE(theElement))                                   \
192     {                                                                    \
193       REFINE_ELEMENT_LIST(d,theElement,s2)                             \
194     }                                                                                \
195   }                                                                        \
196   ENDDEBUG
197 
198 
199 #define REFINE_MULTIGRID_LIST(d,mg,s1,s2,s3)                                 \
200   IFDEBUG(gm,d)                                                            \
201   {                                                                        \
202     INT k;                                                               \
203                                                                              \
204     UserWriteF( s1 );                                                    \
205     for (k=0; k<=TOPLEVEL(mg); k++)                                      \
206     {                                                                    \
207       GRID    *grid = GRID_ON_LEVEL(mg,k);                             \
208       ELEMENT *theElement;                                             \
209                                                                              \
210       UserWriteF( s2 );                                                \
211       for (theElement=PFIRSTELEMENT(grid);                             \
212            theElement!=NULL;                                           \
213            theElement=SUCCE(theElement))                               \
214       {                                                                \
215         REFINE_ELEMENT_LIST(d,theElement,s3)                         \
216       }                                                                            \
217     }                                                                    \
218   }                                                                        \
219   ENDDEBUG
220 
221 /****************************************************************************/
222 /*                                                                                                                                                      */
223 /* typedefs                                                                                                                                     */
224 /*                                                                                                                                                      */
225 /****************************************************************************/
226 
227 typedef struct refineinfo
228 {
229   INT step;                                               /* count of calls to AdaptMultiGrid   */
230   float markcount[RINFO_MAX];             /* count of currently marked elements */
231   float predicted_new[RINFO_MAX][3];
232   /* count of elements, would be created */
233   float real[RINFO_MAX];                      /* count of elements before refinement */
234   float predicted_max[RINFO_MAX];        /* count of elements which can be created */
235 } REFINEINFO;
236 
237 typedef INT (*Get_Sons_of_ElementSideProcPtr)(ELEMENT *theElement, INT side, INT *Sons_of_Side,ELEMENT *SonList[MAX_SONS], INT *SonSides, INT NeedSons);
238 
239 /****************************************************************************/
240 /*                                                                          */
241 /* definition of exported global variables                                  */
242 /*                                                                          */
243 /****************************************************************************/
244 
245 extern REFINEINFO refine_info;
246 #ifdef ModelP
247 extern INT ce_NEW_NIDENT;
248 extern INT ce_NEW_EDIDENT;
249 #endif
250 
251 /****************************************************************************/
252 /*                                                                                                                                                      */
253 /* functions exported                                                                                                           */
254 /*                                                                                                                                                      */
255 /****************************************************************************/
256 
257 INT     GetSonSideNodes                                                 (const ELEMENT *theElement, INT side, INT *nodes, NODE *SideNodes[MAX_SIDE_NODES], INT ioflag);
258 INT Get_Sons_of_ElementSide(const ELEMENT *theElement,
259                             INT side,
260                             INT *Sons_of_Side,
261                             ELEMENT *SonList[MAX_SONS],
262                             INT *SonSides,
263                             INT NeedSons,
264                             INT ioflag,
265                             INT useRefineClass=0);
266 INT     Connect_Sons_of_ElementSide                     (GRID *theGrid, ELEMENT *theElement, INT side, INT Sons_of_Side, ELEMENT **Sons_of_Side_List, INT *SonSides, INT ioflag);
267 INT             Refinement_Changes                                              (ELEMENT *theElement);
268 
269 END_UGDIM_NAMESPACE
270 
271 #endif
272