Skip to content

Commit a36fbbe

Browse files
committed
Refactoring
Roll out C++20 features. Update headers with include-what-you-use. Remove a few static variables. Avoid uses of non-qualified size_t. Use east const and pragma once more often. Cleanup Doxygen blocks. Remove utility functions when the STL provides alternatives.
1 parent d74714f commit a36fbbe

File tree

118 files changed

+343
-497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+343
-497
lines changed

maintainer/CI/build_cmake.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ if [ "${with_coverage}" = true ] || [ "${with_coverage_python}" = true ]; then
386386
echo "Running lcov and gcov..."
387387
codecov_opts="${codecov_opts} --gcov"
388388
"${srcdir}/maintainer/CI/run_lcov.sh" coverage.info
389-
rm coverage.info
390389
fi
391390
if [ "${with_coverage_python}" = true ]; then
392391
echo "Running python3-coverage..."

src/core/BoxGeometry.hpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "lees_edwards/LeesEdwardsBC.hpp"
2424

2525
#include <utils/Vector.hpp>
26-
#include <utils/math/sgn.hpp>
2726

2827
#include <bitset>
2928
#include <cassert>
@@ -176,6 +175,7 @@ class BoxGeometry {
176175
* @param box_l Length that should be set.
177176
*/
178177
void set_length(Utils::Vector3d const &box_l) {
178+
assert(box_l > Utils::Vector3d::broadcast(0.));
179179
m_length = box_l;
180180
m_length_inv = {1. / box_l[0], 1. / box_l[1], 1. / box_l[2]};
181181
m_length_half = 0.5 * box_l;
@@ -213,9 +213,8 @@ class BoxGeometry {
213213
* periodic images, i.e. <tt>a - b</tt>.
214214
*/
215215
template <typename T>
216-
ESPRESSO_ATTR_ALWAYS_INLINE inline Utils::Vector<T, 3>
217-
get_mi_vector(const Utils::Vector<T, 3> &a,
218-
const Utils::Vector<T, 3> &b) const {
216+
ESPRESSO_ATTR_ALWAYS_INLINE inline Utils::Vector3<T>
217+
get_mi_vector(Utils::Vector3<T> const &a, Utils::Vector3<T> const &b) const {
219218
if (type() == BoxType::LEES_EDWARDS) {
220219
auto const shear_plane_normal = lees_edwards_bc().shear_plane_normal;
221220
auto a_tmp = a;
@@ -228,8 +227,8 @@ class BoxGeometry {
228227
m_length_inv, m_periodic);
229228
}
230229
assert(type() == BoxType::CUBOID);
231-
return {get_mi_coord(a[0], b[0], 0), get_mi_coord(a[1], b[1], 1),
232-
get_mi_coord(a[2], b[2], 2)};
230+
return {get_mi_coord(a[0], b[0], 0u), get_mi_coord(a[1], b[1], 1u),
231+
get_mi_coord(a[2], b[2], 2u)};
233232
}
234233

235234
/**
@@ -247,13 +246,13 @@ class BoxGeometry {
247246
* periodic images, i.e. <tt>a - b</tt>.
248247
*/
249248
template <typename T>
250-
ESPRESSO_ATTR_ALWAYS_INLINE inline Utils::Vector<T, 3>
249+
ESPRESSO_ATTR_ALWAYS_INLINE inline Utils::Vector3<T>
251250
get_mi_vector(T const &a0, T const &a1, T const &a2, T const &b0, T const &b1,
252251
T const &b2) const {
253252
if (type() == BoxType::LEES_EDWARDS) {
254253
auto const shear_plane_normal = lees_edwards_bc().shear_plane_normal;
255-
auto a_tmp = Utils::Vector<T, 3>{a0, a1, a2};
256-
auto b_tmp = Utils::Vector<T, 3>{b0, b1, b2};
254+
auto a_tmp = Utils::Vector3<T>{a0, a1, a2};
255+
auto b_tmp = Utils::Vector3<T>{b0, b1, b2};
257256
a_tmp[shear_plane_normal] = Algorithm::periodic_fold(
258257
a_tmp[shear_plane_normal], m_length[shear_plane_normal]);
259258
b_tmp[shear_plane_normal] = Algorithm::periodic_fold(
@@ -262,8 +261,8 @@ class BoxGeometry {
262261
m_length_inv, m_periodic);
263262
}
264263
assert(type() == BoxType::CUBOID);
265-
return {get_mi_coord(a0, b0, 0), get_mi_coord(a1, b1, 1),
266-
get_mi_coord(a2, b2, 2)};
264+
return {get_mi_coord(a0, b0, 0u), get_mi_coord(a1, b1, 1u),
265+
get_mi_coord(a2, b2, 2u)};
267266
}
268267

269268
BoxType type() const { return m_type; }
@@ -293,8 +292,8 @@ class BoxGeometry {
293292
auto const shear_plane_normal = le.shear_plane_normal;
294293
auto const shear_direction = le.shear_direction;
295294
auto const dy = x[shear_plane_normal] - y[shear_plane_normal];
296-
if (fabs(dy) > length_half()[shear_plane_normal]) {
297-
ret[shear_direction] -= Utils::sgn(dy) * le.shear_velocity;
295+
if (std::fabs(dy) > length_half()[shear_plane_normal]) {
296+
ret[shear_direction] -= std::copysign(le.shear_velocity, dy);
298297
}
299298
}
300299
return ret;
@@ -329,7 +328,7 @@ class BoxGeometry {
329328
*/
330329
auto folded_position(Utils::Vector3d const &pos) const {
331330
auto pos_folded = pos;
332-
for (unsigned int i = 0u; i < 3u; i++) {
331+
for (auto i = 0u; i < 3u; i++) {
333332
if (m_periodic[i]) {
334333
pos_folded[i] = Algorithm::periodic_fold(pos[i], m_length[i]);
335334
}

src/core/Particle.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct ThermalStonerWohlfarthParameters {
7272
/** angle between the director and dipole moment of a Stoner-Wohlfarth
7373
* particle */
7474
double phi0 = 0.;
75-
/** saturation magnetisation of a polarisable particle */
75+
/** saturation magnetisation of a polarizable particle */
7676
double sat_mag = 0.;
7777
/**
7878
* @brief Inverse anisotropy field in reduced units.

src/core/accumulators/AutoUpdateAccumulators.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "system/Leaf.hpp"
2525

26+
#include <vector>
27+
2628
namespace Accumulators {
2729

2830
class AutoUpdateAccumulators : public System::Leaf<AutoUpdateAccumulators> {

src/core/analysis/statistics.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "Particle.hpp"
3131
#include "cell_system/CellStructure.hpp"
3232
#include "communication.hpp"
33-
#include "errorhandling.hpp"
34-
#include "npt.hpp"
3533
#include "particle_reduction.hpp"
3634
#include "system/System.hpp"
3735

@@ -49,7 +47,6 @@
4947
#include <functional>
5048
#include <limits>
5149
#include <numbers>
52-
#include <stdexcept>
5350
#include <tuple>
5451
#include <utility>
5552
#include <vector>

src/core/bond_breakage/bond_breakage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
#include <boost/mpi.hpp>
3232
#include <boost/serialization/access.hpp>
3333

34+
#include <algorithm>
3435
#include <cassert>
3536
#include <memory>
37+
#include <span>
3638
#include <unordered_set>
3739
#include <utility>
3840
#include <variant>

src/core/bond_breakage/bond_breakage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
namespace BondBreakage {
3333

34-
/** Stores one or two bond parnters for pair/angle bonds */
34+
/** Stores one or two bond partners for pair/angle bonds */
3535
using BondPartners = std::array<std::optional<int>, 2>;
3636

3737
enum class ActionType {

src/core/bond_error.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
* You should have received a copy of the GNU General Public License
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
21-
#ifndef ESPRESSO_BOND_ERROR_HPP
22-
#define ESPRESSO_BOND_ERROR_HPP
21+
22+
#pragma once
2323

2424
#include <exception>
2525
#include <span>
@@ -47,5 +47,3 @@ struct BondInvalidSizeError : std::exception {
4747

4848
int size;
4949
};
50-
51-
#endif // ESPRESSO_BOND_ERROR_HPP

src/core/bonded_interactions/bonded_interaction_data.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919

2020
#include "bonded_interaction_data.hpp"
2121

22-
#include "BoxGeometry.hpp"
23-
#include "cell_system/CellStructure.hpp"
2422
#include "immersed_boundary/ImmersedBoundaries.hpp"
2523
#include "rigid_bond.hpp"
2624
#include "system/System.hpp"
2725
#include "thermalized_bond.hpp"
28-
#include "thermostat.hpp"
2926

3027
#include <algorithm>
3128
#include <numeric>

src/core/bonded_interactions/bonded_interaction_data.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <config/config.hpp>
2828

29-
#include "angle_common.hpp"
3029
#include "angle_cosine.hpp"
3130
#include "angle_cossquare.hpp"
3231
#include "angle_harmonic.hpp"
@@ -46,17 +45,16 @@
4645
#include "thermalized_bond.hpp"
4746

4847
#include "BondList.hpp"
49-
#include "TabulatedPotential.hpp"
48+
#include "Particle.hpp"
5049
#include "system/Leaf.hpp"
5150

5251
#include <algorithm>
5352
#include <cassert>
5453
#include <cmath>
54+
#include <memory>
5555
#include <optional>
56-
#include <stdexcept>
5756
#include <unordered_map>
5857
#include <variant>
59-
#include <vector>
6058

6159
/** Interaction type for unused bonded interaction slots */
6260
struct NoneBond {
@@ -129,7 +127,7 @@ class BondedInteractionsMap : public System::Leaf<BondedInteractionsMap> {
129127
}
130128
virtual void activate_bond(mapped_type const &ptr);
131129
virtual void deactivate_bond(mapped_type const &ptr);
132-
mapped_type at(key_type const &key) const { return m_params.at(key); }
130+
mapped_type const &at(key_type const &key) const { return m_params.at(key); }
133131
bool contains(key_type const &key) const { return m_params.contains(key); }
134132
bool empty() const { return m_params.empty(); }
135133
auto size() const { return m_params.size(); }

0 commit comments

Comments
 (0)