diff --git a/cmake/version.cmake b/cmake/version.cmake index a630119b2d9..175632e978f 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -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) diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt index dd34cb4b971..e86f46f4424 100644 --- a/src/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -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) diff --git a/src/config/config.hpp b/src/config/config.hpp index 79f1084bcf1..130e29d5cbb 100644 --- a/src/config/config.hpp +++ b/src/config/config.hpp @@ -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. */ diff --git a/src/config/version.hpp.in b/src/config/version.hpp.in index dc922562f97..22923ab7f08 100644 --- a/src/config/version.hpp.in +++ b/src/config/version.hpp.in @@ -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@" diff --git a/src/core/Particle.hpp b/src/core/Particle.hpp index 12484af8f03..74465f05093 100644 --- a/src/core/Particle.hpp +++ b/src/core/Particle.hpp @@ -25,6 +25,15 @@ #include #include +#include + +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 @@ -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.}; @@ -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 @@ -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 diff --git a/src/core/io/writer/h5md_core.cpp b/src/core/io/writer/h5md_core.cpp index 3b9326db3db..97ef8a2ae8a 100644 --- a/src/core/io/writer/h5md_core.cpp +++ b/src/core/io/writer/h5md_core.cpp @@ -24,6 +24,7 @@ #include "communication.hpp" #include "grid.hpp" #include "integrate.hpp" +#include "version.hpp" #include diff --git a/src/core/particle_data.cpp b/src/core/particle_data.cpp index b2b25d8a1a4..0f48c9b1192 100644 --- a/src/core/particle_data.cpp +++ b/src/core/particle_data.cpp @@ -137,7 +137,9 @@ using UpdatePropertyMessage = boost::variant #ifdef MEMBRANE_COLLISION , UpdateProperty #endif - , UpdateProperty +#ifdef ROTATION + , UpdateProperty +#endif #ifdef ELECTROSTATICS , UpdateProperty #endif @@ -166,7 +168,7 @@ using UpdatePropertyMessage = boost::variant , UpdateProperty #else , UpdateProperty -#endif // ROTATIONAL_INERTIA +#endif // PARTICLE_ANISOTROPY #endif // ROTATION #endif // LANGEVIN_PER_PARTICLE #ifdef EXTERNAL_FORCES @@ -842,7 +844,8 @@ constexpr Utils::Vector3d ParticleProperties::rinertia; #endif #ifdef ROTATION void set_particle_rotation(int part, int rot) { - mpi_update_particle_property(part, rot); + mpi_update_particle_property(part, + rot); } #endif #ifdef ROTATION @@ -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) { diff --git a/src/core/particle_data.hpp b/src/core/particle_data.hpp index 6122b68f726..c806bbdb96a 100644 --- a/src/core/particle_data.hpp +++ b/src/core/particle_data.hpp @@ -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 diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 777a8895e69..d6c2a0886ec 100644 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -33,10 +33,6 @@ #include #include -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); diff --git a/src/python/espressomd/particle_data.pxd b/src/python/espressomd/particle_data.pxd index cf909a42a88..ef9bffb5b46 100644 --- a/src/python/espressomd/particle_data.pxd +++ b/src/python/espressomd/particle_data.pxd @@ -23,6 +23,7 @@ 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" @@ -30,6 +31,9 @@ include "myconfig.pxi" 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. @@ -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 @@ -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) diff --git a/src/python/espressomd/particle_data.pyx b/src/python/espressomd/particle_data.pyx index 1b76dc8b94d..97654dbb9e5 100644 --- a/src/python/espressomd/particle_data.pyx +++ b/src/python/espressomd/particle_data.pyx @@ -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 @@ -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) diff --git a/src/python/espressomd/version.pyx b/src/python/espressomd/version.pyx index 7be8aad623a..77d2af070b7 100644 --- a/src/python/espressomd/version.pyx +++ b/src/python/espressomd/version.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from espressomd.utils import to_str + def major(): """Prints the major version of Espresso. @@ -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(): @@ -54,4 +56,4 @@ def git_state(): was not changed from git_commit(), "DIRTY" otherwise. """ - return GIT_STATE + return to_str(GIT_STATE)