Debian Codegraph @

add_ons/albertasystems/Elast/Common/elast_test.cc

raw
1 //#include "phase_elast.hh"
2 #include <ctype.h>
3 #include "alberta.h"
4 #include "newalberta.hh"
5 #include "do_on_el.hh"
6 #include "do_elfunc_on_el.hh"
7 #include "prototype_fem_elfunc.hh"
8 #include "fem_elfunc.hh"
9 #include "fem_base.hh"
10 #include "build_stat.hh"
11 #include "build_diff.hh"
12 #include "est.hh"
13 #include "ellipt_est.hh"
14 #include "parab_est.hh"
15 #include "master.hh"
16 #include "graphics.hh"
17 #include "operator_parts.hh"
18 #include "elast_problem.hh"
19 #include "elast.hh"
20 #include "adapt.hh"
21 #if USE_NCDF
22 #include "dxexport.hh"
23 #endif
24 #include "periodic.h"
25 #include "heat.hh"
26 #include "heat_problem.hh" //fuer Test-Polynome
27 #include "th_strain_rhs.hh"
28 // Konstanten >0
29 REAL time_est = 0.0;
30
31 struct leaf_data
32 {
33 U_CHAR mark; /* needed for special refinement ???? */
34 };// dummy. Mal ganz weghauen.muesste gehen
35
36 static REAL (*sol_ex)(const REAL_D x); /* known temperature soln */
37
38 /*dies dient zum Testen von elast.cc.*/
39
40 MESH *mesh;
41 ADAPT_INSTAT *adapt_elast = nil;
42 ADAPT_INSTAT *adapt_heat = nil;
43
44 REAL ph_tw_stat(const REAL_D x)
45 {
46 return( 0.5 );
47 }
48
49 static REAL p(REAL x)
50 {
51 return(x*x*(1-x)*(1-x));
52 }
53
54 static REAL pprime(REAL x)
55 {
56 return(2.0*x*(1.0-x)*(1.0-2.0*x));
57 }
58 REAL p2prime(REAL x)
59 {
60 return(12.0*x*x-12.0*x+2.0);
61 /* return(2.0*x*(1-x)*(1-2*x));*/
62 }
63
64 const REAL a=100.0; //
65
66 static REAL th_ex7(const REAL_D x)
67 {
68
69 return(723.0 + a*(p2prime(x[0])*p(x[1]) + p2prime(x[1])*p(x[0])) );
70 //better with perlit-start-temperature.
71 }
72 static REAL *grd_th_ex7(const REAL_D x, REAL t)
73 {
74 static REAL_D grad_th = {0.0, 0.0};
75 // static REAL c1=0.0;
76 // REAL alpha = 1.55E-5;
77 // if (!c1)...
78 grad_th[0] = 0.0;
79 grad_th[1] = 0.0;/*dummy*/
80 return(grad_th);
81 }
82
83
84
85 static const REAL *u_sol7(const REAL_D x, REAL_D u_x)/*Argumente u Konstrukt von interpol_d vorgegebe
86 n*/
87 {
88 FUNCNAME("u_sol7");
89 static REAL_D u = {0.0, 0.0};
90 static REAL c1=0.0;
91 const REAL alpha = 1.55E-5;
92 if (!c1) {
93 REAL lambda = prob_data_s11.physconstants[LAMBDA];
94 REAL mu = prob_data_s11.physconstants[MU];
95 c1=alpha*(3.0* lambda+ 2.0*mu)/(lambda+ 2.0*mu);
96 }
97 u[0]=a*pprime(x[0])*p(x[1])*c1;
98 u[1]=a*pprime(x[1])*p(x[0])*c1;
99 return(u);
100 }
101
102
103 static REAL u_sol7_0(const REAL_D x)
104 { //does not depend on u
105 return(u_sol7( x, NULL)[0]);
106 }
107 static REAL u_sol7_1(const REAL_D x)
108 { //neither
109 return(u_sol7( x, NULL)[1]);
110 }
111
112 static const REAL *gu_D_8(const REAL_D x, REAL t, REAL_D g_x)/*vorgegebene Verschiebung f Zugversuch p
113 rob 8*/
114 {
115 static REAL_D g = {0.0, 0.0};
116 REAL *gx = g_x ? g_x : g;
117 /*for (i=0; i<DIM_OF_WORLD; i++)*/
118 gx[0] = 0.0;
119 gx[1] = 0.01*x[1];
120
121 return(gx);
122 }
123
124 PROB_DATA_DIFF prob_data_heat_polynomial =
125 {
126 nil, nil, /* Diffusionsmatrix, order0 werden ueberschrieben!!*/
127 nil //massfunc
128 , 1 //constflag
129 ,{0.0, 0.077, 0.084,/*latent_heat pearl, Martensit*/ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, //phys. konstanten. Feld is eher f. phase gedacht
130 /*rhs function:*/
131 nil, th_ex7, nil /*gth_D_6*/,nil /* gth_N_5*/,
132 th_ex7, grd_th_ex7, /* th_ex, grd_th_ex */
133 };
134 PROB_DATA_DIFF prob_data_heat_const =
135 {
136 nil, nil, /* Diffusionsmatrix, order0 werden ueberschrieben!!*/
137 nil //massfunc
138 , 1 //constflag
139 ,{0.0, 0.077, 0.084,/*latent_heat pearl, Martensit*/ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
140 }, //phys. konstanten. Feld is eher f. phase gedacht
141 nil, th0, nil /*gth_D_6*/,nil /* liefert Nullen*/,
142 th0, grd_th_ex7, /* th_ex, grd_th_ex nicht dafuer gemacht aber ok*/
143 };
144
145
146 void init_problem_zugversuch(const PROB_DATA_DIFF* (* prob_datas_elast_ptr)[DIM*DIM])
147 {
148 FUNCNAME("init_problem_zugversuch");
149 int i =0,j=0;
150 init_problem_standard_steel();
151 // prob_data_s11.g_Dirich = ;
152 // alle rhs 0, kommt alles inne allgem. RHS
153 prob_data_s11.g_Neumann = nil;
154 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s11;
155 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s12;
156 if (DIM==3)
157 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s13;
158 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s21;
159 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s22;
160 if (DIM==3)
161 {
162 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s23;
163 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s31;
164 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s32;
165 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s33;
166 }
167 for (i=0; i<DIM; i++)
168 {
169 for (j=0;j<DIM;j++)// Spalte
170 {
171 MSG("phase %d %d diffcoeff[0][0]: %f, [0][1]: %f\n",i,j, (* prob_datas_elast_ptr)[i*DIM+j]->diffmat->getcomp(0,0),
172 (* prob_datas_elast_ptr)[i*DIM+j]->diffmat->getcomp(0,1) );
173 }
174 }//nur fuer konstante Koeffs
175 }
176
177
178 static void init_problem_polynomial(const PROB_DATA_DIFF* (* prob_datas_elast_ptr)[DIM*DIM])
179 {
180 FUNCNAME("init_problem_polynomial");
181 int i=0,j=0;
182 init_problem_standard_steel();
183 prob_data_s11.g_Dirich = nil;
184 prob_data_s11.g_Neumann = nil;
185 prob_data_s22.g_Dirich = nil;
186 prob_data_s22.g_Neumann = nil;
187 prob_data_s11.sol_0 =prob_data_s11.sol_ex = u_sol7_0; //war original andersrum!
188 prob_data_s22.sol_0 =prob_data_s22.sol_ex = u_sol7_1;
189 if (DIM==3)
190 prob_data_s33.sol_0 =prob_data_s33.sol_ex = 0;
191
192 // alle rhs 0, kommt alles inne RHS
193 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s11;
194 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s12;
195 if (DIM==3)
196 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s13;
197 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s21;
198 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *) &prob_data_s22;
199 if (DIM==3)
200 {
201 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s23;
202 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s31;
203 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s32;
204 (* prob_datas_elast_ptr)[i++] = (const PROB_DATA_DIFF *)&prob_data_s33;
205 }
206 for (i=0; i<DIM; i++)
207 {
208 for (j=0;j<DIM;j++)// Spalte
209 {
210 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),
211 (* prob_datas_elast_ptr)[i*DIM+j]->diffmat->getcomp(0,1) );
212 }
213 }//nur fuer konstante Koeffs
214 }
215
216
217
218 static REAL get_time_est(MESH *mesh, ADAPT_INSTAT *adapt)
219 {REAL a=time_est;
220 time_est=0.0; //irgendwie musser auf 0. normal in estimate, aber da hab ich ja nir den von
221 //Phase
222 return(a);
223 }
224 //Pfusch... tschuldigung!
225 static void (*solve_ptr)(MESH *mesh);
226 static void solve(MESH *mesh)
227 {
228 FUNCNAME("solve");
229 TEST_EXIT(adapt_heat,"no adapt_heat\n");
230 TEST_EXIT(adapt_elast,"no adapt_elast\n");
231
232
233 if (adapt_heat->adapt_space->solve)
234 adapt_heat->adapt_space->solve(mesh);
235
236 if (solve_ptr)
237 (*solve_ptr)(mesh);
238
239 return;
240 }
241 static void (*solve0_ptr)(MESH *mesh);
242 static void solve0(MESH *mesh)
243 {
244 FUNCNAME("solve0");
245 TEST_EXIT(adapt_heat,"no adapt_heat\n");
246 TEST_EXIT(adapt_elast,"no adapt_elast\n");
247
248
249 if (adapt_heat->adapt_initial->solve)
250 adapt_heat->adapt_initial->solve(mesh);
251
252 if (solve0_ptr)
253 (*solve0_ptr)(mesh);
254
255 return;
256 }
257
258 // graphik anstatt close_p_timestep aus phase.cc +
259 static void close_timestep(MESH *mesh, ADAPT_INSTAT *adapt)
260 {
261 FUNCNAME("close_p_timestep");
262 const DOF_REAL_VEC *const * const deformation = get_deformation();
263 // const DOF_REAL_VEC *const stress = get_stress();
264 const DOF_REAL_VEC *const temperature = get_temperature();
265
266 static const DOF_REAL_VEC * * vecs_for_save=MEM_CALLOC(DIM+4,const DOF_REAL_VEC *);
267 static const DOF_REAL_VEC * const * const uh_estimate = get_uh_estimate();
268 static int nwrite=-5, iwrite=0, count=0, i;
269 static char path[128] = "";
270 static char filename[128] = "";
271 static DOF_REAL_VEC * exact_sol_vec = get_dof_real_vec("exact_sol_vec",deformation[0]->fe_space) ;
272
273 interpol( sol_ex, exact_sol_vec); // Scheisse so
274 calc_stress();
275 if (nwrite < 0)
276 {
277 nwrite=0;
278 GET_PARAMETER(1, "write data", "%d", &nwrite);
279 GET_PARAMETER(1, "data path", "%s", path);
280 }
281
282 #if USE_NCDF
283 if (nwrite>0)
284 {
285 if ((iwrite % nwrite) == 0)
286 {
287 if (vecs_for_save[0]== nil)
288 {for (i=0; i<DIM; ++i )
289 {vecs_for_save[i] = deformation[i];
290 }
291 for (i=0; i<DIM; ++i )
292 {vecs_for_save[i + DIM] = uh_estimate[i];
293 }
294 }
295 sprintf(filename,"%s%s%05d",path,"results_test_",count++ );
296 if ( (i = dxexport(mesh, filename, adapt->time, vecs_for_save, 2*DIM )))
297 MSG("dxexport failed! Err Nr: %d\n",i);
298 }
299 }
300 #endif
301 graphics(mesh, nil, deformation[0], nil, 2);
302 graphics(mesh, adapt_elast->adapt_space->get_el_est/*( EL *el)*/, nil,
303 nil, 1);
304 //geht, debuggen graphics(mesh, get_plot_subdom/*( EL *el)*/, nil,
305 // nil, 1);
306 graphics(mesh, nil, deformation[1]/*exact_sol_vec*/, nil, 3);
307 graphics(mesh, nil, get_stress(), nil, 4);
308 // graphics(mesh, nil, temperature, nil, 4);
309
310
311
312 static FILE *file_ph00=nil,/* *file_ph01=nil;
313 static FILE *file_ph10=nil,*/ *file_ph11=nil;
314
315 if (!file_ph00)
316 {
317 if (!(file_ph00 = fopen("ph00.xg", "w"))){ perror("ph00.xg");}
318 // if (!(file_ph01 = fopen("ph01.xg", "w"))){ perror("ph01.xg");}
319 // if (!(file_ph10 = fopen("ph10.xg", "w"))){ perror("ph10.xg");}
320 if (!(file_ph11 = fopen("ph11.xg", "w"))){ perror("ph11.xg");}
321 }
322 fprintf(file_ph00, "%.6le %.6le\n",get_time(),dof_max(deformation[0])
323 );
324 fprintf(file_ph11, "%.6le %.6le\n",get_time(),dof_max(deformation[1]));
325 fflush(nil);
326 return;
327 }
328
329
330 static void init_dof_admin(MESH *mesh)
331 {
332 init_elast_dof_admin(mesh);
333 init_heat_dof_admin(mesh);
334 init_subdom_dof_admin(mesh);
335 init_err_dof_admin(mesh);
336 #if USE_NCDF
337 init_export_dof_admin(mesh);
338 #endif
339 return;
340 }
341 #define N_PROB 2
342 static int init_problem( const fem_elfunc** rhs_el_func_ptr
343 ,const PROB_DATA_DIFF* (* prob_datas_elast_ptr)[DIM*DIM]
344 ,const PROB_DATA_DIFF **return_prob_data_heat)
345 {
346 FUNCNAME("init_problem");
347 // char filename[156],filename2[156];
348 int pn = 0, rhs_nr =100;
349 GET_PARAMETER(2, "problem number", "%d", &pn);
350 TEST_EXIT(pn >= 0 && pn < N_PROB,"problem %d not defined\n", pn);
351 switch (pn)
352 {
353 case 0:
354 init_problem_zugversuch(prob_datas_elast_ptr);
355 *return_prob_data_heat= (const PROB_DATA_DIFF *)&prob_data_heat_const;
356 break;
357 case 1:
358 init_problem_polynomial(prob_datas_elast_ptr);
359 *return_prob_data_heat= (const PROB_DATA_DIFF *)&prob_data_heat_polynomial;
360 break;
361 default:
362 MSG("No such problem");
363 return(1);
364 }
365 GET_PARAMETER(1, "common elast rhs", "%d", &rhs_nr);
366 switch (rhs_nr)
367 {
368 case 0:
369 MSG("You will be using *prob_datas_elast_ptr rhs (rhs_nr=%d)\n", rhs_nr);
370 *rhs_el_func_ptr = nil;
371 break;
372 case 1:
373 MSG("You will be adding th_strain_rhs to rhs(rhs_nr=%d)\n", rhs_nr);
374 *rhs_el_func_ptr = new th_strain_rhs(get_temperature(), *prob_datas_elast_ptr, -1 /*quad_degree*/);
375 break;
376 default:
377 ERROR_EXIT("No such problem");
378 }
379 return(0);
380 }
381
382 int main(int argc, char **argv)
383 {
384 FUNCNAME("main");
385 int k;
386 /* char geom[128] = "300x300+0+0";*/
387 const fem_elfunc* rhs_el_func;
388 const PROB_DATA_DIFF* (prob_datas_elast)[DIM_OF_WORLD*DIM_OF_WORLD];
389 const PROB_DATA_DIFF* prob_data_heat= nil;
390 char filename[156];
391 FLAGS periodic = 0U;
392 /****************************************************************************/
393 /* first of all, init parameters of the init file */
394 /****************************************************************************/
395 MSG("started\n");
396 init_parameters(0, "elast_test.dat");
397 for (k = 1; k+1 < argc; k += 2)
398 ADD_PARAMETER(4, argv[k], argv[k+1]);
399
400 /****************************************************************************/
401 /* get a mesh, and read the macro triangulation from file */
402 /****************************************************************************/
403
404 GET_PARAMETER(1, "macro file name", "%s", filename);
405 GET_PARAMETER(2, "periodic", "%d", &periodic);
406
407 MACRO_DATA *data = read_macro(filename);
408
409 if (periodic) mesh = GET_MESH(DIM, "ALBERTA mesh", data, NULL,init_wall_trafos);
410 else mesh = GET_MESH(DIM, "ALBERTA mesh", data, NULL, NULL );
411 free_macro_data(data);
412
413 init_dof_admin(mesh);
414
415
416 init_problem( &rhs_el_func, &prob_datas_elast, &prob_data_heat);
417 sol_ex= prob_datas_elast[0]->sol_ex; /* known temperature soln */
418
419 adapt_heat = get_adapt_instat(DIM,"adapt_heat", "adapt_heat",
420 1, adapt_heat);
421
422 init_heat(adapt_heat, prob_data_heat);
423
424
425 /****************************************************************************/
426 /* init adapt structure and start adaptive method */
427 /****************************************************************************/
428 adapt_elast = get_adapt_instat(DIM,"adapt_elast", "adapt_master",
429 1, adapt_elast);
430 init_elast(adapt_elast, rhs_el_func, &prob_datas_elast);
431 init_master(mesh, adapt_elast);
432 // init_phase(adapt_, &prob_datas_)
433 adapt_elast->close_timestep = close_timestep;
434 adapt_elast->adapt_space->marking = okmarking;
435 adapt_elast->set_time = set_time; //in master.cc
436 adapt_elast->get_time_est = get_time_est; // time_est: globale var, steht summe
437 // aller return-werte (Teiproblem-time-ests) von parab_est::estimator drin
438 solve_ptr = adapt_elast->adapt_space->solve;
439 adapt_elast->adapt_space->solve = solve;
440 solve0_ptr = adapt_elast->adapt_initial->solve;
441 adapt_elast->adapt_initial->solve = solve0;
442
443
444 #if LOCALDEBUG
445 MSG("mesh->parametric: %h\n",
446 mesh->parametric);
447 #endif
448 adapt_method_instat(mesh, adapt_elast);
449
450 WAIT_REALLY;
451 return(0);
452 }
453