Skip to content

Commit

Permalink
Refactor System class (#4816)
Browse files Browse the repository at this point in the history
Description of changes:
- encapsulate several global variables inside the `System` class
   - new members: cell_system, integrator, electrostatics, magnetostatics, analysis, comfixed, galilei, bond_breakage
   - required for #4613
   - partial fix for #2628
- make energy/pressure/force calculation functions members of the `System` class
- fully encapsulate event hooks in the `System` class
- simplify checkpointing of the `System` class
- remove `EspressoSystemStandAlone` class
- API changes:
   - `espressomd.galilei.GalileiTransform` is now a member of the `System` class, accessible via `system.galilei`
  • Loading branch information
kodiakhq[bot] authored Nov 20, 2023
2 parents cb3c23c + 7c3efae commit 38a5338
Show file tree
Hide file tree
Showing 285 changed files with 4,219 additions and 4,135 deletions.
4 changes: 2 additions & 2 deletions doc/doxygen/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ EXTRACT_PRIVATE = NO
# methods of a class will be included in the documentation.
# The default value is: NO.

EXTRACT_PRIV_VIRTUAL = NO
EXTRACT_PRIV_VIRTUAL = YES

# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
# scope will be included in the documentation.
Expand All @@ -468,7 +468,7 @@ EXTRACT_STATIC = YES
# for Java sources.
# The default value is: YES.

EXTRACT_LOCAL_CLASSES = NO
EXTRACT_LOCAL_CLASSES = YES

# This flag is only useful for Objective-C code. If set to YES, local methods,
# which are defined in the implementation section but not in the interface are
Expand Down
7 changes: 1 addition & 6 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ add_library(
dpd.cpp
energy.cpp
errorhandling.cpp
forcecap.cpp
forces.cpp
ghosts.cpp
global_ghost_flags.cpp
immersed_boundaries.cpp
interactions.cpp
event.cpp
integrate.cpp
npt.cpp
partCfg_global.cpp
particle_node.cpp
polymer.cpp
pressure.cpp
rattle.cpp
rotate_system.cpp
rotation.cpp
Observable_stat.cpp
thermostat.cpp
Expand All @@ -53,7 +49,6 @@ add_library(
system/GpuParticleData.cpp
system/System.cpp
PartCfg.cpp
EspressoSystemStandAlone.cpp
TabulatedPotential.cpp)
add_library(espresso::core ALIAS espresso_core)
set_target_properties(espresso_core PROPERTIES CXX_CLANG_TIDY
Expand Down
76 changes: 0 additions & 76 deletions src/core/EspressoSystemStandAlone.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions src/core/EspressoSystemStandAlone.hpp

This file was deleted.

3 changes: 1 addition & 2 deletions src/core/LocalBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class LocalBox {
boundaries[2u * dir + 1u] = -(node_index[dir] + 1 == node_grid[dir]);
}

return {my_left, local_length, boundaries,
CellStructureType::CELL_STRUCTURE_REGULAR};
return {my_left, local_length, boundaries, CellStructureType::REGULAR};
}
};
22 changes: 8 additions & 14 deletions src/core/Observable_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

#include "config/config.hpp"

#include "bonded_interactions/bonded_interaction_data.hpp"
#include "communication.hpp"
#include "nonbonded_interactions/nonbonded_interaction_data.hpp"

#include <utils/Span.hpp>
#include <utils/index.hpp>
Expand All @@ -37,13 +35,9 @@
#include <functional>
#include <vector>

static auto max_non_bonded_pairs() {
auto const n = static_cast<std::size_t>(max_seen_particle_type);
return (n * (n + 1)) / 2;
}

Observable_stat::Observable_stat(std::size_t chunk_size)
: m_chunk_size(chunk_size) {
Observable_stat::Observable_stat(std::size_t chunk_size, std::size_t n_bonded,
int max_type)
: m_data{}, m_chunk_size{chunk_size} {
// number of chunks for different interaction types
constexpr std::size_t n_coulomb = 2;
constexpr std::size_t n_dipolar = 2;
Expand All @@ -52,9 +46,9 @@ Observable_stat::Observable_stat(std::size_t chunk_size)
#else
constexpr std::size_t n_vs = 0;
#endif
auto const n_bonded =
static_cast<std::size_t>(bonded_ia_params.get_next_key());
auto const n_non_bonded = max_non_bonded_pairs();
auto const n_non_bonded =
static_cast<std::size_t>(Utils::lower_triangular(max_type, max_type)) +
1ul;
constexpr std::size_t n_ext_fields = 1; // reduction over all fields
constexpr std::size_t n_kinetic = 1; // linear+angular kinetic contributions

Expand All @@ -80,8 +74,8 @@ Observable_stat::Observable_stat(std::size_t chunk_size)
Utils::Span<double>
Observable_stat::get_non_bonded_contribution(Utils::Span<double> base_pointer,
int type1, int type2) const {
auto const offset = static_cast<std::size_t>(Utils::upper_triangular(
std::min(type1, type2), std::max(type1, type2), max_seen_particle_type));
auto const offset = static_cast<std::size_t>(
Utils::lower_triangular(std::max(type1, type2), std::min(type1, type2)));
return {base_pointer.begin() + offset * m_chunk_size, m_chunk_size};
}

Expand Down
8 changes: 3 additions & 5 deletions src/core/Observable_stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ESPRESSO_OBSERVABLE_STAT_HPP
#define ESPRESSO_OBSERVABLE_STAT_HPP

#pragma once

#include <boost/range/algorithm/transform.hpp>
#include <boost/range/numeric.hpp>
Expand All @@ -43,7 +43,7 @@ class Observable_stat {
int type2) const;

public:
explicit Observable_stat(std::size_t chunk_size);
Observable_stat(std::size_t chunk_size, std::size_t n_bonded, int max_type);

auto get_chunk_size() const { return m_chunk_size; }

Expand Down Expand Up @@ -121,5 +121,3 @@ class Observable_stat {
/** MPI reduction. */
void mpi_reduce();
};

#endif // ESPRESSO_OBSERVABLE_STAT_HPP
9 changes: 1 addition & 8 deletions src/core/PartCfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
#include <cstddef>

void PartCfg::update() {
if (m_valid)
return;

auto const &box_geo = *System::get_system().box_geo;

m_parts.clear();

auto const ids = get_particle_ids();
Expand All @@ -51,12 +46,10 @@ void PartCfg::update() {
m_parts.push_back(get_particle_data(id));

auto &p = m_parts.back();
p.pos() += box_geo.image_shift(p.image_box());
p.pos() += m_box_geo.image_shift(p.image_box());
p.image_box() = {};
}

offset += this_size;
}

m_valid = true;
}
Loading

0 comments on commit 38a5338

Please sign in to comment.