Skip to content

Commit

Permalink
Merge #3259 #3263
Browse files Browse the repository at this point in the history
3259: cmake: generate version.hpp at compile time to avoid rebuilds r=fweik a=junghans

Make version.hpp a proper target. This prevents CMake from rebuilding all source files when a minor change is introduced anywhere in the docs, tests, or CMakeLists.txt files. Significantly reduce the number of source files including version.hpp to limit the number of objects to rebuild when the commit or branch changes.

3263: Clean up rotation flags r=jngrad a=fweik

Description of changes:
 - Single source of truth for the rotation flags
 - Turned them into enum
 - Appropriate type
 - Made `ParticleProperties::rotation` exist idependent of features


Co-authored-by: Christoph Junghans <[email protected]>
Co-authored-by: Kai Szuttor <[email protected]>
Co-authored-by: Christoph Junghans <[email protected]>
Co-authored-by: Jean-Noël Grad <[email protected]>
Co-authored-by: Florian Weik <[email protected]>
  • Loading branch information
6 people authored Oct 18, 2019
3 parents b2b3aed + 62785c5 + e2945b3 commit 0446313
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 67 deletions.
57 changes: 30 additions & 27 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
find_package(Git)

if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_EXECUTABLE)
# Get the name of the working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
OUTPUT_STRIP_TRAILING_WHITESPACE
# Get branch status
execute_process(
COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD --
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
RESULT_VARIABLE GIT_DIFF_INDEX_RESULT
OUTPUT_VARIABLE GIT_DIFF_INDEX_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_DIFF_INDEX_RESULT EQUAL 0)
set(GIT_STATE "CLEAN")
else()
set(GIT_STATE "DIRTY")
endif()

endif(GIT_EXECUTABLE)

