Skip to content

Commit

Permalink
Calculate Displacement Update (#75)
Browse files Browse the repository at this point in the history
Resolves #74 
- Updated Changelog to note all changes
- Regenerated docs
- Updated copyright in Object class files
- Updated Object::calculateDisplacement function to calculate the net displacement when specifying and direction instead of the absolute displacement and updated the documentation accordingly
- Updated CalculateDisplacement units tests to check for negative displacement when specifying the displacement direction
  • Loading branch information
Michael C. Heiber authored Aug 9, 2020
1 parent 4bc153e commit 27e02c6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v2.1.0] - 2020-07-25 - Build Update
## [v2.1.0] - 2020-08-09 - Build and Bugfix Update

### Added
- .travis.yml - Test builds for GCC 9
Expand All @@ -18,17 +18,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- README.md - Information about clang compiler support

### Changed
- .travis.yml - Copyright years up 2020
- .travis.yml - Copyright years up to 2020
- .travis.yml - Test build OS from Ubuntu trusty to Ubuntu xenial and bionic
- .travis.yml - Simplified how GCC versions are installed and configured
- docs - Updated Doxygen documentation for v2.1.0 using Doxygen v1.8.18
- Doxyfile - Project version to v2.1.0 and other adjustments for Doxygen version v1.8.18
- LICENSE - Copyright years up 2020
- makefile - Copyright years up 2020
- LICENSE - Copyright years up to 2020
- makefile - Copyright years up to 2020
- makefile - Updated how the underlying compiler is detected now using 'mpicxx -show'
- Object - Copyright years up to 2020
- Object - Updated calculateDisplacement method to calculate net displacement when specifying a direction instead of the absolute displacement
- README.md - Latest stable release version to v2.1.0
- README.md - Updated description of testing configurations
- Version - Copyright years up 2020
- test.cpp (CalculateDisplacementTests) - Updated tests to check for negative net displacement when specifying a direction
- Version - Copyright years up to 2020
- Version - Current version string to v2.1.0

