Моделирование провисания балки

Материал из Department of Theoretical and Applied Mechanics
Версия от 19:41, 19 июня 2019; 217.66.152.173 (обсуждение) (Визуализация)

Перейти к: навигация, поиск

Описание

Моделирование провисания балки из дерева или стали

Исполнитель: Волоцкий Арсений,Штамм Максим

Файл: [[1]]

Математическая модель

Основные допущения

При моделировании балки были сделаны следующие допущения:

  1. Не учитывается скручивание;

Входные данные

Перед началом моделирования задаются следующие данные:

  1. Размеры балки
  2. Материал

Визуализация

Код программы

Текст программы на языке JavaScript:
  1 let ctx     = space.getContext("2d"),
  2         ctt     = graph.getContext("2d"),
  3 
  4         Fg,
  5         R,
  6         rho,
  7         E,
  8         t       = 0,
  9         dt      = 0.01, //переменная интегрироваания
 10         g       = 10,   //уск. св. падения
 11         k,              //коэф. жесткости
 12         F_l_y,          //сила упругости в левой пружине по оси у
 13         F_r_y,          //сила упругости в правой пружине по оси у
 14         F_y,            //суммарная сила по оси у
 15         F_l_x,          //сила упругости в левой пружине по оси х
 16         F_r_x,          //сила упругости в правой пружине по оси х
 17         F_x,            //суммарная сила упругости по х
 18         F_dis_y,        //сила сопр-ия у
 19         F_dis_x,        //сила сопр-ия x
 20         betta,          //коэф затухания
 21         cos_l,          //зн-ие косинуса для левой пружины
 22         cos_r,          //зн-ие косинуса для правой пружины
 23         sin_l,          //зн-ие синуса для левой пружины
 24         sin_r,          //зн-ие синуса для правой пружины
 25         a,              //width
 26         b,              //height
 27         L,              //length
 28         ball_weight,
 29         L_spr,
 30         scale_x,
 31         y_max,
 32         max_pot_energy,
 33         i;
 34 
 35                             //модуль физики
 36 
 37     function right_spr_deform(x, x_next, y, y_next) {
 38         return Math.sqrt(Math.pow((x_next - x),2)+Math.pow((y_next - y),2));
 39     }
 40 
 41 
 42     function left_spr_deform(x, x_prev, y, y_prev) {
 43         return Math.sqrt(Math.pow((x - x_prev),2)+Math.pow((y - y_prev),2));
 44     }
 45 
 46 
 47     function physics(i)
 48     {
 49         cos_l = (r[i].y - r[i-1].y) / left_spr_deform(r[i].x, r[i-1].x, r[i].y, r[i-1].y);
 50         sin_l = (r[i].x - r[i-1].x) / left_spr_deform(r[i].x, r[i-1].x, r[i].y, r[i-1].y);
 51 
 52         F_l_y = -k * (left_spr_deform(r[i].x, r[i-1].x, r[i].y, r[i-1].y) - L_spr) * cos_l;
 53         F_l_x = -k * (left_spr_deform(r[i].x, r[i-1].x, r[i].y, r[i-1].y) - L_spr) * sin_l;
 54 
 55         cos_r = (r[i+1].y - r[i].y) / right_spr_deform(r[i].x, r[i+1].x, r[i].y, r[i+1].y);
 56         sin_r = (r[i+1].x - r[i].x) / right_spr_deform(r[i].x, r[i+1].x, r[i].y, r[i+1].y);
 57 
 58         F_r_y = k * (right_spr_deform(r[i].x, r[i+1].x, r[i].y, r[i+1].y) - L_spr) * cos_r;
 59         F_r_x = k * (right_spr_deform(r[i].x, r[i+1].x, r[i].y, r[i+1].y) - L_spr) * sin_r;
 60 
 61         F_dis_x = -betta * r[i].v_x;
 62         F_dis_y = -betta * r[i].v_y;
 63 
 64         F_y = F_r_y + F_l_y + Fg + F_dis_y;
 65         F_x = F_r_x + F_l_x + F_dis_x;
 66 
 67         r[i].v_y = r[i].v_y + F_y * dt / r[i].m;
 68         r[i].v_x = r[i].v_x + F_x * dt / r[i].m;
 69 
 70         r[i].x = r[i].x + r[i].v_x * dt;
 71         r[i].y = r[i].y + r[i].v_y * dt;
 72     }
 73 
 74 
 75     function teor_phys()
 76     {
 77         a = parseInt(document.getElementById("p1").value); //width
 78         b = parseInt(document.getElementById("p2").value); //height
 79         L = parseInt(document.getElementById("p3").value); //length
 80 
 81         let Qn   = rho * b / 1000 * a / 1000,
 82             I    = Math.pow(a,3) * b / 12 / 1000000;
 83 
 84         R = 5 / 384 * Qn * Math.pow(L,4) / (E * I);
 85         console.log(R+' m');
 86 
 87         ball_weight = rho * a / 1000 * b / 1000 * L / K;
 88         k = ball_weight * 100;
 89         betta = k / 20;
 90         L_spr = L / (K - 1);
 91         scale_x = 380 / L;
 92 
 93         for (i=0; i<K; i++)
 94         {
 95             r.push(new Ball(i * L_spr, 0, ball_weight, 0, 0));
 96         }
 97         Fg = -r[1].m * g;
 98     }
 99 
