muMECH  1.0
tests_standa.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <iostream>
3 #include <time.h>
4 
5 #include "problem.h"
6 #include "types.h"
7 //#include "postprocessVtk.h"
8 #include "tests.h"
9 
10 
11 using namespace std;
12 using namespace mumech;
13 
14 
15 void test01(void);
16 void twoInclTest(void);
17 void energyTest01(void);
18 void transformace(void);
19 
21 void tests_standa(void)
22 {
23  std::cout << "standa test Running" << std::endl;
24  //twoInclTest();
25  //energyTest01();
26  //transformace();
27  test01();
28 }
29 
30 void twoInclTest(void) {
31  int i, j;
32  Problem *analFce2D;
33 
34  int nlc = 1;
35  int bodu = 1;
36  double **points2D;
37  points2D = new double*[bodu];
38  for (i = 0; i < bodu; i++) {
39  points2D[i] = new double[3];
40  points2D[i][2] = 0.;
41  points2D[i][0] = 0.;
42  points2D[i][1] = 0.;
43  }
44 
45  double **strain_2D = NULL;
46  strain_2D = new double*[nlc];
47  for (i = 0; i < nlc; i++)strain_2D[i] = new double[4];
48  double **stress_2D = NULL;
49  stress_2D = new double*[nlc];
50  for (i = 0; i < nlc; i++)stress_2D[i] = new double[4];
51  double **disp_2D = NULL;
52  disp_2D = new double*[nlc];
53  for (i = 0; i < nlc; i++)disp_2D[i] = new double[2];
54 
55 
56  double rs2D[] = { 1.0, 0.0, 0.0, 0.0 };
57 
58  analFce2D = new Problem();
59  analFce2D->set_problem_size(-1.1, -.6, 0, 1.1, .6, 0, 0.05);
60  analFce2D->set_problem_size(-7., -7., 0, 7., 7., 0, 0.05);
61  analFce2D->set_problem_size(-9., -7.5, 0, 9., 7.5, 0, 0.1);
62  //points2D[0][1] = 0.75;
63  double cc = 20;
64  analFce2D->set_problem_size(-cc, -cc, 0, cc, cc, 0, 0.05);
65 
66 
67  //char vtkFile_2D[] = "./input_SBAL1.vtk";
68  char vtkFile_2D[] = "./input_5x5.vtk";
69  analFce2D->read_input_file(vtkFile_2D);
70  analFce2D->set_SBAM(SBAT_STANDA);
71  //analFce2D->set_SBA_requiredNumberOfIterations(0);
72  analFce2D->set_intFieldsShape(2);
73  analFce2D->set_approximation(0);
74  analFce2D->set_SBA_optimized(true);
75  analFce2D->set_diffType(DT_NUMERICAL);
77  analFce2D->convert_to_equivalent_problem();
78  FILE *fstrain1,*fstrain2;
79  fstrain1 = fopen("./3x1_rez1_strain1.txt", "wt");
80  //fstrain2 = fopen("./3x1_rez1_strain2.txt", "wt");
81  //fstrain1 = fopen("./termit/5x5_rez1_strain1.txt", "wt");
82  //fstrain2 = fopen("./termit/5x5_rez1_strain2.txt", "wt");
83  //fstrain1 = fopen("./termit/rez2_d2_strain1.txt", "wt");
84  //fstrain2 = fopen("./termit/rez2_d2_strain2.txt", "wt");
85  for (points2D[0][0] = 0.0; points2D[0][0] <= 12.0; points2D[0][0] += 0.01) {
86  analFce2D->giveFieldsOfPoint(disp_2D, strain_2D, stress_2D, points2D[0], 't', 0, nlc, PFCM_FULL);
87  fprintf(fstrain1, "%lf %lf\n", points2D[0][0], strain_2D[0][0]);
88  //fprintf(fstrain2, "%lf %lf\n", points2D[0][0], strain_2D[0][3]);
89  }
90  delete analFce2D;
91  fclose(fstrain1);
92  //fclose(fstrain2);
93  //e(666);
94 }
95 
96 void energyTest01(void) {
97  Problem *analFce2D;
98  double *strn = new double[4];
99  for (int i = 0; i < 4; i++)strn[i] = 0.;
100  double space[] = { 4.,1. };
101  double ds = 0.05;
102  double **points;
103  int npoints = ceil((space[0] * 2 / ds)*(space[1] * 2 / ds));
104  int bod = 0;
105  points = new double*[npoints];
106  for (double x = -space[0] + ds / 2; x < space[0]; x += ds)
107  for (double y = -space[1] + ds / 2; y < space[1]; y += ds) {
108  points[bod] = new double[3];
109  points[bod][0] = x;
110  points[bod][1] = y;
111  points[bod][2] = 0.;
112  bod++;
113  }
114  printf("%d bodu\n", npoints);
115  int nlc = 1;
116  double **strain_2D = NULL;
117  strain_2D = new double*[nlc];
118  for (int i = 0; i < nlc; i++)strain_2D[i] = new double[4];
119  double **stress_2D = NULL;
120  stress_2D = new double*[nlc];
121  for (int i = 0; i < nlc; i++)stress_2D[i] = new double[4];
122  double **disp_2D = NULL;
123  disp_2D = new double*[nlc];
124  for (int i = 0; i < nlc; i++)disp_2D[i] = new double[2];
125  double rs2D[] = { 1.0, 0.0, 0.0, 0.0 };
126  analFce2D = new Problem();
127  analFce2D->set_problem_size(-5., -5., 0, 5., 5., 0, 0.02);
128  char vtkFile_2D[] = "./input_energyTest01.vtk";
129  analFce2D->read_input_file(vtkFile_2D);
130  analFce2D->set_SBAM(SBAT_STANDA);
131  //analFce2D->set_SBA_requiredNumberOfIterations(0);
132  analFce2D->set_intFieldsShape(0);
133  analFce2D->set_approximation(0);
134  analFce2D->set_SBA_optimized(true);
135  analFce2D->set_diffType(DT_NUMERICAL);
137  analFce2D->convert_to_equivalent_problem();
138  double energy = 0.;
139  for (int i = 0; i < npoints; i++) {
140  analFce2D->giveFieldsOfPoint(disp_2D, strain_2D, stress_2D, points[i], 't', 0, nlc, PFCM_OPTIMIZED);
141  for (int j = 0; j < 4; j++)energy += strain_2D[0][j] * stress_2D[0][j]*ds*ds;
142  for (int j = 0; j < 4; j++)strn[j] += strain_2D[0][j]*ds*ds;
143  }
144  energy /= space[0] * space[1] * 4;
145  delete analFce2D;
146 
147  printf("Energie = %lf\n", energy);
148  for (int j = 0; j < 4; j++)printf("%lf\n",strn[j]);
149  e(666);
150 }
151 /*
152 void test01(void) {
153  // rozblemcany
154 
155  int i, j;
156  Problem *analFce2D;
157 
158  int nlc = 1;
159  int bodu = 1;
160  double **points2D;
161  points2D = new double*[bodu];
162  for (i = 0; i < bodu; i++) {
163  points2D[i] = new double[3];
164  points2D[i][2] = 0.;
165  points2D[i][0] = 0.;
166  points2D[i][1] = 0.;
167  }
168 
169  double **strain_2D = NULL;
170  strain_2D = new double*[nlc];
171  for (i = 0; i < nlc; i++)strain_2D[i] = new double[4];
172  double **stress_2D = NULL;
173  stress_2D = new double*[nlc];
174  for (i = 0; i < nlc; i++)stress_2D[i] = new double[4];
175  double **disp_2D = NULL;
176  disp_2D = new double*[nlc];
177  for (i = 0; i < nlc; i++)disp_2D[i] = new double[2];
178 
179 
180  double rs2D[] = { 1.0, 0.0, 0.0, 0.0 };
181 
182  analFce2D = new Problem();
183  analFce2D->set_problem_size(-1.1, -.6, 0, 1.1, .6, 0, 0.05);
184  analFce2D->set_problem_size(-7., -7., 0, 7., 7., 0, 0.05);
185  analFce2D->set_problem_size(-9., -7.5, 0, 9., 7.5, 0, 0.1);
186  //points2D[0][1] = 0.75;
187  double cc = 20;
188  analFce2D->set_problem_size(-cc, -cc, 0, cc, cc, 0, 0.05);
189 
190 
191  //char vtkFile_2D[] = "./input_SBAL1.vtk";
192  char vtkFile_2D[] = "./input_5x5.vtk";
193  analFce2D->read_input_file(vtkFile_2D);
194  analFce2D->set_SBAM(SBAT_STANDA);
195  analFce2D->set_addExt(1);
196  //analFce2D->set_SBA_requiredNumberOfIterations(0);
197  analFce2D->set_intFieldsShape(0);
198  analFce2D->set_approximation(2);
199  analFce2D->set_SBA_optimized(true);
200  analFce2D->set_diffType(DT_NUMERICAL);
201  analFce2D->input_data_initialize_and_check_consistency();
202  analFce2D->convert_to_equivalent_problem();
203  FILE *fstrain;
204  fstrain = fopen("./3x1_rez1_strain1.txt", "wt");
205 
206  for (points2D[0][0] = -10.0; points2D[0][0] <= 0.0; points2D[0][0] += 0.01) {
207  analFce2D->giveFieldsOfPoint(disp_2D, strain_2D, stress_2D, points2D[0], 't', 0, nlc, PFCM_FULL);
208  fprintf(fstrain, "%lf %lf\n", points2D[0][0], strain_2D[0][0]);
209  }
210  delete analFce2D;
211  fclose(fstrain);
212 }*/
213 void test01(void) {
214  // rozblemcany
215 
216  int i, j;
217  Problem *analFce2D;
218 
219  int nlc = 1;
220  int bodu = 1;
221  double **points2D;
222  points2D = new double*[bodu];
223  for (i = 0; i < bodu; i++) {
224  points2D[i] = new double[3];
225  points2D[i][2] = 0.;
226  points2D[i][0] = 0.;
227  points2D[i][1] = 0.;
228  }
229 
230  double **strain_2D = NULL;
231  strain_2D = new double*[nlc];
232  for (i = 0; i < nlc; i++)strain_2D[i] = new double[4];
233  double **stress_2D = NULL;
234  stress_2D = new double*[nlc];
235  for (i = 0; i < nlc; i++)stress_2D[i] = new double[4];
236  double **disp_2D = NULL;
237  disp_2D = new double*[nlc];
238  for (i = 0; i < nlc; i++)disp_2D[i] = new double[2];
239 
240 
241  double rs2D[] = { 1.0, 0.0, 0.0, 0.0 };
242 
243  analFce2D = new Problem();
244 
245  //char vtkFile_2D[] = "./input_SBAL1.vtk";
246  char vtkFile_2D[] = "./input3incl.vtk";
247  analFce2D->read_input_file(vtkFile_2D);
248  analFce2D->set_SBAM(SBAT_STANDA);
249  //analFce2D->set_SBA_requiredNumberOfIterations(0);
250  analFce2D->set_intFieldsShape(4);
251  analFce2D->set_approximation(0);
252  analFce2D->set_SBA_optimized(true);
253  analFce2D->set_diffType(DT_NUMERICAL);
255  analFce2D->convert_to_equivalent_problem();
256  FILE *fstrain;
257  fstrain = fopen("./TST/comp_4.txt", "wt");
258 
259  for (points2D[0][0] = -10.0; points2D[0][0] <= 0.0; points2D[0][0] += 0.01) {
260  analFce2D->giveFieldsOfPoint(disp_2D, strain_2D, stress_2D, points2D[0], 't', 0, nlc, PFCM_FULL);
261  fprintf(fstrain, "%lf %lf\n", points2D[0][0], strain_2D[0][0]);
262  }
263  delete analFce2D;
264  fclose(fstrain);
265 }
266 
267 /*void transformace(void) {
268  Problem *analFce2D;
269  double **points2D;
270 
271  double **strain_2D = NULL;
272  strain_2D = new double*[1];
273  for (int i = 0; i < 1; i++)strain_2D[i] = new double[4];
274  double **stress_2D = NULL;
275  stress_2D = new double*[1];
276  for (int i = 0; i < 1; i++)stress_2D[i] = new double[4];
277  double **disp_2D = NULL;
278  disp_2D = new double*[1];
279  for (int i = 0; i < 1; i++)disp_2D[i] = new double[2];
280 
281  analFce2D = new Problem();
282  char vtkFile_2D[] = "./RezClanek/input.vtk";
283  analFce2D->read_input_file(vtkFile_2D);
284  analFce2D->set_SBAM(SBAT_STANDA);
285  analFce2D->set_addExt(1);
286  //analFce2D->set_SBA_requiredNumberOfIterations(0);
287  analFce2D->set_intFieldsShape(0);
288  analFce2D->set_approximation(0);
289  analFce2D->set_SBA_optimized(true);
290  analFce2D->set_diffType(DT_NUMERICAL);
291  analFce2D->input_data_initialize_and_check_consistency();
292  analFce2D->convert_to_equivalent_problem();
293 
294  char sfile[50], dfile1[50], dfile2[50],name[30];
295  int ind = 0;
296  sprintf(name,"3x1_d2_r2");
297  FILE *source, *dest1,*dest2;
298  sprintf(sfile, "./RezClanek/input_%s.txt", name);
299  sprintf(dfile1, "./RezClanek/termit/%s_xx.txt", name);
300  sprintf(dfile2, "./RezClanek/termit/%s_yy.txt", name);
301  source = fopen(sfile, "rt");
302  dest1 = fopen(dfile1, "wt");
303  dest2 = fopen(dfile2, "wt");
304 
305  int hodnot = 1201;
306  double x, value1,value2;
307  int inside;
308  double *strain_in, *strain_out;
309  strain_in = new double[4];
310  strain_out = new double[4];
311  for (int i = 0; i < 4; i++)strain_in[i] = 0.;
312  for (int i = 0; i < 4; i++)strain_out[i] = 0.;
313 
314 
315  for (int i = 0; i < hodnot; i++) {
316  fscanf(source, "%lf %lf %lf %d", &x, &value1, &value2, &inside);
317  strain_in[0] = value1;
318  strain_in[1] = value2;
319  if (inside==1) {
320  analFce2D->give_inside_strain_of_incl0_on_other_affect(strain_in, strain_out);
321  value1 = strain_out[0];
322  value2 = strain_out[1];
323  }
324  value1 += 1.;
325  fprintf(dest1, "%.2lf %lf\n", x, value1);
326  fprintf(dest2, "%.2lf %lf\n", x, value2);
327  }
328 
329 
330 
331  fclose(source);
332  fclose(dest1);
333  fclose(dest2);
334  delete analFce2D;
335 }*/
void input_data_initialize_and_check_consistency(void)
Initializes and checks consistency of all input data. This function has to be called after data input...
Definition: problem.cpp:127
void set_approximation(int val)
Definition: problem.cpp:178
void twoInclTest(void)
file of various types and symbolic constant definitions
Problem description.
Definition: problem.h:154
void energyTest01(void)
void set_problem_size(double a1, double a2, double a3, double b1, double b2, double b3, double node_distance)
Definition: problem.h:376
void set_SBA_optimized(bool val)
Set type of self-balancing algorithm.
Definition: problem.h:368
void set_SBAM(SBAtype val)
Definition: problem.h:372
void test01(void)
void set_diffType(DiffTypes val)
Sets type of differentiation, analytical by default.
Definition: problem.h:455
void tests_standa(void)
void read_input_file(const char *filename)
Reads filename VTK input file containing inclusion geometry and topology.
Definition: problem.cpp:357
New Standa&#39;s b.
Definition: types.h:91
long giveFieldsOfPoint(double **displc, double **strain, double **stress, const double *coords, char ptFlag, int rs, int nrs, PFCmode pfcMode=PFCM_OPTIMIZED, long reqIncl=-3, STRNotation tn=STRN_THEORETICAL_ROW) const
Function gives the analytical solution of the perturbation or total fields (displacements, strains and stresses) of a point for given set of remote strains.
Definition: problem.cpp:1706
void set_intFieldsShape(int val)
Definition: problem.h:371
Class Problem.
void transformace(void)
void e(int i)
void convert_to_equivalent_problem(void)
Converts the given heterogeneous problem to the equivalent problem.
Definition: problem.cpp:781