Debian Codegraph @

add_ons/static_condensation/demo/Common/mini-quasi-stokes.c

raw symbols SCIP
1 /*******************************************************************************
2 *
3 * ALBERTA: an Adaptive multi Level finite element toolbox using
4 * Bisectioning refinement and Error control by Residual
5 * Techniques
6 *
7 * www.alberta-fem.de
8 *
9 ******************************************************************************
10 *
11 * File: mini-quasi-stokes.c
12 *
13 * Description: solver for a simple Quasi-Stokes problem:
14 *
15 * \mu u - \nu\Delta u + \nabla p = f in \Omega
16 * \nabla\cdot u = 0 in \Omega
17 * \sigma(u, p) n = F on \partial \Omega
18 *
19 * with \sigma(u, p) = \nu D(u) - I p, D(u) = \nabla u + (\nable u)^t, n
20 * is the outer normal to \partial\Omega.
21 *
22 *
23 * with static condensation, as an example how to use
24 * the functions 'condense_mini_spp_dd()' and 'expand_mini_spp_dd()'.
25 *
26 *
27 * To incorporate the stress boundary-conditions it is necessary to
28 * use the symmetric gradient in the distributional formulation, the
29 * resulting stiffness-matrix is a DIM_OF_WORLD x DIM_OF_WORLD block
30 * matrix. The physical meaning of the boundary conditions is that the
31 * intrinsic stresses of the fluid are counter-balanced by the
32 * force-density F on the boundary.
33 *
34 * The code below can actually also be used to solve a Quasi-Stokes
35 * problem with Dirichlet boundary conditions; there is a
36 * corresponding parameter in the init-file.
37 *
38 ******************************************************************************
39 *
40 * author(s): Claus-Justus Heine
41 * Abteilung fuer Angewandte Mathematik
42 * Albert-Ludwigs-Universitaet Freiburg
43 * Hermann-Herder-Str. 10
44 * 79104 Freiburg
45 * Germany
46 * [email protected]
47 *
48 * Rebecca Stotz
49 * Abteilung fuer Angewandte Mathematik
50 * Albert-Ludwigs-Universitaet Freiburg
51 * Hermann-Herder-Str. 10
52 * 79104 Freiburg
53 * Germany
54 *
55 *
56 * (c) by C.-J. Heine (2007), R. Stotz (2009)
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 * global variables: finite element space, discrete solution
75 * load vector and system matrix
76 *
77 * These variables are kept global because they are shared across build(),
78 * solve() and estimate().
79 ******************************************************************************/
80
81 static const FE_SPACE *u_fe_space; /* velocity FE-space */
82 static const FE_SPACE *p_fe_space; /* pressure FE-space */
83 static DOF_REAL_VEC_D *u_h; /* discrete velocity */
84 static DOF_REAL_VEC *p_h; /* discrete pressure */
85
86 static DOF_REAL_VEC_D *f_h; /* RHS for velocity */
87 static DOF_REAL_VEC *g_h; /* RHS for pressure (if necessary) */
88 static DOF_SCHAR_VEC *bound; /* boundary vector */
89 static DOF_MATRIX *A; /* system matrix */
90
91 static DOF_MATRIX *B; /* discrete pressure gradient */
92 static DOF_MATRIX *Bt; /* discrete velocity divergence */
93 static DOF_MATRIX *Yproj; /* projection/precon matrix for B^\ast */
94 static DOF_MATRIX *Yprec; /* projection/precon matrix for B^\ast */
95
96 static const EL_MATRIX_INFO *matrix_info;
97 static EL_MATRIX_INFO B_minfo;
98
99 /********** "static condensation" ************/
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 /* Quasi-Stokes parameters */
119 static REAL mu = 1.0;
120 static REAL nu = 1.0;
121 static REAL alpha_robin = 1.0;
122
123 /* Parameters for the exact "solution" */
124 static REAL gauss_bell = 10.0; /* factor for the pressure */
125 static REAL_D p_shift; /* translation for the pressure */
126 static REAL_D v_shift; /* translation for the velocity */
127
128 static BNDRY_FLAGS dirichlet_bndry; /* Dirichlet part of the bndry, if any. */
129 static BNDRY_FLAGS stress_bndry; /* Complement of dirichlet_mask. */
130
131 static REAL ticks_per_second;
132
133
134 /*******************************************************************************
135 * struct ellipt_leaf_data: structure for storing one REAL value on each
136 * leaf element as LEAF_DATA
137 * rw_el_est(): return a pointer to the memory for storing the element
138 * estimate (stored as LEAF_DATA), called by ellipt_est()
139 * get_el_est(): return the value of the element estimates (from LEAF_DATA),
140 * called by adapt_method_stat() and graphics()
141 ******************************************************************************/
142
143 struct ellipt_leaf_data
144 {
145 REAL estimate; /* one real for the 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 * For test purposes: exact solution and its gradient (optional)
166 ******************************************************************************/
167
168 /*
169 * u(x) = \frac{x}{|x|^d} (make sure 0 lives outside of the domain ...
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 * [(r^2-x^2*d)*r^(-d-2), -d*x*y*r^(-d-2), -d*x*z*r^(-d-2)]
191 * etc.
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 * problem data: right hand side, boundary values
243 ******************************************************************************/
244
245 /* Dirichlet boundary values */
246 static const REAL *g(const REAL_D x, REAL_D res)
247 {
248 return u(x, res);
249 }
250
251 /* \mu u - \nu \Delta u + \nabla p */
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 /* u is harmonic */
262 AXPY_DOW(mu, u(_x, u_val), (REAL *)grd_p(_x, res));
263
264 return res;
265 }
266
267 /* stress tensor on the boundary, needed for non-zero stress boundary
268 * conditions.
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); /* in our example grd_u is already symmetric */
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 * build(): assemblage of the linear system: matrix, load vector,
298 * boundary values, called by adapt_method_stat()
299 * on the first call initialize u_h, f_h, matrix and information
300 * for assembling the system matrix
301 *
302 * struct op_info: structure for passing information from init_element() to
303 * LALt()
304 *
305 * u_init_element(), p_init_element():
306 * initialization on the element; calculates the
307 * coordinates and |det DF_S| used by LALt; passes these
308 * values to LALt via user_data,
309 * called on each element by update_matrix()
310 *
311 * LDDLt(): implementation of Lambda DD Lambda^t for the -Delta v
312 * term in the stress-tensor formulation
313 *
314 * LALt(): implementation of Lambda id Lambda^t for -Delta p,
315 * called by update_matrix() after init_element()
316 *
317 * B_Lb1(): operator kernel (just Lambda) for \phi\nabla\psi
318 *
319 * c(): mass matrix for the projection to the pressure space
320 *
321 ******************************************************************************/
322
323 typedef struct op_data
324 {
325 REAL_BD Lambda; /* the gradient of the barycentric coordinates */
326 REAL det; /* |det D F_S| */
327 REAL LALt_factor; /* a factor for the 2nd order element matrices */
328 REAL c_factor; /* a factor for the 0th order element matrices */
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 /* Return false, i.e. not parametric */
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 /* Use a very simplistic finite-volume method */
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 /* Deformation tensor. This is 1/2 D(\phi^l_k):D(\phi^n_m) transformed
427 * to the reference element, where the components of the vector-valued
428 * test functions are given by (\phi^l_k)_j = \delta_{kj}\phi^l for an
429 * "ordinary" scalar basis function.
430 *
431 * We have to assemble the block-matrices
432 * ${{\cal B}^{\alpha\beta}}\in\R^{d\times d}$:
433 *
434 * ({{\cal B}^{\alpha\beta}})_{km}
435 * =
436 * \delta_{km}\,\Lambda^{\alpha r}\,\Lambda^{\beta r}
437 * +
438 * \Lambda^{\alpha m}\,\Lambda^{\beta k}.
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 /* The first part is just LLt reordered such that it matches the
477 * block-matrix conventions
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 /* The second part is symmtric w.r.t. to the exchange of index
491 * pairs. We do loop unrolling here to reduce the number of loads
492 * required to store stuff into the 4 dimensional array.
493 */
494 for (m = 0; m < DIM_OF_WORLD; m++) {
495 /* (alpha, m, alpha, m) */
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 /* (alpha, m, alpha, k)
500 * (alpha, k, alpha, m)
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 /* (alpha, m, beta, m)
508 * (beta, m, alpha, m)
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 /* (alpha, m, beta, k)
515 * (beta, k, alpha, m)
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 /* The first order term for the divergence constraint */
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 /* static const EL_MATRIX_INFO *matrix_info;
554 static EL_MATRIX_INFO B_minfo;
555 'matrix_info' and 'B_minfo' are now global variables. */
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) { /* information for matrix assembling */
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; /* pw const. assemblage is faster */
582 o_info.LALt_symmetric = false /*true*/; /* symmetric assemblage is faster */
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); /* Dirichlet bc on part of the bndry? */
588 o_info.fill_flag = CALL_LEAF_EL|FILL_COORDS;
589 matrix_info = fill_matrix_info(&o_info, NULL);
590
591 /* Operator-info for divergence constraint, only the B operator,
592 * B^\ast will be generated by transposition of B and projection
593 * to the pressure space.
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 /* Projection to the pressure space: B^\ast = Pr_Y \circ B^{tr} */
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 /* (Part of) the preconditioner for the Schur-Complement operator;
615 * the Poissoin-part of the pre-conditioner corresponds to the
616 * mass-part of the Quasi-Stokes operator.
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 /* Discontinuous pressure, use a finite volume (degree == 0) or
632 * DG method (degree > 0) to solve the Poisson problem.
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 /* ALBERTA requires that the boundary contributions are split
639 * into one part which is assembled using only the current's
640 * element local basis functions, and a second part which pairs
641 * the given element with its neighbour. In our case both
642 * contributions are simple mass-matrices
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); /* all interior edges */
651
652 el_bop_info.fill_flag = CALL_LEAF_EL|FILL_COORDS|FILL_OPP_COORDS;
653
654 /* The contribution of the pairing with the neighbouring basis
655 * functions is almost the same:
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 /* assembling of matrix */
667 clear_dof_matrix(A);
668 update_matrix(A, matrix_info, NoTranspose);
669
670 /* assembling of load vector */
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 /* boundary values, we have to fill in the "bound" vector for
676 * sp_dirichlet_bound_sd() below, and add a boundary integral for
677 * inhomogeneous stress boundary conditions.
678 *
679 * For a pure Stokes problem (mu == 0.0) we also request an
680 * automatic mean-value correction of the right-hand side; this is
681 * triggered by "bndry_type == NEUMANN && robin_alpha < 0.0".
682 */
683 boundary_conditions_dow(NULL /* matrix */, f_h, u_h, bound,
684 dirichlet_bndry,
685 g, g_stress,
686 mu == 0.0 ? -1.0 : 0.0 /* robin_alpha */,
687 NULL);
688
689 /* Now go for the divergence constraint */
690
691 /* First for B */
692 clear_dof_matrix(B);
693 BNDRY_FLAGS_CPY(B_minfo.dirichlet_bndry, dirichlet_bndry);
694 update_matrix(B, &B_minfo, NoTranspose);
695
696 /* Then for Bt. Ideally, one would loop just once over the mesh
697 * and assemble both matrices together.
698 */
699 clear_dof_matrix(Bt);
700 BNDRY_FLAGS_INIT(B_minfo.dirichlet_bndry);
701 update_matrix(Bt, &B_minfo, Transpose);
702
703 /* In order to have compatible boundary conditions on the discrete
704 * level we have to make sure that either the boundary integral over
705 * the boundary values vanishes (discretely), or we have to perturb
706 * the RHS for the pressure, i.e. solve a (slightly) inhomogeneous
707 * saddle-point problem. This is what we are doing here because it
708 * is conceptual simpler.
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 ************* condensed-version ************************************
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 /* Finally the projection/preconditioner for the pressure space */
734
735 /* Assemble the projection; at the same time the part of the
736 * preconditioner "responsible" for the 2nd-order part of the
737 * Quasi-Stokes operator.
738 */
739 clear_dof_matrix(Yproj);
740 update_matrix(Yproj, Yproj_minfo, NoTranspose);
741
742 /* Assemble the part of the preconditiner "responsible" for the
743 * 0th-order part of the Quasi-Stokes operator. We need Robin
744 * boundary conditions because of the Neumann-style boundary
745 * conditions in the velocity space.
746 */
747 clear_dof_matrix(Yprec);
748 update_matrix(Yprec, Yprec_minfo, NoTranspose);
749 robin_bound(Yprec, stress_bndry, alpha_robin, NULL /* bndry_quad */, 1.0);
750
751 /* That's it */
752 }
753
754
755 /******************************************************************************
756 * 'block_solve' is the solve-function of the version with static condensation,
757 * the variable 'norm_res' is needed to compare the lengths of time of
758 * the two different versions
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 /* static OEM_PRECON icon = DiagPrecon;
770 static BLOCK_PRECON_TYPE block_icon = { BlkDiagPrecon,{ { DiagPrecon, },{ DiagPrecon, },}};*/
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 /*block_prec_type.precon_type[0].type = ILUkPrecon;
784 block_prec_type.precon_type[0].param.ILUk.level = 2;*/
785
786 block_prec_type.precon_type[1].type = DiagPrecon;
787
788 /* block_prec_type.precon_type[0].param.BlkDiag.precon[1].type = DiagPrecon;*/
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 /*GET_PARAMETER(1, "block->solver precon", "%d", &block_icon.type);*/
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 /* bound */, load_vector, up_h,
820 solver, tol, precon /* 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 * solve(): solve the linear system, called by adapt_method_stat()
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 /* bound */, MAX(0, info-3),
954 &A_prec_type);
955 Yproj_prec = init_precon_from_type(Yproj, NULL /* bound */, MAX(0, info-3),
956 &Yproj_prec_type);
957 if (mu > 0) {
958 Yprec_prec = init_precon_from_type(Yprec, NULL /* bound */, MAX(0, info-3),
959 &Yprec_prec_type);
960 }
961 Yprec_prec = init_precon_from_type(Yprec, NULL /* bound */, MAX(0, info-3),
962 &Yprec_prec_type);
963 oem_sp_solve_dow_scl(solver, tol, tol_incr, miter, info,
964 A, NULL /* bound */, 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 /* Yproj_frac */, mu /* Yprec_frac */,
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 * Functions for error estimate:
993 *
994 * estimate(): compute a residual error estimate and the exact error
995 * (the latter for testing purposes). The estimate is performed for
996 * the velocity only, the pressure enters as lower-order term on the
997 * RHS.
998 *
999 * r(): calculates the lower order terms of the element residual on
1000 * each element at the quadrature node iq of quad argument to
1001 * ellipt_est() and called by ellipt_est()
1002 *
1003 * stress_res(): residual of the stress boundary conditions.
1004 ******************************************************************************/
1005
1006 /* Lower order terms: right-hand side, the 0th order term, the
1007 * gradient of the discrete pressure.
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 /* pressure stuff */
1028 if (!qfast ||
1029 qfast->bas_fcts != p_fe_space->bas_fcts || qfast->quad != quad) {
1030 /* Aquire a QUAD_FAST structure for the evaluation of the gradient
1031 * of the discrete pressure.
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 /* 0-th order term */
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 /* Compute the residual for the stress boundary conditions.
1073 *
1074 * We need to compute (\nu D(u) - p I) n - g_{stress}.
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 /* pressure stuff */
1094 if (!qfast || qfast->quad != quad ||
1095 qfast->bas_fcts != p_fe_space->bas_fcts) {
1096 /* Aquire a QUAD_FAST structure for the evaluation of the gradient
1097 * of the discrete pressure.
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); /* "+" is correct here, the
1118 * estimator only computes the
1119 * (A\nabla u_h + (A\nabla u_h)^t)
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 /* Determine whether the pressure is determined only up to a
1147 * constant.
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 /* We use the standard error estimator for elliptic problems, but
1167 * optionally add the L2-norm of the divergence of u_h, controlled
1168 * by C[3].
1169 */
1170
1171 /*********************** start of modified estimator ***********************/
1172 est_handle = ellipt_est_dow_init(u_h, adapt, rw_el_est, NULL /* rw_estc */,
1173 quad, NULL /* wall_quad */,
1174 H1_NORM, C,
1175 A, MATENT_REAL, MATENT_REAL,
1176 true /* sym_grad */,
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] /* h2 */ * 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 /*********************** end of modified estimator ***********************/
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 /* rel_error */,
1248 only_dirichlet /* mean-value*/,
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 /****** u_h_single & p_h and uh_bubble ************/
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 /* rel_error */, true /* mean-value*/,
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 /* time */);
1300 }
1301
1302 return adapt->err_sum;
1303 }
1304
1305 /*******************************************************************************
1306 * The main program.
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 * first of all, initialize the access to parameters of the init file
1325 ****************************************************************************/
1326 parse_parameters(argc, argv, "INIT/mini-quasi-stokes.dat");
1327
1328 /*****************************************************************************
1329 * then read some basic parameters
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 /* Boundary classifiction */
1338 BNDRY_FLAGS_ALL(stress_bndry);
1339 if (dirichlet_mask > 0) {
1340 dirichlet_bndry[0] = dirichlet_mask | 1;
1341 /*BNDRY_FLAGS_SET(dirichlet_bndry, dirichlet_bit);*/
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 * get a mesh, and read the macro triangulation from file
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 * aquire velocity and pressure space finite element spaces
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 * Globally refine the mesh a little bit. Maybe do some graphics
1383 * output to amuse the spectators.
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 /* time */);
1389 }
1390
1391 /*****************************************************************************
1392 * initialize the global variables shared across build(), solve()
1393 * and estimate().
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 /* Do not forget to initialize u_h and p_h */
1413 dof_set_dow(0.0, u_h);
1414 dof_set(0.0, p_h);
1415
1416
1417 /**** BLOCK_DOF_* for the static condensation *******************/
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 * init the adapt structure and start adaptive method
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 }