Debian Codegraph @

add_ons/albertasystems/Elast/Common/elast.cc

raw
1 /****************************************************************************/
2 /* ALBERT: an Adaptive multi Level finite element toolbox using */
3 /* Bisectioning refinement and Error control by Residual */
4 /* Techniques */
5 /****************************************************************************/
6 /* authors: Alfred Schmidt and Kunibert G. Siebert */
7 /* Institut f"ur Angewandte Mathematik */
8 /* Albert-Ludwigs-Universit"at Freiburg */
9 /* Hermann-Herder-Str. 10 */
10 /* 79104 Freiburg */
11 /* Germany */
12 /* */
13 /* email: alfred,[email protected] */
14 /* */
15 /* (c) by A. Schmidt and K.G. Siebert (1996-2000) */
16 /****************************************************************************/
17
18 /*Aus Klonkopie von phase_real_sys entstanden. */
19
20 #include <alberta.h>
21 #if (defined(ALBERTA_VER) && (ALBERTA_VER==2))
22 # include "alberta1_wrapper.h"
23 #endif
24
25 #include "newalberta.hh"
26 //#include "phase_elast.hh"
27 //#include "PE_diff.hh"
28 #include "do_on_el.hh"
29 #include "do_elfunc_on_el.hh"
30 //#include "public_do_elfunc_on_el.hh"
31 #include "traverse.hh"
32 #include "prototype_fem_elfunc.hh"
33 #include "fem_elfunc.hh"
34 #include "fem_base.hh"
35 #include "est.hh"
36 #include "ellipt_est.hh"
37 #include "parab_est.hh"
38 #include "sys_est.hh"
39 #include "build_stat.hh"
40 #include "build_diff.hh"
41 #include "build_sys.hh"
42 //#include "oem.h"mal sehen
43 #include "solve_multiphase.h"
44 #include "operator_parts.hh"
45 #include "elast_problem.hh"
46 /*wegen DIM,prob_datas_elast. Wir verfahren hier anders als bei heat, die
47 Instanziierung mehrerer Saetze von Phasenfeldern ist sehr unwahrscheinlich, deshalb
48 vorlaeufig prob_datas_elast global.*/
49 #include "master.hh"
50 #include "adapt.hh" //fuer okmarking
51 #include "error_c.h"
52 #include "th_strain_rhs.hh"
53 //#include "phase.hh" lieber trennen... thermische dehnung ist mehr als genug zum testen
54 #include "heat.hh"
55 #define _LOCALDEBUG_
56 //nur zum debuggen
57 #include "graphics.hh"
58
59 //static const int
60 //#define DIM erstmal schon in phase_problem.hh
61 extern ADAPT_INSTAT *adapt_elast;
62 static const FE_SPACE *fe_space=nil;
63 //in phase_problem.hh: extern const PROB_DATA_DIFF* const (prob_datas_elast)[DIM*(DIM+1)/2];
64 static const PROB_DATA_DIFF* (prob_datas_elast)[DIM*DIM];
65 //static build_stat *build_elast[DIM*DIM]={nil};
66 static build_sys *build_elast={nil};//
67 static sys_est *est_elast ={nil};
68 static DOF_REAL_VEC* u_h[DIM];
69 static DOF_REAL_VEC* uh_old[DIM];
70 static DOF_REAL_VEC* f_h[DIM];
71 static DOF_MATRIX* mat_phase[DIM*DIM];
72 static DOF_SCHAR_VEC* bound_vec[DIM];
73
74 static DOF_REAL_VEC const * uh_estimate[DIM];
75 static DOF_REAL_VEC *dudt[DIM]; /* holds lambda dt phase */
76
77 static DOF_REAL_VEC * stress=nil;
78 static fem_elfunc* rhs_el_fct; //brauchen wir ausserhalb von build_elast
79
80 /*static immer gut zum debuggen*/ void close_timestep(MESH *mesh, ADAPT_INSTAT *adapt);
81
82 static REAL err_L2=0.0, err_H1=0.0;
83 /****************************************************************************/
84 /****************************************************************************/
85
86 const DOF_REAL_VEC *const * const get_deformation(void)
87 {
88 return((const DOF_REAL_VEC * const *const)u_h);
89 }
90
91 const DOF_REAL_VEC *const * const get_uh_old(void)
92 {
93 return((const DOF_REAL_VEC * const *const)uh_old);
94 }
95
96
97
98 /*Punktweise Stress-Berechnung. Das polynomiale test-Problem ohne Mittelung ueber die Elenmente zeigt ein
99 merkwuerdig pickeliges Bild. Es ist aber alles auf Herz und nieren getestet u die Pickel kommen wohl von
100 der mangelnden Mittelung.*/
101
102 static void stress_assemble()
103 {
104 FUNCNAME("stress_assemble");
105 TRAVERSE_STACK *stack;
106 const EL_INFO *el_info; /*meins*/
107 const DOF *dof;
108 static REAL deformTensor[DIM_OF_WORLD][DIM_OF_WORLD];
109 static REAL stressTensor[DIM_OF_WORLD][DIM_OF_WORLD];
110 REAL s=0.0, trace=0.0, trace_s=0.0, c1=0.0, c2=0.0,nr_of_els=0;
111 int i=0,j=0,k=0;
112 REAL lambda=0.0, mu=0.0, fac=0.0, *lagrangenodes;
113 static const BAS_FCTS *bas_fcts=fe_space->bas_fcts;
114 static const int n_phi= bas_fcts->n_bas_fcts;
115 static const int dim = bas_fcts->dim;
116 static const DOF *(*get_dof)(const EL *, const DOF_ADMIN *, DOF *)
117 = bas_fcts->get_dof_indices;
118 static const REAL *(*get_real_vec)(const EL *, const DOF_REAL_VEC *, REAL *)
119 = bas_fcts->get_real_vec;
120 REAL u_loc[n_phi];
121 REAL grd_u[dim*n_phi];
122 static DOF_REAL_VEC *nr_of_surrounding_els = get_dof_real_vec("nr_of_surrounding_els", fe_space);
123 static DOF_REAL_VEC *strain[DIM_OF_WORLD*(DIM_OF_WORLD+1)/2];
124 static DOF_REAL_VEC *stresstensor[DIM_OF_WORLD*(DIM_OF_WORLD+1)/2];
125 /*f. oberflachenintegral der anliegenden Kraefte (zur kontrolle)*/
126 /* REAL_D normal;
127 REAL_D bound_stress;
128 REAL_D normal_stress;
129 REAL_D stress_int;
130 static FILE *file_int=nil;
131 */ const WALL_QUAD *wall_quad=nil;
132 /*brauchen lagrange-Bas-fcts. Weiss aber nicht, wie das abzufragen ist.*/
133 // dof_set(0.0, stress);
134
135 // TEST_EXIT(N_MESHES == 1,"not yet for N_MESHES > 1\n");
136 if (fe_space->bas_fcts->degree > 2) MSG("untested for u->degree = %d\n", fe_space->bas_fcts->degree);
137 /*strain-Komponenten zum Zeichnen*/
138 dof_set(0.0,nr_of_surrounding_els );
139 for (i=0;i<dim*(dim+1)/2;i++)
140 {if (!strain[i])
141 {char name[15];
142 sprintf(name,"%s%d","strain",i);
143 strain[i] = get_dof_real_vec(name, fe_space);
144 strain[i]->refine_interpol = bas_fcts->real_refine_inter;
145 strain[i]->coarse_restrict = bas_fcts->real_coarse_inter;
146 sprintf(name,"%s%d","stress",i);
147 stresstensor[i] = get_dof_real_vec(name, fe_space);
148 stresstensor[i]->refine_interpol = bas_fcts->real_refine_inter;
149 stresstensor[i]->coarse_restrict = bas_fcts->real_coarse_inter;
150 }
151 dof_set(0.0, strain[i]);
152 dof_set(0.0, stresstensor[i]);
153 }
154 wall_quad = get_wall_quad(DIM, 2*bas_fcts->degree);
155 /* wahrsch. unnoetig wall_quad_fast =
156 get_wall_quad_fast(u_h[0]->fe_space->bas_fcts, wall_quad,
157 INIT_GRD_PHI|INIT_UH);
158 */
159 lambda = prob_data_s11.physconstants[LAMBDA]*prob_data_s11.physconstants[MU_LAMBDA_SCALE]; // prob_data->lambda * prob_data->mu_lambda_scale;
160 mu = prob_data_s11.physconstants[MU]*prob_data_s11.physconstants[MU_LAMBDA_SCALE]; //prob_data->mu * prob_data->mu_lambda_scale;
161 //scale im Original da
162
163 stack = get_traverse_stack();
164 el_info = traverse_first(stack, fe_space->mesh, -1,
165 CALL_LEAF_EL|FILL_COORDS|FILL_BOUND);
166 while (el_info)
167 {
168 fill_el_geom_cache(el_info, FILL_EL_DET|FILL_EL_LAMBDA); //ahem... hier ist das Agument const wie oben
169 if (rhs_el_fct) rhs_el_fct->set_at_el(el_info, nil);
170 dof = (*get_dof)(el_info->el, fe_space->admin, nil);
171
172 /*brauchen lagrange-Bas-fcts. Weiss aber nicht, wie das abzufragen ist.*/
173 lagrangenodes=(REAL *)(bas_fcts->bas_fcts_data); /*ist tasaechlich ein 1x... -Vektor u keine Dim+1x...Matrix*/
174
175 for (k=0;k<n_phi; k++)
176 {
177 /* MSG("lagrangenodes: %f, %f, %f\n",lagrangenodes[(DIM+1)*k],lagrangenodes[(DIM+1)*k+1],lagrangenodes[(DIM+1)*k+2]);
178 MSG("grd_u: %f, %f, %f, %f \n",grd_u[0][0],grd_u[0][1],grd_u[1][0],grd_u[1][1]);
179 */ trace=0.0;
180 /*grd_u[i][j]= d_xi uj*/
181 for (i=0; i< dim; i++)
182 {
183 get_real_vec(el_info->el, u_h[i], u_loc);
184 eval_grd_uh(&lagrangenodes[(dim +1)*k] ,
185 el_info->el_geom_cache.Lambda,(const REAL *) u_loc, bas_fcts, &grd_u[i*dim] );
186 // deformTensor[i][i] = grd_u[i][i];
187 deformTensor[i][i] = grd_u[i*dim + i];
188 for (j=0; j<i; j++)
189 {
190 deformTensor[i][j] = deformTensor[j][i] =
191 0.5*(grd_u[i*dim + j] + grd_u[j*dim + i]);
192 // 0.5*(grd_u[i][j] + grd_u[j][i]);
193 }
194 trace += deformTensor[i][i];
195 } /*das ist also vollstaendiger Verzerrungstensor incl therm. u. Dichteeinfluss*/
196
197 // aus = 1.0 - ph_at_el[k] - mh_at_el[k];
198 // fac1 = prob_data->elast_rhs_th(th_at_phik, aus, ph_at_phik, mh_at_el[k]);
199 // fac2 = prob_data->elast_rhs_rho(th_at_phik, aus, ph_at_phik, mh_at_el[k]);
200 // fac = (3*lambda+2*mu)*(fac1 + fac2/3.0);
201 /*Baustelle. Kontrolle ob sachlich richtig. Scheint ok zu sein. Getestet mit Problem 8 u 7.*/
202 if (rhs_el_fct) fac = rhs_el_fct->calc((const REAL*const)&lagrangenodes[k*(dim+1)]);
203 #if 1
204 //both ways should bear same result
205 c1 = 2 * mu;
206 c2 = lambda * trace - fac;
207 /* MSG("fac,trace : %e, %e , lambda: %e \n", fac,trace,lambda);
208 MSG("c2: %e, lambda: %e,\n", c2,lambda);
209 */ trace_s = 0.0;
210
211 for (i=0; i<DIM_OF_WORLD; i++)
212 {
213 for (j=0; j<DIM_OF_WORLD; j++)
214 {
215 stressTensor[i][j] = c1 * deformTensor[i][j];
216 }
217 stressTensor[i][i] += c2;
218 trace_s += stressTensor[i][i];
219 }
220 #else
221 //it should be like this :(still wrong)
222 for (int s_row=0; s_row< dim; s_row++) //tension row
223 {
224 for (int s_col=0; s_col<=s_row; s_col++) //dx_j
225 {
226 stressTensor[s_row][s_col] =0.0;
227 for (int e_row=0; e_row<dim; e_row++)
228 {
229 for (int e_col=0; e_col<dim; e_col++)
230 {
231 REAL elasticpart;
232 if (e_row==e_col) elasticpart = deformTensor[e_row][e_row] -fac;
233 else elasticpart = deformTensor[e_row][e_col];
234 stressTensor[s_row][s_col]
235 = (prob_datas_elast)[s_row*dim+e_row]->diffmat->getcomp(s_col,e_col) *
236 elasticpart;
237 }
238 }
239 stressTensor[s_row][s_col] *=prob_data_s11.physconstants[MU_LAMBDA_SCALE];
240 stressTensor[s_col][s_row] = stressTensor[s_row][s_col];
241
242 }
243 trace_s += stressTensor[i][i];
244 }
245
246 #endif
247 s = 0.0;
248 for (i=0; i<DIM_OF_WORLD; i++)
249 {
250 for (j=0; j<DIM_OF_WORLD; j++)
251 {
252 s += SQR(stressTensor[i][j]);//nicht von Mises!
253 }
254 }
255 /* mitteln ueber alle Elemente, die an einen Knoten grenzen. */
256 nr_of_surrounding_els->vec[dof[k]]+=1.0;
257 stress->vec[dof[k]] += s;
258 #if DIM_OF_WORLD==2
259 strain[0]->vec[dof[k]]+=deformTensor[0][0];
260 strain[1]->vec[dof[k]]+=deformTensor[0][1];
261 strain[2]->vec[dof[k]]+=deformTensor[1][1];
262 #else
263 #if DIM_OF_WORLD==3
264 strain[0]->vec[dof[k]]+=deformTensor[0][0];
265 strain[1]->vec[dof[k]]+=deformTensor[0][1];
266 strain[2]->vec[dof[k]]+=deformTensor[0][2];
267 strain[3]->vec[dof[k]]+=deformTensor[1][1];
268 strain[4]->vec[dof[k]]+=deformTensor[1][2];
269 strain[5]->vec[dof[k]]+=deformTensor[2][2];
270 #endif
271 #endif
272 #if DIM_OF_WORLD==2
273 stresstensor[0]->vec[dof[k]]+=stressTensor[0][0];
274 stresstensor[1]->vec[dof[k]]+=stressTensor[0][1];
275 stresstensor[2]->vec[dof[k]]+=stressTensor[1][1];
276 #else
277 #if DIM_OF_WORLD==3
278 stresstensor[0]->vec[dof[k]]+=stressTensor[0][0];
279 stresstensor[1]->vec[dof[k]]+=stressTensor[0][1];
280 stresstensor[2]->vec[dof[k]]+=stressTensor[0][2];
281 stresstensor[3]->vec[dof[k]]+=stressTensor[1][1];
282 stresstensor[4]->vec[dof[k]]+=stressTensor[1][2];
283 stresstensor[5]->vec[dof[k]]+=stressTensor[2][2];
284 #endif
285 #endif
286 }/*ende schleife Knoten k*/
287 el_info = traverse_next(stack, el_info);
288 }
289 free_traverse_stack(stack);
290 /*Mittelung*/
291 FOR_ALL_DOFS( fe_space->admin,
292 nr_of_els=nr_of_surrounding_els->vec[dof];
293 stress->vec[dof]/=nr_of_els;
294 stress->vec[dof] =sqrt(stress->vec[dof]);//neu-vergessen?
295 for (i=0; i<dim*(dim+1)/2; i++)
296 {
297 strain[i]->vec[dof]/=nr_of_els;
298 stresstensor[i]->vec[dof]/=nr_of_els;
299 }
300 );
301 /*
302 for (k=0; k<N_NEIGH; k++)
303 {
304 if (el_info->boundary[k] && (el_info->boundary[k]->bound <= NEUMANN))
305 {
306 bound_int_d(el_info, stresstensor, stress_int , k, wall_quad,
307 /*u_h->fe_space*/
308 /* bas_fcts, n_phi, dof);
309 }
310 }
311
312
313 */
314 #if 0
315 MSG("sigmaxx after multi mesh traverse:\n");
316 print_dof_real_vec(stresstensor[0]);
317 MSG("sigmaxy after multi mesh traverse:\n");
318 print_dof_real_vec(stresstensor[1]);
319 MSG("sigmayy after multi mesh traverse:\n");
320 print_dof_real_vec(stresstensor[2]);
321 #endif
322 }
323 const DOF_REAL_VEC *const get_stress(void)
324 {
325 /* Initialisierung war auskommentiert. Erlaube mir, sie einzusetzen*/
326 FUNCNAME("get_stress");
327 if (!stress)
328 {
329 const FE_SPACE *fe_space=build_elast->get_sol()->fe_space;
330
331 MSG("called and initialized with zeros\n");
332 stress = get_dof_real_vec("stress", fe_space);
333 stress->refine_interpol = fe_space->bas_fcts->real_refine_inter;
334 stress->coarse_restrict = fe_space->bas_fcts->real_coarse_inter;
335 dof_set(0.0, stress);
336 } //Baustelle (bez. fe_space)
337 return((const DOF_REAL_VEC *const)stress);
338 }
339
340 void calc_stress()
341 {
342 FUNCNAME("calc_stress");
343 REAL norm;
344 /*Initialisierung: stress = So gehts nicht wegen const*/
345 get_stress();
346 stress_assemble( ); /* stress damals norm und projektionsmatrix */
347 // valgrind mekkert: enthaelt stress sinnvolles? EP
348 // MSG("min and max stress: %e %e\n", dof_min(stress), dof_max(stress));
349 }
350
351 const DOF_REAL_VEC *const * const get_dudt(void)
352 {
353 return((const DOF_REAL_VEC * const *const)dudt);
354 }
355
356 const DOF_REAL_VEC *const * const get_uh_estimate(void)
357 {
358 return(/*(const DOF_REAL_VEC * const *const)*/uh_estimate);
359 }
360 /****************************************************************************/
361 /****************************************************************************/
362
363
364 /****************************************************************************/
365 /* init_dof_admin(): init DOFs for Lagrange elements of order */
366 /* <polynomial degree>, called by GET_MESH() */
367 /****************************************************************************/
368
369 void init_elast_dof_admin(MESH *mesh)
370 {
371 FUNCNAME("init_elast_dof_admin");
372 int degree = 1;
373 const BAS_FCTS *lagrange;
374 GET_PARAMETER(1, "elast polynomial degree", "%d", &degree);
375 FLAGS periodic = 0U, flag = 0U;
376 GET_PARAMETER(2, "periodic", "%d", &periodic);
377 if (periodic) {flag = ADM_PERIODIC ;}
378 else {flag = 0U;}
379
380 lagrange = get_lagrange(DIM,degree);
381 TEST_EXIT(lagrange,"no lagrange BAS_FCTS\n");
382 fe_space = get_fe_space(mesh, lagrange->name, nil, lagrange, flag);
383
384 return;
385 }
386
387 /****************************************************************************/
388 // der darf nur fuer Graphik sein.
389 static REAL get_el_est(EL *el)
390 { int i; REAL out=0.0;
391 if (IS_LEAF_EL(el))
392 {
393 for (i=0; i<DIM; i++) {
394 out += (est_elast->get_el_est)(el,i);
395 // MSG("phase %d estimator: %f\n", i,out);
396 };
397 return(out);
398 }
399 else
400 return(0.0);
401 }
402
403
404 static REAL get_el_estc(EL *el)
405 {
406 int i; REAL out=0;
407 if (IS_LEAF_EL(el))
408 {
409 for (i=0; i<DIM; i++) {out += *(est_elast->rw_el_estc(el,i));}
410 return(out);
411 }
412 else
413 return(0.0);
414 }
415
416 void clear_indicator_elast(MESH * mesh)
417 {
418 est_elast->clear_indicator( mesh);
419 }
420
421 /****************************************************************************/
422 /* interpolation is solve on the initial grid */
423 /****************************************************************************/
424
425 static void init_elast_timestep(MESH *mesh, ADAPT_INSTAT *adapt)
426 {
427 build_elast->init_timestep();
428 return;
429 }
430
431
432 static void close_elast_timestep(MESH *mesh, ADAPT_INSTAT *adapt)
433 {
434 FUNCNAME("close_elast_timestep");
435 static REAL err_L2H1 = 0.0;
436 static REAL err_LinftyL2 = 0.0;
437
438 err_LinftyL2 = MAX(err_LinftyL2, err_L2);
439
440 err_L2H1 += adapt->timestep * err_H1*err_H1;
441
442 MSG("Elast LinftyL2 error: %.3le L2H1 error: %.3le\n", /* total error: %.3le\n",*/
443 err_LinftyL2, sqrt(err_L2H1));
444 // err_LinftyL2*(1.0+sqrt((*prob_datas_elast)[0]->physconstants[SMALL] /*->relax*/))
445 // + sqrt(err_L2H1 * (*prob_datas_elast)[0]->diffkoeff)); Weiss nich, was das soll
446 //Baustelle das is natuerlich noch mist....
447 //debugging: Nuetzlich
448 // graphics(mesh, nil, build_elast->get_rhs(0), nil, 4);
449 return;
450 }
451
452 /****************************************************************************/
453 /* build(): assemblage of the linear system: matrix, load vector, */
454 /* boundary values, called by adapt_method_stat() */
455 /* on the first call initialize u_h, f_h, matrix and information */
456 /* for assembling the system matrix */
457 /* */
458 /* struct op_info: structure for passing information from init_element() to */
459 /* LALt() */
460 /* init_element(): initialization on the element; calculates the */
461 /* coordinates and |det DF_S| used by LALt; passes these */
462 /* values to LALt via user_data, */
463 /* called on each element by update_matrix() */
464 /* LALt(): implementation of -Lambda id Lambda^t for -Delta u, */
465 /* called by update_matrix() */
466 /* c(): implementation of 1/tau*m(,) */
467 /****************************************************************************/
468 /****************************************************************************/
469
470 static void build(MESH *mesh, U_CHAR flag)
471 {
472 FUNCNAME("build (elast)");
473 int i,j, dim = mesh->dim;
474 dof_compress(mesh);
475 INFO(adapt_elast->adapt_space->info, 3,
476 "%d DOFs for %s\n", fe_space->admin->size_used, fe_space->name);
477 for (i=0;i< dim;i++)
478 {
479 dof_set(0.0, build_elast->get_rhs(i));
480 }
481 //noch. Baustelle
482 build_elast->assemble();
483 for (i=0;i<dim;i++)
484 {
485 for (j=0;j<dim; j++)
486 {
487 mat_phase[i*dim + j] = build_elast->get_mat_block(i,j);
488 if (adapt_elast->adapt_space->info >= 9)
489 {
490 if (mat_phase[i*dim + j])
491 { MSG("Block Matrix row %d col %d after multi mesh traverse:\n",i,j);
492 print_dof_matrix(mat_phase[i*dim + j]);
493 }
494 }
495 }
496 if (adapt_elast->adapt_space->info >= 8)
497 {
498 print_dof_real_vec(u_h[i]);
499 print_dof_real_vec(build_elast->get_rhs(i));
500 // print_dof_real_vec(f_h[i]);
501 }
502 }
503 // hier war viel debuggen angesagt
504 return;
505 }
506
507 /****************************************************************************/
508 /* solve(): solve the linear system, called by adapt_method_stat() */
509 /****************************************************************************/
510 /*solve_diag: this function implements solving of the coupled system with all off-diagonal matrix
511 blocks multiplied with old sol and added to rhs. For testing purposes.
512 This now must be implemented via theta =0 !!!*/
513
514 static void solve_system(MESH *mesh)
515 {
516 FUNCNAME("solve_system");
517 static REAL omega = 1.0;
518 static int solver=-1,i;
519 static SOLVE_DATA sd = {1e-8, 999, -1000, 2};
520
521 build(mesh, 1);
522
523 if (solver<0)
524 {
525 solver=1;
526 GET_PARAMETER(1, "elast solver", "%d", &solver);
527 GET_PARAMETER(1, "elast solver tolerance", "%f", &(sd.tolerance));
528 GET_PARAMETER(1, "elast solver max iteration", "%d", &(sd.max_iter));
529 GET_PARAMETER(1, "elast solver info", "%d", &(sd.info));
530 GET_PARAMETER(1, "elast solver omega", "%f", &omega);
531 }
532
533
534 if (solver)
535 cg_multi(&sd, DIM, mat_phase, f_h, u_h);
536
537 else
538 {//TEST_EXIT(prob_data_phase->sol_ex,"neither exact sol nor solver\n");
539 // eval_time_ph = adapt_elast->time;
540 for (i=0; i<DIM;i++)
541 {
542 int diag_ind = i*DIM + i;
543 if ((prob_datas_elast)[/*(i+1)*(i+2) - 1*/diag_ind ]->sol_ex)
544 interpol((prob_datas_elast)[diag_ind]->sol_ex, u_h[i]);/*ok Baustelle*/
545 else MSG("heat solver switched off, but no ex_sol given\n");
546 }
547 }
548
549 for (i=0; i<DIM;i++)
550 {
551 #if 0
552 print_dof_real_vec(build_elast->get_sol(i));
553 print_dof_real_vec(u_h[i]);
554 print_dof_matrix(build_elast[i]->get_mat(i,i));
555 WAIT;
556 #endif
557 dof_copy( build_elast->get_sol(i), dudt[i]);/*ok Baustelle*/
558 dof_axpy(-1.0, build_elast->get_old_sol(i), dudt[i]);
559 dof_scal(/*prob_data->prob_data_heat.latent_heat*/1.0/adapt_elast/*PE*/->timestep, dudt[i]);
560 }/*Baustelle, die Zeiten muessen gesetzt sein!!!!*/
561 return;
562 }
563
564 static void interpol0(MESH *mesh)
565 { FUNCNAME("interpol0 (elast)");
566 //interpol(prob_data_heat->sol_0,base_heat->get_sol() );
567 int i,j,n;
568 dof_compress(mesh);
569 TEST_EXIT(fe_space,"no fe_space yet\n");
570 TEST_EXIT(fe_space->mesh,"no fe_space->mesh yet\n");
571 n =fe_space->bas_fcts->n_bas_fcts;
572 for (i=0; i<DIM; i++)
573 {
574 dof_set(0.0,build_elast->get_sol(i));
575 dof_set(0.0,build_elast->get_old_sol(i));
576 }
577 for (j=0; j<DIM; j++)
578 {
579 if ((prob_datas_elast)[j*DIM + j]->sol_0)
580 {
581 MSG("(prob_datas_elast)[...]->sol_0 will be used\n");
582 interpol((prob_datas_elast)[j*DIM + j]->sol_0,build_elast->get_sol(j));
583 }
584 else ERROR("No prob_datas_elast)[%d *DIM + %d]->sol_0!\n",j,j );
585 }
586 if (adapt_elast->adapt_space->info >= 8)
587 {
588 for (i=0; i<DIM;i++)
589 {
590 print_dof_real_vec(build_elast->get_rhs(i));
591 if (adapt_elast->adapt_space->info >= 9)
592 for ( j=0; j<DIM; j++)
593 print_dof_matrix(build_elast->get_mat_block(i ,j));MSG("\n");
594 }
595 }
596
597 init_elast_timestep(mesh, nil);
598 INFO(adapt_elast->adapt_initial->info, 2,
599 "time:%f\n", get_time());
600 return;
601 }
602
603 /****************************************************************************/
604 /* Functions for error estimate: */
605 /* estimate(): calculates error estimate via heat_est() */
606 /* calculates exact error also (only for test purpose), */
607 /* called by adapt_method_stat() */
608 /****************************************************************************/
609 //Baustelle!!
610 static REAL estimate_phase(MESH *mesh, ADAPT_STAT *adapt)
611 {
612 FUNCNAME("estimate_phase");
613 static int i,degree;
614
615 adapt_elast->adapt_space->err_sum = 0.0 ;
616 adapt_elast->adapt_space->err_max = 0.0 ;
617 //wir werden sehen
618
619 est_elast->clear_indicator( mesh);
620
621 degree = 2*fe_space->bas_fcts->degree; /*Vorsicht! evtl u_h[?] nehmen*/
622 err_L2 = 0.0;
623 err_H1 = 0.0;
624 time_est +=est_elast->estimator(adapt_elast);
625 for (i=0;i<DIM;i++)
626 {
627 //Debugging:
628 // print_dof_real_vec(est_elast[i]->err_estimate);
629 // graphics(mesh, adapt_elast->adapt_space->get_el_est/*( EL *el)*/, nil, nil, 1);
630 if ((prob_datas_elast)[i*DIM + i]->sol_ex)
631 {
632 err_L2 += L2_err((prob_datas_elast)[i]->sol_ex, build_elast->get_sol(i), nil, false, false, nil, nil);
633 INFO(adapt_elast->info, 2,
634 "time=%.4le ||u-uh||L2 = %.8le\n", adapt_elast->time, err_L2);
635 }
636 else
637 {
638 err_L2 = 0.0;
639 }
640 /* ersma so
641 if ((*prob_datas_elast)[i]->grd_sol_ex)
642 {
643 err_H1 += H1_err((*prob_datas_elast)[i]->grd_sol_ex,build_elast[i]->get_sol(), nil, 0, nil, nil);
644 }
645 else
646 {
647 err_H1 = 0.0;*/
648 }
649
650 INFO(adapt_elast->info, 2,
651 "time=%.4le, adapt_space->: err_sum^2 = %.8le, tolerance = %.8le max^2=%.3le\n", adapt_elast->time,
652 adapt_elast->adapt_space->err_sum,adapt_elast->adapt_space->tolerance, adapt_elast->adapt_space->err_max);
653 INFO(adapt_elast->info, 2,"time est: %8le\n", time_est);
654 return(adapt_elast->adapt_space->err_sum);
655 }
656
657 /****************************************************************************/
658 #if 0
659 static REAL est_initial_phase(MESH *mesh, ADAPT_STAT *adapt)
660 {
661 FUNCNAME("est_initial_phase");
662 static REAL C = -1.0;
663
664 if (C < 0.0) {
665 C = 1.0;
666 GET_PARAMETER(1, "elast estimator C0", "%f", &C);
667 }
668
669 adapt->err_sum = L2_err_c(prob_data_phase->sol_0, u_h[0],
670 nil, rw_el_est, &adapt->err_max,
671 C * sqrt(prob_data_phase->physconstants[SMALL]));
672 /*Baustelle. Evtl rausschmeissen u mehrmals f. Zeitschrittweite 0 loesen. u_h[0] kann evtl falsch werden*/
673 MSG("L2_err = %.3le\n", adapt->err_sum);
674
675 return(adapt->err_sum);
676 }
677 #endif
678 /****************************************************************************/
679
680 void init_elast(ADAPT_INSTAT *adapt_elast, const fem_elfunc* rhs_el_func_ptr,
681 const PROB_DATA_DIFF* const (*prob_datas_elast_ptr)[DIM*DIM])
682 {
683 FUNCNAME("init_elast");
684 int i,j=0, rhs_nr=0;
685 int quad_degree = 2*fe_space->bas_fcts->degree;
686 char key[128];
687 REAL theta;
688 // public_do_elfunc_on_el*
689 rhs_el_fct = (fem_elfunc*) rhs_el_func_ptr;
690 TEST_EXIT(adapt_elast,"no adapt_elast\n");
691 TEST_EXIT((*prob_datas_elast_ptr),"surely no prob_datas_elast\n");
692 GET_PARAMETER(1, "parameter theta", "%e", &theta);
693 if (theta < 0.5)
694 {
695 WARNING("You are using the explicit Euler scheme\n");
696 WARNING("Use a sufficiently small time step size!!!\n");
697 }
698
699 for (i=0;i<DIM;i++)//Zeile
700 {
701 for (j=0;j<DIM;j++)
702 { prob_datas_elast[i*DIM + j] = (*prob_datas_elast_ptr)[i*DIM + j];
703 TEST_EXIT(prob_datas_elast[i*DIM + j],"no prob_datas_elast[%d]\n",i*DIM + j);
704 MSG("elast %d %d diffcoeff[0][0]: %f, [0][1]: %f\n",i,j, (* prob_datas_elast_ptr)[i*DIM+j]->diffmat->getcomp(0,0),
705 (* prob_datas_elast_ptr)[i*DIM+j]->diffmat->getcomp(0,1) );
706 }
707 sprintf(key, "u_h%d",i);
708 u_h[i] = get_dof_real_vec(key, fe_space);
709 sprintf(key, "ef_h%d",i);
710 f_h[i] = get_dof_real_vec(key, fe_space);
711 sprintf(key, "uh_old%d",i);
712 uh_old[i] = get_dof_real_vec(key, fe_space);
713 sprintf(key, "uh_bound%d", i);
714 bound_vec[i] = get_dof_schar_vec(key, fe_space);
715 sprintf(key, "dudt%d",i);
716 dudt[i] = get_dof_real_vec(key, fe_space);
717 dudt[i]->refine_interpol = u_h[i]->refine_interpol = f_h[i]->refine_interpol = uh_old[i]->refine_interpol
718 = fe_space->bas_fcts->real_refine_inter;
719 dudt[i]->coarse_restrict = u_h[i]->coarse_restrict = f_h[i]->coarse_restrict = uh_old[i]->coarse_restrict
720 = fe_space->bas_fcts->real_coarse_inter;
721 dof_set(0.0, dudt[i]);
722
723 }
724 build_elast = new build_sys("u_h", u_h, uh_old, bound_vec
725 , f_h //eigentlich Bloedsinn!
726 , prob_datas_elast
727 ,rhs_el_fct
728 ,DIM, -1// quad_degree
729 ,&(adapt_elast->time), &(adapt_elast->timestep),theta);
730 est_elast= new sys_est("uh", build_elast,
731 &(adapt_elast->time), &(adapt_elast->timestep), /*int degree*/-1);
732 for (i=0;i<DIM;i++)//Zeile
733 {
734 uh_estimate[i] = est_elast->get_err_estimate(i);
735 }
736
737 adapt_elast->set_time = set_time; //in master.cc
738
739 adapt_elast->init_timestep = init_elast_timestep;
740 adapt_elast->close_timestep = close_elast_timestep;
741 /* adapt_elast->get_time_est = get_time_est; */
742
743 adapt_elast->adapt_initial->solve = interpol0;
744 adapt_elast->adapt_initial->estimate = estimate_phase; /*est_initial_phase;*/
745 adapt_elast->adapt_initial->get_el_est = get_el_est;
746 adapt_elast->adapt_initial->marking = okmarking; /* wrapper, adapt.c Standard. */
747
748 // adapt_elast->adapt_space->build_after_coarsen = build; geht im Allgemeinen nicht
749 adapt_elast->adapt_space->solve =solve_system;
750 adapt_elast->adapt_space->estimate = estimate_phase;
751 adapt_elast->adapt_space->get_el_est = get_el_est; /* static in PE_phase!"*/
752 adapt_elast->adapt_space->get_el_estc = get_el_estc;/* static in PE_phase !"*/
753 // adapt_elast->adapt_space->marking = okmarking; /* wrapper, adapt.c Standard. */
754 return;
755 }