<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.2">Jekyll</generator><link href="https://msse-2021-bootcamp.github.io/team2-blog/feed.xml" rel="self" type="application/atom+xml" /><link href="https://msse-2021-bootcamp.github.io/team2-blog/" rel="alternate" type="text/html" /><updated>2022-08-06T17:02:41+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/feed.xml</id><title type="html">MSSE Bootcamp Blog</title><subtitle>A website for the MSSE Bootcamp</subtitle><entry><title type="html">The Light Particles @ The End of The Tunnel</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/20/Day-10-Post.html" rel="alternate" type="text/html" title="The Light Particles @ The End of The Tunnel" /><published>2021-08-20T00:00:00+00:00</published><updated>2021-08-20T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/20/Day-10-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/20/Day-10-Post.html">&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;h1 id=&quot;all-about-the-data&quot;&gt;All About The Data&lt;/h1&gt;
&lt;p&gt;The day ran short, but the energy was high. Before wrapping up the Bootcamp with our presentation. We had an hour to talk in our team 2 breakroom to finalize the details of the presentation on our chosen topic: Code Performance Assessment.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;h1 id=&quot;molecular-simulations&quot;&gt;Molecular Simulations&lt;/h1&gt;
&lt;p&gt;We separated the material into three topics. Usman's presentation described what Monte Carlo methods are, what they are used for and how you can leverage them beyond the lab or classroom. The Bootcamp used the Monte Carlo as a primary focus for us to learn to create simulations in three different versions.
For us to do a systematic assessment of the performance of the three MC versions. We had to make some minor adjustments to the code so we could easily track the code speed by comparing different cases.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;h1 id=&quot;programming-and-data&quot;&gt;Programming and Data&lt;/h1&gt;
&lt;p&gt;Kevin presented the data we gathered during the performance assessment. We decided to do some further investigation and ran a performance comparison, not only against the number of steps, but also: cutoff, temperature, maximum displacement, and a base case. As he showed today during the presentation the one condition that affected performance the most was the number of steps. From the three MC versions, c++ was significantly faster than both versions of Python. We did not run c++ with any optimization and yet it was able to outrun even the NumPy version over half the time.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;h1 id=&quot;software-engineering&quot;&gt;Software Engineering&lt;/h1&gt;
&lt;p&gt;During the Bootcamp, we used important aspects of SWE, such as Version Control. VC facilitated our interaction as a team. It became particularly more important in our final project when we depended on the same source code. We also used testing, refactoring, and optimization. During our performance assessment Kevin noticed that our version of NumPy had not leveraged Numpy in some vectors in the run_simulation function, once he refactored that code, we ran all the Python assessment again on the same computer and we discovered that just by changing a few lines of code the NumPy could perform almost in half the time.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;</content><author><name>Vinny Harris-Riviello</name></author><summary type="html"></summary></entry><entry><title type="html">Amazon prime has delivered a C++ package!</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/19/Day-9-Post.html" rel="alternate" type="text/html" title="Amazon prime has delivered a C++ package!" /><published>2021-08-19T00:00:00+00:00</published><updated>2021-08-19T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/19/Day-9-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/19/Day-9-Post.html">&lt;h1 id=&quot;multi-file-projects-&quot;&gt;Multi-file projects !&lt;/h1&gt;
&lt;p&gt;Placing all relevant functions for a program in the same file may be intuitive, however it can quickly become unorganized and hard to find functions you may need to change or update. Additionally, having all the functions in the same files requires that they all be written before your main() function, unless you declare the function before your main() and then define it after. This is known as forward declaration:&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;iostream&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Forward declaration of convert_F_to_C&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convert_F_to_C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;77&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;convert_F_to_C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Temperature is &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Function definition&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convert_F_to_C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.8&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Forward declaration tells the complier of the existence of the function, however the linker actually links the definition of the function into main after compiling. This may be necessary to avoid circular dependencies which occurs when two or more modules depend on each other to function properly. However placing a forward declaration into multiple files that require that function is inefficient and messy. Instead, header files ending with .hpp are used to declare a set of functions for source files to use. This way you place all the declarations of the functions your source files require into the header.hpp, and then import it using the include statement at the top of your source file. Thus, we can break up the program above into 3 files, main.cpp, temperature.cpp, and temperature.hpp.&lt;/p&gt;
&lt;p&gt;main.cpp:&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &quot;temperature.hpp&quot;
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;77&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;convert_F_to_C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Temperature is &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;temperature.cpp:&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;c1&quot;&gt;// Function definition&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convert_F_to_C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.8&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;temperature.hpp:&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Declaration of convert_F_to_C&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convert_F_to_C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Based on convention, files that are a part of the current project are included using quotation marks, but files from libraries are included with angled brackets. To avoid any circular dependency issues it is best practice to include &amp;quot;#pragma once&amp;quot; at the top of the header file, this tells the compiler to include the current file only once during compilation.&lt;/p&gt;
&lt;h1 id=&quot;documentation-&quot;&gt;Documentation !&lt;/h1&gt;
&lt;p&gt;To generate C++ documentation a program called Doxygen is used. You can place the documentation into the header file or the source file. There are pros and cons to each but no &amp;quot;right&amp;quot; way, however it is a best practice to choose one way and be consistent. In general, documentation should be up to date and include:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Short description&lt;/li&gt;
&lt;li&gt;Longer description&lt;/li&gt;
&lt;li&gt;Descriptions of arguments and types&lt;/li&gt;
&lt;li&gt;Description of return and type&lt;/li&gt;
&lt;li&gt;Exceptions and error conditions&lt;/li&gt;
&lt;li&gt;Edge cases&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following is documentation for our function above, placed in the temperature.hpp file above its function declaration.&lt;/p&gt;
&lt;p&gt;temperature.hpp:&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;cm&quot;&gt;/*! \brief Converts a temperature from Celsius to Fahrenheit
 *
 * Given a temperature in Celsius, converts it to Fahrenheit.
 * 
 *
 * \param [in] temperature Temperature (in Celsius) to convert
 * \return \p temperature converted to Fahrenheit
 */&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Declaration of convert_F_to_C&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convert_F_to_C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;At first glance this may seem like a normal C++ comment using &lt;code&gt;/*   */&lt;/code&gt;, however it starts with a &lt;code&gt;/*!&lt;/code&gt; which Doxygen looks for indicating documentation. The &lt;code&gt;\brief&lt;/code&gt; command denotes the short description and after the new line, everything is considered the long description. &lt;code&gt;\param&lt;/code&gt; denotes the parameter of the function and &lt;code&gt;\return&lt;/code&gt; denotes what the function returns. Before stating what the parameter name is, you need to add a tag for how the parameter is used, &lt;code&gt;[in]&lt;/code&gt; denotes input, &lt;code&gt;[out]&lt;/code&gt; denotes output and &lt;code&gt;[inout]&lt;/code&gt; denotes input and output.&lt;/p&gt;</content><author><name>Usman Jamshed</name></author><summary type="html">Multi-file projects ! Placing all relevant functions for a program in the same file may be intuitive, however it can quickly become unorganized and hard to find functions you may need to change or update. Additionally, having all the functions in the same files requires that they all be written before your main() function, unless you declare the function before your main() and then define it after. This is known as forward declaration:</summary></entry><entry><title type="html">If I Could Call An Argument, Do You Think Const Would Pass Me By?</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/18/Day-8-Post.html" rel="alternate" type="text/html" title="If I Could Call An Argument, Do You Think Const Would Pass Me By?" /><published>2021-08-18T00:00:00+00:00</published><updated>2021-08-18T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/18/Day-8-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/18/Day-8-Post.html">&lt;h2 id=&quot;argument-passing-by-copy-reference-pointer&quot;&gt;Argument Passing by Copy, Reference, Pointer&lt;/h2&gt;
&lt;p&gt;There are many different ways to call arguments into a function in C++. Unless specified, arguments are passed into function in C++ by copying the contents. Because the copy is stored in a new address, changes that are made to the data within the function are not reflected in the original data outside of the function. In the case we want to mutate the data we are calling into a function, we will need to refer to the data with &lt;code&gt;&amp;amp;&lt;/code&gt; in the signature of the function. Because a reference simply refers to a variable, a reference can be made to modify the variable's contents through the variable. Calling the reference should be the default way to pass in data that will be changed by the function.&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;iostream&amp;gt;
&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;5.0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;9.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;212.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Original temperature is &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;F.&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;New temperature is &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;C.&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;It is also possible to passing data by point. By passing the data with &lt;code&gt;*&lt;/code&gt; in the signature, the address of the variable will be passed into the function. Passing by pointer is sometimes used to pass around arrays allocated with &lt;code&gt;new&lt;/code&gt;, after which elements are accessed with &lt;code&gt;*&lt;/code&gt;. However, this is awkward for other uses, where passing by references are preferred.&lt;/p&gt;
&lt;h2 id=&quot;const-referencing&quot;&gt;Const referencing&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;const&lt;/code&gt; reference can be passed into a function to make an immutable variable. Once a const variable is passed into a function, it cannot be changed within the function. However it is important to maintain &lt;em&gt;const correctness&lt;/em&gt; when use const references. A &lt;code&gt;const&lt;/code&gt; reference can accept both &lt;code&gt;const&lt;/code&gt; and non-&lt;code&gt;const&lt;/code&gt; data, but non-&lt;code&gt;const&lt;/code&gt; reference can only take non-&lt;code&gt;const&lt;/code&gt; objects. Therefore, a non-&lt;code&gt;const&lt;/code&gt; reference cannot be made of a &lt;code&gt;const&lt;/code&gt; object, you can't try to refer and change a &lt;code&gt;const&lt;/code&gt; object. It's generally recommending to make reference arguments const if you do not have any intention of modifying the data, and is importing for maintaining the integrity of large data structures, like vectors and strings. It is much safer to write functions that do not mutate their input parameters, and to avoid global parameters.&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;iostream&amp;gt;
&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;5.0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;9.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperatureF&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;212.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tempuratureC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperatureF&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Original temperature is &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperatureF&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;F.&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;New temperature is &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperatureC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;C.&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;function-overloading&quot;&gt;Function Overloading&lt;/h2&gt;
&lt;p&gt;In C++, we can have multiple functions of the same name, so long as the functions have different signatures. This is called function overloading Because the compiler will determine which function is used based on the data types and numbers of the argument. It is important to note that functions cannot be overloaded by return type, meaning you cannot have two functions that input the same data type, but return two different types of data.  For examples, we can have two &lt;code&gt;convertFtoC&lt;/code&gt; functions, where one takes a &lt;code&gt;double&lt;/code&gt; and the other takes a &lt;code&gt;std::vector&amp;lt;double&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;5.0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;9.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperatures&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperatures&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;exceptions&quot;&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;C++ gives us several tools to test for errors. Because C++ requires the code to be free of errors upon compilation, any errors in the code will force the program to terminate. Therefore it is useful to use exceptions to catch areas of code that may be prone to errors to facilitate identifying sources of bug.  The &lt;code&gt;try&lt;/code&gt; statement allows us to test a section of code for errors. If an error is encountered in the &lt;code&gt;try&lt;/code&gt; block, a &lt;code&gt;catch&lt;/code&gt; statement can then be used to define a section of code to be executed. At any point a error is caught, a &lt;code&gt;throw&lt;/code&gt; statement allows us to make custom errors before the program is aborted.&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;stdexcept&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abs_zero&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;459.67&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;abs_zero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;runtime_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature is less than absolute zero&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;5.0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;9.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;500.00&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;runtime_error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error occurred!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;what&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;stdpair&quot;&gt;std::pair&lt;/h2&gt;
&lt;p&gt;A pair is a class of &lt;code&gt;std::tuple&lt;/code&gt; of two elements. It allows us to store two heterogeneous data types in one unit. The first element can be called by &lt;code&gt;first&lt;/code&gt;, and the second can be called by &lt;code&gt;second&lt;/code&gt;. a &lt;code&gt;std::pair&lt;/code&gt; makes it possible for us to return a unit of two different data types from a function. the keyword auto can be used to have C++ automatically determine the data type called, to the ease of the programmer. However it prudent to not use auto recklessly where data types are not explicitly understood, and where they may be incompatible.&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;utility&amp;gt;
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;5.0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;9.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Fahrenheit&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;convertFtoC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;212.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;In &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;, temperature is &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Kevin Fong</name></author><summary type="html">Argument Passing by Copy, Reference, Pointer</summary></entry><entry><title type="html">Turn up the speed with Monte C++arlo</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/17/Day-7-Post.html" rel="alternate" type="text/html" title="Turn up the speed with Monte C++arlo" /><published>2021-08-17T00:00:00+00:00</published><updated>2021-08-17T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/17/Day-7-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/17/Day-7-Post.html">&lt;h1 id=&quot;data-structures&quot;&gt;Data Structures&lt;/h1&gt;
&lt;p&gt;Stepping deeper into the grounds of c++. Today's material covered Arrays and Vectors, as well as Pointers and Memory concepts.
Some comparison points between std::array and vectors are:&lt;/p&gt;
&lt;p&gt;|        *          |  Array                            |  Vector                       |
|-------------------|-----------------------------------|-------------------------------|
| Length            |  Constant - known at compile time | Dynamic                       |
| Type              |  Homogeneous                      | Homogeneous                   |
| Memory            |  Contigous                        | Contiguos                     |
| Mem Management    |  Allocation needs to be dumped    | Automatically handled         |
| Access            |  Constant                         | By position - time-consuming  |
| Indexing          |  Index-based                      | Non-Index Based               |
| Resizing          | Expensive - requires new allocation | Dynamic by nature           |&lt;/p&gt;
&lt;h1 id=&quot;converting-mcsim-to-c&quot;&gt;Converting MCSIM to C++&lt;/h1&gt;
&lt;p&gt;We have been running Monte Carlo Simulation in Python. Now that we are learning c++ we are adventuring into creating a package in c++. Today's assignment is to rewrite our code to produce a c++ mcsim package.&lt;/p&gt;
&lt;h1 id=&quot;pointers-and-reference&quot;&gt;Pointers and Reference&lt;/h1&gt;
&lt;p&gt;Pointers can be thought of as school lockers. Let's say you get assigned locker #2 and you store your chem280 book inside. Well, a pointer would be like some other student also is given a key to access locker #2. So, that other student opens the locker and reads the chem280 book you stored inside. Now what would happen if after they read the chem280 book then they decide to store instead a book on ML? when you open that locker, what book would you find inside? Yes! now instead of finding your, originally stored, chem280 book you find the ML book inside. Nice, ha?&lt;/p&gt;
&lt;p&gt;References are another similar concept. However, key differences are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pointers in-memory store the address of the variable they are pointing to.&lt;/li&gt;
&lt;li&gt;Whereas references are like aliases, they have the same address. Whether in a variable or as arguments, they are referencing the same object.
&lt;ul&gt;
&lt;li&gt;It would be like someone knocking on your door looking for you but instead of using your name, they somehow got a hold of your secret super hero identity. Oh boy! Same address, same you.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;caveats&quot;&gt;Caveats&lt;/h1&gt;
&lt;p&gt;A few things to consider while rewriting code from Python to c++.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Remember that brackets matter
&lt;ul&gt;
&lt;li&gt;While a clause can allow the lack of curly bracket for a single line of code, the following lines will be out of scope regardless of indentation.&lt;/li&gt;
&lt;li&gt;Example the code below would throw an error, why?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rij&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cutoff&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pairEnergy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;culculatePE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;totalEnergy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pairEnergy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;In c++ you need to declare the type of the variables, and the return type of the functions, if there is no return then we use void.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;  &lt;span class=&quot;nf&quot;&gt;printAtom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AtomCoord&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atomLocation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;   
        &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atomSize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atomLocation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Atom location: [&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;atomSize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;atomLocation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atomSize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;, &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
            &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;]&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Make sure to always add a decimal to double types to avoid any strange type conversion.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Leverage the power of typedef. We can make typing more maneageable by defining a type such as a vector or array you will be working with a descriptive name.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Particles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Particles&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Coords&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;performance&quot;&gt;Performance&lt;/h1&gt;
&lt;p&gt;It needs to be said, we will have more details tomorrow when we finish the mcsim package, but what became very evident is that c++ is oh so fast.&lt;/p&gt;</content><author><name>Vinny Harris-Riviello</name></author><summary type="html">Data Structures Stepping deeper into the grounds of c++. Today's material covered Arrays and Vectors, as well as Pointers and Memory concepts. Some comparison points between std::array and vectors are:</summary></entry><entry><title type="html">Doing more? Say Less. we have C++</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/16/Day-6-Post.html" rel="alternate" type="text/html" title="Doing more? Say Less. we have C++" /><published>2021-08-16T00:00:00+00:00</published><updated>2021-08-16T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/16/Day-6-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/16/Day-6-Post.html">&lt;h2 id=&quot;c-as-a-programming-language&quot;&gt;C++ as a Programming Language&lt;/h2&gt;
&lt;p&gt;C++ is a general purpose programming language created as an extension of the C programming language. It was designed with an orientation toward system programming and embedded, resource-contained software and large systems, with performance, efficiency, and flexibility of us as its design highlights.&lt;/p&gt;
&lt;p&gt;C++ is an object oriented, staticly typed, compiled language. As a static typed language, all objects have their data type declared upon definition. As a compiled language, the source code is translated using compilers to produce machine code. Once compiled, the machine code is often undecipherable to humans. Because the compilation is performed in one step, compilation errors will prevent the code from compiling, and the code must debugged before the code is run and executed.&lt;/p&gt;
&lt;h2 id=&quot;comparing-python-and-cquot&quot;&gt;Comparing Python and C++&amp;quot;&lt;/h2&gt;
&lt;p&gt;Python by comparison is a high-level, mutli-paradigm, dynamically typed, garbage-collected, interpreted language. As an interpreted language, Python code is not compiled into machine instructions and is ready to be read and interpreted as is. Because it is dynamically written, data types are not declared, making Python more flexible and easy to use. However C++ is able to perform more efficiently because all data types are declared at the point of compilation, so the machine does not have to consume any extra time to interpret the code to determine what data types are being used.&lt;/p&gt;
&lt;p&gt;In terms of syntax, C++ is a more rigorously structured language. As all object need to be declared, and syntax accuracy is more important, C++ may use more lines of code to accomplish the same objective in Python. On the other hand, as a language Python is sensitive to whitespace, meaning code written in python uses indents to separate sections and layer of code. C++ ignores whitespace, and uses curly braces &lt;code&gt;{}&lt;/code&gt; to delineate sections of code and &lt;code&gt;;&lt;/code&gt; to separate lines. Between the two, only Python forces the programmer to organize the code visually through indents, although it is good practice to or intent in C++ to make the code more legible.&lt;/p&gt;
&lt;p&gt;C++ also uses various shortcuts or conventions which I feel add some character to the language. As in the namesake, C++ has an increment operator (&lt;code&gt;++&lt;/code&gt;) as well as a decrement operator (&lt;code&gt;--&lt;/code&gt;). C++ will also use the conventions of &lt;code&gt;||&lt;/code&gt; and &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; for &lt;strong&gt;or&lt;/strong&gt; and &lt;strong&gt;and&lt;/strong&gt; respectively.&lt;/p&gt;
&lt;h2 id=&quot;debugging-c&quot;&gt;Debugging C++&lt;/h2&gt;
&lt;p&gt;Because C++ is compiled language, the code must be free of errors for the code to compile successfully. C++ has a strict syntax, thus the compilers are able to identify any and all deviations in the code from expected syntax that will prevent the compilers from interpreting to code as we expect. As C++ will try to give full details and insight about each instance of error it encounters, it often produces large returns of error messages that become ironically increasingly less useful to the human programmer to troubleshoot and fix.&lt;/p&gt;
&lt;h2 id=&quot;riemann-sum-in-c&quot;&gt;Riemann Sum in C++&lt;/h2&gt;
&lt;p&gt;A Riemann sum is an approximation of an integral using a finite sum of areas of uniform width. The formula for the Riemann sum is as follows:
$$&lt;em&gt;S&lt;/em&gt; = \sum_{i = 1}^{n} f(x_{i}&lt;em&gt;) \Delta x$$
For our particular approximation we implemented Midpoint Riemann Sum, where the height $f(x_{i}&lt;/em&gt;$ of the box is calculated at the midpoints of the boxes, at points  $a + \frac{\Delta x}{2} , a + \frac{3\Delta x}{2} , ... , b - a + \frac{\Delta x}{2}$ . We used C++ to define the function of the integrand, and calculated the midpoints of our boxes to determine the height of our boxes to be summed. The code for the calculation of the Riemann sum of the integral $\int_{0}^{1} \frac{1}{1-x^2} dx$ in C++ is as follows&lt;/p&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;integrand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;integral&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n_points&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Riemann&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_points&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n_points&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;boxArea&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;integrand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dx&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dx&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Riemann&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;boxArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Riemann&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;double&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;integral&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;For &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; boxes, pi is approximately &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;.&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This exercise was very valuable for us to understand the data types and the scope of the objects we are declaring in our code and if they are able to be called in a given step.&lt;/p&gt;</content><author><name>Kevin Fong</name></author><summary type="html">C++ as a Programming Language</summary></entry><entry><title type="html">Amazon has delivered a Python Package!</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/13/Day-5-Post.html" rel="alternate" type="text/html" title="Amazon has delivered a Python Package!" /><published>2021-08-13T00:00:00+00:00</published><updated>2021-08-13T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/13/Day-5-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/13/Day-5-Post.html">&lt;h1 id=&quot;packages-&quot;&gt;Packages !&lt;/h1&gt;
&lt;p&gt;Code organization is an important aspect of software development. Making program packages is a great way to organize your code and make your code accessible to share with others. Once your code is in a package you can import the package like NumPy and Random and use all the functions in the package. This cleans up the code you would have to write and lets you reuse code/functions you have already created easily. To start you should create a folder which will serve as your package and place your code inside of it. Then you should create a new file called setup.py and place the following code in it:&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;This code will set up the package for you and if you intend to upload the package to the Python Package Index (PyPi), the name you set would have to be unique. The final step to be able to import the code anywhere you need to use the &amp;quot;pip install -e .&amp;quot; command in the folder containing the setup.py. This will install the package into your python site packages folder. By adding an &amp;quot;&lt;strong&gt;init&lt;/strong&gt;.py&amp;quot; file you can change the way you can import the functions from the python modules of your package. If done correctly, you can decrease the amount of imports you have to do for a package and import all the functions using just one import statement.&lt;/p&gt;
&lt;h1 id=&quot;testing-in-pytest-&quot;&gt;Testing in Pytest !&lt;/h1&gt;
&lt;p&gt;Writing code is important but making sure it does what you think it does is even more important. Thus, creating test cases to evaluate if your functions return what you think they should is essential. One way to do this is by creating &lt;strong&gt;assert&lt;/strong&gt; statements. However, this is not as efficient as making a test suite that tests all your functions and makes sure they don't throw any exceptions. To do this you can install a testing framework called pytest using &amp;quot;pip install -U pytest-cov&amp;quot;. Then create a folder called with test_name and inside create a python file starting with test_name.py. Inside this test_name.py folder you can add functions to run tests on the functions you have written in another file or package, but make sure to import them first. Then to run, you can just call &amp;quot;pytest&amp;quot; in the testing directory and it will run all the tests and let you know which have passed/failed.&lt;/p&gt;</content><author><name>Usman Jamshed</name></author><summary type="html">Packages ! Code organization is an important aspect of software development. Making program packages is a great way to organize your code and make your code accessible to share with others. Once your code is in a package you can import the package like NumPy and Random and use all the functions in the package. This cleans up the code you would have to write and lets you reuse code/functions you have already created easily. To start you should create a folder which will serve as your package and place your code inside of it. Then you should create a new file called setup.py and place the following code in it:</summary></entry><entry><title type="html">NumPy to the rescue! No more Loops.</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/12/Day-4-Post.html" rel="alternate" type="text/html" title="NumPy to the rescue! No more Loops." /><published>2021-08-12T00:00:00+00:00</published><updated>2021-08-12T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/12/Day-4-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/12/Day-4-Post.html">&lt;h1 id=&quot;numpy-library&quot;&gt;NumPy Library&lt;/h1&gt;
&lt;p&gt;We started the day with the introduction of a Python library called NumPy. We used it to simplify the operations we have been working with.
As shown during our lecture and group work today, NumPy is very powerful.  Another one of its benefits is efficiency. We compared the Python library definitions of functions to the ones we modified to use NumPy, and we observed significant performance gains. Under the hood NumPy uses C, making it faster than the standard Python implementation.&lt;/p&gt;
&lt;h3 id=&quot;numpy-arrays&quot;&gt;NumPy Arrays&lt;/h3&gt;
&lt;p&gt;One of the benefits of NumPy is how clean the code becomes. To work with NumPy we had to convert our lists to numpy.ndarray objects. The previous days we had been storing the coordinates in lists. NumPy allows us to initialize a numpy.ndarray with a list. Thus it was easy to transform. Array operations using the NumPy library are concise and intuitive. For example, all we needed to do to multiply one array with another was to literally multiply one by the other. We were able to remove embedded 'for loops'. NumPy takes care of the heavy lifting for us so there is no need to loop through the elements in the array.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;a1 = np.array([2, 1, 0])
a2 = np.array([1, 3, 5])

a1 * a2
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Note: It is important to understand that in multidimensional arrays shape matters, meaning to perform operations on multiple arrays they need to be compatible.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;discussion&quot;&gt;Discussion&lt;/h2&gt;
&lt;p&gt;Today we had our discussion session in different groups. Kevin and I joined with Joyce to talk about the NumPy arrays and how we could leverage them in the Monte Carlo Simulation.&lt;/p&gt;
&lt;p&gt;We were already given the &lt;strong&gt;calculate_distance_np&lt;/strong&gt; to start with but we still needed to update some other functions to be able to use the library.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;def calculate_distance_np(coord1, coord2, box_length=None):
    &amp;quot;&amp;quot;&amp;quot;
    Calculate the distance between two points. 
    When box_length is set, the minimum image convention is
    used to calculate the distance between the points.

    Parameters
    ----------
    coord1, coord2 : np.array
        The coordinates of the points, [x, y, z]
    
    box_length : float, optional
        The box length

    Returns
    -------
    distance : float
        The distance between the two points accounting for periodic boundaries
    &amp;quot;&amp;quot;&amp;quot;
    coord_dist=coord1-coord2
    if box_length:    
            coord_dist = coord_dist - (box_length * np.round(coord_dist/box_length))
    if coord_dist.ndim &amp;lt;2:
        #reshaping the array, make it have 2 dimensions
        coord_dist = coord_dist.reshape (1,-1)
    coord_dist=coord_dist**2
    dist_sum= coord_dist.sum(axis=1)
    distance = np.sqrt(dist_sum)
    return distance
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We considered the different places and functions where using NumPy would make a difference. Since some of the functions are handling the operations done on the large number of coordinates and looping through them, they were a good starting point.&lt;/p&gt;
&lt;p&gt;We concluded that we needed to create the following based on their standard implementation&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;calculate_pair_energy_np&lt;/li&gt;
&lt;li&gt;calculate_total_energy_np&lt;/li&gt;
&lt;li&gt;and possibly the calculate_lj_np&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;/h2&gt;
&lt;p&gt;Once we moved back to our original team2 members we implemented the solutions. For the top two, we were able to remove the 'for loops', but to do that we had to modify the calculate_LJ to take in an np array.&lt;/p&gt;
&lt;h3 id=&quot;comparing-run-time&quot;&gt;Comparing run time&lt;/h3&gt;
&lt;p&gt;During our morning lecture, we also learned about calculating elapsed time and comparing the two implementations to validate the efficiency of NumPy. Again we confirmed that using NumPy does offer a performance gain.&lt;/p&gt;</content><author><name>Vinny Harris-Riviello</name></author><summary type="html">NumPy Library We started the day with the introduction of a Python library called NumPy. We used it to simplify the operations we have been working with. As shown during our lecture and group work today, NumPy is very powerful. Another one of its benefits is efficiency. We compared the Python library definitions of functions to the ones we modified to use NumPy, and we observed significant performance gains. Under the hood NumPy uses C, making it faster than the standard Python implementation.</summary></entry><entry><title type="html">Monte Carlo again? It’s a Loop</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/11/Day-3-Post.html" rel="alternate" type="text/html" title="Monte Carlo again? It’s a Loop" /><published>2021-08-11T00:00:00+00:00</published><updated>2021-08-11T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/11/Day-3-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/11/Day-3-Post.html">&lt;h2 id=&quot;continuing-on-monte-carlo-simulation&quot;&gt;Continuing on Monte Carlo Simulation&lt;/h2&gt;
&lt;p&gt;Our primary topic today focuses on the application of the Monte Carlo simulation to generate sample configurations of particles in order understand and characterize the statistical mechanics of a system. However as powerful as Monte Carlo simulation is, simply considering all coordinates for our configuration is very inefficient. This is because although a randomly generated configuration may be possible, configurations with high energy are simply not likely to occur. Therefore it is useful to sample positions from a desired equilibrium probability distribution, where configurations that have a low probability are generated less frequently to more realistic and relevent configurations. This is the concept of &lt;strong&gt;importance sampling&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;implementing-the-metropolis-criteron&quot;&gt;Implementing the Metropolis Criteron&lt;/h2&gt;
&lt;p&gt;To accomplish this, we are going to implement acceptance criteria, specifically the &lt;em&gt;Metropolis-Hasting&lt;/em&gt; algorithm, to determine if we will accept a change in the position of a particle in a system considering the changes in the system energy that the positional shift imparts. The &lt;em&gt;Metropolis-Hasting&lt;/em&gt; criterion we built into our model is as follows:&lt;/p&gt;
&lt;p&gt;$$ P_acc &lt;em&gt;P&lt;!-- raw HTML omitted --&gt;acc&lt;!-- raw HTML omitted --&gt;(m → n)&lt;/em&gt; = min[1,&lt;em&gt;e&lt;/em&gt;&lt;!-- raw HTML omitted --&gt;-$\Delta$U/&lt;em&gt;T&lt;/em&gt;&lt;!-- raw HTML omitted --&gt;] $$&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;As we have established our system, if a configuration is energetically more favorable, it is always accepted. If a configuration is more energetically &amp;quot;uphill&amp;quot;, a number is generated randomly on (0,1) and compared to the expression &lt;em&gt;e&lt;/em&gt;&lt;!-- raw HTML omitted --&gt;-$\Delta$U/&lt;em&gt;T&lt;/em&gt;&lt;!-- raw HTML omitted --&gt;. If the generated number is less than the result of the expression, the criterion is not met, and the change is rejected. By this model, all configurations with lower energy are always accepted, configuration with increases in energy are accepted a fraction of the time, and configurations that have great increases in energy are possible, but very unlikely.&lt;/p&gt;
&lt;p&gt;We continued to investigate on the relation between the expression &lt;em&gt;e&lt;/em&gt;&lt;!-- raw HTML omitted --&gt;-$\Delta$U/&lt;em&gt;T&lt;/em&gt;&lt;!-- raw HTML omitted --&gt; and the probability density. Upon plotting the probability density against $\Delta$U from (-2,2) for different values of T the following graph was generated.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Figure 1&lt;/strong&gt;: Probability density visualized against various $\Delta$U for three different temperatures&lt;/em&gt;&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;Upon discussing our models, we noted that for the domain $\Delta$U &amp;gt; 0, if the temperature of the system is higher, the probability density is also higher. This means that at higher temperatures, systems are more likely to enter states of higher energy. We also noted that for all $\Delta$U &amp;lt; 0, the generated &lt;em&gt;P&lt;!-- raw HTML omitted --&gt;acc&lt;!-- raw HTML omitted --&gt;&lt;/em&gt; was above 1.0 for all temperatures. However, because this value was only compared to a generated number from (0,1), the shift is effectively accepted 100% of the time. This lines up with our assumption that all configurations of lower energy are accepted.&lt;/p&gt;
&lt;h2 id=&quot;monte-carlo-looping&quot;&gt;Monte Carlo Looping&lt;/h2&gt;
&lt;p&gt;Using a function we built to calculate the sum of all pairwise interactions experienced by a particle, accounting for cutoff and periodic boundaries, we built a Monte Carlo simulation loop to simulate the step taken by our input configuration. If a step produces a state that is accepted by our &lt;em&gt;Metropolis Criterion&lt;/em&gt;, then the step is accepted, the energy is recorded in a list, and the simulation continues. Otherwise, the step is reverted back to the original configuration before the generated changes, and the Monte Carlo randomly introduces another configuration. The Monte Carlo loop we built is shown below:&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;h2 id=&quot;random-seed-i-mean-randomseed&quot;&gt;Random Seed, I mean random.seed()&lt;/h2&gt;
&lt;p&gt;A useful tool to build sanity checks for functions with random number generators is to call a seed. This means that the same sequence of random numbers are call by that seed anytime it is called. Very handy for teaching and debugging purposes.&lt;/p&gt;</content><author><name>Kevin Fong</name></author><summary type="html">Continuing on Monte Carlo Simulation</summary></entry><entry><title type="html">The Three Musketeers: Monte Carlo, Monty Python and Lennard Jones</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/10/Day-2-Post.html" rel="alternate" type="text/html" title="The Three Musketeers: Monte Carlo, Monty Python and Lennard Jones" /><published>2021-08-10T00:00:00+00:00</published><updated>2021-08-10T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/10/Day-2-Post</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/10/Day-2-Post.html">&lt;h1 id=&quot;monte-carlo-simulations&quot;&gt;Monte Carlo Simulations!&lt;/h1&gt;
&lt;p&gt;Traditional integration techniques are very efficient in solving simple integrals, however sometimes integrals can be impossible to evaluate analytically, leading to the use of Monte Carlo simulations. This method uses repeated random sampling to &lt;strong&gt;estimate&lt;/strong&gt; the outcomes of an event. Using this technique, integrals that are virtually impossible to analytically calculate become much more manageable. However, due to the nature of repeated random sampling a large number of observations needs to be conducted to ensure an accurate estimate. Thus, a balance between speed and accuracy needs to be met, where the simulation is both fast (lower number of observations) and accurate (higher number of observations) to the true result.&lt;/p&gt;
&lt;h1 id=&quot;lennard-jones-potentials&quot;&gt;Lennard Jones Potentials!&lt;/h1&gt;
&lt;p&gt;The Lennard Jones Potential is an approximation of the energy of nonbonded interactions (Equation 1). It is a pairwise potential and can be visualized as a graph with two main sections, a repulsive domain and an attractive domain. At a relatively great distance, the pair of atoms have negligible interactions and their potential is ~0. However as the particles are brought closer together, the interaction becomes attractive until the point $$r_m$$, where the potential energy is at a minimum of - $\varepsilon$ . At closer distances, the repulsive interactions overtake the attractive forces. The energy potential rising exponentially as the distance between them approaches 0. Conducting the approximation in reduced units is ideal because using SI units makes the values incredibility inconvenient to work with due to their very large or very small values and the inherent floating point error. The total pair potential energy of a system of particles can also be calculated by calculating the sum of the Lennard Jones energies over all pairwise interactions.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Figure 1&lt;/strong&gt;: Graph of the Lennard Jones Potential, taken from https://en.wikipedia.org/wiki/Lennard-Jones_potential#/media/File:Graph_of_Lenanrd-Jones_potential.png&lt;/em&gt;&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;$$ U^&lt;em&gt;\left(r_{ij} \right) = 4 \left[\left(\frac{1}{r^&lt;/em&gt;&lt;em&gt;{ij}}\right)^{12} -\left(\frac{1}{r^*&lt;/em&gt;{ij}}\right)^{6} \right] $$
&lt;em&gt;&lt;strong&gt;Equation 1&lt;/strong&gt;: Reduced Lennard Jones potential equation&lt;/em&gt;&lt;/p&gt;
&lt;h1 id=&quot;python&quot;&gt;Python!&lt;/h1&gt;
&lt;p&gt;Writing code is a useful skill but documenting your code is an essential good coding practice. Writing docstrings within functions gives other programmers a rough idea of what your function does and what its parameters are. To write a docstring, start by writing three quotes and separating them with a line. Begin your docstring with a title of the function followed up with a short description (sometimes a title is descriptive enough). After the introduction you should write out the parameters used by the function as well as their data type and a short description. Then you should write what the function returns as well as its data type and a short description. Finally, you can conclude your docstring with some examples and the expected output.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;Testing and debugging code is another useful skill and can be done painlessly using the &lt;strong&gt;assert&lt;/strong&gt; function in python. To use it, write assert followed by a condition that you believe is true. If the condition evaluates to True, the program will continue to run. However if the condition returns False, the assert function will raise an assertion error at that point, at which you will need to troubleshoot the code.&lt;/p&gt;</content><author><name>Usman Jamshed</name></author><summary type="html">Monte Carlo Simulations! Traditional integration techniques are very efficient in solving simple integrals, however sometimes integrals can be impossible to evaluate analytically, leading to the use of Monte Carlo simulations. This method uses repeated random sampling to estimate the outcomes of an event. Using this technique, integrals that are virtually impossible to analytically calculate become much more manageable. However, due to the nature of repeated random sampling a large number of observations needs to be conducted to ensure an accurate estimate. Thus, a balance between speed and accuracy needs to be met, where the simulation is both fast (lower number of observations) and accurate (higher number of observations) to the true result.</summary></entry><entry><title type="html">Introducing Kevin Fong</title><link href="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/09/Kevin-Fong.html" rel="alternate" type="text/html" title="Introducing Kevin Fong" /><published>2021-08-09T00:00:00+00:00</published><updated>2021-08-09T00:00:00+00:00</updated><id>https://msse-2021-bootcamp.github.io/team2-blog/2021/08/09/Kevin-Fong</id><content type="html" xml:base="https://msse-2021-bootcamp.github.io/team2-blog/2021/08/09/Kevin-Fong.html">&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;h1 id=&quot;about&quot;&gt;About!&lt;/h1&gt;
&lt;p&gt;Kevin is from LA and lived there for 18 years, but is currently living in San Francisco. His favourite food is seared scallops from Octavia, which was so good that he had to take a moment in the resturant to collect himself. His least favourite food is cucumbers which he detests and will not eat food which has been &amp;quot;contaminated&amp;quot; with them. He is very much an indoor person and enjoys overcast days right before its going to rain. He enjoys socializing through video games board games and loves hosting dinner parties and cooking for his friends.&lt;/p&gt;
&lt;h1 id=&quot;pets&quot;&gt;Pets!&lt;/h1&gt;
&lt;p&gt;No pets 😞&lt;/p&gt;
&lt;h1 id=&quot;hobbies&quot;&gt;Hobbies!&lt;/h1&gt;
&lt;p&gt;Enjoys Pokemon and has bought all releases religiously up till Pokemon Sword and Shield, but isn't really excited for the upcoming releases due to GameFreaks past short comings. Kevin listens to alot of EDM and enjoys raves. He is a huge fan of Porter Robinson because hes able to express a strong sense of escapism through his music. Proter Robinson's new album Nurture, is centered around his mental health which Kevin really resonated with and is hands down his favourite album of 2021. He also used to work at a boba shop during his undergrad where he was able to be a part of a small resturant community in the city. This experience made him realize he loves being involved in his community and enjoys building a craft for others to enjoy.&lt;/p&gt;</content><author><name>Usman Jamshed</name></author><summary type="html"></summary></entry></feed>