- Содержание
- Часть работы
- Список литературы
СОДЕРЖАНИЕ
ВВЕДЕНИЕ
1 НАУЧНО ИССЛЕДОВАТЕЛЬСКИЙ АНАЛИЗ
1.1 Упругое столкновение
1.1 Анализ задания и выбор технологии, языка и среды разработки
2 ПРОЕКТИРОВАНИЕ СТРУКТУРЫ И КОМПОНЕНТОВ ПРОГРАММНОГО ПРОДУКТА
2.1 Проектирование алгоритма работы приложения
2.2 Разработка программной структуры приложения
2.3 Реализация приложения
3 ТЕСТИРОВАНИЕ ПРИЛОЖЕНИЯ
ЗАКЛЮЧЕНИЕ
СПИСОК ИСПОЛЬЗОВАННЫХ ИСТОЧНИКОВ
ПРИЛОЖЕНИЕ А Код программы
Фрагмент для ознакомления
radius * 2 * size1pixels), (int)(this.radius * 2 * size1pixels))));} }}Simulation.csusing System;using System.Collections.Generic;using System.Linq;using System.Numerics;using System.Security.Policy;using System.Text;using System.Threading.Tasks;namespace GasMolecularDynamicsSimulation{ public class Simulation { private List particles = null; /* A class for a simple hard-circle molecular dynamics simulation. The simulation is carried out on a square domain: 0 <= x < 1, 0 <= y < 1. Initialize the simulation with n Particles with radii radius. */ public Simulation(float[] radius, KeyValuePair[] styles = null) { init_particles(radius, styles); } private void init_particles(float[] radius, KeyValuePair[] styles = null) { //Initialize the n Particles of the simulation. //Positions and velocities are chosen randomly; radius can be a single //value or a sequence with n values. this.particles = new List(); Random random = new Random(); for (int i = 0; i < radius.Length; i++) { float rad = radius[i]; //Try to find a random initial position for this particle. while (true) { // Choose x, y so that the Particle is entirely inside the // domain of the simulation. //x, y = rad + (1 - 2*rad) * np.random.random(2) float x = (float)(rad + (1 - 2 * rad) * random.NextDouble()); float y = (float)(rad + (1 - 2 * rad) * random.NextDouble()); // Choose a random velocity (within some reasonable range of values) for the Particle. double vr = 0.1 * random.NextDouble() + 0.05; double vphi = 2 * Math.PI * random.NextDouble(); float vx = (float)(vr * Math.Cos(vphi)); float vy = (float)(vr * Math.Sin(vphi)); var particle = new Particle(x, y, vx, vy, rad, styles != null ? styles[i].Key : null, styles != null ? styles[i].Value : false); //Check that the Particle doesn't overlap one that's already been placed. bool floverlap = false; foreach (var p2 in this.particles) { if (p2.overlaps(particle)) { floverlap = true; break; } } if (!floverlap) { this.particles.Add(particle); break; } } } } public void handle_collisions() { //Detect and handle any collisions between the Particles. //When two Particles collide, they do so elastically: their velocities //change such that both energy and momentum are conserved. for (int i = 0; i < particles.Count; i++) { for (int j = i + 1; j < particles.Count; j++) { if (particles[i].overlaps(particles[j])) { Particle p1 = particles[i]; Particle p2 = particles[j]; //Particles p1 and p2 have collided elastically: update their velocities. float m1 = (float)Math.Pow(p1.Radius, 2); float m2 = (float)Math.Pow(p2.Radius, 2); float M = m1 + m2; System.Numerics.Vector2 r1 = p1.R; System.Numerics.Vector2 r2 = p2.R; float d = (float)(Math.Pow(r1.X - r2.X, 2) + Math.Pow(r1.Y - r2.Y, 2)); System.Numerics.Vector2 v1 = p1.V; System.Numerics.Vector2 v2 = p2.V; Vector2 u1 = v1 - 2 * m2 / M * System.Numerics.Vector2.Dot(v1 - v2, r1 - r2) / d * (r1 - r2); Vector2 u2 = v2 - 2 * m1 / M * System.Numerics.Vector2.Dot(v2 - v1, r2 - r1) / d * (r2 - r1); p1.V = u1; p2.V = u2; } } } } public void advance_animation(float dt) { foreach (Particle p in this.particles) { p.advance(dt); } handle_collisions(); } public void animate() { advance_animation(0.1f); } public void draw(Graphics g, int size1pixels) { foreach (Particle p in this.particles) { p.draw(g, size1pixels); } } }}Form1.csusing System.Security.Policy;namespace GasMolecularDynamicsSimulation{ public partial class Form1 : Form { Simulation sim = null; Bitmap bitmap; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Random random = new Random(); int nparticles = 5; float[] radii = new float[nparticles]; for (int i = 0; i < nparticles; i++) { radii[i] = (float)(random.NextDouble() * 0.03f + 0.02f); } sim = new Simulation(radii); bitmap = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height); Graphics graphics = Graphics.FromImage(bitmap); int sqsize = Math.Min(this.pictureBox1.Width, this.pictureBox1.Height); graphics.FillRectangle(Brushes.White, 0, 0, sqsize, sqsize); graphics.DrawRectangle(Pens.Black, 0, 0, sqsize - 1, sqsize - 1); sim.draw(graphics, sqsize); pictureBox1.Image = bitmap; this.timer1.Start(); } bool animated = false; private void timer1_Tick(object sender, EventArgs e) { if (!animated) { animated = true; this.sim.animate(); Graphics graphics = Graphics.FromImage(bitmap); int sqsize = Math.Min(this.pictureBox1.Width, this.pictureBox1.Height); graphics.Clear(Color.White); graphics.DrawRectangle(Pens.Black, 0, 0, sqsize - 1, sqsize - 1); sim.draw(graphics, sqsize); graphics.Dispose(); Graphics g = this.pictureBox1.CreateGraphics(); g.DrawImage(bitmap, 0, 0); animated = false;} } }}
СПИСОК ИСПОЛЬЗОВАННЫХ ИСТОЧНИКОВ
1. Трофимова, Т. И. Курс физики / Т. И. Трофимова. – М. : Высшая школа, 1998.
2. Степанов, М. А. Лабораторная работа № 124. Исследование динамики упругого соударения шаров / М. А. Степанов, Е. Е. Трофименко, С. И. Шеденков. – Минск : БНТУ, 2008.
3. Чертов, А. Г. Задачник по физике : учебное пособие для втузов / А. Г. Чертов, А. А. Воробьев. – 8-е изд., перераб. и доп. – М. : Физматлит, 2007. – 640 с.
4. Задачи на столкновения и законы сохранения импульса и энергии URL: https://zftsh.online/articles/4801
5. https://en.wikipedia.org/wiki/Elastic_collision
6. Рихтер, Джеффри CLR via C#. Программирование на платформе Microsoft .NET Framework 4.0 на языке C# / Джеффри Рихтер. - М.: Питер, 2013. - 928 c
7. Хейлсберг, А. Язык программирования C#. Классика Computers Science / А. Хейлсберг, М. Торгерсен, С. Вилтамут. — СПб.: Питер, 2016. — 784 c.
8. Кауфман, В.Ш. Языки программирования. Концепции и принципы / В.Ш. Кауфман. — М.: ДМК, 2017. — 464 c.