if(res EQUAL 0)
set(GIT_STATE "CLEAN")
else()
set(GIT_STATE "DIRTY")
endif()
endif()
configure_file(${PROJECT_SOURCE_DIR}/src/config/version.hpp.in version.hpp.tmp)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different version.hpp.tmp version.hpp)
15 changes: 9 additions & 6 deletions src/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ add_dependencies(EspressoConfig myconfig check_myconfig generate_config_features
install(TARGETS EspressoConfig LIBRARY DESTINATION ${PYTHON_INSTDIR}/espressomd)
target_include_directories(EspressoConfig PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

find_package(Git)
# Parse repository info from git if available
include(version)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/version.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/version.hpp
)
# Run this at build time to avoid rebuilds
add_custom_target(version COMMAND ${CMAKE_COMMAND}
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-DPROJECT_VERSION=${PROJECT_VERSION}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-P ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES version.hpp version.hpp.tmp)
add_dependencies(EspressoConfig version)
1 change: 0 additions & 1 deletion src/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#define MPICH_SKIP_MPICXX

#include "config-features.hpp"
#include "version.hpp"

/** P3M: Default for number of interpolation points of the charge
assignment function. */
Expand Down
4 changes: 2 additions & 2 deletions src/config/version.hpp.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef VERSION_HPP
#define VERSION_HPP

#define ESPRESSO_VERSION_MAJOR 5
#define ESPRESSO_VERSION_MINOR 0
#define ESPRESSO_VERSION_MAJOR 4
#define ESPRESSO_VERSION_MINOR 2
#define ESPRESSO_VERSION "@PROJECT_VERSION@"
#define GIT_BRANCH "@GIT_BRANCH@"
#define GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"
Expand Down
19 changes: 16 additions & 3 deletions src/core/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
#include <utils/Vector.hpp>
#include <utils/math/quaternion.hpp>

#include <cstdint>

enum : uint8_t {
ROTATION_FIXED = 0u,
ROTATION_X = 1u,
ROTATION_Y = 2u,
ROTATION_Z = 4u
};

/** Properties of a particle which are not supposed to
* change during the integration, but have to be known
* for all ghosts. Ghosts are particles which are
Expand All @@ -46,8 +55,8 @@ struct ParticleProperties {
constexpr static double mass{1.0};
#endif /* MASS */

#ifdef ROTATIONAL_INERTIA
/** rotational inertia */
#ifdef ROTATIONAL_INERTIA
Utils::Vector3d rinertia = {1., 1., 1.};
#else
static constexpr Utils::Vector3d rinertia = {1., 1., 1.};
Expand All @@ -59,7 +68,11 @@ struct ParticleProperties {
#endif

/** bitfield for the particle axes of rotation */
int rotation = 0;
#ifdef ROTATION
uint8_t rotation = ROTATION_FIXED;
#else
static constexpr uint8_t rotation = ROTATION_FIXED;
#endif

/** charge. */
#ifdef ELECTROSTATICS
Expand Down Expand Up @@ -105,7 +118,7 @@ struct ParticleProperties {
} vs_relative;
#endif
#else /* VIRTUAL_SITES */
static constexpr const bool is_virtual = false;
static constexpr bool is_virtual = false;
#endif /* VIRTUAL_SITES */

#ifdef LANGEVIN_PER_PARTICLE
Expand Down
1 change: 1 addition & 0 deletions src/core/io/writer/h5md_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "communication.hpp"
#include "grid.hpp"
#include "integrate.hpp"
#include "version.hpp"

#include <vector>

Expand Down
13 changes: 6 additions & 7 deletions src/core/particle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ using UpdatePropertyMessage = boost::variant
#ifdef MEMBRANE_COLLISION
, UpdateProperty<Utils::Vector3d, &Prop::out_direction>
#endif
, UpdateProperty<int, &Prop::rotation>
#ifdef ROTATION
, UpdateProperty<uint8_t, &Prop::rotation>
#endif
#ifdef ELECTROSTATICS
, UpdateProperty<double, &Prop::q>
#endif
Expand Down Expand Up @@ -166,7 +168,7 @@ using UpdatePropertyMessage = boost::variant
, UpdateProperty<double, &Prop::gamma_rot>
#else
, UpdateProperty<Utils::Vector3d, &Prop::gamma_rot>
#endif // ROTATIONAL_INERTIA
#endif // PARTICLE_ANISOTROPY
#endif // ROTATION
#endif // LANGEVIN_PER_PARTICLE
#ifdef EXTERNAL_FORCES
Expand Down Expand Up @@ -842,7 +844,8 @@ constexpr Utils::Vector3d ParticleProperties::rinertia;
#endif
#ifdef ROTATION
void set_particle_rotation(int part, int rot) {
mpi_update_particle_property<int, &ParticleProperties::rotation>(part, rot);
mpi_update_particle_property<uint8_t, &ParticleProperties::rotation>(part,
rot);
}
#endif
#ifdef ROTATION
Expand Down Expand Up @@ -1550,10 +1553,6 @@ void pointer_to_temperature(Particle const *p, double const *&res) {
}
#endif // LANGEVIN_PER_PARTICLE

void pointer_to_rotation(Particle const *p, int const *&res) {
res = &(p->p.rotation);
}

#ifdef ENGINE
void pointer_to_swimming(Particle const *p,
ParticleParametersSwimming const *&swim) {
Expand Down
1 change: 0 additions & 1 deletion src/core/particle_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ void pointer_to_gamma_rot(Particle const *p, double const *&res);
#endif
#endif // LANGEVIN_PER_PARTICLE
#ifdef ROTATION
void pointer_to_rotation(Particle const *p, int const *&res);
#endif

#ifdef ENGINE
Expand Down
4 changes: 0 additions & 4 deletions src/core/rotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
#include <utils/Vector.hpp>
#include <utils/math/quaternion.hpp>

constexpr const int ROTATION_X = 2;
constexpr const int ROTATION_Y = 4;
constexpr const int ROTATION_Z = 8;

/** Propagate angular velocities and update quaternions on a particle */
void propagate_omega_quat_particle(Particle &p);

Expand Down
6 changes: 5 additions & 1 deletion src/python/espressomd/particle_data.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ from espressomd.utils cimport Vector4d, Vector3d, Vector3i, List, Span
from espressomd.utils import array_locked
from libcpp cimport bool
from libcpp.memory cimport unique_ptr
from libc cimport stdint

include "myconfig.pxi"

# Import particle data structures and setter functions from particle_data.hpp

cdef extern from "particle_data.hpp":
# DATA STRUCTURES
stdint.uint8_t ROTATION_X
stdint.uint8_t ROTATION_Y
stdint.uint8_t ROTATION_Z

# Note: Conditional compilation is not possible within ctypedef blocks.
# Therefore, only member variables are imported here, which are always compiled into Espresso.
Expand All @@ -40,6 +44,7 @@ cdef extern from "particle_data.hpp":
int mol_id
int type
double mass
stdint.uint8_t rotation

ctypedef struct particle_position "ParticlePosition":
Vector3d p
Expand Down Expand Up @@ -98,7 +103,6 @@ cdef extern from "particle_data.hpp":

IF ROTATION:
void set_particle_rotation(int part, int rot)
void pointer_to_rotation(const particle * p, const int * & res)

void set_particle_q(int part, double q)

Expand Down
20 changes: 8 additions & 12 deletions src/python/espressomd/particle_data.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ def _COORD_FIXED(coord):

COORDS_FIX_MASK = _COORD_FIXED(0) | _COORD_FIXED(1) | _COORD_FIXED(2)
PARTICLE_EXT_TORQUE = 16
ROT_X = 2
ROT_Y = 4
ROT_Z = 8

# List of particle attributes for pickle and the like
# Autogenerated from the class. Everything which is of the same
Expand Down Expand Up @@ -1060,24 +1057,23 @@ cdef class ParticleHandle:

rot = 0
if _rot[0]:
rot += ROT_X
rot += ROTATION_X
if _rot[1]:
rot += ROT_Y
rot += ROTATION_Y
if _rot[2]:
rot += ROT_Z
rot += ROTATION_Z
set_particle_rotation(self._id, rot)

def __get__(self):
self.update_particle_data()
cdef const int * _rot = NULL
pointer_to_rotation(self.particle_data, _rot)
rot = _rot[0]
rot = self.particle_data.p.rotation

res = np.zeros(3, dtype=int)
if rot & ROT_X:
if rot & ROTATION_X:
res[0] = 1
if rot & ROT_Y:
if rot & ROTATION_Y:
res[1] = 1
if rot & ROT_Z:
if rot & ROTATION_Z:
res[2] = 1
return array_locked(res)

Expand Down
8 changes: 5 additions & 3 deletions src/python/espressomd/version.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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/>.

from espressomd.utils import to_str


def major():
"""Prints the major version of Espresso.
Expand All @@ -38,14 +40,14 @@ def git_branch():
"""Git branch of the build if known, otherwise
empty.
"""
return GIT_BRANCH
return to_str(GIT_BRANCH)


def git_commit():
"""Git commit of the build if known, otherwise
empty.
"""
return GIT_COMMIT_HASH
return to_str(GIT_COMMIT_HASH)


def git_state():
Expand All @@ -54,4 +56,4 @@ def git_state():
was not changed from git_commit(), "DIRTY"
otherwise.
"""
return GIT_STATE
return to_str(GIT_STATE)

0 comments on commit 0446313

Please sign in to comment.