100 
101     function fast_modeling()
102     {
103         while (t < 200)
104         {
105             for (i = 1; i < K - 1; i++)
106             {
107                 physics(i);
108             }
109             t += dt;
110         }
111         y_max = -r[4].y;
112         t = 0;
113         for (i = 1; i < K - 1; i++)
114         {
115             r[i].y = 0;
116             r[i].x = i * L_spr;
117             r[i].v_x = 0;
118             r[i].v_y = 0;
119         }
120         max_pot_energy = sum_pot_energy();
121     }
122 
123 
124     function sum_springs_energy()
125     {
126         let sum_spr_energy = 0,
127             L_def,
128             R_def;
129         for (i = 1; i < K; i += 2){
130             L_def = left_spr_deform(r[i].x, r[i-1].x, r[i].y, r[i-1].y) - L_spr;
131             R_def = right_spr_deform(r[i].x, r[i+1].x, r[i].y, r[i+1].y) - L_spr;
132             sum_spr_energy += k * Math.pow(L_def,2) / 2 + k * Math.pow(R_def,2) / 2;
133         }
134         return sum_spr_energy;
135     }
136 
137 
138     function sum_kin_energy()
139     {
140         let E_kin = 0;
141         for (i = 1; i < K - 1; i++)
142         {
143             E_kin += r[i].kin_energy();
144         }
145         return E_kin;
146     }
147 
148 
149     function sum_pot_energy()
150     {
151         let E_pot = 0;
152         for (i = 0; i < K; i++)
153         {
154             E_pot += (r[i].m * g * y_max - r[i].pot_energy());
155         }
156         return E_pot;
157     }
158 
159 
160     function sum_full_energy()
161     {
162         return sum_pot_energy() + sum_kin_energy() + sum_springs_energy();
163     }
164 
165 
166                             //модуль рисования
167 
168 
169     function draw()
170     {
171         t += dt;
172         ctx.beginPath();
173         ctx.arc(10 +r [0].x * scale_x, 100, 10, 0, 2 * Math.PI);
174         ctx.arc(10 + r[K-1].x * scale_x, 100, 10, 0, 2 * Math.PI);
175         ctx.fill();
176 
177         let e_kin_prev  = sum_kin_energy(),
178             e_pot_prev  = sum_pot_energy(),
179             e_spr_prev  = sum_springs_energy(),
180             e_full_prev = sum_full_energy(),
181             energy_scale = -180 / max_pot_energy;
182 
183         for (i = 1; i < K - 1; i++)
184         {
185             ctx.beginPath();
186             ctx.fillStyle = 'white';
187             ctx.arc(10 + r[i].x * scale_x, 100 - r[i].y * 10, 11, 0, 2 * Math.PI);
188             ctx.fill();
189 
190             ctx.beginPath();
191             physics(i);
192             ctx.fillStyle = 'black';
193             ctx.arc(10 + r[i].x * scale_x, 100 - r[i].y * 10, 10, 0, 2 * Math.PI);
194             ctx.fill();
195         }
196 
197 
198         ctt.lineWidth = '2';
199 
200         ctt.beginPath();
201         ctt.moveTo((t - dt) * 10,200 + e_pot_prev*energy_scale);
202         ctt.strokeStyle = 'red';
203         ctt.lineTo(t * 10,200 + sum_pot_energy()*energy_scale);
204         ctt.stroke();
205 
206         ctt.beginPath();
207         ctt.moveTo((t - dt) * 10,200 + e_spr_prev * energy_scale);
208         ctt.strokeStyle = 'black';
209         ctt.lineTo(t * 10,200 + sum_springs_energy() * energy_scale);
210         ctt.stroke();
211 
212         ctt.beginPath();
213         ctt.moveTo((t - dt) * 10,200 + e_kin_prev * energy_scale);
214         ctt.strokeStyle = 'green';
215         ctt.lineTo(t * 10,200 + sum_kin_energy() * energy_scale);
216         ctt.stroke();
217 
218         ctt.beginPath();
219         ctt.moveTo((t - dt) * 10,200 + e_full_prev * energy_scale);
220         ctt.strokeStyle = 'blue';
221         ctt.lineTo(t * 10,200 + sum_full_energy() * energy_scale);
222         ctt.stroke();
223 
224         if (t > 40)
225         {
226             ctt.beginPath();
227             ctt.fillStyle = 'white';
228             ctt.rect(0,0,400,400);
229             ctt.fill();
230             t = 0;
231             drawgraf();
232         }
233     }
234 
235 
236     function drawgraf()
237     {
238         let ctthig = 400,
239             cttlen = 400;
240 
241         ctt.beginPath();
242         ctt.strokeStyle = 'black';
243         ctt.lineWidth="3";
244         ctt.moveTo(0,ctthig / 2);
245         ctt.lineTo(cttlen,ctthig / 2);
246         ctt.lineTo(cttlen - 10,ctthig / 2 - 10);
247         ctt.moveTo(cttlen,ctthig / 2);
248         ctt.lineTo(cttlen - 10,ctthig / 2 + 10);
249         ctt.moveTo(0, ctthig);
250         ctt.lineTo(0,0);
251         ctt.lineTo(-10,10);
252         ctt.moveTo(0,0);
253         ctt.lineTo(10,10);
254         ctt.stroke();
255 
256         ctt.beginPath();
257         ctt.lineWidth = '1';
258         ctt.rect(299, 0, 101, 60);
259         ctt.stroke();
260 
261         ctt.beginPath();
262         ctt.lineWidth = '4';
263         ctt.strokeStyle = 'red';
264         ctt.moveTo(390, 7);
265         ctt.lineTo(395,7);
266         ctt.stroke();
267 
268         ctt.beginPath();
269         ctt.lineWidth = '4';
270         ctt.strokeStyle = 'black';
271         ctt.moveTo(390, 22);
272         ctt.lineTo(395,22);
273         ctt.stroke();
274 
275         ctt.beginPath();
276         ctt.lineWidth = '4';
277         ctt.strokeStyle = 'green';
278         ctt.moveTo(390, 37);
279         ctt.lineTo(395,37);
280         ctt.stroke();
281 
282         ctt.beginPath();
283         ctt.lineWidth = '4';
284         ctt.strokeStyle = 'blue';
285         ctt.moveTo(390, 52);
286         ctt.lineTo(395,52);
287         ctt.stroke();
288 
289         ctt.font = "normal small-caps normal 13px Times New Roman";
290         ctt.fillText('Full', 300, 55);
291 
292         ctt.font = "normal small-caps normal 13px Times New Roman";
293         ctt.fillText('Kinetic', 300, 40);
294 
295         ctt.font = "normal small-caps normal 13px Times New Roman";
296         ctt.fillText('Interaction', 300, 25);
297 
298         ctt.font = "normal small-caps normal 13px Times New Roman";
299         ctt.fillText('Potencial', 300, 10);
300     }
301 
302 
303     //модуль вывода
304 
305 
306     button1.onclick = function()
307     {
308         ctt.moveTo(0,200);
309         if (document.getElementById('p4').checked === true)
310         {
311             rho = 7900;
312             E = 200000;
313         }
314         if (document.getElementById('p5').checked === true)
315         {
316             rho = 600;
317             E = 100000;
318         }
319         teor_phys();
320         fast_modeling();
321         timerId = setInterval(draw,  60/1000);
322         drawgraf();
323     };
324 
325 
326     button2.onclick = function()
327     {
328         clearInterval(timerId);
329     };
330 
331 
332     button3.onclick = function()
333     {
334         clearInterval(timerId);
335         r = [];
336         t = 0;
337         ctx.beginPath();
338         ctx.fillStyle = 'white';
339         ctx.rect(0,0,400,400);
340         ctx.fill();
341         ctt.beginPath();
342         ctt.fillStyle = 'white';
343         ctt.rect(0,0,400,400);
344         ctt.fill();
345     }
346 }