Derek Ostrom

From Materials Simulation Group
Jump to: navigation, search
Molecular Dynamic simulation showing molecules heating from a solid to a gas. Each time the temperature is raised the minions become more purple. The minions are governed by the Lennard-Jones Potential.

Bio

My name is Derek Ostrom. I have been working in Dr. Hart's Material Simulation Group since May of 2013.

Projects

Realistic Bicycle

This was one of the earliest simulations I made. It shows the speed of a bicyclist with air drag and the force of the bicyclist in the calculating.

  1. /*Program for simulating bike velocity with air resistance
  2.   Derek Ostrom
  3. */
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7. #include <vector>
  8. #include <cmath>
  9. #include <string>
  10. #include <sstream>
  11. using namespace std;
  12.  
  13. int text_num = 0;
  14.  
  15. //asks for the variables to use
  16. void initialize(vector<double> &bikeSpeed, vector<double> &time, double &power, double &dt, double &mass, double &area)
  17. {
  18. 	power = 400;
  19. 	bikeSpeed[0]=4.0;
  20. 	mass = 70;
  21. 	area = 0.33;
  22. 	cout << "Time step (in seconds) -> ";
  23. 	cin >> dt;
  24. 	time[0]=0.0;
  25. }
  26. //calculate the results and store them in the two vectors
  27. void calculateFinal(vector<double> &bikeSpeed, vector<double> &time, double power, double &dt, double mass, double area)
  28. {
  29. 	for(int i = 0; i < bikeSpeed.size()-1; i++)
  30. 	{
  31. 		bikeSpeed[i+1] = bikeSpeed[i] + power/(mass*bikeSpeed[i])*dt - 1.204*area*pow(bikeSpeed[i],2.0)/(2*mass)*dt;
  32. 		time[i+1] = time[i] + dt;
  33. 	}
  34. }
  35. //calculates the results without air resistance
  36. void calculateIdeal(vector<double> &bikeSpeed, vector<double> &time, double power, double &dt, double mass)
  37. {
  38. 	for(int i = 0; i < bikeSpeed.size()-1; i++)
  39. 	{
  40. 		time[i+1] = time[i] + dt;
  41. 		bikeSpeed[i+1] = bikeSpeed[i] + (power/(mass*bikeSpeed[i]))*dt;
  42. 	}
  43. }
  44. //calculate error
  45. void calculateError(vector<double>bikeSpeed, vector<double>&Error, double x)
  46. {
  47. 	for(int i=0; i<bikeSpeed.size(); i++)
  48. 	{
  49. 		Error[i] = fabs(x*2-bikeSpeed[i])/(x*2);
  50. 	}
  51. }
  52. //store the speed information 
  53. void store_speed(vector<double> &bikeSpeed, vector<double> &time)
  54. {
  55. 	ofstream out_file;
  56. 	out_file.open("BikeSpeed.txt");	
  57. 	for(int i = 0; i < bikeSpeed.size(); i++)
  58. 	{
  59. 		out_file << bikeSpeed[i]<< endl;
  60. 	}
  61. 	out_file.close();
  62. }
  63. //stores the time information
  64. void store_time(vector<double> &bikeSpeed, vector<double> &time)
  65. {
  66. 	ofstream out_file;
  67. 	out_file.open("time.txt");	
  68. 	for(int i = 0; i < bikeSpeed.size(); i++)
  69. 	{
  70. 		out_file << time[i]<< endl;
  71. 	}
  72. 	out_file.close();
  73. }
  74. //stores the speed without air resistance
  75. void store_ideal_speed(vector<double> &bikeSpeed, vector<double> &time)
  76. {
  77. 	ofstream out_file;
  78. 	out_file.open("BikeSpeedIdeal.txt");	
  79. 	for(int i = 0; i < bikeSpeed.size(); i++)
  80. 	{
  81. 		out_file << bikeSpeed[i]<< endl;
  82. 	}
  83. 	out_file.close();
  84. }
  85. //stores the error
  86. void store_Error(vector<double> &Error)
  87. {
  88. 	ofstream out_file;
  89. 	out_file.open("eValue.txt");	
  90. 	for(int i = 0; i < Error.size(); i++)
  91. 	{
  92. 		out_file << Error[i]<< endl;
  93. 	}
  94. 	out_file.close();
  95. }
  96.  
  97. int main()
  98. {
  99. 	vector<double> bikeSpeed(150);
  100. 	vector<double> time(150);
  101. 	vector<double> Error(150);
  102. 	double power=0;
  103. 	double dt=0;
  104. 	double mass=0;
  105. 	double area=0;
  106.  
  107. 	initialize(bikeSpeed, time, power,dt,mass,area);
  108. 	calculateFinal(bikeSpeed, time, power, dt, mass, area);
  109. 	store_speed(bikeSpeed, time);
  110. 	store_time(bikeSpeed, time);
  111. 	calculateIdeal(bikeSpeed, time, power, dt, mass);
  112. 	store_ideal_speed(bikeSpeed, time);
  113. 	//calculateError(bikeSpeed, Error, dt);
  114. 	//store_Error(Error);
  115.  
  116. }

Cannon

