| 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 rm.h |
| 6 |
* \ingroup gm |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
/****************************************************************************/ |
| 11 |
/* */ |
| 12 |
/* File: rule manager header file */ |
| 13 |
/* */ |
| 14 |
/* Purpose: defines data structures for refinement rules */ |
| 15 |
/* */ |
| 16 |
/* Author: Stefan Lang */ |
| 17 |
/* Institut fuer Computeranwendungen III */ |
| 18 |
/* Universitaet Stuttgart */ |
| 19 |
/* Pfaffenwaldring 27 */ |
| 20 |
/* 70550 Stuttgart */ |
| 21 |
/* */ |
| 22 |
/* History: 20.11.95 begin, ugp version 3.0 */ |
| 23 |
/* */ |
| 24 |
/* Remarks: */ |
| 25 |
/* */ |
| 26 |
/****************************************************************************/ |
| 27 |
|
| 28 |
|
| 29 |
/****************************************************************************/ |
| 30 |
/* */ |
| 31 |
/* auto include mechanism and other include files */ |
| 32 |
/* */ |
| 33 |
/****************************************************************************/ |
| 34 |
|
| 35 |
#ifndef __RULEMANAGER__ |
| 36 |
#define __RULEMANAGER__ |
| 37 |
|
| 38 |
#include <memory> |
| 39 |
|
| 40 |
#include "gm.h" |
| 41 |
#include "refine.h" |
| 42 |
|
| 43 |
#include <dune/uggrid/low/namespace.h> |
| 44 |
|
| 45 |
START_UGDIM_NAMESPACE |
| 46 |
|
| 47 |
/****************************************************************************/ |
| 48 |
/* */ |
| 49 |
/* defines in the following order */ |
| 50 |
/* */ |
| 51 |
/* compile time constants defining static data size (i.e. arrays) */ |
| 52 |
/* other constants */ |
| 53 |
/* macros */ |
| 54 |
/* */ |
| 55 |
/****************************************************************************/ |
| 56 |
|
| 57 |
/* Declaration of DUNE_UGGRID_TET_RULESET has been moved to config.h */ |
| 58 |
/* uncomment this if you want to use the full rule set for tetrahedra */ |
| 59 |
|
| 60 |
/** \brief Defines for edge types */ |
| 61 |
enum {INNER_EDGE = 1, |
| 62 |
SIDE_EDGE = 2, |
| 63 |
HALF_FATHER_EDGE = 3, |
| 64 |
FATHER_EDGE = 4}; |
| 65 |
|
| 66 |
#define NEXTSIDEMASKHEX 0x00000007 |
| 67 |
#define NEXTSIDEHEX(i,n) (((i) & (NEXTSIDEMASKHEX<<(3*(n))))>>(3*(n))) |
| 68 |
|
| 69 |
#define FATHER_SIDE_OFFSET 100 /* greater values indicate outside faces */ |
| 70 |
|
| 71 |
#define MAX_NEW_CORNERS(tag) MaxNewCorners[(tag)] /* midpoints on edges and sides plus center */ |
| 72 |
#define MAX_NEW_EDGES(tag) MaxNewEdges[(tag)] /* maximal new edges of type 1/2 */ |
| 73 |
#define MAX_RULES(tag) MaxRules[(tag)] /* number of rules for one element type */ |
| 74 |
#define CENTER_NODE_INDEX(e) CenterNodeIndex[TAG(e)] /* index of centernode in sonandnode and elemcontext */ |
| 75 |
#define CENTER_NODE_INDEX_TAG(t) CenterNodeIndex[(t)] /* index of centernode in sonandnode and elemcontext */ |
| 76 |
|
| 77 |
#define MARK2RULE(e,m) (m) |
| 78 |
#define MARK2RULEADR(e,m) (&(RefRules[TAG(e)][(m)])) |
| 79 |
#define RULE2PATTERN(e,r) (RefRules[TAG(e)][(r)].pattern) |
| 80 |
#define RULE2PAT(e,r) (RefRules[TAG(e)][(r)].pat) |
| 81 |
#define MARK2PAT(e,r) (RefRules[TAG(e)][(r)].pat) |
| 82 |
#define MARK2PATTERN(e,m) (RefRules[TAG(e)][(m)].pattern) |
| 83 |
|
| 84 |
#define PATTERN2RULE(e,p) (Patterns2Rules((e),(p))) |
| 85 |
#define RULE2MARK(e,r) (RefRules[TAG(e)][(r)].mark) |
| 86 |
#define PATTERN2MARK(e,p) (((PATTERN2RULE((e),(p)))>=0) ? (RefRules[TAG(e)][PATTERN2RULE((e),(p))].mark) : -1) |
| 87 |
|
| 88 |
#ifdef __SR2201__ |
| 89 |
#define NODE_OF_RULE(e,m,i) ((*MARK2RULEADR((e),(m))).sonandnode[(i)][0]!=-1) |
| 90 |
#else |
| 91 |
#define NODE_OF_RULE(e,m,i) (MARK2RULEADR((e),(m))->sonandnode[(i)][0]!=-1) |
| 92 |
#endif |
| 93 |
|
| 94 |
#define CONCAT(a,b,c) CONCAT_AUX(a,b,c) |
| 95 |
#define CONCAT_AUX(a,b,c) a ## b ## c |
| 96 |
|
| 97 |
/* dimension dependent MAX_CORNERS_OF_ELEM */ |
| 98 |
#define MAX_CORNERS_OF_ELEM_2D 4 |
| 99 |
#define MAX_CORNERS_OF_ELEM_3D 8 |
| 100 |
#define MAX_CORNERS_OF_ELEM_DIM CONCAT(MAX_CORNERS_OF_ELEM_,DIM,D) |
| 101 |
|
| 102 |
/* dimension dependent MAX_EDGES_OF_ELEM */ |
| 103 |
#define MAX_EDGES_OF_ELEM_2D 4 |
| 104 |
#define MAX_EDGES_OF_ELEM_3D 12 |
| 105 |
#define MAX_EDGES_OF_ELEM_DIM CONCAT(MAX_EDGES_OF_ELEM_,DIM,D) |
| 106 |
|
| 107 |
/* dimension dependent MAX_NEW_CORNERS */ |
| 108 |
#define MAX_NEW_CORNERS_2D 5 |
| 109 |
#define MAX_NEW_CORNERS_3D 19 |
| 110 |
#define MAX_NEW_CORNERS_DIM CONCAT(MAX_NEW_CORNERS_,DIM,D) |
| 111 |
|
| 112 |
/* dimension dependent MAX_NEW_EDGES */ |
| 113 |
#define MAX_NEW_EDGES_2D 12 |
| 114 |
#define MAX_NEW_EDGES_3D 54 |
| 115 |
#define MAX_NEW_EDGES_DIM CONCAT(MAX_NEW_EDGES_,DIM,D) |
| 116 |
|
| 117 |
/* dimension dependent MAX_SIDES_OF_ELEM */ |
| 118 |
#define MAX_SIDES_OF_ELEM_2D 4 |
| 119 |
#define MAX_SIDES_OF_ELEM_3D 6 |
| 120 |
#define MAX_SIDES_OF_ELEM_DIM CONCAT(MAX_SIDES_OF_ELEM_,DIM,D) |
| 121 |
|
| 122 |
/* dimension dependent MAX_SONS */ |
| 123 |
#define MAX_SONS_2D 4 |
| 124 |
#define MAX_SONS_3D 12 |
| 125 |
#define MAX_SONS_DIM CONCAT(MAX_SONS_,DIM,D) |
| 126 |
|
| 127 |
#if FATHER_SIDE_OFFSET<MAX_SONS |
| 128 |
#error /* increase FATHER_SIDE_OFFSET correspondigly */ |
| 129 |
#endif |
| 130 |
|
| 131 |
/* max fine grid nodes of an element */ |
| 132 |
#define MAX_REFINED_CORNERS_DIM (MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM) |
| 133 |
|
| 134 |
#define IS_REFINED(e) (REFINE(e)!=NO_REFINEMENT) |
| 135 |
#define MARKED(e) (MARK(e)!=NO_REFINEMENT) |
| 136 |
#define LEAFELEM(e) (!IS_REFINED(e)) |
| 137 |
|
| 138 |
/** \brief Indices of rules in rule array */ |
| 139 |
enum {T_NOREF = 0, |
| 140 |
T_COPY = 1, |
| 141 |
T_RED = 2, |
| 142 |
T_BISECT_1_0 = 3, |
| 143 |
T_BISECT_1_1 = 4, |
| 144 |
T_BISECT_1_2 = 5, |
| 145 |
T_BISECT_2_T1_0 = 7, |
| 146 |
T_BISECT_2_T1_1 = 8, |
| 147 |
T_BISECT_2_T1_2 = 6, |
| 148 |
T_BISECT_2_T2_0 = 11, |
| 149 |
T_BISECT_2_T2_1 = 9, |
| 150 |
T_BISECT_2_T2_2 = 10, |
| 151 |
T_BISECT_2_Q_0 = 12, |
| 152 |
T_BISECT_2_Q_1 = 13, |
| 153 |
T_BISECT_2_Q_2 = 14, |
| 154 |
T_BISECT_3_0 = 15, |
| 155 |
T_BISECT_3_1 = 16, |
| 156 |
T_BISECT_3_2 = 17}; |
| 157 |
|
| 158 |
enum {Q_NOREF, |
| 159 |
Q_COPY, |
| 160 |
Q_RED, |
| 161 |
Q_CLOSE_1_0, |
| 162 |
Q_CLOSE_1_1, |
| 163 |
Q_CLOSE_1_2, |
| 164 |
Q_CLOSE_1_3, |
| 165 |
Q_BLUE_0, |
| 166 |
Q_BLUE_1, |
| 167 |
Q_CLOSE_2_0, |
| 168 |
Q_CLOSE_2_1, |
| 169 |
Q_CLOSE_2_2, |
| 170 |
Q_CLOSE_2_3, |
| 171 |
Q_CLOSE_3_0, |
| 172 |
Q_CLOSE_3_1, |
| 173 |
Q_CLOSE_3_2, |
| 174 |
Q_CLOSE_3_3}; |
| 175 |
|
| 176 |
#define TET_COPY 1 |
| 177 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 178 |
#define FULL_REFRULE Pattern2Rule[TETRAHEDRON][0x3F] |
| 179 |
#define FULL_REFRULE_0_5 (Pattern2Rule[TETRAHEDRON][0x3F]+1) |
| 180 |
#define FULL_REFRULE_1_3 (Pattern2Rule[TETRAHEDRON][0x3F]+2) |
| 181 |
#define FULL_REFRULE_2_4 (Pattern2Rule[TETRAHEDRON][0x3F]+0) |
| 182 |
#define TET_RED FULL_REFRULE |
| 183 |
#define TET_RED_0_5 FULL_REFRULE_0_5 |
| 184 |
#define TET_RED_1_3 FULL_REFRULE_1_3 |
| 185 |
#define TET_RED_2_4 FULL_REFRULE_2_4 |
| 186 |
#else |
| 187 |
#define TET_RED 2 |
| 188 |
#define TET_RED_0_5 3 |
| 189 |
#define TET_RED_1_3 4 |
| 190 |
#define TET_RED_2_4 2 |
| 191 |
#define FULL_REFRULE TET_RED |
| 192 |
#define FULL_REFRULE_0_5 TET_RED_0_5 |
| 193 |
#define FULL_REFRULE_1_3 TET_RED_1_3 |
| 194 |
#define FULL_REFRULE_2_4 TET_RED_2_4 |
| 195 |
#define TET_RED_HEX 5 |
| 196 |
#endif |
| 197 |
|
| 198 |
enum {PYR_COPY = 1, |
| 199 |
PYR_RED = 2, |
| 200 |
PYR_BISECT_0_1 = 3, |
| 201 |
PYR_BISECT_0_2 = 4}; |
| 202 |
|
| 203 |
enum {PRI_COPY = 1, |
| 204 |
PRI_RED = 2, |
| 205 |
PRI_QUADSECT = 3, |
| 206 |
PRI_BISECT_0_1 = 4, |
| 207 |
PRI_BISECT_0_2 = 5, |
| 208 |
PRI_BISECT_0_3 = 6, |
| 209 |
PRI_BISECT_1_2 = 7, |
| 210 |
PRI_BISECT_HEX0 = 8, |
| 211 |
PRI_BISECT_HEX1 = 9, |
| 212 |
PRI_BISECT_HEX2 = 10, |
| 213 |
PRI_RED_HEX = 11, |
| 214 |
PRI_ROT_L = 12, |
| 215 |
PRI_ROT_R = 13, |
| 216 |
PRI_QUADSECT_HEXPRI0 = 14}; |
| 217 |
|
| 218 |
enum {HEXA_COPY = 1, |
| 219 |
HEXA_RED = 2, |
| 220 |
HEXA_BISECT_0_1 = 3, |
| 221 |
HEXA_BISECT_0_2 = 4, |
| 222 |
HEXA_BISECT_0_3 = 5, |
| 223 |
HEXA_QUADSECT_0 = 6, |
| 224 |
HEXA_QUADSECT_1 = 7, |
| 225 |
HEXA_QUADSECT_2 = 8, |
| 226 |
HEXA_TRISECT_0 = 9, |
| 227 |
HEXA_TRISECT_5 = 10, |
| 228 |
HEXA_BISECT_HEXPRI0 = 11, |
| 229 |
HEXA_BISECT_HEXPRI1 = 12}; |
| 230 |
|
| 231 |
|
| 232 |
/****************************************************************************/ |
| 233 |
/* */ |
| 234 |
/* macros for rules */ |
| 235 |
/* */ |
| 236 |
/****************************************************************************/ |
| 237 |
|
| 238 |
#define TAG_OF_RULE(r) ((r)->tag) |
| 239 |
#define MARK_OF_RULE(r) ((r)->mark) |
| 240 |
#define CLASS_OF_RULE(r) ((r)->rclass) |
| 241 |
#define NSONS_OF_RULE(r) ((r)->nsons) |
| 242 |
#define SON_OF_RULE(r,s) (&((r)->sons[(s)])) |
| 243 |
#define PATTERN_OF_RULE(r,i) ((r)->pattern[(i)]) |
| 244 |
#define PAT_OF_RULE(r) ((r)->pat) |
| 245 |
#define SON_OF_NODE_OF_RULE(r,n) ((r)->sonandnode[(n)][0]) |
| 246 |
#define SONNODE_OF_NODE_OF_RULE(r,n)((r)->sonandnode[(n)][0]) |
| 247 |
#define SON_TAG_OF_RULE(r,s) ((r)->sons[(s)].tag) |
| 248 |
#define SON_TAG(s) ((s)->tag) |
| 249 |
#define SON_CORNER_OF_RULE(r,s,n) ((r)->sons[(s)].corners[(n)]) |
| 250 |
#define SON_CORNER(s,n) ((s)->corners[(n)]) |
| 251 |
#define SON_NB_OF_RULE(r,s,n) ((r)->sons[(s)].nb[(n)]) |
| 252 |
#define SON_NB(s,n) ((s)->nb[(n)]) |
| 253 |
#define SON_PATH_OF_RULE(r,s) ((r)->sons[(s)].path) |
| 254 |
#define SON_PATH(s) ((s)->path) |
| 255 |
|
| 256 |
/* macros for referencing of sons paths */ |
| 257 |
/* 4 high bits for no of neighbours to be passed */ |
| 258 |
#define PATHDEPTHMASK 0xF0000000 |
| 259 |
#define PATHDEPTHSHIFT 28 |
| 260 |
#define PATHDEPTH(i) (((i) & PATHDEPTHMASK)>>PATHDEPTHSHIFT) |
| 261 |
#define SETPATHDEPTH(i,val) (i) = ((i)&(~PATHDEPTHMASK))|(((val)<<PATHDEPTHSHIFT)&PATHDEPTHMASK) |
| 262 |
|
| 263 |
/* 3 bits at position n for element side */ |
| 264 |
#define NEXTSIDEMASK 0x00000007 |
| 265 |
#define NEXTSIDE(i,n) (((i) & (NEXTSIDEMASK<<(3*(n))))>>(3*(n))) |
| 266 |
#define SETNEXTSIDE(i,n,val) (i) = ((i)&(~(NEXTSIDEMASK<<(3*(n)))))|(((val)&NEXTSIDEMASK)<<(3*(n))) |
| 267 |
|
| 268 |
#define MAX_PATH_DEPTH (PATHDEPTHSHIFT/3) |
| 269 |
|
| 270 |
#define NOCLASS(c) ((c) == 0) |
| 271 |
#define YELLOWCLASS(c) ((c) & 1) |
| 272 |
#define GREENCLASS(c) ((c) & 2) |
| 273 |
#define REDCLASS(c) ((c) & 3) |
| 274 |
#define SWITCHCLASS(c) ((c) & 4) |
| 275 |
|
| 276 |
/****************************************************************************/ |
| 277 |
/* */ |
| 278 |
/* data structures exported by the corresponding source file */ |
| 279 |
/* */ |
| 280 |
/****************************************************************************/ |
| 281 |
|
| 282 |
typedef INT (*FULLREFRULEPTR)(ELEMENT *); |
| 283 |
|
| 284 |
typedef struct { |
| 285 |
/** \brief Fields for environment list variable */ |
| 286 |
NS_PREFIX ENVVAR v; |
| 287 |
|
| 288 |
/* full ref rule specific stuff */ |
| 289 |
FULLREFRULEPTR theFullRefRule; /* the best full refrule */ |
| 290 |
|
| 291 |
} FULLREFRULE; |
| 292 |
|
| 293 |
struct sondata { |
| 294 |
SHORT tag; /* which element type is the son */ |
| 295 |
SHORT corners[MAX_CORNERS_OF_ELEM_DIM]; /* corners of the son */ |
| 296 |
SHORT nb[MAX_SIDES_OF_ELEM_DIM]; /* neighbors of this son */ |
| 297 |
/* < FATHER_SIDE_OFFSET if nb has same father */ |
| 298 |
/* >= FATHER_SIDE_OFFSET if nb has other father*/ |
| 299 |
INT path; /* path used in GetSons() for tetras */ |
| 300 |
}; |
| 301 |
|
| 302 |
struct refrule { |
| 303 |
SHORT tag; /* which element type this rule can refine */ |
| 304 |
SHORT mark; /* the mark of this rule */ |
| 305 |
SHORT rclass; /* class of rule:3bits for COPY, IREG, REG */ |
| 306 |
SHORT nsons; /* number of sons rule creates */ |
| 307 |
SHORT pattern[MAX_NEW_CORNERS_DIM]; /* stores which edges are refined */ |
| 308 |
INT pat; /* bitwise format of pattern */ |
| 309 |
SHORT sonandnode[MAX_NEW_CORNERS_DIM][2]; /* for each new node the number of the son */ |
| 310 |
/* and the local node number of the node */ |
| 311 |
struct sondata sons[MAX_SONS_DIM]; |
| 312 |
}; |
| 313 |
|
| 314 |
typedef struct sondata SONDATA; |
| 315 |
typedef struct refrule REFRULE; |
| 316 |
|
| 317 |
|
| 318 |
/****************************************************************************/ |
| 319 |
/* */ |
| 320 |
/* definition of exported global variables */ |
| 321 |
/* */ |
| 322 |
/****************************************************************************/ |
| 323 |
|
| 324 |
extern INT MaxRules[TAGS]; |
| 325 |
extern INT MaxNewCorners[TAGS]; |
| 326 |
extern INT MaxNewEdges[TAGS]; |
| 327 |
extern INT CenterNodeIndex[TAGS]; |
| 328 |
extern REFRULE *RefRules[TAGS]; |
| 329 |
extern const SHORT* Pattern2Rule[TAGS]; |
| 330 |
extern FULLREFRULEPTR theFullRefRule; |
| 331 |
|
| 332 |
|
| 333 |
/****************************************************************************/ |
| 334 |
/* */ |
| 335 |
/* function declarations */ |
| 336 |
/* */ |
| 337 |
/****************************************************************************/ |
| 338 |
|
| 339 |
INT ShowRefRule (INT tag, INT nb); |
| 340 |
INT ShowRefRuleX (INT tag, INT nb, PrintfProcPtr Printf); |
| 341 |
|
| 342 |
INT InitRuleManager (void); |
| 343 |
INT Patterns2Rules (ELEMENT *theElement,INT pattern); |
| 344 |
ELEMENT *ELEMENT_TO_MARK (ELEMENT *theElement); |
| 345 |
|
| 346 |
#ifdef UG_DIM_3 |
| 347 |
INT GetRule_AnisotropicRed (ELEMENT *theElement, INT *Rule); |
| 348 |
#endif |
| 349 |
|
| 350 |
END_UGDIM_NAMESPACE |
| 351 |
|
| 352 |
#endif |