### Removed
Expand Down
4 changes: 2 additions & 2 deletions docs/_object_8h_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<div class="title">Object.h</div> </div>
</div><!--header-->
<div class="contents">
<a href="_object_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">// Copyright (c) 2017-2019 Michael C. Heiber</span></div>
<a href="_object_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;<span class="comment">// Copyright (c) 2017-2020 Michael C. Heiber</span></div>
<div class="line"><a name="l00002"></a><span class="lineno"> 2</span>&#160;<span class="comment">// This source file is part of the KMC_Lattice project, which is subject to the MIT License.</span></div>
<div class="line"><a name="l00003"></a><span class="lineno"> 3</span>&#160;<span class="comment">// For more information, see the LICENSE file that accompanies this software.</span></div>
<div class="line"><a name="l00004"></a><span class="lineno"> 4</span>&#160;<span class="comment">// The KMC_Lattice project can be found on Github at https://github.com/MikeHeiber/KMC_Lattice</span></div>
Expand Down Expand Up @@ -156,7 +156,7 @@
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="aclass_k_m_c___lattice_1_1_object_html_a7d3cf585bb696b0a550ca3ba19891dd3"><div class="ttname"><a href="class_k_m_c___lattice_1_1_object.html#a7d3cf585bb696b0a550ca3ba19891dd3">KMC_Lattice::Object::getObjectType</a></div><div class="ttdeci">virtual std::string getObjectType() const</div><div class="ttdoc">Gets the name of the Object class.</div><div class="ttdef"><b>Definition:</b> Object.cpp:56</div></div>
<div class="ttc" id="aclass_k_m_c___lattice_1_1_object_html_a1831d9ef4058f8605c630cf68fc36b68"><div class="ttname"><a href="class_k_m_c___lattice_1_1_object.html#a1831d9ef4058f8605c630cf68fc36b68">KMC_Lattice::Object::calculateDisplacement</a></div><div class="ttdeci">double calculateDisplacement(const int direction=0) const</div><div class="ttdoc">Calculates the absolute displacement of the object from its starting coordinates in lattice units.</div><div class="ttdef"><b>Definition:</b> Object.cpp:29</div></div>
<div class="ttc" id="aclass_k_m_c___lattice_1_1_object_html_a1831d9ef4058f8605c630cf68fc36b68"><div class="ttname"><a href="class_k_m_c___lattice_1_1_object.html#a1831d9ef4058f8605c630cf68fc36b68">KMC_Lattice::Object::calculateDisplacement</a></div><div class="ttdeci">double calculateDisplacement(const int direction=0) const</div><div class="ttdoc">Calculates the displacement of the object from its starting coordinates in lattice units.</div><div class="ttdef"><b>Definition:</b> Object.cpp:29</div></div>
<div class="ttc" id="aclass_k_m_c___lattice_1_1_object_html_a3d2c9e1ec9c369bd99d65d3b56d7329d"><div class="ttname"><a href="class_k_m_c___lattice_1_1_object.html#a3d2c9e1ec9c369bd99d65d3b56d7329d">KMC_Lattice::Object::incrementDZ</a></div><div class="ttdeci">void incrementDZ(const int num)</div><div class="ttdoc">Increments the dz parameter, which is to be used when the Object crosses a z-direction periodic bound...</div><div class="ttdef"><b>Definition:</b> Object.cpp:72</div></div>
<div class="ttc" id="a_utils_8h_html"><div class="ttname"><a href="_utils_8h.html">Utils.h</a></div></div>
<div class="ttc" id="aclass_k_m_c___lattice_1_1_object_html_aefef862e9b7d6664f49c0187743dc757"><div class="ttname"><a href="class_k_m_c___lattice_1_1_object.html#aefef862e9b7d6664f49c0187743dc757">KMC_Lattice::Object::Object</a></div><div class="ttdeci">Object()</div><div class="ttdoc">Default constructor that creates an empty Object object.</div><div class="ttdef"><b>Definition:</b> Object.cpp:18</div></div>
Expand Down
8 changes: 4 additions & 4 deletions docs/class_k_m_c___lattice_1_1_object.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<tr class="memdesc:a3cc5166f14876fb0a6ceebbdd19d5b40"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructor that creates and initializes a usable <a class="el" href="class_k_m_c___lattice_1_1_object.html" title="This base class contains the basic properties of a KMC simulation object and the functions needed to ...">Object</a> object. <a href="class_k_m_c___lattice_1_1_object.html#a3cc5166f14876fb0a6ceebbdd19d5b40">More...</a><br /></td></tr>
<tr class="separator:a3cc5166f14876fb0a6ceebbdd19d5b40"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1831d9ef4058f8605c630cf68fc36b68"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_k_m_c___lattice_1_1_object.html#a1831d9ef4058f8605c630cf68fc36b68">calculateDisplacement</a> (const int direction=0) const</td></tr>
<tr class="memdesc:a1831d9ef4058f8605c630cf68fc36b68"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the absolute displacement of the object from its starting coordinates in lattice units. <a href="class_k_m_c___lattice_1_1_object.html#a1831d9ef4058f8605c630cf68fc36b68">More...</a><br /></td></tr>
<tr class="memdesc:a1831d9ef4058f8605c630cf68fc36b68"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the displacement of the object from its starting coordinates in lattice units. <a href="class_k_m_c___lattice_1_1_object.html#a1831d9ef4058f8605c630cf68fc36b68">More...</a><br /></td></tr>
<tr class="separator:a1831d9ef4058f8605c630cf68fc36b68"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a83a7bab6def0127d9a9a867a5f7f7ca8"><td class="memItemLeft" align="right" valign="top"><a class="el" href="struct_k_m_c___lattice_1_1_coords.html">Coords</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_k_m_c___lattice_1_1_object.html#a83a7bab6def0127d9a9a867a5f7f7ca8">getCoords</a> () const</td></tr>
<tr class="memdesc:a83a7bab6def0127d9a9a867a5f7f7ca8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Gets the current coordinates of the <a class="el" href="class_k_m_c___lattice_1_1_object.html" title="This base class contains the basic properties of a KMC simulation object and the functions needed to ...">Object</a>. <a href="class_k_m_c___lattice_1_1_object.html#a83a7bab6def0127d9a9a867a5f7f7ca8">More...</a><br /></td></tr>
Expand Down Expand Up @@ -148,7 +148,7 @@
<div class="textblock"><p>This base class contains the basic properties of a KMC simulation object and the functions needed to interact with it. </p>
<p>This base class is designed to work with the <a class="el" href="class_k_m_c___lattice_1_1_simulation.html" title="This abstract base class contains the basic properties of a KMC simulation and the functions needed t...">Simulation</a> class to construct a KMC simulation. This base class is intended to be extended to create classes that represent specific types of objects. </p><dl class="section copyright"><dt>Copyright</dt><dd>MIT License. For more information, see the LICENSE file that accompanies this software package. </dd></dl>
<dl class="section author"><dt>Author</dt><dd>Michael C. Heiber </dd></dl>
<dl class="section date"><dt>Date</dt><dd>2017-2019 </dd></dl>
<dl class="section date"><dt>Date</dt><dd>2017-2020 </dd></dl>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a2f950c46bb2903eda745a8082dee201e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2f950c46bb2903eda745a8082dee201e">&#9670;&nbsp;</a></span>~Object()</h2>
Expand Down Expand Up @@ -257,10 +257,10 @@ <h2 class="memtitle"><span class="permalink"><a href="#a1831d9ef4058f8605c630cf6
</table>
</div><div class="memdoc">