This was another simple project that shows how angle, air resistance, and air density go into shooting a shells with the same velocity out of a cannon.

  1. /*Program for simulating velocity of a cannon shell
  2.   Derek Ostrom
  3. */
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7. #include <vector>
  8. #include <cmath>
  9. #include <string>
  10. #include <sstream>
  11. using namespace std;
  12.  
  13. int text_num = 0;
  14.  
  15. //asks for the variables to use
  16. void initialize(vector<double> &shellPositionX, vector<double> &shellPositionY, vector<double> &shellSpeedX, vector<double> &shellSpeedY, vector<double> &time, double angle, vector<double> &airDensity, double &dt, double &mass, double &B2, double &density)
  17. {
  18. 	shellPositionX[0]=0.0;
  19. 	shellPositionY[0]=0.0;
  20. 	shellSpeedX[0]=700.0 * cos(angle);
  21. 	shellSpeedY[0]=700.0 * sin(angle);
  22. 	mass = 25;
  23. 	dt = 1;
  24. 	time[0]=0.0;
  25. 	B2 = 4*pow(10.0,-5.0);
  26. 	density = 1.204;
  27. 	airDensity[0]=density;
  28. }
  29. //calculate the results and store them in the two vectors
  30. void calculateVelocity(vector<double> &shellPositionX, vector<double> &shellPositionY, vector<double> &shellSpeedX, vector<double> &shellSpeedY, vector<double> &time, double angle, vector<double> &airDensity, double &dt, double mass, double &B2, double &density)
  31. {
  32. 	double a = 6.5 * pow(10.0,-3.0);
  33. 	double Temp0 = 301.0;
  34. 	double alpha = 2.5;
  35. 	double dragX;
  36. 	double dragY;
  37.  
  38. 	for(int i = 0; i < 149; i++)
  39. 	{
  40. 		//position
  41. 		shellPositionX[i+1] = shellPositionX[i] + shellSpeedX[i] * dt;
  42. 		shellPositionY[i+1] = shellPositionY[i] + shellSpeedY[i] * dt;
  43. 		//density Dependance
  44. 		airDensity[i+1] = density * pow((1 - (a * shellPositionY[i]) / Temp0), alpha);
  45. 		//drag
  46. 		dragX = (-B2 * airDensity[i] / density) * sqrt(pow(shellSpeedX[i],2)+pow(shellSpeedY[i],2)) * shellSpeedX[i];
  47. 		dragY = (-B2 * airDensity[i] / density) * sqrt(pow(shellSpeedX[i],2)+pow(shellSpeedY[i],2)) * shellSpeedY[i];
  48. 		//velocity
  49. 		shellSpeedX[i+1] = shellSpeedX[i] + (dragX) * dt;
  50. 		shellSpeedY[i+1] = shellSpeedY[i] + (-9.8 + dragY)* dt;
  51. 		//interpolate if y gets below 0
  52. 		if(shellPositionY[i+1] <= 0)
  53. 		{
  54. 			double r = -shellPositionY[i] / shellPositionY[i+1];
  55. 			shellPositionX[i+1] = (shellPositionX[i] + r * shellPositionX[i+1]) / (r + 1);
  56. 			shellPositionY[i+1] = 0;
  57. 			return;
  58. 		}
  59. 	}
  60. }
  61. //store the speed information 
  62. void store_xPosition(vector<double> shellPositionX)
  63. {
  64. 	ofstream out_file;
  65. 	out_file.open("X_position.txt");	
  66. 	for(int i = 0; i < 149; i++)
  67. 	{
  68. 		out_file << shellPositionX[i]<< endl;
  69. 	}
  70. 	out_file.close();
  71. }
  72. void store_yPosition(vector<double> shellPositionY)
  73. {
  74. 	ofstream out_file;
  75. 	out_file.open("Y_position.txt");	
  76. 	for(int i = 0; i < 149; i++)
  77. 	{
  78. 		out_file << shellPositionY[i]<< endl;
  79. 	}
  80. 	out_file.close();
  81. }
  82.  
  83. int main(int argc, const char * argv[])
  84. {
  85. 	vector<double> shellPositionX(150);
  86. 	vector<double> shellPositionY(150);
  87. 	vector<double> shellSpeedX(150);
  88. 	vector<double> shellSpeedY(150);
  89. 	vector<double> time(150);
  90. 	vector<double> airDensity(150);
  91. 	vector<double> Error(150);
  92. 	double angle=atof(argv[1]);
  93. 	double power=0;
  94. 	double dt=0;
  95. 	double mass=0;
  96. 	double B2=0;
  97. 	double density=0;
  98.  
  99. 	initialize(shellPositionX, shellPositionY, shellSpeedX, shellSpeedY, time, angle, airDensity, dt, mass, B2, density);
  100. 	calculateVelocity(shellPositionX, shellPositionY, shellSpeedX, shellSpeedY, time, angle, airDensity, dt, mass, B2, density);
  101. 	store_xPosition(shellPositionX);
  102. 	store_yPosition(shellPositionY);
  103. 	return 0;
  104. }

The different paths of cannon shells fired from a cannon at the same speed. The angles are different and so the air resistance and air density each shell experienced was different.