| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
/*! \file std_domain.c |
| 6 |
* \ingroup std |
| 7 |
*/ |
| 8 |
|
| 9 |
/** \addtogroup std |
| 10 |
* |
| 11 |
* @{ |
| 12 |
*/ |
| 13 |
|
| 14 |
/****************************************************************************/ |
| 15 |
/* */ |
| 16 |
/* File: std_domain.c */ |
| 17 |
/* */ |
| 18 |
/* Purpose: standard ug domain description */ |
| 19 |
/* */ |
| 20 |
/* Author: Klaus Johannsen / Christian Wieners */ |
| 21 |
/* Institut fuer Computeranwendungen III */ |
| 22 |
/* Universitaet Stuttgart */ |
| 23 |
/* Pfaffenwaldring 27 */ |
| 24 |
/* 70550 Stuttgart */ |
| 25 |
/* email: [email protected] */ |
| 26 |
/* */ |
| 27 |
/* History: Feb 18 1996 begin, ug version 3.1 */ |
| 28 |
/* Sep 12 1996 ug version 3.4 */ |
| 29 |
/* Apr 9 1998 first step to Marc */ |
| 30 |
/* */ |
| 31 |
/* Remarks: */ |
| 32 |
/* */ |
| 33 |
/****************************************************************************/ |
| 34 |
|
| 35 |
/****************************************************************************/ |
| 36 |
/* */ |
| 37 |
/* include files */ |
| 38 |
/* system include files */ |
| 39 |
/* application include files */ |
| 40 |
/* */ |
| 41 |
/****************************************************************************/ |
| 42 |
|
| 43 |
#include <config.h> |
| 44 |
|
| 45 |
/* standard C library */ |
| 46 |
#include <cstdlib> |
| 47 |
#include <cstddef> |
| 48 |
#include <cstdio> |
| 49 |
#include <cstring> |
| 50 |
#include <cassert> |
| 51 |
#include <cmath> |
| 52 |
|
| 53 |
/* standard C++ library */ |
| 54 |
/* set needed in BVP_Init */ |
| 55 |
#include <set> |
| 56 |
|
| 57 |
#include <dune/common/fvector.hh> |
| 58 |
|
| 59 |
/* low modules */ |
| 60 |
#include <dune/uggrid/low/architecture.h> |
| 61 |
#include <dune/uggrid/low/bio.h> |
| 62 |
#include <dune/uggrid/low/debug.h> |
| 63 |
#include <dune/uggrid/low/fileopen.h> |
| 64 |
#include <dune/uggrid/low/heaps.h> |
| 65 |
#include <dune/uggrid/low/misc.h> |
| 66 |
#include <dune/uggrid/low/namespace.h> |
| 67 |
#include <dune/uggrid/low/ugenv.h> |
| 68 |
#include <dune/uggrid/low/ugtypes.h> |
| 69 |
|
| 70 |
#include <dune/uggrid/gm/evm.h> |
| 71 |
|
| 72 |
/* dev modules */ |
| 73 |
#include <dune/uggrid/ugdevices.h> |
| 74 |
|
| 75 |
/* domain module */ |
| 76 |
#include <dune/uggrid/domain/std_domain.h> |
| 77 |
|
| 78 |
USING_UGDIM_NAMESPACE |
| 79 |
USING_UG_NAMESPACE |
| 80 |
|
| 81 |
#ifdef ModelP |
| 82 |
using namespace PPIF; |
| 83 |
#endif |
| 84 |
|
| 85 |
/****************************************************************************/ |
| 86 |
/* */ |
| 87 |
/* defines in the following order */ |
| 88 |
/* */ |
| 89 |
/* compile time constants defining static data size (i.e. arrays) */ |
| 90 |
/* other constants */ |
| 91 |
/* macros */ |
| 92 |
/* */ |
| 93 |
/****************************************************************************/ |
| 94 |
|
| 95 |
#define SMALL_DIFF SMALL_C*100 |
| 96 |
|
| 97 |
|
| 98 |
/****************************************************************************/ |
| 99 |
/* */ |
| 100 |
/* data structures used in this source file (exported data structures are */ |
| 101 |
/* in the corresponding include file!) */ |
| 102 |
/* */ |
| 103 |
/****************************************************************************/ |
| 104 |
|
| 105 |
/****************************************************************************/ |
| 106 |
/* */ |
| 107 |
/* definition of exported global variables */ |
| 108 |
/* */ |
| 109 |
/****************************************************************************/ |
| 110 |
|
| 111 |
/****************************************************************************/ |
| 112 |
/* */ |
| 113 |
/* definition of variables global to this source file only (static!) */ |
| 114 |
/* */ |
| 115 |
/****************************************************************************/ |
| 116 |
|
| 117 |
static STD_BVP *currBVP; |
| 118 |
|
| 119 |
|
| 120 |
/****************************************************************************/ |
| 121 |
/* Methods for the class 'boundary_segment' */ |
| 122 |
/****************************************************************************/ |
| 123 |
|
| 124 |
boundary_segment::boundary_segment(INT idA, |
| 125 |
const INT* pointsA, |
| 126 |
BndSegFuncPtr bndSegFuncA, |
| 127 |
void *dataA) |
| 128 |
: id(idA), BndSegFunc(bndSegFuncA), data(dataA) |
| 129 |
{ |
| 130 |
for (INT i = 0; i < CORNERS_OF_BND_SEG; i++) |
| 131 |
points[i] = pointsA[i]; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/****************************************************************************/ |
| 136 |
/* Methods for the class 'linear_segment' */ |
| 137 |
/****************************************************************************/ |
| 138 |
|
| 139 |
linear_segment::linear_segment(INT idA, |
| 140 |
INT nA, |
| 141 |
const INT * point, |
| 142 |
const std::array<FieldVector<DOUBLE,DIM>, CORNERS_OF_BND_SEG>& xA) |
| 143 |
: id(idA), n(nA), x(xA) |
| 144 |
{ |
| 145 |
if (n > CORNERS_OF_BND_SEG) |
| 146 |
std::terminate(); |
| 147 |
|
| 148 |
for (int i = 0; i < n; i++) |
| 149 |
points[i] = point[i]; |
| 150 |
} |
| 151 |
|
| 152 |
UINT NS_DIM_PREFIX GetBoundarySegmentId(BNDS* boundarySegment) |
| 153 |
{ |
| 154 |
const BND_PS *ps = (BND_PS*)boundarySegment; |
| 155 |
const PATCH *patch = currBVP->patches[ps->patch_id]; |
| 156 |
if (patch == nullptr) { |
| 157 |
PrintErrorMessageF ('E', "GetBoundarySegmentId", "invalid argument"); |
| 158 |
return 0; |
| 159 |
} |
| 160 |
|
| 161 |
/* The ids in the patch data structure are consecutive but they |
| 162 |
start at currBVP->sideoffset instead of zero. */ |
| 163 |
return PATCH_ID(patch) - currBVP->sideoffset; |
| 164 |
} |
| 165 |
|
| 166 |
static INT |
| 167 |
GetNumberOfPatches (const PATCH * p) |
| 168 |
{ |
| 169 |
switch (PATCH_TYPE (p)) |
| 170 |
{ |
| 171 |
case PARAMETRIC_PATCH_TYPE : |
| 172 |
case LINEAR_PATCH_TYPE : |
| 173 |
return (1); |
| 174 |
case POINT_PATCH_TYPE : |
| 175 |
return (POINT_PATCH_N (p)); |
| 176 |
#ifdef UG_DIM_3 |
| 177 |
case LINE_PATCH_TYPE : |
| 178 |
return (LINE_PATCH_N (p)); |
| 179 |
#endif |
| 180 |
} |
| 181 |
|
| 182 |
return (-1); |
| 183 |
} |
| 184 |
|
| 185 |
static INT |
| 186 |
GetPatchId (const PATCH * p, INT i) |
| 187 |
{ |
| 188 |
switch (PATCH_TYPE (p)) |
| 189 |
{ |
| 190 |
case LINEAR_PATCH_TYPE : |
| 191 |
case PARAMETRIC_PATCH_TYPE : |
| 192 |
return (PATCH_ID (p)); |
| 193 |
case POINT_PATCH_TYPE : |
| 194 |
return (POINT_PATCH_PID (p, i)); |
| 195 |
#ifdef UG_DIM_3 |
| 196 |
case LINE_PATCH_TYPE : |
| 197 |
return (LINE_PATCH_PID (p, i)); |
| 198 |
#endif |
| 199 |
} |
| 200 |
|
| 201 |
assert(0); |
| 202 |
return (-1); |
| 203 |
} |
| 204 |
|
| 205 |
static BNDP * |
| 206 |
CreateBndPOnPoint (HEAP * Heap, PATCH * p) |
| 207 |
{ |
| 208 |
BND_PS *ps; |
| 209 |
PATCH *pp; |
| 210 |
INT j, l, m; |
| 211 |
|
| 212 |
if (PATCH_TYPE (p) != POINT_PATCH_TYPE) |
| 213 |
return (NULL); |
| 214 |
|
| 215 |
PRINTDEBUG (dom, 1, (" p %d\n", PATCH_ID (p))); |
| 216 |
for (l = 0; l < GetNumberOfPatches (p); l++) |
| 217 |
PRINTDEBUG (dom, 1, (" bp pid %d\n", GetPatchId (p, l))); |
| 218 |
|
| 219 |
m = POINT_PATCH_N (p); |
| 220 |
ps = (BND_PS *) GetFreelistMemory (Heap, sizeof (BND_PS) |
| 221 |
+ (m - 1) * sizeof (COORD_BND_VECTOR)); |
| 222 |
if (ps == NULL) |
| 223 |
REP_ERR_RETURN (NULL); |
| 224 |
ps->n = m; |
| 225 |
ps->patch_id = PATCH_ID (p); |
| 226 |
|
| 227 |
for (j = 0; j < m; j++) |
| 228 |
{ |
| 229 |
pp = currBVP->patches[POINT_PATCH_PID (p, j)]; |
| 230 |
if (PATCH_TYPE (pp) == PARAMETRIC_PATCH_TYPE) |
| 231 |
{ |
| 232 |
PRINTDEBUG (dom, 1, ("cp r %f %f %f %f\n", |
| 233 |
PARAM_PATCH_RANGE (pp)[0][0], |
| 234 |
PARAM_PATCH_RANGE (pp)[0][1], |
| 235 |
PARAM_PATCH_RANGE (pp)[1][0], |
| 236 |
PARAM_PATCH_RANGE (pp)[1][1])); |
| 237 |
switch (POINT_PATCH_CID (p, j)) |
| 238 |
{ |
| 239 |
#ifdef UG_DIM_2 |
| 240 |
case 0 : |
| 241 |
ps->local[j][0] = PARAM_PATCH_RANGE (pp)[0][0]; |
| 242 |
break; |
| 243 |
case 1 : |
| 244 |
ps->local[j][0] = PARAM_PATCH_RANGE (pp)[1][0]; |
| 245 |
break; |
| 246 |
#endif |
| 247 |
#ifdef UG_DIM_3 |
| 248 |
case 0 : |
| 249 |
ps->local[j][0] = PARAM_PATCH_RANGE (pp)[0][0]; |
| 250 |
ps->local[j][1] = PARAM_PATCH_RANGE (pp)[0][1]; |
| 251 |
break; |
| 252 |
case 1 : |
| 253 |
ps->local[j][0] = PARAM_PATCH_RANGE (pp)[1][0]; |
| 254 |
ps->local[j][1] = PARAM_PATCH_RANGE (pp)[0][1]; |
| 255 |
break; |
| 256 |
case 2 : |
| 257 |
ps->local[j][0] = PARAM_PATCH_RANGE (pp)[1][0]; |
| 258 |
ps->local[j][1] = PARAM_PATCH_RANGE (pp)[1][1]; |
| 259 |
break; |
| 260 |
case 3 : |
| 261 |
ps->local[j][0] = PARAM_PATCH_RANGE (pp)[0][0]; |
| 262 |
ps->local[j][1] = PARAM_PATCH_RANGE (pp)[1][1]; |
| 263 |
break; |
| 264 |
#endif |
| 265 |
} |
| 266 |
PRINTDEBUG (dom, 1, ("mesh loc j %d pid %d cid %d loc %f %f\n", |
| 267 |
j, |
| 268 |
POINT_PATCH_PID (p, j), |
| 269 |
POINT_PATCH_CID (p, j), |
| 270 |
ps->local[j][0], ps->local[j][1])); |
| 271 |
} |
| 272 |
else if (PATCH_TYPE (pp) == LINEAR_PATCH_TYPE) |
| 273 |
{ |
| 274 |
switch (POINT_PATCH_CID (p, j)) |
| 275 |
{ |
| 276 |
#ifdef UG_DIM_2 |
| 277 |
case 0 : |
| 278 |
ps->local[j][0] = 0.0; |
| 279 |
break; |
| 280 |
case 1 : |
| 281 |
ps->local[j][0] = 1.0; |
| 282 |
break; |
| 283 |
#endif |
| 284 |
#ifdef UG_DIM_3 |
| 285 |
case 0 : |
| 286 |
ps->local[j][0] = 0.0; |
| 287 |
ps->local[j][1] = 0.0; |
| 288 |
break; |
| 289 |
case 1 : |
| 290 |
ps->local[j][0] = 1.0; |
| 291 |
ps->local[j][1] = 0.0; |
| 292 |
break; |
| 293 |
case 2 : |
| 294 |
/* This coordinate depends on whether we're looking at a triangle or a quadrilateral */ |
| 295 |
ps->local[j][0] = (LINEAR_PATCH_N(pp)==3) ? 0.0 : 1.0; |
| 296 |
ps->local[j][1] = 1.0; |
| 297 |
break; |
| 298 |
case 3 : |
| 299 |
ps->local[j][0] = 0.0; |
| 300 |
ps->local[j][1] = 1.0; |
| 301 |
break; |
| 302 |
#endif |
| 303 |
} |
| 304 |
} |
| 305 |
} |
| 306 |
return ((BNDP *) ps); |
| 307 |
} |
| 308 |
|
| 309 |
static INT |
| 310 |
CreateCornerPoints (HEAP * Heap, STD_BVP * theBVP, BNDP ** bndp) |
| 311 |
{ |
| 312 |
int i; |
| 313 |
|
| 314 |
for (i = 0; i < theBVP->ncorners; i++) |
| 315 |
{ |
| 316 |
bndp[i] = CreateBndPOnPoint (Heap, theBVP->patches[i]); |
| 317 |
if (bndp[i] == NULL) |
| 318 |
REP_ERR_RETURN (1); |
| 319 |
} |
| 320 |
|
| 321 |
for (i = 0; i < theBVP->ncorners; i++) |
| 322 |
PRINTDEBUG (dom, 1, (" id %d\n", PATCH_ID (theBVP->patches[i]))); |
| 323 |
|
| 324 |
return (0); |
| 325 |
} |
| 326 |
|
| 327 |
#ifdef UG_DIM_3 |
| 328 |
/** \brief Add a line between two vertices to the boundary data structure |
| 329 |
|
| 330 |
\param i, j The line goes from vertex i to vertex j |
| 331 |
\param corners Array with pointers to all vertices |
| 332 |
*/ |
| 333 |
static void |
| 334 |
CreateLine(INT i, INT j, HEAP *Heap, PATCH **corners, PATCH **lines, PATCH **sides, |
| 335 |
INT *nlines, INT *err) |
| 336 |
{ |
| 337 |
INT k, n, m; |
| 338 |
|
| 339 |
k = 0; |
| 340 |
for (n = 0; n < POINT_PATCH_N (corners[i]); n++) |
| 341 |
for (m = 0; m < POINT_PATCH_N (corners[j]); m++) |
| 342 |
if (POINT_PATCH_PID (corners[i], n) == |
| 343 |
POINT_PATCH_PID (corners[j], m)) |
| 344 |
k++; |
| 345 |
/* points share one patch only and lie on opposite corners of this patch */ |
| 346 |
if (k < 2) |
| 347 |
return; |
| 348 |
|
| 349 |
PATCH* thePatch = |
| 350 |
(PATCH *) GetFreelistMemory (Heap, sizeof (LINE_PATCH) |
| 351 |
+ (k - |
| 352 |
1) * sizeof (struct line_on_patch)); |
| 353 |
if (thePatch == NULL) |
| 354 |
return; |
| 355 |
PATCH_TYPE (thePatch) = LINE_PATCH_TYPE; |
| 356 |
PATCH_ID (thePatch) = *nlines; |
| 357 |
LINE_PATCH_C0 (thePatch) = i; |
| 358 |
LINE_PATCH_C1 (thePatch) = j; |
| 359 |
k = 0; |
| 360 |
for (n = 0; n < POINT_PATCH_N (corners[i]); n++) |
| 361 |
for (m = 0; m < POINT_PATCH_N (corners[j]); m++) |
| 362 |
if (POINT_PATCH_PID (corners[i], n) == |
| 363 |
POINT_PATCH_PID (corners[j], m)) |
| 364 |
{ |
| 365 |
LINE_PATCH_PID (thePatch, k) = |
| 366 |
POINT_PATCH_PID (corners[i], n); |
| 367 |
LINE_PATCH_CID0 (thePatch, k) = |
| 368 |
POINT_PATCH_CID (corners[i], n); |
| 369 |
LINE_PATCH_CID1 (thePatch, k) = |
| 370 |
POINT_PATCH_CID (corners[j], m); |
| 371 |
k++; |
| 372 |
} |
| 373 |
LINE_PATCH_N (thePatch) = k; |
| 374 |
|
| 375 |
for (n = 0; n < LINE_PATCH_N (thePatch); n++) |
| 376 |
PRINTDEBUG (dom, 1, (" pid %d cid %d %d", |
| 377 |
LINE_PATCH_PID (thePatch, n), |
| 378 |
LINE_PATCH_CID0 (thePatch, n), |
| 379 |
LINE_PATCH_CID1 (thePatch, n))); |
| 380 |
PRINTDEBUG (dom, 1, ("\n")); |
| 381 |
|
| 382 |
IFDEBUG (dom, 10) if (k == 2) |
| 383 |
{ |
| 384 |
INT o0, o1, s0, s1; |
| 385 |
|
| 386 |
s0 = LINE_PATCH_PID (thePatch, 0); |
| 387 |
s1 = LINE_PATCH_PID (thePatch, 1); |
| 388 |
o0 = |
| 389 |
(LINE_PATCH_CID0 (thePatch, 0) == |
| 390 |
((LINE_PATCH_CID1 (thePatch, 0) + 1) % (2 * DIM_OF_BND))); |
| 391 |
o1 = |
| 392 |
(LINE_PATCH_CID0 (thePatch, 1) == |
| 393 |
((LINE_PATCH_CID1 (thePatch, 1) + 1) % (2 * DIM_OF_BND))); |
| 394 |
if (o0 != o1) |
| 395 |
{ |
| 396 |
if ((PARAM_PATCH_LEFT (sides[s0]) != |
| 397 |
PARAM_PATCH_LEFT (sides[s1])) |
| 398 |
|| ((PARAM_PATCH_RIGHT (sides[s0]) != |
| 399 |
PARAM_PATCH_RIGHT (sides[s1])))) |
| 400 |
{ |
| 401 |
PRINTDEBUG (dom, 0, ("patch %d and patch %d:" |
| 402 |
"orientations do not match\n", s0, s1)); |
| 403 |
(*err)++; |
| 404 |
} |
| 405 |
} |
| 406 |
else |
| 407 |
{ |
| 408 |
if ((PARAM_PATCH_LEFT (sides[s0]) != |
| 409 |
PARAM_PATCH_RIGHT (sides[s1])) |
| 410 |
|| ((PARAM_PATCH_RIGHT (sides[s0]) != |
| 411 |
PARAM_PATCH_LEFT (sides[s1])))) |
| 412 |
{ |
| 413 |
PRINTDEBUG (dom, 0, ("patch %d and patch %d:" |
| 414 |
"orientations do not match\n", s0, s1)); |
| 415 |
(*err)++; |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
ENDDEBUG |
| 420 |
lines[(*nlines)++] = thePatch; |
| 421 |
PRINTDEBUG (dom, 1, ("lines id %d type %d n %d\n", |
| 422 |
PATCH_ID (thePatch), PATCH_TYPE (thePatch), |
| 423 |
LINE_PATCH_N (thePatch))); |
| 424 |
|
| 425 |
|
| 426 |
} |
| 427 |
#endif |
| 428 |
|
| 429 |
void NS_DIM_PREFIX |
| 430 |
BVP_Init (STD_BVP* theBVP, HEAP * Heap, MESH * Mesh, INT MarkKey) |
| 431 |
{ |
| 432 |
PATCH **corners, **sides; |
| 433 |
unsigned short* segmentsPerPoint, *cornerCounters; |
| 434 |
INT i, j, n, m, ncorners, nlines, nsides; |
| 435 |
# ifdef UG_DIM_3 |
| 436 |
PATCH **lines; |
| 437 |
INT err; |
| 438 |
INT nn; |
| 439 |
# endif |
| 440 |
|
| 441 |
assert(theBVP); |
| 442 |
currBVP = theBVP; |
| 443 |
|
| 444 |
auto& theDomain = theBVP->Domain; |
| 445 |
assert(theDomain); |
| 446 |
|
| 447 |
/* fill in data of domain */ |
| 448 |
ncorners = theDomain->numOfCorners; |
| 449 |
nsides = theDomain->numOfSegments; |
| 450 |
|
| 451 |
/* create parameter patches */ |
| 452 |
sides = (PATCH **) GetTmpMem (Heap, nsides * sizeof (PATCH *), MarkKey); |
| 453 |
assert (sides); |
| 454 |
|
| 455 |
for (i = 0; i < nsides; i++) |
| 456 |
sides[i] = NULL; |
| 457 |
theBVP->nsides = nsides; |
| 458 |
for (const boundary_segment& theSegment : theDomain->boundarySegments) |
| 459 |
{ |
| 460 |
assert((theSegment.id >= 0) && (theSegment.id < nsides)); |
| 461 |
|
| 462 |
PATCH* thePatch = (PATCH *) GetFreelistMemory (Heap, sizeof (PARAMETER_PATCH)); |
| 463 |
assert (thePatch); |
| 464 |
|
| 465 |
PATCH_TYPE (thePatch) = PARAMETRIC_PATCH_TYPE; |
| 466 |
PATCH_ID (thePatch) = theSegment.id; |
| 467 |
for (i = 0; i < 2 * DIM_OF_BND; i++) |
| 468 |
PARAM_PATCH_POINTS (thePatch, i) = theSegment.points[i]; |
| 469 |
// TODO: Remove PARAM_PATCH_RANGE, because it is always (0,1)^d |
| 470 |
for (i = 0; i < DIM_OF_BND; i++) |
| 471 |
{ |
| 472 |
PARAM_PATCH_RANGE (thePatch)[0][i] = 0; |
| 473 |
PARAM_PATCH_RANGE (thePatch)[1][i] = 1; |
| 474 |
} |
| 475 |
PARAM_PATCH_BS (thePatch) = theSegment.BndSegFunc; |
| 476 |
PARAM_PATCH_BSD (thePatch) = theSegment.data; |
| 477 |
sides[theSegment.id] = thePatch; |
| 478 |
PRINTDEBUG (dom, 1, ("sides id %d type %d left %d right %d\n", |
| 479 |
PATCH_ID (thePatch), PATCH_TYPE (thePatch), |
| 480 |
PARAM_PATCH_LEFT (thePatch), |
| 481 |
PARAM_PATCH_RIGHT (thePatch))); |
| 482 |
for (i = 0; i < 2 * DIM_OF_BND; i++) |
| 483 |
PRINTDEBUG (dom, 1, |
| 484 |
(" corners %d", PARAM_PATCH_POINTS (thePatch, i))); |
| 485 |
PRINTDEBUG (dom, 1, ("\n")); |
| 486 |
} |
| 487 |
for (const linear_segment& theLinSegment : theDomain->linearSegments) |
| 488 |
{ |
| 489 |
assert((theLinSegment.id >= 0) && (theLinSegment.id < nsides)); |
| 490 |
|
| 491 |
PATCH* thePatch = (PATCH *) GetFreelistMemory (Heap, sizeof (LINEAR_PATCH)); |
| 492 |
assert(thePatch); |
| 493 |
|
| 494 |
PATCH_TYPE (thePatch) = LINEAR_PATCH_TYPE; |
| 495 |
PATCH_ID (thePatch) = theLinSegment.id; |
| 496 |
LINEAR_PATCH_N (thePatch) = theLinSegment.n; |
| 497 |
for (j = 0; j < theLinSegment.n; j++) |
| 498 |
{ |
| 499 |
LINEAR_PATCH_POINTS (thePatch, j) = theLinSegment.points[j]; |
| 500 |
for (i = 0; i < DIM; i++) |
| 501 |
LINEAR_PATCH_POS (thePatch, j)[i] = theLinSegment.x[j][i]; |
| 502 |
} |
| 503 |
sides[theLinSegment.id] = thePatch; |
| 504 |
PRINTDEBUG (dom, 1, ("sides id %d type %d left %d right %d\n", |
| 505 |
PATCH_ID (thePatch), PATCH_TYPE (thePatch), |
| 506 |
LINEAR_PATCH_LEFT (thePatch), |
| 507 |
LINEAR_PATCH_RIGHT (thePatch))); |
| 508 |
} |
| 509 |
for (i = 0; i < nsides; i++) |
| 510 |
assert(sides[i]); |
| 511 |
|
| 512 |
/* create point patches */ |
| 513 |
corners = (PATCH **) GetTmpMem (Heap, ncorners * sizeof (PATCH *), MarkKey); |
| 514 |
assert(corners); |
| 515 |
|
| 516 |
theBVP->ncorners = ncorners; |
| 517 |
|
| 518 |
/* precompute the number of segments at each point patch */ |
| 519 |
segmentsPerPoint = (unsigned short*)calloc(ncorners,sizeof(unsigned short)); |
| 520 |
|
| 521 |
for (j = 0; j < nsides; j++) { |
| 522 |
|
| 523 |
if (PATCH_TYPE (sides[j]) == LINEAR_PATCH_TYPE) { |
| 524 |
for (n = 0; n < LINEAR_PATCH_N (sides[j]); n++) |
| 525 |
segmentsPerPoint[LINEAR_PATCH_POINTS (sides[j], n)]++; |
| 526 |
|
| 527 |
} else if (PATCH_TYPE (sides[j]) == PARAMETRIC_PATCH_TYPE) { |
| 528 |
for (n = 0; n < 2 * DIM_OF_BND; n++) |
| 529 |
if (PARAM_PATCH_POINTS (sides[j], n) >= 0) /* Entry may be -1 for triangular faces */ |
| 530 |
segmentsPerPoint[PARAM_PATCH_POINTS (sides[j], n)]++; |
| 531 |
} |
| 532 |
|
| 533 |
} |
| 534 |
|
| 535 |
/* Allocate point patches */ |
| 536 |
for (i = 0; i < ncorners; i++) { |
| 537 |
|
| 538 |
m = segmentsPerPoint[i]; |
| 539 |
|
| 540 |
PATCH* thePatch = |
| 541 |
(PATCH *) GetFreelistMemory (Heap, sizeof (POINT_PATCH) |
| 542 |
+ (m-1) * sizeof (struct point_on_patch)); |
| 543 |
assert(thePatch); |
| 544 |
|
| 545 |
PATCH_TYPE (thePatch) = POINT_PATCH_TYPE; |
| 546 |
PATCH_ID (thePatch) = i; |
| 547 |
|
| 548 |
POINT_PATCH_N (thePatch) = m; |
| 549 |
corners[i] = thePatch; |
| 550 |
|
| 551 |
} |
| 552 |
|
| 553 |
cornerCounters = (unsigned short*)calloc(ncorners,sizeof(unsigned short)); |
| 554 |
|
| 555 |
for (j = 0; j < nsides; j++) |
| 556 |
{ |
| 557 |
if (PATCH_TYPE (sides[j]) == LINEAR_PATCH_TYPE) |
| 558 |
{ |
| 559 |
for (n = 0; n < LINEAR_PATCH_N (sides[j]); n++) |
| 560 |
{ |
| 561 |
i = LINEAR_PATCH_POINTS (sides[j], n); |
| 562 |
POINT_PATCH_PID (corners[i], cornerCounters[i]) = j; |
| 563 |
POINT_PATCH_CID (corners[i], cornerCounters[i]++) = n; |
| 564 |
} |
| 565 |
} |
| 566 |
else if (PATCH_TYPE (sides[j]) == PARAMETRIC_PATCH_TYPE) |
| 567 |
{ |
| 568 |
for (n = 0; n < 2 * DIM_OF_BND; n++) |
| 569 |
{ |
| 570 |
i = PARAM_PATCH_POINTS (sides[j], n); |
| 571 |
if (i>=0 && i<ncorners) { |
| 572 |
POINT_PATCH_PID (corners[i], cornerCounters[i]) = j; |
| 573 |
POINT_PATCH_CID (corners[i], cornerCounters[i]++) = n; |
| 574 |
} |
| 575 |
} |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
/* Return memory that will not be used anymore */ |
| 580 |
free(segmentsPerPoint); |
| 581 |
free(cornerCounters); |
| 582 |
|
| 583 |
/* create line patches */ |
| 584 |
nlines = 0; |
| 585 |
#ifdef UG_DIM_3 |
| 586 |
/* The maximum number of boundary lines is equal to the number of |
| 587 |
boundary faces (nsides) times the max number of lines per face (=4) |
| 588 |
divided by two. */ |
| 589 |
lines = |
| 590 |
(PATCH **) GetTmpMem (Heap, nsides * 2 * sizeof (PATCH *), |
| 591 |
MarkKey); |
| 592 |
assert(lines); |
| 593 |
|
| 594 |
err = 0; |
| 595 |
|
| 596 |
/* We create the set of all boundary lines by looping over the sides |
| 597 |
and for each side loop over the edges of this side. That way, we |
| 598 |
meet each boundary line twice. We cannot assume |
| 599 |
that the sides are properly oriented. Thus we introduce a c++-std::set |
| 600 |
which saves the index pair of the nodes defining the line. |
| 601 |
When a line is visited the second time, the pair is expunged from the |
| 602 |
set in order to save memory. |
| 603 |
*/ |
| 604 |
typedef std::set<std::pair<long,long> > set; |
| 605 |
set bnd_edges; |
| 606 |
|
| 607 |
for (int s=0; s<nsides; s++) { |
| 608 |
|
| 609 |
if (PATCH_TYPE (sides[s]) == LINEAR_PATCH_TYPE) { |
| 610 |
|
| 611 |
for (nn = 0; nn < LINEAR_PATCH_N (sides[s]); nn++) |
| 612 |
{ |
| 613 |
i = LINEAR_PATCH_POINTS (sides[s], nn); |
| 614 |
j = LINEAR_PATCH_POINTS (sides[s], (nn+1)%LINEAR_PATCH_N(sides[s])); |
| 615 |
|
| 616 |
long max = std::max(i,j); |
| 617 |
long min = i + j - max; |
| 618 |
std::pair<long, long> z(min,max); |
| 619 |
|
| 620 |
if ( bnd_edges.insert(z).second ) /* true if bnd_edges didn't contain z yet */ |
| 621 |
{ |
| 622 |
/* Insert the line into the boundary data structure */ |
| 623 |
CreateLine(min, max, Heap, corners, lines, sides, &nlines, &err); |
| 624 |
} |
| 625 |
else |
| 626 |
bnd_edges.erase(z); |
| 627 |
|
| 628 |
} |
| 629 |
|
| 630 |
} else if (PATCH_TYPE (sides[s]) == PARAMETRIC_PATCH_TYPE) { |
| 631 |
|
| 632 |
/* Handle edges of parametric patches */ |
| 633 |
|
| 634 |
/* Determine whether the boundary segment is a triangle or a quadrilateral. |
| 635 |
We assume that it is a triangle if the fourth vertex is invalid, and |
| 636 |
a quadrilateral otherwise. This is the best we can do. |
| 637 |
*/ |
| 638 |
|
| 639 |
int cornersOfParametricPatch = (PARAM_PATCH_POINTS (sides[s], 3) < 0 || PARAM_PATCH_POINTS (sides[s], 3) > ncorners) ? 3 : 4; |
| 640 |
|
| 641 |
for (nn = 0; nn < cornersOfParametricPatch; nn++) |
| 642 |
{ |
| 643 |
i = PARAM_PATCH_POINTS (sides[s], nn); |
| 644 |
j = PARAM_PATCH_POINTS (sides[s], (nn+1)%cornersOfParametricPatch); |
| 645 |
|
| 646 |
long max = std::max(i,j); |
| 647 |
long min = i + j - max; |
| 648 |
std::pair<long, long> z(min,max); |
| 649 |
|
| 650 |
if ( bnd_edges.insert(z).second ) /* true if bnd_edges didn't contain z yet */ |
| 651 |
{ |
| 652 |
/* Insert the line into the boundary data structure */ |
| 653 |
CreateLine(min, max, Heap, corners, lines, sides, &nlines, &err); |
| 654 |
} |
| 655 |
else |
| 656 |
bnd_edges.erase(z); |
| 657 |
|
| 658 |
} |
| 659 |
|
| 660 |
} else |
| 661 |
UserWrite("Error: unknown PATCH_TYPE found for a boundary side!\n"); |
| 662 |
|
| 663 |
} |
| 664 |
ASSERT (err == 0); |
| 665 |
#endif |
| 666 |
|
| 667 |
m = ncorners + nlines; |
| 668 |
theBVP->sideoffset = m; |
| 669 |
theBVP->patches.resize(m+nsides); |
| 670 |
n = 0; |
| 671 |
for (i = 0; i < ncorners; i++) |
| 672 |
{ |
| 673 |
PATCH* thePatch = corners[i]; |
| 674 |
for (j = 0; j < POINT_PATCH_N (thePatch); j++) |
| 675 |
POINT_PATCH_PID (thePatch, j) += m; |
| 676 |
theBVP->patches[n++] = thePatch; |
| 677 |
} |
| 678 |
#ifdef UG_DIM_3 |
| 679 |
for (i = 0; i < nlines; i++) |
| 680 |
{ |
| 681 |
PATCH* thePatch = lines[i]; |
| 682 |
PATCH_ID (thePatch) = n; |
| 683 |
for (j = 0; j < LINE_PATCH_N (thePatch); j++) |
| 684 |
LINE_PATCH_PID (thePatch, j) += m; |
| 685 |
theBVP->patches[n++] = thePatch; |
| 686 |
} |
| 687 |
#endif |
| 688 |
for (i = 0; i < nsides; i++) |
| 689 |
{ |
| 690 |
PATCH* thePatch = sides[i]; |
| 691 |
PATCH_ID (thePatch) = n; |
| 692 |
theBVP->patches[n++] = thePatch; |
| 693 |
} |
| 694 |
|
| 695 |
PRINTDEBUG (dom, 1, ("ncorners %d\n", theBVP->ncorners)); |
| 696 |
for (i = 0; i < theBVP->ncorners; i++) |
| 697 |
PRINTDEBUG (dom, 1, (" id %d\n", PATCH_ID (theBVP->patches[i]))); |
| 698 |
|
| 699 |
if (Mesh != NULL) |
| 700 |
{ |
| 701 |
Mesh->mesh_status = MESHSTAT_CNODES; |
| 702 |
Mesh->nBndP = theBVP->ncorners; |
| 703 |
Mesh->nInnP = 0; |
| 704 |
Mesh->nElements = NULL; |
| 705 |
Mesh->VertexLevel = NULL; |
| 706 |
Mesh->VertexPrio = NULL; |
| 707 |
Mesh->ElementLevel = NULL; |
| 708 |
Mesh->ElementPrio = NULL; |
| 709 |
Mesh->ElemSideOnBnd = NULL; |
| 710 |
Mesh->theBndPs = |
| 711 |
(BNDP **) GetTmpMem (Heap, n * sizeof (BNDP *), MarkKey); |
| 712 |
assert(Mesh->theBndPs); |
| 713 |
|
| 714 |
CreateCornerPoints (Heap, theBVP, Mesh->theBndPs); |
| 715 |
|
| 716 |
PRINTDEBUG (dom, 1, ("mesh n %d\n", Mesh->nBndP)); |
| 717 |
for (i = 0; i < theBVP->ncorners; i++) |
| 718 |
PRINTDEBUG (dom, 1, (" id %d\n", |
| 719 |
BND_PATCH_ID ((BND_PS *) (Mesh->theBndPs[i])))); |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
/* domain interface function: for description see domain.h */ |
| 724 |
NS_DIM_PREFIX std_BoundaryValueProblem::~std_BoundaryValueProblem() |
| 725 |
{ |
| 726 |
for (auto&& p : patches) |
| 727 |
free (p); |
| 728 |
} |
| 729 |
|
| 730 |
void NS_DIM_PREFIX |
| 731 |
Set_Current_BVP(STD_BVP *theBVP) |
| 732 |
{ |
| 733 |
currBVP = theBVP; |
| 734 |
} |
| 735 |
|
| 736 |
static INT |
| 737 |
GetNumberOfCommonPatches (const PATCH * p0, const PATCH * p1, INT * Pid) |
| 738 |
{ |
| 739 |
INT i, j, cnt, np0, np1, pid; |
| 740 |
|
| 741 |
cnt = 0; |
| 742 |
np0 = GetNumberOfPatches (p0); |
| 743 |
np1 = GetNumberOfPatches (p1); |
| 744 |
for (i = 0; i < np0; i++) |
| 745 |
{ |
| 746 |
pid = GetPatchId (p0, i); |
| 747 |
for (j = 0; j < np1; j++) |
| 748 |
if (pid == GetPatchId (p1, j)) |
| 749 |
{ |
| 750 |
if (!cnt) |
| 751 |
*Pid = pid; |
| 752 |
cnt++; |
| 753 |
} |
| 754 |
} |
| 755 |
|
| 756 |
return (cnt); |
| 757 |
} |
| 758 |
|
| 759 |
#ifdef UG_DIM_3 |
| 760 |
static INT |
| 761 |
GetCommonPatchId (const PATCH * p0, const PATCH * p1, INT k) |
| 762 |
{ |
| 763 |
INT i, j, cnt; |
| 764 |
|
| 765 |
cnt = 0; |
| 766 |
for (i = 0; i < GetNumberOfPatches (p0); i++) |
| 767 |
for (j = 0; j < GetNumberOfPatches (p1); j++) |
| 768 |
if (GetPatchId (p0, i) == GetPatchId (p1, j)) |
| 769 |
if (k == cnt++) |
| 770 |
return (GetPatchId (p1, j)); |
| 771 |
|
| 772 |
return (-1); |
| 773 |
} |
| 774 |
|
| 775 |
static INT |
| 776 |
GetCommonLinePatchId (PATCH * p0, PATCH * p1) |
| 777 |
{ |
| 778 |
INT i, k, l, cnt, cnt1; |
| 779 |
|
| 780 |
if (PATCH_TYPE (p0) == LINE_PATCH_TYPE) |
| 781 |
return (PATCH_ID (p0)); |
| 782 |
else if (PATCH_TYPE (p1) == LINE_PATCH_TYPE) |
| 783 |
return (PATCH_ID (p1)); |
| 784 |
|
| 785 |
cnt = GetNumberOfCommonPatches (p0, p1, &i); |
| 786 |
|
| 787 |
if (cnt < 1) |
| 788 |
return (-1); |
| 789 |
|
| 790 |
for (k = currBVP->ncorners; k < currBVP->sideoffset; k++) |
| 791 |
{ |
| 792 |
PATCH *p = currBVP->patches[k]; |
| 793 |
if (LINE_PATCH_N (p) != cnt) |
| 794 |
continue; |
| 795 |
cnt1 = 0; |
| 796 |
for (i = 0; i < cnt; i++) |
| 797 |
for (l = 0; l < LINE_PATCH_N (p); l++) |
| 798 |
if (GetCommonPatchId (p0, p1, i) == LINE_PATCH_PID (p, l)) |
| 799 |
cnt1++; |
| 800 |
if (cnt == cnt1) |
| 801 |
return (k); |
| 802 |
} |
| 803 |
|
| 804 |
return (-1); |
| 805 |
} |
| 806 |
#endif |
| 807 |
|
| 808 |
|
| 809 |
/****************************************************************************/ |
| 810 |
/****************************************************************************/ |
| 811 |
/* */ |
| 812 |
/* functions for BNDS */ |
| 813 |
/* */ |
| 814 |
/****************************************************************************/ |
| 815 |
/****************************************************************************/ |
| 816 |
|
| 817 |
static INT |
| 818 |
PatchGlobal (const PATCH * p, DOUBLE * lambda, Dune::FieldVector<DOUBLE,DIM>& global) |
| 819 |
{ |
| 820 |
if (PATCH_TYPE (p) == PARAMETRIC_PATCH_TYPE) |
| 821 |
return ((*PARAM_PATCH_BS (p))(PARAM_PATCH_BSD (p), lambda, global)); |
| 822 |
else if (PATCH_TYPE (p) == LINEAR_PATCH_TYPE) |
| 823 |
{ |
| 824 |
#ifdef UG_DIM_2 |
| 825 |
global[0] = (1 - lambda[0]) * LINEAR_PATCH_POS (p, 0)[0] |
| 826 |
+ lambda[0] * LINEAR_PATCH_POS (p, 1)[0]; |
| 827 |
global[1] = (1 - lambda[0]) * LINEAR_PATCH_POS (p, 0)[1] |
| 828 |
+ lambda[0] * LINEAR_PATCH_POS (p, 1)[1]; |
| 829 |
#endif |
| 830 |
#ifdef UG_DIM_3 |
| 831 |
|
| 832 |
if (LINEAR_PATCH_N(p) ==3) { |
| 833 |
/* Linear interpolation for a triangle boundary segment */ |
| 834 |
int i; |
| 835 |
for (i=0; i<3; i++) |
| 836 |
global[i] = (1 - lambda[0] - lambda[1]) * LINEAR_PATCH_POS (p, 0)[i] |
| 837 |
+ lambda[0] * LINEAR_PATCH_POS (p, 1)[i] |
| 838 |
+ lambda[1] * LINEAR_PATCH_POS (p, 2)[i]; |
| 839 |
|
| 840 |
} else { |
| 841 |
/* Bilinear interpolation for a quadrilateral boundary segment */ |
| 842 |
int i; |
| 843 |
for (i=0; i<3; i++) |
| 844 |
global[i] = LINEAR_PATCH_POS (p, 0)[i] |
| 845 |
+ lambda[0]*(LINEAR_PATCH_POS (p, 1)[i] - LINEAR_PATCH_POS (p, 0)[i]) |
| 846 |
+ lambda[1]*(LINEAR_PATCH_POS (p, 3)[i] - LINEAR_PATCH_POS (p, 0)[i]) |
| 847 |
+ lambda[0]*lambda[1]*(LINEAR_PATCH_POS (p, 0)[i]+LINEAR_PATCH_POS (p, 2)[i]-LINEAR_PATCH_POS (p, 1)[i]-LINEAR_PATCH_POS (p, 3)[i]); |
| 848 |
} |
| 849 |
#endif |
| 850 |
return (0); |
| 851 |
} |
| 852 |
|
| 853 |
return (1); |
| 854 |
} |
| 855 |
|
| 856 |
static INT |
| 857 |
local2lambda (BND_PS * ps, const Dune::FieldVector<DOUBLE,DIM_OF_BND>& local, DOUBLE lambda[]) |
| 858 |
{ |
| 859 |
const PATCH *p = currBVP->patches[ps->patch_id]; |
| 860 |
|
| 861 |
if ((PATCH_TYPE (p) == PARAMETRIC_PATCH_TYPE) |
| 862 |
|| (PATCH_TYPE (p) == LINEAR_PATCH_TYPE)) |
| 863 |
#ifdef UG_DIM_2 |
| 864 |
lambda[0] = |
| 865 |
(1.0 - local[0]) * ps->local[0][0] + local[0] * ps->local[1][0]; |
| 866 |
#endif |
| 867 |
#ifdef UG_DIM_3 |
| 868 |
switch (ps->n) |
| 869 |
{ |
| 870 |
case 3 : |
| 871 |
lambda[0] = (1.0 - local[0] - local[1]) * ps->local[0][0] |
| 872 |
+ local[0] * ps->local[1][0] + local[1] * ps->local[2][0]; |
| 873 |
lambda[1] = (1.0 - local[0] - local[1]) * ps->local[0][1] |
| 874 |
+ local[0] * ps->local[1][1] + local[1] * ps->local[2][1]; |
| 875 |
break; |
| 876 |
case 4 : |
| 877 |
lambda[0] = (1.0 - local[0]) * (1.0 - local[1]) * ps->local[0][0] |
| 878 |
+ local[0] * (1.0 - local[1]) * ps->local[1][0] |
| 879 |
+ local[0] * local[1] * ps->local[2][0] |
| 880 |
+ (1.0 - local[0]) * local[1] * ps->local[3][0]; |
| 881 |
lambda[1] = (1.0 - local[0]) * (1.0 - local[1]) * ps->local[0][1] |
| 882 |
+ local[0] * (1.0 - local[1]) * ps->local[1][1] |
| 883 |
+ local[0] * local[1] * ps->local[2][1] |
| 884 |
+ (1.0 - local[0]) * local[1] * ps->local[3][1]; |
| 885 |
break; |
| 886 |
} |
| 887 |
#endif |
| 888 |
else |
| 889 |
return (1); |
| 890 |
|
| 891 |
return (0); |
| 892 |
} |
| 893 |
|
| 894 |
static bool |
| 895 |
SideIsCooriented (BND_PS * ps) |
| 896 |
{ |
| 897 |
# ifdef UG_DIM_2 |
| 898 |
if (BND_LOCAL (ps, 1)[0] > BND_LOCAL (ps, 0)[0]) |
| 899 |
return true; |
| 900 |
else |
| 901 |
return false; |
| 902 |
# endif |
| 903 |
|
| 904 |
# ifdef UG_DIM_3 |
| 905 |
DOUBLE vp, x0[2], x1[2]; |
| 906 |
|
| 907 |
ASSERT (BND_N (ps) >= 3); |
| 908 |
|
| 909 |
/* check whether an (arbitrary) angle of the side is > 180 degree */ |
| 910 |
V2_SUBTRACT (BND_LOCAL (ps, 1), BND_LOCAL (ps, 0), x0); |
| 911 |
V2_SUBTRACT (BND_LOCAL (ps, 2), BND_LOCAL (ps, 0), x1); |
| 912 |
V2_VECTOR_PRODUCT (x1, x0, vp); |
| 913 |
|
| 914 |
ASSERT (fabs (vp) > SMALL_C); |
| 915 |
|
| 916 |
if (vp > SMALL_C) |
| 917 |
return true; |
| 918 |
else |
| 919 |
return false; |
| 920 |
# endif |
| 921 |
} |
| 922 |
|
| 923 |
/* domain interface function: for description see domain.h */ |
| 924 |
INT NS_DIM_PREFIX |
| 925 |
BNDS_BndSDesc (BNDS * theBndS, INT * id, INT * nbid) |
| 926 |
{ |
| 927 |
BND_PS *ps; |
| 928 |
PATCH *p; |
| 929 |
INT left, right; |
| 930 |
|
| 931 |
ps = (BND_PS *) theBndS; |
| 932 |
p = currBVP->patches[ps->patch_id]; |
| 933 |
|
| 934 |
if (PATCH_TYPE (p) == PARAMETRIC_PATCH_TYPE) |
| 935 |
{ |
| 936 |
left = PARAM_PATCH_LEFT (p); |
| 937 |
right = PARAM_PATCH_RIGHT (p); |
| 938 |
} |
| 939 |
else if (PATCH_TYPE (p) == LINEAR_PATCH_TYPE) |
| 940 |
{ |
| 941 |
left = LINEAR_PATCH_LEFT (p); |
| 942 |
right = LINEAR_PATCH_RIGHT (p); |
| 943 |
} |
| 944 |
else |
| 945 |
return (1); |
| 946 |
|
| 947 |
/* check orientation */ |
| 948 |
if (SideIsCooriented (ps)) |
| 949 |
{ |
| 950 |
/* patch and side are co-oriented */ |
| 951 |
*id = left; |
| 952 |
*nbid = right; |
| 953 |
} |
| 954 |
else |
| 955 |
{ |
| 956 |
/* patch and side are anti-oriented */ |
| 957 |
*id = right; |
| 958 |
*nbid = left; |
| 959 |
} |
| 960 |
|
| 961 |
return (0); |
| 962 |
} |
| 963 |
|
| 964 |
/* domain interface function: for description see domain.h */ |
| 965 |
BNDP *NS_DIM_PREFIX |
| 966 |
BNDS_CreateBndP (HEAP * Heap, BNDS * aBndS, const FieldVector<DOUBLE,DIM_OF_BND>& local) |
| 967 |
{ |
| 968 |
BND_PS *ps, *pp; |
| 969 |
|
| 970 |
if (aBndS == NULL) |
| 971 |
return (NULL); |
| 972 |
|
| 973 |
ps = (BND_PS *) aBndS; |
| 974 |
|
| 975 |
pp = (BND_PS *) GetFreelistMemory (Heap, sizeof (BND_PS)); |
| 976 |
if (pp == NULL) |
| 977 |
return (NULL); |
| 978 |
|
| 979 |
pp->patch_id = ps->patch_id; |
| 980 |
pp->n = 1; |
| 981 |
|
| 982 |
if (local2lambda (ps, local, pp->local[0])) |
| 983 |
return (NULL); |
| 984 |
|
| 985 |
PRINTDEBUG (dom, 1, (" BNDP s %d\n", pp->patch_id)); |
| 986 |
|
| 987 |
return ((BNDP *) pp); |
| 988 |
} |
| 989 |
|
| 990 |
/****************************************************************************/ |
| 991 |
/****************************************************************************/ |
| 992 |
/* */ |
| 993 |
/* functions for BNDP */ |
| 994 |
/* */ |
| 995 |
/****************************************************************************/ |
| 996 |
/****************************************************************************/ |
| 997 |
|
| 998 |
/* domain interface function: for description see domain.h */ |
| 999 |
INT NS_DIM_PREFIX |
| 1000 |
BNDP_Global (const BNDP * aBndP, FieldVector<DOUBLE,DIM>& global) |
| 1001 |
{ |
| 1002 |
using std::abs; |
| 1003 |
BND_PS *ps; |
| 1004 |
PATCH *p, *s; |
| 1005 |
INT j, k; |
| 1006 |
FieldVector<DOUBLE,DIM> pglobal; |
| 1007 |
|
| 1008 |
ps = (BND_PS *) aBndP; |
| 1009 |
p = currBVP->patches[ps->patch_id]; |
| 1010 |
|
| 1011 |
PRINTDEBUG (dom, 1, (" bndp pid %d %d %d\n", ps->patch_id, |
| 1012 |
PATCH_ID (p), PATCH_TYPE (p))); |
| 1013 |
|
| 1014 |
switch (PATCH_TYPE (p)) |
| 1015 |
{ |
| 1016 |
case PARAMETRIC_PATCH_TYPE : |
| 1017 |
case LINEAR_PATCH_TYPE : |
| 1018 |
return (PatchGlobal (p, ps->local[0], global)); |
| 1019 |
case POINT_PATCH_TYPE : |
| 1020 |
|
| 1021 |
s = currBVP->patches[POINT_PATCH_PID (p, 0)]; |
| 1022 |
|
| 1023 |
PRINTDEBUG (dom, 1, (" bndp n %d %d loc %f %f gl \n", |
| 1024 |
POINT_PATCH_N (p), |
| 1025 |
POINT_PATCH_PID (p, 0), |
| 1026 |
ps->local[0][0], ps->local[0][1])); |
| 1027 |
|
| 1028 |
PatchGlobal(s, ps->local[0], global); |
| 1029 |
|
| 1030 |
for (j = 1; j < POINT_PATCH_N (p); j++) |
| 1031 |
{ |
| 1032 |
s = currBVP->patches[POINT_PATCH_PID (p, j)]; |
| 1033 |
|
| 1034 |
if (PatchGlobal(s, ps->local[j], pglobal)) |
| 1035 |
REP_ERR_RETURN (1); |
| 1036 |
|
| 1037 |
PRINTDEBUG (dom,1, (" bndp j %d %d loc %f %f gl %f %f %f\n", j, |
| 1038 |
POINT_PATCH_PID (p, j), |
| 1039 |
ps->local[j][0], |
| 1040 |
ps->local[j][1], |
| 1041 |
pglobal[0], pglobal[1], pglobal[2])); |
| 1042 |
for (k = 0; k < DIM; k++) |
| 1043 |
if (abs(pglobal[k] - global[k]) > SMALL_DIFF) |
| 1044 |
REP_ERR_RETURN (1); |
| 1045 |
} |
| 1046 |
|
| 1047 |
return (0); |
| 1048 |
#ifdef UG_DIM_3 |
| 1049 |
case LINE_PATCH_TYPE : |
| 1050 |
s = currBVP->patches[LINE_PATCH_PID (p, 0)]; |
| 1051 |
|
| 1052 |
if (PatchGlobal(s, ps->local[0], global)) |
| 1053 |
REP_ERR_RETURN (1); |
| 1054 |
|
| 1055 |
PRINTDEBUG (dom, 1, (" bndp n %d %d loc %f %f gl %f %f %f\n", |
| 1056 |
POINT_PATCH_N (p), |
| 1057 |
LINE_PATCH_PID (p, 0), |
| 1058 |
ps->local[0][0], |
| 1059 |
ps->local[0][1], global[0], global[1], global[2])); |
| 1060 |
for (j = 1; j < LINE_PATCH_N (p); j++) |
| 1061 |
{ |
| 1062 |
s = currBVP->patches[LINE_PATCH_PID (p, j)]; |
| 1063 |
|
| 1064 |
if (PatchGlobal(s, ps->local[j], pglobal)) |
| 1065 |
REP_ERR_RETURN (1); |
| 1066 |
|
| 1067 |
PRINTDEBUG (dom, 1, (" bndp j %d %d loc %f %f gl %f %f %f\n", j, |
| 1068 |
LINE_PATCH_PID (p, j), |
| 1069 |
ps->local[j][0], |
| 1070 |
ps->local[j][1], |
| 1071 |
pglobal[0], pglobal[1], pglobal[2])); |
| 1072 |
for (k = 0; k < DIM; k++) |
| 1073 |
if (abs(pglobal[k] - global[k]) > SMALL_DIFF) |
| 1074 |
REP_ERR_RETURN (1); |
| 1075 |
} |
| 1076 |
return (0); |
| 1077 |
#endif |
| 1078 |
} |
| 1079 |
|
| 1080 |
REP_ERR_RETURN (1); |
| 1081 |
} |
| 1082 |
|
| 1083 |
/* domain interface function: for description see domain.h */ |
| 1084 |
INT NS_DIM_PREFIX |
| 1085 |
BNDP_BndPDesc (BNDP * theBndP, INT * move) |
| 1086 |
{ |
| 1087 |
BND_PS *ps; |
| 1088 |
PATCH *p; |
| 1089 |
|
| 1090 |
ps = (BND_PS *) theBndP; |
| 1091 |
p = STD_BVP_PATCH (currBVP, ps->patch_id); |
| 1092 |
|
| 1093 |
switch (PATCH_TYPE (p)) |
| 1094 |
{ |
| 1095 |
case PARAMETRIC_PATCH_TYPE : |
| 1096 |
case LINEAR_PATCH_TYPE : |
| 1097 |
*move = DIM_OF_BND; |
| 1098 |
return (0); |
| 1099 |
|
| 1100 |
case POINT_PATCH_TYPE : |
| 1101 |
*move = 0; |
| 1102 |
return (0); |
| 1103 |
|
| 1104 |
# ifdef UG_DIM_3 |
| 1105 |
case LINE_PATCH_TYPE : |
| 1106 |
*move = 1; |
| 1107 |
return (0); |
| 1108 |
# endif |
| 1109 |
} |
| 1110 |
|
| 1111 |
return (1); |
| 1112 |
} |
| 1113 |
|
| 1114 |
/* domain interface function: for description see domain.h */ |
| 1115 |
INT NS_DIM_PREFIX |
| 1116 |
BNDP_BndEDesc (BNDP * aBndP0, BNDP * aBndP1) |
| 1117 |
{ |
| 1118 |
const BND_PS *bp0 = (BND_PS*)aBndP0; |
| 1119 |
const BND_PS *bp1 = (BND_PS*)aBndP1; |
| 1120 |
|
| 1121 |
if ((bp0 == nullptr) || (bp1 == nullptr)) |
| 1122 |
REP_ERR_RETURN (1); |
| 1123 |
|
| 1124 |
return (0); |
| 1125 |
} |
| 1126 |
|
| 1127 |
/* domain interface function: for description see domain.h */ |
| 1128 |
BNDS *NS_DIM_PREFIX |
| 1129 |
BNDP_CreateBndS (HEAP * Heap, BNDP ** aBndP, INT n) |
| 1130 |
{ |
| 1131 |
BND_PS *bp[4], *bs; |
| 1132 |
PATCH *p[4]; |
| 1133 |
DOUBLE *lambda[4]; |
| 1134 |
INT i, j, l, pid; |
| 1135 |
# ifdef UG_DIM_3 |
| 1136 |
INT k; |
| 1137 |
# endif |
| 1138 |
|
| 1139 |
PRINTDEBUG (dom, 1, ("Create BNDS:\n")); |
| 1140 |
for (i = 0; i < n; i++) |
| 1141 |
{ |
| 1142 |
bp[i] = (BND_PS *) aBndP[i]; |
| 1143 |
p[i] = currBVP->patches[bp[i]->patch_id]; |
| 1144 |
|
| 1145 |
PRINTDEBUG (dom, 1, (" bp %d p %d n %d\n", |
| 1146 |
bp[i]->patch_id, PATCH_ID (p[i]), n)); |
| 1147 |
for (l = 0; l < GetNumberOfPatches (p[i]); l++) |
| 1148 |
PRINTDEBUG (dom, 1, (" bp pid %d\n", GetPatchId (p[i], l))); |
| 1149 |
} |
| 1150 |
|
| 1151 |
pid = -1; |
| 1152 |
#ifdef UG_DIM_2 |
| 1153 |
if (n != 2) |
| 1154 |
return (NULL); |
| 1155 |
/* find common patch of boundary points */ |
| 1156 |
for (i = 0; i < GetNumberOfPatches (p[0]); i++) |
| 1157 |
for (j = 0; j < GetNumberOfPatches (p[1]); j++) |
| 1158 |
{ |
| 1159 |
PRINTDEBUG (dom, 1, (" pid i, j %d %d %d %d\n", i, j, |
| 1160 |
GetPatchId (p[0], i), GetPatchId (p[1], j))); |
| 1161 |
if (GetPatchId (p[0], i) == GetPatchId (p[1], j)) |
| 1162 |
{ |
| 1163 |
pid = GetPatchId (p[0], i); |
| 1164 |
lambda[0] = bp[0]->local[i]; |
| 1165 |
lambda[1] = bp[1]->local[j]; |
| 1166 |
break; |
| 1167 |
PRINTDEBUG (dom, 1, (" pid %d \n", pid)); |
| 1168 |
} |
| 1169 |
} |
| 1170 |
#endif |
| 1171 |
#ifdef UG_DIM_3 |
| 1172 |
switch (n) |
| 1173 |
{ |
| 1174 |
case 3 : |
| 1175 |
for (i = 0; i < GetNumberOfPatches (p[0]); i++) |
| 1176 |
for (j = 0; j < GetNumberOfPatches (p[1]); j++) |
| 1177 |
if (GetPatchId (p[0], i) == GetPatchId (p[1], j)) |
| 1178 |
for (k = 0; k < GetNumberOfPatches (p[2]); k++) |
| 1179 |
if (GetPatchId (p[0], i) == GetPatchId (p[2], k)) |
| 1180 |
{ |
| 1181 |
pid = GetPatchId (p[0], i); |
| 1182 |
lambda[0] = bp[0]->local[i]; |
| 1183 |
lambda[1] = bp[1]->local[j]; |
| 1184 |
lambda[2] = bp[2]->local[k]; |
| 1185 |
break; |
| 1186 |
} |
| 1187 |
break; |
| 1188 |
case 4 : |
| 1189 |
for (i = 0; i < GetNumberOfPatches (p[0]); i++) |
| 1190 |
for (j = 0; j < GetNumberOfPatches (p[1]); j++) |
| 1191 |
if (GetPatchId (p[0], i) == GetPatchId (p[1], j)) |
| 1192 |
for (k = 0; k < GetNumberOfPatches (p[2]); k++) |
| 1193 |
if (GetPatchId (p[0], i) == GetPatchId (p[2], k)) |
| 1194 |
for (l = 0; l < GetNumberOfPatches (p[3]); l++) |
| 1195 |
if (GetPatchId (p[0], i) == GetPatchId (p[3], l)) |
| 1196 |
{ |
| 1197 |
pid = GetPatchId (p[0], i); |
| 1198 |
lambda[0] = bp[0]->local[i]; |
| 1199 |
lambda[1] = bp[1]->local[j]; |
| 1200 |
lambda[2] = bp[2]->local[k]; |
| 1201 |
lambda[3] = bp[3]->local[l]; |
| 1202 |
break; |
| 1203 |
} |
| 1204 |
break; |
| 1205 |
} |
| 1206 |
#endif |
| 1207 |
|
| 1208 |
if (pid == -1) |
| 1209 |
return (NULL); |
| 1210 |
|
| 1211 |
bs = (BND_PS *) GetFreelistMemory (Heap, (n - 1) * sizeof (COORD_BND_VECTOR) |
| 1212 |
+ sizeof (BND_PS)); |
| 1213 |
if (bs == NULL) |
| 1214 |
return (NULL); |
| 1215 |
bs->n = n; |
| 1216 |
bs->patch_id = pid; |
| 1217 |
for (i = 0; i < n; i++) |
| 1218 |
for (j = 0; j < DIM_OF_BND; j++) |
| 1219 |
bs->local[i][j] = lambda[i][j]; |
| 1220 |
|
| 1221 |
for (i = 0; i < n; i++) |
| 1222 |
for (j = 0; j < DIM_OF_BND; j++) |
| 1223 |
PRINTDEBUG (dom, 1, (" bnds i, j %d %d %f\n", i, j, lambda[i][j])); |
| 1224 |
|
| 1225 |
PRINTDEBUG (dom, 1, (" Create BNDS %x %d\n", bs, pid)); |
| 1226 |
|
| 1227 |
return ((BNDS *) bs); |
| 1228 |
} |
| 1229 |
|
| 1230 |
/* domain interface function: for description see domain.h */ |
| 1231 |
BNDP *NS_DIM_PREFIX |
| 1232 |
BNDP_CreateBndP (HEAP * Heap, BNDP * aBndP0, BNDP * aBndP1, DOUBLE lcoord) |
| 1233 |
{ |
| 1234 |
BND_PS *bp0, *bp1, *bp; |
| 1235 |
PATCH *p0, *p1; |
| 1236 |
INT i, j, k, l, cnt; |
| 1237 |
|
| 1238 |
bp0 = (BND_PS *) aBndP0; |
| 1239 |
bp1 = (BND_PS *) aBndP1; |
| 1240 |
|
| 1241 |
if ((bp0 == NULL) || (bp1 == NULL)) |
| 1242 |
return (NULL); |
| 1243 |
|
| 1244 |
p0 = currBVP->patches[bp0->patch_id]; |
| 1245 |
p1 = currBVP->patches[bp1->patch_id]; |
| 1246 |
|
| 1247 |
PRINTDEBUG (dom, 1, (" bp0 %d pid %d\n", bp0->patch_id, PATCH_ID (p0))); |
| 1248 |
for (l = 0; l < GetNumberOfPatches (p0); l++) |
| 1249 |
PRINTDEBUG (dom, 1, (" bp pid %d\n", GetPatchId (p0, l))); |
| 1250 |
PRINTDEBUG (dom, 1, (" bp1 %d pid %d\n", bp1->patch_id, PATCH_ID (p1))); |
| 1251 |
for (l = 0; l < GetNumberOfPatches (p1); l++) |
| 1252 |
PRINTDEBUG (dom, 1, (" bp pid %d\n", GetPatchId (p1, l))); |
| 1253 |
|
| 1254 |
cnt = GetNumberOfCommonPatches (p0, p1, &i); |
| 1255 |
if (cnt == 0) |
| 1256 |
return (NULL); |
| 1257 |
|
| 1258 |
bp = |
| 1259 |
(BND_PS *) GetFreelistMemory (Heap, |
| 1260 |
(cnt - 1) * sizeof (COORD_BND_VECTOR) + |
| 1261 |
sizeof (BND_PS)); |
| 1262 |
if (bp == NULL) |
| 1263 |
return (NULL); |
| 1264 |
bp->n = cnt; |
| 1265 |
|
| 1266 |
#ifdef UG_DIM_3 |
| 1267 |
if (cnt > 1) |
| 1268 |
{ |
| 1269 |
PATCH *p; |
| 1270 |
k = GetCommonLinePatchId (p0, p1); |
| 1271 |
if ((k < currBVP->ncorners) || (k >= currBVP->sideoffset)) |
| 1272 |
return (NULL); |
| 1273 |
p = currBVP->patches[k]; |
| 1274 |
bp->patch_id = k; |
| 1275 |
|
| 1276 |
PRINTDEBUG (dom, 1, (" Create BNDP line %d cnt %d\n", k, cnt)); |
| 1277 |
PRINTDEBUG (dom, 1, (" bp0 %d pid %d\n", |
| 1278 |
bp0->patch_id, PATCH_ID (p0))); |
| 1279 |
for (l = 0; l < GetNumberOfPatches (p0); l++) |
| 1280 |
PRINTDEBUG (dom, 1, (" bp pid %d\n", GetPatchId (p0, l))); |
| 1281 |
PRINTDEBUG (dom, 1, (" bp1 %d pid %d\n", |
| 1282 |
bp1->patch_id, PATCH_ID (p1))); |
| 1283 |
for (l = 0; l < GetNumberOfPatches (p1); l++) |
| 1284 |
PRINTDEBUG (dom, 1, (" bp pid %d\n", GetPatchId (p1, l))); |
| 1285 |
|
| 1286 |
for (l = 0; l < LINE_PATCH_N (p); l++) |
| 1287 |
{ |
| 1288 |
for (i = 0; i < GetNumberOfPatches (p0); i++) |
| 1289 |
if (GetPatchId (p0, i) == LINE_PATCH_PID (p, l)) |
| 1290 |
for (j = 0; j < GetNumberOfPatches (p1); j++) |
| 1291 |
if (GetPatchId (p1, j) == LINE_PATCH_PID (p, l)) |
| 1292 |
for (k = 0; k < DIM_OF_BND; k++) |
| 1293 |
bp->local[l][k] = (1.0 - lcoord) * bp0->local[i][k] |
| 1294 |
+ lcoord * bp1->local[j][k]; |
| 1295 |
} |
| 1296 |
|
| 1297 |
for (l = 0; l < LINE_PATCH_N (p); l++) |
| 1298 |
PRINTDEBUG (dom, 1, (" Create BNDP line %d l %d %f %f\n", |
| 1299 |
LINE_PATCH_PID (p, l), l, |
| 1300 |
bp->local[l][0], bp->local[l][1])); |
| 1301 |
|
| 1302 |
return ((BNDP *) bp); |
| 1303 |
} |
| 1304 |
#endif |
| 1305 |
|
| 1306 |
for (i = 0; i < GetNumberOfPatches (p0); i++) |
| 1307 |
for (j = 0; j < GetNumberOfPatches (p1); j++) |
| 1308 |
if (GetPatchId (p0, i) == GetPatchId (p1, j)) |
| 1309 |
{ |
| 1310 |
bp->patch_id = GetPatchId (p0, i); |
| 1311 |
for (k = 0; k < DIM_OF_BND; k++) |
| 1312 |
bp->local[0][k] = (1.0 - lcoord) * bp0->local[i][k] |
| 1313 |
+ lcoord * bp1->local[j][k]; |
| 1314 |
PRINTDEBUG (dom, 1, |
| 1315 |
(" Create BNDP param %d \n", GetPatchId (p0, i))); |
| 1316 |
|
| 1317 |
break; |
| 1318 |
} |
| 1319 |
|
| 1320 |
return ((BNDP *) bp); |
| 1321 |
} |
| 1322 |
|
| 1323 |
/* domain interface function: for description see domain.h */ |
| 1324 |
INT NS_DIM_PREFIX |
| 1325 |
BNDP_SaveInsertedBndP (BNDP * theBndP, char *data, INT max_data_size) |
| 1326 |
{ |
| 1327 |
BND_PS *bp; |
| 1328 |
PATCH *p; |
| 1329 |
INT pid; |
| 1330 |
|
| 1331 |
bp = (BND_PS *) theBndP; |
| 1332 |
|
| 1333 |
if (bp == NULL) |
| 1334 |
return (1); |
| 1335 |
|
| 1336 |
pid = bp->patch_id; |
| 1337 |
p = currBVP->patches[pid]; |
| 1338 |
|
| 1339 |
switch (PATCH_TYPE (p)) |
| 1340 |
{ |
| 1341 |
case PARAMETRIC_PATCH_TYPE : |
| 1342 |
case LINEAR_PATCH_TYPE : |
| 1343 |
pid -= currBVP->sideoffset; |
| 1344 |
break; |
| 1345 |
case POINT_PATCH_TYPE : |
| 1346 |
pid = POINT_PATCH_PID (p, 0) - currBVP->sideoffset; |
| 1347 |
break; |
| 1348 |
#ifdef UG_DIM_3 |
| 1349 |
case LINE_PATCH_TYPE : |
| 1350 |
pid = LINE_PATCH_PID (p, 0) - currBVP->sideoffset; |
| 1351 |
break; |
| 1352 |
#endif |
| 1353 |
} |
| 1354 |
|
| 1355 |
PRINTDEBUG (dom, 1, (" Insert pid %d %d\n", bp->patch_id, pid)); |
| 1356 |
|
| 1357 |
#ifdef UG_DIM_2 |
| 1358 |
if (snprintf (data, max_data_size, "bn %d %f", pid, (float) bp->local[0][0]) > |
| 1359 |
max_data_size) |
| 1360 |
return (1); |
| 1361 |
#endif |
| 1362 |
|
| 1363 |
#ifdef UG_DIM_3 |
| 1364 |
if (snprintf (data, max_data_size, "bn %d %f %f", (int) pid, |
| 1365 |
(float) bp->local[0][0], |
| 1366 |
(float) bp->local[0][1]) > max_data_size) |
| 1367 |
return (1); |
| 1368 |
#endif |
| 1369 |
|
| 1370 |
return (0); |
| 1371 |
} |
| 1372 |
|
| 1373 |
/* domain interface function: for description see domain.h */ |
| 1374 |
INT NS_DIM_PREFIX |
| 1375 |
BNDP_SurfaceId (BNDP * aBndP, INT * n, INT i) |
| 1376 |
{ |
| 1377 |
BND_PS *ps; |
| 1378 |
|
| 1379 |
if (i < 0) |
| 1380 |
return (1); |
| 1381 |
|
| 1382 |
ps = (BND_PS *) aBndP; |
| 1383 |
if (ps == NULL) |
| 1384 |
return (-1); |
| 1385 |
|
| 1386 |
return ps->patch_id; |
| 1387 |
} |
| 1388 |
|
| 1389 |
/* domain interface function: for description see domain.h */ |
| 1390 |
INT NS_DIM_PREFIX |
| 1391 |
BNDP_Dispose (HEAP * Heap, BNDP * theBndP) |
| 1392 |
{ |
| 1393 |
BND_PS *ps; |
| 1394 |
|
| 1395 |
if (theBndP == NULL) |
| 1396 |
return (0); |
| 1397 |
|
| 1398 |
ps = (BND_PS *) theBndP; |
| 1399 |
DisposeMem(Heap, ps); |
| 1400 |
return 0; |
| 1401 |
} |
| 1402 |
|
| 1403 |
/* domain interface function: for description see domain.h */ |
| 1404 |
INT NS_DIM_PREFIX |
| 1405 |
BNDS_Dispose (HEAP * Heap, BNDS * theBndS) |
| 1406 |
{ |
| 1407 |
BND_PS *ps; |
| 1408 |
|
| 1409 |
if (theBndS == NULL) |
| 1410 |
return (0); |
| 1411 |
|
| 1412 |
ps = (BND_PS *) theBndS; |
| 1413 |
DisposeMem(Heap, ps); |
| 1414 |
return 0; |
| 1415 |
} |
| 1416 |
|
| 1417 |
/* domain interface function: for description see domain.h */ |
| 1418 |
INT NS_DIM_PREFIX |
| 1419 |
BNDP_SaveBndP (BNDP * BndP) |
| 1420 |
{ |
| 1421 |
BND_PS *bp; |
| 1422 |
INT i, j; |
| 1423 |
int iList[2]; |
| 1424 |
double dList[DIM]; |
| 1425 |
|
| 1426 |
iList[0] = BND_PATCH_ID (BndP); |
| 1427 |
iList[1] = BND_N (BndP); |
| 1428 |
if (Bio_Write_mint (2, iList)) |
| 1429 |
return (1); |
| 1430 |
|
| 1431 |
bp = (BND_PS *) BndP; |
| 1432 |
for (i = 0; i < BND_N (BndP); i++) |
| 1433 |
{ |
| 1434 |
for (j = 0; j < DIM - 1; j++) |
| 1435 |
dList[j] = bp->local[i][j]; |
| 1436 |
if (Bio_Write_mdouble (DIM - 1, dList)) |
| 1437 |
return (1); |
| 1438 |
} |
| 1439 |
|
| 1440 |
return (0); |
| 1441 |
} |
| 1442 |
|
| 1443 |
|
| 1444 |
INT NS_DIM_PREFIX |
| 1445 |
BNDP_SaveBndP_Ext (BNDP * BndP) |
| 1446 |
{ |
| 1447 |
BND_PS *bp; |
| 1448 |
INT i, j; |
| 1449 |
int iList[2]; |
| 1450 |
double dList[DIM]; |
| 1451 |
|
| 1452 |
/* TODO: save free boundary points */ |
| 1453 |
iList[0] = BND_PATCH_ID (BndP); |
| 1454 |
iList[1] = BND_N (BndP); |
| 1455 |
if (Bio_Write_mint (2, iList)) |
| 1456 |
return (1); |
| 1457 |
|
| 1458 |
bp = (BND_PS *) BndP; |
| 1459 |
for (i = 0; i < BND_N (BndP); i++) |
| 1460 |
{ |
| 1461 |
for (j = 0; j < DIM - 1; j++) |
| 1462 |
dList[j] = bp->local[i][j]; |
| 1463 |
if (Bio_Write_mdouble (DIM - 1, dList)) |
| 1464 |
return (1); |
| 1465 |
} |
| 1466 |
|
| 1467 |
return (0); |
| 1468 |
} |
| 1469 |
|
| 1470 |
/* domain interface function: for description see domain.h */ |
| 1471 |
BNDP *NS_DIM_PREFIX |
| 1472 |
BNDP_LoadBndP (STD_BVP *theBVP, HEAP * Heap) |
| 1473 |
{ |
| 1474 |
BND_PS *bp; |
| 1475 |
int i, j, pid, n; |
| 1476 |
int iList[2]; |
| 1477 |
double dList[DIM]; |
| 1478 |
|
| 1479 |
if (Bio_Read_mint (2, iList)) |
| 1480 |
return (NULL); |
| 1481 |
pid = iList[0]; |
| 1482 |
n = iList[1]; |
| 1483 |
bp = |
| 1484 |
(BND_PS *) GetFreelistMemory (Heap, |
| 1485 |
(n - 1) * sizeof (COORD_BND_VECTOR) + |
| 1486 |
sizeof (BND_PS)); |
| 1487 |
bp->n = n; |
| 1488 |
bp->patch_id = pid; |
| 1489 |
for (i = 0; i < n; i++) |
| 1490 |
{ |
| 1491 |
if (Bio_Read_mdouble (DIM - 1, dList)) |
| 1492 |
return (NULL); |
| 1493 |
for (j = 0; j < DIM - 1; j++) |
| 1494 |
bp->local[i][j] = dList[j]; |
| 1495 |
} |
| 1496 |
|
| 1497 |
return ((BNDP *) bp); |
| 1498 |
} |
| 1499 |
|
| 1500 |
BNDP *NS_DIM_PREFIX |
| 1501 |
BNDP_LoadBndP_Ext (void) |
| 1502 |
{ |
| 1503 |
BND_PS *bp; |
| 1504 |
int i, j, pid, n; |
| 1505 |
int iList[2]; |
| 1506 |
double dList[DIM - 1]; |
| 1507 |
|
| 1508 |
if (Bio_Read_mint (2, iList)) |
| 1509 |
return (NULL); |
| 1510 |
pid = iList[0]; |
| 1511 |
n = iList[1]; |
| 1512 |
bp = |
| 1513 |
(BND_PS *) malloc ((n - 1) * sizeof (COORD_BND_VECTOR) + sizeof (BND_PS)); |
| 1514 |
bp->n = n; |
| 1515 |
bp->patch_id = pid; |
| 1516 |
for (i = 0; i < n; i++) |
| 1517 |
{ |
| 1518 |
if (Bio_Read_mdouble (DIM - 1, dList)) |
| 1519 |
return (NULL); |
| 1520 |
for (j = 0; j < DIM - 1; j++) |
| 1521 |
bp->local[i][j] = dList[j]; |
| 1522 |
} |
| 1523 |
|
| 1524 |
return ((BNDP *) bp); |
| 1525 |
} |
| 1526 |
|
| 1527 |
/** @} */ |