辅导data编程、c++,Java程序设计讲解、辅导Python语言程序 解析Haskell程序|讲解SPSS
- 首页 >> Python编程 N-Body Simulation
You are tasked with constructing an application for an n-body simulation. This is a common
astrophysics simulation, modelling orbiting bodies within our solar system and galaxy. Your
application will simulate the orbiting patterns of celestial bodies within your system. This may be
set data provided to you via command line arguments or randomly generated particles.
On top of modelling this application, you will need to write a report and produce a graphical
application which will visualise simulation using the SDL library and render the data. You will be
provided sample test data involving four bodies.
You should aim to not have any locks in your codebase and your application should clearly benefit
from multiple threads processing it.
Modelling The Data
Each body is given the following fields. Each x, y, z field relates to a point in space. Each body has
a velocity, with each part broken into different components. You will use the current velocity
which will update the coordinates every iteration. Each body will have a mass associated which
will change the velocity of other bodies.
You can use the following constants within your simulation as part of your data.
With the data you should be able to represent each element within the simulation. You are free to
modify the body struct as part of optimisations and fixes to your application. Prioritise a correct
result over execution time.
struct body {
double x;
double y;
double z;
double velocity_x;
double velocity_y;
double velocity_z;
double mass;
};
#define PI (3.141592653589793)
#define SOLARMASS (4 * PI * PI) #Use for deriving your own test cases
#define NDAYS (365.25) #Use for deriving your own test cases
#define GCONST (6.67e-11) #Gravitational Constant
Simulation
The main function you will need to implement will be responsible for controlling the simulation
with a change of time (dt) as an argument. You will need to implement the following function
within your application. This function will advance the simulation with time difference (dt).
You will need to document your step function in your repository's README.md file. You will need
to calculate the distance and magnitude between different bodies within the simulation. The
difference between points is represented through the symbols dx, dy, dz. You can calculate the
distance between two bodies using the following formula.
dt is the difference in time and is input to the step function. You will need to calculate the
magnitude for the next operation to update the velocity of body. Use the gravitational constant
(6.67e-11) in your calculation and simulation.
You will need to construct a unit vector between i and j, which you use for the direction.
You will need to calculate acceleration vector using your newly acquired unit vector, magnitude
and mass. (Do note, you can apply a to either i or j, it depends on what )
Afterwards you will need to apply changes to the current body's velocity from all other bodies
within the system. Based on the current time interval (t), to calculate the velocity based on the
next time interval.
Do note, while in this context, you may want to apply changes to the j's velocity. Afterwards, you
will need to update the points of all bodies within the system.
You will need to implement the following function and extract the energy data from the
simulation. The total amount of energy should result in roughly the same value (conserve total
energy, however it may fluctuate within the simulate, note the fluctuation in your final report) at
the simulation and you can use this function to verify the starting energy value with the final
energy value. You may encounter some strange issues with your setup, generation or depending
how long it computes, your energy function may return an invalid value. In your report, attempt
to explain any cases that exist that impact the simulation.
void step(...)
double energy(...)
Energy within the system calculated with the following formula. Use as part of your test suite to
ensure that your application is correct to the best of your abilities. (Alternatively, you can extract
the kinetic energy for all elements and extract potential entity for entities to get the result you
want)
Your command line application will be invoked with the following command line arguments. The
command line program can support -b or -f flags, -b will correspond to the number of
randomly generated bodies while -f flag corresponds to a file that contains particle data. The
second argument requires the change in time value to be used for each step of the simulation.
Example of executing the program with 50 randomly placed celestial bodies and will iterate 3000
times.
Each iteration will correspond to a change of time of dt within the simulation as specified by the
command line argument. Below is an example of executing the program with a file containing
data and will iterate 3000 times.
Your program will need to support the following file format when the -f flag is provided. The
application will need to handle a filename and load the data in the following format.
GUI
Once you have successfully constructed the simulation and have set up a command line
application. You are required to construct a GUI that will visualise the simulation. You have been
given an SDL template that will allow you to get your code working. You can access the SDL
documentation from the following website https://wiki.libsdl.org/.
You will need to support the following command line arguments that will be in the following form.
Below is an example of executing this application with 400 bodies randomly scattered.
Like the command line application, your GUI program will be invoked like so.
./nbody (-b | -f )
./nbody 3000 0.01 -b 50
./nbody 3000 0.01 -f data.csv
,,,,,,
./nbody-gui (-b
| -f) (scale)
./nbody-gui 800 600 50000 0.1 -b 400 0.00025
./nbody-gui 800 600 50000 10 -f data.csv 0.00025
Each frame corresponds to a time change of dt within the simulation. Each body is represented
by a simple red circle which the radius will be clamped to 10 pixels or below. Scale the . Below is
an example screenshot of the GUI demo. However, you can describe a method for scaling planets
within your application. (Picture below violates 10 pixel radius)
You will need to ensure you compile and link to -lSDL2 . All platforms have access to this library
that you will need to install use through out your assessment. Template will be accessible from
the resources section of Ed.
Submission (11:59PM 3/11/2020)
You are required to submit source code and a report, documenting your development process,
identifying issues with your simulation and how you addressed them. Please state any errors,
deviations or issues you encountered during this project in your README.md file.
Your build script should provide the following scripts.
Command line application
GUI Application
Test Suite Execution
Benchmark
Your application will need to be compiled with the following command.
Your code submission must be submitted to a github.sydney.edu.au repository with the name
soft3410a1 . Please invite your tutor to your repository so they can review and assess it.
gcc -O0
You are tasked with constructing an application for an n-body simulation. This is a common
astrophysics simulation, modelling orbiting bodies within our solar system and galaxy. Your
application will simulate the orbiting patterns of celestial bodies within your system. This may be
set data provided to you via command line arguments or randomly generated particles.
On top of modelling this application, you will need to write a report and produce a graphical
application which will visualise simulation using the SDL library and render the data. You will be
provided sample test data involving four bodies.
You should aim to not have any locks in your codebase and your application should clearly benefit
from multiple threads processing it.
Modelling The Data
Each body is given the following fields. Each x, y, z field relates to a point in space. Each body has
a velocity, with each part broken into different components. You will use the current velocity
which will update the coordinates every iteration. Each body will have a mass associated which
will change the velocity of other bodies.
You can use the following constants within your simulation as part of your data.
With the data you should be able to represent each element within the simulation. You are free to
modify the body struct as part of optimisations and fixes to your application. Prioritise a correct
result over execution time.
struct body {
double x;
double y;
double z;
double velocity_x;
double velocity_y;
double velocity_z;
double mass;
};
#define PI (3.141592653589793)
#define SOLARMASS (4 * PI * PI) #Use for deriving your own test cases
#define NDAYS (365.25) #Use for deriving your own test cases
#define GCONST (6.67e-11) #Gravitational Constant
Simulation
The main function you will need to implement will be responsible for controlling the simulation
with a change of time (dt) as an argument. You will need to implement the following function
within your application. This function will advance the simulation with time difference (dt).
You will need to document your step function in your repository's README.md file. You will need
to calculate the distance and magnitude between different bodies within the simulation. The
difference between points is represented through the symbols dx, dy, dz. You can calculate the
distance between two bodies using the following formula.
dt is the difference in time and is input to the step function. You will need to calculate the
magnitude for the next operation to update the velocity of body. Use the gravitational constant
(6.67e-11) in your calculation and simulation.
You will need to construct a unit vector between i and j, which you use for the direction.
You will need to calculate acceleration vector using your newly acquired unit vector, magnitude
and mass. (Do note, you can apply a to either i or j, it depends on what )
Afterwards you will need to apply changes to the current body's velocity from all other bodies
within the system. Based on the current time interval (t), to calculate the velocity based on the
next time interval.
Do note, while in this context, you may want to apply changes to the j's velocity. Afterwards, you
will need to update the points of all bodies within the system.
You will need to implement the following function and extract the energy data from the
simulation. The total amount of energy should result in roughly the same value (conserve total
energy, however it may fluctuate within the simulate, note the fluctuation in your final report) at
the simulation and you can use this function to verify the starting energy value with the final
energy value. You may encounter some strange issues with your setup, generation or depending
how long it computes, your energy function may return an invalid value. In your report, attempt
to explain any cases that exist that impact the simulation.
void step(...)
double energy(...)
Energy within the system calculated with the following formula. Use as part of your test suite to
ensure that your application is correct to the best of your abilities. (Alternatively, you can extract
the kinetic energy for all elements and extract potential entity for entities to get the result you
want)
Your command line application will be invoked with the following command line arguments. The
command line program can support -b or -f flags, -b will correspond to the number of
randomly generated bodies while -f flag corresponds to a file that contains particle data. The
second argument requires the change in time value to be used for each step of the simulation.
Example of executing the program with 50 randomly placed celestial bodies and will iterate 3000
times.
Each iteration will correspond to a change of time of dt within the simulation as specified by the
command line argument. Below is an example of executing the program with a file containing
data and will iterate 3000 times.
Your program will need to support the following file format when the -f flag is provided. The
application will need to handle a filename and load the data in the following format.
GUI
Once you have successfully constructed the simulation and have set up a command line
application. You are required to construct a GUI that will visualise the simulation. You have been
given an SDL template that will allow you to get your code working. You can access the SDL
documentation from the following website https://wiki.libsdl.org/.
You will need to support the following command line arguments that will be in the following form.
Below is an example of executing this application with 400 bodies randomly scattered.
Like the command line application, your GUI program will be invoked like so.
./nbody
./nbody 3000 0.01 -b 50
./nbody 3000 0.01 -f data.csv
./nbody-gui
| -f
./nbody-gui 800 600 50000 0.1 -b 400 0.00025
./nbody-gui 800 600 50000 10 -f data.csv 0.00025
Each frame corresponds to a time change of dt within the simulation. Each body is represented
by a simple red circle which the radius will be clamped to 10 pixels or below. Scale the . Below is
an example screenshot of the GUI demo. However, you can describe a method for scaling planets
within your application. (Picture below violates 10 pixel radius)
You will need to ensure you compile and link to -lSDL2 . All platforms have access to this library
that you will need to install use through out your assessment. Template will be accessible from
the resources section of Ed.
Submission (11:59PM 3/11/2020)
You are required to submit source code and a report, documenting your development process,
identifying issues with your simulation and how you addressed them. Please state any errors,
deviations or issues you encountered during this project in your README.md file.
Your build script should provide the following scripts.
Command line application
GUI Application
Test Suite Execution
Benchmark
Your application will need to be compiled with the following command.
Your code submission must be submitted to a github.sydney.edu.au repository with the name
soft3410a1 . Please invite your tutor to your repository so they can review and assess it.
gcc -O0