Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always define q #2266

Merged
merged 4 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/core/particle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ int set_particle_q(int part, double q) {
mpi_send_q(pnode, part, q);
return ES_OK;
}
#ifndef ELECTROSTATICS
constexpr double ParticleProperties::q;
#endif

#ifdef LB_ELECTROHYDRODYNAMICS
int set_particle_mu_E(int part, double mu_E[3]) {
Expand Down Expand Up @@ -1247,9 +1250,7 @@ void pointer_to_quatu(Particle const *p, double const *&res) {
}
#endif

#ifdef ELECTROSTATICS
void pointer_to_q(Particle const *p, double const *&res) { res = &(p->p.q); }
#endif

#ifdef VIRTUAL_SITES
void pointer_to_virtual(Particle const *p, int const *&res) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/particle_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ struct ParticleProperties {
// integrated
short int rotation = 0;

#ifdef ELECTROSTATICS
/** charge. */
#ifdef ELECTROSTATICS
double q = 0.0;
#else
constexpr static double q{0.0};
#endif

#ifdef LB_ELECTROHYDRODYNAMICS
Expand Down Expand Up @@ -991,9 +993,7 @@ void pointer_to_quatu(Particle const *p, double const *&res);

#endif

#ifdef ELECTROSTATICS
void pointer_to_q(Particle const *p, double const *&res);
#endif

#ifdef VIRTUAL_SITES
void pointer_to_virtual(Particle const *p, int const *&res);
Expand Down
6 changes: 2 additions & 4 deletions src/python/espressomd/particle_data.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ cdef extern from "particle_data.hpp":
int set_particle_rotation(int part, int rot)
void pointer_to_rotation(const particle * p, const short int * & res)

IF ELECTROSTATICS:
int set_particle_q(int part, double q)
int set_particle_q(int part, double q)

IF LB_ELECTROHYDRODYNAMICS:
int set_particle_mu_E(int part, double mu_E[3])
Expand Down Expand Up @@ -178,8 +177,7 @@ cdef extern from "particle_data.hpp":
int set_particle_vs_relative(int part, int vs_relative_to, double vs_distance, double * rel_ori)
void set_particle_vs_quat(int part, double * vs_quat)

IF ELECTROSTATICS:
void pointer_to_q(const particle * P, const double * & res)
void pointer_to_q(const particle * P, const double * & res)

IF EXTERNAL_FORCES:
IF ROTATION:
Expand Down
39 changes: 19 additions & 20 deletions src/python/espressomd/particle_data.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -609,31 +609,30 @@ cdef class ParticleHandle(object):


# Charge
IF ELECTROSTATICS:
property q:
"""
Particle charge.
property q:
"""
Particle charge.

q : :obj:`float`
q : :obj:`float`

.. note::
This needs the feature ELECTROSTATICS.
.. note::
This needs the feature ELECTROSTATICS.

"""
"""

def __set__(self, _q):
cdef double myq
check_type_or_throw_except(
_q, 1, float, "Charge has to be floats.")
myq = _q
if set_particle_q(self._id, myq) == 1:
raise Exception("Set particle position first.")
def __set__(self, _q):
cdef double myq
check_type_or_throw_except(
_q, 1, float, "Charge has to be floats.")
myq = _q
if set_particle_q(self._id, myq) == 1:
raise Exception("Set particle position first.")

def __get__(self):
self.update_particle_data()
cdef const double * x = NULL
pointer_to_q(self.particle_data, x)
return x[0]
def __get__(self):
self.update_particle_data()
cdef const double * x = NULL
pointer_to_q(self.particle_data, x)
return x[0]

IF LB_ELECTROHYDRODYNAMICS:
property mu_E:
Expand Down