{"action":"created","comment":{"url":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/comments/52256110","id":52256110,"diff_hunk":"@@ -0,0 +1,168 @@\n+/*\n+ @file      Distributions.cpp\n+ @brief     Functions for sampling monte carlo distributions\n+ @details   This file contains functions to be used in a Monte Carlo simulation\n+            to sample the various distributions arising in reactor physics.\n+ @author    Luke Eure\n+ @date      January 8, 2016\n+*/\n+\n+#include \"Distributions.h\"\n+\n+/*\n+  @brief    Returns a uniform random number between 0 and 1\n+  @return   a double in the range (0, 1)\n+*/\n+double urand() {\n+    return (double) rand() / (double) RAND_MAX;\n+}\n+\n+/*\n+  @brief    Function that randomly samples an azimuthal angle                   \n+  @details  An azimuthal angle is uniformally sampled in [0, 2 pi]              \n+  @return   A randomly sampled angle in [0, 2pi] \n+*/\n+double sampleAzimuthalAngle() {\n+    return 2 * M_PI * urand();\n+}\n+\n+/*\n+ @brief     Function that randomly samples a polar angle\n+ @details   The cosine of the polar angle is uniformally sampled in [-1, 1]\n+            and then transformed to the polar angle with an inverse cosine\n+ @return    A randomly sampled polar angle in [0, pi]\n+*/\n+double samplePolarAngle() {\n+    double cos_theta = 2 * urand() - 1.0;\n+    return acos(cos_theta);\n+}\n+\n+/*\n+ @brief     Function that samples the distance of travel based on a total\n+            cross-section.\n+ @details   A distance of travel is sampled in [0, infinity) assuming an\n+            exponential distibution of the form sigma_t * exp(-sigma_t * d).\n+ @param     mat a Material object that contains information about the material\n+ @param     group an int denoting the energy group of the neutron\n+ @return    A randomly sampled distance in [0, infinity)\n+*/\n+double sampleDistance(Material* mat, int group) {\n+    return -log(urand()) / mat->getSigmaT(group);\n+}\n+\n+/*\n+ @brief     Function that samples the interaction type (0 = scattering,\n+            1 = absorption)\n+ @details   Based on cross-sections, the interaction is sampled as scattering\n+            (0) or absorption (1).\n+ @param     mat a Material object that contains information\n+            about the material\n+ @param     group an int denoting the energy group of the neutron \n+ @return    An interaction type (0 = scattering, 1 = absorption)\n+*/\n+int sampleInteraction(Material* mat, int group) {\n+    return (int) (urand() < mat->getSigmaA(group)\n+                / mat->getSigmaT(group));\n+}\n+\n+/*\n+ @brief     Function that samples a random location within a bounding box.\n+ @details   A point is randomly and uniformally sampled in the bounding box \n+            provided in the input.\n+ @param     bounds a Boundaries object containing the limits of the\n+            bounding box\n+ @return    _dist_location a vector that contains the coordinates of a point\n+*/\n+std::vector <double> sampleLocation(Boundaries bounds) {\n+    std::vector <double> _dist_location;\n+    double width;\n+    double coord;\n+    for (int axis=0; axis<3; ++axis) {\n+        width = bounds.getSurfaceCoord(axis, 1)\n+            - bounds.getSurfaceCoord(axis, 0);\n+        coord = bounds.getSurfaceCoord(axis, 0) + width * urand();","path":"Distributions.cpp","position":83,"original_position":83,"commit_id":"36e060aee2d856a7b32f5153b4943682a37f16d3","original_commit_id":"36e060aee2d856a7b32f5153b4943682a37f16d3","user":{"login":"geogunow","id":2420416,"avatar_url":"https://avatars.githubusercontent.com/u/2420416?v=3","gravatar_id":"","url":"https://api.github.com/users/geogunow","html_url":"https://github.com/geogunow","followers_url":"https://api.github.com/users/geogunow/followers","following_url":"https://api.github.com/users/geogunow/following{/other_user}","gists_url":"https://api.github.com/users/geogunow/gists{/gist_id}","starred_url":"https://api.github.com/users/geogunow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geogunow/subscriptions","organizations_url":"https://api.github.com/users/geogunow/orgs","repos_url":"https://api.github.com/users/geogunow/repos","events_url":"https://api.github.com/users/geogunow/events{/privacy}","received_events_url":"https://api.github.com/users/geogunow/received_events","type":"User","site_admin":false},"body":"Stylistically, it would be better to do:\r\n```\r\ndouble width = bounds.getSurfaceCoord(axis, 1)\r\n                        - bounds.getSurfaceCoord(axis, 0);\r\ndouble coord = bounds.getSurfaceCoord(axis, 0) + width * urand();\r\n```","created_at":"2016-02-09T01:24:49Z","updated_at":"2016-02-09T01:24:49Z","html_url":"https://github.com/geogunow/MultiGroupMC/pull/10#discussion_r52256110","pull_request_url":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/comments/52256110"},"html":{"href":"https://github.com/geogunow/MultiGroupMC/pull/10#discussion_r52256110"},"pull_request":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10","id":57245020,"html_url":"https://github.com/geogunow/MultiGroupMC/pull/10","diff_url":"https://github.com/geogunow/MultiGroupMC/pull/10.diff","patch_url":"https://github.com/geogunow/MultiGroupMC/pull/10.patch","issue_url":"https://api.github.com/repos/geogunow/MultiGroupMC/issues/10","number":10,"state":"open","locked":false,"title":"Created Monte Carlo solver in C++","user":{"login":"ljeure","id":14911179,"avatar_url":"https://avatars.githubusercontent.com/u/14911179?v=3","gravatar_id":"","url":"https://api.github.com/users/ljeure","html_url":"https://github.com/ljeure","followers_url":"https://api.github.com/users/ljeure/followers","following_url":"https://api.github.com/users/ljeure/following{/other_user}","gists_url":"https://api.github.com/users/ljeure/gists{/gist_id}","starred_url":"https://api.github.com/users/ljeure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ljeure/subscriptions","organizations_url":"https://api.github.com/users/ljeure/orgs","repos_url":"https://api.github.com/users/ljeure/repos","events_url":"https://api.github.com/users/ljeure/events{/privacy}","received_events_url":"https://api.github.com/users/ljeure/received_events","type":"User","site_admin":false},"body":"I created and tested a Monte Carlo solver in C++. It runs mostly the same way as the python solver did, but much faster. It does not display a heat map of neutron densities. I also fixed an issue we had with sampling absorptions in the python version of the code.\r\n\r\nI tested k-values for a geometry with homogeneous materials and reflective boundaries. I tested both a 1-group and a 2-group problem which had expected k-values of 1.5 and 1.4 respectively. Using one million neutrons, the simulation gave k-values of 1.500 and 1.40 respectively.","created_at":"2016-01-26T17:41:57Z","updated_at":"2016-02-09T01:24:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1ec803f9234d950e2a85ce168cfa904456a831cb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10/commits","review_comments_url":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10/comments","review_comment_url":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/comments{/number}","comments_url":"https://api.github.com/repos/geogunow/MultiGroupMC/issues/10/comments","statuses_url":"https://api.github.com/repos/geogunow/MultiGroupMC/statuses/36e060aee2d856a7b32f5153b4943682a37f16d3","head":{"label":"ljeure:master","ref":"master","sha":"36e060aee2d856a7b32f5153b4943682a37f16d3","user":{"login":"ljeure","id":14911179,"avatar_url":"https://avatars.githubusercontent.com/u/14911179?v=3","gravatar_id":"","url":"https://api.github.com/users/ljeure","html_url":"https://github.com/ljeure","followers_url":"https://api.github.com/users/ljeure/followers","following_url":"https://api.github.com/users/ljeure/following{/other_user}","gists_url":"https://api.github.com/users/ljeure/gists{/gist_id}","starred_url":"https://api.github.com/users/ljeure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ljeure/subscriptions","organizations_url":"https://api.github.com/users/ljeure/orgs","repos_url":"https://api.github.com/users/ljeure/repos","events_url":"https://api.github.com/users/ljeure/events{/privacy}","received_events_url":"https://api.github.com/users/ljeure/received_events","type":"User","site_admin":false},"repo":{"id":43451444,"name":"MultiGroupMC","full_name":"ljeure/MultiGroupMC","owner":{"login":"ljeure","id":14911179,"avatar_url":"https://avatars.githubusercontent.com/u/14911179?v=3","gravatar_id":"","url":"https://api.github.com/users/ljeure","html_url":"https://github.com/ljeure","followers_url":"https://api.github.com/users/ljeure/followers","following_url":"https://api.github.com/users/ljeure/following{/other_user}","gists_url":"https://api.github.com/users/ljeure/gists{/gist_id}","starred_url":"https://api.github.com/users/ljeure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ljeure/subscriptions","organizations_url":"https://api.github.com/users/ljeure/orgs","repos_url":"https://api.github.com/users/ljeure/repos","events_url":"https://api.github.com/users/ljeure/events{/privacy}","received_events_url":"https://api.github.com/users/ljeure/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ljeure/MultiGroupMC","description":"Tutorial to build a multi-group Monte Carlo solver","fork":true,"url":"https://api.github.com/repos/ljeure/MultiGroupMC","forks_url":"https://api.github.com/repos/ljeure/MultiGroupMC/forks","keys_url":"https://api.github.com/repos/ljeure/MultiGroupMC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ljeure/MultiGroupMC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ljeure/MultiGroupMC/teams","hooks_url":"https://api.github.com/repos/ljeure/MultiGroupMC/hooks","issue_events_url":"https://api.github.com/repos/ljeure/MultiGroupMC/issues/events{/number}","events_url":"https://api.github.com/repos/ljeure/MultiGroupMC/events","assignees_url":"https://api.github.com/repos/ljeure/MultiGroupMC/assignees{/user}","branches_url":"https://api.github.com/repos/ljeure/MultiGroupMC/branches{/branch}","tags_url":"https://api.github.com/repos/ljeure/MultiGroupMC/tags","blobs_url":"https://api.github.com/repos/ljeure/MultiGroupMC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ljeure/MultiGroupMC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ljeure/MultiGroupMC/git/refs{/sha}","trees_url":"https://api.github.com/repos/ljeure/MultiGroupMC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ljeure/MultiGroupMC/statuses/{sha}","languages_url":"https://api.github.com/repos/ljeure/MultiGroupMC/languages","stargazers_url":"https://api.github.com/repos/ljeure/MultiGroupMC/stargazers","contributors_url":"https://api.github.com/repos/ljeure/MultiGroupMC/contributors","subscribers_url":"https://api.github.com/repos/ljeure/MultiGroupMC/subscribers","subscription_url":"https://api.github.com/repos/ljeure/MultiGroupMC/subscription","commits_url":"https://api.github.com/repos/ljeure/MultiGroupMC/commits{/sha}","git_commits_url":"https://api.github.com/repos/ljeure/MultiGroupMC/git/commits{/sha}","comments_url":"https://api.github.com/repos/ljeure/MultiGroupMC/comments{/number}","issue_comment_url":"https://api.github.com/repos/ljeure/MultiGroupMC/issues/comments{/number}","contents_url":"https://api.github.com/repos/ljeure/MultiGroupMC/contents/{+path}","compare_url":"https://api.github.com/repos/ljeure/MultiGroupMC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ljeure/MultiGroupMC/merges","archive_url":"https://api.github.com/repos/ljeure/MultiGroupMC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ljeure/MultiGroupMC/downloads","issues_url":"https://api.github.com/repos/ljeure/MultiGroupMC/issues{/number}","pulls_url":"https://api.github.com/repos/ljeure/MultiGroupMC/pulls{/number}","milestones_url":"https://api.github.com/repos/ljeure/MultiGroupMC/milestones{/number}","notifications_url":"https://api.github.com/repos/ljeure/MultiGroupMC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ljeure/MultiGroupMC/labels{/name}","releases_url":"https://api.github.com/repos/ljeure/MultiGroupMC/releases{/id}","deployments_url":"https://api.github.com/repos/ljeure/MultiGroupMC/deployments","created_at":"2015-09-30T18:34:54Z","updated_at":"2016-02-08T16:28:40Z","pushed_at":"2016-02-08T16:28:34Z","git_url":"git://github.com/ljeure/MultiGroupMC.git","ssh_url":"git@github.com:ljeure/MultiGroupMC.git","clone_url":"https://github.com/ljeure/MultiGroupMC.git","svn_url":"https://github.com/ljeure/MultiGroupMC","homepage":null,"size":1671,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"geogunow:master","ref":"master","sha":"15096ccc72d57a71992ffca4f2b613b6d960729f","user":{"login":"geogunow","id":2420416,"avatar_url":"https://avatars.githubusercontent.com/u/2420416?v=3","gravatar_id":"","url":"https://api.github.com/users/geogunow","html_url":"https://github.com/geogunow","followers_url":"https://api.github.com/users/geogunow/followers","following_url":"https://api.github.com/users/geogunow/following{/other_user}","gists_url":"https://api.github.com/users/geogunow/gists{/gist_id}","starred_url":"https://api.github.com/users/geogunow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geogunow/subscriptions","organizations_url":"https://api.github.com/users/geogunow/orgs","repos_url":"https://api.github.com/users/geogunow/repos","events_url":"https://api.github.com/users/geogunow/events{/privacy}","received_events_url":"https://api.github.com/users/geogunow/received_events","type":"User","site_admin":false},"repo":{"id":43439750,"name":"MultiGroupMC","full_name":"geogunow/MultiGroupMC","owner":{"login":"geogunow","id":2420416,"avatar_url":"https://avatars.githubusercontent.com/u/2420416?v=3","gravatar_id":"","url":"https://api.github.com/users/geogunow","html_url":"https://github.com/geogunow","followers_url":"https://api.github.com/users/geogunow/followers","following_url":"https://api.github.com/users/geogunow/following{/other_user}","gists_url":"https://api.github.com/users/geogunow/gists{/gist_id}","starred_url":"https://api.github.com/users/geogunow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geogunow/subscriptions","organizations_url":"https://api.github.com/users/geogunow/orgs","repos_url":"https://api.github.com/users/geogunow/repos","events_url":"https://api.github.com/users/geogunow/events{/privacy}","received_events_url":"https://api.github.com/users/geogunow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/geogunow/MultiGroupMC","description":"Tutorial to build a multi-group Monte Carlo solver","fork":false,"url":"https://api.github.com/repos/geogunow/MultiGroupMC","forks_url":"https://api.github.com/repos/geogunow/MultiGroupMC/forks","keys_url":"https://api.github.com/repos/geogunow/MultiGroupMC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/geogunow/MultiGroupMC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/geogunow/MultiGroupMC/teams","hooks_url":"https://api.github.com/repos/geogunow/MultiGroupMC/hooks","issue_events_url":"https://api.github.com/repos/geogunow/MultiGroupMC/issues/events{/number}","events_url":"https://api.github.com/repos/geogunow/MultiGroupMC/events","assignees_url":"https://api.github.com/repos/geogunow/MultiGroupMC/assignees{/user}","branches_url":"https://api.github.com/repos/geogunow/MultiGroupMC/branches{/branch}","tags_url":"https://api.github.com/repos/geogunow/MultiGroupMC/tags","blobs_url":"https://api.github.com/repos/geogunow/MultiGroupMC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/geogunow/MultiGroupMC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/geogunow/MultiGroupMC/git/refs{/sha}","trees_url":"https://api.github.com/repos/geogunow/MultiGroupMC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/geogunow/MultiGroupMC/statuses/{sha}","languages_url":"https://api.github.com/repos/geogunow/MultiGroupMC/languages","stargazers_url":"https://api.github.com/repos/geogunow/MultiGroupMC/stargazers","contributors_url":"https://api.github.com/repos/geogunow/MultiGroupMC/contributors","subscribers_url":"https://api.github.com/repos/geogunow/MultiGroupMC/subscribers","subscription_url":"https://api.github.com/repos/geogunow/MultiGroupMC/subscription","commits_url":"https://api.github.com/repos/geogunow/MultiGroupMC/commits{/sha}","git_commits_url":"https://api.github.com/repos/geogunow/MultiGroupMC/git/commits{/sha}","comments_url":"https://api.github.com/repos/geogunow/MultiGroupMC/comments{/number}","issue_comment_url":"https://api.github.com/repos/geogunow/MultiGroupMC/issues/comments{/number}","contents_url":"https://api.github.com/repos/geogunow/MultiGroupMC/contents/{+path}","compare_url":"https://api.github.com/repos/geogunow/MultiGroupMC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/geogunow/MultiGroupMC/merges","archive_url":"https://api.github.com/repos/geogunow/MultiGroupMC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/geogunow/MultiGroupMC/downloads","issues_url":"https://api.github.com/repos/geogunow/MultiGroupMC/issues{/number}","pulls_url":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls{/number}","milestones_url":"https://api.github.com/repos/geogunow/MultiGroupMC/milestones{/number}","notifications_url":"https://api.github.com/repos/geogunow/MultiGroupMC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/geogunow/MultiGroupMC/labels{/name}","releases_url":"https://api.github.com/repos/geogunow/MultiGroupMC/releases{/id}","deployments_url":"https://api.github.com/repos/geogunow/MultiGroupMC/deployments","created_at":"2015-09-30T15:04:33Z","updated_at":"2015-09-30T15:05:08Z","pushed_at":"2016-02-08T16:28:34Z","git_url":"git://github.com/geogunow/MultiGroupMC.git","ssh_url":"git@github.com:geogunow/MultiGroupMC.git","clone_url":"https://github.com/geogunow/MultiGroupMC.git","svn_url":"https://github.com/geogunow/MultiGroupMC","homepage":null,"size":1353,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10"},"html":{"href":"https://github.com/geogunow/MultiGroupMC/pull/10"},"issue":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/issues/10"},"comments":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/geogunow/MultiGroupMC/statuses/36e060aee2d856a7b32f5153b4943682a37f16d3"}}}}