Lab12 due Monday December 7th 2015.
Monte-Carlo simulation of a one dimensional atomic bomb...
1) Complete the function double rndm() so it returns a pseudorandom number
uniformly distributed between 0 and 1.00. The function should make use of
the function random() which returns a pseudorandom integer uniformly
distributed between 0 and RAND_MAX. In the main function, draw a large
number of values returned by rndm() and calculate their mean and standard
deviation to check they match your expectation.
2) Complete the function double expev() so it returns a pseudorandom
number u>0 with the probability density exp(-u). The function expdev()
should make use of the function rndm() and it should be safe of numerical
error for all the possible values generated by rndm(). In the main
function, draw a large number of values returned by expdev() and calculate
their mean and standard deviation to check they match your expectation.
3) In the main function, a linked list is initialized. Create a node in this
linked list. Initialize the data of this new node so m=multiplicity and
x is a random number uniformly distributed between 0 and and boxwidth.
The multiplicity is the number of particles (neutrons) that will be
generated by the decay represented by the node. Each particle will have
some chance to escape and some chance to induce another decay.
4) - Create a while loop which will keep running as long as there are nodes in
the linked list.
- In this while loop, for a number of times equal to the multiplicity m of
the head node, produce a coordinate newx which has as many chances to be
on the left or the right of the x value of the head node and at a distance
from x that is randomly distributed with an exponential distribution (We
are using the mean free path of the particles as the unit of length).
- This newx corresponds to the point when a particle emitted in x would
interact in the sample. If the value of newx is outside the interval
[0,boxwidth] the particle escapes the sample and, otherwise, it induces a
nuclear reaction in newx for which you should create a new node with its m
value initialized to the m value of the head node and the x value
initialized to newx.
- The above process gives some chance for the number of nodes to grow.
If the number of nodes in the list exceeds 10000, it very likely means
the system is diverging and a nuclear explosion is under way and you
should run for cover: your program should print "Boom!" and then quit.
Once you are done generating new particles, delete the head node as it is
now useless.
5) The previous exercise (4) had you implement the simulation of a chain
reaction (a cascade) initiated by a single decay event. Modify your code
so that, instead, there are NBSPONT cascades being simulated. For each
simulated cascade, count the number of particles escaping the sample and
calculate the average and standard deviation of this number of particle
escaping the sample per cascade.
6) Run your code in a for loop so as to run your calculation for sample
sizes (boxwidth) from 0 to 2.0 in steps of 0.05 (remember we use the
particle mean free path as our distance unit). For each sample size,
print the size, the mean number of escaping particles and the standard
deviation of the number of escaping particles. Run your code for
multiplicities of 2,3 and 4 and store the results into three files by
redirecting the standard output of your code. Write a gnuplot script to
display the standard deviation and the mean of the number of particles
escaping the sample per spontaneous decay as a function of the sample size.
To submit your work, use the command:
submit p6720 Lab12 boom.cpp