<p>Calculates the absolute displacement of the object from its starting coordinates in lattice units. </p>
<p>Calculates the displacement of the object from its starting coordinates in lattice units. </p>
<p>The function accounts for when periodic boundaries are crossed to determine the real displacement distance. </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">direction</td><td>is an optional parameter that specifies whether the displacement only along a particular Cartesian direction should be calculated. When direction is not set, the default three-dimensional displacement is calculated, but when set to 1, 2, or 3, the function calculates the displacement only in the x-, y-, and z-directions, respectively. </td></tr>
<tr><td class="paramname">direction</td><td>is an optional parameter that specifies whether the displacement only along a particular Cartesian direction should be calculated. When direction is not set, the default three-dimensional absolute displacement is calculated, but when set to 1, 2, or 3, the function calculates the net displacement only in the x-, y-, and z-directions, respectively. </td></tr>
</table>
</dd>
</dl>
Expand Down
8 changes: 4 additions & 4 deletions src/Object.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2019 Michael C. Heiber
// Copyright (c) 2017-2020 Michael C. Heiber
// This source file is part of the KMC_Lattice project, which is subject to the MIT License.
// For more information, see the LICENSE file that accompanies this software.
// The KMC_Lattice project can be found on Github at https://github.com/MikeHeiber/KMC_Lattice
Expand Down Expand Up @@ -31,11 +31,11 @@ namespace KMC_Lattice {
case 0:
return sqrt((coords_current.x + dx - coords_initial.x)*(coords_current.x + dx - coords_initial.x) + (coords_current.y + dy - coords_initial.y)*(coords_current.y + dy - coords_initial.y) + (coords_current.z + dz - coords_initial.z)*(coords_current.z + dz - coords_initial.z));
case 1:
return abs(coords_current.x + dx - coords_initial.x);
return coords_current.x + dx - coords_initial.x;
case 2:
return abs(coords_current.y + dy - coords_initial.y);
return coords_current.y + dy - coords_initial.y;
case 3:
return abs(coords_current.z + dz - coords_initial.z);
return coords_current.z + dz - coords_initial.z;
default:
throw invalid_argument("Error! Specified direction input parameter is invalid.");
}
Expand Down
8 changes: 4 additions & 4 deletions src/Object.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2019 Michael C. Heiber
// Copyright (c) 2017-2020 Michael C. Heiber
// This source file is part of the KMC_Lattice project, which is subject to the MIT License.
// For more information, see the LICENSE file that accompanies this software.
// The KMC_Lattice project can be found on Github at https://github.com/MikeHeiber/KMC_Lattice
Expand All @@ -20,7 +20,7 @@ namespace KMC_Lattice {
//! base class is intended to be extended to create classes that represent specific types of objects.
//! \copyright MIT License. For more information, see the LICENSE file that accompanies this software package.
//! \author Michael C. Heiber
//! \date 2017-2019
//! \date 2017-2020
class Object {
public:
//! Default virtual destructor needed by the base class.
Expand All @@ -35,11 +35,11 @@ namespace KMC_Lattice {
//! \param start_coords is the Coords struct that defines the starting coordinates of the Object.
Object(const double time, const int tag_num, const Coords& start_coords);

//! \brief Calculates the absolute displacement of the object from its starting coordinates in lattice units.
//! \brief Calculates the displacement of the object from its starting coordinates in lattice units.
//! \details The function accounts for when periodic boundaries are crossed to determine the real
//! displacement distance.
//! \param direction is an optional parameter that specifies whether the displacement only along a particular Cartesian direction should be calculated.
//! When direction is not set, the default three-dimensional displacement is calculated, but when set to 1, 2, or 3, the function calculates the displacement
//! When direction is not set, the default three-dimensional absolute displacement is calculated, but when set to 1, 2, or 3, the function calculates the net displacement
//! only in the x-, y-, and z-directions, respectively.
double calculateDisplacement(const int direction = 0) const;

Expand Down
20 changes: 10 additions & 10 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2019 Michael C. Heiber
// Copyright (c) 2017-2020 Michael C. Heiber
// This source file is part of the KMC_Lattice project, which is subject to the MIT License.
// For more information, see the LICENSE file that accompanies this software.
// The KMC_Lattice project can be found on Github at https://github.com/MikeHeiber/KMC_Lattice
Expand Down Expand Up @@ -1555,29 +1555,29 @@ namespace ObjectTests {
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(0));
EXPECT_DOUBLE_EQ(0.0, object1.calculateDisplacement(1));
EXPECT_DOUBLE_EQ(0.0, object1.calculateDisplacement(2));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(3));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(3));
object1.setCoords({ 49,49,49 });
object1.incrementDX(-50);
object1.incrementDY(-50);
EXPECT_DOUBLE_EQ(sqrt(3), object1.calculateDisplacement());
EXPECT_DOUBLE_EQ(sqrt(3), object1.calculateDisplacement(0));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(1));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(2));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(3));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(1));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(2));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(3));
object1.setCoords({ 49,0,49 });
object1.incrementDY(50);
EXPECT_DOUBLE_EQ(sqrt(2), object1.calculateDisplacement());
EXPECT_DOUBLE_EQ(sqrt(2), object1.calculateDisplacement(0));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(1));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(1));
EXPECT_DOUBLE_EQ(0.0, object1.calculateDisplacement(2));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(3));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(3));
object1.resetInitialCoords({ 5,5,5 });
object1.setCoords({ 4,4,4 });
EXPECT_DOUBLE_EQ(sqrt(3), object1.calculateDisplacement());
EXPECT_DOUBLE_EQ(sqrt(3), object1.calculateDisplacement(0));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(1));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(2));
EXPECT_DOUBLE_EQ(1.0, object1.calculateDisplacement(3));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(1));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(2));
EXPECT_DOUBLE_EQ(-1.0, object1.calculateDisplacement(3));
// Check invalid direction parameter usage
EXPECT_THROW(object1.calculateDisplacement(4), invalid_argument);
}
Expand Down

0 comments on commit 27e02c6

Please sign in to comment.