XALM  1.0
 Vše Třídy Prostory jmen Soubory Funkce Proměnné Výčty Hodnoty výčtu Friends Definice maker
strut_xalm.cpp
Zobrazit dokumentaci tohoto souboru.
1 #include "strut_xalm.h"
2 #include <math.h>
3 #include <stdio.h>
4 
5 
6 namespace xalm {
7 
8 
9 // funkce pro vypocet deformaci a vnitrnich sil na prvku
10 // In:
11 // x - vektor souradnic uzlu prvku (x1,y1,x2,y2)
12 // E- modul pruznosti
13 // r - vektor uzlovych posunu prvku (u1,v1,u2,v2)
14 //
15 // Out:
16 // eps deformace
17 // s napeti
18 //
19 void truss2d_postpro (const double *x, double E, const double *r, double &eps, double &s)
20 {
21  double l2 = ( (x[2]-x[0])*(x[2]-x[0]) + (x[3]-x[1])*(x[3]-x[1]) );
22 
23  double x12 = x[0] - x[2];
24  double y12 = x[1] - x[3];
25  double x21 = x[2] - x[0];
26  double y21 = x[3] - x[1];
27 
28  double u12 = r[0] - r[2];
29  double v12 = r[1] - r[3];
30  double u21 = r[2] - r[0];
31  double v21 = r[3] - r[1];
32 
33  eps = (1/l2)*(x12*r[0]+y12*r[1]+x21*r[2]+y21*r[3]) + (1/(l2*2))*(u12*r[0]+v12*r[1]+u21*r[2]+v21*r[3]);
34  s = E * eps;
35 }
36 
37 
38 // funkce pro vypocet vektoru vnitrnich uzlovych sil fint na prvku
39 // In:
40 // x - vektor souradnic uzlu prvku (x1,y1,x2,y2)
41 // r - vektor uzlovych posunu prvku (u1,v1,u2,v2)
42 // s - vnitrni sily = napeti
43 // A - plocha
44 //
45 // Out:
46 // fint
47 //
48 void truss2d_fint (const double *x, const double *r, double s, double A, double *fint)
49 {
50  double l = sqrt( (x[2]-x[0])*(x[2]-x[0]) + (x[3]-x[1])*(x[3]-x[1]) );
51 
52  double xu[4];
53  for (int i = 0; i<4; i++)
54  xu[i] = x[i] + r[i];
55 
56  fint[0] = s * (A/l) * (xu[0]-xu[2]);
57  fint[1] = s * (A/l) * (xu[1]-xu[3]);
58  fint[2] = s * (A/l) * (xu[2]-xu[0]);
59  fint[3] = s * (A/l) * (xu[3]-xu[1]);
60 }
61 
71 void truss2d (const double *x, double EA, double ke[4][4])
72 {
73  double length = sqrt( (x[2]-x[0])*(x[2]-x[0]) + (x[3]-x[1])*(x[3]-x[1]) );
74 
75  double c = (x[2]-x[0]) / length; double c2 = c*c;
76  double s = (x[3]-x[1]) / length; double s2 = s*s;
77 
78  double k = (EA/length);
79 
80  ke[0][0] = k * c2; ke[0][1] = k * c*s; ke[0][2] = k * -c2; ke[0][3] = k * -c*s;
81  ke[1][0] = k * c*s; ke[1][1] = k * s2; ke[1][2] = k * -c*s; ke[1][3] = k * -s2;
82  ke[2][0] = k * -c2; ke[2][1] = k * -c*s; ke[2][2] = k * c2; ke[2][3] = k * c*s;
83  ke[3][0] = k * -c*s; ke[3][1] = k * -s2; ke[3][2] = k * c*s; ke[3][3] = k * s2;
84 }
85 
87 double norm (double val)
88 {
89  if (val < 0) val *= -1;
90  return val;
91 }
92 
93 
96 {
97  // *** nastaveni promennych rodicovske tridy XALM ***
98  nsteps = 34;
99 
100  minStepLength = 0.01;
101  maxStepLength = 0.2;
102  initialStepLength = 0.2;
103 
104  Psi = 0.0; // displacement control on
105 
106  rtolf = rtold = 1.e-3;
107 
108  neq = 1;
109 
110 
111  // lokalni pozadavky, zavisle na FEM baliku ktery inkluduje XALM knihovnu
112  // sestavi matice tuhosti, vektor zatizeni atd.
113  this->initialize_local();
114 }
115 
118 {
119  int step = give_step();
120 
121  tisk1[step+1] = this->give_totalDisplacement()[0];
122  tisk2[step+1] = -this->give_loadLevel();
123 
124  if (step == this->nsteps-1){
125  FILE *file = fopen("graf1.xalm.dat", "w");
126  for (long i = 0; i <=nsteps; i++)
127  fprintf (file, "%g %g\n", tisk1[i], tisk2[i]);
128 
129  fclose(file);
130  }
131 }
132 
133 
136 {
137  // sestavit incrementalLoadVector
139  incrementalLoadVector[0] = -1;
140 
141  //
143  initialLoadVector[0] = 0;
144 
145 
146  // *** zde se nastavi popis vzperadla ***
147 
148  // souradnice uzlu 1. uzel 2. uzel
149  double xz[2][2] = { {0,0}, {4,3} };
150 
151  // vektor souradnic uzlu prvku (x1, y1, x2, y2)
152  xze[0] = xz[0][0];
153  xze[1] = xz[0][1];
154  xze[2] = xz[1][0];
155  xze[3] = xz[1][1];
156 
157  // modul pruznosti
158  E = 1.0;
159 
160  // plocha
161  A = 1;
162 
163  // typ matice tuhosti (false - elasticka, 1-tecna)
164  tangent_stiff_mtrx = false;
165 
166  // matice tuhosti, pro vzperadlo ma rozmer 1x1
167  k = 0;
168 
169  tisk1 = new double[nsteps+1]; memset (tisk1, 0, (nsteps+1)*sizeof(double));
170  tisk2 = new double[nsteps+1]; memset (tisk2, 0, (nsteps+1)*sizeof(double));
171 
172  tisk1[0] = 0.0;
173  tisk2[0] = 0.0;
174 }
175 
178 {
179  // vypocet tecne matice tuhosti, pokazde kdyz je vznesen pozadavek
180  if (tangent_stiff_mtrx) {
181  errol;
182  //sestaveni linearizovane podminky rovnovahy
183  // // ks = truss2d_initialstress(xze, A, s(1));
184  // // kg = truss2d_initialdeformation (xze, r(lm(1,:)), E*A);
185  // // if mtype == 1
186  // // k = klin +kg+ks;
187  // // else
188  // // k = klin;
189  // // end
190  // tady dat asi vypocet k = klin +kg+ks;
191  }
192  // vypocet elasticke matice tuhosti, jen v prvnim kroku
193  else {
194  if (this->give_step() == 0) {
195  double klin[4][4];
196  truss2d (xze, E*A, klin);
197  k = klin[3][3];
198  }
199  }
200 }
201 
203 void XALM_interface :: update_internal_forces (Dvctr *internalForces, const Dvctr *X)
204 {
205  double eps, s;
206  double fint[4];
207 
208  // vektor vsech posunu na prutu
209  double r[4];
210  r[0] = r[1] = r[2] = 0.0;
211  r[3] = (*X)[0];
212 
213  // dopocteni deformaci a napeti
214  truss2d_postpro (xze, E, r, eps, s);
215 
216  // dopocteni fint
217  truss2d_fint (xze, r, s, A, fint);
218  (*internalForces)[0] = fint[3];
219 }
220 
223 {
224  (*X)[0] = (*R)[0] / k;
225 }
226 
229 {
230  neq = 1;
231 
232  // souradnice uzlu
233  double xz[2][2] = {{0,0},{4,3}};
234 
235  // kodova cisla prvku
236  //lm = [1,2,3,4];
237 
238  // element nodes
239  int en[] {0,1};
240 
241  // typ matice tuhosti (0-elasticka, 1-tecna)
242  //int mtype = 0;
243 
244  // mode (0...load displacement plot, 1...convergence plot)
245  int mode = 0;
246 
247  // modul pruznosti
248  double E = 1.0;
249 
250  // plocha
251  double A = 1;
252 
253 
254 
255  // pocet predepsanych
256  int pneq = 3;
257 
258  // vektor zatizeni
259  double f[neq] = {0};
260 
261  // prirustek zatizeni
262  double df[neq] = {0};
263 
264  // matice tuhosti
265  //double k[neq][neq] = {0};
266 
267  // vektor neznamych posunuti
268  double ru[neq] = {0};
269 
270  // vektor vsech posunu
271  double r[neq+pneq] = {0};
272 
273  // residual vector
274  double res[neq] = {0};
275 
276  // vektor vnitrnich sil = napeti
277  //double s[1] = {0};
278 
279  //vektor pro ukladani historie chyby (graf konvergence)
280  //double rh;
281 
282 
283  f[0] = 0.00;
284  df[0]=-0.01;
285  double limit = 1.e-6;
286  double eps, s;
287  double fint[4];
288 
289  FILE *file = fopen("graf1.mumech.dat", "w");
290  // kontrola posunem
291  fprintf (file, "%g %g\n", 0.0, 0.0);
292 
293  double xze[] = { xz[en[0]][0], xz[en[0]][1], xz[en[1]][0], xz[en[1]][1] };
294  for (int i = 1; i<=35; i++) {
295  r[0] = r[1] = r[2] = 0.0;
296  r[3] = -i*0.2;
297  truss2d_postpro (xze, E, r, eps, s);
298 
299  // dopocteni fint
300  truss2d_fint (xze, r, s, A, fint);
301  if (mode == 0) // load -displacement plot
302  fprintf (file, "%g %g\n", r[3], fint[3]);
303  }
304  fclose(file);
305 
306 
307  r[3] = 0;
308 
309  file = fopen("graf2.mumech.dat", "w");
310  // kontrola posunem
311  fprintf (file, "%lf %lf\n", 0.0, 0.0);
312 
313  //cyklus prez prirustky zatizeni
314  for (int i = 0; i<5; i++) {
315 
316  res[0] = df[0];
317  double klin[4][4];
318  truss2d (xze, E*A, klin);
319  // //inicializace citace iteraci
320  double nite = 0;
321  //rh=[];
322  // iterace rovnovahy
323  while (norm(res[0]) > limit) {
324  nite = nite+1;
325  //sestaveni linearizovane podminky rovnovahy
326  // ks = truss2d_initialstress(xze, A, s(1));
327  // kg = truss2d_initialdeformation (xze, r(lm(1,:)), E*A);
328  // if mtype == 1
329  // k = klin +kg+ks;
330  // else
331  // k = klin;
332  // end
333 
334  // vyresime soustavu klin * ru = res kde neznama je ru
335  // ru[0] = klin[3][3] \ res[0];
336 
337  ru[0] = res[0] / klin[3][3];
338 
339  r[3] += ru[0];
340  // dopocteni deformaci a napeti
341  truss2d_postpro (xze, E, r, eps, s);
342 
343  // dopocteni fint
344  truss2d_fint (xze, r, s, A, fint);
345 
346  res[0] = -1.0*(fint[3] - f[0] - df[0]);
347  //rh(nite)=abs(res(1)); %remember for convergence plot
348  }
349 
350  if (mode == 0) // load -displacement plot
351  fprintf (file, "%g %g\n", r[3], fint[3]);
352  else
353  ; //semilogy (rh)
354 
355  // [nite; fint(4)] ?????
356  f[0] = f[0] + df[0];
357 
358  }
359 
360  fclose(file);
361 
362 }
363 
364 } // namespace xalm
virtual void update_internal_forces(Dvctr *internalForces, const Dvctr *X)
Definition: strut_xalm.cpp:203
Dvctr * resize_ignore_vals(long newsize)
Definition: arrays.h:622
double minStepLength
Minimalní délka kroku.
Definition: xalm.h:156
Definition: xalm.cpp:9
void truss2d_postpro(const double *x, double E, const double *r, double &eps, double &s)
Definition: strut_xalm.cpp:19
Dvctr initialLoadVector
Vektor pocatecniho zatizeni, nemeni se behem vypoctu, je aplikovan cely.
Definition: xalm.h:171
#define errol
Definition: gelib.h:151
virtual void initialize(void)
Funkce nemá parametry a nic nevrací.
Definition: strut_xalm.cpp:95
virtual void update_stiffness_matrix(const Dvctr *X)
Definition: strut_xalm.cpp:177
long nsteps
Počet zatěžovacích kroků.
Definition: xalm.h:155
const double * give_totalDisplacement(void) const
Funkce vrátí konstantní ukazatel na vektor celkových posunů.
Definition: xalm.h:73
double rtold
Tolerance relativní chyby nevyrovnaných posunů.
Definition: xalm.h:165
double Psi
Parametr kontroly kroku. Pokud je rovno 0, tak se jedná o kontrolu přírůstkem posunutí, pokud je rovno nekonečnu, tak se jedná o kontrolu přírůstkem zatížení.
Definition: xalm.h:162
double rtolf
Tolerance relativní chyby nevyrovnaných sil.
Definition: xalm.h:164
void truss2d_fint(const double *x, const double *r, double s, double A, double *fint)
Definition: strut_xalm.cpp:48
double maxStepLength
Maximalní délka kroku.
Definition: xalm.h:157
Dvctr incrementalLoadVector
Vektor prirustkoveho zatizeni, meni se se stupnem lambda.
Definition: xalm.h:170
void initialize_local(void)
Definition: strut_xalm.cpp:135
virtual void update_step(void)
Ve funkci je možné po každém provedeném iteračním kroku vykonat požadované úkony. ...
Definition: strut_xalm.cpp:117
int give_step(void)
Funkce vrací číslo aktuálního zatěžovacího kroku.
Definition: xalm.h:178
double give_loadLevel(void) const
Funkce vrátí loadLevel - dosažený stupeň přírůstkového zatížení.
Definition: xalm.h:75
double initialStepLength
Počáteční délka kroku.
Definition: xalm.h:158
Interface to library XALM.
void truss2d(const double *x, double EA, double ke[4][4])
funkce pocita matici tuhosti tazeneho-tlaceneho prutu ve 2d (truss 2d) In: x - vektor souradnic uzlu ...
Definition: strut_xalm.cpp:71
virtual void lineq_solve(Dvctr *X, const Dvctr *R)
Definition: strut_xalm.cpp:222
double norm(double val)
norma = delka vektoru, pro vektor delky 1 je to absolutni hodnota
Definition: strut_xalm.cpp:87
int step
Aktuální krok.
Definition: xalm.h:92
long neq
Pocet rovnic v matici soustavy = pocet neznamych.
Definition: xalm.h:169