muMECH  1.0
comparison.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: comparison.cpp
10 // author(s): Ladislav Svoboda
11 // language: C, C++
12 // license: This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 //********************************************************************************************************
26 
27 // toto je kvuli WIN32_LEAN_AND_MEAN
28 #include "types.h"
29 
30 #include "comparison.h"
31 #include "problem.h"
32 #include "mesh.h"
33 
34 
35 namespace mumech {
36 
37 
39 double Comparison :: cmp_mm_ansys_total_energy (const char *basename, const char *vtkGeomFile, int lc)
40 {
41  fprintf (stdout, "cmp: \n");
42 
43  char name[1023];
44 
45  // MESH
46  Mesh *mesh = new Mesh(0, NULL);
47  sprintf (name, "%sANSYS/rslts_lc%d/list.IB.mesh.vtu", basename, lc); // orig: IB
48  mesh->read_geometry_file_vtk (name, -1, -1, false);
49 
50  // muMECH reseni
51  Problem *pMM = new Problem;
53  int pidMM = mesh->add_problem(pMM);
54  mesh->compute_element_fields ('t', false, true, true, pidMM, lc, 1, PFCM_FULL); // termitovo ERROR kdyz tam dam optimize tak se to sere
55  mesh->compute_node_fields ('t', true, false, false, pidMM, lc, 1, PFCM_FULL); // termitovo ERROR kdyz tam dam optimize tak se to sere
56 
57  // ANSYS reseni
58  ProblemFEM *pAS = new ProblemFEM (pMM->give_dimension(), pMM->give_nLC());
59  int pidAS = mesh->add_problem(pAS);
60  sprintf (name, "%sANSYS/rslts_lc%d/list.IB.rslt.vtu", basename, lc);
61  mesh->read_geometry_file_vtk (name, pidAS, lc, true);
62 
63 
64  // ENERGY
65  // energy error
66  double Err_all = mesh->give_error(pidMM, pidAS, lc);
67  fprintf (stdout, "Error: %.3lf%%\n", Err_all);
68 
69 
70  // PRINT
71  if (1) {
72  sprintf (name, "%s%s", basename, "cmp_energy.meshMM.vtk");
73  mesh->print_geometry_file_vtk (name, pidMM, lc, 1);
74 
75  sprintf (name, "%s%s", basename, "cmp_energy.meshAS.vtk");
76  mesh->print_geometry_file_vtk (name, pidAS, lc, 1);
77  }
78 
79  delete mesh;
80  delete pMM;
81  delete pAS;
82 
83  return Err_all;
84 }
85 
86 
89 {
90  fprintf (stdout, "cmp: \n");
91 
92  char name[1023];
93 
94  Mesh *mesh = NULL;
95 
96  int pidMM;
97  double Eh, Et, Ep;
98 
99  double p1[3]; p1[2] = 0.0;
100  double p2[3]; p2[2] = 0.0;
101  long nn[3]; nn[2] = 0;
102  double x1, x2, y1, y2, dx, dy;
103  x1 = y1 = -5.0;
104  x2 = y2 = 5.0;
105  dx = dy = 0.02;
106  double delta = 1.0;
107 
108  // muMECH reseni
109  Problem *pMM = new Problem;
110  pMM->generate_equiv_1x2dI_2d(1.0, 0.2, NULL, 0.0, 0.0, 10, 0.3, 1.0, 0.5, 0.0, DT_NUMERICAL);
111 
112  int steps = 13;
113 
114  FILE *file = fopen ("energy_MM.txt", "wt");
115 
116  sprintf (name, "energy_MM.lc0.%2ld.%4.2lf.dat", steps, dx); FILE *file0 = fopen (name, "wt");
117  sprintf (name, "energy_MM.lc1.%2ld.%4.2lf.dat", steps, dx); FILE *file1 = fopen (name, "wt");
118  sprintf (name, "energy_MM.lc2.%2ld.%4.2lf.dat", steps, dx); FILE *file2 = fopen (name, "wt");
119 
120 
121  for (int step=0; step<steps; step++) {
122  // regular mesh
123  p1[0] = x1 - step*delta; p1[1] = y1 - step*delta;
124  p2[0] = x2 + step*delta; p2[1] = y2 + step*delta;
125  nn[0] = (p2[0] - p1[0]) / dx; nn[1] = (p2[1] - p1[1]) / dy;
126 
127  fprintf (file, "BB %lf \n", p2[0]);
128 
129  // MESH
130  mesh = new Mesh(0, NULL);
131  mesh->generate_regular_mesh(p1, p2, nn);
132  pidMM = mesh->add_problem(pMM);
133  mesh->compute_element_fields ('t', false, true, true, pidMM, 0, 0, PFCM_FULL); // termitovo ERROR kdyz tam dam optimize tak se to sere
134  //mesh->compute_node_fields ('t', true, false, false, pidMM, lc, 1, PFCM_FULL); // termitovo ERROR kdyz tam dam optimize tak se to sere
135 
136 
137  for (int lc=0; lc<3; lc++) {
138  fprintf (file, " lc = %ld\n", lc);
139 
140  Eh = mesh->give_homog_energy(pidMM, lc);
141  fprintf (file, " lc%ld Ehom = %lf\n", lc, Eh);
142 
143  Et = mesh->give_total_energy(pidMM, lc);
144  fprintf (file, " lc%ld Etot = %lf\n", lc, Et);
145 
146  fprintf (file, " lc%ld Epert num = Etotal - Ehomog = %lf\n", lc, Et - Eh);
147 
148  if (lc == 0) fprintf (file0, "%lf %lf\n", p2[0], Et - Eh);
149  if (lc == 1) fprintf (file1, "%lf %lf\n", p2[0], Et - Eh);
150  if (lc == 2) fprintf (file2, "%lf %lf\n", p2[0], Et - Eh);
151 
152  //Ep = pMM->compute_supplement_energy (lc);
153  //fprintf (file, "Epert anal = %lf\n", Ep);
154  }
155 
156  delete mesh;
157  }
158 
159 
160  fclose(file);
161  fclose(file0);
162  fclose(file1);
163  fclose(file2);
164 
166  //if (1) {
167  // sprintf (name, "%s%s", basename, "cmp_energy.meshMM.vtk");
168  // mesh->print_geometry_file_vtk (name, pidMM, lc, 1);
169  //
170  // sprintf (name, "%s%s", basename, "cmp_energy.meshAS.vtk");
171  // mesh->print_geometry_file_vtk (name, pidAS, lc, 1);
172  //}
173 
174  //delete mesh;
175  delete pMM;
176 }
177 
178 
179 
180 } // end of namespace mumech
181 
182 /*end of file*/
void print_geometry_file_vtk(const char *rsltFileName, int pid, int lc, int nLC)
Print output file with mesh geometry with results to vtk file.
Definition: mesh.cpp:956
void generate_regular_mesh(const double *p1, const double *p2, const long *n)
Generate regular mesh geometry of rectangular cuboid shape compound of rectangular cuboid shape eleme...
Definition: mesh.cpp:260
int give_dimension(void) const
Definition: problem.h:86
file of various types and symbolic constant definitions
virtual int give_nLC(void) const
Give number of load cases, e.i. number of load cases, i.e. number of Remote_strain fields...
Definition: problem.h:334
Problem * read_inclusions_plus_initialize_and_print(const char *inclusion_file, const char *equiv_file, DiffTypes dt)
Definition: problem.cpp:2059
Problem description.
Definition: problem.h:154
static void give_energy_MM()
compute energy of mumech solution
Definition: comparison.cpp:88
Class Mesh.
void compute_node_fields(char flag, bool displc_flag, bool strain_flag, bool stress_flag, int pid, int lc, int nLC, PFCmode pfcMode)
Definition: mesh.cpp:1111
static double cmp_mm_ansys_total_energy(const char *basename, const char *vtkGeomFile, int lc)
Definition: comparison.cpp:39
Class Comparison.
void read_geometry_file_vtk(const char *vtkMeshFile, int pid, int lc, bool add)
Read input file with mesh geometry from vtk file.
Definition: mesh.cpp:355
double give_homog_energy(int lc, int pid=0)
Definition: mesh.cpp:1238
double give_error(int pid1, int pid2, int lc)
Definition: mesh.cpp:1284
void compute_element_fields(char flag, bool displc_flag, bool strain_flag, bool stress_flag, int pid, int lc, int nLC, PFCmode pfcMode)
predpokladame trojuhelnikove nebo tetrahedron prvky, tj. na elementu budeme drzet jednu hodnotu ...
Definition: mesh.cpp:1138
double give_total_energy(int pid, int lc)
Definition: mesh.cpp:1269
Class Mesh contains and handles all mesh data.
Definition: mesh.h:52
#define delta(i, j)
Definition: macros.h:187
int add_problem(const Problems *p)
Definition: mesh.cpp:148
void generate_equiv_1x2dI_2d(double Em, double num, const double *rs, double x, double y, double E, double nu, double a1, double a2, double ea, DiffTypes dt)
Definition: problem.cpp:147
Problem description for FEM problem with results.
Definition: problem.h:121
Class Problem.