| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
#include <alberta/alberta.h> |
| 61 |
#include <alberta/albas.h> |
| 62 |
|
| 63 |
#include "alberta-demo.h" |
| 64 |
|
| 65 |
#include <oem_block_solve.h> |
| 66 |
#include <sys/times.h> |
| 67 |
#include <unistd.h> |
| 68 |
|
| 69 |
#include "static-condensation.h" |
| 70 |
|
| 71 |
static int do_graphics = true; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
static const FE_SPACE *u_fe_space; |
| 82 |
static const FE_SPACE *p_fe_space; |
| 83 |
static DOF_REAL_VEC_D *u_h; |
| 84 |
static DOF_REAL_VEC *p_h; |
| 85 |
|
| 86 |
static DOF_REAL_VEC_D *f_h; |
| 87 |
static DOF_REAL_VEC *g_h; |
| 88 |
static DOF_SCHAR_VEC *bound; |
| 89 |
static DOF_MATRIX *A; |
| 90 |
|
| 91 |
static DOF_MATRIX *B; |
| 92 |
static DOF_MATRIX *Bt; |
| 93 |
static DOF_MATRIX *Yproj; |
| 94 |
static DOF_MATRIX *Yprec; |
| 95 |
|
| 96 |
static const EL_MATRIX_INFO *matrix_info; |
| 97 |
static EL_MATRIX_INFO B_minfo; |
| 98 |
|
| 99 |
|
| 100 |
static const FE_SPACE *u_fsp_single; |
| 101 |
|
| 102 |
static DOF_MATRIX *A_single; |
| 103 |
static DOF_MATRIX *B_single; |
| 104 |
static DOF_MATRIX *Bt_single; |
| 105 |
static DOF_MATRIX *C_single; |
| 106 |
|
| 107 |
static DOF_REAL_D_VEC *fh_single; |
| 108 |
static DOF_REAL_VEC_D *uh_single; |
| 109 |
static DOF_REAL_VEC *ph_single; |
| 110 |
static DOF_REAL_VEC *gh_single; |
| 111 |
static DOF_REAL_VEC_D *uh; |
| 112 |
|
| 113 |
static BLOCK_DOF_VEC *up_h = NULL; |
| 114 |
static BLOCK_DOF_VEC *load_vector = NULL; |
| 115 |
static BLOCK_DOF_MATRIX *system_matrix = NULL; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
static REAL mu = 1.0; |
| 120 |
static REAL nu = 1.0; |
| 121 |
static REAL alpha_robin = 1.0; |
| 122 |
|
| 123 |
|
| 124 |
static REAL gauss_bell = 10.0; |
| 125 |
static REAL_D p_shift; |
| 126 |
static REAL_D v_shift; |
| 127 |
|
| 128 |
static BNDRY_FLAGS dirichlet_bndry; |
| 129 |
static BNDRY_FLAGS stress_bndry; |
| 130 |
|
| 131 |
static REAL ticks_per_second; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
struct ellipt_leaf_data |
| 144 |
{ |
| 145 |
REAL estimate; |
| 146 |
}; |
| 147 |
|
| 148 |
static REAL *rw_el_est(EL *el) |
| 149 |
{ |
| 150 |
if (IS_LEAF_EL(el)) |
| 151 |
return &((struct ellipt_leaf_data *)LEAF_DATA(el))->estimate; |
| 152 |
else |
| 153 |
return NULL; |
| 154 |
} |
| 155 |
|
| 156 |
static REAL get_el_est(EL *el) |
| 157 |
{ |
| 158 |
if (IS_LEAF_EL(el)) |
| 159 |
return ((struct ellipt_leaf_data *)LEAF_DATA(el))->estimate; |
| 160 |
else |
| 161 |
return 0.0; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
static const REAL *u(const REAL_D _x, REAL_D res) |
| 172 |
{ |
| 173 |
static REAL_D space; |
| 174 |
REAL r; |
| 175 |
|
| 176 |
if (!res) { |
| 177 |
res = space; |
| 178 |
} |
| 179 |
|
| 180 |
AXPBY_DOW(1.0, _x, -1.0, v_shift, res); |
| 181 |
|
| 182 |
r = NORM_DOW(res); |
| 183 |
|
| 184 |
SCAL_DOW(1.0/POW_DOW(r), res); |
| 185 |
|
| 186 |
return res; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
static const REAL_D *grd_u(const REAL_D _x, REAL_DD res) |
| 194 |
{ |
| 195 |
static REAL_DD space; |
| 196 |
REAL_D x; |
| 197 |
REAL r; |
| 198 |
int i; |
| 199 |
|
| 200 |
if (!res) { |
| 201 |
res = space; |
| 202 |
} |
| 203 |
|
| 204 |
AXPBY_DOW(1.0, _x, -1.0, v_shift, x); |
| 205 |
|
| 206 |
r = NORM_DOW(x); |
| 207 |
|
| 208 |
for (i = 0; i < DIM_OF_WORLD; i++) { |
| 209 |
AXEY_DOW(-(REAL)DIM_OF_WORLD*x[i], x, res[i]); |
| 210 |
res[i][i] += SQR(r); |
| 211 |
SCAL_DOW(pow(r, (REAL)(-DIM_OF_WORLD - 2)), res[i]); |
| 212 |
} |
| 213 |
return (const REAL_D *)res; |
| 214 |
} |
| 215 |
|
| 216 |
static REAL p(const REAL_D _x) |
| 217 |
{ |
| 218 |
REAL_D x; |
| 219 |
|
| 220 |
AXPBY_DOW(1.0, _x, -1.0, p_shift, x); |
| 221 |
|
| 222 |
return exp(-gauss_bell*SCP_DOW(x,x)); |
| 223 |
} |
| 224 |
|
| 225 |
static const REAL *grd_p(const REAL_D _x, REAL_D res) |
| 226 |
{ |
| 227 |
static REAL_D space; |
| 228 |
REAL_D x; |
| 229 |
|
| 230 |
if (!res) { |
| 231 |
res = space; |
| 232 |
} |
| 233 |
|
| 234 |
AXPBY_DOW(1.0, _x, -1.0, p_shift, x); |
| 235 |
|
| 236 |
AXEY_DOW(-2.0*gauss_bell*p(_x), x, res); |
| 237 |
|
| 238 |
return res; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
static const REAL *g(const REAL_D x, REAL_D res) |
| 247 |
{ |
| 248 |
return u(x, res); |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
static const REAL *f(const REAL_D _x, REAL_D res) |
| 253 |
{ |
| 254 |
static REAL_D space; |
| 255 |
REAL_D u_val; |
| 256 |
|
| 257 |
if (!res) { |
| 258 |
res = space; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
AXPY_DOW(mu, u(_x, u_val), (REAL *)grd_p(_x, res)); |
| 263 |
|
| 264 |
return res; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
static const REAL *g_stress(const REAL_D x, |
| 271 |
const REAL_D normal, |
| 272 |
REAL_D res) |
| 273 |
{ |
| 274 |
static REAL_D space; |
| 275 |
int i; |
| 276 |
REAL_DD Dv; |
| 277 |
REAL p_val; |
| 278 |
|
| 279 |
if (!res) { |
| 280 |
res = space; |
| 281 |
} |
| 282 |
|
| 283 |
grd_u(x, Dv); |
| 284 |
p_val = p(x); |
| 285 |
MSCAL_DOW(2.0*nu, Dv); |
| 286 |
for (i = 0; i < DIM_OF_WORLD; i++) { |
| 287 |
Dv[i][i] -= p_val; |
| 288 |
} |
| 289 |
|
| 290 |
SET_DOW(0.0, res); |
| 291 |
MV_DOW((const REAL_D *)Dv, normal, res); |
| 292 |
|
| 293 |
return res; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
typedef struct op_data |
| 324 |
{ |
| 325 |
REAL_BD Lambda; |
| 326 |
REAL det; |
| 327 |
REAL LALt_factor; |
| 328 |
REAL c_factor; |
| 329 |
REAL wall_det[N_WALLS_MAX]; |
| 330 |
} OP_DATA; |
| 331 |
|
| 332 |
static bool u_init_element(const EL_INFO *el_info, |
| 333 |
const QUAD *quad[3], |
| 334 |
void *ud) |
| 335 |
{ |
| 336 |
OP_DATA *data = (OP_DATA *)ud; |
| 337 |
|
| 338 |
data->det = el_grd_lambda(el_info, data->Lambda); |
| 339 |
|
| 340 |
data->LALt_factor = data->det * nu; |
| 341 |
data->c_factor = data->det * mu; |
| 342 |
|
| 343 |
|
| 344 |
return false; |
| 345 |
} |
| 346 |
|
| 347 |
static bool p_init_element(const EL_INFO *el_info, |
| 348 |
const QUAD *quad[3], |
| 349 |
void *ud) |
| 350 |
{ |
| 351 |
OP_DATA *data = (OP_DATA *)ud; |
| 352 |
|
| 353 |
data->det = el_grd_lambda(el_info, data->Lambda); |
| 354 |
|
| 355 |
data->LALt_factor = data->det; |
| 356 |
data->c_factor = data->det; |
| 357 |
|
| 358 |
return 0; |
| 359 |
} |
| 360 |
|
| 361 |
static bool dg_wall_init_element(const EL_INFO *el_info, int wall, |
| 362 |
const WALL_QUAD *quad[3], void *ud) |
| 363 |
{ |
| 364 |
OP_DATA *info = (OP_DATA *)ud; |
| 365 |
|
| 366 |
info->wall_det[wall] = 1e3; |
| 367 |
|
| 368 |
info->c_factor = info->wall_det[wall]; |
| 369 |
|
| 370 |
return false; |
| 371 |
} |
| 372 |
|
| 373 |
static bool fv_wall_init_element(const EL_INFO *el_info, int wall, |
| 374 |
const WALL_QUAD *quad[3], void *ud) |
| 375 |
{ |
| 376 |
OP_DATA *info = (OP_DATA *)ud; |
| 377 |
REAL det = get_wall_normal(el_info, wall, NULL); |
| 378 |
|
| 379 |
#define VAL (1.0/(REAL)N_LAMBDA_MAX) |
| 380 |
const REAL_B c_b = INIT_BARY_MAX(VAL, VAL, VAL, VAL); |
| 381 |
#undef VAL |
| 382 |
EL_INFO neigh_info[1]; |
| 383 |
const EL_GEOM_CACHE *elgc = |
| 384 |
fill_el_geom_cache(el_info, FILL_EL_WALL_REL_ORIENTATION(wall)); |
| 385 |
REAL_D c, cn; |
| 386 |
REAL delta; |
| 387 |
|
| 388 |
fill_neigh_el_info(neigh_info, el_info, wall, elgc->rel_orientation[wall]); |
| 389 |
|
| 390 |
coord_to_world(el_info, c_b, c); |
| 391 |
coord_to_world(neigh_info, c_b, cn); |
| 392 |
delta = DIST_DOW(c, cn); |
| 393 |
|
| 394 |
info->c_factor = info->wall_det[wall] = det / delta; |
| 395 |
|
| 396 |
return false; |
| 397 |
} |
| 398 |
|
| 399 |
static bool dg_fv_neigh_init_element(const EL_INFO *el_info, int wall, |
| 400 |
const WALL_QUAD *quad[3], void *ud) |
| 401 |
{ |
| 402 |
OP_DATA *info = (OP_DATA *)ud; |
| 403 |
|
| 404 |
info->c_factor = -info->wall_det[wall]; |
| 405 |
|
| 406 |
return false; |
| 407 |
} |
| 408 |
|
| 409 |
static const REAL_B *LALt(const EL_INFO *el_info, |
| 410 |
const QUAD *quad, int iq, void *ud) |
| 411 |
{ |
| 412 |
OP_DATA *data = (OP_DATA *)ud; |
| 413 |
int i, j, dim = el_info->mesh->dim; |
| 414 |
static REAL_BB LALt; |
| 415 |
|
| 416 |
for (i = 0; i <= dim; i++) { |
| 417 |
for (j = i; j <= dim; j++) { |
| 418 |
LALt[j][i] = LALt[i][j] = |
| 419 |
data->LALt_factor*SCP_DOW(data->Lambda[i], data->Lambda[j]); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
return (const REAL_B *)LALt; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
#if 1 |
| 441 |
static const REAL_BDD *LDDLt(const EL_INFO *el_info, const QUAD *quad, |
| 442 |
int iq, void *ud) |
| 443 |
{ |
| 444 |
static REAL_BBDD LDDLt; |
| 445 |
OP_DATA *info = (OP_DATA *)ud; |
| 446 |
int m, n, i, j, dim = el_info->mesh->dim; |
| 447 |
REAL factor = info->LALt_factor; |
| 448 |
|
| 449 |
for (m = 0; m < DIM_OF_WORLD; m++) |
| 450 |
for (n = 0; n < DIM_OF_WORLD; n++) |
| 451 |
for (i = 0; i <= dim; i++) |
| 452 |
for (j = 0; j <= dim; j++) { |
| 453 |
LDDLt[i][j][m][n] = 0.0; |
| 454 |
|
| 455 |
if(m == n) { |
| 456 |
LDDLt[i][j][m][m] += SCP_DOW(info->Lambda[i], info->Lambda[j]); |
| 457 |
} |
| 458 |
|
| 459 |
LDDLt[i][j][m][n] += info->Lambda[i][n] * info->Lambda[j][m]; |
| 460 |
LDDLt[i][j][m][n] *= factor; |
| 461 |
} |
| 462 |
return (const REAL_BDD *)LDDLt; |
| 463 |
} |
| 464 |
#else |
| 465 |
static const REAL_BDD *LDDLt(const EL_INFO *el_info, |
| 466 |
const QUAD *quad, int iq, void *ud) |
| 467 |
{ |
| 468 |
static REAL_BBDD LDDLt; |
| 469 |
struct op_info *info = (struct op_info *)ud; |
| 470 |
REAL value; |
| 471 |
int alpha, beta, k, m; |
| 472 |
int dim = el_info->mesh->dim; |
| 473 |
REAL factor = info->LALt_factor; |
| 474 |
|
| 475 |
for (alpha = 0; alpha < N_VERTICES(dim); alpha++) { |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
MSET_DOW(0.0, LDDLt[alpha][alpha]); |
| 480 |
value = factor*SCP_DOW(info->Lambda[alpha], info->Lambda[alpha]); |
| 481 |
MSCMAXPY_DOW(1.0, value, LDDLt[alpha][alpha]); |
| 482 |
for (beta = alpha+1; beta < N_VERTICES(dim); beta++) { |
| 483 |
MSET_DOW(0.0, LDDLt[alpha][beta]); |
| 484 |
MSET_DOW(0.0, LDDLt[beta][alpha]); |
| 485 |
value = factor*SCP_DOW(info->Lambda[alpha], info->Lambda[beta]); |
| 486 |
MSCMAXPY_DOW(1.0, value, LDDLt[alpha][beta]); |
| 487 |
MSCMAXPY_DOW(1.0, value, LDDLt[beta][alpha]); |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
for (m = 0; m < DIM_OF_WORLD; m++) { |
| 495 |
|
| 496 |
value = factor*SQR(info->Lambda[alpha][m]); |
| 497 |
LDDLt[alpha][alpha][m][m] += value; |
| 498 |
for (k = m+1; k < DIM_OF_WORLD; k++) { |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
value = factor*info->Lambda[alpha][m]*info->Lambda[alpha][k]; |
| 503 |
LDDLt[alpha][alpha][m][k] += value; |
| 504 |
LDDLt[alpha][alpha][k][m] += value; |
| 505 |
} |
| 506 |
for (beta = alpha+1; beta < N_VERTICES(dim); beta++) { |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
value = factor*info->Lambda[alpha][m]*info->Lambda[beta][m]; |
| 511 |
LDDLt[alpha][beta][m][m] += value; |
| 512 |
LDDLt[beta][alpha][m][m] += value; |
| 513 |
for (k = m+1; k < DIM_OF_WORLD; k++) { |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
value = factor*info->Lambda[alpha][m]*info->Lambda[beta][k]; |
| 518 |
LDDLt[alpha][beta][m][k] += value; |
| 519 |
LDDLt[beta][alpha][k][m] += value; |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
return (const REAL_BDD *)LDDLt; |
| 525 |
} |
| 526 |
#endif |
| 527 |
|
| 528 |
|
| 529 |
const REAL_D *B_Lb1(const EL_INFO *el_info, const QUAD *quad, int iq, void *ud) |
| 530 |
{ |
| 531 |
OP_DATA *info = (OP_DATA *)ud; |
| 532 |
static REAL_BD B_Lb1; |
| 533 |
int i; |
| 534 |
|
| 535 |
for (i = 0; i < N_VERTICES(el_info->mesh->dim); i++) { |
| 536 |
AXEY_DOW(-info->det, info->Lambda[i], B_Lb1[i]); |
| 537 |
} |
| 538 |
|
| 539 |
return (const REAL_D *)B_Lb1; |
| 540 |
} |
| 541 |
|
| 542 |
static REAL c(const EL_INFO *el_info, const QUAD *quad, int iq, void *ud) |
| 543 |
{ |
| 544 |
OP_DATA *info = (OP_DATA *)ud; |
| 545 |
|
| 546 |
return info->c_factor; |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
static void build(MESH *mesh, U_CHAR flag) |
| 551 |
{ |
| 552 |
FUNCNAME("build"); |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
static const EL_MATRIX_INFO *Yproj_minfo; |
| 558 |
static const EL_MATRIX_INFO *Yprec_minfo; |
| 559 |
|
| 560 |
static OP_DATA opi_udata; |
| 561 |
|
| 562 |
const QUAD *quad; |
| 563 |
REAL flux; |
| 564 |
|
| 565 |
dof_compress(mesh); |
| 566 |
MSG("%d DOFs for %s\n", dof_real_vec_d_length(u_fe_space), u_fe_space->name); |
| 567 |
MSG("%d DOFs for %s\n", p_fe_space->admin->size_used, p_fe_space->name); |
| 568 |
|
| 569 |
if (!matrix_info) { |
| 570 |
OPERATOR_INFO o_info = { NULL, }; |
| 571 |
OPERATOR_INFO B_oinfo = { NULL, }; |
| 572 |
OPERATOR_INFO Yproj_oinfo = { NULL, }; |
| 573 |
OPERATOR_INFO Yprec_oinfo = { NULL, }; |
| 574 |
bool p_disc; |
| 575 |
|
| 576 |
o_info.row_fe_space = o_info.col_fe_space = u_fe_space; |
| 577 |
o_info.init_element = u_init_element; |
| 578 |
o_info.user_data = &opi_udata; |
| 579 |
o_info.LALt.real_dd = LDDLt; |
| 580 |
o_info.LALt_type = MATENT_REAL_DD; |
| 581 |
o_info.LALt_pw_const = true; |
| 582 |
o_info.LALt_symmetric = false ; |
| 583 |
o_info.c.real = c; |
| 584 |
o_info.c_type = MATENT_REAL; |
| 585 |
o_info.c_pw_const = true; |
| 586 |
BNDRY_FLAGS_CPY(o_info.dirichlet_bndry, |
| 587 |
dirichlet_bndry); |
| 588 |
o_info.fill_flag = CALL_LEAF_EL|FILL_COORDS; |
| 589 |
matrix_info = fill_matrix_info(&o_info, NULL); |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
B_oinfo.row_fe_space = u_fe_space; |
| 596 |
B_oinfo.col_fe_space = p_fe_space; |
| 597 |
B_oinfo.init_element = p_init_element; |
| 598 |
B_oinfo.user_data = o_info.user_data; |
| 599 |
B_oinfo.Lb1.real_d = B_Lb1; |
| 600 |
B_oinfo.Lb_type = MATENT_REAL_D; |
| 601 |
B_oinfo.Lb1_pw_const = true; |
| 602 |
B_oinfo.fill_flag = CALL_LEAF_EL|FILL_COORDS; |
| 603 |
fill_matrix_info(&B_oinfo, &B_minfo); |
| 604 |
|
| 605 |
|
| 606 |
Yproj_oinfo.row_fe_space = Yproj_oinfo.col_fe_space = p_fe_space; |
| 607 |
Yproj_oinfo.init_element = p_init_element; |
| 608 |
Yproj_oinfo.user_data = o_info.user_data; |
| 609 |
Yproj_oinfo.c.real = c; |
| 610 |
Yproj_oinfo.c_pw_const = true; |
| 611 |
Yproj_oinfo.fill_flag = CALL_LEAF_EL|FILL_COORDS; |
| 612 |
Yproj_minfo = fill_matrix_info(&Yproj_oinfo, NULL); |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
Yprec_oinfo.row_fe_space = Yprec_oinfo.col_fe_space = p_fe_space; |
| 619 |
Yprec_oinfo.init_element = p_init_element; |
| 620 |
Yprec_oinfo.user_data = o_info.user_data; |
| 621 |
Yprec_oinfo.LALt.real = LALt; |
| 622 |
Yprec_oinfo.LALt_symmetric = true; |
| 623 |
Yprec_oinfo.LALt_pw_const = true; |
| 624 |
Yprec_oinfo.fill_flag = CALL_LEAF_EL|FILL_COORDS; |
| 625 |
|
| 626 |
p_disc = |
| 627 |
p_fe_space->bas_fcts->n_dof[CENTER] == p_fe_space->bas_fcts->n_bas_fcts; |
| 628 |
if (!p_disc) { |
| 629 |
Yprec_minfo = fill_matrix_info(&Yprec_oinfo, NULL); |
| 630 |
} else { |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
BNDRY_OPERATOR_INFO el_bop_info = { NULL, }; |
| 635 |
BNDRY_OPERATOR_INFO neigh_bop_info = { NULL, }; |
| 636 |
bool do_fv = p_fe_space->bas_fcts->degree == 0; |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
el_bop_info.row_fe_space = p_fe_space; |
| 645 |
el_bop_info.init_element = |
| 646 |
do_fv ? fv_wall_init_element : dg_wall_init_element; |
| 647 |
el_bop_info.c.real = c; |
| 648 |
el_bop_info.c_pw_const = true; |
| 649 |
el_bop_info.user_data = o_info.user_data; |
| 650 |
BNDRY_FLAGS_INIT(el_bop_info.bndry_type); |
| 651 |
|
| 652 |
el_bop_info.fill_flag = CALL_LEAF_EL|FILL_COORDS|FILL_OPP_COORDS; |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
neigh_bop_info = el_bop_info; |
| 658 |
neigh_bop_info.init_element = dg_fv_neigh_init_element; |
| 659 |
neigh_bop_info.discontinuous = true; |
| 660 |
|
| 661 |
Yprec_minfo = fill_matrix_info_ext( |
| 662 |
NULL, do_fv ? NULL : &Yprec_oinfo, &el_bop_info, &neigh_bop_info, NULL); |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
clear_dof_matrix(A); |
| 668 |
update_matrix(A, matrix_info, NoTranspose); |
| 669 |
|
| 670 |
|
| 671 |
dof_set_dow(0.0, f_h); |
| 672 |
quad = get_quadrature(mesh->dim, 2*u_fe_space->bas_fcts->degree - 2); |
| 673 |
L2scp_fct_bas_dow(f, quad, f_h); |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
boundary_conditions_dow(NULL , f_h, u_h, bound, |
| 684 |
dirichlet_bndry, |
| 685 |
g, g_stress, |
| 686 |
mu == 0.0 ? -1.0 : 0.0 , |
| 687 |
NULL); |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
clear_dof_matrix(B); |
| 693 |
BNDRY_FLAGS_CPY(B_minfo.dirichlet_bndry, dirichlet_bndry); |
| 694 |
update_matrix(B, &B_minfo, NoTranspose); |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
clear_dof_matrix(Bt); |
| 700 |
BNDRY_FLAGS_INIT(B_minfo.dirichlet_bndry); |
| 701 |
update_matrix(Bt, &B_minfo, Transpose); |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
dof_set(0.0, g_h); |
| 711 |
flux = sp_dirichlet_bound_dow_scl(NoTranspose, Bt, bound, u_h, g_h); |
| 712 |
|
| 713 |
MSG("Total flux-excess: %e\n", flux); |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
clear_block_dof_matrix(system_matrix); |
| 719 |
#if 0 |
| 720 |
clear_dof_matrix(A_single); |
| 721 |
clear_dof_matrix(B_single); |
| 722 |
clear_dof_matrix(Bt_single); |
| 723 |
clear_dof_matrix(C_single); |
| 724 |
#endif |
| 725 |
dof_set_d(0.0, fh_single); |
| 726 |
|
| 727 |
condense_mini_spp_dd(u_h, f_h, g_h, dirichlet_bndry, |
| 728 |
(EL_MATRIX_INFO *)matrix_info, &B_minfo, |
| 729 |
system_matrix, up_h, load_vector); |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
clear_dof_matrix(Yproj); |
| 740 |
update_matrix(Yproj, Yproj_minfo, NoTranspose); |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
clear_dof_matrix(Yprec); |
| 748 |
update_matrix(Yprec, Yprec_minfo, NoTranspose); |
| 749 |
robin_bound(Yprec, stress_bndry, alpha_robin, NULL , 1.0); |
| 750 |
|
| 751 |
|
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
static void block_solve(MESH *mesh, REAL norm_res) |
| 761 |
{ |
| 762 |
FUNCNAME("block_solve"); |
| 763 |
|
| 764 |
|
| 765 |
static REAL tol = 3.125e-10, ssor_omega = 1.0; |
| 766 |
static int max_iter = 1000, info = 2, restart = 0, ssor_iter = 1; |
| 767 |
static OEM_SOLVER solver = NoSolver; |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
static DOF_REAL_VEC *res; |
| 773 |
static REAL norm_block_res, seconds, init_tol = 0; |
| 774 |
static int i, reach_tol = 20; |
| 775 |
static clock_t time_block, time_block_solve; |
| 776 |
struct tms tms; |
| 777 |
|
| 778 |
const PRECON *precon; |
| 779 |
static BLOCK_PRECON_TYPE block_prec_type; |
| 780 |
|
| 781 |
block_prec_type.block_type = BlkDiagPrecon; |
| 782 |
block_prec_type.precon_type[0].type = HBPrecon; |
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
block_prec_type.precon_type[1].type = DiagPrecon; |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
if (solver == NoSolver) |
| 791 |
{ |
| 792 |
tol = 1.e-8; |
| 793 |
GET_PARAMETER(1, "block->solver", "%d", &solver); |
| 794 |
GET_PARAMETER(1, "block->solver tolerance", "%f", &tol); |
| 795 |
|
| 796 |
GET_PARAMETER(1, "block->solver max iteration", "%d", &max_iter); |
| 797 |
GET_PARAMETER(1, "block->solver info", "%d", &info); |
| 798 |
GET_PARAMETER(1, "block->precon ssor omega", "%f", &ssor_omega); |
| 799 |
GET_PARAMETER(1, "block->precon ssor iter", "%d", &ssor_iter); |
| 800 |
if (solver == GMRes) |
| 801 |
GET_PARAMETER(1, "block->solver restart", "%d", &restart); |
| 802 |
} |
| 803 |
|
| 804 |
res = get_dof_real_vec("res", p_fe_space); |
| 805 |
|
| 806 |
if(init_tol == 0.0) { |
| 807 |
init_tol = tol; |
| 808 |
} |
| 809 |
|
| 810 |
for (i = 0; i < reach_tol; i++) { |
| 811 |
dof_copy_dow((const DOF_REAL_VEC_D *)load_vector->dof_vec[0], |
| 812 |
up_h->dof_vec[0]); |
| 813 |
dof_scal(0.0, (DOF_REAL_VEC *)up_h->dof_vec[1]); |
| 814 |
|
| 815 |
times(&tms); |
| 816 |
time_block = tms.tms_utime; |
| 817 |
precon = init_oem_block_precon(system_matrix, NULL, info, |
| 818 |
&block_prec_type); |
| 819 |
oem_block_solve(system_matrix, NULL , load_vector, up_h, |
| 820 |
solver, tol, precon , |
| 821 |
restart, max_iter, info); |
| 822 |
|
| 823 |
dof_mv_scl_dow(NoTranspose, system_matrix->dof_mat[1][0], NULL, |
| 824 |
up_h->dof_vec[0], res); |
| 825 |
dof_gemv(NoTranspose, 1.0, system_matrix->dof_mat[1][1], NULL, |
| 826 |
(const DOF_REAL_VEC *)up_h->dof_vec[1], 1.0, res); |
| 827 |
dof_axpy(-1.0, (const DOF_REAL_VEC *)load_vector->dof_vec[1], res); |
| 828 |
norm_block_res = dof_nrm2(res); |
| 829 |
|
| 830 |
MSG("\n Block-tolerance = %.8e\n", tol); |
| 831 |
if(norm_block_res > norm_res) { |
| 832 |
tol = tol/sqrt(2); |
| 833 |
} else { |
| 834 |
i = reach_tol; |
| 835 |
tol = init_tol; |
| 836 |
} |
| 837 |
MSG("\n B*_single uh + C_single ph - gh = %.8e \n\n", norm_block_res); |
| 838 |
times(&tms); |
| 839 |
time_block_solve = tms.tms_utime; |
| 840 |
seconds = ((REAL )(time_block_solve - time_block))/ ticks_per_second; |
| 841 |
|
| 842 |
MSG("\n ********* Block-solver-time: %f sec *******************\n\n", |
| 843 |
seconds); |
| 844 |
} |
| 845 |
|
| 846 |
expand_mini_spp_dd(up_h, f_h, uh, dirichlet_bndry, |
| 847 |
(EL_MATRIX_INFO *)matrix_info, &B_minfo); |
| 848 |
|
| 849 |
dof_copy(g_h, res); |
| 850 |
dof_gemv_scl_dow(NoTranspose, 1.0, Bt, NULL, uh, -1.0, res); |
| 851 |
norm_block_res = dof_nrm2(res); |
| 852 |
MSG("\n B*u_h - g_h = %.8e \n\n", norm_block_res); |
| 853 |
|
| 854 |
free_dof_real_vec(res); |
| 855 |
|
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
static void solve(MESH *mesh) |
| 863 |
{ |
| 864 |
FUNCNAME("solve"); |
| 865 |
static REAL tol = 1.e-8, tol_incr = 1e2; |
| 866 |
static int miter = 1000, info = 2, restart = 0; |
| 867 |
static OEM_SOLVER solver = NoSolver, A_solver = NoSolver; |
| 868 |
static OEM_SOLVER Yproj_solver = NoSolver, Yprec_solver = NoSolver; |
| 869 |
static int A_miter, A_restart; |
| 870 |
static int Yproj_miter, Yprec_miter; |
| 871 |
const PRECON *A_prec, *Yproj_prec, *Yprec_prec; |
| 872 |
clock_t time, time_solve; |
| 873 |
struct tms tms; |
| 874 |
REAL norm_res, seconds; |
| 875 |
static DOF_REAL_VEC *res; |
| 876 |
static PRECON_TYPE A_prec_type = { |
| 877 |
BlkDiagPrecon, |
| 878 |
}; |
| 879 |
static PRECON_TYPE Yprec_prec_type = { |
| 880 |
DiagPrecon, |
| 881 |
}; |
| 882 |
static PRECON_TYPE Yproj_prec_type = { |
| 883 |
DiagPrecon, |
| 884 |
}; |
| 885 |
|
| 886 |
if (solver == NoSolver) { |
| 887 |
int i; |
| 888 |
|
| 889 |
GET_PARAMETER(1, "sp->solver", "%d", &solver); |
| 890 |
GET_PARAMETER(1, "sp->solver tolerance", "%f", &tol); |
| 891 |
GET_PARAMETER(1, "sp->solver tol incr", "%f", &tol_incr); |
| 892 |
GET_PARAMETER(1, "sp->solver max iteration", "%d", &miter); |
| 893 |
GET_PARAMETER(1, "sp->solver info", "%d", &info); |
| 894 |
if (solver == GMRes) { |
| 895 |
GET_PARAMETER(1, "sp->solver restart", "%d", &restart); |
| 896 |
} |
| 897 |
|
| 898 |
GET_PARAMETER(1, "sp->Auf solver", "%d", &A_solver); |
| 899 |
GET_PARAMETER(1, "sp->Auf max iteration", "%d", &A_miter); |
| 900 |
struct __precon_type *first = &A_prec_type.param.BlkDiag.precon[0]; |
| 901 |
GET_PARAMETER(1, "sp->Auf precon", "%d", &first->type); |
| 902 |
if (first->type == __SSORPrecon) { |
| 903 |
GET_PARAMETER(1, "sp->Auf precon ssor omega", "%f", |
| 904 |
&first->param.__SSOR.omega); |
| 905 |
GET_PARAMETER(1, "sp->Auf precon ssor iter", "%d", |
| 906 |
&first->param.__SSOR.n_iter); |
| 907 |
} else if (first->type == ILUkPrecon) { |
| 908 |
GET_PARAMETER(1, "sp->Auf precon ilu(k)", "%d", |
| 909 |
&first->param.ILUk.level); |
| 910 |
} |
| 911 |
for (i = 1; i < N_BLOCK_PRECON_MAX; ++i) { |
| 912 |
A_prec_type.param.BlkDiag.precon[i].type = DiagPrecon; |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
if (A_solver == GMRes) { |
| 917 |
GET_PARAMETER(1, "sp->Auf restart", "%d", &A_restart); |
| 918 |
} |
| 919 |
|
| 920 |
GET_PARAMETER(1, "sp->Yproj solver", "%d", &Yproj_solver); |
| 921 |
GET_PARAMETER(1, "sp->Yproj max iteration", "%d", &Yproj_miter); |
| 922 |
GET_PARAMETER(1, "sp->Yproj precon", "%d", &Yproj_prec_type.type); |
| 923 |
if (Yproj_prec_type.type == __SSORPrecon) { |
| 924 |
GET_PARAMETER(1, "sp->Yproj precon ssor omega", "%f", |
| 925 |
&Yproj_prec_type.param.__SSOR.omega); |
| 926 |
GET_PARAMETER(1, "sp->Yproj precon ssor iter", "%d", |
| 927 |
&Yproj_prec_type.param.__SSOR.n_iter); |
| 928 |
} else if (Yproj_prec_type.type == ILUkPrecon) { |
| 929 |
GET_PARAMETER(1, "sp->Yproj precon ilu(k)", "%d", |
| 930 |
&Yproj_prec_type.param.ILUk.level); |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
GET_PARAMETER(1, "sp->Yprec solver", "%d", &Yprec_solver); |
| 935 |
GET_PARAMETER(1, "sp->Yprec max iteration", "%d", &Yprec_miter); |
| 936 |
GET_PARAMETER(1, "sp->Yprec precon", "%d", &Yprec_prec_type.type); |
| 937 |
if (Yprec_prec_type.type == __SSORPrecon) { |
| 938 |
GET_PARAMETER(1, "sp->Yprec precon ssor omega", "%f", |
| 939 |
&Yprec_prec_type.param.__SSOR.omega); |
| 940 |
GET_PARAMETER(1, "sp->Yprec precon ssor iter", "%d", |
| 941 |
&Yprec_prec_type.param.__SSOR.n_iter); |
| 942 |
} else if (Yprec_prec_type.type == ILUkPrecon) { |
| 943 |
GET_PARAMETER(1, "sp->Yprec precon ilu(k)", "%d", |
| 944 |
&Yprec_prec_type.param.ILUk.level); |
| 945 |
} |
| 946 |
} |
| 947 |
dof_copy_dow(f_h, u_h); |
| 948 |
dof_set(0.0, p_h); |
| 949 |
|
| 950 |
times(&tms); |
| 951 |
time = tms.tms_utime; |
| 952 |
|
| 953 |
A_prec = init_precon_from_type(A, NULL , MAX(0, info-3), |
| 954 |
&A_prec_type); |
| 955 |
Yproj_prec = init_precon_from_type(Yproj, NULL , MAX(0, info-3), |
| 956 |
&Yproj_prec_type); |
| 957 |
if (mu > 0) { |
| 958 |
Yprec_prec = init_precon_from_type(Yprec, NULL , MAX(0, info-3), |
| 959 |
&Yprec_prec_type); |
| 960 |
} |
| 961 |
Yprec_prec = init_precon_from_type(Yprec, NULL , MAX(0, info-3), |
| 962 |
&Yprec_prec_type); |
| 963 |
oem_sp_solve_dow_scl(solver, tol, tol_incr, miter, info, |
| 964 |
A, NULL , A_solver, A_miter, A_prec, |
| 965 |
B, Bt, |
| 966 |
Yproj, Yproj_solver, Yproj_miter, Yproj_prec, |
| 967 |
mu > 0 ? Yprec : NULL, Yprec_solver, Yprec_miter, |
| 968 |
Yprec_prec, |
| 969 |
nu , mu , |
| 970 |
f_h, g_h, u_h, p_h); |
| 971 |
|
| 972 |
res = get_dof_real_vec("res", p_fe_space); |
| 973 |
dof_copy(g_h, res); |
| 974 |
dof_gemv_scl_dow(NoTranspose, 1.0, Bt, NULL, u_h, -1.0, res); |
| 975 |
norm_res = dof_nrm2(res); |
| 976 |
MSG("\n CG-tolerance = %.8e\n", tol); |
| 977 |
MSG("\n B*u_h - g_h = %.8e \n", norm_res); |
| 978 |
|
| 979 |
times(&tms); |
| 980 |
time_solve = tms.tms_utime; |
| 981 |
seconds = ((REAL )(time_solve - time))/ ticks_per_second; |
| 982 |
MSG("\n *************** Solver-time: %f sec *******************\n\n", |
| 983 |
seconds); |
| 984 |
|
| 985 |
block_solve(mesh, norm_res); |
| 986 |
|
| 987 |
free_dof_real_vec(res); |
| 988 |
|
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
static const REAL *r(REAL_D fx, |
| 1010 |
const EL_INFO *el_info, |
| 1011 |
const QUAD *quad, |
| 1012 |
int iq, |
| 1013 |
const REAL_D uh_at_qp, const REAL_DD grd_uh_at_qp) |
| 1014 |
{ |
| 1015 |
static REAL_D space; |
| 1016 |
static const QUAD_FAST *qfast; |
| 1017 |
static EL *el; |
| 1018 |
static EL_REAL_VEC *ph_loc; |
| 1019 |
static const EL_GEOM_CACHE *elgc; |
| 1020 |
static const QUAD_EL_CACHE *qelc; |
| 1021 |
REAL_D grd_ph; |
| 1022 |
|
| 1023 |
if (!fx) { |
| 1024 |
fx = space; |
| 1025 |
} |
| 1026 |
|
| 1027 |
|
| 1028 |
if (!qfast || |
| 1029 |
qfast->bas_fcts != p_fe_space->bas_fcts || qfast->quad != quad) { |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
qfast = get_quad_fast(p_fe_space->bas_fcts, quad, INIT_GRD_PHI); |
| 1034 |
|
| 1035 |
if (ph_loc) { |
| 1036 |
free_el_real_vec(ph_loc); |
| 1037 |
} |
| 1038 |
ph_loc = get_el_real_vec(p_fe_space->bas_fcts); |
| 1039 |
} |
| 1040 |
|
| 1041 |
if (el != el_info->el) { |
| 1042 |
el = el_info->el; |
| 1043 |
fill_el_real_vec(ph_loc, el, p_h); |
| 1044 |
if (!(el_info->fill_flag & FILL_COORDS)) { |
| 1045 |
qelc = fill_quad_el_cache(el_info, quad, |
| 1046 |
FILL_EL_QUAD_WORLD|FILL_EL_QUAD_LAMBDA); |
| 1047 |
} else { |
| 1048 |
elgc = fill_el_geom_cache(el_info, FILL_EL_LAMBDA); |
| 1049 |
qelc = fill_quad_el_cache(el_info, quad, FILL_EL_QUAD_WORLD); |
| 1050 |
} |
| 1051 |
} |
| 1052 |
|
| 1053 |
f(qelc->world[iq], fx); |
| 1054 |
SCAL_DOW(-1.0, fx); |
| 1055 |
|
| 1056 |
|
| 1057 |
AXPY_DOW(mu, uh_at_qp, fx); |
| 1058 |
|
| 1059 |
if (!(el_info->fill_flag & FILL_COORDS)) { |
| 1060 |
eval_grd_uh_fast(grd_ph, |
| 1061 |
(const REAL_D *)qelc->param.Lambda[iq], ph_loc, qfast, iq); |
| 1062 |
} else { |
| 1063 |
eval_grd_uh_fast(grd_ph, |
| 1064 |
(const REAL_D *)elgc->Lambda, ph_loc, qfast, iq); |
| 1065 |
} |
| 1066 |
|
| 1067 |
AXPY_DOW(1.0, grd_ph, fx); |
| 1068 |
|
| 1069 |
return (const REAL *)fx; |
| 1070 |
} |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
static const REAL *stress_res(REAL_D result, |
| 1077 |
const EL_INFO *el_info, |
| 1078 |
const QUAD *quad, int qp, |
| 1079 |
const REAL_D uh_qp, |
| 1080 |
const REAL_D normal) |
| 1081 |
{ |
| 1082 |
static REAL_D space; |
| 1083 |
static const QUAD_FAST *qfast; |
| 1084 |
static EL *el; |
| 1085 |
static EL_REAL_VEC *ph_loc; |
| 1086 |
REAL_D x; |
| 1087 |
REAL p_val; |
| 1088 |
|
| 1089 |
if (!result) { |
| 1090 |
result = space; |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
if (!qfast || qfast->quad != quad || |
| 1095 |
qfast->bas_fcts != p_fe_space->bas_fcts) { |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
qfast = get_quad_fast(p_fe_space->bas_fcts, quad, INIT_PHI); |
| 1100 |
if (ph_loc) { |
| 1101 |
free_el_real_vec(ph_loc); |
| 1102 |
} |
| 1103 |
ph_loc = get_el_real_vec(p_fe_space->bas_fcts); |
| 1104 |
} |
| 1105 |
|
| 1106 |
if (el != el_info->el) { |
| 1107 |
el = el_info->el; |
| 1108 |
fill_el_real_vec(ph_loc, el, p_h); |
| 1109 |
INIT_ELEMENT(el_info, qfast); |
| 1110 |
} |
| 1111 |
|
| 1112 |
p_val = eval_uh_fast(ph_loc, qfast, qp); |
| 1113 |
|
| 1114 |
coord_to_world(el_info, quad->lambda[qp], x); |
| 1115 |
|
| 1116 |
g_stress(x, normal, result); |
| 1117 |
AXPY_DOW(p_val, normal, result); |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
return result; |
| 1123 |
} |
| 1124 |
|
| 1125 |
#define EOC(e, eo) log(eo/MAX(e, 1.0e-15))/M_LN2 |
| 1126 |
|
| 1127 |
static REAL estimate(MESH *mesh, ADAPT_STAT *adapt) |
| 1128 |
{ |
| 1129 |
FUNCNAME("estimate"); |
| 1130 |
static int init_done, only_dirichlet; |
| 1131 |
static REAL C[4] = { 1.0, 1.0, 0.0, 1.0 }; |
| 1132 |
static REAL est_old = -1.0, u_err_old = -1.0, p_err_old = -1.0; |
| 1133 |
static REAL_DD A; |
| 1134 |
static const QUAD *quad; |
| 1135 |
REAL est, u_err, p_err; |
| 1136 |
FLAGS fill_flags; |
| 1137 |
const void *est_handle; |
| 1138 |
|
| 1139 |
static REAL usingle_err_old = -1.0, psingle_err_old = -1.0; |
| 1140 |
static REAL uerr_old = -1.0; |
| 1141 |
REAL usingle_err, psingle_err, uerr; |
| 1142 |
|
| 1143 |
if (!init_done) { |
| 1144 |
init_done = true; |
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
only_dirichlet = true; |
| 1150 |
FOR_ALL_DOFS(bound->fe_space->admin, |
| 1151 |
if (bound->vec[dof] == NEUMANN) { |
| 1152 |
only_dirichlet = false; |
| 1153 |
} |
| 1154 |
); |
| 1155 |
|
| 1156 |
GET_PARAMETER(1, "estimator C0", "%f", &C[0]); |
| 1157 |
GET_PARAMETER(1, "estimator C1", "%f", &C[1]); |
| 1158 |
GET_PARAMETER(1, "estimator C2", "%f", &C[2]); |
| 1159 |
GET_PARAMETER(1, "estimator C3", "%f", &C[3]); |
| 1160 |
|
| 1161 |
quad = get_quadrature(mesh->dim, 2*u_fe_space->bas_fcts->degree); |
| 1162 |
|
| 1163 |
A[0][0] = nu; |
| 1164 |
} |
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
est_handle = ellipt_est_dow_init(u_h, adapt, rw_el_est, NULL , |
| 1173 |
quad, NULL , |
| 1174 |
H1_NORM, C, |
| 1175 |
A, MATENT_REAL, MATENT_REAL, |
| 1176 |
true , |
| 1177 |
dirichlet_bndry, |
| 1178 |
r, INIT_GRD_UH|(mu != 0.0 ? INIT_UH : 0), |
| 1179 |
stress_res, 0); |
| 1180 |
|
| 1181 |
fill_flags = FILL_NEIGH|FILL_COORDS|FILL_OPP_COORDS|FILL_BOUND|CALL_LEAF_EL; |
| 1182 |
TRAVERSE_FIRST(mesh, -1, fill_flags) { |
| 1183 |
const EL_GEOM_CACHE *elgc; |
| 1184 |
const QUAD_EL_CACHE *qelc; |
| 1185 |
REAL est_el; |
| 1186 |
|
| 1187 |
est_el = element_est_d(el_info, est_handle); |
| 1188 |
|
| 1189 |
if (C[3]) { |
| 1190 |
REAL div_uh_el, div_uh_qp; |
| 1191 |
const REAL_DD *grd_uh_qp; |
| 1192 |
int qp, i; |
| 1193 |
|
| 1194 |
grd_uh_qp = element_est_grd_uh_d(est_handle); |
| 1195 |
div_uh_el = 0.0; |
| 1196 |
if (!(el_info->fill_flag & FILL_COORDS)) { |
| 1197 |
qelc = fill_quad_el_cache(el_info, quad, FILL_EL_QUAD_DET); |
| 1198 |
|
| 1199 |
for (qp = 0; qp < quad->n_points; qp++) { |
| 1200 |
div_uh_qp = 0; |
| 1201 |
for (i = 0; i < DIM_OF_WORLD; i++) { |
| 1202 |
div_uh_qp += grd_uh_qp[qp][i][i]; |
| 1203 |
} |
| 1204 |
div_uh_el += qelc->param.det[qp]*quad->w[qp]*SQR(div_uh_qp); |
| 1205 |
} |
| 1206 |
} else { |
| 1207 |
elgc = fill_el_geom_cache(el_info, FILL_EL_DET); |
| 1208 |
|
| 1209 |
for (qp = 0; qp < quad->n_points; qp++) { |
| 1210 |
div_uh_qp = 0; |
| 1211 |
for (i = 0; i < DIM_OF_WORLD; i++) { |
| 1212 |
div_uh_qp += grd_uh_qp[qp][i][i]; |
| 1213 |
} |
| 1214 |
div_uh_el += quad->w[qp]*SQR(div_uh_qp); |
| 1215 |
} |
| 1216 |
div_uh_el *= elgc->det; |
| 1217 |
} |
| 1218 |
|
| 1219 |
est_el += C[3] * div_uh_el; |
| 1220 |
} |
| 1221 |
|
| 1222 |
element_est_d_finish(el_info, est_el, est_handle); |
| 1223 |
} TRAVERSE_NEXT(); |
| 1224 |
est = ellipt_est_d_finish(adapt, est_handle); |
| 1225 |
|
| 1226 |
|
| 1227 |
MSG("estimate = %.8le", est); |
| 1228 |
if (est_old >= 0) { |
| 1229 |
print_msg(", EOC: %.2lf\n", EOC(est,est_old)); |
| 1230 |
} else { |
| 1231 |
print_msg("\n"); |
| 1232 |
} |
| 1233 |
est_old = est; |
| 1234 |
|
| 1235 |
quad = get_quadrature(mesh->dim, 2*(u_h->fe_space->bas_fcts->degree - 1)); |
| 1236 |
|
| 1237 |
u_err = H1_err_dow(grd_u, u_h, quad, 0, NULL, NULL); |
| 1238 |
|
| 1239 |
MSG("||u-uh||H1 = %.8le", u_err); |
| 1240 |
if (u_err_old >= 0) { |
| 1241 |
print_msg(", EOC: %.2lf\n", EOC(u_err, u_err_old)); |
| 1242 |
} else { |
| 1243 |
print_msg("\n"); |
| 1244 |
} |
| 1245 |
u_err_old = u_err; |
| 1246 |
|
| 1247 |
p_err = L2_err(p, p_h, quad, false , |
| 1248 |
only_dirichlet , |
| 1249 |
NULL, NULL); |
| 1250 |
|
| 1251 |
MSG("||p-ph||L2 = %.8le", p_err); |
| 1252 |
if (p_err_old >= 0) { |
| 1253 |
print_msg(", EOC: %.2lf\n", EOC(p_err, p_err_old)); |
| 1254 |
} else { |
| 1255 |
print_msg("\n"); |
| 1256 |
} |
| 1257 |
p_err_old = p_err; |
| 1258 |
|
| 1259 |
MSG("(||u-uh||H1 + ||p-p_h||L2)/estimate = %.2lf\n", |
| 1260 |
(u_err + p_err)/MAX(est,1.e-15)); |
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
usingle_err = H1_err_dow(grd_u, uh_single, quad, 0, NULL, NULL); |
| 1266 |
MSG("version of static condensation:\n"); |
| 1267 |
MSG("||u-uh||H1 = %.8le", usingle_err); |
| 1268 |
if (usingle_err_old >= 0) { |
| 1269 |
print_msg(", EOC: %.2lf\n", EOC(usingle_err, usingle_err_old)); |
| 1270 |
} else { |
| 1271 |
print_msg("\n"); |
| 1272 |
} |
| 1273 |
usingle_err_old = usingle_err; |
| 1274 |
|
| 1275 |
psingle_err = L2_err(p, ph_single, quad, |
| 1276 |
false , true , |
| 1277 |
NULL, NULL); |
| 1278 |
|
| 1279 |
MSG("||p-ph||L2 = %.8le", psingle_err); |
| 1280 |
if (psingle_err_old >= 0) { |
| 1281 |
print_msg(", EOC: %.2lf\n", EOC(psingle_err, psingle_err_old)); |
| 1282 |
} else { |
| 1283 |
print_msg("\n"); |
| 1284 |
} |
| 1285 |
psingle_err_old = psingle_err; |
| 1286 |
|
| 1287 |
MSG("uh_single & uh_bubble: \n"); |
| 1288 |
uerr = H1_err_dow(grd_u, uh, quad, 0, NULL, NULL); |
| 1289 |
MSG("||u-uh||H1 = %.8le", uerr); |
| 1290 |
if (uerr_old >= 0) { |
| 1291 |
print_msg(", EOC: %.2lf\n", EOC(uerr, uerr_old)); |
| 1292 |
} else { |
| 1293 |
print_msg("\n"); |
| 1294 |
} |
| 1295 |
uerr_old = uerr; |
| 1296 |
|
| 1297 |
|
| 1298 |
if (do_graphics) { |
| 1299 |
graphics_d(mesh, u_h, p_h, get_el_est, u, HUGE_VAL ); |
| 1300 |
} |
| 1301 |
|
| 1302 |
return adapt->err_sum; |
| 1303 |
} |
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
int main(int argc, char **argv) |
| 1310 |
{ |
| 1311 |
FUNCNAME("main"); |
| 1312 |
MACRO_DATA *data; |
| 1313 |
MESH *mesh; |
| 1314 |
int n_refine = 0, dim, u_degree = 2; |
| 1315 |
FLAGS dirichlet_mask = 0; |
| 1316 |
ADAPT_STAT *adapt; |
| 1317 |
STOKES_PAIR stokes; |
| 1318 |
char stokes_name[256]; |
| 1319 |
char filename[PATH_MAX]; |
| 1320 |
|
| 1321 |
ticks_per_second = (REAL)sysconf(_SC_CLK_TCK); |
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
parse_parameters(argc, argv, "INIT/mini-quasi-stokes.dat"); |
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
GET_PARAMETER(1, "mesh dimension", "%d", &dim); |
| 1332 |
GET_PARAMETER(1, "macro file name", "%s", filename); |
| 1333 |
GET_PARAMETER(1, "global refinements", "%d", &n_refine); |
| 1334 |
GET_PARAMETER(1, "online graphics", "%d", &do_graphics); |
| 1335 |
GET_PARAMETER(1, "dirichlet boundary", "%i", &dirichlet_mask); |
| 1336 |
|
| 1337 |
|
| 1338 |
BNDRY_FLAGS_ALL(stress_bndry); |
| 1339 |
if (dirichlet_mask > 0) { |
| 1340 |
dirichlet_bndry[0] = dirichlet_mask | 1; |
| 1341 |
|
| 1342 |
BNDRY_FLAGS_XOR(stress_bndry, dirichlet_bndry); |
| 1343 |
stress_bndry[0] |= 1; |
| 1344 |
} |
| 1345 |
|
| 1346 |
GET_PARAMETER(1, "stokes pair", "%s", stokes_name); |
| 1347 |
GET_PARAMETER(1, "velocity degree", "%d", &u_degree); |
| 1348 |
|
| 1349 |
GET_PARAMETER(1, "QS mu", "%f", &mu); |
| 1350 |
GET_PARAMETER(1, "QS nu", "%f", &nu); |
| 1351 |
|
| 1352 |
GET_PARAMETER(1, "velocity translation", |
| 1353 |
SCAN_FORMAT_DOW, SCAN_EXPAND_DOW(v_shift)); |
| 1354 |
GET_PARAMETER(1, "pressure translation", |
| 1355 |
SCAN_FORMAT_DOW, SCAN_EXPAND_DOW(p_shift)); |
| 1356 |
|
| 1357 |
if (mu > 0) { |
| 1358 |
alpha_robin = 1.0/mu; |
| 1359 |
} else { |
| 1360 |
alpha_robin = 0.0; |
| 1361 |
} |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
data = read_macro(filename); |
| 1368 |
mesh = GET_MESH(dim, "ALBERTA mesh", data, NULL, NULL); |
| 1369 |
free_macro_data(data); |
| 1370 |
init_leaf_data(mesh, sizeof(struct ellipt_leaf_data), NULL, NULL); |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
stokes = stokes_pair(stokes_name, dim, u_degree); |
| 1376 |
u_fe_space = get_fe_space(mesh, "velocity", stokes.velocity, DIM_OF_WORLD, |
| 1377 |
ADM_FLAGS_DFLT); |
| 1378 |
p_fe_space = get_fe_space(mesh, "pressure", stokes.pressure, 1, |
| 1379 |
ADM_FLAGS_DFLT); |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
global_refine(mesh, n_refine * mesh->dim, FILL_NOTHING); |
| 1386 |
|
| 1387 |
if (do_graphics) { |
| 1388 |
graphics_d(mesh, NULL, NULL, NULL, NULL, HUGE_VAL ); |
| 1389 |
} |
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
A = get_dof_matrix("A", u_fe_space, NULL); |
| 1396 |
f_h = get_dof_real_vec_d("f_h", u_fe_space); |
| 1397 |
u_h = get_dof_real_vec_d("u_h", u_fe_space); |
| 1398 |
u_h->refine_interpol = u_fe_space->bas_fcts->real_refine_inter_d; |
| 1399 |
u_h->coarse_restrict = u_fe_space->bas_fcts->real_coarse_inter_d; |
| 1400 |
|
| 1401 |
B = get_dof_matrix("B", u_fe_space, p_fe_space); |
| 1402 |
Bt = get_dof_matrix("Bt", p_fe_space, u_fe_space); |
| 1403 |
p_h = get_dof_real_vec("p_h", p_fe_space); |
| 1404 |
p_h->refine_interpol = p_fe_space->bas_fcts->real_refine_inter; |
| 1405 |
p_h->coarse_restrict = p_fe_space->bas_fcts->real_coarse_inter; |
| 1406 |
g_h = get_dof_real_vec("g_h", p_fe_space); |
| 1407 |
bound = get_dof_schar_vec("bound", u_fe_space); |
| 1408 |
|
| 1409 |
Yproj = get_dof_matrix("Yproj", p_fe_space, NULL); |
| 1410 |
Yprec = get_dof_matrix("Yprec", p_fe_space, NULL); |
| 1411 |
|
| 1412 |
|
| 1413 |
dof_set_dow(0.0, u_h); |
| 1414 |
dof_set(0.0, p_h); |
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
u_fsp_single = u_fe_space->unchained; |
| 1420 |
|
| 1421 |
load_vector = get_block_dof_vec("load_vector", 2, |
| 1422 |
u_fsp_single, p_fe_space); |
| 1423 |
fh_single = (DOF_REAL_D_VEC*)load_vector->dof_vec[0]; |
| 1424 |
gh_single = (DOF_REAL_VEC *)load_vector->dof_vec[1]; |
| 1425 |
|
| 1426 |
up_h = get_block_dof_vec("up_h", 2, u_fsp_single, p_fe_space); |
| 1427 |
uh_single = (DOF_REAL_VEC_D *)up_h->dof_vec[0]; |
| 1428 |
ph_single = (DOF_REAL_VEC *)up_h->dof_vec[1]; |
| 1429 |
|
| 1430 |
system_matrix = get_block_dof_matrix("system_matrix", |
| 1431 |
2, 2, Full, |
| 1432 |
u_fsp_single, u_fsp_single, |
| 1433 |
p_fe_space, p_fe_space); |
| 1434 |
|
| 1435 |
A_single = system_matrix->dof_mat[0][0]; |
| 1436 |
B_single = system_matrix->dof_mat[0][1]; |
| 1437 |
Bt_single = system_matrix->dof_mat[1][0]; |
| 1438 |
C_single = system_matrix->dof_mat[1][1]; |
| 1439 |
|
| 1440 |
uh = get_dof_real_vec_d("uh", u_fe_space); |
| 1441 |
|
| 1442 |
set_refine_inter_dow(uh); |
| 1443 |
set_coarse_inter_dow(uh); |
| 1444 |
|
| 1445 |
set_refine_inter_dow(uh_single); |
| 1446 |
set_coarse_inter_dow(uh_single); |
| 1447 |
|
| 1448 |
ph_single->refine_interpol = p_fe_space->bas_fcts->real_refine_inter; |
| 1449 |
ph_single->coarse_restrict = p_fe_space->bas_fcts->real_coarse_inter; |
| 1450 |
|
| 1451 |
dof_set_dow(0.0, uh_single); |
| 1452 |
dof_set(0.0, ph_single); |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
adapt = get_adapt_stat(mesh->dim, "Quasi-Stokes", "adapt", 2, NULL); |
| 1460 |
adapt->estimate = estimate; |
| 1461 |
adapt->get_el_est = get_el_est; |
| 1462 |
adapt->build_after_coarsen = build; |
| 1463 |
adapt->solve = solve; |
| 1464 |
|
| 1465 |
adapt_method_stat(mesh, adapt); |
| 1466 |
|
| 1467 |
WAIT_REALLY; |
| 1468 |
|
| 1469 |
return 0; |
| 1470 |
} |