| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
/****************************************************************************/ |
| 4 |
/* */ |
| 5 |
/* File: refine.c */ |
| 6 |
/* */ |
| 7 |
/* Purpose: unstructured grid adaption using a general element concept */ |
| 8 |
/* (dimension independent for 2/3D) */ |
| 9 |
/* */ |
| 10 |
/* Author: Stefan Lang */ |
| 11 |
/* Institut fuer Computeranwendungen III */ |
| 12 |
/* Universitaet Stuttgart */ |
| 13 |
/* Pfaffenwaldring 27 */ |
| 14 |
/* 70569 Stuttgart */ |
| 15 |
/* email: [email protected] */ |
| 16 |
/* */ |
| 17 |
/* History: 08.08.95 begin serial algorithm, ug version 3.0 */ |
| 18 |
/* */ |
| 19 |
/* Remarks: - level 0 grid consists of red elements only */ |
| 20 |
/* - the only restriction in the element hierarchy is that */ |
| 21 |
/* green or yellow elements might not have sons of class */ |
| 22 |
/* green or red */ |
| 23 |
/* - the rule set for refinement consists of regular (red) */ |
| 24 |
/* and irregular rules; regular rules create red elements */ |
| 25 |
/* while irregular rules result in green elements */ |
| 26 |
/* (green elements are needed for the closure of the grid, */ |
| 27 |
/* yellow elements, which are from copy rules, save */ |
| 28 |
/* the numerical properties of the solver and are handsome for */ |
| 29 |
/* the discretisation */ |
| 30 |
/* - if the rule set for the red rules is not complete for build-*/ |
| 31 |
/* up a consistent red refined region the FIFO might be used */ |
| 32 |
/* for some (hopefully not too much) iterations to find a */ |
| 33 |
/* consistent one */ |
| 34 |
/* - in 2D: exists a complete rule set for grids of triangles */ |
| 35 |
/* and quadrilaterals exclusively */ |
| 36 |
/* - in 3D: exists a complete rule set for tetrahedrons */ |
| 37 |
/* and we assume after some analysation a complete set */ |
| 38 |
/* of rules described by an algorithm for hexahedrons */ |
| 39 |
/* - for mixed element types in arbitrary dimension no */ |
| 40 |
/* rule set for the closure exists */ |
| 41 |
/* - BEFORE refinement we assume a situation where the error */ |
| 42 |
/* estimator has detected and marked the leaf elements for */ |
| 43 |
/* further refinement */ |
| 44 |
/* - AFTER refinement all elements are refined by a rule in way */ |
| 45 |
/* that no hanging nodes remain (this is the default mode) */ |
| 46 |
/* or with hanging nodes (in the hanging node mode) */ |
| 47 |
/* if you use inconsistent red refinement, you need to tell */ |
| 48 |
/* the algorithm explicitly to use the FIFO */ |
| 49 |
/* */ |
| 50 |
/****************************************************************************/ |
| 51 |
|
| 52 |
/****************************************************************************/ |
| 53 |
/* */ |
| 54 |
/* include files */ |
| 55 |
/* system include files */ |
| 56 |
/* application include files */ |
| 57 |
/* */ |
| 58 |
/****************************************************************************/ |
| 59 |
|
| 60 |
/* standard C library */ |
| 61 |
#include <config.h> |
| 62 |
#include <array> |
| 63 |
#include <cassert> |
| 64 |
#include <cmath> |
| 65 |
#include <cstdio> |
| 66 |
#include <cstdlib> |
| 67 |
#include <cstring> |
| 68 |
|
| 69 |
#include <algorithm> |
| 70 |
#include <array> |
| 71 |
|
| 72 |
/* low module */ |
| 73 |
#include <dune/uggrid/low/debug.h> |
| 74 |
#include <dune/uggrid/low/heaps.h> |
| 75 |
#include <dune/uggrid/low/misc.h> |
| 76 |
#include <dune/uggrid/low/ugtypes.h> |
| 77 |
|
| 78 |
/* dev module */ |
| 79 |
#include <dune/uggrid/ugdevices.h> |
| 80 |
|
| 81 |
/* gm module */ |
| 82 |
#include "algebra.h" |
| 83 |
#include "evm.h" |
| 84 |
#include "gm.h" |
| 85 |
#include "cw.h" |
| 86 |
#include "refine.h" |
| 87 |
#include "elements.h" |
| 88 |
#include "rm.h" |
| 89 |
#include "ugm.h" |
| 90 |
|
| 91 |
/* parallel modules */ |
| 92 |
#ifdef ModelP |
| 93 |
#include <dune/uggrid/parallel/ppif/ppif.h> |
| 94 |
#include <dune/uggrid/parallel/ddd/include/ddd.h> |
| 95 |
#include <dune/uggrid/parallel/dddif/debugger.h> |
| 96 |
#include <dune/uggrid/parallel/dddif/identify.h> |
| 97 |
#include <dune/uggrid/parallel/dddif/parallel.h> |
| 98 |
#include "pargm.h" |
| 99 |
#endif |
| 100 |
|
| 101 |
#ifdef Debug |
| 102 |
#include <dune/uggrid/low/architecture.h> |
| 103 |
#endif |
| 104 |
|
| 105 |
#include <dune/uggrid/parallel/ppif/ppifcontext.hh> |
| 106 |
|
| 107 |
USING_UG_NAMESPACES |
| 108 |
using namespace PPIF; |
| 109 |
|
| 110 |
/****************************************************************************/ |
| 111 |
/* */ |
| 112 |
/* defines in the following order */ |
| 113 |
/* */ |
| 114 |
/* compile time constants defining static data size (i.e. arrays) */ |
| 115 |
/* other constants */ |
| 116 |
/* macros */ |
| 117 |
/* */ |
| 118 |
/****************************************************************************/ |
| 119 |
|
| 120 |
/* undefine if overlap should be only updated where needed */ |
| 121 |
/* This does not work since the connection of the overlap needs the |
| 122 |
fatherelements on both sides (ghost and master sons) and this is |
| 123 |
not ensured. |
| 124 |
#define UPDATE_FULLOVERLAP |
| 125 |
*/ |
| 126 |
|
| 127 |
/* define for use of DDD_ConsCheck() */ |
| 128 |
/* |
| 129 |
#define DDD_CONSCHECK(context) if (DDD_ConsCheck(context)) assert(0); |
| 130 |
*/ |
| 131 |
#define DDD_CONSCHECK(context) |
| 132 |
|
| 133 |
#define MINVNCLASS 2 /* determines copies, dep. on discr. ! */ |
| 134 |
|
| 135 |
/* defines for side matching of elements 8 bits: */ |
| 136 |
/* _ _ _ _ (4 bits for corner of one element) _ _ _ _ (4 bits for the other)*/ |
| 137 |
|
| 138 |
#define LINEPOINTS 51 /* 0011 0011 */ |
| 139 |
#define TRIPOINTS 119 /* 0111 0111 */ |
| 140 |
#define QUADPOINTS 255 /* 1111 1111 */ |
| 141 |
|
| 142 |
#define MAX_GREEN_SONS 32 /* max num of sons for green refinement */ |
| 143 |
|
| 144 |
/* define to control element which is responsible */ |
| 145 |
/* equal side refinement of neighboring elements */ |
| 146 |
#ifdef ModelP |
| 147 |
#define _EID_ EGID |
| 148 |
#define _ID_ GID |
| 149 |
#else |
| 150 |
#define _EID_ ID |
| 151 |
#define _ID_ ID |
| 152 |
#endif |
| 153 |
|
| 154 |
#define EDGE_IN_PATTERN(p,i) (((p)[(i)]) & 0x1) |
| 155 |
#define SIDE_IN_PATTERN(e,p,i) (((p)[EDGES_OF_ELEM(e)+(i)]) & 0x1) |
| 156 |
#define EDGE_IN_PAT(p,i) (((p)>>(i)) & 0x1) |
| 157 |
#define SIDE_IN_PAT(p,i) (((p)>>(i)) & 0x1) |
| 158 |
|
| 159 |
#define MARK_BISECT_EDGE(r,i) ((r)->pattern[(i)]==1) |
| 160 |
|
| 161 |
#define REF_TYPE_CHANGES(e) ((REFINE(e)!=MARK(e)) || \ |
| 162 |
(REFINECLASS(e)!=MARKCLASS(e))) |
| 163 |
#define MARKED(e) (MARK(e)!=NO_REFINEMENT) |
| 164 |
|
| 165 |
/* green marked elements were NEWGREEN is true are refined without rule */ |
| 166 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 167 |
#define NEWGREEN(e) (TAG(e)==HEXAHEDRON || TAG(e)== PRISM || \ |
| 168 |
TAG(e)==PYRAMID) |
| 169 |
#else |
| 170 |
#define NEWGREEN(e) (TAG(e)==HEXAHEDRON || TAG(e)== PRISM || \ |
| 171 |
TAG(e)==PYRAMID || TAG(e)== TETRAHEDRON) |
| 172 |
#endif |
| 173 |
|
| 174 |
/* marked elem with new green refinement (without rule, only 3D) */ |
| 175 |
#ifdef __ANISOTROPIC__ |
| 176 |
#define MARKED_NEW_GREEN(elem) \ |
| 177 |
(DIM==3 && ((NEWGREEN(elem) && MARKCLASS(elem)==GREEN_CLASS) || \ |
| 178 |
((TAG(elem)==PRISM && MARKCLASS(elem)==RED_CLASS && USED(elem)==1)))) |
| 179 |
#else |
| 180 |
#define MARKED_NEW_GREEN(elem) \ |
| 181 |
(DIM==3 && NEWGREEN(elem) && MARKCLASS(elem)==GREEN_CLASS) |
| 182 |
#endif |
| 183 |
|
| 184 |
/** \brief Refined elem with new green refinement (without rule, only 3D) */ |
| 185 |
#define REFINED_NEW_GREEN(elem) \ |
| 186 |
(DIM==3 && NEWGREEN(elem) && REFINECLASS(elem)==GREEN_CLASS) |
| 187 |
|
| 188 |
/** \brief Macro to test whether element changes refinement */ |
| 189 |
#define REFINEMENT_CHANGES(elem) \ |
| 190 |
(REF_TYPE_CHANGES(elem) || \ |
| 191 |
(MARKED_NEW_GREEN(elem) && \ |
| 192 |
(REFINECLASS(elem)!=GREEN_CLASS || (REFINECLASS(elem)==GREEN_CLASS \ |
| 193 |
&& USED(elem)==1)))) |
| 194 |
|
| 195 |
/** @name Macros for storing sparse data needed in ExchangeClosureInfo() */ |
| 196 |
/*@{*/ |
| 197 |
#define MARKCLASSDATA_SHIFT 20 |
| 198 |
#define GETMARKCLASSDATA(elem,dataadr) \ |
| 199 |
(*(dataadr)) = (*(dataadr)) | ((MARKCLASS(elem))<<MARKCLASSDATA_SHIFT) |
| 200 |
#define SETMARKCLASSDATA(elem,data) \ |
| 201 |
SETMARKCLASS((elem),((data)>>MARKCLASSDATA_SHIFT)&((1<<MARKCLASS_LEN)-1)) |
| 202 |
/*@}*/ |
| 203 |
|
| 204 |
/** @name Macros for storing sparse data needed in ExchangeClosureInfo() */ |
| 205 |
/*@{*/ |
| 206 |
#define MARKDATA_SHIFT 22 |
| 207 |
#define GETMARKDATA(elem,dataadr) \ |
| 208 |
(*(dataadr)) = (*(dataadr)) | ((MARK(elem))<<MARKDATA_SHIFT) |
| 209 |
#define SETMARKDATA(elem,data) \ |
| 210 |
SETMARK((elem),MARK(elem)|(((data)>>MARKDATA_SHIFT)&((1<<MARK_LEN)-1))) |
| 211 |
/*@}*/ |
| 212 |
|
| 213 |
/** @name Macros for storing sparse data needed in ExchangeClosureInfo() */ |
| 214 |
/*@{*/ |
| 215 |
#define COARSENDATA_SHIFT 19 |
| 216 |
#define GETCOARSENDATA(elem,dataadr) \ |
| 217 |
(*(dataadr)) = (*(dataadr)) | ((COARSEN(elem))<<COARSENDATA_SHIFT) |
| 218 |
#define SETCOARSENDATA(elem,data) \ |
| 219 |
SETCOARSEN((elem),((data)>>COARSENDATA_SHIFT)&((1<<COARSEN_LEN)-1)) |
| 220 |
/*@}*/ |
| 221 |
|
| 222 |
/** @name Macros to get and set the edgepattern on an element */ |
| 223 |
/*@{*/ |
| 224 |
#define GetEdgeInfo(elem,patadr,macro) \ |
| 225 |
{ \ |
| 226 |
INT i,pattern; \ |
| 227 |
EDGE *theEdge; \ |
| 228 |
\ |
| 229 |
pattern = 0; \ |
| 230 |
for (i=EDGES_OF_ELEM(elem)-1; i>=0; i--) \ |
| 231 |
{ \ |
| 232 |
theEdge=GetEdge(CORNER_OF_EDGE_PTR((elem),i,0), \ |
| 233 |
CORNER_OF_EDGE_PTR((elem),i,1)); \ |
| 234 |
ASSERT(theEdge!=NULL); \ |
| 235 |
\ |
| 236 |
pattern = (pattern<<1) | macro(theEdge); \ |
| 237 |
} \ |
| 238 |
\ |
| 239 |
(*(patadr)) |= pattern; \ |
| 240 |
} |
| 241 |
|
| 242 |
#define SetEdgeInfo(elem,pat,macro,OP) \ |
| 243 |
{ \ |
| 244 |
INT i,pattern; \ |
| 245 |
EDGE *theEdge; \ |
| 246 |
\ |
| 247 |
pattern = (pat); \ |
| 248 |
for (i=0; i<EDGES_OF_ELEM(elem); i++) \ |
| 249 |
{ \ |
| 250 |
theEdge = GetEdge(CORNER_OF_EDGE_PTR((elem),i,0), \ |
| 251 |
CORNER_OF_EDGE_PTR((elem),i,1)); \ |
| 252 |
ASSERT(theEdge!=NULL); \ |
| 253 |
\ |
| 254 |
SET ## macro(theEdge, macro(theEdge) OP (pattern&0x1)); \ |
| 255 |
pattern >>= 1; \ |
| 256 |
} \ |
| 257 |
} |
| 258 |
/*@}*/ |
| 259 |
|
| 260 |
#define REFINE_CONTEXT_LIST(d,context) \ |
| 261 |
IFDEBUG(gm,2) \ |
| 262 |
{ \ |
| 263 |
INT i; \ |
| 264 |
\ |
| 265 |
UserWrite(" UpdateContext is :\n"); \ |
| 266 |
for(i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) \ |
| 267 |
UserWriteF(" %3d",i); \ |
| 268 |
UserWrite("\n"); \ |
| 269 |
for(i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) \ |
| 270 |
if ((context)[i] != NULL) \ |
| 271 |
UserWriteF(" %3d",ID((context)[i])); \ |
| 272 |
else \ |
| 273 |
UserWriteF(" "); \ |
| 274 |
UserWrite("\n"); \ |
| 275 |
} \ |
| 276 |
ENDDEBUG |
| 277 |
|
| 278 |
#ifndef STAT_OUT |
| 279 |
#undef NEW_TIMER |
| 280 |
#undef DEL_TIMER |
| 281 |
#undef START_TIMER |
| 282 |
#undef STOP_TIMER |
| 283 |
#undef DIFF_TIMER |
| 284 |
#undef SUM_TIMER |
| 285 |
#undef EVAL_TIMER |
| 286 |
|
| 287 |
#define NEW_TIMER(n) |
| 288 |
#define DEL_TIMER(n) |
| 289 |
#define START_TIMER(n) |
| 290 |
#define STOP_TIMER(n) |
| 291 |
#define DIFF_TIMER(n) |
| 292 |
#define SUM_TIMER(n) |
| 293 |
#define EVAL_TIMER(n) |
| 294 |
#endif |
| 295 |
|
| 296 |
/****************************************************************************/ |
| 297 |
/* */ |
| 298 |
/* data structures used in this source file (exported data structures are */ |
| 299 |
/* in the corresponding include file!) */ |
| 300 |
/* */ |
| 301 |
/****************************************************************************/ |
| 302 |
|
| 303 |
typedef NODE *ELEMENTCONTEXT[MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM]; |
| 304 |
|
| 305 |
|
| 306 |
/****************************************************************************/ |
| 307 |
/* */ |
| 308 |
/* definition of exported global variables */ |
| 309 |
/* */ |
| 310 |
/****************************************************************************/ |
| 311 |
|
| 312 |
/* information used by the estimator and refine*/ |
| 313 |
REFINEINFO NS_DIM_PREFIX refine_info; |
| 314 |
|
| 315 |
#ifdef ModelP |
| 316 |
/* control words for identiftication of new nodes and edges */ |
| 317 |
INT NS_DIM_PREFIX ce_NEW_NIDENT; |
| 318 |
INT NS_DIM_PREFIX ce_NEW_EDIDENT; |
| 319 |
#endif |
| 320 |
|
| 321 |
/****************************************************************************/ |
| 322 |
/* */ |
| 323 |
/* definition of variables global to this source file only (static!) */ |
| 324 |
/* */ |
| 325 |
/****************************************************************************/ |
| 326 |
|
| 327 |
/** \brief type of refinement */ |
| 328 |
static int rFlag=GM_REFINE_TRULY_LOCAL; |
| 329 |
|
| 330 |
/** \brief refine with hanging nodes? */ |
| 331 |
static int hFlag=0; |
| 332 |
|
| 333 |
/** \brief use fifo? 0=no 1=yes */ |
| 334 |
static int fifoFlag=0; |
| 335 |
|
| 336 |
/** \brief fifo loop counter */ |
| 337 |
static int first; |
| 338 |
|
| 339 |
/** \brief first element in fifo work list */ |
| 340 |
static ELEMENT *fifo_first=NULL; |
| 341 |
|
| 342 |
/** \brief last element in fifo work list */ |
| 343 |
static ELEMENT *fifo_last=NULL; |
| 344 |
|
| 345 |
/** \brief first element in fifo insertlist */ |
| 346 |
static ELEMENT *fifo_insertfirst=NULL; |
| 347 |
|
| 348 |
/** \brief last element in fifo insertlist */ |
| 349 |
static ELEMENT *fifo_insertlast=NULL; |
| 350 |
|
| 351 |
/** \brief first element to consider for next loop */ |
| 352 |
static ELEMENT *firstElement=NULL; |
| 353 |
|
| 354 |
/** \brief Counter for green refinements doesn't need to be updated */ |
| 355 |
static INT No_Green_Update; |
| 356 |
|
| 357 |
/** \brief green refined element counter */ |
| 358 |
static INT Green_Marks; |
| 359 |
|
| 360 |
/** \brief 0/1: do/do not parallel part */ |
| 361 |
static INT refine_seq = 0; |
| 362 |
|
| 363 |
/** \brief counter for FIFO loops */ |
| 364 |
static INT fifoloop = 0; |
| 365 |
|
| 366 |
/** \brief count of adapted elements */ |
| 367 |
static INT total_adapted = 0; |
| 368 |
|
| 369 |
#ifdef STAT_OUT |
| 370 |
/* timing variables */ |
| 371 |
static int adapt_timer,closure_timer,gridadapt_timer,gridadapti_timer; |
| 372 |
static int gridadaptl_timer,ident_timer,overlap_timer,gridcons_timer; |
| 373 |
static int algebra_timer; |
| 374 |
#endif |
| 375 |
|
| 376 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 377 |
/* determine number of edge from reduced (i.e. restricted to one side) edgepattern */ |
| 378 |
/* if there are two edges marked for bisection, if not deliver -1. If the edge- */ |
| 379 |
/* is not reduced (i.e. marked edges lying on more than one side) deliver -2 */ |
| 380 |
static INT TriSectionEdge[64][2] = |
| 381 |
{ {-1,-1},{-1,-1},{-1,-1},{ 1, 0},{-1,-1},{ 0, 2},{ 2, 1},{-1,-1}, |
| 382 |
{-1,-1},{ 3, 0},{-2,-2},{-2,-2},{ 2, 3},{-2,-2},{-2,-2},{-2,-2}, |
| 383 |
{-1,-1},{ 0, 4},{ 4, 1},{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2}, |
| 384 |
{ 4, 3},{-1,-1},{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2}, |
| 385 |
{-1,-1},{-2,-2},{ 1, 5},{-2,-2},{ 5, 2},{-2,-2},{-2,-2},{-2,-2}, |
| 386 |
{ 3, 5},{-2,-2},{-2,-2},{-2,-2},{-1,-1},{-2,-2},{-2,-2},{-2,-2}, |
| 387 |
{ 5, 4},{-2,-2},{-1,-1},{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2}, |
| 388 |
{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2},{-2,-2}}; |
| 389 |
|
| 390 |
/* the indices of the edges of each side */ |
| 391 |
static INT CondensedEdgeOfSide[4] = {0x07,0x32,0x2C,0x19}; |
| 392 |
#endif |
| 393 |
|
| 394 |
/****************************************************************************/ |
| 395 |
/* */ |
| 396 |
/* forward declarations of functions used before they are defined */ |
| 397 |
/* */ |
| 398 |
/****************************************************************************/ |
| 399 |
|
| 400 |
#ifdef ModelP |
| 401 |
static void CheckConsistency (MULTIGRID *theMG, INT level ,INT debugstart, INT gmlevel, int *check); |
| 402 |
#endif |
| 403 |
|
| 404 |
/****************************************************************************/ |
| 405 |
/** \brief Fill refineinfo structure |
| 406 |
|
| 407 |
This function fills the refineinfo structure |
| 408 |
|
| 409 |
\return <ul> |
| 410 |
<li> GM_OK if ok </li> |
| 411 |
<li> GM_ERROR if an error occurs </li> |
| 412 |
</ul> |
| 413 |
*/ |
| 414 |
/****************************************************************************/ |
| 415 |
|
| 416 |
INT NS_DIM_PREFIX SetRefineInfo (MULTIGRID *theMG) |
| 417 |
{ |
| 418 |
if (MultiGridStatus(theMG,1,0,0,0) != GM_OK) return(GM_ERROR); |
| 419 |
|
| 420 |
return(GM_OK); |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
/****************************************************************************/ |
| 425 |
/** \brief Drop marks from leafelements to first regular |
| 426 |
|
| 427 |
This function drops marks from leafelements to first regular, and resets |
| 428 |
marks on all elements above (important for restrict marks) |
| 429 |
|
| 430 |
\return <ul> |
| 431 |
.n GM_OK if ok |
| 432 |
.n GM_ERROR if an error occurs |
| 433 |
*/ |
| 434 |
/****************************************************************************/ |
| 435 |
|
| 436 |
static INT DropMarks (MULTIGRID *theMG) |
| 437 |
{ |
| 438 |
return(GM_OK); |
| 439 |
|
| 440 |
for (INT k = TOPLEVEL(theMG); k > 0; k--) |
| 441 |
{ |
| 442 |
const GRID *theGrid = GRID_ON_LEVEL(theMG,k); |
| 443 |
for (ELEMENT *theElement = FIRSTELEMENT(theGrid); |
| 444 |
theElement != NULL; |
| 445 |
theElement=SUCCE(theElement)) |
| 446 |
if ((MARKCLASS(theElement) == RED_CLASS) && |
| 447 |
(ECLASS(theElement) != RED_CLASS)) |
| 448 |
{ |
| 449 |
INT Mark = MARK(theElement); |
| 450 |
/** \todo marks must be changed if element type changes */ |
| 451 |
if (TAG(theElement)!=HEXAHEDRON && |
| 452 |
TAG(EFATHER(theElement))==HEXAHEDRON) Mark = HEXA_RED; |
| 453 |
if (TAG(theElement)!=PYRAMID && |
| 454 |
TAG(EFATHER(theElement))==PYRAMID) Mark = PYR_RED; |
| 455 |
ELEMENT *FatherElement = theElement; |
| 456 |
|
| 457 |
SETMARK(FatherElement,NO_REFINEMENT); |
| 458 |
SETMARKCLASS(FatherElement,NO_CLASS); |
| 459 |
FatherElement = EFATHER(FatherElement); |
| 460 |
|
| 461 |
SETMARK(FatherElement,Mark); |
| 462 |
SETMARKCLASS(FatherElement,RED_CLASS); |
| 463 |
} |
| 464 |
} |
| 465 |
return(GM_OK); |
| 466 |
} |
| 467 |
|
| 468 |
/* Functions for realizing the (parallel) closure FIFO */ |
| 469 |
|
| 470 |
|
| 471 |
/****************************************************************************/ |
| 472 |
/** \brief Function for realizing the (parallel) closure FIFO |
| 473 |
*/ |
| 474 |
/****************************************************************************/ |
| 475 |
|
| 476 |
static INT InitClosureFIFO (void) |
| 477 |
{ |
| 478 |
fifo_first=fifo_last=fifo_insertfirst=fifo_insertlast=NULL; |
| 479 |
first = 1; |
| 480 |
fifoloop = 0; |
| 481 |
if (0) UserWriteF("Using FIFO: loop %d\n",fifoloop); |
| 482 |
|
| 483 |
return (GM_OK); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
/****************************************************************************/ |
| 488 |
/** \brief Function for realizing the (parallel) closure FIFO |
| 489 |
|
| 490 |
\param theGrid - pointer to grid structure |
| 491 |
. theElement |
| 492 |
. thePattern |
| 493 |
. NewPattern |
| 494 |
|
| 495 |
DESCRIPTION: |
| 496 |
|
| 497 |
*/ |
| 498 |
/****************************************************************************/ |
| 499 |
|
| 500 |
static INT UpdateFIFOLists (GRID *theGrid, ELEMENT *theElement, INT thePattern, INT NewPattern) |
| 501 |
{ |
| 502 |
|
| 503 |
if (MARKCLASS(theElement)==RED_CLASS && thePattern!=NewPattern) |
| 504 |
{ |
| 505 |
#ifdef UG_DIM_2 |
| 506 |
for (INT j = 0; j < EDGES_OF_ELEM(theElement); j++) |
| 507 |
{ |
| 508 |
if (EDGE_IN_PAT(thePattern,j)==0 && |
| 509 |
EDGE_IN_PAT(NewPattern,j)) |
| 510 |
{ |
| 511 |
|
| 512 |
EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, j, 0), |
| 513 |
CORNER_OF_EDGE_PTR(theElement, j, 1)); |
| 514 |
ASSERT(theEdge != NULL); |
| 515 |
|
| 516 |
SETPATTERN(theEdge,1); |
| 517 |
|
| 518 |
/* boundary case */ |
| 519 |
if (SIDE_ON_BND(theElement,j)) continue; |
| 520 |
|
| 521 |
/* add the element sharing this edge to fifo_queue */ |
| 522 |
ELEMENT *NbElement = NBELEM(theElement, j); |
| 523 |
|
| 524 |
if (NbElement==NULL) continue; |
| 525 |
|
| 526 |
PRINTDEBUG(gm,1,(" ADDING to FIFO: NBID=%d\n", |
| 527 |
ID(NbElement))) |
| 528 |
|
| 529 |
/* unlink element from element list */ |
| 530 |
if (PREDE(NbElement) != NULL) |
| 531 |
SUCCE(PREDE(NbElement)) = SUCCE(NbElement); |
| 532 |
if (SUCCE(NbElement) != NULL) |
| 533 |
PREDE(SUCCE(NbElement)) = PREDE(NbElement); |
| 534 |
if (FIRSTELEMENT(theGrid) == NbElement) |
| 535 |
FIRSTELEMENT(theGrid) = SUCCE(NbElement); |
| 536 |
|
| 537 |
SUCCE(NbElement) = PREDE(NbElement) = NULL; |
| 538 |
/* insert into fifo */ |
| 539 |
if (fifo_insertfirst == NULL) |
| 540 |
{ |
| 541 |
fifo_insertfirst = fifo_insertlast = NbElement; |
| 542 |
} |
| 543 |
else |
| 544 |
{ |
| 545 |
SUCCE(fifo_insertlast) = NbElement; |
| 546 |
PREDE(NbElement) = fifo_insertlast; |
| 547 |
fifo_insertlast = NbElement; |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
if (EDGE_IN_PAT(thePattern,j) && |
| 552 |
EDGE_IN_PAT(NewPattern,j)==0) |
| 553 |
{ |
| 554 |
|
| 555 |
UserWriteF("UpdateFIFOLists(): ERROR EID=%d in fifo " |
| 556 |
"thePattern=%d has edge=%d refined but " |
| 557 |
"NewPattern=%d NOT!\n", |
| 558 |
ID(theElement),thePattern,j,NewPattern); |
| 559 |
RETURN(-1); |
| 560 |
} |
| 561 |
} |
| 562 |
#endif |
| 563 |
#ifdef UG_DIM_3 |
| 564 |
UserWriteF("UpdateFIFOLists(): ERROR fifo for 3D NOT implemented!\n"); |
| 565 |
ASSERT(0); |
| 566 |
#endif |
| 567 |
} |
| 568 |
|
| 569 |
return(GM_OK); |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
/****************************************************************************/ |
| 574 |
/** \brief Function for realizing the (parallel) closure FIFO |
| 575 |
|
| 576 |
\param theGrid - pointer to grid structure |
| 577 |
|
| 578 |
*/ |
| 579 |
/****************************************************************************/ |
| 580 |
|
| 581 |
static INT UpdateClosureFIFO (GRID *theGrid) |
| 582 |
{ |
| 583 |
/* insert fifo work list into elementlist */ |
| 584 |
for (ELEMENT *theElement = fifo_last; theElement != nullptr; |
| 585 |
theElement=PREDE(theElement)) |
| 586 |
{ |
| 587 |
SUCCE(theElement) = FIRSTELEMENT(theGrid); |
| 588 |
PREDE(FIRSTELEMENT(theGrid)) = theElement; |
| 589 |
FIRSTELEMENT(theGrid) = theElement; |
| 590 |
} |
| 591 |
|
| 592 |
PREDE(FIRSTELEMENT(theGrid)) = NULL; |
| 593 |
|
| 594 |
if (fifo_insertfirst != NULL) |
| 595 |
{ |
| 596 |
/* append fifo insert list to fifo work list */ |
| 597 |
firstElement = fifo_first = fifo_insertfirst; |
| 598 |
fifo_last = fifo_insertlast; |
| 599 |
|
| 600 |
IFDEBUG(gm,2) |
| 601 |
UserWriteF(" FIFO Queue:"); |
| 602 |
for (ELEMENT *theElement = fifo_first; theElement != nullptr; |
| 603 |
theElement=SUCCE(theElement)) |
| 604 |
UserWriteF(" %d\n", ID(theElement)); |
| 605 |
ENDDEBUG |
| 606 |
|
| 607 |
fifo_insertfirst = fifo_insertlast = NULL; |
| 608 |
first = 0; |
| 609 |
fifoloop++; |
| 610 |
UserWriteF(" loop %d",fifoloop); |
| 611 |
return(1); |
| 612 |
} |
| 613 |
|
| 614 |
return(0); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
/****************************************************************************/ |
| 619 |
/* |
| 620 |
ManageParallelFIFO - function for realizing the (parallel) closure FIFO |
| 621 |
|
| 622 |
SYNOPSIS: |
| 623 |
static INT ManageParallelFIFO (ELEMENT *firstElement); |
| 624 |
|
| 625 |
PARAMETERS: |
| 626 |
\param firstElement |
| 627 |
|
| 628 |
DESCRIPTION: |
| 629 |
|
| 630 |
\return <ul> |
| 631 |
INT |
| 632 |
*/ |
| 633 |
/****************************************************************************/ |
| 634 |
|
| 635 |
static INT ManageParallelFIFO (const PPIF::PPIFContext& context, const ELEMENT *firstElement) |
| 636 |
{ |
| 637 |
#if defined(FIFO) && defined(ModelP) |
| 638 |
if (context.procs() == 1) return(0); |
| 639 |
|
| 640 |
do |
| 641 |
{ |
| 642 |
/* exchange FIFO flag and PATTERN from slaves to master */ |
| 643 |
IF_FIF0AndPat_S2M(GLEVEL(grid)); |
| 644 |
|
| 645 |
/* add all master elements of horizontal interface to FIFO */ |
| 646 |
for (ELEMENT *theElement = firstElement; theElement != nullptr; |
| 647 |
theElement=SUCCE(theElement)) |
| 648 |
{ |
| 649 |
if (IS_HOR_MASTER(theElement) && FIFO(theElement)) |
| 650 |
{ |
| 651 |
AddToFIFIO(theElement); |
| 652 |
SETFIFO(theElement,0); |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
/* check condition for termination of pattern adaptation */ |
| 657 |
AllFIFOsEmpty = CheckGlobalFIFOStatus(fifo); |
| 658 |
} |
| 659 |
while (fifo==NULL && AllFIFOsEmpty==1); |
| 660 |
#else |
| 661 |
return (0); |
| 662 |
#endif |
| 663 |
} |
| 664 |
|
| 665 |
/****************************************************************************/ |
| 666 |
/** \brief Changes refinement of element |
| 667 |
|
| 668 |
\param theElement - pointer to element |
| 669 |
|
| 670 |
This function returns a boolean value to indicate, whether an element |
| 671 |
changes its refinement (1) or not (0). |
| 672 |
|
| 673 |
\return <ul> |
| 674 |
.n 0 if element will not change refinement |
| 675 |
.n 1 if it will |
| 676 |
*/ |
| 677 |
/****************************************************************************/ |
| 678 |
|
| 679 |
INT NS_DIM_PREFIX Refinement_Changes (ELEMENT *theElement) |
| 680 |
{ |
| 681 |
return(REFINEMENT_CHANGES(theElement)); |
| 682 |
} |
| 683 |
|
| 684 |
/****************************************************************************/ |
| 685 |
/* |
| 686 |
GridClosure - compute closure for next level |
| 687 |
|
| 688 |
SYNOPSIS: |
| 689 |
static INT PrepareGridClosure (GRID *theGrid); |
| 690 |
|
| 691 |
PARAMETERS: |
| 692 |
\param theGrid - pointer to grid structure |
| 693 |
|
| 694 |
DESCRIPTION: |
| 695 |
This function computes the closure for next level. A closure can only be |
| 696 |
determined if the rule set for the used elements is complete. This means |
| 697 |
that for all side and edge patterns possible for an element type exists a |
| 698 |
rule which closes the element. In this case a FIFO for computing the closure |
| 699 |
is not needed any more and the closure can be computed in one step. |
| 700 |
|
| 701 |
\return <ul> |
| 702 |
INT |
| 703 |
.n >0 if elements will be refined |
| 704 |
.n 0 if no elements will be refined |
| 705 |
.n -1 if an error occurred |
| 706 |
*/ |
| 707 |
/****************************************************************************/ |
| 708 |
|
| 709 |
static INT PrepareGridClosure (const GRID *theGrid) |
| 710 |
{ |
| 711 |
/* reset USED flag of elements and PATTERN and */ |
| 712 |
/* ADDPATTERN flag on the edges */ |
| 713 |
for (ELEMENT *theElement = PFIRSTELEMENT(theGrid); theElement != nullptr; |
| 714 |
theElement=SUCCE(theElement)) |
| 715 |
{ |
| 716 |
SETUSED(theElement,0); |
| 717 |
if (EGHOST(theElement)) |
| 718 |
{ |
| 719 |
SETCOARSEN(theElement,0); |
| 720 |
SETMARK(theElement,NO_REFINEMENT); |
| 721 |
SETMARKCLASS(theElement,0); |
| 722 |
} |
| 723 |
|
| 724 |
for (INT j = 0; j < EDGES_OF_ELEM(theElement); j++) |
| 725 |
{ |
| 726 |
EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, j, 0), |
| 727 |
CORNER_OF_EDGE_PTR(theElement, j, 1)); |
| 728 |
ASSERT(theEdge != NULL); |
| 729 |
|
| 730 |
SETPATTERN(theEdge,0); |
| 731 |
SETADDPATTERN(theEdge,1); /* needed in RestrictMarks() */ |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
return(GM_OK); |
| 736 |
} |
| 737 |
|
| 738 |
#ifdef ModelP |
| 739 |
|
| 740 |
|
| 741 |
/****************************************************************************/ |
| 742 |
/* |
| 743 |
Gather_ElementClosureInfo - |
| 744 |
|
| 745 |
SYNOPSIS: |
| 746 |
static int Gather_ElementClosureInfo (DDD_OBJ obj, void *data); |
| 747 |
|
| 748 |
PARAMETERS: |
| 749 |
. obj |
| 750 |
. data |
| 751 |
|
| 752 |
DESCRIPTION: |
| 753 |
|
| 754 |
\return <ul> |
| 755 |
int |
| 756 |
*/ |
| 757 |
/****************************************************************************/ |
| 758 |
|
| 759 |
static int Gather_ElementClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) |
| 760 |
{ |
| 761 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 762 |
|
| 763 |
PRINTDEBUG(gm,1,("Gather_ElementClosureInfo(): e=" EID_FMTX "\n", |
| 764 |
EID_PRTX(theElement))) |
| 765 |
|
| 766 |
INT refinedata = 0; |
| 767 |
|
| 768 |
#ifdef UG_DIM_2 |
| 769 |
GetEdgeInfo(theElement,&refinedata,PATTERN); |
| 770 |
#endif |
| 771 |
|
| 772 |
/* mark and sidepattern have same control word positions */ |
| 773 |
/* if this changes sidepattern must be sent separately */ |
| 774 |
GETMARKDATA(theElement,&refinedata); |
| 775 |
GETMARKCLASSDATA(theElement,&refinedata); |
| 776 |
GETCOARSENDATA(theElement,&refinedata); |
| 777 |
((INT *)data)[0] = refinedata; |
| 778 |
|
| 779 |
PRINTDEBUG(gm,1,("Gather_ElementClosureInfo(): refinedata=%08x " |
| 780 |
"sidepattern=%d markclass=%d mark=%d coarse=%d\n",refinedata, |
| 781 |
SIDEPATTERN(theElement),MARKCLASS(theElement),MARK(theElement),COARSEN(theElement))) |
| 782 |
|
| 783 |
return(GM_OK); |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
/****************************************************************************/ |
| 789 |
/* |
| 790 |
Scatter_ElementClosureInfo - |
| 791 |
|
| 792 |
SYNOPSIS: |
| 793 |
static int Scatter_ElementClosureInfo (DDD_OBJ obj, void *data); |
| 794 |
|
| 795 |
PARAMETERS: |
| 796 |
. obj |
| 797 |
. data |
| 798 |
|
| 799 |
DESCRIPTION: |
| 800 |
|
| 801 |
\return <ul> |
| 802 |
int |
| 803 |
*/ |
| 804 |
/****************************************************************************/ |
| 805 |
|
| 806 |
static int Scatter_ElementClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) |
| 807 |
{ |
| 808 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 809 |
|
| 810 |
PRINTDEBUG(gm,1,("Scatter_ElementClosureInfo(): e=" EID_FMTX "\n", |
| 811 |
EID_PRTX(theElement))) |
| 812 |
|
| 813 |
INT refinedata = ((INT *)data)[0]; |
| 814 |
|
| 815 |
#ifdef UG_DIM_2 |
| 816 |
SetEdgeInfo(theElement,refinedata,PATTERN,|); |
| 817 |
#endif |
| 818 |
|
| 819 |
/* mark and sidepattern have same control word positions */ |
| 820 |
/* if this changes sidepattern must be sent separately */ |
| 821 |
SETMARKDATA(theElement,refinedata); |
| 822 |
|
| 823 |
if (EMASTER(theElement)) return(GM_OK); |
| 824 |
if (EGHOST(theElement) && EGHOSTPRIO(prio)) return(GM_OK); |
| 825 |
|
| 826 |
SETMARKCLASSDATA(theElement,refinedata); |
| 827 |
SETCOARSENDATA(theElement,refinedata); |
| 828 |
|
| 829 |
PRINTDEBUG(gm,1,("Scatter_ElementClosureInfo(): refinedata=%08x " |
| 830 |
"sidepattern=%d markclass=%d mark=%d coarse=%d\n",refinedata, |
| 831 |
SIDEPATTERN(theElement),MARKCLASS(theElement),MARK(theElement),COARSEN(theElement))) |
| 832 |
|
| 833 |
return(GM_OK); |
| 834 |
} |
| 835 |
|
| 836 |
static INT ExchangeElementClosureInfo (GRID *theGrid) |
| 837 |
{ |
| 838 |
auto& context = theGrid->dddContext(); |
| 839 |
const auto& dddctrl = ddd_ctrl(context); |
| 840 |
|
| 841 |
/* exchange information of elements to compute closure */ |
| 842 |
DDD_IFAOnewayX(context, |
| 843 |
dddctrl.ElementSymmVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), |
| 844 |
Gather_ElementClosureInfo, Scatter_ElementClosureInfo); |
| 845 |
|
| 846 |
return(GM_OK); |
| 847 |
} |
| 848 |
|
| 849 |
static int Gather_ElementRefine (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) |
| 850 |
{ |
| 851 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 852 |
|
| 853 |
PRINTDEBUG(gm,1,("Gather_ElementRefine(): e=" EID_FMTX "\n", |
| 854 |
EID_PRTX(theElement))) |
| 855 |
|
| 856 |
((INT *)data)[0] = MARKCLASS(theElement); |
| 857 |
((INT *)data)[1] = MARK(theElement); |
| 858 |
|
| 859 |
return(GM_OK); |
| 860 |
} |
| 861 |
|
| 862 |
static int Scatter_ElementRefine (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio) |
| 863 |
{ |
| 864 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 865 |
|
| 866 |
PRINTDEBUG(gm,1,("Scatter_ElementClosureInfo(): e=" EID_FMTX "\n", |
| 867 |
EID_PRTX(theElement))) |
| 868 |
|
| 869 |
if (EMASTER(theElement)) return(GM_OK); |
| 870 |
if (EGHOST(theElement) && EGHOSTPRIO(prio)) return(GM_OK); |
| 871 |
|
| 872 |
SETMARKCLASS(theElement,((INT *)data)[0]); |
| 873 |
SETMARK(theElement,((INT *)data)[1]); |
| 874 |
|
| 875 |
return(GM_OK); |
| 876 |
} |
| 877 |
|
| 878 |
static INT ExchangeElementRefine (GRID *theGrid) |
| 879 |
{ |
| 880 |
auto& context = theGrid->dddContext(); |
| 881 |
const auto& dddctrl = ddd_ctrl(context); |
| 882 |
|
| 883 |
/* exchange information of elements to compute closure */ |
| 884 |
DDD_IFAOnewayX(context, |
| 885 |
dddctrl.ElementSymmVHIF,GRID_ATTR(theGrid),IF_FORWARD,2*sizeof(INT), |
| 886 |
Gather_ElementRefine, Scatter_ElementRefine); |
| 887 |
|
| 888 |
return(GM_OK); |
| 889 |
} |
| 890 |
|
| 891 |
#ifdef UG_DIM_3 |
| 892 |
|
| 893 |
/****************************************************************************/ |
| 894 |
/* |
| 895 |
Gather_EdgeClosureInfo - |
| 896 |
|
| 897 |
SYNOPSIS: |
| 898 |
static int Gather_EdgeClosureInfo (DDD_OBJ obj, void *data); |
| 899 |
|
| 900 |
PARAMETERS: |
| 901 |
. obj |
| 902 |
. data |
| 903 |
|
| 904 |
DESCRIPTION: |
| 905 |
|
| 906 |
\return <ul> |
| 907 |
int |
| 908 |
*/ |
| 909 |
/****************************************************************************/ |
| 910 |
|
| 911 |
static int Gather_EdgeClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data) |
| 912 |
{ |
| 913 |
EDGE *theEdge = (EDGE *)obj; |
| 914 |
|
| 915 |
PRINTDEBUG(gm,1,("Gather_EdgeClosureInfo(): e=" ID_FMTX "pattern=%d \n", |
| 916 |
ID_PRTX(theEdge),PATTERN(theEdge))) |
| 917 |
|
| 918 |
INT pattern = PATTERN(theEdge); |
| 919 |
|
| 920 |
((INT *)data)[0] = pattern; |
| 921 |
|
| 922 |
return(GM_OK); |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
/****************************************************************************/ |
| 928 |
/* |
| 929 |
Scatter_EdgeClosureInfo - |
| 930 |
|
| 931 |
SYNOPSIS: |
| 932 |
static int Scatter_EdgeClosureInfo (DDD_OBJ obj, void *data); |
| 933 |
|
| 934 |
PARAMETERS: |
| 935 |
. obj |
| 936 |
. data |
| 937 |
|
| 938 |
DESCRIPTION: |
| 939 |
|
| 940 |
\return <ul> |
| 941 |
int |
| 942 |
*/ |
| 943 |
/****************************************************************************/ |
| 944 |
|
| 945 |
static int Scatter_EdgeClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data) |
| 946 |
{ |
| 947 |
EDGE *theEdge = (EDGE *)obj; |
| 948 |
|
| 949 |
INT pattern = std::max((INT)PATTERN(theEdge),((INT *)data)[0]); |
| 950 |
|
| 951 |
PRINTDEBUG(gm,1,("Gather_EdgeClosureInfo(): e=" ID_FMTX "pattern=%d \n", |
| 952 |
ID_PRTX(theEdge),pattern)) |
| 953 |
|
| 954 |
SETPATTERN(theEdge,pattern); |
| 955 |
|
| 956 |
return(GM_OK); |
| 957 |
} |
| 958 |
|
| 959 |
INT ExchangeEdgeClosureInfo (GRID *theGrid) |
| 960 |
{ |
| 961 |
auto& context = theGrid->dddContext(); |
| 962 |
const auto& dddctrl = ddd_ctrl(context); |
| 963 |
|
| 964 |
/* exchange information of edges to compute closure */ |
| 965 |
DDD_IFAOneway(context, |
| 966 |
dddctrl.EdgeVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), |
| 967 |
Gather_EdgeClosureInfo, Scatter_EdgeClosureInfo); |
| 968 |
|
| 969 |
return(GM_OK); |
| 970 |
} |
| 971 |
#endif |
| 972 |
|
| 973 |
/****************************************************************************/ |
| 974 |
/* |
| 975 |
ExchangeClosureInfo - |
| 976 |
|
| 977 |
SYNOPSIS: |
| 978 |
static INT ExchangeClosureInfo (GRID *theGrid); |
| 979 |
|
| 980 |
PARAMETERS: |
| 981 |
. theGrid |
| 982 |
|
| 983 |
DESCRIPTION: |
| 984 |
|
| 985 |
\return <ul> |
| 986 |
INT |
| 987 |
*/ |
| 988 |
/****************************************************************************/ |
| 989 |
|
| 990 |
static INT ExchangeClosureInfo (GRID *theGrid) |
| 991 |
{ |
| 992 |
|
| 993 |
/* exchange information of elements to compute closure */ |
| 994 |
if (ExchangeElementClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR); |
| 995 |
|
| 996 |
#ifdef UG_DIM_3 |
| 997 |
/* exchange information of edges to compute closure */ |
| 998 |
if (ExchangeEdgeClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR); |
| 999 |
#endif |
| 1000 |
|
| 1001 |
return(GM_OK); |
| 1002 |
} |
| 1003 |
#endif |
| 1004 |
|
| 1005 |
|
| 1006 |
/****************************************************************************/ |
| 1007 |
/* |
| 1008 |
ComputePatterns - |
| 1009 |
|
| 1010 |
SYNOPSIS: |
| 1011 |
static INT ComputePatterns (GRID *theGrid); |
| 1012 |
|
| 1013 |
PARAMETERS: |
| 1014 |
. theGrid - pointer to grid structure |
| 1015 |
|
| 1016 |
DESCRIPTION: |
| 1017 |
|
| 1018 |
\return <ul> |
| 1019 |
INT |
| 1020 |
*/ |
| 1021 |
/****************************************************************************/ |
| 1022 |
|
| 1023 |
static INT ComputePatterns (const GRID *theGrid) |
| 1024 |
{ |
| 1025 |
/* ComputePatterns works only on master elements */ |
| 1026 |
/* since ghost elements have no information from */ |
| 1027 |
/* RestrictMarks() up to this time and this may */ |
| 1028 |
/* leed to inconsistency while coarsening */ |
| 1029 |
|
| 1030 |
/* reset EDGE/SIDEPATTERN in elements */ |
| 1031 |
/* set SIDEPATTERN in elements */ |
| 1032 |
/* set PATTERN on the edges */ |
| 1033 |
for (ELEMENT *theElement = PFIRSTELEMENT(theGrid); theElement != nullptr; |
| 1034 |
theElement=SUCCE(theElement)) |
| 1035 |
{ |
| 1036 |
#ifdef ModelP |
| 1037 |
if (EGHOST(theElement)) |
| 1038 |
{ |
| 1039 |
#ifdef UG_DIM_3 |
| 1040 |
SETSIDEPATTERN(theElement,0); |
| 1041 |
#endif |
| 1042 |
continue; |
| 1043 |
} |
| 1044 |
#endif |
| 1045 |
|
| 1046 |
if (MARKCLASS(theElement)==RED_CLASS) |
| 1047 |
{ |
| 1048 |
INT Mark = MARK(theElement); |
| 1049 |
SHORT *thePattern = MARK2PATTERN(theElement,Mark); |
| 1050 |
|
| 1051 |
for (INT i = 0; i < EDGES_OF_ELEM(theElement); i++) |
| 1052 |
if (EDGE_IN_PATTERN(thePattern,i)) |
| 1053 |
{ |
| 1054 |
EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, i, 0), |
| 1055 |
CORNER_OF_EDGE_PTR(theElement, i, 1)); |
| 1056 |
|
| 1057 |
ASSERT(theEdge != NULL); |
| 1058 |
|
| 1059 |
SETPATTERN(theEdge,1); |
| 1060 |
} |
| 1061 |
|
| 1062 |
#ifdef UG_DIM_3 |
| 1063 |
/* SIDEPATTERN must be reset here for master elements, */ |
| 1064 |
/* because it overlaps with MARK (980217 s.l.) */ |
| 1065 |
SETSIDEPATTERN(theElement,0); |
| 1066 |
for (INT i = 0; i < SIDES_OF_ELEM(theElement); i++) |
| 1067 |
{ |
| 1068 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 1069 |
if (CORNERS_OF_SIDE(theElement,i)==4) |
| 1070 |
{ |
| 1071 |
#endif |
| 1072 |
/* set SIDEPATTERN if side has node */ |
| 1073 |
if(SIDE_IN_PATTERN(theElement,thePattern,i)) |
| 1074 |
SETSIDEPATTERN(theElement, |
| 1075 |
SIDEPATTERN(theElement) | 1<<i); |
| 1076 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 1077 |
} |
| 1078 |
#endif |
| 1079 |
} |
| 1080 |
#endif |
| 1081 |
} |
| 1082 |
else |
| 1083 |
{ |
| 1084 |
#ifdef UG_DIM_3 |
| 1085 |
/* SIDEPATTERN must be reset here for master elements, */ |
| 1086 |
/* because it overlaps with MARK (980217 s.l.) */ |
| 1087 |
SETSIDEPATTERN(theElement,0); |
| 1088 |
#endif |
| 1089 |
SETMARKCLASS(theElement,NO_CLASS); |
| 1090 |
} |
| 1091 |
} |
| 1092 |
|
| 1093 |
return(GM_OK); |
| 1094 |
} |
| 1095 |
|
| 1096 |
#ifdef UG_DIM_3 |
| 1097 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 1098 |
|
| 1099 |
/****************************************************************************/ |
| 1100 |
/* |
| 1101 |
CorrectTetrahedronSidePattern - |
| 1102 |
|
| 1103 |
SYNOPSIS: |
| 1104 |
static INT CorrectTetrahedronSidePattern (ELEMENT *theElement, INT i, ELEMENT *theNeighbor, INT j); |
| 1105 |
|
| 1106 |
PARAMETERS: |
| 1107 |
. theElement |
| 1108 |
. i |
| 1109 |
. theNeighbor |
| 1110 |
. j |
| 1111 |
|
| 1112 |
DESCRIPTION: |
| 1113 |
|
| 1114 |
\return <ul> |
| 1115 |
INT |
| 1116 |
*/ |
| 1117 |
/****************************************************************************/ |
| 1118 |
|
| 1119 |
static INT CorrectTetrahedronSidePattern (ELEMENT *theElement, INT i, ELEMENT *theNeighbor, INT j) |
| 1120 |
{ |
| 1121 |
INT theEdgeNum,theEdgePattern=0; |
| 1122 |
INT NbEdgeNum,NbEdgePattern,NbSidePattern,NbSideMask; |
| 1123 |
|
| 1124 |
if (TAG(theElement)==PYRAMID || TAG(theElement)==PRISM) |
| 1125 |
return(GM_OK); |
| 1126 |
|
| 1127 |
for (INT k = EDGES_OF_ELEM(theElement) - 1; k >= 0; k--) |
| 1128 |
{ |
| 1129 |
EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, k, 0), |
| 1130 |
CORNER_OF_EDGE_PTR(theElement, k, 1)); |
| 1131 |
ASSERT(theEdge!=NULL); |
| 1132 |
|
| 1133 |
theEdgePattern = (theEdgePattern<<1) | PATTERN(theEdge); |
| 1134 |
} |
| 1135 |
|
| 1136 |
/* because SIDEPATTERN is set to zero, */ |
| 1137 |
/* I choose TriSectionEdge[0] */ |
| 1138 |
theEdgeNum = TriSectionEdge[theEdgePattern |
| 1139 |
&CondensedEdgeOfSide[i]][0]; |
| 1140 |
|
| 1141 |
if (theEdgeNum == -2) RETURN(-1); |
| 1142 |
|
| 1143 |
if (theEdgeNum == -1) return(GM_OK); |
| 1144 |
|
| 1145 |
switch (TAG(theNeighbor)) |
| 1146 |
{ |
| 1147 |
|
| 1148 |
case TETRAHEDRON : |
| 1149 |
|
| 1150 |
NbEdgePattern = 0; |
| 1151 |
|
| 1152 |
for (INT k = 0; k < EDGES_OF_ELEM(theNeighbor); k++) |
| 1153 |
{ |
| 1154 |
EDGE *NbEdge = GetEdge(CORNER_OF_EDGE_PTR(theNeighbor, k, 0), |
| 1155 |
CORNER_OF_EDGE_PTR(theNeighbor, k, 1)); |
| 1156 |
ASSERT(NbEdge!=NULL); |
| 1157 |
NbEdgePattern = NbEdgePattern | (PATTERN(NbEdge)<<k); |
| 1158 |
} |
| 1159 |
|
| 1160 |
NbEdgeNum = TriSectionEdge[NbEdgePattern |
| 1161 |
&CondensedEdgeOfSide[j]][0]; |
| 1162 |
|
| 1163 |
if (NbEdgeNum == -2 || NbEdgeNum == -1) |
| 1164 |
RETURN(-1); |
| 1165 |
|
| 1166 |
if (!(CORNER_OF_EDGE_PTR(theElement,theEdgeNum,0) == |
| 1167 |
CORNER_OF_EDGE_PTR(theNeighbor,NbEdgeNum,0) && |
| 1168 |
CORNER_OF_EDGE_PTR(theElement,theEdgeNum,1) == |
| 1169 |
CORNER_OF_EDGE_PTR(theNeighbor,NbEdgeNum,1) ) |
| 1170 |
&& |
| 1171 |
!(CORNER_OF_EDGE_PTR(theElement,theEdgeNum,0) == |
| 1172 |
CORNER_OF_EDGE_PTR(theNeighbor,NbEdgeNum,1) && |
| 1173 |
CORNER_OF_EDGE_PTR(theElement,theEdgeNum,1) == |
| 1174 |
CORNER_OF_EDGE_PTR(theNeighbor,NbEdgeNum,0) ) ) |
| 1175 |
{ |
| 1176 |
NbSidePattern = SIDEPATTERN(theNeighbor); |
| 1177 |
NbSideMask = (1<<j); |
| 1178 |
|
| 1179 |
if ( NbSidePattern & NbSideMask ) |
| 1180 |
{ |
| 1181 |
NbSidePattern &= ~NbSideMask; |
| 1182 |
#ifdef ModelP |
| 1183 |
/* in this case ExchangeSidePatterns() fails */ |
| 1184 |
/* does it occur ? (980217 s.l.) */ |
| 1185 |
assert(0); |
| 1186 |
#endif |
| 1187 |
} |
| 1188 |
else |
| 1189 |
NbSidePattern |= NbSideMask; |
| 1190 |
|
| 1191 |
PRINTDEBUG(gm,1,("CorrectTetrahedronSidePattern(): nb=" EID_FMTX |
| 1192 |
" new nbsidepattern=%d\n",EID_PRTX(theNeighbor),NbSidePattern)); |
| 1193 |
SETSIDEPATTERN(theNeighbor,NbSidePattern); |
| 1194 |
} |
| 1195 |
break; |
| 1196 |
|
| 1197 |
case PYRAMID : |
| 1198 |
case PRISM : |
| 1199 |
{ |
| 1200 |
INT trisectionedge=-1; |
| 1201 |
|
| 1202 |
for (INT k = 0; k < CORNERS_OF_SIDE(theNeighbor, j); k++) |
| 1203 |
{ |
| 1204 |
INT edge = EDGE_OF_SIDE(theElement, j, k); |
| 1205 |
|
| 1206 |
EDGE *NbEdge = GetEdge(CORNER_OF_EDGE_PTR(theNeighbor, edge, 0), |
| 1207 |
CORNER_OF_EDGE_PTR(theNeighbor, edge, 1)); |
| 1208 |
ASSERT(NbEdge!=NULL); |
| 1209 |
|
| 1210 |
if (PATTERN(NbEdge) && (edge>trisectionedge)) |
| 1211 |
trisectionedge = edge; |
| 1212 |
} |
| 1213 |
assert(trisectionedge != -1); |
| 1214 |
|
| 1215 |
if (theEdgeNum != trisectionedge) |
| 1216 |
SETSIDEPATTERN(theNeighbor, |
| 1217 |
SIDEPATTERN(theNeighbor)|(1<<j)); |
| 1218 |
|
| 1219 |
break; |
| 1220 |
} |
| 1221 |
|
| 1222 |
default : |
| 1223 |
ASSERT(0); |
| 1224 |
} |
| 1225 |
|
| 1226 |
return(GM_OK); |
| 1227 |
} |
| 1228 |
#endif |
| 1229 |
|
| 1230 |
|
| 1231 |
/****************************************************************************/ |
| 1232 |
/* |
| 1233 |
CorrectElementSidePattern - |
| 1234 |
|
| 1235 |
SYNOPSIS: |
| 1236 |
static INT CorrectElementSidePattern (ELEMENT *theElement, ELEMENT *theNeighbor, INT i); |
| 1237 |
|
| 1238 |
PARAMETERS: |
| 1239 |
. theElement |
| 1240 |
. theNeighbor |
| 1241 |
. i |
| 1242 |
|
| 1243 |
DESCRIPTION: |
| 1244 |
|
| 1245 |
\return <ul> |
| 1246 |
INT |
| 1247 |
*/ |
| 1248 |
/****************************************************************************/ |
| 1249 |
|
| 1250 |
static INT CorrectElementSidePattern (ELEMENT *theElement, ELEMENT *theNeighbor, INT i) |
| 1251 |
{ |
| 1252 |
INT j; |
| 1253 |
|
| 1254 |
#ifdef ModelP |
| 1255 |
/* this case should not occur */ |
| 1256 |
if (theNeighbor == NULL) |
| 1257 |
{ |
| 1258 |
ASSERT(EGHOST(theElement)); |
| 1259 |
UserWriteF("CorrectElementSidePattern(): error elem=" EID_FMTX " nb[%d]=" |
| 1260 |
EID_FMTX " nb=" EID_FMTX |
| 1261 |
"\n", EID_PRTX(theElement),i,EID_PRTX(NBELEM(theElement,i)), |
| 1262 |
EID_PRTX(theNeighbor)); |
| 1263 |
return(GM_OK); |
| 1264 |
} |
| 1265 |
#endif |
| 1266 |
|
| 1267 |
/* search neighbors side */ |
| 1268 |
for (j=0; j<SIDES_OF_ELEM(theNeighbor); j++) |
| 1269 |
if (NBELEM(theNeighbor,j) == theElement) |
| 1270 |
break; |
| 1271 |
#ifdef ModelP |
| 1272 |
if (j >= SIDES_OF_ELEM(theNeighbor)) |
| 1273 |
{ |
| 1274 |
if (!(EGHOST(theElement) && EGHOST(theNeighbor))) |
| 1275 |
{ |
| 1276 |
UserWriteF("CorrectElementSidePattern(): ERROR nbelem not found elem=%08x/" |
| 1277 |
EID_FMTX " nb=%08x/" EID_FMTX "\n", |
| 1278 |
theElement,EID_PRTX(theElement),theNeighbor,EID_PRTX(theNeighbor)); |
| 1279 |
} |
| 1280 |
ASSERT(EGHOST(theElement) && EGHOST(theNeighbor)); |
| 1281 |
return(GM_OK); |
| 1282 |
} |
| 1283 |
#else |
| 1284 |
ASSERT(j<SIDES_OF_ELEM(theNeighbor)); |
| 1285 |
#endif |
| 1286 |
|
| 1287 |
/* side is triangle or quadrilateral */ |
| 1288 |
switch (CORNERS_OF_SIDE(theElement,i)) |
| 1289 |
{ |
| 1290 |
case 3 : |
| 1291 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 1292 |
/* handle case with 2 edges of the side refined */ |
| 1293 |
if (CorrectTetrahedronSidePattern(theElement,i,theNeighbor,j) != GM_OK) |
| 1294 |
RETURN(GM_ERROR); |
| 1295 |
#endif |
| 1296 |
break; |
| 1297 |
|
| 1298 |
case 4 : |
| 1299 |
/* if side of one of the neighboring elements has a */ |
| 1300 |
/* sidenode, then both need a sidenode */ |
| 1301 |
if (SIDE_IN_PAT(SIDEPATTERN(theElement),i)) |
| 1302 |
{ |
| 1303 |
SETSIDEPATTERN(theNeighbor, |
| 1304 |
SIDEPATTERN(theNeighbor) | (1<<j)); |
| 1305 |
} |
| 1306 |
else if (SIDE_IN_PAT(SIDEPATTERN(theNeighbor),j)) |
| 1307 |
{ |
| 1308 |
SETSIDEPATTERN(theElement, |
| 1309 |
SIDEPATTERN(theElement) | (1<<i)); |
| 1310 |
} |
| 1311 |
break; |
| 1312 |
|
| 1313 |
default : |
| 1314 |
ASSERT(0); |
| 1315 |
} |
| 1316 |
|
| 1317 |
return(GM_OK); |
| 1318 |
} |
| 1319 |
|
| 1320 |
|
| 1321 |
/****************************************************************************/ |
| 1322 |
/* |
| 1323 |
SetElementSidePatterns - |
| 1324 |
|
| 1325 |
SYNOPSIS: |
| 1326 |
static INT SetElementSidePatterns (GRID *theGrid, ELEMENT *firstElement); |
| 1327 |
|
| 1328 |
PARAMETERS: |
| 1329 |
. theGrid - pointer to grid structure |
| 1330 |
. firstElement |
| 1331 |
|
| 1332 |
DESCRIPTION: |
| 1333 |
|
| 1334 |
\return <ul> |
| 1335 |
INT |
| 1336 |
*/ |
| 1337 |
/****************************************************************************/ |
| 1338 |
|
| 1339 |
static INT SetElementSidePatterns (GRID *theGrid, ELEMENT *firstElement) |
| 1340 |
{ |
| 1341 |
INT i; |
| 1342 |
ELEMENT *theElement,*theNeighbor; |
| 1343 |
|
| 1344 |
/* set pattern (edge and side) on the elements */ |
| 1345 |
for (theElement=firstElement; theElement!=NULL; |
| 1346 |
theElement=SUCCE(theElement)) |
| 1347 |
{ |
| 1348 |
/* make edgepattern consistent with pattern of edges */ |
| 1349 |
SETUSED(theElement,1); |
| 1350 |
|
| 1351 |
#ifndef __ANISOTROPIC__ |
| 1352 |
/** \todo change this for red refinement of pyramids */ |
| 1353 |
if (DIM==3 && TAG(theElement)==PYRAMID) continue; |
| 1354 |
#endif |
| 1355 |
|
| 1356 |
/* make sidepattern consistent with neighbors */ |
| 1357 |
for (i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 1358 |
{ |
| 1359 |
theNeighbor = NBELEM(theElement,i); |
| 1360 |
if (theNeighbor == NULL) continue; |
| 1361 |
|
| 1362 |
/* only one of the neighboring elements does corrections */ |
| 1363 |
/* determine element for side correction by (g)id */ |
| 1364 |
if (_EID_(theElement) < _EID_(theNeighbor)) continue; |
| 1365 |
|
| 1366 |
/* determine element for side correction by used flag */ |
| 1367 |
/** \todo delete this: |
| 1368 |
if (USED(theNeighbor)) continue; |
| 1369 |
*/ |
| 1370 |
|
| 1371 |
/* edgepatterns from theElement and theNeighbor are in final state */ |
| 1372 |
|
| 1373 |
if (CorrectElementSidePattern(theElement,theNeighbor,i) != GM_OK) RETURN(GM_ERROR); |
| 1374 |
} |
| 1375 |
} |
| 1376 |
|
| 1377 |
return(GM_OK); |
| 1378 |
} |
| 1379 |
#endif |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
/****************************************************************************/ |
| 1384 |
/* |
| 1385 |
SetElementRules - |
| 1386 |
|
| 1387 |
SYNOPSIS: |
| 1388 |
static INT SetElementRules (GRID *theGrid, ELEMENT *firstElement, INT *cnt); |
| 1389 |
|
| 1390 |
PARAMETERS: |
| 1391 |
. theGrid - pointer to grid structure |
| 1392 |
. firstElement |
| 1393 |
. cnt |
| 1394 |
|
| 1395 |
DESCRIPTION: |
| 1396 |
|
| 1397 |
\return <ul> |
| 1398 |
INT |
| 1399 |
*/ |
| 1400 |
/****************************************************************************/ |
| 1401 |
|
| 1402 |
static INT SetElementRules (GRID *theGrid, ELEMENT *firstElement, INT *cnt) |
| 1403 |
{ |
| 1404 |
INT Mark,NewPattern; |
| 1405 |
INT thePattern,theEdgePattern,theSidePattern=0; |
| 1406 |
ELEMENT *theElement; |
| 1407 |
|
| 1408 |
[[maybe_unused]] const int me = theGrid->ppifContext().me(); |
| 1409 |
|
| 1410 |
/* set refinement rules from edge- and sidepattern */ |
| 1411 |
(*cnt) = 0; |
| 1412 |
for (theElement=firstElement; theElement!=NULL; |
| 1413 |
theElement=SUCCE(theElement)) |
| 1414 |
{ |
| 1415 |
theEdgePattern = 0; |
| 1416 |
|
| 1417 |
/* compute element pattern */ |
| 1418 |
GetEdgeInfo(theElement,&theEdgePattern,PATTERN); |
| 1419 |
|
| 1420 |
#ifdef UG_DIM_2 |
| 1421 |
thePattern = theEdgePattern; |
| 1422 |
PRINTDEBUG(gm,2,(PFMT "SetElementRules(): e=" EID_FMTX " edgepattern=%d\n", |
| 1423 |
me,EID_PRTX(theElement),theEdgePattern)); |
| 1424 |
#endif |
| 1425 |
#ifdef UG_DIM_3 |
| 1426 |
theSidePattern = SIDEPATTERN(theElement); |
| 1427 |
thePattern = theSidePattern<<EDGES_OF_ELEM(theElement) | theEdgePattern; |
| 1428 |
PRINTDEBUG(gm,2,(PFMT "SetElementRules(): e=" EID_FMTX |
| 1429 |
" edgepattern=%03x sidepattern=%02x\n", |
| 1430 |
me,EID_PRTX(theElement),theEdgePattern,theSidePattern)); |
| 1431 |
#endif |
| 1432 |
|
| 1433 |
/* get Mark from pattern */ |
| 1434 |
Mark = PATTERN2MARK(theElement,thePattern); |
| 1435 |
|
| 1436 |
/* treat Mark according to mode */ |
| 1437 |
if (fifoFlag) |
| 1438 |
{ |
| 1439 |
/* directed refinement */ |
| 1440 |
if (Mark == -1 && MARKCLASS(theElement)==RED_CLASS) |
| 1441 |
{ |
| 1442 |
/* there is no rule for this pattern, switch to red */ |
| 1443 |
Mark = RED; |
| 1444 |
} |
| 1445 |
else |
| 1446 |
ASSERT(Mark != -1); |
| 1447 |
} |
| 1448 |
else if (hFlag==0 && MARKCLASS(theElement)!=RED_CLASS) |
| 1449 |
{ |
| 1450 |
/* refinement with hanging nodes */ |
| 1451 |
Mark = NO_REFINEMENT; |
| 1452 |
} |
| 1453 |
else |
| 1454 |
{ |
| 1455 |
/* refinement with closure (default) */ |
| 1456 |
#ifdef __ANISOTROPIC__ |
| 1457 |
if (MARKCLASS(theElement)==RED_CLASS && TAG(theElement)==PRISM) |
| 1458 |
{ |
| 1459 |
ASSERT(USED(theElement)==1); |
| 1460 |
if (Mark==-1) |
| 1461 |
{ |
| 1462 |
ASSERT(TAG(theElement)==PRISM); |
| 1463 |
/* to implement the anisotropic case for other elements */ |
| 1464 |
/* and anisotropic refinements the initial anisotropic */ |
| 1465 |
/* rule is needed here. (980316 s.l.) */ |
| 1466 |
Mark = PRI_QUADSECT; |
| 1467 |
} |
| 1468 |
else |
| 1469 |
SETUSED(theElement,0); |
| 1470 |
} |
| 1471 |
#endif |
| 1472 |
ASSERT(Mark != -1); |
| 1473 |
|
| 1474 |
/* switch green class to red class? */ |
| 1475 |
if (MARKCLASS(theElement)!=RED_CLASS && |
| 1476 |
SWITCHCLASS(CLASS_OF_RULE(MARK2RULEADR(theElement,Mark)))) |
| 1477 |
{ |
| 1478 |
IFDEBUG(gm,1) |
| 1479 |
UserWriteF(" Switching MARKCLASS=%d for MARK=%d of EID=%d " |
| 1480 |
"to RED_CLASS\n", |
| 1481 |
MARKCLASS(theElement),Mark,ID(theElement)); |
| 1482 |
ENDDEBUG |
| 1483 |
SETMARKCLASS(theElement,RED_CLASS); |
| 1484 |
} |
| 1485 |
} |
| 1486 |
|
| 1487 |
REFINE_ELEMENT_LIST(1,theElement,""); |
| 1488 |
|
| 1489 |
#ifdef UG_DIM_3 |
| 1490 |
/* choose best tet_red rule according to (*theFullRefRule)() */ |
| 1491 |
if (TAG(theElement)==TETRAHEDRON && MARKCLASS(theElement)==RED_CLASS) |
| 1492 |
{ |
| 1493 |
#ifndef DUNE_UGGRID_TET_RULESET |
| 1494 |
if ((Mark==TET_RED || Mark==TET_RED_0_5 || |
| 1495 |
Mark==TET_RED_1_3)) |
| 1496 |
#endif |
| 1497 |
{ |
| 1498 |
PRINTDEBUG(gm,5,("FullRefRule() call with mark=%d\n",Mark)) |
| 1499 |
|
| 1500 |
Mark = (*theFullRefRule)(theElement); |
| 1501 |
assert( Mark==FULL_REFRULE_0_5 || |
| 1502 |
Mark==FULL_REFRULE_1_3 || |
| 1503 |
Mark==FULL_REFRULE_2_4); |
| 1504 |
} |
| 1505 |
} |
| 1506 |
#endif |
| 1507 |
|
| 1508 |
/* get new pattern from mark */ |
| 1509 |
NewPattern = MARK2PAT(theElement,Mark); |
| 1510 |
IFDEBUG(gm,2) |
| 1511 |
UserWriteF(" thePattern=%d EdgePattern=%d SidePattern=%d NewPattern=%d Mark=%d\n", |
| 1512 |
thePattern,theEdgePattern,theSidePattern,NewPattern,Mark); |
| 1513 |
ENDDEBUG |
| 1514 |
|
| 1515 |
|
| 1516 |
if (fifoFlag) |
| 1517 |
{ |
| 1518 |
if (UpdateFIFOLists(theGrid,theElement,thePattern,NewPattern) != GM_OK) return(GM_OK); |
| 1519 |
} |
| 1520 |
|
| 1521 |
if (Mark) (*cnt)++; |
| 1522 |
SETMARK(theElement,Mark); |
| 1523 |
} |
| 1524 |
|
| 1525 |
return(GM_OK); |
| 1526 |
} |
| 1527 |
|
| 1528 |
|
| 1529 |
#ifdef ModelP |
| 1530 |
|
| 1531 |
/****************************************************************************/ |
| 1532 |
/* |
| 1533 |
Gather_AddEdgePattern - |
| 1534 |
|
| 1535 |
SYNOPSIS: |
| 1536 |
static int Gather_AddEdgePattern (DDD_OBJ obj, void *data); |
| 1537 |
|
| 1538 |
PARAMETERS: |
| 1539 |
. obj |
| 1540 |
. data |
| 1541 |
|
| 1542 |
DESCRIPTION: |
| 1543 |
|
| 1544 |
\return <ul> |
| 1545 |
int |
| 1546 |
*/ |
| 1547 |
/****************************************************************************/ |
| 1548 |
|
| 1549 |
static int Gather_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data) |
| 1550 |
{ |
| 1551 |
#ifdef UG_DIM_2 |
| 1552 |
INT pat; |
| 1553 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 1554 |
|
| 1555 |
pat = 0; |
| 1556 |
GetEdgeInfo(theElement,&pat,ADDPATTERN); |
| 1557 |
|
| 1558 |
((INT *)data)[0] = pat; |
| 1559 |
|
| 1560 |
PRINTDEBUG(gm,4,("Gather_AddEdgePattern(): elem=" EID_FMTX "pat=%08x\n", |
| 1561 |
EID_PRTX(theElement),pat)); |
| 1562 |
return(GM_OK); |
| 1563 |
#endif |
| 1564 |
|
| 1565 |
#ifdef UG_DIM_3 |
| 1566 |
INT addpattern; |
| 1567 |
EDGE *theEdge = (EDGE *)obj; |
| 1568 |
|
| 1569 |
addpattern = ADDPATTERN(theEdge); |
| 1570 |
|
| 1571 |
((INT *)data)[0] = addpattern; |
| 1572 |
|
| 1573 |
PRINTDEBUG(gm,4,("Gather_AddEdgePattern(): edge=" ID_FMTX "pat=%08x\n", |
| 1574 |
ID_PRTX(theEdge),addpattern)); |
| 1575 |
return(GM_OK); |
| 1576 |
#endif |
| 1577 |
} |
| 1578 |
|
| 1579 |
|
| 1580 |
/****************************************************************************/ |
| 1581 |
/* |
| 1582 |
Scatter_AddEdgePattern - |
| 1583 |
|
| 1584 |
SYNOPSIS: |
| 1585 |
static int Scatter_AddEdgePattern (DDD_OBJ obj, void *data); |
| 1586 |
|
| 1587 |
PARAMETERS: |
| 1588 |
. obj |
| 1589 |
. data |
| 1590 |
|
| 1591 |
DESCRIPTION: |
| 1592 |
|
| 1593 |
\return <ul> |
| 1594 |
int |
| 1595 |
*/ |
| 1596 |
/****************************************************************************/ |
| 1597 |
|
| 1598 |
static int Scatter_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data) |
| 1599 |
{ |
| 1600 |
#ifdef UG_DIM_2 |
| 1601 |
INT pat; |
| 1602 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 1603 |
|
| 1604 |
/** \todo (HRR 971207): output after SetEdgeInfo (pat not init)? */ |
| 1605 |
PRINTDEBUG(gm,4,("Scatter_AddEdgePattern(): elem=" EID_FMTX "pat=%08x\n", |
| 1606 |
EID_PRTX(theElement),pat)); |
| 1607 |
|
| 1608 |
pat = ((INT *)data)[0]; |
| 1609 |
SetEdgeInfo(theElement,pat,ADDPATTERN,&); |
| 1610 |
|
| 1611 |
return(GM_OK); |
| 1612 |
#endif |
| 1613 |
|
| 1614 |
#ifdef UG_DIM_3 |
| 1615 |
INT addpattern; |
| 1616 |
EDGE *theEdge = (EDGE *)obj; |
| 1617 |
|
| 1618 |
addpattern = std::min((INT)ADDPATTERN(theEdge),((INT *)data)[0]); |
| 1619 |
|
| 1620 |
PRINTDEBUG(gm,4,("Gather_AddEdgePattern(): edge=" ID_FMTX "pat=%08x\n", |
| 1621 |
ID_PRTX(theEdge),addpattern)); |
| 1622 |
|
| 1623 |
SETADDPATTERN(theEdge,addpattern); |
| 1624 |
|
| 1625 |
return(GM_OK); |
| 1626 |
#endif |
| 1627 |
} |
| 1628 |
|
| 1629 |
|
| 1630 |
/****************************************************************************/ |
| 1631 |
/* |
| 1632 |
ExchangeAddPatterns - |
| 1633 |
|
| 1634 |
SYNOPSIS: |
| 1635 |
static INT ExchangeAddPatterns (GRID *theGrid); |
| 1636 |
|
| 1637 |
PARAMETERS: |
| 1638 |
. theGrid - pointer to grid structure |
| 1639 |
|
| 1640 |
DESCRIPTION: |
| 1641 |
|
| 1642 |
\return <ul> |
| 1643 |
INT |
| 1644 |
*/ |
| 1645 |
/****************************************************************************/ |
| 1646 |
|
| 1647 |
static INT ExchangeAddPatterns (GRID *theGrid) |
| 1648 |
{ |
| 1649 |
auto& context = theGrid->dddContext(); |
| 1650 |
const auto& dddctrl = ddd_ctrl(context); |
| 1651 |
|
| 1652 |
/* exchange addpatterns of edges */ |
| 1653 |
#ifdef UG_DIM_2 |
| 1654 |
DDD_IFAOneway(context, |
| 1655 |
dddctrl.ElementVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), |
| 1656 |
Gather_AddEdgePattern, Scatter_AddEdgePattern); |
| 1657 |
#endif |
| 1658 |
#ifdef UG_DIM_3 |
| 1659 |
DDD_IFAOneway(context, |
| 1660 |
dddctrl.EdgeVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT), |
| 1661 |
Gather_AddEdgePattern, Scatter_AddEdgePattern); |
| 1662 |
#endif |
| 1663 |
|
| 1664 |
return(GM_OK); |
| 1665 |
} |
| 1666 |
#endif |
| 1667 |
|
| 1668 |
|
| 1669 |
/****************************************************************************/ |
| 1670 |
/* |
| 1671 |
SetAddPatterns - |
| 1672 |
|
| 1673 |
SYNOPSIS: |
| 1674 |
static INT SetAddPatterns (GRID *theGrid); |
| 1675 |
|
| 1676 |
PARAMETERS: |
| 1677 |
. theGrid - pointer to grid structure |
| 1678 |
|
| 1679 |
DESCRIPTION: |
| 1680 |
|
| 1681 |
\return <ul> |
| 1682 |
INT |
| 1683 |
*/ |
| 1684 |
/****************************************************************************/ |
| 1685 |
|
| 1686 |
static INT SetAddPatterns (GRID *theGrid) |
| 1687 |
{ |
| 1688 |
INT j; |
| 1689 |
ELEMENT *theElement; |
| 1690 |
EDGE *theEdge; |
| 1691 |
|
| 1692 |
/* set additional pattern on the edges */ |
| 1693 |
for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; |
| 1694 |
theElement=SUCCE(theElement)) |
| 1695 |
{ |
| 1696 |
if (MARKCLASS(theElement)!=RED_CLASS) continue; |
| 1697 |
|
| 1698 |
REFINE_ELEMENT_LIST(1,theElement,"SetAddPatterns(): addpattern=0"); |
| 1699 |
|
| 1700 |
for (j=0; j<EDGES_OF_ELEM(theElement); j++) |
| 1701 |
{ |
| 1702 |
/* no green elements for this edge if there is no edge node */ |
| 1703 |
if (!NODE_OF_RULE(theElement,MARK(theElement),j)) |
| 1704 |
continue; |
| 1705 |
|
| 1706 |
theEdge=GetEdge(CORNER_OF_EDGE_PTR(theElement,j,0), |
| 1707 |
CORNER_OF_EDGE_PTR(theElement,j,1)); |
| 1708 |
ASSERT(theEdge != NULL); |
| 1709 |
|
| 1710 |
/* ADDPATTERN is now set to 0 for all edges of red elements */ |
| 1711 |
SETADDPATTERN(theEdge,0); |
| 1712 |
} |
| 1713 |
} |
| 1714 |
|
| 1715 |
#ifdef ModelP |
| 1716 |
if (ExchangeAddPatterns(theGrid)) RETURN(GM_FATAL); |
| 1717 |
#endif |
| 1718 |
|
| 1719 |
return(GM_OK); |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
/****************************************************************************/ |
| 1724 |
/* |
| 1725 |
BuildGreenClosure - |
| 1726 |
|
| 1727 |
SYNOPSIS: |
| 1728 |
static INT BuildGreenClosure (GRID *theGrid); |
| 1729 |
|
| 1730 |
PARAMETERS: |
| 1731 |
. theGrid - pointer to grid structure |
| 1732 |
|
| 1733 |
DESCRIPTION: |
| 1734 |
|
| 1735 |
\return <ul> |
| 1736 |
INT |
| 1737 |
*/ |
| 1738 |
/****************************************************************************/ |
| 1739 |
|
| 1740 |
static INT BuildGreenClosure (const GRID *theGrid) |
| 1741 |
{ |
| 1742 |
INT i; |
| 1743 |
ELEMENT *theElement; |
| 1744 |
EDGE *theEdge; |
| 1745 |
#ifdef UG_DIM_3 |
| 1746 |
INT j; |
| 1747 |
#endif |
| 1748 |
|
| 1749 |
/* build a green covering around the red elements */ |
| 1750 |
for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; |
| 1751 |
theElement=SUCCE(theElement)) |
| 1752 |
{ |
| 1753 |
#ifdef __ANISOTROPIC__ |
| 1754 |
if (MARKCLASS(theElement)==RED_CLASS && |
| 1755 |
!(TAG(theElement)==PRISM && MARK(theElement)==PRI_QUADSECT)) continue; |
| 1756 |
|
| 1757 |
ASSERT(MARKCLASS(theElement)!=RED_CLASS || |
| 1758 |
(MARKCLASS(theElement)==RED_CLASS && TAG(theElement)==PRISM |
| 1759 |
&& MARK(theElement)==PRI_QUADSECT)); |
| 1760 |
#else |
| 1761 |
if (MARKCLASS(theElement)==RED_CLASS) continue; |
| 1762 |
#endif |
| 1763 |
|
| 1764 |
SETUPDATE_GREEN(theElement,0); |
| 1765 |
|
| 1766 |
/* if edge node exists element needs to be green */ |
| 1767 |
for (i=0; i<EDGES_OF_ELEM(theElement); i++) |
| 1768 |
{ |
| 1769 |
theEdge=GetEdge(CORNER_OF_EDGE_PTR(theElement,i,0), |
| 1770 |
CORNER_OF_EDGE_PTR(theElement,i,1)); |
| 1771 |
ASSERT(theEdge != NULL); |
| 1772 |
|
| 1773 |
/* if edge is refined this will be a green element */ |
| 1774 |
if (ADDPATTERN(theEdge) == 0) |
| 1775 |
{ |
| 1776 |
/* for pyramids, prisms and hexhedra Patterns2Rules returns 0 */ |
| 1777 |
/* for non red elements, because there is no complete rule set */ |
| 1778 |
/* switch to mark COPY, because COPY rule refines no edges */ |
| 1779 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 1780 |
if (DIM==3 && TAG(theElement)!=TETRAHEDRON) |
| 1781 |
#else |
| 1782 |
if (DIM==3) |
| 1783 |
#endif |
| 1784 |
{ |
| 1785 |
/* set to no-empty rule, e.g. COPY rule */ |
| 1786 |
#ifdef __ANISOTROPIC__ |
| 1787 |
if (MARKCLASS(theElement) != RED_CLASS) |
| 1788 |
#endif |
| 1789 |
SETMARK(theElement,COPY); |
| 1790 |
|
| 1791 |
/* no existing edge node renew green refinement */ |
| 1792 |
if (MIDNODE(theEdge)==NULL) |
| 1793 |
{ |
| 1794 |
SETUPDATE_GREEN(theElement,1); |
| 1795 |
} |
| 1796 |
} |
| 1797 |
/* tetrahedra in 3D and 2D elements have a complete rule set */ |
| 1798 |
else if (MARK(theElement) == NO_REFINEMENT) |
| 1799 |
{ |
| 1800 |
IFDEBUG(gm,2) |
| 1801 |
UserWriteF(" ERROR: green tetrahedron with no rule! " |
| 1802 |
"EID=%d TAG=%d " |
| 1803 |
"REFINECLASS=%d REFINE=%d MARKCLASS=%d MARK=%d\n", |
| 1804 |
ID(theElement),TAG(theElement),REFINECLASS(theElement), |
| 1805 |
REFINE(theElement),MARKCLASS(theElement), |
| 1806 |
MARK(theElement)); |
| 1807 |
ENDDEBUG |
| 1808 |
} |
| 1809 |
|
| 1810 |
#ifdef __ANISOTROPIC__ |
| 1811 |
if (MARKCLASS(theElement) != RED_CLASS) |
| 1812 |
#endif |
| 1813 |
SETMARKCLASS(theElement,GREEN_CLASS); |
| 1814 |
} |
| 1815 |
else |
| 1816 |
{ |
| 1817 |
/* existing edge node is deleted */ |
| 1818 |
/* renew green refinement if element will be a green one */ |
| 1819 |
if (MIDNODE(theEdge)!=NULL) |
| 1820 |
SETUPDATE_GREEN(theElement,1); |
| 1821 |
} |
| 1822 |
} |
| 1823 |
|
| 1824 |
#ifdef UG_DIM_3 |
| 1825 |
/* if side node exists element needs to be green */ |
| 1826 |
for (i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 1827 |
{ |
| 1828 |
ELEMENT *theNeighbor; |
| 1829 |
|
| 1830 |
theNeighbor = NBELEM(theElement,i); |
| 1831 |
|
| 1832 |
if (theNeighbor==NULL) continue; |
| 1833 |
|
| 1834 |
for (j=0; j<SIDES_OF_ELEM(theNeighbor); j++) |
| 1835 |
if (NBELEM(theNeighbor,j) == theElement) |
| 1836 |
break; |
| 1837 |
|
| 1838 |
#ifdef ModelP |
| 1839 |
if (j >= SIDES_OF_ELEM(theNeighbor)) |
| 1840 |
{ |
| 1841 |
ASSERT(EGHOST(theElement) && EGHOST(theNeighbor)); |
| 1842 |
continue; |
| 1843 |
} |
| 1844 |
#else |
| 1845 |
ASSERT(j<SIDES_OF_ELEM(theNeighbor)); |
| 1846 |
#endif |
| 1847 |
|
| 1848 |
if (NODE_OF_RULE(theNeighbor,MARK(theNeighbor), |
| 1849 |
EDGES_OF_ELEM(theNeighbor)+j)) |
| 1850 |
{ |
| 1851 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 1852 |
if (TAG(theNeighbor)==TETRAHEDRON) |
| 1853 |
printf("ERROR: no side nodes for tetrahedra! side=%d\n",j); |
| 1854 |
#endif |
| 1855 |
#ifdef __ANISOTROPIC__ |
| 1856 |
if (MARKCLASS(theElement) != RED_CLASS) |
| 1857 |
#endif |
| 1858 |
SETMARKCLASS(theElement,GREEN_CLASS); |
| 1859 |
} |
| 1860 |
|
| 1861 |
|
| 1862 |
/* side node change? */ |
| 1863 |
if ((!NODE_OF_RULE(theNeighbor,REFINE(theNeighbor), |
| 1864 |
EDGES_OF_ELEM(theNeighbor)+j) && |
| 1865 |
NODE_OF_RULE(theNeighbor,MARK(theNeighbor), |
| 1866 |
EDGES_OF_ELEM(theNeighbor)+j)) || |
| 1867 |
(NODE_OF_RULE(theNeighbor,REFINE(theNeighbor), |
| 1868 |
EDGES_OF_ELEM(theNeighbor)+j) && |
| 1869 |
!NODE_OF_RULE(theNeighbor,MARK(theNeighbor), |
| 1870 |
EDGES_OF_ELEM(theNeighbor)+j))) |
| 1871 |
{ |
| 1872 |
SETUPDATE_GREEN(theElement,1); |
| 1873 |
} |
| 1874 |
} |
| 1875 |
#endif |
| 1876 |
|
| 1877 |
|
| 1878 |
#ifndef ModelP |
| 1879 |
/* if element is green before refinement and will be green after */ |
| 1880 |
/* refinement and nothing changes -> reset USED flag */ |
| 1881 |
/* in parallel case: one communication to determine the minimum */ |
| 1882 |
/* over all copies of an green element would be needed */ |
| 1883 |
if (REFINECLASS(theElement)==GREEN_CLASS && |
| 1884 |
MARKCLASS(theElement)==GREEN_CLASS && UPDATE_GREEN(theElement)==0) |
| 1885 |
{ |
| 1886 |
/* do not renew green refinement */ |
| 1887 |
SETUSED(theElement,0); |
| 1888 |
} |
| 1889 |
#ifdef __ANISOTROPIC__ |
| 1890 |
if (MARKCLASS(theElement)==RED_CLASS && UPDATE_GREEN(theElement)==0) |
| 1891 |
{ |
| 1892 |
ASSERT(TAG(theElement)==PRISM && MARK(theElement)==PRI_QUADSECT); |
| 1893 |
SETUSED(theElement,0); |
| 1894 |
} |
| 1895 |
#endif |
| 1896 |
#endif |
| 1897 |
} |
| 1898 |
|
| 1899 |
return(GM_OK); |
| 1900 |
} |
| 1901 |
|
| 1902 |
#if defined(ModelP) && defined(Debug) |
| 1903 |
|
| 1904 |
#define CEIL(n) ((n)+((ALIGNMENT-((n)&(ALIGNMENT-1)))&(ALIGNMENT-1))) |
| 1905 |
|
| 1906 |
/****************************************************************************/ |
| 1907 |
/* |
| 1908 |
Gather_ElementInfo - |
| 1909 |
|
| 1910 |
SYNOPSIS: |
| 1911 |
static int Gather_ElementInfo (DDD_OBJ obj, void *Data); |
| 1912 |
|
| 1913 |
PARAMETERS: |
| 1914 |
. obj |
| 1915 |
. Data |
| 1916 |
|
| 1917 |
DESCRIPTION: |
| 1918 |
|
| 1919 |
\return <ul> |
| 1920 |
int |
| 1921 |
*/ |
| 1922 |
/****************************************************************************/ |
| 1923 |
|
| 1924 |
static int Gather_ElementInfo (DDD::DDDContext&, DDD_OBJ obj, void *Data) |
| 1925 |
{ |
| 1926 |
INT epat,eaddpat; |
| 1927 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 1928 |
char *data = (char *)Data; |
| 1929 |
|
| 1930 |
PRINTDEBUG(gm,4,("Gather_ElementInfo(): elem=" EID_FMTX "\n", |
| 1931 |
EID_PRTX(theElement))); |
| 1932 |
|
| 1933 |
memcpy(data,theElement,sizeof(struct generic_element)); |
| 1934 |
data += CEIL(sizeof(struct generic_element)); |
| 1935 |
|
| 1936 |
epat = 0; |
| 1937 |
GetEdgeInfo(theElement,&epat,PATTERN); |
| 1938 |
((int *)data)[0] = epat; |
| 1939 |
data += sizeof(INT); |
| 1940 |
|
| 1941 |
eaddpat = 0; |
| 1942 |
GetEdgeInfo(theElement,&eaddpat,ADDPATTERN); |
| 1943 |
((int *)data)[0] = eaddpat; |
| 1944 |
|
| 1945 |
return(GM_OK); |
| 1946 |
} |
| 1947 |
|
| 1948 |
/* this macro compares control word macros of two elements */ |
| 1949 |
#define COMPARE_MACRO(elem0,elem1,macro,print) \ |
| 1950 |
if (macro(elem0) != macro(elem1)) \ |
| 1951 |
{ \ |
| 1952 |
print("e=" EID_FMTX " macro=%s differs value0=%d value1=%d \n", \ |
| 1953 |
EID_PRTX(elem0),# macro,macro(elem0),macro(elem1)); \ |
| 1954 |
assert(0); \ |
| 1955 |
} |
| 1956 |
|
| 1957 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 1958 |
#define COMPARE_MACROX(elem0,elem1,macro,print) \ |
| 1959 |
{ \ |
| 1960 |
INT _mark0,_mark1,_pat0,_pat1; \ |
| 1961 |
\ |
| 1962 |
_mark0 = macro(elem0); _mark1 = macro(elem1); \ |
| 1963 |
_pat0 = MARK2PAT((elem0),_mark0); _pat1 = MARK2PAT((elem1),_mark1); \ |
| 1964 |
if ((_pat0 & ((1<<10)-1)) != (_pat1 & ((1<<10)-1))) \ |
| 1965 |
COMPARE_MACRO(elem0,elem1,macro,print) \ |
| 1966 |
} |
| 1967 |
#else |
| 1968 |
#define COMPARE_MACROX(elem0,elem1,macro,print) \ |
| 1969 |
COMPARE_MACRO(elem0,elem1,macro,print) |
| 1970 |
#endif |
| 1971 |
|
| 1972 |
/* this macro compares two values */ |
| 1973 |
#define COMPARE_VALUE(elem0,val0,val1,string,print) \ |
| 1974 |
if ((val0) != (val1)) \ |
| 1975 |
{ \ |
| 1976 |
(print)("e=" EID_FMTX " %s differs value0=%d value1=%d \n", \ |
| 1977 |
EID_PRTX(elem0),(string),(val0),(val1)); \ |
| 1978 |
assert(0); \ |
| 1979 |
} |
| 1980 |
|
| 1981 |
|
| 1982 |
/****************************************************************************/ |
| 1983 |
/* |
| 1984 |
Scatter_ElementInfo - |
| 1985 |
|
| 1986 |
SYNOPSIS: |
| 1987 |
static int Scatter_ElementInfo (DDD_OBJ obj, void *Data); |
| 1988 |
|
| 1989 |
PARAMETERS: |
| 1990 |
. obj |
| 1991 |
. Data |
| 1992 |
|
| 1993 |
DESCRIPTION: |
| 1994 |
|
| 1995 |
\return <ul> |
| 1996 |
int |
| 1997 |
*/ |
| 1998 |
/****************************************************************************/ |
| 1999 |
|
| 2000 |
static int Scatter_ElementInfo (DDD::DDDContext&, DDD_OBJ obj, void *Data) |
| 2001 |
{ |
| 2002 |
INT epat,mpat,eaddpat,maddpat; |
| 2003 |
ELEMENT *theElement = (ELEMENT *)obj; |
| 2004 |
struct generic_element ge; |
| 2005 |
ELEMENT *theMaster = (ELEMENT *)≥ |
| 2006 |
char *data = (char *)Data; |
| 2007 |
|
| 2008 |
memcpy(theMaster,data,sizeof(struct generic_element)); |
| 2009 |
data += CEIL(sizeof(struct generic_element)); |
| 2010 |
|
| 2011 |
PRINTDEBUG(gm,4,("Scatter_ElementInfo(): Comparing elem=" |
| 2012 |
EID_FMTX " master=" EID_FMTX "\n",EID_PRTX(theElement), |
| 2013 |
EID_PRTX(theMaster))); |
| 2014 |
|
| 2015 |
/* now compare the control entries of master with it local copy */ |
| 2016 |
COMPARE_MACRO(theElement,theMaster,REFINECLASS,PrintDebug) |
| 2017 |
COMPARE_MACRO(theElement,theMaster,MARKCLASS,PrintDebug) |
| 2018 |
COMPARE_MACROX(theElement,theMaster,REFINE,PrintDebug) |
| 2019 |
COMPARE_MACROX(theElement,theMaster,MARK,PrintDebug) |
| 2020 |
COMPARE_MACRO(theElement,theMaster,COARSEN,PrintDebug) |
| 2021 |
COMPARE_MACRO(theElement,theMaster,USED,PrintDebug) |
| 2022 |
/* #ifndef DUNE_UGGRID_TET_RULESET */ |
| 2023 |
#ifdef UG_DIM_3 |
| 2024 |
COMPARE_MACRO(theElement,theMaster,SIDEPATTERN,PrintDebug) |
| 2025 |
#endif |
| 2026 |
/* #endif */ |
| 2027 |
|
| 2028 |
epat = 0; |
| 2029 |
GetEdgeInfo(theElement,&epat,PATTERN); |
| 2030 |
mpat = ((INT *)data)[0]; |
| 2031 |
data += sizeof(INT); |
| 2032 |
COMPARE_VALUE(theElement,epat,mpat,"EdgePattern",PrintDebug) |
| 2033 |
|
| 2034 |
eaddpat = 0; |
| 2035 |
GetEdgeInfo(theElement,&eaddpat,ADDPATTERN); |
| 2036 |
maddpat = ((INT *)data)[0]; |
| 2037 |
COMPARE_VALUE(theElement,eaddpat,maddpat,"EdgeAddPattern",PrintDebug) |
| 2038 |
|
| 2039 |
return(GM_OK); |
| 2040 |
} |
| 2041 |
|
| 2042 |
static INT CheckElementInfo (GRID *theGrid) |
| 2043 |
{ |
| 2044 |
auto& context = theGrid->dddContext(); |
| 2045 |
const auto& dddctrl = ddd_ctrl(context); |
| 2046 |
|
| 2047 |
/* exchange element info */ |
| 2048 |
DDD_IFAOneway(context, |
| 2049 |
dddctrl.ElementVHIF,GRID_ATTR(theGrid),IF_FORWARD, |
| 2050 |
CEIL(sizeof(struct generic_element))+2*sizeof(INT), |
| 2051 |
Gather_ElementInfo, Scatter_ElementInfo); |
| 2052 |
|
| 2053 |
return(GM_OK); |
| 2054 |
} |
| 2055 |
#endif |
| 2056 |
|
| 2057 |
|
| 2058 |
/****************************************************************************/ |
| 2059 |
/* */ |
| 2060 |
/* Function: GridClosure */ |
| 2061 |
/* */ |
| 2062 |
/* Purpose: compute closure for next level. A closure can only be */ |
| 2063 |
/* determined if the rule set for the used elements is complete. */ |
| 2064 |
/* This means that for all side and edge patterns possible for */ |
| 2065 |
/* an element type exists a rule which closes the element. */ |
| 2066 |
/* In this case a FIFO for computing the closure is not needed */ |
| 2067 |
/* any more and the closure can be computed in one step. */ |
| 2068 |
/* */ |
| 2069 |
/* Param: GRID *theGrid: pointer to grid structure */ |
| 2070 |
/* */ |
| 2071 |
/* return: INT >0: elements will be refined */ |
| 2072 |
/* INT 0: no elements will be refined */ |
| 2073 |
/* INT -1: an error occurred */ |
| 2074 |
/* */ |
| 2075 |
/****************************************************************************/ |
| 2076 |
/****************************************************************************/ |
| 2077 |
/** \brief Compute closure for next level |
| 2078 |
|
| 2079 |
\param theGrid - pointer to grid structure |
| 2080 |
|
| 2081 |
This function computes closure for next level. A closure can only be |
| 2082 |
determined if the rule set for the used elements is complete. This means |
| 2083 |
that for all side and edge patterns possible for an element type exists |
| 2084 |
a rule which closes the element. In this case a FIFO for computing the |
| 2085 |
closure is not needed any more and the closure can be computed in one step. |
| 2086 |
|
| 2087 |
\return <ul> |
| 2088 |
.n >0 elements will be refined |
| 2089 |
.n =0 no elements will be refined |
| 2090 |
.n =-1 an error occurred |
| 2091 |
*/ |
| 2092 |
/****************************************************************************/ |
| 2093 |
|
| 2094 |
static int GridClosure (GRID *theGrid) |
| 2095 |
{ |
| 2096 |
INT cnt; |
| 2097 |
|
| 2098 |
/* initialize used control word entries */ |
| 2099 |
if (PrepareGridClosure(theGrid) != GM_OK) RETURN(GM_ERROR); |
| 2100 |
|
| 2101 |
/* compute pattern on edges and elements */ |
| 2102 |
if (ComputePatterns(theGrid) != GM_OK) RETURN(GM_ERROR); |
| 2103 |
|
| 2104 |
firstElement = PFIRSTELEMENT(theGrid); |
| 2105 |
|
| 2106 |
if (fifoFlag) |
| 2107 |
if (InitClosureFIFO() != GM_OK) return(GM_OK); |
| 2108 |
|
| 2109 |
/* fifo loop */ |
| 2110 |
do |
| 2111 |
{ |
| 2112 |
#ifdef UG_DIM_3 |
| 2113 |
#if defined(ModelP) && defined(DUNE_UGGRID_TET_RULESET) |
| 2114 |
/* edge pattern is needed consistently in CorrectTetrahedronSidePattern() */ |
| 2115 |
if (!refine_seq) |
| 2116 |
{ |
| 2117 |
if (ExchangeEdgeClosureInfo(theGrid) != GM_OK) return(GM_ERROR); |
| 2118 |
} |
| 2119 |
#endif |
| 2120 |
|
| 2121 |
/* set side patterns on the elements */ |
| 2122 |
if (SetElementSidePatterns(theGrid,firstElement) != GM_OK) RETURN(GM_ERROR); |
| 2123 |
#endif |
| 2124 |
|
| 2125 |
#ifdef ModelP |
| 2126 |
if (ExchangeClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR); |
| 2127 |
#endif |
| 2128 |
|
| 2129 |
/* set rules on the elements */ |
| 2130 |
if (SetElementRules(theGrid,firstElement,&cnt) != GM_OK) RETURN(GM_ERROR); |
| 2131 |
|
| 2132 |
} |
| 2133 |
/* exit only if fifo not active or fifo queue */ |
| 2134 |
/* empty or all processor have finished closure */ |
| 2135 |
while (fifoFlag && UpdateClosureFIFO(theGrid) && |
| 2136 |
ManageParallelFIFO(theGrid->ppifContext(), firstElement)); |
| 2137 |
|
| 2138 |
/* set patterns on all edges of red elements */ |
| 2139 |
if (SetAddPatterns(theGrid) != GM_OK) RETURN(GM_ERROR); |
| 2140 |
|
| 2141 |
/* build the closure around the red elements */ |
| 2142 |
if (BuildGreenClosure(theGrid) != GM_OK) RETURN(GM_ERROR); |
| 2143 |
|
| 2144 |
#if defined(Debug) && defined(ModelP) |
| 2145 |
if (CheckElementInfo(theGrid)) RETURN(GM_ERROR); |
| 2146 |
#endif |
| 2147 |
|
| 2148 |
return(cnt); |
| 2149 |
} |
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
/****************************************************************************/ |
| 2154 |
/* |
| 2155 |
GetNeighborSons - fill SonList for theElement |
| 2156 |
|
| 2157 |
SYNOPSIS: |
| 2158 |
static INT GetNeighborSons (ELEMENT *theElement, ELEMENT *theSon, |
| 2159 |
ELEMENT *SonList[MAX_SONS], int count, int nsons); |
| 2160 |
|
| 2161 |
PARAMETERS: |
| 2162 |
. theElement - father element |
| 2163 |
. theSon - currently visited son |
| 2164 |
. SonList[MAX_SONS] - the list of sons |
| 2165 |
. count - son count |
| 2166 |
. sons - number of sons |
| 2167 |
|
| 2168 |
DESCRIPTION: |
| 2169 |
This function fills SonList for theElement with a breadth first search |
| 2170 |
|
| 2171 |
\return <ul> |
| 2172 |
INT |
| 2173 |
.n new son count |
| 2174 |
*/ |
| 2175 |
/****************************************************************************/ |
| 2176 |
|
| 2177 |
static INT GetNeighborSons (ELEMENT *theElement, ELEMENT *theSon, |
| 2178 |
ELEMENT *SonList[MAX_SONS], int count, int nsons) |
| 2179 |
{ |
| 2180 |
ELEMENT *NbElement; |
| 2181 |
int i,j, startson, stopson; |
| 2182 |
|
| 2183 |
startson = count; |
| 2184 |
|
| 2185 |
for (i=0; i<SIDES_OF_ELEM(theSon); i++) |
| 2186 |
{ |
| 2187 |
NbElement = NBELEM(theSon,i); |
| 2188 |
if (NbElement == NULL) continue; |
| 2189 |
if (EFATHER(NbElement) == theElement) |
| 2190 |
{ |
| 2191 |
/* is NbElement already in list */ |
| 2192 |
for (j=0; j<count; j++) |
| 2193 |
if (SonList[j] == NbElement) |
| 2194 |
break; |
| 2195 |
if (j==count && count<nsons) |
| 2196 |
SonList[count++] = NbElement; |
| 2197 |
} |
| 2198 |
} |
| 2199 |
if (count == nsons) return(count); |
| 2200 |
|
| 2201 |
stopson = count; |
| 2202 |
for (i=startson; i<stopson; i++) |
| 2203 |
{ |
| 2204 |
if (count<nsons) count = GetNeighborSons(theElement,SonList[i], |
| 2205 |
SonList,count,nsons); |
| 2206 |
else return(count); |
| 2207 |
} |
| 2208 |
return(count); |
| 2209 |
} |
| 2210 |
|
| 2211 |
|
| 2212 |
#ifdef ModelP |
| 2213 |
|
| 2214 |
|
| 2215 |
/****************************************************************************/ |
| 2216 |
/* |
| 2217 |
GetSons - fill SonList for theElement |
| 2218 |
|
| 2219 |
SYNOPSIS: |
| 2220 |
INT GetAllSons (ELEMENT *theElement, ELEMENT *SonList[MAX_SONS]); |
| 2221 |
|
| 2222 |
PARAMETERS: |
| 2223 |
. theElement |
| 2224 |
. SonList[MAX_SONS] |
| 2225 |
|
| 2226 |
DESCRIPTION: |
| 2227 |
This function fills SonList for theElement |
| 2228 |
|
| 2229 |
\return <ul> |
| 2230 |
INT |
| 2231 |
.n 0 if ok |
| 2232 |
.n 1 if an error occurs |
| 2233 |
*/ |
| 2234 |
/****************************************************************************/ |
| 2235 |
|
| 2236 |
INT NS_DIM_PREFIX GetAllSons (const ELEMENT *theElement, ELEMENT *SonList[MAX_SONS]) |
| 2237 |
{ |
| 2238 |
ELEMENT *son; |
| 2239 |
int SonID,i; |
| 2240 |
|
| 2241 |
ASSERT(theElement != NULL); |
| 2242 |
|
| 2243 |
for (SonID=0; SonID<MAX_SONS; SonID++) |
| 2244 |
SonList[SonID] = NULL; |
| 2245 |
|
| 2246 |
if (NSONS(theElement) == 0) return(GM_OK); |
| 2247 |
|
| 2248 |
SonID = 0; |
| 2249 |
|
| 2250 |
for (i=0; i<2; i++) |
| 2251 |
{ |
| 2252 |
if (i == 0) |
| 2253 |
son = SON(theElement,PRIO2INDEX(PrioMaster)); |
| 2254 |
else |
| 2255 |
son = SON(theElement,PRIO2INDEX(PrioHGhost)); |
| 2256 |
|
| 2257 |
if (son == NULL) |
| 2258 |
continue; |
| 2259 |
else |
| 2260 |
SonList[SonID++] = son; |
| 2261 |
|
| 2262 |
while (SUCCE(son) != NULL) |
| 2263 |
{ |
| 2264 |
if (EFATHER(SUCCE(son)) == theElement |
| 2265 |
&& PRIO2INDEX(EPRIO(son))==PRIO2INDEX(EPRIO(SUCCE(son))) |
| 2266 |
) |
| 2267 |
{ |
| 2268 |
SonList[SonID++] = SUCCE(son); |
| 2269 |
son = SUCCE(son); |
| 2270 |
ASSERT(SonID <= MAX_SONS); |
| 2271 |
} |
| 2272 |
else |
| 2273 |
break; |
| 2274 |
} |
| 2275 |
} |
| 2276 |
|
| 2277 |
return(GM_OK); |
| 2278 |
} |
| 2279 |
#endif |
| 2280 |
|
| 2281 |
|
| 2282 |
/****************************************************************************/ |
| 2283 |
/* |
| 2284 |
GetSons - |
| 2285 |
|
| 2286 |
SYNOPSIS: |
| 2287 |
INT GetSons (ELEMENT *theElement, ELEMENT *SonList[MAX_SONS]); |
| 2288 |
|
| 2289 |
PARAMETERS: |
| 2290 |
. theElement |
| 2291 |
. SonList[MAX_SONS] |
| 2292 |
|
| 2293 |
DESCRIPTION: |
| 2294 |
|
| 2295 |
\return <ul> |
| 2296 |
INT |
| 2297 |
*/ |
| 2298 |
/****************************************************************************/ |
| 2299 |
|
| 2300 |
INT NS_DIM_PREFIX GetSons (const ELEMENT *theElement, ELEMENT *SonList[MAX_SONS]) |
| 2301 |
{ |
| 2302 |
int SonID; |
| 2303 |
ELEMENT *son; |
| 2304 |
|
| 2305 |
if (theElement==NULL) RETURN(GM_ERROR); |
| 2306 |
|
| 2307 |
for (SonID=0; SonID<MAX_SONS; SonID++) |
| 2308 |
SonList[SonID] = NULL; |
| 2309 |
|
| 2310 |
if (NSONS(theElement) == 0) return(GM_OK); |
| 2311 |
|
| 2312 |
SonID = 0; |
| 2313 |
SonList[SonID++] = son = SON(theElement,PRIO2INDEX(PrioMaster)); |
| 2314 |
|
| 2315 |
if (son == NULL) return(GM_OK); |
| 2316 |
|
| 2317 |
while (SUCCE(son) != NULL) |
| 2318 |
{ |
| 2319 |
if (EFATHER(SUCCE(son)) == theElement |
| 2320 |
#ifdef ModelP |
| 2321 |
&& PRIO2INDEX(EPRIO(son))==PRIO2INDEX(EPRIO(SUCCE(son))) |
| 2322 |
#endif |
| 2323 |
) |
| 2324 |
{ |
| 2325 |
SonList[SonID++] = SUCCE(son); |
| 2326 |
son = SUCCE(son); |
| 2327 |
ASSERT(SonID <= MAX_SONS); |
| 2328 |
} |
| 2329 |
else |
| 2330 |
break; |
| 2331 |
|
| 2332 |
} |
| 2333 |
|
| 2334 |
return(GM_OK); |
| 2335 |
} |
| 2336 |
|
| 2337 |
/****************************************************************************/ |
| 2338 |
/* */ |
| 2339 |
/* Function: RestrictElementMark */ |
| 2340 |
/* */ |
| 2341 |
/* Purpose: restrict refinement marks of an element whose sons are */ |
| 2342 |
/* further marked for refinement */ |
| 2343 |
/* */ |
| 2344 |
/* Param: ELEMENT *theElement: pointer to the element */ |
| 2345 |
/* */ |
| 2346 |
/* return: INT: =0 ok */ |
| 2347 |
/* >0 error */ |
| 2348 |
/* */ |
| 2349 |
/****************************************************************************/ |
| 2350 |
/****************************************************************************/ |
| 2351 |
/* |
| 2352 |
RestrictElementMark - restrict refinement marks |
| 2353 |
|
| 2354 |
SYNOPSIS: |
| 2355 |
static INT RestrictElementMark(ELEMENT *theElement); |
| 2356 |
|
| 2357 |
PARAMETERS: |
| 2358 |
. theElement - pointer to the element |
| 2359 |
|
| 2360 |
DESCRIPTION: |
| 2361 |
This function restricts refinement marks of an element whose sons are |
| 2362 |
further marked for refinement |
| 2363 |
|
| 2364 |
\return <ul> |
| 2365 |
INT |
| 2366 |
.n =0 - ok |
| 2367 |
.n >0 - error |
| 2368 |
*/ |
| 2369 |
/****************************************************************************/ |
| 2370 |
|
| 2371 |
static INT RestrictElementMark(ELEMENT *theElement) |
| 2372 |
{ |
| 2373 |
#ifdef UG_DIM_3 |
| 2374 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 2375 |
EDGE *theEdge; |
| 2376 |
int j,Rule,Pattern; |
| 2377 |
#endif |
| 2378 |
#endif |
| 2379 |
|
| 2380 |
if (MARKCLASS(theElement)==RED_CLASS) |
| 2381 |
{ |
| 2382 |
/** \todo this mark is from DropMarks()! */ |
| 2383 |
/* theElement is marked from outside */ |
| 2384 |
/** \todo edit this for new element type or */ |
| 2385 |
/* for different restrictions */ |
| 2386 |
switch (TAG(theElement)) |
| 2387 |
{ |
| 2388 |
#ifdef UG_DIM_2 |
| 2389 |
case TRIANGLE : |
| 2390 |
SETMARK(theElement,T_RED); |
| 2391 |
break; |
| 2392 |
case QUADRILATERAL : |
| 2393 |
SETMARK(theElement,Q_RED); |
| 2394 |
break; |
| 2395 |
#endif |
| 2396 |
#ifdef UG_DIM_3 |
| 2397 |
case TETRAHEDRON : |
| 2398 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 2399 |
if (MARK(theElement)!=RED) |
| 2400 |
/** \todo Is REFINE always as red rule available? */ |
| 2401 |
SETMARK(theElement,REFINE(theElement)); |
| 2402 |
#else |
| 2403 |
SETMARK(theElement,TET_RED); |
| 2404 |
#endif |
| 2405 |
break; |
| 2406 |
case PYRAMID : |
| 2407 |
SETMARK(theElement,PYR_RED); |
| 2408 |
break; |
| 2409 |
case PRISM : |
| 2410 |
SETMARK(theElement,PRI_RED); |
| 2411 |
break; |
| 2412 |
case HEXAHEDRON : |
| 2413 |
SETMARK(theElement,HEXA_RED); |
| 2414 |
break; |
| 2415 |
#endif |
| 2416 |
|
| 2417 |
default : |
| 2418 |
ASSERT(0); |
| 2419 |
} |
| 2420 |
} |
| 2421 |
else |
| 2422 |
{ |
| 2423 |
/** \todo edit this for new element type or for different restrictions */ |
| 2424 |
switch (TAG(theElement)) |
| 2425 |
{ |
| 2426 |
#ifdef UG_DIM_2 |
| 2427 |
case TRIANGLE : |
| 2428 |
SETMARK(theElement,T_RED); |
| 2429 |
break; |
| 2430 |
|
| 2431 |
case QUADRILATERAL : |
| 2432 |
SETMARK(theElement,Q_RED); |
| 2433 |
break; |
| 2434 |
#endif |
| 2435 |
#ifdef UG_DIM_3 |
| 2436 |
case TETRAHEDRON : |
| 2437 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 2438 |
/* theElement is not marked from outside, */ |
| 2439 |
/* so find a reg. rule being consistent */ |
| 2440 |
/* with those neighbors of all sons of */ |
| 2441 |
/* theElement which are marked for refine.*/ |
| 2442 |
/* this choice will make sure these marks */ |
| 2443 |
/* will not be distroyed. */ |
| 2444 |
Pattern = RULE2PAT(theElement, |
| 2445 |
REFINE(theElement)); |
| 2446 |
for (j=0; j<EDGES_OF_ELEM(theElement); j++) |
| 2447 |
{ |
| 2448 |
theEdge=GetEdge(CORNER_OF_EDGE_PTR(theElement,j,0), |
| 2449 |
CORNER_OF_EDGE_PTR(theElement,j,1)); |
| 2450 |
ASSERT(theEdge != NULL); |
| 2451 |
|
| 2452 |
/** \todo What's on when MIDNODE exists?? */ |
| 2453 |
if (MIDNODE(theEdge)==NULL) |
| 2454 |
{ |
| 2455 |
theEdge=GetEdge( |
| 2456 |
SONNODE(CORNER_OF_EDGE_PTR(theElement,j,0)), |
| 2457 |
SONNODE(CORNER_OF_EDGE_PTR(theElement,j,1))); |
| 2458 |
ASSERT(theEdge != NULL); |
| 2459 |
|
| 2460 |
/** \todo Is ADDPATTERN needed for fitting with other green elements?? */ |
| 2461 |
if (ADDPATTERN(theEdge)) |
| 2462 |
Pattern |= (1<<j); |
| 2463 |
PRINTDEBUG(gm,4,("RestrictElementMark(): modified Pattern=%d bisects now edge=%d too\n",Pattern,j)) |
| 2464 |
} |
| 2465 |
} |
| 2466 |
Rule = PATTERN2RULE(theElement,Pattern); |
| 2467 |
SETMARK(theElement,RULE2MARK(theElement,Rule)); |
| 2468 |
/** \todo delete this old code |
| 2469 |
SETMARK(theElement,PATTERN2MARK(theElement,Pattern)); */ |
| 2470 |
/** \todo this would be the quick fix |
| 2471 |
SETMARK(theElement,FULL_REFRULE); */ |
| 2472 |
#else |
| 2473 |
SETMARK(theElement,TET_RED); |
| 2474 |
#endif |
| 2475 |
break; |
| 2476 |
case PYRAMID : |
| 2477 |
SETMARK(theElement,PYR_RED); |
| 2478 |
break; |
| 2479 |
case PRISM : |
| 2480 |
#ifdef __ANISOTROPIC__ |
| 2481 |
SETMARK(theElement,PRI_QUADSECT); |
| 2482 |
#else |
| 2483 |
SETMARK(theElement,PRI_RED); |
| 2484 |
#endif |
| 2485 |
break; |
| 2486 |
case HEXAHEDRON : |
| 2487 |
SETMARK(theElement,HEXA_RED); |
| 2488 |
break; |
| 2489 |
#endif |
| 2490 |
default : |
| 2491 |
ASSERT(0); |
| 2492 |
} |
| 2493 |
SETMARKCLASS(theElement,RED_CLASS); |
| 2494 |
} |
| 2495 |
|
| 2496 |
return(GM_OK); |
| 2497 |
} |
| 2498 |
|
| 2499 |
/****************************************************************************/ |
| 2500 |
/* |
| 2501 |
RestrictMarks - restrict refinement marks when going down |
| 2502 |
|
| 2503 |
SYNOPSIS: |
| 2504 |
static INT RestrictMarks (GRID *theGrid); |
| 2505 |
|
| 2506 |
PARAMETERS: |
| 2507 |
. theGrid - pointer to grid structure |
| 2508 |
|
| 2509 |
DESCRIPTION: |
| 2510 |
This function restricts refinement marks when going down |
| 2511 |
|
| 2512 |
\return <ul> |
| 2513 |
INT |
| 2514 |
.n 0 if ok |
| 2515 |
.n >0 if an error occurs |
| 2516 |
*/ |
| 2517 |
/****************************************************************************/ |
| 2518 |
|
| 2519 |
static INT RestrictMarks (const GRID *theGrid) |
| 2520 |
{ |
| 2521 |
ELEMENT *theElement,*SonList[MAX_SONS]; |
| 2522 |
INT flag; |
| 2523 |
|
| 2524 |
for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; |
| 2525 |
theElement=SUCCE(theElement)) |
| 2526 |
{ |
| 2527 |
if (GetSons(theElement,SonList)!=GM_OK) RETURN(GM_ERROR); |
| 2528 |
|
| 2529 |
if (hFlag) |
| 2530 |
{ |
| 2531 |
if ( |
| 2532 |
/* if element is not refined anyway, */ |
| 2533 |
/* then there are no restrictions to apply */ |
| 2534 |
REFINE(theElement) == NO_REFINEMENT || |
| 2535 |
|
| 2536 |
/* irregular elements are marked by estimator, */ |
| 2537 |
/* because they are leaf elements */ |
| 2538 |
ECLASS(theElement) == YELLOW_CLASS || |
| 2539 |
ECLASS(theElement) == GREEN_CLASS || |
| 2540 |
|
| 2541 |
/* regular elements with YELLOW_CLASS copies are */ |
| 2542 |
/* marked by estimator, because the marks are dropped */ |
| 2543 |
REFINECLASS(theElement) == YELLOW_CLASS |
| 2544 |
) |
| 2545 |
{ |
| 2546 |
continue; |
| 2547 |
} |
| 2548 |
|
| 2549 |
/* regular elements with GREEN_CLASS refinement */ |
| 2550 |
/* go to no refinement or red refinement */ |
| 2551 |
if (REFINECLASS(theElement)==GREEN_CLASS) |
| 2552 |
{ |
| 2553 |
for (UINT i=0; i<NSONS(theElement); i++) |
| 2554 |
{ |
| 2555 |
#ifdef ModelP |
| 2556 |
if (SonList[i] == NULL) break; |
| 2557 |
#endif |
| 2558 |
|
| 2559 |
/* Is the son marked for further refinement */ |
| 2560 |
if (MARK(SonList[i])>NO_REFINEMENT) |
| 2561 |
{ |
| 2562 |
if (RestrictElementMark(theElement)) RETURN(GM_ERROR); |
| 2563 |
|
| 2564 |
/* this must be done only once for each element */ |
| 2565 |
break; |
| 2566 |
} |
| 2567 |
} |
| 2568 |
continue; |
| 2569 |
} |
| 2570 |
|
| 2571 |
/* regular elements with regular refinement are */ |
| 2572 |
/* the only ones to coarsen */ |
| 2573 |
if (REFINECLASS(theElement) == RED_CLASS) |
| 2574 |
{ |
| 2575 |
#ifndef __ANISOTROPIC__ |
| 2576 |
SETMARK(theElement,REFINE(theElement)); |
| 2577 |
SETMARKCLASS(theElement,REFINECLASS(theElement)); |
| 2578 |
#else |
| 2579 |
ASSERT(MARK(theElement)>=1); |
| 2580 |
#endif |
| 2581 |
} |
| 2582 |
} |
| 2583 |
|
| 2584 |
#ifdef ModelP |
| 2585 |
/* if no (or not all) sons are found by GetSons() on */ |
| 2586 |
/* this proc then coarsening is not allowed */ |
| 2587 |
if (REFINECLASS(theElement)==RED_CLASS && |
| 2588 |
SonList[0]==NULL) continue; |
| 2589 |
#endif |
| 2590 |
|
| 2591 |
flag = 0; |
| 2592 |
for (UINT i=0; i < MAX_SONS && SonList[i]!=NULL; i++) |
| 2593 |
{ |
| 2594 |
/* if not all sons are marked no unrefinement is possible */ |
| 2595 |
if (!COARSEN(SonList[i]) || REFINECLASS(SonList[i])==RED_CLASS) |
| 2596 |
{ |
| 2597 |
flag = 1; |
| 2598 |
break; |
| 2599 |
} |
| 2600 |
} |
| 2601 |
|
| 2602 |
if (flag) continue; |
| 2603 |
|
| 2604 |
/* preserve regular refinement marks */ |
| 2605 |
if (hFlag==0 && SonList[0]==NULL) continue; |
| 2606 |
|
| 2607 |
/* remove refinement */ |
| 2608 |
SETMARK(theElement,NO_REFINEMENT); |
| 2609 |
SETMARKCLASS(theElement,NO_CLASS); |
| 2610 |
SETCOARSEN(theElement,1); |
| 2611 |
} |
| 2612 |
|
| 2613 |
return(GM_OK); |
| 2614 |
} |
| 2615 |
|
| 2616 |
/****************************************************************************/ |
| 2617 |
/* |
| 2618 |
ComputeCopies - determine copy elements from node classes |
| 2619 |
|
| 2620 |
SYNOPSIS: |
| 2621 |
static int ComputeCopies (GRID *theGrid); |
| 2622 |
|
| 2623 |
PARAMETERS: |
| 2624 |
. theGrid - pointer to grid structure |
| 2625 |
|
| 2626 |
DESCRIPTION: |
| 2627 |
This function determines copy elements from node classes |
| 2628 |
|
| 2629 |
\return <ul> |
| 2630 |
int |
| 2631 |
.n GM_OK if ok |
| 2632 |
*/ |
| 2633 |
/****************************************************************************/ |
| 2634 |
|
| 2635 |
static int ComputeCopies (GRID *theGrid) |
| 2636 |
{ |
| 2637 |
ELEMENT *theElement; |
| 2638 |
int flag; |
| 2639 |
int cnt = 0; |
| 2640 |
PRINTDEBUG(gm,1,("ComputeCopies on level %d\n",GLEVEL(theGrid))); |
| 2641 |
|
| 2642 |
[[maybe_unused]] const int me = theGrid->ppifContext().me(); |
| 2643 |
|
| 2644 |
/* set class of all dofs on next level to 0 */ |
| 2645 |
ClearNextNodeClasses(theGrid); |
| 2646 |
|
| 2647 |
/* seed dofs of regularly and irregularly refined elements to 3 */ |
| 2648 |
flag = 0; |
| 2649 |
for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; |
| 2650 |
theElement=SUCCE(theElement)) |
| 2651 |
{ |
| 2652 |
if (MARK(theElement)!=NO_REFINEMENT && |
| 2653 |
(MARKCLASS(theElement)==RED_CLASS || |
| 2654 |
MARKCLASS(theElement)==GREEN_CLASS)) |
| 2655 |
{ |
| 2656 |
SeedNextNodeClasses(theElement); |
| 2657 |
flag=1; /* there is at least one element to be refined */ |
| 2658 |
} |
| 2659 |
} |
| 2660 |
|
| 2661 |
/* copy all option or neighborhood */ |
| 2662 |
if (rFlag==GM_COPY_ALL) |
| 2663 |
{ |
| 2664 |
#ifdef ModelP |
| 2665 |
flag = UG_GlobalMaxINT(theGrid->ppifContext(), flag); |
| 2666 |
#endif |
| 2667 |
if (flag) |
| 2668 |
for (theElement=FIRSTELEMENT(theGrid); theElement!=NULL; |
| 2669 |
theElement=SUCCE(theElement)) |
| 2670 |
{ |
| 2671 |
SeedNextNodeClasses(theElement); |
| 2672 |
} |
| 2673 |
} |
| 2674 |
else |
| 2675 |
{ |
| 2676 |
PropagateNextNodeClasses(theGrid); |
| 2677 |
} |
| 2678 |
|
| 2679 |
/* an element is copied if it has a dof of class 2 and higher */ |
| 2680 |
for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; |
| 2681 |
theElement=SUCCE(theElement)) |
| 2682 |
{ |
| 2683 |
INT maxclass = 0; |
| 2684 |
|
| 2685 |
if ((MARK(theElement)==NO_REFINEMENT)&& |
| 2686 |
((maxclass=MaxNextNodeClass(theElement))>=MINVNCLASS)) |
| 2687 |
{ |
| 2688 |
PRINTDEBUG(gm,1,(PFMT "ComputeCopies(): level=%d e=" EID_FMTX "yellow marked\n", |
| 2689 |
me,LEVEL(theElement),EID_PRTX(theElement))); |
| 2690 |
SETMARK(theElement,COPY); |
| 2691 |
SETMARKCLASS(theElement,YELLOW_CLASS); |
| 2692 |
cnt++; |
| 2693 |
} |
| 2694 |
else |
| 2695 |
{ |
| 2696 |
PRINTDEBUG(gm,1,(PFMT "ComputeCopies(): level=%d e=" EID_FMTX "not yellow marked" |
| 2697 |
" mark=%d maxclass=%d\n", |
| 2698 |
me,LEVEL(theElement),EID_PRTX(theElement),MARK(theElement),maxclass)); |
| 2699 |
} |
| 2700 |
} |
| 2701 |
|
| 2702 |
return(cnt); |
| 2703 |
} |
| 2704 |
|
| 2705 |
/****************************************************************************/ |
| 2706 |
/* |
| 2707 |
CheckElementContextConsistency - check NTYPE flags of nodes |
| 2708 |
|
| 2709 |
SYNOPSIS: |
| 2710 |
static void CheckElementContextConsistency(ELEMENT *theElement); |
| 2711 |
|
| 2712 |
PARAMETERS: |
| 2713 |
. theElement - element to check |
| 2714 |
|
| 2715 |
DESCRIPTION: |
| 2716 |
This function checks NTYPE flags of nodes in elementcontextt with the sons |
| 2717 |
|
| 2718 |
\return <ul> |
| 2719 |
void |
| 2720 |
*/ |
| 2721 |
/****************************************************************************/ |
| 2722 |
#ifdef Debug |
| 2723 |
static void CheckElementContextConsistency(ELEMENT *theElement, |
| 2724 |
ELEMENTCONTEXT theElementContext) |
| 2725 |
{ |
| 2726 |
int i; |
| 2727 |
[[maybe_unused]] int errorflag = 0; |
| 2728 |
int errortype[MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM]; |
| 2729 |
int correcttype[MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM]; |
| 2730 |
|
| 2731 |
for (i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) |
| 2732 |
errortype[i] = correcttype[i] = -1; |
| 2733 |
|
| 2734 |
|
| 2735 |
/* check corner nodes */ |
| 2736 |
for (i=0; i<CORNERS_OF_ELEM(theElement); i++) |
| 2737 |
if (theElementContext[i] != NULL) |
| 2738 |
if(!CORNERTYPE(theElementContext[i])) |
| 2739 |
{ |
| 2740 |
errortype[i] = NTYPE(theElementContext[i]); |
| 2741 |
correcttype[i] = CORNER_NODE; |
| 2742 |
} |
| 2743 |
|
| 2744 |
/* check mid nodes */ |
| 2745 |
for (i=CORNERS_OF_ELEM(theElement); |
| 2746 |
i<CORNERS_OF_ELEM(theElement)+EDGES_OF_ELEM(theElement); |
| 2747 |
i++) |
| 2748 |
{ |
| 2749 |
if (theElementContext[i] != NULL) |
| 2750 |
if(NTYPE(theElementContext[i]) != MID_NODE) |
| 2751 |
{ |
| 2752 |
errortype[i] = NTYPE(theElementContext[i]); |
| 2753 |
correcttype[i] = MID_NODE; |
| 2754 |
} |
| 2755 |
} |
| 2756 |
|
| 2757 |
#ifdef UG_DIM_3 |
| 2758 |
/* check side nodes */ |
| 2759 |
for (i=CORNERS_OF_ELEM(theElement)+EDGES_OF_ELEM(theElement); |
| 2760 |
i<CORNERS_OF_ELEM(theElement)+EDGES_OF_ELEM(theElement)+ |
| 2761 |
SIDES_OF_ELEM(theElement); |
| 2762 |
i++) |
| 2763 |
{ |
| 2764 |
if (theElementContext[i] != NULL) |
| 2765 |
if(NTYPE(theElementContext[i]) != SIDE_NODE) |
| 2766 |
{ |
| 2767 |
errortype[i] = NTYPE(theElementContext[i]); |
| 2768 |
correcttype[i] = SIDE_NODE; |
| 2769 |
} |
| 2770 |
} |
| 2771 |
|
| 2772 |
#endif |
| 2773 |
|
| 2774 |
/* check center node */ |
| 2775 |
i = CORNERS_OF_ELEM(theElement)+CENTER_NODE_INDEX(theElement); |
| 2776 |
if (theElementContext[i] != NULL) |
| 2777 |
if(NTYPE(theElementContext[i]) != CENTER_NODE) |
| 2778 |
{ |
| 2779 |
errortype[i] = NTYPE(theElementContext[i]); |
| 2780 |
correcttype[i] = CENTER_NODE; |
| 2781 |
} |
| 2782 |
|
| 2783 |
for (i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) |
| 2784 |
if (errortype[i] != -1) |
| 2785 |
{ |
| 2786 |
printf("ERROR: TAG=%d NTYPE(CONTEXT(i=%d)=%d should be %d\n", |
| 2787 |
TAG(theElement),i,errortype[i],correcttype[i]); |
| 2788 |
fflush(stdout); |
| 2789 |
errorflag = 1; |
| 2790 |
} |
| 2791 |
|
| 2792 |
ASSERT(errorflag == 0); |
| 2793 |
} |
| 2794 |
#endif |
| 2795 |
|
| 2796 |
/****************************************************************************/ |
| 2797 |
/* |
| 2798 |
UpdateContext - assemble references |
| 2799 |
|
| 2800 |
SYNOPSIS: |
| 2801 |
static int UpdateContext (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext); |
| 2802 |
|
| 2803 |
PARAMETERS: |
| 2804 |
. theGrid - grid level of the sons of theElement |
| 2805 |
. theElement - element to refine |
| 2806 |
. theContext - context structure to update |
| 2807 |
|
| 2808 |
DESCRIPTION: |
| 2809 |
This function assembles references to objects which interact with the sons |
| 2810 |
of the given element, i.e. objects are allocated, kept or deleted as |
| 2811 |
indicated by MARK (i) corner nodes (ii) nodes at midpoints of edges |
| 2812 |
|
| 2813 |
\return <ul> |
| 2814 |
int |
| 2815 |
.n 0 - ok |
| 2816 |
.n 1 - fatal memory error |
| 2817 |
*/ |
| 2818 |
/****************************************************************************/ |
| 2819 |
|
| 2820 |
static int UpdateContext (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext) |
| 2821 |
{ |
| 2822 |
/* reset context to NULL */ |
| 2823 |
for(INT i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) |
| 2824 |
theElementContext[i] = NULL; |
| 2825 |
|
| 2826 |
/* is element to refine */ |
| 2827 |
if (!MARKED(theElement)) return(GM_OK); |
| 2828 |
|
| 2829 |
const INT Mark = MARK(theElement); |
| 2830 |
|
| 2831 |
/* allocate corner nodes if necessary */ |
| 2832 |
for (INT i=0; i<CORNERS_OF_ELEM(theElement); i++) |
| 2833 |
{ |
| 2834 |
NODE* theNode = CORNER(theElement,i); |
| 2835 |
if (SONNODE(theNode)==NULL) |
| 2836 |
{ |
| 2837 |
SONNODE(theNode) = CreateSonNode(theGrid,theNode); |
| 2838 |
if (SONNODE(theNode)==NULL) |
| 2839 |
RETURN(GM_FATAL); |
| 2840 |
#ifdef IDENT_ONLY_NEW |
| 2841 |
SETNEW_NIDENT(SONNODE(theNode),1); |
| 2842 |
#endif |
| 2843 |
} |
| 2844 |
theElementContext[i] = SONNODE(theNode); |
| 2845 |
} |
| 2846 |
|
| 2847 |
/* allocate edge midpoint nodes */ |
| 2848 |
/* nodes on refined edges */ |
| 2849 |
NODE** MidNodes = theElementContext+CORNERS_OF_ELEM(theElement); |
| 2850 |
for (INT i=0; i<EDGES_OF_ELEM(theElement); i++) |
| 2851 |
{ |
| 2852 |
const INT Corner0 = CORNER_OF_EDGE(theElement,i,0); |
| 2853 |
const INT Corner1 = CORNER_OF_EDGE(theElement,i,1); |
| 2854 |
|
| 2855 |
bool toBisect = false; |
| 2856 |
|
| 2857 |
if (MARKED_NEW_GREEN(theElement)) |
| 2858 |
{ |
| 2859 |
const EDGE* theEdge = GetEdge(CORNER(theElement,Corner0), |
| 2860 |
CORNER(theElement,Corner1)); |
| 2861 |
ASSERT(theEdge != NULL); |
| 2862 |
|
| 2863 |
if (ADDPATTERN(theEdge) == 0) |
| 2864 |
{ |
| 2865 |
toBisect = true; |
| 2866 |
MidNodes[i] = MIDNODE(theEdge); |
| 2867 |
} |
| 2868 |
} |
| 2869 |
#ifndef __ANISOTROPIC__ |
| 2870 |
else |
| 2871 |
#endif |
| 2872 |
if (NODE_OF_RULE(theElement,Mark,i)) |
| 2873 |
{ |
| 2874 |
toBisect = true; |
| 2875 |
} |
| 2876 |
|
| 2877 |
IFDEBUG(gm,2) |
| 2878 |
if (MidNodes[i] == NULL) |
| 2879 |
UserWriteF("\n MidNodes[%d]: toBisect=%d ID(Corner0)=%d " |
| 2880 |
"ID(Corner1)=%d", |
| 2881 |
i,toBisect,ID(CORNER(theElement,Corner0)), |
| 2882 |
ID(CORNER(theElement,Corner1))); |
| 2883 |
else |
| 2884 |
UserWriteF("\n MidNodes[%d]: toBisect=%d ID(Corner0)=%d " |
| 2885 |
"ID(Corner1)=%d" |
| 2886 |
" ID(MidNode)=%d",i,toBisect,ID(CORNER(theElement,Corner0)), |
| 2887 |
ID(CORNER(theElement,Corner1)),ID(MidNodes[i])); |
| 2888 |
ENDDEBUG |
| 2889 |
|
| 2890 |
if (toBisect) |
| 2891 |
{ |
| 2892 |
/* we need a midpoint node */ |
| 2893 |
if (MidNodes[i]!=NULL) continue; |
| 2894 |
const NODE* Node0 = CORNER(theElement,Corner0); |
| 2895 |
const NODE* Node1 = CORNER(theElement,Corner1); |
| 2896 |
const EDGE* theEdge = GetEdge(Node0,Node1); |
| 2897 |
if (theEdge == nullptr) |
| 2898 |
RETURN(GM_FATAL); |
| 2899 |
MidNodes[i] = MIDNODE(theEdge); |
| 2900 |
/* MidNodes[i] = GetMidNode(theElement,i); */ |
| 2901 |
if (MidNodes[i] == NULL) |
| 2902 |
{ |
| 2903 |
MidNodes[i] = CreateMidNode(theGrid,theElement,NULL,i); |
| 2904 |
if (MidNodes[i]==NULL) |
| 2905 |
RETURN(GM_FATAL); |
| 2906 |
#ifdef IDENT_ONLY_NEW |
| 2907 |
SETNEW_NIDENT(MidNodes[i],1); |
| 2908 |
#endif |
| 2909 |
IFDEBUG(gm,2) |
| 2910 |
UserWriteF(" created ID(MidNode)=%d for edge=%d",ID(MidNodes[i]),i); |
| 2911 |
ENDDEBUG |
| 2912 |
} |
| 2913 |
assert(MidNodes[i]!=NULL); |
| 2914 |
} |
| 2915 |
} |
| 2916 |
|
| 2917 |
IFDEBUG(gm,2) |
| 2918 |
UserWriteF("\n"); |
| 2919 |
ENDDEBUG |
| 2920 |
|
| 2921 |
#ifdef UG_DIM_3 |
| 2922 |
/* nodes on refined sides */ |
| 2923 |
NODE** SideNodes = theElementContext+CORNERS_OF_ELEM(theElement)+ |
| 2924 |
EDGES_OF_ELEM(theElement); |
| 2925 |
for (INT i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 2926 |
{ |
| 2927 |
/* no side nodes for triangular sides yet */ |
| 2928 |
#ifdef DUNE_UGGRID_TET_RULESET |
| 2929 |
if (CORNERS_OF_SIDE(theElement,i) == 3) continue; |
| 2930 |
#endif |
| 2931 |
|
| 2932 |
bool toCreate = false; |
| 2933 |
/* is side node needed */ |
| 2934 |
if (MARKED_NEW_GREEN(theElement)) |
| 2935 |
{ |
| 2936 |
const ELEMENT *theNeighbor = NBELEM(theElement,i); |
| 2937 |
|
| 2938 |
if (theNeighbor!=NULL) |
| 2939 |
{ |
| 2940 |
if (MARKCLASS(theNeighbor)!=GREEN_CLASS && |
| 2941 |
MARKCLASS(theNeighbor)!=YELLOW_CLASS) |
| 2942 |
{ |
| 2943 |
INT j; |
| 2944 |
for (j=0; j<SIDES_OF_ELEM(theNeighbor); j++) |
| 2945 |
{ |
| 2946 |
if (NBELEM(theNeighbor,j) == theElement) break; |
| 2947 |
} |
| 2948 |
ASSERT(j<SIDES_OF_ELEM(theNeighbor)); |
| 2949 |
if (NODE_OF_RULE(theNeighbor,MARK(theNeighbor), |
| 2950 |
EDGES_OF_ELEM(theNeighbor)+j)) |
| 2951 |
toCreate = true; |
| 2952 |
} |
| 2953 |
} |
| 2954 |
} |
| 2955 |
#ifndef __ANISOTROPIC__ |
| 2956 |
else |
| 2957 |
#endif |
| 2958 |
if (NODE_OF_RULE(theElement,Mark,EDGES_OF_ELEM(theElement)+i)) |
| 2959 |
{ |
| 2960 |
toCreate = true; |
| 2961 |
} |
| 2962 |
|
| 2963 |
IFDEBUG(gm,2) |
| 2964 |
if (SideNodes[i] == NULL) |
| 2965 |
UserWriteF(" SideNode[%d]: create=%d old=%x", |
| 2966 |
i,toCreate,SideNodes[i]); |
| 2967 |
else |
| 2968 |
UserWriteF(" SideNode[%d]: create=%d old=%x oldID=%d",i,toCreate, |
| 2969 |
SideNodes[i],ID(SideNodes[i])); |
| 2970 |
if (SideNodes[i] != NULL) |
| 2971 |
if (START(SideNodes[i])!=NULL) |
| 2972 |
{ |
| 2973 |
UserWriteF("\n NO_OF_ELEM of EDGES:"); |
| 2974 |
for (LINK *sidelink = START(SideNodes[i]); |
| 2975 |
sidelink!=NULL; |
| 2976 |
sidelink=NEXT(sidelink)) |
| 2977 |
{ |
| 2978 |
UserWriteF(" NO=%d NodeTo=%d",NO_OF_ELEM(MYEDGE(sidelink)), |
| 2979 |
ID(NBNODE(sidelink))); |
| 2980 |
} |
| 2981 |
UserWrite("\n"); |
| 2982 |
} |
| 2983 |
ENDDEBUG |
| 2984 |
|
| 2985 |
if (toCreate) |
| 2986 |
{ |
| 2987 |
const ELEMENT *theNeighbor = NBELEM(theElement,i); |
| 2988 |
|
| 2989 |
IFDEBUG(gm,1) |
| 2990 |
if (theNeighbor != NULL) |
| 2991 |
{ |
| 2992 |
IFDEBUG(gm,3) |
| 2993 |
UserWriteF(" ID(theNeighbor)=%d nbadr=%x:\n", |
| 2994 |
ID(theNeighbor),theNeighbor); |
| 2995 |
ENDDEBUG |
| 2996 |
} |
| 2997 |
else |
| 2998 |
{ |
| 2999 |
/* this must be a boundary side */ |
| 3000 |
ASSERT(SIDE_ON_BND(theElement,i)); |
| 3001 |
} |
| 3002 |
ENDDEBUG |
| 3003 |
|
| 3004 |
/* |
| 3005 |
if (MARKED_NEW_GREEN(theNeighbor) && USED(theNeighbor)==0) |
| 3006 |
*/ |
| 3007 |
if (theNeighbor !=NULL) |
| 3008 |
{ |
| 3009 |
|
| 3010 |
IFDEBUG(gm,3) |
| 3011 |
UserWriteF(" Searching for side node already allocated:\n"); |
| 3012 |
ENDDEBUG |
| 3013 |
|
| 3014 |
/* check for side node */ |
| 3015 |
SideNodes[i] = GetSideNode(theElement,i); |
| 3016 |
} |
| 3017 |
|
| 3018 |
if (SideNodes[i] == NULL) |
| 3019 |
{ |
| 3020 |
|
| 3021 |
/* allocate the sidenode */ |
| 3022 |
if ((SideNodes[i] = CreateSideNode(theGrid,theElement,NULL,i)) == NULL) |
| 3023 |
RETURN(GM_FATAL); |
| 3024 |
|
| 3025 |
#ifdef IDENT_ONLY_NEW |
| 3026 |
SETNEW_NIDENT(SideNodes[i],1); |
| 3027 |
#endif |
| 3028 |
} |
| 3029 |
|
| 3030 |
IFDEBUG(gm,0) |
| 3031 |
ASSERT(SideNodes[i]!=NULL); |
| 3032 |
for (INT j = 0; j < EDGES_OF_SIDE(theElement,i); j++) |
| 3033 |
{ |
| 3034 |
const EDGE *fatherEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement,EDGE_OF_SIDE(theElement,i,j),0), |
| 3035 |
CORNER_OF_EDGE_PTR(theElement,EDGE_OF_SIDE(theElement,i,j),1)); |
| 3036 |
|
| 3037 |
[[maybe_unused]] const NODE* Node0 = MIDNODE(fatherEdge); |
| 3038 |
|
| 3039 |
/* if side node exists all mid nodes must exist */ |
| 3040 |
ASSERT(Node0 != NULL); |
| 3041 |
} |
| 3042 |
ENDDEBUG |
| 3043 |
} |
| 3044 |
|
| 3045 |
IFDEBUG(gm,2) |
| 3046 |
if (SideNodes[i] != NULL) |
| 3047 |
UserWriteF(" new=%x newID=%d\n",SideNodes[i],ID(SideNodes[i])); |
| 3048 |
else |
| 3049 |
UserWriteF(" new=%x\n",SideNodes[i]); |
| 3050 |
ENDDEBUG |
| 3051 |
} |
| 3052 |
#endif |
| 3053 |
|
| 3054 |
/* allocate center node */ |
| 3055 |
NODE** CenterNode = MidNodes+CENTER_NODE_INDEX(theElement); |
| 3056 |
CenterNode[0] = NULL; |
| 3057 |
|
| 3058 |
bool toCreate = false; |
| 3059 |
if (CenterNode[0] == NULL) |
| 3060 |
{ |
| 3061 |
|
| 3062 |
if (MARKED_NEW_GREEN(theElement)) |
| 3063 |
{ |
| 3064 |
toCreate = true; |
| 3065 |
} |
| 3066 |
#ifndef __ANISOTROPIC__ |
| 3067 |
else |
| 3068 |
#endif |
| 3069 |
if (NODE_OF_RULE(theElement,Mark,CENTER_NODE_INDEX(theElement))) |
| 3070 |
{ |
| 3071 |
toCreate = true; |
| 3072 |
} |
| 3073 |
} |
| 3074 |
|
| 3075 |
IFDEBUG(gm,2) |
| 3076 |
if (CenterNode[0] == NULL) |
| 3077 |
UserWriteF(" CenterNode: create=%d old=%x",toCreate,CenterNode[0]); |
| 3078 |
else |
| 3079 |
UserWriteF(" CenterNode: create=%d old=%x oldID=%d",toCreate, |
| 3080 |
CenterNode[0],ID(CenterNode[0])); |
| 3081 |
ENDDEBUG |
| 3082 |
|
| 3083 |
if (toCreate) |
| 3084 |
{ |
| 3085 |
if ((CenterNode[0] = CreateCenterNode(theGrid,theElement,NULL)) == NULL) |
| 3086 |
RETURN(GM_FATAL); |
| 3087 |
} |
| 3088 |
|
| 3089 |
#ifdef ModelP |
| 3090 |
/* mark nodes as needed */ |
| 3091 |
for(INT i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) |
| 3092 |
{ |
| 3093 |
if (theElementContext[i] != NULL) SETUSED(theElementContext[i],1); |
| 3094 |
} |
| 3095 |
#endif |
| 3096 |
|
| 3097 |
IFDEBUG(gm,2) |
| 3098 |
if (CenterNode[0] != NULL) |
| 3099 |
UserWriteF(" new=%x newID=%d\n",CenterNode[0],ID(CenterNode[0])); |
| 3100 |
else |
| 3101 |
UserWriteF(" new=%x\n",CenterNode[0]); |
| 3102 |
ENDDEBUG |
| 3103 |
|
| 3104 |
return(GM_OK); |
| 3105 |
} |
| 3106 |
|
| 3107 |
|
| 3108 |
/****************************************************************************/ |
| 3109 |
/* |
| 3110 |
UnrefineElement - remove previous refinement |
| 3111 |
|
| 3112 |
SYNOPSIS: |
| 3113 |
static INT UnrefineElement (GRID *theGrid, ELEMENT *theElement); |
| 3114 |
|
| 3115 |
PARAMETERS: |
| 3116 |
. theGrid: grid level of sons of theElement |
| 3117 |
. theElement: element to refine |
| 3118 |
|
| 3119 |
DESCRIPTION: |
| 3120 |
This function removes previous refinement for an element and all sonelement |
| 3121 |
recursively, deletes: (i) all connections, (ii) all interior nodes and edges |
| 3122 |
are deleted, (iii) sons are deleted and references to sons reset to NULL. |
| 3123 |
|
| 3124 |
\return <ul> |
| 3125 |
INT |
| 3126 |
*/ |
| 3127 |
/****************************************************************************/ |
| 3128 |
|
| 3129 |
static INT UnrefineElement (GRID *theGrid, ELEMENT *theElement) |
| 3130 |
{ |
| 3131 |
int s; |
| 3132 |
ELEMENT *theSon,*SonList[MAX_SONS]; |
| 3133 |
|
| 3134 |
/* something to do ? */ |
| 3135 |
if ((REFINE(theElement)==NO_REFINEMENT)||(theGrid==NULL)) return(GM_OK); |
| 3136 |
|
| 3137 |
if (GetAllSons(theElement,SonList)!=GM_OK) RETURN(GM_FATAL); |
| 3138 |
|
| 3139 |
for (s=0; s<MAX_SONS && SonList[s]!=NULL; s++) |
| 3140 |
{ |
| 3141 |
theSon = SonList[s]; |
| 3142 |
SETMARK(theSon,NO_REFINEMENT); |
| 3143 |
if (IS_REFINED(theSon)) |
| 3144 |
{ |
| 3145 |
if (UnrefineElement(UPGRID(theGrid),theSon)) RETURN(GM_FATAL); |
| 3146 |
} |
| 3147 |
} |
| 3148 |
|
| 3149 |
/* remove son elements */ |
| 3150 |
#ifndef ModelP |
| 3151 |
IFDEBUG(gm,1) |
| 3152 |
if (!REFINED_NEW_GREEN(theElement)) |
| 3153 |
{ |
| 3154 |
if (NSONS(theElement) != NSONS_OF_RULE(MARK2RULEADR(theElement, |
| 3155 |
REFINE(theElement)))) |
| 3156 |
{ |
| 3157 |
UserWriteF("ERROR: NSONS=%d but rule.sons=%d\n",NSONS(theElement), |
| 3158 |
NSONS_OF_RULE(MARK2RULEADR(theElement,REFINE(theElement)))); |
| 3159 |
} |
| 3160 |
} |
| 3161 |
ENDDEBUG |
| 3162 |
#endif |
| 3163 |
|
| 3164 |
[[maybe_unused]] const int me = theGrid->ppifContext().me(); |
| 3165 |
for (s=0; s<MAX_SONS && SonList[s]!=NULL; s++) |
| 3166 |
{ |
| 3167 |
/** \todo delete special debug */ |
| 3168 |
/* if (ID(SonList[s])==11644) { RETURN(GM_FATAL); } */ |
| 3169 |
PRINTDEBUG(gm,1,(PFMT "UnrefineElement(): DisposeElement[%d]=" |
| 3170 |
EID_FMTX "\n",me,s,EID_PRTX(SonList[s]))); |
| 3171 |
|
| 3172 |
if (DisposeElement(theGrid,SonList[s])!=0) |
| 3173 |
RETURN(GM_FATAL); |
| 3174 |
} |
| 3175 |
|
| 3176 |
return (GM_OK); |
| 3177 |
} |
| 3178 |
|
| 3179 |
|
| 3180 |
START_UGDIM_NAMESPACE |
| 3181 |
|
| 3182 |
struct compare_record |
| 3183 |
{ |
| 3184 |
/** \brief Element to connect */ |
| 3185 |
ELEMENT *elem; |
| 3186 |
|
| 3187 |
/** \brief Side of element to connect */ |
| 3188 |
INT side; |
| 3189 |
|
| 3190 |
/** \brief Number of nodes of side */ |
| 3191 |
INT nodes; |
| 3192 |
|
| 3193 |
/** \brief Number of nodes in descending order */ |
| 3194 |
NODE *nodeptr[4]; |
| 3195 |
}; |
| 3196 |
typedef struct compare_record COMPARE_RECORD; |
| 3197 |
|
| 3198 |
END_UGDIM_NAMESPACE |
| 3199 |
|
| 3200 |
INT NS_DIM_PREFIX GetSonSideNodes (const ELEMENT *theElement, INT side, INT *nodes, |
| 3201 |
NODE *SideNodes[MAX_SIDE_NODES], INT ioflag) |
| 3202 |
{ |
| 3203 |
INT i,ncorners,nedges; |
| 3204 |
|
| 3205 |
ncorners = CORNERS_OF_SIDE(theElement,side); |
| 3206 |
nedges = EDGES_OF_SIDE(theElement,side); |
| 3207 |
(*nodes) = 0; |
| 3208 |
|
| 3209 |
|
| 3210 |
/* reset pointers */ |
| 3211 |
for (i=0; i<MAX_SIDE_NODES; i++) |
| 3212 |
{ |
| 3213 |
SideNodes[i] = NULL; |
| 3214 |
} |
| 3215 |
|
| 3216 |
/* determine corner nodes */ |
| 3217 |
for (i=0; i<ncorners; i++) |
| 3218 |
{ |
| 3219 |
SideNodes[i] = SONNODE(CORNER_OF_SIDE_PTR(theElement,side,i)); |
| 3220 |
#ifndef ModelP |
| 3221 |
assert(SideNodes[i]!=NULL); |
| 3222 |
#endif |
| 3223 |
if (!ioflag) |
| 3224 |
assert(SideNodes[i]==NULL || CORNERTYPE(SideNodes[i])); |
| 3225 |
(*nodes)++; |
| 3226 |
} |
| 3227 |
|
| 3228 |
/* determine mid nodes */ |
| 3229 |
for (i=0; i<nedges; i++) |
| 3230 |
{ |
| 3231 |
/** \todo delete |
| 3232 |
#ifdef UG_DIM_2 |
| 3233 |
ASSERT(OBJT(NFATHER(SideNodes[i])) == NDOBJ); |
| 3234 |
ASSERT(OBJT(NFATHER(SideNodes[i+1])) == NDOBJ); |
| 3235 |
theEdge = GetEdge((NODE *)NFATHER(SideNodes[i]), |
| 3236 |
(NODE *)NFATHER(SideNodes[i+1])); |
| 3237 |
#endif |
| 3238 |
#ifdef UG_DIM_3 |
| 3239 |
ASSERT(OBJT(NFATHER(SideNodes[i])) == NDOBJ); |
| 3240 |
ASSERT(OBJT(NFATHER(SideNodes[(i+1)%nedges])) == NDOBJ); |
| 3241 |
theEdge = GetEdge((NODE *)NFATHER(SideNodes[i]), |
| 3242 |
(NODE *)NFATHER(SideNodes[(i+1)%nedges])); |
| 3243 |
#endif |
| 3244 |
assert(theEdge != NULL); |
| 3245 |
|
| 3246 |
IFDEBUG(gm,4) |
| 3247 |
UserWriteF("theEdge=%x midnode=%x\n",theEdge,MIDNODE(theEdge)); |
| 3248 |
ENDDEBUG |
| 3249 |
|
| 3250 |
if (MIDNODE(theEdge) != NULL) |
| 3251 |
{ |
| 3252 |
SideNodes[ncorners+i] = MIDNODE(theEdge); |
| 3253 |
assert(NTYPE(MIDNODE(theEdge)) == MID_NODE); |
| 3254 |
(*nodes)++; |
| 3255 |
} |
| 3256 |
*/ |
| 3257 |
|
| 3258 |
SideNodes[ncorners+i] = GetMidNode(theElement,EDGE_OF_SIDE(theElement,side,i)); |
| 3259 |
if (SideNodes[ncorners+i] != NULL) |
| 3260 |
{ |
| 3261 |
assert(NTYPE(SideNodes[ncorners+i]) == MID_NODE); |
| 3262 |
(*nodes)++; |
| 3263 |
} |
| 3264 |
} |
| 3265 |
|
| 3266 |
#ifdef UG_DIM_3 |
| 3267 |
/* determine side node */ |
| 3268 |
{ |
| 3269 |
NODE *theNode; |
| 3270 |
|
| 3271 |
theNode = GetSideNode(theElement,side); |
| 3272 |
if (theNode != NULL) |
| 3273 |
{ |
| 3274 |
(*nodes)++; |
| 3275 |
} |
| 3276 |
|
| 3277 |
SideNodes[ncorners+nedges] = theNode; |
| 3278 |
|
| 3279 |
IFDEBUG(gm,4) |
| 3280 |
UserWriteF("sidenode=%x\n",theNode); |
| 3281 |
ENDDEBUG |
| 3282 |
} |
| 3283 |
#endif |
| 3284 |
|
| 3285 |
IFDEBUG(gm,2) |
| 3286 |
UserWriteF("GetSonSideNodes\n"); |
| 3287 |
for (i=0; i<MAX_SIDE_NODES; i++) UserWriteF(" %5d",i); |
| 3288 |
UserWriteF("\n"); |
| 3289 |
for (i=0; i<MAX_SIDE_NODES; i++) |
| 3290 |
if (SideNodes[i]!=NULL) UserWriteF(" %5d",ID(SideNodes[i])); |
| 3291 |
UserWriteF("\n"); |
| 3292 |
ENDDEBUG |
| 3293 |
|
| 3294 |
return(GM_OK); |
| 3295 |
} |
| 3296 |
|
| 3297 |
|
| 3298 |
/****************************************************************************/ |
| 3299 |
/* |
| 3300 |
compare_node - |
| 3301 |
|
| 3302 |
SYNOPSIS: |
| 3303 |
static bool compare_node (const NODE* a, const NODE* b) |
| 3304 |
|
| 3305 |
PARAMETERS: |
| 3306 |
. a |
| 3307 |
. b |
| 3308 |
|
| 3309 |
DESCRIPTION: |
| 3310 |
|
| 3311 |
\return <ul> |
| 3312 |
bool |
| 3313 |
*/ |
| 3314 |
/****************************************************************************/ |
| 3315 |
|
| 3316 |
static bool compare_node(const NODE* a, const NODE* b) |
| 3317 |
{ |
| 3318 |
return a > b; |
| 3319 |
} |
| 3320 |
|
| 3321 |
/****************************************************************************/ |
| 3322 |
/** \brief Get the sons of an element side |
| 3323 |
|
| 3324 |
\param[in] theElement Input element |
| 3325 |
\param[in] side Input element side number |
| 3326 |
\param[out] Sons_of_Side Number of topological sons of the element side |
| 3327 |
\param[in,out] SonList[MAX_SONS] Output elements |
| 3328 |
\param[out] SonSides Output element side numbers |
| 3329 |
\param[in] NeedSons If this is false, the correct list of sons is expected to be |
| 3330 |
provided in SonList. If not it is recomputed. |
| 3331 |
\param[in] ioflag An obsolete debugging flag |
| 3332 |
\param[in] useRefineClass |
| 3333 |
|
| 3334 |
For a given side of an element, this routine computes all element sides |
| 3335 |
on the next finer grid level which are topological sons of the input |
| 3336 |
element side. |
| 3337 |
*/ |
| 3338 |
/****************************************************************************/ |
| 3339 |
|
| 3340 |
INT NS_DIM_PREFIX Get_Sons_of_ElementSide (const ELEMENT *theElement, INT side, INT *Sons_of_Side, |
| 3341 |
ELEMENT *SonList[MAX_SONS], INT *SonSides, |
| 3342 |
INT NeedSons, INT ioflag, |
| 3343 |
INT useRefineClass) |
| 3344 |
{ |
| 3345 |
enum MarkClass markclass; |
| 3346 |
|
| 3347 |
/* reset soncount */ |
| 3348 |
*Sons_of_Side = 0; |
| 3349 |
|
| 3350 |
/* get sons of element */ |
| 3351 |
if (NeedSons) |
| 3352 |
if (GetAllSons(theElement,SonList) != GM_OK) RETURN(GM_FATAL); |
| 3353 |
|
| 3354 |
IFDEBUG(gm,2) |
| 3355 |
UserWriteF(" Get_Sons_of_ElementSide():" |
| 3356 |
" id=%d tag=%d, refineclass=%d markclass=%d refine=%d mark=%d coarse=%d" |
| 3357 |
" used=%d nsons=%d side=%d needsons=%d\n", |
| 3358 |
ID(theElement),TAG(theElement),REFINECLASS(theElement),MARKCLASS(theElement), |
| 3359 |
REFINE(theElement),MARK(theElement),COARSEN(theElement), |
| 3360 |
USED(theElement),NSONS(theElement),side,NeedSons); |
| 3361 |
for (INT i = 0; i < MAX_SONS && SonList[i] != NULL; i++) |
| 3362 |
UserWriteF(" son[%d]=" EID_FMTX "\n",i,EID_PRTX(SonList[i])); |
| 3363 |
ENDDEBUG |
| 3364 |
|
| 3365 |
#ifdef UG_DIM_2 |
| 3366 |
markclass = RED_CLASS; |
| 3367 |
#endif |
| 3368 |
#ifdef UG_DIM_3 |
| 3369 |
/* The following line used to read: markclass = (enum MarkClass) MARKCLASS(theElement); |
| 3370 |
This works well within the UG grid refinement context. However, now I want to use this |
| 3371 |
method within the DUNE UGGridLeafIntersectionIterator. The problem is that the user |
| 3372 |
may have randomly marked elements before calling the iterator. In that case the |
| 3373 |
mark classes may not be set the way this method expects it. Hence we allow the option |
| 3374 |
to use REFINECLASS instead. To be absolutely certain we don't break existing code |
| 3375 |
we keep the old behaviour as the default.*/ |
| 3376 |
markclass = (enum MarkClass) ((useRefineClass) ? REFINECLASS(theElement) : MARKCLASS(theElement)); |
| 3377 |
#endif |
| 3378 |
|
| 3379 |
/** \todo quick fix */ |
| 3380 |
#ifdef ModelP |
| 3381 |
if (EHGHOST(theElement)) |
| 3382 |
markclass = GREEN_CLASS; |
| 3383 |
#endif |
| 3384 |
|
| 3385 |
/* select sons to connect */ |
| 3386 |
switch (markclass) |
| 3387 |
{ |
| 3388 |
|
| 3389 |
case YELLOW_CLASS : |
| 3390 |
{ |
| 3391 |
*Sons_of_Side = 1; |
| 3392 |
SonSides[0] = side; |
| 3393 |
break; |
| 3394 |
} |
| 3395 |
|
| 3396 |
case GREEN_CLASS : |
| 3397 |
case RED_CLASS : |
| 3398 |
{ |
| 3399 |
/* determine sonnodes of side */ |
| 3400 |
NODE *SideNodes[MAX_SIDE_NODES]; |
| 3401 |
INT nodes; |
| 3402 |
INT nsons = 0; |
| 3403 |
|
| 3404 |
/* determine nodes of sons on side of element */ |
| 3405 |
GetSonSideNodes(theElement,side,&nodes,SideNodes,ioflag); |
| 3406 |
|
| 3407 |
/* sort side nodes in descending address order */ |
| 3408 |
std::sort(SideNodes, SideNodes + MAX_SIDE_NODES, compare_node); |
| 3409 |
|
| 3410 |
IFDEBUG(gm,3) |
| 3411 |
UserWriteF("After qsort:\n"); |
| 3412 |
for (INT i = 0; i < MAX_SIDE_NODES; i++) UserWriteF(" %8d",i); |
| 3413 |
UserWriteF("\n"); |
| 3414 |
for (INT i = 0; i < MAX_SIDE_NODES; i++) |
| 3415 |
if (SideNodes[i]!=NULL) UserWriteF(" %x",SideNodes[i]); |
| 3416 |
else UserWriteF(" %8d",0); |
| 3417 |
UserWriteF("\n"); |
| 3418 |
ENDDEBUG |
| 3419 |
|
| 3420 |
/* determine sonnode on side */ |
| 3421 |
/* for (i=0; i<NSONS(theElement); i++) */ |
| 3422 |
for (INT i = 0; i<MAX_SONS && SonList[i] != NULL; i++) |
| 3423 |
{ |
| 3424 |
INT n = 0; |
| 3425 |
std::array<INT,MAX_CORNERS_OF_SIDE> corner; |
| 3426 |
std::fill(corner.begin(), corner.end(), -1); |
| 3427 |
|
| 3428 |
IFDEBUG(gm,4) |
| 3429 |
UserWriteF("son=%d\n",i); |
| 3430 |
ENDDEBUG |
| 3431 |
|
| 3432 |
/* soncorners on side */ |
| 3433 |
for (INT j = 0; j < CORNERS_OF_ELEM(SonList[i]); j++) |
| 3434 |
{ |
| 3435 |
const NODE *nd = CORNER(SonList[i], j); |
| 3436 |
if (std::binary_search(SideNodes, SideNodes + nodes, nd, compare_node)) |
| 3437 |
{ |
| 3438 |
corner[n] = j; |
| 3439 |
n++; |
| 3440 |
} |
| 3441 |
} |
| 3442 |
assert(n<5); |
| 3443 |
|
| 3444 |
IFDEBUG(gm,4) |
| 3445 |
UserWriteF("\n nodes on side n=%d:",n); |
| 3446 |
for (INT j = 0; j < MAX_CORNERS_OF_SIDE; j++) |
| 3447 |
UserWriteF(" %d",corner[j]); |
| 3448 |
ENDDEBUG |
| 3449 |
|
| 3450 |
|
| 3451 |
IFDEBUG(gm,0) |
| 3452 |
if (n==3) assert(TAG(SonList[i])!=HEXAHEDRON); |
| 3453 |
if (n==4) assert(TAG(SonList[i])!=TETRAHEDRON); |
| 3454 |
ENDDEBUG |
| 3455 |
|
| 3456 |
/* sonside on side */ |
| 3457 |
#ifdef UG_DIM_2 |
| 3458 |
assert(n<=2); |
| 3459 |
if (n==2) |
| 3460 |
{ |
| 3461 |
if (corner[0]+1 == corner[1]) |
| 3462 |
SonSides[nsons] = corner[0]; |
| 3463 |
else |
| 3464 |
{ |
| 3465 |
/** \todo find proper assert |
| 3466 |
assert(corner[1] == CORNERS_OF_ELEM(theElement)-1); */ |
| 3467 |
SonSides[nsons] = corner[1]; |
| 3468 |
} |
| 3469 |
SonList[nsons] = SonList[i]; |
| 3470 |
nsons++; |
| 3471 |
} |
| 3472 |
#endif |
| 3473 |
#ifdef UG_DIM_3 |
| 3474 |
if (n==3 || n==4) |
| 3475 |
{ |
| 3476 |
/* determine side number */ |
| 3477 |
INT edge0 = EDGE_WITH_CORNERS(SonList[i],corner[0],corner[1]); |
| 3478 |
INT edge1 = EDGE_WITH_CORNERS(SonList[i],corner[1],corner[2]); |
| 3479 |
/* corners are not stored in local side numbering, */ |
| 3480 |
/* therefore corner[x]-corner[y] might be the diagonal */ |
| 3481 |
if (n==4 && edge0==-1) |
| 3482 |
edge0 = EDGE_WITH_CORNERS(SonList[i],corner[0], |
| 3483 |
corner[3]); |
| 3484 |
if (n==4 && edge1==-1) |
| 3485 |
edge1 = EDGE_WITH_CORNERS(SonList[i],corner[1], |
| 3486 |
corner[3]); |
| 3487 |
assert(edge0!=-1 && edge1!=-1); |
| 3488 |
|
| 3489 |
INT sonside = -1; |
| 3490 |
for (INT side0 = 0; side0 < MAX_SIDES_OF_EDGE; side0++) |
| 3491 |
{ |
| 3492 |
for (INT side1 = 0; side1 < MAX_SIDES_OF_EDGE; side1++) |
| 3493 |
{ |
| 3494 |
IFDEBUG(gm,5) |
| 3495 |
UserWriteF("edge0=%d side0=%d SIDE_WITH_EDGE=%d\n", |
| 3496 |
edge0, side0, |
| 3497 |
SIDE_WITH_EDGE(SonList[i],edge0,side0)); |
| 3498 |
UserWriteF("edge1=%d side1=%d SIDE_WITH_EDGE=%d\n", |
| 3499 |
edge1, side1, |
| 3500 |
SIDE_WITH_EDGE(SonList[i],edge1,side1)); |
| 3501 |
ENDDEBUG |
| 3502 |
if (SIDE_WITH_EDGE(SonList[i],edge0,side0) == |
| 3503 |
SIDE_WITH_EDGE(SonList[i],edge1,side1)) |
| 3504 |
{ |
| 3505 |
sonside = SIDE_WITH_EDGE(SonList[i],edge0,side0); |
| 3506 |
break; |
| 3507 |
} |
| 3508 |
} |
| 3509 |
if (sonside != -1) break; |
| 3510 |
} |
| 3511 |
assert(sonside != -1); |
| 3512 |
IFDEBUG(gm,4) |
| 3513 |
UserWriteF(" son[%d]=%x with sonside=%d on eside=%d\n", |
| 3514 |
i,SonList[i],sonside,side); |
| 3515 |
ENDDEBUG |
| 3516 |
|
| 3517 |
IFDEBUG(gm,3) |
| 3518 |
|
| 3519 |
for (INT k = 0; k < SIDES_OF_ELEM(SonList[i]); k++) |
| 3520 |
{ |
| 3521 |
const ELEMENT *Nb = NBELEM(SonList[i],k); |
| 3522 |
if (Nb!=NULL) |
| 3523 |
{ |
| 3524 |
INT j; |
| 3525 |
for (j=0; j<SIDES_OF_ELEM(Nb); j++) |
| 3526 |
{ |
| 3527 |
if (NBELEM(Nb,j)==SonList[i]) break; |
| 3528 |
} |
| 3529 |
if (j<SIDES_OF_ELEM(Nb)) |
| 3530 |
UserWriteF(" sonside=%d has backptr to son " |
| 3531 |
"Nb=%x Nbside=%d\n",k,Nb,j); |
| 3532 |
} |
| 3533 |
} |
| 3534 |
ENDDEBUG |
| 3535 |
|
| 3536 |
ASSERT(CORNERS_OF_SIDE(SonList[i],sonside) == n); |
| 3537 |
|
| 3538 |
SonSides[nsons] = sonside; |
| 3539 |
SonList[nsons] = SonList[i]; |
| 3540 |
nsons++; |
| 3541 |
} |
| 3542 |
#endif |
| 3543 |
} |
| 3544 |
#ifndef ModelP |
| 3545 |
assert(nsons>0 && nsons<6); |
| 3546 |
#endif |
| 3547 |
|
| 3548 |
IFDEBUG(gm,3) |
| 3549 |
UserWriteF(" nsons on side=%d\n",nsons); |
| 3550 |
ENDDEBUG |
| 3551 |
|
| 3552 |
*Sons_of_Side = nsons; |
| 3553 |
break; |
| 3554 |
} |
| 3555 |
|
| 3556 |
/* old style |
| 3557 |
This case would work for the sequential case if SonList is ordered according to |
| 3558 |
rule (e.g. introduce GetOrderedSonList()). The upper case, used now in each |
| 3559 |
situation, is a factor of 2 |
| 3560 |
slower for uniform refinement!! (s.l. 981016) |
| 3561 |
#ifndef ModelP |
| 3562 |
case RED_CLASS: |
| 3563 |
#endif |
| 3564 |
*/ |
| 3565 |
{ |
| 3566 |
INT nsons = 0; |
| 3567 |
for (INT i = 0; i < MAX_SONS && SonList[i] != NULL; i++) |
| 3568 |
{ |
| 3569 |
const SONDATA *sondata = SON_OF_RULE(MARK2RULEADR(theElement, MARK(theElement)), i); |
| 3570 |
|
| 3571 |
for (INT j = 0; j < SIDES_OF_ELEM(SonList[i]); j++) |
| 3572 |
if (SON_NB(sondata,j) == FATHER_SIDE_OFFSET+side) |
| 3573 |
{ |
| 3574 |
SonSides[nsons] = j; |
| 3575 |
SonList[nsons] = SonList[i]; |
| 3576 |
nsons ++; |
| 3577 |
} |
| 3578 |
} |
| 3579 |
*Sons_of_Side = nsons; |
| 3580 |
break; |
| 3581 |
} |
| 3582 |
|
| 3583 |
default : |
| 3584 |
RETURN(GM_FATAL); |
| 3585 |
} |
| 3586 |
|
| 3587 |
#ifdef ModelP |
| 3588 |
IFDEBUG(gm,4) |
| 3589 |
UserWriteF("Sons_of_Side=%d\n",*Sons_of_Side); |
| 3590 |
for (INT i = 0; i < *Sons_of_Side; i++) |
| 3591 |
UserWriteF("son[%d]=" EID_FMTX " sonside[%d]=%d\n",i, |
| 3592 |
EID_PRTX(SonList[i]),i,SonSides[i]); |
| 3593 |
ENDDEBUG |
| 3594 |
#endif |
| 3595 |
|
| 3596 |
for (INT i = *Sons_of_Side; i < MAX_SONS; i++) |
| 3597 |
SonList[i] = NULL; |
| 3598 |
|
| 3599 |
return(GM_OK); |
| 3600 |
} |
| 3601 |
|
| 3602 |
|
| 3603 |
/****************************************************************************/ |
| 3604 |
/* |
| 3605 |
Sort_Node_Ptr - |
| 3606 |
|
| 3607 |
SYNOPSIS: |
| 3608 |
static INT Sort_Node_Ptr (INT n,NODE **nodes); |
| 3609 |
|
| 3610 |
PARAMETERS: |
| 3611 |
. n |
| 3612 |
. nodes |
| 3613 |
|
| 3614 |
DESCRIPTION: |
| 3615 |
|
| 3616 |
\return <ul> |
| 3617 |
INT |
| 3618 |
*/ |
| 3619 |
/****************************************************************************/ |
| 3620 |
|
| 3621 |
static INT Sort_Node_Ptr (INT n,NODE **nodes) |
| 3622 |
{ |
| 3623 |
NODE* nd; |
| 3624 |
INT i,j,max; |
| 3625 |
|
| 3626 |
max = 0; |
| 3627 |
|
| 3628 |
switch (n) |
| 3629 |
{ |
| 3630 |
|
| 3631 |
#ifdef UG_DIM_2 |
| 3632 |
case 2 : |
| 3633 |
#endif |
| 3634 |
#ifdef UG_DIM_3 |
| 3635 |
case 3 : |
| 3636 |
case 4 : |
| 3637 |
#endif |
| 3638 |
for (i=0; i<n; i++) |
| 3639 |
{ |
| 3640 |
max = i; |
| 3641 |
for (j=i+1; j<n; j++) |
| 3642 |
if (nodes[max]<nodes[j]) max = j; |
| 3643 |
if (i != max) |
| 3644 |
{ |
| 3645 |
nd = nodes[i]; |
| 3646 |
nodes[i] = nodes[max]; |
| 3647 |
nodes[max] = nd; |
| 3648 |
} |
| 3649 |
} |
| 3650 |
break; |
| 3651 |
|
| 3652 |
default : |
| 3653 |
RETURN(GM_FATAL); |
| 3654 |
} |
| 3655 |
|
| 3656 |
return(GM_OK); |
| 3657 |
} |
| 3658 |
|
| 3659 |
/****************************************************************************/ |
| 3660 |
/* |
| 3661 |
Fill_Comp_Table - |
| 3662 |
|
| 3663 |
SYNOPSIS: |
| 3664 |
static INT Fill_Comp_Table (COMPARE_RECORD **SortTable, COMPARE_RECORD *Table, INT nelems, ELEMENT **Elements, INT *Sides); |
| 3665 |
|
| 3666 |
PARAMETERS: |
| 3667 |
. SortTable |
| 3668 |
. Table |
| 3669 |
. nelems |
| 3670 |
. Elements |
| 3671 |
. Sides |
| 3672 |
|
| 3673 |
DESCRIPTION: |
| 3674 |
|
| 3675 |
\return <ul> |
| 3676 |
INT |
| 3677 |
*/ |
| 3678 |
/****************************************************************************/ |
| 3679 |
|
| 3680 |
static INT Fill_Comp_Table (COMPARE_RECORD **SortTable, COMPARE_RECORD *Table, INT nelems, |
| 3681 |
ELEMENT **Elements, const INT *Sides) |
| 3682 |
{ |
| 3683 |
for (INT i = 0; i < nelems; i++) |
| 3684 |
{ |
| 3685 |
SortTable[i] = Table+i; |
| 3686 |
COMPARE_RECORD *Entry = Table+i; |
| 3687 |
Entry->elem = Elements[i]; |
| 3688 |
Entry->side = Sides[i]; |
| 3689 |
Entry->nodes = CORNERS_OF_SIDE(Entry->elem,Entry->side); |
| 3690 |
for (INT j = 0; j < CORNERS_OF_SIDE(Entry->elem, Entry->side); j++) |
| 3691 |
Entry->nodeptr[j] = CORNER_OF_SIDE_PTR(Entry->elem,Entry->side,j); |
| 3692 |
if (Sort_Node_Ptr(Entry->nodes,Entry->nodeptr)!=GM_OK) RETURN(GM_FATAL); |
| 3693 |
} |
| 3694 |
|
| 3695 |
return(GM_OK); |
| 3696 |
} |
| 3697 |
|
| 3698 |
|
| 3699 |
/****************************************************************************/ |
| 3700 |
/* |
| 3701 |
compare_nodes - |
| 3702 |
|
| 3703 |
SYNOPSIS: |
| 3704 |
static bool compare_nodes(const COMPARE_RECORD* a, const COMPARE_RECORD* b) |
| 3705 |
|
| 3706 |
PARAMETERS: |
| 3707 |
. a |
| 3708 |
. b |
| 3709 |
|
| 3710 |
DESCRIPTION: |
| 3711 |
|
| 3712 |
\return <ul> |
| 3713 |
bool |
| 3714 |
*/ |
| 3715 |
/****************************************************************************/ |
| 3716 |
|
| 3717 |
static bool compare_nodes(const COMPARE_RECORD* a, const COMPARE_RECORD* b) |
| 3718 |
{ |
| 3719 |
const int n = (a->nodes == 4 && b->nodes == 4) ? 4 : 3; |
| 3720 |
|
| 3721 |
for (int i = 0; i < n; ++i) { |
| 3722 |
if (a->nodeptr[i] > b->nodeptr[i]) |
| 3723 |
return true; |
| 3724 |
else if (a->nodeptr[i] < b->nodeptr[i]) |
| 3725 |
return false; |
| 3726 |
} |
| 3727 |
|
| 3728 |
return false; |
| 3729 |
} |
| 3730 |
|
| 3731 |
/****************************************************************************/ |
| 3732 |
/* |
| 3733 |
Connect_Sons_of_ElementSide - |
| 3734 |
|
| 3735 |
SYNOPSIS: |
| 3736 |
INT Connect_Sons_of_ElementSide (GRID *theGrid, ELEMENT *theElement, INT side, INT Sons_of_Side, ELEMENT **Sons_of_Side_List, INT *SonSides, INT ioflag); |
| 3737 |
|
| 3738 |
PARAMETERS: |
| 3739 |
. theGrid |
| 3740 |
. theElement |
| 3741 |
. side |
| 3742 |
. Sons_of_Side |
| 3743 |
. Sons_of_Side_List |
| 3744 |
. SonSides |
| 3745 |
. ioflag |
| 3746 |
|
| 3747 |
DESCRIPTION: |
| 3748 |
|
| 3749 |
\return <ul> |
| 3750 |
INT |
| 3751 |
*/ |
| 3752 |
/****************************************************************************/ |
| 3753 |
|
| 3754 |
INT NS_DIM_PREFIX Connect_Sons_of_ElementSide (GRID *theGrid, ELEMENT *theElement, INT side, INT Sons_of_Side, ELEMENT **Sons_of_Side_List, INT *SonSides, INT ioflag) |
| 3755 |
{ |
| 3756 |
COMPARE_RECORD ElemSonTable[MAX_SONS]; |
| 3757 |
COMPARE_RECORD NbSonTable[MAX_SONS]; |
| 3758 |
COMPARE_RECORD *ElemSortTable[MAX_SONS]; |
| 3759 |
COMPARE_RECORD *NbSortTable[MAX_SONS]; |
| 3760 |
|
| 3761 |
ELEMENT *theNeighbor; |
| 3762 |
ELEMENT *Sons_of_NbSide_List[MAX_SONS]; |
| 3763 |
INT nbside,Sons_of_NbSide,NbSonSides[MAX_SONS]; |
| 3764 |
INT k; |
| 3765 |
|
| 3766 |
IFDEBUG(gm,2) |
| 3767 |
UserWriteF("Connect_Sons_of_ElementSide: ID(elem)=%d side=%d " |
| 3768 |
"Sons_of_Side=%d\n",ID(theElement),side,Sons_of_Side); |
| 3769 |
REFINE_ELEMENT_LIST(0,theElement,"theElement:"); |
| 3770 |
ENDDEBUG |
| 3771 |
|
| 3772 |
if (Sons_of_Side <= 0) return(GM_OK); |
| 3773 |
|
| 3774 |
/* connect to boundary */ |
| 3775 |
if (OBJT(theElement)==BEOBJ && SIDE_ON_BND(theElement,side)) |
| 3776 |
{ |
| 3777 |
/** \todo connect change test */ |
| 3778 |
|
| 3779 |
for (int i = 0; i < Sons_of_Side; i++) |
| 3780 |
{ |
| 3781 |
|
| 3782 |
assert(OBJT(Sons_of_Side_List[i])==BEOBJ); |
| 3783 |
if (CreateSonElementSide(theGrid,theElement,side, |
| 3784 |
Sons_of_Side_List[i],SonSides[i]) != GM_OK) |
| 3785 |
{ |
| 3786 |
return(GM_FATAL); |
| 3787 |
} |
| 3788 |
} |
| 3789 |
|
| 3790 |
/* internal boundaries not connected */ |
| 3791 |
/* return(GM_OK); */ |
| 3792 |
} |
| 3793 |
|
| 3794 |
/* connect to neighbor element */ |
| 3795 |
theNeighbor = NBELEM(theElement,side); |
| 3796 |
|
| 3797 |
if (theNeighbor==NULL) return(GM_OK); |
| 3798 |
|
| 3799 |
/* master elements only connect to master elements */ |
| 3800 |
/* ghost elements connect to ghost and master elements */ |
| 3801 |
#ifdef ModelP |
| 3802 |
if (!ioflag && EMASTER(theElement) && EHGHOST(theNeighbor)) |
| 3803 |
return(GM_OK); |
| 3804 |
#endif |
| 3805 |
|
| 3806 |
/* only yellow elements may have no neighbors */ |
| 3807 |
if (MARKCLASS(theNeighbor)==NO_CLASS) |
| 3808 |
{ |
| 3809 |
|
| 3810 |
if (hFlag) assert(MARKCLASS(theElement)==YELLOW_CLASS); |
| 3811 |
|
| 3812 |
return(GM_OK); |
| 3813 |
} |
| 3814 |
|
| 3815 |
if (REFINEMENT_CHANGES(theNeighbor)) return(GM_OK); |
| 3816 |
|
| 3817 |
/* determine corresponding side of neighbor */ |
| 3818 |
for (nbside=0; nbside<SIDES_OF_ELEM(theNeighbor); nbside++) |
| 3819 |
if (NBELEM(theNeighbor,nbside) == theElement) break; |
| 3820 |
assert(nbside<SIDES_OF_ELEM(theNeighbor)); |
| 3821 |
|
| 3822 |
/* get sons of neighbor to connect */ |
| 3823 |
Get_Sons_of_ElementSide(theNeighbor,nbside,&Sons_of_NbSide, |
| 3824 |
Sons_of_NbSide_List,NbSonSides,1,ioflag); |
| 3825 |
|
| 3826 |
#ifdef ModelP |
| 3827 |
if (!ioflag) |
| 3828 |
{ |
| 3829 |
#endif |
| 3830 |
/* match exactly */ |
| 3831 |
if (1) ASSERT(Sons_of_Side == Sons_of_NbSide && Sons_of_NbSide>0 |
| 3832 |
&& Sons_of_NbSide<6); |
| 3833 |
else |
| 3834 |
if (!(Sons_of_Side == Sons_of_NbSide && Sons_of_NbSide>0 |
| 3835 |
&& Sons_of_NbSide<6)) |
| 3836 |
{ |
| 3837 |
ELEMENT *elem=NULL; |
| 3838 |
ELEMENT *SonList[MAX_SONS]; |
| 3839 |
|
| 3840 |
REFINE_ELEMENT_LIST(0,theElement,"theElement:"); |
| 3841 |
REFINE_ELEMENT_LIST(0,theNeighbor,"theNeighbor:"); |
| 3842 |
UserWriteF("elem=" EID_FMTX " nb=" EID_FMTX |
| 3843 |
"Sons_of_Side=%d Sons_of_NbSide=%d\n",EID_PRTX(theElement), |
| 3844 |
EID_PRTX(theNeighbor),Sons_of_Side,Sons_of_NbSide); |
| 3845 |
fflush(stdout); |
| 3846 |
GetAllSons(theElement,SonList); |
| 3847 |
for (int i = 0; i < MAX_SONS && SonList[i] != NULL; i++) |
| 3848 |
{ |
| 3849 |
REFINE_ELEMENT_LIST(0,SonList[i],"son:"); |
| 3850 |
} |
| 3851 |
GetAllSons(theNeighbor,SonList); |
| 3852 |
for (int i = 0; i < MAX_SONS && SonList[i] != NULL; i++) |
| 3853 |
{ |
| 3854 |
REFINE_ELEMENT_LIST(0,SonList[i],"nbson:"); |
| 3855 |
} |
| 3856 |
|
| 3857 |
/* sig bus error to see stack in totalview */ |
| 3858 |
SET_NBELEM(elem,0,NULL); |
| 3859 |
assert(0); |
| 3860 |
|
| 3861 |
} |
| 3862 |
#ifdef ModelP |
| 3863 |
} |
| 3864 |
#endif |
| 3865 |
|
| 3866 |
IFDEBUG(gm,2) |
| 3867 |
UserWriteF("Connect_Sons_of_ElementSide: NBID(elem)=%d side=%d " |
| 3868 |
"Sons_of_Side=%d\n",ID(theNeighbor),nbside,Sons_of_NbSide); |
| 3869 |
REFINE_ELEMENT_LIST(0,theNeighbor,"theNeighbor:"); |
| 3870 |
ENDDEBUG |
| 3871 |
|
| 3872 |
/* fill sort and comparison tables */ |
| 3873 |
Fill_Comp_Table(ElemSortTable,ElemSonTable,Sons_of_Side,Sons_of_Side_List, |
| 3874 |
SonSides); |
| 3875 |
Fill_Comp_Table(NbSortTable,NbSonTable,Sons_of_NbSide,Sons_of_NbSide_List, |
| 3876 |
NbSonSides); |
| 3877 |
|
| 3878 |
IFDEBUG(gm,5) |
| 3879 |
|
| 3880 |
if (!ioflag) |
| 3881 |
{ |
| 3882 |
UserWriteF("BEFORE qsort\n"); |
| 3883 |
|
| 3884 |
/* test whether all entries are corresponding */ |
| 3885 |
for (int i = 0; i < Sons_of_Side; i++) |
| 3886 |
{ |
| 3887 |
COMPARE_RECORD *Entry, *NbEntry; |
| 3888 |
|
| 3889 |
Entry = ElemSortTable[i]; |
| 3890 |
NbEntry = NbSortTable[i]; |
| 3891 |
|
| 3892 |
if (Entry->nodes != NbEntry->nodes) |
| 3893 |
UserWriteF("Connect_Sons_of_ElementSide(): LIST Sorttables[%d]" |
| 3894 |
" eNodes=%d nbNodes=%d\n", |
| 3895 |
i,Entry->nodes,NbEntry->nodes); |
| 3896 |
for (int j = 0; j < Entry->nodes; j++) |
| 3897 |
UserWriteF("Connect_Sons_of_ElementSide(): LIST Sorttables[%d][%d]" |
| 3898 |
" eNodePtr=%d/%8x/%d nbNodePtr=%d/%8x/%d\n", |
| 3899 |
i,j, |
| 3900 |
ID(Entry->nodeptr[j]),Entry->nodeptr[j],NTYPE(Entry->nodeptr[j]), |
| 3901 |
ID(NbEntry->nodeptr[j]),NbEntry->nodeptr[j],NTYPE(NbEntry->nodeptr[j])); |
| 3902 |
UserWriteF("\n"); |
| 3903 |
} |
| 3904 |
UserWriteF("\n\n"); |
| 3905 |
} |
| 3906 |
ENDDEBUG |
| 3907 |
|
| 3908 |
/* qsort the tables using nodeptrs */ |
| 3909 |
std::sort(ElemSortTable, ElemSortTable + Sons_of_Side, compare_nodes); |
| 3910 |
std::sort(NbSortTable, NbSortTable + Sons_of_NbSide, compare_nodes); |
| 3911 |
|
| 3912 |
#ifdef ModelP |
| 3913 |
if (!ioflag && Sons_of_NbSide!=Sons_of_Side) ASSERT(0); |
| 3914 |
#endif |
| 3915 |
|
| 3916 |
#ifdef Debug |
| 3917 |
if (!ioflag) |
| 3918 |
/* check whether both sort table match exactly */ |
| 3919 |
for (int i = 0; i < Sons_of_Side; i++) |
| 3920 |
{ |
| 3921 |
COMPARE_RECORD *Entry, *NbEntry; |
| 3922 |
|
| 3923 |
Entry = ElemSortTable[i]; |
| 3924 |
NbEntry = NbSortTable[i]; |
| 3925 |
|
| 3926 |
if (Entry->nodes != NbEntry->nodes) |
| 3927 |
{ |
| 3928 |
printf("Connect_Sons_of_ElementSide(): ERROR Sorttables[%d]"\ |
| 3929 |
" eNodes=%d nbNodes=%d\n",i,Entry->nodes,NbEntry->nodes); |
| 3930 |
assert(0); |
| 3931 |
} |
| 3932 |
for (int j = 0; j < Entry->nodes; j++) |
| 3933 |
if (Entry->nodeptr[j] != NbEntry->nodeptr[j]) |
| 3934 |
{ |
| 3935 |
printf("Connect_Sons_of_ElementSide(): " |
| 3936 |
"ERROR Sorttables[%d][%d]"\ |
| 3937 |
" eNodePtr=%p nbNodePtr=%p\n", |
| 3938 |
i,j,Entry->nodeptr[j],NbEntry->nodeptr[j]); |
| 3939 |
/* assert(0);*/ |
| 3940 |
} |
| 3941 |
} |
| 3942 |
#endif |
| 3943 |
|
| 3944 |
IFDEBUG(gm,4) |
| 3945 |
if (!ioflag) |
| 3946 |
{ |
| 3947 |
UserWriteF("After qsort\n"); |
| 3948 |
|
| 3949 |
/* test whether all entries are corresponding */ |
| 3950 |
UserWriteF("SORTTABLELIST:\n"); |
| 3951 |
for (int i = 0; i < Sons_of_Side; i++) |
| 3952 |
{ |
| 3953 |
COMPARE_RECORD *Entry, *NbEntry; |
| 3954 |
|
| 3955 |
Entry = ElemSortTable[i]; |
| 3956 |
NbEntry = NbSortTable[i]; |
| 3957 |
|
| 3958 |
UserWriteF("EAdr=%x side=%d realNbAdr=%x NbAdr=%x nbside=%x " |
| 3959 |
"realNbAdr=%x\n", |
| 3960 |
Entry->elem, Entry->side, NBELEM(Entry->elem,Entry->side), |
| 3961 |
NbEntry->elem, NbEntry->side,NBELEM(NbEntry->elem,NbEntry->side)); |
| 3962 |
} |
| 3963 |
|
| 3964 |
for (int i = 0; i < Sons_of_Side; i++) |
| 3965 |
{ |
| 3966 |
COMPARE_RECORD *Entry, *NbEntry; |
| 3967 |
|
| 3968 |
Entry = ElemSortTable[i]; |
| 3969 |
NbEntry = NbSortTable[i]; |
| 3970 |
|
| 3971 |
if (NBELEM(Entry->elem,Entry->side)!=NbEntry->elem) |
| 3972 |
{ |
| 3973 |
UserWriteF("NOTEQUAL for i=%d elem=%x: elemrealnb=%x " |
| 3974 |
"elemsortnb=%x\n", |
| 3975 |
i,Entry->elem,NBELEM(Entry->elem,Entry->side),NbEntry->elem); |
| 3976 |
REFINE_ELEMENT_LIST(0,theElement,"theElement:"); |
| 3977 |
REFINE_ELEMENT_LIST(0,theNeighbor,"theNeighbor:"); |
| 3978 |
} |
| 3979 |
if (NBELEM(NbEntry->elem,NbEntry->side)!=Entry->elem) |
| 3980 |
{ |
| 3981 |
UserWriteF("NOTEQUAL for i=%d nb=%x: nbrealnb=%x nbsortnb=%x\n", |
| 3982 |
i,NbEntry->elem,NBELEM(NbEntry->elem,NbEntry->side), |
| 3983 |
Entry->elem); |
| 3984 |
REFINE_ELEMENT_LIST(0,theElement,"theE:"); |
| 3985 |
REFINE_ELEMENT_LIST(0,theNeighbor,"theN:"); |
| 3986 |
} |
| 3987 |
} |
| 3988 |
UserWriteF("\n\n"); |
| 3989 |
} |
| 3990 |
ENDDEBUG |
| 3991 |
|
| 3992 |
/* set neighborship relations */ |
| 3993 |
if (ioflag) |
| 3994 |
{ |
| 3995 |
for (int i = 0; i < Sons_of_Side; i++) |
| 3996 |
{ |
| 3997 |
const COMPARE_RECORD *Entry = ElemSortTable[i]; |
| 3998 |
for (k=0; k<Sons_of_NbSide; k++) |
| 3999 |
{ |
| 4000 |
const COMPARE_RECORD *NbEntry = NbSortTable[k]; |
| 4001 |
|
| 4002 |
if (Entry->nodes != NbEntry->nodes) continue; |
| 4003 |
|
| 4004 |
int idx; |
| 4005 |
for (idx = 0; idx < Entry->nodes; idx++) |
| 4006 |
if (Entry->nodeptr[idx] != NbEntry->nodeptr[idx]) |
| 4007 |
break; |
| 4008 |
if (idx == Entry->nodes) |
| 4009 |
{ |
| 4010 |
SET_NBELEM(ElemSortTable[i]->elem,ElemSortTable[i]->side, |
| 4011 |
NbSortTable[k]->elem); |
| 4012 |
SET_NBELEM(NbSortTable[k]->elem,NbSortTable[k]->side, |
| 4013 |
ElemSortTable[i]->elem); |
| 4014 |
} |
| 4015 |
} |
| 4016 |
} |
| 4017 |
} |
| 4018 |
else |
| 4019 |
/* all entries need to match exactly */ |
| 4020 |
for (int i = 0; i < Sons_of_Side; i++) |
| 4021 |
{ |
| 4022 |
SET_NBELEM(ElemSortTable[i]->elem,ElemSortTable[i]->side, |
| 4023 |
NbSortTable[i]->elem); |
| 4024 |
SET_NBELEM(NbSortTable[i]->elem,NbSortTable[i]->side, |
| 4025 |
ElemSortTable[i]->elem); |
| 4026 |
#ifdef UG_DIM_3 |
| 4027 |
if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) |
| 4028 |
if (DisposeDoubledSideVector(theGrid,ElemSortTable[i]->elem, |
| 4029 |
ElemSortTable[i]->side, |
| 4030 |
NbSortTable[i]->elem, |
| 4031 |
NbSortTable[i]->side)) |
| 4032 |
RETURN(GM_FATAL); |
| 4033 |
#endif |
| 4034 |
} |
| 4035 |
|
| 4036 |
return(GM_OK); |
| 4037 |
} |
| 4038 |
|
| 4039 |
/****************************************************************************/ |
| 4040 |
/** \brief Copy an element |
| 4041 |
|
| 4042 |
\param theGrid - grid level of sons of theElement |
| 4043 |
\param theElement - element to refine |
| 4044 |
\param theContext - nodes needed for new elements |
| 4045 |
|
| 4046 |
This function copies an element, (i) corner nodes are already allocated, (iv) create son and set references to sons |
| 4047 |
|
| 4048 |
\return <ul> |
| 4049 |
<li> 0 - ok </li> |
| 4050 |
<li> 1 - fatal memory error </li> |
| 4051 |
</ul> |
| 4052 |
*/ |
| 4053 |
/****************************************************************************/ |
| 4054 |
static INT RefineElementYellow (GRID *theGrid, ELEMENT *theElement, NODE **theContext) |
| 4055 |
{ |
| 4056 |
INT i; |
| 4057 |
bool boundaryelement = false; |
| 4058 |
const int me = theGrid->ppifContext().me(); |
| 4059 |
|
| 4060 |
/* check for boundary */ |
| 4061 |
if (OBJT(theElement) == BEOBJ) |
| 4062 |
for (i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 4063 |
{ |
| 4064 |
/* at the boundary */ |
| 4065 |
if (SIDE_ON_BND(theElement,i)) |
| 4066 |
{ |
| 4067 |
boundaryelement = true; |
| 4068 |
break; |
| 4069 |
} |
| 4070 |
} |
| 4071 |
|
| 4072 |
#ifdef Debug |
| 4073 |
/* check son nodes validity */ |
| 4074 |
for (i=0; i<CORNERS_OF_ELEM(theElement); i++) |
| 4075 |
{ |
| 4076 |
assert (theContext[i] != NULL); |
| 4077 |
} |
| 4078 |
#endif |
| 4079 |
|
| 4080 |
/* create son */ |
| 4081 |
const INT theSonType = boundaryelement ? BEOBJ : IEOBJ; |
| 4082 |
ELEMENT* theSon = CreateElement(theGrid,TAG(theElement), theSonType, |
| 4083 |
theContext,theElement,1); |
| 4084 |
if (theSon==NULL) RETURN(GM_ERROR); |
| 4085 |
SETECLASS(theSon,MARKCLASS(theElement)); |
| 4086 |
|
| 4087 |
/* connect son */ |
| 4088 |
IFDEBUG(gm,2) |
| 4089 |
UserWriteF(PFMT "CONNECTING elem=" EID_FMTX "\n",me,EID_PRTX(theElement)); |
| 4090 |
ENDDEBUG |
| 4091 |
for (i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 4092 |
{ |
| 4093 |
INT j,Sons_of_Side; |
| 4094 |
ELEMENT *Sons_of_Side_List[MAX_SONS]; |
| 4095 |
INT SonSides[MAX_SIDE_NODES]; |
| 4096 |
|
| 4097 |
IFDEBUG(gm,2) |
| 4098 |
UserWriteF(PFMT " CONNECT side=%i of elem=" EID_FMTX "\n",me,i,EID_PRTX(theElement)); |
| 4099 |
ENDDEBUG |
| 4100 |
|
| 4101 |
for (j=0; j<MAX_SONS; j++) |
| 4102 |
Sons_of_Side_List[j] = NULL; |
| 4103 |
|
| 4104 |
Sons_of_Side = 1; |
| 4105 |
Sons_of_Side_List[0] = theSon; |
| 4106 |
SonSides[0] = i; |
| 4107 |
|
| 4108 |
if (Connect_Sons_of_ElementSide(theGrid,theElement,i,Sons_of_Side, |
| 4109 |
Sons_of_Side_List,SonSides,0)!=GM_OK) RETURN(GM_FATAL); |
| 4110 |
|
| 4111 |
#ifdef ModelP |
| 4112 |
if (Identify_Objects_of_ElementSide(theGrid,theElement,i)) RETURN(GM_FATAL); |
| 4113 |
#endif |
| 4114 |
} |
| 4115 |
|
| 4116 |
return(GM_OK); |
| 4117 |
} |
| 4118 |
|
| 4119 |
|
| 4120 |
/****************************************************************************/ |
| 4121 |
/** \brief Refine an element without context |
| 4122 |
|
| 4123 |
\param theGrid - grid level of sons of theElement |
| 4124 |
\param theElement - element to refine |
| 4125 |
\param theContext - nodes needed for new elements |
| 4126 |
|
| 4127 |
This function refines an element without context, |
| 4128 |
(i) corner and midnodes are already allocated, |
| 4129 |
(ii) edges between corner and midnodes are ok, |
| 4130 |
(iii) create interior nodes and edges, |
| 4131 |
(iv) create sons and set references to sons. |
| 4132 |
|
| 4133 |
\return <ul> |
| 4134 |
INT |
| 4135 |
.n 0 - ok |
| 4136 |
.n 1 - fatal memory error |
| 4137 |
*/ |
| 4138 |
/****************************************************************************/ |
| 4139 |
static int RefineElementGreen (GRID *theGrid, ELEMENT *theElement, NODE **theContext) |
| 4140 |
{ |
| 4141 |
struct greensondata |
| 4142 |
{ |
| 4143 |
/** \brief Element type */ |
| 4144 |
short tag; |
| 4145 |
/** \brief Boundary element: yes (=1) or no (=0) */ |
| 4146 |
short bdy; |
| 4147 |
std::array<NODE*, MAX_CORNERS_OF_ELEM> corners; |
| 4148 |
int nb[MAX_SIDES_OF_ELEM]; |
| 4149 |
ELEMENT *theSon; |
| 4150 |
}; |
| 4151 |
typedef struct greensondata GREENSONDATA; |
| 4152 |
|
| 4153 |
std::array<GREENSONDATA, MAX_GREEN_SONS> sons; |
| 4154 |
|
| 4155 |
int j, k, l; |
| 4156 |
int node0; |
| 4157 |
bool bdy; |
| 4158 |
|
| 4159 |
IFDEBUG(gm,1) |
| 4160 |
UserWriteF("RefineElementGreen(): ELEMENT ID=%d\n",ID(theElement)); |
| 4161 |
ENDDEBUG |
| 4162 |
|
| 4163 |
/* init son data array */ |
| 4164 |
for (int i = 0; i < MAX_GREEN_SONS; i++) |
| 4165 |
{ |
| 4166 |
sons[i].tag = -1; |
| 4167 |
sons[i].bdy = -1; |
| 4168 |
for (j=0; j<MAX_CORNERS_OF_ELEM; j++) sons[i].corners[j] = NULL; |
| 4169 |
for (j=0; j<MAX_SIDES_OF_ELEM; j++) sons[i].nb[j] = -1; |
| 4170 |
sons[i].theSon = NULL; |
| 4171 |
} |
| 4172 |
|
| 4173 |
IFDEBUG(gm,2) |
| 4174 |
UserWriteF(" Element ID=%d actual CONTEXT is:\n",ID(theElement)); |
| 4175 |
for (int i = 0; i < MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) |
| 4176 |
UserWriteF(" %3d",i); |
| 4177 |
UserWrite("\n"); |
| 4178 |
for (int i = 0; i < MAX_CORNERS_OF_ELEM + MAX_NEW_CORNERS_DIM; i++) |
| 4179 |
if (theContext[i] != NULL) |
| 4180 |
UserWriteF(" %3d",ID(theContext[i])); |
| 4181 |
else |
| 4182 |
UserWriteF(" "); |
| 4183 |
UserWrite("\n"); |
| 4184 |
ENDDEBUG |
| 4185 |
int corner; |
| 4186 |
IFDEBUG(gm,3) |
| 4187 |
for (corner = 0; corner < MAX_CORNERS_OF_ELEM + MAX_NEW_CORNERS_DIM; corner++) |
| 4188 |
{ |
| 4189 |
if ((theContext[corner] != nullptr) && (NDOBJ != OBJT(theContext[corner]))) |
| 4190 |
UserWriteF(" ERROR NO NDOBJ(5) OBJT(corner=%d)=%d ID=%d adr=%x\n",\ |
| 4191 |
corner,OBJT(theContext[corner]),ID(theContext[corner]),theContext[corner]); |
| 4192 |
} |
| 4193 |
ENDDEBUG |
| 4194 |
|
| 4195 |
/* init indices for son elements */ |
| 4196 |
/* outer side for tetrahedra is side 0 */ |
| 4197 |
const int tetNode0 = CORNER_OF_SIDE_TAG(TETRAHEDRON, 0, 0); |
| 4198 |
const int tetNode1 = CORNER_OF_SIDE_TAG(TETRAHEDRON, 0, 1); |
| 4199 |
const int tetNode2 = CORNER_OF_SIDE_TAG(TETRAHEDRON, 0, 2); |
| 4200 |
|
| 4201 |
const int tetEdge0 = EDGE_OF_SIDE_TAG(TETRAHEDRON, 0, 0); |
| 4202 |
const int tetEdge1 = EDGE_OF_SIDE_TAG(TETRAHEDRON, 0, 1); |
| 4203 |
const int tetEdge2 = EDGE_OF_SIDE_TAG(TETRAHEDRON, 0, 2); |
| 4204 |
|
| 4205 |
int tetSideNode0Node1 = SIDE_WITH_EDGE_TAG(TETRAHEDRON, tetEdge0, 0); |
| 4206 |
if (tetSideNode0Node1 == 0) |
| 4207 |
tetSideNode0Node1 = SIDE_WITH_EDGE_TAG(TETRAHEDRON,tetEdge0,1); |
| 4208 |
|
| 4209 |
int tetSideNode1Node2 = SIDE_WITH_EDGE_TAG(TETRAHEDRON, tetEdge1, 0); |
| 4210 |
if (tetSideNode1Node2 == 0) |
| 4211 |
tetSideNode1Node2 = SIDE_WITH_EDGE_TAG(TETRAHEDRON,tetEdge1,1); |
| 4212 |
|
| 4213 |
int tetSideNode0Node2 = SIDE_WITH_EDGE_TAG(TETRAHEDRON, tetEdge2, 0); |
| 4214 |
if (tetSideNode0Node2 == 0) |
| 4215 |
tetSideNode0Node2 = SIDE_WITH_EDGE_TAG(TETRAHEDRON,tetEdge2,1); |
| 4216 |
|
| 4217 |
/* outer side for pyramid has 4 corners */ |
| 4218 |
for (corner = 0; corner < SIDES_OF_TAG(PYRAMID); corner++) |
| 4219 |
if (CORNERS_OF_SIDE_TAG(PYRAMID, corner) == 4) |
| 4220 |
break; |
| 4221 |
const int pyrNode0 = CORNER_OF_SIDE_TAG(PYRAMID, corner, 0); |
| 4222 |
const int pyrNode1 = CORNER_OF_SIDE_TAG(PYRAMID, corner, 1); |
| 4223 |
const int pyrNode2 = CORNER_OF_SIDE_TAG(PYRAMID, corner, 2); |
| 4224 |
const int pyrNode3 = CORNER_OF_SIDE_TAG(PYRAMID, corner, 3); |
| 4225 |
|
| 4226 |
const int pyrEdge0 = EDGE_OF_SIDE_TAG(PYRAMID, corner, 0); |
| 4227 |
const int pyrEdge1 = EDGE_OF_SIDE_TAG(PYRAMID, corner, 1); |
| 4228 |
const int pyrEdge2 = EDGE_OF_SIDE_TAG(PYRAMID, corner, 2); |
| 4229 |
const int pyrEdge3 = EDGE_OF_SIDE_TAG(PYRAMID, corner, 3); |
| 4230 |
|
| 4231 |
int pyrSideNode0Node1 = SIDE_WITH_EDGE_TAG(PYRAMID, pyrEdge0, 1); |
| 4232 |
if (pyrSideNode0Node1 == corner) |
| 4233 |
pyrSideNode0Node1 = SIDE_WITH_EDGE_TAG(PYRAMID,pyrEdge0,0); |
| 4234 |
|
| 4235 |
int pyrSideNode1Node2 = SIDE_WITH_EDGE_TAG(PYRAMID, pyrEdge1, 1); |
| 4236 |
if (pyrSideNode1Node2 == corner) |
| 4237 |
pyrSideNode1Node2 = SIDE_WITH_EDGE_TAG(PYRAMID,pyrEdge1,0); |
| 4238 |
|
| 4239 |
int pyrSideNode2Node3 = SIDE_WITH_EDGE_TAG(PYRAMID, pyrEdge2, 1); |
| 4240 |
if (pyrSideNode2Node3 == corner) |
| 4241 |
pyrSideNode2Node3 = SIDE_WITH_EDGE_TAG(PYRAMID,pyrEdge2,0); |
| 4242 |
|
| 4243 |
int pyrSideNode0Node3 = SIDE_WITH_EDGE_TAG(PYRAMID, pyrEdge3, 1); |
| 4244 |
if (pyrSideNode0Node3 == corner) |
| 4245 |
pyrSideNode0Node3 = SIDE_WITH_EDGE_TAG(PYRAMID,pyrEdge3,0); |
| 4246 |
|
| 4247 |
/* create edges on inner of sides, create son elements and connect them */ |
| 4248 |
std::array<int, 4> sides; |
| 4249 |
std::array<NODE*, 8> theSideNodes; |
| 4250 |
|
| 4251 |
for (int i = 0; i < SIDES_OF_ELEM(theElement); i++) |
| 4252 |
{ |
| 4253 |
NODE *theNode = theContext[CORNERS_OF_ELEM(theElement)+ |
| 4254 |
EDGES_OF_ELEM(theElement)+i]; |
| 4255 |
const int nedges = EDGES_OF_SIDE(theElement,i); |
| 4256 |
|
| 4257 |
bdy = (OBJT(theElement) == BEOBJ && SIDE_ON_BND(theElement,i)); |
| 4258 |
|
| 4259 |
int nelem = 5*i; /* A face in 3d gets subdivided into at most 5 (yes, 5) parts */ |
| 4260 |
for (j=nelem; j<(nelem+5); j++) |
| 4261 |
sons[j].bdy = bdy; |
| 4262 |
|
| 4263 |
k = 0; |
| 4264 |
for (j=0; j<EDGES_OF_SIDE(theElement,i); j++) |
| 4265 |
{ |
| 4266 |
const int edge = EDGE_OF_SIDE(theElement,i,j); |
| 4267 |
for (l=0; l<MAX_SIDES_OF_ELEM; l++) |
| 4268 |
if (SIDE_WITH_EDGE(theElement,edge,l) != i) |
| 4269 |
{ |
| 4270 |
sides[k++] = SIDE_WITH_EDGE(theElement,edge,l)+ |
| 4271 |
MAX_GREEN_SONS; |
| 4272 |
break; |
| 4273 |
} |
| 4274 |
ASSERT(l<2); |
| 4275 |
} |
| 4276 |
|
| 4277 |
k = 0; |
| 4278 |
for (j=0; j<nedges; j++) |
| 4279 |
{ |
| 4280 |
theSideNodes[2*j] = theContext[CORNER_OF_SIDE(theElement,i,j)]; |
| 4281 |
theSideNodes[2*j+1] = theContext[CORNERS_OF_ELEM(theElement)+ |
| 4282 |
EDGE_OF_SIDE(theElement,i,j)]; |
| 4283 |
if (theSideNodes[2*j+1] != NULL) k++; |
| 4284 |
} |
| 4285 |
|
| 4286 |
IFDEBUG(gm,2) |
| 4287 |
UserWriteF(" SIDE %d has %d nodes and sidenode=%x\n",i,k,theNode); |
| 4288 |
ENDDEBUG |
| 4289 |
|
| 4290 |
switch (CORNERS_OF_SIDE(theElement,i)) |
| 4291 |
{ |
| 4292 |
|
| 4293 |
case 4 : |
| 4294 |
|
| 4295 |
/* theNode points to a potential new side node */ |
| 4296 |
if (theNode == NULL) |
| 4297 |
{ |
| 4298 |
switch (k) /* The number of nodes on the edges of this side */ |
| 4299 |
{ |
| 4300 |
case 0 : |
| 4301 |
sons[nelem].tag = PYRAMID; |
| 4302 |
sons[nelem].corners[pyrNode0] = theSideNodes[0]; |
| 4303 |
sons[nelem].corners[pyrNode1] = theSideNodes[2]; |
| 4304 |
sons[nelem].corners[pyrNode2] = theSideNodes[4]; |
| 4305 |
sons[nelem].corners[pyrNode3] = theSideNodes[6]; |
| 4306 |
|
| 4307 |
sons[nelem].nb[pyrSideNode0Node1] = sides[0]; |
| 4308 |
sons[nelem].nb[pyrSideNode1Node2] = sides[1]; |
| 4309 |
sons[nelem].nb[pyrSideNode2Node3] = sides[2]; |
| 4310 |
sons[nelem].nb[pyrSideNode0Node3] = sides[3]; |
| 4311 |
|
| 4312 |
break; |
| 4313 |
|
| 4314 |
case 1 : |
| 4315 |
for (j=0; j<nedges; j++) |
| 4316 |
{ |
| 4317 |
node0 = 2*j+1; |
| 4318 |
if (theSideNodes[node0] != NULL) |
| 4319 |
{ |
| 4320 |
|
| 4321 |
/* define the son corners and inner side relations */ |
| 4322 |
sons[nelem].tag = TETRAHEDRON; |
| 4323 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4324 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4325 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4326 |
|
| 4327 |
sons[nelem].nb[tetSideNode0Node1] = sides[j]; |
| 4328 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+1)%nedges]; |
| 4329 |
sons[nelem].nb[tetSideNode0Node2] = nelem+2; |
| 4330 |
nelem++; |
| 4331 |
|
| 4332 |
sons[nelem].tag = TETRAHEDRON; |
| 4333 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4334 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4335 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+7)%(2*nedges)]; |
| 4336 |
|
| 4337 |
sons[nelem].nb[tetSideNode0Node1] = nelem+1; |
| 4338 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+3)%nedges]; |
| 4339 |
sons[nelem].nb[tetSideNode0Node2] = sides[j]; |
| 4340 |
nelem++; |
| 4341 |
|
| 4342 |
sons[nelem].tag = TETRAHEDRON; |
| 4343 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4344 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4345 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4346 |
|
| 4347 |
sons[nelem].nb[tetSideNode0Node1] = nelem-2; |
| 4348 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4349 |
sons[nelem].nb[tetSideNode0Node2] = nelem-1; |
| 4350 |
|
| 4351 |
break; |
| 4352 |
} |
| 4353 |
} |
| 4354 |
break; |
| 4355 |
|
| 4356 |
case 2 : |
| 4357 |
/* two cases: sidenodes are not on neighboring edges OR are on neighboring edges */ |
| 4358 |
for (j=0; j<nedges; j++) |
| 4359 |
{ |
| 4360 |
node0 = 2*j+1; |
| 4361 |
if (theSideNodes[node0] != NULL) |
| 4362 |
break; |
| 4363 |
} |
| 4364 |
if (theSideNodes[(node0+6)%(2*nedges)] != NULL) |
| 4365 |
{ |
| 4366 |
node0 = (node0+6)%(2*nedges); |
| 4367 |
j = (j+3)%nedges; |
| 4368 |
} |
| 4369 |
if (theSideNodes[(node0+4)%(2*nedges)] == NULL) |
| 4370 |
{ |
| 4371 |
|
| 4372 |
sons[nelem].tag = TETRAHEDRON; |
| 4373 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4374 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4375 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4376 |
|
| 4377 |
sons[nelem].nb[tetSideNode0Node1] = sides[(j)%nedges]; |
| 4378 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+1)%nedges]; |
| 4379 |
sons[nelem].nb[tetSideNode0Node2] = nelem+3; |
| 4380 |
nelem++; |
| 4381 |
|
| 4382 |
sons[nelem].tag = TETRAHEDRON; |
| 4383 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4384 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4385 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+7)%(2*nedges)]; |
| 4386 |
|
| 4387 |
sons[nelem].nb[tetSideNode0Node1] = nelem+2; |
| 4388 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+3)%nedges]; |
| 4389 |
sons[nelem].nb[tetSideNode0Node2] = sides[(j)%nedges]; |
| 4390 |
nelem++; |
| 4391 |
|
| 4392 |
sons[nelem].tag = TETRAHEDRON; |
| 4393 |
sons[nelem].corners[tetNode0] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4394 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4395 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4396 |
|
| 4397 |
sons[nelem].nb[tetSideNode0Node1] = sides[(j+1)%nedges]; |
| 4398 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4399 |
sons[nelem].nb[tetSideNode0Node2] = nelem+1; |
| 4400 |
nelem++; |
| 4401 |
|
| 4402 |
sons[nelem].tag = TETRAHEDRON; |
| 4403 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4404 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4405 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4406 |
|
| 4407 |
sons[nelem].nb[tetSideNode0Node1] = nelem-3; |
| 4408 |
sons[nelem].nb[tetSideNode1Node2] = nelem-1; |
| 4409 |
sons[nelem].nb[tetSideNode0Node2] = nelem-2; |
| 4410 |
} |
| 4411 |
else |
| 4412 |
{ |
| 4413 |
sons[nelem].tag = PYRAMID; |
| 4414 |
sons[nelem].corners[pyrNode0] = theSideNodes[node0]; |
| 4415 |
sons[nelem].corners[pyrNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4416 |
sons[nelem].corners[pyrNode2] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4417 |
sons[nelem].corners[pyrNode3] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4418 |
|
| 4419 |
sons[nelem].nb[pyrSideNode0Node1] = sides[(j)%nedges]; |
| 4420 |
sons[nelem].nb[pyrSideNode1Node2] = sides[(j+1)%nedges]; |
| 4421 |
sons[nelem].nb[pyrSideNode2Node3] = sides[(j+2)%nedges]; |
| 4422 |
sons[nelem].nb[pyrSideNode0Node3] = nelem+1; |
| 4423 |
nelem++; |
| 4424 |
|
| 4425 |
sons[nelem].tag = PYRAMID; |
| 4426 |
sons[nelem].corners[pyrNode0] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4427 |
sons[nelem].corners[pyrNode1] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4428 |
sons[nelem].corners[pyrNode2] = theSideNodes[(node0+7)%(2*nedges)]; |
| 4429 |
sons[nelem].corners[pyrNode3] = theSideNodes[(node0+8)%(2*nedges)]; |
| 4430 |
|
| 4431 |
sons[nelem].nb[pyrSideNode0Node1] = sides[(j+2)%nedges]; |
| 4432 |
sons[nelem].nb[pyrSideNode1Node2] = sides[(j+3)%nedges]; |
| 4433 |
sons[nelem].nb[pyrSideNode2Node3] = sides[(j)%nedges]; |
| 4434 |
sons[nelem].nb[pyrSideNode0Node3] = nelem-1; |
| 4435 |
} |
| 4436 |
break; |
| 4437 |
|
| 4438 |
case 3 : |
| 4439 |
for (j=0; j<nedges; j++) |
| 4440 |
{ |
| 4441 |
node0 = 2*j+1; |
| 4442 |
if (theSideNodes[node0] == NULL) |
| 4443 |
break; |
| 4444 |
} |
| 4445 |
|
| 4446 |
sons[nelem].tag = PYRAMID; |
| 4447 |
sons[nelem].corners[pyrNode0] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4448 |
sons[nelem].corners[pyrNode1] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4449 |
sons[nelem].corners[pyrNode2] = theSideNodes[(node0+6)%(2*nedges)]; |
| 4450 |
sons[nelem].corners[pyrNode3] = theSideNodes[(node0+7)%(2*nedges)]; |
| 4451 |
|
| 4452 |
sons[nelem].nb[pyrSideNode0Node1] = sides[(j+1)%nedges]; |
| 4453 |
sons[nelem].nb[pyrSideNode1Node2] = nelem+3; |
| 4454 |
sons[nelem].nb[pyrSideNode2Node3] = sides[(j+3)%nedges]; |
| 4455 |
sons[nelem].nb[pyrSideNode0Node3] = sides[(j)%nedges]; |
| 4456 |
nelem++; |
| 4457 |
|
| 4458 |
sons[nelem].tag = TETRAHEDRON; |
| 4459 |
sons[nelem].corners[tetNode0] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4460 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4461 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4462 |
|
| 4463 |
sons[nelem].nb[tetSideNode0Node1] = sides[(j+1)%nedges]; |
| 4464 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4465 |
sons[nelem].nb[tetSideNode0Node2] = nelem+2; |
| 4466 |
nelem++; |
| 4467 |
|
| 4468 |
sons[nelem].tag = TETRAHEDRON; |
| 4469 |
sons[nelem].corners[tetNode0] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4470 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4471 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+6)%(2*nedges)]; |
| 4472 |
|
| 4473 |
sons[nelem].nb[tetSideNode0Node1] = sides[(j+2)%nedges]; |
| 4474 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+3)%nedges]; |
| 4475 |
sons[nelem].nb[tetSideNode0Node2] = nelem+1; |
| 4476 |
nelem++; |
| 4477 |
|
| 4478 |
sons[nelem].tag = TETRAHEDRON; |
| 4479 |
sons[nelem].corners[tetNode0] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4480 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4481 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+6)%(2*nedges)]; |
| 4482 |
|
| 4483 |
sons[nelem].nb[tetSideNode0Node1] = nelem-2; |
| 4484 |
sons[nelem].nb[tetSideNode1Node2] = nelem-1; |
| 4485 |
sons[nelem].nb[tetSideNode0Node2] = nelem-3; |
| 4486 |
|
| 4487 |
break; |
| 4488 |
|
| 4489 |
case 4 : |
| 4490 |
for (j=0; j<nedges; j++) |
| 4491 |
{ |
| 4492 |
node0 = 2*j+1; |
| 4493 |
|
| 4494 |
sons[nelem].tag = TETRAHEDRON; |
| 4495 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4496 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4497 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4498 |
|
| 4499 |
sons[nelem].nb[tetSideNode0Node1] = sides[(j)%nedges]; |
| 4500 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+1)%nedges]; |
| 4501 |
sons[nelem].nb[tetSideNode0Node2] = nelem+(nedges-j); |
| 4502 |
nelem++; |
| 4503 |
} |
| 4504 |
|
| 4505 |
sons[nelem].tag = PYRAMID; |
| 4506 |
sons[nelem].corners[pyrNode0] = theSideNodes[1]; |
| 4507 |
sons[nelem].corners[pyrNode1] = theSideNodes[3]; |
| 4508 |
sons[nelem].corners[pyrNode2] = theSideNodes[5]; |
| 4509 |
sons[nelem].corners[pyrNode3] = theSideNodes[7]; |
| 4510 |
|
| 4511 |
sons[nelem].nb[pyrSideNode0Node1] = nelem-4; |
| 4512 |
sons[nelem].nb[pyrSideNode1Node2] = nelem-3; |
| 4513 |
sons[nelem].nb[pyrSideNode2Node3] = nelem-2; |
| 4514 |
sons[nelem].nb[pyrSideNode0Node3] = nelem-1; |
| 4515 |
break; |
| 4516 |
|
| 4517 |
default : |
| 4518 |
RETURN(GM_FATAL); |
| 4519 |
} |
| 4520 |
} |
| 4521 |
else /* theNode != NULL */ |
| 4522 |
{ |
| 4523 |
/* create the four side edges */ |
| 4524 |
for (j=0; j<nedges; j++) |
| 4525 |
{ |
| 4526 |
node0 = 2*j+1; |
| 4527 |
if (theSideNodes[node0] == NULL) break; |
| 4528 |
|
| 4529 |
sons[nelem].tag = PYRAMID; |
| 4530 |
sons[nelem].corners[pyrNode0] = theSideNodes[node0%(2*nedges)]; |
| 4531 |
sons[nelem].corners[pyrNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4532 |
sons[nelem].corners[pyrNode2] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4533 |
sons[nelem].corners[pyrNode3] = theNode; |
| 4534 |
|
| 4535 |
sons[nelem].nb[pyrSideNode0Node1] = sides[(j)%nedges]; |
| 4536 |
sons[nelem].nb[pyrSideNode1Node2] = sides[(j+1)%nedges]; |
| 4537 |
if (j == 3) |
| 4538 |
sons[nelem].nb[pyrSideNode2Node3] = nelem-3; |
| 4539 |
else |
| 4540 |
sons[nelem].nb[pyrSideNode2Node3] = nelem+1; |
| 4541 |
if (j == 0) |
| 4542 |
sons[nelem].nb[pyrSideNode0Node3] = nelem+3; |
| 4543 |
else |
| 4544 |
sons[nelem].nb[pyrSideNode0Node3] = nelem-1; |
| 4545 |
nelem++; |
| 4546 |
|
| 4547 |
} |
| 4548 |
ASSERT(j==4); |
| 4549 |
} |
| 4550 |
|
| 4551 |
break; |
| 4552 |
|
| 4553 |
case 3 : |
| 4554 |
if (theNode == NULL) |
| 4555 |
{ |
| 4556 |
switch (k) |
| 4557 |
{ |
| 4558 |
case 0 : |
| 4559 |
sons[nelem].tag = TETRAHEDRON; |
| 4560 |
sons[nelem].corners[tetNode0] = theSideNodes[0]; |
| 4561 |
sons[nelem].corners[tetNode1] = theSideNodes[2]; |
| 4562 |
sons[nelem].corners[tetNode2] = theSideNodes[4]; |
| 4563 |
|
| 4564 |
sons[nelem].nb[tetSideNode0Node1] = sides[0]; |
| 4565 |
sons[nelem].nb[tetSideNode1Node2] = sides[1]; |
| 4566 |
sons[nelem].nb[tetSideNode0Node2] = sides[2]; |
| 4567 |
|
| 4568 |
break; |
| 4569 |
|
| 4570 |
case 1 : |
| 4571 |
for (j=0; j<nedges; j++) |
| 4572 |
{ |
| 4573 |
node0 = 2*j+1; |
| 4574 |
if (theSideNodes[node0] != NULL) |
| 4575 |
{ |
| 4576 |
|
| 4577 |
/* define the son corners and inner side relations */ |
| 4578 |
sons[nelem].tag = TETRAHEDRON; |
| 4579 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4580 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4581 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4582 |
|
| 4583 |
sons[nelem].nb[tetSideNode0Node1] = sides[j]; |
| 4584 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+1)%nedges]; |
| 4585 |
sons[nelem].nb[tetSideNode0Node2] = nelem+1; |
| 4586 |
nelem++; |
| 4587 |
|
| 4588 |
sons[nelem].tag = TETRAHEDRON; |
| 4589 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4590 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4591 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4592 |
|
| 4593 |
sons[nelem].nb[tetSideNode0Node1] = nelem-1; |
| 4594 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4595 |
sons[nelem].nb[tetSideNode0Node2] = sides[j]; |
| 4596 |
|
| 4597 |
break; |
| 4598 |
} |
| 4599 |
} |
| 4600 |
break; |
| 4601 |
|
| 4602 |
case 2 : |
| 4603 |
{ |
| 4604 |
INT node; |
| 4605 |
/*INT maxedge=-1;*/ |
| 4606 |
#ifdef ModelP |
| 4607 |
unsigned int maxid = 0; |
| 4608 |
#else |
| 4609 |
INT maxid = -1; |
| 4610 |
#endif |
| 4611 |
|
| 4612 |
node0 = -1; |
| 4613 |
for (k=0; k<nedges; k++) |
| 4614 |
{ |
| 4615 |
node = (2*k+3)%(2*nedges); |
| 4616 |
if (theSideNodes[node] == NULL) |
| 4617 |
{ |
| 4618 |
node0 = 2*k+1; |
| 4619 |
j = k; |
| 4620 |
} |
| 4621 |
/* |
| 4622 |
if (EDGE_OF_SIDE(theElement,i,k)>maxedge) |
| 4623 |
maxedge = 2*k+1; |
| 4624 |
*/ |
| 4625 |
/* neighboring elements need to refine in the same way */ |
| 4626 |
/* in parallel case all copies of the elements also */ |
| 4627 |
if (theSideNodes[2*k+1]!=NULL && _ID_(theSideNodes[2*k+1])>maxid) |
| 4628 |
maxid = _ID_(theSideNodes[2*k+1]); |
| 4629 |
} |
| 4630 |
#if !defined ModelP // For an unknown reason the maxid variable is unsigned when ModelP is set, and signed otherwise. |
| 4631 |
assert(maxid != -1); |
| 4632 |
#endif |
| 4633 |
assert(node0 != -1); |
| 4634 |
|
| 4635 |
/* if (node0 == maxedge && ((SIDEPATTERN(theElement)&(1<<i)) == 0)) */ |
| 4636 |
if (_ID_(theSideNodes[node0]) == maxid) |
| 4637 |
{ |
| 4638 |
|
| 4639 |
sons[nelem].tag = TETRAHEDRON; |
| 4640 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4641 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4642 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4643 |
|
| 4644 |
sons[nelem].nb[tetSideNode0Node1] = sides[j]; |
| 4645 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+1)%nedges]; |
| 4646 |
sons[nelem].nb[tetSideNode0Node2] = nelem+2; |
| 4647 |
nelem++; |
| 4648 |
|
| 4649 |
sons[nelem].tag = TETRAHEDRON; |
| 4650 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4651 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4652 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4653 |
|
| 4654 |
sons[nelem].nb[tetSideNode0Node1] = nelem+1; |
| 4655 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4656 |
sons[nelem].nb[tetSideNode0Node2] = sides[j]; |
| 4657 |
nelem++; |
| 4658 |
|
| 4659 |
sons[nelem].tag = TETRAHEDRON; |
| 4660 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4661 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4662 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4663 |
|
| 4664 |
sons[nelem].nb[tetSideNode0Node1] = nelem-2; |
| 4665 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4666 |
sons[nelem].nb[tetSideNode0Node2] = nelem-1; |
| 4667 |
} |
| 4668 |
else |
| 4669 |
{ |
| 4670 |
sons[nelem].tag = TETRAHEDRON; |
| 4671 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4672 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4673 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4674 |
|
| 4675 |
sons[nelem].nb[tetSideNode0Node1] = sides[j]; |
| 4676 |
sons[nelem].nb[tetSideNode1Node2] = nelem+1; |
| 4677 |
sons[nelem].nb[tetSideNode0Node2] = nelem+2; |
| 4678 |
nelem++; |
| 4679 |
|
| 4680 |
sons[nelem].tag = TETRAHEDRON; |
| 4681 |
sons[nelem].corners[tetNode0] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4682 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4683 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4684 |
|
| 4685 |
sons[nelem].nb[tetSideNode0Node1] = nelem-1; |
| 4686 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+1)%nedges]; |
| 4687 |
sons[nelem].nb[tetSideNode0Node2] = sides[(j+2)%nedges]; |
| 4688 |
nelem++; |
| 4689 |
|
| 4690 |
sons[nelem].tag = TETRAHEDRON; |
| 4691 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4692 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4693 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4694 |
|
| 4695 |
sons[nelem].nb[tetSideNode0Node1] = nelem-2; |
| 4696 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4697 |
sons[nelem].nb[tetSideNode0Node2] = sides[j]; |
| 4698 |
} |
| 4699 |
|
| 4700 |
break; |
| 4701 |
} |
| 4702 |
case 3 : |
| 4703 |
j = 0; |
| 4704 |
node0 = 1; |
| 4705 |
|
| 4706 |
sons[nelem].tag = TETRAHEDRON; |
| 4707 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4708 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4709 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4710 |
|
| 4711 |
sons[nelem].nb[tetSideNode0Node1] = sides[j]; |
| 4712 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+1)%nedges]; |
| 4713 |
sons[nelem].nb[tetSideNode0Node2] = nelem+3; |
| 4714 |
nelem++; |
| 4715 |
|
| 4716 |
sons[nelem].tag = TETRAHEDRON; |
| 4717 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4718 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4719 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+5)%(2*nedges)]; |
| 4720 |
|
| 4721 |
sons[nelem].nb[tetSideNode0Node1] = nelem+2; |
| 4722 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4723 |
sons[nelem].nb[tetSideNode0Node2] = sides[j]; |
| 4724 |
nelem++; |
| 4725 |
|
| 4726 |
sons[nelem].tag = TETRAHEDRON; |
| 4727 |
sons[nelem].corners[tetNode0] = theSideNodes[node0+2]; |
| 4728 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+3)%(2*nedges)]; |
| 4729 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4730 |
|
| 4731 |
sons[nelem].nb[tetSideNode0Node1] = sides[(j+1)%nedges]; |
| 4732 |
sons[nelem].nb[tetSideNode1Node2] = sides[(j+2)%nedges]; |
| 4733 |
sons[nelem].nb[tetSideNode0Node2] = nelem+1; |
| 4734 |
nelem++; |
| 4735 |
|
| 4736 |
sons[nelem].tag = TETRAHEDRON; |
| 4737 |
sons[nelem].corners[tetNode0] = theSideNodes[node0]; |
| 4738 |
sons[nelem].corners[tetNode1] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4739 |
sons[nelem].corners[tetNode2] = theSideNodes[(node0+4)%(2*nedges)]; |
| 4740 |
|
| 4741 |
sons[nelem].nb[tetSideNode0Node1] = nelem-3; |
| 4742 |
sons[nelem].nb[tetSideNode1Node2] = nelem-1; |
| 4743 |
sons[nelem].nb[tetSideNode0Node2] = nelem-2; |
| 4744 |
|
| 4745 |
break; |
| 4746 |
|
| 4747 |
default : |
| 4748 |
assert(0); |
| 4749 |
break; |
| 4750 |
} |
| 4751 |
} |
| 4752 |
|
| 4753 |
else /* theNode != NULL */ |
| 4754 |
{ |
| 4755 |
/* create the four side edges */ |
| 4756 |
for (j=0; j<nedges; j++) |
| 4757 |
{ |
| 4758 |
node0 = 2*j+1; |
| 4759 |
if (theSideNodes[node0] == NULL) break; |
| 4760 |
|
| 4761 |
sons[nelem].tag = PYRAMID; |
| 4762 |
sons[nelem].corners[pyrNode0] = theSideNodes[node0%(2*nedges)]; |
| 4763 |
sons[nelem].corners[pyrNode1] = theSideNodes[(node0+1)%(2*nedges)]; |
| 4764 |
sons[nelem].corners[pyrNode2] = theSideNodes[(node0+2)%(2*nedges)]; |
| 4765 |
sons[nelem].corners[pyrNode3] = theNode; |
| 4766 |
|
| 4767 |
sons[nelem].nb[pyrSideNode0Node1] = sides[(j)%nedges]; |
| 4768 |
sons[nelem].nb[pyrSideNode1Node2] = sides[(j+1)%nedges]; |
| 4769 |
if (j == 2) |
| 4770 |
sons[nelem].nb[pyrSideNode2Node3] = nelem-2; |
| 4771 |
else |
| 4772 |
sons[nelem].nb[pyrSideNode2Node3] = nelem+1; |
| 4773 |
if (j == 0) |
| 4774 |
sons[nelem].nb[pyrSideNode0Node3] = nelem+2; |
| 4775 |
else |
| 4776 |
sons[nelem].nb[pyrSideNode0Node3] = nelem-1; |
| 4777 |
} |
| 4778 |
ASSERT(j==nedges); |
| 4779 |
} |
| 4780 |
|
| 4781 |
break; |
| 4782 |
|
| 4783 |
default : /* Side with neither 3 nor 4 vertices found */ |
| 4784 |
assert(0); |
| 4785 |
break; |
| 4786 |
} |
| 4787 |
} |
| 4788 |
|
| 4789 |
/* connect elements over edges */ |
| 4790 |
for (int i = 0; i < EDGES_OF_ELEM(theElement); i++) |
| 4791 |
{ |
| 4792 |
const int side0 = SIDE_WITH_EDGE(theElement, i, 0); |
| 4793 |
const int side1 = SIDE_WITH_EDGE(theElement, i, 1); |
| 4794 |
|
| 4795 |
if (theContext[i+CORNERS_OF_ELEM(theElement)] == NULL) /* No new node in the middle of this edge */ |
| 4796 |
{ |
| 4797 |
/* two elements share this edge */ |
| 4798 |
|
| 4799 |
/* get son elements for this edge */ |
| 4800 |
bool found = false; |
| 4801 |
for (j=side0*5; j<(side0*5+5); j++) |
| 4802 |
{ |
| 4803 |
for (k=0; k<MAX_SIDES_OF_ELEM; k++) |
| 4804 |
if ((sons[j].nb[k]-MAX_GREEN_SONS)==side1) |
| 4805 |
{ |
| 4806 |
found = true; |
| 4807 |
break; |
| 4808 |
} |
| 4809 |
if (found) break; |
| 4810 |
} |
| 4811 |
ASSERT(j<side0*5+5); |
| 4812 |
|
| 4813 |
found = false; |
| 4814 |
int m; |
| 4815 |
for (l=side1*5; l<side1*5+5; l++) |
| 4816 |
{ |
| 4817 |
for (m=0; m<MAX_SIDES_OF_ELEM; m++) |
| 4818 |
if ((sons[l].nb[m]-MAX_GREEN_SONS)==side0) |
| 4819 |
{ |
| 4820 |
found = true; |
| 4821 |
break; |
| 4822 |
} |
| 4823 |
if (found) break; |
| 4824 |
} |
| 4825 |
ASSERT(l<side1*5+5); |
| 4826 |
|
| 4827 |
sons[j].nb[k] = l; |
| 4828 |
sons[l].nb[m] = j; |
| 4829 |
} |
| 4830 |
else |
| 4831 |
{ |
| 4832 |
/* four elements share this edge */ |
| 4833 |
|
| 4834 |
/* get son elements for this edge */ |
| 4835 |
std::array<int, 5> elementsSide0; |
| 4836 |
l = 0; |
| 4837 |
for (j=side0*5; j<(side0*5+5); j++) |
| 4838 |
{ |
| 4839 |
for (k=0; k<MAX_SIDES_OF_ELEM; k++) |
| 4840 |
if ((sons[j].nb[k]-MAX_GREEN_SONS)==side1) |
| 4841 |
elementsSide0[l++] = j; |
| 4842 |
} |
| 4843 |
ASSERT(l==2); |
| 4844 |
|
| 4845 |
std::array<int, 5> elementsSide1; |
| 4846 |
l = 0; |
| 4847 |
for (j=side1*5; j<(side1*5+5); j++) |
| 4848 |
{ |
| 4849 |
for (int m = 0; m < MAX_SIDES_OF_ELEM; m++) |
| 4850 |
if ((sons[j].nb[m]-MAX_GREEN_SONS)==side0) |
| 4851 |
elementsSide1[l++] = j; |
| 4852 |
} |
| 4853 |
ASSERT(l==2); |
| 4854 |
|
| 4855 |
/* determine neighboring elements */ |
| 4856 |
for (j=0; j<CORNERS_OF_EDGE; j++) |
| 4857 |
{ |
| 4858 |
const NODE *theNode1 = theContext[CORNER_OF_EDGE(theElement,i,j)]; |
| 4859 |
bool found = false; |
| 4860 |
for (l=0; l<2; l++) |
| 4861 |
{ |
| 4862 |
for (k=0; k<MAX_CORNERS_OF_ELEM; k++) |
| 4863 |
{ |
| 4864 |
if (theNode1 == sons[elementsSide0[l]].corners[k]) |
| 4865 |
{ |
| 4866 |
found = true; |
| 4867 |
break; |
| 4868 |
} |
| 4869 |
} |
| 4870 |
if (found) break; |
| 4871 |
} |
| 4872 |
ASSERT(k<MAX_CORNERS_OF_ELEM); |
| 4873 |
ASSERT(l<2); |
| 4874 |
|
| 4875 |
found = false; |
| 4876 |
int m; |
| 4877 |
for (m=0; m<2; m++) |
| 4878 |
{ |
| 4879 |
for (k=0; k<MAX_CORNERS_OF_ELEM; k++) |
| 4880 |
{ |
| 4881 |
if (theNode1 == sons[elementsSide1[m]].corners[k]) |
| 4882 |
{ |
| 4883 |
found = true; |
| 4884 |
break; |
| 4885 |
} |
| 4886 |
} |
| 4887 |
if (found) break; |
| 4888 |
} |
| 4889 |
ASSERT(k<MAX_CORNERS_OF_ELEM); |
| 4890 |
ASSERT(m<2); |
| 4891 |
|
| 4892 |
/* init neighbor field */ |
| 4893 |
for (k=0; k<MAX_SIDES_OF_ELEM; k++) |
| 4894 |
if ((sons[elementsSide0[l]].nb[k]-MAX_GREEN_SONS)==side1) |
| 4895 |
break; |
| 4896 |
ASSERT(k<MAX_SIDES_OF_ELEM); |
| 4897 |
sons[elementsSide0[l]].nb[k] = elementsSide1[m]; |
| 4898 |
|
| 4899 |
for (k=0; k<MAX_SIDES_OF_ELEM; k++) |
| 4900 |
if ((sons[elementsSide1[m]].nb[k]-MAX_GREEN_SONS)==side0) |
| 4901 |
break; |
| 4902 |
ASSERT(k<MAX_SIDES_OF_ELEM); |
| 4903 |
sons[elementsSide1[m]].nb[k] = elementsSide0[l]; |
| 4904 |
} |
| 4905 |
} |
| 4906 |
} |
| 4907 |
|
| 4908 |
/* create son elements */ |
| 4909 |
IFDEBUG(gm,1) |
| 4910 |
UserWriteF(" Creating SON elements for element ID=%d:\n",ID(theElement)); |
| 4911 |
ENDDEBUG |
| 4912 |
int n = 0; |
| 4913 |
for (int i = 0; i < MAX_GREEN_SONS; i++) |
| 4914 |
{ |
| 4915 |
if (sons[i].tag >= 0) |
| 4916 |
{ |
| 4917 |
|
| 4918 |
IFDEBUG(gm,2) |
| 4919 |
if (i%5 == 0) |
| 4920 |
UserWriteF(" SIDE %d:\n",i/5); |
| 4921 |
ENDDEBUG |
| 4922 |
|
| 4923 |
NODE *ElementNodes[MAX_CORNERS_OF_ELEM]; |
| 4924 |
l = 0; |
| 4925 |
for (j=0; j<CORNERS_OF_TAG(sons[i].tag); j++) |
| 4926 |
{ |
| 4927 |
if (sons[i].corners[j] == NULL) |
| 4928 |
{ |
| 4929 |
sons[i].corners[j] = theContext[CORNERS_OF_ELEM(theElement)+ |
| 4930 |
CENTER_NODE_INDEX(theElement)]; |
| 4931 |
l++; |
| 4932 |
} |
| 4933 |
ElementNodes[j] = sons[i].corners[j]; |
| 4934 |
} |
| 4935 |
ASSERT(l == 1); |
| 4936 |
|
| 4937 |
if (sons[i].bdy == 1) |
| 4938 |
sons[i].theSon = CreateElement(theGrid,sons[i].tag,BEOBJ, |
| 4939 |
ElementNodes,theElement,1); |
| 4940 |
else |
| 4941 |
sons[i].theSon = CreateElement(theGrid,sons[i].tag,IEOBJ, |
| 4942 |
ElementNodes,theElement,1); |
| 4943 |
if (sons[i].theSon==NULL) RETURN(GM_FATAL); |
| 4944 |
|
| 4945 |
IFDEBUG(gm,0) |
| 4946 |
for (j=0; j<CORNERS_OF_ELEM(sons[i].theSon); j++) |
| 4947 |
{ |
| 4948 |
for (int m = 0; m < CORNERS_OF_ELEM(sons[i].theSon); m++) |
| 4949 |
{ |
| 4950 |
if (sons[i].corners[j] == NULL || sons[i].corners[m] == NULL) |
| 4951 |
{ |
| 4952 |
if ((m!=j) && (sons[i].corners[j] == sons[i].corners[m])) |
| 4953 |
{ |
| 4954 |
UserWriteF(" ERROR: son %d has equivalent corners " |
| 4955 |
"%d=%d adr=%x adr=%x\n", |
| 4956 |
n,j,m,sons[i].corners[j],sons[i].corners[m]); |
| 4957 |
} |
| 4958 |
} |
| 4959 |
else if ((m != j) |
| 4960 |
&& (sons[i].corners[j] == sons[i].corners[m] || (_ID_(sons[i].corners[j]) == _ID_(sons[i].corners[m])))) |
| 4961 |
{ |
| 4962 |
UserWriteF(" ERROR: son %d has equivalent corners " |
| 4963 |
"%d=%d ID=%d ID=%d adr=%x adr=%x\n", |
| 4964 |
n,j,m,_ID_(sons[i].corners[j]),_ID_(sons[i].corners[m]), |
| 4965 |
sons[i].corners[j],sons[i].corners[m]); |
| 4966 |
} |
| 4967 |
} |
| 4968 |
} |
| 4969 |
ENDDEBUG |
| 4970 |
|
| 4971 |
IFDEBUG(gm,2) |
| 4972 |
UserWriteF(" SONS[i=%d] ID=%d: CORNERS ",i,ID(sons[i].theSon)); |
| 4973 |
for (j=0; j<CORNERS_OF_ELEM(sons[i].theSon); j++) |
| 4974 |
{ |
| 4975 |
if (sons[i].corners[j] != NULL) |
| 4976 |
UserWriteF(" %d",_ID_(sons[i].corners[j])); |
| 4977 |
} |
| 4978 |
UserWriteF("\n"); |
| 4979 |
ENDDEBUG |
| 4980 |
|
| 4981 |
#ifdef __ANISOTROPIC__ |
| 4982 |
if (MARK(theElement) != COPY) |
| 4983 |
SETECLASS(sons[i].theSon,RED_CLASS); |
| 4984 |
else |
| 4985 |
SETECLASS(sons[i].theSon,GREEN_CLASS); |
| 4986 |
#else |
| 4987 |
SETECLASS(sons[i].theSon,GREEN_CLASS); |
| 4988 |
#endif |
| 4989 |
if (i == 0) SET_SON(theElement,0,sons[i].theSon); |
| 4990 |
for (int s = 0; s < SIDES_OF_ELEM(sons[i].theSon); s++) |
| 4991 |
SET_NBELEM(sons[i].theSon,s,NULL); |
| 4992 |
|
| 4993 |
n++; |
| 4994 |
} |
| 4995 |
} |
| 4996 |
IFDEBUG(gm,1) |
| 4997 |
UserWriteF(" n=%d sons created NSONS=%d\n",n,NSONS(theElement)); |
| 4998 |
ENDDEBUG |
| 4999 |
|
| 5000 |
/* translate neighbor information */ |
| 5001 |
for (int i = 0; i < MAX_GREEN_SONS; i++) |
| 5002 |
{ |
| 5003 |
if (sons[i].tag >= 0) /* valid son entry */ |
| 5004 |
{ |
| 5005 |
l = 0; |
| 5006 |
IFDEBUG(gm,0) |
| 5007 |
for (j=0; j<SIDES_OF_ELEM(sons[i].theSon); j++) |
| 5008 |
{ |
| 5009 |
for (int m = 0; m < SIDES_OF_ELEM(sons[i].theSon); m++) |
| 5010 |
{ |
| 5011 |
if (sons[i].nb[j] == sons[i].nb[m] && (m!=j)) |
| 5012 |
UserWriteF(" ERROR: son %d has equivalent " |
| 5013 |
"neighbors %d=%d NB=%d\n",n,j,m,sons[i].nb[m]); |
| 5014 |
} |
| 5015 |
} |
| 5016 |
ENDDEBUG |
| 5017 |
for (j=0; j<SIDES_OF_ELEM(sons[i].theSon); j++) |
| 5018 |
{ |
| 5019 |
if (sons[i].nb[j] != -1) |
| 5020 |
SET_NBELEM(sons[i].theSon,j,sons[sons[i].nb[j]].theSon); |
| 5021 |
else |
| 5022 |
l++; |
| 5023 |
} |
| 5024 |
/* l counts the number of element sides without a neighboring element. |
| 5025 |
* Since all elements are pyramids/tetrahedra with exactly one vertex in the interior, |
| 5026 |
* this value must be one. */ |
| 5027 |
ASSERT(l == 1); |
| 5028 |
} |
| 5029 |
} |
| 5030 |
|
| 5031 |
#ifdef UG_DIM_3 |
| 5032 |
/* If there are side vectors for the elements, then the CreateElement methods called above have |
| 5033 |
* allocated one side vector for each new element face. Therefore, for each face shared by |
| 5034 |
* two elements there are now two side vectors, even though there should be only one (shared). |
| 5035 |
* The following loops gets rid of the second redundant side vector. The redundant side |
| 5036 |
* vectors shared with elements in the rest of the grid are treated in the method Connect_Sons_of_ElementSide, |
| 5037 |
* called further below. |
| 5038 |
*/ |
| 5039 |
if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) |
| 5040 |
{ |
| 5041 |
for (int i = 0; i < MAX_GREEN_SONS; i++) |
| 5042 |
{ |
| 5043 |
if (sons[i].tag < 0) /* empty son entry */ |
| 5044 |
continue; |
| 5045 |
|
| 5046 |
for (j=0; j<SIDES_OF_ELEM(sons[i].theSon); j++) |
| 5047 |
{ |
| 5048 |
if (sons[i].nb[j] != -1) /* We have neighbor on the j-th face */ |
| 5049 |
{ |
| 5050 |
if (sons[i].nb[j] <= i) /* Visit every element pair only once */ |
| 5051 |
continue; |
| 5052 |
|
| 5053 |
ELEMENT* theNeighbor = sons[sons[i].nb[j]].theSon; |
| 5054 |
/* what neighbor are we for the neighbor? */ |
| 5055 |
for (l=0; l<SIDES_OF_ELEM(theNeighbor); l++) |
| 5056 |
if (sons[sons[i].nb[j]].nb[l] == i) |
| 5057 |
break; |
| 5058 |
ASSERT(l < SIDES_OF_ELEM(theNeighbor)); |
| 5059 |
|
| 5060 |
DisposeDoubledSideVector(theGrid, sons[i].theSon, j, theNeighbor, l); |
| 5061 |
} |
| 5062 |
} |
| 5063 |
} |
| 5064 |
} |
| 5065 |
#endif |
| 5066 |
|
| 5067 |
/* connect sons over outer sides */ |
| 5068 |
for (int i = 0; i < SIDES_OF_ELEM(theElement); i++) |
| 5069 |
{ |
| 5070 |
INT Sons_of_Side; |
| 5071 |
ELEMENT *Sons_of_Side_List[MAX_SONS]; |
| 5072 |
INT SonSides[MAX_SIDE_NODES]; |
| 5073 |
|
| 5074 |
Sons_of_Side = 0; |
| 5075 |
|
| 5076 |
for (j=0; j<MAX_SONS; j++) |
| 5077 |
Sons_of_Side_List[j] = NULL; |
| 5078 |
|
| 5079 |
for (j=0; j<5; j++) |
| 5080 |
{ |
| 5081 |
if (sons[i*5+j].tag < 0) break; |
| 5082 |
Sons_of_Side_List[j] = sons[i*5+j].theSon; |
| 5083 |
Sons_of_Side++; |
| 5084 |
SonSides[j] = 0; |
| 5085 |
if (sons[i*5+j].tag == PYRAMID) |
| 5086 |
{ |
| 5087 |
for (k=0; k<SIDES_OF_TAG(PYRAMID); k++) |
| 5088 |
if (CORNERS_OF_SIDE_TAG(PYRAMID,k) == 4) |
| 5089 |
break; |
| 5090 |
SonSides[j] = k; |
| 5091 |
} |
| 5092 |
} |
| 5093 |
assert(Sons_of_Side>0 && Sons_of_Side<6); |
| 5094 |
|
| 5095 |
if (Connect_Sons_of_ElementSide(theGrid,theElement,i,Sons_of_Side, |
| 5096 |
Sons_of_Side_List,SonSides,0)!=GM_OK) RETURN(GM_FATAL); |
| 5097 |
|
| 5098 |
#ifdef ModelP |
| 5099 |
if (Identify_Objects_of_ElementSide(theGrid,theElement,i)) RETURN(GM_FATAL); |
| 5100 |
#endif |
| 5101 |
} |
| 5102 |
|
| 5103 |
return(GM_OK); |
| 5104 |
} |
| 5105 |
|
| 5106 |
|
| 5107 |
/****************************************************************************/ |
| 5108 |
/* |
| 5109 |
RefineElementRed - refine an element in the given context |
| 5110 |
|
| 5111 |
SYNOPSIS: |
| 5112 |
static int RefineElementRed (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext); |
| 5113 |
|
| 5114 |
PARAMETERS: |
| 5115 |
\param theGrid - grid level of sons of theElement |
| 5116 |
\param theElement - element to refine |
| 5117 |
\param theContext - current context of element |
| 5118 |
|
| 5119 |
DESCRIPTION: |
| 5120 |
This function refines an element in the given context, |
| 5121 |
(i) corner and midnodes are already allocated, |
| 5122 |
(ii) edges between corner and midnodes are ok, |
| 5123 |
(iii) create interior nodes and edges, |
| 5124 |
(iv) create sons and set references to sons. |
| 5125 |
|
| 5126 |
\return <ul> |
| 5127 |
INT |
| 5128 |
.n GM_OK - ok |
| 5129 |
.n GM_FATAL - fatal memory error |
| 5130 |
*/ |
| 5131 |
/****************************************************************************/ |
| 5132 |
static int RefineElementRed (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext) |
| 5133 |
{ |
| 5134 |
const int me = theGrid->ppifContext().me(); |
| 5135 |
|
| 5136 |
/* is something to do ? */ |
| 5137 |
if (!MARKED(theElement)) return(GM_OK); |
| 5138 |
|
| 5139 |
std::array<ELEMENT*, MAX_SONS> SonList = {}; |
| 5140 |
|
| 5141 |
REFRULE const* rule = MARK2RULEADR(theElement,MARK(theElement)); |
| 5142 |
|
| 5143 |
/* create elements */ |
| 5144 |
for (INT s=0; s<NSONS_OF_RULE(rule); s++) |
| 5145 |
{ |
| 5146 |
bool boundaryelement = false; |
| 5147 |
/** \todo how can boundary detection be generalized */ |
| 5148 |
if (OBJT(theElement) == BEOBJ) |
| 5149 |
{ |
| 5150 |
for (INT i=0; i<SIDES_OF_TAG(SON_TAG_OF_RULE(rule,s)); i++) |
| 5151 |
{ |
| 5152 |
const INT side = SON_NB_OF_RULE(rule,s,i); |
| 5153 |
/* exterior side */ |
| 5154 |
if (side >= FATHER_SIDE_OFFSET) |
| 5155 |
{ |
| 5156 |
/* at the boundary */ |
| 5157 |
if (SIDE_ON_BND(theElement,side-FATHER_SIDE_OFFSET)) |
| 5158 |
{ |
| 5159 |
boundaryelement = true; |
| 5160 |
break; |
| 5161 |
} |
| 5162 |
} |
| 5163 |
} |
| 5164 |
} |
| 5165 |
|
| 5166 |
NODE* ElementNodes[MAX_CORNERS_OF_ELEM]; |
| 5167 |
for (INT i=0; i<CORNERS_OF_TAG(SON_TAG_OF_RULE(rule,s)); i++) |
| 5168 |
{ |
| 5169 |
ASSERT(theElementContext[SON_CORNER_OF_RULE(rule,s,i)]!=NULL); |
| 5170 |
ElementNodes[i] = theElementContext[SON_CORNER_OF_RULE(rule,s,i)]; |
| 5171 |
} |
| 5172 |
|
| 5173 |
const INT theSonType = boundaryelement ? BEOBJ : IEOBJ; |
| 5174 |
ELEMENT* theSon = CreateElement(theGrid,SON_TAG_OF_RULE(rule,s),theSonType, |
| 5175 |
ElementNodes,theElement,1); |
| 5176 |
if (theSon==NULL) RETURN(GM_ERROR); |
| 5177 |
|
| 5178 |
/* fill in son data */ |
| 5179 |
SonList[s] = theSon; |
| 5180 |
SETECLASS(theSon,MARKCLASS(theElement)); |
| 5181 |
} |
| 5182 |
|
| 5183 |
/* connect elements */ |
| 5184 |
for (INT s=0; s<NSONS_OF_RULE(rule); s++) |
| 5185 |
{ |
| 5186 |
SONDATA const* sdata = SON_OF_RULE(rule,s); |
| 5187 |
for (INT i=0; i<SIDES_OF_ELEM(SonList[s]); i++) |
| 5188 |
{ |
| 5189 |
SET_NBELEM(SonList[s],i,NULL); |
| 5190 |
|
| 5191 |
const INT side = SON_NB(sdata,i); |
| 5192 |
/* an interior face */ |
| 5193 |
if (side < FATHER_SIDE_OFFSET) |
| 5194 |
{ |
| 5195 |
SET_NBELEM(SonList[s],i,SonList[side]); |
| 5196 |
|
| 5197 |
IFDEBUG(gm,3) |
| 5198 |
UserWriteF("elid=%3d: side:",ID(SonList[s])); |
| 5199 |
for (INT p=0; p<CORNERS_OF_SIDE(SonList[s],i); p++) |
| 5200 |
UserWriteF(" %2d",ID(CORNER_OF_SIDE_PTR(SonList[s],i,p))); |
| 5201 |
UserWriteF(" INSIDE of father"); |
| 5202 |
UserWriteF("\nnbid=%3d: side:",ID(SonList[side])); |
| 5203 |
{ |
| 5204 |
int ss,qq,pp,f,pts; |
| 5205 |
f=0; |
| 5206 |
for (ss=0; ss<SIDES_OF_ELEM(SonList[side]); ss++) |
| 5207 |
{ |
| 5208 |
pts = 0; |
| 5209 |
for (pp=0; pp<CORNERS_OF_SIDE(SonList[s],i); pp++) |
| 5210 |
for (qq=0; qq<CORNERS_OF_SIDE(SonList[side],ss); qq++) |
| 5211 |
if (CORNER_OF_SIDE_PTR(SonList[s],i,pp) == |
| 5212 |
CORNER_OF_SIDE_PTR(SonList[side],ss,qq)) |
| 5213 |
{ |
| 5214 |
pts |= ((1<<pp) | (16<<qq)); |
| 5215 |
break; |
| 5216 |
} |
| 5217 |
switch (pts) |
| 5218 |
{ |
| 5219 |
#ifdef UG_DIM_2 |
| 5220 |
case (LINEPOINTS) : |
| 5221 |
#endif |
| 5222 |
#ifdef UG_DIM_3 |
| 5223 |
case (TRIPOINTS) : |
| 5224 |
case (QUADPOINTS) : |
| 5225 |
#endif |
| 5226 |
if (pts==TRIPOINTS && |
| 5227 |
CORNERS_OF_SIDE(SonList[s],i)==4) |
| 5228 |
{ |
| 5229 |
PrintErrorMessage('E',"RefineElement", |
| 5230 |
"quad side with 3 equal nodes"); |
| 5231 |
RETURN(GM_FATAL); |
| 5232 |
} |
| 5233 |
f=1; |
| 5234 |
break; |
| 5235 |
default : |
| 5236 |
break; |
| 5237 |
} |
| 5238 |
if (f) break; |
| 5239 |
} |
| 5240 |
ASSERT(f==1); |
| 5241 |
for (pp=0; pp<CORNERS_OF_SIDE(SonList[side],ss); pp++) |
| 5242 |
UserWriteF(" %2d",ID(CORNER_OF_SIDE_PTR(SonList[side],ss,pp))); |
| 5243 |
} |
| 5244 |
UserWriteF("\n\n"); |
| 5245 |
ENDDEBUG |
| 5246 |
|
| 5247 |
ASSERT(SonList[side]!=NULL); |
| 5248 |
|
| 5249 |
/* dispose doubled side vectors if */ |
| 5250 |
#ifdef UG_DIM_3 |
| 5251 |
if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC)) |
| 5252 |
{ |
| 5253 |
INT l; |
| 5254 |
for (l=0; l<SIDES_OF_ELEM(SonList[side]); l++) |
| 5255 |
if (NBELEM(SonList[side],l)==SonList[s]) |
| 5256 |
break; |
| 5257 |
|
| 5258 |
if (l<SIDES_OF_ELEM(SonList[side])) |
| 5259 |
{ |
| 5260 |
/* assert consistency of rule set */ |
| 5261 |
ASSERT(SON_NB_OF_RULE(rule,side,l)==s); |
| 5262 |
ASSERT(SON_NB_OF_RULE(rule,s,i)==side); |
| 5263 |
ASSERT(NBELEM(SonList[s],i)==SonList[side] |
| 5264 |
&& NBELEM(SonList[side],l)==SonList[s]); |
| 5265 |
if (DisposeDoubledSideVector(theGrid,SonList[s],i, |
| 5266 |
SonList[side],l)) RETURN(GM_FATAL); |
| 5267 |
} |
| 5268 |
} |
| 5269 |
#endif |
| 5270 |
continue; |
| 5271 |
} |
| 5272 |
} |
| 5273 |
} |
| 5274 |
|
| 5275 |
IFDEBUG(gm,2) |
| 5276 |
UserWriteF(PFMT "CONNECTING elem=" EID_FMTX "\n",me,EID_PRTX(theElement)); |
| 5277 |
ENDDEBUG |
| 5278 |
for (INT i=0; i<SIDES_OF_ELEM(theElement); i++) |
| 5279 |
{ |
| 5280 |
INT Sons_of_Side; |
| 5281 |
ELEMENT *Sons_of_Side_List[MAX_SONS]; |
| 5282 |
INT SonSides[MAX_SIDE_NODES]; |
| 5283 |
|
| 5284 |
IFDEBUG(gm,2) |
| 5285 |
UserWriteF(PFMT " CONNECT side=%i of elem=" EID_FMTX "\n",me,i,EID_PRTX(theElement)); |
| 5286 |
ENDDEBUG |
| 5287 |
|
| 5288 |
for (INT j=0; j<MAX_SONS; j++) |
| 5289 |
Sons_of_Side_List[j] = NULL; |
| 5290 |
|
| 5291 |
for (INT j=0; j<NSONS_OF_RULE(rule); j++) |
| 5292 |
Sons_of_Side_List[j] = SonList[j]; |
| 5293 |
|
| 5294 |
if (Get_Sons_of_ElementSide(theElement,i,&Sons_of_Side, |
| 5295 |
Sons_of_Side_List,SonSides,0,0)!=GM_OK) RETURN(GM_FATAL); |
| 5296 |
|
| 5297 |
if (Connect_Sons_of_ElementSide(theGrid,theElement,i,Sons_of_Side, |
| 5298 |
Sons_of_Side_List,SonSides,0)!=GM_OK) RETURN(GM_FATAL); |
| 5299 |
|
| 5300 |
#ifdef ModelP |
| 5301 |
if (Identify_Objects_of_ElementSide(theGrid,theElement,i)) RETURN(GM_FATAL); |
| 5302 |
#endif |
| 5303 |
} |
| 5304 |
|
| 5305 |
return(GM_OK); |
| 5306 |
} |
| 5307 |
|
| 5308 |
|
| 5309 |
/****************************************************************************/ |
| 5310 |
/* |
| 5311 |
- refine an element |
| 5312 |
|
| 5313 |
SYNOPSIS: |
| 5314 |
static INT RefineElement (GRID *UpGrid, ELEMENT *theElement,NODE** theNodeContext); |
| 5315 |
|
| 5316 |
PARAMETERS: |
| 5317 |
\param UpGrid - grid level to refine |
| 5318 |
\param theElement - element to refine |
| 5319 |
\param theNodeContext - nodecontext for refinement |
| 5320 |
|
| 5321 |
DESCRIPTION: |
| 5322 |
This function refines an element |
| 5323 |
\return <ul> |
| 5324 |
INT |
| 5325 |
.n GM_OK - ok |
| 5326 |
.n GM_FATAL - fatal memory error |
| 5327 |
*/ |
| 5328 |
/****************************************************************************/ |
| 5329 |
|
| 5330 |
static INT RefineElement (GRID *UpGrid, ELEMENT *theElement,NODE** theNodeContext) |
| 5331 |
{ |
| 5332 |
switch (MARKCLASS(theElement)) |
| 5333 |
{ |
| 5334 |
case (YELLOW_CLASS) : |
| 5335 |
if (RefineElementYellow(UpGrid,theElement,theNodeContext)!=GM_OK) |
| 5336 |
RETURN(GM_FATAL); |
| 5337 |
break; |
| 5338 |
|
| 5339 |
case (GREEN_CLASS) : |
| 5340 |
#ifdef __ANISOTROPIC__ |
| 5341 |
case (RED_CLASS) : |
| 5342 |
#endif |
| 5343 |
if (MARKED_NEW_GREEN(theElement)) |
| 5344 |
{ |
| 5345 |
/* elements with incomplete rules set */ |
| 5346 |
if (RefineElementGreen(UpGrid,theElement,theNodeContext) != GM_OK) |
| 5347 |
RETURN(GM_FATAL); |
| 5348 |
} |
| 5349 |
else |
| 5350 |
{ |
| 5351 |
/* elements with complete rules set */ |
| 5352 |
if (RefineElementRed(UpGrid,theElement,theNodeContext)!=GM_OK) |
| 5353 |
RETURN(GM_FATAL); |
| 5354 |
} |
| 5355 |
break; |
| 5356 |
|
| 5357 |
#ifndef __ANISOTROPIC__ |
| 5358 |
case (RED_CLASS) : |
| 5359 |
if (RefineElementRed(UpGrid,theElement,theNodeContext)!=GM_OK) |
| 5360 |
RETURN(GM_FATAL); |
| 5361 |
break; |
| 5362 |
#endif |
| 5363 |
|
| 5364 |
default : |
| 5365 |
RETURN(GM_FATAL); |
| 5366 |
} |
| 5367 |
|
| 5368 |
return(GM_OK); |
| 5369 |
} |
| 5370 |
|
| 5371 |
|
| 5372 |
/****************************************************************************/ |
| 5373 |
/* |
| 5374 |
AdaptGrid - adapt one level of the multigrid |
| 5375 |
|
| 5376 |
SYNOPSIS: |
| 5377 |
static int AdaptGrid (GRID *theGrid, INT *nadapted) |
| 5378 |
|
| 5379 |
PARAMETERS: |
| 5380 |
\param theGrid - grid level to refine |
| 5381 |
\param nadapted - number elements have been changed |
| 5382 |
|
| 5383 |
DESCRIPTION: |
| 5384 |
This function refines one level of the grid |
| 5385 |
|
| 5386 |
\return <ul> |
| 5387 |
INT |
| 5388 |
.n GM_OK - ok |
| 5389 |
.n GM_FATAL - fatal memory error |
| 5390 |
*/ |
| 5391 |
/****************************************************************************/ |
| 5392 |
|
| 5393 |
#ifdef ModelP |
| 5394 |
static int AdaptLocalGrid (GRID *theGrid, INT *nadapted) |
| 5395 |
#else |
| 5396 |
static int AdaptGrid (GRID *theGrid, INT *nadapted) |
| 5397 |
#endif |
| 5398 |
{ |
| 5399 |
INT modified = 0; |
| 5400 |
ELEMENT *NextElement; |
| 5401 |
#ifdef ModelP |
| 5402 |
const int me = theGrid->ppifContext().me(); |
| 5403 |
auto& dddContext = theGrid->dddContext(); |
| 5404 |
#endif |
| 5405 |
|
| 5406 |
GRID *UpGrid = UPGRID(theGrid); |
| 5407 |
if (UpGrid == nullptr) |
| 5408 |
RETURN(GM_FATAL); |
| 5409 |
|
| 5410 |
REFINE_GRID_LIST(1,MYMG(theGrid),GLEVEL(theGrid),("AdaptGrid(%d):\n",GLEVEL(theGrid)),""); |
| 5411 |
|
| 5412 |
#ifdef IDENT_ONLY_NEW |
| 5413 |
/* reset ident flags for old objects */ |
| 5414 |
for (NODE *theNode = PFIRSTNODE(UpGrid); theNode != nullptr; theNode = SUCCN(theNode)) |
| 5415 |
SETNEW_NIDENT(theNode, 0); |
| 5416 |
|
| 5417 |
for (ELEMENT* theElement = PFIRSTELEMENT(UpGrid); theElement != nullptr; theElement = SUCCE(theElement)) |
| 5418 |
{ |
| 5419 |
for (INT i = 0; i < EDGES_OF_ELEM(theElement); i++) |
| 5420 |
{ |
| 5421 |
EDGE *theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement, i, 0), |
| 5422 |
CORNER_OF_EDGE_PTR(theElement, i, 1)); |
| 5423 |
SETNEW_EDIDENT(theEdge, 0); |
| 5424 |
} |
| 5425 |
} |
| 5426 |
#endif |
| 5427 |
|
| 5428 |
/* refine elements */ |
| 5429 |
/* ModelP: first loop over master elems, then loop over ghost elems */ |
| 5430 |
/* this assures that no unnecessary disposures of objects are done */ |
| 5431 |
/* which may cause trouble during identification (s.l. 9803020 */ |
| 5432 |
for (ELEMENT *theElement = FIRSTELEMENT(theGrid); theElement != nullptr; |
| 5433 |
theElement=NextElement) |
| 5434 |
{ |
| 5435 |
NextElement = SUCCE(theElement); |
| 5436 |
#ifdef ModelP |
| 5437 |
/* loop over master elems first, then over ghost elems */ |
| 5438 |
if (NextElement == NULL) NextElement=PFIRSTELEMENT(theGrid); |
| 5439 |
if (NextElement == FIRSTELEMENT(theGrid)) NextElement = NULL; |
| 5440 |
#endif |
| 5441 |
|
| 5442 |
#ifdef ModelP |
| 5443 |
/* reset update overlap flag */ |
| 5444 |
SETTHEFLAG(theElement,0); |
| 5445 |
#endif |
| 5446 |
|
| 5447 |
/* do not change PrioVGhost elements */ |
| 5448 |
if (EVGHOST(theElement)) continue; |
| 5449 |
|
| 5450 |
if (REFINEMENT_CHANGES(theElement)) |
| 5451 |
{ |
| 5452 |
#ifdef ModelP |
| 5453 |
{ |
| 5454 |
/* check for valid load balancing */ |
| 5455 |
const auto& proclist = DDD_InfoProcListRange(dddContext, PARHDRE(theElement), false); |
| 5456 |
for (auto&& [proc, prio] : proclist) |
| 5457 |
{ |
| 5458 |
if (prio != PrioMaster && prio != PrioHGhost) |
| 5459 |
{ |
| 5460 |
UserWriteF(PFMT "ERROR invalid load balancing: element=" |
| 5461 |
EID_FMTX " has copies of type=%d on proc=%d\n", |
| 5462 |
me, EID_PRTX(theElement), prio, proc); |
| 5463 |
REFINE_ELEMENT_LIST(0,theElement,"ERROR element: "); |
| 5464 |
assert(0); |
| 5465 |
} |
| 5466 |
} |
| 5467 |
} |
| 5468 |
#endif |
| 5469 |
|
| 5470 |
if (hFlag==0 && MARKCLASS(theElement)!=RED_CLASS) |
| 5471 |
{ |
| 5472 |
/* remove copy marks */ |
| 5473 |
SETMARK(theElement,NO_REFINEMENT); |
| 5474 |
SETMARKCLASS(theElement,NO_CLASS); |
| 5475 |
/* continue; */ |
| 5476 |
} |
| 5477 |
|
| 5478 |
REFINE_ELEMENT_LIST(1,theElement,"REFINING element: "); |
| 5479 |
|
| 5480 |
if (UnrefineElement(UpGrid,theElement)) |
| 5481 |
RETURN(GM_FATAL); |
| 5482 |
|
| 5483 |
#ifdef ModelP |
| 5484 |
/* dispose hghost elements with EFATHER==NULL */ |
| 5485 |
/** \todo how handle this situation? */ |
| 5486 |
/* situation possibly some elements to be coarsened are */ |
| 5487 |
/* disconnected from their fathers (970109 s.l.) */ |
| 5488 |
if (0) |
| 5489 |
if (EHGHOST(theElement) && COARSEN(theElement)) |
| 5490 |
{ |
| 5491 |
if (LEVEL(theElement)>0 && EFATHER(theElement)==NULL) |
| 5492 |
{ |
| 5493 |
DisposeElement(theGrid,theElement); |
| 5494 |
continue; |
| 5495 |
} |
| 5496 |
} |
| 5497 |
#endif |
| 5498 |
|
| 5499 |
if (EMASTER(theElement)) |
| 5500 |
{ |
| 5501 |
ELEMENTCONTEXT theContext; |
| 5502 |
if (UpdateContext(UpGrid,theElement,theContext)!=0) |
| 5503 |
RETURN(GM_FATAL); |
| 5504 |
|
| 5505 |
REFINE_CONTEXT_LIST(2,theContext); |
| 5506 |
|
| 5507 |
#ifdef Debug |
| 5508 |
CheckElementContextConsistency(theElement,theContext); |
| 5509 |
#endif |
| 5510 |
|
| 5511 |
/* is something to do ? */ |
| 5512 |
if (MARKED(theElement)) |
| 5513 |
if (RefineElement(UpGrid,theElement,theContext)) |
| 5514 |
RETURN(GM_FATAL); |
| 5515 |
} |
| 5516 |
|
| 5517 |
/* refine and refineclass flag */ |
| 5518 |
SETREFINE(theElement,MARK(theElement)); |
| 5519 |
SETREFINECLASS(theElement,MARKCLASS(theElement)); |
| 5520 |
SETUSED(theElement,0); |
| 5521 |
|
| 5522 |
#ifdef ModelP |
| 5523 |
/* set update overlap flag */ |
| 5524 |
SETTHEFLAG(theElement,1); |
| 5525 |
#endif |
| 5526 |
|
| 5527 |
/* this grid is modified */ |
| 5528 |
modified++; |
| 5529 |
} |
| 5530 |
else |
| 5531 |
{ |
| 5532 |
#ifdef ModelP |
| 5533 |
/* dispose hghost elements with EFATHER==NULL */ |
| 5534 |
/** \todo how handle this situation? */ |
| 5535 |
/* situation possibly some elements to be coarsened are */ |
| 5536 |
/* disconnected from their fathers (970109 s.l.) */ |
| 5537 |
if (0) |
| 5538 |
if (EHGHOST(theElement) && COARSEN(theElement)) |
| 5539 |
{ |
| 5540 |
if (LEVEL(theElement)>0 && EFATHER(theElement)==NULL) |
| 5541 |
{ |
| 5542 |
DisposeElement(theGrid,theElement); |
| 5543 |
continue; |
| 5544 |
} |
| 5545 |
} |
| 5546 |
#endif |
| 5547 |
|
| 5548 |
#ifdef __ANISOTROPIC__ |
| 5549 |
if (USED(theElement)==0 && MARKCLASS(theElement)==GREEN_CLASS) |
| 5550 |
#else |
| 5551 |
if (USED(theElement)==0) |
| 5552 |
#endif |
| 5553 |
{ |
| 5554 |
/* count not updated green refinements */ |
| 5555 |
No_Green_Update++; |
| 5556 |
} |
| 5557 |
} |
| 5558 |
|
| 5559 |
/* count green marks */ |
| 5560 |
if (MARKCLASS(theElement) == GREEN_CLASS) Green_Marks++; |
| 5561 |
|
| 5562 |
/* reset coarse flag */ |
| 5563 |
SETCOARSEN(theElement,0); |
| 5564 |
} |
| 5565 |
|
| 5566 |
if (UG_GlobalMaxINT(theGrid->ppifContext(), modified)) |
| 5567 |
{ |
| 5568 |
/* reset (multi)grid status */ |
| 5569 |
SETGLOBALGSTATUS(UpGrid); |
| 5570 |
RESETMGSTATUS(MYMG(UpGrid)); |
| 5571 |
} |
| 5572 |
REFINE_GRID_LIST(1,MYMG(theGrid),GLEVEL(theGrid), |
| 5573 |
("END AdaptGrid(%d):\n",GLEVEL(theGrid)),""); |
| 5574 |
|
| 5575 |
*nadapted = modified; |
| 5576 |
|
| 5577 |
return(GM_OK); |
| 5578 |
} |
| 5579 |
|
| 5580 |
#ifdef ModelP |
| 5581 |
static int AdaptGrid (GRID *theGrid, INT toplevel, INT level, INT newlevel, INT *nadapted) |
| 5582 |
{ |
| 5583 |
GRID *FinerGrid = UPGRID(theGrid); |
| 5584 |
|
| 5585 |
START_TIMER(gridadapti_timer) |
| 5586 |
|
| 5587 |
#ifdef UPDATE_FULLOVERLAP |
| 5588 |
DDD_XferBegin(theGrid->dddContext()); |
| 5589 |
{ |
| 5590 |
for (ELEMENT *theElement = PFIRSTELEMENT(FinerGrid); |
| 5591 |
theElement != nullptr; |
| 5592 |
theElement=SUCCE(theElement)) |
| 5593 |
{ |
| 5594 |
if (EPRIO(theElement) == PrioHGhost) DisposeElement(FinerGrid,theElement,true); |
| 5595 |
} |
| 5596 |
} |
| 5597 |
DDD_XferEnd(theGrid->dddContext()); |
| 5598 |
#endif |
| 5599 |
|
| 5600 |
DDD_IdentifyBegin(theGrid->dddContext()); |
| 5601 |
SET_IDENT_MODE(IDENT_ON); |
| 5602 |
DDD_XferBegin(theGrid->dddContext()); |
| 5603 |
|
| 5604 |
DDD_CONSCHECK(theGrid->dddContext()); |
| 5605 |
|
| 5606 |
/* now really manipulate the next finer level */ |
| 5607 |
START_TIMER(gridadaptl_timer) |
| 5608 |
|
| 5609 |
#ifdef DDDOBJMGR |
| 5610 |
DDD_ObjMgrBegin(); |
| 5611 |
#endif |
| 5612 |
if (level<toplevel || newlevel) |
| 5613 |
if (AdaptLocalGrid(theGrid,nadapted)!=GM_OK) |
| 5614 |
RETURN(GM_FATAL); |
| 5615 |
#ifdef DDDOBJMGR |
| 5616 |
DDD_ObjMgrEnd(); |
| 5617 |
#endif |
| 5618 |
|
| 5619 |
DDD_XferEnd(theGrid->dddContext()); |
| 5620 |
|
| 5621 |
SUM_TIMER(gridadaptl_timer) |
| 5622 |
|
| 5623 |
DDD_CONSCHECK(theGrid->dddContext()); |
| 5624 |
|
| 5625 |
{ |
| 5626 |
int check=1; |
| 5627 |
int debugstart=3; |
| 5628 |
#ifdef Debug |
| 5629 |
int gmlevel=Debuggm; |
| 5630 |
#else |
| 5631 |
int gmlevel=0; |
| 5632 |
#endif |
| 5633 |
|
| 5634 |
|
| 5635 |
if (IDENT_IN_STEPS) |
| 5636 |
{ |
| 5637 |
DDD_IdentifyEnd(theGrid->dddContext()); |
| 5638 |
} |
| 5639 |
|
| 5640 |
/* if no grid adaption has occurred adapt next level */ |
| 5641 |
*nadapted = UG_GlobalSumINT(theGrid->ppifContext(), *nadapted); |
| 5642 |
if (*nadapted == 0) |
| 5643 |
{ |
| 5644 |
if (!IDENT_IN_STEPS) |
| 5645 |
{ |
| 5646 |
SET_IDENT_MODE(IDENT_OFF); |
| 5647 |
DDD_IdentifyEnd(theGrid->dddContext()); |
| 5648 |
} |
| 5649 |
|
| 5650 |
SUM_TIMER(gridadapti_timer) |
| 5651 |
|
| 5652 |
return(GM_OK); |
| 5653 |
} |
| 5654 |
|
| 5655 |
/* DDD_JoinBegin(); */ |
| 5656 |
if (IDENT_IN_STEPS) |
| 5657 |
DDD_IdentifyBegin(theGrid->dddContext()); |
| 5658 |
|
| 5659 |
DDD_CONSCHECK(theGrid->dddContext()); |
| 5660 |
|
| 5661 |
START_TIMER(ident_timer) |
| 5662 |
|
| 5663 |
if (Identify_SonObjects(theGrid)) RETURN(GM_FATAL); |
| 5664 |
|
| 5665 |
SET_IDENT_MODE(IDENT_OFF); |
| 5666 |
DDD_IdentifyEnd(theGrid->dddContext()); |
| 5667 |
|
| 5668 |
SUM_TIMER(ident_timer) |
| 5669 |
/* DDD_JoinEnd(); */ |
| 5670 |
|
| 5671 |
|
| 5672 |
DDD_CONSCHECK(theGrid->dddContext()); |
| 5673 |
|
| 5674 |
if (level<toplevel || newlevel) |
| 5675 |
{ |
| 5676 |
START_TIMER(overlap_timer) |
| 5677 |
DDD_XferBegin(theGrid->dddContext()); |
| 5678 |
if (0) /* delete sine this is already done in */ |
| 5679 |
/* ConstructConsistentGrid() (s.l. 980522) */ |
| 5680 |
if (SetGridBorderPriorities(theGrid)) RETURN(GM_FATAL); |
| 5681 |
if (UpdateGridOverlap(theGrid)) RETURN(GM_FATAL); |
| 5682 |
|
| 5683 |
|
| 5684 |
DDD_XferEnd(theGrid->dddContext()); |
| 5685 |
|
| 5686 |
DDD_CONSCHECK(theGrid->dddContext()); |
| 5687 |
|
| 5688 |
DDD_XferBegin(theGrid->dddContext()); |
| 5689 |
if (ConnectGridOverlap(theGrid)) RETURN(GM_FATAL); |
| 5690 |
DDD_XferEnd(theGrid->dddContext()); |
| 5691 |
|
| 5692 |
DDD_CONSCHECK(theGrid->dddContext()); |
| 5693 |
|
| 5694 |
/* this is needed due to special cases while coarsening */ |
| 5695 |
/* sample scene: a ghost element is needed as overlap */ |
| 5696 |
/* for two master elements, one of the master elements */ |
| 5697 |
/* is coarsened, then the prio of nodes of the ghost */ |
| 5698 |
/* element must eventually be downgraded from master */ |
| 5699 |
/* to ghost prio (s.l. 971020) */ |
| 5700 |
/* this is done as postprocessing step, since this needs */ |
| 5701 |
/* 2 XferBegin/Ends here per modified gridlevel (s.l. 980522) */ |
| 5702 |
/* |
| 5703 |
#ifndef NEW_GRIDCONS_STYLE |
| 5704 |
ConstructConsistentGrid(FinerGrid); |
| 5705 |
#endif |
| 5706 |
*/ |
| 5707 |
SUM_TIMER(overlap_timer) |
| 5708 |
} |
| 5709 |
|
| 5710 |
DDD_CONSCHECK(theGrid->dddContext()); |
| 5711 |
|
| 5712 |
|
| 5713 |
CheckConsistency(MYMG(theGrid),(INT)level,(INT)debugstart,(INT)gmlevel,&check); |
| 5714 |
|
| 5715 |
|
| 5716 |
} |
| 5717 |
|
| 5718 |
if (0) CheckGrid(FinerGrid,1,0,1,1); |
| 5719 |
|
| 5720 |
SUM_TIMER(gridadapti_timer) |
| 5721 |
|
| 5722 |
return(GM_OK); |
| 5723 |
} |
| 5724 |
#endif |
| 5725 |
|
| 5726 |
|
| 5727 |
#ifdef ModelP |
| 5728 |
/* parameters for CheckGrid() */ |
| 5729 |
#define GHOSTS 1 |
| 5730 |
#define GEOM 1 |
| 5731 |
#define ALG 0 |
| 5732 |
#define LIST 1 |
| 5733 |
#define IF 1 |
| 5734 |
|
| 5735 |
|
| 5736 |
/****************************************************************************/ |
| 5737 |
/* |
| 5738 |
CheckConsistency - |
| 5739 |
|
| 5740 |
SYNOPSIS: |
| 5741 |
void CheckConsistency (MULTIGRID *theMG, INT level ,INT debugstart, INT gmlevel, INT *check); |
| 5742 |
|
| 5743 |
PARAMETERS: |
| 5744 |
. theMG |
| 5745 |
. level |
| 5746 |
. debugstart |
| 5747 |
. gmlevel |
| 5748 |
. check |
| 5749 |
|
| 5750 |
*/ |
| 5751 |
/****************************************************************************/ |
| 5752 |
|
| 5753 |
static void CheckConsistency (MULTIGRID *theMG, INT level ,INT debugstart, INT gmlevel, int *check) |
| 5754 |
{ |
| 5755 |
GRID *theGrid = GRID_ON_LEVEL(theMG,level); |
| 5756 |
|
| 5757 |
IFDEBUG(gm,debugstart) |
| 5758 |
printf(PFMT "AdaptMultiGrid(): %d. ConsCheck() on level=%d\n",theMG->ppifContext().me(),(*check)++,level); |
| 5759 |
#ifdef Debug |
| 5760 |
Debuggm = GHOSTS; |
| 5761 |
#endif |
| 5762 |
CheckGrid(theGrid,GEOM,ALG,LIST,IF); |
| 5763 |
#ifdef Debug |
| 5764 |
Debuggm=gmlevel; |
| 5765 |
#endif |
| 5766 |
if (DDD_ConsCheck(theMG->dddContext()) > 0) buggy(theMG); |
| 5767 |
ENDDEBUG |
| 5768 |
} |
| 5769 |
#endif |
| 5770 |
|
| 5771 |
|
| 5772 |
#ifdef STAT_OUT |
| 5773 |
void NS_DIM_PREFIX Manage_Adapt_Timer (int alloc) |
| 5774 |
{ |
| 5775 |
if (alloc) |
| 5776 |
{ |
| 5777 |
NEW_TIMER(adapt_timer) |
| 5778 |
NEW_TIMER(closure_timer) |
| 5779 |
NEW_TIMER(gridadapt_timer) |
| 5780 |
NEW_TIMER(gridadapti_timer) |
| 5781 |
NEW_TIMER(gridadaptl_timer) |
| 5782 |
NEW_TIMER(ident_timer) |
| 5783 |
NEW_TIMER(overlap_timer) |
| 5784 |
NEW_TIMER(gridcons_timer) |
| 5785 |
NEW_TIMER(algebra_timer) |
| 5786 |
} |
| 5787 |
else |
| 5788 |
{ |
| 5789 |
DEL_TIMER(adapt_timer) |
| 5790 |
DEL_TIMER(closure_timer) |
| 5791 |
DEL_TIMER(gridadapt_timer) |
| 5792 |
DEL_TIMER(gridadapti_timer) |
| 5793 |
DEL_TIMER(gridadaptl_timer) |
| 5794 |
DEL_TIMER(ident_timer) |
| 5795 |
DEL_TIMER(overlap_timer) |
| 5796 |
DEL_TIMER(gridcons_timer) |
| 5797 |
DEL_TIMER(algebra_timer) |
| 5798 |
} |
| 5799 |
} |
| 5800 |
|
| 5801 |
void NS_DIM_PREFIX Print_Adapt_Timer (const MULTIGRID* theMG, int total_adapted) |
| 5802 |
{ |
| 5803 |
UserWriteF("ADAPT: total_adapted=%d t_adapt=%.2f: t_closure=%.2f t_gridadapt=%.2f t_gridadapti=%.2f " |
| 5804 |
"t_gridadaptl=%.2f t_overlap=%.2f t_ident=%.2f t_gridcons=%.2f t_algebra=%.2f\n", |
| 5805 |
total_adapted,EVAL_TIMER(adapt_timer),EVAL_TIMER(closure_timer),EVAL_TIMER(gridadapt_timer), |
| 5806 |
EVAL_TIMER(gridadapti_timer),EVAL_TIMER(gridadaptl_timer),EVAL_TIMER(overlap_timer), |
| 5807 |
EVAL_TIMER(ident_timer),EVAL_TIMER(gridcons_timer),EVAL_TIMER(algebra_timer)); |
| 5808 |
UserWriteF("ADAPTMAX: total_adapted=%d t_adapt=%.2f: t_closure=%.2f t_gridadapt=%.2f " |
| 5809 |
"t_gridadapti=%.2f " |
| 5810 |
"t_gridadaptl=%.2f t_overlap=%.2f t_ident=%.2f t_gridcons=%.2f t_algebra=%.2f\n", |
| 5811 |
total_adapted,UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(adapt_timer)), |
| 5812 |
UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(closure_timer)), |
| 5813 |
UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridadapt_timer)),UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridadapti_timer)), |
| 5814 |
UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridadaptl_timer)), |
| 5815 |
UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(overlap_timer)), |
| 5816 |
UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(ident_timer)),UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(gridcons_timer)), |
| 5817 |
UG_GlobalMaxDOUBLE(theMG->ppifContext(), EVAL_TIMER(algebra_timer))); |
| 5818 |
} |
| 5819 |
#endif |
| 5820 |
|
| 5821 |
static INT PreProcessAdaptMultiGrid(MULTIGRID *theMG) |
| 5822 |
{ |
| 5823 |
/* The matrices for the calculation are removed, to remember the |
| 5824 |
recalculating the MGSTATUS is set to 1 */ |
| 5825 |
|
| 5826 |
MGSTATUS(theMG) = 1 ; |
| 5827 |
|
| 5828 |
return(0); |
| 5829 |
} |
| 5830 |
|
| 5831 |
static INT PostProcessAdaptMultiGrid(MULTIGRID *theMG) |
| 5832 |
{ |
| 5833 |
START_TIMER(algebra_timer) |
| 5834 |
if (CreateAlgebra(theMG)) REP_ERR_RETURN(1); |
| 5835 |
SUM_TIMER(algebra_timer) |
| 5836 |
|
| 5837 |
REFINE_MULTIGRID_LIST(1,theMG,"END AdaptMultiGrid():\n","",""); |
| 5838 |
|
| 5839 |
/* |
| 5840 |
if (hFlag) |
| 5841 |
UserWriteF(" Number of green refinements not updated: " |
| 5842 |
"%d (%d green marks)\n",No_Green_Update,Green_Marks); |
| 5843 |
*/ |
| 5844 |
|
| 5845 |
/* increment step count */ |
| 5846 |
SETREFINESTEP(REFINEINFO(theMG),REFINESTEP(REFINEINFO(theMG))+1); |
| 5847 |
|
| 5848 |
SUM_TIMER(adapt_timer) |
| 5849 |
/* |
| 5850 |
CheckMultiGrid(theMG); |
| 5851 |
*/ |
| 5852 |
|
| 5853 |
#ifdef STAT_OUT |
| 5854 |
Print_Adapt_Timer(theMG, total_adapted); |
| 5855 |
Manage_Adapt_Timer(0); |
| 5856 |
#endif |
| 5857 |
|
| 5858 |
return(0); |
| 5859 |
} |
| 5860 |
|
| 5861 |
/****************************************************************************/ |
| 5862 |
/** \brief Adapt whole multigrid structure |
| 5863 |
|
| 5864 |
\param theMG - multigrid to refine |
| 5865 |
\param flag - flag for switching between different yellow closures |
| 5866 |
|
| 5867 |
This function refines whole multigrid structure |
| 5868 |
|
| 5869 |
\return <ul> |
| 5870 |
<li> 0 - ok |
| 5871 |
<li> 1 - out of memory, but data structure as before |
| 5872 |
<li> 2 - fatal memory error, data structure corrupted |
| 5873 |
</ul> |
| 5874 |
*/ |
| 5875 |
/****************************************************************************/ |
| 5876 |
|
| 5877 |
INT NS_DIM_PREFIX AdaptMultiGrid (MULTIGRID *theMG, INT flag, INT seq, INT mgtest) |
| 5878 |
{ |
| 5879 |
INT nrefined,nadapted; |
| 5880 |
|
| 5881 |
/* check necessary condition */ |
| 5882 |
if (!MG_COARSE_FIXED(theMG)) |
| 5883 |
return (GM_COARSE_NOT_FIXED); |
| 5884 |
|
| 5885 |
if (PreProcessAdaptMultiGrid(theMG)) REP_ERR_RETURN(1); |
| 5886 |
|
| 5887 |
#ifdef ModelP |
| 5888 |
{ |
| 5889 |
/* check and restrict partitioning of elements */ |
| 5890 |
if (CheckPartitioning(theMG)) |
| 5891 |
{ |
| 5892 |
/* Each call to RestrictPartitioning fixes the partitionings of children with |
| 5893 |
* respect to their fathers. To fix also fix the partitionings of the grandchildren, |
| 5894 |
* the method has to be called again. To be on the save side we call it once for |
| 5895 |
* every level. |
| 5896 |
* If I omit the loop (the way it was until 11.4.2014 I get assertion failures here |
| 5897 |
* when mixing load balancing and adaptive refinement. I am not really sure whether |
| 5898 |
* the loop is the correct fix, or whether it just papers over the problem. |
| 5899 |
* Anyway, no crashes for now. |
| 5900 |
*/ |
| 5901 |
for (int level = 0; level < TOPLEVEL(theMG); level++) |
| 5902 |
if (RestrictPartitioning(theMG)) RETURN(GM_FATAL); |
| 5903 |
if (CheckPartitioning(theMG)) assert(0); |
| 5904 |
} |
| 5905 |
} |
| 5906 |
#endif |
| 5907 |
|
| 5908 |
#ifdef STAT_OUT |
| 5909 |
Manage_Adapt_Timer(1); |
| 5910 |
#endif |
| 5911 |
|
| 5912 |
START_TIMER(adapt_timer) |
| 5913 |
|
| 5914 |
/* set up information in refine_info */ |
| 5915 |
#ifndef ModelP |
| 5916 |
if (TOPLEVEL(theMG) == 0) |
| 5917 |
#else |
| 5918 |
if (UG_GlobalMaxINT(theMG->ppifContext(), TOPLEVEL(theMG)) == 0) |
| 5919 |
#endif |
| 5920 |
{ |
| 5921 |
SETREFINESTEP(REFINEINFO(theMG),0); |
| 5922 |
} |
| 5923 |
|
| 5924 |
/* set info for refinement prediction */ |
| 5925 |
SetRefineInfo(theMG); |
| 5926 |
/* evaluate prediction */ |
| 5927 |
if (mgtest) |
| 5928 |
{ |
| 5929 |
UserWriteF("refinetest: predicted_new0=%9.0f predicted_new1=%9.0f\n", |
| 5930 |
PREDNEW0(REFINEINFO(theMG)), PREDNEW1(REFINEINFO(theMG))); |
| 5931 |
} |
| 5932 |
|
| 5933 |
/* set flags for different modes */ |
| 5934 |
rFlag=flag & 0x03; /* copy local or all */ |
| 5935 |
hFlag=!((flag>>2)&0x1); /* use hanging nodes */ |
| 5936 |
fifoFlag=(flag>>3)&0x1; /* use fifo */ |
| 5937 |
|
| 5938 |
refine_seq = seq; |
| 5939 |
|
| 5940 |
No_Green_Update=0; |
| 5941 |
Green_Marks=0; |
| 5942 |
|
| 5943 |
/* drop marks to regular elements */ |
| 5944 |
if (hFlag) |
| 5945 |
if (DropMarks(theMG)) RETURN(GM_ERROR); |
| 5946 |
|
| 5947 |
/* prepare algebra (set internal flags correctly) */ |
| 5948 |
START_TIMER(algebra_timer) |
| 5949 |
|
| 5950 |
PrepareAlgebraModification(theMG); |
| 5951 |
|
| 5952 |
SUM_TIMER(algebra_timer) |
| 5953 |
|
| 5954 |
const INT toplevel = TOPLEVEL(theMG); |
| 5955 |
|
| 5956 |
REFINE_MULTIGRID_LIST(1,theMG,"AdaptMultiGrid()","","") |
| 5957 |
|
| 5958 |
/* compute modification of coarser levels from above */ |
| 5959 |
START_TIMER(closure_timer) |
| 5960 |
|
| 5961 |
for (INT level = toplevel; level > 0; level--) |
| 5962 |
{ |
| 5963 |
GRID *theGrid = GRID_ON_LEVEL(theMG,level); |
| 5964 |
|
| 5965 |
if (hFlag) |
| 5966 |
{ |
| 5967 |
PRINTDEBUG(gm,1,("Begin GridClosure(%d,down):\n",level)) |
| 5968 |
|
| 5969 |
if ((nrefined = GridClosure(GRID_ON_LEVEL(theMG,level)))<0) |
| 5970 |
{ |
| 5971 |
PrintErrorMessage('E',"AdaptMultiGrid","error in GridClosure"); |
| 5972 |
RETURN(GM_ERROR); |
| 5973 |
} |
| 5974 |
|
| 5975 |
REFINE_GRID_LIST(1,theMG,level,("End GridClosure(%d,down):\n",level),""); |
| 5976 |
} |
| 5977 |
#ifdef ModelP |
| 5978 |
else |
| 5979 |
{ |
| 5980 |
ExchangeElementRefine(theGrid); |
| 5981 |
} |
| 5982 |
#endif |
| 5983 |
|
| 5984 |
/* restrict marks on next lower grid level */ |
| 5985 |
if (RestrictMarks(GRID_ON_LEVEL(theMG,level-1))!=GM_OK) RETURN(GM_ERROR); |
| 5986 |
|
| 5987 |
REFINE_GRID_LIST(1,theMG,level-1,("End RestrictMarks(%d,down):\n",level),""); |
| 5988 |
} |
| 5989 |
|
| 5990 |
SUM_TIMER(closure_timer) |
| 5991 |
|
| 5992 |
|
| 5993 |
#ifdef ModelP |
| 5994 |
IdentifyInit(theMG); |
| 5995 |
#endif |
| 5996 |
|
| 5997 |
INT newlevel = 0; |
| 5998 |
for (INT level = 0; level <= toplevel; level++) |
| 5999 |
{ |
| 6000 |
GRID *theGrid = GRID_ON_LEVEL(theMG,level); |
| 6001 |
GRID *FinerGrid = nullptr; |
| 6002 |
if (level < toplevel) |
| 6003 |
FinerGrid = GRID_ON_LEVEL(theMG,level+1); |
| 6004 |
|
| 6005 |
START_TIMER(closure_timer) |
| 6006 |
|
| 6007 |
/* reset MODIFIED flags for grid and nodes */ |
| 6008 |
SETMODIFIED(theGrid,0); |
| 6009 |
for (NODE *theNode = FIRSTNODE(theGrid); theNode != nullptr; theNode = SUCCN(theNode)) |
| 6010 |
{ |
| 6011 |
SETMODIFIED(theNode,0); |
| 6012 |
} |
| 6013 |
|
| 6014 |
if (hFlag) |
| 6015 |
{ |
| 6016 |
/* leave only regular marks */ |
| 6017 |
for (ELEMENT *theElement = PFIRSTELEMENT(theGrid); theElement != nullptr; theElement = SUCCE(theElement)) |
| 6018 |
{ |
| 6019 |
if ((ECLASS(theElement)==RED_CLASS) && MARKCLASS(theElement)==RED_CLASS) continue; |
| 6020 |
SETMARK(theElement,NO_REFINEMENT); |
| 6021 |
} |
| 6022 |
|
| 6023 |
PRINTDEBUG(gm,1,("Begin GridClosure(%d,up):\n",level)); |
| 6024 |
|
| 6025 |
/* determine regular and irregular elements on next level */ |
| 6026 |
if ((nrefined = GridClosure(theGrid))<0) |
| 6027 |
{ |
| 6028 |
PrintErrorMessage('E',"AdaptMultiGrid","error in 2. GridClosure"); |
| 6029 |
RETURN(GM_ERROR); |
| 6030 |
} |
| 6031 |
|
| 6032 |
REFINE_GRID_LIST(1,theMG,level,("End GridClosure(%d,up):\n",level),""); |
| 6033 |
} |
| 6034 |
#ifdef ModelP |
| 6035 |
else |
| 6036 |
{ |
| 6037 |
ExchangeElementRefine(theGrid); |
| 6038 |
} |
| 6039 |
#endif |
| 6040 |
|
| 6041 |
nrefined += ComputeCopies(theGrid); |
| 6042 |
|
| 6043 |
/** \todo bug fix to force new level creation */ |
| 6044 |
if (!hFlag) |
| 6045 |
{ |
| 6046 |
/* set this variable>0 */ |
| 6047 |
nrefined = 1; |
| 6048 |
} |
| 6049 |
|
| 6050 |
/* create a new grid level, if at least one element is refined on finest level */ |
| 6051 |
if (nrefined>0 && level==toplevel) newlevel = 1; |
| 6052 |
#ifdef ModelP |
| 6053 |
newlevel = UG_GlobalMaxINT(theMG->ppifContext(), newlevel); |
| 6054 |
#endif |
| 6055 |
if (newlevel) |
| 6056 |
{ |
| 6057 |
if (CreateNewLevel(theMG)==NULL) |
| 6058 |
RETURN(GM_FATAL); |
| 6059 |
FinerGrid = GRID_ON_LEVEL(theMG,toplevel+1); |
| 6060 |
} |
| 6061 |
|
| 6062 |
PRINTDEBUG(gm,1,(PFMT "AdaptMultiGrid(): toplevel=%d nrefined=%d newlevel=%d\n", |
| 6063 |
me,toplevel,nrefined,newlevel)); |
| 6064 |
|
| 6065 |
SUM_TIMER(closure_timer) |
| 6066 |
|
| 6067 |
/* now really manipulate the next finer level */ |
| 6068 |
START_TIMER(gridadapt_timer) |
| 6069 |
|
| 6070 |
nadapted = 0; |
| 6071 |
|
| 6072 |
if (level<toplevel || newlevel) |
| 6073 |
#ifndef ModelP |
| 6074 |
if (AdaptGrid(theGrid,&nadapted)!=GM_OK) |
| 6075 |
RETURN(GM_FATAL); |
| 6076 |
#else |
| 6077 |
if (AdaptGrid(theGrid,toplevel,level,newlevel,&nadapted)!=GM_OK) |
| 6078 |
RETURN(GM_FATAL); |
| 6079 |
#endif |
| 6080 |
|
| 6081 |
SUM_TIMER(gridadapt_timer) |
| 6082 |
|
| 6083 |
/* if no grid adaption has occurred adapt next level */ |
| 6084 |
if (nadapted == 0) continue; |
| 6085 |
|
| 6086 |
total_adapted += nadapted; |
| 6087 |
|
| 6088 |
if (level<toplevel || newlevel) |
| 6089 |
{ |
| 6090 |
START_TIMER(algebra_timer) |
| 6091 |
|
| 6092 |
/* and compute the vector classes on the new (or changed) level */ |
| 6093 |
ClearNodeClasses(FinerGrid); |
| 6094 |
|
| 6095 |
for (ELEMENT *theElement = FIRSTELEMENT(FinerGrid); theElement != nullptr; theElement = SUCCE(theElement)) |
| 6096 |
if (ECLASS(theElement)>=GREEN_CLASS || (rFlag==GM_COPY_ALL)) { |
| 6097 |
SeedNodeClasses(theElement); |
| 6098 |
} |
| 6099 |
|
| 6100 |
PropagateNodeClasses(FinerGrid); |
| 6101 |
|
| 6102 |
SUM_TIMER(algebra_timer) |
| 6103 |
} |
| 6104 |
} |
| 6105 |
|
| 6106 |
#ifdef ModelP |
| 6107 |
IdentifyExit(); |
| 6108 |
|
| 6109 |
/* now repair inconsistencies */ |
| 6110 |
/* former done on each grid level (s.l. 980522) */ |
| 6111 |
START_TIMER(gridcons_timer); |
| 6112 |
|
| 6113 |
ConstructConsistentMultiGrid(theMG); |
| 6114 |
|
| 6115 |
SUM_TIMER(gridcons_timer) |
| 6116 |
#endif |
| 6117 |
|
| 6118 |
DisposeTopLevel(theMG); |
| 6119 |
if (TOPLEVEL(theMG) > 0) DisposeTopLevel(theMG); |
| 6120 |
|
| 6121 |
if (PostProcessAdaptMultiGrid(theMG)) REP_ERR_RETURN(1); |
| 6122 |
|
| 6123 |
return(GM_OK); |
| 6124 |
} |