Skip to content

Commit

Permalink
Merge pull request #7 from MikeHeiber/development
Browse files Browse the repository at this point in the history
Minor Development Update
  • Loading branch information
MikeHeiber authored Aug 31, 2017
2 parents 398997f + 5d28e41 commit 0b6c10a
Show file tree
Hide file tree
Showing 22 changed files with 278 additions and 57 deletions.
9 changes: 9 additions & 0 deletions Lattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ int Lattice::getNumSites() const{
return (int)site_ptrs.size();
}

Coords Lattice::getSiteCoords(int site_index) {
Coords coords;
coords.x = site_index / (Width*Height);
int remainder = site_index % (Width*Height);
coords.y = remainder / Height;
coords.z = remainder % Height;
return coords;
}

int Lattice::getSiteIndex(const Coords& coords) const{
return coords.x*Width*Height + coords.y*Height + coords.z;
}
Expand Down
5 changes: 5 additions & 0 deletions Lattice.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ class Lattice{
//! \return The number of sites in the lattice.
int getNumSites() const;

//! \brief Gets the coordinates of the specified site.
//! \param site_index is the vector index of the input site
//! \return a Coords object that contains the coordinates of the site specified by the site index.
Coords getSiteCoords(int site_index);

//! \brief Gets the vector index for the site corresponding to the input coordinates.
//! \param coords is the Coords struct that represents the input coordinates.
//! \return The vector index for the sites vector that is associated with the site located at the input coordinates.
Expand Down
21 changes: 21 additions & 0 deletions Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ namespace Utils {
}
}

double integrateData(const vector<pair<double, double>>& data) {
double area = 0;
for (int i = 1; i < (int)data.size(); i++) {
area += ((data[i - 1].second + data[i].second) / 2.0)*(data[i].first - data[i - 1].first);
}
return area;
}

double interpolateData(const vector<pair<double, double>>& data, const double x_val) {
for (int i = 1; i < (int)data.size(); i++) {
if (data[i-1].first < x_val && data[i].first > x_val) {
return data[i - 1].second + ((data[i].second - data[i - 1].second) / (data[i].first - data[i - 1].first))*(x_val - data[i - 1].first);
}
if (abs(data[i].first - x_val) < 1e-6) {
return data[i].second;
}
}
cout << "Warning! The input x-value lies outside the range of the input data set." << endl;
return NAN;
}

vector<double> MPI_calculateVectorAvg(const vector<double>& input_vector) {
int data_size = 0;
int data_count = 0;
Expand Down
29 changes: 28 additions & 1 deletion Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Coords{
//! \date 2017
namespace Utils {

// Scientifc Constants
// Scientific Constants
static constexpr double K_b = 8.61733035e-5;
static constexpr double Elementary_charge = 1.602176621e-19; // C
static constexpr double Vacuum_permittivity = 8.854187818e-12; // C/Vm
Expand Down Expand Up @@ -116,6 +116,19 @@ namespace Utils {
//! \return flase if the input string is "flase".
bool importBooleanParam(const string& input, bool& error_status);

//! \brief Numerically integrates a vector of x-y data using the trapezoid rule.
//! \warning The function assumes that the data is sorted by the x values.
//! \param data is the data vector containing x-y data pairs.
//! \return the numerically calculated area.
double integrateData(const vector<pair<double, double>>& data);

//! \brief Linearly interpolates an x-y data set to determine the interpolated y-value corresponding to an input x-value.
//! \warning The function assumes that the data is sorted by the x values.
//! \param data is the data vector containing x-y data pairs.
//! \param x_val is the x-value that will be interpolated to.
//! \return the interpolated y-value when the input x-value lies within the range of the input data.
double interpolateData(const vector<pair<double, double>>& data, const double x_val);

//! \brief Uses MPI to calculate the element-wise average vector from separate vectors coming from different processors.
//! \details Each processor calls this function and sends an input vector. Upon function return, processor 0
//! receives the average vector and all of the other processors receive an empty vector.
Expand Down Expand Up @@ -224,6 +237,20 @@ namespace Utils {
outfile.close();
}

//! \brief This template function outputs the input data pair vector to a file with the specified filename.
//! \warning This function may overwrite existing files if not used carefully.
//! \param vec is the input data pair vector.
//! \param filename is the input file name.
template<typename T>
void outputVectorToFile(vector<pair<T,T>>& vec, string filename) {
ofstream outfile;
outfile.open(filename);
for (int i = 0; i < (int)vec.size(); i++) {
outfile << vec[i].first << "," << vec[i].second << "\n";
}
outfile.close();
}

//! \brief This template function efficienctly removes the duplicate entries from an input vector.
//! \details This algorithm allow efficient removal of duplicate vector objects when > or < comparison operators do not exist.
//! \param vec is the input vector to be operated on.
Expand Down
2 changes: 1 addition & 1 deletion docs/_lattice_8h_source.html

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/_utils_8h_source.html

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions docs/class_lattice-members.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,20 @@
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#aaa0cba3ab33ac620d9b9f9508c56d1ac">getHeight</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#a4b43b67a36fcd3dfe62c9eeaffa561d2">getLength</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#ae8046ebe4dbbe34b03548384ae79d4ae">getNumSites</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#abafcbcee9689c0cf7a21134095075604">getSiteIndex</a>(const Coords &amp;coords) const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#a46f7d12855d24e1bdd02814621b0a178">getSiteIt</a>(const Coords &amp;coords)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#ac6963a6b2b4b8d96d3417f6e9c2a509d">getUnitSize</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#aeb60d2b8bfb02d9da8bef463f0d41428">getWidth</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#a4067a9617cc24fa60ca6b47fccb4c123">init</a>(const Parameters_Lattice &amp;params, mt19937 *generator_ptr)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#a4d37afb6ad4c67f4f6462c2f6d5c337d">isOccupied</a>(const Coords &amp;coords) const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#accf3b995e0d0cb422907728a29b1b523">isXPeriodic</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#ac3192acefb019c5258143a6c758b3e48">isYPeriodic</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#ad7dd1b12a253e506aba5cedb57bf86ea">isZPeriodic</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#a70a5cebc3c0c5a0f609be0592e7cc117">Lattice</a>()</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#aa1f65735ecbd750ec04b6413b4d47316">outputLatticeOccupancy</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#a515b8bc548ef4a87c3495a7352a60399">setOccupied</a>(const Coords &amp;coords)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#aaa16f46daaf157c155f0e9b378a07b5d">setSitePointers</a>(const vector&lt; Site *&gt; &amp;input_ptrs)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#a554b9d4e654f02246ffbeab24a670362">getSiteCoords</a>(int site_index)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#abafcbcee9689c0cf7a21134095075604">getSiteIndex</a>(const Coords &amp;coords) const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#a46f7d12855d24e1bdd02814621b0a178">getSiteIt</a>(const Coords &amp;coords)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#ac6963a6b2b4b8d96d3417f6e9c2a509d">getUnitSize</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#aeb60d2b8bfb02d9da8bef463f0d41428">getWidth</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#a4067a9617cc24fa60ca6b47fccb4c123">init</a>(const Parameters_Lattice &amp;params, mt19937 *generator_ptr)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#a4d37afb6ad4c67f4f6462c2f6d5c337d">isOccupied</a>(const Coords &amp;coords) const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#accf3b995e0d0cb422907728a29b1b523">isXPeriodic</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#ac3192acefb019c5258143a6c758b3e48">isYPeriodic</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#ad7dd1b12a253e506aba5cedb57bf86ea">isZPeriodic</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#a70a5cebc3c0c5a0f609be0592e7cc117">Lattice</a>()</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#aa1f65735ecbd750ec04b6413b4d47316">outputLatticeOccupancy</a>() const</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_lattice.html#a515b8bc548ef4a87c3495a7352a60399">setOccupied</a>(const Coords &amp;coords)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_lattice.html#aaa16f46daaf157c155f0e9b378a07b5d">setSitePointers</a>(const vector&lt; Site *&gt; &amp;input_ptrs)</td><td class="entry"><a class="el" href="class_lattice.html">Lattice</a></td><td class="entry"></td></tr>
</table></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
Expand Down
30 changes: 30 additions & 0 deletions docs/class_lattice.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<tr class="memitem:ae8046ebe4dbbe34b03548384ae79d4ae"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_lattice.html#ae8046ebe4dbbe34b03548384ae79d4ae">getNumSites</a> () const</td></tr>
<tr class="memdesc:ae8046ebe4dbbe34b03548384ae79d4ae"><td class="mdescLeft">&#160;</td><td class="mdescRight">Gets the number of sites contained in the lattice. <a href="#ae8046ebe4dbbe34b03548384ae79d4ae">More...</a><br /></td></tr>
<tr class="separator:ae8046ebe4dbbe34b03548384ae79d4ae"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a554b9d4e654f02246ffbeab24a670362"><td class="memItemLeft" align="right" valign="top"><a class="el" href="struct_coords.html">Coords</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_lattice.html#a554b9d4e654f02246ffbeab24a670362">getSiteCoords</a> (int site_index)</td></tr>
<tr class="memdesc:a554b9d4e654f02246ffbeab24a670362"><td class="mdescLeft">&#160;</td><td class="mdescRight">Gets the coordinates of the specified site. <a href="#a554b9d4e654f02246ffbeab24a670362">More...</a><br /></td></tr>
<tr class="separator:a554b9d4e654f02246ffbeab24a670362"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:abafcbcee9689c0cf7a21134095075604"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_lattice.html#abafcbcee9689c0cf7a21134095075604">getSiteIndex</a> (const <a class="el" href="struct_coords.html">Coords</a> &amp;coords) const</td></tr>
<tr class="memdesc:abafcbcee9689c0cf7a21134095075604"><td class="mdescLeft">&#160;</td><td class="mdescRight">Gets the vector index for the site corresponding to the input coordinates. <a href="#abafcbcee9689c0cf7a21134095075604">More...</a><br /></td></tr>
<tr class="separator:abafcbcee9689c0cf7a21134095075604"><td class="memSeparator" colspan="2">&#160;</td></tr>
Expand Down Expand Up @@ -780,6 +783,33 @@ <h2 class="memtitle"><span class="permalink"><a href="#ae8046ebe4dbbe34b03548384
<p>Gets the number of sites contained in the lattice. </p>
<dl class="section return"><dt>Returns</dt><dd>The number of sites in the lattice. </dd></dl>

</div>
</div>
<a id="a554b9d4e654f02246ffbeab24a670362"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a554b9d4e654f02246ffbeab24a670362">&#9670;&nbsp;</a></span>getSiteCoords()</h2>

<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="struct_coords.html">Coords</a> Lattice::getSiteCoords </td>
<td>(</td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>site_index</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">

<p>Gets the coordinates of the specified site. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">site_index</td><td>is the vector index of the input site </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a <a class="el" href="struct_coords.html" title="This simple struct contains Cartesian coordinates specified by integers x,y,z. ">Coords</a> object that contains the coordinates of the site specified by the site index. </dd></dl>

</div>
</div>
<a id="abafcbcee9689c0cf7a21134095075604"></a>
Expand Down
1 change: 1 addition & 0 deletions docs/class_lattice.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var class_lattice =
[ "getHeight", "class_lattice.html#aaa0cba3ab33ac620d9b9f9508c56d1ac", null ],
[ "getLength", "class_lattice.html#a4b43b67a36fcd3dfe62c9eeaffa561d2", null ],
[ "getNumSites", "class_lattice.html#ae8046ebe4dbbe34b03548384ae79d4ae", null ],
[ "getSiteCoords", "class_lattice.html#a554b9d4e654f02246ffbeab24a670362", null ],
[ "getSiteIndex", "class_lattice.html#abafcbcee9689c0cf7a21134095075604", null ],
[ "getSiteIt", "class_lattice.html#a46f7d12855d24e1bdd02814621b0a178", null ],
[ "getUnitSize", "class_lattice.html#ac6963a6b2b4b8d96d3417f6e9c2a509d", null ],
Expand Down
3 changes: 3 additions & 0 deletions docs/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ <h3><a id="index_g"></a>- g -</h3><ul>
<li>getObjectTargetPtr()
: <a class="el" href="class_event.html#ab86f724c3c894faa1d6ccca78c357d24">Event</a>
</li>
<li>getSiteCoords()
: <a class="el" href="class_lattice.html#a554b9d4e654f02246ffbeab24a670362">Lattice</a>
</li>
<li>getSiteIndex()
: <a class="el" href="class_lattice.html#abafcbcee9689c0cf7a21134095075604">Lattice</a>
</li>
Expand Down
3 changes: 3 additions & 0 deletions docs/functions_func.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ <h3><a id="index_g"></a>- g -</h3><ul>
<li>getObjectTargetPtr()
: <a class="el" href="class_event.html#ab86f724c3c894faa1d6ccca78c357d24">Event</a>
</li>
<li>getSiteCoords()
: <a class="el" href="class_lattice.html#a554b9d4e654f02246ffbeab24a670362">Lattice</a>
</li>
<li>getSiteIndex()
: <a class="el" href="class_lattice.html#abafcbcee9689c0cf7a21134095075604">Lattice</a>
</li>
Expand Down
Loading

0 comments on commit 0b6c10a

Please sign in to comment.