From 1ac37f9d3003e4a22dea1d9ca4543f5b99d8a29f Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Wed, 13 Sep 2017 01:22:00 +0300 Subject: [PATCH 001/150] Brownian Dynamics feature: core/python/test --- .travis.yml | 4 + maintainer/configs/maxset-bd.hpp | 85 +++++ src/core/integrate.cpp | 331 ++++++++++++++++- src/core/integrate.hpp | 1 - src/core/rotation.cpp | 343 +++++++++++++++++- src/core/rotation.hpp | 21 ++ src/core/thermostat.cpp | 104 +++++- src/core/thermostat.hpp | 1 + src/features.def | 1 + src/python/espressomd/thermostat.pxd | 1 + src/python/espressomd/thermostat.pyx | 85 +++-- testsuite/python/CMakeLists.txt | 1 + ...mass-and-rinertia-brownian_per_particle.py | 194 ++++++++++ 13 files changed, 1094 insertions(+), 78 deletions(-) create mode 100755 maintainer/configs/maxset-bd.hpp create mode 100644 testsuite/python/mass-and-rinertia-brownian_per_particle.py diff --git a/.travis.yml b/.travis.yml index d104c21a48b..e8f20551269 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,10 @@ matrix: sudo: required services: docker env: myconfig=maxset + - os: linux + sudo: required + services: docker + env: myconfig=maxset-bd - os: linux sudo: required services: docker diff --git a/maintainer/configs/maxset-bd.hpp b/maintainer/configs/maxset-bd.hpp new file mode 100755 index 00000000000..453fff89e81 --- /dev/null +++ b/maintainer/configs/maxset-bd.hpp @@ -0,0 +1,85 @@ +/* maximal set of features usable at the same time */ +#define PARTIAL_PERIODIC +#define ELECTROSTATICS +#define DIPOLES +#define ROTATION +#define ROTATIONAL_INERTIA +#define PARTICLE_ANISOTROPY +#define EXTERNAL_FORCES +#define CONSTRAINTS +#define MASS +#define EXCLUSIONS +#define COMFORCE +#define COMFIXED +#define MOLFORCES + +#ifdef FFTW +#define MODES +#endif + +#define BOND_VIRTUAL +#define COLLISION_DETECTION +#define LANGEVIN_PER_PARTICLE +#define ROTATION_PER_PARTICLE +#define CATALYTIC_REACTIONS +#define REACTION_ENSEMBLE + +#define NEMD +#define NPT +#define GHMC + +#define LB +#define LB_BOUNDARIES +#define LB_ELECTROHYDRODYNAMICS + +#define ENGINE +#define BROWNIAN_DYNAMICS + +#ifdef CUDA +#define LB_GPU +#define LB_BOUNDARIES_GPU +#define ELECTROKINETICS +#define EK_BOUNDARIES +#define EK_ELECTROSTATIC_COUPLING +#define MMM1D_GPU +#define EWALD_GPU +#endif + +#define AREA_FORCE_GLOBAL +#define VOLUME_FORCE + +#define TABULATED +#define LENNARD_JONES +#define LENNARD_JONES_GENERIC +#define LJGEN_SOFTCORE +#define LJCOS +#define LJCOS2 +#define GAUSSIAN +#define HAT +#define LJ_ANGLE +#define GAY_BERNE +#define SMOOTH_STEP +#define HERTZIAN +#define BMHTF_NACL +#define MORSE +#define BUCKINGHAM +#define SOFT_SPHERE +#define INTER_RF +#define OVERLAPPED + +#define TWIST_STACK +#define HYDROGEN_BOND + +#define BOND_ANGLE +#define BOND_ANGLEDIST +#define BOND_ANGLEDIST_HARMONIC +#define BOND_ENDANGLEDIST +#define BOND_ENDANGLEDIST_HARMONIC + +#define VIRTUAL_SITES_RELATIVE +#define FLATNOISE + + + + + diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 7746284c5e0..f3a795bc5b8 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -138,6 +138,20 @@ void force_and_velocity_display(); void finalize_p_inst_npt(); +#ifdef BROWNIAN_DYNAMICS + +/** Propagate position: viscous drift driven by conservative forces.*/ +void bd_drift(Particle *p, double dt); +/** Set velocity: viscous drift driven by conservative forces.*/ +void bd_drift_vel(Particle *p, double dt); + +/** Propagate position: random walk part.*/ +void bd_random_walk(Particle *p, double dt); +/** Thermalize velocity: random walk part.*/ +void bd_random_walk_vel(Particle *p, double dt); + +#endif // BROWNIAN_DYNAMICS + /*@}*/ void integrator_sanity_checks() { @@ -716,8 +730,18 @@ void rescale_forces_propagate_vel() { friction_therm0_nptiso(p[i].m.v[j]) / (p[i]).p.mass; } else #endif - /* Propagate velocity: v(t+dt) = v(t+0.5*dt) + 0.5*dt * f(t+dt) */ - p[i].m.v[j] += p[i].f.f[j]; + { +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift_vel(&(p[i]),0.5 * time_step); + bd_random_walk_vel(&(p[i]),0.5 * time_step); + } else +#endif // BROWNIAN_DYNAMICS + { + /* Propagate velocity: v(t+dt) = v(t+0.5*dt) + 0.5*dt * f(t+dt) */ + p[i].m.v[j] += p[i].f.f[j]; + } + } #ifdef EXTERNAL_FORCES } #endif @@ -922,7 +946,12 @@ void propagate_vel() { np = cell->n; for (i = 0; i < np; i++) { #ifdef ROTATION - propagate_omega_quat_particle(&p[i]); +#ifdef BROWNIAN_DYNAMICS + if (!(thermo_switch & THERMO_BROWNIAN)) +#endif // BROWNIAN_DYNAMICS + { + propagate_omega_quat_particle(&p[i]); + } #endif // Don't propagate translational degrees of freedom of vs @@ -949,8 +978,20 @@ void propagate_vel() { nptiso.p_vel[j] += SQR(p[i].m.v[j]) * (p[i]).p.mass; } else #endif - /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5*dt * f(t) */ - p[i].m.v[j] += p[i].f.f[j]; + { +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift_vel(&(p[i]),0.5 * time_step); + bd_drift_vel_rot(&(p[i]),0.5 * time_step); + bd_random_walk_vel(&(p[i]),0.5 * time_step); + bd_random_walk_vel_rot(&(p[i]),0.5 * time_step); + } else +#endif // BROWNIAN_DYNAMICS + { + /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5*dt * f(t) */ + p[i].m.v[j] += p[i].f.f[j]; + } + } /* SPECIAL TASKS in particle loop */ #ifdef NEMD @@ -1010,9 +1051,21 @@ void propagate_pos() { if (j == 0) nemd_add_velocity(&p[i]); #endif - /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * - * v(t+0.5*dt) */ - p[i].r.p[j] += p[i].m.v[j]; +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift(&(p[i]), time_step); + bd_drift_rot(&(p[i]), time_step); + bd_random_walk(&(p[i]), time_step); + bd_random_walk_rot(&(p[i]), time_step); + } else +#endif // BROWNIAN_DYNAMICS + { + /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * + * v(t+0.5*dt) */ + p[i].r.p[j] += p[i].m.v[j]; + } + + } } /* Verlet criterion check */ @@ -1043,7 +1096,12 @@ void propagate_vel_pos() { for (i = 0; i < np; i++) { #ifdef ROTATION - propagate_omega_quat_particle(&p[i]); +#ifdef BROWNIAN_DYNAMICS + if (!(thermo_switch & THERMO_BROWNIAN)) +#endif // BROWNIAN_DYNAMICS + { + propagate_omega_quat_particle(&p[i]); + } #endif // Don't propagate translational degrees of freedom of vs @@ -1056,15 +1114,37 @@ void propagate_vel_pos() { if (!(p[i].p.ext_flag & COORD_FIXED(j))) #endif { - /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5*dt * f(t) */ - p[i].m.v[j] += p[i].f.f[j]; +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift_vel(&(p[i]),0.5 * time_step); + bd_drift_vel_rot(&(p[i]),0.5 * time_step); + bd_random_walk_vel(&(p[i]),0.5 * time_step); + bd_random_walk_vel_rot(&(p[i]),0.5 * time_step); + } else +#endif // BROWNIAN_DYNAMICS + { + /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5*dt * f(t) */ + p[i].m.v[j] += p[i].f.f[j]; + } #ifdef MULTI_TIMESTEP if (smaller_time_step < 0. || current_time_step_is_small == 1) #endif - /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * - * v(t+0.5*dt) */ - p[i].r.p[j] += p[i].m.v[j]; + { +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift(&(p[i]), time_step); + bd_drift_rot(&(p[i]), time_step); + bd_random_walk(&(p[i]), time_step); + bd_random_walk_rot(&(p[i]), time_step); + } else +#endif // BROWNIAN_DYNAMICS + { + /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * + * v(t+0.5*dt) */ + p[i].r.p[j] += p[i].m.v[j]; + } + } } } @@ -1350,3 +1430,226 @@ int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, mpi_bcast_nptiso_geom(); return (ES_OK); } + +#ifdef BROWNIAN_DYNAMICS + +void bd_drift(Particle *p, double dt) { + int j; + double scale_f; +#ifndef PARTICLE_ANISOTROPY + double local_gamma; +#else + double local_gamma[3]; +#endif + + scale_f = 0.5 * time_step * time_step / p->p.mass; + +#ifndef PARTICLE_ANISOTROPY + if(p->p.gamma >= 0.) local_gamma = p->p.gamma; + else local_gamma = langevin_gamma; +#else + for (j = 0; j < 3; j++) + if(p->p.gamma[j] >= 0.) local_gamma[j] = p->p.gamma[j]; + else local_gamma[j] = langevin_gamma[j]; +#endif // PARTICLE_ANISOTROPY + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { + // scale_f is required to be aligned with rescaled forces + // only a conservative part of the force is used here +#ifndef PARTICLE_ANISOTROPY + p->r.p[j] += p->f.f[j] * dt / (local_gamma * scale_f); +#else + p->r.p[j] += p->f.f[j] * dt / (local_gamma[j] * scale_f); +#endif // PARTICLE_ANISOTROPY + } + } +} + +void bd_drift_vel(Particle *p, double dt) { + int j; + double scale_f; +#ifndef PARTICLE_ANISOTROPY + double local_gamma; +#else + double local_gamma[3]; +#endif + + scale_f = 0.5 * time_step * time_step / p->p.mass; + +#ifndef PARTICLE_ANISOTROPY + if(p->p.gamma >= 0.) local_gamma = p->p.gamma; + else local_gamma = langevin_gamma; +#else + for (j = 0; j < 3; j++) + if(p->p.gamma[j] >= 0.) local_gamma[j] = p->p.gamma[j]; + else local_gamma[j] = langevin_gamma[j]; +#endif // PARTICLE_ANISOTROPY + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (p->p.ext_flag & COORD_FIXED(j)) { + p->m.v[j] = 0.0; + } else +#endif + { + // here, the additional time_step is used only to align with Espresso default dimensionless model + // scale_f is required to be aligned with rescaled forces + // only conservative part of the force is used here + // NOTE: velocity is assigned here and propagated by thermal part further on top of it +#ifndef PARTICLE_ANISOTROPY + p->m.v[j] = p->f.f[j] * time_step / (local_gamma * scale_f); +#else + p->m.v[j] = p->f.f[j] * time_step / (local_gamma[j] * scale_f); +#endif // PARTICLE_ANISOTROPY + } + } +} + +/** Propagate the positions: random walk part.*/ +void bd_random_walk(Particle *p, double dt) { + int j; +#ifndef PARTICLE_ANISOTROPY + extern double brown_sigma_pos; + double brown_sigma_pos_temp; +#else + extern double brown_sigma_pos[3]; + double brown_sigma_pos_temp[3]; + double delta_pos_body[3] = { 0.0, 0.0, 0.0 }, delta_pos_lab[3] = { 0.0, 0.0, + 0.0 }; +#endif + int aniso_flag = 1; // particle anisotropy flag + + // first, set defaults +#ifndef PARTICLE_ANISOTROPY + brown_sigma_pos_temp = brown_sigma_pos; +#else + for (j = 0; j < 3; j++) + brown_sigma_pos_temp[j] = brown_sigma_pos[j]; +#endif // PARTICLE_ANISOTROPY + // Override defaults if per-particle values for T and gamma are given +#ifdef LANGEVIN_PER_PARTICLE + auto const constexpr langevin_temp_coeff = 24.0; + +#ifndef PARTICLE_ANISOTROPY + if(p->p.gamma >= 0.) + { + // Is a particle-specific temperature also specified? + if(p->p.T >= 0.) + brown_sigma_pos_temp = sqrt(langevin_temp_coeff * p->p.T / p->p.gamma); + else + // Default temperature but particle-specific gamma + brown_sigma_pos_temp = sqrt(langevin_temp_coeff * temperature / p->p.gamma); + } // particle specific gamma + else + { + // No particle-specific gamma, but is there particle-specific temperature + if(p->p.T >= 0.) + brown_sigma_pos_temp = sqrt(langevin_temp_coeff * p->p.T / langevin_gamma); + else + // Defaut values for both + brown_sigma_pos_temp = brown_sigma_pos; + } +#else + for (j = 0; j < 3; j++) + if (p->p.gamma[j] >= 0.) { + // Is a particle-specific temperature also specified? + if (p->p.T >= 0.) + brown_sigma_pos_temp[j] = sqrt( + langevin_temp_coeff * p->p.T / p->p.gamma[j]); + else + // Default temperature but particle-specific gamma + brown_sigma_pos_temp[j] = sqrt( + langevin_temp_coeff * temperature / p->p.gamma[j]); + } // particle specific gamma + else { + // No particle-specific gamma, but is there particle-specific temperature + if (p->p.T >= 0.) + brown_sigma_pos_temp[j] = sqrt( + langevin_temp_coeff * p->p.T / langevin_gamma[j]); + else + // Defaut values for both + brown_sigma_pos_temp[j] = brown_sigma_pos[j]; + } +#endif // PARTICLE_ANISOTROPY +#endif /* LANGEVIN_PER_PARTICLE */ + +#ifdef PARTICLE_ANISOTROPY + // Particle frictional isotropy check. + aniso_flag = (brown_sigma_pos_temp[0] != brown_sigma_pos_temp[1]) + || (brown_sigma_pos_temp[1] != brown_sigma_pos_temp[2]); +#endif + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { +#ifndef PARTICLE_ANISOTROPY + delta_pos_body[j] = brown_sigma_pos_temp * sqrt(dt) * Thermostat::noise(); +#else + delta_pos_body[j] = brown_sigma_pos_temp[j] * sqrt(dt) * Thermostat::noise(); +#endif // PARTICLE_ANISOTROPY + } + } + + if (aniso_flag) { + convert_vec_body_to_space(p, delta_pos_body, delta_pos_lab); + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { + p->r.p[j] += delta_pos_lab[j]; + } + } + } else { + // in order to save a calculation performance: + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { + p->r.p[j] += delta_pos_body[j]; + } + } + } +} + +/** Determine the velocities: random walk part.*/ +void bd_random_walk_vel(Particle *p, double dt) { + int j; + extern double brown_sigma_vel; + double brown_sigma_vel_temp; + + // first, set defaults + brown_sigma_vel_temp = brown_sigma_vel; + + // Override defaults if per-particle values for T and gamma are given +#ifdef LANGEVIN_PER_PARTICLE + auto const constexpr langevin_temp_coeff = 12.0; + // Is a particle-specific temperature specified? + if (p->p.T >= 0.) + brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T); + else + brown_sigma_vel_temp = brown_sigma_vel; +#endif /* LANGEVIN_PER_PARTICLE */ + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { + // velocity is added here. It is assigned in the drift part. + // here, the time_step is used only to align with Espresso default dimensionless model + p->m.v[j] += brown_sigma_vel_temp * Thermostat::noise() * time_step + / sqrt(p->p.mass); + } + } +} + +#endif // BROWNIAN_DYNAMICS diff --git a/src/core/integrate.hpp b/src/core/integrate.hpp index f243ee5b8d4..c9c71e3eafb 100755 --- a/src/core/integrate.hpp +++ b/src/core/integrate.hpp @@ -116,5 +116,4 @@ int python_integrate(int n_steps, bool recalc_forces, bool reuse_forces); void integrate_set_nvt(); int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, int ydir, int zdir, bool cubic_box); - #endif diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 447aa9c2f29..d7dc0a42ce1 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -337,32 +337,39 @@ void convert_torques_propagate_omega() } #endif - ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n",this_node,p[i].f.f[0],p[i].f.f[1],p[i].f.f[2],p[i].m.v[0],p[i].m.v[1],p[i].m.v[2])); +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift_vel_rot(&(p[i]),0.5 * time_step); + bd_random_walk_vel_rot(&(p[i]),0.5 * time_step); + } else +#endif // BROWNIAN_DYNAMICS + { + ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n",this_node,p[i].f.f[0],p[i].f.f[1],p[i].f.f[2],p[i].m.v[0],p[i].m.v[1],p[i].m.v[2])); - p[i].m.omega[0]+= time_step_half*p[i].f.torque[0]/p[i].p.rinertia[0]; - p[i].m.omega[1]+= time_step_half*p[i].f.torque[1]/p[i].p.rinertia[1]; - p[i].m.omega[2]+= time_step_half*p[i].f.torque[2]/p[i].p.rinertia[2]; + p[i].m.omega[0]+= time_step_half*p[i].f.torque[0]/p[i].p.rinertia[0]; + p[i].m.omega[1]+= time_step_half*p[i].f.torque[1]/p[i].p.rinertia[1]; + p[i].m.omega[2]+= time_step_half*p[i].f.torque[2]/p[i].p.rinertia[2]; - // zeroth estimate of omega - for (int j = 0; j < 3; j++) omega_0[j] = p[i].m.omega[j]; + // zeroth estimate of omega + for (int j = 0; j < 3; j++) omega_0[j] = p[i].m.omega[j]; - /* if the tensor of inertia is isotropic, the following refinement is not needed. - Otherwise repeat this loop 2-3 times depending on the required accuracy */ - for(int times=0; times <= 5; times++) - { - double Wd[3]; + /* if the tensor of inertia is isotropic, the following refinement is not needed. + Otherwise repeat this loop 2-3 times depending on the required accuracy */ + for(int times=0; times <= 5; times++) + { + double Wd[3]; - Wd[0] = (p[i].m.omega[1]*p[i].m.omega[2]*(p[i].p.rinertia[1]-p[i].p.rinertia[2]))/p[i].p.rinertia[0]; - Wd[1] = (p[i].m.omega[2]*p[i].m.omega[0]*(p[i].p.rinertia[2]-p[i].p.rinertia[0]))/p[i].p.rinertia[1]; - Wd[2] = (p[i].m.omega[0]*p[i].m.omega[1]*(p[i].p.rinertia[0]-p[i].p.rinertia[1]))/p[i].p.rinertia[2]; + Wd[0] = (p[i].m.omega[1]*p[i].m.omega[2]*(p[i].p.rinertia[1]-p[i].p.rinertia[2]))/p[i].p.rinertia[0]; + Wd[1] = (p[i].m.omega[2]*p[i].m.omega[0]*(p[i].p.rinertia[2]-p[i].p.rinertia[0]))/p[i].p.rinertia[1]; + Wd[2] = (p[i].m.omega[0]*p[i].m.omega[1]*(p[i].p.rinertia[0]-p[i].p.rinertia[1]))/p[i].p.rinertia[2]; - p[i].m.omega[0] = omega_0[0] + time_step_half*Wd[0]; - p[i].m.omega[1] = omega_0[1] + time_step_half*Wd[1]; - p[i].m.omega[2] = omega_0[2] + time_step_half*Wd[2]; - } - - ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT: PV_2 v_new = (%.3e,%.3e,%.3e)\n",this_node,p[i].m.v[0],p[i].m.v[1],p[i].m.v[2])); + p[i].m.omega[0] = omega_0[0] + time_step_half*Wd[0]; + p[i].m.omega[1] = omega_0[1] + time_step_half*Wd[1]; + p[i].m.omega[2] = omega_0[2] + time_step_half*Wd[2]; + } + ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT: PV_2 v_new = (%.3e,%.3e,%.3e)\n",this_node,p[i].m.v[0],p[i].m.v[1],p[i].m.v[2])); + } } } } @@ -463,6 +470,15 @@ void convert_vec_space_to_body(Particle *p, double *v,double* res) res[2] = A[2 + 3*0]*v[0] + A[2 + 3*1]*v[1] + A[2 + 3*2]*v[2]; } +void convert_vec_body_to_space(Particle *p, double *v,double* res) +{ + double A[9]; + define_rotation_matrix(p, A); + + res[0] = A[0 + 3*0]*v[0] + A[1 + 3*0]*v[1] + A[2 + 3*0]*v[2]; + res[1] = A[0 + 3*1]*v[0] + A[1 + 3*1]*v[1] + A[2 + 3*1]*v[2]; + res[2] = A[0 + 3*2]*v[0] + A[1 + 3*2]*v[1] + A[2 + 3*2]*v[2]; +} /** Multiply two quaternions */ void multiply_quaternions(double a[4], double b[4], double result[4]) @@ -526,6 +542,293 @@ void rotate_particle(Particle* p, double* aSpaceFrame, double phi) #endif } +/** Rotate the particle p around the body axis "a" by amount phi */ +void rotate_particle_body(Particle* p, double* a, double phi) +{ + // Apply restrictions from the rotation_per_particle feature +#ifdef ROTATION_PER_PARTICLE + // Rotation turned off entirely? + if (p->p.rotation <2) return; + + // Per coordinate fixing + if (!(p->p.rotation & 2)) a[0]=0; + if (!(p->p.rotation & 4)) a[1]=0; + if (!(p->p.rotation & 8)) a[2]=0; + // Re-normalize rotation axis + double l=sqrt(sqrlen(a)); + // Check, if the rotation axis is nonzero + if (l<1E-10) return; + + for (int i=0;i<3;i++) + a[i]/=l; + +#endif + + double q[4]; + q[0]=cos(phi/2); + double tmp=sin(phi/2); + q[1]=tmp*a[0]; + q[2]=tmp*a[1]; + q[3]=tmp*a[2]; + + // Normalize + normalize_quaternion(q); + + // Rotate the particle + double qn[4]; // Resulting quaternion + multiply_quaternions(p->r.quat,q,qn); + for (int k=0; k<4; k++) + p->r.quat[k]=qn[k]; + convert_quat_to_quatu(p->r.quat, p->r.quatu); +#ifdef DIPOLES + // When dipoles are enabled, update dipole moment + convert_quatu_to_dip(p->r.quatu, p->p.dipm, p->r.dip); +#endif +} +/** Rotate the particle p around the j-th body axis by amount phi */ +void rotate_particle_body_j(Particle* p, int j, double phi) +{ + double u_dphi[3] = {0.0, 0.0, 0.0}; + if (phi) { + u_dphi[j] = 1.0; + rotate_particle_body(p, u_dphi, phi); + } +} + +void bd_drift_rot(Particle *p, double dt) { + int j; + double a[3]; + double dphi[3]; +#ifndef ROTATIONAL_INERTIA + double local_gamma; +#else + double local_gamma[3]; +#endif + + a[0] = a[1] = a[2] = 1.0; +#ifdef ROTATION_PER_PARTICLE + if (!p->p.rotation) + return; + if (!(p->p.rotation & 2)) + a[0] = 0.0; + if (!(p->p.rotation & 4)) + a[1] = 0.0; + if (!(p->p.rotation & 8)) + a[2] = 0.0; +#endif + +#ifndef ROTATIONAL_INERTIA + if(p->p.gamma_rot >= 0.) local_gamma = p->p.gamma_rot; + else local_gamma = langevin_gamma_rotation; +#else + for (j = 0; j < 3; j++) + if(p->p.gamma_rot[j] >= 0.) local_gamma[j] = p->p.gamma_rot[j]; + else local_gamma[j] = langevin_gamma_rotation[j]; +#endif // ROTATIONAL_INERTIA + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { + dphi[0] = dphi[1] = dphi[2] = 0.0; + // only a conservative part of the torque is used here +#ifndef ROTATIONAL_INERTIA + dphi[j] = a[j] * p->f.torque[j] * dt / (local_gamma); +#else + dphi[j] = a[j] * p->f.torque[j] * dt / (local_gamma[j]); +#endif // ROTATIONAL_INERTIA + rotate_particle_body_j(p, j, dphi[j]); + } + } +} + +void bd_drift_vel_rot(Particle *p, double dt) { + int j; + double m_dphi; + double a[3]; +#ifndef ROTATIONAL_INERTIA + double local_gamma; +#else + double local_gamma[3]; +#endif + + a[0] = a[1] = a[2] = 1.0; +#ifdef ROTATION_PER_PARTICLE + if (!p->p.rotation) + return; + if (!(p->p.rotation & 2)) + a[0] = 0.0; + if (!(p->p.rotation & 4)) + a[1] = 0.0; + if (!(p->p.rotation & 8)) + a[2] = 0.0; +#endif + +#ifndef ROTATIONAL_INERTIA + if(p->p.gamma_rot >= 0.) local_gamma = p->p.gamma_rot; + else local_gamma = langevin_gamma_rotation; +#else + for (j = 0; j < 3; j++) + if(p->p.gamma_rot[j] >= 0.) local_gamma[j] = p->p.gamma_rot[j]; + else local_gamma[j] = langevin_gamma_rotation[j]; +#endif // ROTATIONAL_INERTIA + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (p->p.ext_flag & COORD_FIXED(j)) { + p->m.omega[j] = 0.0; + } else +#endif + { + // only conservative part of the force is used here + // NOTE: velocity is assigned here and propagated by thermal part further on top of it +#ifndef ROTATIONAL_INERTIA + p->m.omega[j] = a[j] * p->f.torque[j] / (local_gamma); +#else + p->m.omega[j] = a[j] * p->f.torque[j] / (local_gamma[j]); +#endif // ROTATIONAL_INERTIA + } + } +} + +/** Propagate the positions: random walk part.*/ +void bd_random_walk_rot(Particle *p, double dt) { + double a[3]; + double dphi[3]; + int j; +#ifndef ROTATIONAL_INERTIA + extern double brown_sigma_pos_rotation; + double brown_sigma_pos_temp; +#else + extern double brown_sigma_pos_rotation[3]; + double brown_sigma_pos_temp[3]; +#endif + + a[0] = a[1] = a[2] = 1.0; +#ifdef ROTATION_PER_PARTICLE + if (!p->p.rotation) + return; + if (!(p->p.rotation & 2)) + a[0] = 0.0; + if (!(p->p.rotation & 4)) + a[1] = 0.0; + if (!(p->p.rotation & 8)) + a[2] = 0.0; +#endif + + // first, set defaults +#ifndef ROTATIONAL_INERTIA + brown_sigma_pos_temp = brown_sigma_pos_rotation; +#else + for (j = 0; j < 3; j++) + brown_sigma_pos_temp[j] = brown_sigma_pos_rotation[j]; +#endif // ROTATIONAL_INERTIA + // Override defaults if per-particle values for T and gamma are given +#ifdef LANGEVIN_PER_PARTICLE + auto const constexpr langevin_temp_coeff = 24.0; + +#ifndef ROTATIONAL_INERTIA + if(p->p.gamma_rot >= 0.) + { + // Is a particle-specific temperature also specified? + if(p->p.T >= 0.) + brown_sigma_pos_temp = sqrt(langevin_temp_coeff * p->p.T / p->p.gamma_rot); + else + // Default temperature but particle-specific gamma + brown_sigma_pos_temp = sqrt(langevin_temp_coeff * temperature / p->p.gamma_rot); + } // particle specific gamma + else + { + // No particle-specific gamma, but is there particle-specific temperature + if(p->p.T >= 0.) + brown_sigma_pos_temp = sqrt(langevin_temp_coeff * p->p.T / langevin_gamma_rotation); + else + // Defaut values for both + brown_sigma_pos_temp = brown_sigma_pos_rotation; + } +#else + for (j = 0; j < 3; j++) + if (p->p.gamma_rot[j] >= 0.) { + // Is a particle-specific temperature also specified? + if (p->p.T >= 0.) + brown_sigma_pos_temp[j] = sqrt( + langevin_temp_coeff * p->p.T / p->p.gamma_rot[j]); + else + // Default temperature but particle-specific gamma + brown_sigma_pos_temp[j] = sqrt( + langevin_temp_coeff * temperature / p->p.gamma_rot[j]); + } // particle specific gamma + else { + // No particle-specific gamma, but is there particle-specific temperature + if (p->p.T >= 0.) + brown_sigma_pos_temp[j] = sqrt( + langevin_temp_coeff * p->p.T / langevin_gamma_rotation[j]); + else + // Defaut values for both + brown_sigma_pos_temp[j] = brown_sigma_pos_rotation[j]; + } +#endif // ROTATIONAL_INERTIA +#endif /* LANGEVIN_PER_PARTICLE */ + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { + dphi[0] = dphi[1] = dphi[2] = 0.0; +#ifndef ROTATIONAL_INERTIA + dphi[j] = a[j] * Thermostat::noise() * brown_sigma_pos_temp * sqrt(dt); +#else + dphi[j] = a[j] * Thermostat::noise() * brown_sigma_pos_temp[j] * sqrt(dt); +#endif // ROTATIONAL_INERTIA + rotate_particle_body_j(p, j, dphi[j]); + } + } +} + +/** Determine the angular velocities: random walk part.*/ +void bd_random_walk_vel_rot(Particle *p, double dt) { + int j; + double a[3]; + extern double brown_sigma_vel_rotation; + double brown_sigma_vel_temp; + + a[0] = a[1] = a[2] = 1.0; +#ifdef ROTATION_PER_PARTICLE + if (!p->p.rotation) + return; + if (!(p->p.rotation & 2)) + a[0] = 0.0; + if (!(p->p.rotation & 4)) + a[1] = 0.0; + if (!(p->p.rotation & 8)) + a[2] = 0.0; +#endif + + // first, set defaults + brown_sigma_vel_temp = brown_sigma_vel_rotation; + + // Override defaults if per-particle values for T and gamma are given +#ifdef LANGEVIN_PER_PARTICLE + auto const constexpr langevin_temp_coeff = 12.0; + // Is a particle-specific temperature specified? + if (p->p.T >= 0.) + brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T); + else + brown_sigma_vel_temp = brown_sigma_vel_rotation; +#endif /* LANGEVIN_PER_PARTICLE */ + + for (j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p->p.ext_flag & COORD_FIXED(j))) +#endif + { + // velocity is added here. It is assigned in the drift part. + p->m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise() / sqrt(p->p.rinertia[j]); + } + } +} #endif diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 1b36ec9a30c..978c4a00501 100755 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -55,6 +55,9 @@ void convert_torques_body_to_space(Particle *p, double *torque); to the body-fixed frame */ void convert_vel_space_to_body(Particle *p, double *vel_body); +/** convert a vector from the body-fixed frames to space-fixed coordinates */ +void convert_vec_body_to_space(Particle *p, double *v,double* res); + /** Here we use quaternions to calculate the rotation matrix which will be used then to transform torques from the laboratory to the body-fixed frames */ @@ -103,6 +106,10 @@ inline void convert_quatu_to_dip(double quatu[3], double dipm, double dip[3]) /** Rotate the particle p around the NORMALIZED axis a by amount phi */ void rotate_particle(Particle* p, double* a, double phi); +/** Rotate the particle p around the body axis "a" by amount phi */ +void rotate_particle_body(Particle* p, double* a, double phi); +/** Rotate the particle p around the j-th body axis by amount phi */ +void rotate_particle_body_j(Particle* p, int j, double phi); inline void normalize_quaternion(double* q) { double tmp=sqrt(q[0]*q[0] +q[1]*q[1] +q[2]*q[2] +q[3]*q[3]); @@ -112,4 +119,18 @@ inline void normalize_quaternion(double* q) { q[3]/=tmp; } +#ifdef BROWNIAN_DYNAMICS + +/** Propagate quaternions: viscous drift driven by conservative torques.*/ +void bd_drift_rot(Particle *p, double dt); +/** Set angular velocity: viscous drift driven by conservative torques.*/ +void bd_drift_vel_rot(Particle *p, double dt); + +/** Propagate quaternion: random walk part.*/ +void bd_random_walk_rot(Particle *p, double dt); +/** Thermalize angular velocity: random walk part.*/ +void bd_random_walk_vel_rot(Particle *p, double dt); + +#endif // BROWNIAN_DYNAMICS + #endif diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index ed7b5188bf9..8ec9ead30af 100755 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -36,6 +36,7 @@ int thermo_switch = THERMO_OFF; double temperature = 0.0; /* LANGEVIN THERMOSTAT */ +// Note: BROWNIAN_DYNAMICS feature implies the same langevin parameters #ifndef PARTICLE_ANISOTROPY /* Langevin friction coefficient gamma for translation. */ double langevin_gamma = -1.0; @@ -70,16 +71,34 @@ double ghmc_phi = 0; #ifndef PARTICLE_ANISOTROPY double langevin_pref1, langevin_pref2; +#ifdef BROWNIAN_DYNAMICS +// Brownian position random walk standard deviation +double brown_sigma_pos; +#endif // BROWNIAN_DYNAMICS #else + double langevin_pref1[3], langevin_pref2[3]; +#ifdef BROWNIAN_DYNAMICS +double brown_sigma_pos[3]; +#endif // BROWNIAN_DYNAMICS #endif #ifndef ROTATIONAL_INERTIA -double langevin_pref2_rotation; +double langevin_pref1_rotation, langevin_pref2_rotation; +#ifdef BROWNIAN_DYNAMICS +double brown_sigma_pos_rotation; +#endif // BROWNIAN_DYNAMICS #else -double langevin_pref2_rotation[3]; +double langevin_pref1_rotation[3], langevin_pref2_rotation[3]; +#ifdef BROWNIAN_DYNAMICS +double brown_sigma_pos_rotation[3]; +#endif // BROWNIAN_DYNAMICS #endif +#ifdef BROWNIAN_DYNAMICS +double brown_sigma_vel, brown_sigma_vel_rotation; +#endif // BROWNIAN_DYNAMICS + #ifdef MULTI_TIMESTEP double langevin_pref1_small, langevin_pref2_small; static double langevin_pref2_small_buffer; @@ -106,6 +125,26 @@ double nptiso_pref3; double nptiso_pref4; #endif +void thermo_langevin_rot_parameters() +{ + int j; +#ifndef ROTATIONAL_INERTIA + if ( langevin_gamma_rotation < 0.0 ) + { + langevin_gamma_rotation = langevin_gamma; + } +#else + if (( langevin_gamma_rotation[0] < 0.0 ) || (langevin_gamma_rotation[1] < 0.0) || (langevin_gamma_rotation[2] < 0.0)) + for ( j = 0 ; j < 3 ; j++) + { +#ifdef PARTICLE_ANISOTROPY + langevin_gamma_rotation[j] = langevin_gamma[j]; +#else + langevin_gamma_rotation[j] = langevin_gamma; +#endif // PARTICLE_ANISOTROPY + } +#endif // ROTATIONAL_INERTIA +} void thermo_init_langevin() { @@ -136,22 +175,7 @@ void thermo_init_langevin() #endif #ifdef ROTATION -#ifndef ROTATIONAL_INERTIA - if ( langevin_gamma_rotation < 0.0 ) - { - langevin_gamma_rotation = langevin_gamma; - } -#else - if (( langevin_gamma_rotation[0] < 0.0 ) || (langevin_gamma_rotation[1] < 0.0) || (langevin_gamma_rotation[2] < 0.0)) - for ( j = 0 ; j < 3 ; j++) - { -#ifdef PARTICLE_ANISOTROPY - langevin_gamma_rotation[j] = langevin_gamma[j]; -#else - langevin_gamma_rotation[j] = langevin_gamma; -#endif // PARTICLE_ANISOTROPY - } -#endif // ROTATIONAL_INERTIA + thermo_langevin_rot_parameters(); #ifndef ROTATIONAL_INERTIA langevin_pref2_rotation = sqrt(24.0*temperature*langevin_gamma_rotation/time_step); @@ -190,6 +214,47 @@ void thermo_init_npt_isotropic() { } #endif +#ifdef BROWNIAN_DYNAMICS +// brown_sigma_vel determines here the heat velocity random walk dispersion +// brown_sigma_pos determines here the BD position random walk dispersion +// default particle mass is assumed to be unitary in this global parameters +void thermo_init_brownian() { + int j; + // here, the time_step is used only to align with Espresso default dimensionless model (translational velocity only) + brown_sigma_vel = sqrt(12.0 * temperature) * time_step; + #ifndef PARTICLE_ANISOTROPY + brown_sigma_pos = sqrt(24.0 * temperature / langevin_gamma); + #else + for (j = 0; j < 3; j++) brown_sigma_pos[j] = sqrt(24.0 * temperature / langevin_gamma[j]); + #endif // PARTICLE_ANISOTROPY + + #ifdef ROTATION + // Note: the BD thermostat assigns the langevin viscous parameters as well + thermo_langevin_rot_parameters(); + brown_sigma_vel_rotation = sqrt(12.0 * temperature); + #ifndef ROTATIONAL_INERTIA + brown_sigma_pos_rotation = sqrt(24.0 * temperature / langevin_gamma); + #else + for ( j = 0 ; j < 3 ; j++) brown_sigma_pos_rotation[j] = sqrt(24.0 * temperature / langevin_gamma[j]); + #endif // ROTATIONAL_INERTIA +#ifndef ROTATIONAL_INERTIA + THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation)); +#else + for ( j = 0 ; j < 3 ; j++) { + THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation[%d]=%f, brown_sigma_pos_rotation[%d]=%f",this_node,j,brown_sigma_vel,j,brown_sigma_pos)); + } +#endif // ROTATIONAL_INERTIA + #endif // ROTATION +#ifndef PARTICLE_ANISOTROPY + THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos=%f",this_node,brown_sigma_vel,brown_sigma_pos)); +#else + for ( j = 0 ; j < 3 ; j++) { + THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel[%d]=%f, brown_sigma_pos[%d]=%f",this_node,j,brown_sigma_vel,j,brown_sigma_pos)); + } +#endif // PARTICLE_ANISOTROPY +} +#endif // BROWNIAN_DYNAMICS + void thermo_init() { if(thermo_switch == THERMO_OFF){ @@ -208,6 +273,9 @@ void thermo_init() #ifdef GHMC if(thermo_switch & THERMO_GHMC) thermo_init_ghmc(); #endif +#ifdef BROWNIAN_DYNAMICS + if(thermo_switch & THERMO_BROWNIAN) thermo_init_brownian(); +#endif } void thermo_heat_up() diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 46e811fe85e..eef1545b4b7 100755 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -49,6 +49,7 @@ #define THERMO_INTER_DPD 16 #define THERMO_GHMC 32 #define THERMO_CPU 64 +#define THERMO_BROWNIAN 128 /*@}*/ namespace Thermostat { diff --git a/src/features.def b/src/features.def index 78761074586..df6ef024463 100755 --- a/src/features.def +++ b/src/features.def @@ -38,6 +38,7 @@ CATALYTIC_REACTIONS MULTI_TIMESTEP requires not GAUSSRANDOMCUT and not GAUSSRANDOM ENGINE implies ROTATION, EXTERNAL_FORCES PARTICLE_ANISOTROPY +BROWNIAN_DYNAMICS /* Rotation */ ROTATION diff --git a/src/python/espressomd/thermostat.pxd b/src/python/espressomd/thermostat.pxd index 0d628647a88..27c0ab44126 100644 --- a/src/python/espressomd/thermostat.pxd +++ b/src/python/espressomd/thermostat.pxd @@ -54,3 +54,4 @@ cdef extern from "thermostat.hpp": int THERMO_NPT_ISO int THERMO_DPD int THERMO_INTER_DPD + int THERMO_BROWNIAN diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 6b8ea5db5bf..09cc7a8a908 100755 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -101,6 +101,9 @@ cdef class Thermostat(object): "p_diff"], piston=thmst["piston"]) if thmst["type"] == "DPD" or thmst["type"] == "INTER_DPD": pass + if thmst["type"] == "BROWNIAN": + self.set_brownian(kT=thmst["kT"], gamma=thmst[ + "gamma"], gamma_rotation=thmst["gamma_rotation"]) def get_ts(self): return thermo_switch @@ -195,28 +198,7 @@ cdef class Thermostat(object): # here other thermostats stuff return True - @AssertThermostatType(THERMO_LANGEVIN) - def set_langevin(self, kT=None, gamma=None, gamma_rotation=None): - """Sets the Langevin thermostat with required parameters 'kT' 'gamma' - and optional parameter 'gamma_rotation'. - - Parameters - ----------- - 'kT': float - Thermal energy of the simulated heat bath. - - 'gamma': float - Contains the friction coefficient of the bath. If the feature 'PARTICLE_ANISOTROPY' - is compiled in then 'gamma' can be a list of three positive floats, for the friction - coefficient in each cardinal direction. - - gamma_rotation: float, optional - The same applies to 'gamma_rotation', which requires the feature - 'ROTATION' to work properly. But also accepts three floating point numbers - if 'PARTICLE_ANISOTROPY' is also compiled in. - - """ - + def _set_langevin_gamma(self, kT=None, gamma=None, gamma_rotation=None): scalar_gamma_def = True scalar_gamma_rot_def = True IF PARTICLE_ANISOTROPY: @@ -317,13 +299,37 @@ cdef class Thermostat(object): ELSE: langevin_gamma_rotation = langevin_gamma - global thermo_switch - thermo_switch = (thermo_switch | THERMO_LANGEVIN) - mpi_bcast_parameter(FIELD_THERMO_SWITCH) mpi_bcast_parameter(FIELD_TEMPERATURE) mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA) IF ROTATION: mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA_ROTATION) + + @AssertThermostatType(THERMO_LANGEVIN) + def set_langevin(self, kT=None, gamma=None, gamma_rotation=None): + """Sets the Langevin thermostat with required parameters 'kT' 'gamma' + and optional parameter 'gamma_rotation'. + + Parameters + ----------- + 'kT': float + Thermal energy of the simulated heat bath. + + 'gamma': float + Contains the friction coefficient of the bath. If the feature 'PARTICLE_ANISOTROPY' + is compiled in then 'gamma' can be a list of three positive floats, for the friction + coefficient in each cardinal direction. + + gamma_rotation: float, optional + The same applies to 'gamma_rotation', which requires the feature + 'ROTATION' to work properly. But also accepts three floating point numbers + if 'PARTICLE_ANISOTROPY' is also compiled in. + + """ + + self._set_langevin_gamma(kT=kT, gamma=gamma, gamma_rotation=gamma_rotation) + global thermo_switch + thermo_switch = (thermo_switch | THERMO_LANGEVIN) + mpi_bcast_parameter(FIELD_THERMO_SWITCH) return True IF LB_GPU or LB: @@ -427,3 +433,32 @@ cdef class Thermostat(object): req = ["kT","gamma","r_cut"] valid = ["kT","gamma","r_cut","tgamma","tr_cut","wf","twf"] raise Exception("Not implemented yet.") + + IF BROWNIAN_DYNAMICS: + @AssertThermostatType(THERMO_BROWNIAN) + def set_brownian(self, kT=None, gamma=None, gamma_rotation=None): + """Sets the Brownian Dynamics thermostat with required parameters 'kT' 'gamma' + and optional parameter 'gamma_rotation'. + + Parameters + ----------- + 'kT': float + Thermal energy of the simulated heat bath. + + 'gamma': float + Contains the friction coefficient of the bath. If the feature 'PARTICLE_ANISOTROPY' + is compiled in then 'gamma' can be a list of three positive floats, for the friction + coefficient in each cardinal direction. + + gamma_rotation: float, optional + The same applies to 'gamma_rotation', which requires the feature + 'ROTATION' to work properly. But also accepts three floating point numbers + if 'PARTICLE_ANISOTROPY'/'ROTATIONAL_INERTIA' are also compiled in. + + """ + + self._set_langevin_gamma(kT=kT, gamma=gamma, gamma_rotation=gamma_rotation) + global thermo_switch + thermo_switch = (thermo_switch | THERMO_BROWNIAN) + mpi_bcast_parameter(FIELD_THERMO_SWITCH) + return True diff --git a/testsuite/python/CMakeLists.txt b/testsuite/python/CMakeLists.txt index f3bf87d92b6..3bcb39c6bfa 100644 --- a/testsuite/python/CMakeLists.txt +++ b/testsuite/python/CMakeLists.txt @@ -39,6 +39,7 @@ python_test(FILE ewald_gpu.py MAX_NUM_PROC 4) python_test(FILE icc.py MAX_NUM_PROC 4) python_test(FILE magnetostaticInteractions.py MAX_NUM_PROC 1) python_test(FILE mass-and-rinertia_per_particle.py MAX_NUM_PROC 1) +python_test(FILE mass-and-rinertia-brownian_per_particle.py MAX_NUM_PROC 1) python_test(FILE nonBondedInteractions.py MAX_NUM_PROC 4) python_test(FILE observables.py MAX_NUM_PROC 4) python_test(FILE p3m_gpu.py MAX_NUM_PROC 4) diff --git a/testsuite/python/mass-and-rinertia-brownian_per_particle.py b/testsuite/python/mass-and-rinertia-brownian_per_particle.py new file mode 100644 index 00000000000..de7bf3cb142 --- /dev/null +++ b/testsuite/python/mass-and-rinertia-brownian_per_particle.py @@ -0,0 +1,194 @@ +from __future__ import print_function +import unittest as ut +import numpy as np +from numpy.random import random,seed +import espressomd +import math + +@ut.skipIf(not espressomd.has_features(["MASS","ROTATIONAL_INERTIA","LANGEVIN_PER_PARTICLE","BROWNIAN_DYNAMICS"]), + "Features not available, skipping test!") +class ThermoTest(ut.TestCase): + longMessage = True + # Handle for espresso system + es = espressomd.System() + + def run_test_case(self, test_case): + seed(1) + + for i in range(len(self.es.part)): + self.es.part[i].delete() + + # thermalization + # Checks if every degree of freedom has 1/2 kT of energy, even when + # mass and inertia tensor are active + + # 2 different langevin parameters for particles + temp = np.array([2.5, 2.0]) + # gamma_tran/gamma_rot matrix: [2 types of particless] x [3 dimensions X Y Z] + gamma_tran = np.zeros((2,3)) + gamma_tr = np.zeros((2,3)) + gamma_rot = np.zeros((2,3)) + D_tr = np.zeros((2,3)) + for k in range(2): + if "PARTICLE_ANISOTROPY" in espressomd.features(): + gamma_tran[k,:] = np.array((0.4 + random(3)) * 10) + else: + gamma_tran[k,0] = np.array((0.4 + random(1)) * 10) + gamma_tran[k,1] = gamma_tran[k,0] + gamma_tran[k,2] = gamma_tran[k,0] + gamma_rot[k,:] = np.array((0.2 + random(3)) * 20) + + box = 10.0 + self.es.box_l = [box, box, box] + if espressomd.has_features(("PARTIAL_PERIODIC",)): + self.es.periodicity=0,0,0 + kT = 1.5 + gamma_global = np.ones((3)) + + if test_case == 2 or test_case == 3: + halfkT = temp / 2.0 + else: + halfkT = np.array([kT, kT]) / 2.0 + + if test_case == 1 or test_case == 3: + gamma_tr = gamma_tran + else: + for k in range(2): + gamma_tr[k,:] = gamma_global[:] + + # translational diffusion + for k in range(2): + D_tr[k,:] = 2.0 * halfkT[k] / gamma_tr[k,:] + + if "PARTICLE_ANISOTROPY" in espressomd.features(): + self.es.thermostat.set_brownian(kT=kT, gamma=[gamma_global[0],gamma_global[1],gamma_global[2]]) + else: + self.es.thermostat.set_brownian(kT=kT, gamma=gamma_global[0]) + + # no need to rebuild Verlet lists, avoid it + self.es.cell_system.skin = 5.0 + self.es.time_step = 0.03 + n = 200 + mass = (0.2 + random()) * 7.0 + J = np.array((0.2 + random(3)) * 7.0) + + for i in range(n): + for k in range(2): + ind = i + k * n + part_pos = np.array(random(3) * box) + part_v = np.array([0.0, 0.0, 0.0]) + part_omega_body = np.array([0.0, 0.0, 0.0]) + self.es.part.add(id = ind, mass = mass, rinertia = J, pos = part_pos, v = part_v) + if "ROTATION" in espressomd.features(): + self.es.part[ind].omega_body = part_omega_body + if test_case == 1: + if "PARTICLE_ANISOTROPY" in espressomd.features(): + self.es.part[ind].gamma = gamma_tran[k,:] + else: + self.es.part[ind].gamma = gamma_tran[k,0] + if "ROTATION" in espressomd.features(): + self.es.part[ind].gamma_rot = gamma_rot[k,:] + + if test_case == 2: + self.es.part[ind].temp = temp[k] + if test_case == 3: + if "PARTICLE_ANISOTROPY" in espressomd.features(): + self.es.part[ind].gamma = gamma_tran[k,:] + else: + self.es.part[ind].gamma = gamma_tran[k,0] + if "ROTATION" in espressomd.features(): + self.es.part[ind].gamma_rot = gamma_rot[k,:] + self.es.part[ind].temp = temp[k] + + # Get rid of short range calculations if exclusions are on + #if espressomd.has_features("EXCLUSIONS"): + + + # matrices: [2 types of particless] x [3 dimensions X Y Z] + # velocity^2, omega^2, position^2 + v2 = np.zeros((2,3)) + o2 = np.zeros((2,3)) + dr2 = np.zeros((2,3)) + sigma2_tr = np.zeros((2)) + dr_norm = np.zeros((2)) + + pos0 = np.zeros((2 * n, 3)) + for p in range(n): + for k in range(2): + ind = p + k * n + pos0[ind,:] = self.es.part[ind].pos + dt0 = mass / gamma_tr + + loops = 200 + print("Thermalizing...") + therm_steps = 150 + self.es.integrator.run(therm_steps) + print("Measuring...") + + int_steps = 5 + for i in range(loops): + self.es.integrator.run(int_steps) + # Get kinetic energy in each degree of freedom for all particles + for p in range(n): + for k in range(2): + ind = p + k * n + v = self.es.part[ind].v + if "ROTATION" in espressomd.features(): + o = self.es.part[ind].omega_body + o2[k,:] = o2[k,:] + np.power(o[:], 2) + pos = self.es.part[ind].pos + v2[k,:] = v2[k,:] + np.power(v[:], 2) + dr2[k,:] = np.power((pos[:] - pos0[ind,:]), 2) + dt = (int_steps * (i + 1) + therm_steps) * self.es.time_step + # translational diffusion variance: after a closed-form integration of the Langevin EOM + sigma2_tr[k] = 0.0 + for j in range(3): + sigma2_tr[k] = sigma2_tr[k] + D_tr[k,j] * (2 * dt + dt0[k,j] * (- 3 + 4 * math.exp(- dt / dt0[k,j]) - math.exp( - 2 * dt / dt0[k,j]))) + dr_norm[k] = dr_norm[k] + (sum(dr2[k,:]) - sigma2_tr[k]) / sigma2_tr[k] + + tolerance = 0.15 + Ev = 0.5 * mass * v2 / (n * loops) + Eo = 0.5 * J * o2 / (n * loops) + dv = np.zeros((2)) + do = np.zeros((2)) + do_vec = np.zeros((2,3)) + for k in range(2): + dv[k] = sum(Ev[k,:]) / (3 * halfkT[k]) - 1.0 + do[k] = sum(Eo[k,:]) / (3 * halfkT[k]) - 1.0 + do_vec[k,:] = Eo[k,:] / halfkT[k] - 1.0 + dr_norm = dr_norm / (n * loops) + for k in range(2): + print("\n") + print("k = " + str(k)) + print("mass = " + str(mass)) + print("gamma_tr = {0} {1} {2}".format(gamma_tr[k,0], gamma_tr[k,1], gamma_tr[k,2])) + if test_case == 1 or test_case == 3: + print("gamma_rot = {0} {1} {2}".format(gamma_rot[k,0], gamma_rot[k,1], gamma_rot[k,2])) + else: + print("gamma_global = {0} {1} {2}".format(gamma_global[0], gamma_global[1], gamma_global[2])) + print("Moment of inertia principal components: = " + str(J)) + print("1/2 kT = " + str(halfkT[k])) + print("Translational energy: {0} {1} {2}".format(Ev[k,0], Ev[k,1], Ev[k,2])) + print("Rotational energy: {0} {1} {2}".format(Eo[k,0], Eo[k,1], Eo[k,2])) + + print("Deviation in translational energy: " + str(dv[k])) + if "ROTATION" in espressomd.features(): + print("Deviation in rotational energy: " + str(do[k])) + print("Deviation in rotational energy per degrees of freedom: {0} {1} {2}".format(do_vec[k,0], do_vec[k,1], do_vec[k,2])) + print("Deviation in translational diffusion: {0} ".format(dr_norm[k])) + + self.assertTrue(abs(dv[k]) <= tolerance, msg = 'Relative deviation in translational energy too large: {0}'.format(dv[k])) + if "ROTATION" in espressomd.features(): + self.assertTrue(abs(do[k]) <= tolerance, msg = 'Relative deviation in rotational energy too large: {0}'.format(do[k])) + self.assertTrue(abs(do_vec[k,0]) <= tolerance, msg = 'Relative deviation in rotational energy per the body axis X is too large: {0}'.format(do_vec[k,0])) + self.assertTrue(abs(do_vec[k,1]) <= tolerance, msg = 'Relative deviation in rotational energy per the body axis Y is too large: {0}'.format(do_vec[k,1])) + self.assertTrue(abs(do_vec[k,2]) <= tolerance, msg = 'Relative deviation in rotational energy per the body axis Z is too large: {0}'.format(do_vec[k,2])) + self.assertTrue(abs(dr_norm[k]) <= tolerance, msg = 'Relative deviation in translational diffusion is too large: {0}'.format(dr_norm[k])) + + def test(self): + for i in range(4): + self.run_test_case(i) + +if __name__ == '__main__': + print("Features: ", espressomd.features()) + ut.main() From fe27b6164feb8427a01de628d18d259ad2f4f36c Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Wed, 13 Sep 2017 01:33:16 +0300 Subject: [PATCH 002/150] Partial fix of the BD thermo test --- src/core/integrate.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index f3a795bc5b8..e24847f4b6a 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1633,8 +1633,9 @@ void bd_random_walk_vel(Particle *p, double dt) { #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 12.0; // Is a particle-specific temperature specified? + // here, the time_step is used only to align with Espresso default dimensionless model if (p->p.T >= 0.) - brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T); + brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T) * time_step; else brown_sigma_vel_temp = brown_sigma_vel; #endif /* LANGEVIN_PER_PARTICLE */ @@ -1645,9 +1646,7 @@ void bd_random_walk_vel(Particle *p, double dt) { #endif { // velocity is added here. It is assigned in the drift part. - // here, the time_step is used only to align with Espresso default dimensionless model - p->m.v[j] += brown_sigma_vel_temp * Thermostat::noise() * time_step - / sqrt(p->p.mass); + p->m.v[j] += brown_sigma_vel_temp * Thermostat::noise() / sqrt(p->p.mass); } } } From 25348997b22ac402e93eec4bc8deaa7fd5c84436 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 16 Sep 2017 20:50:58 +0300 Subject: [PATCH 003/150] Fix --- src/core/integrate.cpp | 67 +++++++++++-------- ...mass-and-rinertia-brownian_per_particle.py | 2 +- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index e24847f4b6a..fffe3da3a57 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -712,6 +712,12 @@ void rescale_forces_propagate_vel() { if (ifParticleIsVirtual(&p[i])) continue; #endif +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift_vel(&(p[i]),0.5 * time_step); + bd_random_walk_vel(&(p[i]),0.5 * time_step); + } +#endif // BROWNIAN_DYNAMICS for (j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p[i].p.ext_flag & COORD_FIXED(j))) { @@ -732,10 +738,7 @@ void rescale_forces_propagate_vel() { #endif { #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drift_vel(&(p[i]),0.5 * time_step); - bd_random_walk_vel(&(p[i]),0.5 * time_step); - } else + if (!(thermo_switch & THERMO_BROWNIAN)) #endif // BROWNIAN_DYNAMICS { /* Propagate velocity: v(t+dt) = v(t+0.5*dt) + 0.5*dt * f(t+dt) */ @@ -959,6 +962,14 @@ void propagate_vel() { if (ifParticleIsVirtual(&p[i])) continue; #endif +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift_vel(&(p[i]),0.5 * time_step); + bd_drift_vel_rot(&(p[i]),0.5 * time_step); + bd_random_walk_vel(&(p[i]),0.5 * time_step); + bd_random_walk_vel_rot(&(p[i]),0.5 * time_step); + } +#endif // BROWNIAN_DYNAMICS for (j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p[i].p.ext_flag & COORD_FIXED(j))) @@ -980,12 +991,7 @@ void propagate_vel() { #endif { #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drift_vel(&(p[i]),0.5 * time_step); - bd_drift_vel_rot(&(p[i]),0.5 * time_step); - bd_random_walk_vel(&(p[i]),0.5 * time_step); - bd_random_walk_vel_rot(&(p[i]),0.5 * time_step); - } else + if (!(thermo_switch & THERMO_BROWNIAN)) #endif // BROWNIAN_DYNAMICS { /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5*dt * f(t) */ @@ -1041,6 +1047,14 @@ void propagate_pos() { if (ifParticleIsVirtual(&p[i])) continue; #endif +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift(&(p[i]), time_step); + bd_drift_rot(&(p[i]), time_step); + bd_random_walk(&(p[i]), time_step); + bd_random_walk_rot(&(p[i]), time_step); + } +#endif // BROWNIAN_DYNAMICS for (j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p[i].p.ext_flag & COORD_FIXED(j))) @@ -1052,12 +1066,7 @@ void propagate_pos() { nemd_add_velocity(&p[i]); #endif #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drift(&(p[i]), time_step); - bd_drift_rot(&(p[i]), time_step); - bd_random_walk(&(p[i]), time_step); - bd_random_walk_rot(&(p[i]), time_step); - } else + if (!(thermo_switch & THERMO_BROWNIAN)) #endif // BROWNIAN_DYNAMICS { /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * @@ -1109,18 +1118,25 @@ void propagate_vel_pos() { if (ifParticleIsVirtual(&p[i])) continue; #endif +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) { + bd_drift_vel(&(p[i]),0.5 * time_step); + bd_drift_vel_rot(&(p[i]),0.5 * time_step); + bd_random_walk_vel(&(p[i]),0.5 * time_step); + bd_random_walk_vel_rot(&(p[i]),0.5 * time_step); + bd_drift(&(p[i]), time_step); + bd_drift_rot(&(p[i]), time_step); + bd_random_walk(&(p[i]), time_step); + bd_random_walk_rot(&(p[i]), time_step); + } +#endif // BROWNIAN_DYNAMICS for (j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p[i].p.ext_flag & COORD_FIXED(j))) #endif { #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drift_vel(&(p[i]),0.5 * time_step); - bd_drift_vel_rot(&(p[i]),0.5 * time_step); - bd_random_walk_vel(&(p[i]),0.5 * time_step); - bd_random_walk_vel_rot(&(p[i]),0.5 * time_step); - } else + if (!(thermo_switch & THERMO_BROWNIAN)) #endif // BROWNIAN_DYNAMICS { /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5*dt * f(t) */ @@ -1132,12 +1148,7 @@ void propagate_vel_pos() { #endif { #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drift(&(p[i]), time_step); - bd_drift_rot(&(p[i]), time_step); - bd_random_walk(&(p[i]), time_step); - bd_random_walk_rot(&(p[i]), time_step); - } else + if (!(thermo_switch & THERMO_BROWNIAN)) #endif // BROWNIAN_DYNAMICS { /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * diff --git a/testsuite/python/mass-and-rinertia-brownian_per_particle.py b/testsuite/python/mass-and-rinertia-brownian_per_particle.py index de7bf3cb142..c4621e9625f 100644 --- a/testsuite/python/mass-and-rinertia-brownian_per_particle.py +++ b/testsuite/python/mass-and-rinertia-brownian_per_particle.py @@ -67,7 +67,7 @@ def run_test_case(self, test_case): # no need to rebuild Verlet lists, avoid it self.es.cell_system.skin = 5.0 - self.es.time_step = 0.03 + self.es.time_step = 0.3 n = 200 mass = (0.2 + random()) * 7.0 J = np.array((0.2 + random(3)) * 7.0) From ec686535793e6d60037e83a07914405adbe30c7d Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 20 Oct 2017 00:54:37 +0300 Subject: [PATCH 004/150] maxset build fix --- src/core/rotation.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index a3ab2ecd2cb..d886f780f9b 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -631,6 +631,8 @@ void rotate_particle_body_j(Particle* p, int j, double phi) } } +#ifdef BROWNIAN_DYNAMICS + void bd_drift_rot(Particle *p, double dt) { int j; double a[3]; @@ -828,4 +830,6 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { } } +#endif // BROWNIAN_DYNAMICS + #endif From d4836e33298f4498b5b03b5237e67679008614cc Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 20 Oct 2017 00:57:09 +0300 Subject: [PATCH 005/150] Travis BD improvement --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 568dde7dbcd..228d37654ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,11 +13,15 @@ matrix: - os: linux sudo: required services: docker - env: myconfig=maxset-bd + env: myconfig=maxset-bd with_coverage=true - os: linux sudo: required services: docker env: myconfig=maxset image=ubuntu-python3 + - os: linux + sudo: required + services: docker + env: myconfig=maxset-bd image=ubuntu-python3 - os: linux sudo: required services: docker From d551f17bfa58da70e96755e7e284b645d1fa7e93 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 24 Oct 2017 01:00:05 +0300 Subject: [PATCH 006/150] BD maxset update by head changes --- maintainer/configs/maxset-bd.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/maintainer/configs/maxset-bd.hpp b/maintainer/configs/maxset-bd.hpp index 453fff89e81..ee1b03e9d7a 100755 --- a/maintainer/configs/maxset-bd.hpp +++ b/maintainer/configs/maxset-bd.hpp @@ -1,6 +1,7 @@ /* maximal set of features usable at the same time */ #define PARTIAL_PERIODIC #define ELECTROSTATICS +#define COULOMB_DEBYE_HUECKEL #define DIPOLES #define ROTATION #define ROTATIONAL_INERTIA @@ -17,12 +18,12 @@ #define MODES #endif +#define BOND_CONSTRAINT #define BOND_VIRTUAL #define COLLISION_DETECTION #define LANGEVIN_PER_PARTICLE #define ROTATION_PER_PARTICLE #define CATALYTIC_REACTIONS -#define REACTION_ENSEMBLE #define NEMD #define NPT @@ -79,7 +80,4 @@ #define VIRTUAL_SITES_RELATIVE #define FLATNOISE - - - - +#define ADDITIONAL_CHECKS From ea20f77f53ccc38eb375006c3c11f1767b0730a7 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 24 Oct 2017 01:00:14 +0300 Subject: [PATCH 007/150] BD thermo test merge into LD test as test cases --- ...mass-and-rinertia-brownian_per_particle.py | 194 ------------------ testsuite/mass-and-rinertia_per_particle.py | 142 ++++++++++--- 2 files changed, 113 insertions(+), 223 deletions(-) delete mode 100644 testsuite/mass-and-rinertia-brownian_per_particle.py diff --git a/testsuite/mass-and-rinertia-brownian_per_particle.py b/testsuite/mass-and-rinertia-brownian_per_particle.py deleted file mode 100644 index 071e6033352..00000000000 --- a/testsuite/mass-and-rinertia-brownian_per_particle.py +++ /dev/null @@ -1,194 +0,0 @@ -from __future__ import print_function -import unittest as ut -import numpy as np -from numpy.random import random,seed -import espressomd -import math - -@ut.skipIf(not espressomd.has_features(["MASS","ROTATIONAL_INERTIA","LANGEVIN_PER_PARTICLE","BROWNIAN_DYNAMICS"]), - "Features not available, skipping test!") -class ThermoTest(ut.TestCase): - longMessage = True - # Handle for espresso system - es = espressomd.System() - - def run_test_case(self, test_case): - seed(1) - - for i in range(len(self.es.part)): - self.es.part[i].remove() - - # thermalization - # Checks if every degree of freedom has 1/2 kT of energy, even when - # mass and inertia tensor are active - - # 2 different langevin parameters for particles - temp = np.array([2.5, 2.0]) - # gamma_tran/gamma_rot matrix: [2 types of particless] x [3 dimensions X Y Z] - gamma_tran = np.zeros((2,3)) - gamma_tr = np.zeros((2,3)) - gamma_rot = np.zeros((2,3)) - D_tr = np.zeros((2,3)) - for k in range(2): - if "PARTICLE_ANISOTROPY" in espressomd.features(): - gamma_tran[k,:] = np.array((0.4 + random(3)) * 10) - else: - gamma_tran[k,0] = np.array((0.4 + random(1)) * 10) - gamma_tran[k,1] = gamma_tran[k,0] - gamma_tran[k,2] = gamma_tran[k,0] - gamma_rot[k,:] = np.array((0.2 + random(3)) * 20) - - box = 10.0 - self.es.box_l = [box, box, box] - if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.es.periodicity=0,0,0 - kT = 1.5 - gamma_global = np.ones((3)) - - if test_case == 2 or test_case == 3: - halfkT = temp / 2.0 - else: - halfkT = np.array([kT, kT]) / 2.0 - - if test_case == 1 or test_case == 3: - gamma_tr = gamma_tran - else: - for k in range(2): - gamma_tr[k,:] = gamma_global[:] - - # translational diffusion - for k in range(2): - D_tr[k,:] = 2.0 * halfkT[k] / gamma_tr[k,:] - - if "PARTICLE_ANISOTROPY" in espressomd.features(): - self.es.thermostat.set_brownian(kT=kT, gamma=[gamma_global[0],gamma_global[1],gamma_global[2]]) - else: - self.es.thermostat.set_brownian(kT=kT, gamma=gamma_global[0]) - - # no need to rebuild Verlet lists, avoid it - self.es.cell_system.skin = 5.0 - self.es.time_step = 0.3 - n = 200 - mass = (0.2 + random()) * 7.0 - J = np.array((0.2 + random(3)) * 7.0) - - for i in range(n): - for k in range(2): - ind = i + k * n - part_pos = np.array(random(3) * box) - part_v = np.array([0.0, 0.0, 0.0]) - part_omega_body = np.array([0.0, 0.0, 0.0]) - self.es.part.add(rotation=(1,1,1), id = ind, mass = mass, rinertia = J, pos = part_pos, v = part_v) - if "ROTATION" in espressomd.features(): - self.es.part[ind].omega_body = part_omega_body - if test_case == 1: - if "PARTICLE_ANISOTROPY" in espressomd.features(): - self.es.part[ind].gamma = gamma_tran[k,:] - else: - self.es.part[ind].gamma = gamma_tran[k,0] - if "ROTATION" in espressomd.features(): - self.es.part[ind].gamma_rot = gamma_rot[k,:] - - if test_case == 2: - self.es.part[ind].temp = temp[k] - if test_case == 3: - if "PARTICLE_ANISOTROPY" in espressomd.features(): - self.es.part[ind].gamma = gamma_tran[k,:] - else: - self.es.part[ind].gamma = gamma_tran[k,0] - if "ROTATION" in espressomd.features(): - self.es.part[ind].gamma_rot = gamma_rot[k,:] - self.es.part[ind].temp = temp[k] - - # Get rid of short range calculations if exclusions are on - #if espressomd.has_features("EXCLUSIONS"): - - - # matrices: [2 types of particless] x [3 dimensions X Y Z] - # velocity^2, omega^2, position^2 - v2 = np.zeros((2,3)) - o2 = np.zeros((2,3)) - dr2 = np.zeros((2,3)) - sigma2_tr = np.zeros((2)) - dr_norm = np.zeros((2)) - - pos0 = np.zeros((2 * n, 3)) - for p in range(n): - for k in range(2): - ind = p + k * n - pos0[ind,:] = self.es.part[ind].pos - dt0 = mass / gamma_tr - - loops = 200 - print("Thermalizing...") - therm_steps = 150 - self.es.integrator.run(therm_steps) - print("Measuring...") - - int_steps = 5 - for i in range(loops): - self.es.integrator.run(int_steps) - # Get kinetic energy in each degree of freedom for all particles - for p in range(n): - for k in range(2): - ind = p + k * n - v = self.es.part[ind].v - if "ROTATION" in espressomd.features(): - o = self.es.part[ind].omega_body - o2[k,:] = o2[k,:] + np.power(o[:], 2) - pos = self.es.part[ind].pos - v2[k,:] = v2[k,:] + np.power(v[:], 2) - dr2[k,:] = np.power((pos[:] - pos0[ind,:]), 2) - dt = (int_steps * (i + 1) + therm_steps) * self.es.time_step - # translational diffusion variance: after a closed-form integration of the Langevin EOM - sigma2_tr[k] = 0.0 - for j in range(3): - sigma2_tr[k] = sigma2_tr[k] + D_tr[k,j] * (2 * dt + dt0[k,j] * (- 3 + 4 * math.exp(- dt / dt0[k,j]) - math.exp( - 2 * dt / dt0[k,j]))) - dr_norm[k] = dr_norm[k] + (sum(dr2[k,:]) - sigma2_tr[k]) / sigma2_tr[k] - - tolerance = 0.15 - Ev = 0.5 * mass * v2 / (n * loops) - Eo = 0.5 * J * o2 / (n * loops) - dv = np.zeros((2)) - do = np.zeros((2)) - do_vec = np.zeros((2,3)) - for k in range(2): - dv[k] = sum(Ev[k,:]) / (3 * halfkT[k]) - 1.0 - do[k] = sum(Eo[k,:]) / (3 * halfkT[k]) - 1.0 - do_vec[k,:] = Eo[k,:] / halfkT[k] - 1.0 - dr_norm = dr_norm / (n * loops) - for k in range(2): - print("\n") - print("k = " + str(k)) - print("mass = " + str(mass)) - print("gamma_tr = {0} {1} {2}".format(gamma_tr[k,0], gamma_tr[k,1], gamma_tr[k,2])) - if test_case == 1 or test_case == 3: - print("gamma_rot = {0} {1} {2}".format(gamma_rot[k,0], gamma_rot[k,1], gamma_rot[k,2])) - else: - print("gamma_global = {0} {1} {2}".format(gamma_global[0], gamma_global[1], gamma_global[2])) - print("Moment of inertia principal components: = " + str(J)) - print("1/2 kT = " + str(halfkT[k])) - print("Translational energy: {0} {1} {2}".format(Ev[k,0], Ev[k,1], Ev[k,2])) - print("Rotational energy: {0} {1} {2}".format(Eo[k,0], Eo[k,1], Eo[k,2])) - - print("Deviation in translational energy: " + str(dv[k])) - if "ROTATION" in espressomd.features(): - print("Deviation in rotational energy: " + str(do[k])) - print("Deviation in rotational energy per degrees of freedom: {0} {1} {2}".format(do_vec[k,0], do_vec[k,1], do_vec[k,2])) - print("Deviation in translational diffusion: {0} ".format(dr_norm[k])) - - self.assertTrue(abs(dv[k]) <= tolerance, msg = 'Relative deviation in translational energy too large: {0}'.format(dv[k])) - if "ROTATION" in espressomd.features(): - self.assertTrue(abs(do[k]) <= tolerance, msg = 'Relative deviation in rotational energy too large: {0}'.format(do[k])) - self.assertTrue(abs(do_vec[k,0]) <= tolerance, msg = 'Relative deviation in rotational energy per the body axis X is too large: {0}'.format(do_vec[k,0])) - self.assertTrue(abs(do_vec[k,1]) <= tolerance, msg = 'Relative deviation in rotational energy per the body axis Y is too large: {0}'.format(do_vec[k,1])) - self.assertTrue(abs(do_vec[k,2]) <= tolerance, msg = 'Relative deviation in rotational energy per the body axis Z is too large: {0}'.format(do_vec[k,2])) - self.assertTrue(abs(dr_norm[k]) <= tolerance, msg = 'Relative deviation in translational diffusion is too large: {0}'.format(dr_norm[k])) - - def test(self): - for i in range(4): - self.run_test_case(i) - -if __name__ == '__main__': - print("Features: ", espressomd.features()) - ut.main() diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index c367076f334..4471a23a010 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -17,11 +17,13 @@ class ThermoTest(ut.TestCase): es = espressomd.System() def run_test_case(self, test_case): + self.es.thermostat.turn_off() gamma = np.array([1.0, 1.0]) # Decelleration self.es.time_step = 0.007 - self.es.thermostat.set_langevin(kT=0.0, gamma=gamma[0]) + if not "BROWNIAN_DYNAMICS" in espressomd.features(): + self.es.thermostat.set_langevin(kT=0.0, gamma=gamma[0]) self.es.cell_system.skin = 5.0 seed(1) mass = 12.74 @@ -41,6 +43,9 @@ def run_test_case(self, test_case): print("\n") if test_case == 0: + print("================================================") + print("Group of test cases 0-3: Langevin thermostat") + print("================================================") print("------------------------------------------------") print("Test " + str(test_case) + ": no particle specific values") print("------------------------------------------------") @@ -95,21 +100,82 @@ def run_test_case(self, test_case): self.es.part[1].gamma_rot = np.array( [gamma[1], gamma[1], gamma[1]]) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + if test_case == 4: + print("================================================") + print("Group of test cases 4-7: Brownian thermostat") + print("================================================") + print("------------------------------------------------") + print("Test " + str(test_case) + ": no particle specific values") + print("------------------------------------------------") + gamma[1] = gamma[0] + + if test_case == 5: + print("------------------------------------------------") + print("Test " + str(test_case) + + ": particle specific gamma but not temperature") + print("------------------------------------------------") + if "PARTICLE_ANISOTROPY" in espressomd.features(): + self.es.part[0].gamma = np.array( + [gamma[0], gamma[0], gamma[0]]) + self.es.part[1].gamma = np.array( + [gamma[1], gamma[1], gamma[1]]) + else: + self.es.part[0].gamma = gamma[0] + self.es.part[1].gamma = gamma[1] + if "ROTATION" in espressomd.features(): + self.es.part[0].gamma_rot = np.array( + [gamma[0], gamma[0], gamma[0]]) + self.es.part[1].gamma_rot = np.array( + [gamma[1], gamma[1], gamma[1]]) + + if test_case == 6: + print("------------------------------------------------") + print("Test " + str(test_case) + + ": particle specific temperature but not gamma") + print("------------------------------------------------") + self.es.part[0].temp = 0.0 + self.es.part[1].temp = 0.0 + gamma[1] = gamma[0] + + if test_case == 7: + print("------------------------------------------------") + print("Test " + str(test_case) + + ": both particle specific gamma and temperature") + print("------------------------------------------------") + self.es.part[0].temp = 0.0 + self.es.part[1].temp = 0.0 + if "PARTICLE_ANISOTROPY" in espressomd.features(): + self.es.part[0].gamma = np.array( + [gamma[0], gamma[0], gamma[0]]) + self.es.part[1].gamma = np.array( + [gamma[1], gamma[1], gamma[1]]) + else: + self.es.part[0].gamma = gamma[0] + self.es.part[1].gamma = gamma[1] + if "ROTATION" in espressomd.features(): + self.es.part[0].gamma_rot = np.array( + [gamma[0], gamma[0], gamma[0]]) + self.es.part[1].gamma_rot = np.array( + [gamma[1], gamma[1], gamma[1]]) + self.es.time = 0.0 - tol = 1.25E-4 - for i in range(100): - for k in range(3): - self.assertLess( - abs(self.es.part[0].v[k] - math.exp(- gamma[0] * self.es.time / mass)), tol) - self.assertLess( - abs(self.es.part[1].v[k] - math.exp(- gamma[1] * self.es.time / mass)), tol) - if "ROTATION" in espressomd.features(): - self.assertLess(abs( - self.es.part[0].omega_body[k] - math.exp(- gamma[0] * self.es.time / J[k])), tol) - self.assertLess(abs( - self.es.part[1].omega_body[k] - math.exp(- gamma[1] * self.es.time / J[k])), tol) - self.es.integrator.run(10) + if not "BROWNIAN_DYNAMICS" in espressomd.features(): + tol = 1.25E-4 + for i in range(100): + for k in range(3): + self.assertLess( + abs(self.es.part[0].v[k] - math.exp(- gamma[0] * self.es.time / mass)), tol) + self.assertLess( + abs(self.es.part[1].v[k] - math.exp(- gamma[1] * self.es.time / mass)), tol) + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + self.es.part[0].omega_body[k] - math.exp(- gamma[0] * self.es.time / J[k])), tol) + self.assertLess(abs( + self.es.part[1].omega_body[k] - math.exp(- gamma[1] * self.es.time / J[k])), tol) + self.es.integrator.run(10) + # TODO: start the BD drift test here from the Brownian thermostat activation. for i in range(len(self.es.part)): self.es.part[i].remove() @@ -142,12 +208,12 @@ def run_test_case(self, test_case): kT = 1.5 gamma_global = np.ones((3)) - if test_case == 2 or test_case == 3: + if test_case in [2,3,6,7]: halfkT = temp / 2.0 else: halfkT = np.array([kT, kT]) / 2.0 - if test_case == 1 or test_case == 3: + if test_case in [1,3,5,7]: gamma_tr = gamma_tran else: for k in range(2): @@ -158,18 +224,32 @@ def run_test_case(self, test_case): D_tr[k, :] = 2.0 * halfkT[k] / gamma_tr[k, :] if "PARTICLE_ANISOTROPY" in espressomd.features(): - self.es.thermostat.set_langevin( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) + if test_case < 4: + self.es.thermostat.set_langevin( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) + else: + self.es.thermostat.set_brownian( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) else: - self.es.thermostat.set_langevin(kT=kT, gamma=gamma_global[0]) + if test_case < 4: + self.es.thermostat.set_langevin(kT=kT, gamma=gamma_global[0]) + else: + self.es.thermostat.set_brownian(kT=kT, gamma=gamma_global[0]) # no need to rebuild Verlet lists, avoid it self.es.cell_system.skin = 5.0 - self.es.time_step = 0.03 + if test_case < 4: + self.es.time_step = 0.03 + else: + self.es.time_step = 0.3 n = 200 mass = (0.2 + random()) * 7.0 J = np.array((0.2 + random(3)) * 7.0) @@ -184,7 +264,7 @@ def run_test_case(self, test_case): pos=part_pos, v=part_v) if "ROTATION" in espressomd.features(): self.es.part[ind].omega_body = part_omega_body - if test_case == 1: + if test_case in [1,5]: if "PARTICLE_ANISOTROPY" in espressomd.features(): self.es.part[ind].gamma = gamma_tran[k, :] else: @@ -192,9 +272,9 @@ def run_test_case(self, test_case): if "ROTATION" in espressomd.features(): self.es.part[ind].gamma_rot = gamma_rot[k, :] - if test_case == 2: + if test_case in [2,6]: self.es.part[ind].temp = temp[k] - if test_case == 3: + if test_case in [3,7]: if "PARTICLE_ANISOTROPY" in espressomd.features(): self.es.part[ind].gamma = gamma_tran[k, :] else: @@ -272,7 +352,7 @@ def run_test_case(self, test_case): print("mass = " + str(mass)) print("gamma_tr = {0} {1} {2}".format( gamma_tr[k, 0], gamma_tr[k, 1], gamma_tr[k, 2])) - if test_case == 1 or test_case == 3: + if test_case in [1,5,3,7]: print("gamma_rot = {0} {1} {2}".format( gamma_rot[k, 0], gamma_rot[k, 1], gamma_rot[k, 2])) else: @@ -321,7 +401,11 @@ def run_test_case(self, test_case): dr_norm[k])) def test(self): - for i in range(4): + if not "BROWNIAN_DYNAMICS" in espressomd.features(): + n_test_cases = 4 + else: + n_test_cases = 8 + for i in range(n_test_cases): self.run_test_case(i) From f13c04f6346b428084a26da0f24f5a14640b9fea Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 24 Oct 2017 01:12:39 +0300 Subject: [PATCH 008/150] Travis BD test infra fix --- testsuite/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 9c697126e4d..00813ddba18 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -38,7 +38,6 @@ python_test(FILE ewald_gpu.py MAX_NUM_PROC 4) python_test(FILE icc.py MAX_NUM_PROC 4) python_test(FILE magnetostaticInteractions.py MAX_NUM_PROC 1) python_test(FILE mass-and-rinertia_per_particle.py MAX_NUM_PROC 1) -python_test(FILE mass-and-rinertia-brownian_per_particle.py MAX_NUM_PROC 1) python_test(FILE interactions_bond_angle.py MAX_NUM_PROC 4) python_test(FILE interactions_bonded_interface.py MAX_NUM_PROC 4) python_test(FILE interactions_bonded.py MAX_NUM_PROC 2) From c51d96f9c4e9c2e8ee62e1239c82cda4524cec2d Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 29 Oct 2017 09:36:01 +0200 Subject: [PATCH 009/150] Drift test stub --- testsuite/mass-and-rinertia_per_particle.py | 29 ++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 4471a23a010..f5acb27a0cc 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -21,9 +21,6 @@ def run_test_case(self, test_case): gamma = np.array([1.0, 1.0]) # Decelleration - self.es.time_step = 0.007 - if not "BROWNIAN_DYNAMICS" in espressomd.features(): - self.es.thermostat.set_langevin(kT=0.0, gamma=gamma[0]) self.es.cell_system.skin = 5.0 seed(1) mass = 12.74 @@ -161,7 +158,9 @@ def run_test_case(self, test_case): self.es.time = 0.0 - if not "BROWNIAN_DYNAMICS" in espressomd.features(): + if test_case < 4: + self.es.time_step = 0.007 + self.es.thermostat.set_langevin(kT=0.0, gamma=gamma[0]) tol = 1.25E-4 for i in range(100): for k in range(3): @@ -175,7 +174,25 @@ def run_test_case(self, test_case): self.assertLess(abs( self.es.part[1].omega_body[k] - math.exp(- gamma[1] * self.es.time / J[k])), tol) self.es.integrator.run(10) - # TODO: start the BD drift test here from the Brownian thermostat activation. + # BD drift test + else: + # Brownian dynamics is designed for larger time-steps + # propagate for time_step >> max(tau0_tran, tau0_rot) + # tau0_tran = mass / gamma = 12.74 / 1.0 + # tau0_rot = I / gamma = 10 / 1.0 + # Hence, let's select time_step ~ 100 + self.es.time_step = 100 + # Brownian thermostat activation + self.es.thermostat.set_brownian(kT=0.0, gamma=gamma[0]) + if "EXTERNAL_FORCES" in espressomd.features(): + f1 = np.array([-1.2, 58.3578, 0.002]) + f2 = np.array([-15.112, -2.0, 368]) + self.es.part[0].ext_force = f1 + self.es.part[1].ext_force = f2 + for i in range(100): + self.es.integrator.run(1) + for k in range(3): + # TODO for i in range(len(self.es.part)): self.es.part[i].remove() @@ -249,7 +266,7 @@ def run_test_case(self, test_case): if test_case < 4: self.es.time_step = 0.03 else: - self.es.time_step = 0.3 + self.es.time_step = 10 n = 200 mass = (0.2 + random()) * 7.0 J = np.array((0.2 + random(3)) * 7.0) From 30112e5446a8603e0e697068ca3a0572340bfd7e Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 29 Oct 2017 19:23:40 +0200 Subject: [PATCH 010/150] Drift accuracy calc improvement --- src/core/rotation.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 09e0f296cc2..579e3088204 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -635,7 +635,8 @@ void rotate_particle_body_j(Particle* p, int j, double phi) void bd_drift_rot(Particle *p, double dt) { int j; double a[3]; - double dphi[3]; + double dphi[3], dphi_u[3]; + double dphi_m; Thermostat::GammaType local_gamma; a[0] = a[1] = a[2] = 1.0; @@ -653,20 +654,27 @@ void bd_drift_rot(Particle *p, double dt) { if(p->p.gamma_rot >= Thermostat::GammaType{}) local_gamma = p->p.gamma_rot; else local_gamma = langevin_gamma_rotation; + dphi[0] = dphi[1] = dphi[2] = 0.0; for (j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif { - dphi[0] = dphi[1] = dphi[2] = 0.0; // only a conservative part of the torque is used here #ifndef PARTICLE_ANISOTROPY dphi[j] = a[j] * p->f.torque[j] * dt / (local_gamma); #else dphi[j] = a[j] * p->f.torque[j] * dt / (local_gamma[j]); #endif // ROTATIONAL_INERTIA - rotate_particle_body_j(p, j, dphi[j]); + //rotate_particle_body_j(p, j, dphi[j]); } + } //j + dphi_m = 0.0; + for (j = 0; j < 3; j++) dphi_m += pow(dphi[j], 2); + dphi_m = sqrt(dphi_m); + if (dphi_m) { + for (j = 0; j < 3; j++) dphi_u[j] = dphi[j] / dphi_m; + rotate_particle_body(p, dphi_u, dphi_m); } } From 3a697dbf1c9d241dc7bc1ed21faeace03532f489 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 29 Oct 2017 19:24:36 +0200 Subject: [PATCH 011/150] Positional drift tests: rotational and translational ones --- testsuite/mass-and-rinertia_per_particle.py | 42 +++++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index d0dcd320d86..e1a18f9eaad 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -230,18 +230,40 @@ def run_test_case(self, test_case): tor1 = np.array([-0.03, -174, 368]) self.es.part[0].ext_torque = tor0 self.es.part[1].ext_torque = tor1 + # Let's set the dipole perpendicular to the torque + if "DIPOLES" in espressomd.features(): + dip0 = np.array([0.0, tor0[2], -tor0[1]]) + dip1 = np.array([-tor1[2], 0.0, tor1[0]]) + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 for i in range(100): - self.es.integrator.run(1) + self.es.integrator.run(10) + #print("i = {0}".format(i)) for k in range(3): self.assertLess( abs(self.es.part[0].v[k] - f0[k] / gamma_tr[0, k]), tol) self.assertLess( abs(self.es.part[1].v[k] - f1[k] / gamma_tr[1, k]), tol) + self.assertLess( + abs(self.es.part[0].pos[k] - self.es.time * f0[k] / gamma_tr[0, k]), tol) + self.assertLess( + abs(self.es.part[1].pos[k] - self.es.time * f1[k] / gamma_tr[1, k]), tol) if "ROTATION" in espressomd.features(): self.assertLess(abs( self.es.part[0].omega_lab[k] - tor0[k] / gamma_rot_validate[0, k]), tol) self.assertLess(abs( self.es.part[1].omega_lab[k] - tor1[k] / gamma_rot_validate[1, k]), tol) + if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): + cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) + cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0]) + + cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) + cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0]) + + #print("cos_alpha0 = {0}, cos_alpha0_test={1}".format(cos_alpha0, cos_alpha0_test)) + #print("dip0 = {0}, self.es.part[0].dip={1}".format(dip0, self.es.part[0].dip)) + self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) + self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) for i in range(len(self.es.part)): self.es.part[i].remove() @@ -296,17 +318,21 @@ def run_test_case(self, test_case): gamma_global[1], gamma_global[2]]) else: - self.es.thermostat.set_brownian( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) else: if test_case < 4: self.es.thermostat.set_langevin(kT=kT, gamma=gamma_global[0]) else: - self.es.thermostat.set_brownian(kT=kT, gamma=gamma_global[0]) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=kT, gamma=gamma_global[0]) # no need to rebuild Verlet lists, avoid it self.es.cell_system.skin = 5.0 From b030f9a8b091ed9d010b67523caaeaf0e982e6c5 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 29 Oct 2017 20:40:33 +0200 Subject: [PATCH 012/150] The sin() validation in the drift tests --- testsuite/mass-and-rinertia_per_particle.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index e1a18f9eaad..5100d033602 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -236,6 +236,8 @@ def run_test_case(self, test_case): dip1 = np.array([-tor1[2], 0.0, tor1[0]]) self.es.part[0].dip = dip0 self.es.part[1].dip = dip1 + tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) + tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) for i in range(100): self.es.integrator.run(10) #print("i = {0}".format(i)) @@ -256,14 +258,20 @@ def run_test_case(self, test_case): if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0]) + sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) + sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0])) cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0]) + sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) + sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0])) #print("cos_alpha0 = {0}, cos_alpha0_test={1}".format(cos_alpha0, cos_alpha0_test)) #print("dip0 = {0}, self.es.part[0].dip={1}".format(dip0, self.es.part[0].dip)) self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) + self.assertEqual(sgn0, sgn0_test) + self.assertEqual(sgn1, sgn1_test) for i in range(len(self.es.part)): self.es.part[i].remove() From 8da44b5cd61a425fc008102780579496255f1d04 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 29 Oct 2017 22:00:49 +0200 Subject: [PATCH 013/150] Tolerance tuning --- testsuite/mass-and-rinertia_per_particle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 5100d033602..00d2981c022 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -213,7 +213,7 @@ def run_test_case(self, test_case): self.es.integrator.run(10) # Brownian dynamics drift test else: - tol = 1.25E-4 + tol = 1.27E-6 # Brownian dynamics is designed for larger time-steps # propagate for time_step >> max(tau0_tran, tau0_rot) # tau0_tran = mass / gamma = 12.74 / 1.0 From 6e971c334eeccb32424166bb410e85422ad16d54 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Mon, 6 Nov 2017 00:57:31 +0200 Subject: [PATCH 014/150] Test utils: reference frame conversion --- testsuite/rotational_inertia.py | 36 +++++++-------------------------- testsuite/tests_common.py | 23 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/testsuite/rotational_inertia.py b/testsuite/rotational_inertia.py index 6852b1bd35e..79bd03ff739 100644 --- a/testsuite/rotational_inertia.py +++ b/testsuite/rotational_inertia.py @@ -3,6 +3,7 @@ import numpy as np import espressomd import math +import tests_common as tc @ut.skipIf(not espressomd.has_features(["MASS", "ROTATIONAL_INERTIA"]), @@ -13,29 +14,6 @@ class RotationalInertia(ut.TestCase): es = espressomd.System() es.cell_system.skin = 0 - def define_rotation_matrix(self, part): - A = np.zeros((3, 3)) - quat = self.es.part[part].quat - qq = np.power(quat, 2) - - A[0, 0] = qq[0] + qq[1] - qq[2] - qq[3] - A[1, 1] = qq[0] - qq[1] + qq[2] - qq[3] - A[2, 2] = qq[0] - qq[1] - qq[2] + qq[3] - - A[0, 1] = 2 * (quat[1] * quat[2] + quat[0] * quat[3]) - A[0, 2] = 2 * (quat[1] * quat[3] - quat[0] * quat[2]) - A[1, 0] = 2 * (quat[1] * quat[2] - quat[0] * quat[3]) - - A[1, 2] = 2 * (quat[2] * quat[3] + quat[0] * quat[1]) - A[2, 0] = 2 * (quat[1] * quat[3] + quat[0] * quat[2]) - A[2, 1] = 2 * (quat[2] * quat[3] - quat[0] * quat[1]) - - return A - - def convert_vec_body_to_space(self, part, vec): - A = self.define_rotation_matrix(part) - return np.dot(A.transpose(), vec) - # Angular momentum def L_body(self, part): return self.es.part[part].omega_body[:] * \ @@ -63,11 +41,11 @@ def test_stability(self): # Angular momentum L_0_body = self.L_body(0) - L_0_lab = self.convert_vec_body_to_space(0, L_0_body) + L_0_lab = tc.convert_vec_body_to_space(self.es, 0, L_0_body) for i in range(100): L_body = self.L_body(0) - L_lab = self.convert_vec_body_to_space(0, L_body) + L_lab = tc.convert_vec_body_to_space(self.es, 0, L_body) for k in range(3): self.assertLessEqual( abs( @@ -99,11 +77,11 @@ def test_stability(self): self.es.part[0].rinertia = J[:] L_0_body = self.L_body(0) - L_0_lab = self.convert_vec_body_to_space(0, L_0_body) + L_0_lab = tc.convert_vec_body_to_space(self.es, 0, L_0_body) for i in range(100): L_body = self.L_body(0) - L_lab = self.convert_vec_body_to_space(0, L_body) + L_lab = tc.convert_vec_body_to_space(self.es, 0, L_body) for k in range(3): self.assertLessEqual( abs( @@ -135,11 +113,11 @@ def test_stability(self): self.es.part[0].rinertia = J[:] L_0_body = self.L_body(0) - L_0_lab = self.convert_vec_body_to_space(0, L_0_body) + L_0_lab = tc.convert_vec_body_to_space(self.es, 0, L_0_body) for i in range(100): L_body = self.L_body(0) - L_lab = self.convert_vec_body_to_space(0, L_body) + L_lab = tc.convert_vec_body_to_space(self.es, 0, L_body) for k in range(3): self.assertLessEqual( abs( diff --git a/testsuite/tests_common.py b/testsuite/tests_common.py index fad0316c1e2..aad9d0e3716 100644 --- a/testsuite/tests_common.py +++ b/testsuite/tests_common.py @@ -158,3 +158,26 @@ def verify_lj_forces(system, tolerance, ids_to_skip=[]): def abspath(path): return os.path.join(os.path.dirname(os.path.abspath(__file__)), path) + +def define_rotation_matrix(system, part): + A = np.zeros((3, 3)) + quat = system.part[part].quat + qq = np.power(quat, 2) + + A[0, 0] = qq[0] + qq[1] - qq[2] - qq[3] + A[1, 1] = qq[0] - qq[1] + qq[2] - qq[3] + A[2, 2] = qq[0] - qq[1] - qq[2] + qq[3] + + A[0, 1] = 2 * (quat[1] * quat[2] + quat[0] * quat[3]) + A[0, 2] = 2 * (quat[1] * quat[3] - quat[0] * quat[2]) + A[1, 0] = 2 * (quat[1] * quat[2] - quat[0] * quat[3]) + + A[1, 2] = 2 * (quat[2] * quat[3] + quat[0] * quat[1]) + A[2, 0] = 2 * (quat[1] * quat[3] + quat[0] * quat[2]) + A[2, 1] = 2 * (quat[2] * quat[3] - quat[0] * quat[1]) + + return A + +def convert_vec_body_to_space(system, part, vec): + A = define_rotation_matrix(system, part) + return np.dot(A.transpose(), vec) From badd2e1c682996d1f84833c49891875e74a89053 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Mon, 6 Nov 2017 00:58:06 +0200 Subject: [PATCH 015/150] Rotational diffusion validation --- testsuite/mass-and-rinertia_per_particle.py | 102 ++++++++++++++++++-- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 78f77a97c33..792b5d0c94d 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -4,6 +4,7 @@ from numpy.random import random, seed import espressomd import math +import tests_common as tc @ut.skipIf(not espressomd.has_features(["MASS", @@ -171,7 +172,14 @@ def run_test_case(self, test_case): D_tr = np.zeros((2, 3)) for k in range(2): gamma_tran[k, :] = np.array((0.4 + np.random.random(3)) * 10) - gamma_rot[k, :] = np.array((0.2 + np.random.random(3)) * 20) + # Second particle should be isotropic for the rotational diffusion test. + # It is valid within test cases #1 and #3 + if test_case in (1, 3) and k == 1: + gamma_rot[k, 0] = np.array((0.4 + np.random.random()) * 20) + gamma_rot[k, 1] = gamma_rot[k, 0] + gamma_rot[k, 2] = gamma_rot[k, 0] + else: + gamma_rot[k, :] = np.array((0.2 + np.random.random(3)) * 20) box = 10.0 self.es.box_l = [box, box, box] @@ -221,7 +229,18 @@ def run_test_case(self, test_case): self.es.time_step = 0.03 n = 200 mass = (0.2 + np.random.random()) * 7.0 - J = np.array((0.2 + np.random.random(3)) * 7.0) + J = np.zeros((2, 3)) + J[0, :] = np.array((0.2 + np.random.random(3)) * 7.0) + # Second particle should be isotropic for the rotational diffusion test. + # It is valid within test cases #1 and #3 + if test_case in (1, 3): + J[1, 0] = np.array((0.2 + np.random.random()) * 1.0) + J[1, 1] = J[1, 0] + J[1, 2] = J[1, 0] + else: + J[1, :] = np.array((0.2 + np.random.random(3)) * 7.0) + + D_rot_p1 = 2.0 * halfkT[1] / gamma_rot[1, 0] for i in range(n): for k in range(2): @@ -229,7 +248,8 @@ def run_test_case(self, test_case): part_pos = np.array(np.random.random(3) * box) part_v = np.array([0.0, 0.0, 0.0]) part_omega_body = np.array([0.0, 0.0, 0.0]) - self.es.part.add(rotation=(1,1,1), id=ind, mass=mass, rinertia=J, + self.es.part.add(rotation=(1,1,1), id=ind, mass=mass, + rinertia=[J[k, 0], J[k, 1], J[k, 2]], pos=part_pos, v=part_v) if "ROTATION" in espressomd.features(): self.es.part[ind].omega_body = part_omega_body @@ -245,6 +265,14 @@ def run_test_case(self, test_case): if "ROTATION" in espressomd.features(): self.es.part[ind].gamma_rot = gamma_rot[k, :] self.es.part[ind].temp = temp[k] + # It is needed for further rotational diffusion validation: + if k == 1: + if i <= n / 3: + self.es.part[ind].rotation = 1, 0, 0 + if i > n / 3 and i <= 2 * n / 3: + self.es.part[ind].rotation = 0, 1, 0 + if i > 2 * n / 3: + self.es.part[ind].rotation = 0, 0, 1 # Get rid of short range calculations if exclusions are on # if espressomd.has_features("EXCLUSIONS"): @@ -256,6 +284,19 @@ def run_test_case(self, test_case): dr2 = np.zeros((2, 3)) sigma2_tr = np.zeros((2)) dr_norm = np.zeros((2)) + + # Only for the second particle. + # Total curve within a spherical trigonometry: + alpha = np.zeros((n, 3)) + alpha_norm = 0.0 + # Previous directions of the principal axes: + # [particle_index, which principal axis, its lab coordinate] + prev_pa_lab = np.zeros((n, 3, 3)) + pa_body = np.zeros((3)) + pa_lab = np.zeros((3, 3)) + vec = np.zeros((3)) + vec1 = np.zeros((3)) + vec_diag = np.ones((3)) pos0 = np.zeros((2 * n, 3)) for p in range(n): @@ -263,14 +304,16 @@ def run_test_case(self, test_case): ind = p + k * n pos0[ind, :] = self.es.part[ind].pos dt0 = mass / gamma_tr + # Corresponding below test will be made only for the second particle: + dt0_rot_1 = J[1, 0] / gamma_rot[1, 0] - loops = 200 + loops = 1250 print("Thermalizing...") therm_steps = 150 self.es.integrator.run(therm_steps) print("Measuring...") - int_steps = 5 + int_steps = 1 for i in range(loops): self.es.integrator.run(int_steps) # Get kinetic energy in each degree of freedom for all particles @@ -297,6 +340,32 @@ def run_test_case(self, test_case): j]))) dr_norm[k] = dr_norm[k] + \ (sum(dr2[k, :]) - sigma2_tr[k]) / sigma2_tr[k] + + # Rotational diffusion variance. + if test_case in (1, 3) and k == 1: + dt -= self.es.time_step * (1 + therm_steps) + # First, let's identify principal axes in the lab reference frame. + for j in range(3): + for j1 in range(3): + pa_body[j1] = 0.0 + pa_body[j] = 1.0 + vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) + pa_lab[j, :] = vec[:] + + if i > 0: + # Calc a rotational diffusion within the spherical trigonometry + vec1[:] = prev_pa_lab[p, j, :] + dalpha = np.arccos(np.dot(vec, vec1) / (np.linalg.norm(vec) * np.linalg.norm(vec1))) + # just a formal sign keep to distinguish opposite rotations + sign = np.sign(np.dot(np.cross(vec, vec1), vec_diag)) + alpha[p, j] += sign * dalpha + alpha2 = alpha[p, j]**2 + sigma2_alpha = D_rot_p1 * (2.0 * dt + dt0_rot_1 * (- 3.0 + + 4.0 * math.exp(- dt / dt0_rot_1) + - math.exp(- 2.0 * dt / dt0_rot_1))) + if dalpha > 0: + alpha_norm += (alpha2 - sigma2_alpha) / sigma2_alpha + prev_pa_lab[p, j, :] = pa_lab[j, :] tolerance = 0.15 Ev = 0.5 * mass * v2 / (n * loops) @@ -306,9 +375,18 @@ def run_test_case(self, test_case): do_vec = np.zeros((2, 3)) for k in range(2): dv[k] = sum(Ev[k, :]) / (3 * halfkT[k]) - 1.0 - do[k] = sum(Eo[k, :]) / (3 * halfkT[k]) - 1.0 - do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 + if k == 0: + do[k] = sum(Eo[k, :]) / (3 * halfkT[k]) - 1.0 + do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 + else: + # Two rotational axes are fixed for the second particle: + do[k] = sum(Eo[k, :]) / (1 * halfkT[k]) - 1.0 + do_vec[k, :] = Eo[k, :] / (halfkT[k] / 3.0) - 1.0 dr_norm = dr_norm / (n * loops) + + # Only two body axes move around the non-fixed third one. + alpha_norm = alpha_norm / (2 * n * loops) + for k in range(2): print("\n") print("k = " + str(k)) @@ -336,6 +414,9 @@ def run_test_case(self, test_case): print( "Deviation in translational diffusion: {0} ".format( dr_norm[k])) + print( + "Deviation in rotational diffusion: {0} ".format( + alpha_norm)) self.assertLessEqual( abs( @@ -362,6 +443,13 @@ def run_test_case(self, test_case): tolerance, msg='Relative deviation in translational diffusion is too large: {0}'.format( dr_norm[k])) + if test_case in (1, 3): + self.assertLessEqual( + abs( + alpha_norm), + tolerance, + msg='Relative deviation in rotational diffusion is too large: {0}'.format( + alpha_norm)) def test(self): if "ROTATION" in espressomd.features(): From 522cee91a7a9555701a02be31e1fe6f1a39403a1 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 7 Nov 2017 01:01:24 +0200 Subject: [PATCH 016/150] Rot diffusion tests without any fixed axes --- testsuite/mass-and-rinertia_per_particle.py | 66 +++++++++++---------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 792b5d0c94d..fc163805c0a 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -265,14 +265,6 @@ def run_test_case(self, test_case): if "ROTATION" in espressomd.features(): self.es.part[ind].gamma_rot = gamma_rot[k, :] self.es.part[ind].temp = temp[k] - # It is needed for further rotational diffusion validation: - if k == 1: - if i <= n / 3: - self.es.part[ind].rotation = 1, 0, 0 - if i > n / 3 and i <= 2 * n / 3: - self.es.part[ind].rotation = 0, 1, 0 - if i > 2 * n / 3: - self.es.part[ind].rotation = 0, 0, 1 # Get rid of short range calculations if exclusions are on # if espressomd.has_features("EXCLUSIONS"): @@ -286,17 +278,20 @@ def run_test_case(self, test_case): dr_norm = np.zeros((2)) # Only for the second particle. - # Total curve within a spherical trigonometry: - alpha = np.zeros((n, 3)) + # Total curve within a spherical trigonometry. + # [particle_index, which principal axis, around which lab axis] + alpha = np.zeros((n, 3, 3)) alpha_norm = 0.0 # Previous directions of the principal axes: # [particle_index, which principal axis, its lab coordinate] prev_pa_lab = np.zeros((n, 3, 3)) pa_body = np.zeros((3)) pa_lab = np.zeros((3, 3)) + ref_lab = np.zeros((3)) vec = np.zeros((3)) vec1 = np.zeros((3)) - vec_diag = np.ones((3)) + vec2 = np.zeros((3)) + #vec_diag = np.ones((3)) pos0 = np.zeros((2 * n, 3)) for p in range(n): @@ -353,18 +348,29 @@ def run_test_case(self, test_case): pa_lab[j, :] = vec[:] if i > 0: - # Calc a rotational diffusion within the spherical trigonometry - vec1[:] = prev_pa_lab[p, j, :] - dalpha = np.arccos(np.dot(vec, vec1) / (np.linalg.norm(vec) * np.linalg.norm(vec1))) - # just a formal sign keep to distinguish opposite rotations - sign = np.sign(np.dot(np.cross(vec, vec1), vec_diag)) - alpha[p, j] += sign * dalpha - alpha2 = alpha[p, j]**2 - sigma2_alpha = D_rot_p1 * (2.0 * dt + dt0_rot_1 * (- 3.0 + - 4.0 * math.exp(- dt / dt0_rot_1) - - math.exp(- 2.0 * dt / dt0_rot_1))) - if dalpha > 0: - alpha_norm += (alpha2 - sigma2_alpha) / sigma2_alpha + # Around which axis we rotates? + for j1 in range(3): + # Calc a rotational diffusion within the spherical trigonometry + vec2 = vec + #vec2[j1] = 0.0 + vec1[:] = prev_pa_lab[p, j, :] + #vec1[j1] = 0.0 + for j2 in range(3): + ref_lab[j2] = 0.0 + ref_lab[j1] = 1.0 + dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) + # just a formal sign keep to distinguish opposite rotations + # it can be zero and this is important to track non-rotational + #sign = np.sign(np.dot(np.cross(vec2, vec1), ref_lab)) + rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) + theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) + alpha[p, j, j1] += dalpha * rot_projection / np.sin(theta) + alpha2 = alpha[p, j, j1]**2 + sigma2_alpha = D_rot_p1 * (2.0 * dt + dt0_rot_1 * (- 3.0 + + 4.0 * math.exp(- dt / dt0_rot_1) + - math.exp(- 2.0 * dt / dt0_rot_1))) + if dalpha > 0: + alpha_norm += (alpha2 - sigma2_alpha) / sigma2_alpha prev_pa_lab[p, j, :] = pa_lab[j, :] tolerance = 0.15 @@ -375,17 +381,17 @@ def run_test_case(self, test_case): do_vec = np.zeros((2, 3)) for k in range(2): dv[k] = sum(Ev[k, :]) / (3 * halfkT[k]) - 1.0 - if k == 0: - do[k] = sum(Eo[k, :]) / (3 * halfkT[k]) - 1.0 - do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 - else: + #if k == 0: + do[k] = sum(Eo[k, :]) / (3 * halfkT[k]) - 1.0 + do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 + #else: # Two rotational axes are fixed for the second particle: - do[k] = sum(Eo[k, :]) / (1 * halfkT[k]) - 1.0 - do_vec[k, :] = Eo[k, :] / (halfkT[k] / 3.0) - 1.0 + # do[k] = sum(Eo[k, :]) / (1 * halfkT[k]) - 1.0 + # do_vec[k, :] = Eo[k, :] / (halfkT[k] / 3.0) - 1.0 dr_norm = dr_norm / (n * loops) # Only two body axes move around the non-fixed third one. - alpha_norm = alpha_norm / (2 * n * loops) + alpha_norm = alpha_norm / (9 * n * loops) for k in range(2): print("\n") From 0f0ed382a11741f75f2aa45a1b21343a464e2da1 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 14 Nov 2017 01:20:01 +0200 Subject: [PATCH 017/150] Anisotropic rotational diffusion test, its speed-up --- testsuite/mass-and-rinertia_per_particle.py | 108 +++++++++----------- 1 file changed, 49 insertions(+), 59 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 6f460663ccf..212b46f0755 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -171,16 +171,10 @@ def run_test_case(self, test_case): # 2 different langevin parameters for particles temp = np.array([2.5, 2.0]) D_tr = np.zeros((2, 3)) + D_rot = np.zeros((2, 3)) for k in range(2): gamma_tran[k, :] = np.array((0.4 + np.random.random(3)) * 10) - # Second particle should be isotropic for the rotational diffusion test. - # It is valid within test cases #1 and #3 - if test_case in (1, 3) and k == 1: - gamma_rot[k, 0] = np.array((0.4 + np.random.random()) * 20) - gamma_rot[k, 1] = gamma_rot[k, 0] - gamma_rot[k, 2] = gamma_rot[k, 0] - else: - gamma_rot[k, :] = np.array((0.2 + np.random.random(3)) * 20) + gamma_rot[k, :] = np.array((0.2 + np.random.random(3)) * 20) box = 10.0 self.es.box_l = [box, box, box] @@ -205,6 +199,8 @@ def run_test_case(self, test_case): # translational diffusion for k in range(2): D_tr[k, :] = 2.0 * halfkT[k] / gamma_tr[k, :] + if test_case == 1 or test_case == 3: + D_rot[k, :] = 2.0 * halfkT[k] / gamma_rot[k, :] if test_case != 4: self.es.thermostat.set_langevin( @@ -231,17 +227,8 @@ def run_test_case(self, test_case): n = 200 mass = (0.2 + np.random.random()) * 7.0 J = np.zeros((2, 3)) - J[0, :] = np.array((0.2 + np.random.random(3)) * 7.0) - # Second particle should be isotropic for the rotational diffusion test. - # It is valid within test cases #1 and #3 - if test_case in (1, 3): - J[1, 0] = np.array((0.2 + np.random.random()) * 1.0) - J[1, 1] = J[1, 0] - J[1, 2] = J[1, 0] - else: - J[1, :] = np.array((0.2 + np.random.random(3)) * 7.0) - - D_rot_p1 = 2.0 * halfkT[1] / gamma_rot[1, 0] + for k in range(2): + J[k, :] = np.array((0.2 + np.random.random(3)) * 7.0) for i in range(n): for k in range(2): @@ -278,14 +265,15 @@ def run_test_case(self, test_case): sigma2_tr = np.zeros((2)) dr_norm = np.zeros((2)) - # Only for the second particle. # Total curve within a spherical trigonometry. # [particle_index, which principal axis, around which lab axis] - alpha = np.zeros((n, 3, 3)) - alpha_norm = 0.0 + alpha = np.zeros((2, n, 3, 3)) + alpha_norm = np.zeros((2)) + sigma2_alpha = np.zeros((2)) + alpha2 = np.zeros((2)) # Previous directions of the principal axes: # [particle_index, which principal axis, its lab coordinate] - prev_pa_lab = np.zeros((n, 3, 3)) + prev_pa_lab = np.zeros((2, n, 3, 3)) pa_body = np.zeros((3)) pa_lab = np.zeros((3, 3)) ref_lab = np.zeros((3)) @@ -300,8 +288,7 @@ def run_test_case(self, test_case): ind = p + k * n pos0[ind, :] = self.es.part[ind].pos dt0 = mass / gamma_tr - # Corresponding below test will be made only for the second particle: - dt0_rot_1 = J[1, 0] / gamma_rot[1, 0] + dt0_rot = J / gamma_rot loops = 1250 print("Thermalizing...") @@ -310,6 +297,7 @@ def run_test_case(self, test_case): print("Measuring...") int_steps = 1 + fraction_i = 0.65 for i in range(loops): self.es.integrator.run(int_steps) # Get kinetic energy in each degree of freedom for all particles @@ -338,36 +326,40 @@ def run_test_case(self, test_case): (sum(dr2[k, :]) - sigma2_tr[k]) / sigma2_tr[k] # Rotational diffusion variance. - if test_case in (1, 3) and k == 1: - dt -= self.es.time_step * (1 + therm_steps) - # First, let's identify principal axes in the lab reference frame. - for j in range(3): - for j1 in range(3): - pa_body[j1] = 0.0 - pa_body[j] = 1.0 - vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) - pa_lab[j, :] = vec[:] - - if i > 0: - # Around which axis we rotates? + if i >= fraction_i * loops: + # let's limit test cases to speed this test.. + if test_case == 3: + dt -= self.es.time_step * (1 + therm_steps + fraction_i * loops) + # First, let's identify principal axes in the lab reference frame. + alpha2[k] = 0.0 + sigma2_alpha[k] = 0.0 + for j in range(3): for j1 in range(3): - # Calc a rotational diffusion within the spherical trigonometry - vec2 = vec - vec1[:] = prev_pa_lab[p, j, :] - for j2 in range(3): - ref_lab[j2] = 0.0 - ref_lab[j1] = 1.0 - dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) - rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) - theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) - alpha[p, j, j1] += dalpha * rot_projection / np.sin(theta) - alpha2 = alpha[p, j, j1]**2 - sigma2_alpha = D_rot_p1 * (2.0 * dt + dt0_rot_1 * (- 3.0 + - 4.0 * math.exp(- dt / dt0_rot_1) - - math.exp(- 2.0 * dt / dt0_rot_1))) - if dalpha > 0: - alpha_norm += (alpha2 - sigma2_alpha) / sigma2_alpha - prev_pa_lab[p, j, :] = pa_lab[j, :] + pa_body[j1] = 0.0 + pa_body[j] = 1.0 + vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) + pa_lab[j, :] = vec[:] + + if i >= fraction_i * loops + 1: + # Around which axis we rotates? + for j1 in range(3): + # Calc a rotational diffusion within the spherical trigonometry + vec2 = vec + vec1[:] = prev_pa_lab[k, p, j, :] + for j2 in range(3): + ref_lab[j2] = 0.0 + ref_lab[j1] = 1.0 + dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) + rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) + theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) + alpha[k, p, j, j1] += dalpha * rot_projection / np.sin(theta) + alpha2[k] += alpha[k, p, j, j1]**2 + sigma2_alpha[k] += D_rot[k, j] * (2.0 * dt + dt0_rot[k, j] * (- 3.0 + + 4.0 * math.exp(- dt / dt0_rot[k, j]) + - math.exp(- 2.0 * dt / dt0_rot[k, j]))) + prev_pa_lab[k, p, j, :] = pa_lab[j, :] + if i >= fraction_i * loops + 1: + alpha_norm[k] += (alpha2[k] - sigma2_alpha[k]) / sigma2_alpha[k] tolerance = 0.15 Ev = 0.5 * mass * v2 / (n * loops) @@ -380,9 +372,7 @@ def run_test_case(self, test_case): do[k] = sum(Eo[k, :]) / (3.0 * halfkT[k]) - 1.0 do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 dr_norm = dr_norm / (n * loops) - - # Only two body axes move around the non-fixed third one. - alpha_norm = alpha_norm / (9 * n * loops) + alpha_norm = alpha_norm / (n * (1 - fraction_i) * loops) for k in range(2): print("\n") @@ -443,10 +433,10 @@ def run_test_case(self, test_case): if test_case in (1, 3): self.assertLessEqual( abs( - alpha_norm), + alpha_norm[k]), tolerance, msg='Relative deviation in rotational diffusion is too large: {0}'.format( - alpha_norm)) + alpha_norm[k])) def test(self): if "ROTATION" in espressomd.features(): From 5bdb382bf0fb0a9b7e662ac66c69ff43f589ab98 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 17 Nov 2017 01:05:48 +0200 Subject: [PATCH 018/150] BD: Maxwell distribution enablement --- src/core/integrate.cpp | 10 +- src/core/rotation.cpp | 10 +- src/core/thermostat.cpp | 9 +- src/core/thermostat.hpp | 4 + src/python/espressomd/thermostat.pyx | 8 +- testsuite/CMakeLists.txt | 1 + testsuite/brownian_thermostat.py | 412 +++++++++++++++++++++++++++ 7 files changed, 437 insertions(+), 17 deletions(-) create mode 100644 testsuite/brownian_thermostat.py diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index a3c25af1bb6..5099742b651 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1393,7 +1393,7 @@ void bd_random_walk(Particle *p, double dt) { // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 24.0; + auto const constexpr langevin_temp_coeff = 2.0; if(p->p.gamma >= Thermostat::GammaType{}) { @@ -1436,12 +1436,12 @@ void bd_random_walk(Particle *p, double dt) { { #ifndef PARTICLE_ANISOTROPY if (brown_sigma_pos_temp_inv > 0.0) - delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * Thermostat::noise(); + delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * Thermostat::noise_g(); else delta_pos_body[j] = 0.0; #else if (brown_sigma_pos_temp_inv[j] > 0.0) - delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * Thermostat::noise(); + delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * Thermostat::noise_g(); else delta_pos_body[j] = 0.0; #endif // PARTICLE_ANISOTROPY @@ -1483,7 +1483,7 @@ void bd_random_walk_vel(Particle *p, double dt) { // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 12.0; + auto const constexpr langevin_temp_coeff = 1.0; // Is a particle-specific temperature specified? // here, the time_step is used only to align with Espresso default dimensionless model if (p->p.T >= 0.) @@ -1498,7 +1498,7 @@ void bd_random_walk_vel(Particle *p, double dt) { #endif { // velocity is added here. It is assigned in the drift part. - p->m.v[j] += brown_sigma_vel_temp * Thermostat::noise() / sqrt(p->p.mass); + p->m.v[j] += brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p->p.mass); } } } diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 579e3088204..089d65466fd 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -742,7 +742,7 @@ void bd_random_walk_rot(Particle *p, double dt) { // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 24.0; + auto const constexpr langevin_temp_coeff = 2.0; if(p->p.gamma_rot >= Thermostat::GammaType{}) { @@ -780,12 +780,12 @@ void bd_random_walk_rot(Particle *p, double dt) { dphi[0] = dphi[1] = dphi[2] = 0.0; #ifndef PARTICLE_ANISOTROPY if (brown_sigma_pos_temp_inv > 0.0) - dphi[j] = a[j] * Thermostat::noise() * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); + dphi[j] = a[j] * Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); else dphi[j] = 0.0; #else if (brown_sigma_pos_temp_inv[j] > 0.0) - dphi[j] = a[j] * Thermostat::noise() * (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); + dphi[j] = a[j] * Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); else dphi[j] = 0.0; #endif // ROTATIONAL_INERTIA @@ -818,7 +818,7 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 12.0; + auto const constexpr langevin_temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p->p.T >= 0.) brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T); @@ -832,7 +832,7 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { #endif { // velocity is added here. It is assigned in the drift part. - p->m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise() / sqrt(p->p.rinertia[j]); + p->m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p->p.rinertia[j]); } } } diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 9fb16cefc56..3de6e059160 100755 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -171,10 +171,11 @@ void thermo_init_npt_isotropic() { // default particle mass is assumed to be unitary in this global parameters void thermo_init_brownian() { int j; + // Dispersions correspond to the Gaussian noise only which is only valid for the BD. // here, the time_step is used only to align with Espresso default dimensionless model (translational velocity only) - brown_sigma_vel = sqrt(12.0 * temperature) * time_step; + brown_sigma_vel = sqrt(temperature) * time_step; if (temperature > 0.0) - brown_sigma_pos_inv = sqrt(langevin_gamma / (24.0 * temperature)); + brown_sigma_pos_inv = sqrt(langevin_gamma / (2.0 * temperature)); else brown_sigma_pos_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here #ifdef ROTATION @@ -184,9 +185,9 @@ void thermo_init_brownian() { if (langevin_gamma_rotation < GammaType{}) { langevin_gamma_rotation = langevin_gamma; } - brown_sigma_vel_rotation = sqrt(12.0 * temperature); + brown_sigma_vel_rotation = sqrt(temperature); if (temperature > 0.0) - brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (24.0 * temperature)); + brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (2.0 * temperature)); else brown_sigma_pos_rotation_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation_inv)); diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 0b9faf1ee55..e9c3f880199 100755 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -55,6 +55,10 @@ namespace Thermostat { auto noise = []() { return (d_random() - 0.5); }; +#ifdef BROWNIAN_DYNAMICS +// Only Gaussian noise is allowed for the BD, otherwise the Maxwell distribution will fail. +auto noise_g = []() { return gaussian_random(); }; +#endif #ifdef PARTICLE_ANISOTROPY using GammaType = Vector3d; diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index defe008896a..f35fff55ff0 100755 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -445,20 +445,22 @@ cdef class Thermostat(object): if 'PARTICLE_ANISOTROPY' is also compiled in. """ + scalar_gamma_def = True scalar_gamma_rot_def = True IF PARTICLE_ANISOTROPY: - if isinstance(gamma, list): + if hasattr(gamma, "__iter__"): scalar_gamma_def = False else: scalar_gamma_def = True IF PARTICLE_ANISOTROPY: - if isinstance(gamma_rotation, list): + if hasattr(gamma_rotation, "__iter__"): scalar_gamma_rot_def = False else: scalar_gamma_rot_def = True - + + if kT is None or gamma is None: raise ValueError( "Both, kT and gamma have to be given as keyword args") diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index d18ac273c20..b7e0cdbdc94 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -69,6 +69,7 @@ python_test(FILE ek_eof_one_species_y_nonlinear.py MAX_NUM_PROC 1) python_test(FILE ek_eof_one_species_z_nonlinear.py MAX_NUM_PROC 1) python_test(FILE exclusions.py MAX_NUM_PROC 4) python_test(FILE langevin_thermostat.py MAX_NUM_PROC 1) +python_test(FILE brownian_thermostat.py MAX_NUM_PROC 1) python_test(FILE nsquare.py MAX_NUM_PROC 4) python_test(FILE virtual_sites_relative.py MAX_NUM_PROC 2) python_test(FILE domain_decomposition.py MAX_NUM_PROC 4) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py new file mode 100644 index 00000000000..2e38e0bf0d3 --- /dev/null +++ b/testsuite/brownian_thermostat.py @@ -0,0 +1,412 @@ +# +# Copyright (C) 2013,2014,2015,2016 The ESPResSo project +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +from __future__ import print_function +import unittest as ut +import espressomd +import numpy as np +from espressomd.interactions import FeneBond +from time import time +from espressomd.correlators import Correlator +from espressomd.observables import ParticleVelocities, ParticleBodyAngularVelocities + +@ut.skipIf(espressomd.has_features("THERMOSTAT_IGNORE_NON_VIRTUAL"), + "Skipped because of THERMOSTAT_IGNORE_NON_VIRTUAL") +class BrownianThermostat(ut.TestCase): + """Tests the velocity distribution created by the Brownian thermostat against + the single component Maxwell distribution.""" + + s = espressomd.System() + s.cell_system.set_n_square() + s.cell_system.skin = 0.3 + s.seed = range(s.cell_system.get_state()["n_nodes"]) + if espressomd.has_features("PARTIAL_PERIODIC"): + s.periodicity = 0,0,0 + + + @classmethod + def setUpClass(cls): + np.random.seed(42) + + def single_component_maxwell(self, x1, x2, kT): + """Integrate the probability density from x1 to x2 using the trapez rule""" + x = np.linspace(x1, x2, 1000) + return np.trapz(np.exp(-x**2 / (2. * kT)), x) / \ + np.sqrt(2. * np.pi * kT) + + def check_velocity_distribution(self, vel, minmax, n_bins, error_tol, kT): + """check the recorded particle distributions in vel againsta histogram with n_bins bins. Drop velocities outside minmax. Check individual histogram bins up to an accuracy of error_tol agaisnt the analytical result for kT.""" + for i in range(3): + hist = np.histogram( + vel[:, i], range=(-minmax, minmax), bins=n_bins, normed=False) + data = hist[0] / float(vel.shape[0]) + bins = hist[1] + for j in range(n_bins): + found = data[j] + expected = self.single_component_maxwell( + bins[j], bins[j + 1], kT) + self.assertLessEqual(abs(found - expected), error_tol) + + def test_aa_verify_single_component_maxwell(self): + """Verifies the normalization of the analytical expression.""" + self.assertLessEqual( + abs(self.single_component_maxwell(-10, 10, 4.) - 1.), 1E-4) + + def test_global_brownian(self): + """Test for global Brownian parameters.""" + N = 200 + s = self.s + s.part.clear() + s.time_step = 0.02 + + # Place particles + s.part.add(pos=np.random.random((N, 3))) + + # Enable rotation if compiled in + if espressomd.has_features("ROTATION"): + s.part[:].rotation = 1,1,1 + + kT = 2.3 + gamma = 1.5 + s.thermostat.set_brownian(kT=kT, gamma=gamma) + + # Warmup + s.integrator.run(100) + + # Sampling + loops = 4000 + v_stored = np.zeros((N * loops, 3)) + omega_stored = np.zeros((N * loops, 3)) + for i in range(loops): + s.integrator.run(2) + v_stored[i * N:(i + 1) * N, :] = s.part[:].v + if espressomd.has_features("ROTATION"): + omega_stored[i * N:(i + 1) * N, :] = s.part[:].omega_body + + v_minmax = 5 + bins = 5 + error_tol = 0.015 + self.check_velocity_distribution( + v_stored, v_minmax, bins, error_tol, kT) + if espressomd.has_features("ROTATION"): + self.check_velocity_distribution( + omega_stored, v_minmax, bins, error_tol, kT) + + @ut.skipIf(not espressomd.has_features("LANGEVIN_PER_PARTICLE"), + "Test requires LANGEVIN_PER_PARTICLE") + def test_brownian_per_particle(self): + """Test for Brownian particle. Covers all combinations of + particle specific gamma and temp set or not set. + """ + N = 200 + s = self.s + s.part.clear() + s.time_step = 0.02 + s.part.add(pos=np.random.random((N, 3))) + if espressomd.has_features("ROTATION"): + s.part[:].rotation = 1,1,1 + + kT = 2.3 + gamma = 1.5 + gamma2 = 2.3 + kT2 = 1.5 + s.thermostat.set_brownian(kT=kT, gamma=gamma) + # Set different kT on 2nd half of particles + s.part[int(N / 2):].temp = kT2 + # Set different gamma on half of the partiles (overlap over both kTs) + if espressomd.has_features("PARTICLE_ANISOTROPY"): + s.part[int(N / 4):int(3 * N / 4)].gamma = gamma2, gamma2, gamma2 + else: + s.part[int(N / 4):int(3 * N / 4)].gamma = gamma2 + + s.integrator.run(50) + loops = 4000 + + v_kT = np.zeros((int(N / 2) * loops, 3)) + v_kT2 = np.zeros((int(N / 2 * loops), 3)) + + if espressomd.has_features("ROTATION"): + omega_kT = np.zeros((int(N / 2) * loops, 3)) + omega_kT2 = np.zeros((int(N / 2 * loops), 3)) + + for i in range(loops): + s.integrator.run(2) + v_kT[int(i * N / 2):int((i + 1) * N / 2), + :] = s.part[:int(N / 2)].v + v_kT2[int(i * N / 2):int((i + 1) * N / 2), + :] = s.part[int(N / 2):].v + + if espressomd.has_features("ROTATION"): + omega_kT[int(i * N / 2):int((i + 1) * N / 2), + :] = s.part[:int(N / 2)].omega_body + omega_kT2[int(i * N / 2):int((i + 1) * N / 2), + :] = s.part[int(N / 2):].omega_body + v_minmax = 5 + bins = 5 + error_tol = 0.014 + self.check_velocity_distribution(v_kT, v_minmax, bins, error_tol, kT) + self.check_velocity_distribution(v_kT2, v_minmax, bins, error_tol, kT2) + + if espressomd.has_features("ROTATION"): + self.check_velocity_distribution(omega_kT, v_minmax, bins, error_tol, kT) + self.check_velocity_distribution(omega_kT2, v_minmax, bins, error_tol, kT2) + + def setup_diff_mass_rinertia(self,p): + if espressomd.has_features("MASS"): + p.mass=0.5 + if espressomd.has_features("ROTATION"): + p.rotation = 1,1,1 + # Make sure rinertia does not change diff coeff + if espressomd.has_features("ROTATIONAL_INERTIA"): + p.rinertia =0.4,0.4,0.4 + + def test_diffusion(self): + """This tests rotational and translational diffusion coeff via green-kubo""" + s=self.s + s.part.clear() + + kT=1.37 + dt=0.05 + s.time_step=dt + + # Translational gamma. We cannot test per-component, if rotation is on, + # because body and space frames become different. + gamma=3.1 + + # Rotational gamma + gamma_rot_i=0.7 + gamma_rot_a=0.7,1,1.2 + + # If we have langevin per particle: + # per particle kT + per_part_kT=1.6 + # Translation + per_part_gamma=1.63 + # Rotational + per_part_gamma_rot_i=0.6 + per_part_gamma_rot_a=0.4,0.8,1.1 + + + + + + + # Particle with global thermostat params + p_global=s.part.add(pos=(0,0,0)) + # Make sure, mass doesn't change diff coeff + self.setup_diff_mass_rinertia(p_global) + + # particle specific gamma, kT, and both + if espressomd.has_features("LANGEVIN_PER_PARTICLE"): + p_gamma=s.part.add(pos=(0,0,0)) + self.setup_diff_mass_rinertia(p_gamma) + if espressomd.has_features("PARTICLE_ANISOTROPY"): + p_gamma.gamma =per_part_gamma,per_part_gamma,per_part_gamma + if espressomd.has_features("ROTATION"): + p_gamma.gamma_rot=per_part_gamma_rot_a + else: + p_gamma.gamma =per_part_gamma + if espressomd.has_features("ROTATION"): + p_gamma.gamma_rot=per_part_gamma_rot_i + + p_kT=s.part.add(pos=(0,0,0)) + self.setup_diff_mass_rinertia(p_kT) + p_kT.temp=per_part_kT + + p_both=s.part.add(pos=(0,0,0)) + self.setup_diff_mass_rinertia(p_both) + p_both.temp=per_part_kT + if espressomd.has_features("PARTICLE_ANISOTROPY"): + p_both.gamma =per_part_gamma,per_part_gamma,per_part_gamma + if espressomd.has_features("ROTATION"): + p_both.gamma_rot=per_part_gamma_rot_a + else: + p_both.gamma =per_part_gamma + if espressomd.has_features("ROTATION"): + p_both.gamma_rot=per_part_gamma_rot_i + + + + + # Thermostat setup + if espressomd.has_features("ROTATION"): + if espressomd.has_features("PARTICLE_ANISOTROPY"): + # particle anisotropy and rotation + s.thermostat.set_brownian(kT=kT,gamma=gamma,gamma_rotation=gamma_rot_a) + else: + # Rotation without particle anisotropy + s.thermostat.set_brownian(kT=kT,gamma=gamma,gamma_rotation=gamma_rot_i) + else: + # No rotation + s.thermostat.set_brownian(kT=kT,gamma=gamma) + + + + s.cell_system.skin =0.4 + s.integrator.run(5000) + + # Correlators + vel_obs={} + omega_obs={} + corr_vel={} + corr_omega={} + all_particles=[p_global] + if espressomd.has_features("LANGEVIN_PER_PARTICLE"): + all_particles.append(p_gamma) + all_particles.append(p_kT) + all_particles.append(p_both) + + for p in all_particles: + # linear vel + vel_obs[p]=ParticleVelocities(ids=(p.id,)) + corr_vel[p] = Correlator(obs1=vel_obs[p], tau_lin=32, tau_max=4., dt=2*dt, + corr_operation="componentwise_product", compress1="discard1") + s.auto_update_correlators.add(corr_vel[p]) + # angular vel + if espressomd.has_features("ROTATION"): + omega_obs[p]=ParticleBodyAngularVelocities(ids=(p.id,)) + corr_omega[p] = Correlator(obs1=omega_obs[p], tau_lin=32, tau_max=4, dt=2*dt, + corr_operation="componentwise_product", compress1="discard1") + s.auto_update_correlators.add(corr_omega[p]) + + s.integrator.run(800000) + for c in corr_vel.values(): + s.auto_update_correlators.remove(c) + for c in corr_omega.values(): + s.auto_update_correlators.remove(c) + + # Verify diffusion + # Translation + # Cast gammas to vector, to make checks independent of PARTICLE_ANISOTROPY + + # TODO: to return this after an implementation of the fine inertial BD + #gamma=np.ones(3) *gamma + #per_part_gamma=np.ones(3) *per_part_gamma + #self.verify_diffusion(p_global,corr_vel,kT,gamma) + #if espressomd.has_features("LANGEVIN_PER_PARTICLE"): + # self.verify_diffusion(p_gamma,corr_vel,kT,per_part_gamma) + # self.verify_diffusion(p_kT,corr_vel,per_part_kT,gamma) + # self.verify_diffusion(p_both,corr_vel,per_part_kT,per_part_gamma) + + # Rotation + if espressomd.has_features("ROTATION"): + # Decide on effective gamma rotation, since for rotation it is direction dependent + eff_gamma_rot=None + per_part_eff_gamma_rot=None + if espressomd.has_features("PARTICLE_ANISOTROPY"): + eff_gamma_rot=gamma_rot_a + eff_per_part_gamma_rot =per_part_gamma_rot_a + else: + eff_gamma_rot=gamma_rot_i*np.ones(3) + eff_per_part_gamma_rot =per_part_gamma_rot_i *np.ones(3) + +# TODO: to return this after an implementation of the fine inertial BD +# self.verify_diffusion(p_global,corr_omega,kT,eff_gamma_rot) +# if espressomd.has_features("LANGEVIN_PER_PARTICLE"): +# self.verify_diffusion(p_gamma,corr_omega,kT,eff_per_part_gamma_rot) +# self.verify_diffusion(p_kT,corr_omega,per_part_kT,eff_gamma_rot) +# self.verify_diffusion(p_both,corr_omega,per_part_kT,eff_per_part_gamma_rot) + + + +# TODO: to return this after an implementation of the fine inertial BD +# def verify_diffusion(self,p,corr,kT,gamma): +# """Verifify diffusion coeff. +# +# p: particle, corr: dict containing correltor with particle as key, +# kT=kT, gamma=gamma as 3 component vector. +# """ +# c=corr[p] +# # Integral of vacf via Green-Kubo +# #D= int_0^infty dt (o 1/3, since we work componentwise) +# acf=c.result() +# #Integrate w. trapez rule +# for coord in 2,3,4: +# I=np.trapz(acf[:,coord],acf[:,0]) +# ratio = I/(kT/gamma[coord-2]) +# self.assertAlmostEqual(ratio,1.,delta=0.07) + + +# TODO: to return this after an implementation of the fine inertial BD +# def test_00__friction_trans(self): +# """Tests the translational friction-only part of the thermostat.""" +# +# +# s=self.s +# # Translation +# gamma_t_i=2 +# gamma_t_a=0.5,2,1.5 +# v0=5. +# +# s.time_step=0.0005 +# s.part.clear() +# s.part.add(pos=(0,0,0),v=(v0,v0,v0)) +# if espressomd.has_features("MASS"): +# s.part[0].mass=3 +# if espressomd.has_features("PARTICLE_ANISOTROPY"): +# s.thermostat.set_brownian(kT=0,gamma=gamma_t_a) +# else: +# s.thermostat.set_brownian(kT=0,gamma=gamma_t_i) +# +# s.time=0 +# for i in range(100): +# s.integrator.run(10) +# for j in range(3): +# if espressomd.has_features("PARTICLE_ANISOTROPY"): +# self.assertAlmostEqual(s.part[0].v[j],v0*np.exp(-gamma_t_a[j]/s.part[0].mass*s.time),places=2) +# else: +# self.assertAlmostEqual(s.part[0].v[j],v0*np.exp(-gamma_t_i/s.part[0].mass*s.time),places=2) + +# TODO: to return this after an implementation of the fine inertial BD +# @ut.skipIf(not espressomd.has_features("ROTATION"), "Skipped for lack of ROTATION" ) +# def test_00__friction_rot(self): +# """Tests the rotational friction-only part of the thermostat.""" +# +# +# s=self.s +# # Translation +# gamma_t_i=2 +# gamma_t_a=0.5,2,1.5 +# gamma_r_i=3 +# gamma_r_a=1.5,0.7,1.2 +# o0=5. +# +# s.time_step=0.0005 +# s.part.clear() +# s.part.add(pos=(0,0,0),omega_body=(o0,o0,o0),rotation=(1,1,1)) +# if espressomd.has_features("ROTATIONAL_INERTIA"): +# s.part[0].rinertia=2,2,2 +# if espressomd.has_features("PARTICLE_ANISOTROPY"): +# s.thermostat.set_brownian(kT=0,gamma=gamma_t_a,gamma_rotation=gamma_r_a) +# else: +# s.thermostat.set_brownian(kT=0,gamma=gamma_t_i,gamma_rotation=gamma_r_i) +# +# s.time=0 +# for i in range(100): +# s.integrator.run(10) +# for j in range(3): +# if espressomd.has_features("PARTICLE_ANISOTROPY"): +# self.assertAlmostEqual(s.part[0].omega_body[j],o0*np.exp(-gamma_r_a[j]/s.part[0].rinertia[j]*s.time),places=2) +# else: +# self.assertAlmostEqual(s.part[0].omega_body[j],o0*np.exp(-gamma_r_i/s.part[0].rinertia[j]*s.time),places=2) + + + + +if __name__ == "__main__": + ut.main() From 71c36539afbfac48bf4810c2d8f24010b7363ea2 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 26 Nov 2017 13:01:12 +0200 Subject: [PATCH 019/150] BD docs, corrections --- doc/sphinx/setup.rst | 59 ++++++++++++++++++++++++++++++++++++++++++-- doc/sphinx/zrefs.bib | 13 ++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/setup.rst b/doc/sphinx/setup.rst index 88e72e9879e..f1168a306b0 100644 --- a/doc/sphinx/setup.rst +++ b/doc/sphinx/setup.rst @@ -138,7 +138,7 @@ the particle becomes .. math:: D = \frac{\text{temperature}}{\text{gamma}}. -The relaxation time is given by :math:`\text{gamma}/\text{MASS}`, with +The relaxation time is given by :math:`\text{MASS}/\text{gamma}`, with ``MASS`` the particle’s mass. For a more detailed explanation, refer to :cite:`grest86a`. An anisotropic diffusion coefficient tensor is available to simulate anisotropic colloids (rods, etc.) properly. It can be enabled by the @@ -151,7 +151,7 @@ same value as that for the translation. A separate rotational diffusion coefficient can be set by inputting ``gamma_rotate``. This also allows one to properly match the translational and -rotational diffusion coefficients of a sphere. ``ROTATIONAL_INERTIA`` Feature +rotational diffusion coefficients of a sphere. ``PARTICLE_ANISOTROPY`` feature enables an anisotropic rotational diffusion coefficient tensor through corresponding friction coefficients. @@ -396,6 +396,61 @@ Be aware that this feature is neither properly examined for all systems nor is it maintained regularly. If you use it and notice strange behaviour, please contribute to solving the problem. +Brownian thermostat +~~~~~~~~~~~~~~~~~~~ + +Brownian thermostat is a formal name of a thermostat enabling the +Brownian Dynamics feature (see :cite:`schlick2010`). + +In order to activate the Brownian thermostat the memberfunction +:py:attr:`~espressomd.thermostat.Thermostat.set_brownian` of the thermostat +class :class:`espressomd.thermostat.Thermostat` has to be invoked. +Best explained in an example::: + + import espressomd + system = espressomd.System() + therm = system.Thermostat() + + therm.set_brownian(kT=1.0, gamma=1.0) + +In terms of Python interface and setup, Brownian thermostat derives most +properties of the :ref:`Langevin thermostat`. Same feature +``LANGEVIN_PER_PARTICLE`` is using to control the per-particle +temperature and the friction coefficient setup. Major differences are +its internal integrator implementation and other temporal constraints. +The integrator is still symplectic Velocity Verlet-like integrator. +It is implemented via a drift part and a random walk of both position and +velocity. Due to a nature of the Brownian Dynamics method, ``time_step`` +should be large enough compare to the relaxation time +:math:`\text{MASS}/\text{gamma}`. Note, that with all similarities of +Langevin and Brownian Dynamics, the Langevin thermostat temporal constraint +is opposite. Hence, a velocity is restarting from zero at every step, +velocity at the beginning of the the ``time_step`` interval is dissipated +and does not contribute to the final one. Another temporal constrain +which is valid for both Langevin and Brownian Dynamics: conservative forces +should not change significantly over the ``time_step`` interval. + +The position :math:`\Delta_r` and velocity :math:`\Delta_v` +drift are driven by conservative forces: + +.. math:: \Delta r = \frac{\text{F} \cdot \text{time_step}}{\text{gamma}} + +.. math:: \Delta v = \frac{\text{F}}{\text{gamma}} + +Position random walk variance of each coordinate :math:`\sigma_p^2` +corresponds to a diffusion within the Wiener process: + +.. math:: \sigma_p^2 = 2 D \Delta t + +Velocity component random walk variance :math:`\sigma_v^2` is defined by a heat +velocity component: + +.. math:: \sigma_v^2 = \frac{\text{temperature}}{\text{MASS}} + +A rotational motion is implemented similarly. The Velocity Verlet quaternion +based rotational method implementation is still used, however, modified +for a larger ``time_step``. + .. _\`\`nemd\`\`\: Setting up non-equilibirum MD: ``nemd``: Setting up non-equilibrium MD diff --git a/doc/sphinx/zrefs.bib b/doc/sphinx/zrefs.bib index dd67ce96392..57e5def50f2 100755 --- a/doc/sphinx/zrefs.bib +++ b/doc/sphinx/zrefs.bib @@ -1089,3 +1089,16 @@ @ARTICLE{wolff04a timestamp = {2007.06.14} } +@book{schlick2010, +address = {New York, NY}, +author = {Schlick, Tamar}, +doi = {10.1007/978-1-4419-6351-2}, +isbn = {978-1-4419-6350-5}, +publisher = {Springer New York}, +series = {Interdisciplinary Applied Mathematics}, +title = {{Molecular Modeling and Simulation: An Interdisciplinary Guide}}, +volume = {21}, +year = {2010} +} + + From 23982e9a5ee4db80fe200038773f5c389cd98471 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Wed, 10 Jan 2018 23:32:12 +0200 Subject: [PATCH 020/150] Drag terminal velocity tests ..aka the drift in case of the electrostatics --- testsuite/mass-and-rinertia_per_particle.py | 127 +++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 5e4c6bb5541..f26d843b9a9 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -17,9 +17,13 @@ class ThermoTest(ut.TestCase): es = espressomd.System() def run_test_case(self, test_case): - seed(1) + seed(2) # Decelleration self.es.time_step = 0.007 + box = 1.0E5 + self.es.box_l = [box, box, box] + if espressomd.has_features(("PARTIAL_PERIODIC")): + self.es.periodicity = 0, 0, 0 # gamma_tran/gamma_rot matrix: [2 types of particless] x [3 dimensions # X Y Z] gamma_tran = np.zeros((2, 3)) @@ -160,6 +164,127 @@ def run_test_case(self, test_case): self.es.part[k].omega_body[j] - math.exp(- gamma_rot_validate[k, j] * self.es.time / J[j])), tol) self.es.integrator.run(10) + # The drag terminal velocity tests + ################################## + #..aka the drift in case of the electrostatics + + # Isotropic reassignment is required here for the drag tests + gamma_global_rot = np.zeros((3)) + gamma_global_rot[0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) + gamma_global_rot[1] = gamma_global_rot[0] + gamma_global_rot[2] = gamma_global_rot[0] + # Second particle already has isotropic gamma_rot + # A correction is needed for the 1st one: + gamma_rot[0, 0] = np.array((0.5 + random(1)) * 2.0 / 3.0) + gamma_rot[0, 1] = gamma_rot[0, 0] + gamma_rot[0, 2] = gamma_rot[0, 0] + + if test_case == 1 or test_case == 3: + gamma_tr = gamma_tran + gamma_rot_validate = gamma_rot + # A correction is needed for the 1st particle only: + if "ROTATION" in espressomd.features(): + self.es.part[0].gamma_rot = gamma_rot[0, :] + else: + for k in range(2): + gamma_tr[k, :] = gamma_global[:] + if test_case != 4: + gamma_rot_validate[k, :] = gamma_global[:] + else: + gamma_rot_validate[k, :] = gamma_global_rot[:] + + if test_case != 4: + self.es.thermostat.set_langevin( + kT=0.0, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) + else: + self.es.thermostat.set_langevin( + kT=0.0, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]], + gamma_rotation=[ + gamma_global_rot[0], + gamma_global_rot[1], + gamma_global_rot[2]]) + + self.es.time = 0.0 + self.es.time_step = 7E-5 + # The terminal velocity is starting since t >> t0 = mass / gamma + t0_max = -1.0 + for k in range(2): + t0_max = max(t0_max, max(mass / gamma_tr[k, :]), max(J[:] / gamma_rot_validate[k, :])) + drag_steps_0 = int(math.floor(20 * t0_max / self.es.time_step)) + print("drag_steps_0 = {0}".format(drag_steps_0)) + + tol = 7E-3 + if "EXTERNAL_FORCES" in espressomd.features(): + for k in range(2): + self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) + self.es.part[k].v = np.array([0.0, 0.0, 0.0]) + self.es.part[k].omega_body = np.array([0.0, 0.0, 0.0]) + f0 = np.array([-1.2, 58.3578, 0.002]) + f1 = np.array([-15.112, -2.0, 368.0]) + self.es.part[0].ext_force = f0 + self.es.part[1].ext_force = f1 + if "ROTATION" in espressomd.features(): + tor0 = np.array([12, 0.022, 87]) + tor1 = np.array([-0.03, -174, 368]) + self.es.part[0].ext_torque = tor0 + self.es.part[1].ext_torque = tor1 + # Let's set the dipole perpendicular to the torque + if "DIPOLES" in espressomd.features(): + dip0 = np.array([0.0, tor0[2], -tor0[1]]) + dip1 = np.array([-tor1[2], 0.0, tor1[0]]) + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) + tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) + self.es.integrator.run(drag_steps_0) + self.es.time = 0.0 + for k in range(2): + self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) + if "DIPOLES" in espressomd.features(): + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + for i in range(100): + self.es.integrator.run(10) + for k in range(3): + self.assertLess( + abs(self.es.part[0].v[k] - f0[k] / gamma_tr[0, k]), tol) + self.assertLess( + abs(self.es.part[1].v[k] - f1[k] / gamma_tr[1, k]), tol) + self.assertLess( + abs(self.es.part[0].pos[k] - self.es.time * f0[k] / gamma_tr[0, k]), tol) + self.assertLess( + abs(self.es.part[1].pos[k] - self.es.time * f1[k] / gamma_tr[1, k]), tol) + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + self.es.part[0].omega_lab[k] - tor0[k] / gamma_rot_validate[0, k]), tol) + self.assertLess(abs( + self.es.part[1].omega_lab[k] - tor1[k] / gamma_rot_validate[1, k]), tol) + if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): + cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) + cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0]) + sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) + sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0])) + + cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) + cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0]) + sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) + sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0])) + + #print("cos_alpha0 = {0}, cos_alpha0_test={1}".format(cos_alpha0, cos_alpha0_test)) + #print("dip0 = {0}, self.es.part[0].dip={1}".format(dip0, self.es.part[0].dip)) + self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) + self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) + self.assertEqual(sgn0, sgn0_test) + self.assertEqual(sgn1, sgn1_test) + for i in range(len(self.es.part)): self.es.part[i].remove() From 33524e702430267da9cd8bd24bf5e5131d8a52a1 Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Fri, 9 Feb 2018 14:12:04 +0200 Subject: [PATCH 021/150] BD feature test requirement --- testsuite/brownian_thermostat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index 2e38e0bf0d3..b598f2896d7 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -25,7 +25,8 @@ from espressomd.correlators import Correlator from espressomd.observables import ParticleVelocities, ParticleBodyAngularVelocities -@ut.skipIf(espressomd.has_features("THERMOSTAT_IGNORE_NON_VIRTUAL"), +@ut.skipIf(espressomd.has_features("THERMOSTAT_IGNORE_NON_VIRTUAL") and + not espressomd.has_features("BROWNIAN_DYNAMICS"), "Skipped because of THERMOSTAT_IGNORE_NON_VIRTUAL") class BrownianThermostat(ut.TestCase): """Tests the velocity distribution created by the Brownian thermostat against From d49e0d2e9841342edab205c9dcb1ff16d4584663 Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Fri, 9 Feb 2018 14:45:58 +0200 Subject: [PATCH 022/150] Feature configuration condition --- testsuite/brownian_thermostat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index b598f2896d7..e20fa227d62 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -25,9 +25,9 @@ from espressomd.correlators import Correlator from espressomd.observables import ParticleVelocities, ParticleBodyAngularVelocities -@ut.skipIf(espressomd.has_features("THERMOSTAT_IGNORE_NON_VIRTUAL") and +@ut.skipIf(espressomd.has_features("THERMOSTAT_IGNORE_NON_VIRTUAL") or not espressomd.has_features("BROWNIAN_DYNAMICS"), - "Skipped because of THERMOSTAT_IGNORE_NON_VIRTUAL") + "Skipped because of the features set") class BrownianThermostat(ut.TestCase): """Tests the velocity distribution created by the Brownian thermostat against the single component Maxwell distribution.""" From ed19f3bc6db98605b5d4e57a2873689089b4a290 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 9 Feb 2018 21:31:42 +0200 Subject: [PATCH 023/150] Repeating code move to the function --- testsuite/mass-and-rinertia_per_particle.py | 175 ++++++-------------- 1 file changed, 48 insertions(+), 127 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index bd844420c2d..f9fd388da77 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -15,6 +15,50 @@ class ThermoTest(ut.TestCase): # Handle for espresso system es = espressomd.System() rot_flag = 0 + + def set_thermo_all(self, test_case, kT, gamma_global, gamma_global_rot): + if test_case < 4: + self.es.thermostat.set_langevin( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) + elif test_case == 4 and self.rot_flag == 1: + self.es.thermostat.set_langevin( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]], + gamma_rotation=[ + gamma_global_rot[0], + gamma_global_rot[1], + gamma_global_rot[2]]) + elif test_case < 8 + self.rot_flag: + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Brownian thermostat activation + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) + elif test_case == 9: + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Brownian thermostat activation + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]], + gamma_rotation=[ + gamma_global_rot[0], + gamma_global_rot[1], + gamma_global_rot[2]]) def run_test_case(self, test_case): seed(2) @@ -62,49 +106,8 @@ def run_test_case(self, test_case): gamma_rot[1, 0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) gamma_rot[1, 1] = gamma_rot[1, 0] gamma_rot[1, 2] = gamma_rot[1, 0] - - if test_case < 4: - self.es.thermostat.set_langevin( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 4 and self.rot_flag == 1: - self.es.thermostat.set_langevin( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) - elif test_case < 8 + self.rot_flag: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 9: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) + + self.set_thermo_all(test_case, 0.0, gamma_global, gamma_global_rot) self.es.cell_system.skin = 5.0 mass = 12.74 @@ -284,48 +287,7 @@ def run_test_case(self, test_case): else: gamma_rot_validate[k, :] = gamma_global[:] - if test_case < 4: - self.es.thermostat.set_langevin( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 4 and self.rot_flag == 1: - self.es.thermostat.set_langevin( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) - elif test_case < 8 + self.rot_flag: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - #self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 9: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - #self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=0.0, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) + self.set_thermo_all(test_case, 0.0, gamma_global, gamma_global_rot) self.es.time = 0.0 self.es.time_step = 7E-5 @@ -438,48 +400,7 @@ def run_test_case(self, test_case): for k in range(2): D_tr[k, :] = 2.0 * halfkT[k] / gamma_tr[k, :] - if test_case < 4: - self.es.thermostat.set_langevin( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 4 and self.rot_flag == 1: - self.es.thermostat.set_langevin( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) - elif test_case < 8 + self.rot_flag: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 9: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) + self.set_thermo_all(test_case, kT, gamma_global, gamma_global_rot) # no need to rebuild Verlet lists, avoid it self.es.cell_system.skin = 5.0 From 78de70a1731760bf52ae51545c44057e01841263 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 10 Feb 2018 12:45:14 +0200 Subject: [PATCH 024/150] Naming convention --- doc/sphinx/setup.rst | 36 ++++++++++++++++++++---------------- src/core/integrate.cpp | 34 ++++++++++++++++++---------------- src/core/rotation.cpp | 12 +++++++----- src/core/rotation.hpp | 8 ++++---- 4 files changed, 49 insertions(+), 41 deletions(-) diff --git a/doc/sphinx/setup.rst b/doc/sphinx/setup.rst index f865ba36bfa..d0be23efe7b 100644 --- a/doc/sphinx/setup.rst +++ b/doc/sphinx/setup.rst @@ -280,7 +280,7 @@ Brownian thermostat Brownian thermostat is a formal name of a thermostat enabling the Brownian Dynamics feature (see :cite:`schlick2010`). -In order to activate the Brownian thermostat the memberfunction +In order to activate the Brownian thermostat the member function :py:attr:`~espressomd.thermostat.Thermostat.set_brownian` of the thermostat class :class:`espressomd.thermostat.Thermostat` has to be invoked. Best explained in an example::: @@ -291,43 +291,47 @@ Best explained in an example::: therm.set_brownian(kT=1.0, gamma=1.0) -In terms of Python interface and setup, Brownian thermostat derives most +In terms of the Python interface and setup, Brownian thermostat derives most properties of the :ref:`Langevin thermostat`. Same feature -``LANGEVIN_PER_PARTICLE`` is using to control the per-particle +``LANGEVIN_PER_PARTICLE`` is using to be able to control the per-particle temperature and the friction coefficient setup. Major differences are its internal integrator implementation and other temporal constraints. -The integrator is still symplectic Velocity Verlet-like integrator. -It is implemented via a drift part and a random walk of both position and +The integrator is still a symplectic Velocity Verlet-like integrator. +It is implemented via a viscous drag part and a random walk of both the position and velocity. Due to a nature of the Brownian Dynamics method, ``time_step`` should be large enough compare to the relaxation time -:math:`\text{MASS}/\text{gamma}`. Note, that with all similarities of +:math:`\text{MASS}/\text{gamma}`. This requirement is just a conceptual one +without specific implementation technical restrictions. +Note, that with all similarities of Langevin and Brownian Dynamics, the Langevin thermostat temporal constraint -is opposite. Hence, a velocity is restarting from zero at every step, -velocity at the beginning of the the ``time_step`` interval is dissipated -and does not contribute to the final one. Another temporal constrain +is opposite. Hence, a velocity is restarting from zero at every step. +The velocity at the beginning of the the ``time_step`` interval is dissipated +and does not contribute to the end one as well as to the positional random walk. + +Another temporal constraint which is valid for both Langevin and Brownian Dynamics: conservative forces should not change significantly over the ``time_step`` interval. -The position :math:`\Delta_r` and velocity :math:`\Delta_v` -drift are driven by conservative forces: +The viscous terminal velocity :math:`\Delta_v` and corresponding positional +drag :math:`\Delta_r` are fully driven by conservative forces: .. math:: \Delta r = \frac{\text{F} \cdot \text{time_step}}{\text{gamma}} .. math:: \Delta v = \frac{\text{F}}{\text{gamma}} -Position random walk variance of each coordinate :math:`\sigma_p^2` +A positional random walk variance of each coordinate :math:`\sigma_p^2` corresponds to a diffusion within the Wiener process: .. math:: \sigma_p^2 = 2 D \Delta t -Velocity component random walk variance :math:`\sigma_v^2` is defined by a heat -velocity component: +Each velocity component random walk variance :math:`\sigma_v^2` is defined by the heat +component: .. math:: \sigma_v^2 = \frac{\text{temperature}}{\text{MASS}} A rotational motion is implemented similarly. The Velocity Verlet quaternion -based rotational method implementation is still used, however, modified -for a larger ``time_step``. +based rotational method implementation is still used, however, had been modified +for the larger ``time_step`` case to be consistent and still the Velocity Verlet-compliant. .. _\`\`nemd\`\`\: Setting up non-equilibirum MD: diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 6765d83c68b..7e967b8f785 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -137,10 +137,10 @@ void finalize_p_inst_npt(); #ifdef BROWNIAN_DYNAMICS -/** Propagate position: viscous drift driven by conservative forces.*/ -void bd_drift(Particle *p, double dt); -/** Set velocity: viscous drift driven by conservative forces.*/ -void bd_drift_vel(Particle *p, double dt); +/** Propagate position: viscous drag driven by conservative forces.*/ +void bd_drag(Particle *p, double dt); +/** Set the terminal velocity driven by the conservative forces drag.*/ +void bd_drag_vel(Particle *p, double dt); /** Propagate position: random walk part.*/ void bd_random_walk(Particle *p, double dt); @@ -681,7 +681,7 @@ void rescale_forces_propagate_vel() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drift_vel(&p,0.5 * time_step); + bd_drag_vel(&p,0.5 * time_step); bd_random_walk_vel(&p,0.5 * time_step); } #endif // BROWNIAN_DYNAMICS @@ -913,8 +913,8 @@ void propagate_vel() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drift_vel(&p,0.5 * time_step); - bd_drift_vel_rot(&p,0.5 * time_step); + bd_drag_vel(&p,0.5 * time_step); + bd_drag_vel_rot(&p,0.5 * time_step); bd_random_walk_vel(&p,0.5 * time_step); bd_random_walk_vel_rot(&p,0.5 * time_step); } @@ -985,8 +985,8 @@ void propagate_pos() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drift(&p, time_step); - bd_drift_rot(&p, time_step); + bd_drag(&p, time_step); + bd_drag_rot(&p, time_step); bd_random_walk(&p, time_step); bd_random_walk_rot(&p, time_step); } @@ -1044,12 +1044,12 @@ void propagate_vel_pos() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drift_vel(&p,0.5 * time_step); - bd_drift_vel_rot(&p,0.5 * time_step); + bd_drag_vel(&p,0.5 * time_step); + bd_drag_vel_rot(&p,0.5 * time_step); bd_random_walk_vel(&p,0.5 * time_step); bd_random_walk_vel_rot(&p,0.5 * time_step); - bd_drift(&p, time_step); - bd_drift_rot(&p, time_step); + bd_drag(&p, time_step); + bd_drag_rot(&p, time_step); bd_random_walk(&p, time_step); bd_random_walk_rot(&p, time_step); } @@ -1323,7 +1323,8 @@ int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, #ifdef BROWNIAN_DYNAMICS -void bd_drift(Particle *p, double dt) { +/** Propagate position: viscous drag driven by conservative forces.*/ +void bd_drag(Particle *p, double dt) { int j; double scale_f; Thermostat::GammaType local_gamma; @@ -1349,7 +1350,8 @@ void bd_drift(Particle *p, double dt) { } } -void bd_drift_vel(Particle *p, double dt) { +/** Set the terminal velocity driven by the conservative forces drag.*/ +void bd_drag_vel(Particle *p, double dt) { int j; double scale_f; Thermostat::GammaType local_gamma; @@ -1498,7 +1500,7 @@ void bd_random_walk_vel(Particle *p, double dt) { if (!(p->p.ext_flag & COORD_FIXED(j))) #endif { - // velocity is added here. It is assigned in the drift part. + // velocity is added here. It is already initialized in the terminal drag part. p->m.v[j] += brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p->p.mass); } } diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 5f07e6a43b9..f3719e7b3d9 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -352,7 +352,7 @@ void convert_torques_propagate_omega() { #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drift_vel_rot(&p,0.5 * time_step); + bd_drag_vel_rot(&p,0.5 * time_step); bd_random_walk_vel_rot(&p,0.5 * time_step); } else #endif // BROWNIAN_DYNAMICS @@ -632,7 +632,8 @@ void rotate_particle_body_j(Particle* p, int j, double phi) #ifdef BROWNIAN_DYNAMICS -void bd_drift_rot(Particle *p, double dt) { +/** Propagate quaternions: viscous drag driven by conservative torques.*/ +void bd_drag_rot(Particle *p, double dt) { int j; double a[3]; double dphi[3], dphi_u[3]; @@ -678,7 +679,8 @@ void bd_drift_rot(Particle *p, double dt) { } } -void bd_drift_vel_rot(Particle *p, double dt) { +/** Set the terminal angular velocity driven by the conservative torques drag.*/ +void bd_drag_vel_rot(Particle *p, double dt) { int j; double m_dphi; double a[3]; @@ -717,7 +719,7 @@ void bd_drift_vel_rot(Particle *p, double dt) { } } -/** Propagate the positions: random walk part.*/ +/** Propagate the quaternions: random walk part.*/ void bd_random_walk_rot(Particle *p, double dt) { double a[3]; double dphi[3]; @@ -831,7 +833,7 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { if (!(p->p.ext_flag & COORD_FIXED(j))) #endif { - // velocity is added here. It is assigned in the drift part. + // velocity is added here. It is already initialized in the terminal drag part. p->m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p->p.rinertia[j]); } } diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 842bc034c8c..ed2ccf23000 100755 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -126,10 +126,10 @@ inline void normalize_quaternion(double *q) { #ifdef BROWNIAN_DYNAMICS -/** Propagate quaternions: viscous drift driven by conservative torques.*/ -void bd_drift_rot(Particle *p, double dt); -/** Set angular velocity: viscous drift driven by conservative torques.*/ -void bd_drift_vel_rot(Particle *p, double dt); +/** Propagate quaternions: viscous drag driven by conservative torques.*/ +void bd_drag_rot(Particle *p, double dt); +/** Set the terminal angular velocity driven by the conservative torques drag.*/ +void bd_drag_vel_rot(Particle *p, double dt); /** Propagate quaternion: random walk part.*/ void bd_random_walk_rot(Particle *p, double dt); From a8f3a00082973e58c0f75f7cbdf5f4bcdae3ddcc Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 10 Feb 2018 12:46:14 +0200 Subject: [PATCH 025/150] Interim durable test --- testsuite/mass-and-rinertia_per_particle.py | 68 +++++++++++---------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 35d92757445..05fb6128937 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -478,7 +478,11 @@ def run_test_case(self, test_case): dt0 = mass / gamma_tr dt0_rot = J / gamma_rot - loops = 1250 + #if test_case in [3,(7 + self.rot_flag)]: + # loops = 5000 + #else: + # loops = 1250 + loops = 5000 print("Thermalizing...") therm_steps = 150 self.es.integrator.run(therm_steps) @@ -516,38 +520,38 @@ def run_test_case(self, test_case): # Rotational diffusion variance. if i >= fraction_i * loops: # let's limit test cases to speed this test.. - if test_case == 3: - dt -= self.es.time_step * (1 + therm_steps + fraction_i * loops) - # First, let's identify principal axes in the lab reference frame. - alpha2[k] = 0.0 - sigma2_alpha[k] = 0.0 - for j in range(3): - for j1 in range(3): - pa_body[j1] = 0.0 - pa_body[j] = 1.0 - vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) - pa_lab[j, :] = vec[:] - - if i >= fraction_i * loops + 1: - # Around which axis we rotates? - for j1 in range(3): - # Calc a rotational diffusion within the spherical trigonometry - vec2 = vec - vec1[:] = prev_pa_lab[k, p, j, :] - for j2 in range(3): - ref_lab[j2] = 0.0 - ref_lab[j1] = 1.0 - dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) - rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) - theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) - alpha[k, p, j, j1] += dalpha * rot_projection / np.sin(theta) - alpha2[k] += alpha[k, p, j, j1]**2 - sigma2_alpha[k] += D_rot[k, j] * (2.0 * dt + dt0_rot[k, j] * (- 3.0 + - 4.0 * math.exp(- dt / dt0_rot[k, j]) - - math.exp(- 2.0 * dt / dt0_rot[k, j]))) - prev_pa_lab[k, p, j, :] = pa_lab[j, :] + #if test_case in [3,(7 + self.rot_flag)]: + dt -= self.es.time_step * (1 + therm_steps + fraction_i * loops) + # First, let's identify principal axes in the lab reference frame. + alpha2[k] = 0.0 + sigma2_alpha[k] = 0.0 + for j in range(3): + for j1 in range(3): + pa_body[j1] = 0.0 + pa_body[j] = 1.0 + vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) + pa_lab[j, :] = vec[:] + if i >= fraction_i * loops + 1: - alpha_norm[k] += (alpha2[k] - sigma2_alpha[k]) / sigma2_alpha[k] + # Around which axis we rotates? + for j1 in range(3): + # Calc a rotational diffusion within the spherical trigonometry + vec2 = vec + vec1[:] = prev_pa_lab[k, p, j, :] + for j2 in range(3): + ref_lab[j2] = 0.0 + ref_lab[j1] = 1.0 + dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) + rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) + theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) + alpha[k, p, j, j1] += dalpha * rot_projection / np.sin(theta) + alpha2[k] += alpha[k, p, j, j1]**2 + sigma2_alpha[k] += D_rot[k, j] * (2.0 * dt + dt0_rot[k, j] * (- 3.0 + + 4.0 * math.exp(- dt / dt0_rot[k, j]) + - math.exp(- 2.0 * dt / dt0_rot[k, j]))) + prev_pa_lab[k, p, j, :] = pa_lab[j, :] + if i >= fraction_i * loops + 1: + alpha_norm[k] += (alpha2[k] - sigma2_alpha[k]) / sigma2_alpha[k] tolerance = 0.15 Ev = 0.5 * mass * v2 / (n * loops) From a728951eb72264dab9b87aca36cb6140d3e8cd91 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 10 Feb 2018 18:00:52 +0200 Subject: [PATCH 026/150] Long run rot diffusion test --- ...d-rinertia_per_particle_rotdiff-longrun.py | 656 ++++++++++++++++++ 1 file changed, 656 insertions(+) create mode 100644 testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py diff --git a/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py b/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py new file mode 100644 index 00000000000..fd721ef8371 --- /dev/null +++ b/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py @@ -0,0 +1,656 @@ +from __future__ import print_function +import unittest as ut +import numpy as np +from numpy.random import random, seed +import espressomd +import math +import tests_common as tc + +@ut.skipIf(not espressomd.has_features(["MASS", + "PARTICLE_ANISOTROPY", + "ROTATIONAL_INERTIA", + "LANGEVIN_PER_PARTICLE"]), + "Features not available, skipping test!") +class ThermoTest(ut.TestCase): + longMessage = True + # Handle for espresso system + es = espressomd.System(box_l=[1.0E5, 1.0E5, 1.0E5]) + rot_flag = 0 + + def set_thermo_all(self, test_case, kT, gamma_global, gamma_global_rot): + if test_case < 4: + self.es.thermostat.set_langevin( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) + elif test_case == 4 and self.rot_flag == 1: + self.es.thermostat.set_langevin( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]], + gamma_rotation=[ + gamma_global_rot[0], + gamma_global_rot[1], + gamma_global_rot[2]]) + elif test_case < 8 + self.rot_flag: + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Brownian thermostat activation + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]]) + elif test_case == 9: + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Brownian thermostat activation + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian( + kT=kT, + gamma=[ + gamma_global[0], + gamma_global[1], + gamma_global[2]], + gamma_rotation=[ + gamma_global_rot[0], + gamma_global_rot[1], + gamma_global_rot[2]]) + + def run_test_case(self, test_case): + seed(2) + # Decelleration + self.es.time_step = 0.007 + box = 1.0E5 + self.es.box_l = [box, box, box] + if espressomd.has_features(("PARTIAL_PERIODIC")): + self.es.periodicity = 0, 0, 0 + # gamma_tran/gamma_rot matrix: [2 types of particless] x [3 dimensions + # X Y Z] + gamma_tran = np.zeros((2, 3)) + gamma_tr = np.zeros((2, 3)) + gamma_rot = np.zeros((2, 3)) + gamma_rot_validate = np.zeros((2, 3)) + # The translational gamma isotropy is required here. See comments below. + # Global gamma for tests without particle-specific gammas: + # gamma_global = np.ones((3)) + gamma_global = np.zeros((3)) + gamma_global[0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) + gamma_global[1] = gamma_global[0] + gamma_global[2] = gamma_global[0] + # Additional test case (5th) for the specific global rotational gamma set. + gamma_global_rot = np.array((0.5 + np.random.random(3)) * 2.0 / 3.0) + # Per-paricle values for the remaining decelleration tests: + # Either translational friction isotropy is required + # or both translational and rotational ones. + # Otherwise these types of motion will interfere. + # ..Let's test both cases depending on the particle index. + gamma_tran[0, 0] = np.array(0.5 + np.random.random()) + gamma_tran[0, 1] = gamma_tran[0, 0] + gamma_tran[0, 2] = gamma_tran[0, 0] + if test_case < 4 + self.rot_flag: + gamma_rot[0, :] = np.array((0.5 + random(3)) * 2.0 / 3.0) + else: + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Isotropy is required here for the drag tests (see below) + gamma_rot[0, 0] = np.array((0.5 + random(1)) * 2.0 / 3.0) + gamma_rot[0, 1] = gamma_rot[0, 0] + gamma_rot[0, 2] = gamma_rot[0, 0] + + gamma_tran[1, 0] = np.array(0.5 + np.random.random()) + gamma_tran[1, 1] = gamma_tran[1, 0] + gamma_tran[1, 2] = gamma_tran[1, 0] + gamma_rot[1, 0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) + gamma_rot[1, 1] = gamma_rot[1, 0] + gamma_rot[1, 2] = gamma_rot[1, 0] + + self.set_thermo_all(test_case, 0.0, gamma_global, gamma_global_rot) + + self.es.cell_system.skin = 5.0 + mass = 12.74 + J = [10.0, 10.0, 10.0] + + for i in range(len(self.es.part)): + self.es.part[i].remove() + + for i in range(2): + self.es.part.add(rotation=(1,1,1), pos=np.array([0.0, 0.0, 0.0]), id=i) + self.es.part[i].v = np.array([1.0, 1.0, 1.0]) + if "ROTATION" in espressomd.features(): + self.es.part[i].omega_body = np.array([1.0, 1.0, 1.0]) + self.es.part[i].mass = mass + self.es.part[i].rinertia = np.array(J) + + print("\n") + + for k in range(2): + if test_case == 0: + if (k == 0): + print("================================================") + print("Langevin thermostat test cases") + print("================================================") + print("------------------------------------------------") + print("Test " + str(test_case) + ": no particle specific values") + print("------------------------------------------------") + # No assignments are needed. + + if test_case == 1: + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + + ": particle specific gamma but not temperature") + print("------------------------------------------------") + self.es.part[k].gamma = gamma_tran[k, :] + if "ROTATION" in espressomd.features(): + self.es.part[k].gamma_rot = gamma_rot[k, :] + + if test_case == 2: + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + + ": particle specific temperature but not gamma") + print("------------------------------------------------") + self.es.part[k].temp = 0.0 + + if test_case == 3: + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + + ": both particle specific gamma and temperature") + print("------------------------------------------------") + self.es.part[k].temp = 0.0 + self.es.part[k].gamma = gamma_tran[k, :] + if "ROTATION" in espressomd.features(): + self.es.part[k].gamma_rot = gamma_rot[k, :] + + if test_case == 4 and self.rot_flag == 1: + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + ": no particle specific values.") + print("Rotational specific global thermostat") + print("------------------------------------------------") + # No assignments are needed. + + if "BROWNIAN_DYNAMICS" in espressomd.features(): + for k in range(2): + if test_case == 4 + self.rot_flag: + if (k == 0): + print("================================================") + print("Brownian thermostat test cases") + print("================================================") + print("------------------------------------------------") + print("Test " + str(test_case) + ": no particle specific values") + print("------------------------------------------------") + # No assignments are needed. + + if test_case == 5 + self.rot_flag: + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + + ": particle specific gamma but not temperature") + print("------------------------------------------------") + if "PARTICLE_ANISOTROPY" in espressomd.features(): + self.es.part[k].gamma = gamma_tran[k, :] + else: + self.es.part[k].gamma = gamma_tran[k, 0] + if "ROTATION" in espressomd.features(): + self.es.part[k].gamma_rot = gamma_rot[k, :] + + if test_case == 6 + self.rot_flag: + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + + ": particle specific temperature but not gamma") + print("------------------------------------------------") + self.es.part[k].temp = 0.0 + + if test_case == 7 + self.rot_flag: + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + + ": both particle specific gamma and temperature") + print("------------------------------------------------") + self.es.part[k].temp = 0.0 + if "PARTICLE_ANISOTROPY" in espressomd.features(): + self.es.part[k].gamma = gamma_tran[k, :] + else: + self.es.part[k].gamma = gamma_tran[k, 0] + if "ROTATION" in espressomd.features(): + self.es.part[k].gamma_rot = gamma_rot[k, :] + + if test_case == 8 + self.rot_flag: + if (k == 0): + if (k == 0): + print("------------------------------------------------") + print("Test " + str(test_case) + ": no particle specific values.") + print("Rotational specific global thermostat") + print("------------------------------------------------") + # No assignments are needed. + + if test_case == 1 or test_case == 3 or test_case == (5 + self.rot_flag) or test_case == (7 + self.rot_flag): + gamma_tr = gamma_tran + gamma_rot_validate = gamma_rot + else: + for k in range(2): + gamma_tr[k, :] = gamma_global[:] + if (test_case == 4 or test_case == 9) and self.rot_flag == 1: + gamma_rot_validate[k, :] = gamma_global_rot[:] + else: + gamma_rot_validate[k, :] = gamma_global[:] + + if test_case < 4 + self.rot_flag: + # Langevin thermostat only. Brownian thermostat is defined + # over larger time-step by its concept. + self.es.time = 0.0 + tol = 1.25E-4 + for i in range(100): + for k in range(2): + for j in range(3): + # Note: velocity is defined in the lab frame of reference + # while gamma_tr is defined in the body one. + # Hence, only isotropic gamma_tr could be tested here. + self.assertLess( + abs(self.es.part[k].v[j] - math.exp(- gamma_tr[k, j] * self.es.time / mass)), tol) + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + self.es.part[k].omega_body[j] - math.exp(- gamma_rot_validate[k, j] * self.es.time / J[j])), tol) + self.es.integrator.run(10) + # The drag terminal velocity tests + ################################## + #..aka the drift in case of the electrostatics + + # Isotropic reassignment is required here for the drag tests + gamma_global_rot = np.zeros((3)) + gamma_global_rot[0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) + gamma_global_rot[1] = gamma_global_rot[0] + gamma_global_rot[2] = gamma_global_rot[0] + # Second particle already has isotropic gamma_rot + # A correction is needed for the 1st one: + gamma_rot[0, 0] = np.array((0.5 + random(1)) * 2.0 / 3.0) + gamma_rot[0, 1] = gamma_rot[0, 0] + gamma_rot[0, 2] = gamma_rot[0, 0] + + if test_case == 1 or test_case == 3 or test_case == (5 + self.rot_flag) or test_case == (7 + self.rot_flag): + gamma_tr = gamma_tran + gamma_rot_validate = gamma_rot + # A correction is needed for the 1st particle only: + if "ROTATION" in espressomd.features(): + self.es.part[0].gamma_rot = gamma_rot[0, :] + else: + for k in range(2): + gamma_tr[k, :] = gamma_global[:] + if (test_case == 4 or test_case == 9) and self.rot_flag == 1: + gamma_rot_validate[k, :] = gamma_global_rot[:] + else: + gamma_rot_validate[k, :] = gamma_global[:] + + self.set_thermo_all(test_case, 0.0, gamma_global, gamma_global_rot) + + self.es.time = 0.0 + self.es.time_step = 7E-5 + # The terminal velocity is starting since t >> t0 = mass / gamma + t0_max = -1.0 + for k in range(2): + t0_max = max(t0_max, max(mass / gamma_tr[k, :]), max(J[:] / gamma_rot_validate[k, :])) + drag_steps_0 = int(math.floor(20 * t0_max / self.es.time_step)) + print("drag_steps_0 = {0}".format(drag_steps_0)) + + tol = 7E-3 + if "EXTERNAL_FORCES" in espressomd.features(): + for k in range(2): + self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) + self.es.part[k].v = np.array([0.0, 0.0, 0.0]) + self.es.part[k].omega_body = np.array([0.0, 0.0, 0.0]) + f0 = np.array([-1.2, 58.3578, 0.002]) + f1 = np.array([-15.112, -2.0, 368.0]) + self.es.part[0].ext_force = f0 + self.es.part[1].ext_force = f1 + if "ROTATION" in espressomd.features(): + tor0 = np.array([12, 0.022, 87]) + tor1 = np.array([-0.03, -174, 368]) + self.es.part[0].ext_torque = tor0 + self.es.part[1].ext_torque = tor1 + # Let's set the dipole perpendicular to the torque + if "DIPOLES" in espressomd.features(): + dip0 = np.array([0.0, tor0[2], -tor0[1]]) + dip1 = np.array([-tor1[2], 0.0, tor1[0]]) + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) + tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) + self.es.integrator.run(drag_steps_0) + self.es.time = 0.0 + for k in range(2): + self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) + if "DIPOLES" in espressomd.features(): + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + for i in range(100): + self.es.integrator.run(10) + for k in range(3): + self.assertLess( + abs(self.es.part[0].v[k] - f0[k] / gamma_tr[0, k]), tol) + self.assertLess( + abs(self.es.part[1].v[k] - f1[k] / gamma_tr[1, k]), tol) + self.assertLess( + abs(self.es.part[0].pos[k] - self.es.time * f0[k] / gamma_tr[0, k]), tol) + self.assertLess( + abs(self.es.part[1].pos[k] - self.es.time * f1[k] / gamma_tr[1, k]), tol) + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + self.es.part[0].omega_lab[k] - tor0[k] / gamma_rot_validate[0, k]), tol) + self.assertLess(abs( + self.es.part[1].omega_lab[k] - tor1[k] / gamma_rot_validate[1, k]), tol) + if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): + cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) + cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0]) + sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) + sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0])) + + cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) + cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0]) + sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) + sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0])) + + #print("cos_alpha0 = {0}, cos_alpha0_test={1}".format(cos_alpha0, cos_alpha0_test)) + #print("dip0 = {0}, self.es.part[0].dip={1}".format(dip0, self.es.part[0].dip)) + self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) + self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) + self.assertEqual(sgn0, sgn0_test) + self.assertEqual(sgn1, sgn1_test) + + for i in range(len(self.es.part)): + self.es.part[i].remove() + + # thermalization + # Checks if every degree of freedom has 1/2 kT of energy, even when + # mass and inertia tensor are active + + # 2 different langevin parameters for particles + temp = np.array([2.5, 2.0]) + D_tr = np.zeros((2, 3)) + D_rot = np.zeros((2, 3)) + for k in range(2): + gamma_tran[k, :] = np.array((0.4 + np.random.random(3)) * 10) + gamma_rot[k, :] = np.array((0.2 + np.random.random(3)) * 20) + + box = 10.0 + self.es.box_l = [box, box, box] + if espressomd.has_features(("PARTIAL_PERIODIC",)): + self.es.periodicity = 0, 0, 0 + # Random temperature + kT = (0.3 + np.random.random()) * 5 + gamma_global = np.array((0.5 + np.random.random(3)) * 2.0 / 3.0) + gamma_global_rot = np.array((0.2 + np.random.random(3)) * 20) + + if test_case in [2,3,(6+self.rot_flag),(7+self.rot_flag)]: + halfkT = temp / 2.0 + else: + halfkT = np.array([kT, kT]) / 2.0 + + if test_case in [1,3,(5+self.rot_flag),(7+self.rot_flag)]: + gamma_tr = gamma_tran + else: + for k in range(2): + gamma_tr[k, :] = gamma_global[:] + + if test_case in [1,3,(5+self.rot_flag),(7+self.rot_flag)]: + gamma_tr = gamma_tran + gamma_rot_validate = gamma_rot + else: + for k in range(2): + gamma_tr[k, :] = gamma_global[:] + if (test_case == 4 or test_case == 9) and self.rot_flag == 1: + gamma_rot_validate[k, :] = gamma_global_rot[:] + else: + gamma_rot_validate[k, :] = gamma_global[:] + + # translational and rotational diffusion + for k in range(2): + D_tr[k, :] = 2.0 * halfkT[k] / gamma_tr[k, :] + D_rot[k, :] = 2.0 * halfkT[k] / gamma_rot_validate[k, :] + + self.set_thermo_all(test_case, kT, gamma_global, gamma_global_rot) + + # no need to rebuild Verlet lists, avoid it + self.es.cell_system.skin = 5.0 + if test_case < 4 + self.rot_flag: + self.es.time_step = 0.03 + else: + self.es.time_step = 10 + n = 200 + mass = (0.2 + np.random.random()) * 7.0 + J = np.zeros((2, 3)) + for k in range(2): + J[k, :] = np.array((0.2 + np.random.random(3)) * 7.0) + + for i in range(n): + for k in range(2): + ind = i + k * n + part_pos = np.array(np.random.random(3) * box) + part_v = np.array([0.0, 0.0, 0.0]) + part_omega_body = np.array([0.0, 0.0, 0.0]) + self.es.part.add(rotation=(1,1,1), id=ind, mass=mass, + rinertia=[J[k, 0], J[k, 1], J[k, 2]], + pos=part_pos, v=part_v) + if "ROTATION" in espressomd.features(): + self.es.part[ind].omega_body = part_omega_body + if test_case in [1,(5+self.rot_flag)]: + self.es.part[ind].gamma = gamma_tran[k, :] + if "ROTATION" in espressomd.features(): + self.es.part[ind].gamma_rot = gamma_rot[k, :] + + if test_case in [2,(6+self.rot_flag)]: + self.es.part[ind].temp = temp[k] + if test_case in [3,(7+self.rot_flag)]: + self.es.part[ind].gamma = gamma_tran[k, :] + if "ROTATION" in espressomd.features(): + self.es.part[ind].gamma_rot = gamma_rot[k, :] + self.es.part[ind].temp = temp[k] + + # Get rid of short range calculations if exclusions are on + # if espressomd.has_features("EXCLUSIONS"): + + # matrices: [2 types of particless] x [3 dimensions X Y Z] + # velocity^2, omega^2, position^2 + v2 = np.zeros((2, 3)) + o2 = np.zeros((2, 3)) + dr2 = np.zeros((2, 3)) + sigma2_tr = np.zeros((2)) + dr_norm = np.zeros((2)) + + # Total curve within a spherical trigonometry. + # [particle_index, which principal axis, around which lab axis] + alpha = np.zeros((2, n, 3, 3)) + alpha_norm = np.zeros((2)) + sigma2_alpha = np.zeros((2)) + alpha2 = np.zeros((2)) + # Previous directions of the principal axes: + # [particle_index, which principal axis, its lab coordinate] + prev_pa_lab = np.zeros((2, n, 3, 3)) + pa_body = np.zeros((3)) + pa_lab = np.zeros((3, 3)) + ref_lab = np.zeros((3)) + vec = np.zeros((3)) + vec1 = np.zeros((3)) + vec2 = np.zeros((3)) + #vec_diag = np.ones((3)) + + pos0 = np.zeros((2 * n, 3)) + for p in range(n): + for k in range(2): + ind = p + k * n + pos0[ind, :] = self.es.part[ind].pos + dt0 = mass / gamma_tr + dt0_rot = J / gamma_rot_validate + + #if test_case in [3,(7 + self.rot_flag)]: + # loops = 5000 + #else: + # loops = 1250 + loops = 5000 + print("Thermalizing...") + therm_steps = 150 + self.es.integrator.run(therm_steps) + print("Measuring...") + + int_steps = 1 + fraction_i = 0.65 + for i in range(loops): + self.es.integrator.run(int_steps) + # Get kinetic energy in each degree of freedom for all particles + for p in range(n): + for k in range(2): + ind = p + k * n + v = self.es.part[ind].v + if "ROTATION" in espressomd.features(): + o = self.es.part[ind].omega_body + o2[k, :] = o2[k, :] + np.power(o[:], 2) + pos = self.es.part[ind].pos + v2[k, :] = v2[k, :] + np.power(v[:], 2) + dr2[k, :] = np.power((pos[:] - pos0[ind, :]), 2) + dt = (int_steps * (i + 1) + therm_steps) * \ + self.es.time_step + # translational diffusion variance: after a closed-form + # integration of the Langevin EOM + sigma2_tr[k] = 0.0 + for j in range(3): + sigma2_tr[k] = sigma2_tr[k] + D_tr[k, + j] * (2.0 * dt + dt0[k, + j] * (- 3.0 + 4.0 * math.exp(- dt / dt0[k, + j]) - math.exp(- 2.0 * dt / dt0[k, + j]))) + dr_norm[k] = dr_norm[k] + \ + (sum(dr2[k, :]) - sigma2_tr[k]) / sigma2_tr[k] + + # Rotational diffusion variance. + if i >= fraction_i * loops: + # let's limit test cases to speed this test.. + #if test_case in [3,(7 + self.rot_flag)]: + dt -= self.es.time_step * (1 + therm_steps + fraction_i * loops) + # First, let's identify principal axes in the lab reference frame. + alpha2[k] = 0.0 + sigma2_alpha[k] = 0.0 + for j in range(3): + for j1 in range(3): + pa_body[j1] = 0.0 + pa_body[j] = 1.0 + vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) + pa_lab[j, :] = vec[:] + + if i >= fraction_i * loops + 1: + # Around which axis we rotates? + for j1 in range(3): + # Calc a rotational diffusion within the spherical trigonometry + vec2 = vec + vec1[:] = prev_pa_lab[k, p, j, :] + for j2 in range(3): + ref_lab[j2] = 0.0 + ref_lab[j1] = 1.0 + dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) + rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) + theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) + alpha[k, p, j, j1] += dalpha * rot_projection / np.sin(theta) + alpha2[k] += alpha[k, p, j, j1]**2 + sigma2_alpha[k] += D_rot[k, j] * (2.0 * dt + dt0_rot[k, j] * (- 3.0 + + 4.0 * math.exp(- dt / dt0_rot[k, j]) + - math.exp(- 2.0 * dt / dt0_rot[k, j]))) + prev_pa_lab[k, p, j, :] = pa_lab[j, :] + if i >= fraction_i * loops + 3: + alpha_norm[k] += (alpha2[k] - sigma2_alpha[k]) / sigma2_alpha[k] + + tolerance = 0.15 + Ev = 0.5 * mass * v2 / (n * loops) + Eo = 0.5 * J * o2 / (n * loops) + dv = np.zeros((2)) + do = np.zeros((2)) + do_vec = np.zeros((2, 3)) + for k in range(2): + dv[k] = sum(Ev[k, :]) / (3.0 * halfkT[k]) - 1.0 + do[k] = sum(Eo[k, :]) / (3.0 * halfkT[k]) - 1.0 + do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 + dr_norm = dr_norm / (n * loops) + alpha_norm = alpha_norm / (n * (1 - fraction_i) * loops - 2) + + for k in range(2): + print("\n") + print("k = " + str(k)) + print("mass = " + str(mass)) + print("gamma_tr = {0} {1} {2}".format( + gamma_tr[k, 0], gamma_tr[k, 1], gamma_tr[k, 2])) + if test_case in [1,5,3,7]: + print("gamma_rot_validate = {0} {1} {2}".format( + gamma_rot_validate[k, 0], gamma_rot_validate[k, 1], gamma_rot_validate[k, 2])) + else: + print("gamma_global = {0} {1} {2}".format( + gamma_global[0], gamma_global[1], gamma_global[2])) + print("Moment of inertia principal components: = " + str(J)) + print("1/2 kT = " + str(halfkT[k])) + print("Translational energy: {0} {1} {2}".format( + Ev[k, 0], Ev[k, 1], Ev[k, 2])) + print("Rotational energy: {0} {1} {2}".format( + Eo[k, 0], Eo[k, 1], Eo[k, 2])) + + print("Deviation in translational energy: " + str(dv[k])) + if "ROTATION" in espressomd.features(): + print("Deviation in rotational energy: " + str(do[k])) + print("Deviation in rotational energy per degrees of freedom: {0} {1} {2}".format( + do_vec[k, 0], do_vec[k, 1], do_vec[k, 2])) + print( + "Deviation in translational diffusion: {0} ".format( + dr_norm[k])) + print( + "Deviation in rotational diffusion: {0} ".format( + alpha_norm)) + + self.assertLessEqual( + abs( + dv[k]), + tolerance, + msg='Relative deviation in translational energy too large: {0}'.format( + dv[k])) + if "ROTATION" in espressomd.features(): + self.assertLessEqual( + abs( + do[k]), + tolerance, + msg='Relative deviation in rotational energy too large: {0}'.format( + do[k])) + self.assertLessEqual(abs( + do_vec[k, 0]), tolerance, msg='Relative deviation in rotational energy per the body axis X is too large: {0}'.format(do_vec[k, 0])) + self.assertLessEqual(abs( + do_vec[k, 1]), tolerance, msg='Relative deviation in rotational energy per the body axis Y is too large: {0}'.format(do_vec[k, 1])) + self.assertLessEqual(abs( + do_vec[k, 2]), tolerance, msg='Relative deviation in rotational energy per the body axis Z is too large: {0}'.format(do_vec[k, 2])) + self.assertLessEqual( + abs( + dr_norm[k]), + tolerance, + msg='Relative deviation in translational diffusion is too large: {0}'.format( + dr_norm[k])) + if test_case in (1, 3): + self.assertLessEqual( + abs( + alpha_norm[k]), + tolerance, + msg='Relative deviation in rotational diffusion is too large: {0}'.format( + alpha_norm[k])) + + def test(self): + if "ROTATION" in espressomd.features(): + self.rot_flag = 1 + if not "BROWNIAN_DYNAMICS" in espressomd.features(): + n_test_cases = 4 + self.rot_flag + else: + n_test_cases = 2 * (4 + self.rot_flag) + for i in range(n_test_cases): + self.run_test_case(i) + + +if __name__ == '__main__': + print("Features: ", espressomd.features()) + ut.main() From bdd2c305bacc4ef20c1bb5494806c3867821a480 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 10 Feb 2018 19:19:55 +0200 Subject: [PATCH 027/150] Test call correction --- testsuite/brownian_thermostat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index e20fa227d62..8f5b1dc27b5 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -32,7 +32,7 @@ class BrownianThermostat(ut.TestCase): """Tests the velocity distribution created by the Brownian thermostat against the single component Maxwell distribution.""" - s = espressomd.System() + s = espressomd.System(box_l=[1.0, 1.0, 1.0]) s.cell_system.set_n_square() s.cell_system.skin = 0.3 s.seed = range(s.cell_system.get_state()["n_nodes"]) From edb628c7a7d351686b505f5ea8013bf64a162408 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 10 Feb 2018 19:20:09 +0200 Subject: [PATCH 028/150] Test speed up --- testsuite/mass-and-rinertia_per_particle.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 5cb8443ce4f..1a0c67c2800 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -488,10 +488,7 @@ def run_test_case(self, test_case): dt0 = mass / gamma_tr dt0_rot = J / gamma_rot_validate - if test_case in [3,(7 + self.rot_flag)]: - loops = 5000 - else: - loops = 1250 + loops = 1250 print("Thermalizing...") therm_steps = 150 self.es.integrator.run(therm_steps) @@ -529,7 +526,7 @@ def run_test_case(self, test_case): # Rotational diffusion variance. if i >= fraction_i * loops: # let's limit test cases to speed this test.. - if test_case in [3,(7 + self.rot_flag)]: + if test_case in [(7 + self.rot_flag)]: dt -= self.es.time_step * (1 + therm_steps + fraction_i * loops) # First, let's identify principal axes in the lab reference frame. alpha2[k] = 0.0 From c50cc11e5b84f1249fe588fe81904e8e57b5a142 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 10 Feb 2018 19:46:01 +0200 Subject: [PATCH 029/150] Test speed up --- testsuite/mass-and-rinertia_per_particle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 1a0c67c2800..8bbd752df1e 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -488,13 +488,13 @@ def run_test_case(self, test_case): dt0 = mass / gamma_tr dt0_rot = J / gamma_rot_validate - loops = 1250 + loops = 200 print("Thermalizing...") therm_steps = 150 self.es.integrator.run(therm_steps) print("Measuring...") - int_steps = 1 + int_steps = 5 fraction_i = 0.65 for i in range(loops): self.es.integrator.run(int_steps) From c39d875202c7a2bf2635baa240aaed38f9d99cca Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 11 Mar 2018 14:23:51 +0200 Subject: [PATCH 030/150] BD documentation improvement --- doc/sphinx/system_setup.rst | 39 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index 735ad5ff8fd..c9ab0e78808 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -274,9 +274,7 @@ Best explained in an example::: import espressomd system = espressomd.System() - therm = system.Thermostat() - - therm.set_langevin(kT=1.0, gamma=1.0) + system.thermostat.set_langevin(kT=1.0, gamma=1.0) As explained before the temperature is set as thermal energy :math:`k_\mathrm{B} T`. The Langevin thermostat consists of a friction and noise term coupled @@ -421,6 +419,8 @@ Be aware that this feature is neither properly examined for all systems nor is it maintained regularly. If you use it and notice strange behavior, please contribute to solving the problem. +.. _Brownian thermostat: + Brownian thermostat ~~~~~~~~~~~~~~~~~~~ @@ -430,59 +430,58 @@ Brownian Dynamics feature (see :cite:`schlick2010`). In order to activate the Brownian thermostat the member function :py:attr:`~espressomd.thermostat.Thermostat.set_brownian` of the thermostat class :class:`espressomd.thermostat.Thermostat` has to be invoked. -Best explained in an example::: +Best explained in an example:: import espressomd system = espressomd.System() - therm = system.Thermostat() - - therm.set_brownian(kT=1.0, gamma=1.0) + system.thermostat.set_brownian(kT=1.0, gamma=1.0) +where ``gamma`` (hereinafter :math:`\gamma`) is a viscous friction coefficient. In terms of the Python interface and setup, Brownian thermostat derives most properties of the :ref:`Langevin thermostat`. Same feature ``LANGEVIN_PER_PARTICLE`` is using to be able to control the per-particle temperature and the friction coefficient setup. Major differences are its internal integrator implementation and other temporal constraints. -The integrator is still a symplectic Velocity Verlet-like integrator. +The integrator is still a symplectic Velocity Verlet-like one. It is implemented via a viscous drag part and a random walk of both the position and -velocity. Due to a nature of the Brownian Dynamics method, ``time_step`` +velocity. Due to a nature of the Brownian Dynamics method, its time step :math:`\Delta t` should be large enough compare to the relaxation time -:math:`\text{MASS}/\text{gamma}`. This requirement is just a conceptual one +:math:`m/\gamma` where :math:`m` is the particle mass. +This requirement is just a conceptual one without specific implementation technical restrictions. Note, that with all similarities of Langevin and Brownian Dynamics, the Langevin thermostat temporal constraint is opposite. A velocity is restarting from zero at every step. -Formally, the previous step velocity at the beginning of the the ``time_step`` interval +Formally, the previous step velocity at the beginning of the the :math:`\Delta t` interval is dissipated further and does not contribute to the end one as well as to the positional random walk. - Another temporal constraint which is valid for both Langevin and Brownian Dynamics: conservative forces -should not change significantly over the ``time_step`` interval. +should not change significantly over the :math:`\Delta t` interval. The viscous terminal velocity :math:`\Delta v` and corresponding positional -drag :math:`\Delta r` are fully driven by conservative forces: +step :math:`\Delta r` are fully driven by conservative forces :math:`F`: -.. math:: \Delta r = \frac{\text{F} \cdot \text{time_step}}{\text{gamma}} +.. math:: \Delta r = \frac{F \cdot \Delta t}{\gamma} -.. math:: \Delta v = \frac{\text{F}}{\text{gamma}} +.. math:: \Delta v = \frac{F}{\gamma} A positional random walk variance of each coordinate :math:`\sigma_p^2` corresponds to a diffusion within the Wiener process: -.. math:: \sigma_p^2 = 2 D \cdot \text{time_step} +.. math:: \sigma_p^2 = 2 D \cdot \Delta t -with the diffusion coefficient defined in the :ref:`Langevin thermostat` section. +with the diffusion coefficient :math:`D` defined in the :ref:`Langevin thermostat` section. Each velocity component random walk variance :math:`\sigma_v^2` is defined by the heat component: -.. math:: \sigma_v^2 = \frac{\text{temperature}}{\text{MASS}} +.. math:: \sigma_v^2 = \frac{kT}{m} Note, that the velocity random walk is propagated from zero at each step. A rotational motion is implemented similarly. The Velocity Verlet quaternion based rotational method implementation is still used, however, had been modified -for the larger ``time_step`` case to be consistent and still the Velocity Verlet-compliant. +for the larger :math:`\Delta t` case to be consistent and still the Velocity Verlet-compliant. .. _CUDA: From e0c0dae5f05d7d73162ba49e971dd08647ae40ca Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 11 Mar 2018 14:40:33 +0200 Subject: [PATCH 031/150] BD infrastructure correction, cleanup --- .travis.yml | 4 -- maintainer/configs/maxset-bd.hpp | 77 -------------------------------- maintainer/configs/maxset.hpp | 2 + testsuite/python/CMakeLists.txt | 77 -------------------------------- 4 files changed, 2 insertions(+), 158 deletions(-) delete mode 100755 maintainer/configs/maxset-bd.hpp delete mode 100644 testsuite/python/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index 14aaa78713c..1925660368e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,6 @@ matrix: sudo: required services: docker env: myconfig=maxset with_coverage=true - - os: linux - sudo: required - services: docker - env: myconfig=maxset-bd with_coverage=true - os: linux sudo: required services: docker diff --git a/maintainer/configs/maxset-bd.hpp b/maintainer/configs/maxset-bd.hpp deleted file mode 100755 index 127f86eb7f5..00000000000 --- a/maintainer/configs/maxset-bd.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* maximal set of features usable at the same time */ -#define PARTIAL_PERIODIC -#define ELECTROSTATICS -#define DIPOLES -#define ROTATION -#define ROTATIONAL_INERTIA -#define PARTICLE_ANISOTROPY -#define EXTERNAL_FORCES -#define CONSTRAINTS -#define MASS -#define EXCLUSIONS -#define MOLFORCES - - -#define BOND_CONSTRAINT -#define COLLISION_DETECTION -#define LANGEVIN_PER_PARTICLE -#define CATALYTIC_REACTIONS - -#define NEMD -#define NPT -#define GHMC -#define DPD -#define METADYNAMICS - -#define LB -#define LB_BOUNDARIES -#define LB_ELECTROHYDRODYNAMICS - -#define ENGINE - -#define BROWNIAN_DYNAMICS - -#ifdef CUDA -#define LB_GPU -#define LB_BOUNDARIES_GPU -#define ELECTROKINETICS -#define EK_BOUNDARIES -#define EK_ELECTROSTATIC_COUPLING -#define MMM1D_GPU -#endif - -#define TABULATED -#define LENNARD_JONES -#define LENNARD_JONES_GENERIC -#define LJGEN_SOFTCORE -#define LJCOS -#define LJCOS2 -#define GAUSSIAN -#define HAT -#define LJ_ANGLE -#define GAY_BERNE -#define SMOOTH_STEP -#define HERTZIAN -#define BMHTF_NACL -#define MORSE -#define BUCKINGHAM -#define SOFT_SPHERE -#define INTER_RF -#define OVERLAPPED - -#define TWIST_STACK -#define HYDROGEN_BOND - -#define BOND_ANGLE -#define BOND_ANGLEDIST -#define BOND_ANGLEDIST_HARMONIC -#define BOND_ENDANGLEDIST -#define BOND_ENDANGLEDIST_HARMONIC - -#define EXPERIMENTAL_FEATURES - - -#define VIRTUAL_SITES_RELATIVE -#define FLATNOISE - -#define ADDITIONAL_CHECKS diff --git a/maintainer/configs/maxset.hpp b/maintainer/configs/maxset.hpp index f7297f453b6..127f86eb7f5 100755 --- a/maintainer/configs/maxset.hpp +++ b/maintainer/configs/maxset.hpp @@ -29,6 +29,8 @@ #define ENGINE +#define BROWNIAN_DYNAMICS + #ifdef CUDA #define LB_GPU #define LB_BOUNDARIES_GPU diff --git a/testsuite/python/CMakeLists.txt b/testsuite/python/CMakeLists.txt deleted file mode 100644 index 3bcb39c6bfa..00000000000 --- a/testsuite/python/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -if(NOT DEFINED TEST_NP) - include(ProcessorCount) - ProcessorCount(NP) - math(EXPR TEST_NP "${NP}/2 + 1") -endif() - -function(PYTHON_TEST) - cmake_parse_arguments(TEST "" "FILE;MAX_NUM_PROC" "" ${ARGN} ) - get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) - - if(${TEST_MAX_NUM_PROC} LESS ${TEST_NP}) - set(TEST_NUM_PROC ${TEST_MAX_NUM_PROC}) - else() - set(TEST_NUM_PROC ${TEST_NP}) - endif() - - if(EXISTS ${MPIEXEC}) - add_test(${TEST_NAME} ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${TEST_NUM_PROC} ${CMAKE_BINARY_DIR}/pypresso ${TEST_FILE}) - else() - add_test(${TEST_NAME} ${CMAKE_BINARY_DIR}/pypresso ${TEST_FILE}) - endif() - - set(python_tests ${python_tests} ${TEST_FILE} PARENT_SCOPE) -endfunction(PYTHON_TEST) - -python_test(FILE bondedInteractions.py MAX_NUM_PROC 4) -python_test(FILE cellsystem.py MAX_NUM_PROC 4) -python_test(FILE constraint_homogeneous_magnetic_field.py MAX_NUM_PROC 4) -python_test(FILE constraint_shape_based.py MAX_NUM_PROC 4) -python_test(FILE coulomb_cloud_wall.py MAX_NUM_PROC 4) -python_test(FILE coulomb_tuning.py MAX_NUM_PROC 4) -python_test(FILE correlation.py MAX_NUM_PROC 4) -python_test(FILE dawaanr-and-dds-gpu.py MAX_NUM_PROC 4) -python_test(FILE electrostaticInteractions.py MAX_NUM_PROC 4) -python_test(FILE engine_langevin.py MAX_NUM_PROC 4) -python_test(FILE engine_lb.py MAX_NUM_PROC 1) -python_test(FILE engine_lbgpu.py MAX_NUM_PROC 1) -python_test(FILE ewald_gpu.py MAX_NUM_PROC 4) -python_test(FILE icc.py MAX_NUM_PROC 4) -python_test(FILE magnetostaticInteractions.py MAX_NUM_PROC 1) -python_test(FILE mass-and-rinertia_per_particle.py MAX_NUM_PROC 1) -python_test(FILE mass-and-rinertia-brownian_per_particle.py MAX_NUM_PROC 1) -python_test(FILE nonBondedInteractions.py MAX_NUM_PROC 4) -python_test(FILE observables.py MAX_NUM_PROC 4) -python_test(FILE p3m_gpu.py MAX_NUM_PROC 4) -python_test(FILE particle.py MAX_NUM_PROC 4) -python_test(FILE scafacos_dipoles_1d_2d.py MAX_NUM_PROC 4) -python_test(FILE tabulated.py MAX_NUM_PROC 4) -python_test(FILE particle_slice.py MAX_NUM_PROC 4) -python_test(FILE rotational_inertia.py MAX_NUM_PROC 4) -python_test(FILE script_interface_object_params.py MAX_NUM_PROC 4) -python_test(FILE lbgpu_remove_total_momentum.py MAX_NUM_PROC 4) -python_test(FILE tabulated.py MAX_NUM_PROC 4) -python_test(FILE reaction_ensemble.py MAX_NUM_PROC 4) -python_test(FILE constant_pH.py MAX_NUM_PROC 4) -python_test(FILE writevtf.py MAX_NUM_PROC 4) -python_test(FILE lb_stokes_sphere_gpu.py MAX_NUM_PROC 1) -python_test(FILE ek_eof_one_species_x.py MAX_NUM_PROC 1) -python_test(FILE ek_eof_one_species_y.py MAX_NUM_PROC 1) -python_test(FILE ek_eof_one_species_z.py MAX_NUM_PROC 1) -python_test(FILE ek_eof_one_species_x_nonlinear.py MAX_NUM_PROC 1) -python_test(FILE ek_eof_one_species_y_nonlinear.py MAX_NUM_PROC 1) -python_test(FILE ek_eof_one_species_z_nonlinear.py MAX_NUM_PROC 1) -python_test(FILE exclusions.py MAX_NUM_PROC 4) -python_test(FILE langevin_thermostat.py MAX_NUM_PROC 2) -python_test(FILE nsquare.py MAX_NUM_PROC 4) - -if(PY_H5PY) - python_test(FILE h5md.py MAX_NUM_PROC 2) -endif(PY_H5PY) - -add_custom_target(python_tests - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) - -add_custom_target(check_python COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) -add_dependencies(check_python pypresso python_tests) -add_dependencies(check check_python) From f697be04ed2c9ae76a5f80f0c8b3a6829673df54 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 11 Mar 2018 16:41:37 +0200 Subject: [PATCH 032/150] Formatting and code style polishing --- src/core/integrate.cpp | 64 ++++++++++++++++---------------- src/core/integrate.hpp | 1 + src/core/rotation.cpp | 59 +++++++++++++++-------------- src/core/thermostat.cpp | 48 ++++++++++++------------ testsuite/brownian_thermostat.py | 14 +++---- 5 files changed, 92 insertions(+), 94 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 5f2c1e04dc5..678b0e98ff2 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1322,16 +1322,16 @@ int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, /** Propagate position: viscous drag driven by conservative forces.*/ void bd_drag(Particle *p, double dt) { - int j; - double scale_f; Thermostat::GammaType local_gamma; - scale_f = 0.5 * time_step * time_step / p->p.mass; - - if(p->p.gamma >= Thermostat::GammaType{}) local_gamma = p->p.gamma; - else local_gamma = langevin_gamma; + if(p->p.gamma >= Thermostat::GammaType{}) { + local_gamma = p->p.gamma; + } else { + local_gamma = langevin_gamma; + } - for (j = 0; j < 3; j++) { + double scale_f = 0.5 * time_step * time_step / p->p.mass; + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif @@ -1349,16 +1349,16 @@ void bd_drag(Particle *p, double dt) { /** Set the terminal velocity driven by the conservative forces drag.*/ void bd_drag_vel(Particle *p, double dt) { - int j; - double scale_f; Thermostat::GammaType local_gamma; - scale_f = 0.5 * time_step * time_step / p->p.mass; - - if(p->p.gamma >= Thermostat::GammaType{}) local_gamma = p->p.gamma; - else local_gamma = langevin_gamma; + if(p->p.gamma >= Thermostat::GammaType{}) { + local_gamma = p->p.gamma; + } else { + local_gamma = langevin_gamma; + } - for (j = 0; j < 3; j++) { + double scale_f = 0.5 * time_step * time_step / p->p.mass; + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (p->p.ext_flag & COORD_FIXED(j)) { p->m.v[j] = 0.0; @@ -1380,16 +1380,9 @@ void bd_drag_vel(Particle *p, double dt) { /** Propagate the positions: random walk part.*/ void bd_random_walk(Particle *p, double dt) { - int j; extern Thermostat::GammaType brown_sigma_pos_inv; - Thermostat::GammaType brown_sigma_pos_temp_inv; -#ifdef PARTICLE_ANISOTROPY - double delta_pos_body[3] = { 0.0, 0.0, 0.0 }, delta_pos_lab[3] = { 0.0, 0.0, 0.0 }; -#endif - int aniso_flag = 1; // particle anisotropy flag - // first, set defaults - brown_sigma_pos_temp_inv = brown_sigma_pos_inv; + Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_inv;; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -1417,19 +1410,26 @@ void bd_random_walk(Particle *p, double dt) { brown_sigma_pos_temp_inv = sqrt(langevin_gamma / (langevin_temp_coeff * p->p.T)); else brown_sigma_pos_temp_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here - } else + } else { // Defaut values for both brown_sigma_pos_temp_inv = brown_sigma_pos_inv; + } } #endif /* LANGEVIN_PER_PARTICLE */ + int aniso_flag = 1; // particle anisotropy flag + #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. aniso_flag = (brown_sigma_pos_temp_inv[0] != brown_sigma_pos_temp_inv[1]) || (brown_sigma_pos_temp_inv[1] != brown_sigma_pos_temp_inv[2]); #endif - for (j = 0; j < 3; j++) { +#ifdef PARTICLE_ANISOTROPY + double delta_pos_body[3] = { 0.0, 0.0, 0.0 }, delta_pos_lab[3] = { 0.0, 0.0, 0.0 }; +#endif + + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif @@ -1451,7 +1451,7 @@ void bd_random_walk(Particle *p, double dt) { if (aniso_flag) { convert_vec_body_to_space(p, delta_pos_body, delta_pos_lab); - for (j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif @@ -1461,7 +1461,7 @@ void bd_random_walk(Particle *p, double dt) { } } else { // in order to save a calculation performance: - for (j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif @@ -1474,25 +1474,23 @@ void bd_random_walk(Particle *p, double dt) { /** Determine the velocities: random walk part.*/ void bd_random_walk_vel(Particle *p, double dt) { - int j; extern double brown_sigma_vel; - double brown_sigma_vel_temp; - // first, set defaults - brown_sigma_vel_temp = brown_sigma_vel; + double brown_sigma_vel_temp = brown_sigma_vel; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 1.0; // Is a particle-specific temperature specified? // here, the time_step is used only to align with Espresso default dimensionless model - if (p->p.T >= 0.) + if (p->p.T >= 0.) { brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T) * time_step; - else + } else { brown_sigma_vel_temp = brown_sigma_vel; + } #endif /* LANGEVIN_PER_PARTICLE */ - for (j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif diff --git a/src/core/integrate.hpp b/src/core/integrate.hpp index d642386d4b6..18777d10802 100755 --- a/src/core/integrate.hpp +++ b/src/core/integrate.hpp @@ -115,3 +115,4 @@ void integrate_set_nvt(); int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, int ydir, int zdir, bool cubic_box); #endif + diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 91ff56b9133..afad1c3c41c 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -625,10 +625,8 @@ void rotate_particle_body_j(Particle* p, int j, double phi) /** Propagate quaternions: viscous drag driven by conservative torques.*/ void bd_drag_rot(Particle *p, double dt) { - int j; double a[3]; - double dphi[3], dphi_u[3]; - double dphi_m; + double dphi[3]; Thermostat::GammaType local_gamma; a[0] = a[1] = a[2] = 1.0; @@ -643,11 +641,14 @@ void bd_drag_rot(Particle *p, double dt) { a[2] = 0.0; #endif - if(p->p.gamma_rot >= Thermostat::GammaType{}) local_gamma = p->p.gamma_rot; - else local_gamma = langevin_gamma_rotation; + if(p->p.gamma_rot >= Thermostat::GammaType{}) { + local_gamma = p->p.gamma_rot; + } else { + local_gamma = langevin_gamma_rotation; + } dphi[0] = dphi[1] = dphi[2] = 0.0; - for (j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif @@ -661,19 +662,18 @@ void bd_drag_rot(Particle *p, double dt) { //rotate_particle_body_j(p, j, dphi[j]); } } //j - dphi_m = 0.0; - for (j = 0; j < 3; j++) dphi_m += pow(dphi[j], 2); + double dphi_m = 0.0; + for (int j = 0; j < 3; j++) dphi_m += pow(dphi[j], 2); dphi_m = sqrt(dphi_m); + double dphi_u[3]; if (dphi_m) { - for (j = 0; j < 3; j++) dphi_u[j] = dphi[j] / dphi_m; + for (int j = 0; j < 3; j++) dphi_u[j] = dphi[j] / dphi_m; rotate_particle_body(p, dphi_u, dphi_m); } } /** Set the terminal angular velocity driven by the conservative torques drag.*/ void bd_drag_vel_rot(Particle *p, double dt) { - int j; - double m_dphi; double a[3]; Thermostat::GammaType local_gamma; @@ -689,10 +689,13 @@ void bd_drag_vel_rot(Particle *p, double dt) { a[2] = 0.0; #endif - if(p->p.gamma_rot >= Thermostat::GammaType{}) local_gamma = p->p.gamma_rot; - else local_gamma = langevin_gamma_rotation; + if(p->p.gamma_rot >= Thermostat::GammaType{}) { + local_gamma = p->p.gamma_rot; + } else { + local_gamma = langevin_gamma_rotation; + } - for (j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (p->p.ext_flag & COORD_FIXED(j)) { p->m.omega[j] = 0.0; @@ -713,10 +716,9 @@ void bd_drag_vel_rot(Particle *p, double dt) { /** Propagate the quaternions: random walk part.*/ void bd_random_walk_rot(Particle *p, double dt) { double a[3]; - double dphi[3]; - int j; extern Thermostat::GammaType brown_sigma_pos_rotation_inv; - Thermostat::GammaType brown_sigma_pos_temp_inv; + // first, set defaults + Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; a[0] = a[1] = a[2] = 1.0; #ifdef ROTATION_PER_PARTICLE @@ -730,9 +732,6 @@ void bd_random_walk_rot(Particle *p, double dt) { a[2] = 0.0; #endif - // first, set defaults - brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; - // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 2.0; @@ -759,13 +758,15 @@ void bd_random_walk_rot(Particle *p, double dt) { brown_sigma_pos_temp_inv = sqrt(langevin_gamma_rotation / (langevin_temp_coeff * p->p.T)); else brown_sigma_pos_temp_inv = -1.0 * sqrt(langevin_gamma_rotation); // just an indication of the infinity; negative sign has no sense here - } else + } else { // Defaut values for both brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; + } } #endif /* LANGEVIN_PER_PARTICLE */ - for (j = 0; j < 3; j++) { + double dphi[3]; + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif @@ -789,10 +790,10 @@ void bd_random_walk_rot(Particle *p, double dt) { /** Determine the angular velocities: random walk part.*/ void bd_random_walk_vel_rot(Particle *p, double dt) { - int j; double a[3]; extern double brown_sigma_vel_rotation; - double brown_sigma_vel_temp; + // first, set defaults + double brown_sigma_vel_temp = brown_sigma_vel_rotation; a[0] = a[1] = a[2] = 1.0; #ifdef ROTATION_PER_PARTICLE @@ -806,20 +807,18 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { a[2] = 0.0; #endif - // first, set defaults - brown_sigma_vel_temp = brown_sigma_vel_rotation; - // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 1.0; // Is a particle-specific temperature specified? - if (p->p.T >= 0.) + if (p->p.T >= 0.) { brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T); - else + } else { brown_sigma_vel_temp = brown_sigma_vel_rotation; + } #endif /* LANGEVIN_PER_PARTICLE */ - for (j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p->p.ext_flag & COORD_FIXED(j))) #endif diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index fa8091f3fbc..16f142517d7 100755 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -48,6 +48,7 @@ Vector3d sentinel(Vector3d) { return {-1.0, -1.0, -1.0}; } } /* LANGEVIN THERMOSTAT */ + /* Langevin friction coefficient gamma for translation. */ GammaType langevin_gamma = sentinel(GammaType{}); /* Friction coefficient gamma for rotation. */ @@ -186,29 +187,30 @@ void thermo_init_npt_isotropic() { // brown_sigma_pos determines here the BD position random walk dispersion // default particle mass is assumed to be unitary in this global parameters void thermo_init_brownian() { - int j; - // Dispersions correspond to the Gaussian noise only which is only valid for the BD. - // here, the time_step is used only to align with Espresso default dimensionless model (translational velocity only) - brown_sigma_vel = sqrt(temperature) * time_step; - if (temperature > 0.0) - brown_sigma_pos_inv = sqrt(langevin_gamma / (2.0 * temperature)); - else - brown_sigma_pos_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here - #ifdef ROTATION - // Note: the BD thermostat assigns the langevin viscous parameters as well - /* If gamma_rotation is not set explicitly, - use the linear one. */ - if (langevin_gamma_rotation < GammaType{}) { - langevin_gamma_rotation = langevin_gamma; - } - brown_sigma_vel_rotation = sqrt(temperature); - if (temperature > 0.0) - brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (2.0 * temperature)); - else - brown_sigma_pos_rotation_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here - THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation_inv)); - #endif // ROTATION - THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos=%f",this_node,brown_sigma_vel,brown_sigma_pos_inv)); + // Dispersions correspond to the Gaussian noise only which is only valid for the BD. + // here, the time_step is used only to align with Espresso default dimensionless model (translational velocity only) + brown_sigma_vel = sqrt(temperature) * time_step; + if (temperature > 0.0) { + brown_sigma_pos_inv = sqrt(langevin_gamma / (2.0 * temperature)); + } else { + brown_sigma_pos_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here + } +#ifdef ROTATION + // Note: the BD thermostat assigns the langevin viscous parameters as well + /* If gamma_rotation is not set explicitly, + use the linear one. */ + if (langevin_gamma_rotation < GammaType{}) { + langevin_gamma_rotation = langevin_gamma; + } + brown_sigma_vel_rotation = sqrt(temperature); + if (temperature > 0.0) { + brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (2.0 * temperature)); + } else { + brown_sigma_pos_rotation_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here + } + THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation_inv)); +#endif // ROTATION + THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos=%f",this_node,brown_sigma_vel,brown_sigma_pos_inv)); } #endif // BROWNIAN_DYNAMICS diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index 8f5b1dc27b5..7d92a694316 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -153,10 +153,8 @@ def test_brownian_per_particle(self): :] = s.part[int(N / 2):].v if espressomd.has_features("ROTATION"): - omega_kT[int(i * N / 2):int((i + 1) * N / 2), - :] = s.part[:int(N / 2)].omega_body - omega_kT2[int(i * N / 2):int((i + 1) * N / 2), - :] = s.part[int(N / 2):].omega_body + omega_kT[int(i * N / 2):int((i + 1) * N / 2),:] = s.part[:int(N / 2)].omega_body + omega_kT2[int(i * N / 2):int((i + 1) * N / 2),:] = s.part[int(N / 2):].omega_body v_minmax = 5 bins = 5 error_tol = 0.014 @@ -219,11 +217,11 @@ def test_diffusion(self): if espressomd.has_features("PARTICLE_ANISOTROPY"): p_gamma.gamma =per_part_gamma,per_part_gamma,per_part_gamma if espressomd.has_features("ROTATION"): - p_gamma.gamma_rot=per_part_gamma_rot_a + p_gamma.gamma_rot=per_part_gamma_rot_a else: p_gamma.gamma =per_part_gamma if espressomd.has_features("ROTATION"): - p_gamma.gamma_rot=per_part_gamma_rot_i + p_gamma.gamma_rot=per_part_gamma_rot_i p_kT=s.part.add(pos=(0,0,0)) self.setup_diff_mass_rinertia(p_kT) @@ -235,11 +233,11 @@ def test_diffusion(self): if espressomd.has_features("PARTICLE_ANISOTROPY"): p_both.gamma =per_part_gamma,per_part_gamma,per_part_gamma if espressomd.has_features("ROTATION"): - p_both.gamma_rot=per_part_gamma_rot_a + p_both.gamma_rot=per_part_gamma_rot_a else: p_both.gamma =per_part_gamma if espressomd.has_features("ROTATION"): - p_both.gamma_rot=per_part_gamma_rot_i + p_both.gamma_rot=per_part_gamma_rot_i From 3aa767f27da8d8e4d5429aa58fd658b55f2c91af Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 00:57:58 +0200 Subject: [PATCH 033/150] Requested refactoring, bibliography references --- src/core/brownian_inline.hpp | 66 +++++++++++ src/core/integrate.cpp | 208 +++++++++++++++++------------------ src/core/rotation.cpp | 183 +++++++++++++++++------------- src/core/rotation.hpp | 10 +- src/core/thermostat.cpp | 23 +++- src/core/thermostat.hpp | 2 +- 6 files changed, 302 insertions(+), 190 deletions(-) create mode 100644 src/core/brownian_inline.hpp diff --git a/src/core/brownian_inline.hpp b/src/core/brownian_inline.hpp new file mode 100644 index 00000000000..057678d182b --- /dev/null +++ b/src/core/brownian_inline.hpp @@ -0,0 +1,66 @@ +/* + Copyright (C) 2010,2011,2012,2013,2014,2015,2016,2017,2018 The ESPResSo project + Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 + Max-Planck-Institute for Polymer Research, Theory Group + + This file is part of ESPResSo. + + ESPResSo is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ESPResSo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** \file brownian_inline.hpp */ + +#ifndef BROWNIAN_INLINE_HPP +#define BROWNIAN_INLINE_HPP + +#include "thermostat.hpp" + +#ifdef BROWNIAN_DYNAMICS +/** Propagate position: viscous drag driven by conservative forces.*/ +/*********************************************************/ +/** \name bd_drag */ +/*********************************************************/ +/**(Eq. (14.39) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +inline void bd_drag(Particle &p, double dt) { + // The friction tensor Z from the Eq. (14.31) of Schlick2010: + Thermostat::GammaType local_gamma; + + if(p.p.gamma >= Thermostat::GammaType{}) { + local_gamma = p.p.gamma; + } else { + local_gamma = langevin_gamma; + } + + double scale_f = 0.5 * time_step * time_step / p.p.mass; + for (int j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p.p.ext_flag & COORD_FIXED(j))) +#endif + { + // Second (deterministic) term of the Eq. (14.39) of Schlick2010. + // scale_f is required to be aligned with rescaled forces + // only a conservative part of the force is used here +#ifndef PARTICLE_ANISOTROPY + p.r.p[j] += p.f.f[j] * dt / (local_gamma * scale_f); +#else + p.r.p[j] += p.f.f[j] * dt / (local_gamma[j] * scale_f); +#endif // PARTICLE_ANISOTROPY + } + } +} +#endif // BROWNIAN_DYNAMICS + +#endif // BROWNIAN_INLINE_HPP diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 678b0e98ff2..9bfa92fcca0 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -59,6 +59,9 @@ #include "virtual_sites.hpp" #include "npt.hpp" #include "collision.hpp" +#ifdef BROWNIAN_DYNAMICS +#include "brownian_inline.hpp" +#endif // BROWNIAN_DYNAMICS #include #include #include @@ -137,15 +140,13 @@ void finalize_p_inst_npt(); #ifdef BROWNIAN_DYNAMICS -/** Propagate position: viscous drag driven by conservative forces.*/ -void bd_drag(Particle *p, double dt); /** Set the terminal velocity driven by the conservative forces drag.*/ -void bd_drag_vel(Particle *p, double dt); +void bd_drag_vel(Particle &p, double dt); /** Propagate position: random walk part.*/ -void bd_random_walk(Particle *p, double dt); +void bd_random_walk(Particle &p, double dt); /** Thermalize velocity: random walk part.*/ -void bd_random_walk_vel(Particle *p, double dt); +void bd_random_walk_vel(Particle &p, double dt); #endif // BROWNIAN_DYNAMICS @@ -678,8 +679,8 @@ void rescale_forces_propagate_vel() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel(&p,0.5 * time_step); - bd_random_walk_vel(&p,0.5 * time_step); + bd_drag_vel(p,0.5 * time_step); + bd_random_walk_vel(p,0.5 * time_step); } #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { @@ -910,10 +911,10 @@ void propagate_vel() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel(&p,0.5 * time_step); - bd_drag_vel_rot(&p,0.5 * time_step); - bd_random_walk_vel(&p,0.5 * time_step); - bd_random_walk_vel_rot(&p,0.5 * time_step); + bd_drag_vel(p,0.5 * time_step); + bd_drag_vel_rot(p,0.5 * time_step); + bd_random_walk_vel(p,0.5 * time_step); + bd_random_walk_vel_rot(p,0.5 * time_step); } #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { @@ -982,10 +983,10 @@ void propagate_pos() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drag(&p, time_step); - bd_drag_rot(&p, time_step); - bd_random_walk(&p, time_step); - bd_random_walk_rot(&p, time_step); + bd_drag(p, time_step); + bd_drag_rot(p, time_step); + bd_random_walk(p, time_step); + bd_random_walk_rot(p, time_step); } #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { @@ -1041,14 +1042,14 @@ void propagate_vel_pos() { #endif #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel(&p,0.5 * time_step); - bd_drag_vel_rot(&p,0.5 * time_step); - bd_random_walk_vel(&p,0.5 * time_step); - bd_random_walk_vel_rot(&p,0.5 * time_step); - bd_drag(&p, time_step); - bd_drag_rot(&p, time_step); - bd_random_walk(&p, time_step); - bd_random_walk_rot(&p, time_step); + bd_drag_vel(p,0.5 * time_step); + bd_drag_vel_rot(p,0.5 * time_step); + bd_random_walk_vel(p,0.5 * time_step); + bd_random_walk_vel_rot(p,0.5 * time_step); + bd_drag(p, time_step); + bd_drag_rot(p, time_step); + bd_random_walk(p, time_step); + bd_random_walk_rot(p, time_step); } #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { @@ -1320,96 +1321,90 @@ int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, #ifdef BROWNIAN_DYNAMICS -/** Propagate position: viscous drag driven by conservative forces.*/ -void bd_drag(Particle *p, double dt) { - Thermostat::GammaType local_gamma; - - if(p->p.gamma >= Thermostat::GammaType{}) { - local_gamma = p->p.gamma; - } else { - local_gamma = langevin_gamma; - } - - double scale_f = 0.5 * time_step * time_step / p->p.mass; - for (int j = 0; j < 3; j++) { -#ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) -#endif - { - // scale_f is required to be aligned with rescaled forces - // only a conservative part of the force is used here -#ifndef PARTICLE_ANISOTROPY - p->r.p[j] += p->f.f[j] * dt / (local_gamma * scale_f); -#else - p->r.p[j] += p->f.f[j] * dt / (local_gamma[j] * scale_f); -#endif // PARTICLE_ANISOTROPY - } - } -} - /** Set the terminal velocity driven by the conservative forces drag.*/ -void bd_drag_vel(Particle *p, double dt) { +/*********************************************************/ +/** \name bd_drag_vel */ +/*********************************************************/ +/**(Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_drag_vel(Particle &p, double dt) { + // The friction tensor Z from the eq. (14.31) of Schlick2010: Thermostat::GammaType local_gamma; - if(p->p.gamma >= Thermostat::GammaType{}) { - local_gamma = p->p.gamma; + if(p.p.gamma >= Thermostat::GammaType{}) { + local_gamma = p.p.gamma; } else { local_gamma = langevin_gamma; } - double scale_f = 0.5 * time_step * time_step / p->p.mass; + double scale_f = 0.5 * time_step * time_step / p.p.mass; for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (p->p.ext_flag & COORD_FIXED(j)) { - p->m.v[j] = 0.0; + if (p.p.ext_flag & COORD_FIXED(j)) { + p.m.v[j] = 0.0; } else #endif { - // here, the additional time_step is used only to align with Espresso default dimensionless model + // First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). + // here, the additional time_step is used only to align with ESPResSo default dimensionless model // scale_f is required to be aligned with rescaled forces // only conservative part of the force is used here // NOTE: velocity is assigned here and propagated by thermal part further on top of it #ifndef PARTICLE_ANISOTROPY - p->m.v[j] = p->f.f[j] * time_step / (local_gamma * scale_f); + p.m.v[j] = p.f.f[j] * time_step / (local_gamma * scale_f); #else - p->m.v[j] = p->f.f[j] * time_step / (local_gamma[j] * scale_f); + p.m.v[j] = p.f.f[j] * time_step / (local_gamma[j] * scale_f); #endif // PARTICLE_ANISOTROPY } } } /** Propagate the positions: random walk part.*/ -void bd_random_walk(Particle *p, double dt) { +/*********************************************************/ +/** \name bd_drag_vel */ +/*********************************************************/ +/**(Eq. (14.37) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_random_walk(Particle &p, double dt) { + // Position dispersion is defined by the second eq. (14.38) of Schlick2010 taking into account eq. (14.35). + // Its time interval factor will be added at the end of this function. + // Its square root is the standard deviation. A multiplicative inverse of the position standard deviation: extern Thermostat::GammaType brown_sigma_pos_inv; + // Just a NAN setter, technical variable: + extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults - Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_inv;; + Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_inv; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 2.0; - if(p->p.gamma >= Thermostat::GammaType{}) - { + if(p.p.gamma >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? - if(p->p.T >= 0.) + if(p.p.T >= 0.) { - if (p->p.T > 0.0) - brown_sigma_pos_temp_inv = sqrt(p->p.gamma / (langevin_temp_coeff * p->p.T)); - else - brown_sigma_pos_temp_inv = -1.0 * sqrt(p->p.gamma); // just an indication of the infinity; negative sign has no sense here + if (p.p.T > 0.0) { + brown_sigma_pos_temp_inv = sqrt(p.p.gamma / (langevin_temp_coeff * p.p.T)); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + } } else // Default temperature but particle-specific gamma - brown_sigma_pos_temp_inv = sqrt(p->p.gamma / (langevin_temp_coeff * temperature)); + brown_sigma_pos_temp_inv = sqrt(p.p.gamma / (langevin_temp_coeff * temperature)); } // particle specific gamma else { // No particle-specific gamma, but is there particle-specific temperature - if(p->p.T >= 0.) - { - if(p->p.T > 0.0) - brown_sigma_pos_temp_inv = sqrt(langevin_gamma / (langevin_temp_coeff * p->p.T)); - else - brown_sigma_pos_temp_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here + if(p.p.T >= 0.) { + if(p.p.T > 0.0) { + brown_sigma_pos_temp_inv = sqrt(langevin_gamma / (langevin_temp_coeff * p.p.T)); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + } } else { // Defaut values for both brown_sigma_pos_temp_inv = brown_sigma_pos_inv; @@ -1417,7 +1412,7 @@ void bd_random_walk(Particle *p, double dt) { } #endif /* LANGEVIN_PER_PARTICLE */ - int aniso_flag = 1; // particle anisotropy flag + bool aniso_flag = true; // particle anisotropy flag #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. @@ -1429,51 +1424,52 @@ void bd_random_walk(Particle *p, double dt) { double delta_pos_body[3] = { 0.0, 0.0, 0.0 }, delta_pos_lab[3] = { 0.0, 0.0, 0.0 }; #endif + // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared magnitude defined in the second eq. (14.38), Schlick2010. for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { #ifndef PARTICLE_ANISOTROPY - if (brown_sigma_pos_temp_inv > 0.0) + if (brown_sigma_pos_temp_inv > 0.0) { delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * Thermostat::noise_g(); - else + } else { delta_pos_body[j] = 0.0; + } #else - if (brown_sigma_pos_temp_inv[j] > 0.0) + if (brown_sigma_pos_temp_inv[j] > 0.0) { delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * Thermostat::noise_g(); - else + } else { delta_pos_body[j] = 0.0; + } #endif // PARTICLE_ANISOTROPY } } if (aniso_flag) { - convert_vec_body_to_space(p, delta_pos_body, delta_pos_lab); + convert_vec_body_to_space(&(p), delta_pos_body, delta_pos_lab); + } - for (int j = 0; j < 3; j++) { -#ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) -#endif - { - p->r.p[j] += delta_pos_lab[j]; - } - } - } else { - // in order to save a calculation performance: - for (int j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif - { - p->r.p[j] += delta_pos_body[j]; - } + { + p.r.p[j] += aniso_flag ? delta_pos_lab[j] : delta_pos_body[j]; } } } /** Determine the velocities: random walk part.*/ -void bd_random_walk_vel(Particle *p, double dt) { +/*********************************************************/ +/** \name bd_random_walk_vel */ +/*********************************************************/ +/**(Eq. (10.2.16) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_random_walk_vel(Particle &p, double dt) { + // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs afterwards, Pottier2010 extern double brown_sigma_vel; // first, set defaults double brown_sigma_vel_temp = brown_sigma_vel; @@ -1482,9 +1478,9 @@ void bd_random_walk_vel(Particle *p, double dt) { #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 1.0; // Is a particle-specific temperature specified? - // here, the time_step is used only to align with Espresso default dimensionless model - if (p->p.T >= 0.) { - brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T) * time_step; + // here, the time_step is used only to align with ESPResSo default dimensionless model + if (p.p.T >= 0.) { + brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p.p.T) * time_step; } else { brown_sigma_vel_temp = brown_sigma_vel; } @@ -1492,11 +1488,15 @@ void bd_random_walk_vel(Particle *p, double dt) { for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - // velocity is added here. It is already initialized in the terminal drag part. - p->m.v[j] += brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p->p.mass); + // Random (heat) velocity is added here. It is already initialized in the terminal drag part. + // See eq. (10.2.16) taking into account eq. (10.2.18) and (10.2.29), Pottier2010. + // Note, that the Pottier2010 units system (see Eq. (10.1.1) there) has been adapted towards the ESPResSo and the referenced above Schlick2010 one, + // which is defined by the eq. (14.31) of Schlick2010. A difference is the mass factor to the friction tensor. + // The noise is Gaussian according to the convention at p. 237 (last paragraph), Pottier2010. + p.m.v[j] += brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p.p.mass); } } } diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index afad1c3c41c..48563986966 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -45,6 +45,9 @@ #include "particle_data.hpp" #include "thermostat.hpp" #include "utils.hpp" +#ifdef BROWNIAN_DYNAMICS +#include "brownian_inline.hpp" +#endif // BROWNIAN_DYNAMICS #include #include #include @@ -352,8 +355,8 @@ void convert_torques_propagate_omega() { #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel_rot(&p,0.5 * time_step); - bd_random_walk_vel_rot(&p,0.5 * time_step); + bd_drag_vel_rot(p,0.5 * time_step); + bd_random_walk_vel_rot(p,0.5 * time_step); } else #endif // BROWNIAN_DYNAMICS { @@ -498,7 +501,7 @@ void convert_vel_space_to_body(const Particle *p, double *vel_body) { A[2 + 3 * 2] * p->m.v[2]; } -void convert_vec_space_to_body(Particle *p, double *v, double *res) { +void convert_vec_space_to_body(Particle *p, double const *v, double *res) { double A[9]; define_rotation_matrix(p, A); @@ -507,7 +510,7 @@ void convert_vec_space_to_body(Particle *p, double *v, double *res) { res[2] = A[2 + 3 * 0] * v[0] + A[2 + 3 * 1] * v[1] + A[2 + 3 * 2] * v[2]; } -void convert_vec_body_to_space(Particle *p, double *v,double* res) +void convert_vec_body_to_space(Particle *p, double const *v,double* res) { double A[9]; define_rotation_matrix(p, A); @@ -545,12 +548,12 @@ void rotate_particle(Particle *p, double *aSpaceFrame, double phi) { for (int i = 0; i < 3; i++) a[i] /= l; - double q[4]; - q[0] = cos(phi / 2); - double tmp = sin(phi / 2); - q[1] = tmp * a[0]; - q[2] = tmp * a[1]; - q[3] = tmp * a[2]; + double q[] = { + cos(phi / 2), + sin(phi / 2) * a[0], + sin(phi / 2) * a[1], + sin(phi / 2) * a[2] + }; // Normalize normalize_quaternion(q); @@ -589,12 +592,12 @@ void rotate_particle_body(Particle* p, double* a, double phi) #endif - double q[4]; - q[0]=cos(phi/2); - double tmp=sin(phi/2); - q[1]=tmp*a[0]; - q[2]=tmp*a[1]; - q[3]=tmp*a[2]; + double q[] = { + cos(phi / 2), + sin(phi / 2) * a[0], + sin(phi / 2) * a[1], + sin(phi / 2) * a[2] + }; // Normalize normalize_quaternion(q); @@ -615,7 +618,7 @@ void rotate_particle_body(Particle* p, double* a, double phi) void rotate_particle_body_j(Particle* p, int j, double phi) { double u_dphi[3] = {0.0, 0.0, 0.0}; - if (phi) { + if (phi != 0.0) { u_dphi[j] = 1.0; rotate_particle_body(p, u_dphi, phi); } @@ -624,25 +627,32 @@ void rotate_particle_body_j(Particle* p, int j, double phi) #ifdef BROWNIAN_DYNAMICS /** Propagate quaternions: viscous drag driven by conservative torques.*/ -void bd_drag_rot(Particle *p, double dt) { +/*********************************************************/ +/** \name bd_drag_rot */ +/*********************************************************/ +/**(An analogy of eq. (14.39) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_drag_rot(Particle &p, double dt) { double a[3]; double dphi[3]; Thermostat::GammaType local_gamma; a[0] = a[1] = a[2] = 1.0; #ifdef ROTATION_PER_PARTICLE - if (!p->p.rotation) + if (!p.p.rotation) return; - if (!(p->p.rotation & 2)) + if (!(p.p.rotation & 2)) a[0] = 0.0; - if (!(p->p.rotation & 4)) + if (!(p.p.rotation & 4)) a[1] = 0.0; - if (!(p->p.rotation & 8)) + if (!(p.p.rotation & 8)) a[2] = 0.0; #endif - if(p->p.gamma_rot >= Thermostat::GammaType{}) { - local_gamma = p->p.gamma_rot; + if(p.p.gamma_rot >= Thermostat::GammaType{}) { + local_gamma = p.p.gamma_rot; } else { local_gamma = langevin_gamma_rotation; } @@ -650,14 +660,14 @@ void bd_drag_rot(Particle *p, double dt) { dphi[0] = dphi[1] = dphi[2] = 0.0; for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { // only a conservative part of the torque is used here #ifndef PARTICLE_ANISOTROPY - dphi[j] = a[j] * p->f.torque[j] * dt / (local_gamma); + dphi[j] = a[j] * p.f.torque[j] * dt / (local_gamma); #else - dphi[j] = a[j] * p->f.torque[j] * dt / (local_gamma[j]); + dphi[j] = a[j] * p.f.torque[j] * dt / (local_gamma[j]); #endif // ROTATIONAL_INERTIA //rotate_particle_body_j(p, j, dphi[j]); } @@ -668,67 +678,82 @@ void bd_drag_rot(Particle *p, double dt) { double dphi_u[3]; if (dphi_m) { for (int j = 0; j < 3; j++) dphi_u[j] = dphi[j] / dphi_m; - rotate_particle_body(p, dphi_u, dphi_m); + rotate_particle_body(&(p), dphi_u, dphi_m); } } /** Set the terminal angular velocity driven by the conservative torques drag.*/ -void bd_drag_vel_rot(Particle *p, double dt) { +/*********************************************************/ +/** \name bd_drag_vel_rot */ +/*********************************************************/ +/**(An analogy of the 1st term of the eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_drag_vel_rot(Particle &p, double dt) { double a[3]; Thermostat::GammaType local_gamma; a[0] = a[1] = a[2] = 1.0; #ifdef ROTATION_PER_PARTICLE - if (!p->p.rotation) + if (!p.p.rotation) return; - if (!(p->p.rotation & 2)) + if (!(p.p.rotation & 2)) a[0] = 0.0; - if (!(p->p.rotation & 4)) + if (!(p.p.rotation & 4)) a[1] = 0.0; - if (!(p->p.rotation & 8)) + if (!(p.p.rotation & 8)) a[2] = 0.0; #endif - if(p->p.gamma_rot >= Thermostat::GammaType{}) { - local_gamma = p->p.gamma_rot; + if(p.p.gamma_rot >= Thermostat::GammaType{}) { + local_gamma = p.p.gamma_rot; } else { local_gamma = langevin_gamma_rotation; } for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (p->p.ext_flag & COORD_FIXED(j)) { - p->m.omega[j] = 0.0; + if (p.p.ext_flag & COORD_FIXED(j)) { + p.m.omega[j] = 0.0; } else #endif { // only conservative part of the force is used here // NOTE: velocity is assigned here and propagated by thermal part further on top of it #ifndef PARTICLE_ANISOTROPY - p->m.omega[j] = a[j] * p->f.torque[j] / (local_gamma); + p.m.omega[j] = a[j] * p.f.torque[j] / (local_gamma); #else - p->m.omega[j] = a[j] * p->f.torque[j] / (local_gamma[j]); + p.m.omega[j] = a[j] * p.f.torque[j] / (local_gamma[j]); #endif // ROTATIONAL_INERTIA } } } /** Propagate the quaternions: random walk part.*/ -void bd_random_walk_rot(Particle *p, double dt) { +/*********************************************************/ +/** \name bd_random_walk_rot */ +/*********************************************************/ +/**(An analogy of eq. (14.37) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_random_walk_rot(Particle &p, double dt) { double a[3]; extern Thermostat::GammaType brown_sigma_pos_rotation_inv; + extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; a[0] = a[1] = a[2] = 1.0; #ifdef ROTATION_PER_PARTICLE - if (!p->p.rotation) + if (!p.p.rotation) return; - if (!(p->p.rotation & 2)) + if (!(p.p.rotation & 2)) a[0] = 0.0; - if (!(p->p.rotation & 4)) + if (!(p.p.rotation & 4)) a[1] = 0.0; - if (!(p->p.rotation & 8)) + if (!(p.p.rotation & 8)) a[2] = 0.0; #endif @@ -736,28 +761,27 @@ void bd_random_walk_rot(Particle *p, double dt) { #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 2.0; - if(p->p.gamma_rot >= Thermostat::GammaType{}) - { + if(p.p.gamma_rot >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? - if(p->p.T >= 0.) + if(p.p.T >= 0.) { - if (p->p.T > 0.0) - brown_sigma_pos_temp_inv = sqrt(p->p.gamma_rot / (langevin_temp_coeff * p->p.T) ); - else - brown_sigma_pos_temp_inv = -1.0 * sqrt(p->p.gamma_rot); // just an indication of the infinity; negative sign has no sense here + if (p.p.T > 0.0) { + brown_sigma_pos_temp_inv = sqrt(p.p.gamma_rot / (langevin_temp_coeff * p.p.T) ); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + } } else // Default temperature but particle-specific gamma - brown_sigma_pos_temp_inv = sqrt(p->p.gamma_rot / (langevin_temp_coeff * temperature)); + brown_sigma_pos_temp_inv = sqrt(p.p.gamma_rot / (langevin_temp_coeff * temperature)); } // particle specific gamma - else - { + else { // No particle-specific gamma, but is there particle-specific temperature - if(p->p.T >= 0.) - { - if (p->p.T > 0.0) - brown_sigma_pos_temp_inv = sqrt(langevin_gamma_rotation / (langevin_temp_coeff * p->p.T)); - else - brown_sigma_pos_temp_inv = -1.0 * sqrt(langevin_gamma_rotation); // just an indication of the infinity; negative sign has no sense here + if(p.p.T >= 0.) { + if (p.p.T > 0.0) { + brown_sigma_pos_temp_inv = sqrt(langevin_gamma_rotation / (langevin_temp_coeff * p.p.T)); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + } } else { // Defaut values for both brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; @@ -768,28 +792,37 @@ void bd_random_walk_rot(Particle *p, double dt) { double dphi[3]; for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { dphi[0] = dphi[1] = dphi[2] = 0.0; #ifndef PARTICLE_ANISOTROPY - if (brown_sigma_pos_temp_inv > 0.0) + if (brown_sigma_pos_temp_inv > 0.0) { dphi[j] = a[j] * Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); - else + } else { dphi[j] = 0.0; + } #else - if (brown_sigma_pos_temp_inv[j] > 0.0) + if (brown_sigma_pos_temp_inv[j] > 0.0) { dphi[j] = a[j] * Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); - else + } else { dphi[j] = 0.0; + } #endif // ROTATIONAL_INERTIA - rotate_particle_body_j(p, j, dphi[j]); + rotate_particle_body_j(&(p), j, dphi[j]); } } } /** Determine the angular velocities: random walk part.*/ -void bd_random_walk_vel_rot(Particle *p, double dt) { +/*********************************************************/ +/** \name bd_random_walk_vel_rot */ +/*********************************************************/ +/**(An analogy of eq. (10.2.16) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_random_walk_vel_rot(Particle &p, double dt) { double a[3]; extern double brown_sigma_vel_rotation; // first, set defaults @@ -797,13 +830,13 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { a[0] = a[1] = a[2] = 1.0; #ifdef ROTATION_PER_PARTICLE - if (!p->p.rotation) + if (!p.p.rotation) return; - if (!(p->p.rotation & 2)) + if (!(p.p.rotation & 2)) a[0] = 0.0; - if (!(p->p.rotation & 4)) + if (!(p.p.rotation & 4)) a[1] = 0.0; - if (!(p->p.rotation & 8)) + if (!(p.p.rotation & 8)) a[2] = 0.0; #endif @@ -811,8 +844,8 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 1.0; // Is a particle-specific temperature specified? - if (p->p.T >= 0.) { - brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p->p.T); + if (p.p.T >= 0.) { + brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p.p.T); } else { brown_sigma_vel_temp = brown_sigma_vel_rotation; } @@ -820,11 +853,11 @@ void bd_random_walk_vel_rot(Particle *p, double dt) { for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (!(p->p.ext_flag & COORD_FIXED(j))) + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { // velocity is added here. It is already initialized in the terminal drag part. - p->m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p->p.rinertia[j]); + p.m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p.p.rinertia[j]); } } } diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index cbf1b7674f6..dbf8474420f 100755 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -65,7 +65,7 @@ Vector3d convert_vector_body_to_space(const Particle& p, const Vector3d& v); void convert_vel_space_to_body(const Particle *p, double *vel_body); /** convert a vector from the body-fixed frames to space-fixed coordinates */ -void convert_vec_body_to_space(Particle *p, double *v,double* res); +void convert_vec_body_to_space(Particle *p, double const *v,double* res); /** Here we use quaternions to calculate the rotation matrix which will be used then to transform torques from the laboratory to @@ -134,14 +134,14 @@ inline void normalize_quaternion(double *q) { #ifdef BROWNIAN_DYNAMICS /** Propagate quaternions: viscous drag driven by conservative torques.*/ -void bd_drag_rot(Particle *p, double dt); +void bd_drag_rot(Particle &p, double dt); /** Set the terminal angular velocity driven by the conservative torques drag.*/ -void bd_drag_vel_rot(Particle *p, double dt); +void bd_drag_vel_rot(Particle &p, double dt); /** Propagate quaternion: random walk part.*/ -void bd_random_walk_rot(Particle *p, double dt); +void bd_random_walk_rot(Particle &p, double dt); /** Thermalize angular velocity: random walk part.*/ -void bd_random_walk_vel_rot(Particle *p, double dt); +void bd_random_walk_vel_rot(Particle &p, double dt); #endif // BROWNIAN_DYNAMICS diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 16f142517d7..16ea13a5ef8 100755 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -45,6 +45,10 @@ namespace { set yet. */ constexpr double sentinel(double) { return -1.0; } Vector3d sentinel(Vector3d) { return {-1.0, -1.0, -1.0}; } +#ifdef BROWNIAN_DYNAMICS +constexpr double set_nan(double) { return NAN; } +Vector3d set_nan(Vector3d) { return {NAN, NAN, NAN}; } +#endif // BROWNIAN_DYNAMICS } /* LANGEVIN THERMOSTAT */ @@ -60,6 +64,7 @@ GammaType langevin_pref2_rotation; // Brownian position random walk standard deviation GammaType brown_sigma_pos_inv = sentinel(GammaType{}); GammaType brown_sigma_pos_rotation_inv = sentinel(GammaType{}); +GammaType brown_gammatype_nan = set_nan(GammaType{}); double brown_sigma_vel; double brown_sigma_vel_rotation; #endif // BROWNIAN_DYNAMICS @@ -188,25 +193,33 @@ void thermo_init_npt_isotropic() { // default particle mass is assumed to be unitary in this global parameters void thermo_init_brownian() { // Dispersions correspond to the Gaussian noise only which is only valid for the BD. - // here, the time_step is used only to align with Espresso default dimensionless model (translational velocity only) + // here, the time_step is used only to align with Espresso default dimensionless model (translational velocity only). + // Just a square root of kT, see (10.2.17) and comments in 2 paragraphs afterwards, Pottier2010 https://doi.org/10.1007/s10955-010-0114-6 brown_sigma_vel = sqrt(temperature) * time_step; + // Position dispersion is defined by the second eq. (14.38) of Schlick2010 https://doi.org/10.1007/978-1-4419-6351-2. + // Its time interval factor will be added in the Brownian Dynamics functions. + // Its square root is the standard deviation. A multiplicative inverse of the position standard deviation: if (temperature > 0.0) { brown_sigma_pos_inv = sqrt(langevin_gamma / (2.0 * temperature)); } else { - brown_sigma_pos_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here + brown_sigma_pos_inv = brown_gammatype_nan; // just an indication of the infinity } #ifdef ROTATION - // Note: the BD thermostat assigns the langevin viscous parameters as well + // Note: the BD thermostat assigns the langevin viscous parameters as well. + // They correspond to the friction tensor Z from the eq. (14.31) of Schlick2010: /* If gamma_rotation is not set explicitly, - use the linear one. */ + we use the translational one. */ if (langevin_gamma_rotation < GammaType{}) { langevin_gamma_rotation = langevin_gamma; } brown_sigma_vel_rotation = sqrt(temperature); + // Position dispersion is defined by the second eq. (14.38) of Schlick2010. + // Its time interval factor will be added in the Brownian Dynamics functions. + // Its square root is the standard deviation. A multiplicative inverse of the position standard deviation: if (temperature > 0.0) { brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (2.0 * temperature)); } else { - brown_sigma_pos_rotation_inv = -1.0 * sqrt(langevin_gamma); // just an indication of the infinity; negative sign has no sense here + brown_sigma_pos_rotation_inv = brown_gammatype_nan; // just an indication of the infinity } THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation_inv)); #endif // ROTATION diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index c9aa0f60283..e11240d2f3d 100755 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -55,7 +55,7 @@ namespace Thermostat { static auto noise = []() { return (d_random() - 0.5); }; #ifdef BROWNIAN_DYNAMICS // Only Gaussian noise is allowed for the BD, otherwise the Maxwell distribution will fail. -auto noise_g = []() { return gaussian_random(); }; +static auto noise_g = []() { return gaussian_random(); }; #endif #ifdef PARTICLE_ANISOTROPY From a669b4502ac37d411de610d17c235de939acfa60 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 00:59:18 +0200 Subject: [PATCH 034/150] CPU number in the Brownian Dynamics test --- testsuite/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 4ac79a84b84..73b0528f0a8 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -78,7 +78,7 @@ python_test(FILE ek_eof_one_species_y_nonlinear.py MAX_NUM_PROC 1) python_test(FILE ek_eof_one_species_z_nonlinear.py MAX_NUM_PROC 1) python_test(FILE exclusions.py MAX_NUM_PROC 2) python_test(FILE langevin_thermostat.py MAX_NUM_PROC 1) -python_test(FILE brownian_thermostat.py MAX_NUM_PROC 1) +python_test(FILE brownian_thermostat.py MAX_NUM_PROC 4) python_test(FILE nsquare.py MAX_NUM_PROC 4) python_test(FILE virtual_sites_relative.py MAX_NUM_PROC 2) python_test(FILE domain_decomposition.py MAX_NUM_PROC 4) From 5f37f3ccbf88122087ddd97fbe89247b44d60c4d Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 01:04:22 +0200 Subject: [PATCH 035/150] Infra: special maxset-bd configuration removal --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1925660368e..922a94aa737 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,10 +14,6 @@ matrix: sudo: required services: docker env: myconfig=maxset image=ubuntu-python3 - - os: linux - sudo: required - services: docker - env: myconfig=maxset-bd image=ubuntu-python3 - os: linux sudo: required services: docker From 86959165677adb6aca561bc9437cd4f7b388c5f4 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 01:54:20 +0200 Subject: [PATCH 036/150] Making more BD functions inline --- src/core/brownian_inline.hpp | 81 ++++++++++++++++++++++++++++++++ src/core/integrate.cpp | 89 ------------------------------------ 2 files changed, 81 insertions(+), 89 deletions(-) diff --git a/src/core/brownian_inline.hpp b/src/core/brownian_inline.hpp index 057678d182b..2c60c2ddb20 100644 --- a/src/core/brownian_inline.hpp +++ b/src/core/brownian_inline.hpp @@ -61,6 +61,87 @@ inline void bd_drag(Particle &p, double dt) { } } } + +/** Set the terminal velocity driven by the conservative forces drag.*/ +/*********************************************************/ +/** \name bd_drag_vel */ +/*********************************************************/ +/**(Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +inline void bd_drag_vel(Particle &p, double dt) { + // The friction tensor Z from the eq. (14.31) of Schlick2010: + Thermostat::GammaType local_gamma; + + if(p.p.gamma >= Thermostat::GammaType{}) { + local_gamma = p.p.gamma; + } else { + local_gamma = langevin_gamma; + } + + double scale_f = 0.5 * time_step * time_step / p.p.mass; + for (int j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (p.p.ext_flag & COORD_FIXED(j)) { + p.m.v[j] = 0.0; + } else +#endif + { + // First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). + // here, the additional time_step is used only to align with ESPResSo default dimensionless model + // scale_f is required to be aligned with rescaled forces + // only conservative part of the force is used here + // NOTE: velocity is assigned here and propagated by thermal part further on top of it +#ifndef PARTICLE_ANISOTROPY + p.m.v[j] = p.f.f[j] * time_step / (local_gamma * scale_f); +#else + p.m.v[j] = p.f.f[j] * time_step / (local_gamma[j] * scale_f); +#endif // PARTICLE_ANISOTROPY + } + } +} + +/** Determine the velocities: random walk part.*/ +/*********************************************************/ +/** \name bd_random_walk_vel */ +/*********************************************************/ +/**(Eq. (10.2.16) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010)) + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +inline void bd_random_walk_vel(Particle &p, double dt) { + // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs afterwards, Pottier2010 + extern double brown_sigma_vel; + // first, set defaults + double brown_sigma_vel_temp = brown_sigma_vel; + + // Override defaults if per-particle values for T and gamma are given +#ifdef LANGEVIN_PER_PARTICLE + auto const constexpr langevin_temp_coeff = 1.0; + // Is a particle-specific temperature specified? + // here, the time_step is used only to align with ESPResSo default dimensionless model + if (p.p.T >= 0.) { + brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p.p.T) * time_step; + } else { + brown_sigma_vel_temp = brown_sigma_vel; + } +#endif /* LANGEVIN_PER_PARTICLE */ + + for (int j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p.p.ext_flag & COORD_FIXED(j))) +#endif + { + // Random (heat) velocity is added here. It is already initialized in the terminal drag part. + // See eq. (10.2.16) taking into account eq. (10.2.18) and (10.2.29), Pottier2010. + // Note, that the Pottier2010 units system (see Eq. (10.1.1) there) has been adapted towards the ESPResSo and the referenced above Schlick2010 one, + // which is defined by the eq. (14.31) of Schlick2010. A difference is the mass factor to the friction tensor. + // The noise is Gaussian according to the convention at p. 237 (last paragraph), Pottier2010. + p.m.v[j] += brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p.p.mass); + } + } +} #endif // BROWNIAN_DYNAMICS #endif // BROWNIAN_INLINE_HPP diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 9bfa92fcca0..1ffd583c34f 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -139,15 +139,8 @@ void force_and_velocity_display(); void finalize_p_inst_npt(); #ifdef BROWNIAN_DYNAMICS - -/** Set the terminal velocity driven by the conservative forces drag.*/ -void bd_drag_vel(Particle &p, double dt); - /** Propagate position: random walk part.*/ void bd_random_walk(Particle &p, double dt); -/** Thermalize velocity: random walk part.*/ -void bd_random_walk_vel(Particle &p, double dt); - #endif // BROWNIAN_DYNAMICS /*@}*/ @@ -1320,47 +1313,6 @@ int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, } #ifdef BROWNIAN_DYNAMICS - -/** Set the terminal velocity driven by the conservative forces drag.*/ -/*********************************************************/ -/** \name bd_drag_vel */ -/*********************************************************/ -/**(Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) - */ -void bd_drag_vel(Particle &p, double dt) { - // The friction tensor Z from the eq. (14.31) of Schlick2010: - Thermostat::GammaType local_gamma; - - if(p.p.gamma >= Thermostat::GammaType{}) { - local_gamma = p.p.gamma; - } else { - local_gamma = langevin_gamma; - } - - double scale_f = 0.5 * time_step * time_step / p.p.mass; - for (int j = 0; j < 3; j++) { -#ifdef EXTERNAL_FORCES - if (p.p.ext_flag & COORD_FIXED(j)) { - p.m.v[j] = 0.0; - } else -#endif - { - // First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). - // here, the additional time_step is used only to align with ESPResSo default dimensionless model - // scale_f is required to be aligned with rescaled forces - // only conservative part of the force is used here - // NOTE: velocity is assigned here and propagated by thermal part further on top of it -#ifndef PARTICLE_ANISOTROPY - p.m.v[j] = p.f.f[j] * time_step / (local_gamma * scale_f); -#else - p.m.v[j] = p.f.f[j] * time_step / (local_gamma[j] * scale_f); -#endif // PARTICLE_ANISOTROPY - } - } -} - /** Propagate the positions: random walk part.*/ /*********************************************************/ /** \name bd_drag_vel */ @@ -1460,45 +1412,4 @@ void bd_random_walk(Particle &p, double dt) { } } -/** Determine the velocities: random walk part.*/ -/*********************************************************/ -/** \name bd_random_walk_vel */ -/*********************************************************/ -/**(Eq. (10.2.16) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) - */ -void bd_random_walk_vel(Particle &p, double dt) { - // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs afterwards, Pottier2010 - extern double brown_sigma_vel; - // first, set defaults - double brown_sigma_vel_temp = brown_sigma_vel; - - // Override defaults if per-particle values for T and gamma are given -#ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 1.0; - // Is a particle-specific temperature specified? - // here, the time_step is used only to align with ESPResSo default dimensionless model - if (p.p.T >= 0.) { - brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p.p.T) * time_step; - } else { - brown_sigma_vel_temp = brown_sigma_vel; - } -#endif /* LANGEVIN_PER_PARTICLE */ - - for (int j = 0; j < 3; j++) { -#ifdef EXTERNAL_FORCES - if (!(p.p.ext_flag & COORD_FIXED(j))) -#endif - { - // Random (heat) velocity is added here. It is already initialized in the terminal drag part. - // See eq. (10.2.16) taking into account eq. (10.2.18) and (10.2.29), Pottier2010. - // Note, that the Pottier2010 units system (see Eq. (10.1.1) there) has been adapted towards the ESPResSo and the referenced above Schlick2010 one, - // which is defined by the eq. (14.31) of Schlick2010. A difference is the mass factor to the friction tensor. - // The noise is Gaussian according to the convention at p. 237 (last paragraph), Pottier2010. - p.m.v[j] += brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p.p.mass); - } - } -} - #endif // BROWNIAN_DYNAMICS From 7919b0adf0fca7bc069ffd676cda97c0fe09a0e4 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 19:56:30 +0200 Subject: [PATCH 037/150] Code cleanup --- src/core/integrate.cpp | 4 ---- src/core/rotation.cpp | 2 -- src/core/rotation.hpp | 4 ---- src/core/thermostat.cpp | 2 -- src/core/thermostat.hpp | 2 -- 5 files changed, 14 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 3a2d9f7f936..5eea198d2f1 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -58,9 +58,7 @@ #include "virtual_sites.hpp" #include "npt.hpp" #include "collision.hpp" -#ifdef BROWNIAN_DYNAMICS #include "brownian_inline.hpp" -#endif // BROWNIAN_DYNAMICS #include #include #include @@ -128,10 +126,8 @@ void force_and_velocity_display(); void finalize_p_inst_npt(); -#ifdef BROWNIAN_DYNAMICS /** Propagate position: random walk part.*/ void bd_random_walk(Particle &p, double dt); -#endif // BROWNIAN_DYNAMICS /*@}*/ diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index d7421abf95a..bec538e471a 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -45,9 +45,7 @@ #include "particle_data.hpp" #include "thermostat.hpp" #include "utils.hpp" -#ifdef BROWNIAN_DYNAMICS #include "brownian_inline.hpp" -#endif // BROWNIAN_DYNAMICS #include #include #include diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index d37d876c592..db7bd160349 100755 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -131,8 +131,6 @@ inline void normalize_quaternion(double *q) { q[3] /= tmp; } -#ifdef BROWNIAN_DYNAMICS - /** Propagate quaternions: viscous drag driven by conservative torques.*/ void bd_drag_rot(Particle &p, double dt); /** Set the terminal angular velocity driven by the conservative torques drag.*/ @@ -143,6 +141,4 @@ void bd_random_walk_rot(Particle &p, double dt); /** Thermalize angular velocity: random walk part.*/ void bd_random_walk_vel_rot(Particle &p, double dt); -#endif // BROWNIAN_DYNAMICS - #endif diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 1f77abcd1a3..ee084ee888b 100755 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -46,10 +46,8 @@ namespace { set yet. */ constexpr double sentinel(double) { return -1.0; } Vector3d sentinel(Vector3d) { return {-1.0, -1.0, -1.0}; } -#ifdef BROWNIAN_DYNAMICS constexpr double set_nan(double) { return NAN; } Vector3d set_nan(Vector3d) { return {NAN, NAN, NAN}; } -#endif // BROWNIAN_DYNAMICS } /* LANGEVIN THERMOSTAT */ diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index e11240d2f3d..a7583e973b5 100755 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -53,10 +53,8 @@ namespace Thermostat { static auto noise = []() { return (d_random() - 0.5); }; -#ifdef BROWNIAN_DYNAMICS // Only Gaussian noise is allowed for the BD, otherwise the Maxwell distribution will fail. static auto noise_g = []() { return gaussian_random(); }; -#endif #ifdef PARTICLE_ANISOTROPY using GammaType = Vector3d; From 0629002b30fdcc8dc1f2c1ddd2e17aaea48d7fc7 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 19:56:46 +0200 Subject: [PATCH 038/150] Refactoring --- src/python/espressomd/thermostat.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index aecdefe2c5f..8f05b44ef69 100755 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -309,13 +309,13 @@ cdef class Thermostat(object): ELSE: langevin_gamma_rotation = langevin_gamma + global thermo_switch + thermo_switch = (thermo_switch | THERMO_LANGEVIN) + mpi_bcast_parameter(FIELD_THERMO_SWITCH) mpi_bcast_parameter(FIELD_TEMPERATURE) mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA) IF ROTATION: mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA_ROTATION) - global thermo_switch - thermo_switch = (thermo_switch | THERMO_LANGEVIN) - mpi_bcast_parameter(FIELD_THERMO_SWITCH) return True IF LB_GPU or LB: From 95f6d9957225a7dce4f70668d8b6eaf3a61dc5ce Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 19:57:19 +0200 Subject: [PATCH 039/150] Test cleanup, speed up --- testsuite/mass-and-rinertia_per_particle.py | 73 ++------------------- 1 file changed, 4 insertions(+), 69 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 07957abed83..190c2737134 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -293,7 +293,7 @@ def run_test_case(self, test_case): t0_max = -1.0 for k in range(2): t0_max = max(t0_max, max(mass / gamma_tr[k, :]), max(J[:] / gamma_rot_validate[k, :])) - drag_steps_0 = int(math.floor(20 * t0_max / self.es.time_step)) + drag_steps_0 = int(math.floor(15 * t0_max / self.es.time_step)) print("drag_steps_0 = {0}".format(drag_steps_0)) tol = 7E-3 @@ -326,8 +326,8 @@ def run_test_case(self, test_case): if "DIPOLES" in espressomd.features(): self.es.part[0].dip = dip0 self.es.part[1].dip = dip1 - for i in range(100): - self.es.integrator.run(10) + for i in range(7): + self.es.integrator.run(3) for k in range(3): self.assertLess( abs(self.es.part[0].v[k] - f0[k] / gamma_tr[0, k]), tol) @@ -416,7 +416,7 @@ def run_test_case(self, test_case): # no need to rebuild Verlet lists, avoid it self.es.cell_system.skin = 5.0 if test_case < 4 + self.rot_flag: - self.es.time_step = 0.03 + self.es.time_step = 0.04 else: self.es.time_step = 10 n = 200 @@ -460,23 +460,6 @@ def run_test_case(self, test_case): sigma2_tr = np.zeros((2)) dr_norm = np.zeros((2)) - # Total curve within a spherical trigonometry. - # [particle_index, which principal axis, around which lab axis] - alpha = np.zeros((2, n, 3, 3)) - alpha_norm = np.zeros((2)) - sigma2_alpha = np.zeros((2)) - alpha2 = np.zeros((2)) - # Previous directions of the principal axes: - # [particle_index, which principal axis, its lab coordinate] - prev_pa_lab = np.zeros((2, n, 3, 3)) - pa_body = np.zeros((3)) - pa_lab = np.zeros((3, 3)) - ref_lab = np.zeros((3)) - vec = np.zeros((3)) - vec1 = np.zeros((3)) - vec2 = np.zeros((3)) - #vec_diag = np.ones((3)) - pos0 = np.zeros((2 * n, 3)) for p in range(n): for k in range(2): @@ -492,7 +475,6 @@ def run_test_case(self, test_case): print("Measuring...") int_steps = 5 - fraction_i = 0.65 for i in range(loops): self.es.integrator.run(int_steps) # Get kinetic energy in each degree of freedom for all particles @@ -519,42 +501,6 @@ def run_test_case(self, test_case): j]))) dr_norm[k] = dr_norm[k] + \ (sum(dr2[k, :]) - sigma2_tr[k]) / sigma2_tr[k] - - # Rotational diffusion variance. - if i >= fraction_i * loops: - # let's limit test cases to speed this test.. - if test_case in [(7 + self.rot_flag)]: - dt -= self.es.time_step * (1 + therm_steps + fraction_i * loops) - # First, let's identify principal axes in the lab reference frame. - alpha2[k] = 0.0 - sigma2_alpha[k] = 0.0 - for j in range(3): - for j1 in range(3): - pa_body[j1] = 0.0 - pa_body[j] = 1.0 - vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) - pa_lab[j, :] = vec[:] - - if i >= fraction_i * loops + 1: - # Around which axis we rotates? - for j1 in range(3): - # Calc a rotational diffusion within the spherical trigonometry - vec2 = vec - vec1[:] = prev_pa_lab[k, p, j, :] - for j2 in range(3): - ref_lab[j2] = 0.0 - ref_lab[j1] = 1.0 - dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) - rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) - theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) - alpha[k, p, j, j1] += dalpha * rot_projection / np.sin(theta) - alpha2[k] += alpha[k, p, j, j1]**2 - sigma2_alpha[k] += D_rot[k, j] * (2.0 * dt + dt0_rot[k, j] * (- 3.0 + - 4.0 * math.exp(- dt / dt0_rot[k, j]) - - math.exp(- 2.0 * dt / dt0_rot[k, j]))) - prev_pa_lab[k, p, j, :] = pa_lab[j, :] - if i >= fraction_i * loops + 3: - alpha_norm[k] += (alpha2[k] - sigma2_alpha[k]) / sigma2_alpha[k] tolerance = 0.15 Ev = 0.5 * mass * v2 / (n * loops) @@ -567,7 +513,6 @@ def run_test_case(self, test_case): do[k] = sum(Eo[k, :]) / (3.0 * halfkT[k]) - 1.0 do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 dr_norm = dr_norm / (n * loops) - alpha_norm = alpha_norm / (n * (1 - fraction_i) * loops - 2) for k in range(2): print("\n") @@ -596,9 +541,6 @@ def run_test_case(self, test_case): print( "Deviation in translational diffusion: {0} ".format( dr_norm[k])) - print( - "Deviation in rotational diffusion: {0} ".format( - alpha_norm)) self.assertLessEqual( abs( @@ -625,13 +567,6 @@ def run_test_case(self, test_case): tolerance, msg='Relative deviation in translational diffusion is too large: {0}'.format( dr_norm[k])) - if test_case in (1, 3): - self.assertLessEqual( - abs( - alpha_norm[k]), - tolerance, - msg='Relative deviation in rotational diffusion is too large: {0}'.format( - alpha_norm[k])) def test(self): if "ROTATION" in espressomd.features(): From fd34faaa26c93f79e095b8c3d3733699706050c1 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 21:00:41 +0200 Subject: [PATCH 040/150] Test speed up --- testsuite/mass-and-rinertia_per_particle.py | 137 ++++++++++---------- 1 file changed, 66 insertions(+), 71 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 190c2737134..753d3b8ceb7 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -287,78 +287,73 @@ def run_test_case(self, test_case): self.set_thermo_all(test_case, 0.0, gamma_global, gamma_global_rot) - self.es.time = 0.0 - self.es.time_step = 7E-5 - # The terminal velocity is starting since t >> t0 = mass / gamma - t0_max = -1.0 - for k in range(2): - t0_max = max(t0_max, max(mass / gamma_tr[k, :]), max(J[:] / gamma_rot_validate[k, :])) - drag_steps_0 = int(math.floor(15 * t0_max / self.es.time_step)) - print("drag_steps_0 = {0}".format(drag_steps_0)) - - tol = 7E-3 - if "EXTERNAL_FORCES" in espressomd.features(): - for k in range(2): - self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) - self.es.part[k].v = np.array([0.0, 0.0, 0.0]) - self.es.part[k].omega_body = np.array([0.0, 0.0, 0.0]) - f0 = np.array([-1.2, 58.3578, 0.002]) - f1 = np.array([-15.112, -2.0, 368.0]) - self.es.part[0].ext_force = f0 - self.es.part[1].ext_force = f1 - if "ROTATION" in espressomd.features(): - tor0 = np.array([12, 0.022, 87]) - tor1 = np.array([-0.03, -174, 368]) - self.es.part[0].ext_torque = tor0 - self.es.part[1].ext_torque = tor1 - # Let's set the dipole perpendicular to the torque - if "DIPOLES" in espressomd.features(): - dip0 = np.array([0.0, tor0[2], -tor0[1]]) - dip1 = np.array([-tor1[2], 0.0, tor1[0]]) - self.es.part[0].dip = dip0 - self.es.part[1].dip = dip1 - tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) - tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) - self.es.integrator.run(drag_steps_0) + if test_case >= 4 + self.rot_flag: + # Brownian thermostat only. self.es.time = 0.0 - for k in range(2): - self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) - if "DIPOLES" in espressomd.features(): - self.es.part[0].dip = dip0 - self.es.part[1].dip = dip1 - for i in range(7): - self.es.integrator.run(3) - for k in range(3): - self.assertLess( - abs(self.es.part[0].v[k] - f0[k] / gamma_tr[0, k]), tol) - self.assertLess( - abs(self.es.part[1].v[k] - f1[k] / gamma_tr[1, k]), tol) - self.assertLess( - abs(self.es.part[0].pos[k] - self.es.time * f0[k] / gamma_tr[0, k]), tol) - self.assertLess( - abs(self.es.part[1].pos[k] - self.es.time * f1[k] / gamma_tr[1, k]), tol) - if "ROTATION" in espressomd.features(): - self.assertLess(abs( - self.es.part[0].omega_lab[k] - tor0[k] / gamma_rot_validate[0, k]), tol) - self.assertLess(abs( - self.es.part[1].omega_lab[k] - tor1[k] / gamma_rot_validate[1, k]), tol) - if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): - cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) - cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0]) - sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) - sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0])) - - cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) - cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0]) - sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) - sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0])) - - #print("cos_alpha0 = {0}, cos_alpha0_test={1}".format(cos_alpha0, cos_alpha0_test)) - #print("dip0 = {0}, self.es.part[0].dip={1}".format(dip0, self.es.part[0].dip)) - self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) - self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) - self.assertEqual(sgn0, sgn0_test) - self.assertEqual(sgn1, sgn1_test) + self.es.time_step = 1E-4 + tol = 7E-3 + if "EXTERNAL_FORCES" in espressomd.features(): + for k in range(2): + self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) + self.es.part[k].v = np.array([0.0, 0.0, 0.0]) + self.es.part[k].omega_body = np.array([0.0, 0.0, 0.0]) + f0 = np.array([-1.2, 58.3578, 0.002]) + f1 = np.array([-15.112, -2.0, 368.0]) + self.es.part[0].ext_force = f0 + self.es.part[1].ext_force = f1 + if "ROTATION" in espressomd.features(): + tor0 = np.array([12, 0.022, 87]) + tor1 = np.array([-0.03, -174, 368]) + self.es.part[0].ext_torque = tor0 + self.es.part[1].ext_torque = tor1 + # Let's set the dipole perpendicular to the torque + if "DIPOLES" in espressomd.features(): + dip0 = np.array([0.0, tor0[2], -tor0[1]]) + dip1 = np.array([-tor1[2], 0.0, tor1[0]]) + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) + tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) + self.es.integrator.run(7) + self.es.time = 0.0 + for k in range(2): + self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) + if "DIPOLES" in espressomd.features(): + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + for i in range(3): + self.es.integrator.run(2) + for k in range(3): + self.assertLess( + abs(self.es.part[0].v[k] - f0[k] / gamma_tr[0, k]), tol) + self.assertLess( + abs(self.es.part[1].v[k] - f1[k] / gamma_tr[1, k]), tol) + self.assertLess( + abs(self.es.part[0].pos[k] - self.es.time * f0[k] / gamma_tr[0, k]), tol) + self.assertLess( + abs(self.es.part[1].pos[k] - self.es.time * f1[k] / gamma_tr[1, k]), tol) + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + self.es.part[0].omega_lab[k] - tor0[k] / gamma_rot_validate[0, k]), tol) + self.assertLess(abs( + self.es.part[1].omega_lab[k] - tor1[k] / gamma_rot_validate[1, k]), tol) + if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): + cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) + cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0]) + sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) + sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0])) + + cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) + cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0]) + sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) + sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0])) + + #print("cos_alpha0 = {0}, cos_alpha0_test={1}".format(cos_alpha0, cos_alpha0_test)) + #print("dip0 = {0}, self.es.part[0].dip={1}".format(dip0, self.es.part[0].dip)) + self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) + self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) + self.assertEqual(sgn0, sgn0_test) + self.assertEqual(sgn1, sgn1_test) for i in range(len(self.es.part)): self.es.part[i].remove() From 5414c551b55d9c0e239a9e6b5075467585468b5e Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 22:01:00 +0200 Subject: [PATCH 041/150] Cleanup of test fragments which are out of the BD scope --- testsuite/brownian_thermostat.py | 302 +------------------------------ 1 file changed, 3 insertions(+), 299 deletions(-) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index 7d92a694316..dfe5c2f4caf 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -25,6 +25,9 @@ from espressomd.correlators import Correlator from espressomd.observables import ParticleVelocities, ParticleBodyAngularVelocities +#TODO: this test should be as close to langevin_thermostat.py as possible +# these tests probably even could be merged +# after an implementation of the fine inertial BD @ut.skipIf(espressomd.has_features("THERMOSTAT_IGNORE_NON_VIRTUAL") or not espressomd.has_features("BROWNIAN_DYNAMICS"), "Skipped because of the features set") @@ -108,304 +111,5 @@ def test_global_brownian(self): self.check_velocity_distribution( omega_stored, v_minmax, bins, error_tol, kT) - @ut.skipIf(not espressomd.has_features("LANGEVIN_PER_PARTICLE"), - "Test requires LANGEVIN_PER_PARTICLE") - def test_brownian_per_particle(self): - """Test for Brownian particle. Covers all combinations of - particle specific gamma and temp set or not set. - """ - N = 200 - s = self.s - s.part.clear() - s.time_step = 0.02 - s.part.add(pos=np.random.random((N, 3))) - if espressomd.has_features("ROTATION"): - s.part[:].rotation = 1,1,1 - - kT = 2.3 - gamma = 1.5 - gamma2 = 2.3 - kT2 = 1.5 - s.thermostat.set_brownian(kT=kT, gamma=gamma) - # Set different kT on 2nd half of particles - s.part[int(N / 2):].temp = kT2 - # Set different gamma on half of the partiles (overlap over both kTs) - if espressomd.has_features("PARTICLE_ANISOTROPY"): - s.part[int(N / 4):int(3 * N / 4)].gamma = gamma2, gamma2, gamma2 - else: - s.part[int(N / 4):int(3 * N / 4)].gamma = gamma2 - - s.integrator.run(50) - loops = 4000 - - v_kT = np.zeros((int(N / 2) * loops, 3)) - v_kT2 = np.zeros((int(N / 2 * loops), 3)) - - if espressomd.has_features("ROTATION"): - omega_kT = np.zeros((int(N / 2) * loops, 3)) - omega_kT2 = np.zeros((int(N / 2 * loops), 3)) - - for i in range(loops): - s.integrator.run(2) - v_kT[int(i * N / 2):int((i + 1) * N / 2), - :] = s.part[:int(N / 2)].v - v_kT2[int(i * N / 2):int((i + 1) * N / 2), - :] = s.part[int(N / 2):].v - - if espressomd.has_features("ROTATION"): - omega_kT[int(i * N / 2):int((i + 1) * N / 2),:] = s.part[:int(N / 2)].omega_body - omega_kT2[int(i * N / 2):int((i + 1) * N / 2),:] = s.part[int(N / 2):].omega_body - v_minmax = 5 - bins = 5 - error_tol = 0.014 - self.check_velocity_distribution(v_kT, v_minmax, bins, error_tol, kT) - self.check_velocity_distribution(v_kT2, v_minmax, bins, error_tol, kT2) - - if espressomd.has_features("ROTATION"): - self.check_velocity_distribution(omega_kT, v_minmax, bins, error_tol, kT) - self.check_velocity_distribution(omega_kT2, v_minmax, bins, error_tol, kT2) - - def setup_diff_mass_rinertia(self,p): - if espressomd.has_features("MASS"): - p.mass=0.5 - if espressomd.has_features("ROTATION"): - p.rotation = 1,1,1 - # Make sure rinertia does not change diff coeff - if espressomd.has_features("ROTATIONAL_INERTIA"): - p.rinertia =0.4,0.4,0.4 - - def test_diffusion(self): - """This tests rotational and translational diffusion coeff via green-kubo""" - s=self.s - s.part.clear() - - kT=1.37 - dt=0.05 - s.time_step=dt - - # Translational gamma. We cannot test per-component, if rotation is on, - # because body and space frames become different. - gamma=3.1 - - # Rotational gamma - gamma_rot_i=0.7 - gamma_rot_a=0.7,1,1.2 - - # If we have langevin per particle: - # per particle kT - per_part_kT=1.6 - # Translation - per_part_gamma=1.63 - # Rotational - per_part_gamma_rot_i=0.6 - per_part_gamma_rot_a=0.4,0.8,1.1 - - - - - - - # Particle with global thermostat params - p_global=s.part.add(pos=(0,0,0)) - # Make sure, mass doesn't change diff coeff - self.setup_diff_mass_rinertia(p_global) - - # particle specific gamma, kT, and both - if espressomd.has_features("LANGEVIN_PER_PARTICLE"): - p_gamma=s.part.add(pos=(0,0,0)) - self.setup_diff_mass_rinertia(p_gamma) - if espressomd.has_features("PARTICLE_ANISOTROPY"): - p_gamma.gamma =per_part_gamma,per_part_gamma,per_part_gamma - if espressomd.has_features("ROTATION"): - p_gamma.gamma_rot=per_part_gamma_rot_a - else: - p_gamma.gamma =per_part_gamma - if espressomd.has_features("ROTATION"): - p_gamma.gamma_rot=per_part_gamma_rot_i - - p_kT=s.part.add(pos=(0,0,0)) - self.setup_diff_mass_rinertia(p_kT) - p_kT.temp=per_part_kT - - p_both=s.part.add(pos=(0,0,0)) - self.setup_diff_mass_rinertia(p_both) - p_both.temp=per_part_kT - if espressomd.has_features("PARTICLE_ANISOTROPY"): - p_both.gamma =per_part_gamma,per_part_gamma,per_part_gamma - if espressomd.has_features("ROTATION"): - p_both.gamma_rot=per_part_gamma_rot_a - else: - p_both.gamma =per_part_gamma - if espressomd.has_features("ROTATION"): - p_both.gamma_rot=per_part_gamma_rot_i - - - - - # Thermostat setup - if espressomd.has_features("ROTATION"): - if espressomd.has_features("PARTICLE_ANISOTROPY"): - # particle anisotropy and rotation - s.thermostat.set_brownian(kT=kT,gamma=gamma,gamma_rotation=gamma_rot_a) - else: - # Rotation without particle anisotropy - s.thermostat.set_brownian(kT=kT,gamma=gamma,gamma_rotation=gamma_rot_i) - else: - # No rotation - s.thermostat.set_brownian(kT=kT,gamma=gamma) - - - - s.cell_system.skin =0.4 - s.integrator.run(5000) - - # Correlators - vel_obs={} - omega_obs={} - corr_vel={} - corr_omega={} - all_particles=[p_global] - if espressomd.has_features("LANGEVIN_PER_PARTICLE"): - all_particles.append(p_gamma) - all_particles.append(p_kT) - all_particles.append(p_both) - - for p in all_particles: - # linear vel - vel_obs[p]=ParticleVelocities(ids=(p.id,)) - corr_vel[p] = Correlator(obs1=vel_obs[p], tau_lin=32, tau_max=4., dt=2*dt, - corr_operation="componentwise_product", compress1="discard1") - s.auto_update_correlators.add(corr_vel[p]) - # angular vel - if espressomd.has_features("ROTATION"): - omega_obs[p]=ParticleBodyAngularVelocities(ids=(p.id,)) - corr_omega[p] = Correlator(obs1=omega_obs[p], tau_lin=32, tau_max=4, dt=2*dt, - corr_operation="componentwise_product", compress1="discard1") - s.auto_update_correlators.add(corr_omega[p]) - - s.integrator.run(800000) - for c in corr_vel.values(): - s.auto_update_correlators.remove(c) - for c in corr_omega.values(): - s.auto_update_correlators.remove(c) - - # Verify diffusion - # Translation - # Cast gammas to vector, to make checks independent of PARTICLE_ANISOTROPY - - # TODO: to return this after an implementation of the fine inertial BD - #gamma=np.ones(3) *gamma - #per_part_gamma=np.ones(3) *per_part_gamma - #self.verify_diffusion(p_global,corr_vel,kT,gamma) - #if espressomd.has_features("LANGEVIN_PER_PARTICLE"): - # self.verify_diffusion(p_gamma,corr_vel,kT,per_part_gamma) - # self.verify_diffusion(p_kT,corr_vel,per_part_kT,gamma) - # self.verify_diffusion(p_both,corr_vel,per_part_kT,per_part_gamma) - - # Rotation - if espressomd.has_features("ROTATION"): - # Decide on effective gamma rotation, since for rotation it is direction dependent - eff_gamma_rot=None - per_part_eff_gamma_rot=None - if espressomd.has_features("PARTICLE_ANISOTROPY"): - eff_gamma_rot=gamma_rot_a - eff_per_part_gamma_rot =per_part_gamma_rot_a - else: - eff_gamma_rot=gamma_rot_i*np.ones(3) - eff_per_part_gamma_rot =per_part_gamma_rot_i *np.ones(3) - -# TODO: to return this after an implementation of the fine inertial BD -# self.verify_diffusion(p_global,corr_omega,kT,eff_gamma_rot) -# if espressomd.has_features("LANGEVIN_PER_PARTICLE"): -# self.verify_diffusion(p_gamma,corr_omega,kT,eff_per_part_gamma_rot) -# self.verify_diffusion(p_kT,corr_omega,per_part_kT,eff_gamma_rot) -# self.verify_diffusion(p_both,corr_omega,per_part_kT,eff_per_part_gamma_rot) - - - -# TODO: to return this after an implementation of the fine inertial BD -# def verify_diffusion(self,p,corr,kT,gamma): -# """Verifify diffusion coeff. -# -# p: particle, corr: dict containing correltor with particle as key, -# kT=kT, gamma=gamma as 3 component vector. -# """ -# c=corr[p] -# # Integral of vacf via Green-Kubo -# #D= int_0^infty dt (o 1/3, since we work componentwise) -# acf=c.result() -# #Integrate w. trapez rule -# for coord in 2,3,4: -# I=np.trapz(acf[:,coord],acf[:,0]) -# ratio = I/(kT/gamma[coord-2]) -# self.assertAlmostEqual(ratio,1.,delta=0.07) - - -# TODO: to return this after an implementation of the fine inertial BD -# def test_00__friction_trans(self): -# """Tests the translational friction-only part of the thermostat.""" -# -# -# s=self.s -# # Translation -# gamma_t_i=2 -# gamma_t_a=0.5,2,1.5 -# v0=5. -# -# s.time_step=0.0005 -# s.part.clear() -# s.part.add(pos=(0,0,0),v=(v0,v0,v0)) -# if espressomd.has_features("MASS"): -# s.part[0].mass=3 -# if espressomd.has_features("PARTICLE_ANISOTROPY"): -# s.thermostat.set_brownian(kT=0,gamma=gamma_t_a) -# else: -# s.thermostat.set_brownian(kT=0,gamma=gamma_t_i) -# -# s.time=0 -# for i in range(100): -# s.integrator.run(10) -# for j in range(3): -# if espressomd.has_features("PARTICLE_ANISOTROPY"): -# self.assertAlmostEqual(s.part[0].v[j],v0*np.exp(-gamma_t_a[j]/s.part[0].mass*s.time),places=2) -# else: -# self.assertAlmostEqual(s.part[0].v[j],v0*np.exp(-gamma_t_i/s.part[0].mass*s.time),places=2) - -# TODO: to return this after an implementation of the fine inertial BD -# @ut.skipIf(not espressomd.has_features("ROTATION"), "Skipped for lack of ROTATION" ) -# def test_00__friction_rot(self): -# """Tests the rotational friction-only part of the thermostat.""" -# -# -# s=self.s -# # Translation -# gamma_t_i=2 -# gamma_t_a=0.5,2,1.5 -# gamma_r_i=3 -# gamma_r_a=1.5,0.7,1.2 -# o0=5. -# -# s.time_step=0.0005 -# s.part.clear() -# s.part.add(pos=(0,0,0),omega_body=(o0,o0,o0),rotation=(1,1,1)) -# if espressomd.has_features("ROTATIONAL_INERTIA"): -# s.part[0].rinertia=2,2,2 -# if espressomd.has_features("PARTICLE_ANISOTROPY"): -# s.thermostat.set_brownian(kT=0,gamma=gamma_t_a,gamma_rotation=gamma_r_a) -# else: -# s.thermostat.set_brownian(kT=0,gamma=gamma_t_i,gamma_rotation=gamma_r_i) -# -# s.time=0 -# for i in range(100): -# s.integrator.run(10) -# for j in range(3): -# if espressomd.has_features("PARTICLE_ANISOTROPY"): -# self.assertAlmostEqual(s.part[0].omega_body[j],o0*np.exp(-gamma_r_a[j]/s.part[0].rinertia[j]*s.time),places=2) -# else: -# self.assertAlmostEqual(s.part[0].omega_body[j],o0*np.exp(-gamma_r_i/s.part[0].rinertia[j]*s.time),places=2) - - - - if __name__ == "__main__": ut.main() From c075ec810d25555ff1dc2fc0bbb97c3d393ff013 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 13 Mar 2018 23:45:50 +0200 Subject: [PATCH 042/150] Rotational diffusion test fix --- testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py b/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py index fd721ef8371..343afdd98ca 100644 --- a/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py +++ b/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py @@ -65,10 +65,7 @@ def run_test_case(self, test_case): seed(2) # Decelleration self.es.time_step = 0.007 - box = 1.0E5 - self.es.box_l = [box, box, box] - if espressomd.has_features(("PARTIAL_PERIODIC")): - self.es.periodicity = 0, 0, 0 + self.es.part.clear() # gamma_tran/gamma_rot matrix: [2 types of particless] x [3 dimensions # X Y Z] gamma_tran = np.zeros((2, 3)) From 5952c1ce554488b3841f90b0cb92d940d87ff3df Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Wed, 14 Mar 2018 00:29:50 +0200 Subject: [PATCH 043/150] Trigger From 78e59751f2f282bf621d335bfd26352911793ef4 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 18 Mar 2018 19:35:06 +0200 Subject: [PATCH 044/150] The changes cleanup --- src/core/integrate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/integrate.hpp b/src/core/integrate.hpp index 18777d10802..08e4bbf77d9 100755 --- a/src/core/integrate.hpp +++ b/src/core/integrate.hpp @@ -114,5 +114,5 @@ int python_integrate(int n_steps, bool recalc_forces, bool reuse_forces); void integrate_set_nvt(); int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, int ydir, int zdir, bool cubic_box); -#endif +#endif From 2744188b33fbf9f54cc23bd751135b5903b69584 Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Mon, 19 Mar 2018 16:31:51 +0200 Subject: [PATCH 045/150] BD: additional documentation --- doc/sphinx/system_setup.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index c9ab0e78808..c4f3ecdcd6e 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -297,7 +297,7 @@ same value as that for the translation. A separate rotational diffusion coefficient can be set by inputting ``gamma_rotate``. This also allows one to properly match the translational and -rotational diffusion coefficients of a sphere. ``ROTATIONAL_INERTIA`` Feature +rotational diffusion coefficients of a sphere. ``PARTICLE_ANISOTROPY`` Feature enables an anisotropic rotational diffusion coefficient tensor through corresponding friction coefficients. @@ -482,6 +482,8 @@ Note, that the velocity random walk is propagated from zero at each step. A rotational motion is implemented similarly. The Velocity Verlet quaternion based rotational method implementation is still used, however, had been modified for the larger :math:`\Delta t` case to be consistent and still the Velocity Verlet-compliant. +Note: this Brownian dynamics implementation is compatible with particles which have +the isotropic moment of inertia tensor only. .. _CUDA: From fb26fc6029cb8fe8b50d0818baa43de3035a078e Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Mon, 23 Apr 2018 23:48:40 +0300 Subject: [PATCH 046/150] Merge branch 'python' of https://github.com/espressomd/espresso into espressomd-python --- .gitlab-ci.yml | 32 + Readme.md | 4 + doc/sphinx/advanced_methods.rst | 24 +- doc/sphinx/analysis.rst | 6 +- doc/sphinx/figures/shape-simplepore.png | Bin 86225 -> 50448 bytes doc/sphinx/installation.rst | 24 +- doc/sphinx/introduction.rst | 26 +- doc/sphinx/magnetostatics.rst | 179 +-- doc/sphinx/running.rst | 42 +- doc/sphinx/system_setup.rst | 6 + doc/sphinx/visualization.rst | 125 +- doc/sphinx/zrefs.bib | 15 +- .../01-lennard_jones/scripts/lj_tutorial.py | 6 +- .../09-swimmer_reactions.pdf} | Bin .../09-swimmer_reactions.tex} | 6 +- .../CMakeLists.txt | 0 .../EXERCISES/reaction.py | 0 .../FIGURES/avacf.pdf | Bin .../FIGURES/janus-particle.pdf | Bin .../FIGURES/janus-particle.tex | 0 .../FIGURES/msd.pdf | Bin .../FIGURES/number-conserving.pdf | Bin .../FIGURES/number-conserving.tex | 0 .../SOLUTIONS/reaction.py | 2 +- .../SOLUTIONS/solutions.txt | 0 .../refs.bib | 0 doc/tutorials/CMakeLists.txt | 2 +- maintainer/configs/immersed_boundaries.hpp | 2 +- maintainer/configs/lees-edwards.hpp | 2 +- maintainer/configs/maxset.hpp | 2 +- maintainer/configs/nocheck-maxset.hpp | 2 +- samples/billard.py | 13 +- samples/coulomb_debye_hueckel.py | 242 --- samples/debye_hueckel.py | 2 +- samples/drude_bmimpf6.py | 7 +- samples/electrophoresis.py | 4 +- samples/lj_liquid.py | 3 +- samples/lj_liquid_distribution.py | 2 +- samples/lj_liquid_structurefactor.py | 2 +- samples/load_properties.py | 15 +- samples/observables_correlators.py | 2 +- samples/p3m.py | 2 +- samples/save_checkpoint.py | 5 +- samples/store_bonds.py | 3 +- samples/store_properties.py | 13 +- samples/visualization_bonded.py | 15 +- samples/visualization_cellsystem.py | 33 + samples/visualization_charged.py | 102 ++ samples/visualization_constraints.py | 19 +- ...OpenGL.py => visualization_interactive.py} | 82 +- samples/visualization_lbboundaries.py | 30 + samples/visualization_mmm2d.py | 18 +- samples/visualization_npt.py | 34 +- samples/visualization_poisseuille.py | 18 +- src/core/communication.cpp | 58 +- src/core/communication.hpp | 12 +- src/core/constraints/ShapeBasedConstraint.cpp | 66 +- src/core/constraints/ShapeBasedConstraint.hpp | 27 +- src/core/ghosts.cpp | 129 +- src/core/ghosts.hpp | 3 - src/core/initialize.cpp | 8 +- src/core/integrate.cpp | 14 +- src/core/interaction_data.cpp | 32 +- src/core/interaction_data.hpp | 20 +- src/core/minimize_energy.cpp | 2 +- src/core/p3m-dipolar.hpp | 2 + src/core/particle_data.cpp | 12 +- src/core/particle_data.hpp | 10 +- src/core/rotate_system.cpp | 2 +- src/core/rotation.cpp | 16 +- src/core/rotation.hpp | 3 +- .../{reaction.cpp => swimmer_reaction.cpp} | 6 +- .../{reaction.hpp => swimmer_reaction.hpp} | 10 +- src/core/tunable_slip.cpp | 84 -- src/core/tunable_slip.hpp | 44 - .../virtual_sites/VirtualSitesRelative.cpp | 6 +- src/features.def | 3 +- src/python/espressomd/cellsystem.pyx | 35 +- src/python/espressomd/checkpointing.py | 4 +- src/python/espressomd/constraints.py | 4 +- src/python/espressomd/electrostatics.pyx | 322 ++-- src/python/espressomd/globals.pxd | 2 +- src/python/espressomd/interactions.pxd | 5 + src/python/espressomd/interactions.pyx | 37 +- src/python/espressomd/lbboundaries.py | 8 + src/python/espressomd/magnetostatics.pyx | 27 +- src/python/espressomd/observables.py | 37 +- src/python/espressomd/particle_data.pxd | 2 + src/python/espressomd/particle_data.pyx | 30 +- src/python/espressomd/polymer.pyx | 3 + src/python/espressomd/reaction_ensemble.pyx | 1 + .../{reaction.pxd => swimmer_reaction.pxd} | 4 +- .../{reaction.pyx => swimmer_reaction.pyx} | 10 +- src/python/espressomd/system.pyx | 50 +- .../espressomd/visualization_opengl.pyx | 1307 +++++++++++------ .../constraints/ShapeBasedConstraint.hpp | 9 +- testsuite/CMakeLists.txt | 37 +- testsuite/dpd.py | 97 +- testsuite/ek_common.py | 86 ++ testsuite/ek_eof_one_species_x.py | 65 +- testsuite/ek_eof_one_species_x_nonlinear.py | 73 +- testsuite/ek_eof_one_species_y.py | 75 +- testsuite/ek_eof_one_species_y_nonlinear.py | 81 +- testsuite/ek_eof_one_species_z.py | 73 +- testsuite/ek_eof_one_species_z_nonlinear.py | 86 +- testsuite/rotation_per_particle.py | 51 +- testsuite/save_checkpoint.py | 25 + testsuite/stress.py | 21 + ...alytic_reaction.py => swimmer_reaction.py} | 6 +- testsuite/test_checkpoint.py | 49 + testsuite/thermalized_bond.py | 8 +- 111 files changed, 2452 insertions(+), 2020 deletions(-) rename doc/tutorials/{09-catalytic_reactions/09-catalytic_reactions.pdf => 09-swimmer_reactions/09-swimmer_reactions.pdf} (100%) rename doc/tutorials/{09-catalytic_reactions/09-catalytic_reactions.tex => 09-swimmer_reactions/09-swimmer_reactions.tex} (92%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/CMakeLists.txt (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/EXERCISES/reaction.py (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/FIGURES/avacf.pdf (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/FIGURES/janus-particle.pdf (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/FIGURES/janus-particle.tex (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/FIGURES/msd.pdf (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/FIGURES/number-conserving.pdf (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/FIGURES/number-conserving.tex (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/SOLUTIONS/reaction.py (99%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/SOLUTIONS/solutions.txt (100%) rename doc/tutorials/{09-catalytic_reactions => 09-swimmer_reactions}/refs.bib (100%) delete mode 100644 samples/coulomb_debye_hueckel.py create mode 100644 samples/visualization_cellsystem.py create mode 100644 samples/visualization_charged.py rename samples/{visualization_OpenGL.py => visualization_interactive.py} (54%) create mode 100644 samples/visualization_lbboundaries.py mode change 100755 => 100644 src/core/communication.cpp rename src/core/{reaction.cpp => swimmer_reaction.cpp} (99%) rename src/core/{reaction.hpp => swimmer_reaction.hpp} (90%) delete mode 100755 src/core/tunable_slip.cpp delete mode 100755 src/core/tunable_slip.hpp rename src/python/espressomd/{reaction.pxd => swimmer_reaction.pxd} (83%) rename src/python/espressomd/{reaction.pyx => swimmer_reaction.pyx} (97%) create mode 100644 testsuite/ek_common.py create mode 100644 testsuite/save_checkpoint.py rename testsuite/{catalytic_reaction.py => swimmer_reaction.py} (89%) create mode 100644 testsuite/test_checkpoint.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1a686c8c067..ed7e49885db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,6 +39,8 @@ status_pending: no_cuda_default: stage: build + except: + - doc script: - export with_cuda=false - export myconfig=default with_coverage=true @@ -46,6 +48,8 @@ no_cuda_default: no_cuda_maxset: stage: build + except: + - doc script: - export with_cuda=false - export myconfig=maxset with_coverage=true @@ -53,6 +57,8 @@ no_cuda_maxset: no_cuda_maxset_python3: stage: build + except: + - doc image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:latest script: - export with_cuda=false @@ -61,6 +67,8 @@ no_cuda_maxset_python3: no_cuda_maxset_debian: stage: build + except: + - doc image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/debian:latest script: - export with_cuda=false @@ -69,6 +77,8 @@ no_cuda_maxset_debian: no_cuda_maxset_opensuse: stage: build + except: + - doc image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/opensuse:latest script: - export with_cuda=false @@ -77,6 +87,8 @@ no_cuda_maxset_opensuse: no_cuda_maxset_centos: stage: build + except: + - doc image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/centos:latest script: - export with_cuda=false @@ -85,6 +97,8 @@ no_cuda_maxset_centos: no_cuda_nocheckmaxset: stage: build + except: + - doc script: - export with_cuda=false - export myconfig=nocheck-maxset make_check=false @@ -92,12 +106,16 @@ no_cuda_nocheckmaxset: shanchen: stage: build + except: + - doc script: - export myconfig=shanchen with_coverage=true - bash maintainer/cuda_build.sh lees_edwards: stage: build + except: + - doc script: - export myconfig=lees-edwards with_coverage=true - export run_tests=lees_edwards @@ -115,6 +133,8 @@ maxset: osx: stage: build + except: + - doc script: - export myconfig=maxset with_cuda=false - bash maintainer/CI/build_cmake.sh @@ -123,6 +143,8 @@ osx: osx-python3: stage: build + except: + - doc script: - export myconfig=maxset with_cuda=false python_version=3 - bash maintainer/CI/build_cmake.sh @@ -131,6 +153,8 @@ osx-python3: osx-cuda: stage: build + except: + - doc script: - export myconfig=maxset with_cuda=true make_check=false - bash maintainer/CI/build_cmake.sh @@ -139,6 +163,8 @@ osx-cuda: clang-static-analysis: stage: build + except: + - doc image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-clang-cuda:latest script: - export myconfig=maxset with_coverage=false with_static_analysis=true @@ -146,6 +172,8 @@ clang-static-analysis: intel: stage: build + except: + - doc image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-intel:latest script: - export myconfig=maxset with_coverage=false @@ -153,6 +181,8 @@ intel: check_sphinx: stage: additional_checks + except: + - doc dependencies: - git_clone - maxset @@ -162,6 +192,8 @@ check_sphinx: check_with_odd_no_of_processors: stage: additional_checks + except: + - doc when: on_success dependencies: - git_clone diff --git a/Readme.md b/Readme.md index 8c41ba97e63..c8c3af30d31 100644 --- a/Readme.md +++ b/Readme.md @@ -1,3 +1,7 @@ +# Call for Scientific Software Developer + +See http://espressomd.org/wordpress/call-for-scientific-software-developer + # ESPResSo [![GitLab CI](https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/badges/doc/pipeline.svg)](https://gitlab.icp.uni-stuttgart.de/espressomd/espresso/commits/doc) diff --git a/doc/sphinx/advanced_methods.rst b/doc/sphinx/advanced_methods.rst index 8d31148ed77..2bf811f32cd 100644 --- a/doc/sphinx/advanced_methods.rst +++ b/doc/sphinx/advanced_methods.rst @@ -10,7 +10,7 @@ Advanced Methods Creating bonds when particles collide ------------------------------------- -Please cite :cite:`espresso2` when using dynamic bonding. +Please cite :cite:`espresso2` when using dynamic bonding. With the help of this feature, bonds between particles can be created automatically during the simulation, every time two particles collide. @@ -105,13 +105,13 @@ The following limitations currently apply for the collision detection: * The “bind at point of collision” approach cannot handle collisions between virtual sites -.. _Catalytic Reactions: +.. _Swimmer Reactions: -Catalytic Reactions -------------------- +Swimmer Reactions +----------------- -With the help of the feature ``CATALYTIC_REACTIONS``, one can define three particle types to act as reactant (e.g. :math:`\mathrm{H_2 O_2}`), catalyzer (e.g. platinum), and product (e.g. :math:`\mathrm{O_2}` and :math:`\mathrm{H_2 O}`). The current setup allows one to simulate active swimmers and their chemical propulsion. +With the help of the feature ``SWIMMER_REACTIONS``, one can define three particle types to act as reactant (e.g. :math:`\mathrm{H_2 O_2}`), catalyzer (e.g. platinum), and product (e.g. :math:`\mathrm{O_2}` and :math:`\mathrm{H_2 O}`). The current setup allows one to simulate active swimmers and their chemical propulsion. For a Janus swimmer consisting of platinum on one hemisphere and gold on the other hemisphere, both surfaces catalytically induce a reaction. We assume an initial abundance of hydrogen peroxide and absence of products, so that back (recombination) reactions seldomly occur at the surface. A typical model for the propulsion of such a particle assumes @@ -131,7 +131,7 @@ That is, catalytic surfaces induce a reactions that produce charged species by c B &\xrightarrow{C^{-}} A \end{aligned} -where on the upper half of the catalyst :math:`C^{+}` a species :math:`A` is converted into :math:`B`, and on the lower half :math:`C^{-}` the opposite reaction takes place. Note that when :math:`A` and :math:`B` are charged, this reaction conserves charge, provided the rates are equal. +where on the upper half of the catalyst :math:`C^{+}` a species :math:`A` is converted into :math:`B`, and on the lower half :math:`C^{-}` the opposite reaction takes place. Note that when :math:`A` and :math:`B` are charged, this reaction conserves charge, provided the rates are equal. Note that this feature uses the word catalyst in a meaning which cannot be brought into agreement with the definition of a catalyst. If the catalyst :math:`C^{+}` catalyzes (on average) the reaction, where :math:`A` is converted to :math:`B`, then it is impossible that a catalyst :math:`C^{-}` perfoms (on average) the reverse reaction. For the example with hydrogen peroxide this would mean that hydrogen peroxide is created spontaneously using a catalyst (under the same environment where another catalyst wants to split hydrogen peroxide). This is chemically impossible. What is meant to be modeled is that hydrogen peroxide is constantly flowing into the system from the bulk and therfore it is not depleted. This behaviour cannot be modeled using a catalyst (in the defined meaning of the word catalyst). In |es| the orientation of a catalyzer particle is used to define hemispheres; half spaces going through the particle's center. The reaction region is bounded by the *reaction range*: :math:`r`. Inside the reaction range, we react only reactant-product pairs. The particles in a pair are swapped from hemisphere to another with a rate prescribed by @@ -183,7 +183,7 @@ can be used.:: * ``print r`` returns the current reaction parameters. -In future versions of |es| the capabilities of the ``CATALYTIC_REACTIONS`` feature may be generalized +In future versions of |es| the capabilities of the ``SWIMMER_REACTIONS`` feature may be generalized to handle multiple reactant, catalyzer, and product types, as well as more general reaction schemes. Other changes may involve merging the current implementation with the ``COLLISION_DETECTION`` feature. @@ -316,8 +316,7 @@ University of Bayreuth if you plan to use this feature. This section describes an alternative way to include soft elastic objects somewhat different from the previous chapter. In the Immersed Boundary Method (IBM), soft particles are considered as an infinitely -thin shell filled with liquid (see e.g. - :cite:`Peskin2002,Crowl2010,KruegerThesis`). When the +thin shell filled with liquid (see e.g. :cite:`Peskin2002,Crowl2010,KruegerThesis`). When the shell is deformed by an external flow it responds by elastic restoring forces which are transmitted into the fluid. In the present case, the inner and outer liquid are of the same type and are simulated using @@ -397,7 +396,7 @@ ibm\_triel, ibm\_tribend and ibm\_volCons: Object-in-fluid --------------- -Please cite  if you use the object-in-fluid implementation described +Please cite if you use the object-in-fluid implementation described below. For more details also see the documentation at http://cell-in-fluid.fri.uniza.sk/oif-documentation or contact the Cell-in-fluid Research Group at University of Žilina. @@ -575,7 +574,7 @@ The following example shows an interaction. inter 106 oif_local_force 1.0 0.5 0.0 1.7 0.6 0.2 0.3 1.1 This command (“invisible” for the user who executes the -``cript``/object\_in\_fluid.tcl  script) takes care of stretching, +``cript``/object\_in\_fluid.tcl script) takes care of stretching, bending and local area conservation all in one interaction with ID 106. Detailed description of the available types of interactions is presented in Section [sec:inter-bonded-oif]. @@ -587,8 +586,7 @@ Available commands In order to use the object-in-fluid (OIF) commands and work with immersed objects, the following features need to be compiled in: -``ASS, \ \verb EXTERNAL_FORCES . We do not specifically require \verb LB, \ \verb LB_BOUNDARIES, \ \verb CONSTRAINTS, \ \verb SOFT_SPHERE, \ \verb ``\ EMBRANE\_COLLISION, - ``IF_L``\ CAL\_FORCES,  ``IF_GL``\ BAL\_FORCES.  They are most likely +``ASS, \ \verb EXTERNAL_FORCES . We do not specifically require \verb LB, \ \verb LB_BOUNDARIES, \ \verb CONSTRAINTS, \ \verb SOFT_SPHERE, \ \verb ``\ EMBRANE\_COLLISION, ``IF_L``\ CAL\_FORCES, ``IF_GL``\ BAL\_FORCES. They are most likely to be used (for objects immersed in fluid and interacting with boundaries and each other), but they are not necessary for the following commands. For up-to-date overview of available oif commands see the OIF diff --git a/doc/sphinx/analysis.rst b/doc/sphinx/analysis.rst index bf5f174f364..7378e170c0a 100644 --- a/doc/sphinx/analysis.rst +++ b/doc/sphinx/analysis.rst @@ -747,7 +747,7 @@ The following observables are available: The particles are ordered according to the list of ids passed to the observable. - ParticleForces: Forces on the particles in the form :math:`f_{x1},\ f_{y1},\ f_{z1},\ f_{x2},\ f_{y2},\ f_{z2},\ \dots\ f_{xn},\ f_{yn},\ f_{zn}`. - - ParticleBodyVelocities: the particles' velocity in their respective body-fixed frames. + - ParticleBodyVelocities: the particles' velocities in their respective body-fixed frames (as per their orientation in space stored in their quaternions). :math:`v_{x1},\ v_{y1},\ v_{z1},\ v_{x2},\ v_{y2},\ v_{z2},\ \dots\ v_{xn},\ v_{yn},\ v_{zn}`. The particles are ordered according to the list of ids passed to the observable. - ParticleAngularVelocities: The particles' angular velocities in the space-fixed frame @@ -780,6 +780,10 @@ The following observables are available: - LBVelocityProfile +- System-wide observables + StressTensor: Total stress tensor (see :ref:`stress tensor`) + + .. _Correlations: diff --git a/doc/sphinx/figures/shape-simplepore.png b/doc/sphinx/figures/shape-simplepore.png index 64447ee2f8d4ee24d5f13541f0415ec05c82721b..6d77ba6cd28093bfc3ac1b4eee88164f52983ecf 100644 GIT binary patch literal 50448 zcmdpeg;!Jm|Nli0MAD=|---xGDxHE!OLtAA2cv5Yl$7!<5=yIdcXv#wDK&b+gb9No z9b?<~^8TFPKk@S%&UWv)d)?Qw9?yIktEcmn=_2Pv005YtKYOGP0Mz~9U+x83@Xl3+ ziAeB+##`;V;RWzt$c2|N;5CQOV^bdkk5@kac3uvEBh}Q{zrV;jMpIvsB{=axYso{Wm!wl`4Jd}yToj;&CqwU7ct0tGP#2BP%KAt`! zKFm2{d9a|zxm?fEwO!*<(-~tn=<)&_>d(Cz(bM{M_DmI9#Bx>%hba9#cmW)IR!F{D z@}rl>1J?E_uj!651iWdRQFQf-pkb304HUe}P3v3ilN~1!|Hcw!_JG_eTwa30s!-e;1!cFhbV@)cqo|v z;RHoFro8x%t}Y4Iw`}6^!i1K@0nV_IX?y>jS^O%-6Qn3wj}d4xj7?Mf<#)ybQ#w!| zs)T8vSM0ceFmW{rfO|d|LnPPx+ud(q|L?V|PwrY@z=B$Gb65|$OwjD)Cc7G+ShwG2o=?k#Yu4}ZFIdSCjFHPawt09Cdt7Tdw7HPAb(%g zk}G`f(KPMOf9fv%o0{*4gtxHNC{Gokg_g{zDxXo_B}N(}8lm%(q-cJmO0Yso{}bC2 zh70||ww4kA@a*x8C*Q7@&efx}6}YNFCRBNM?rC<`9Ebwx-}z$J)DliE%!{5o?D)^< zIQP3*$jZIERjy~m2lIe?pOz@;>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jTKsV$7+BD)E2{pD5dK%Vu+{dpJfR$J*UWR&G;S z_cl|MJoI6=Jmg01jyuH~%;n)V?$mTgyuajgDSHEO}T%T z>)UHd%;_W`Yo{qIS5Sv#n#ymAPI-xiJiOPV{P(YHo*=TOuVSg%Oj0kTa7V%iM`J^C ztBpj&`8bkrU&dhdWbwcFJ2&Fp$MDr15Wu-qf>c0tiS?=;_-TosUnMI^UZmKw%qD1c zIIsa~#X&7^YPm|TWD{0Sjt4M|eXc;$2#Wr9Gy`;@yW;{>ba%2cX9yWy=ie%>;u{{u z*2X;MV_o(foSqlH%{2D%Tfp-S+`19qZN9kL9=duZm+?|jFY-hBcxRuhmzoEDT_MS$ zM^h02UHi3Efm3|o3%qHvRD8Uw(8_HBP!;chcpY%|N|)m};sTY3V1YRsYcw_;_;@TQ zXFQxoM{-&pK~$uhCWbTxQUVFT^uSPj(E<%J08+ZHXpPk%Wx&-7I_pI60zdE;i2u&5 zwARebaCgB3%cc+M12*gDvUrDQ0MkVZ&KaS^2 zd;tFOxvO#3IzH<($oZk8BXfV7&kzBS*g(`dl1u8Av$7SA6gh3QC~3=`93fC-_#@{R zP#|YF^HvB@T|~kR$k_w10QhFF)xkZ2*jWoeAOxaCIG`>sb{QaL4wkZ8(wcr^E_Kn)oo48QScHZ3W0+9l%9CDmuS-fC2tjYSDg1n+FKxvA#!lhrIS4 z$hoZcqgDIT&TXDzExfgX*iI9|M!wYE@3%;A-2rus1HA~KWYq+L{@`^IfVLxE;DG`x ztQhPyU){+Po9BW*1xkS&hwOd821m4G0T+`~WBjVsxDBB;a&Sjl3yqPH)9zZ|+S* z1$@Cz*hvry9ioT-`?xRkrjI~>AK1U{pt^O3JP7C(h>@nVFYv!20Y420 z8EzT`b$qs>vDejeA7>5zuOg*Plj=vy_&1{k8k0OPYY)_UGz`23^@*a)@o#`_ * `Electrokinetics `_ * `Visualization `_ -* `Catalytic reactions `_ +* `Swimmer reactions `_ You can also find the tutorials and related scripts in the directory ``/doc/tutorials``. @@ -394,14 +394,14 @@ or in the `git repository ` to the method. +It is also possible to pass a subset of the method parameters such as `mesh`. In that case, only the omitted parameters are tuned:: -| inter magnetic p3m accuracy -Tuning dipolar P3M works exactly as tuning Coulomb P3M. Therefore, for -details on how to tune the algorithm, refer to the documentation of -Coulomb P3M (see section ). + import espressomd.magnetostatics as magnetostatics + p3m = magnetostatics.DipolarP3M(prefactor=1, mesh=32, accuracy=1E-4) + system.actors.add(p3m) -For the magnetic case, the expressions of the error estimate are given -in :cite:`cerda08a`. +It is important to note that the error estimates given in :cite:`cerda08a` used in the tuning contain assumptions about the system. In particular, a homogeneous system is assumed. If this is no longer the case during the simulation, actual force and torque errors can be significantly larger. .. _Dipolar Layer Correction (DLC): + Dipolar Layer Correction (DLC) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +:class:`espressomd.magnetostatic_extensions.DLC` + +The dipolar layer correction (DLC) is used in conjunction with the dipolar P3M method to calculate dipolar interactions in a 2D-periodic system. +It is based on :cite:`brodka04a` and the dipolar version of +:ref:`Electrostatic Layer Correction (ELC)`. -inter magnetic mdlc +Usage notes: -Like ELC but applied to the case of magnetic dipoles, but here the -accuracy is the one you wish for computing the energy. is set to a value -that, assuming all dipoles to be as larger as the largest of the dipoles -in the system, the error for the energy would be smaller than the value -given by accuracy. At this moment you cannot compute the accuracy for -the forces, or torques, nonetheless, usually you will have an error for -forces and torques smaller than for energies. Thus, the error for the -energies is an upper boundary to all errors in the calculations. + * The non-periodic direction is always the `z`-direction. + + * The method relies on a slab of the simulation box perpendicular to the z-direction not to contain particles. The size in z-direction of this slab is controlled by the `gap_size` parameter. The user has to ensure that no particles enter this region by means of constraints or by fixing the particles' z-coordinate. When there is no empty slab of the specified size, the method will silently produce wrong results. + + * The method can be tuned using the `accuracy` parameter. In contrast to the elctrostatic method, it refers to the energy. Furthermore, it is assumed that all dipole moment are as large as the largest of the dipoles in the system. + +The method is used as follows:: -At present, the program assumes that the gap without particles is along -the z-direction. The gap-size is the length along the z-direction of the -volume where particles are not allowed to enter. + import espressomd.magnetostatics as magnetostatics + import espressomd.magnetostatic_extensions as magnetostatic_extensions + + p3m = magnetostatics.DipolarP3M(prefactor=1, accuracy=1E-4) + dlc = magnetostatic_extensions.DLC(maxPWerror=1E-5, gap_size=2.) + system.actors.add(p3m) + system.actors.add(dlc) -As a reference for the DLC method, see :cite:`brodka04a`. -.. _Dipolar all-with-all and no replicas (DAWAANR): -Dipolar all-with-all and no replicas (DAWAANR) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -inter magnetic dawaanr +.. _Dipolar direct sum on gpu: + +Dipolar direct sum +------------------ This interaction calculates energies and forces between dipoles by explicitly summing over all pairs. For the directions in which the -system is periodic (as defined by ``setmd periodic``), it applies the +system is periodic (as defined by ``system.periodicity``), it applies the minimum image convention, i.e. the interaction is effectively cut off at half a box length. -In periodic systems, this method should only be used if it is not -possible to use dipolar P3M or DLC, because those methods have a far -better accuracy and are much faster. In a non-periodic system, the -DAWAANR-method gives the exact result. +The direct summation methods are mainly intended for non-periodic systems which cannot be solved using the dipolar P3M method. +Due to the long-range nature of dipolar interactions, Direct summation with minimum image convention does not yield good accuracy with periodic systems. -.. _Magnetic Dipolar Direct Sum (MDDS) on CPU: -Magnetic Dipolar Direct Sum (MDDS) on CPU ------------------------------------------ +Two methods are available: -inter magnetic mdds n_cut +* :class:`espressomd.magnetostatics.DipolarDirectSumCpu` + performs the calculation in double precision on the Cpu. -The command enables the “magnetic dipolar direct sum”. The dipole-dipole -interaction is computed by explicitly summing over all pairs. If the -system is periodic in one or more directions, the interactions with -further replicas of the system in all periodic directions is explicitly -computed. + +* :class:`espressomd.magnetostatics.DipolarDirectSumGpu` + performs the calculations in single precision on a Cuda-capable graphics card. + The implementation is optimized for large systems of several thousand + particles. It makes use of one thread per particle. When there are fewer + particles than the number of threads the gpu can execute simultaneously, + the rest of the gpu remains idle. Hence, the method will perform poorly + for small systems. + +To use the methods, create an instance of either :class:`espressomd.magnetostatics.DipolarDirectSumCpu` or :class:`espressomd.magnetostatics.DipolarDirectSumGpu` and add it to the system's list of active actors. The only required parameter is the Prefactor: (:eq:`dipolar_prefactor`):: + + from espressomd.magnetostatics import DipolarDirectSumGpu + dds=DipolarDirectSumGpu(bjerrum_length=1) + system.actors.add(dds) + + +For testing purposes, a variant of the dipolar direct sum is available which adds periodic copies to the system in periodic directions (:class:`espressomd.magnetostatics.DipolarDirectSumWithReplica`). As it is very slow, this method is not intended to do simulations, but rather to check the results you get from more efficient methods like P3M. -.. _Dipolar direct sum on gpu: -Dipolar direct sum on gpu -------------------------- -This interaction calculates energies and forces between dipoles by -explicitly summing over all pairs. For the directions in which the -system is periodic (as defined by ``setmd periodic``), it applies the -minimum image convention, i.e. the interaction is effectively cut off at -half a box length. - -The calculations are performed on the gpu in single precision. The -implementation is optimized for large systems of several thousand -particles. It makes use of one thread per particle. When there are fewer -particles than the number of threads the gpu can execute simultaneously, -the rest of the gpu remains idle. Hence, the method will perform poorly -for small systems. - -To use the method, create an instance of :attr:`espressomd.magnetostatics.DipolarDirectSumGpu` and add it to the system's list of active actors. The only required parameter is the Bjerrum length:: - - from espressomd.magnetostatics import DipolarDirectSumGpu - dds=DipolarDirectSumGpu(bjerrum_length=1) - system.actors.add(dds) .. _Barnes-Hut octree sum on gpu: @@ -184,7 +153,7 @@ an additive distance respectively. For the detailed description of the Barnes-Hut method application to the dipole-dipole interactions, please refer to :cite:`Polyakov2013`. -To use the method, create an instance of :attr:`espressomd.magnetostatics.DipolarBarnesHutGpu` and add it to the system's list of active actors:: +To use the method, create an instance of :class:`espressomd.magnetostatics.DipolarBarnesHutGpu` and add it to the system's list of active actors:: from espressomd.magnetostatics import DipolarBarnesHutGpu bh=DipolarBarnesHutGpu(prefactor = pf_dds_gpu, epssq = 200.0, itolsq = 8.0) @@ -198,8 +167,8 @@ Scafacos Magnetostatics Espresso can use the methods from the Scafacos *Scalable fast Coulomb solvers* library for dipoles, if the methods support dipolar calculations. The feature SCAFACOS_DIPOLES has to be added to -myconfig.hpp to activate this feature. At the time of this writing (May -2017) dipolar calculations are only included in the ``dipolar`` branch of the Scafacos code. +myconfig.hpp to activate this feature. At the time of this writing (Feb +2018) dipolar calculations are only included in the ``dipolar`` branch of the Scafacos code. To use SCAFACOS, create an instance of :attr:`espressomd.magnetostatics.Scafacos` and add it to the list of active actors. Three parameters have to be specified: * method_name: name of the SCAFACOS method being used. diff --git a/doc/sphinx/running.rst b/doc/sphinx/running.rst index dd71a02b1c8..acd7ecdb777 100644 --- a/doc/sphinx/running.rst +++ b/doc/sphinx/running.rst @@ -54,27 +54,14 @@ enforce force recalculation. Run steepest descent minimization --------------------------------- -In Python the ``minimize_energy`` functionality can be imported from -:mod:`espressomd.minimize_energy` as class -:class:`espressomd.minimize_energy.MinimizeEnergy`. Alternatively it -is already part of the :class:`espressomd.system.System` class object -and can be called from there (second variant):: - - espressomd.minimize_energy.init( - f_max = , - gamma = , - max_steps = , - max_displacement = ) - espressomd.minimize_energy.minimize() - - system.minimize_energy.init( - f_max = , - gamma = , - max_steps = , - max_displacement = ) - system.minimize_energy.minimize() - -This command runs a steepest descent energy minimization on the system. +:func:`espressomd.espresso.thermostat.Thermostat.set_steepest_descent` + + + +This feature is used to propagate each particle by a small distance parallel to the force acting on it. +When only conservative forces for which a potential exists are in use, this is equivalent to a steepest descent energy minimization. +A common application is removing overlap between randomly placed particles. + Please note that the behavior is undefined if either a thermostat, Maggs electrostatics or Lattice-Boltzmann is activated. It runs a simple steepest descent algorithm: @@ -90,8 +77,17 @@ Rotational degrees of freedom are treated similarly: each particle is rotated around an axis parallel to the torque acting on the particle. Please be aware of the fact that this needs not to converge to a local minimum in periodic boundary conditions. Translational and rotational -coordinates that are fixed using the ``fix`` command or the -``ROTATION_PER_PARTICLE`` feature are not altered. +coordinates that are fixed using the ``fix`` and ``rotation`` attribute of particles are not altered. + +Usage example:: + + system.integrator.set_steepest_descent( + f_max=0, gamma=0.1, max_displacement=0.1) + system.integrator.run(20) + system.integrator.set_vv() # to switch back to velocity verlet + + + .. _Multi-timestepping: diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index c4f3ecdcd6e..4a0659d9418 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -385,6 +385,12 @@ thermostat acts on the relative velocities between nearest neighbor particles. Larger cutoffs including next nearest neighbors or even more are unphysical. +Boundary conditions for DPD can be introduced by adding the boundary +as a particle constraint, and setting a velocity and a type on it, see +:class:`espressomd.constraints.Constraint`. Then a +:ref:`DPD interaction` with the type can be defined, which acts as a +boundary condition. + .. _Isotropic NPT thermostat: Isotropic NPT thermostat diff --git a/doc/sphinx/visualization.rst b/doc/sphinx/visualization.rst index e0bb2af9b96..f6c5e45a1aa 100644 --- a/doc/sphinx/visualization.rst +++ b/doc/sphinx/visualization.rst @@ -16,8 +16,10 @@ online-visualization: #. A direct rendering engine based on *pyopengl*. As it is developed for |es|, it supports the visualization of several specific features like - external forces or constraints. It has no GUI to setup the - appearance, but can be adjusted by a large set of parameters. + constraints, particle properties, the cell system, Lattice-Boltzmann and + more. It can be adjusted with a large number of parameters to set colors, + materials, camera and interactive features like assigning callbacks to user + input. Additional requirements: python module *PyOpenGL*. @@ -106,18 +108,34 @@ Optional keywords: OpenGL visualizer ----------------- +:class:`espressomd.visualization.openGLLive()` + +The optional keywords in ``**kwargs`` are used to adjust the appearance of the visualization. +The parameters have suitable default values for most simulations. + +Required parameters: + * `system`: The espressomd.System() object. +Optional keywords: + * Have a look at the attribute list in :class:`espressomd.visualization.openGLLive()` + + +.. _Running the visualizer: + +Running the visualizer +~~~~~~~~~~~~~~~~~~~~~~ + | :meth:`espressomd.visualization.openGLLive.run()` -To visually debug your simulation, ``run()`` can be used to conveniently start -an integration loop in a separate thread once the visualizer is initialized:: +To visually debug your simulation, ``run(n)`` can be used to conveniently start +an integration loop with `n` integration steps in a separate thread once the +visualizer is initialized:: import espressomd from espressomd import visualization - system = espressomd.System() + system = espressomd.System(box_l = [10,10,10]) system.cell_system.skin = 0.4 system.time_step = 0.00001 - system.box_l = [10,10,10] system.part.add(pos = [1,1,1], v = [1,0,0]) system.part.add(pos = [9,9,9], v = [0,1,0]) @@ -125,38 +143,69 @@ an integration loop in a separate thread once the visualizer is initialized:: visualizer = visualization.openGLLive(system, background_color = [1,1,1]) visualizer.run(1) -:class:`espressomd.visualization.openGLLive()` -The optional keywords in ``**kwargs`` are used to adjust the appearance of the visualization. -The parameters have suitable default values for most simulations. +.. _Screenshots: -Required parameters: - * `system`: The espressomd.System() object. -Optional keywords: - * Have a look at the attribute list in :class:`espressomd.visualization.openGLLive()` +Screenshots +~~~~~~~~~~~ + +| :meth:`espressomd.visualization.openGLLive.screenshot()` + +The openGL visualizer can also be used for offline rendering. +After creating the visualizer object, call ``screenshot(path)`` +to save an image of your simulation to `path`. Internally, the image is saved +with `matplotlib.pyplot.imsave`, so the file format is specified by the +extension of the filename. The image size is determined by the keyword +argument `window_size` of the visualizer. This method can be used to create +screenshots without blocking the simulation script:: + + import espressomd + from espressomd import visualization + + system = espressomd.System(box_l = [10,10,10]) + system.cell_system.skin = 1.0 + system.time_step = 0.1 + + for i in range(1000): + system.part.add(pos = [5,5,5]) + + system.thermostat.set_langevin(kT=1, gamma=1) + + visualizer = visualization.openGLLive(system, window_size = [500,500]) + + for i in range(100): + system.integrator.run(1) + visualizer.screenshot('screenshot_{}.jpg'.format(i)) + + #You may consider creating a video with ffmpeg: + #ffmpeg -f image2 -framerate 30 -i 'screenshot_%d.jpg' output.mp4 + +It is also possible to create a snapshot during online visualization. +Simply press the *enter* key to create a snapshot of the current window, +which saves it to `_n.png` (with incrementing `n`). .. _Colors and Materials: Colors and Materials ~~~~~~~~~~~~~~~~~~~~ -Colors for particles, bonds and constraints are specified by RGBA arrays. -Materials by an array for the ambient, diffuse, specular and shininess (ADSS) -components. To distinguish particle groups, arrays of RGBA or ADSS entries are +Colors for particles, bonds and constraints are specified by RGB arrays. +Materials by an array for the ambient, diffuse, specular and shininess and opacity (ADSSO) +components. To distinguish particle groups, arrays of RGBA or ADSSO entries are used, which are indexed circularly by the numerical particle type:: # Particle type 0 is red, type 1 is blue (type 2 is red etc).. visualizer = visualization.openGLLive(system, particle_coloring = 'type', - particle_type_colors = [[1, 0, 0, 1],[0, 0, 1, 1]]) + particle_type_colors = [[1, 0, 0],[0, 0, 1]]) `particle_type_materials` lists the materials by type:: # Particle type 0 is gold, type 1 is blue (type 2 is gold again etc). visualizer = visualization.openGLLive(system, particle_coloring = 'type', - particle_type_colors = [[1, 1, 1, 1],[0, 0, 1, 1]], - particle_type_materials = [gold, bright]) + particle_type_colors = [[1, 1, 1],[0, 0, 1]], + particle_type_materials = [steel, bright]) Materials are stored in :attr:`espressomd.visualization.openGLLive().materials`. @@ -194,7 +243,7 @@ feature):: director_arrows = True, director_arrows_type_scale = [1.5, 1.0], director_arrows_type_radii = [0.1, 0.4], - director_arrows_type_colors = [[1.0, 0, 0, 1.0], [0, 1.0, 0, 0.5]]) + director_arrows_type_colors = [[1.0, 0, 0], [0, 1.0, 0]]) for i in range(10): system.part.add(pos = numpy.random.random(3) * box_l, @@ -227,6 +276,11 @@ The camera can be controlled via mouse and keyboard: * mouse wheel / key pair TG: zoom * WASD-Keyboard control (WS: move forwards/backwards, AD: move sidewards) * Key pairs QE, RF, ZC: rotate the system + * Double click on a particle: Show particle information + * Double click in empty space: Disable particle information + * Left/Right arrows: Cycle through particles + * Space: If started with `run(n)`, this pauses the simulation + * Enter: Creates a snapshot of the current window and saves it to `_n.png` (with incrementing `n`) Additional input functionality for mouse and keyboard is possible by assigning callbacks to specified keyboard or mouse buttons. This may be useful for @@ -264,7 +318,7 @@ by a timer or keyboard input:: visualizer.keyboardManager.registerButton(KeyboardButtonEvent('t',KeyboardFireEvent.Hold,increaseTemp)) visualizer.keyboardManager.registerButton(KeyboardButtonEvent('g',KeyboardFireEvent.Hold,decreaseTemp)) -Further examples can be found in samples/python/billard.py or samples/python/visualization\_openGL.py. +Further examples can be found in samples/python/billard.py or samples/python/visualization\_interactive.py. .. _Dragging particles: @@ -280,30 +334,5 @@ distance of particle and mouse cursor). Visualization example scripts ----------------------------- -Various example scripts can be found in the samples/python folder or in -some tutorials: - -- samples/python/visualization.py: LJ-Liquid with live plotting. - -- samples/python/visualization\_bonded.py: Sample for bond - visualization. - -- samples/python/billard.py: Simple billard game including many - features of the openGL visualizer. - -- samples/python/visualization\_openGL.py: Timer and keyboard callbacks - for the openGL visualizer. - -- doc/tutorials/python/02-charged\_system/scripts/nacl\_units\_vis.py: - Periodic NaCl crystal, see tutorial “Charged Systems”. - -- doc/tutorials/python/02-charged\_system/scripts/nacl\_units\_confined\_vis.py: - Confined NaCl with interactively adjustable electric field, see - tutorial “Charged Systems”. - -- doc/tutorials/python/08-visualization/scripts/visualization.py: - LJ-Liquid visualization along with tutorial “Visualization”. - -Finally, it is recommended to go through tutorial “Visualization” for -further code explanations. Also, the tutorial “Charged Systems” has two -visualization examples. +Various :ref:`Sample Scripts` can be found in `samples/python/visualization*` +or in the :ref:`Tutorials` "Visualization" and "Charged Systems". diff --git a/doc/sphinx/zrefs.bib b/doc/sphinx/zrefs.bib index df6f5239d2a..086d7e285dc 100755 --- a/doc/sphinx/zrefs.bib +++ b/doc/sphinx/zrefs.bib @@ -1115,4 +1115,17 @@ @book{schlick2010 year = {2010} } - +@Article{cerda08d, + title = {{P3M} algorithm for dipolar interactions.}, + author = {Juan J. Cerd\`{a} and V. Ballenegger and O. Lenz and Ch. Holm}, + journal = {Journal of Chemical Physics}, + year = {2008}, + pages = {234104}, + volume = {129}, + date-modified = {2009-01-28 08:15:14 +0100}, + doi = {10.1063/1.3000389}, + e-print = {0805.4783}, + file = {cerda08d.pdf:cerda08d.pdf:PDF}, + owner = {jcerda}, + timestamp = {2008.01.14} +} diff --git a/doc/tutorials/01-lennard_jones/scripts/lj_tutorial.py b/doc/tutorials/01-lennard_jones/scripts/lj_tutorial.py index cce2bbc31a4..2e8911a37e8 100644 --- a/doc/tutorials/01-lennard_jones/scripts/lj_tutorial.py +++ b/doc/tutorials/01-lennard_jones/scripts/lj_tutorial.py @@ -33,7 +33,7 @@ # System parameters ############################################################# n_part = 500 -density = 0.8442 +density = 0.2 skin = 0.4 time_step = 0.01 @@ -105,10 +105,10 @@ """.strip().format(warm_n_time, warm_steps, min_dist)) i = 0 -act_min_dist = system.analysis.mindist() +act_min_dist = system.analysis.min_dist() while i < warm_n_time and act_min_dist < min_dist : system.integrator.run(warm_steps) - act_min_dist = system.analysis.mindist() + act_min_dist = system.analysis.min_dist() print("run {} at time = {} (LJ cap= {} ) min dist = {}".strip().format(i, system.time, lj_cap, act_min_dist)) i+=1 lj_cap += 1.0 diff --git a/doc/tutorials/09-catalytic_reactions/09-catalytic_reactions.pdf b/doc/tutorials/09-swimmer_reactions/09-swimmer_reactions.pdf similarity index 100% rename from doc/tutorials/09-catalytic_reactions/09-catalytic_reactions.pdf rename to doc/tutorials/09-swimmer_reactions/09-swimmer_reactions.pdf diff --git a/doc/tutorials/09-catalytic_reactions/09-catalytic_reactions.tex b/doc/tutorials/09-swimmer_reactions/09-swimmer_reactions.tex similarity index 92% rename from doc/tutorials/09-catalytic_reactions/09-catalytic_reactions.tex rename to doc/tutorials/09-swimmer_reactions/09-swimmer_reactions.tex index 8f0c159fb9f..20d902a3c31 100644 --- a/doc/tutorials/09-catalytic_reactions/09-catalytic_reactions.tex +++ b/doc/tutorials/09-swimmer_reactions/09-swimmer_reactions.tex @@ -152,9 +152,11 @@ \section{Catalytic Reactions for Swimming in \es} \caption{\label{fig:nc}Illustration of the catalytic scheme. The cut-off range of $r$ around the catalyzer (green) is subdivided into two half-spaces. A reactant-product pair (blue and red connected by dotted line)is converted by swapping them if the pair is selected, and only if the product (red) resides in the upper half-space (silver background) and the corresponding reactant (blue) resides in the lower half-space (gold background). The catalytic reaction leads to a conversion of one reactant-product pair of particles in this example, denoted by the arrows annotated with $k_{\text{ct}}$. The second reactant-product pair within the reaction range is not viable for conversion. Additionally, particles in a pair may only undergo only one exhange per time step.} \end{figure} +Note: Let the \textit{catalyst} $C^{+}$ (on average) convert more $A$ to $B$. Then the assumption of the model that the \textit{catalyst} $C^{-}$ would convert (on average) more $B$ to $A$ such that the number of $A$ and $B$ is constant in time is hair-raising! $C^{-}$ would have changed the position of chemical equilibrium which it can by the definition of a \textit{catalyst} cannot do. Let s say that $A$ is hydrogen peroxide and $B$ is water and oxygen. Then it is totally clear that a \textit{catalyst} cannot recreate (on average) hydrogen peroxide from water and oxygen under the same conditions where splitting hydrogen peroxide is energetically favourable. Therefore the usage of the word catalyst is wrong here. What the swimmer reactions aim to model is that new hydrogen peroxide (high energetic molecules) enter from the bulk to the vincinity of the active simmer and get split there. This cannot be modeled via a \textit{catalyst} which magically creates new high energetic molecules from low energetic moleucles (water and oxygen). This cannot happen repeatedly spontaneously. It is wrong to assume that a chemical reaction would recover high energetic molecules. + \subsection{Usage in \es} -Catalytic reactions can be enabled in \es\ by compiling in the eponymous feature \code{CATALYTIC_REACTIONS} and the \code{ROTATION} feature to provide the particles with an orientation vector. In \es\ the orientation of the particle is defined by a quaternion; this in turn defines a rotation matrix that acts on the particle's initial orientation (along the $z$-axis), which then defines the particles current orientation~\cite{UG,Limbach_06,Arnold_13}. +Catalytic reactions can be enabled in \es\ by compiling in the eponymous feature \code{SWIMMER_REACTIONS} and the \code{ROTATION} feature to provide the particles with an orientation vector. In \es\ the orientation of the particle is defined by a quaternion; this in turn defines a rotation matrix that acts on the particle's initial orientation (along the $z$-axis), which then defines the particles current orientation~\cite{UG,Limbach_06,Arnold_13}. To setup the reaction there is the \es\ command \codees{Reaction}, which operates on particle types. The general syntax is \begin{espresso} @@ -192,7 +194,7 @@ \section{Configuring \es\ for Catalytic Reactions} #define ROTATION #define ROTATIONAL_INERTIA #define LANGEVIN_PER_PARTICLE -#define CATALYTIC_REACTIONS +#define SWIMMER_REACTIONS #define LENNARD_JONES \end{lstlisting} Now you are ready to build \es. You have to run \code{cmake} again to process the modified \code{myconfig.hpp}. diff --git a/doc/tutorials/09-catalytic_reactions/CMakeLists.txt b/doc/tutorials/09-swimmer_reactions/CMakeLists.txt similarity index 100% rename from doc/tutorials/09-catalytic_reactions/CMakeLists.txt rename to doc/tutorials/09-swimmer_reactions/CMakeLists.txt diff --git a/doc/tutorials/09-catalytic_reactions/EXERCISES/reaction.py b/doc/tutorials/09-swimmer_reactions/EXERCISES/reaction.py similarity index 100% rename from doc/tutorials/09-catalytic_reactions/EXERCISES/reaction.py rename to doc/tutorials/09-swimmer_reactions/EXERCISES/reaction.py diff --git a/doc/tutorials/09-catalytic_reactions/FIGURES/avacf.pdf b/doc/tutorials/09-swimmer_reactions/FIGURES/avacf.pdf similarity index 100% rename from doc/tutorials/09-catalytic_reactions/FIGURES/avacf.pdf rename to doc/tutorials/09-swimmer_reactions/FIGURES/avacf.pdf diff --git a/doc/tutorials/09-catalytic_reactions/FIGURES/janus-particle.pdf b/doc/tutorials/09-swimmer_reactions/FIGURES/janus-particle.pdf similarity index 100% rename from doc/tutorials/09-catalytic_reactions/FIGURES/janus-particle.pdf rename to doc/tutorials/09-swimmer_reactions/FIGURES/janus-particle.pdf diff --git a/doc/tutorials/09-catalytic_reactions/FIGURES/janus-particle.tex b/doc/tutorials/09-swimmer_reactions/FIGURES/janus-particle.tex similarity index 100% rename from doc/tutorials/09-catalytic_reactions/FIGURES/janus-particle.tex rename to doc/tutorials/09-swimmer_reactions/FIGURES/janus-particle.tex diff --git a/doc/tutorials/09-catalytic_reactions/FIGURES/msd.pdf b/doc/tutorials/09-swimmer_reactions/FIGURES/msd.pdf similarity index 100% rename from doc/tutorials/09-catalytic_reactions/FIGURES/msd.pdf rename to doc/tutorials/09-swimmer_reactions/FIGURES/msd.pdf diff --git a/doc/tutorials/09-catalytic_reactions/FIGURES/number-conserving.pdf b/doc/tutorials/09-swimmer_reactions/FIGURES/number-conserving.pdf similarity index 100% rename from doc/tutorials/09-catalytic_reactions/FIGURES/number-conserving.pdf rename to doc/tutorials/09-swimmer_reactions/FIGURES/number-conserving.pdf diff --git a/doc/tutorials/09-catalytic_reactions/FIGURES/number-conserving.tex b/doc/tutorials/09-swimmer_reactions/FIGURES/number-conserving.tex similarity index 100% rename from doc/tutorials/09-catalytic_reactions/FIGURES/number-conserving.tex rename to doc/tutorials/09-swimmer_reactions/FIGURES/number-conserving.tex diff --git a/doc/tutorials/09-catalytic_reactions/SOLUTIONS/reaction.py b/doc/tutorials/09-swimmer_reactions/SOLUTIONS/reaction.py similarity index 99% rename from doc/tutorials/09-catalytic_reactions/SOLUTIONS/reaction.py rename to doc/tutorials/09-swimmer_reactions/SOLUTIONS/reaction.py index 51847909e77..b569e39e1bb 100644 --- a/doc/tutorials/09-catalytic_reactions/SOLUTIONS/reaction.py +++ b/doc/tutorials/09-swimmer_reactions/SOLUTIONS/reaction.py @@ -39,7 +39,7 @@ assert_features(["ROTATION", "ROTATIONAL_INERTIA", "LANGEVIN_PER_PARTICLE", - "CATALYTIC_REACTIONS", + "SWIMMER_REACTIONS", "LENNARD_JONES"]) ################################################################################ diff --git a/doc/tutorials/09-catalytic_reactions/SOLUTIONS/solutions.txt b/doc/tutorials/09-swimmer_reactions/SOLUTIONS/solutions.txt similarity index 100% rename from doc/tutorials/09-catalytic_reactions/SOLUTIONS/solutions.txt rename to doc/tutorials/09-swimmer_reactions/SOLUTIONS/solutions.txt diff --git a/doc/tutorials/09-catalytic_reactions/refs.bib b/doc/tutorials/09-swimmer_reactions/refs.bib similarity index 100% rename from doc/tutorials/09-catalytic_reactions/refs.bib rename to doc/tutorials/09-swimmer_reactions/refs.bib diff --git a/doc/tutorials/CMakeLists.txt b/doc/tutorials/CMakeLists.txt index 98bf5349cab..6b2182e4a5c 100644 --- a/doc/tutorials/CMakeLists.txt +++ b/doc/tutorials/CMakeLists.txt @@ -27,7 +27,7 @@ add_subdirectory(05-raspberry_electrophoresis) add_subdirectory(06-active_matter) add_subdirectory(07-electrokinetics) add_subdirectory(08-visualization) -add_subdirectory(09-catalytic_reactions) +add_subdirectory(09-swimmer_reactions) ### here: add the appropriate tutorial target after DEPENDS diff --git a/maintainer/configs/immersed_boundaries.hpp b/maintainer/configs/immersed_boundaries.hpp index 3501d02e155..0788653021c 100644 --- a/maintainer/configs/immersed_boundaries.hpp +++ b/maintainer/configs/immersed_boundaries.hpp @@ -14,7 +14,7 @@ #define COLLISION_DETECTION #define LANGEVIN_PER_PARTICLE -#define CATALYTIC_REACTIONS +#define SWIMMER_REACTIONS #define NEMD #define NPT diff --git a/maintainer/configs/lees-edwards.hpp b/maintainer/configs/lees-edwards.hpp index 92f4b0d91be..eb25f809757 100644 --- a/maintainer/configs/lees-edwards.hpp +++ b/maintainer/configs/lees-edwards.hpp @@ -14,7 +14,7 @@ #define COLLISION_DETECTION #define LANGEVIN_PER_PARTICLE -#define CATALYTIC_REACTIONS +#define SWIMMER_REACTIONS #define NEMD #define NPT diff --git a/maintainer/configs/maxset.hpp b/maintainer/configs/maxset.hpp index 2ef8f32281f..a328a47a090 100755 --- a/maintainer/configs/maxset.hpp +++ b/maintainer/configs/maxset.hpp @@ -15,7 +15,7 @@ #define BOND_CONSTRAINT #define COLLISION_DETECTION #define LANGEVIN_PER_PARTICLE -#define CATALYTIC_REACTIONS +#define SWIMMER_REACTIONS #define NEMD #define NPT diff --git a/maintainer/configs/nocheck-maxset.hpp b/maintainer/configs/nocheck-maxset.hpp index 0784264e6e3..3ad3a00566e 100755 --- a/maintainer/configs/nocheck-maxset.hpp +++ b/maintainer/configs/nocheck-maxset.hpp @@ -15,7 +15,7 @@ #define COLLISION_DETECTION #define LANGEVIN_PER_PARTICLE -#define CATALYTIC_REACTIONS +#define SWIMMER_REACTIONS #define NEMD #define NPT diff --git a/samples/billard.py b/samples/billard.py index 0ecdd1afb67..1df8475b829 100644 --- a/samples/billard.py +++ b/samples/billard.py @@ -24,15 +24,20 @@ visualizer = openGLLive(system, ext_force_arrows = True, - ext_force_arrows_scale = [0.02], + ext_force_arrows_type_scale = [0.02], + ext_force_arrows_type_radii = [0.01], background_color = [0.5,0.4,0.5], drag_enabled = False, - constraint_type_colors = [[0.039,0.424,0.011,1.0]], - particle_type_colors = [[1,1,1,1],[1,0,0,1],[0,0,1,1],[0.2,0.2,0.2,1]], + particle_type_materials = ['medium', 'bright', 'bright', 'medium'], + particle_type_colors = [[1,1,1],[0.5,0.1,0.1],[0.1,0.2,0.4],[0.2,0.2,0.2]], + constraint_type_materials = ['dark'], + constraint_type_colors = [[0.1,0.424,0.011], [0.1,0.1,0.1]], camera_position = [ 1.12, 2.8, 0.56], window_size = [1000,600], draw_axis = False, - light_brightness = 5.0) + light_pos = [table_dim[0]*0.5, 1.0, table_dim[1]*0.5], + light_colors = [[0.8, 0.8, 0.8], [0.9, 0.9, 0.9], [1.0, 1.0, 1.0]], + light_brightness = 1.0) stopped = True angle = np.pi*0.5 diff --git a/samples/coulomb_debye_hueckel.py b/samples/coulomb_debye_hueckel.py deleted file mode 100644 index 075983683fe..00000000000 --- a/samples/coulomb_debye_hueckel.py +++ /dev/null @@ -1,242 +0,0 @@ -# -# Copyright (C) 2013,2014,2015,2016 The ESPResSo project -# -# This file is part of ESPResSo. -# -# ESPResSo is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ESPResSo is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -from __future__ import print_function -import numpy as np -import espressomd -from espressomd import thermostat -from espressomd import electrostatics -from samples_common import open - -print(""" -======================================================= -= debye_hueckel.py = -======================================================= - -Program Information:""") -print(espressomd.features()) - -dev = "cpu" - -# Constants -############################################################# -N_A = 6.022e23 -pi = 3.14159265359 - -# System parameters -############################################################# - -box_l = 10 -# Molar salt concentration -mol_dens = 0.1 -# Number density of ions -num_dens = mol_dens * N_A -# Convert to MD units with lj_sig = 7.14 Angstrom -num_dens = num_dens * 3.64e-25 - -volume = box_l * box_l * box_l -n_part = int(volume * num_dens) - -# Interaction parameters (repulsive Lennard Jones) -############################################################# - -lj_eps = 1.0 -lj_sig = 1.0 -lj_cut = 1.12246 -lj_cap = 20 - -# Integration parameters -############################################################# -system = espressomd.System(box_l=[box_l]*3) -system.set_random_state_PRNG() -#system.seed = system.cell_system.get_state()['n_nodes'] * [1234] -np.random.seed(seed=system.seed) - -system.time_step = 0.01 -system.cell_system.skin = 0.4 - -thermostat.Thermostat().set_langevin(1.0, 1.0) - -# warmup integration (with capped LJ potential) -warm_steps = 100 -warm_n_times = 30 -# do the warmup until the particles have at least the distance min__dist -min_dist = 0.9 - -# integration -int_steps = 1000 -int_n_times = 10 - - -############################################################# -# Setup System # -############################################################# - -# Interaction setup -############################################################# - -system.non_bonded_inter[0, 0].lennard_jones.set_params( - epsilon=lj_eps, sigma=lj_sig, - cutoff=lj_cut, shift="auto") -system.force_cap = lj_cap - - -print("LJ-parameters:") -print(system.non_bonded_inter[0, 0].lennard_jones.get_params()) - -# Particle setup -############################################################# - -for i in range(n_part): - system.part.add(id=i, pos=np.random.random(3) * system.box_l) - -for i in range(n_part // 2): - system.part[2 * i].q = -1.0 - system.part[2 * i].type = 1 - system.part[2 * i + 1].q = 1.0 - system.part[2 * i + 1].type = 2 - -# for i in range(n_part-1): -# print("Particle {} has charge {} and is of type {}.".format(i,system.part[i].q,system.part[i].type)) - -# Activating the Debye-Hueckel interaction -# The Coulomb prefactor is set to one. Assuming the solvent is water, this -# means that lj_sig is 0.714 nm in SI units. -coulomb_prefactor = 1 -# inverse Debye length for 1:1 electrolyte in water at room temperature (nm) -dh_kappa = np.sqrt(mol_dens) / 0.304 -# convert to MD units -dh_kappa = dh_kappa / 0.714 -dh = electrostatics.CDH(prefactor=coulomb_prefactor, kappa=dh_kappa, - r_cut=5 / dh_kappa, eps_int=1, eps_ext=1, r0=0.5, r1=1, alpha=1) -system.actors.add(dh) -print(system.actors) - - -print("Simulate monovalent salt in a cubic simulation box {} at molar concentration {}." - .format(box_l, mol_dens).strip()) -print("Interactions:\n") -act_min_dist = system.analysis.min_dist() -print("Start with minimal distance {}".format(act_min_dist)) - -system.cell_system.max_num_cells = 2744 - -############################################################# -# Warmup Integration # -############################################################# - -# open Observable file -obs_file = open("pydebye_hueckel.obs", "w") -obs_file.write("# Time\tE_tot\tE_kin\tE_pot\n") -# set obs_file [open "$name$ident.obs" "w"] -# puts $obs_file "\# System: $name$ident" -# puts $obs_file "\# Time\tE_tot\tE_kin\t..." - -print(""" -Start warmup integration: -At maximum {} times {} steps -Stop if minimal distance is larger than {} -""".strip().format(warm_n_times, warm_steps, min_dist)) - -# set LJ cap -lj_cap = 20 -system.force_cap = lj_cap -print(system.non_bonded_inter[0, 0].lennard_jones) - -# Warmup Integration Loop -i = 0 -while (i < warm_n_times and act_min_dist < min_dist): - system.integrator.run(steps=warm_steps) - # Warmup criterion - act_min_dist = system.analysis.min_dist() -# print("\rrun %d at time=%f (LJ cap=%f) min dist = %f\r" % (i,system.time,lj_cap,act_min_dist), end=' ') - i += 1 - -# write observables -# puts $obs_file "{ time [setmd time] } [analyze energy]" - -# Increase LJ cap - lj_cap = lj_cap + 10 - system.force_cap = lj_cap - -# Just to see what else we may get from the c code -import pprint -pprint.pprint(system.cell_system.get_state(), width=1) -# pprint.pprint(system.part.__getstate__(), width=1) -pprint.pprint(system.__getstate__(), width=1) - -# write parameter file - -# polyBlockWrite "$name$ident.set" {box_l time_step skin} "" -set_file = open("pydebye_hueckel.set", "w") -set_file.write("box_l %s\ntime_step %s\nskin %s\n" % - (box_l, system.time_step, system.cell_system.skin)) - -############################################################# -# Integration # -############################################################# -print("\nStart integration: run %d times %d steps" % (int_n_times, int_steps)) - -# remove force capping -lj_cap = 0 -system.force_cap = lj_cap -print(system.non_bonded_inter[0, 0].lennard_jones) - -# print(initial energies) -energies = system.analysis.energy() -print(energies) - -j = 0 -for i in range(0, int_n_times): - print("run %d at time=%f " % (i, system.time)) - -# es._espressoHandle.Tcl_Eval('integrate %d' % int_steps) - system.integrator.run(steps=int_steps) - - energies = system.analysis.energy() - print(energies) - obs_file.write('{ time %s } %s\n' % (system.time, energies)) - -# write observables -# set energies [analyze energy] -# puts $obs_file "{ time [setmd time] } $energies" -# puts -nonewline "temp = [expr [lindex $energies 1 1]/(([degrees_of_freedom]/2.0)*[setmd n_part])]\r" -# flush stdout - -# write intermediate configuration -# if { $i%10==0 } { -# polyBlockWrite "$name$ident.[format %04d $j]" {time box_l} {id pos type} -# incr j -# } - -# write end configuration -end_file = open("pydebye_hueckel.end", "w") -end_file.write("{ time %f } \n { box_l %f }\n" % (system.time, box_l)) -end_file.write("{ particles {type q pos} }") -for i in range(n_part - 1): - end_file.write("%s\t%s\t%s\n" % - (system.part[i].type, system.part[i].q, system.part[i].pos)) - # id & type not working yet - -obs_file.close() -set_file.close() -end_file.close() -# es._espressoHandle.die() - -# terminate program -print("\nFinished.") diff --git a/samples/debye_hueckel.py b/samples/debye_hueckel.py index 1c518c68c86..047c0785607 100644 --- a/samples/debye_hueckel.py +++ b/samples/debye_hueckel.py @@ -167,7 +167,7 @@ import pprint pprint.pprint(system.cell_system.get_state(), width=1) # pprint.pprint(system.part.__getstate__(), width=1) -pprint.pprint(system.__getstate__(), width=1) +pprint.pprint(system.__getstate__()) # write parameter file diff --git a/samples/drude_bmimpf6.py b/samples/drude_bmimpf6.py index b05bb94933d..a76acd8c15e 100644 --- a/samples/drude_bmimpf6.py +++ b/samples/drude_bmimpf6.py @@ -2,7 +2,7 @@ import sys import time import espressomd -from espressomd.electrostatics import P3M, P3MGPU +from espressomd.electrostatics import P3M from espressomd.interactions import ThermalizedBond, HarmonicBond import os import numpy as np @@ -206,6 +206,7 @@ def combination_rule_sigma(rule, sig1, sig2): #ELECTROSTATICS if args.gpup3m: + from espressomd.electrostatics import P3MGPU print("\n-->Tune P3M GPU") p3m=P3MGPU(prefactor = coulomb_prefactor, accuracy=1e-3) else: @@ -233,12 +234,12 @@ def combination_rule_sigma(rule, sig1, sig2): drude_helpers.setup_and_add_drude_exclusion_bonds(system) if args.thole: - print("-->Adding Thole interactions") + print("-->Adding Thole interactions") drude_helpers.add_all_thole(system) if args.intra_ex: #SETUP BONDS ONCE - print("-->Adding intramolecular exclusions") + print("-->Adding intramolecular exclusions") drude_helpers.setup_intramol_exclusion_bonds(system, [types["BMIM_C1_D"], types["BMIM_C2_D"], types["BMIM_C3_D"]], [types["BMIM_C1"], types["BMIM_C2"], types["BMIM_C3"]], [charges["BMIM_C1"], charges["BMIM_C2"], charges["BMIM_C3"]]) #ADD SR EX BONDS PER MOLECULE diff --git a/samples/electrophoresis.py b/samples/electrophoresis.py index fd0da23b1f5..cfb95a442db 100644 --- a/samples/electrophoresis.py +++ b/samples/electrophoresis.py @@ -156,7 +156,7 @@ # Load checkpointed p3m class if os.path.isfile("p3m_checkpoint") and read_checkpoint == True: print("reading p3m from file") - p3m = pickle.load(open("p3m_checkpoint", "r")) + p3m = pickle.load(open("p3m_checkpoint", "rb")) else: p3m = electrostatics.P3M(prefactor=1.0, accuracy=1e-2) print("Tuning P3M") @@ -164,7 +164,7 @@ system.actors.add(p3m) # Checkpoint AFTER tuning (adding method to actors) -pickle.dump(p3m, open("p3m_checkpoint", "w"), -1) +pickle.dump(p3m, open("p3m_checkpoint", "wb"), -1) print("P3M parameter:\n") p3m_params = p3m.get_params() diff --git a/samples/lj_liquid.py b/samples/lj_liquid.py index 125f25b3cf2..a3bc5105b73 100644 --- a/samples/lj_liquid.py +++ b/samples/lj_liquid.py @@ -145,7 +145,8 @@ import pprint pprint.pprint(system.cell_system.get_state(), width=1) # pprint.pprint(system.part.__getstate__(), width=1) -pprint.pprint(system.__getstate__(), width=1) +state=system.__getstate__() +pprint.pprint(state) # write parameter file diff --git a/samples/lj_liquid_distribution.py b/samples/lj_liquid_distribution.py index 35a159faa7c..441c57e3405 100755 --- a/samples/lj_liquid_distribution.py +++ b/samples/lj_liquid_distribution.py @@ -166,7 +166,7 @@ import pprint pprint.pprint(system.cell_system.get_state(), width=1) # pprint.pprint(system.part.__getstate__(), width=1) -pprint.pprint(system.__getstate__(), width=1) +pprint.pprint(system.__getstate__()) # write parameter file diff --git a/samples/lj_liquid_structurefactor.py b/samples/lj_liquid_structurefactor.py index ea1292313bf..c27e8784996 100755 --- a/samples/lj_liquid_structurefactor.py +++ b/samples/lj_liquid_structurefactor.py @@ -157,7 +157,7 @@ # Just to see what else we may get from the c code import pprint pprint.pprint(system.cell_system.get_state(), width=1) -pprint.pprint(system.__getstate__(), width=1) +pprint.pprint(system.__getstate__()) # write parameter file diff --git a/samples/load_properties.py b/samples/load_properties.py index 23acb609cc0..c7495f3acf1 100644 --- a/samples/load_properties.py +++ b/samples/load_properties.py @@ -58,10 +58,10 @@ #system.seed = system.cell_system.get_state()['n_nodes'] * [1234] -with open("system_save", "r") as system_save: +with open("system_save", "rb") as system_save: pickle.load(system_save) -with open("nonBondedInter_save", "r") as bond_save: +with open("nonBondedInter_save", "rb") as bond_save: pickle.load(bond_save) print("Non-bonded interactions from checkpoint:") @@ -73,7 +73,7 @@ # Integration parameters ############################################################# -with open("thermostat_save", "r") as thermostat_save: +with open("thermostat_save", "rb") as thermostat_save: pickle.load(thermostat_save) @@ -101,16 +101,14 @@ print("Reset Lennard-Jones Interactions to:") print(system.non_bonded_inter[0, 0].lennard_jones.get_params()) -exit() # Import of particle properties and P3M parameters ############################################################# -with open("particle_save", "r") as particle_save: +with open("particle_save", "rb") as particle_save: pickle.load(particle_save) - act_min_dist = system.analysis.min_dist() -with open("p3m_save", "r") as p3m_save: +with open("p3m_save", "rb") as p3m_save: p3m = pickle.load(p3m_save) print(p3m.get_params()) @@ -121,8 +119,7 @@ import pprint pprint.pprint(system.cell_system.get_state(), width=1) pprint.pprint(system.thermostat.get_state(), width=1) -# pprint.pprint(system.part.__getstate__(), width=1) -pprint.pprint(system.__getstate__(), width=1) +pprint.pprint(system.__getstate__()) print("P3M parameters:\n") diff --git a/samples/observables_correlators.py b/samples/observables_correlators.py index 6d3c627bf82..6304eba6a02 100644 --- a/samples/observables_correlators.py +++ b/samples/observables_correlators.py @@ -26,7 +26,7 @@ # Calculate and return current value print(p.calculate()) # Return stored current value -print(p.value()) +print(p.calculate()) # Instance a correlator correlating the p observable with itself, calculating the mean squared displacement (msd). diff --git a/samples/p3m.py b/samples/p3m.py index e2d85835946..314d5c83013 100644 --- a/samples/p3m.py +++ b/samples/p3m.py @@ -172,7 +172,7 @@ import pprint pprint.pprint(system.cell_system.get_state(), width=1) # pprint.pprint(system.part.__getstate__(), width=1) -pprint.pprint(system.__getstate__(), width=1) +pprint.pprint(system.__getstate__()) # write parameter file diff --git a/samples/save_checkpoint.py b/samples/save_checkpoint.py index 8c8b8ad9910..f21d4c157b0 100644 --- a/samples/save_checkpoint.py +++ b/samples/save_checkpoint.py @@ -7,6 +7,9 @@ checkpoint = checkpointing.Checkpointing(checkpoint_id="mycheckpoint") +if not len(checkpoint.checkpoint_signals): + checkpoint.register_signal(signal.SIGINT) + # test for user data myvar = "some script variable" checkpoint.register("myvar") @@ -66,8 +69,6 @@ checkpoint.register("p3m") -# signal.SIGINT: signal 2, is sent when ctrl+c is pressed -checkpoint.register_signal(signal.SIGINT) checkpoint.save() diff --git a/samples/store_bonds.py b/samples/store_bonds.py index 2aa58e4832a..ca4ca93f09a 100644 --- a/samples/store_bonds.py +++ b/samples/store_bonds.py @@ -1,7 +1,6 @@ from __future__ import print_function import espressomd from espressomd.interactions import * -from samples_common import open system = espressomd.System(box_l=[10.0, 10.0, 10.0]) f = FeneBond(k=1, d_r_max=1) @@ -21,7 +20,7 @@ output_filename = "bonded_inter_save" -with open(output_filename, "w") as bonded_ia_save: +with open(output_filename, "wb") as bonded_ia_save: pickle.dump(system.bonded_inter, bonded_ia_save, -1) print("The following bonding interactions were stored in file '{}':".format( diff --git a/samples/store_properties.py b/samples/store_properties.py index 2bac816ad3b..dbf56e93c46 100644 --- a/samples/store_properties.py +++ b/samples/store_properties.py @@ -21,7 +21,6 @@ import espressomd from espressomd import electrostatics from espressomd import electrostatic_extensions -from samples_common import open print(""" ======================================================= @@ -153,7 +152,7 @@ pprint.pprint(system.cell_system.get_state(), width=1) pprint.pprint(system.thermostat.get_state(), width=1) # pprint.pprint(system.part.__getstate__(), width=1) -pprint.pprint(system.__getstate__(), width=1) +pprint.pprint(system.__getstate__()) # Pickle data @@ -163,19 +162,19 @@ except ImportError: import pickle -with open("particle_save", "w") as particle_save: +with open("particle_save", "wb") as particle_save: pickle.dump(system.part, particle_save, -1) -with open("p3m_save", "w") as p3m_save: +with open("p3m_save", "wb") as p3m_save: pickle.dump(p3m, p3m_save, -1) -with open("system_save", "w") as system_save: +with open("system_save", "wb") as system_save: pickle.dump(system, system_save, -1) -with open("thermostat_save", "w") as thermostat_save: +with open("thermostat_save", "wb") as thermostat_save: pickle.dump(system.thermostat, thermostat_save, -1) -with open("nonBondedInter_save", "w") as bond_save: +with open("nonBondedInter_save", "wb") as bond_save: pickle.dump(system.non_bonded_inter, bond_save, -1) # terminate program diff --git a/samples/visualization_bonded.py b/samples/visualization_bonded.py index 5eb1b234a44..4a07aaf328d 100644 --- a/samples/visualization_bonded.py +++ b/samples/visualization_bonded.py @@ -12,7 +12,6 @@ system = espressomd.System(box_l=[box_l]*3) system.set_random_state_PRNG() -#system.seed = system.cell_system.get_state()['n_nodes'] * [1234] np.random.seed(seed=system.seed) system.time_step = 0.01 @@ -24,7 +23,6 @@ epsilon=0, sigma=1, cutoff=2, shift="auto") system.bonded_inter[0] = HarmonicBond(k=0.5, r_0=1.0) -system.bonded_inter[1] = HarmonicBond(k=0.5, r_0=1.0) for i in range(n_part): system.part.add(id=i, pos=np.random.random(3) * system.box_l) @@ -39,15 +37,4 @@ f_max=10, gamma=50.0, max_steps=1000, max_displacement=0.2) system.minimize_energy.minimize() -def main(): - while True: - system.integrator.run(1) - visualizer.update() - - -# Start simulation in seperate thread -t = Thread(target=main) -t.daemon = True -t.start() - -visualizer.start() +visualizer.run(1) diff --git a/samples/visualization_cellsystem.py b/samples/visualization_cellsystem.py new file mode 100644 index 00000000000..6ae4cc23c36 --- /dev/null +++ b/samples/visualization_cellsystem.py @@ -0,0 +1,33 @@ +import espressomd +from espressomd.visualization_opengl import openGLLive +import numpy as np + +box = [40,30,20] +system = espressomd.System(box_l = box) +visualizer = openGLLive(system, window_size = [800,800], background_color = [0,0,0], camera_position = [20,15,80], particle_coloring = 'node', draw_nodes = True, draw_cells = True) + +system.time_step = 0.0005 +system.cell_system.set_domain_decomposition(use_verlet_lists=True) +system.cell_system.skin = 0.4 + +for i in range(100): + system.part.add(pos = box*np.random.random(3)) + +system.non_bonded_inter[0, 0].lennard_jones.set_params( + epsilon=100.0, sigma=1.0, + cutoff=3.0, shift="auto") + +energy = system.analysis.energy() +print("Before Minimization: E_total = {}".format(energy['total'])) +system.minimize_energy.init(f_max = 50, gamma = 30.0, max_steps = 10000, max_displacement = 0.001) +system.minimize_energy.minimize() +energy = system.analysis.energy() +print("After Minimization: E_total = {}".format(energy['total'])) + +print("Tune skin") +system.cell_system.tune_skin(0.1,4.0,1e-1, 1000) +print(system.cell_system.get_state()) + +system.thermostat.set_langevin(kT=1, gamma=1) + +visualizer.run(1) diff --git a/samples/visualization_charged.py b/samples/visualization_charged.py new file mode 100644 index 00000000000..7a6afd1866b --- /dev/null +++ b/samples/visualization_charged.py @@ -0,0 +1,102 @@ +import espressomd +from espressomd.visualization_opengl import openGLLive +from espressomd import electrostatics +import numpy as np + +box = [40, 40, 40] +system = espressomd.System(box_l=box) +system.cell_system.set_domain_decomposition(use_verlet_lists=True) +visualizer = openGLLive(system, background_color=[ + 1, 1, 1], drag_enabled=True, drag_force=10) + +# TIMESTEP +time_step_fs = 1.0 +system.time_step = time_step_fs * 1.0e-2 +system.cell_system.skin = 1.2 + +# TEMPERATURE +SI_temperature = 400.0 +kb_kjmol = 0.0083145 +temperature = SI_temperature * kb_kjmol + +# COULOMB PREFACTOR (elementary charge)^2 / (4*pi*epsilon_0) in Angstrom * kJ/mol +epsilon_r = 4.0 +coulomb_prefactor = 1.67101e5 * kb_kjmol / epsilon_r + +# FORCE FIELDS +species = ["Cl", "Na", "Colloid", "Solvent"] +types = {"Cl": 0, "Na": 1, "Colloid": 2, "Solvent": 3} +charges = {"Cl": -1.0, "Na": 1.0, "Colloid": -3.0, "Solvent": 0.0} +lj_sigmas = {"Cl": 3.85, "Na": 2.52, "Colloid": 10.0, "Solvent": 1.5} +lj_epsilons = {"Cl": 192.45, "Na": 17.44, + "Colloid": 100.0, "Solvent": 50.0} +lj_cuts = {"Cl": 2.0 * lj_sigmas["Cl"], "Na": 2.0 * lj_sigmas["Na"], + "Colloid": 1.5 * lj_sigmas["Colloid"], "Solvent": 2.0 * lj_sigmas["Solvent"]} +masses = {"Cl": 35.453, "Na": 22.99, "Colloid": 300, "Solvent": 18.0} + +n_ionpairs = 50 +for i in range(n_ionpairs): + for t in ["Na", "Cl"]: + system.part.add(pos=box * np.random.random(3), + q=charges[t], type=types[t], mass=masses[t]) + +n_colloids = 30 +t = "Colloid" +t_co = "Na" +for i in range(n_colloids): + system.part.add(pos=box * np.random.random(3), + q=charges[t], type=types[t], mass=masses[t]) + for i in range(int(abs(charges[t]))): + system.part.add(pos=box * np.random.random(3), + q=charges[t_co], type=types[t_co], mass=masses[t_co]) + +n_solvents = 800 +t = "Solvent" +for i in range(n_solvents): + system.part.add(pos=box * np.random.random(3), + q=charges[t], type=types[t], mass=masses[t]) + + +def combination_rule_epsilon(rule, eps1, eps2): + if rule == "Lorentz": + return (eps1 * eps2)**0.5 + else: + return ValueError("No combination rule defined") + + +def combination_rule_sigma(rule, sig1, sig2): + if rule == "Berthelot": + return (sig1 + sig2) * 0.5 + else: + return ValueError("No combination rule defined") + + +# Lennard-Jones interactions parameters +for i in range(len(species)): + for j in range(i, len(species)): + s = [species[i], species[j]] + lj_sig = combination_rule_sigma( + "Berthelot", lj_sigmas[s[0]], lj_sigmas[s[1]]) + lj_cut = combination_rule_sigma( + "Berthelot", lj_cuts[s[0]], lj_cuts[s[1]]) + lj_eps = combination_rule_epsilon( + "Lorentz", lj_epsilons[s[0]], lj_epsilons[s[1]]) + + system.non_bonded_inter[types[s[0]], types[s[1]]].lennard_jones.set_params( + epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto") + +energy = system.analysis.energy() +print("Before Minimization: E_total = {}".format(energy['total'])) +system.minimize_energy.init(f_max=1000, gamma=30.0, + max_steps=1000, max_displacement=0.01) +system.minimize_energy.minimize() +energy = system.analysis.energy() +print("After Minimization: E_total = {}".format(energy['total'])) + +print("Tune p3m") +p3m = electrostatics.P3M(prefactor=coulomb_prefactor, accuracy=1e-1) +system.actors.add(p3m) + +system.thermostat.set_langevin(kT=temperature, gamma=2.0) + +visualizer.run(1) diff --git a/samples/visualization_constraints.py b/samples/visualization_constraints.py index 69ce8f58e8a..32653774f34 100755 --- a/samples/visualization_constraints.py +++ b/samples/visualization_constraints.py @@ -18,7 +18,7 @@ rasterize_pointsize=5, camera_position=[150, 25, 25], camera_right=[0, 0, -1]) # Wall -system.constraints.add(shape=Wall(dist=20, normal=[0.1, 0.0, 1]), particle_type=0, penetrable=1) +#system.constraints.add(shape=Wall(dist=20, normal=[0.1, 0.0, 1]), particle_type=0, penetrable=1) # Sphere #system.constraints.add(shape=Sphere(center=[25, 25, 25], radius=15, direction=1), particle_type=0, penetrable=1) @@ -39,7 +39,7 @@ #system.constraints.add(shape=Stomatocyte(inner_radius=3, outer_radius=7, axis=[1.0, 0.0, 0.0], center=[25, 25, 25], layer_width=3, direction=1), particle_type=0, penetrable=1) # SimplePore -#system.constraints.add(shape=SimplePore(center=[25, 25, 25], axis=[1, 0, 0], length=15, radius=12.5, smoothing_radius=2), particle_type=0, penetrable=1) +system.constraints.add(shape=SimplePore(center=[25, 25, 25], axis=[1, 0, 0], length=15, radius=12.5, smoothing_radius=2), particle_type=0, penetrable=1) # Slitpore #system.constraints.add(shape=Slitpore(channel_width=15, lower_smoothing_radius=3, upper_smoothing_radius=3, pore_length=20, pore_mouth=30, pore_width=5), particle_type=0, penetrable=1) @@ -64,17 +64,4 @@ system.force_cap = 1000.0 - -def main(): - - while True: - system.integrator.run(1) - visualizer.update() - -# Start simulation in seperate thread -t = Thread(target=main) -t.daemon = True -t.start() - -# Start blocking visualizer -visualizer.start() +visualizer.run(1) diff --git a/samples/visualization_OpenGL.py b/samples/visualization_interactive.py similarity index 54% rename from samples/visualization_OpenGL.py rename to samples/visualization_interactive.py index 12ab2130c47..e5780611d4d 100644 --- a/samples/visualization_OpenGL.py +++ b/samples/visualization_interactive.py @@ -9,6 +9,34 @@ # Minimal interactive OpenGL visualization for ESPResSo +print("Press u/j to change temperature") + +box_l = 10.0 +system = espressomd.System(box_l=[box_l] * 3) +visualizer = openGLLive(system, drag_enabled=True, drag_force=100) + +system.time_step = 0.00001 +system.cell_system.skin = 3.0 + +N = 50 +for i in range(N): + system.part.add(pos=[0, 0, 0]) + +system.thermostat.set_langevin(kT=1.0, gamma=1.0) + +# Callback for particle positions/velocities + + +def spin(): + system.part[:].pos = [[box_l * 0.5, box_l * + (i + 1) / (N + 2), box_l * 0.5] for i in range(N)] + system.part[:].v = [ + [np.sin(10.0 * i / N) * 20, 0, np.cos(10.0 * i / N) * 20] for i in range(N)] + + +# Register timed callback +visualizer.register_callback(spin, interval=5000) + # Callbacks to control temperature temperature = 1.0 @@ -33,58 +61,14 @@ def decreaseTemp(): print("T = 0") -box_l = 10 -system = espressomd.System(box_l=[box_l]*3) -system.set_random_state_PRNG() -#system.seed = system.cell_system.get_state()['n_nodes'] * [1234] -np.random.seed(seed=system.seed) - -system.time_step = 0.00001 -system.cell_system.skin = 0.4 - -for i in range(10): - rpos = np.random.random(3) * box_l - system.part.add(id=i, pos=rpos) - -system.thermostat.set_langevin(kT=1.0, gamma=1.0) - -visualizer = openGLLive(system, drag_enabled = True) - -for key, value in visualizer.specs.items(): - print(str(key) + ":" + (30 - len(key)) * " " + str(value)) - -# Register buttons +# Register button callbacks visualizer.keyboardManager.register_button( KeyboardButtonEvent('u', KeyboardFireEvent.Hold, increaseTemp)) visualizer.keyboardManager.register_button( KeyboardButtonEvent('j', KeyboardFireEvent.Hold, decreaseTemp)) +# Set initial position +spin() -# Register additional callback to run in main thread -def muu(): - print("muu") - - -def foo(): - print("foo") - - -visualizer.register_callback(foo, interval=500) -visualizer.register_callback(muu) - - -def main(): - - while True: - system.integrator.run(1) - # Update particle information safely here - visualizer.update() - - -# Start simulation in seperate thread -t = Thread(target=main) -t.daemon = True -t.start() - -# Start blocking visualizer -visualizer.start() +# Start the visualizer and run the integration thread +visualizer.run(1) diff --git a/samples/visualization_lbboundaries.py b/samples/visualization_lbboundaries.py new file mode 100644 index 00000000000..1acd306ff49 --- /dev/null +++ b/samples/visualization_lbboundaries.py @@ -0,0 +1,30 @@ +import espressomd +import espressomd.lb +import espressomd.shapes +import espressomd.lbboundaries +from espressomd.visualization_opengl import * + +system = espressomd.System(box_l=[10.0, 10.0, 5.0]) +system.time_step = 0.01 +system.cell_system.skin = 0.4 + +lb_fluid = espressomd.lb.LBFluid(agrid=1.0, fric=1.0, dens=1.0, visc=1.0, tau=0.01, ext_force=[0, 0, 0.15]) +system.actors.add(lb_fluid) + +cylinder_shape = espressomd.shapes.Cylinder( + center = [5.0, 5.0, 5.0], + axis = [0, 0, 1], + direction = -1, + radius = 4.0, + length = 20.0) +cylinder_boundary = espressomd.lbboundaries.LBBoundary(shape=cylinder_shape) +system.lbboundaries.add(cylinder_boundary) + +visualizer = openGLLive(system, + background_color = [1,1,1], + camera_position = [5,5,25], + LB_draw_boundaries = True, + LB_draw_nodes = True, + LB_draw_node_boundaries = True) + +visualizer.run(1) diff --git a/samples/visualization_mmm2d.py b/samples/visualization_mmm2d.py index 8114714e2e2..1a6298aa092 100755 --- a/samples/visualization_mmm2d.py +++ b/samples/visualization_mmm2d.py @@ -10,9 +10,8 @@ box_l = 20 system = espressomd.System(box_l=[box_l]*3) system.set_random_state_PRNG() -#system.seed = system.cell_system.get_state()['n_nodes'] * [1234] np.random.seed(seed=system.seed) -visualizer = openGLLive(system, constraint_type_colors= [[1,1,1,1]], camera_position = [50,15,15], camera_right = [0,0,-1] ) +visualizer = openGLLive(system, constraint_type_colors= [[1,1,1]], camera_position = [50,15,15], camera_right = [0,0,-1] ) system.time_step = 0.02 system.cell_system.skin = 0.4 @@ -44,17 +43,4 @@ mmm2d = electrostatics.MMM2D(prefactor = 10.0, maxPWerror = 1e-3, const_pot = 1, pot_diff = 50.0) system.actors.add(mmm2d) -def main(): - - while True: - system.integrator.run(1) - visualizer.update() - - -# Start simulation in seperate thread -t = Thread(target=main) -t.daemon = True -t.start() - -# Start blocking visualizer -visualizer.start() +visualizer.run(1) diff --git a/samples/visualization_npt.py b/samples/visualization_npt.py index f31644f5026..e0448750973 100644 --- a/samples/visualization_npt.py +++ b/samples/visualization_npt.py @@ -1,6 +1,7 @@ from __future__ import print_function import espressomd from espressomd import thermostat +from espressomd.interactions import HarmonicBond from espressomd.visualization_opengl import * import numpy as np from threading import Thread @@ -8,41 +9,52 @@ box_l = 10 system = espressomd.System(box_l=[box_l]*3) system.set_random_state_PRNG() -#system.seed = system.cell_system.get_state()['n_nodes'] * [1234] np.random.seed(seed=system.seed) -visualizer = openGLLive(system, background_color=[1, 1, 1]) +visualizer = openGLLive(system, background_color=[1, 1, 1], bond_type_radius = [0.2]) -system.time_step = 0.005 -system.cell_system.skin = 0.4 +system.time_step = 0.0005 +system.cell_system.skin = 0.1 +#system.cell_system.min_num_cells = 1 system.box_l = [box_l, box_l, box_l] system.non_bonded_inter[0, 0].lennard_jones.set_params( - epsilon=1, sigma=1, - cutoff=2**(1. / 6.), shift="auto") + epsilon=2, sigma=1, + cutoff=3, shift="auto") -for i in range(100): +system.bonded_inter[0] = HarmonicBond(k=5.0, r_0=1.0) + +n_part = 200 +for i in range(n_part): system.part.add(id=i, pos=np.random.random(3) * system.box_l) +for i in range(0,n_part - 1,2): + system.part[i].add_bond((system.bonded_inter[0], system.part[i + 1].id)) + print("E before minimization:", system.analysis.energy()["total"]) system.minimize_energy.init(f_max=0.0, gamma=30.0, max_steps=10000, max_displacement=0.1) system.minimize_energy.minimize() print("E after minimization:", system.analysis.energy()["total"]) -system.thermostat.set_npt(kT=1.0, gamma0=1.0, gammav=0.1) -system.integrator.set_isotropic_npt(ext_pressure=1.0, piston=1.0) +system.thermostat.set_npt(kT=2.0, gamma0=1.0, gammav=0.01) +system.integrator.set_isotropic_npt(ext_pressure=1.0, piston=0.01) def main(): p = 1.0 b = system.box_l + cnt = 0 while True: system.integrator.run(1) - print("Pressure:", system.analysis.pressure() - ['total'], "Box:", system.box_l) + if cnt > 1000: + print("Pressure:", system.analysis.pressure() + ['total'], "Box:", system.box_l) + cnt = 0 + visualizer.update() + cnt += 1 # Start simulation in seperate thread diff --git a/samples/visualization_poisseuille.py b/samples/visualization_poisseuille.py index 873558d1c40..9211a940d57 100644 --- a/samples/visualization_poisseuille.py +++ b/samples/visualization_poisseuille.py @@ -9,14 +9,14 @@ box_l = 16 system = System(box_l = [box_l] * 3) system.set_random_state_PRNG() -#system.seed = system.cell_system.get_state()['n_nodes'] * [1234] np.random.seed(seed=system.seed) system.time_step = 0.01 system.cell_system.skin = 0.2 visualizer = openGLLive(system, - LB = True, + LB_draw_boundaries = True, + LB_draw_velocity_plane = True, LB_plane_dist = 8, LB_plane_axis = 1, LB_vel_scale = 1e2, @@ -25,7 +25,7 @@ velocity_arrows=True, velocity_arrows_type_scale=[20.], velocity_arrows_type_radii = [0.1], - velocity_arrows_type_colors=[[0,1,0,0.5]] ) + velocity_arrows_type_colors=[[0,1,0]] ) lbf = lb.LBFluid(agrid=1.0, fric = 1.0, dens=1.0, visc=1.0, tau=0.1, ext_force=[0, 0.003, 0]) system.actors.add(lbf) @@ -42,14 +42,4 @@ for wall in walls: system.lbboundaries.add(wall) -def main(): - while True: - system.integrator.run(1) - visualizer.update() - -# Start simulation in seperate thread -t = Thread(target=main) -t.daemon = True -t.start() - -visualizer.start() +visualizer.run(1) diff --git a/src/core/communication.cpp b/src/core/communication.cpp old mode 100755 new mode 100644 index 32b4df8c04a..d943759e0be --- a/src/core/communication.cpp +++ b/src/core/communication.cpp @@ -50,6 +50,7 @@ #include "initialize.hpp" #include "integrate.hpp" #include "interaction_data.hpp" +#include "io/mpiio/mpiio.hpp" #include "lb.hpp" #include "lbboundaries.hpp" #include "lbboundaries/LBBoundary.hpp" @@ -65,7 +66,6 @@ #include "mmm2d.hpp" #include "molforces.hpp" #include "morse.hpp" -#include "io/mpiio/mpiio.hpp" #include "npt.hpp" #include "overlap.hpp" #include "p3m-dipolar.hpp" @@ -73,13 +73,13 @@ #include "partCfg_global.hpp" #include "particle_data.hpp" #include "pressure.hpp" -#include "reaction.hpp" #include "reaction_field.hpp" #include "rotation.hpp" #include "scafacos.hpp" #include "statistics.hpp" #include "statistics_chain.hpp" #include "statistics_fluid.hpp" +#include "swimmer_reaction.hpp" #include "tab.hpp" #include "topology.hpp" #include "virtual_sites.hpp" @@ -103,7 +103,7 @@ std::unique_ptr mpi_env; boost::mpi::communicator comm_cart; namespace Communication { - std::unique_ptr m_callbacks; +std::unique_ptr m_callbacks; /* We use a singelton callback class for now. */ MpiCallbacks &mpiCallbacks() { @@ -172,6 +172,7 @@ static int terminated = 0; CB(mpi_iccp3m_init_slave) \ CB(mpi_send_rotational_inertia_slave) \ CB(mpi_send_affinity_slave) \ + CB(mpi_rotate_particle_slave) \ CB(mpi_send_out_direction_slave) \ CB(mpi_send_mu_E_slave) \ CB(mpi_bcast_max_mu_slave) \ @@ -267,7 +268,8 @@ void mpi_init() { #else int argc{}; char **argv{}; - Communication::mpi_env = Utils::make_unique(argc, argv); + Communication::mpi_env = + Utils::make_unique(argc, argv); #endif MPI_Comm_size(MPI_COMM_WORLD, &n_nodes); @@ -638,6 +640,36 @@ void mpi_send_rotational_inertia_slave(int pnode, int part) { #endif } +void mpi_rotate_particle(int pnode, int part, double axis[3], double angle) { +#ifdef ROTATION + mpi_call(mpi_rotate_particle_slave, pnode, part); + + if (pnode == this_node) { + Particle *p = local_particles[part]; + local_rotate_particle(p, axis, angle); + } else { + MPI_Send(axis, 3, MPI_DOUBLE, pnode, SOME_TAG, comm_cart); + MPI_Send(&angle, 1, MPI_DOUBLE, pnode, SOME_TAG, comm_cart); + } + + on_particle_change(); +#endif +} + +void mpi_rotate_particle_slave(int pnode, int part) { +#ifdef ROTATION + if (pnode == this_node) { + Particle *p = local_particles[part]; + double axis[3], angle; + MPI_Recv(axis, 3, MPI_DOUBLE, 0, SOME_TAG, comm_cart, MPI_STATUS_IGNORE); + MPI_Recv(&angle, 1, MPI_DOUBLE, 0, SOME_TAG, comm_cart, MPI_STATUS_IGNORE); + local_rotate_particle(p, axis, angle); + } + + on_particle_change(); +#endif +} + /********************* REQ_SET_BOND_SITE ********/ void mpi_send_affinity_slave(int pnode, int part) { @@ -963,7 +995,7 @@ void mpi_send_vs_quat(int pnode, int part, double *vs_quat) { mpi_call(mpi_send_vs_quat_slave, pnode, part); if (pnode == this_node) { Particle *p = local_particles[part]; - for (int i=0; i<4; ++i) { + for (int i = 0; i < 4; ++i) { p->p.vs_quat[i] = vs_quat[i]; } } else { @@ -977,8 +1009,8 @@ void mpi_send_vs_quat_slave(int pnode, int part) { #ifdef VIRTUAL_SITES_RELATIVE if (pnode == this_node) { Particle *p = local_particles[part]; - MPI_Recv(p->p.vs_quat, 4, MPI_DOUBLE, 0, SOME_TAG, - comm_cart, MPI_STATUS_IGNORE); + MPI_Recv(p->p.vs_quat, 4, MPI_DOUBLE, 0, SOME_TAG, comm_cart, + MPI_STATUS_IGNORE); } on_particle_change(); @@ -1044,13 +1076,13 @@ void mpi_send_rotation_slave(int pnode, int part) { if (pnode == this_node) { Particle *p = local_particles[part]; MPI_Status status; - MPI_Recv(&p->p.rotation, 1, MPI_SHORT, 0, SOME_TAG, MPI_COMM_WORLD, &status); + MPI_Recv(&p->p.rotation, 1, MPI_SHORT, 0, SOME_TAG, MPI_COMM_WORLD, + &status); } on_particle_change(); } - /********************* REQ_SET_BOND ********/ int mpi_send_bond(int pnode, int part, int *bond, int _delete) { @@ -1148,7 +1180,7 @@ int mpi_integrate(int n_steps, int reuse_forces) { mpi_call(mpi_integrate_slave, n_steps, reuse_forces); integrate_vv(n_steps, reuse_forces); COMM_TRACE( - fprintf(stderr, "%d: integration task %d done.\n", this_node, n_steps)); + fprintf(stderr, "%d: integration task %d done.\n", this_node, n_steps)); return mpi_check_runtime_errors(); } @@ -2384,17 +2416,17 @@ void mpi_galilei_transform_slave(int pnode, int i) { on_particle_change(); } -/******************** REQ_CATALYTIC_REACTIONS ********************/ +/******************** REQ_SWIMMER_REACTIONS ********************/ void mpi_setup_reaction() { -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS mpi_call(mpi_setup_reaction_slave, -1, 0); local_setup_reaction(); #endif } void mpi_setup_reaction_slave(int pnode, int i) { -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS local_setup_reaction(); #endif } diff --git a/src/core/communication.hpp b/src/core/communication.hpp index 3ab0e081847..4b9ea456d66 100755 --- a/src/core/communication.hpp +++ b/src/core/communication.hpp @@ -223,6 +223,16 @@ void mpi_send_mu_E(int node, int part, double mu_E[3]); */ void mpi_send_rotational_inertia(int node, int part, double rinertia[3]); #endif +#ifdef ROTATION +/** Mpi call for rotating a single particle + Also calls \ref on_particle_change. + \param part the particle. + \param node the node it is attached to. + \param axis rotation axis + \param angle rotation angle +*/ +void mpi_rotate_particle(int node, int part, double axis[3],double angle); +#endif #ifdef AFFINITY /** Issue REQ_SET_AFFINITY: send particle affinity. @@ -608,7 +618,7 @@ void mpi_system_CMS_velocity(); void mpi_galilei_transform(); void mpi_observable_lb_radial_velocity_profile(); -/** Issue REQ_CATALYTIC_REACTIONS: notify the system of changes to the reaction +/** Issue REQ_SWIMMER_REACTIONS: notify the system of changes to the reaction * parameters */ void mpi_setup_reaction(); diff --git a/src/core/constraints/ShapeBasedConstraint.cpp b/src/core/constraints/ShapeBasedConstraint.cpp index ce187e5e2c2..52e7a68c16e 100644 --- a/src/core/constraints/ShapeBasedConstraint.cpp +++ b/src/core/constraints/ShapeBasedConstraint.cpp @@ -7,41 +7,39 @@ #include "forces_inline.hpp" #include "interaction_data.hpp" - namespace Constraints { - Vector3d ShapeBasedConstraint::total_force() const { - Vector3d total_force; - boost::mpi::all_reduce(comm_cart, m_local_force, total_force, - std::plus()); + Vector3d total_force; + boost::mpi::all_reduce(comm_cart, m_local_force, total_force, + std::plus()); - return total_force; + return total_force; } - double ShapeBasedConstraint::min_dist() { double global_mindist = std::numeric_limits::infinity(); auto parts = local_cells.particles(); auto const local_mindist = std::accumulate( - parts.begin(), parts.end(), std::numeric_limits::infinity(), - [this](double min, Particle const& p) { - IA_parameters *ia_params; - ia_params = get_ia_param(p.p.type, m_type); - if (checkIfInteraction(ia_params)) { - double vec[3], dist; - m_shape->calculate_dist(folded_position(p).data(), &dist, vec); - return std::min(min, dist); - } - else return min; - }); - boost::mpi::reduce(comm_cart, local_mindist, global_mindist, boost::mpi::minimum(), 0); + parts.begin(), parts.end(), std::numeric_limits::infinity(), + [this](double min, Particle const &p) { + IA_parameters *ia_params; + ia_params = get_ia_param(p.p.type, part_rep.p.type); + if (checkIfInteraction(ia_params)) { + double vec[3], dist; + m_shape->calculate_dist(folded_position(p).data(), &dist, vec); + return std::min(min, dist); + } else + return min; + }); + boost::mpi::reduce(comm_cart, local_mindist, global_mindist, + boost::mpi::minimum(), 0); return global_mindist; } - -void ShapeBasedConstraint::reflect_particle(Particle *p, const double *distance_vector, - const double *folded_pos) const { +void ShapeBasedConstraint::reflect_particle(Particle *p, + const double *distance_vector, + const double *folded_pos) const { double vec[3]; double norm; @@ -80,8 +78,6 @@ void ShapeBasedConstraint::reflect_particle(Particle *p, const double *distance_ void ShapeBasedConstraint::add_force(Particle *p, double *folded_pos) { double dist, vec[3], force[3], torque1[3], torque2[3]; - Particle part_rep; - part_rep.p.type = m_type; IA_parameters *ia_params = get_ia_param(p->p.type, part_rep.p.type); @@ -97,18 +93,24 @@ void ShapeBasedConstraint::add_force(Particle *p, double *folded_pos) { m_shape->calculate_dist(folded_pos, &dist, vec); if (dist > 0) { - calc_non_bonded_pair_force(p, &part_rep, ia_params, vec, dist, - dist * dist, force, torque1, torque2); -#ifdef TUNABLE_SLIP - if (tunable_slip) { - add_tunable_slip_pair_force(p1, &constraints[n].part_rep, ia_params, - vec, dist, force); + auto const dist2 = dist * dist; + calc_non_bonded_pair_force(p, &part_rep, ia_params, vec, dist, dist2, + force, torque1, torque2); +#ifdef DPD + if (thermo_switch & THERMO_DPD) { + add_dpd_pair_force(p, &part_rep, ia_params, vec, dist, dist2); } #endif } else if (m_penetrable && (dist <= 0)) { if ((!m_only_positive) && (dist < 0)) { + auto const dist2 = dist * dist; calc_non_bonded_pair_force(p, &part_rep, ia_params, vec, -1.0 * dist, dist * dist, force, torque1, torque2); +#ifdef DPD + if (thermo_switch & THERMO_DPD) { + add_dpd_pair_force(p, &part_rep, ia_params, vec, dist, dist2); + } +#endif } } else { if (m_reflection_type != ReflectionType::NONE) { @@ -131,12 +133,10 @@ void ShapeBasedConstraint::add_force(Particle *p, double *folded_pos) { } void ShapeBasedConstraint::add_energy(Particle *p, double *folded_pos, - Observable_stat &energy) const { + Observable_stat &energy) const { double dist, vec[3]; IA_parameters *ia_params; double nonbonded_en = 0.0; - Particle part_rep; - part_rep.p.type = m_type; ia_params = get_ia_param(p->p.type, part_rep.p.type); diff --git a/src/core/constraints/ShapeBasedConstraint.hpp b/src/core/constraints/ShapeBasedConstraint.hpp index 904092f5801..9cf06f78e24 100644 --- a/src/core/constraints/ShapeBasedConstraint.hpp +++ b/src/core/constraints/ShapeBasedConstraint.hpp @@ -9,6 +9,8 @@ #include "shapes/NoWhere.hpp" #include "shapes/Shape.hpp" +extern double time_step; + namespace Constraints { class ShapeBasedConstraint : public Constraint { @@ -18,18 +20,18 @@ class ShapeBasedConstraint : public Constraint { ShapeBasedConstraint() : m_shape(std::make_shared()), m_reflection_type(ReflectionType::NONE), m_penetrable(false), - m_only_positive(false), m_tuneable_slip(0), m_type(-1) { + m_only_positive(false) { ShapeBasedConstraint::reset_force(); } virtual void add_energy(Particle *p, double *folded_pos, - Observable_stat &energy) const override; + Observable_stat &energy) const override; virtual void add_force(Particle *p, double *folded_pos) override; /* finds the minimum distance to all particles */ double min_dist(); - + /* Calculate distance from the constraint */ int calc_dist(const double *pos, double *dist, double *vec) const { return m_shape->calculate_dist(pos, dist, vec); @@ -46,16 +48,25 @@ class ShapeBasedConstraint : public Constraint { void reset_force() override { m_local_force = Vector3d{0, 0, 0}; } int &only_positive() { return m_only_positive; } int &penetrable() { return m_penetrable; } - int &type() { return m_type; } - + int &type() { return part_rep.p.type; } + Vector3d velocity() const { return Vector3d{part_rep.m.v} / time_step; } + void set_type(const int &type) { - m_type = type; - make_particle_type_exist_local(m_type); + part_rep.p.type = type; + make_particle_type_exist_local(type); + } + + void set_velocity(const Vector3d v) { + for (int i = 0; i < 3; i++) { + part_rep.m.v[i] = time_step * v[i]; + } } Vector3d total_force() const; private: + Particle part_rep; + /** Private methods */ void reflect_particle(Particle *p, const double *distance_vector, const double *folded_pos) const; @@ -66,8 +77,6 @@ class ShapeBasedConstraint : public Constraint { ReflectionType m_reflection_type; int m_penetrable; int m_only_positive; - int m_tuneable_slip; - int m_type; Vector3d m_local_force; }; diff --git a/src/core/ghosts.cpp b/src/core/ghosts.cpp index b4121906472..8386337d9bc 100755 --- a/src/core/ghosts.cpp +++ b/src/core/ghosts.cpp @@ -56,8 +56,6 @@ static char *r_buffer = nullptr; std::vector r_bondbuffer; -static MPI_Op MPI_FORCES_SUM; - /** whether the ghosts should also have velocity information, e. g. for DPD or RATTLE. You need this whenever you need the relative velocity of two particles. NO CHANGES OF THIS VALUE OUTSIDE OF \ref on_ghost_flags_change !!!! @@ -142,9 +140,9 @@ int calc_transmit_size(GhostCommunication *gc, int data_parts) return n_buffer_new; } -void prepare_send_buffer(GhostCommunication *gc, int data_parts) -{ - GHOST_TRACE(fprintf(stderr, "%d: prepare sending to/bcast from %d\n", this_node, gc->node)); +void prepare_send_buffer(GhostCommunication *gc, int data_parts) { + GHOST_TRACE(fprintf(stderr, "%d: prepare sending to/bcast from %d\n", + this_node, gc->node)); /* reallocate send buffer */ n_s_buffer = calc_transmit_size(gc, data_parts); @@ -159,84 +157,84 @@ void prepare_send_buffer(GhostCommunication *gc, int data_parts) /* put in data */ char *insert = s_buffer; for (int pl = 0; pl < gc->n_part_lists; pl++) { - int np = gc->part_lists[pl]->n; + int np = gc->part_lists[pl]->n; if (data_parts & GHOSTTRANS_PARTNUM) { *(int *)insert = np; insert += sizeof(int); - GHOST_TRACE(fprintf(stderr, "%d: %d particles assigned\n", - this_node, np)); - } - else { + GHOST_TRACE( + fprintf(stderr, "%d: %d particles assigned\n", this_node, np)); + } else { Particle *part = gc->part_lists[pl]->part; for (int p = 0; p < np; p++) { - Particle *pt = &part[p]; - if (data_parts & GHOSTTRANS_PROPRTS) { - memmove(insert, &pt->p, sizeof(ParticleProperties)); - insert += sizeof(ParticleProperties); + Particle *pt = &part[p]; + if (data_parts & GHOSTTRANS_PROPRTS) { + memmove(insert, &pt->p, sizeof(ParticleProperties)); + insert += sizeof(ParticleProperties); #ifdef GHOSTS_HAVE_BONDS *(int *)insert = pt->bl.n; - insert += sizeof(int); + insert += sizeof(int); if (pt->bl.n) { - s_bondbuffer.insert(s_bondbuffer.end(), pt->bl.e, pt->bl.e + pt->bl.n); + s_bondbuffer.insert(s_bondbuffer.end(), pt->bl.e, + pt->bl.e + pt->bl.n); } #ifdef EXCLUSIONS *(int *)insert = pt->el.n; - insert += sizeof(int); + insert += sizeof(int); if (pt->el.n) { - s_bondbuffer.insert(s_bondbuffer.end(), pt->el.e, pt->el.e + pt->el.n); + s_bondbuffer.insert(s_bondbuffer.end(), pt->el.e, + pt->el.e + pt->el.n); } #endif #endif - } - if (data_parts & GHOSTTRANS_POSSHFTD) { - /* ok, this is not nice, but perhaps fast */ - ParticlePosition *pp = (ParticlePosition *)insert; - int i; - memmove(pp, &pt->r, sizeof(ParticlePosition)); - for (i = 0; i < 3; i++) - pp->p[i] += gc->shift[i]; - /* No special wrapping for Lees-Edwards here: - * LE wrap-on-receive instead, for convenience in - * mapping to local cell geometry. */ - insert += sizeof(ParticlePosition); - } - else if (data_parts & GHOSTTRANS_POSITION) { - memmove(insert, &pt->r, sizeof(ParticlePosition)); - insert += sizeof(ParticlePosition); - } - if (data_parts & GHOSTTRANS_MOMENTUM) { - memmove(insert, &pt->m, sizeof(ParticleMomentum)); - insert += sizeof(ParticleMomentum); - } - if (data_parts & GHOSTTRANS_FORCE) { - memmove(insert, &pt->f, sizeof(ParticleForce)); - insert += sizeof(ParticleForce); - } + } + if (data_parts & GHOSTTRANS_POSSHFTD) { + /* ok, this is not nice, but perhaps fast */ + ParticlePosition *pp = (ParticlePosition *)insert; + int i; + memmove(pp, &pt->r, sizeof(ParticlePosition)); + for (i = 0; i < 3; i++) + pp->p[i] += gc->shift[i]; + /* No special wrapping for Lees-Edwards here: + * LE wrap-on-receive instead, for convenience in + * mapping to local cell geometry. */ + insert += sizeof(ParticlePosition); + } else if (data_parts & GHOSTTRANS_POSITION) { + memmove(insert, &pt->r, sizeof(ParticlePosition)); + insert += sizeof(ParticlePosition); + } + if (data_parts & GHOSTTRANS_MOMENTUM) { + memmove(insert, &pt->m, sizeof(ParticleMomentum)); + insert += sizeof(ParticleMomentum); + } + if (data_parts & GHOSTTRANS_FORCE) { + memmove(insert, &pt->f, sizeof(ParticleForce)); + insert += sizeof(ParticleForce); + } #ifdef LB - if (data_parts & GHOSTTRANS_COUPLING) { - memmove(insert, &pt->lc, sizeof(ParticleLatticeCoupling)); - insert += sizeof(ParticleLatticeCoupling); - } + if (data_parts & GHOSTTRANS_COUPLING) { + memmove(insert, &pt->lc, sizeof(ParticleLatticeCoupling)); + insert += sizeof(ParticleLatticeCoupling); + } #endif #ifdef ENGINE - if (data_parts & GHOSTTRANS_SWIMMING) { + if (data_parts & GHOSTTRANS_SWIMMING) { memmove(insert, &pt->swim, sizeof(ParticleParametersSwimming)); - insert += sizeof(ParticleParametersSwimming); + insert += sizeof(ParticleParametersSwimming); } #endif } } } if (data_parts & GHOSTTRANS_PROPRTS) { - GHOST_TRACE(fprintf(stderr, "%d: bond buffer size is %ld\n", - this_node, s_bondbuffer.size())); + GHOST_TRACE(fprintf(stderr, "%d: bond buffer size is %ld\n", this_node, + s_bondbuffer.size())); *(int *)insert = int(s_bondbuffer.size()); insert += sizeof(int); } if (insert - s_buffer != n_s_buffer) { fprintf(stderr, "%d: INTERNAL ERROR: send buffer size %d " - "differs from what I put in (%ld)\n", + "differs from what I put in (%ld)\n", this_node, n_s_buffer, insert - s_buffer); errexit(); } @@ -643,15 +641,21 @@ void ghost_communicator(GhostCommunicator *gc) } } break; - case GHOST_RDCE: - GHOST_TRACE(fprintf(stderr, "%d: ghost_comm reduce to %d (%d bytes)\n", this_node, node, n_s_buffer)); - if (node == this_node) - MPI_Reduce(s_buffer, r_buffer, n_s_buffer, MPI_BYTE, MPI_FORCES_SUM, node, comm_cart); - else - MPI_Reduce(s_buffer, nullptr, n_s_buffer, MPI_BYTE, MPI_FORCES_SUM, node, comm_cart); - break; + case GHOST_RDCE: { + GHOST_TRACE(fprintf(stderr, "%d: ghost_comm reduce to %d (%d bytes)\n", + this_node, node, n_s_buffer)); + + if (node == this_node) + MPI_Reduce(reinterpret_cast(s_buffer), + reinterpret_cast(r_buffer), + n_s_buffer / sizeof(double), MPI_DOUBLE, MPI_SUM, node, + comm_cart); + else + MPI_Reduce(reinterpret_cast(s_buffer), nullptr, + n_s_buffer / sizeof(double), MPI_DOUBLE, MPI_SUM, node, + comm_cart); + } break; } - //GHOST_TRACE(MPI_Barrier(comm_cart)); GHOST_TRACE(fprintf(stderr, "%d: ghost_comm done\n", this_node)); /* recv op; write back data directly, if no PSTSTORE delay is requested. */ @@ -699,11 +703,6 @@ void ghost_communicator(GhostCommunicator *gc) } } -void ghost_init() -{ - MPI_Op_create(reduce_forces_sum, 1, &MPI_FORCES_SUM); -} - /** Go through \ref ghost_cells and remove the ghost entries from \ref local_particles. Part of \ref dd_exchange_and_sort_particles.*/ void invalidate_ghosts() diff --git a/src/core/ghosts.hpp b/src/core/ghosts.hpp index 134b4f555d9..eca1829304b 100755 --- a/src/core/ghosts.hpp +++ b/src/core/ghosts.hpp @@ -190,9 +190,6 @@ void prepare_comm(GhostCommunicator *comm, int data_parts, int num); /** Free a communicator. */ void free_comm(GhostCommunicator *comm); -/** Initialize ghosts. */ -void ghost_init(); - /** do a ghost communication */ void ghost_communicator(GhostCommunicator *gc); diff --git a/src/core/initialize.cpp b/src/core/initialize.cpp index af1273f71a0..5aed9e15e59 100755 --- a/src/core/initialize.cpp +++ b/src/core/initialize.cpp @@ -58,7 +58,7 @@ #include "pressure.hpp" #include "random.hpp" #include "rattle.hpp" -#include "reaction.hpp" +#include "swimmer_reaction.hpp" #include "reaction_ensemble.hpp" #include "reaction_field.hpp" #include "rotation.hpp" @@ -98,8 +98,6 @@ void on_program_start() { /* initially go for domain decomposition */ topology_init(CELL_STRUCTURE_DOMDEC, &local_cells); - ghost_init(); - #ifdef P3M p3m_pre_init(); #endif @@ -117,7 +115,7 @@ void on_program_start() { lb_pre_init(); #endif -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS reaction.eq_rate = 0.0; reaction.sing_mult = 0; reaction.swap = 0; @@ -148,7 +146,7 @@ void on_integration_start() { integrator_npt_sanity_checks(); #endif interactions_sanity_checks(); -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS reactions_sanity_checks(); #endif #ifdef LB diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 5eea198d2f1..055e41477b7 100755 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -51,7 +51,7 @@ #include "particle_data.hpp" #include "pressure.hpp" #include "rattle.hpp" -#include "reaction.hpp" +#include "swimmer_reaction.hpp" #include "rotation.hpp" #include "thermostat.hpp" #include "utils.hpp" @@ -276,7 +276,9 @@ void integrate_vv(int n_steps, int reuse_forces) { thermo_cool_down(); #ifdef COLLISION_DETECTION - handle_collisions(); + if (integ_switch != INTEG_METHOD_STEEPEST_DESCENT) { + handle_collisions(); + } #endif } @@ -373,7 +375,7 @@ void integrate_vv(int n_steps, int reuse_forces) { #endif #endif -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS integrate_reaction(); #endif @@ -401,6 +403,8 @@ void integrate_vv(int n_steps, int reuse_forces) { #endif // progagate one-step functionalities + +if (integ_switch != INTEG_METHOD_STEEPEST_DESCENT) { #ifdef LB if (lattice_switch & LATTICE_LB) lattice_boltzmann_update(); @@ -424,6 +428,7 @@ void integrate_vv(int n_steps, int reuse_forces) { } #endif // LB_GPU + // IMMERSED_BOUNDARY #ifdef IMMERSED_BOUNDARY @@ -445,6 +450,7 @@ void integrate_vv(int n_steps, int reuse_forces) { ghost_communicator(&cell_structure.update_ghost_pos_comm); #endif // IMMERSED_BOUNDARY +} #ifdef ELECTROSTATICS if (coulomb.method == COULOMB_MAGGS) { @@ -467,10 +473,10 @@ void integrate_vv(int n_steps, int reuse_forces) { if (integ_switch != INTEG_METHOD_STEEPEST_DESCENT) { /* Propagate time: t = t+dt */ sim_time += time_step; - } #ifdef COLLISION_DETECTION handle_collisions(); #endif + } if (check_runtime_errors()) break; } diff --git a/src/core/interaction_data.cpp b/src/core/interaction_data.cpp index f4ecd9baa10..7b1cca4c1bd 100755 --- a/src/core/interaction_data.cpp +++ b/src/core/interaction_data.cpp @@ -69,11 +69,18 @@ #include "steppot.hpp" #include "tab.hpp" #include "thermostat.hpp" -#include "tunable_slip.hpp" #include "umbrella.hpp" #include "utils.hpp" +#include "utils/serialization/IA_parameters.hpp" #include #include +#include +#include +#include +#include +#include +#include + /**************************************** * variables @@ -142,6 +149,22 @@ IA_parameters *get_ia_param_safe(int i, int j) { return get_ia_param(i, j); } +std::string ia_params_get_state() { + std::stringstream out; + boost::archive::binary_oarchive oa(out); + oa << ia_params; + return out.str(); +} + +void ia_params_set_state(std::string const &state) { + namespace iostreams = boost::iostreams; + iostreams::array_source src(state.data(), state.size()); + iostreams::stream ss(src); + boost::archive::binary_iarchive ia(ss); + ia_params.clear(); + ia >> ia_params; +} + static void recalc_maximal_cutoff_bonded() { int i; double max_cut_tmp; @@ -424,12 +447,7 @@ static void recalc_maximal_cutoff_nonbonded() { max_cut_current = std::max(max_cut_current, data->TAB.cutoff()); #endif -#ifdef TUNABLE_SLIP - if (max_cut_current < data->TUNABLE_SLIP_r_cut) - max_cut_current = data->TUNABLE_SLIP_r_cut; -#endif - -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS if (max_cut_current < data->REACTION_range) max_cut_current = data->REACTION_range; #endif diff --git a/src/core/interaction_data.hpp b/src/core/interaction_data.hpp index 367d795955f..ee99f4d1a92 100755 --- a/src/core/interaction_data.hpp +++ b/src/core/interaction_data.hpp @@ -448,17 +448,7 @@ struct IA_parameters { double THOLE_q1q2; #endif -#ifdef TUNABLE_SLIP - double TUNABLE_SLIP_temp = 0.0; - double TUNABLE_SLIP_gamma = 0.0; - double TUNABLE_SLIP_r_cut = INACTIVE_CUTOFF; - double TUNABLE_SLIP_time = 0.0; - double TUNABLE_SLIP_vx = 0.0; - double TUNABLE_SLIP_vy = 0.0; - double TUNABLE_SLIP_vz = 0.0; -#endif - -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS double REACTION_range = INACTIVE_CUTOFF; #endif @@ -910,6 +900,14 @@ inline IA_parameters *get_ia_param(int i, int j) { yet present particle types*/ IA_parameters *get_ia_param_safe(int i, int j); +/** @brief Get the state of all non bonded interactions. + */ +std::string ia_params_get_state(); + +/** @brief Set the state of all non bonded interactions. + */ +void ia_params_set_state(std::string const&); + bool is_new_particle_type(int type); /** Makes sure that ia_params is large enough to cover interactions for this particle type. The interactions are initialized with values diff --git a/src/core/minimize_energy.cpp b/src/core/minimize_energy.cpp index f62a96fae7a..7f17e7786be 100644 --- a/src/core/minimize_energy.cpp +++ b/src/core/minimize_energy.cpp @@ -113,7 +113,7 @@ bool steepest_descent_step(void) { l = sgn(l) * params->max_displacement; // Rotate the particle around axis dq by amount l - rotate_particle(&(p), dq, l); + local_rotate_particle(&(p), dq, l); } #endif diff --git a/src/core/p3m-dipolar.hpp b/src/core/p3m-dipolar.hpp index f6477d25ee4..7a2cfd111cc 100755 --- a/src/core/p3m-dipolar.hpp +++ b/src/core/p3m-dipolar.hpp @@ -165,6 +165,8 @@ void dp3m_shrink_wrap_dipole_grid(int n_dipoles); If NPT is compiled in, it returns the energy, which is needed for NPT. */ inline double dp3m_add_pair_force(Particle *p1, Particle *p2, double *d, double dist2, double dist, double force[3]) { + if ((p1->p.dipm==0.) || (p2->p.dipm==0.)) return 0.; + int j; #ifdef NPT double fac1; diff --git a/src/core/particle_data.cpp b/src/core/particle_data.cpp index 23d4f426dc1..046d7081ddd 100644 --- a/src/core/particle_data.cpp +++ b/src/core/particle_data.cpp @@ -521,6 +521,14 @@ int set_particle_rotation(int part, int rot) { return ES_OK; } #endif +#ifdef ROTATION +int rotate_particle(int part, double axis[3], double angle) { + auto const pnode = get_particle_node(part); + + mpi_rotate_particle(pnode, part, axis, angle); + return ES_OK; +} +#endif #ifdef AFFINITY int set_particle_affinity(int part, double bond_site[3]) { @@ -810,9 +818,10 @@ int remove_particle(int p_id) { auto const pnode = get_particle_node(p_id); particle_node[p_id] = -1; - mpi_remove_particle(pnode, p_id); + particle_node.erase(p_id); + if (p_id == max_seen_particle) { max_seen_particle--; mpi_bcast_parameter(FIELD_MAXPART); @@ -855,7 +864,6 @@ void local_remove_particle(int part) { /* update the local_particles array for the moved particle */ local_particles[p->p.identity] = p; } - pl->n--; } diff --git a/src/core/particle_data.hpp b/src/core/particle_data.hpp index c42eee042cd..e633a1446fb 100755 --- a/src/core/particle_data.hpp +++ b/src/core/particle_data.hpp @@ -176,7 +176,7 @@ struct ParticleProperties { #endif // ROTATION #endif // LANGEVIN_PER_PARTICLE -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS int catalyzer_count = 0; #endif @@ -646,6 +646,14 @@ int set_particle_rotational_inertia(int part, double rinertia[3]); */ int set_particle_rotation(int part, int rot); +/** @brief rotate a particle around an axis + + @param part particle id + @param axis rotation axis + @param angle rotation angle +*/ +int rotate_particle(int part, double axis[3], double angle); + #ifdef AFFINITY /** Call only on the master node: set particle affinity. @param part the particle. diff --git a/src/core/rotate_system.cpp b/src/core/rotate_system.cpp index 0bcc6c9680d..ebca858d810 100644 --- a/src/core/rotate_system.cpp +++ b/src/core/rotate_system.cpp @@ -46,7 +46,7 @@ void local_rotate_system(double phi, double theta, double alpha) { p.r.p[j] = com[j] + res[j]; } #ifdef ROTATION - rotate_particle(&p, axis, alpha); + local_rotate_particle(&p, axis, alpha); #endif } diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index bec538e471a..d5be3c0eb65 100755 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -491,6 +491,20 @@ Vector3d convert_vector_body_to_space(const Particle& p, const Vector3d& vec) { return res; } +Vector3d convert_vector_space_to_body(const Particle& p, const Vector3d& v) { + Vector3d res={0,0,0}; + double A[9]; + define_rotation_matrix(p, A); + res[0] = A[0 + 3 * 0] * v[0] + A[0 + 3 * 1] * v[1] + + A[0 + 3 * 2] * v[2]; + res[1] = A[1 + 3 * 0] * v[0] + A[1 + 3 * 1] * v[1] + + A[1 + 3 * 2] * v[2]; + res[2] = A[2 + 3 * 0] * v[0] + A[2 + 3 * 1] * v[1] + + A[2 + 3 * 2] * v[2]; + return res; +} + + void convert_torques_body_to_space(const Particle *p, double *torque) { double A[9]; @@ -537,7 +551,7 @@ void convert_vec_body_to_space(Particle *p, double const *v,double* res) /** Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi */ -void rotate_particle(Particle *p, double *aSpaceFrame, double phi) { +void local_rotate_particle(Particle *p, double *aSpaceFrame, double phi) { // Convert rotation axis to body-fixed frame double a[3]; convert_vec_space_to_body(p, aSpaceFrame, a); diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index db7bd160349..01db0d6d700 100755 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -59,6 +59,7 @@ void convert_torques_body_to_space(const Particle *p, double *torque); Vector3d convert_vector_body_to_space(const Particle& p, const Vector3d& v); +Vector3d convert_vector_space_to_body(const Particle& p, const Vector3d& v); /** convert velocity form the lab-fixed coordinates to the body-fixed frame */ @@ -117,7 +118,7 @@ inline void convert_quatu_to_dip(double quatu[3], double dipm, double dip[3]) { #endif /** Rotate the particle p around the NORMALIZED axis a by amount phi */ -void rotate_particle(Particle *p, double *a, double phi); +void local_rotate_particle(Particle *p, double *a, double phi); /** Rotate the particle p around the body axis "a" by amount phi */ void rotate_particle_body(Particle* p, double* a, double phi); /** Rotate the particle p around the j-th body axis by amount phi */ diff --git a/src/core/reaction.cpp b/src/core/swimmer_reaction.cpp similarity index 99% rename from src/core/reaction.cpp rename to src/core/swimmer_reaction.cpp index 8d10e9e71f1..3354d95d80d 100755 --- a/src/core/reaction.cpp +++ b/src/core/swimmer_reaction.cpp @@ -22,7 +22,7 @@ * */ -#include "reaction.hpp" +#include "swimmer_reaction.hpp" #include "cells.hpp" #include "errorhandling.hpp" #include "forces.hpp" @@ -39,13 +39,13 @@ reaction_struct reaction; -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS void reactions_sanity_checks() { if (reaction.ct_rate != 0.0) { if (!cell_structure.use_verlet_list || cell_structure.type != CELL_STRUCTURE_DOMDEC) { - runtimeErrorMsg() << "The CATALYTIC_REACTIONS feature requires verlet " + runtimeErrorMsg() << "The SWIMMER_REACTIONS feature requires verlet " "lists and domain decomposition"; } diff --git a/src/core/reaction.hpp b/src/core/swimmer_reaction.hpp similarity index 90% rename from src/core/reaction.hpp rename to src/core/swimmer_reaction.hpp index ffe8df306f4..566edcad96e 100755 --- a/src/core/reaction.hpp +++ b/src/core/swimmer_reaction.hpp @@ -18,9 +18,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef REACTION_H -#define REACTION_H -/** \file reaction.hpp +#ifndef SWIMMER_REACTION_H +#define SWIMMER_REACTION_H +/** \file swimmer_reaction.hpp * */ @@ -40,7 +40,7 @@ typedef struct { extern reaction_struct reaction; -#ifdef CATALYTIC_REACTIONS +#ifdef SWIMMER_REACTIONS /** sanity checks for the reaction code */ void reactions_sanity_checks(); /** broadcasts reaction parameters and sets up an entry in the ia_params, so @@ -50,4 +50,4 @@ void local_setup_reaction(); void integrate_reaction(); #endif -#endif /* ifdef REACTION_H */ +#endif /* ifdef SWIMMER_REACTION_H */ diff --git a/src/core/tunable_slip.cpp b/src/core/tunable_slip.cpp deleted file mode 100755 index 48cd807cc16..00000000000 --- a/src/core/tunable_slip.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (C) 2010,2011,2012,2013,2014,2015,2016 The ESPResSo project - Copyright (C) 2009,2010 - Max-Planck-Institute for Polymer Research, Theory Group - - This file is part of ESPResSo. - - ESPResSo is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ESPResSo is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#include "tunable_slip.hpp" -#include "random.hpp" -#include "communication.hpp" - -#ifdef TUNABLE_SLIP - -int tunable_slip_set_params(int part_type_a, int part_type_b, - double temp, double gamma, double r_cut, - double time, double vx, double vy, double vz) -{ - IA_parameters *data = get_ia_param_safe(part_type_a, part_type_b); - - if (!data) return ES_ERROR; - - /* TUNABLE SLIP should be symmetrical! */ - data->TUNABLE_SLIP_temp = temp; - data->TUNABLE_SLIP_gamma = gamma; - data->TUNABLE_SLIP_r_cut = r_cut; - data->TUNABLE_SLIP_time = time; - data->TUNABLE_SLIP_vx = vx; - data->TUNABLE_SLIP_vy = vy; - data->TUNABLE_SLIP_vz = vz; - - /* broadcast interaction parameters */ - mpi_bcast_ia_params(part_type_a, part_type_b); - - return ES_OK; -} - - -void add_tunable_slip_pair_force(Particle *p1, Particle *p2, IA_parameters *ia_params, double d[3], double dist, double force[3]) -{ - double gamma_t=0.0; - double gamma_t_sqrt=0.0; - double pre_diss=0.0; - double pre_rand=0.0; - double scale_vx=0.0; - double scale_vy=0.0; - double scale_vz=0.0; - - if(dist < ia_params->TUNABLE_SLIP_r_cut) { - gamma_t += 1-(dist/(ia_params->TUNABLE_SLIP_r_cut)); - }else{ - gamma_t += 0.0; - } - gamma_t_sqrt += sqrt(gamma_t); - pre_diss += ((ia_params->TUNABLE_SLIP_gamma)/ia_params->TUNABLE_SLIP_time); - pre_rand += sqrt((24.0*ia_params->TUNABLE_SLIP_temp*ia_params->TUNABLE_SLIP_gamma)/ia_params->TUNABLE_SLIP_time); - - /* Rescaling of reference velocity */ - scale_vx += ia_params->TUNABLE_SLIP_vx*ia_params->TUNABLE_SLIP_time; - scale_vy += ia_params->TUNABLE_SLIP_vy*ia_params->TUNABLE_SLIP_time; - scale_vz += ia_params->TUNABLE_SLIP_vz*ia_params->TUNABLE_SLIP_time; - - force[0] += -(pre_diss*gamma_t*(p1->m.v[0]-scale_vx))+(pre_rand*gamma_t_sqrt*(d_random()-0.5)); - force[1] += -(pre_diss*gamma_t*(p1->m.v[1]-scale_vy))+(pre_rand*gamma_t_sqrt*(d_random()-0.5)); - force[2] += -(pre_diss*gamma_t*(p1->m.v[2]-scale_vz))+(pre_rand*gamma_t_sqrt*(d_random()-0.5)); - - ONEPART_TRACE(if(p1->p.identity==check_id) fprintf(stderr,"%d: OPT: TUNABLE_SLIP f = (%.3e,%.3e,%.3e) with part id=%d\n",this_node,p1->f.f[0],p1->f.f[1],p1->f.f[2],p2->p.identity)); - ONEPART_TRACE(if(p2->p.identity==check_id) fprintf(stderr,"%d: OPT: TUNABLE_SLIP f = (%.3e,%.3e,%.3e) with part id=%d\n",this_node,p2->f.f[0],p2->f.f[1],p2->f.f[2],p1->p.identity)); - -} - -#endif diff --git a/src/core/tunable_slip.hpp b/src/core/tunable_slip.hpp deleted file mode 100755 index e22fc7a04a1..00000000000 --- a/src/core/tunable_slip.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (C) 2010,2011,2012,2013,2014,2015,2016 The ESPResSo project - Copyright (C) 2009,2010 - Max-Planck-Institute for Polymer Research, Theory Group - - This file is part of ESPResSo. - - ESPResSo is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ESPResSo is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ -#ifndef _TUNABLE_SLIP_H -#define _TUNABLE_SLIP_H - -/** \file tunable_slip.hpp - * Routines to generate tunable-slip boundary conditions. - * J.Smiatek, M.P. Allen, F. Schmid: - * "Tunable-slip boundaries for coarse-grained simulations of fluid flow", Europ. Phys. J. E 26, 115 (2008) -*/ - -#include "utils.hpp" -#include "interaction_data.hpp" -#include "particle_data.hpp" - -#ifdef TUNABLE_SLIP - -int tunable_slip_set_params(int part_type_a, int part_type_b, - double temp, double gamma, double r_cut, - double time, double vx, double vy, double vz); - -void add_tunable_slip_pair_force(Particle *p1, Particle *p2, IA_parameters *ia_params, double d[3], double dist, double force[3]); - -#endif - -#endif diff --git a/src/core/virtual_sites/VirtualSitesRelative.cpp b/src/core/virtual_sites/VirtualSitesRelative.cpp index fd5649596e0..0d5507a6756 100755 --- a/src/core/virtual_sites/VirtualSitesRelative.cpp +++ b/src/core/virtual_sites/VirtualSitesRelative.cpp @@ -52,6 +52,10 @@ void VirtualSitesRelative::update_virtual_particle_quaternion(Particle& p) const } multiply_quaternions(p_real->r.quat, p.p.vs_quat, p.r.quat); convert_quat_to_quatu(p.r.quat, p.r.quatu); +#ifdef DIPOLES + // When dipoles are enabled, update dipole moment + convert_quatu_to_dip(p.r.quatu, p.p.dipm, p.r.dip); +#endif } @@ -182,7 +186,7 @@ void VirtualSitesRelative::back_transfer_forces_and_torques() const { // Add forces and torques for (int j = 0; j < 3; j++) { - p_real->f.torque[j] += tmp[j]; + p_real->f.torque[j] += tmp[j]+p.f.torque[j]; p_real->f.f[j] += p.f.f[j]; } } diff --git a/src/features.def b/src/features.def index b76e20f1153..254d7ed218e 100755 --- a/src/features.def +++ b/src/features.def @@ -28,7 +28,7 @@ METADYNAMICS NEMD NPT GHMC -CATALYTIC_REACTIONS +SWIMMER_REACTIONS MULTI_TIMESTEP requires not GAUSSRANDOMCUT and not GAUSSRANDOM and EXPERIMENTAL_FEATURES ENGINE implies ROTATION, EXTERNAL_FORCES PARTICLE_ANISOTROPY @@ -63,7 +63,6 @@ VIRTUAL_SITES /* DPD features */ DPD -TUNABLE_SLIP requires EXPERIMENTAL_FEATURES /* Lattice-Boltzmann features */ LB diff --git a/src/python/espressomd/cellsystem.pyx b/src/python/espressomd/cellsystem.pyx index 8deaee4863a..61d264e7f40 100644 --- a/src/python/espressomd/cellsystem.pyx +++ b/src/python/espressomd/cellsystem.pyx @@ -136,6 +136,39 @@ cdef class CellSystem(object): return s + def __getstate__(self): + s = {"use_verlet_list" : cell_structure.use_verlet_list} + + if cell_structure.type == CELL_STRUCTURE_LAYERED: + s["type"] = "layered" + s["n_layers"] = n_layers + if cell_structure.type == CELL_STRUCTURE_DOMDEC: + s["type"] = "domain_decomposition" + if cell_structure.type == CELL_STRUCTURE_NSQUARE: + s["type"] = "nsquare" + + s["skin"] = skin + s["node_grid"] = np.array([node_grid[0], node_grid[1], node_grid[2]]) + s["max_num_cells"] = max_num_cells + s["min_num_cells"] = min_num_cells + return s + + def __setstate__(self, d): + use_verlet_lists = None + for key in d: + if key == "use_velet_list": + use_verlet_lists = d[key] + elif key == "type": + if d[key] == "layered": + self.set_layered(n_layers=d['n_layers'], use_verlet_lists=use_verlet_lists) + elif d[key] == "domain_decomposition": + self.set_domain_decomposition(use_verlet_lists=use_verlet_lists) + elif d[key] == "nsquare": + self.set_n_square(use_verlet_lists=use_verlet_lists) + self.skin = d['skin'] + self.node_grid = d['node_grid'] + self.max_num_cells = d['max_num_cells'] + self.min_num_cells = d['min_num_cells'] def get_pairs_(self, distance): return mpi_get_pairs(distance) @@ -207,7 +240,7 @@ cdef class CellSystem(object): node_grid[1] = _node_grid[1] node_grid[2] = _node_grid[2] mpi_err = mpi_bcast_parameter(FIELD_NODEGRID) - handle_errors("mpi_bcast_parameter failed") + handle_errors("mpi_bcast_parameter for node_grid failed") if mpi_err: raise Exception("Broadcasting the node grid failed") diff --git a/src/python/espressomd/checkpointing.py b/src/python/espressomd/checkpointing.py index 407f91ae399..dfde76b89ab 100644 --- a/src/python/espressomd/checkpointing.py +++ b/src/python/espressomd/checkpointing.py @@ -195,8 +195,8 @@ def load(self, checkpoint_index=None): checkpoint_index = self.get_last_checkpoint_index() filename = os.path.join(self.checkpoint_dir, "{}.checkpoint".format(checkpoint_index)) - with open(filename,"rb") as checkpoint_file: - checkpoint_data = pickle.load(checkpoint_file) + with open(filename, "rb") as f: + checkpoint_data = pickle.load(f) for key in checkpoint_data: self.setattr_submodule(self.calling_module, key, checkpoint_data[key]) diff --git a/src/python/espressomd/constraints.py b/src/python/espressomd/constraints.py index d26c65e2857..391dd9346f0 100644 --- a/src/python/espressomd/constraints.py +++ b/src/python/espressomd/constraints.py @@ -91,6 +91,8 @@ class ShapeBasedConstraint(Constraint): only useful if penetrable is True. particle_type : int Interaction type of the constraint. + particle_velocity : array of :obj:`float` + Interaction velocity of the boudary penetrable : bool Whether particles are allowed to penetrate the constraint. @@ -125,7 +127,7 @@ class ShapeBasedConstraint(Constraint): def min_dist(self): """ Calculates the minimum distance to all interacting particles. - + Returns ---------- :obj:float: The minimum distance diff --git a/src/python/espressomd/electrostatics.pyx b/src/python/espressomd/electrostatics.pyx index 7a04229c1b5..11cf7e6279d 100644 --- a/src/python/espressomd/electrostatics.pyx +++ b/src/python/espressomd/electrostatics.pyx @@ -24,7 +24,7 @@ from . import actors cimport globals import numpy as np IF SCAFACOS == 1: - from .scafacos import ScafacosConnector + from .scafacos import ScafacosConnector from . cimport scafacos from espressomd.utils cimport handle_errors from espressomd.utils import is_valid_type @@ -35,24 +35,36 @@ def check_neutrality(system, _params): total_charge=np.sum(charges) min_abs_nonzero_charge = np.min(np.abs(charges[np.nonzero(charges)[0]])) if abs(total_charge)/min_abs_nonzero_charge>1e-10: - raise ValueError("The system is not charge neutral. Please neutralize the system before adding a new actor via adding the corresponding counterions to the system. Alternatively you can turn off the electroneutrality check via supplying check_neutrality=False when creating the actor. In this case you may be simulating a non-neutral system which will affect physical observables like e.g. the pressure, the chemical potentials of charged species or potential energies of the system. Since simulations of non charge neutral systems are special please make sure you know what you are doing.") - -IF ELECTROSTATICS == 1: + raise ValueError("The system is not charge neutral. Please \ + neutralize the system before adding a new actor via adding \ + the corresponding counterions to the system. Alternatively \ + you can turn off the electroneutrality check via supplying \ + check_neutrality=False when creating the actor. In this \ + case you may be simulating a non-neutral system which will \ + affect physical observables like e.g. the pressure, the \ + chemical potentials of charged species or potential \ + energies of the system. Since simulations of non charge \ + neutral systems are special please make sure you know what \ + you are doing.") + +IF ELECTROSTATICS == 1: cdef class ElectrostaticInteraction(actors.Actor): def _tune(self): raise Exception( - "Subclasses of ElectrostaticInteraction must define the _tune() method or chosen method does not support tuning.") - + "Subclasses of ElectrostaticInteraction must define the _tune() \ + method or chosen method does not support tuning.") + def _set_params_in_es_core(self): raise Exception( - "Subclasses of ElectrostaticInteraction must define the _set_params_in_es_core() method.") + "Subclasses of ElectrostaticInteraction must define the \ + _set_params_in_es_core() method.") def _deactivate_method(self): deactivate_coulomb_method() handle_errors("Coulom method deactivation") - + def Tune(self, **subsetTuneParams): - + # Override default parmas with subset given by user tuneParams = self.default_params() if not subsetTuneParams == None: @@ -60,14 +72,14 @@ IF ELECTROSTATICS == 1: if k not in self.valid_keys(): raise ValueError(k + " is not a valid parameter") tuneParams.update(subsetTuneParams) - + # If param is 'required', it was set before, so don't change it # Do change it if it's given to Tune() by user for param in tuneParams.iterkeys(): if not param in self.required_keys() or (not subsetTuneParams == None and param in subsetTuneParams.keys()): self._params[param] = tuneParams[param] self._tune() - + IF COULOMB_DEBYE_HUECKEL: cdef class CDH(ElectrostaticInteraction): """ Hybrid method to solve electrostatic interactions, on short length @@ -77,22 +89,24 @@ IF COULOMB_DEBYE_HUECKEL: Parameters ---------- - prefactor : float - Electrostatics prefactor (see :eq:`coulomb_prefactor`) - kappa : float - Inverse Debye screening length - r_cut : float - Cut off radius for this interaction - eps_int : float - Relative permitivity in the interior region rr1 - r0 : float - Radius that defines the region where electrostatics are not screened, classical Coulomb potential. - r1 : float - Radius for the transition region from pure Coulomb to Debye-Hueckel - alpha : float - Controls the transition between the pure Coulomb and Debye Hueckel regions + prefactor : :obj:`float` + Electrostatics prefactor (see :eq:`coulomb_prefactor`). + kappa : :obj:`float` + Inverse Debye screening length. + r_cut : :obj:`float` + Cut off radius for this interaction. + eps_int : :obj:`float` + Relative permitivity in the interior region rr1. + r0 : :obj:`float` + Radius that defines the region where electrostatics are not + screened, classical Coulomb potential. + r1 : :obj:`float` + Radius for the transition region from pure Coulomb to Debye-Hueckel. + alpha : :obj:`float` + Controls the transition between the pure Coulomb and Debye Hueckel + regions. """ def validate_params(self): @@ -151,17 +165,17 @@ ELSE: IF ELECTROSTATICS: cdef class DH(ElectrostaticInteraction): """ - Solve electrostatics in the Debye-Hueckel framework see :ref:`Debye-Hückel potential` - for more details. + Solve electrostatics in the Debye-Hueckel framework see + :ref:`Debye-Hückel potential` for more details. Parameters ---------- - prefactor : float - Electrostatics prefactor (see :eq:`coulomb_prefactor`) - kappa : float - Inverse Debye sreening length - r_cut : float - Cut off radius for this interaction + prefactor : :obj:`float` + Electrostatics prefactor (see :eq:`coulomb_prefactor`). + kappa : :obj:`float` + Inverse Debye sreening length. + r_cut : :obj:`float` + Cut off radius for this interaction. """ def validate_params(self): @@ -208,42 +222,34 @@ IF P3M == 1: P3M electrostatics solver. Particle–Particle-Particle–Mesh (P3M) is a Fourier-based Ewald - summation method to calculate potentials in N-body simulation. + summation method to calculate potentials in N-body simulation. Parameters ---------- - prefactor : float - Electrostatics prefactor (see :eq:`coulomb_prefactor`) - accuracy : float - P3M tunes its parameters to provide this target accuracy. - - alpha : float, optional - The Ewald parameter. - - cao : float, optional - The charge-assignment order, an integer between 0 and 7. - - epsilon : string, optional - Use 'metallic' to set the dielectric constant of the - surrounding medium to infinity (Default). - - epsilon : float, optional - A positive number for the dielectric constant of the - surrounding medium. - - mesh : int, optional - The number of mesh points - + prefactor : :obj:`float` + Electrostatics prefactor (see :eq:`coulomb_prefactor`). + accuracy : :obj:`float` + P3M tunes its parameters to provide this target accuracy. + alpha : :obj:`float`, optional + The Ewald parameter. + cao : :obj:`float`, optional + The charge-assignment order, an integer between 0 and 7. + epsilon : :obj:`str`, optional + Use 'metallic' to set the dielectric constant of the + surrounding medium to infinity (Default). + epsilon : :obj:`float`, optional + A positive number for the dielectric constant of the + surrounding medium. + mesh : :obj:`int`, optional + The number of mesh points. mesh : array_like, optional - The number of mesh points in x, y and z direction. This is - relevant for 8 noncubic boxes. - - r_cut : float, optional - The real space cutoff. - - tune : bool, optional - Used to activate/deactivate the tuning method on activation. - Defaults to True + The number of mesh points in x, y and z direction. This is + relevant for noncubic boxes. + r_cut : :obj:`float`, optional + The real space cutoff. + tune : :obj:`bool`, optional + Used to activate/deactivate the tuning method on activation. + Defaults to True. """ super(type(self), self).__init__(*args, **kwargs) @@ -317,11 +323,11 @@ IF P3M == 1: def _set_params_in_es_core(self): #Sets lb, bcast, resets vars to zero if lb=0 coulomb_set_prefactor(self._params["prefactor"]) - #Sets cdef vars and calls p3m_set_params() in core + #Sets cdef vars and calls p3m_set_params() in core python_p3m_set_params(self._params["r_cut"], self._params["mesh"], self._params["cao"], self._params["alpha"], self._params["accuracy"]) - #p3m_set_params() -> set r_cuts, mesh, cao, validates sanity, bcasts + #p3m_set_params() -> set r_cuts, mesh, cao, validates sanity, bcasts #Careful: bcast calls on_coulomb_change(), which calls p3m_init(), # which resets r_cut if lb is zero. OK. #Sets eps, bcast @@ -354,42 +360,34 @@ IF P3M == 1: P3M electrostatics solver with GPU support. Particle–Particle-Particle–Mesh (P3M) is a Fourier-based Ewald - summation method to calculate potentials in N-body simulation. + summation method to calculate potentials in N-body simulation. Parameters ---------- - prefactor : float - Electrostatics prefactor (see :eq:`coulomb_prefactor`) - accuracy : float - P3M tunes its parameters to provide this target accuracy. - - alpha : float, optional - The Ewald parameter. - - cao : float, optional - The charge-assignment order, an integer between 0 and 7. - - epsilon : string, optional - Use 'metallic' to set the dielectric constant of the - surrounding medium to infinity (Default). - - epsilon : float, optional - A positive number for the dielectric constant of the - surrounding medium. - - mesh : int, optional - The number of mesh points - + prefactor : :obj:`float` + Electrostatics prefactor (see :eq:`coulomb_prefactor`). + accuracy : :obj:`float` + P3M tunes its parameters to provide this target accuracy. + alpha : :obj:`float`, optional + The Ewald parameter. + cao : :obj:`float`, optional + The charge-assignment order, an integer between 0 and 7. + epsilon : :obj:`str`, optional + Use 'metallic' to set the dielectric constant of the + surrounding medium to infinity (Default). + epsilon : :obj:`float`, optional + A positive number for the dielectric constant of the + surrounding medium. + mesh : :obj:`int`, optional + The number of mesh points. mesh : array_like, optional - The number of mesh points in x, y and z direction. This is - relevant for 8 noncubic boxes. - - r_cut : float, optional - The real space cutoff. - - tune : bool, optional - Used to activate/deactivate the tuning method on activation. - Defaults to True + The number of mesh points in x, y and z direction. This is + relevant for noncubic boxes. + r_cut : :obj:`float`, optional + The real space cutoff + tune : :obj:`bool`, optional + Used to activate/deactivate the tuning method on activation. + Defaults to True. """ super(type(self), self).__init__(*args, **kwargs) @@ -491,15 +489,15 @@ IF ELECTROSTATICS: Parameters ---------- - prefactor : float - Electrostatics prefactor (see :eq:`coulomb_prefactor`) - maxWPerror : float - Maximal pairwise error - far_switch_radius : float, optional - Radius where near-field and far-field calculation are switched - bessel_cutoff : int, optional - tune : bool, optional - Specify whether to automatically tune ore not. The default is True. + prefactor : :obj:`float` + Electrostatics prefactor (see :eq:`coulomb_prefactor`). + maxWPerror : :obj:`float` + Maximal pairwise error. + far_switch_radius : :obj:`float`, optional + Radius where near-field and far-field calculation are switched. + bessel_cutoff : :obj:`int`, optional + tune : :obj:`bool`, optional + Specify whether to automatically tune ore not. The default is True. """ def validate_params(self): @@ -565,15 +563,15 @@ IF ELECTROSTATICS and MMM1D_GPU: Parameters ---------- - prefactor : float - Electrostatics prefactor (see :eq:`coulomb_prefactor`) - maxWPerror : float - Maximal pairwise error - far_switch_radius : float, optional - Radius where near-field and far-field calculation are switched - bessel_cutoff : int, optional - tune : bool, optional - Specify whether to automatically tune ore not. The default is True. + prefactor : :obj:`float` + Electrostatics prefactor (see :eq:`coulomb_prefactor`). + maxWPerror : :obj:`float` + Maximal pairwise error. + far_switch_radius : :obj:`float`, optional + Radius where near-field and far-field calculation are switched + bessel_cutoff : :obj:`int`, optional + tune : :obj:`bool`, optional + Specify whether to automatically tune ore not. The default is True. """ cdef Mmm1dgpuForce * thisptr cdef EspressoSystemInterface * interface @@ -645,56 +643,50 @@ IF ELECTROSTATICS and MMM1D_GPU: IF ELECTROSTATICS: cdef class MMM2D(ElectrostaticInteraction): """ - Electrostatics solver for systems with two periodic dimensions. + Electrostatics solver for systems with two periodic dimensions. More detail are in the user guide :ref:`MMM2D Theory` Parameters ---------- - prefactor : float - Electrostatics prefactor (see :eq:`coulomb_prefactor`) - maxWPerror : float - Maximal pairwise error - dielectric : int, optional - Selector parameter for setting the dielectric - constants manually (top, mid, bottom), mutually - exclusive with dielectric-contrast - top : float, optional - If dielectric is specified this paramter sets the - dielectric constant *above* the simulation box - :math:`\\varepsilon_\\mathrm{top}` - mid : float, optional - If dielectric is specified this paramter sets the - dielectric constant *in* the simulation box - :math:`\\varepsilon_\\mathrm{mid}` - bottom : float, optional - If dielectric is specified this paramter sets the - dielectric constant *below* the simulation box - :math:`\\varepsilon_\\mathrm{bot}` - dielectric_contrast_on : int, optional - Selector parameter for setting a dielectric - contrast between the upper simulation boundary - and the simulation box, and between the lower - simulation boundary and the simulation box, - respectively. - delta_mid_top : float, optional - If dielectric-contrast mode is selected, then - this parameter sets the dielectric contrast - between the upper boundary and the simulation - box :math:`\\Delta_t`. - delta_mid_bottom : float, optional - If dielectric-contrast mode is selected, then - this parameter sets the dielectric contrast - between the lower boundary and the simulation - box :math:`\\Delta_b`. - const_pot : int, optional - Selector parameter for setting a constant - electric potential between the top and bottom - of the simulation box. - pot_diff : float, optional - If const_pot mode is selected this parameter - controls the applied voltage. - far_cut : float, optional - Cut off radius, use with care, intended for testing purposes. + prefactor : :obj:`float` + Electrostatics prefactor (see :eq:`coulomb_prefactor`). + maxWPerror : :obj:`float` + Maximal pairwise error. + dielectric : :obj:`int`, optional + Selector parameter for setting the dielectric constants manually + (top, mid, bottom), mutually exclusive with dielectric-contrast + top : :obj:`float`, optional + If dielectric is specified this paramter sets the dielectric + constant *above* the simulation box + :math:`\\varepsilon_\\mathrm{top}` + mid : :obj:`float`, optional + If dielectric is specified this paramter sets the dielectric + constant *in* the simulation box :math:`\\varepsilon_\\mathrm{mid}`. + bottom : :obj:`float`, optional + If dielectric is specified this paramter sets the dielectric + constant *below* the simulation box + :math:`\\varepsilon_\\mathrm{bot}`. + dielectric_contrast_on : :obj:`int`, optional + Selector parameter for setting a dielectric contrast between the + upper simulation boundary and the simulation box, and between the + lower simulation boundary and the simulation box, respectively. + delta_mid_top : :obj:`float`, optional + If dielectric-contrast mode is selected, then this parameter sets + the dielectric contrast between the upper boundary and the + simulation box :math:`\\Delta_t`. + delta_mid_bottom : :obj:`float`, optional + If dielectric-contrast mode is selected, then this parameter sets + the dielectric contrast between the lower boundary and the + simulation box :math:`\\Delta_b`. + const_pot : :obj:`int`, optional + Selector parameter for setting a constant electric potential + between the top and bottom of the simulation box. + pot_diff : :obj:`float`, optional + If const_pot mode is selected this parameter controls the applied + voltage. + far_cut : :obj:`float`, optional + Cut off radius, use with care, intended for testing purposes. + """ def validate_params(self): default_params = self.default_params() diff --git a/src/python/espressomd/globals.pxd b/src/python/espressomd/globals.pxd index 0617ec46262..910377fafd0 100644 --- a/src/python/espressomd/globals.pxd +++ b/src/python/espressomd/globals.pxd @@ -152,7 +152,7 @@ cdef extern from "npt.hpp": cdef extern from "statistics.hpp": extern int n_configs -cdef extern from "reaction.hpp": +cdef extern from "swimmer_reaction.hpp": ctypedef struct reaction_struct: int reactant_type int product_type diff --git a/src/python/espressomd/interactions.pxd b/src/python/espressomd/interactions.pxd index e47bb7ff2ce..b51100eb482 100644 --- a/src/python/espressomd/interactions.pxd +++ b/src/python/espressomd/interactions.pxd @@ -19,6 +19,9 @@ # Handling of interactions from __future__ import print_function, absolute_import + +from libcpp.string cimport string + include "myconfig.pxi" from espressomd.system cimport * cimport numpy as np @@ -132,6 +135,8 @@ cdef extern from "interaction_data.hpp": cdef ia_parameters * get_ia_param(int i, int j) cdef ia_parameters * get_ia_param_safe(int i, int j) cdef void make_bond_type_exist(int type) + cdef string ia_params_get_state() + cdef void ia_params_set_state(string) cdef extern from "lj.hpp": cdef int lennard_jones_set_params(int part_type_a, int part_type_b, diff --git a/src/python/espressomd/interactions.pyx b/src/python/espressomd/interactions.pyx index 5eafb281347..f0c311a2342 100644 --- a/src/python/espressomd/interactions.pyx +++ b/src/python/espressomd/interactions.pyx @@ -17,6 +17,9 @@ # along with this program. If not, see . # from __future__ import print_function, absolute_import + +from libcpp.string cimport string + include "myconfig.pxi" from . import utils from espressomd.utils import is_valid_type @@ -98,6 +101,12 @@ cdef class NonBondedInteraction(object): def __str__(self): return self.__class__.__name__ + "(" + str(self.get_params()) + ")" + def __getstate__(self): + return self.get_params() + + def __setstate__(self, p): + self.set_params(p) + def set_params(self, **p): """Update the given parameters. @@ -1532,7 +1541,6 @@ class NonBondedInteractionHandle(object): hat = None thole = None - def __init__(self, _type1, _type2): """Takes two particle types as argument""" if not (is_valid_type(_type1, int) and is_valid_type(_type2, int)): @@ -1576,6 +1584,7 @@ class NonBondedInteractionHandle(object): IF THOLE: self.thole = TholeInteraction(_type1, _type2) + cdef class NonBondedInteractions(object): """ Access to non-bonded interaction parameters via [i,j], where i,j are particle @@ -1594,29 +1603,13 @@ cdef class NonBondedInteractions(object): return NonBondedInteractionHandle(key[0], key[1]) def __getstate__(self): - # contains info about ALL nonbonded interactions - odict = NonBondedInteractionHandle(-1, - - 1).lennard_jones.user_interactions - return odict + cdef string state + state = ia_params_get_state() + return state def __setstate__(self, odict): - for _type1 in odict: - for _type2 in odict[_type1]: - attrs = dir(NonBondedInteractionHandle(_type1, _type2)) - for a in attrs: - attr_ref = getattr( - NonBondedInteractionHandle(_type1, _type2), a) - type_name_ref = getattr(attr_ref, "type_name", None) - if callable(type_name_ref) and type_name_ref() == odict[_type1][_type2]['type_name']: - # found nonbonded inter, e.g. - # LennardJonesInteraction(_type1, _type2) - inter_instance = attr_ref - break - else: - continue - - del odict[_type1][_type2]['type_name'] - inter_instance.set_params(**odict[_type1][_type2]) + cdef string odict_string = odict + ia_params_set_state(odict_string) cdef class BondedInteraction(object): diff --git a/src/python/espressomd/lbboundaries.py b/src/python/espressomd/lbboundaries.py index ab20b26ae9f..11331934e81 100644 --- a/src/python/espressomd/lbboundaries.py +++ b/src/python/espressomd/lbboundaries.py @@ -13,6 +13,14 @@ class LBBoundaries(ScriptInterfaceHelper): _so_name = "LBBoundaries::LBBoundaries" + def __getitem__(self, key): + return self.call_method("get_elements")[key] + + def __iter__(self): + elements = self.call_method("get_elements") + for e in elements: + yield e + def add(self, *args, **kwargs): """ Adds a boundary to the set. diff --git a/src/python/espressomd/magnetostatics.pyx b/src/python/espressomd/magnetostatics.pyx index b40479c9c0e..74dd94d97e8 100644 --- a/src/python/espressomd/magnetostatics.pyx +++ b/src/python/espressomd/magnetostatics.pyx @@ -35,7 +35,7 @@ IF DIPOLES == 1: Attributes ---------- prefactor : :obj:`float` - Magnetostatics prefactor + Magnetostatics prefactor (:math:`\mu_0/(4\pi)`) """ @@ -75,6 +75,8 @@ IF DP3M == 1: Attributes ---------- + prefactor : :obj:`float` + Magnetostatics prefactor (:math:`\mu_0/(4\pi)`) accuracy : :obj:`float` P3M tunes its parameters to provide this target accuracy. alpha : :obj:`float` @@ -234,6 +236,12 @@ IF DIPOLES == 1: If the system has periodic boundaries, the minimum image convention is applied in the respective directions. + + Attributes + ---------- + + prefactor : :obj:`float` + Magnetostatics prefactor (:math:`\mu_0/(4\pi)`) """ @@ -267,6 +275,8 @@ IF DIPOLES == 1: Attributes ---------- + prefactor : :obj:`float` + Magnetostatics prefactor (:math:`\mu_0/(4\pi)`) n_replica : :obj:`int` Number of replicas to be taken into account at periodic boundaries. @@ -297,6 +307,14 @@ IF DIPOLES == 1: class Scafacos(ScafacosConnector, MagnetostaticInteraction): """ Calculates dipolar interactions using dipoles-capable method from the SCAFACOs library. + prefactor : :obj:`float` + Magnetostatics prefactor (:math:`\mu_0/(4\pi)`) + method_name : :obj:`str` + Name of the method as defined in Scafacos + method_params : :obj:`dict` + Dictionary with the key-value pairs of the method parameters as defined in Scafacos. Note that the values are cast to strings to match Scafacos' interface + + """ @@ -325,7 +343,12 @@ IF DIPOLES == 1: If the system has periodic boundaries, the minimum image convention is applied in the respective directions. - GPU version of :class:`espressomd.magnetostatics.DipolarDirectSumCpu`. + This is the GPU version of :class:`espressomd.magnetostatics.DipolarDirectSumCpu` but uses floating point precision. + + Attributes + ---------- + prefactor : :obj:`float` + Magnetostatics prefactor (:math:`\mu_0/(4\pi)`) """ diff --git a/src/python/espressomd/observables.py b/src/python/espressomd/observables.py index 98ba77e4315..45ec174a1ba 100644 --- a/src/python/espressomd/observables.py +++ b/src/python/espressomd/observables.py @@ -189,16 +189,47 @@ class MagneticDipoleMoment(Observable): @script_interface_register class ParticleAngularVelocities(Observable): _so_name = "Observables::ParticleAngularVelocities" + + """Calculates the angular velocity (omega) in the spaced-fixed frame of reference + + Parameters + ---------- + ids : array_like of :obj:`int` + The ids of (existing) particles to take into account. + + """ @script_interface_register class ParticleBodyAngularVelocities(Observable): _so_name = "Observables::ParticleBodyAngularVelocities" + """Calculates the angular velocity (omega) in the particles' body-fixed frame of reference. + + For each particle, the body-fixed frame of reference is obtained from the particle's + orientation stored in the quaternions. + + Parameters + ---------- + ids : array_like of :obj:`int` + The ids of (existing) particles to take into account. + + """ @script_interface_register class ParticleBodyVelocities(Observable): _so_name = "Observables::ParticleBodyVelocities" + """Calculates the particle velocity in the particles' body-fixed frame of reference. + + For each particle, the body-fixed frame of reference is obtained from the particle's + orientation stored in the quaternions. + + Parameters + ---------- + ids : array_like of :obj:`int` + The ids of (existing) particles to take into account. + + """ @script_interface_register @@ -257,10 +288,10 @@ class ParticleVelocities(Observable): class StressTensor(Observable): _so_name = "Observables::StressTensor" + """Calculates the total stress tensor. See :ref:`stress tensor`) + + """ -@script_interface_register -class StressTensorAcf(Observable): - _so_name = "Observables::StressTensorAcf" @script_interface_register diff --git a/src/python/espressomd/particle_data.pxd b/src/python/espressomd/particle_data.pxd index 64e95ffb648..d42d6afbd46 100644 --- a/src/python/espressomd/particle_data.pxd +++ b/src/python/espressomd/particle_data.pxd @@ -218,6 +218,8 @@ cdef extern from "rotation.hpp": void convert_omega_body_to_space(const particle * p, double * omega) void convert_torques_body_to_space(const particle * p, double * torque) Vector3d convert_vector_body_to_space(const particle& p,const Vector3d& v) + Vector3d convert_vector_space_to_body(const particle& p,const Vector3d& v) + void rotate_particle(int id, double* axis, double angle) # The bonded_ia_params stuff has to be included here, because the setter/getter # of the particles' bond property needs to now about the correct number of diff --git a/src/python/espressomd/particle_data.pyx b/src/python/espressomd/particle_data.pyx index b5b5de67399..50ddfa5da18 100644 --- a/src/python/espressomd/particle_data.pyx +++ b/src/python/espressomd/particle_data.pyx @@ -1597,7 +1597,35 @@ cdef class ParticleHandle(object): self.update_particle_data() res= convert_vector_body_to_space(self.particle_data[0],_v) return np.array((res[0],res[1],res[2])) + + def convert_vector_space_to_body(self, vec): + """Converts the given vector from the space frame to the particle's body frame""" + cdef Vector3d res + cdef Vector3d _v + _v[0] = vec[0] + _v[1] = vec[1] + _v[2] = vec[2] + self.update_particle_data() + res= convert_vector_space_to_body(self.particle_data[0],_v) + return np.array((res[0],res[1],res[2])) + + + def rotate(self,axis=None,angle=None): + """Rotates the particle around the given axis + + Parameters + ---------- + axis : array-like + + angle : float + + """ + cdef double[3] a + a[0]=axis[0] + a[1]=axis[1] + a[2]=axis[2] + rotate_particle(self.id,a,angle) cdef class _ParticleSliceImpl(object): """Handles slice inputs. @@ -1766,7 +1794,7 @@ cdef class ParticleList(object): """ pickle_attr = copy(particle_attributes) - for i in ["director", "dip", "id"]: + for i in ["director", "dip", "id", "image_box", "node"]: if i in pickle_attr: pickle_attr.remove(i) IF MASS == 0: diff --git a/src/python/espressomd/polymer.pyx b/src/python/espressomd/polymer.pyx index 7b3f0a66d3d..72964f7da46 100644 --- a/src/python/espressomd/polymer.pyx +++ b/src/python/espressomd/polymer.pyx @@ -33,6 +33,9 @@ def validate_params(_params, default): if _params["bond_length"] < 0 : raise ValueError( "bond_length has to be a positive float" ) + if _params["bond"]._bond_id == -1: + raise Exception( + "The bonded interaction passed as 'bond' keyword argument has not yet been added to the list of active bonds in Espresso.") if _params["start_id"] < 0: raise ValueError( "start_id has to be a positive Integer") diff --git a/src/python/espressomd/reaction_ensemble.pyx b/src/python/espressomd/reaction_ensemble.pyx index 152687cdfee..32cefd42498 100644 --- a/src/python/espressomd/reaction_ensemble.pyx +++ b/src/python/espressomd/reaction_ensemble.pyx @@ -84,6 +84,7 @@ cdef class ReactionAlgorithm(object): """ self.RE.slab_start_z = slab_start_z self.RE.slab_end_z = slab_end_z + self.RE.box_has_wall_constraints=True def get_wall_constraints_in_z_direction(self): """ diff --git a/src/python/espressomd/reaction.pxd b/src/python/espressomd/swimmer_reaction.pxd similarity index 83% rename from src/python/espressomd/reaction.pxd rename to src/python/espressomd/swimmer_reaction.pxd index b1270e33623..4d99d45679f 100644 --- a/src/python/espressomd/reaction.pxd +++ b/src/python/espressomd/swimmer_reaction.pxd @@ -1,12 +1,12 @@ from __future__ import print_function, absolute_import include "myconfig.pxi" -IF CATALYTIC_REACTIONS: +IF SWIMMER_REACTIONS: cdef class Reaction: cdef _params cdef _ct_rate - cdef extern from "reaction.hpp": + cdef extern from "swimmer_reaction.hpp": void reactions_sanity_checks() void local_setup_reaction() void integrate_reaction() diff --git a/src/python/espressomd/reaction.pyx b/src/python/espressomd/swimmer_reaction.pyx similarity index 97% rename from src/python/espressomd/reaction.pyx rename to src/python/espressomd/swimmer_reaction.pyx index 7ea17ba681f..0123892cf73 100644 --- a/src/python/espressomd/reaction.pyx +++ b/src/python/espressomd/swimmer_reaction.pyx @@ -1,20 +1,20 @@ from __future__ import print_function, absolute_import include "myconfig.pxi" cimport globals -from . cimport reaction +from . cimport swimmer_reaction from . cimport utils from .highlander import ThereCanOnlyBeOne from espressomd.utils import is_valid_type -IF CATALYTIC_REACTIONS: +IF SWIMMER_REACTIONS: __reaction_is_initiated = False cdef class Reaction(object): """ - Class that handles catalytic reactions for self propelled particles. + Class that tries to mimic catalytic reactions for self propelled particles. .. note:: - Requires the features CATALYTIC_REACTIONS. + Requires the features SWIMMER_REACTIONS. Keep in mind, that there may be only one reaction enabled. There can be only one. @@ -46,7 +46,7 @@ IF CATALYTIC_REACTIONS: Notes ----- - Requires the features 'CATALYTIC_REACTIONS'. + Requires the features 'SWIMMER_REACTIONS'. """ def validate_params(self): diff --git a/src/python/espressomd/system.pyx b/src/python/espressomd/system.pyx index d4d255e7a46..9186ec2ff87 100755 --- a/src/python/espressomd/system.pyx +++ b/src/python/espressomd/system.pyx @@ -65,7 +65,7 @@ IF LEES_EDWARDS == 1: setable_properties.append("lees_edwards_offset") if VIRTUAL_SITES: - setable_properties.append("virtual_sites") + setable_properties.append("_active_virtual_sites_handle") cdef bool _system_created = False @@ -110,29 +110,28 @@ cdef class System(object): System.__setattr__(self, arg, kwargs.get(arg)) else: raise ValueError("Property {} can not be set via argument to System class.".format(arg)) - self.part = particle_data.ParticleList() - self.non_bonded_inter = interactions.NonBondedInteractions() - self.bonded_inter = interactions.BondedInteractions() - self.cell_system = CellSystem() - self.thermostat = Thermostat() - self.minimize_energy = MinimizeEnergy() self.actors = Actors(_system=self) self.analysis = Analysis(self) - self.galilei = GalileiTransform() - self.integrator = integrate.Integrator() - self.auto_update_correlators = AutoUpdateCorrelators() self.auto_update_accumulators = AutoUpdateAccumulators() + self.auto_update_correlators = AutoUpdateCorrelators() + self.bonded_inter = interactions.BondedInteractions() + self.cell_system = CellSystem() + IF COLLISION_DETECTION==1: + self.collision_detection = CollisionDetection() + self.comfixed = ComFixed() if CONSTRAINTS: self.constraints = Constraints() + IF CUDA: + self.cuda_init_handle = cuda_init.CudaInitHandle() + self.galilei = GalileiTransform() + self.integrator = integrate.Integrator() if LB_BOUNDARIES or LB_BOUNDARIES_GPU: self.lbboundaries = LBBoundaries() self.ekboundaries = EKBoundaries() - IF COLLISION_DETECTION==1: - self.collision_detection = CollisionDetection() - IF CUDA: - self.cuda_init_handle = cuda_init.CudaInitHandle() - - self.comfixed = ComFixed() + self.minimize_energy = MinimizeEnergy() + self.non_bonded_inter = interactions.NonBondedInteractions() + self.part = particle_data.ParticleList() + self.thermostat = Thermostat() IF VIRTUAL_SITES: self._active_virtual_sites_handle=ActiveVirtualSitesHandle(implementation=VirtualSitesOff()) _system_created = True @@ -145,6 +144,25 @@ cdef class System(object): odict = {} for property_ in setable_properties: odict[property_] = System.__getattribute__(self, property_) + odict['actors'] = System.__getattribute__(self, "actors") + odict['analysis'] = System.__getattribute__(self, "analysis") + odict['auto_update_accumulators'] = System.__getattribute__(self, "auto_update_accumulators") + odict['auto_update_correlators'] = System.__getattribute__(self, "auto_update_correlators") + odict['bonded_inter'] = System.__getattribute__(self, "bonded_inter") + odict['cell_system'] = System.__getattribute__(self, "cell_system") + odict['comfixed'] = System.__getattribute__(self, "comfixed") + IF CONSTRAINTS: + odict['constraints'] = System.__getattribute__(self, "constraints") + odict['galilei'] = System.__getattribute__(self, "galilei") + odict['integrator'] = System.__getattribute__(self, "integrator") + IF LB_BOUNDARIES or LB_BOUNDARIES_GPU: + odict['lbboundaries'] = System.__getattribute__(self, "lbboundaries") + odict['minimize_energy'] = System.__getattribute__(self, "minimize_energy") + odict['non_bonded_inter'] = System.__getattribute__(self, "non_bonded_inter") + odict['part'] = System.__getattribute__(self, "part") + odict['thermostat'] = System.__getattribute__(self, "thermostat") + IF VIRTUAL_SITES: + odict['_active_virtual_sites_handle'] = System.__getattribute__(self, "_active_virtual_sites_handle") return odict def __setstate__(self, params): diff --git a/src/python/espressomd/visualization_opengl.pyx b/src/python/espressomd/visualization_opengl.pyx index 548bfc76a19..da72195f8d3 100644 --- a/src/python/espressomd/visualization_opengl.pyx +++ b/src/python/espressomd/visualization_opengl.pyx @@ -2,19 +2,17 @@ from OpenGL.GLUT import * from OpenGL.GLU import * from OpenGL.GL import * from math import * -import math import numpy as np import os import time -import espressomd import collections import sys from threading import Thread - -import scipy.spatial +from matplotlib.pyplot import imsave include "myconfig.pxi" - from copy import deepcopy +import espressomd +from espressomd.particle_data import ParticleHandle class openGLLive(object): @@ -40,7 +38,11 @@ class openGLLive(object): draw_box : :obj:`bool`, optional Draw wireframe boundaries. draw_axis : :obj:`bool`, optional - Draws xyz system axes. + Draw xyz system axes. + draw_nodes : :obj:`bool`, optional + Draw node boxes. + draw_cells : :obj:`bool`, optional + Draw cell boxes. quality_particles : :obj:`int`, optional The number of subdivisions for particle spheres. quality_bonds : :obj:`int`, optional @@ -111,6 +113,8 @@ class openGLLive(object): List of scale factors of external force arrows for different particle types. ext_force_arrows_type_colors : array_like :obj:`float`, optional Colors of ext_force arrows for different particle types. + ext_force_arrows_type_materials : array_like :obj:`float`, optional + Materils of ext_force arrows for different particle types. ext_force_arrows_type_radii : array_like :obj:`float`, optional List of arrow radii for different particle types. force_arrows : :obj:`bool`, optional @@ -119,6 +123,8 @@ class openGLLive(object): List of scale factors of particle force arrows for different particle types. force_arrows_type_colors : array_like :obj:`float`, optional Colors of particle force arrows for different particle types. + force_arrows_type_materials : array_like :obj:`float`, optional + Materials of particle force arrows for different particle types. force_arrows_type_radii : array_like :obj:`float`, optional List of arrow radii for different particle types. velocity_arrows : :obj:`bool`, optional @@ -127,6 +133,8 @@ class openGLLive(object): List of scale factors of particle velocity arrows for different particle types. velocity_arrows_type_colors : array_like :obj:`float`, optional Colors of particle velocity arrows for different particle types. + velocity_arrows_type_materials : array_like :obj:`float`, optional + Materials of particle velocity arrows for different particle types. velocity_arrows_type_radii : array_like :obj:`float`, optional List of arrow radii for different particle types. director_arrows : :obj:`bool`, optional @@ -135,12 +143,23 @@ class openGLLive(object): Scale factor of particle director arrows for different particle types. director_arrows_type_colors : array_like :obj:`float`, optional Colors of particle director arrows for different particle types. + director_arrows_type_materials : array_like :obj:`float`, optional + Materials of particle director arrows for different particle types. director_arrows_type_radii : array_like :obj:`float`, optional List of arrow radii for different particle types. drag_enabled : :obj:`bool`, optional Enables mouse-controlled particles dragging (Default: False) drag_force : :obj:`bool`, optional Factor for particle dragging + + LB_draw_nodes : :obj:`bool`, optional + Draws a lattice representation of the LB nodes that are no boundaries. + LB_draw_node_boundaries : :obj:`bool`, optional + Draws a lattice representation of the LB nodes that are boundaries. + LB_draw_boundaries : :obj:`bool`, optional + Draws the LB shapes. + LB_draw_velocity_plane : :obj:`bool`, optional + Draws LB node velocity arrows specified by LB_plane_axis, LB_plane_dist, LB_plane_ngrid. light_pos : array_like :obj:`float`, optional If auto (default) is used, the light is placed dynamically in the particle barycenter of the system. Otherwise, a fixed @@ -170,104 +189,108 @@ class openGLLive(object): def __init__(self, system, **kwargs): # MATERIALS self.materials = { - 'bright': [[0.9, 0.9, 0.9], [1.0, 1.0, 1.0], [0.8, 0.8, 0.8], 0.6], - 'medium': [[0.6, 0.6, 0.6], [0.8, 0.8, 0.8], [0.2, 0.2, 0.2], 0.5], - 'dark': [[0.4, 0.4, 0.4], [0.5, 0.5, 0.5], [0.1, 0.1, 0.1], 0.4], - 'bluerubber': [[0, 0, 0.05], [0.4, 0.4, 0.5], [0.04, 0.04, 0.7], 0.078125], - 'redrubber': [[0.05, 0, 0], [0.5, 0.4, 0.4], [0.7, 0.04, 0.04], 0.078125], - 'yellowrubber': [[0.05, 0.05, 0], [0.5, 0.5, 0.4], [0.7, 0.7, 0.04], 0.078125], - 'greenrubber': [[0, 0.05, 0], [0.4, 0.5, 0.4], [0.04, 0.7, 0.04], 0.078125], - 'whiterubber': [[0.05, 0.05, 0.05], [0.5, 0.5, 0.5], [0.7, 0.7, 0.7], 0.078125], - 'cyanrubber': [[0, 0.05, 0.05], [0.4, 0.5, 0.5], [0.04, 0.7, 0.7], 0.078125], - 'blackrubber': [[0.02, 0.02, 0.02], [0.01, 0.01, 0.01], [0.4, 0.4, 0.4], 0.078125], - 'emerald': [[0.0215, 0.1745, 0.0215], [0.07568, 0.61424, 0.07568], [0.633, 0.727811, 0.633], 0.6], - 'jade': [[0.135, 0.2225, 0.1575], [0.54, 0.89, 0.63], [0.316228, 0.316228, 0.316228], 0.1], - 'obsidian': [[0.05375, 0.05, 0.06625], [0.18275, 0.17, 0.22525], [0.332741, 0.328634, 0.346435], 0.3], - 'pearl': [[0.25, 0.20725, 0.20725], [1, 0.829, 0.829], [0.296648, 0.296648, 0.296648], 0.088], - 'ruby': [[0.1745, 0.01175, 0.01175], [0.61424, 0.04136, 0.04136], [0.727811, 0.626959, 0.626959], 0.6], - 'turquoise': [[0.1, 0.18725, 0.1745], [0.396, 0.74151, 0.69102], [0.297254, 0.30829, 0.306678], 0.1], - 'brass': [[0.329412, 0.223529, 0.027451], [0.780392, 0.568627, 0.113725], [0.992157, 0.941176, 0.807843], 0.21794872], - 'bronze': [[0.2125, 0.1275, 0.054], [0.714, 0.4284, 0.18144], [0.393548, 0.271906, 0.166721], 0.2], - 'chrome': [[0.25, 0.25, 0.25], [0.4, 0.4, 0.4], [0.774597, 0.774597, 0.774597], 0.6], - 'copper': [[0.19125, 0.0735, 0.0225], [0.7038, 0.27048, 0.0828], [0.256777, 0.137622, 0.086014], 0.1], - 'gold': [[0.24725, 0.1995, 0.0745], [0.75164, 0.60648, 0.22648], [0.628281, 0.555802, 0.366065], 0.4], - 'silver': [[0.19225, 0.19225, 0.19225], [0.50754, 0.50754, 0.50754], [0.508273, 0.508273, 0.508273], 0.4], - 'blackplastic': [[0, 0, 0], [0.01, 0.01, 0.01], [0.5, 0.5, 0.5], 0.25], - 'cyanplastic': [[0, 0.1, 0.06], [0, 0.50980392, 0.50980392], [0.50196078, 0.50196078, 0.50196078], 0.25], - 'greenplastic': [[0, 0, 0], [0.1, 0.35, 0.1], [0.45, 0.55, 0.45], 0.25], - 'redplastic': [[0, 0, 0], [0.5, 0, 0], [0.7, 0.6, 0.6], 0.25], - 'whiteplastic': [[0, 0, 0], [0.55, 0.55, 0.55], [0.7, 0.7, 0.7], 0.25], - 'yellowplastic': [[0, 0, 0], [0.5, 0.5, 0], [0.6, 0.6, 0.5], 0.25]} + 'bright': [0.9, 1.0, 0.8, 0.4, 1.0], + 'medium': [0.6, 0.8, 0.2, 0.4, 1.0], + 'dark': [0.4, 0.5, 0.1, 0.4, 1.0], + 'transparent1': [0.6, 0.8, 0.2, 0.5, 0.8], + 'transparent2': [0.6, 0.8, 0.2, 0.5, 0.4], + 'transparent3': [0.6, 0.8, 0.2, 0.5, 0.2], + 'rubber': [0, 0.4, 0.7, 0.078125, 1.0], + 'chrome': [0.25, 0.4, 0.774597, 0.6, 1.0], + 'plastic': [0, 0.55, 0.7, 0.25, 1.0], + 'steel': [0.25, 0.38, 0, 0.32, 1.0] + } # DEFAULT PROPERTIES self.specs = { 'window_size': [800, 800], 'name': 'Espresso Visualization', + 'background_color': [0, 0, 0], - 'update_fps': 30.0, - 'periodic_images': [0, 0, 0], + + 'draw_fps': False, 'draw_box': True, 'draw_axis': True, + 'draw_nodes': False, + 'draw_cells': False, + + 'update_fps': 30, + + 'periodic_images': [0, 0, 0], + 'quality_particles': 20, 'quality_bonds': 16, 'quality_arrows': 16, 'quality_constraints': 32, + 'close_cut_distance': 0.1, 'far_cut_distance': 5, + 'camera_position': 'auto', 'camera_target': 'auto', 'camera_right': [1.0, 0.0, 0.0], 'particle_coloring': 'auto', 'particle_sizes': 'auto', - 'particle_type_colors': [[1, 1, 0, 1], [1, 0, 1, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 1, 1], [1, 0.5, 0, 1], [0.5, 0, 1, 1]], + 'particle_type_colors': [[1, 1, 0], [1, 0, 1], [0, 0, 1], [0, 1, 1], [1, 1, 1], [1, 0.5, 0], [0.5, 0, 1]], 'particle_type_materials': ['medium'], - 'particle_charge_colors': [[1, 0, 0, 1], [0, 1, 0, 1]], + 'particle_charge_colors': [[1, 0, 0], [0, 1, 0]], 'draw_constraints': True, 'rasterize_pointsize': 10, 'rasterize_resolution': 75.0, - 'constraint_type_colors': [[0.5, 0.5, 0.5, 0.9], [0, 0.5, 0.5, 0.9], [0.5, 0, 0.5, 0.9], [0.5, 0.5, 0, 0.9], [0, 0, 0.5, 0.9], [0.5, 0, 0, 0.9]], - 'constraint_type_materials': ['medium'], + 'constraint_type_colors': [[0.5, 0.5, 0.5], [0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0], [0, 0, 0.5], [0.5, 0, 0]], + 'constraint_type_materials': ['transparent1'], 'draw_bonds': True, 'bond_type_radius': [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5], - 'bond_type_colors': [[1, 1, 1, 1], [1, 0, 1, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 0.5, 0, 1], [0.5, 0, 1, 1]], + 'bond_type_colors': [[1, 1, 1], [1, 0, 1], [0, 0, 1], [0, 1, 1], [1, 1, 0], [1, 0.5, 0], [0.5, 0, 1]], 'bond_type_materials': ['medium'], 'ext_force_arrows': False, 'ext_force_arrows_type_scale': [1.0], - 'ext_force_arrows_type_colors': [[1, 1, 1, 1], [1, 0, 1, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 0.5, 0, 1], [0.5, 0, 1, 1]], + 'ext_force_arrows_type_colors': [[1, 1, 1], [1, 0, 1], [0, 0, 1], [0, 1, 1], [1, 1, 0], [1, 0.5, 0], [0.5, 0, 1]], + 'ext_force_arrows_type_materials': ['transparent2'], 'ext_force_arrows_type_radii': [0.2], - + 'velocity_arrows': False, 'velocity_arrows_type_scale': [1.0], - 'velocity_arrows_type_colors': [[1, 1, 1, 1], [1, 0, 1, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 0.5, 0, 1], [0.5, 0, 1, 1]], + 'velocity_arrows_type_colors': [[1, 1, 1], [1, 0, 1], [0, 0, 1], [0, 1, 1], [1, 1, 0], [1, 0.5, 0], [0.5, 0, 1]], + 'velocity_arrows_type_materials': ['transparent2'], 'velocity_arrows_type_radii': [0.2], - + 'force_arrows': False, 'force_arrows_type_scale': [1.0], - 'force_arrows_type_colors': [[1, 1, 1, 1], [1, 0, 1, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 0.5, 0, 1], [0.5, 0, 1, 1]], + 'force_arrows_type_colors': [[1, 1, 1], [1, 0, 1], [0, 0, 1], [0, 1, 1], [1, 1, 0], [1, 0.5, 0], [0.5, 0, 1]], + 'force_arrows_type_materials': ['transparent2'], 'force_arrows_type_radii': [0.2], 'director_arrows': False, 'director_arrows_type_scale': [1.0], - 'director_arrows_type_colors': [[1, 1, 1, 1], [1, 0, 1, 1], [0, 0, 1, 1], [0, 1, 1, 1], [1, 1, 0, 1], [1, 0.5, 0, 1], [0.5, 0, 1, 1]], + 'director_arrows_type_colors': [[1, 1, 1], [1, 0, 1], [0, 0, 1], [0, 1, 1], [1, 1, 0], [1, 0.5, 0], [0.5, 0, 1]], + 'director_arrows_type_materials': ['transparent2'], 'director_arrows_type_radii': [0.2], - 'LB': False, + 'LB_draw_nodes': False, + 'LB_draw_node_boundaries': False, + 'LB_draw_boundaries': False, + + 'LB_draw_velocity_plane': False, 'LB_plane_axis': 2, 'LB_plane_dist': 0, 'LB_plane_ngrid': 5, 'LB_vel_scale': 1.0, + 'LB_arrow_color': [1, 1, 1], + 'LB_arrow_material': 'transparent1', + 'LB_arrow_quality': 16, 'light_pos': 'auto', - 'light_colors': [[0.1, 0.1, 0.2, 1.0], [0.9, 0.9, 0.9, 1.0], [1.0, 1.0, 1.0, 1.0]], + 'light_colors': [[0.1, 0.1, 0.2], [0.9, 0.9, 0.9], [1.0, 1.0, 1.0]], 'light_brightness': 1.0, 'light_size': 'auto', - 'spotlight_enabled': True, - 'spotlight_colors': [[0.2, 0.2, 0.3, 1.0], [0.5, 0.5, 0.5, 1.0], [1.0, 1.0, 1.0, 1.0]], + 'spotlight_enabled': False, + 'spotlight_colors': [[0.2, 0.2, 0.3], [0.5, 0.5, 0.5], [1.0, 1.0, 1.0]], 'spotlight_angle': 45, 'spotlight_focus': 1, 'spotlight_brightness': 0.6, @@ -292,48 +315,175 @@ class openGLLive(object): IF not ROTATION: self.specs['director_arrows'] = False + IF not CONSTRAINTS: + self.specs['draw_constraints'] = False + + IF not LB and not LB_GPU: + self.specs['LB_draw_velocity_plane'] = False + self.specs['LB_draw_boundaries'] = False + self.specs['LB_draw_nodes'] = False + self.specs['LB_draw_node_boundaries'] = False + + IF not LB_BOUNDARIES and not LB_BOUNDARIES_GPU: + self.specs['LB_draw_boundaries'] = False + self.specs['LB_draw_node_boundaries'] = False + + # ESPRESSO RELATED INITS THAT ARE KNOWN ONLY WHEN RUNNING THE + # INTEGRATION LOOP ARE CALLED ONCE IN UPDATE LOOP: + # CONSTRAINTS, NODE BOXES, CELL BOXES, CHARGE RANGE, BONDS + + # ESPRESSO RELATED INITS THAT ARE KNOWN ON INSTANTIATION GO HERE: + # CONTENT OF PARTICLE DATA self.has_particle_data = {} self.has_particle_data['velocity'] = self.specs['velocity_arrows'] self.has_particle_data['force'] = self.specs['force_arrows'] self.has_particle_data['ext_force'] = self.specs['ext_force_arrows'] or self.specs['drag_enabled'] IF ELECTROSTATICS: - self.has_particle_data['charge'] = self.specs['particle_coloring'] == 'auto' or self.specs['particle_coloring'] == 'charge' - ELSE: + self.has_particle_data['charge'] = self.specs['particle_coloring'] == 'auto' or self.specs['particle_coloring'] == 'charge' + ELSE: self.has_particle_data['charge'] = False self.has_particle_data['director'] = self.specs['director_arrows'] self.has_particle_data['node'] = self.specs['particle_coloring'] == 'node' - # CALC INVERSE BACKGROUND COLOR FOR BOX + # PARTICLE INFO OF HIGHLIGHTED PARTICLE: COLLECT PARTICLE ATTRIBUTES + self.highlighted_particle = {} + self.particle_attributes = [] + for d in dir(ParticleHandle): + if type(getattr(ParticleHandle, d)) == type(ParticleHandle.pos): + if not d in ["pos_folded"]: + self.particle_attributes.append(d) + self.max_len_attr = max([len(a) for a in self.particle_attributes]) + + # FIXED COLORS FROM INVERSE BACKGROUND COLOR FOR GOOD CONTRAST self.invBackgroundCol = np.array([1 - self.specs['background_color'][0], 1 - - self.specs['background_color'][1], 1 - self.specs['background_color'][2]]) + self.specs['background_color'][1], 1 - self.specs['background_color'][2], 1.0]) + + self.node_box_color = np.copy(self.invBackgroundCol) + self.node_box_color[0] += 0.5 * (0.5 - self.node_box_color[0]) + + self.cell_box_color = np.copy(self.invBackgroundCol) + self.cell_box_color[1] += 0.5 * (0.5 - self.cell_box_color[1]) + + self.lb_box_color = np.copy(self.invBackgroundCol) + self.lb_box_color[2] = 0.5 + + self.lb_box_color_boundary = np.copy(self.invBackgroundCol) + self.lb_box_color_boundary[1] = 0.5 + + self.text_color = np.copy(self.invBackgroundCol) + + # INCREASE LINE THICKNESS IF NODE/CELL BOX IS ENABLED + self.line_width_fac = 1.0 + if self.specs['draw_nodes']: + self.line_width_fac += 0.5 + if self.specs['draw_cells']: + self.line_width_fac += 0.5 + + # HAS PERIODIC IMAGES + self.has_images = any(i != 0 for i in self.specs['periodic_images']) + # INITS self.system = system - self.started = False + + self.last_T = -1 + self.last_box_l = self.system.box_l + self.fps_last = 0 + self.fps = 0 + self.fps_count = 0 + + self.glutMainLoop_started = False + self.screenshot_initialized = False + self.hasParticleData = False self.quit_savely = False + self.paused = False + self.take_screenshot = False + self.screenshot_captured = False + self.keyboardManager = KeyboardManager() self.mouseManager = MouseManager() + self.camera = Camera() + self._init_camera() + self.timers = [] self.particles = {} + self.update_elapsed = 0 + self.update_timer = 0 + self.draw_elapsed = 0 + self.draw_timer = 0 + + def register_callback(self, cb, interval=1000): """Register timed callbacks. """ self.timers.append((int(interval), cb)) + def screenshot(self, path): + """Renders the current state and into an image file at path with dimensions of + specs['window_size']. """ + + # ON FIRST CALL: INIT AND CREATE BUFFERS + if not self.screenshot_initialized: + self.screenshot_initialized = True + self._init_opengl() + + # CREATE BUFFERS THAT CAN BE LARGER THAN THE SCREEN + # FRAME BUFFER + fbo = glGenFramebuffers(1) + glBindFramebuffer(GL_FRAMEBUFFER, fbo ) + # COLOR BUFFER + rbo = glGenRenderbuffers(1) + glBindRenderbuffer(GL_RENDERBUFFER, rbo) + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, self.specs['window_size'][0], self.specs['window_size'][1]); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo) + # DEPTH BUFFER + dbo = glGenRenderbuffers(1) + glBindRenderbuffer(GL_RENDERBUFFER, dbo) + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, self.specs['window_size'][0], self.specs['window_size'][1]) + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, dbo) + + self._reshape_window(self.specs['window_size'][0], self.specs['window_size'][1]) + glutHideWindow() + + # INIT AND UPDATE ESPRESSO + self._init_espresso_visualization() + self._initial_espresso_updates() + + # DRAW + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + glLoadMatrixf(self.camera.modelview) + self._draw_system() + + # READ THE PIXES + glReadBuffer(GL_COLOR_ATTACHMENT0) + data = glReadPixels(0, 0, self.specs['window_size'][0], self.specs['window_size'][1], GL_RGB, GL_FLOAT) + + # RESHAPE THE DATA + data = np.flipud(data.reshape((data.shape[1],data.shape[0],3))) + + # SAVE TO IMAGE + imsave(path, data) + def run(self, integ_steps=1): """Convenience method with a simple integration thread. """ def main(): while True: - try: - self.system.integrator.run(integ_steps) - self.update() - except Exception as e: - print(e) - os._exit(1) + + self.update() + + if self.paused: + # sleep(0) is worse + time.sleep(0.0001) + else: + try: + self.system.integrator.run(integ_steps) + except Exception as e: + print(e) + os._exit(1) t = Thread(target=main) t.daemon = True @@ -345,82 +495,59 @@ class openGLLive(object): """The blocking start method. """ - self.init_opengl() - self.init_espresso_visualization() - self.init_camera() - self.init_controls() - self.init_callbacks() - - # POST DISPLAY WITH 60FPS - def timed_update_redraw(data): - glutPostRedisplay() - self.keyboardManager.handle_input() - glutTimerFunc(17, timed_update_redraw, -1) - - # PLACE LIGHT AT PARTICLE CENTER, DAMPED SPRING FOR SMOOTH POSITION - # CHANGE, CALL WITH 10FPS - def timed_update_centerLight(data): - if self.hasParticleData: - ldt = 0.8 - cA = (self.particle_COM - self.smooth_light_pos) * \ - 0.1 - self.smooth_light_posV * 1.8 - self.smooth_light_posV += ldt * cA - self.smooth_light_pos += ldt * self.smooth_light_posV - self.updateLightPos = True - glutTimerFunc(100, timed_update_centerLight, -1) - - # AVERAGE PARTICLE COM ONLY EVERY 2sec - def timed_update_particleCOM(data): - if self.hasParticleData: - if len(self.particles['pos']) > 0: - self.particle_COM = np.average( - self.particles['pos'], axis=0) - glutTimerFunc(2000, timed_update_particleCOM, -1) - - self.started = True - self.hasParticleData = False - - glutTimerFunc(17, timed_update_redraw, -1) + self._init_opengl() + self._init_espresso_visualization() + self._init_controls() + self._init_openGL_callbacks() + self._init_timers() + self._init_camera() - if self.specs['light_pos'] == 'auto': - glutTimerFunc(2000, timed_update_particleCOM, -1) - glutTimerFunc(60, timed_update_centerLight, -1) # START THE BLOCKING MAIN LOOP + self.glutMainLoop_started = True glutMainLoop() + def update(self): """Update method to be called after integration. Changes of espresso system can only happen here. """ - if self.started: + if self.glutMainLoop_started: # UPDATE ON STARTUP if not self.hasParticleData: - self.update_particles() - if self.has_particle_data['charge']: - self.update_charge_color_range() - self.update_bonds() - IF CONSTRAINTS: - self.update_constraints() + self._initial_espresso_updates() self.hasParticleData = True - # IF CALLED TOO OFTEN, ONLY UPDATE WITH GIVEN FREQ - self.elapsedTime += (time.time() - self.measureTimeBeforeIntegrate) - if self.elapsedTime > 1.0 / self.specs['update_fps']: - self.elapsedTime = 0 - self.update_particles() - if self.specs['LB']: - self.update_lb() + # UPDATES + self.update_elapsed += (time.time() - self.update_timer) + if self.update_elapsed > 1.0 / self.specs['update_fps']: + self.update_elapsed = 0 + + # ES UPDATES WHEN SYSTEM HAS PROPAGATED. ALSO UPDATE ON PAUSE FOR PARTICLE INFO + if self.paused or not self.last_T == self.system.time: + self.last_T = self.system.time + self._update_particles() + + # LB UPDATE + if self.specs['LB_draw_velocity_plane']: + self._update_lb_velocity_plane() + + # BOX_L CHANGED + if not (self.last_box_l == self.system.box_l).all(): + self.last_box_l = np.copy(self.system.box_l) + self._box_size_dependence() + # KEYBOARD CALLBACKS MAY CHANGE ESPRESSO SYSTEM PROPERTIES, # ONLY SAVE TO CHANGE HERE for c in self.keyboardManager.userCallbackStack: c() self.keyboardManager.userCallbackStack = [] - self.measureTimeBeforeIntegrate = time.time() + self.update_timer = time.time() - IF EXTERNAL_FORCES: + # DRAG PARTICLES + if self.specs['drag_enabled']: if self.triggerSetParticleDrag == True and self.dragId != -1: self.system.part[self.dragId].ext_force = self.dragExtForce self.triggerSetParticleDrag = False @@ -434,8 +561,21 @@ class openGLLive(object): if self.quit_savely: os._exit(1) + # FETCH DATA ON STARTUP + def _initial_espresso_updates(self): + self._update_particles() + if self.has_particle_data['charge']: + self._update_charge_color_range() + self._update_bonds() + if self.specs['draw_constraints']: + self._update_constraints() + if self.specs['draw_cells'] or self.specs['draw_nodes']: + self._update_nodes() + if self.specs['draw_cells']: + self._update_cells() + # GET THE PARTICLE DATA - def update_particles(self): + def _update_particles(self): self.particles['pos'] = self.system.part[:].pos_folded self.particles['type'] = self.system.part[:].type @@ -458,7 +598,18 @@ class openGLLive(object): if self.has_particle_data['node']: self.particles['node'] = self.system.part[:].node - def update_lb(self): + if self.infoId != -1: + for attr in self.particle_attributes: + self.highlighted_particle[attr] = getattr( + self.system.part[self.infoId], attr) + + def _update_lb_velocity_plane(self): + if self.lb_is_cpu: + self._update_lb_velocity_plane_CPU() + else: + self._update_lb_velocity_plane_GPU() + + def _update_lb_velocity_plane_CPU(self): agrid = self.lb_params['agrid'] self.lb_plane_vel = [] ng = self.specs['LB_plane_ngrid'] @@ -470,8 +621,23 @@ class openGLLive(object): lb_vel = np.copy(self.lb[i, j, k].velocity) self.lb_plane_vel.append([pp, lb_vel]) - def edges_from_pn(self, p, n, diag): - v1, v2 = self.get_tangents(n) + def _update_lb_velocity_plane_GPU(self): + agrid = self.lb_params['agrid'] + ng = self.specs['LB_plane_ngrid'] + col_pos = [] + for xi in xrange(ng): + for xj in xrange(ng): + p = np.array((self.lb_plane_p + xi * 1.0 / ng * self.lb_plane_b1 + + xj * 1.0 / ng * self.lb_plane_b2) % self.system.box_l) + col_pos.append(p) + + lb_vels = self.lb.get_interpolated_fluid_velocity_at_positions(np.array(col_pos)) + self.lb_plane_vel = [] + for p, v in zip(col_pos, lb_vels): + self.lb_plane_vel.append([p, v]) + + def _edges_from_pn(self, p, n, diag): + v1, v2 = self._get_tangents(n) edges = [] edges.append(p + diag * v1) @@ -480,8 +646,28 @@ class openGLLive(object): edges.append(p - diag * v2) return edges - # GET THE update_constraints DATA - def update_constraints(self): + def _update_cells(self): + self.cell_box_origins = [] + cell_system_state = self.system.cell_system.get_state() + self.cell_size = cell_system_state['cell_size'] + for i in range(cell_system_state['cell_grid'][0]): + for j in range(cell_system_state['cell_grid'][1]): + for k in range(cell_system_state['cell_grid'][2]): + self.cell_box_origins.append( + np.array([i, j, k]) * self.cell_size) + + def _update_nodes(self): + self.node_box_origins = [] + self.local_box_l = self.system.cell_system.get_state()['local_box_l'] + for i in range(self.system.cell_system.node_grid[0]): + for j in range(self.system.cell_system.node_grid[1]): + for k in range(self.system.cell_system.node_grid[2]): + self.node_box_origins.append( + np.array([i, j, k]) * self.local_box_l) + + + # GET THE _update_constraints DATA + def _update_constraints(self): box_diag = pow(pow(self.system.box_l[0], 2) + pow( self.system.box_l[1], 2) + pow(self.system.box_l[1], 2), 0.5) @@ -489,22 +675,36 @@ class openGLLive(object): self.shapes = collections.defaultdict(list) # Collect shapes and interaction type (for coloring) from constraints + primitive_shapes = ['Shapes::Wall', 'Shapes::Cylinder', 'Shapes::Ellipsoid', 'Shapes::SimplePore', 'Shapes::Sphere', 'Shapes::SpheroCylinder'] + coll_shape_obj = collections.defaultdict(list) for c in self.system.constraints: if type(c) == espressomd.constraints.ShapeBasedConstraint: t = c.get_parameter('particle_type') s = c.get_parameter('shape') n = s.name() - if n in ['Shapes::Wall', 'Shapes::Cylinder', 'Shapes::Ellipsoid', 'Shapes::Sphere', 'Shapes::SpheroCylinder']: + if n in primitive_shapes: coll_shape_obj[n].append([s, t]) else: coll_shape_obj['Shapes::Misc'].append([s, t]) - # TODO: get shapes from lbboundaries + if self.specs['LB_draw_boundaries']: + ni = 0 + for c in self.system.lbboundaries: + if type(c) == espressomd.ekboundaries.EKBoundary: + t = ni + ni += 1 + s = c.get_parameter('shape') + n = s.name() + if n in primitive_shapes: + coll_shape_obj[n].append([s, t]) + else: + coll_shape_obj['Shapes::Misc'].append([s, t]) + for s in coll_shape_obj['Shapes::Wall']: d = s[0].get_parameter('dist') n = s[0].get_parameter('normal') - edges = self.edges_from_pn(d * np.array(n), n, 2 * box_diag) + edges = self._edges_from_pn(d * np.array(n), n, 2 * box_diag) self.shapes['Shapes::Wall'].append([edges, s[1]]) for s in coll_shape_obj['Shapes::Cylinder']: @@ -527,6 +727,15 @@ class openGLLive(object): r = s[0].get_parameter('radius') self.shapes['Shapes::Sphere'].append([pos, r, s[1]]) + for s in coll_shape_obj['Shapes::SimplePore']: + center = np.array(s[0].get_parameter('center')) + axis = np.array(s[0].get_parameter('axis')) + length = np.array(s[0].get_parameter('length')) + radius = np.array(s[0].get_parameter('radius')) + smoothing_radius = np.array(s[0].get_parameter('smoothing_radius')) + self.shapes['Shapes::SimplePore'].append( + [center, axis, length, radius, smoothing_radius, s[1]]) + for s in coll_shape_obj['Shapes::SpheroCylinder']: pos = np.array(s[0].get_parameter('center')) a = np.array(s[0].get_parameter('axis')) @@ -537,9 +746,9 @@ class openGLLive(object): for s in coll_shape_obj['Shapes::Misc']: self.shapes['Shapes::Misc'].append( - [self.rasterize_brute_force(s[0]), s[1]]) + [self._rasterize_brute_force(s[0]), s[1]]) - def get_tangents(self, n): + def _get_tangents(self, n): n = np.array(n) v1 = np.random.randn(3) v1 -= v1.dot(n) * n / np.linalg.norm(n)**2 @@ -548,7 +757,7 @@ class openGLLive(object): v2 /= np.linalg.norm(v2) return v1, v2 - def rasterize_brute_force(self, shape): + def _rasterize_brute_force(self, shape): sp = max(self.system.box_l) / self.specs['rasterize_resolution'] res = np.array(self.system.box_l) / sp @@ -564,11 +773,10 @@ class openGLLive(object): return points # GET THE BOND DATA, SO FAR CALLED ONCE UPON INITIALIZATION - def update_bonds(self): + def _update_bonds(self): if self.specs['draw_bonds']: self.bonds = [] for i in range(len(self.system.part)): - bs = self.system.part[i].bonds for b in bs: t = b[0].type_number() @@ -576,13 +784,16 @@ class openGLLive(object): for p in b[1:]: self.bonds.append([i, p, t]) - # DRAW CALLED AUTOMATICALLY FROM GLUT DISPLAY FUNC - def draw(self): + def _draw_text(self, x, y, text, color, font=GLUT_BITMAP_9_BY_15): + glColor(color) + glWindowPos2f(x, y) + for ch in text: + glutBitmapCharacter(font, ctypes.c_int(ord(ch))) - if self.specs['LB']: - self.draw_lb_vel() - if self.specs['draw_box']: - self.draw_system_box() + # DRAW CALLED AUTOMATICALLY FROM GLUT DISPLAY FUNC + def _draw_system(self): + if self.specs['LB_draw_velocity_plane']: + self._draw_lb_vel() if self.specs['draw_axis']: axis_fac = 0.2 @@ -594,56 +805,92 @@ class openGLLive(object): draw_arrow([0, 0, 0], [0, 0, self.system.box_l[2] * axis_fac], axis_r, [ 0, 0, 1, 1], self.materials['chrome'], self.specs['quality_arrows']) - if self.hasParticleData: - self.draw_system_particles() - if self.specs['draw_bonds']: - self.draw_bonds() - - IF CONSTRAINTS: - if self.specs['draw_constraints']: - self.draw_constraints() - - def draw_system_box(self): - draw_box([0, 0, 0], self.system.box_l, self.invBackgroundCol) + if self.specs['draw_bonds']: + self._draw_bonds() + self._draw_system_particles() - def draw_constraints(self): + if self.specs['draw_constraints']: + self._draw_constraints() + + if self.specs['draw_box']: + self._draw_system_box() + if self.specs['draw_nodes']: + self._draw_nodes() + if self.specs['draw_cells']: + self._draw_cells() + if self.specs['LB_draw_nodes'] or self.specs['LB_draw_node_boundaries']: + self._draw_lb_grid() + + def _draw_system_box(self): + draw_box([0, 0, 0], self.system.box_l, + self.invBackgroundCol, self.materials['medium'], 2.0 * self.line_width_fac) + + def _draw_nodes(self): + for n in self.node_box_origins: + draw_box(n, self.local_box_l, self.node_box_color, self.materials['transparent1'], + 1.5 * self.line_width_fac) + + def _draw_cells(self): + for n in self.node_box_origins: + for c in self.cell_box_origins: + draw_box(c + n, self.cell_size, self.cell_box_color, self.materials['transparent1'], + 0.75 * self.line_width_fac) + + def _draw_lb_grid(self): + a = self.lb_params['agrid'] + cell_size = np.array([a]*3) + dims = np.rint(np.array(self.system.box_l) / a) + for i in range(int(dims[0])): + for j in range(int(dims[1])): + for k in range(int(dims[2])): + n = np.array([i, j, k]) * cell_size + if self.specs['LB_draw_node_boundaries'] and self.lb[i,j,k].boundary: + draw_box(n, cell_size, self.lb_box_color_boundary, self.materials['transparent2'], 5.0) + if self.specs['LB_draw_nodes'] and not self.lb[i,j,k].boundary: + draw_box(n, cell_size, self.lb_box_color, self.materials['transparent2'], 1.5) + + def _draw_constraints(self): for i in range(6): glEnable(GL_CLIP_PLANE0 + i) glClipPlane(GL_CLIP_PLANE0 + i, self.box_eqn[i]) for s in self.shapes['Shapes::Ellipsoid']: - draw_ellipsoid(s[0], s[1], s[2], s[3], self.modulo_indexing(self.specs['constraint_type_colors'], s[4]), - self.materials[self.modulo_indexing(self.specs['constraint_type_materials'], s[4])], self.specs['quality_constraints']) + draw_ellipsoid(s[0], s[1], s[2], s[3], self._modulo_indexing(self.specs['constraint_type_colors'], s[4]), + self.materials[self._modulo_indexing(self.specs['constraint_type_materials'], s[4])], self.specs['quality_constraints']) + + for s in self.shapes['Shapes::SimplePore']: + draw_simple_pore(s[0], s[1], s[2], s[3], s[4], max(self.system.box_l), self._modulo_indexing(self.specs['constraint_type_colors'], s[5]), + self.materials[self._modulo_indexing(self.specs['constraint_type_materials'], s[5])], self.specs['quality_constraints']) for s in self.shapes['Shapes::Sphere']: - draw_sphere(s[0], s[1], self.modulo_indexing(self.specs['constraint_type_colors'], s[2]), self.materials[self.modulo_indexing( + draw_sphere(s[0], s[1], self._modulo_indexing(self.specs['constraint_type_colors'], s[2]), self.materials[self._modulo_indexing( self.specs['constraint_type_materials'], s[2])], self.specs['quality_constraints']) for s in self.shapes['Shapes::SpheroCylinder']: draw_sphero_cylinder( - s[0], s[1], s[2], self.modulo_indexing( + s[0], s[1], s[2], self._modulo_indexing( self.specs['constraint_type_colors'], s[3]), - self.materials[self.modulo_indexing(self.specs['constraint_type_materials'], s[3])], self.specs['quality_constraints']) + self.materials[self._modulo_indexing(self.specs['constraint_type_materials'], s[3])], self.specs['quality_constraints']) for s in self.shapes['Shapes::Wall']: draw_plane( - s[0], self.modulo_indexing( + s[0], self._modulo_indexing( self.specs['constraint_type_colors'], s[1]), - self.materials[self.modulo_indexing(self.specs['constraint_type_materials'], s[1])]) + self.materials[self._modulo_indexing(self.specs['constraint_type_materials'], s[1])]) for s in self.shapes['Shapes::Cylinder']: - draw_cylinder(s[0], s[1], s[2], self.modulo_indexing(self.specs['constraint_type_colors'], s[3]), self.materials[self.modulo_indexing( + draw_cylinder(s[0], s[1], s[2], self._modulo_indexing(self.specs['constraint_type_colors'], s[3]), self.materials[self._modulo_indexing( self.specs['constraint_type_materials'], s[3])], self.specs['quality_constraints'], True) for s in self.shapes['Shapes::Misc']: - draw_points(s[0], self.specs['rasterize_pointsize'], self.modulo_indexing( - self.specs['constraint_type_colors'], s[1]), self.materials[self.modulo_indexing(self.specs['constraint_type_materials'], s[1])]) + draw_points(s[0], self.specs['rasterize_pointsize'], self._modulo_indexing( + self.specs['constraint_type_colors'], s[1]), self.materials[self._modulo_indexing(self.specs['constraint_type_materials'], s[1])]) for i in range(6): glDisable(GL_CLIP_PLANE0 + i) - def determine_radius(self, ptype): + def _determine_radius(self, ptype): def radiusByLJ(ptype): try: radius = self.system.non_bonded_inter[ptype, ptype].lennard_jones.get_params()[ @@ -660,48 +907,79 @@ class openGLLive(object): radius = self.specs['particle_sizes'](ptype) else: try: - radius = self.modulo_indexing( + radius = self._modulo_indexing( self.specs['particle_sizes'], ptype) except BaseException: radius = self.radiusByLJ(ptype) return radius - def draw_system_particles(self): + def _draw_system_particles(self, colorById=False): pIds = range(len(self.particles['pos'])) + ptype = -1 + reset_material = False + for pid in pIds: + ptype_last = ptype ptype = int(self.particles['type'][pid]) - radius = self.determine_radius(ptype) - - m = self.modulo_indexing( - self.specs['particle_type_materials'], ptype) - material = self.materials[m] - - if self.specs['particle_coloring'] == 'id': - color = self.id_to_fcolor(pid) - glColor(color) - elif self.specs['particle_coloring'] == 'auto': - # Color auto: Charge then Type - if self.particles['charge'][pid] != 0: - color = self.color_by_charge(self.particles['charge'][pid]) + + # Only change material if type/charge has changed, colorById or material was resetted by arrows + if reset_material or colorById or not ptype == ptype_last or pid == self.dragId or pid == self.infoId or self.specs['particle_coloring'] == 'node': + reset_material = False + + radius = self._determine_radius(ptype) + + m = self._modulo_indexing( + self.specs['particle_type_materials'], ptype) + material = self.materials[m] + + if colorById: + color = self._id_to_fcolor(pid) + glColor(color) else: - color = self.modulo_indexing( - self.specs['particle_type_colors'], ptype) - elif self.specs['particle_coloring'] == 'charge': - color = self.color_by_charge(self.particles['charge'][pid]) - elif self.specs['particle_coloring'] == 'type': - color = self.modulo_indexing( - self.specs['particle_type_colors'], ptype) - elif self.specs['particle_coloring'] == 'node': - color = self.modulo_indexing(self.specs['particle_type_colors'], self.particles['node'][pid]) - - draw_sphere(self.particles['pos'][pid], radius, color, material, - self.specs['quality_particles']) - for imx in range(-self.specs['periodic_images'][0], self.specs['periodic_images'][0] + 1): - for imy in range(-self.specs['periodic_images'][1], self.specs['periodic_images'][1] + 1): - for imz in range(-self.specs['periodic_images'][2], self.specs['periodic_images'][2] + 1): - if imx != 0 or imy != 0 or imz != 0: - redraw_sphere( - self.particles['pos'][pid] + (imx * self.imPos[0] + imy * self.imPos[1] + imz * self.imPos[2]), radius, self.specs['quality_particles']) + if self.specs['particle_coloring'] == 'auto': + # Color auto: Charge then Type + if self.has_particle_data['charge'] and self.particles['charge'][pid] != 0: + color = self._color_by_charge( + self.particles['charge'][pid]) + reset_material = True + else: + color = self._modulo_indexing( + self.specs['particle_type_colors'], ptype) + elif self.specs['particle_coloring'] == 'charge': + color = self._color_by_charge( + self.particles['charge'][pid]) + reset_material = True + elif self.specs['particle_coloring'] == 'type': + color = self._modulo_indexing( + self.specs['particle_type_colors'], ptype) + elif self.specs['particle_coloring'] == 'node': + color = self._modulo_indexing( + self.specs['particle_type_colors'], self.particles['node'][pid]) + + # Invert color of highlighted particle + if pid == self.dragId or pid == self.infoId: + reset_material = True + color = [1 - color[0], 1 - color[1], + 1 - color[2]] + + set_solid_material(color, material) + + # Create a new display list, used until next material/color change + glNewList(self.dl_sphere, GL_COMPILE) + glutSolidSphere( + radius, self.specs['quality_particles'], self.specs['quality_particles']) + glEndList() + + self._redraw_sphere( + self.particles['pos'][pid], radius, self.specs['quality_particles']) + + if self.has_images: + for imx in range(-self.specs['periodic_images'][0], self.specs['periodic_images'][0] + 1): + for imy in range(-self.specs['periodic_images'][1], self.specs['periodic_images'][1] + 1): + for imz in range(-self.specs['periodic_images'][2], self.specs['periodic_images'][2] + 1): + if imx != 0 or imy != 0 or imz != 0: + self._redraw_sphere( + self.particles['pos'][pid] + (imx * self.imPos[0] + imy * self.imPos[1] + imz * self.imPos[2]), radius, self.specs['quality_particles']) IF EXTERNAL_FORCES: if self.specs['ext_force_arrows'] or pid == self.dragId: @@ -709,45 +987,56 @@ class openGLLive(object): if pid == self.dragId: sc = 1 else: - sc = self.modulo_indexing(self.specs['ext_force_arrows_type_scale'], ptype) + sc = self._modulo_indexing( + self.specs['ext_force_arrows_type_scale'], ptype) if sc > 0: - col = self.modulo_indexing(self.specs['ext_force_arrows_type_colors'], ptype) - radius = self.modulo_indexing(self.specs['ext_force_arrows_type_radii'], ptype) - draw_arrow(self.particles['pos'][pid], np.array(self.particles['ext_force'][pid]) * sc, radius - , col, self.materials['chrome'], self.specs['quality_arrows']) - + arrow_col = self._modulo_indexing( + self.specs['ext_force_arrows_type_colors'], ptype) + arrow_radius = self._modulo_indexing( + self.specs['ext_force_arrows_type_radii'], ptype) + draw_arrow(self.particles['pos'][pid], np.array( + self.particles['ext_force'][pid]) * sc, arrow_radius, arrow_col, self.materials['chrome'], self.specs['quality_arrows']) + reset_material = True + if self.specs['velocity_arrows']: - self.draw_arrow_property(pid, ptype, self.specs['velocity_arrows_type_scale'], self.specs['velocity_arrows_type_colors'], self.specs['velocity_arrows_type_radii'], 'velocity') - + self._draw_arrow_property(pid, ptype, self.specs['velocity_arrows_type_scale'], self.specs[ + 'velocity_arrows_type_colors'], self.specs['velocity_arrows_type_radii'], 'velocity') + reset_material = True + if self.specs['force_arrows']: - self.draw_arrow_property(pid, ptype, self.specs['force_arrows_type_scale'], self.specs['force_arrows_type_colors'], self.specs['force_arrows_type_radii'], 'force') - + self._draw_arrow_property(pid, ptype, self.specs['force_arrows_type_scale'], + self.specs['force_arrows_type_colors'], self.specs['force_arrows_type_radii'], 'force') + reset_material = True + if self.specs['director_arrows']: - self.draw_arrow_property(pid, ptype, self.specs['director_arrows_type_scale'], self.specs['director_arrows_type_colors'], self.specs['director_arrows_type_radii'], 'director') + self._draw_arrow_property(pid, ptype, self.specs['director_arrows_type_scale'], self.specs[ + 'director_arrows_type_colors'], self.specs['director_arrows_type_radii'], 'director') + reset_material = True - def draw_arrow_property(self, pid, ptype, type_scale, type_colors, type_radii, prop): - sc = self.modulo_indexing(type_scale, ptype) + def _draw_arrow_property(self, pid, ptype, type_scale, type_colors, type_radii, prop): + sc = self._modulo_indexing(type_scale, ptype) if sc > 0: v = self.particles[prop][pid] - col = self.modulo_indexing(type_colors, ptype) - radius = self.modulo_indexing(type_radii, ptype) - draw_arrow(self.particles['pos'][pid], np.array(v) * sc, radius, col, self.materials['chrome'], self.specs['quality_arrows']) - + col = self._modulo_indexing(type_colors, ptype) + radius = self._modulo_indexing(type_radii, ptype) + draw_arrow(self.particles['pos'][pid], np.array( + v) * sc, radius, col, self.materials['chrome'], self.specs['quality_arrows']) - def draw_bonds(self): + def _draw_bonds(self): pIds = range(len(self.particles['pos'])) b2 = self.system.box_l[0] / 2.0 box_l2_sqr = pow(b2, 2.0) for b in self.bonds: - col = self.modulo_indexing(self.specs['bond_type_colors'], b[2]) - mat = self.materials[self.modulo_indexing( + col = self._modulo_indexing(self.specs['bond_type_colors'], b[2]) + mat = self.materials[self._modulo_indexing( self.specs['bond_type_materials'], b[2])] - radius = self.modulo_indexing( + radius = self._modulo_indexing( self.specs['bond_type_radius'], b[2]) d = self.particles['pos'][b[0]] - self.particles['pos'][b[1]] bondLen_sqr = d[0] * d[0] + d[1] * d[1] + d[2] * d[2] if bondLen_sqr < box_l2_sqr: + # BOND COMPLETELY INSIDE BOX draw_cylinder(self.particles['pos'][b[0]], self.particles['pos'][b[1]], radius, col, mat, self.specs['quality_bonds']) for imx in range(-self.specs['periodic_images'][0], self.specs['periodic_images'][0] + 1): @@ -758,6 +1047,7 @@ class openGLLive(object): draw_cylinder(self.particles['pos'][b[0]] + im * self.imPos[dim], self.particles['pos'][b[1]] + im * self.imPos[dim], radius, col, mat, self.specs['quality_bonds']) else: + # SPLIT BOND l = self.particles['pos'][b[0]] - self.particles['pos'][b[1]] l0 = self.particles['pos'][b[0]] hits = 0 @@ -768,7 +1058,7 @@ class openGLLive(object): s = l0 - \ np.dot(l0 - self.box_p[i], self.box_n[i]) / lineBoxNDot * l - if self.is_inside_box(s): + if self._is_inside_box(s): if lineBoxNDot < 0: s0 = s else: @@ -776,77 +1066,158 @@ class openGLLive(object): hits += 1 if hits >= 2: break - draw_cylinder(self.particles['pos'][b[0]], s0, radius, col, - mat, self.specs['quality_bonds']) - draw_cylinder(self.particles['pos'][b[1]], s1, radius, col, - mat, self.specs['quality_bonds']) - - for imx in range(-self.specs['periodic_images'][0], self.specs['periodic_images'][0] + 1): - for imy in range(-self.specs['periodic_images'][1], self.specs['periodic_images'][1] + 1): - for imz in range(-self.specs['periodic_images'][2], self.specs['periodic_images'][2] + 1): - if imx != 0 or imy != 0 or imz != 0: - im = np.array([imx, imy, imz]) - draw_cylinder(self.particles['pos'][b[0]] + im * self.imPos[dim], s0 + im * - self.imPos[dim], radius, col, mat, self.specs['quality_bonds']) - draw_cylinder(self.particles['pos'][b[1]] + im * self.imPos[dim], s1 + im * - self.imPos[dim], radius, col, mat, self.specs['quality_bonds']) + if hits >= 2: + draw_cylinder(self.particles['pos'][b[0]], s0, radius, col, + mat, self.specs['quality_bonds']) + draw_cylinder(self.particles['pos'][b[1]], s1, radius, col, + mat, self.specs['quality_bonds']) + + for imx in range(-self.specs['periodic_images'][0], self.specs['periodic_images'][0] + 1): + for imy in range(-self.specs['periodic_images'][1], self.specs['periodic_images'][1] + 1): + for imz in range(-self.specs['periodic_images'][2], self.specs['periodic_images'][2] + 1): + if imx != 0 or imy != 0 or imz != 0: + im = np.array([imx, imy, imz]) + draw_cylinder(self.particles['pos'][b[0]] + im * self.imPos[dim], s0 + im * + self.imPos[dim], radius, col, mat, self.specs['quality_bonds']) + draw_cylinder(self.particles['pos'][b[1]] + im * self.imPos[dim], s1 + im * + self.imPos[dim], radius, col, mat, self.specs['quality_bonds']) + + def _redraw_sphere(self, pos, radius, quality): + glPushMatrix() + glTranslatef(pos[0], pos[1], pos[2]) + glCallList(self.dl_sphere) + glPopMatrix() # HELPER TO DRAW PERIODIC BONDS - def is_inside_box(self, p): + def _is_inside_box(self, p): eps = 1e-5 for i in range(3): - if p[i] < -eps or p[i] > eps + self.system.box_l[i]: + if p[i] < -eps or p[i] > eps + self.last_box_l[i]: return False return True -# VOXELS FOR LB VELOCITIES - def draw_lb_vel(self): + # ARROWS IN A PLANE FOR LB VELOCITIES + def _draw_lb_vel(self): for lbl in self.lb_plane_vel: p = lbl[0] v = lbl[1] c = np.linalg.norm(v) - draw_arrow(p, v * self.specs['LB_vel_scale'], self.lb_arrow_radius, [ - 1, 1, 1, 1], self.materials['chrome'], 16) + draw_arrow(p, v * self.specs['LB_vel_scale'], self.lb_arrow_radius, self.specs['LB_arrow_color'], self.materials[self.specs['LB_arrow_material']], self.specs['LB_arrow_quality']) # USE MODULO IF THERE ARE MORE PARTICLE TYPES THAN TYPE DEFINITIONS FOR # COLORS, MATERIALS ETC.. - def modulo_indexing(self, l, t): + def _modulo_indexing(self, l, t): return l[t % len(l)] # FADE PARTICE CHARGE COLOR FROM WHITE (q=0) to PLUSCOLOR (q=q_max) RESP # MINUSCOLOR (q=q_min) - def color_by_charge(self, q): + def _color_by_charge(self, q): if q < 0: c = 1.0 * q / self.minq - return np.array(self.specs['particle_charge_colors'][0]) * c + (1 - c) * np.array([1, 1, 1, 1]) + return np.array(self.specs['particle_charge_colors'][0]) * c + (1 - c) * np.array([1, 1, 1]) else: c = 1.0 * q / self.maxq - return np.array(self.specs['particle_charge_colors'][1]) * c + (1 - c) * np.array([1, 1, 1, 1]) + return np.array(self.specs['particle_charge_colors'][1]) * c + (1 - c) * np.array([1, 1, 1]) # ON INITIALIZATION, CHECK q_max/q_min - def update_charge_color_range(self): + def _update_charge_color_range(self): if len(self.particles['charge'][:]) > 0: self.minq = min(self.particles['charge'][:]) self.maxq = max(self.particles['charge'][:]) - # INITS FOR GLUT FUNCTIONS - def init_callbacks(self): - # OpenGl Callbacks - def display(): - if self.hasParticleData: - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) + def _handle_screenshot(self): + if self.take_screenshot: + self.take_screenshot = False + data = glReadPixels(0, 0, self.specs['window_size'][0], self.specs['window_size'][1], GL_RGB, GL_FLOAT) + basename = os.path.basename(__file__)[:-3] + + i = 0 + while os.path.exists("{}_{}.png".format(basename, i)): + i += 1 + fname = "{}_{}.png".format(basename, i) + + data = np.flipud(data.reshape((data.shape[1],data.shape[0],3))) + imsave(fname, data) - glLoadMatrixf(self.camera.modelview) + self.screenshot_captured = True + self.screenshot_capture_time = time.time() + self.screenshot_capture_txt = "Saved screenshot {}".format(fname) - if self.updateLightPos: - self.set_light_pos() - self.updateLightPos = False + def _display_all(self): - self.draw() + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) - glutSwapBuffers() + glLoadMatrixf(self.camera.modelview) + + self._set_camera_spotlight() + + self._draw_system() + self._draw_texts() + + glutSwapBuffers() + + self._handle_screenshot() + + def _draw_texts(self): + + # DRAW FPS TEXT + if self.specs['draw_fps']: + t = time.time() + if t - self.fps_last > 1.0: + self.fps_last = t + self.fps = self.fps_count + self.fps_count = 0 + + self._draw_text(10, 10, "{} fps".format( + self.fps), self.text_color) + self._draw_text( + 10, 30, "{} ms/frame".format(1000.0/self.fps), self.text_color) + self.fps_count += 1 + + # DRAW PARTICLE INFO + if self.infoId != -1: + y = 0 + for k, v in self.highlighted_particle.items(): + txt = "{} {} {}".format( + k, (self.max_len_attr-len(k)) * ' ', v) + self._draw_text( + 10, self.specs['window_size'][1] - 10 - 15 * y, txt, self.text_color) + y += 1 + + # INDICATE SCREEN CAPTURE + if self.screenshot_captured and not self.take_screenshot: + col = np.array(self.text_color) + ts = time.time() - self.screenshot_capture_time + fadetime = 2.0 + col[3] = 1.0 - ts / fadetime + if ts > fadetime: + self.screenshot_captured = False + else: + self._draw_text( self.specs['window_size'][0] - len(self.screenshot_capture_txt)*9.0 - 15, + self.specs['window_size'][1] - 15, self.screenshot_capture_txt, col) + + + # CALLED ION WINDOW POSITION/SIZE CHANGE + def _reshape_window(self, w, h): + glViewport(0, 0, w, h) + glMatrixMode(GL_PROJECTION) + glLoadIdentity() + box_diag = pow(pow(self.system.box_l[0], 2) + pow( + self.system.box_l[1], 2) + pow(self.system.box_l[1], 2), 0.5) + gluPerspective( + 40, 1.0 * w / h, self.specs['close_cut_distance'], self.specs['far_cut_distance'] * box_diag) + glMatrixMode(GL_MODELVIEW) + self.specs['window_size'][0] = w + self.specs['window_size'][1] = h + + # INITS FOR GLUT FUNCTIONS + def _init_openGL_callbacks(self): + # OpenGl Callbacks + def display(): + if self.hasParticleData and self.glutMainLoop_started: + self._display_all() return def keyboard_up(button, x, y): @@ -869,50 +1240,57 @@ class openGLLive(object): self.mouseManager.mouse_move(x, y) return - def idle_update(): + def redraw_on_idle(): + # DONT REPOST FASTER THAN 60 FPS + self.draw_elapsed += (time.time() - self.draw_timer) + if self.draw_elapsed > 1.0 / 60.0: + self.draw_elapsed = 0 + glutPostRedisplay() + self.draw_timer = time.time() return - # CALLED ION WINDOW POSITION/SIZE CHANGE - def reshape_window(w, h): - glViewport(0, 0, w, h) - glMatrixMode(GL_PROJECTION) - glLoadIdentity() - box_diag = pow(pow(self.system.box_l[0], 2) + pow( - self.system.box_l[1], 2) + pow(self.system.box_l[1], 2), 0.5) - gluPerspective( - 40, 1.0 * w / h, self.specs['close_cut_distance'], self.specs['far_cut_distance'] * box_diag) - glMatrixMode(GL_MODELVIEW) - self.specs['window_size'][0] = 1.0 * w - self.specs['window_size'][1] = 1.0 * h - # glPushMatrix() + def reshape_callback(w, h): + self._reshape_window(w, h) def close_window(): os._exit(1) - # TIMERS FOR register_callback - def dummy_timer(index): - self.timers[index][1]() - glutTimerFunc(self.timers[index][0], dummy_timer, index) glutDisplayFunc(display) glutMouseFunc(mouse) glutKeyboardFunc(keyboard_down) glutKeyboardUpFunc(keyboard_up) - glutReshapeFunc(reshape_window) + glutSpecialFunc(keyboard_down) + glutSpecialUpFunc(keyboard_up) + glutReshapeFunc(reshape_callback) glutMotionFunc(motion) glutWMCloseFunc(close_window) - glutIdleFunc(idle_update) + glutIdleFunc(redraw_on_idle) + + def _init_timers(self): + + # TIMERS FOR register_callback + def dummy_timer(index): + self.timers[index][1]() + glutTimerFunc(self.timers[index][0], dummy_timer, index) index = 0 for t in self.timers: glutTimerFunc(t[0], dummy_timer, index) index += 1 + + # HANDLE INPUT WITH 60FPS + def timed_handle_input(data): + self.keyboardManager.handle_input() + glutTimerFunc(17, timed_handle_input, -1) + + glutTimerFunc(17, timed_handle_input, -1) # CLICKED ON PARTICLE: DRAG; CLICKED ON BACKGROUND: CAMERA - def mouse_motion(self, mousePos, mousePosOld, mouseButtonState): + def _mouse_motion(self, mousePos, mousePosOld, mouseButtonState): - if self.dragId != -1: + if self.specs['drag_enabled'] and self.dragId != -1: ppos = self.particles['pos'][self.dragId] viewport = glGetIntegerv(GL_VIEWPORT) mouseWorld = gluUnProject( @@ -925,34 +1303,27 @@ class openGLLive(object): self.camera.rotate_camera(mousePos, mousePosOld, mouseButtonState) # DRAW SCENE AGAIN WITHOUT LIGHT TO IDENTIFY PARTICLE ID BY PIXEL COLOR - def set_particle_drag(self, pos, pos_old): + def _get_particle_id(self, pos, pos_old): glClearColor(0.0, 0.0, 0.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadMatrixf(self.camera.modelview) - oldColMode = self.specs['particle_coloring'] - self.specs['particle_coloring'] = 'id' glDisable(GL_LIGHTING) glDisable(GL_LIGHT0) if self.specs['spotlight_enabled']: glDisable(GL_LIGHT1) - self.draw_system_particles() + self._draw_system_particles(colorById=True) viewport = glGetIntegerv(GL_VIEWPORT) readPixel = glReadPixelsui( pos[0], viewport[3] - pos[1], 1, 1, GL_RGB, GL_FLOAT)[0][0] depth = glReadPixelsf( pos[0], viewport[3] - pos[1], 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT)[0][0] - pid = self.fcolor_to_id(readPixel) - self.dragId = pid - if pid != -1: - self.dragPosInitial = self.particles['pos'][self.dragId] - self.extForceOld = self.particles['ext_force'][self.dragId][:] - self.depth = depth - self.specs['particle_coloring'] = oldColMode + pid = self._fcolor_to_id(readPixel) + glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) if self.specs['spotlight_enabled']: @@ -961,26 +1332,48 @@ class openGLLive(object): self.specs['background_color'][1], self.specs['background_color'][2], 1.) - def reset_particle_drag(self, pos, pos_old): - if self.dragId != -1: - self.triggerResetParticleDrag = True + return pid, depth - def id_to_fcolor(self, pid): + def _id_to_fcolor(self, pid): pid += 1 return [int(pid / (256 * 256)) / 255.0, int((pid % (256 * 256)) / 256) / 255.0, (pid % 256) / 255.0, 1.0] - def fcolor_to_id(self, fcol): + def _fcolor_to_id(self, fcol): if (fcol == [0, 0, 0]).all(): return -1 else: return 256 * 256 * int(fcol[0] * 255) + 256 * int(fcol[1] * 255) + int(fcol[2] * 255) - 1 - # ALL THE INITS - def init_espresso_visualization(self): + def _set_particle_drag(self, pos, pos_old): + pid, depth = self._get_particle_id(pos, pos_old) + self.dragId = pid + + if pid != -1: + self.dragPosInitial = self.particles['pos'][self.dragId] + self.extForceOld = self.particles['ext_force'][self.dragId][:] + self.depth = depth + + def _reset_particle_drag(self, pos, pos_old): + if self.dragId != -1: + self.triggerResetParticleDrag = True + + def _get_particle_info(self, pos, pos_old): + pid, depth = self._get_particle_id(pos, pos_old) + self.infoId = pid + + def _next_particle_info(self): + self.infoId = (self.infoId + 1) % len(self.particles['pos']) + + def _previous_particle_info(self): + self.infoId = (self.infoId - 1) % len(self.particles['pos']) + + # ESPRESSO RELATED INITS + def _init_espresso_visualization(self): self.maxq = 0 self.minq = 0 self.dragId = -1 + self.infoId = -1 self.dragPosInitial = [] self.extForceOld = [] self.dragExtForceOld = [] @@ -992,26 +1385,37 @@ class openGLLive(object): self.imPos = [np.array([self.system.box_l[0], 0, 0]), np.array( [0, self.system.box_l[1], 0]), np.array([0, 0, self.system.box_l[2]])] - if self.specs['LB']: + # LOOK FOR LB ACTOR + if self.specs['LB_draw_velocity_plane'] or self.specs['LB_draw_nodes'] or self.specs['LB_draw_node_boundaries']: for a in self.system.actors: - pa = a.get_params() - if 'agrid' in pa: - self.lb_params = pa + types = [] + IF LB: + types.append(espressomd.lb.LBFluid) + IF LB_GPU: + types.append(espressomd.lb.LBFluidGPU) + + #if type(a) == espressomd.lb.LBFluidGPU or type(a) == espressomd.lb.LBFluid + if type(a) in types: + #if 'agrid' in pa: + self.lb_params = a.get_params() self.lb = a + self.lb_is_cpu = type(a) == espressomd.lb.LBFluid break + if self.specs['LB_draw_velocity_plane']: + if self.specs['LB_plane_axis'] == 0: pn = [1.0, 0.0, 0.0] - self.lb_plane_b1 = [0.0,1.0,0.0] - self.lb_plane_b2 = [0.0,0.0,1.0] + self.lb_plane_b1 = [0.0, 1.0, 0.0] + self.lb_plane_b2 = [0.0, 0.0, 1.0] elif self.specs['LB_plane_axis'] == 1: pn = [0.0, 1.0, 0.0] - self.lb_plane_b1 = [1.0,0.0,0.0] - self.lb_plane_b2 = [0.0,0.0,1.0] + self.lb_plane_b1 = [1.0, 0.0, 0.0] + self.lb_plane_b2 = [0.0, 0.0, 1.0] else: pn = [0.0, 0.0, 1.0] - self.lb_plane_b1 = [1.0,0.0,0.0] - self.lb_plane_b2 = [0.0,1.0,0.0] + self.lb_plane_b1 = [1.0, 0.0, 0.0] + self.lb_plane_b2 = [0.0, 1.0, 0.0] self.lb_plane_b1 *= self.system.box_l self.lb_plane_b2 *= self.system.box_l @@ -1025,16 +1429,19 @@ class openGLLive(object): self.lb_vel_range = self.lb_max_vel - self.lb_min_vel self.lb_min_dens = np.array([0] * 3) self.lb_max_dens = np.array([0] * 3) + + self._update_lb_velocity_plane() - self.update_lb() - - self.elapsedTime = 0 - self.measureTimeBeforeIntegrate = 0 - - self.box_size_dependence() + self._box_size_dependence() # BOX PLANES (NORMAL, ORIGIN) FOR PERIODIC BONDS - def box_size_dependence(self): + def _box_size_dependence(self): + + if self.specs['draw_cells'] or self.specs['draw_nodes']: + self._update_nodes() + if self.specs['draw_cells']: + self._update_cells() + self.box_n = [np.array([1, 0, 0]), np.array([0, 1, 0]), np.array( [0, 0, 1]), np.array([-1, 0, 0]), np.array([0, -1, 0]), np.array([0, 0, -1])] self.box_p = [np.array([0, 0, 0]), np.array([0, 0, 0]), np.array([0, 0, 0]), np.array( @@ -1053,11 +1460,15 @@ class openGLLive(object): self.box_eqn.append( (self.box_n[5][0], self.box_n[5][1], self.box_n[5][2], self.system.box_l[2] * 1.001)) + self.camera.center = np.array(self.system.box_l) * 0.5 + self.camera.update_modelview() + # DEFAULT CONTROLS - def init_controls(self): + def _init_controls(self): + # MOUSE LOOK/ROTATE/DRAG self.mouseManager.register_button(MouseButtonEvent( - None, MouseFireEvent.FreeMotion, self.mouse_motion)) + None, MouseFireEvent.FreeMotion, self._mouse_motion)) self.mouseManager.register_button(MouseButtonEvent( 3, MouseFireEvent.ButtonPressed, self.camera.move_backward)) @@ -1068,13 +1479,33 @@ class openGLLive(object): # START/STOP DRAG if self.specs['drag_enabled']: self.mouseManager.register_button(MouseButtonEvent( - GLUT_LEFT_BUTTON, MouseFireEvent.ButtonPressed, self.set_particle_drag, True)) + GLUT_LEFT_BUTTON, MouseFireEvent.ButtonPressed, self._set_particle_drag, True)) self.mouseManager.register_button(MouseButtonEvent( - GLUT_LEFT_BUTTON, MouseFireEvent.ButtonReleased, self.reset_particle_drag, True)) + GLUT_LEFT_BUTTON, MouseFireEvent.ButtonReleased, self._reset_particle_drag, True)) + + # PARTICLE INFORMATION + self.mouseManager.register_button(MouseButtonEvent( + GLUT_LEFT_BUTTON, MouseFireEvent.DoubleClick, self._get_particle_info, True)) + + # CYCLE THROUGH PARTICLES + self.keyboardManager.register_button(KeyboardButtonEvent( + GLUT_KEY_LEFT, KeyboardFireEvent.Pressed, self._previous_particle_info, False)) + self.keyboardManager.register_button(KeyboardButtonEvent( + GLUT_KEY_RIGHT, KeyboardFireEvent.Pressed, self._next_particle_info, False)) + + # PAUSE INTEGRATION THREAD + self.keyboardManager.register_button(KeyboardButtonEvent( + ' ', KeyboardFireEvent.Pressed, self._pause, True)) + + # TAKE SCREENSHOT + self.keyboardManager.register_button(KeyboardButtonEvent( + '\x0d', KeyboardFireEvent.Pressed, self._trigger_screenshot, True)) - # KEYBOARD BUTTONS + # QUIT self.keyboardManager.register_button(KeyboardButtonEvent( - '\x1b', KeyboardFireEvent.Pressed, self.quit, True)) + '\x1b', KeyboardFireEvent.Pressed, self._quit, True)) + + # CAMERA CONTROL VIA KEYBOARD self.keyboardManager.register_button(KeyboardButtonEvent( 'w', KeyboardFireEvent.Hold, self.camera.move_up, True)) self.keyboardManager.register_button(KeyboardButtonEvent( @@ -1101,29 +1532,25 @@ class openGLLive(object): 'g', KeyboardFireEvent.Hold, self.camera.move_backward, True)) # CALLED ON ESCAPE PRESSED. TRIGGERS sys.exit() after ES is done - def quit(self): + def _quit(self): self.quit_savely = True + def _pause(self): + self.paused = not self.paused + + def _trigger_screenshot(self): + self.take_screenshot = True + # ASYNCHRONOUS PARALLEL CALLS OF glLight CAUSES SEG FAULTS, SO ONLY CHANGE # LIGHT AT CENTRAL display METHOD AND TRIGGER CHANGES - def set_light_pos(self): - if self.specs['light_pos'] == 'auto': - glLightfv(GL_LIGHT0, GL_POSITION, [ - self.smooth_light_pos[0], self.smooth_light_pos[1], self.smooth_light_pos[2], 0.6]) - - self.set_camera_spotlight() - - def set_camera_spotlight(self): - # p = np.linalg.norm(self.camera.state_pos) * self.camera.state_target - p = self.camera.camPos - fp = [p[0], p[1], p[2], 1] - glLightfv(GL_LIGHT1, GL_POSITION, fp) - glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, self.camera.state_target) - - def trigger_light_pos_update(self): - self.updateLightPos = True + def _set_camera_spotlight(self): + if self.specs['spotlight_enabled']: + p = self.camera.camPos + fp = [p[0], p[1], p[2], 1] + glLightfv(GL_LIGHT1, GL_POSITION, fp) + glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, self.camera.state_target) - def init_camera(self): + def _init_camera(self): b = np.array(self.system.box_l) box_diag = np.linalg.norm(b) box_center = b * 0.5 @@ -1139,31 +1566,34 @@ class openGLLive(object): cr = np.array(self.specs['camera_right']) - self.camera = Camera(camPos=np.array(cp), camTarget=ct, camRight=cr, moveSpeed=0.5 * - box_diag / 17.0, center=box_center, updateLights=self.trigger_light_pos_update) - self.smooth_light_pos = np.copy(box_center) - self.smooth_light_posV = np.array([0.0, 0.0, 0.0]) - self.particle_COM = np.copy(box_center) - self.set_camera_spotlight() - self.updateLightPos = True + self.camera.set_camera(camPos=np.array(cp), camTarget=ct, camRight=cr, moveSpeed=0.5 * + box_diag / 17.0, center=box_center) + self._set_camera_spotlight() - def init_opengl(self): + def _init_opengl(self): glutInit(self.specs['name']) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) + glutInitWindowSize(self.specs['window_size'][ 0], self.specs['window_size'][1]) - # glutCreateWindow(bytes(self.specs['name'], encoding='ascii')) glutCreateWindow(b"ESPResSo visualization") + glClearColor(self.specs['background_color'][0], self.specs[ 'background_color'][1], self.specs['background_color'][2], 1.) - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND) + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + glEnable(GL_POINT_SMOOTH) + glEnable(GL_LINE_SMOOTH) + glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) + + # BAD FOR TRANSPARENT PARTICLES # glEnable(GL_CULL_FACE) + # glCullFace(GL_BACK) glLineWidth(2.0) glutIgnoreKeyRepeat(1) @@ -1179,16 +1609,11 @@ class openGLLive(object): # LIGHT0 if self.specs['light_pos'] != 'auto': - glLightfv( - GL_LIGHT0, GL_POSITION, np.array( - self.specs['light_pos']).tolist()) + glLightfv(GL_LIGHT0, GL_POSITION, np.array( + self.specs['light_pos']).tolist()) else: - glLightfv( - GL_LIGHT0, - GL_POSITION, - (np.array( - self.system.box_l) * - 0.5).tolist()) + glLightfv(GL_LIGHT0, GL_POSITION, + (np.array(self.system.box_l) * 1.1).tolist()) glLightfv(GL_LIGHT0, GL_AMBIENT, self.specs['light_colors'][0]) glLightfv(GL_LIGHT0, GL_DIFFUSE, self.specs['light_colors'][1]) @@ -1220,23 +1645,22 @@ class openGLLive(object): glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.0) glEnable(GL_LIGHT1) -# END OF MAIN CLASS + self.dl_sphere = glGenLists(1) -# OPENGL DRAW WRAPPERS +# END OF MAIN CLASS -def set_solid_material(r, g, b, a=1.0, ambient=[0.6, 0.6, 0.6], diffuse=[1.0, 1.0, 1.0], specular=[0.1, 0.1, 0.1], shininess=0.4): - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [ - ambient[0] * r, ambient[1] * g, ambient[2] * g, a]) - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [ - diffuse[0] * r, diffuse[1] * g, diffuse[2] * b, a]) - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [ - specular[0] * r, specular[1] * g, specular[2] * g, a]) - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, int(shininess * 128)) +# OPENGL DRAW WRAPPERS +def set_solid_material(color, material = [0.6, 1.0, 0.1, 0.4, 1.0]): + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0]*material[0], color[1]*material[0], color[2] * material[0], material[4]]) + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [color[0]*material[1], color[1]*material[1], color[2] * material[1], material[4]]) + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [color[0]*material[2], color[1]*material[2], color[2] * material[2], material[4]]) + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, int(material[3] * 128)) -def draw_box(p0, s, color): - set_solid_material(color[0], color[1], color[2]) +def draw_box(p0, s, color, material, width): + glLineWidth(width) + set_solid_material(color, material) glPushMatrix() glTranslatef(p0[0], p0[1], p0[2]) glBegin(GL_LINE_LOOP) @@ -1261,30 +1685,20 @@ def draw_box(p0, s, color): glVertex3f(0.0, s[1], 0.0) glVertex3f(0.0, s[1], s[2]) glEnd() - # glutWireCube(size) - glPopMatrix() - -def draw_sphere(pos, radius, color, material, quality): - glPushMatrix() - glTranslatef(pos[0], pos[1], pos[2]) - set_solid_material(color[0], color[1], color[2], color[ - 3], material[0], material[1], material[2], material[3]) - glutSolidSphere(radius, quality, quality) glPopMatrix() -def redraw_sphere(pos, radius, quality): +def draw_sphere(pos, radius, color, material, quality): glPushMatrix() glTranslatef(pos[0], pos[1], pos[2]) + set_solid_material(color, material) glutSolidSphere(radius, quality, quality) glPopMatrix() - def draw_plane(edges, color, material): - set_solid_material(color[0], color[1], color[2], color[ - 3], material[0], material[1], material[2], material[3]) + set_solid_material(color, material) glBegin(GL_QUADS) for e in edges: @@ -1292,33 +1706,8 @@ def draw_plane(edges, color, material): glEnd() -def draw_cube(pos, size, color, alpha): - set_solid_material(color[0], color[1], color[2], alpha) - glPushMatrix() - glTranslatef(pos[0], pos[1], pos[2]) - glutSolidCube(size) - glPopMatrix() - - -def draw_triangles(triangles, color, material): - np.random.seed(1) - - glBegin(GL_TRIANGLES) - for t in triangles: - color = np.random.random(3).tolist() - color.append(1) - set_solid_material(color[0], color[1], color[2], - color[3], material[0], material[1], material[2], material[3]) - for p in t: - glVertex3f(p[0], p[1], p[2]) - glEnd() - - def draw_points(points, pointsize, color, material): - set_solid_material(color[0], color[1], color[2], color[3], - material[0], material[1], material[2], material[3]) - glEnable(GL_POINT_SMOOTH) - + set_solid_material(color, material) glPointSize(pointsize) glBegin(GL_POINTS) for p in points: @@ -1327,8 +1716,7 @@ def draw_points(points, pointsize, color, material): def draw_cylinder(posA, posB, radius, color, material, quality, draw_caps=False): - set_solid_material(color[0], color[1], color[2], color[3], - material[0], material[1], material[2], material[3]) + set_solid_material(color, material) glPushMatrix() quadric = gluNewQuadric() @@ -1367,9 +1755,9 @@ def rotation_helper(d): return ax, rx, ry + def draw_ellipsoid(pos, semiaxis_a, semiaxis_b, semiaxis_c, color, material, quality): - set_solid_material(color[0], color[1], color[2], color[3], - material[0], material[1], material[2]) + set_solid_material(color, material) glPushMatrix() glTranslatef(pos[0], pos[1], pos[2]) glScalef(semiaxis_a, semiaxis_b, semiaxis_c) @@ -1377,9 +1765,47 @@ def draw_ellipsoid(pos, semiaxis_a, semiaxis_b, semiaxis_c, color, material, qua glPopMatrix() +def draw_simple_pore(center, axis, length, radius, smoothing_radius, max_box_l, color, material, quality): + set_solid_material(color, material) + glPushMatrix() + quadric = gluNewQuadric() + + # basic position and orientation + glTranslate(center[0], center[1], center[2]) + ax, rx, ry = rotation_helper(axis) + glRotatef(ax, rx, ry, 0.0) + # cylinder + glTranslate(0, 0, -0.5 * length + smoothing_radius) + gluCylinder(quadric, radius, radius, length - 2 * + smoothing_radius, quality, quality) + # torus segment + clip_plane = GL_CLIP_PLANE0 + 6 + glEnable(clip_plane) + glClipPlane(clip_plane, (0, 0, -1, 0)) + glutSolidTorus(smoothing_radius, (radius + + smoothing_radius), quality, quality) + glDisable(clip_plane) + # wall + glTranslate(0, 0, -smoothing_radius) + gluPartialDisk(quadric, radius + smoothing_radius, + 2.0 * max_box_l, quality, 1, 0, 360) + # torus segment + glTranslate(0, 0, length - smoothing_radius) + glEnable(clip_plane) + glClipPlane(clip_plane, (0, 0, 1, 0)) + glutSolidTorus(smoothing_radius, (radius + + smoothing_radius), quality, quality) + glDisable(clip_plane) + # wall + glTranslate(0, 0, smoothing_radius) + gluPartialDisk(quadric, radius + smoothing_radius, + 2.0 * max_box_l, quality, 1, 0, 360) + + glPopMatrix() + + def draw_sphero_cylinder(posA, posB, radius, color, material, quality): - set_solid_material(color[0], color[1], color[ - 2], color[3], material[0], material[1], material[2], material[3]) + set_solid_material(color, material) glPushMatrix() quadric = gluNewQuadric() @@ -1402,7 +1828,7 @@ def draw_sphero_cylinder(posA, posB, radius, color, material, quality): glRotatef(ax, rx, ry, 0.0) # First hemispherical cap - clip_plane = GL_CLIP_PLANE0+6 + clip_plane = GL_CLIP_PLANE0 + 6 glEnable(clip_plane) glClipPlane(clip_plane, (0, 0, -1, 0)) gluSphere(quadric, radius, quality, quality) @@ -1444,6 +1870,7 @@ class MouseFireEvent(object): FreeMotion = 1 ButtonMotion = 2 ButtonReleased = 3 + DoubleClick = 4 class MouseButtonEvent(object): @@ -1472,10 +1899,25 @@ class MouseManager(object): self.mouseEventsFreeMotion = [] self.mouseEventsButtonMotion = [] self.mouseEventsReleased = [] + self.mouseEventsDoubleClick = [] self.mouseState = {} self.mouseState[GLUT_LEFT_BUTTON] = GLUT_UP self.mouseState[GLUT_MIDDLE_BUTTON] = GLUT_UP self.mouseState[GLUT_RIGHT_BUTTON] = GLUT_UP + self.mouseState['3'] = GLUT_UP # WHEEL + self.mouseState['4'] = GLUT_UP # WHEEL + self.pressedTime = {} + self.pressedTime[GLUT_LEFT_BUTTON] = 0 + self.pressedTime[GLUT_MIDDLE_BUTTON] = 0 + self.pressedTime[GLUT_RIGHT_BUTTON] = 0 + self.pressedTime[3] = 0 + self.pressedTime[4] = 0 + self.pressedTimeOld = {} + self.pressedTimeOld[GLUT_LEFT_BUTTON] = 0 + self.pressedTimeOld[GLUT_MIDDLE_BUTTON] = 0 + self.pressedTimeOld[GLUT_RIGHT_BUTTON] = 0 + self.pressedTimeOld[3] = 0 + self.pressedTimeOld[4] = 0 def register_button(self, mouseEvent): """Register mouse input callbacks. @@ -1489,6 +1931,8 @@ class MouseManager(object): self.mouseEventsFreeMotion.append(mouseEvent) elif mouseEvent.fireEvent == MouseFireEvent.ButtonMotion: self.mouseEventsButtonMotion.append(mouseEvent) + elif mouseEvent.fireEvent == MouseFireEvent.DoubleClick: + self.mouseEventsDoubleClick.append(mouseEvent) def mouse_click(self, button, state, x, y): self.mousePosOld = self.mousePos @@ -1509,6 +1953,17 @@ class MouseManager(object): else: me.callback() + if state == GLUT_DOWN: + self.pressedTimeOld[button] = self.pressedTime[button] + self.pressedTime[button] = time.time() + + for me in self.mouseEventsDoubleClick: + if me.button == button and state == GLUT_DOWN and self.pressedTime[button] - self.pressedTimeOld[button] < 0.25: + if me.positional: + me.callback(self.mousePos, self.mousePosOld) + else: + me.callback() + def mouse_move(self, x, y): self.mousePosOld = self.mousePos self.mousePos = np.array([x, y]) @@ -1612,13 +2067,15 @@ class KeyboardManager(object): class Camera(object): - def __init__(self, camPos=np.array([0, 0, 1]), camTarget=np.array([0, 0, 0]), camRight=np.array([1.0, 0.0, 0.0]), moveSpeed=0.5, rotSpeed=0.001, globalRotSpeed=3.0, center=np.array([0, 0, 0]), updateLights=None): + def __init__(self): + pass + + def set_camera(self, camPos=np.array([0, 0, 1]), camTarget=np.array([0, 0, 0]), camRight=np.array([1.0, 0.0, 0.0]), moveSpeed=0.5, rotSpeed=0.001, globalRotSpeed=3.0, center=np.array([0, 0, 0])): self.moveSpeed = moveSpeed self.lookSpeed = rotSpeed self.globalRotSpeed = globalRotSpeed self.center = center - self.updateLights = updateLights self.modelview = np.identity(4, np.float32) @@ -1658,38 +2115,38 @@ class Camera(object): self.update_modelview() def rotate_system_XL(self): - self.rotate_camera_H(0.01 * self.globalRotSpeed) + self.rotate_system_y(0.01 * self.globalRotSpeed) def rotate_system_XR(self): - self.rotate_camera_H(-0.01 * self.globalRotSpeed) + self.rotate_system_y(-0.01 * self.globalRotSpeed) def rotate_system_YL(self): - self.rotate_camera_R(0.01 * self.globalRotSpeed) + self.rotate_system_z(0.01 * self.globalRotSpeed) def rotate_system_YR(self): - self.rotate_camera_R(-0.01 * self.globalRotSpeed) + self.rotate_system_z(-0.01 * self.globalRotSpeed) def rotate_system_ZL(self): - self.rotate_camera_V(0.01 * self.globalRotSpeed) + self.rotate_system_x(0.01 * self.globalRotSpeed) def rotate_system_ZR(self): - self.rotate_camera_V(-0.01 * self.globalRotSpeed) + self.rotate_system_x(-0.01 * self.globalRotSpeed) def rotate_camera(self, mousePos, mousePosOld, mouseButtonState): dm = mousePos - mousePosOld if mouseButtonState[GLUT_LEFT_BUTTON] == GLUT_DOWN: if dm[0] != 0: - self.rotate_camera_H(dm[0] * 0.001 * self.globalRotSpeed) + self.rotate_system_y(dm[0] * 0.001 * self.globalRotSpeed) if dm[1] != 0: - self.rotate_camera_V(dm[1] * 0.001 * self.globalRotSpeed) + self.rotate_system_x(dm[1] * 0.001 * self.globalRotSpeed) elif mouseButtonState[GLUT_RIGHT_BUTTON] == GLUT_DOWN: self.state_pos[0] -= 0.05 * dm[0] * self.moveSpeed self.state_pos[1] += 0.05 * dm[1] * self.moveSpeed self.update_modelview() elif mouseButtonState[GLUT_MIDDLE_BUTTON] == GLUT_DOWN: self.state_pos[2] += 0.05 * dm[1] * self.moveSpeed - self.rotate_camera_R(dm[0] * 0.001 * self.globalRotSpeed) + self.rotate_system_z(dm[0] * 0.001 * self.globalRotSpeed) def normalize(self, vec): vec = self.normalized(vec) @@ -1732,17 +2189,17 @@ class Camera(object): vec[1] = w[1] vec[2] = w[2] - def rotate_camera_R(self, da): + def rotate_system_z(self, da): self.rotate_vector(self.state_right, da, self.state_target) self.rotate_vector(self.state_up, da, self.state_target) self.update_modelview() - def rotate_camera_V(self, da): + def rotate_system_x(self, da): self.rotate_vector(self.state_target, da, self.state_right) self.state_up = np.cross(self.state_right, self.state_target) self.update_modelview() - def rotate_camera_H(self, da): + def rotate_system_y(self, da): self.rotate_vector(self.state_target, da, self.state_up) self.state_right = np.cross(self.state_target, self.state_up) self.update_modelview() @@ -1775,8 +2232,6 @@ class Camera(object): np.mat(self.modelview[3, :3]).T self.camPos = np.array([cXYZ[0, 0], cXYZ[1, 0], cXYZ[2, 0]]) - self.updateLights() - class Quaternion: diff --git a/src/script_interface/constraints/ShapeBasedConstraint.hpp b/src/script_interface/constraints/ShapeBasedConstraint.hpp index ed2f0a756f2..904123b6c1e 100644 --- a/src/script_interface/constraints/ShapeBasedConstraint.hpp +++ b/src/script_interface/constraints/ShapeBasedConstraint.hpp @@ -37,7 +37,7 @@ class ShapeBasedConstraint : public Constraint { m_shape(nullptr) { add_parameters({{"only_positive", m_constraint->only_positive()}, {"penetrable", m_constraint->penetrable()}, - {"particle_type", + {"particle_type", [this](Variant const &value) { m_constraint->set_type(get_value(value)); }, @@ -52,7 +52,12 @@ class ShapeBasedConstraint : public Constraint { }, [this]() { return (m_shape != nullptr) ? m_shape->id() : ObjectId(); - }}}); + }}, + {"particle_velocity", + [this](const Variant &v) { + m_constraint->set_velocity(get_value(v)); + }, + [this]() { return m_constraint->velocity(); }}}); } Variant call_method(std::string const &name, VariantMap const &) override { diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 239d0628ec7..36806b27386 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -15,16 +15,24 @@ if(EXISTS ${MPIEXEC}) endif() function(PYTHON_TEST) - cmake_parse_arguments(TEST "" "FILE;MAX_NUM_PROC" "" ${ARGN} ) + cmake_parse_arguments(TEST "" "FILE;MAX_NUM_PROC;RUN_WITH_MPI" "DEPENDENCIES;CONFIGURATIONS" ${ARGN}) get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) - set(TEST_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE}") + configure_file(${TEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE}) + foreach(dependency IN LISTS TEST_DEPENDENCIES) + configure_file(${dependency} ${CMAKE_CURRENT_BINARY_DIR}/${dependency}) + endforeach(dependency) + set(TEST_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE}") + # Default values + if (NOT DEFINED TEST_RUN_WITH_MPI) + set(TEST_RUN_WITH_MPI TRUE) + endif() if(${TEST_MAX_NUM_PROC} LESS 2) - set(TEST_CONFIGURATIONS "serial") + set(TEST_CONFIGURATIONS ${TEST_CONFIGURATIONS} "serial") elseif(${TEST_MAX_NUM_PROC} LESS 3) - set(TEST_CONFIGURATIONS "serial;parallel") + set(TEST_CONFIGURATIONS ${TEST_CONFIGURATIONS} "serial;parallel") else() - set(TEST_CONFIGURATIONS "serial;parallel;parallel_odd") + set(TEST_CONFIGURATIONS ${TEST_CONFIGURATIONS} "serial;parallel;parallel_odd") endif() if(${TEST_MAX_NUM_PROC} LESS ${TEST_NP}) @@ -33,7 +41,7 @@ function(PYTHON_TEST) set(TEST_NUM_PROC ${TEST_NP}) endif() - if(EXISTS ${MPIEXEC}) + if(EXISTS ${MPIEXEC} AND ${TEST_RUN_WITH_MPI}) add_test(NAME ${TEST_NAME} COMMAND ${MPIEXEC} ${MPIEXEC_OVERSUBSCRIBE} ${MPIEXEC_NUMPROC_FLAG} ${TEST_NUM_PROC} ${CMAKE_BINARY_DIR}/pypresso ${TEST_FILE} @@ -47,6 +55,7 @@ function(PYTHON_TEST) set(python_tests ${python_tests} ${TEST_FILE} PARENT_SCOPE) endfunction(PYTHON_TEST) +python_test(FILE test_checkpoint.py MAX_NUM_PROC 1 RUN_WITH_MPI FALSE DEPENDENCIES save_checkpoint.py) python_test(FILE cellsystem.py MAX_NUM_PROC 4) python_test(FILE constraint_homogeneous_magnetic_field.py MAX_NUM_PROC 4) python_test(FILE constraint_shape_based.py MAX_NUM_PROC 4) @@ -81,7 +90,7 @@ python_test(FILE script_interface_object_params.py MAX_NUM_PROC 4) python_test(FILE lbgpu_remove_total_momentum.py MAX_NUM_PROC 4) python_test(FILE reaction_ensemble.py MAX_NUM_PROC 4) python_test(FILE constant_pH.py MAX_NUM_PROC 4) -python_test(FILE catalytic_reaction.py MAX_NUM_PROC 1) +python_test(FILE swimmer_reaction.py MAX_NUM_PROC 1) python_test(FILE writevtf.py MAX_NUM_PROC 4) python_test(FILE lb_stokes_sphere_gpu.py MAX_NUM_PROC 1) python_test(FILE ek_eof_one_species_x.py MAX_NUM_PROC 1) @@ -149,19 +158,21 @@ if(PY_H5PY) python_test(FILE h5md.py MAX_NUM_PROC 2) endif(PY_H5PY) -add_custom_target(python_tests - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +add_custom_target(python_test_data + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_CURRENT_BINARY_DIR}/data + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/tests_common.py ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/ek_common.py ${CMAKE_CURRENT_BINARY_DIR}) add_custom_target(check_python_serial COMMAND ${CMAKE_CTEST_COMMAND} -C serial --output-on-failure) -add_dependencies(check_python_serial pypresso python_tests) +add_dependencies(check_python_serial pypresso python_test_data) add_custom_target(check_python_parallel COMMAND ${CMAKE_CTEST_COMMAND} -C parallel --output-on-failure) -add_dependencies(check_python_parallel pypresso python_tests) +add_dependencies(check_python_parallel pypresso python_test_data) add_custom_target(check_python_parallel_odd COMMAND ${CMAKE_CTEST_COMMAND} -C parallel_odd --output-on-failure) -add_dependencies(check_python_parallel_odd pypresso python_tests) +add_dependencies(check_python_parallel_odd pypresso python_test_data) add_custom_target(check_python) -add_dependencies(check_python pypresso python_tests check_python_serial) +add_dependencies(check_python pypresso python_test_data check_python_serial) add_dependencies(check check_python) diff --git a/testsuite/dpd.py b/testsuite/dpd.py index cea6a16b43d..4f5465ef78b 100644 --- a/testsuite/dpd.py +++ b/testsuite/dpd.py @@ -22,6 +22,7 @@ import espressomd import numpy as np from time import time +from itertools import product @ut.skipIf(not espressomd.has_features("DPD"),"Skipped because feature is disabled") class DPDThermostat(ut.TestCase): @@ -32,7 +33,14 @@ class DPDThermostat(ut.TestCase): s.box_l = 3 * [10] s.time_step = 0.01 s.cell_system.skin=0.4 - s.seed=range(s.cell_system.get_state()["n_nodes"]) + + def setUp(self): + self.s.seed = range(self.s.cell_system.get_state()["n_nodes"]) + np.random.seed(13) + + def tearDown(self): + s = self.s + s.part.clear() def single_component_maxwell(self,x1,x2,kT): """Integrate the probability density from x1 to x2 using the trapez rule""" @@ -64,7 +72,6 @@ def test_single(self): """Test velocity distribution of a dpd fluid with a single type.""" N=200 s=self.s - s.part.clear() s.part.add(pos=s.box_l * np.random.random((N,3))) kT=2.3 gamma=1.5 @@ -73,10 +80,10 @@ def test_single(self): weight_function=0, gamma=gamma, r_cut=1.5, trans_weight_function=0, trans_gamma=gamma, trans_r_cut=1.5) s.integrator.run(100) - loops=1000 + loops=250 v_stored=np.zeros((N*loops,3)) for i in range(loops): - s.integrator.run(5) + s.integrator.run(10) v_stored[i*N:(i+1)*N,:]=s.part[:].v v_minmax=5 bins=5 @@ -88,7 +95,6 @@ def test_binary(self): """Test velocity distribution of binary dpd fluid""" N=200 s=self.s - s.part.clear() s.part.add(pos=s.box_l * np.random.random((N//2,3)), type=N//2*[0]) s.part.add(pos=s.box_l * np.random.random((N//2,3)), type=N//2*[1]) kT=2.3 @@ -104,10 +110,10 @@ def test_binary(self): weight_function=0, gamma=gamma, r_cut=1.5, trans_weight_function=0, trans_gamma=gamma, trans_r_cut=1.5) s.integrator.run(100) - loops=1000 + loops=250 v_stored=np.zeros((N*loops,3)) for i in range(loops): - s.integrator.run(5) + s.integrator.run(10) v_stored[i*N:(i+1)*N,:]=s.part[:].v v_minmax=5 bins=5 @@ -118,7 +124,6 @@ def test_binary(self): def test_disable(self): N=200 s=self.s - s.part.clear() s.time_step=0.01 s.part.add(pos=np.random.random((N,3))) kT=2.3 @@ -127,14 +132,14 @@ def test_disable(self): s.non_bonded_inter[0,0].dpd.set_params( weight_function=0, gamma=gamma, r_cut=1.5, trans_weight_function=0, trans_gamma=gamma, trans_r_cut=1.5) - s.integrator.run(100) + s.integrator.run(10) s.thermostat.turn_off() # Reset velocities s.part[:].v = [1.,2.,3.] - s.integrator.run(100) + s.integrator.run(10) # Check that there was neither noise nor friction for v in s.part[:].v: @@ -147,10 +152,13 @@ def test_disable(self): # Reset velocities for faster convergence s.part[:].v = [0.,0.,0.] - loops=1000 + # Equilibrate + s.integrator.run(250) + + loops=250 v_stored=np.zeros((N*loops,3)) for i in range(loops): - s.integrator.run(5) + s.integrator.run(10) v_stored[i*N:(i+1)*N,:]=s.part[:].v v_minmax=5 bins=5 @@ -159,7 +167,6 @@ def test_disable(self): def test_const_weight_function(self): s=self.s - s.part.clear() kT=0. gamma=1.42 s.thermostat.set_dpd(kT=kT) @@ -208,7 +215,6 @@ def test_const_weight_function(self): def test_linear_weight_function(self): s=self.s - s.part.clear() kT=0. gamma=1.42 s.thermostat.set_dpd(kT=kT) @@ -270,6 +276,69 @@ def omega(dist, r_cut): self.assertTrue(abs(s.part[1].f[1] + omega(0.5, 1.4)**2*gamma*v[1]) < 1e-11) self.assertTrue(abs(s.part[1].f[2] + omega(0.5, 1.4)**2*gamma*v[2]) < 1e-11) + def test_ghosts_have_v(self): + s=self.s + + s.box_l = 3 * [10.] + + r_cut=1.5 + dx = 0.25 * r_cut + + def f(i): + if i == 0: + return dx + else: + return 10. - dx + + # Put a particle in every corner + for ind in product([0, 1], [0, 1], [0, 1]): + pos = [f(x) for x in ind] + v = ind + s.part.add(pos=pos, v=v) + + gamma=1.0 + s.thermostat.set_dpd(kT=0.0) + s.non_bonded_inter[0,0].dpd.set_params( + weight_function=0, gamma=gamma, r_cut=r_cut, + trans_weight_function=0, trans_gamma=gamma, trans_r_cut=r_cut) + + s.integrator.run(0) + + id = 0 + for ind in product([0, 1], [0, 1], [0, 1]): + for i in ind: + if ind[i] == 0: + sgn = 1 + else: + sgn = -1 + + self.assertAlmostEqual(sgn*4.0, s.part[id].f[i]) + id += 1 + + + @ut.skipIf(not espressomd.has_features(["CONSTRAINTS", "DPD"]), "Skipped due to missing features.") + def test_constraint(self): + import espressomd.shapes + + s = self.s + + s.constraints.add(shape=espressomd.shapes.Wall(dist=0, normal=[1,0,0]), particle_type=0, particle_velocity=[1,2,3]) + + s.thermostat.set_dpd(kT=0.0) + s.non_bonded_inter[0,0].dpd.set_params( + weight_function=0, gamma=1., r_cut=1.0, + trans_weight_function=0, trans_gamma=1., trans_r_cut=1.0) + + p = s.part.add(pos=[0.5,0,0], type=0, v=[0,0,0]) + + s.integrator.run(0) + + self.assertAlmostEqual(p.f[0], 1.) + self.assertAlmostEqual(p.f[1], 2.) + self.assertAlmostEqual(p.f[2], 3.) + + for c in s.constraints: + s.constraints.remove(c) if __name__ == "__main__": ut.main() diff --git a/testsuite/ek_common.py b/testsuite/ek_common.py new file mode 100644 index 00000000000..39ccb0690c3 --- /dev/null +++ b/testsuite/ek_common.py @@ -0,0 +1,86 @@ +import math + +# Some common functions used by the ek tests + +# root finding function + + +def solve(xi, d, bjerrum_length, sigma, valency): + pi = math.pi + el_char = 1.0 + return xi * math.tan(xi * d / 2.0) + 2.0 * pi * \ + bjerrum_length * sigma / (valency * el_char) + +# function to calculate the density + + +def density(x, xi, bjerrum_length): + pi = math.pi + kb = 1.0 + return (xi * xi) / (2.0 * pi * bjerrum_length * + math.cos(xi * x) * math.cos(xi * x)) + +# function to calculate the velocity + + +def velocity( + x, + xi, + d, + bjerrum_length, + force, + viscosity_kinematic, + density_water): + pi = math.pi + return force * math.log(math.cos(xi * x) / math.cos(xi * d / 2.0)) / \ + (2.0 * pi * bjerrum_length * viscosity_kinematic * density_water) + +# function to calculate the nonzero component of the pressure tensor + + +def pressure_tensor_offdiagonal(x, xi, bjerrum_length, force): + pi = math.pi + return force * xi * math.tan(xi * x) / (2.0 * pi * bjerrum_length) + +# function to calculate the hydrostatic pressure + +# Technically, the LB simulates a compressible fluid, whiches pressure +# tensor contains an additional term on the diagonal, proportional to +# the divergence of the velocity. We neglect this contribution, which +# creates a small error in the direction normal to the wall, which +# should decay with the simulation time. + + +def hydrostatic_pressure( + ek, + x, + xi, + bjerrum_length, + tensor_entry, + box_x, + box_y, + box_z, + agrid): + offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), + int(box_z / (2 * agrid))].pressure[tensor_entry] + return 0.0 + offset + + +# variant from the nonlinear tests +def hydrostatic_pressure_non_lin( + ek, + x, + xi, + bjerrum_length, + tensor_entry, + box_x, + box_y, + box_z, + agrid, + temperature): + offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), + int(box_z / (2 * agrid))].pressure[tensor_entry] + return temperature * xi * xi * \ + math.tan(xi * x) * math.tan(xi * x) / (2.0 * math.pi * bjerrum_length) + offset + + diff --git a/testsuite/ek_eof_one_species_x.py b/testsuite/ek_eof_one_species_x.py index 3e2c685901e..44adfa8fae6 100644 --- a/testsuite/ek_eof_one_species_x.py +++ b/testsuite/ek_eof_one_species_x.py @@ -22,6 +22,7 @@ import numpy as np import sys import math +from ek_common import * ########################################################################## # Set up the System # @@ -29,70 +30,6 @@ # Set the slit pore geometry the width is the non-periodic part of the geometry # the padding is used to ensure that there is no field inside outside the slit -# root finding function - - -def solve(xi, d, bjerrum_length, sigma, valency): - pi = math.pi - el_char = 1.0 - return xi * math.tan(xi * d / 2.0) + 2.0 * pi * \ - bjerrum_length * sigma / (valency * el_char) - -# function to calculate the density - - -def density(x, xi, bjerrum_length): - pi = math.pi - kb = 1.0 - return (xi * xi) / (2.0 * pi * bjerrum_length * - math.cos(xi * x) * math.cos(xi * x)) - -# function to calculate the velocity - - -def velocity( - x, - xi, - d, - bjerrum_length, - force, - viscosity_kinematic, - density_water): - pi = math.pi - return force * math.log(math.cos(xi * x) / math.cos(xi * d / 2.0)) / \ - (2.0 * pi * bjerrum_length * viscosity_kinematic * density_water) - -# function to calculate the nonzero component of the pressure tensor - - -def pressure_tensor_offdiagonal(x, xi, bjerrum_length, force): - pi = math.pi - return force * xi * math.tan(xi * x) / (2.0 * pi * bjerrum_length) - -# function to calculate the hydrostatic pressure - -# Technically, the LB simulates a compressible fluid, whiches pressure -# tensor contains an additional term on the diagonal, proportional to -# the divergence of the velocity. We neglect this contribution, which -# creates a small error in the direction normal to the wall, which -# should decay with the simulation time. - - -def hydrostatic_pressure( - ek, - x, - xi, - bjerrum_length, - tensor_entry, - box_x, - box_y, - box_z, - agrid): - offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), - int(box_z / (2 * agrid))].pressure[tensor_entry] - return 0.0 + offset - - @ut.skipIf(not espressomd.has_features(["ELECTROKINETICS", "EK_BOUNDARIES"]), "Features not available, skipping test!") class ek_eof_one_species_x(ut.TestCase): diff --git a/testsuite/ek_eof_one_species_x_nonlinear.py b/testsuite/ek_eof_one_species_x_nonlinear.py index 6b73cab08ff..1e935c1770b 100644 --- a/testsuite/ek_eof_one_species_x_nonlinear.py +++ b/testsuite/ek_eof_one_species_x_nonlinear.py @@ -22,6 +22,7 @@ import numpy as np import sys import math +from ek_common import * ########################################################################## # Set up the System # @@ -29,72 +30,6 @@ # Set the slit pore geometry the width is the non-periodic part of the geometry # the padding is used to ensure that there is no field inside outside the slit -# root finding function - - -def solve(xi, d, bjerrum_length, sigma, valency): - pi = math.pi - el_char = 1.0 - return xi * math.tan(xi * d / 2.0) + 2.0 * pi * \ - bjerrum_length * sigma / (valency * el_char) - -# function to calculate the density - - -def density(x, xi, bjerrum_length): - pi = math.pi - kb = 1.0 - return (xi * xi) / (2.0 * pi * bjerrum_length * - math.cos(xi * x) * math.cos(xi * x)) - -# function to calculate the velocity - - -def velocity( - x, - xi, - d, - bjerrum_length, - force, - viscosity_kinematic, - density_water): - pi = math.pi - return force * math.log(math.cos(xi * x) / math.cos(xi * d / 2.0)) / \ - (2.0 * pi * bjerrum_length * viscosity_kinematic * density_water) - -# function to calculate the nonzero component of the pressure tensor - - -def pressure_tensor_offdiagonal(x, xi, bjerrum_length, force): - pi = math.pi - return force * xi * math.tan(xi * x) / (2.0 * pi * bjerrum_length) - -# function to calculate the hydrostatic pressure - -# Technically, the LB simulates a compressible fluid, whiches pressure -# tensor contains an additional term on the diagonal, proportional to -# the divergence of the velocity. We neglect this contribution, which -# creates a small error in the direction normal to the wall, which -# should decay with the simulation time. - - -def hydrostatic_pressure( - ek, - x, - xi, - bjerrum_length, - tensor_entry, - box_x, - box_y, - box_z, - agrid, - temperature): - offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), - int(box_z / (2 * agrid))].pressure[tensor_entry] - return temperature * xi * xi * \ - math.tan(xi * x) * math.tan(xi * x) / (2.0 * math.pi * bjerrum_length) + offset - - @ut.skipIf(not espressomd.has_features(["ELECTROKINETICS", "EK_BOUNDARIES"]), "Features not available, skipping test!") class ek_eof_one_species_x(ut.TestCase): @@ -271,15 +206,15 @@ def test(self): measured_pressure_xx = ek[int( box_x / (2 * agrid)), int(box_y / (2 * agrid)), i].pressure[(0, 0)] - calculated_pressure_xx = hydrostatic_pressure( + calculated_pressure_xx = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (0, 0), box_x, box_y, box_z, agrid, temperature) measured_pressure_yy = ek[int( box_x / (2 * agrid)), int(box_y / (2 * agrid)), i].pressure[(1, 1)] - calculated_pressure_yy = hydrostatic_pressure( + calculated_pressure_yy = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (1, 1), box_x, box_y, box_z, agrid, temperature) measured_pressure_zz = ek[int( box_x / (2 * agrid)), int(box_y / (2 * agrid)), i].pressure[(2, 2)] - calculated_pressure_zz = hydrostatic_pressure( + calculated_pressure_zz = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (2, 2), box_x, box_y, box_z, agrid, temperature) pressure_difference_xx = abs( diff --git a/testsuite/ek_eof_one_species_y.py b/testsuite/ek_eof_one_species_y.py index 6920fc0b715..6686d8b7a43 100644 --- a/testsuite/ek_eof_one_species_y.py +++ b/testsuite/ek_eof_one_species_y.py @@ -22,6 +22,7 @@ import numpy as np import sys import math +from ek_common import * ########################################################################## # Set up the System # @@ -29,70 +30,6 @@ # Set the slit pore geometry the width is the non-periodic part of the geometry # the padding is used to ensure that there is no field inside outside the slit -# root finding function - - -def solve(xi, d, bjerrum_length, sigma, valency): - pi = math.pi - el_char = 1.0 - return xi * math.tan(xi * d / 2.0) + 2.0 * pi * \ - bjerrum_length * sigma / (valency * el_char) - -# function to calculate the density - - -def density(x, xi, bjerrum_length): - pi = math.pi - kb = 1.0 - return (xi * xi) / (2.0 * pi * bjerrum_length * - math.cos(xi * x) * math.cos(xi * x)) - -# function to calculate the velocity - - -def velocity( - x, - xi, - d, - bjerrum_length, - force, - viscosity_kinematic, - density_water): - pi = math.pi - return force * math.log(math.cos(xi * x) / math.cos(xi * d / 2.0)) / \ - (2.0 * pi * bjerrum_length * viscosity_kinematic * density_water) - -# function to calculate the nonzero component of the pressure tensor - - -def pressure_tensor_offdiagonal(x, xi, bjerrum_length, force): - pi = math.pi - return force * xi * math.tan(xi * x) / (2.0 * pi * bjerrum_length) - -# function to calculate the hydrostatic pressure - -# Technically, the LB simulates a compressible fluid, whiches pressure -# tensor contains an additional term on the diagonal, proportional to -# the divergence of the velocity. We neglect this contribution, which -# creates a small error in the direction normal to the wall, which -# should decay with the simulation time. - - -def hydrostatic_pressure( - ek, - x, - xi, - bjerrum_length, - tensor_entry, - box_x, - box_y, - box_z, - agrid): - offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), - int(box_z / (2 * agrid))].pressure[tensor_entry] - return 0.0 + offset - - @ut.skipIf(not espressomd.has_features(["ELECTROKINETICS", "EK_BOUNDARIES"]), "Features not available, skipping test!") class ek_eof_one_species_x(ut.TestCase): @@ -103,16 +40,16 @@ def test(self): system = self.es pi = math.pi - box_z = 6 - box_y = 6 - width = 50 + box_z = 4 + box_y = 4 + width = 40 padding = 6 box_x = width + 2 * padding # Set the electrokinetic parameters agrid = 0.5 - dt = 1.0 / 11.0 + dt = 1.0 / 6.0 force = 0.13 sigma = -0.03 viscosity_kinematic = 1.0 @@ -132,7 +69,7 @@ def test(self): system.time_step = dt system.cell_system.skin = 0.1 system.thermostat.turn_off() - integration_length = 20000 + integration_length = 12000 # Output density, velocity, and pressure tensor profiles diff --git a/testsuite/ek_eof_one_species_y_nonlinear.py b/testsuite/ek_eof_one_species_y_nonlinear.py index ee4a05c8aa6..fdc8a3324fc 100644 --- a/testsuite/ek_eof_one_species_y_nonlinear.py +++ b/testsuite/ek_eof_one_species_y_nonlinear.py @@ -22,6 +22,7 @@ import numpy as np import sys import math +from ek_common import * ########################################################################## @@ -30,70 +31,6 @@ # Set the slit pore geometry the width is the non-periodic part of the geometry # the padding is used to ensure that there is no field inside outside the slit -# root finding function -def solve(xi, d, bjerrum_length, sigma, valency): - pi = math.pi - el_char = 1.0 - return xi * math.tan(xi * d / 2.0) + 2.0 * pi * \ - bjerrum_length * sigma / (valency * el_char) - -# function to calculate the density - - -def density(x, xi, bjerrum_length): - pi = math.pi - kb = 1.0 - return (xi * xi) / (2.0 * pi * bjerrum_length * - math.cos(xi * x) * math.cos(xi * x)) - -# function to calculate the velocity - - -def velocity( - x, - xi, - d, - bjerrum_length, - force, - viscosity_kinematic, - density_water): - pi = math.pi - return force * math.log(math.cos(xi * x) / math.cos(xi * d / 2.0)) / \ - (2.0 * pi * bjerrum_length * viscosity_kinematic * density_water) - -# function to calculate the nonzero component of the pressure tensor - - -def pressure_tensor_offdiagonal(x, xi, bjerrum_length, force): - pi = math.pi - return force * xi * math.tan(xi * x) / (2.0 * pi * bjerrum_length) - -# function to calculate the hydrostatic pressure - -# Technically, the LB simulates a compressible fluid, whiches pressure -# tensor contains an additional term on the diagonal, proportional to -# the divergence of the velocity. We neglect this contribution, which -# creates a small error in the direction normal to the wall, which -# should decay with the simulation time. - - -def hydrostatic_pressure( - ek, - x, - xi, - bjerrum_length, - tensor_entry, - box_x, - box_y, - box_z, - agrid, - temperature): - offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), - int(box_z / (2 * agrid))].pressure[tensor_entry] - return temperature * xi * xi * \ - math.tan(xi * x) * math.tan(xi * x) / (2.0 * math.pi * bjerrum_length) + offset - - @ut.skipIf(not espressomd.has_features(["ELECTROKINETICS", "EK_BOUNDARIES"]), "Features not available, skipping test!") class ek_eof_one_species_x(ut.TestCase): @@ -104,16 +41,16 @@ def test(self): system = self.es pi = math.pi - box_z = 6 - box_y = 6 - width = 50 + box_z = 4 + box_y = 4 + width = 32 padding = 6 box_x = width + 2 * padding # Set the electrokinetic parameters agrid = 0.5 - dt = 1.0 / 11.0 + dt = 1.0 / 5.0 force = 0.13 sigma = -0.03 viscosity_kinematic = 1.0 @@ -133,7 +70,7 @@ def test(self): system.time_step = dt system.cell_system.skin = 0.1 system.thermostat.turn_off() - integration_length = 20000 + integration_length = 10000 # Output density, velocity, and pressure tensor profiles @@ -276,15 +213,15 @@ def test(self): measured_pressure_xx = ek[i, int( box_y / (2 * agrid)), int(box_z / (2 * agrid))].pressure[(0, 0)] - calculated_pressure_xx = hydrostatic_pressure( + calculated_pressure_xx = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (0, 0), box_x, box_y, box_z, agrid, temperature) measured_pressure_yy = ek[i, int( box_y / (2 * agrid)), int(box_z / (2 * agrid))].pressure[(1, 1)] - calculated_pressure_yy = hydrostatic_pressure( + calculated_pressure_yy = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (1, 1), box_x, box_y, box_z, agrid, temperature) measured_pressure_zz = ek[i, int( box_y / (2 * agrid)), int(box_z / (2 * agrid))].pressure[(2, 2)] - calculated_pressure_zz = hydrostatic_pressure( + calculated_pressure_zz = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (2, 2), box_x, box_y, box_z, agrid, temperature) pressure_difference_xx = abs( diff --git a/testsuite/ek_eof_one_species_z.py b/testsuite/ek_eof_one_species_z.py index 33e53e88276..70ddaae8462 100644 --- a/testsuite/ek_eof_one_species_z.py +++ b/testsuite/ek_eof_one_species_z.py @@ -22,6 +22,7 @@ import numpy as np import sys import math +from ek_common import * ########################################################################## @@ -30,68 +31,6 @@ # Set the slit pore geometry the width is the non-periodic part of the geometry # the padding is used to ensure that there is no field inside outside the slit -# root finding function -def solve(xi, d, bjerrum_length, sigma, valency): - pi = math.pi - el_char = 1.0 - return xi * math.tan(xi * d / 2.0) + 2.0 * pi * \ - bjerrum_length * sigma / (valency * el_char) - -# function to calculate the density - - -def density(x, xi, bjerrum_length): - pi = math.pi - kb = 1.0 - return (xi * xi) / (2.0 * pi * bjerrum_length * - math.cos(xi * x) * math.cos(xi * x)) - -# function to calculate the velocity - - -def velocity( - x, - xi, - d, - bjerrum_length, - force, - viscosity_kinematic, - density_water): - pi = math.pi - return force * math.log(math.cos(xi * x) / math.cos(xi * d / 2.0)) / \ - (2.0 * pi * bjerrum_length * viscosity_kinematic * density_water) - -# function to calculate the nonzero component of the pressure tensor - - -def pressure_tensor_offdiagonal(x, xi, bjerrum_length, force): - pi = math.pi - return force * xi * math.tan(xi * x) / (2.0 * pi * bjerrum_length) - -# function to calculate the hydrostatic pressure - -# Technically, the LB simulates a compressible fluid, whiches pressure -# tensor contains an additional term on the diagonal, proportional to -# the divergence of the velocity. We neglect this contribution, which -# creates a small error in the direction normal to the wall, which -# should decay with the simulation time. - - -def hydrostatic_pressure( - ek, - x, - xi, - bjerrum_length, - tensor_entry, - box_x, - box_y, - box_z, - agrid): - offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), - int(box_z / (2 * agrid))].pressure[tensor_entry] - return 0.0 + offset - - @ut.skipIf(not espressomd.has_features(["ELECTROKINETICS", "EK_BOUNDARIES"]), "Features not available, skipping test!") class ek_eof_one_species_x(ut.TestCase): @@ -102,16 +41,16 @@ def test(self): system = self.es pi = math.pi - box_z = 6 - box_x = 6 - width = 50 + box_z = 3 + box_x = 3 + width = 40 padding = 6 box_y = width + 2 * padding # Set the electrokinetic parameters agrid = 1.0 / 3.0 - dt = 1.0 / 13.0 + dt = 1.0 / 7.0 force = 0.07 sigma = -0.04 viscosity_kinematic = 1.7 @@ -131,7 +70,7 @@ def test(self): system.time_step = dt system.cell_system.skin = 0.1 system.thermostat.turn_off() - integration_length = 20000 + integration_length = 9000 # Output density, velocity, and pressure tensor profiles diff --git a/testsuite/ek_eof_one_species_z_nonlinear.py b/testsuite/ek_eof_one_species_z_nonlinear.py index f0445779d05..b502cdecd4a 100644 --- a/testsuite/ek_eof_one_species_z_nonlinear.py +++ b/testsuite/ek_eof_one_species_z_nonlinear.py @@ -22,6 +22,10 @@ import numpy as np import sys import math +from ek_common import * + + + ########################################################################## # Set up the System # @@ -29,72 +33,6 @@ # Set the slit pore geometry the width is the non-periodic part of the geometry # the padding is used to ensure that there is no field inside outside the slit -# root finding function - - -def solve(xi, d, bjerrum_length, sigma, valency): - pi = math.pi - el_char = 1.0 - return xi * math.tan(xi * d / 2.0) + 2.0 * pi * \ - bjerrum_length * sigma / (valency * el_char) - -# function to calculate the density - - -def density(x, xi, bjerrum_length): - pi = math.pi - kb = 1.0 - return (xi * xi) / (2.0 * pi * bjerrum_length * - math.cos(xi * x) * math.cos(xi * x)) - -# function to calculate the velocity - - -def velocity( - x, - xi, - d, - bjerrum_length, - force, - viscosity_kinematic, - density_water): - pi = math.pi - return force * math.log(math.cos(xi * x) / math.cos(xi * d / 2.0)) / \ - (2.0 * pi * bjerrum_length * viscosity_kinematic * density_water) - -# function to calculate the nonzero component of the pressure tensor - - -def pressure_tensor_offdiagonal(x, xi, bjerrum_length, force): - pi = math.pi - return force * xi * math.tan(xi * x) / (2.0 * pi * bjerrum_length) - -# function to calculate the hydrostatic pressure - -# Technically, the LB simulates a compressible fluid, whiches pressure -# tensor contains an additional term on the diagonal, proportional to -# the divergence of the velocity. We neglect this contribution, which -# creates a small error in the direction normal to the wall, which -# should decay with the simulation time. - - -def hydrostatic_pressure( - ek, - x, - xi, - bjerrum_length, - tensor_entry, - box_x, - box_y, - box_z, - agrid, - temperature): - offset = ek[int(box_x / (2 * agrid)), int(box_y / (2 * agrid)), - int(box_z / (2 * agrid))].pressure[tensor_entry] - return temperature * xi * xi * \ - math.tan(xi * x) * math.tan(xi * x) / (2.0 * math.pi * bjerrum_length) + offset - - @ut.skipIf(not espressomd.has_features(["ELECTROKINETICS", "EK_BOUNDARIES"]), "Features not available, skipping test!") class ek_eof_one_species_x(ut.TestCase): @@ -105,16 +43,16 @@ def test(self): system = self.es pi = math.pi - box_z = 6 - box_x = 6 - width = 50 + box_z = 3 + box_x = 3 + width = 30 padding = 6 box_y = width + 2 * padding # Set the electrokinetic parameters agrid = 1.0 / 3.0 - dt = 1.0 / 13.0 + dt = 1.0 / 8. force = 0.07 sigma = -0.04 viscosity_kinematic = 1.7 @@ -134,7 +72,7 @@ def test(self): system.time_step = dt system.cell_system.skin = 0.1 system.thermostat.turn_off() - integration_length = 20000 + integration_length = 10000 # Output density, velocity, and pressure tensor profiles @@ -277,15 +215,15 @@ def test(self): measured_pressure_xx = ek[int( box_x / (2 * agrid)), i, int(box_z / (2 * agrid))].pressure[(0, 0)] - calculated_pressure_xx = hydrostatic_pressure( + calculated_pressure_xx = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (0, 0), box_x, box_y, box_z, agrid, temperature) measured_pressure_yy = ek[int( box_x / (2 * agrid)), i, int(box_z / (2 * agrid))].pressure[(1, 1)] - calculated_pressure_yy = hydrostatic_pressure( + calculated_pressure_yy = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (1, 1), box_x, box_y, box_z, agrid, temperature) measured_pressure_zz = ek[int( box_x / (2 * agrid)), i, int(box_z / (2 * agrid))].pressure[(2, 2)] - calculated_pressure_zz = hydrostatic_pressure( + calculated_pressure_zz = hydrostatic_pressure_non_lin( ek, position, xi, bjerrum_length, (2, 2), box_x, box_y, box_z, agrid, temperature) pressure_difference_xx = abs( diff --git a/testsuite/rotation_per_particle.py b/testsuite/rotation_per_particle.py index e03a5b36f5a..6643de75a57 100644 --- a/testsuite/rotation_per_particle.py +++ b/testsuite/rotation_per_particle.py @@ -87,7 +87,56 @@ def test_axes_changes(self): self.assertLess(np.dot(axis,s.part[0].convert_vector_body_to_space(axis)),0.95) - + + + def test_frame_conversion_and_rotation(self): + s=self.s + s.part.clear() + p=s.part.add(pos=np.random.random(3),rotation=(1,1,1)) + + # Space and body frame co-incide? + np.testing.assert_allclose(p.director,p.convert_vector_body_to_space((0,0,1)),atol=1E-10) + + # Random vector should still co-incide + v=(1.,5.5,17) + np.testing.assert_allclose(v,p.convert_vector_space_to_body(v),atol=1E-10) + np.testing.assert_allclose(v,p.convert_vector_body_to_space(v),atol=1E-10) + + # Particle rotation + + p.rotate((1,2,0),np.pi/4) + # Check angle for director + self.assertAlmostEqual(np.arccos(np.dot(p.director, (0,0,1))),np.pi/4,delta=1E-10) + # Check other vector + v=(5,-7,3) + v_r=p.convert_vector_body_to_space(v) + self.assertAlmostEqual(np.dot(v,v),np.dot(v_r,v_r),delta=1e-10) + np.testing.assert_allclose(p.convert_vector_space_to_body(v_r),v,atol=1E-10) + + # Rotation axis should co-incide + np.testing.assert_allclose((1,2,0),p.convert_vector_body_to_space((1,2,0))) + + + # Check rotation axis with all elements set + p.rotate(axis=(-5,2,17),angle=1.) + v=(5,-7,3) + v_r=p.convert_vector_body_to_space(v) + self.assertAlmostEqual(np.dot(v,v),np.dot(v_r,v_r),delta=1e-10) + np.testing.assert_allclose(p.convert_vector_space_to_body(v_r),v,atol=1E-10) + + + + + + + + + + + # + + + diff --git a/testsuite/save_checkpoint.py b/testsuite/save_checkpoint.py new file mode 100644 index 00000000000..ffb68e65c7d --- /dev/null +++ b/testsuite/save_checkpoint.py @@ -0,0 +1,25 @@ +import espressomd +import espressomd.checkpointing +import espressomd.virtual_sites + +checkpoint = espressomd.checkpointing.Checkpointing(checkpoint_id="mycheckpoint", checkpoint_path="@CMAKE_CURRENT_BINARY_DIR@") + +system = espressomd.System(box_l=[10.0, 10.0, 10.0]) +checkpoint.register("system") +system.cell_system.skin = 0.4 +system.time_step = 0.01 +system.min_global_cut = 2.0 + +system.part.add(pos=[1.0]*3) +system.part.add(pos=[1.0, 1.0, 2.0]) + +system.thermostat.set_langevin(kT=1.0, gamma=2.0) + +if espressomd.has_features(['VIRTUAL_SITES', 'VIRTUAL_SITES_RELATIVE']): + system.virtual_sites = espressomd.virtual_sites.VirtualSitesRelative(have_velocity = True, + have_quaternion = True) + system.part[1].vs_auto_relate_to(0) + checkpoint.register("system.virtual_sites") +if espressomd.has_features(['LENNARD_JONES']): + system.non_bonded_inter[0, 0].lennard_jones.set_params(epsilon=1.2, sigma=1.3, cutoff=2.0, shift=0.1) +checkpoint.save(0) diff --git a/testsuite/stress.py b/testsuite/stress.py index 52fb7a966f5..a52f781d904 100644 --- a/testsuite/stress.py +++ b/testsuite/stress.py @@ -3,10 +3,13 @@ from __future__ import print_function import unittest as ut + import espressomd from espressomd.interactions import HarmonicBond from espressomd.interactions import FeneBond from espressomd import analyze +from espressomd.observables import StressTensor + import itertools from tests_common import fene_force, fene_potential, fene_force2 @@ -259,6 +262,12 @@ def test(self): self.assertTrue(np.max(np.abs(sim_pressure_total-sim_pressure_kinetic-sim_pressure_bonded-sim_pressure_nonbonded)) < tol, 'total pressure is not given as the sum of all major pressure components') + # Compare stress tensor observable to stress tensor from analysis + np.testing.assert_allclose( + StressTensor().calculate(), + system.analysis.stress_tensor()["total"].reshape(9), + atol=1E-10) + @ut.skipIf(not espressomd.has_features(['EXTERNAL_FORCES']), 'Features not available, skipping test!') class stress_test_fene(ut.TestCase): @@ -312,6 +321,13 @@ def test_fene(self): sim_pressure_fene=system.analysis.pressure()['bonded',len(system.bonded_inter)-1] anal_pressure_fene=np.einsum("ii",anal_stress_fene)/3.0 self.assertTrue(np.max(np.abs(sim_pressure_fene-anal_pressure_fene)) < tol, 'bonded pressure for fene does not match analytical result') + + + # Compare stress tensor observable to stress tensor from analysis + np.testing.assert_allclose( + StressTensor().calculate(), + system.analysis.stress_tensor()["total"].reshape(9), + atol=1E-10) system.part.clear() @@ -511,6 +527,11 @@ def test(self): self.assertTrue(np.abs(sim_pressure_nonbonded_intra-anal_pressure_nonbonded_intra) < tol, 'non-bonded intramolecular pressure does not match analytical result') self.assertTrue(np.abs(sim_pressure_nonbonded_intra00-anal_pressure_nonbonded_intra) < tol, 'non-bonded intramolecular pressure molecule 0 does not match analytical result') self.assertTrue(np.abs(sim_pressure_total-anal_pressure_total) < tol, 'total pressure does not match analytical result') + # Compare stress tensor observable to stress tensor from analysis + np.testing.assert_allclose( + StressTensor().calculate(), + system.analysis.stress_tensor()["total"].reshape(9), + atol=1E-10) if __name__ == "__main__": ut.main() diff --git a/testsuite/catalytic_reaction.py b/testsuite/swimmer_reaction.py similarity index 89% rename from testsuite/catalytic_reaction.py rename to testsuite/swimmer_reaction.py index ea5c58b5990..c95105ea06c 100644 --- a/testsuite/catalytic_reaction.py +++ b/testsuite/swimmer_reaction.py @@ -3,10 +3,10 @@ import espressomd from espressomd import has_features -if(has_features(["CATALYTIC_REACTIONS"])): - from espressomd.reaction import Reaction +if(has_features(["SWIMMER_REACTIONS"])): + from espressomd.swimmer_reaction import Reaction -@ut.skipIf(not has_features(["CATALYTIC_REACTIONS"]), +@ut.skipIf(not has_features(["SWIMMER_REACTIONS"]), "Features missing") class ReactionTest(ut.TestCase): diff --git a/testsuite/test_checkpoint.py b/testsuite/test_checkpoint.py new file mode 100644 index 00000000000..790dea902cc --- /dev/null +++ b/testsuite/test_checkpoint.py @@ -0,0 +1,49 @@ +import subprocess +import unittest as ut +import numpy as np + +import espressomd +import espressomd.checkpointing +import espressomd.virtual_sites + + + +class CheckpointTest(ut.TestCase): + @classmethod + def setUpClass(self): + # Write checkpoint. + p = subprocess.Popen(['@CMAKE_BINARY_DIR@/pypresso', '@CMAKE_CURRENT_BINARY_DIR@/save_checkpoint.py']) + p.wait() + system = espressomd.System(box_l=[10.0, 10.0, 10.0]) + checkpoint = espressomd.checkpointing.Checkpointing(checkpoint_id="mycheckpoint", checkpoint_path="@CMAKE_CURRENT_BINARY_DIR@") + checkpoint.load(0) + + def test_variables(self): + self.assertEqual(system.cell_system.skin, 0.4) + self.assertEqual(system.time_step, 0.01) + self.assertEqual(system.min_global_cut, 2.0) + + def test_part(self): + np.testing.assert_array_equal(np.copy(system.part[0].pos), np.array([1.0, 1.0, 1.0])) + np.testing.assert_array_equal(np.copy(system.part[1].pos), np.array([1.0, 1.0, 2.0])) + + def test_thermostat(self): + self.assertEqual(system.thermostat.get_state()[0]['type'], 'LANGEVIN') + self.assertEqual(system.thermostat.get_state()[0]['kT'], 1.0) + np.testing.assert_array_equal(system.thermostat.get_state()[0]['gamma'], np.array([2.0, 2.0, 2.0])) + + @ut.skipIf(not espressomd.has_features(['LENNARD_JONES']), + "Cannot test for Lennard-Jones checkpointing because feature not compiled in.") + def test_non_bonded_inter(self): + state = system.non_bonded_inter[0, 0].lennard_jones._get_params_from_es_core() + reference = {'shift': 0.1, 'sigma': 1.3, 'epsilon': 1.2, 'cutoff': 2.0, 'offset': 0.0, 'min': 0.0} + self.assertEqual(len(set(state.items()) & set(reference.items())), len(reference)) + + @ut.skipIf(not espressomd.has_features(['VIRTUAL_SITES', 'VIRTUAL_SITES_RELATIVE']), + "Cannot test for virtual site checkpointing because feature not compiled in.") + def test_virtual_sites(self): + self.assertEqual(system.part[1].virtual, 1) + self.assertTrue(isinstance(system.virtual_sites, espressomd.virtual_sites.VirtualSitesRelative)) + +if __name__ == '__main__': + ut.main() diff --git a/testsuite/thermalized_bond.py b/testsuite/thermalized_bond.py index 0f437428c5b..9552d01f035 100644 --- a/testsuite/thermalized_bond.py +++ b/testsuite/thermalized_bond.py @@ -94,10 +94,10 @@ def test_com_langevin(self): self.system.integrator.run(50) # Sampling - loops = 160 + loops = 200 v_stored = np.zeros((N2 * loops, 3)) for i in range(loops): - self.system.integrator.run(2) + self.system.integrator.run(12) v_com = 1.0/(m1+m2)*(m1*self.system.part[::2].v+m2*self.system.part[1::2].v) v_stored[i * N2:(i + 1) * N2, :] = v_com @@ -138,10 +138,10 @@ def test_dist_langevin(self): self.system.integrator.run(50) # Sampling - loops = 160 + loops = 200 v_stored = np.zeros((N2 * loops, 3)) for i in range(loops): - self.system.integrator.run(2) + self.system.integrator.run(12) v_dist = self.system.part[1::2].v - self.system.part[::2].v v_stored[i * N2:(i + 1) * N2, :] = v_dist From 050881b41af5fea268a816f26e90b7493cc31ee5 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 24 Apr 2018 00:20:56 +0300 Subject: [PATCH 047/150] BD doc update --- doc/sphinx/system_setup.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index 4a0659d9418..0e33f1736fd 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -488,8 +488,9 @@ Note, that the velocity random walk is propagated from zero at each step. A rotational motion is implemented similarly. The Velocity Verlet quaternion based rotational method implementation is still used, however, had been modified for the larger :math:`\Delta t` case to be consistent and still the Velocity Verlet-compliant. -Note: this Brownian dynamics implementation is compatible with particles which have -the isotropic moment of inertia tensor only. +Note: the rotational Brownian dynamics implementation is compatible with particles which have +the isotropic moment of inertia tensor only. Otherwise, the viscous terminal angular velocity +is not defined, i.e. it has no constant direction over the time. .. _CUDA: From 401ab2a11fb961cfb1114124fa3e4418884d6f35 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sun, 27 May 2018 13:24:51 +0300 Subject: [PATCH 048/150] Reduction of the box --- testsuite/mass-and-rinertia_per_particle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 5ccb362bc5b..674034f8b26 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -14,7 +14,7 @@ class ThermoTest(ut.TestCase): longMessage = True # Handle for espresso system - es = espressomd.System(box_l=[1.0E5, 1.0E5, 1.0E5]) + es = espressomd.System(box_l=[1.0, 1.0, 1.0]) rot_flag = 0 def set_thermo_all(self, test_case, kT, gamma_global, gamma_global_rot): From a4b1bda0c1837d22f3fcbbef690044e3fd0a0d1d Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Mon, 28 May 2018 13:21:53 +0300 Subject: [PATCH 049/150] BD test fix according to new accumulators package --- testsuite/brownian_thermostat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index dfe5c2f4caf..bf2d469e9a8 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -16,13 +16,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # +# Tests particle property setters/getters from __future__ import print_function import unittest as ut import espressomd import numpy as np from espressomd.interactions import FeneBond from time import time -from espressomd.correlators import Correlator +from espressomd.accumulators import Correlator from espressomd.observables import ParticleVelocities, ParticleBodyAngularVelocities #TODO: this test should be as close to langevin_thermostat.py as possible From 16faae2b29454b376670d2664491f33e01595e70 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Thu, 14 Jun 2018 23:14:10 +0300 Subject: [PATCH 050/150] Longrun removal --- ...d-rinertia_per_particle_rotdiff-longrun.py | 653 ------------------ 1 file changed, 653 deletions(-) delete mode 100644 testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py diff --git a/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py b/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py deleted file mode 100644 index 343afdd98ca..00000000000 --- a/testsuite/mass-and-rinertia_per_particle_rotdiff-longrun.py +++ /dev/null @@ -1,653 +0,0 @@ -from __future__ import print_function -import unittest as ut -import numpy as np -from numpy.random import random, seed -import espressomd -import math -import tests_common as tc - -@ut.skipIf(not espressomd.has_features(["MASS", - "PARTICLE_ANISOTROPY", - "ROTATIONAL_INERTIA", - "LANGEVIN_PER_PARTICLE"]), - "Features not available, skipping test!") -class ThermoTest(ut.TestCase): - longMessage = True - # Handle for espresso system - es = espressomd.System(box_l=[1.0E5, 1.0E5, 1.0E5]) - rot_flag = 0 - - def set_thermo_all(self, test_case, kT, gamma_global, gamma_global_rot): - if test_case < 4: - self.es.thermostat.set_langevin( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 4 and self.rot_flag == 1: - self.es.thermostat.set_langevin( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) - elif test_case < 8 + self.rot_flag: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]]) - elif test_case == 9: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian thermostat activation - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian( - kT=kT, - gamma=[ - gamma_global[0], - gamma_global[1], - gamma_global[2]], - gamma_rotation=[ - gamma_global_rot[0], - gamma_global_rot[1], - gamma_global_rot[2]]) - - def run_test_case(self, test_case): - seed(2) - # Decelleration - self.es.time_step = 0.007 - self.es.part.clear() - # gamma_tran/gamma_rot matrix: [2 types of particless] x [3 dimensions - # X Y Z] - gamma_tran = np.zeros((2, 3)) - gamma_tr = np.zeros((2, 3)) - gamma_rot = np.zeros((2, 3)) - gamma_rot_validate = np.zeros((2, 3)) - # The translational gamma isotropy is required here. See comments below. - # Global gamma for tests without particle-specific gammas: - # gamma_global = np.ones((3)) - gamma_global = np.zeros((3)) - gamma_global[0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) - gamma_global[1] = gamma_global[0] - gamma_global[2] = gamma_global[0] - # Additional test case (5th) for the specific global rotational gamma set. - gamma_global_rot = np.array((0.5 + np.random.random(3)) * 2.0 / 3.0) - # Per-paricle values for the remaining decelleration tests: - # Either translational friction isotropy is required - # or both translational and rotational ones. - # Otherwise these types of motion will interfere. - # ..Let's test both cases depending on the particle index. - gamma_tran[0, 0] = np.array(0.5 + np.random.random()) - gamma_tran[0, 1] = gamma_tran[0, 0] - gamma_tran[0, 2] = gamma_tran[0, 0] - if test_case < 4 + self.rot_flag: - gamma_rot[0, :] = np.array((0.5 + random(3)) * 2.0 / 3.0) - else: - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Isotropy is required here for the drag tests (see below) - gamma_rot[0, 0] = np.array((0.5 + random(1)) * 2.0 / 3.0) - gamma_rot[0, 1] = gamma_rot[0, 0] - gamma_rot[0, 2] = gamma_rot[0, 0] - - gamma_tran[1, 0] = np.array(0.5 + np.random.random()) - gamma_tran[1, 1] = gamma_tran[1, 0] - gamma_tran[1, 2] = gamma_tran[1, 0] - gamma_rot[1, 0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) - gamma_rot[1, 1] = gamma_rot[1, 0] - gamma_rot[1, 2] = gamma_rot[1, 0] - - self.set_thermo_all(test_case, 0.0, gamma_global, gamma_global_rot) - - self.es.cell_system.skin = 5.0 - mass = 12.74 - J = [10.0, 10.0, 10.0] - - for i in range(len(self.es.part)): - self.es.part[i].remove() - - for i in range(2): - self.es.part.add(rotation=(1,1,1), pos=np.array([0.0, 0.0, 0.0]), id=i) - self.es.part[i].v = np.array([1.0, 1.0, 1.0]) - if "ROTATION" in espressomd.features(): - self.es.part[i].omega_body = np.array([1.0, 1.0, 1.0]) - self.es.part[i].mass = mass - self.es.part[i].rinertia = np.array(J) - - print("\n") - - for k in range(2): - if test_case == 0: - if (k == 0): - print("================================================") - print("Langevin thermostat test cases") - print("================================================") - print("------------------------------------------------") - print("Test " + str(test_case) + ": no particle specific values") - print("------------------------------------------------") - # No assignments are needed. - - if test_case == 1: - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + - ": particle specific gamma but not temperature") - print("------------------------------------------------") - self.es.part[k].gamma = gamma_tran[k, :] - if "ROTATION" in espressomd.features(): - self.es.part[k].gamma_rot = gamma_rot[k, :] - - if test_case == 2: - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + - ": particle specific temperature but not gamma") - print("------------------------------------------------") - self.es.part[k].temp = 0.0 - - if test_case == 3: - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + - ": both particle specific gamma and temperature") - print("------------------------------------------------") - self.es.part[k].temp = 0.0 - self.es.part[k].gamma = gamma_tran[k, :] - if "ROTATION" in espressomd.features(): - self.es.part[k].gamma_rot = gamma_rot[k, :] - - if test_case == 4 and self.rot_flag == 1: - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + ": no particle specific values.") - print("Rotational specific global thermostat") - print("------------------------------------------------") - # No assignments are needed. - - if "BROWNIAN_DYNAMICS" in espressomd.features(): - for k in range(2): - if test_case == 4 + self.rot_flag: - if (k == 0): - print("================================================") - print("Brownian thermostat test cases") - print("================================================") - print("------------------------------------------------") - print("Test " + str(test_case) + ": no particle specific values") - print("------------------------------------------------") - # No assignments are needed. - - if test_case == 5 + self.rot_flag: - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + - ": particle specific gamma but not temperature") - print("------------------------------------------------") - if "PARTICLE_ANISOTROPY" in espressomd.features(): - self.es.part[k].gamma = gamma_tran[k, :] - else: - self.es.part[k].gamma = gamma_tran[k, 0] - if "ROTATION" in espressomd.features(): - self.es.part[k].gamma_rot = gamma_rot[k, :] - - if test_case == 6 + self.rot_flag: - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + - ": particle specific temperature but not gamma") - print("------------------------------------------------") - self.es.part[k].temp = 0.0 - - if test_case == 7 + self.rot_flag: - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + - ": both particle specific gamma and temperature") - print("------------------------------------------------") - self.es.part[k].temp = 0.0 - if "PARTICLE_ANISOTROPY" in espressomd.features(): - self.es.part[k].gamma = gamma_tran[k, :] - else: - self.es.part[k].gamma = gamma_tran[k, 0] - if "ROTATION" in espressomd.features(): - self.es.part[k].gamma_rot = gamma_rot[k, :] - - if test_case == 8 + self.rot_flag: - if (k == 0): - if (k == 0): - print("------------------------------------------------") - print("Test " + str(test_case) + ": no particle specific values.") - print("Rotational specific global thermostat") - print("------------------------------------------------") - # No assignments are needed. - - if test_case == 1 or test_case == 3 or test_case == (5 + self.rot_flag) or test_case == (7 + self.rot_flag): - gamma_tr = gamma_tran - gamma_rot_validate = gamma_rot - else: - for k in range(2): - gamma_tr[k, :] = gamma_global[:] - if (test_case == 4 or test_case == 9) and self.rot_flag == 1: - gamma_rot_validate[k, :] = gamma_global_rot[:] - else: - gamma_rot_validate[k, :] = gamma_global[:] - - if test_case < 4 + self.rot_flag: - # Langevin thermostat only. Brownian thermostat is defined - # over larger time-step by its concept. - self.es.time = 0.0 - tol = 1.25E-4 - for i in range(100): - for k in range(2): - for j in range(3): - # Note: velocity is defined in the lab frame of reference - # while gamma_tr is defined in the body one. - # Hence, only isotropic gamma_tr could be tested here. - self.assertLess( - abs(self.es.part[k].v[j] - math.exp(- gamma_tr[k, j] * self.es.time / mass)), tol) - if "ROTATION" in espressomd.features(): - self.assertLess(abs( - self.es.part[k].omega_body[j] - math.exp(- gamma_rot_validate[k, j] * self.es.time / J[j])), tol) - self.es.integrator.run(10) - # The drag terminal velocity tests - ################################## - #..aka the drift in case of the electrostatics - - # Isotropic reassignment is required here for the drag tests - gamma_global_rot = np.zeros((3)) - gamma_global_rot[0] = np.array((0.5 + np.random.random()) * 2.0 / 3.0) - gamma_global_rot[1] = gamma_global_rot[0] - gamma_global_rot[2] = gamma_global_rot[0] - # Second particle already has isotropic gamma_rot - # A correction is needed for the 1st one: - gamma_rot[0, 0] = np.array((0.5 + random(1)) * 2.0 / 3.0) - gamma_rot[0, 1] = gamma_rot[0, 0] - gamma_rot[0, 2] = gamma_rot[0, 0] - - if test_case == 1 or test_case == 3 or test_case == (5 + self.rot_flag) or test_case == (7 + self.rot_flag): - gamma_tr = gamma_tran - gamma_rot_validate = gamma_rot - # A correction is needed for the 1st particle only: - if "ROTATION" in espressomd.features(): - self.es.part[0].gamma_rot = gamma_rot[0, :] - else: - for k in range(2): - gamma_tr[k, :] = gamma_global[:] - if (test_case == 4 or test_case == 9) and self.rot_flag == 1: - gamma_rot_validate[k, :] = gamma_global_rot[:] - else: - gamma_rot_validate[k, :] = gamma_global[:] - - self.set_thermo_all(test_case, 0.0, gamma_global, gamma_global_rot) - - self.es.time = 0.0 - self.es.time_step = 7E-5 - # The terminal velocity is starting since t >> t0 = mass / gamma - t0_max = -1.0 - for k in range(2): - t0_max = max(t0_max, max(mass / gamma_tr[k, :]), max(J[:] / gamma_rot_validate[k, :])) - drag_steps_0 = int(math.floor(20 * t0_max / self.es.time_step)) - print("drag_steps_0 = {0}".format(drag_steps_0)) - - tol = 7E-3 - if "EXTERNAL_FORCES" in espressomd.features(): - for k in range(2): - self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) - self.es.part[k].v = np.array([0.0, 0.0, 0.0]) - self.es.part[k].omega_body = np.array([0.0, 0.0, 0.0]) - f0 = np.array([-1.2, 58.3578, 0.002]) - f1 = np.array([-15.112, -2.0, 368.0]) - self.es.part[0].ext_force = f0 - self.es.part[1].ext_force = f1 - if "ROTATION" in espressomd.features(): - tor0 = np.array([12, 0.022, 87]) - tor1 = np.array([-0.03, -174, 368]) - self.es.part[0].ext_torque = tor0 - self.es.part[1].ext_torque = tor1 - # Let's set the dipole perpendicular to the torque - if "DIPOLES" in espressomd.features(): - dip0 = np.array([0.0, tor0[2], -tor0[1]]) - dip1 = np.array([-tor1[2], 0.0, tor1[0]]) - self.es.part[0].dip = dip0 - self.es.part[1].dip = dip1 - tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) - tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) - self.es.integrator.run(drag_steps_0) - self.es.time = 0.0 - for k in range(2): - self.es.part[k].pos = np.array([0.0, 0.0, 0.0]) - if "DIPOLES" in espressomd.features(): - self.es.part[0].dip = dip0 - self.es.part[1].dip = dip1 - for i in range(100): - self.es.integrator.run(10) - for k in range(3): - self.assertLess( - abs(self.es.part[0].v[k] - f0[k] / gamma_tr[0, k]), tol) - self.assertLess( - abs(self.es.part[1].v[k] - f1[k] / gamma_tr[1, k]), tol) - self.assertLess( - abs(self.es.part[0].pos[k] - self.es.time * f0[k] / gamma_tr[0, k]), tol) - self.assertLess( - abs(self.es.part[1].pos[k] - self.es.time * f1[k] / gamma_tr[1, k]), tol) - if "ROTATION" in espressomd.features(): - self.assertLess(abs( - self.es.part[0].omega_lab[k] - tor0[k] / gamma_rot_validate[0, k]), tol) - self.assertLess(abs( - self.es.part[1].omega_lab[k] - tor1[k] / gamma_rot_validate[1, k]), tol) - if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): - cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) - cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0]) - sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) - sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / gamma_rot_validate[0, 0])) - - cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) - cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0]) - sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) - sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / gamma_rot_validate[1, 0])) - - #print("cos_alpha0 = {0}, cos_alpha0_test={1}".format(cos_alpha0, cos_alpha0_test)) - #print("dip0 = {0}, self.es.part[0].dip={1}".format(dip0, self.es.part[0].dip)) - self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) - self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) - self.assertEqual(sgn0, sgn0_test) - self.assertEqual(sgn1, sgn1_test) - - for i in range(len(self.es.part)): - self.es.part[i].remove() - - # thermalization - # Checks if every degree of freedom has 1/2 kT of energy, even when - # mass and inertia tensor are active - - # 2 different langevin parameters for particles - temp = np.array([2.5, 2.0]) - D_tr = np.zeros((2, 3)) - D_rot = np.zeros((2, 3)) - for k in range(2): - gamma_tran[k, :] = np.array((0.4 + np.random.random(3)) * 10) - gamma_rot[k, :] = np.array((0.2 + np.random.random(3)) * 20) - - box = 10.0 - self.es.box_l = [box, box, box] - if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.es.periodicity = 0, 0, 0 - # Random temperature - kT = (0.3 + np.random.random()) * 5 - gamma_global = np.array((0.5 + np.random.random(3)) * 2.0 / 3.0) - gamma_global_rot = np.array((0.2 + np.random.random(3)) * 20) - - if test_case in [2,3,(6+self.rot_flag),(7+self.rot_flag)]: - halfkT = temp / 2.0 - else: - halfkT = np.array([kT, kT]) / 2.0 - - if test_case in [1,3,(5+self.rot_flag),(7+self.rot_flag)]: - gamma_tr = gamma_tran - else: - for k in range(2): - gamma_tr[k, :] = gamma_global[:] - - if test_case in [1,3,(5+self.rot_flag),(7+self.rot_flag)]: - gamma_tr = gamma_tran - gamma_rot_validate = gamma_rot - else: - for k in range(2): - gamma_tr[k, :] = gamma_global[:] - if (test_case == 4 or test_case == 9) and self.rot_flag == 1: - gamma_rot_validate[k, :] = gamma_global_rot[:] - else: - gamma_rot_validate[k, :] = gamma_global[:] - - # translational and rotational diffusion - for k in range(2): - D_tr[k, :] = 2.0 * halfkT[k] / gamma_tr[k, :] - D_rot[k, :] = 2.0 * halfkT[k] / gamma_rot_validate[k, :] - - self.set_thermo_all(test_case, kT, gamma_global, gamma_global_rot) - - # no need to rebuild Verlet lists, avoid it - self.es.cell_system.skin = 5.0 - if test_case < 4 + self.rot_flag: - self.es.time_step = 0.03 - else: - self.es.time_step = 10 - n = 200 - mass = (0.2 + np.random.random()) * 7.0 - J = np.zeros((2, 3)) - for k in range(2): - J[k, :] = np.array((0.2 + np.random.random(3)) * 7.0) - - for i in range(n): - for k in range(2): - ind = i + k * n - part_pos = np.array(np.random.random(3) * box) - part_v = np.array([0.0, 0.0, 0.0]) - part_omega_body = np.array([0.0, 0.0, 0.0]) - self.es.part.add(rotation=(1,1,1), id=ind, mass=mass, - rinertia=[J[k, 0], J[k, 1], J[k, 2]], - pos=part_pos, v=part_v) - if "ROTATION" in espressomd.features(): - self.es.part[ind].omega_body = part_omega_body - if test_case in [1,(5+self.rot_flag)]: - self.es.part[ind].gamma = gamma_tran[k, :] - if "ROTATION" in espressomd.features(): - self.es.part[ind].gamma_rot = gamma_rot[k, :] - - if test_case in [2,(6+self.rot_flag)]: - self.es.part[ind].temp = temp[k] - if test_case in [3,(7+self.rot_flag)]: - self.es.part[ind].gamma = gamma_tran[k, :] - if "ROTATION" in espressomd.features(): - self.es.part[ind].gamma_rot = gamma_rot[k, :] - self.es.part[ind].temp = temp[k] - - # Get rid of short range calculations if exclusions are on - # if espressomd.has_features("EXCLUSIONS"): - - # matrices: [2 types of particless] x [3 dimensions X Y Z] - # velocity^2, omega^2, position^2 - v2 = np.zeros((2, 3)) - o2 = np.zeros((2, 3)) - dr2 = np.zeros((2, 3)) - sigma2_tr = np.zeros((2)) - dr_norm = np.zeros((2)) - - # Total curve within a spherical trigonometry. - # [particle_index, which principal axis, around which lab axis] - alpha = np.zeros((2, n, 3, 3)) - alpha_norm = np.zeros((2)) - sigma2_alpha = np.zeros((2)) - alpha2 = np.zeros((2)) - # Previous directions of the principal axes: - # [particle_index, which principal axis, its lab coordinate] - prev_pa_lab = np.zeros((2, n, 3, 3)) - pa_body = np.zeros((3)) - pa_lab = np.zeros((3, 3)) - ref_lab = np.zeros((3)) - vec = np.zeros((3)) - vec1 = np.zeros((3)) - vec2 = np.zeros((3)) - #vec_diag = np.ones((3)) - - pos0 = np.zeros((2 * n, 3)) - for p in range(n): - for k in range(2): - ind = p + k * n - pos0[ind, :] = self.es.part[ind].pos - dt0 = mass / gamma_tr - dt0_rot = J / gamma_rot_validate - - #if test_case in [3,(7 + self.rot_flag)]: - # loops = 5000 - #else: - # loops = 1250 - loops = 5000 - print("Thermalizing...") - therm_steps = 150 - self.es.integrator.run(therm_steps) - print("Measuring...") - - int_steps = 1 - fraction_i = 0.65 - for i in range(loops): - self.es.integrator.run(int_steps) - # Get kinetic energy in each degree of freedom for all particles - for p in range(n): - for k in range(2): - ind = p + k * n - v = self.es.part[ind].v - if "ROTATION" in espressomd.features(): - o = self.es.part[ind].omega_body - o2[k, :] = o2[k, :] + np.power(o[:], 2) - pos = self.es.part[ind].pos - v2[k, :] = v2[k, :] + np.power(v[:], 2) - dr2[k, :] = np.power((pos[:] - pos0[ind, :]), 2) - dt = (int_steps * (i + 1) + therm_steps) * \ - self.es.time_step - # translational diffusion variance: after a closed-form - # integration of the Langevin EOM - sigma2_tr[k] = 0.0 - for j in range(3): - sigma2_tr[k] = sigma2_tr[k] + D_tr[k, - j] * (2.0 * dt + dt0[k, - j] * (- 3.0 + 4.0 * math.exp(- dt / dt0[k, - j]) - math.exp(- 2.0 * dt / dt0[k, - j]))) - dr_norm[k] = dr_norm[k] + \ - (sum(dr2[k, :]) - sigma2_tr[k]) / sigma2_tr[k] - - # Rotational diffusion variance. - if i >= fraction_i * loops: - # let's limit test cases to speed this test.. - #if test_case in [3,(7 + self.rot_flag)]: - dt -= self.es.time_step * (1 + therm_steps + fraction_i * loops) - # First, let's identify principal axes in the lab reference frame. - alpha2[k] = 0.0 - sigma2_alpha[k] = 0.0 - for j in range(3): - for j1 in range(3): - pa_body[j1] = 0.0 - pa_body[j] = 1.0 - vec = tc.convert_vec_body_to_space(self.es, ind, pa_body) - pa_lab[j, :] = vec[:] - - if i >= fraction_i * loops + 1: - # Around which axis we rotates? - for j1 in range(3): - # Calc a rotational diffusion within the spherical trigonometry - vec2 = vec - vec1[:] = prev_pa_lab[k, p, j, :] - for j2 in range(3): - ref_lab[j2] = 0.0 - ref_lab[j1] = 1.0 - dalpha = np.arccos(np.dot(vec2, vec1) / (np.linalg.norm(vec2) * np.linalg.norm(vec1))) - rot_projection = np.dot(np.cross(vec2, vec1), ref_lab) / np.linalg.norm(np.cross(vec2, vec1)) - theta = np.arccos(np.dot(vec2, ref_lab) / (np.linalg.norm(vec2) * np.linalg.norm(ref_lab))) - alpha[k, p, j, j1] += dalpha * rot_projection / np.sin(theta) - alpha2[k] += alpha[k, p, j, j1]**2 - sigma2_alpha[k] += D_rot[k, j] * (2.0 * dt + dt0_rot[k, j] * (- 3.0 + - 4.0 * math.exp(- dt / dt0_rot[k, j]) - - math.exp(- 2.0 * dt / dt0_rot[k, j]))) - prev_pa_lab[k, p, j, :] = pa_lab[j, :] - if i >= fraction_i * loops + 3: - alpha_norm[k] += (alpha2[k] - sigma2_alpha[k]) / sigma2_alpha[k] - - tolerance = 0.15 - Ev = 0.5 * mass * v2 / (n * loops) - Eo = 0.5 * J * o2 / (n * loops) - dv = np.zeros((2)) - do = np.zeros((2)) - do_vec = np.zeros((2, 3)) - for k in range(2): - dv[k] = sum(Ev[k, :]) / (3.0 * halfkT[k]) - 1.0 - do[k] = sum(Eo[k, :]) / (3.0 * halfkT[k]) - 1.0 - do_vec[k, :] = Eo[k, :] / halfkT[k] - 1.0 - dr_norm = dr_norm / (n * loops) - alpha_norm = alpha_norm / (n * (1 - fraction_i) * loops - 2) - - for k in range(2): - print("\n") - print("k = " + str(k)) - print("mass = " + str(mass)) - print("gamma_tr = {0} {1} {2}".format( - gamma_tr[k, 0], gamma_tr[k, 1], gamma_tr[k, 2])) - if test_case in [1,5,3,7]: - print("gamma_rot_validate = {0} {1} {2}".format( - gamma_rot_validate[k, 0], gamma_rot_validate[k, 1], gamma_rot_validate[k, 2])) - else: - print("gamma_global = {0} {1} {2}".format( - gamma_global[0], gamma_global[1], gamma_global[2])) - print("Moment of inertia principal components: = " + str(J)) - print("1/2 kT = " + str(halfkT[k])) - print("Translational energy: {0} {1} {2}".format( - Ev[k, 0], Ev[k, 1], Ev[k, 2])) - print("Rotational energy: {0} {1} {2}".format( - Eo[k, 0], Eo[k, 1], Eo[k, 2])) - - print("Deviation in translational energy: " + str(dv[k])) - if "ROTATION" in espressomd.features(): - print("Deviation in rotational energy: " + str(do[k])) - print("Deviation in rotational energy per degrees of freedom: {0} {1} {2}".format( - do_vec[k, 0], do_vec[k, 1], do_vec[k, 2])) - print( - "Deviation in translational diffusion: {0} ".format( - dr_norm[k])) - print( - "Deviation in rotational diffusion: {0} ".format( - alpha_norm)) - - self.assertLessEqual( - abs( - dv[k]), - tolerance, - msg='Relative deviation in translational energy too large: {0}'.format( - dv[k])) - if "ROTATION" in espressomd.features(): - self.assertLessEqual( - abs( - do[k]), - tolerance, - msg='Relative deviation in rotational energy too large: {0}'.format( - do[k])) - self.assertLessEqual(abs( - do_vec[k, 0]), tolerance, msg='Relative deviation in rotational energy per the body axis X is too large: {0}'.format(do_vec[k, 0])) - self.assertLessEqual(abs( - do_vec[k, 1]), tolerance, msg='Relative deviation in rotational energy per the body axis Y is too large: {0}'.format(do_vec[k, 1])) - self.assertLessEqual(abs( - do_vec[k, 2]), tolerance, msg='Relative deviation in rotational energy per the body axis Z is too large: {0}'.format(do_vec[k, 2])) - self.assertLessEqual( - abs( - dr_norm[k]), - tolerance, - msg='Relative deviation in translational diffusion is too large: {0}'.format( - dr_norm[k])) - if test_case in (1, 3): - self.assertLessEqual( - abs( - alpha_norm[k]), - tolerance, - msg='Relative deviation in rotational diffusion is too large: {0}'.format( - alpha_norm[k])) - - def test(self): - if "ROTATION" in espressomd.features(): - self.rot_flag = 1 - if not "BROWNIAN_DYNAMICS" in espressomd.features(): - n_test_cases = 4 + self.rot_flag - else: - n_test_cases = 2 * (4 + self.rot_flag) - for i in range(n_test_cases): - self.run_test_case(i) - - -if __name__ == '__main__': - print("Features: ", espressomd.features()) - ut.main() From d0faa2cbb541ab664e48734992d71e820d469037 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Thu, 14 Jun 2018 23:19:32 +0300 Subject: [PATCH 051/150] Refactoring according to previous review --- testsuite/mass-and-rinertia_per_particle.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index c65c9947da0..23f4f149a7e 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -51,7 +51,6 @@ def setUpClass(cls): def setUp(self): self.es.time = 0.0 self.es.part.clear() - print("\n") def generate_scalar_ranged_rnd(self, min_par, max_par): """ @@ -287,10 +286,10 @@ def check_fluctuation_dissipation(self,n): dt0 = self.mass / self.gamma_tran_p_validate loops = 200 - print("Thermalizing...") + # Thermalizing... therm_steps = 20 self.es.integrator.run(therm_steps) - print("Measuring...") + # Measuring... int_steps = 5 for i in range(loops): @@ -334,9 +333,6 @@ def check_fluctuation_dissipation(self,n): dr_norm /= (n * loops) for k in range(2): - print("\n") - print("k = " + str(k)) - self.assertLessEqual( abs( dv[k]), From 274cf7675fc164eeee9f24d4a065c0889f0c7bab Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 15 Jun 2018 01:06:25 +0300 Subject: [PATCH 052/150] BD thermo viscous test --- testsuite/CMakeLists.txt | 1 + ...brownian_mass-and-rinertia_per_particle.py | 628 ++++++++++++++++++ 2 files changed, 629 insertions(+) create mode 100644 testsuite/brownian_mass-and-rinertia_per_particle.py diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 2a82886ee5c..96a13384da6 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -72,6 +72,7 @@ python_test(FILE engine_lbgpu.py MAX_NUM_PROC 1) python_test(FILE icc.py MAX_NUM_PROC 4) python_test(FILE magnetostaticInteractions.py MAX_NUM_PROC 1) python_test(FILE mass-and-rinertia_per_particle.py MAX_NUM_PROC 1) +python_test(FILE brownian_mass-and-rinertia_per_particle.py MAX_NUM_PROC 1) python_test(FILE interactions_bond_angle.py MAX_NUM_PROC 4) python_test(FILE interactions_bonded_interface.py MAX_NUM_PROC 4) python_test(FILE interactions_bonded.py MAX_NUM_PROC 2) diff --git a/testsuite/brownian_mass-and-rinertia_per_particle.py b/testsuite/brownian_mass-and-rinertia_per_particle.py new file mode 100644 index 00000000000..33867605077 --- /dev/null +++ b/testsuite/brownian_mass-and-rinertia_per_particle.py @@ -0,0 +1,628 @@ +from __future__ import print_function +import unittest as ut +import numpy as np +from numpy.random import random, seed +import espressomd +import math + + +@ut.skipIf(not espressomd.has_features(["MASS", + "PARTICLE_ANISOTROPY", + "ROTATIONAL_INERTIA", + "LANGEVIN_PER_PARTICLE", + "BROWNIAN_DYNAMICS"]), + "Features not available, skipping test!") +class BDThermoTest(ut.TestCase): + longMessage = True + # Handle for espresso system + es = espressomd.System(box_l=[1.0,1.0,1.0]) + es.cell_system.skin = 5.0 + + # The NVT thermostat parameters + kT = 0.0 + gamma_global = np.zeros((3)) + gamma_global_rot = np.zeros((3)) + + # Particle properties + mass = 0.0 + J = 0.0,0.0,0.0 + + ## Per-particle type parameters. + # 2 different langevin parameters for particles. + kT_p = np.zeros((2)) + # gamma_tran/gamma_rot matrix: [2 kinds of particles] x [3 dimensions X Y Z] + # These matrices are assigning per-particle in corresponding test cases. + gamma_tran_p = np.zeros((2, 3)) + gamma_rot_p = np.zeros((2, 3)) + + ## These variables will take the values to compare with. + # Depending on the test case following matrices either equals to the previous + # or the global corresponding parameters. The corresponding setting effect is an essence of + # all the test cases' differentiation here. + halfkT_p_validate = np.zeros((2)) + gamma_tran_p_validate = np.zeros((2, 3)) + gamma_rot_p_validate = np.zeros((2, 3)) + # Diffusivity + D_tran_p_validate = np.zeros((2,3)) + + @classmethod + def setUpClass(cls): + np.random.seed(15) + + def setUp(self): + self.es.time = 0.0 + self.es.part.clear() + + def generate_scalar_ranged_rnd(self, min_par, max_par): + """ + Generate the scaled random scalar in the range between + min_par*max_par and (min_par+1.0)*max_par. + + Parameters + ---------- + min_par : :obj:`int` + Minimal value parameter. + max_par : :obj:`int` + Maximal value parameter. + + """ + + res = (min_par + np.random.random()) * max_par + return res + + def generate_vec_ranged_rnd(self, min_par, max_par): + """ + Generate the scaled random 3D vector with a magnitude + in the range between sqrt(3)*min_par*max_par and + sqrt(3)*(min_par+1.0)*max_par. + + Parameters + ---------- + min_par : :obj:`int` + Minimal value parameter. + max_par : :obj:`int` + Maximal value parameter. + + """ + + res = (min_par + np.random.random(3)) * max_par + return res + + def set_langevin_global_defaults(self): + """ + Setup the NVT thermostat viscous friction parameters. + + """ + + # Global NVT thermostat parameters are assigning by default + for k in range(2): + self.gamma_tran_p_validate[k, :] = self.gamma_global[:] + self.gamma_rot_p_validate[k, :] = self.gamma_global[:] + self.halfkT_p_validate[k] = self.kT / 2.0 + + def set_langevin_global_defaults_rot_differ(self): + """ + Setup the NVT thermostat viscous friction parameters + with a rotation-specific gamma. + + """ + + # Global NVT thermostat parameters are assigning by default + for k in range(2): + self.gamma_tran_p_validate[k, :] = self.gamma_global[:] + self.gamma_rot_p_validate[k, :] = self.gamma_global_rot[:] + self.halfkT_p_validate[k] = self.kT / 2.0 + + def dissipation_param_setup(self): + """ + Setup the parameters for the following dissipation + test. + + """ + + ## Time + self.es.time_step = 0.007 + + ## Space + box = 1.0 + self.es.box_l = box,box,box + if espressomd.has_features(("PARTIAL_PERIODIC",)): + self.es.periodicity = 0,0,0 + + ## NVT thermostat + self.kT = 0.0 + # The translational gamma isotropy is required here. + # Global gamma for tests without particle-specific gammas. + # + # As far as the problem characteristic time is t0 ~ mass / gamma + # and the Langevin equation finite-difference approximation is stable + # only for time_step << t0, it is needed to set the gamma less than + # some maximal value according to the value max_gamma_param. + # Also, it cannot be very small (min_gamma_param), otherwise the thermalization will require + # too much of the CPU time. Same: for all such gamma assignments throughout the test. + # + min_gamma_param = 0.5 + max_gamma_param = 2.0/3.0 + gamma_rnd = self.generate_scalar_ranged_rnd(min_gamma_param, max_gamma_param) + self.gamma_global = gamma_rnd, gamma_rnd, gamma_rnd + # Additional test case for the specific global rotational gamma set. + self.gamma_global_rot = self.generate_vec_ranged_rnd(0.5,2.0/3.0) + # Per-paricle values: + self.kT_p = 0.0,0.0 + # Either translational friction isotropy is required + # or both translational and rotational ones. + # Otherwise these types of motion will interfere. + # ..Let's test both cases depending on the particle index. + self.gamma_tran_p[0, 0] = self.generate_scalar_ranged_rnd(0.5,1.0) + self.gamma_tran_p[0, 1] = self.gamma_tran_p[0, 0] + self.gamma_tran_p[0, 2] = self.gamma_tran_p[0, 0] + self.gamma_rot_p[0, :] = self.generate_vec_ranged_rnd(0.5,2.0/3.0) + self.gamma_tran_p[1, 0] = self.generate_scalar_ranged_rnd(0.5,1.0) + self.gamma_tran_p[1, 1] = self.gamma_tran_p[1, 0] + self.gamma_tran_p[1, 2] = self.gamma_tran_p[1, 0] + self.gamma_rot_p[1, 0] = self.generate_scalar_ranged_rnd(0.5,2.0/3.0) + self.gamma_rot_p[1, 1] = self.gamma_rot_p[1, 0] + self.gamma_rot_p[1, 2] = self.gamma_rot_p[1, 0] + + ## Particles + self.mass = 12.74 + self.J = 10.0,10.0,10.0 + for i in range(2): + self.es.part.add(rotation=(1,1,1), pos=(0.0,0.0,0.0), id=i) + self.es.part[i].v = 1.0,1.0,1.0 + if "ROTATION" in espressomd.features(): + self.es.part[i].omega_body = 1.0,1.0,1.0 + self.es.part[i].mass = self.mass + self.es.part[i].rinertia = self.J + + def dissipation_viscous_drag_setup(self): + """ + Setup the specific parameters for the following dissipation + test of the viscous drag terminal velocity stationarity. + + """ + ## Time + # Large time_step is OK for the BD by its definition & its benefits + self.es.time_step = 10.0 + ## NVT thermostat + # Isotropic reassignment is required here for the drag tests + self.gamma_global_rot = np.zeros((3)) + self.gamma_global_rot[0] = (0.5 + np.random.random()) * 2.0 / 3.0 + self.gamma_global_rot[1] = self.gamma_global_rot[0] + self.gamma_global_rot[2] = self.gamma_global_rot[0] + # Isotropy is required here for the drag tests + self.gamma_rot_p[0, 0] = self.generate_scalar_ranged_rnd(0.5,2.0/3.0) + self.gamma_rot_p[0, 1] = self.gamma_rot_p[0, 0] + self.gamma_rot_p[0, 2] = self.gamma_rot_p[0, 0] + + def fluctuation_dissipation_param_setup(self,n): + """ + Setup the parameters for the following fluctuation-dissipation + test. + + Parameters + ---------- + n : :obj:`int` + Number of particles of the each type. There are 2 types. + + """ + + ## Time + # Large time_step is OK for the BD by its definition + self.es.time_step = 10.0 + + ## Space + box = 10.0 + self.es.box_l = box,box,box + if espressomd.has_features(("PARTIAL_PERIODIC",)): + self.es.periodicity = 0,0,0 + + ## NVT thermostat + # Just some temperature range to cover by the test: + self.kT = self.generate_scalar_ranged_rnd(0.3,5) + # See the above comment regarding the gamma assignments. + # Note: here & hereinafter specific variations in these ranges are related to + # the test execution duration to achieve the required statistical averages faster. + self.gamma_global = self.generate_vec_ranged_rnd(0.5,2.0/3.0) + self.gamma_global_rot = self.generate_vec_ranged_rnd(0.2,20) + # Per-particle parameters + self.kT_p = 2.5,2.0 + for k in range(2): + self.gamma_tran_p[k, :] = self.generate_vec_ranged_rnd(0.4,10.0) + self.gamma_rot_p[k, :] = self.generate_vec_ranged_rnd(0.2,20.0) + + ## Particles + # As far as the problem characteristic time is t0 ~ mass / gamma + # and the Langevin equation finite-difference approximation is stable + # only for time_step << t0, it is needed to set the mass higher than + # some minimal value according to the value min_mass_param. + # Also, it is expected to test the large enough mass (max_mass_param). + # It should be not very large, otherwise the thermalization will require + # too much of the CPU time. + min_mass_param = 0.2 + max_mass_param = 7.0 + self.mass = self.generate_scalar_ranged_rnd(min_mass_param,max_mass_param) + self.J = self.generate_vec_ranged_rnd(min_mass_param,max_mass_param) + for i in range(n): + for k in range(2): + ind = i + k * n + part_pos = np.random.random(3) * box + part_v = 0.0,0.0,0.0 + part_omega_body = 0.0,0.0,0.0 + self.es.part.add(rotation=(1,1,1), id=ind, mass=self.mass, rinertia=self.J, + pos=part_pos, v=part_v) + if "ROTATION" in espressomd.features(): + self.es.part[ind].omega_body = part_omega_body + + # Note: the decelleration test is needed for the Langevin thermostat only. Brownian thermostat is defined + # over a larger time-step by its concept. cf. mass-and-rinertia_per_particle.py (def check_dissipation(self):) + def check_dissipation_viscous_drag(self): + """ + Check the dissipation relations: the drag terminal velocity tests, + aka the drift in case of the electrostatics + + """ + tol = 7E-3 + if "EXTERNAL_FORCES" in espressomd.features(): + for k in range(2): + self.es.part[k].pos = np.zeros((3)) + self.es.part[k].v = np.zeros((3)) + self.es.part[k].omega_body = np.zeros((3)) + # Just some random forces + f0 = -1.2,58.3578,0.002 + f1 = -15.112,-2.0,368.0 + self.es.part[0].ext_force = f0 + self.es.part[1].ext_force = f1 + if "ROTATION" in espressomd.features(): + # Just some random torques + tor0 = 12,0.022,87 + tor1 = -0.03,-174,368 + self.es.part[0].ext_torque = tor0 + self.es.part[1].ext_torque = tor1 + # Let's set the dipole perpendicular to the torque + if "DIPOLES" in espressomd.features(): + dip0 = 0.0,tor0[2],-tor0[1] + dip1 = -tor1[2],0.0,tor1[0] + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) + tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) + # Small number of steps is enough for the terminal velocity within the BD by its definition. + # A simulation of the original saturation of the velocity. + self.es.integrator.run(7) + self.es.time = 0.0 + for k in range(2): + self.es.part[k].pos = np.zeros((3)) + if "DIPOLES" in espressomd.features(): + self.es.part[0].dip = dip0 + self.es.part[1].dip = dip1 + for i in range(3): + # Small number of steps + self.es.integrator.run(2) + for k in range(3): + # Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010) + # First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). + self.assertLess( + abs(self.es.part[0].v[k] - f0[k] / self.gamma_tran_p_validate[0, k]), tol) + self.assertLess( + abs(self.es.part[1].v[k] - f1[k] / self.gamma_tran_p_validate[1, k]), tol) + # Second (deterministic) term of the Eq. (14.39) of Schlick2010. + self.assertLess( + abs(self.es.part[0].pos[k] - self.es.time * f0[k] / self.gamma_tran_p_validate[0, k]), tol) + self.assertLess( + abs(self.es.part[1].pos[k] - self.es.time * f1[k] / self.gamma_tran_p_validate[1, k]), tol) + # Same, a rotational analogy. + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + self.es.part[0].omega_lab[k] - tor0[k] / self.gamma_rot_p_validate[0, k]), tol) + self.assertLess(abs( + self.es.part[1].omega_lab[k] - tor1[k] / self.gamma_rot_p_validate[1, k]), tol) + if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): + # Same, a rotational analogy. One is implemented using a simple linear algebra; + # the polar angles with a sign control just for a correct inverse trigonometric functions application. + cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) + cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0]) + sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) + sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0])) + + cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) + cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0]) + sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) + sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0])) + + self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) + self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) + self.assertEqual(sgn0, sgn0_test) + self.assertEqual(sgn1, sgn1_test) + + def check_fluctuation_dissipation(self,n): + """ + Check the fluctuation-dissipation relations: thermalization + and diffusion properties. + + Parameters + ---------- + n : :obj:`int` + Number of particles of the each type. There are 2 types. + + """ + + ## The thermalization and diffusion test + # Checks if every degree of freedom has 1/2 kT of energy, even when + # mass and inertia tensor are active + # Check the factual translational diffusion. + # + # matrices: [2 types of particless] x [3 dimensions X Y Z] + # velocity^2, omega^2, position^2 + v2 = np.zeros((2, 3)) + o2 = np.zeros((2, 3)) + dr2 = np.zeros((2, 3)) + # Variance to compare with: + sigma2_tr = np.zeros((2)) + # Comparable variance: + dr_norm = np.zeros((2)) + + pos0 = np.zeros((2 * n, 3)) + for p in range(n): + for k in range(2): + ind = p + k * n + pos0[ind, :] = self.es.part[ind].pos + dt0 = self.mass / self.gamma_tran_p_validate + + loops = 2 + # Thermalizing... + therm_steps = 20 + self.es.integrator.run(therm_steps) + # Measuring... + + int_steps = 5 + for i in range(loops): + self.es.integrator.run(int_steps) + # Get kinetic energy in each degree of freedom for all particles + for p in range(n): + for k in range(2): + ind = p + k * n + v = self.es.part[ind].v + if "ROTATION" in espressomd.features(): + o = self.es.part[ind].omega_body + o2[k, :] = o2[k, :] + np.power(o[:], 2) + pos = self.es.part[ind].pos + v2[k, :] = v2[k, :] + np.power(v[:], 2) + dr2[k, :] = np.power((pos[:] - pos0[ind, :]), 2) + dt = (int_steps * (i + 1) + therm_steps) * \ + self.es.time_step + # translational diffusion variance: after a closed-form + # integration of the Langevin EOM; + # ref. the eq. (10.2.26) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010) + # after simple transformations and the dimensional model matching (cf. eq. (10.1.1) there). + # The BD requires also the limit dt >> dt0, hence one gets rid of the exponents here. + sigma2_tr[k] = 0.0 + for j in range(3): + sigma2_tr[k] += self.D_tran_p_validate[k,j] * 2.0 * dt + dr_norm[k] += (sum(dr2[k, :]) - sigma2_tr[k]) / sigma2_tr[k] + + tolerance = 0.15 + Ev = 0.5 * self.mass * v2 / (n * loops) + Eo = 0.5 * self.J * o2 / (n * loops) + dv = np.zeros((2)) + do = np.zeros((2)) + do_vec = np.zeros((2, 3)) + for k in range(2): + dv[k] = sum(Ev[k, :]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 + do[k] = sum(Eo[k, :]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 + do_vec[k, :] = Eo[k, :] / self.halfkT_p_validate[k] - 1.0 + dr_norm /= (n * loops) + + for k in range(2): + self.assertLessEqual( + abs( + dv[k]), + tolerance, + msg='Relative deviation in translational energy too large: {0}'.format( + dv[k])) + if "ROTATION" in espressomd.features(): + self.assertLessEqual( + abs( + do[k]), + tolerance, + msg='Relative deviation in rotational energy too large: {0}'.format( + do[k])) + self.assertLessEqual(abs( + do_vec[k, 0]), tolerance, msg='Relative deviation in rotational energy per the body axis X is too large: {0}'.format(do_vec[k, 0])) + self.assertLessEqual(abs( + do_vec[k, 1]), tolerance, msg='Relative deviation in rotational energy per the body axis Y is too large: {0}'.format(do_vec[k, 1])) + self.assertLessEqual(abs( + do_vec[k, 2]), tolerance, msg='Relative deviation in rotational energy per the body axis Z is too large: {0}'.format(do_vec[k, 2])) + self.assertLessEqual( + abs( + dr_norm[k]), + tolerance, + msg='Relative deviation in translational diffusion is too large: {0}'.format( + dr_norm[k])) + + def set_particle_specific_gamma(self,n): + """ + Set the particle-specific gamma. + + Parameters + ---------- + n : :obj:`int` + Number of particles of the each type. There are 2 types. + + """ + + for k in range(2): + self.gamma_tran_p_validate[k, :] = self.gamma_tran_p[k, :] + self.gamma_rot_p_validate[k, :] = self.gamma_rot_p[k, :] + for i in range(n): + ind = i + k * n + self.es.part[ind].gamma = self.gamma_tran_p[k, :] + if "ROTATION" in espressomd.features(): + self.es.part[ind].gamma_rot = self.gamma_rot_p[k, :] + + def set_particle_specific_temperature(self,n): + """ + Set the particle-specific temperature. + + Parameters + ---------- + n : :obj:`int` + Number of particles of the each type. There are 2 types. + + """ + + for k in range(2): + self.halfkT_p_validate[k] = self.kT_p[k] / 2.0 + for i in range(n): + ind = i + k * n + self.es.part[ind].temp = self.kT_p[k] + + def set_diffusivity_tran(self): + """ + Set the translational diffusivity to validate further. + + """ + + for k in range(2): + # Translational diffusivity for a validation + self.D_tran_p_validate[k, :] = 2.0 * self.halfkT_p_validate[k] / self.gamma_tran_p_validate[k, :] + + # Test case 0.0: no particle specific values / dissipation only + def test_case_00(self): + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_dissipation_viscous_drag() + + # Test case 0.1: no particle specific values / fluctuation & dissipation + def test_case_01(self): + # Each of 2 kind of particles will be represented by n instances: + n = 200 + self.fluctuation_dissipation_param_setup(n) + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_diffusivity_tran() + # Actual integration and validation run + self.check_fluctuation_dissipation(n) + + # Test case 1.0: particle specific gamma but not temperature / dissipation only + def test_case_10(self): + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_particle_specific_gamma(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag() + + # Test case 1.1: particle specific gamma but not temperature / fluctuation & dissipation + def test_case_11(self): + # Each of 2 kind of particles will be represented by n instances: + n = 200 + self.fluctuation_dissipation_param_setup(n) + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_particle_specific_gamma(n) + self.set_diffusivity_tran() + # Actual integration and validation run + self.check_fluctuation_dissipation(n) + + # Test case 2.0: particle specific temperature but not gamma / dissipation only + def test_case_20(self): + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_particle_specific_temperature(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag() + + # Test case 2.1: particle specific temperature but not gamma / fluctuation & dissipation + def test_case_21(self): + # Each of 2 kind of particles will be represented by n instances: + n = 200 + self.fluctuation_dissipation_param_setup(n) + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_particle_specific_temperature(n) + self.set_diffusivity_tran() + # Actual integration and validation run + self.check_fluctuation_dissipation(n) + + # Test case 3.0: both particle specific gamma and temperature / dissipation only + def test_case_30(self): + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_particle_specific_gamma(n) + self.set_particle_specific_temperature(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag() + + # Test case 3.1: both particle specific gamma and temperature / fluctuation & dissipation + def test_case_31(self): + # Each of 2 kind of particles will be represented by n instances: + n = 200 + self.fluctuation_dissipation_param_setup(n) + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_particle_specific_gamma(n) + self.set_particle_specific_temperature(n) + self.set_diffusivity_tran() + # Actual integration and validation run + self.check_fluctuation_dissipation(n) + + # Test case 4.0: no particle specific values / rotational specific global thermostat / dissipation only + def test_case_40(self): + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup() + self.set_langevin_global_defaults_rot_differ() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) + # Actual integration and validation run + self.check_dissipation_viscous_drag() + + # Test case 4.1: no particle specific values / rotational specific global thermostat / fluctuation & dissipation + def test_case_41(self): + # Each of 2 kind of particles will be represented by n instances: + n = 200 + self.fluctuation_dissipation_param_setup(n) + self.set_langevin_global_defaults_rot_differ() + # The test case-specific thermostat and per-particle parameters + self.es.thermostat.turn_off() + self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) + self.set_diffusivity_tran() + # Actual integration and validation run + self.check_fluctuation_dissipation(n) +if __name__ == '__main__': + ut.main() From 8930afe3ffb0e7d04c4e90aec33a81f9dbd10fa7 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 15 Jun 2018 01:06:41 +0300 Subject: [PATCH 053/150] Refactoring --- testsuite/mass-and-rinertia_per_particle.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 23f4f149a7e..1b5ec22976c 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -532,5 +532,4 @@ def test_case_41(self): self.check_fluctuation_dissipation(n) if __name__ == '__main__': - print("Features: ", espressomd.features()) ut.main() From 2e97d5968bad0d97cff07d1e03de2b3e1c90e9a0 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 15 Jun 2018 01:07:59 +0300 Subject: [PATCH 054/150] Significant performance improvement due to BD advantages --- testsuite/brownian_thermostat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index bf2d469e9a8..e039baa6994 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -94,7 +94,7 @@ def test_global_brownian(self): s.integrator.run(100) # Sampling - loops = 4000 + loops = 13 v_stored = np.zeros((N * loops, 3)) omega_stored = np.zeros((N * loops, 3)) for i in range(loops): From 5753d65180ff14b005eae876b112857bd90c2506 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 15 Jun 2018 01:30:04 +0300 Subject: [PATCH 055/150] Different random generators related fine-tuning --- testsuite/brownian_thermostat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py index e039baa6994..5dbddc9c8bd 100644 --- a/testsuite/brownian_thermostat.py +++ b/testsuite/brownian_thermostat.py @@ -94,7 +94,7 @@ def test_global_brownian(self): s.integrator.run(100) # Sampling - loops = 13 + loops = 30 v_stored = np.zeros((N * loops, 3)) omega_stored = np.zeros((N * loops, 3)) for i in range(loops): From 28ef0ddb3bc9cc5fa696d707d2a0b0eb2054ce81 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 11 Sep 2018 22:25:39 +0300 Subject: [PATCH 056/150] Runtime error fix --- src/core/integrate.cpp | 4 ++-- src/core/rotation.hpp | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index c7e8089fc15..2d9cab2359d 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1114,7 +1114,7 @@ void bd_random_walk(Particle &p, double dt) { #endif #ifdef PARTICLE_ANISOTROPY - double delta_pos_body[3] = { 0.0, 0.0, 0.0 }, delta_pos_lab[3] = { 0.0, 0.0, 0.0 }; + Vector3d delta_pos_body, delta_pos_lab; #endif // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared magnitude defined in the second eq. (14.38), Schlick2010. @@ -1140,7 +1140,7 @@ void bd_random_walk(Particle &p, double dt) { } if (aniso_flag) { - convert_vec_body_to_space(&(p), delta_pos_body, delta_pos_lab); + delta_pos_lab = convert_vector_body_to_space(p, delta_pos_body); } for (int j = 0; j < 3; j++) { diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 77f11351091..7141dd901b1 100644 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -63,9 +63,6 @@ Vector3d convert_vector_space_to_body(const Particle &p, const Vector3d &v); to the body-fixed frame */ void convert_vel_space_to_body(const Particle *p, double *vel_body); -/** convert a vector from the body-fixed frames to space-fixed coordinates */ -void convert_vec_body_to_space(Particle *p, double const *v,double* res); - /** Here we use quaternions to calculate the rotation matrix which will be used then to transform torques from the laboratory to the body-fixed frames */ From f663ec424acd113815a491f7a32f900830dc5eb4 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 11 Sep 2018 22:26:57 +0300 Subject: [PATCH 057/150] Test fix and speed-up --- testsuite/brownian_mass-and-rinertia_per_particle.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testsuite/brownian_mass-and-rinertia_per_particle.py b/testsuite/brownian_mass-and-rinertia_per_particle.py index 33867605077..404da3e92c9 100644 --- a/testsuite/brownian_mass-and-rinertia_per_particle.py +++ b/testsuite/brownian_mass-and-rinertia_per_particle.py @@ -16,6 +16,7 @@ class BDThermoTest(ut.TestCase): longMessage = True # Handle for espresso system es = espressomd.System(box_l=[1.0,1.0,1.0]) + es.seed = es.cell_system.get_state()['n_nodes'] * [1234] es.cell_system.skin = 5.0 # The NVT thermostat parameters @@ -371,11 +372,11 @@ def check_fluctuation_dissipation(self,n): loops = 2 # Thermalizing... - therm_steps = 20 + therm_steps = 2 self.es.integrator.run(therm_steps) # Measuring... - int_steps = 5 + int_steps = 19 for i in range(loops): self.es.integrator.run(int_steps) # Get kinetic energy in each degree of freedom for all particles From e2777473f023cad0d504aab06bad85865424b011 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Tue, 11 Sep 2018 22:28:22 +0300 Subject: [PATCH 058/150] Refactoring according to the CodeFactor critical requirement --- testsuite/CMakeLists.txt | 1 - testsuite/brownian_thermostat.py | 116 ------------------------------- testsuite/langevin_thermostat.py | 67 +++++++++++++----- 3 files changed, 49 insertions(+), 135 deletions(-) delete mode 100644 testsuite/brownian_thermostat.py diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 6197672576c..8f9add9f2a5 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -103,7 +103,6 @@ python_test(FILE ek_eof_one_species_y_nonlinear.py MAX_NUM_PROC 1) python_test(FILE ek_eof_one_species_z_nonlinear.py MAX_NUM_PROC 1) python_test(FILE exclusions.py MAX_NUM_PROC 2) python_test(FILE langevin_thermostat.py MAX_NUM_PROC 1) -python_test(FILE brownian_thermostat.py MAX_NUM_PROC 4) python_test(FILE nsquare.py MAX_NUM_PROC 4) python_test(FILE virtual_sites_relative.py MAX_NUM_PROC 2) python_test(FILE virtual_sites_tracers.py MAX_NUM_PROC 2) diff --git a/testsuite/brownian_thermostat.py b/testsuite/brownian_thermostat.py deleted file mode 100644 index 5dbddc9c8bd..00000000000 --- a/testsuite/brownian_thermostat.py +++ /dev/null @@ -1,116 +0,0 @@ -# -# Copyright (C) 2013,2014,2015,2016 The ESPResSo project -# -# This file is part of ESPResSo. -# -# ESPResSo is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ESPResSo is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Tests particle property setters/getters -from __future__ import print_function -import unittest as ut -import espressomd -import numpy as np -from espressomd.interactions import FeneBond -from time import time -from espressomd.accumulators import Correlator -from espressomd.observables import ParticleVelocities, ParticleBodyAngularVelocities - -#TODO: this test should be as close to langevin_thermostat.py as possible -# these tests probably even could be merged -# after an implementation of the fine inertial BD -@ut.skipIf(espressomd.has_features("THERMOSTAT_IGNORE_NON_VIRTUAL") or - not espressomd.has_features("BROWNIAN_DYNAMICS"), - "Skipped because of the features set") -class BrownianThermostat(ut.TestCase): - """Tests the velocity distribution created by the Brownian thermostat against - the single component Maxwell distribution.""" - - s = espressomd.System(box_l=[1.0, 1.0, 1.0]) - s.cell_system.set_n_square() - s.cell_system.skin = 0.3 - s.seed = range(s.cell_system.get_state()["n_nodes"]) - if espressomd.has_features("PARTIAL_PERIODIC"): - s.periodicity = 0,0,0 - - - @classmethod - def setUpClass(cls): - np.random.seed(42) - - def single_component_maxwell(self, x1, x2, kT): - """Integrate the probability density from x1 to x2 using the trapez rule""" - x = np.linspace(x1, x2, 1000) - return np.trapz(np.exp(-x**2 / (2. * kT)), x) / \ - np.sqrt(2. * np.pi * kT) - - def check_velocity_distribution(self, vel, minmax, n_bins, error_tol, kT): - """check the recorded particle distributions in vel againsta histogram with n_bins bins. Drop velocities outside minmax. Check individual histogram bins up to an accuracy of error_tol agaisnt the analytical result for kT.""" - for i in range(3): - hist = np.histogram( - vel[:, i], range=(-minmax, minmax), bins=n_bins, normed=False) - data = hist[0] / float(vel.shape[0]) - bins = hist[1] - for j in range(n_bins): - found = data[j] - expected = self.single_component_maxwell( - bins[j], bins[j + 1], kT) - self.assertLessEqual(abs(found - expected), error_tol) - - def test_aa_verify_single_component_maxwell(self): - """Verifies the normalization of the analytical expression.""" - self.assertLessEqual( - abs(self.single_component_maxwell(-10, 10, 4.) - 1.), 1E-4) - - def test_global_brownian(self): - """Test for global Brownian parameters.""" - N = 200 - s = self.s - s.part.clear() - s.time_step = 0.02 - - # Place particles - s.part.add(pos=np.random.random((N, 3))) - - # Enable rotation if compiled in - if espressomd.has_features("ROTATION"): - s.part[:].rotation = 1,1,1 - - kT = 2.3 - gamma = 1.5 - s.thermostat.set_brownian(kT=kT, gamma=gamma) - - # Warmup - s.integrator.run(100) - - # Sampling - loops = 30 - v_stored = np.zeros((N * loops, 3)) - omega_stored = np.zeros((N * loops, 3)) - for i in range(loops): - s.integrator.run(2) - v_stored[i * N:(i + 1) * N, :] = s.part[:].v - if espressomd.has_features("ROTATION"): - omega_stored[i * N:(i + 1) * N, :] = s.part[:].omega_body - - v_minmax = 5 - bins = 5 - error_tol = 0.015 - self.check_velocity_distribution( - v_stored, v_minmax, bins, error_tol, kT) - if espressomd.has_features("ROTATION"): - self.check_velocity_distribution( - omega_stored, v_minmax, bins, error_tol, kT) - -if __name__ == "__main__": - ut.main() diff --git a/testsuite/langevin_thermostat.py b/testsuite/langevin_thermostat.py index 0a40046ee0c..26f4bf9e1f3 100644 --- a/testsuite/langevin_thermostat.py +++ b/testsuite/langevin_thermostat.py @@ -69,6 +69,37 @@ def test_aa_verify_single_component_maxwell(self): self.assertLessEqual( abs(self.single_component_maxwell(-10, 10, 4.) - 1.), 1E-4) + def global_langevin_run_check(self, N, kT, loops): + """Sampling for the global Langevin parameters test. + + Parameters + ---------- + N : :obj:`int` + Number of particles. + kT : :obj:`float` + Temperature. + loops : :obj:`int` + Number of integration steps to sample. + + """ + system = self.system + v_stored = np.zeros((N * loops, 3)) + omega_stored = np.zeros((N * loops, 3)) + for i in range(loops): + system.integrator.run(1) + v_stored[i * N:(i + 1) * N, :] = system.part[:].v + if espressomd.has_features("ROTATION"): + omega_stored[i * N:(i + 1) * N, :] = system.part[:].omega_body + + v_minmax = 5 + bins = 4 + error_tol = 0.016 + self.check_velocity_distribution( + v_stored, v_minmax, bins, error_tol, kT) + if espressomd.has_features("ROTATION"): + self.check_velocity_distribution( + omega_stored, v_minmax, bins, error_tol, kT) + def test_global_langevin(self): """Test for global Langevin parameters.""" N = 200 @@ -90,24 +121,24 @@ def test_global_langevin(self): # Warmup system.integrator.run(100) - # Sampling - loops = 400 - v_stored = np.zeros((N * loops, 3)) - omega_stored = np.zeros((N * loops, 3)) - for i in range(loops): - system.integrator.run(1) - v_stored[i * N:(i + 1) * N, :] = system.part[:].v - if espressomd.has_features("ROTATION"): - omega_stored[i * N:(i + 1) * N, :] = system.part[:].omega_body - - v_minmax = 5 - bins = 4 - error_tol = 0.016 - self.check_velocity_distribution( - v_stored, v_minmax, bins, error_tol, kT) - if espressomd.has_features("ROTATION"): - self.check_velocity_distribution( - omega_stored, v_minmax, bins, error_tol, kT) + self.global_langevin_run_check(N, kT, 400) + + if espressomd.has_features("BROWNIAN_DYNAMICS"): + # Large time-step is OK for BD. + system.time_step = 7.214 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=kT, gamma=gamma) + # Warmup + # The BD does not require so the warmup. Only 1 step is enough. + # More steps are taken just to be sure that they will not lead + # to wrong results. + system.integrator.run(3) + # Less number of loops are needed in case of BD because the velocity + # distribution is already as required. It is not a result of a real dynamics. + self.global_langevin_run_check(N, kT, 40) + system.thermostat.turn_off() @ut.skipIf(not espressomd.has_features("LANGEVIN_PER_PARTICLE"), "Test requires LANGEVIN_PER_PARTICLE") From 66df6f5034ce31ed5f7599db97872903f08dd190 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Wed, 12 Sep 2018 02:20:22 +0300 Subject: [PATCH 059/150] Refactoring --- testsuite/CMakeLists.txt | 1 - ...brownian_mass-and-rinertia_per_particle.py | 629 ------------------ testsuite/mass-and-rinertia_per_particle.py | 337 ++++++++-- 3 files changed, 285 insertions(+), 682 deletions(-) delete mode 100644 testsuite/brownian_mass-and-rinertia_per_particle.py diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 8f9add9f2a5..125da768d15 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -72,7 +72,6 @@ python_test(FILE engine_lbgpu.py MAX_NUM_PROC 1) python_test(FILE icc.py MAX_NUM_PROC 4) python_test(FILE magnetostaticInteractions.py MAX_NUM_PROC 1) python_test(FILE mass-and-rinertia_per_particle.py MAX_NUM_PROC 1) -python_test(FILE brownian_mass-and-rinertia_per_particle.py MAX_NUM_PROC 1) python_test(FILE interactions_bond_angle.py MAX_NUM_PROC 4) python_test(FILE interactions_bonded_interface.py MAX_NUM_PROC 4) python_test(FILE interactions_bonded.py MAX_NUM_PROC 2) diff --git a/testsuite/brownian_mass-and-rinertia_per_particle.py b/testsuite/brownian_mass-and-rinertia_per_particle.py deleted file mode 100644 index 404da3e92c9..00000000000 --- a/testsuite/brownian_mass-and-rinertia_per_particle.py +++ /dev/null @@ -1,629 +0,0 @@ -from __future__ import print_function -import unittest as ut -import numpy as np -from numpy.random import random, seed -import espressomd -import math - - -@ut.skipIf(not espressomd.has_features(["MASS", - "PARTICLE_ANISOTROPY", - "ROTATIONAL_INERTIA", - "LANGEVIN_PER_PARTICLE", - "BROWNIAN_DYNAMICS"]), - "Features not available, skipping test!") -class BDThermoTest(ut.TestCase): - longMessage = True - # Handle for espresso system - es = espressomd.System(box_l=[1.0,1.0,1.0]) - es.seed = es.cell_system.get_state()['n_nodes'] * [1234] - es.cell_system.skin = 5.0 - - # The NVT thermostat parameters - kT = 0.0 - gamma_global = np.zeros((3)) - gamma_global_rot = np.zeros((3)) - - # Particle properties - mass = 0.0 - J = 0.0,0.0,0.0 - - ## Per-particle type parameters. - # 2 different langevin parameters for particles. - kT_p = np.zeros((2)) - # gamma_tran/gamma_rot matrix: [2 kinds of particles] x [3 dimensions X Y Z] - # These matrices are assigning per-particle in corresponding test cases. - gamma_tran_p = np.zeros((2, 3)) - gamma_rot_p = np.zeros((2, 3)) - - ## These variables will take the values to compare with. - # Depending on the test case following matrices either equals to the previous - # or the global corresponding parameters. The corresponding setting effect is an essence of - # all the test cases' differentiation here. - halfkT_p_validate = np.zeros((2)) - gamma_tran_p_validate = np.zeros((2, 3)) - gamma_rot_p_validate = np.zeros((2, 3)) - # Diffusivity - D_tran_p_validate = np.zeros((2,3)) - - @classmethod - def setUpClass(cls): - np.random.seed(15) - - def setUp(self): - self.es.time = 0.0 - self.es.part.clear() - - def generate_scalar_ranged_rnd(self, min_par, max_par): - """ - Generate the scaled random scalar in the range between - min_par*max_par and (min_par+1.0)*max_par. - - Parameters - ---------- - min_par : :obj:`int` - Minimal value parameter. - max_par : :obj:`int` - Maximal value parameter. - - """ - - res = (min_par + np.random.random()) * max_par - return res - - def generate_vec_ranged_rnd(self, min_par, max_par): - """ - Generate the scaled random 3D vector with a magnitude - in the range between sqrt(3)*min_par*max_par and - sqrt(3)*(min_par+1.0)*max_par. - - Parameters - ---------- - min_par : :obj:`int` - Minimal value parameter. - max_par : :obj:`int` - Maximal value parameter. - - """ - - res = (min_par + np.random.random(3)) * max_par - return res - - def set_langevin_global_defaults(self): - """ - Setup the NVT thermostat viscous friction parameters. - - """ - - # Global NVT thermostat parameters are assigning by default - for k in range(2): - self.gamma_tran_p_validate[k, :] = self.gamma_global[:] - self.gamma_rot_p_validate[k, :] = self.gamma_global[:] - self.halfkT_p_validate[k] = self.kT / 2.0 - - def set_langevin_global_defaults_rot_differ(self): - """ - Setup the NVT thermostat viscous friction parameters - with a rotation-specific gamma. - - """ - - # Global NVT thermostat parameters are assigning by default - for k in range(2): - self.gamma_tran_p_validate[k, :] = self.gamma_global[:] - self.gamma_rot_p_validate[k, :] = self.gamma_global_rot[:] - self.halfkT_p_validate[k] = self.kT / 2.0 - - def dissipation_param_setup(self): - """ - Setup the parameters for the following dissipation - test. - - """ - - ## Time - self.es.time_step = 0.007 - - ## Space - box = 1.0 - self.es.box_l = box,box,box - if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.es.periodicity = 0,0,0 - - ## NVT thermostat - self.kT = 0.0 - # The translational gamma isotropy is required here. - # Global gamma for tests without particle-specific gammas. - # - # As far as the problem characteristic time is t0 ~ mass / gamma - # and the Langevin equation finite-difference approximation is stable - # only for time_step << t0, it is needed to set the gamma less than - # some maximal value according to the value max_gamma_param. - # Also, it cannot be very small (min_gamma_param), otherwise the thermalization will require - # too much of the CPU time. Same: for all such gamma assignments throughout the test. - # - min_gamma_param = 0.5 - max_gamma_param = 2.0/3.0 - gamma_rnd = self.generate_scalar_ranged_rnd(min_gamma_param, max_gamma_param) - self.gamma_global = gamma_rnd, gamma_rnd, gamma_rnd - # Additional test case for the specific global rotational gamma set. - self.gamma_global_rot = self.generate_vec_ranged_rnd(0.5,2.0/3.0) - # Per-paricle values: - self.kT_p = 0.0,0.0 - # Either translational friction isotropy is required - # or both translational and rotational ones. - # Otherwise these types of motion will interfere. - # ..Let's test both cases depending on the particle index. - self.gamma_tran_p[0, 0] = self.generate_scalar_ranged_rnd(0.5,1.0) - self.gamma_tran_p[0, 1] = self.gamma_tran_p[0, 0] - self.gamma_tran_p[0, 2] = self.gamma_tran_p[0, 0] - self.gamma_rot_p[0, :] = self.generate_vec_ranged_rnd(0.5,2.0/3.0) - self.gamma_tran_p[1, 0] = self.generate_scalar_ranged_rnd(0.5,1.0) - self.gamma_tran_p[1, 1] = self.gamma_tran_p[1, 0] - self.gamma_tran_p[1, 2] = self.gamma_tran_p[1, 0] - self.gamma_rot_p[1, 0] = self.generate_scalar_ranged_rnd(0.5,2.0/3.0) - self.gamma_rot_p[1, 1] = self.gamma_rot_p[1, 0] - self.gamma_rot_p[1, 2] = self.gamma_rot_p[1, 0] - - ## Particles - self.mass = 12.74 - self.J = 10.0,10.0,10.0 - for i in range(2): - self.es.part.add(rotation=(1,1,1), pos=(0.0,0.0,0.0), id=i) - self.es.part[i].v = 1.0,1.0,1.0 - if "ROTATION" in espressomd.features(): - self.es.part[i].omega_body = 1.0,1.0,1.0 - self.es.part[i].mass = self.mass - self.es.part[i].rinertia = self.J - - def dissipation_viscous_drag_setup(self): - """ - Setup the specific parameters for the following dissipation - test of the viscous drag terminal velocity stationarity. - - """ - ## Time - # Large time_step is OK for the BD by its definition & its benefits - self.es.time_step = 10.0 - ## NVT thermostat - # Isotropic reassignment is required here for the drag tests - self.gamma_global_rot = np.zeros((3)) - self.gamma_global_rot[0] = (0.5 + np.random.random()) * 2.0 / 3.0 - self.gamma_global_rot[1] = self.gamma_global_rot[0] - self.gamma_global_rot[2] = self.gamma_global_rot[0] - # Isotropy is required here for the drag tests - self.gamma_rot_p[0, 0] = self.generate_scalar_ranged_rnd(0.5,2.0/3.0) - self.gamma_rot_p[0, 1] = self.gamma_rot_p[0, 0] - self.gamma_rot_p[0, 2] = self.gamma_rot_p[0, 0] - - def fluctuation_dissipation_param_setup(self,n): - """ - Setup the parameters for the following fluctuation-dissipation - test. - - Parameters - ---------- - n : :obj:`int` - Number of particles of the each type. There are 2 types. - - """ - - ## Time - # Large time_step is OK for the BD by its definition - self.es.time_step = 10.0 - - ## Space - box = 10.0 - self.es.box_l = box,box,box - if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.es.periodicity = 0,0,0 - - ## NVT thermostat - # Just some temperature range to cover by the test: - self.kT = self.generate_scalar_ranged_rnd(0.3,5) - # See the above comment regarding the gamma assignments. - # Note: here & hereinafter specific variations in these ranges are related to - # the test execution duration to achieve the required statistical averages faster. - self.gamma_global = self.generate_vec_ranged_rnd(0.5,2.0/3.0) - self.gamma_global_rot = self.generate_vec_ranged_rnd(0.2,20) - # Per-particle parameters - self.kT_p = 2.5,2.0 - for k in range(2): - self.gamma_tran_p[k, :] = self.generate_vec_ranged_rnd(0.4,10.0) - self.gamma_rot_p[k, :] = self.generate_vec_ranged_rnd(0.2,20.0) - - ## Particles - # As far as the problem characteristic time is t0 ~ mass / gamma - # and the Langevin equation finite-difference approximation is stable - # only for time_step << t0, it is needed to set the mass higher than - # some minimal value according to the value min_mass_param. - # Also, it is expected to test the large enough mass (max_mass_param). - # It should be not very large, otherwise the thermalization will require - # too much of the CPU time. - min_mass_param = 0.2 - max_mass_param = 7.0 - self.mass = self.generate_scalar_ranged_rnd(min_mass_param,max_mass_param) - self.J = self.generate_vec_ranged_rnd(min_mass_param,max_mass_param) - for i in range(n): - for k in range(2): - ind = i + k * n - part_pos = np.random.random(3) * box - part_v = 0.0,0.0,0.0 - part_omega_body = 0.0,0.0,0.0 - self.es.part.add(rotation=(1,1,1), id=ind, mass=self.mass, rinertia=self.J, - pos=part_pos, v=part_v) - if "ROTATION" in espressomd.features(): - self.es.part[ind].omega_body = part_omega_body - - # Note: the decelleration test is needed for the Langevin thermostat only. Brownian thermostat is defined - # over a larger time-step by its concept. cf. mass-and-rinertia_per_particle.py (def check_dissipation(self):) - def check_dissipation_viscous_drag(self): - """ - Check the dissipation relations: the drag terminal velocity tests, - aka the drift in case of the electrostatics - - """ - tol = 7E-3 - if "EXTERNAL_FORCES" in espressomd.features(): - for k in range(2): - self.es.part[k].pos = np.zeros((3)) - self.es.part[k].v = np.zeros((3)) - self.es.part[k].omega_body = np.zeros((3)) - # Just some random forces - f0 = -1.2,58.3578,0.002 - f1 = -15.112,-2.0,368.0 - self.es.part[0].ext_force = f0 - self.es.part[1].ext_force = f1 - if "ROTATION" in espressomd.features(): - # Just some random torques - tor0 = 12,0.022,87 - tor1 = -0.03,-174,368 - self.es.part[0].ext_torque = tor0 - self.es.part[1].ext_torque = tor1 - # Let's set the dipole perpendicular to the torque - if "DIPOLES" in espressomd.features(): - dip0 = 0.0,tor0[2],-tor0[1] - dip1 = -tor1[2],0.0,tor1[0] - self.es.part[0].dip = dip0 - self.es.part[1].dip = dip1 - tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) - tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) - # Small number of steps is enough for the terminal velocity within the BD by its definition. - # A simulation of the original saturation of the velocity. - self.es.integrator.run(7) - self.es.time = 0.0 - for k in range(2): - self.es.part[k].pos = np.zeros((3)) - if "DIPOLES" in espressomd.features(): - self.es.part[0].dip = dip0 - self.es.part[1].dip = dip1 - for i in range(3): - # Small number of steps - self.es.integrator.run(2) - for k in range(3): - # Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010) - # First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). - self.assertLess( - abs(self.es.part[0].v[k] - f0[k] / self.gamma_tran_p_validate[0, k]), tol) - self.assertLess( - abs(self.es.part[1].v[k] - f1[k] / self.gamma_tran_p_validate[1, k]), tol) - # Second (deterministic) term of the Eq. (14.39) of Schlick2010. - self.assertLess( - abs(self.es.part[0].pos[k] - self.es.time * f0[k] / self.gamma_tran_p_validate[0, k]), tol) - self.assertLess( - abs(self.es.part[1].pos[k] - self.es.time * f1[k] / self.gamma_tran_p_validate[1, k]), tol) - # Same, a rotational analogy. - if "ROTATION" in espressomd.features(): - self.assertLess(abs( - self.es.part[0].omega_lab[k] - tor0[k] / self.gamma_rot_p_validate[0, k]), tol) - self.assertLess(abs( - self.es.part[1].omega_lab[k] - tor1[k] / self.gamma_rot_p_validate[1, k]), tol) - if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): - # Same, a rotational analogy. One is implemented using a simple linear algebra; - # the polar angles with a sign control just for a correct inverse trigonometric functions application. - cos_alpha0 = np.dot(dip0,self.es.part[0].dip) / (np.linalg.norm(dip0) * self.es.part[0].dipm) - cos_alpha0_test = np.cos(self.es.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0]) - sgn0 = np.sign(np.dot(self.es.part[0].dip, tmp_axis0)) - sgn0_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0])) - - cos_alpha1 = np.dot(dip1,self.es.part[1].dip) / (np.linalg.norm(dip1) * self.es.part[1].dipm) - cos_alpha1_test = np.cos(self.es.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0]) - sgn1 = np.sign(np.dot(self.es.part[1].dip, tmp_axis1)) - sgn1_test = np.sign(np.sin(self.es.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0])) - - self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) - self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) - self.assertEqual(sgn0, sgn0_test) - self.assertEqual(sgn1, sgn1_test) - - def check_fluctuation_dissipation(self,n): - """ - Check the fluctuation-dissipation relations: thermalization - and diffusion properties. - - Parameters - ---------- - n : :obj:`int` - Number of particles of the each type. There are 2 types. - - """ - - ## The thermalization and diffusion test - # Checks if every degree of freedom has 1/2 kT of energy, even when - # mass and inertia tensor are active - # Check the factual translational diffusion. - # - # matrices: [2 types of particless] x [3 dimensions X Y Z] - # velocity^2, omega^2, position^2 - v2 = np.zeros((2, 3)) - o2 = np.zeros((2, 3)) - dr2 = np.zeros((2, 3)) - # Variance to compare with: - sigma2_tr = np.zeros((2)) - # Comparable variance: - dr_norm = np.zeros((2)) - - pos0 = np.zeros((2 * n, 3)) - for p in range(n): - for k in range(2): - ind = p + k * n - pos0[ind, :] = self.es.part[ind].pos - dt0 = self.mass / self.gamma_tran_p_validate - - loops = 2 - # Thermalizing... - therm_steps = 2 - self.es.integrator.run(therm_steps) - # Measuring... - - int_steps = 19 - for i in range(loops): - self.es.integrator.run(int_steps) - # Get kinetic energy in each degree of freedom for all particles - for p in range(n): - for k in range(2): - ind = p + k * n - v = self.es.part[ind].v - if "ROTATION" in espressomd.features(): - o = self.es.part[ind].omega_body - o2[k, :] = o2[k, :] + np.power(o[:], 2) - pos = self.es.part[ind].pos - v2[k, :] = v2[k, :] + np.power(v[:], 2) - dr2[k, :] = np.power((pos[:] - pos0[ind, :]), 2) - dt = (int_steps * (i + 1) + therm_steps) * \ - self.es.time_step - # translational diffusion variance: after a closed-form - # integration of the Langevin EOM; - # ref. the eq. (10.2.26) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010) - # after simple transformations and the dimensional model matching (cf. eq. (10.1.1) there). - # The BD requires also the limit dt >> dt0, hence one gets rid of the exponents here. - sigma2_tr[k] = 0.0 - for j in range(3): - sigma2_tr[k] += self.D_tran_p_validate[k,j] * 2.0 * dt - dr_norm[k] += (sum(dr2[k, :]) - sigma2_tr[k]) / sigma2_tr[k] - - tolerance = 0.15 - Ev = 0.5 * self.mass * v2 / (n * loops) - Eo = 0.5 * self.J * o2 / (n * loops) - dv = np.zeros((2)) - do = np.zeros((2)) - do_vec = np.zeros((2, 3)) - for k in range(2): - dv[k] = sum(Ev[k, :]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 - do[k] = sum(Eo[k, :]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 - do_vec[k, :] = Eo[k, :] / self.halfkT_p_validate[k] - 1.0 - dr_norm /= (n * loops) - - for k in range(2): - self.assertLessEqual( - abs( - dv[k]), - tolerance, - msg='Relative deviation in translational energy too large: {0}'.format( - dv[k])) - if "ROTATION" in espressomd.features(): - self.assertLessEqual( - abs( - do[k]), - tolerance, - msg='Relative deviation in rotational energy too large: {0}'.format( - do[k])) - self.assertLessEqual(abs( - do_vec[k, 0]), tolerance, msg='Relative deviation in rotational energy per the body axis X is too large: {0}'.format(do_vec[k, 0])) - self.assertLessEqual(abs( - do_vec[k, 1]), tolerance, msg='Relative deviation in rotational energy per the body axis Y is too large: {0}'.format(do_vec[k, 1])) - self.assertLessEqual(abs( - do_vec[k, 2]), tolerance, msg='Relative deviation in rotational energy per the body axis Z is too large: {0}'.format(do_vec[k, 2])) - self.assertLessEqual( - abs( - dr_norm[k]), - tolerance, - msg='Relative deviation in translational diffusion is too large: {0}'.format( - dr_norm[k])) - - def set_particle_specific_gamma(self,n): - """ - Set the particle-specific gamma. - - Parameters - ---------- - n : :obj:`int` - Number of particles of the each type. There are 2 types. - - """ - - for k in range(2): - self.gamma_tran_p_validate[k, :] = self.gamma_tran_p[k, :] - self.gamma_rot_p_validate[k, :] = self.gamma_rot_p[k, :] - for i in range(n): - ind = i + k * n - self.es.part[ind].gamma = self.gamma_tran_p[k, :] - if "ROTATION" in espressomd.features(): - self.es.part[ind].gamma_rot = self.gamma_rot_p[k, :] - - def set_particle_specific_temperature(self,n): - """ - Set the particle-specific temperature. - - Parameters - ---------- - n : :obj:`int` - Number of particles of the each type. There are 2 types. - - """ - - for k in range(2): - self.halfkT_p_validate[k] = self.kT_p[k] / 2.0 - for i in range(n): - ind = i + k * n - self.es.part[ind].temp = self.kT_p[k] - - def set_diffusivity_tran(self): - """ - Set the translational diffusivity to validate further. - - """ - - for k in range(2): - # Translational diffusivity for a validation - self.D_tran_p_validate[k, :] = 2.0 * self.halfkT_p_validate[k] / self.gamma_tran_p_validate[k, :] - - # Test case 0.0: no particle specific values / dissipation only - def test_case_00(self): - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_param_setup() - self.dissipation_viscous_drag_setup() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - # Actual integration and validation run - self.check_dissipation_viscous_drag() - - # Test case 0.1: no particle specific values / fluctuation & dissipation - def test_case_01(self): - # Each of 2 kind of particles will be represented by n instances: - n = 200 - self.fluctuation_dissipation_param_setup(n) - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.set_diffusivity_tran() - # Actual integration and validation run - self.check_fluctuation_dissipation(n) - - # Test case 1.0: particle specific gamma but not temperature / dissipation only - def test_case_10(self): - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_param_setup() - self.dissipation_viscous_drag_setup() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.set_particle_specific_gamma(n) - # Actual integration and validation run - self.check_dissipation_viscous_drag() - - # Test case 1.1: particle specific gamma but not temperature / fluctuation & dissipation - def test_case_11(self): - # Each of 2 kind of particles will be represented by n instances: - n = 200 - self.fluctuation_dissipation_param_setup(n) - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.set_particle_specific_gamma(n) - self.set_diffusivity_tran() - # Actual integration and validation run - self.check_fluctuation_dissipation(n) - - # Test case 2.0: particle specific temperature but not gamma / dissipation only - def test_case_20(self): - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_param_setup() - self.dissipation_viscous_drag_setup() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.set_particle_specific_temperature(n) - # Actual integration and validation run - self.check_dissipation_viscous_drag() - - # Test case 2.1: particle specific temperature but not gamma / fluctuation & dissipation - def test_case_21(self): - # Each of 2 kind of particles will be represented by n instances: - n = 200 - self.fluctuation_dissipation_param_setup(n) - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.set_particle_specific_temperature(n) - self.set_diffusivity_tran() - # Actual integration and validation run - self.check_fluctuation_dissipation(n) - - # Test case 3.0: both particle specific gamma and temperature / dissipation only - def test_case_30(self): - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_param_setup() - self.dissipation_viscous_drag_setup() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.set_particle_specific_gamma(n) - self.set_particle_specific_temperature(n) - # Actual integration and validation run - self.check_dissipation_viscous_drag() - - # Test case 3.1: both particle specific gamma and temperature / fluctuation & dissipation - def test_case_31(self): - # Each of 2 kind of particles will be represented by n instances: - n = 200 - self.fluctuation_dissipation_param_setup(n) - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.set_particle_specific_gamma(n) - self.set_particle_specific_temperature(n) - self.set_diffusivity_tran() - # Actual integration and validation run - self.check_fluctuation_dissipation(n) - - # Test case 4.0: no particle specific values / rotational specific global thermostat / dissipation only - def test_case_40(self): - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_param_setup() - self.dissipation_viscous_drag_setup() - self.set_langevin_global_defaults_rot_differ() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) - # Actual integration and validation run - self.check_dissipation_viscous_drag() - - # Test case 4.1: no particle specific values / rotational specific global thermostat / fluctuation & dissipation - def test_case_41(self): - # Each of 2 kind of particles will be represented by n instances: - n = 200 - self.fluctuation_dissipation_param_setup(n) - self.set_langevin_global_defaults_rot_differ() - # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) - self.set_diffusivity_tran() - # Actual integration and validation run - self.check_fluctuation_dissipation(n) -if __name__ == '__main__': - ut.main() diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 5682f291558..f838f2498e4 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -30,9 +30,9 @@ class ThermoTest(ut.TestCase): longMessage = True # Handle for espresso system - es = espressomd.System(box_l=[1.0, 1.0, 1.0]) - es.seed = es.cell_system.get_state()['n_nodes'] * [1234] - es.cell_system.skin = 5.0 + system = espressomd.System(box_l=[1.0, 1.0, 1.0]) + system.seed = system.cell_system.get_state()['n_nodes'] * [1234] + system.cell_system.skin = 5.0 # The NVT thermostat parameters kT = 0.0 @@ -66,8 +66,8 @@ def setUpClass(cls): np.random.seed(15) def setUp(self): - self.es.time = 0.0 - self.es.part.clear() + self.system.time = 0.0 + self.system.part.clear() def generate_scalar_ranged_rnd(self, min_par, max_par): """ @@ -133,14 +133,15 @@ def dissipation_param_setup(self): """ + system = self.system # Time - self.es.time_step = 0.007 + self.system.time_step = 0.007 # Space box = 1.0 - self.es.box_l = box, box, box + self.system.box_l = box, box, box if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.es.periodicity = 0, 0, 0 + self.system.periodicity = 0, 0, 0 # NVT thermostat self.kT = 0.0 @@ -183,12 +184,32 @@ def dissipation_param_setup(self): self.mass = 12.74 self.J = 10.0, 10.0, 10.0 for i in range(2): - self.es.part.add(rotation=(1, 1, 1), pos=(0.0, 0.0, 0.0), id=i) - self.es.part[i].v = 1.0, 1.0, 1.0 + system.part.add(rotation=(1, 1, 1), pos=(0.0, 0.0, 0.0), id=i) + system.part[i].v = 1.0, 1.0, 1.0 if "ROTATION" in espressomd.features(): - self.es.part[i].omega_body = 1.0, 1.0, 1.0 - self.es.part[i].mass = self.mass - self.es.part[i].rinertia = self.J + system.part[i].omega_body = 1.0, 1.0, 1.0 + system.part[i].mass = self.mass + system.part[i].rinertia = self.J + + def dissipation_viscous_drag_setup(self): + """ + Setup the specific parameters for the following dissipation + test of the viscous drag terminal velocity stationarity. + + """ + ## Time + # Large time_step is OK for the BD by its definition & its benefits + self.system.time_step = 17.0 + ## NVT thermostat + # Isotropic reassignment is required here for the drag tests + self.gamma_global_rot = np.zeros((3)) + self.gamma_global_rot[0] = (0.5 + np.random.random()) * 2.0 / 3.0 + self.gamma_global_rot[1] = self.gamma_global_rot[0] + self.gamma_global_rot[2] = self.gamma_global_rot[0] + # Isotropy is required here for the drag tests + self.gamma_rot_p[0, 0] = self.generate_scalar_ranged_rnd(0.5,2.0/3.0) + self.gamma_rot_p[0, 1] = self.gamma_rot_p[0, 0] + self.gamma_rot_p[0, 2] = self.gamma_rot_p[0, 0] def fluctuation_dissipation_param_setup(self, n): """ @@ -202,13 +223,13 @@ def fluctuation_dissipation_param_setup(self, n): """ # Time - self.es.time_step = 0.03 + self.system.time_step = 0.03 # Space box = 10.0 - self.es.box_l = box, box, box + self.system.box_l = box, box, box if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.es.periodicity = 0, 0, 0 + self.system.periodicity = 0, 0, 0 # NVT thermostat # Just some temperature range to cover by the test: @@ -217,7 +238,7 @@ def fluctuation_dissipation_param_setup(self, n): # Note: here & hereinafter specific variations in these ranges are related to # the test execution duration to achieve the required statistical # averages faster. - self.gamma_global = self.generate_vec_ranged_rnd(0.5, 2.0 / 3.0) + self.gamma_global = self.generate_vec_ranged_rnd(1.5, 2.0 / 3.0) self.gamma_global_rot = self.generate_vec_ranged_rnd(0.2, 20) # Per-particle parameters self.kT_p = 2.5, 2.0 @@ -244,7 +265,7 @@ def fluctuation_dissipation_param_setup(self, n): part_pos = np.random.random(3) * box part_v = 0.0, 0.0, 0.0 part_omega_body = 0.0, 0.0, 0.0 - self.es.part.add( + self.system.part.add( rotation=( 1, 1, @@ -255,7 +276,7 @@ def fluctuation_dissipation_param_setup(self, n): pos=part_pos, v=part_v) if "ROTATION" in espressomd.features(): - self.es.part[ind].omega_body = part_omega_body + self.system.part[ind].omega_body = part_omega_body def check_dissipation(self): """ @@ -263,6 +284,7 @@ def check_dissipation(self): """ + system = self.system tol = 1.25E-4 for i in range(100): for k in range(2): @@ -272,12 +294,94 @@ def check_dissipation(self): # Hence, only isotropic gamma_tran_p_validate could be # tested here. self.assertLess(abs( - self.es.part[k].v[j] - math.exp(- self.gamma_tran_p_validate[k, j] * self.es.time / self.mass)), tol) + system.part[k].v[j] - math.exp(- self.gamma_tran_p_validate[k, j] * system.time / self.mass)), tol) if "ROTATION" in espressomd.features(): self.assertLess(abs( - self.es.part[k].omega_body[j] - math.exp(- self.gamma_rot_p_validate[k, j] * self.es.time / self.J[j])), tol) + system.part[k].omega_body[j] - math.exp(- self.gamma_rot_p_validate[k, j] * system.time / self.J[j])), tol) - def check_fluctuation_dissipation(self, n): + # Note: the decelleration test is needed for the Langevin thermostat only. Brownian thermostat is defined + # over a larger time-step by its concept. + def check_dissipation_viscous_drag(self): + """ + Check the dissipation relations: the drag terminal velocity tests, + aka the drift in case of the electrostatics + + """ + system = self.system + tol = 7E-3 + if "EXTERNAL_FORCES" in espressomd.features(): + for k in range(2): + system.part[k].pos = np.zeros((3)) + system.part[k].v = np.zeros((3)) + system.part[k].omega_body = np.zeros((3)) + # Just some random forces + f0 = -1.2,58.3578,0.002 + f1 = -15.112,-2.0,368.0 + system.part[0].ext_force = f0 + system.part[1].ext_force = f1 + if "ROTATION" in espressomd.features(): + # Just some random torques + tor0 = 12,0.022,87 + tor1 = -0.03,-174,368 + system.part[0].ext_torque = tor0 + system.part[1].ext_torque = tor1 + # Let's set the dipole perpendicular to the torque + if "DIPOLES" in espressomd.features(): + dip0 = 0.0,tor0[2],-tor0[1] + dip1 = -tor1[2],0.0,tor1[0] + system.part[0].dip = dip0 + system.part[1].dip = dip1 + tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) + tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) + # Small number of steps is enough for the terminal velocity within the BD by its definition. + # A simulation of the original saturation of the velocity. + system.integrator.run(7) + system.time = 0.0 + for k in range(2): + system.part[k].pos = np.zeros((3)) + if "DIPOLES" in espressomd.features(): + system.part[0].dip = dip0 + system.part[1].dip = dip1 + for i in range(3): + # Small number of steps + system.integrator.run(2) + for k in range(3): + # Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010) + # First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). + self.assertLess( + abs(system.part[0].v[k] - f0[k] / self.gamma_tran_p_validate[0, k]), tol) + self.assertLess( + abs(system.part[1].v[k] - f1[k] / self.gamma_tran_p_validate[1, k]), tol) + # Second (deterministic) term of the Eq. (14.39) of Schlick2010. + self.assertLess( + abs(system.part[0].pos[k] - system.time * f0[k] / self.gamma_tran_p_validate[0, k]), tol) + self.assertLess( + abs(system.part[1].pos[k] - system.time * f1[k] / self.gamma_tran_p_validate[1, k]), tol) + # Same, a rotational analogy. + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + system.part[0].omega_lab[k] - tor0[k] / self.gamma_rot_p_validate[0, k]), tol) + self.assertLess(abs( + system.part[1].omega_lab[k] - tor1[k] / self.gamma_rot_p_validate[1, k]), tol) + if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): + # Same, a rotational analogy. One is implemented using a simple linear algebra; + # the polar angles with a sign control just for a correct inverse trigonometric functions application. + cos_alpha0 = np.dot(dip0,system.part[0].dip) / (np.linalg.norm(dip0) * system.part[0].dipm) + cos_alpha0_test = np.cos(system.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0]) + sgn0 = np.sign(np.dot(system.part[0].dip, tmp_axis0)) + sgn0_test = np.sign(np.sin(system.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0])) + + cos_alpha1 = np.dot(dip1,system.part[1].dip) / (np.linalg.norm(dip1) * system.part[1].dipm) + cos_alpha1_test = np.cos(system.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0]) + sgn1 = np.sign(np.dot(system.part[1].dip, tmp_axis1)) + sgn1_test = np.sign(np.sin(system.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0])) + + self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) + self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) + self.assertEqual(sgn0, sgn0_test) + self.assertEqual(sgn1, sgn1_test) + + def check_fluctuation_dissipation(self, n, therm_steps, loops): """ Check the fluctuation-dissipation relations: thermalization and diffusion properties. @@ -286,8 +390,13 @@ def check_fluctuation_dissipation(self, n): ---------- n : :obj:`int` Number of particles of the each type. There are 2 types. + therm_steps : :obj:`int` + Number of thermalization steps. + loops : :obj:`int` + Number of iterations in the sampling. """ + system = self.system # The thermalization and diffusion test # Checks if every degree of freedom has 1/2 kT of energy, even when # mass and inertia tensor are active @@ -307,29 +416,27 @@ def check_fluctuation_dissipation(self, n): for p in range(n): for k in range(2): ind = p + k * n - pos0[ind, :] = self.es.part[ind].pos + pos0[ind, :] = system.part[ind].pos dt0 = self.mass / self.gamma_tran_p_validate - loops = 250 - therm_steps = 20 - self.es.integrator.run(therm_steps) + system.integrator.run(therm_steps) int_steps = 5 for i in range(loops): - self.es.integrator.run(int_steps) + system.integrator.run(int_steps) # Get kinetic energy in each degree of freedom for all particles for p in range(n): for k in range(2): ind = p + k * n - v = self.es.part[ind].v + v = system.part[ind].v if "ROTATION" in espressomd.features(): - o = self.es.part[ind].omega_body + o = system.part[ind].omega_body o2[k, :] = o2[k, :] + np.power(o[:], 2) - pos = self.es.part[ind].pos + pos = system.part[ind].pos v2[k, :] = v2[k, :] + np.power(v[:], 2) dr2[k, :] = np.power((pos[:] - pos0[ind, :]), 2) dt = (int_steps * (i + 1) + therm_steps) * \ - self.es.time_step + system.time_step # translational diffusion variance: after a closed-form # integration of the Langevin EOM; # ref. the eq. (10.2.26) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010) @@ -405,9 +512,9 @@ def set_particle_specific_gamma(self, n): self.gamma_rot_p_validate[k, :] = self.gamma_rot_p[k, :] for i in range(n): ind = i + k * n - self.es.part[ind].gamma = self.gamma_tran_p[k, :] + self.system.part[ind].gamma = self.gamma_tran_p[k, :] if "ROTATION" in espressomd.features(): - self.es.part[ind].gamma_rot = self.gamma_rot_p[k, :] + self.system.part[ind].gamma_rot = self.gamma_rot_p[k, :] def set_particle_specific_temperature(self, n): """ @@ -424,7 +531,7 @@ def set_particle_specific_temperature(self, n): self.halfkT_p_validate[k] = self.kT_p[k] / 2.0 for i in range(n): ind = i + k * n - self.es.part[ind].temp = self.kT_p[k] + self.system.part[ind].temp = self.kT_p[k] def set_diffusivity_tran(self): """ @@ -439,143 +546,269 @@ def set_diffusivity_tran(self): # Test case 0.0: no particle specific values / dissipation only def test_case_00(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) # Actual integration and validation run self.check_dissipation() + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.dissipation_viscous_drag_setup() + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 0.1: no particle specific values / fluctuation & dissipation def test_case_01(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 200 + therm_steps = 20 + loops = 250 self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.turn_off() + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_diffusivity_tran() # Actual integration and validation run - self.check_fluctuation_dissipation(n) + self.check_fluctuation_dissipation(n, therm_steps, loops) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Large time-step is OK for BD. + system.time_step = 42 + # Less number of loops are needed in case of BD because the velocity + # distribution is already as required. It is not a result of a real dynamics. + loops = 8 + # The BD does not require so the warmup. Only 1 step is enough. + # More steps are taken just to be sure that they will not lead + # to wrong results. + therm_steps = 2 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.check_fluctuation_dissipation(n, therm_steps, loops) # Test case 1.0: particle specific gamma but not temperature / dissipation # only def test_case_10(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.turn_off() + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) # Actual integration and validation run self.check_dissipation() + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.dissipation_viscous_drag_setup() + self.set_particle_specific_gamma(n) + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 1.1: particle specific gamma but not temperature / fluctuation # & dissipation def test_case_11(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 200 + therm_steps = 20 + loops = 250 self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.turn_off() + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) self.set_diffusivity_tran() # Actual integration and validation run - self.check_fluctuation_dissipation(n) + self.check_fluctuation_dissipation(n, therm_steps, loops) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + system.time_step = 42 + loops = 8 + therm_steps = 2 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.check_fluctuation_dissipation(n, therm_steps, loops) # Test case 2.0: particle specific temperature but not gamma / dissipation # only def test_case_20(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.turn_off() + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_temperature(n) # Actual integration and validation run self.check_dissipation() + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.dissipation_viscous_drag_setup() + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 2.1: particle specific temperature but not gamma / fluctuation # & dissipation def test_case_21(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 200 + therm_steps = 20 + loops = 250 self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.turn_off() + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_temperature(n) self.set_diffusivity_tran() # Actual integration and validation run - self.check_fluctuation_dissipation(n) + self.check_fluctuation_dissipation(n, therm_steps, loops) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + system.time_step = 42 + loops = 8 + therm_steps = 2 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.check_fluctuation_dissipation(n, therm_steps, loops) # Test case 3.0: both particle specific gamma and temperature / # dissipation only def test_case_30(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.turn_off() + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) self.set_particle_specific_temperature(n) # Actual integration and validation run self.check_dissipation() + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.dissipation_viscous_drag_setup() + self.set_particle_specific_gamma(n) + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 3.1: both particle specific gamma and temperature / # fluctuation & dissipation def test_case_31(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 200 + therm_steps = 20 + loops = 250 self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) + system.thermostat.turn_off() + system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) self.set_particle_specific_temperature(n) self.set_diffusivity_tran() # Actual integration and validation run - self.check_fluctuation_dissipation(n) + self.check_fluctuation_dissipation(n, therm_steps, loops) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + system.time_step = 42 + loops = 8 + therm_steps = 2 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.check_fluctuation_dissipation(n, therm_steps, loops) # Test case 4.0: no particle specific values / rotational specific global # thermostat / dissipation only def test_case_40(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults_rot_differ() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_langevin( + system.thermostat.turn_off() + system.thermostat.set_langevin( kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) # Actual integration and validation run self.check_dissipation() + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.dissipation_viscous_drag_setup() + self.set_langevin_global_defaults_rot_differ() + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian( + kT=self.kT, + gamma=self.gamma_global, + gamma_rotation=self.gamma_global_rot) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 4.1: no particle specific values / rotational specific global # thermostat / fluctuation & dissipation def test_case_41(self): + system = self.system # Each of 2 kind of particles will be represented by n instances: n = 200 + therm_steps = 20 + loops = 250 self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults_rot_differ() # The test case-specific thermostat and per-particle parameters - self.es.thermostat.turn_off() - self.es.thermostat.set_langevin( + system.thermostat.turn_off() + system.thermostat.set_langevin( kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) self.set_diffusivity_tran() # Actual integration and validation run - self.check_fluctuation_dissipation(n) - + self.check_fluctuation_dissipation(n, therm_steps, loops) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + system.time_step = 42 + loops = 8 + therm_steps = 2 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian( + kT=self.kT, + gamma=self.gamma_global, + gamma_rotation=self.gamma_global_rot) + self.check_fluctuation_dissipation(n, therm_steps, loops) if __name__ == '__main__': ut.main() From c14b5bce8bea3145abeaeca113ade3a54653a9da Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Wed, 12 Sep 2018 23:05:57 +0300 Subject: [PATCH 060/150] Clang build fix: zero division removal --- src/core/integrate.cpp | 6 +++++- src/core/rotation.cpp | 6 +++++- src/core/rotation.hpp | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 2d9cab2359d..4d5b78b8616 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1087,7 +1087,11 @@ void bd_random_walk(Particle &p, double dt) { } } else // Default temperature but particle-specific gamma - brown_sigma_pos_temp_inv = sqrt(p.p.gamma / (langevin_temp_coeff * temperature)); + if (temperature > 0.0) { + brown_sigma_pos_temp_inv = sqrt(p.p.gamma / (langevin_temp_coeff * temperature)); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; + } } // particle specific gamma else { diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 2d063fcab65..e372ca6bd59 100644 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -787,7 +787,11 @@ void bd_random_walk_rot(Particle &p, double dt) { } } else // Default temperature but particle-specific gamma - brown_sigma_pos_temp_inv = sqrt(p.p.gamma_rot / (langevin_temp_coeff * temperature)); + if (temperature > 0.) { + brown_sigma_pos_temp_inv = sqrt(p.p.gamma_rot / (langevin_temp_coeff * temperature)); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; + } } // particle specific gamma else { // No particle-specific gamma, but is there particle-specific temperature diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 7141dd901b1..30ee9c5b32b 100644 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -130,6 +130,7 @@ inline void normalize_quaternion(double *q) { q[3] /= tmp; } +#ifdef BROWNIAN_DYNAMICS /** Propagate quaternions: viscous drag driven by conservative torques.*/ void bd_drag_rot(Particle &p, double dt); /** Set the terminal angular velocity driven by the conservative torques drag.*/ @@ -139,5 +140,6 @@ void bd_drag_vel_rot(Particle &p, double dt); void bd_random_walk_rot(Particle &p, double dt); /** Thermalize angular velocity: random walk part.*/ void bd_random_walk_vel_rot(Particle &p, double dt); +#endif // BROWNIAN_DYNAMICS #endif From b8e2ceb973e3c436fa72e77599195251a38456a1 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Wed, 12 Sep 2018 23:48:39 +0300 Subject: [PATCH 061/150] Trigger From a2c43c41b443a246a68122c989a93e9d94b6fb71 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 14 Sep 2018 00:46:51 +0300 Subject: [PATCH 062/150] Refactoring --- maintainer/configs/nocheck-maxset.hpp | 2 + src/core/integrate.cpp | 76 +++++++------ src/core/rotation.cpp | 117 +++++--------------- testsuite/mass-and-rinertia_per_particle.py | 97 ++++++---------- 4 files changed, 106 insertions(+), 186 deletions(-) diff --git a/maintainer/configs/nocheck-maxset.hpp b/maintainer/configs/nocheck-maxset.hpp index 5c579234eec..3fa0aedd4c0 100755 --- a/maintainer/configs/nocheck-maxset.hpp +++ b/maintainer/configs/nocheck-maxset.hpp @@ -41,6 +41,8 @@ along with this program. If not, see . #define LB_BOUNDARIES #define LB_ELECTROHYDRODYNAMICS +#define BROWNIAN_DYNAMICS + #ifdef CUDA #define LB_GPU #define LB_BOUNDARIES_GPU diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 4d5b78b8616..971f332b196 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -124,8 +124,14 @@ void force_and_velocity_display(); void finalize_p_inst_npt(); +#ifdef BROWNIAN_DYNAMICS /** Propagate position: random walk part.*/ void bd_random_walk(Particle &p, double dt); +/** Propagate velocities: all parts.*/ +void bd_vel_steps(Particle &p, double dt); +/** Propagate positions: all parts.*/ +void bd_pos_steps(Particle &p, double dt); +#endif /*@}*/ @@ -699,12 +705,7 @@ void propagate_vel() { for (auto &p : local_cells.particles()) { #ifdef ROTATION -#ifdef BROWNIAN_DYNAMICS - if (!(thermo_switch & THERMO_BROWNIAN)) -#endif // BROWNIAN_DYNAMICS - { propagate_omega_quat_particle(&p); - } #endif // Don't propagate translational degrees of freedom of vs @@ -713,12 +714,7 @@ void propagate_vel() { continue; #endif #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel(p,0.5 * time_step); - bd_drag_vel_rot(p,0.5 * time_step); - bd_random_walk_vel(p,0.5 * time_step); - bd_random_walk_vel_rot(p,0.5 * time_step); - } + bd_vel_steps(p, 0.5 * time_step); #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES @@ -781,12 +777,7 @@ void propagate_pos() { continue; #endif #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drag(p, time_step); - bd_drag_rot(p, time_step); - bd_random_walk(p, time_step); - bd_random_walk_rot(p, time_step); - } + bd_pos_steps(p, time_step); #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES @@ -826,12 +817,7 @@ void propagate_vel_pos() { for (auto &p : local_cells.particles()) { #ifdef ROTATION -#ifdef BROWNIAN_DYNAMICS - if (!(thermo_switch & THERMO_BROWNIAN)) -#endif // BROWNIAN_DYNAMICS - { - propagate_omega_quat_particle(&p); - } + propagate_omega_quat_particle(&p); #endif // Don't propagate translational degrees of freedom of vs @@ -840,16 +826,8 @@ void propagate_vel_pos() { continue; #endif #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel(p,0.5 * time_step); - bd_drag_vel_rot(p,0.5 * time_step); - bd_random_walk_vel(p,0.5 * time_step); - bd_random_walk_vel_rot(p,0.5 * time_step); - bd_drag(p, time_step); - bd_drag_rot(p, time_step); - bd_random_walk(p, time_step); - bd_random_walk_rot(p, time_step); - } + bd_vel_steps(p, 0.5 * time_step); + bd_pos_steps(p, time_step); #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES @@ -1054,6 +1032,38 @@ int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, } #ifdef BROWNIAN_DYNAMICS +/** Propagate the velocities: all parts.*/ +/*********************************************************/ +/** \name bd_vel_steps */ +/*********************************************************/ +/** + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_vel_steps(Particle &p, double dt) { + if (thermo_switch & THERMO_BROWNIAN) { + bd_drag_vel(p, dt); + bd_drag_vel_rot(p, dt); + bd_random_walk_vel(p, dt); + bd_random_walk_vel_rot(p, dt); + } +} +/** Propagate the positions: all parts.*/ +/*********************************************************/ +/** \name bd_pos_steps */ +/*********************************************************/ +/** + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_pos_steps(Particle &p, double dt) { + if (thermo_switch & THERMO_BROWNIAN) { + bd_drag(p, dt); + bd_drag_rot(p, dt); + bd_random_walk(p, dt); + bd_random_walk_rot(p, dt); + } +} /** Propagate the positions: random walk part.*/ /*********************************************************/ /** \name bd_drag_vel */ diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index e372ca6bd59..4b2e2d0a58b 100644 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -219,6 +219,10 @@ void propagate_omega_quat_particle(Particle *p) { // If rotation for the particle is disabled entirely, return early. if (!p->p.rotation) return; +#ifdef BROWNIAN_DYNAMICS + if (thermo_switch & THERMO_BROWNIAN) + return; +#endif // BROWNIAN_DYNAMICS // Clear rotational velocity for blocked rotation axes. if (!(p->p.rotation & ROTATION_X)) @@ -535,25 +539,36 @@ void convert_vec_space_to_body(Particle *p, double const *v, double *res) { res[2] = A[2 + 3 * 0] * v[0] + A[2 + 3 * 1] * v[1] + A[2 + 3 * 2] * v[2]; } +/** Fixing the per-particle per-axis rotations + */ +void rotation_fix(Particle &p, double *a) { + // Per coordinate fixing + if (!(p.p.rotation & ROTATION_X)) + a[0] = 0; + if (!(p.p.rotation & ROTATION_Y)) + a[1] = 0; + if (!(p.p.rotation & ROTATION_Z)) + a[2] = 0; +} + /** Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi */ void local_rotate_particle(Particle *p, double *aSpaceFrame, double phi) { // Convert rotation axis to body-fixed frame double a[3]; convert_vec_space_to_body(p, aSpaceFrame, a); + rotate_particle_body(p, a, phi); +} +/** Rotate the particle p around the body axis "a" by amount phi */ +void rotate_particle_body(Particle* p, double* a, double phi) +{ // printf("%g %g %g - ",a[0],a[1],a[2]); // Rotation turned off entirely? if (!p->p.rotation) return; - // Per coordinate fixing - if (!(p->p.rotation & ROTATION_X)) - a[0] = 0; - if (!(p->p.rotation & ROTATION_Y)) - a[1] = 0; - if (!(p->p.rotation & ROTATION_Z)) - a[2] = 0; + rotation_fix(*p, a); // Re-normalize rotation axis double l = sqrt(sqrlen(a)); // Check, if the rotation axis is nonzero @@ -585,50 +600,6 @@ void local_rotate_particle(Particle *p, double *aSpaceFrame, double phi) { #endif } -/** Rotate the particle p around the body axis "a" by amount phi */ -void rotate_particle_body(Particle* p, double* a, double phi) -{ - // Apply restrictions from the rotation_per_particle feature -#ifdef ROTATION_PER_PARTICLE - // Rotation turned off entirely? - if (p->p.rotation <2) return; - - // Per coordinate fixing - if (!(p->p.rotation & 2)) a[0]=0; - if (!(p->p.rotation & 4)) a[1]=0; - if (!(p->p.rotation & 8)) a[2]=0; - // Re-normalize rotation axis - double l=sqrt(sqrlen(a)); - // Check, if the rotation axis is nonzero - if (l<1E-10) return; - - for (int i=0;i<3;i++) - a[i]/=l; - -#endif - - double q[] = { - cos(phi / 2), - sin(phi / 2) * a[0], - sin(phi / 2) * a[1], - sin(phi / 2) * a[2] - }; - - // Normalize - normalize_quaternion(q); - - // Rotate the particle - double qn[4]; // Resulting quaternion - multiply_quaternions(p->r.quat,q,qn); - for (int k=0; k<4; k++) - p->r.quat[k]=qn[k]; - convert_quat_to_quatu(p->r.quat, p->r.quatu); -#ifdef DIPOLES - // When dipoles are enabled, update dipole moment - convert_quatu_to_dip(p->r.quatu, p->p.dipm, p->r.dip); -#endif -} - /** Rotate the particle p around the j-th body axis by amount phi */ void rotate_particle_body_j(Particle* p, int j, double phi) { @@ -655,16 +626,7 @@ void bd_drag_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; a[0] = a[1] = a[2] = 1.0; -#ifdef ROTATION_PER_PARTICLE - if (!p.p.rotation) - return; - if (!(p.p.rotation & 2)) - a[0] = 0.0; - if (!(p.p.rotation & 4)) - a[1] = 0.0; - if (!(p.p.rotation & 8)) - a[2] = 0.0; -#endif + rotation_fix(p, a); if(p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; @@ -710,16 +672,7 @@ void bd_drag_vel_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; a[0] = a[1] = a[2] = 1.0; -#ifdef ROTATION_PER_PARTICLE - if (!p.p.rotation) - return; - if (!(p.p.rotation & 2)) - a[0] = 0.0; - if (!(p.p.rotation & 4)) - a[1] = 0.0; - if (!(p.p.rotation & 8)) - a[2] = 0.0; -#endif + rotation_fix(p, a); if(p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; @@ -761,16 +714,7 @@ void bd_random_walk_rot(Particle &p, double dt) { Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; a[0] = a[1] = a[2] = 1.0; -#ifdef ROTATION_PER_PARTICLE - if (!p.p.rotation) - return; - if (!(p.p.rotation & 2)) - a[0] = 0.0; - if (!(p.p.rotation & 4)) - a[1] = 0.0; - if (!(p.p.rotation & 8)) - a[2] = 0.0; -#endif + rotation_fix(p, a); // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -848,16 +792,7 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { double brown_sigma_vel_temp = brown_sigma_vel_rotation; a[0] = a[1] = a[2] = 1.0; -#ifdef ROTATION_PER_PARTICLE - if (!p.p.rotation) - return; - if (!(p.p.rotation & 2)) - a[0] = 0.0; - if (!(p.p.rotation & 4)) - a[1] = 0.0; - if (!(p.p.rotation & 8)) - a[2] = 0.0; -#endif + rotation_fix(p, a); // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index f838f2498e4..315681e289d 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -544,6 +544,33 @@ def set_diffusivity_tran(self): self.D_tran_p_validate[k, :] = 2.0 * \ self.halfkT_p_validate[k] / self.gamma_tran_p_validate[k, :] + if "BROWNIAN_DYNAMICS" in espressomd.features(): + def check_fluctuation_dissipation_bd(self, n): + system = self.system + # Large time-step is OK for BD. + system.time_step = 42 + # Less number of loops are needed in case of BD because the velocity + # distribution is already as required. It is not a result of a real dynamics. + loops = 8 + # The BD does not require so the warmup. Only 1 step is enough. + # More steps are taken just to be sure that they will not lead + # to wrong results. + therm_steps = 2 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.check_fluctuation_dissipation(n, therm_steps, loops) + + def check_dissipation_viscous_drag_bd(self): + system = self.system + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_dissipation_viscous_drag() + # Test case 0.0: no particle specific values / dissipation only def test_case_00(self): system = self.system @@ -557,12 +584,7 @@ def test_case_00(self): self.check_dissipation() if "BROWNIAN_DYNAMICS" in espressomd.features(): self.dissipation_viscous_drag_setup() - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag_bd() # Test case 0.1: no particle specific values / fluctuation & dissipation def test_case_01(self): @@ -580,20 +602,7 @@ def test_case_01(self): # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Large time-step is OK for BD. - system.time_step = 42 - # Less number of loops are needed in case of BD because the velocity - # distribution is already as required. It is not a result of a real dynamics. - loops = 8 - # The BD does not require so the warmup. Only 1 step is enough. - # More steps are taken just to be sure that they will not lead - # to wrong results. - therm_steps = 2 - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.check_fluctuation_dissipation_bd(n) # Test case 1.0: particle specific gamma but not temperature / dissipation # only @@ -612,12 +621,7 @@ def test_case_10(self): if "BROWNIAN_DYNAMICS" in espressomd.features(): self.dissipation_viscous_drag_setup() self.set_particle_specific_gamma(n) - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag_bd() # Test case 1.1: particle specific gamma but not temperature / fluctuation # & dissipation @@ -637,14 +641,7 @@ def test_case_11(self): # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - system.time_step = 42 - loops = 8 - therm_steps = 2 - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.check_fluctuation_dissipation_bd(n) # Test case 2.0: particle specific temperature but not gamma / dissipation # only @@ -662,12 +659,7 @@ def test_case_20(self): self.check_dissipation() if "BROWNIAN_DYNAMICS" in espressomd.features(): self.dissipation_viscous_drag_setup() - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag_bd() # Test case 2.1: particle specific temperature but not gamma / fluctuation # & dissipation @@ -687,14 +679,7 @@ def test_case_21(self): # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - system.time_step = 42 - loops = 8 - therm_steps = 2 - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.check_fluctuation_dissipation_bd(n) # Test case 3.0: both particle specific gamma and temperature / # dissipation only @@ -714,12 +699,7 @@ def test_case_30(self): if "BROWNIAN_DYNAMICS" in espressomd.features(): self.dissipation_viscous_drag_setup() self.set_particle_specific_gamma(n) - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag_bd() # Test case 3.1: both particle specific gamma and temperature / # fluctuation & dissipation @@ -740,14 +720,7 @@ def test_case_31(self): # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - system.time_step = 42 - loops = 8 - therm_steps = 2 - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.check_fluctuation_dissipation_bd(n) # Test case 4.0: no particle specific values / rotational specific global # thermostat / dissipation only From 86db6a9da1d438b26ca3be4c17e96e51b8221576 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 14 Sep 2018 22:10:16 +0300 Subject: [PATCH 063/150] nocheck build fix (BD) --- src/core/thermostat.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 31600481385..2705651bc89 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -195,9 +195,26 @@ void thermo_init_brownian() { } else { brown_sigma_pos_rotation_inv = brown_gammatype_nan; // just an indication of the infinity } - THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation_inv)); #endif // ROTATION +#ifdef PARTICLE_ANISOTROPY + THERMO_TRACE(fprintf(stderr, + "%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos_inv=(%f,%f,%f)", + this_node, + brown_sigma_vel, + brown_sigma_pos_inv[0], brown_sigma_pos_inv[1], brown_sigma_pos_inv[2])); +#ifdef ROTATION + THERMO_TRACE(fprintf(stderr, + "%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation_inv=(%f,%f,%f)", + this_node, + brown_sigma_vel_rotation, + brown_sigma_pos_rotation_inv[0], brown_sigma_pos_rotation_inv[1], brown_sigma_pos_rotation_inv[2])); +#endif // ROTATION +#else THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos=%f",this_node,brown_sigma_vel,brown_sigma_pos_inv)); +#ifdef ROTATION + THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation_inv)); +#endif // ROTATION +#endif // PARTICLE_ANISOTROPY } #endif // BROWNIAN_DYNAMICS From ab7fbf18efd97d16304cb633b006398390ac70a8 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Sat, 15 Sep 2018 00:02:56 +0300 Subject: [PATCH 064/150] Formatting --- src/core/brownian_inline.hpp | 29 +++-- src/core/integrate.cpp | 97 ++++++++------- src/core/rotation.cpp | 123 +++++++++++--------- src/core/rotation.hpp | 4 +- src/core/thermostat.cpp | 58 +++++---- src/core/thermostat.hpp | 3 +- src/python/espressomd/thermostat.pyx | 7 +- testsuite/langevin_thermostat.py | 3 +- testsuite/mass-and-rinertia_per_particle.py | 60 +++++----- testsuite/tests_common.py | 3 + 10 files changed, 216 insertions(+), 171 deletions(-) diff --git a/src/core/brownian_inline.hpp b/src/core/brownian_inline.hpp index 6f1aa3c67a5..932e1e066a6 100644 --- a/src/core/brownian_inline.hpp +++ b/src/core/brownian_inline.hpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2010,2011,2012,2013,2014,2015,2016,2017,2018 The ESPResSo project + Copyright (C) 2010-2018 The ESPResSo project Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Max-Planck-Institute for Polymer Research, Theory Group @@ -38,7 +38,7 @@ inline void bd_drag(Particle &p, double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: Thermostat::GammaType local_gamma; - if(p.p.gamma >= Thermostat::GammaType{}) { + if (p.p.gamma >= Thermostat::GammaType{}) { local_gamma = p.p.gamma; } else { local_gamma = langevin_gamma; @@ -72,7 +72,7 @@ inline void bd_drag_vel(Particle &p, double dt) { // The friction tensor Z from the eq. (14.31) of Schlick2010: Thermostat::GammaType local_gamma; - if(p.p.gamma >= Thermostat::GammaType{}) { + if (p.p.gamma >= Thermostat::GammaType{}) { local_gamma = p.p.gamma; } else { local_gamma = langevin_gamma; @@ -85,9 +85,10 @@ inline void bd_drag_vel(Particle &p, double dt) { } else #endif { - // First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). - // Only conservative part of the force is used here - // NOTE: velocity is assigned here and propagated by thermal part further on top of it + // First (deterministic) term of the eq. (14.34) of Schlick2010 taking + // into account eq. (14.35). Only conservative part of the force is used + // here NOTE: velocity is assigned here and propagated by thermal part + // further on top of it #ifndef PARTICLE_ANISOTROPY p.m.v[j] = p.f.f[j] / (local_gamma); #else @@ -106,7 +107,8 @@ inline void bd_drag_vel(Particle &p, double dt) { * @param dt Time interval (Input) */ inline void bd_random_walk_vel(Particle &p, double dt) { - // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs afterwards, Pottier2010 + // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs + // afterwards, Pottier2010 extern double brown_sigma_vel; // first, set defaults double brown_sigma_vel_temp = brown_sigma_vel; @@ -127,11 +129,14 @@ inline void bd_random_walk_vel(Particle &p, double dt) { if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - // Random (heat) velocity is added here. It is already initialized in the terminal drag part. - // See eq. (10.2.16) taking into account eq. (10.2.18) and (10.2.29), Pottier2010. - // Note, that the Pottier2010 units system (see Eq. (10.1.1) there) has been adapted towards the ESPResSo and the referenced above Schlick2010 one, - // which is defined by the eq. (14.31) of Schlick2010. A difference is the mass factor to the friction tensor. - // The noise is Gaussian according to the convention at p. 237 (last paragraph), Pottier2010. + // Random (heat) velocity is added here. It is already initialized in the + // terminal drag part. See eq. (10.2.16) taking into account eq. (10.2.18) + // and (10.2.29), Pottier2010. Note, that the Pottier2010 units system + // (see Eq. (10.1.1) there) has been adapted towards the ESPResSo and the + // referenced above Schlick2010 one, which is defined by the eq. (14.31) + // of Schlick2010. A difference is the mass factor to the friction tensor. + // The noise is Gaussian according to the convention at p. 237 (last + // paragraph), Pottier2010. p.m.v[j] += brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p.p.mass); } } diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 971f332b196..534e32d23e0 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -56,8 +56,8 @@ #include "utils.hpp" #include "virtual_sites.hpp" -#include "collision.hpp" #include "brownian_inline.hpp" +#include "collision.hpp" #include "forces.hpp" #include "immersed_boundaries.hpp" #include "npt.hpp" @@ -540,12 +540,12 @@ void propagate_vel_finalize_p_inst() { continue; #endif #ifdef BROWNIAN_DYNAMICS - if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel(p,0.5 * time_step); - bd_random_walk_vel(p,0.5 * time_step); - } + if (thermo_switch & THERMO_BROWNIAN) { + bd_drag_vel(p, 0.5 * time_step); + bd_random_walk_vel(p, 0.5 * time_step); + } #endif // BROWNIAN_DYNAMICS - for (int j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) { #endif @@ -716,7 +716,7 @@ void propagate_vel() { #ifdef BROWNIAN_DYNAMICS bd_vel_steps(p, 0.5 * time_step); #endif // BROWNIAN_DYNAMICS - for (int j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif @@ -829,24 +829,24 @@ void propagate_vel_pos() { bd_vel_steps(p, 0.5 * time_step); bd_pos_steps(p, time_step); #endif // BROWNIAN_DYNAMICS - for (int j = 0; j < 3; j++) { + for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (!(p.p.ext_flag & COORD_FIXED(j))) + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif - { + { #ifdef BROWNIAN_DYNAMICS - if (!(thermo_switch & THERMO_BROWNIAN)) + if (!(thermo_switch & THERMO_BROWNIAN)) #endif // BROWNIAN_DYNAMICS - { - /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5 * dt * a(t) */ - p.m.v[j] += 0.5 * time_step * p.f.f[j] / p.p.mass; + { + /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5 * dt * a(t) */ + p.m.v[j] += 0.5 * time_step * p.f.f[j] / p.p.mass; - /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * - * v(t+0.5*dt) */ - p.r.p[j] += time_step * p.m.v[j]; - } + /* Propagate positions (only NVT): p(t + dt) = p(t) + dt * + * v(t+0.5*dt) */ + p.r.p[j] += time_step * p.m.v[j]; } } + } ONEPART_TRACE(if (p.p.identity == check_id) fprintf( stderr, "%d: OPT: PV_1 v_new = (%.3e,%.3e,%.3e)\n", this_node, p.m.v[0], @@ -1073,9 +1073,10 @@ void bd_pos_steps(Particle &p, double dt) { * @param dt Time interval (Input) */ void bd_random_walk(Particle &p, double dt) { - // Position dispersion is defined by the second eq. (14.38) of Schlick2010 taking into account eq. (14.35). - // Its time interval factor will be added at the end of this function. - // Its square root is the standard deviation. A multiplicative inverse of the position standard deviation: + // Position dispersion is defined by the second eq. (14.38) of Schlick2010 + // taking into account eq. (14.35). Its time interval factor will be added at + // the end of this function. Its square root is the standard deviation. A + // multiplicative inverse of the position standard deviation: extern Thermostat::GammaType brown_sigma_pos_inv; // Just a NAN setter, technical variable: extern Thermostat::GammaType brown_gammatype_nan; @@ -1086,34 +1087,37 @@ void bd_random_walk(Particle &p, double dt) { #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 2.0; - if(p.p.gamma >= Thermostat::GammaType{}) { + if (p.p.gamma >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? - if(p.p.T >= 0.) - { + if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_temp_inv = sqrt(p.p.gamma / (langevin_temp_coeff * p.p.T)); + brown_sigma_pos_temp_inv = + sqrt(p.p.gamma / (langevin_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + brown_sigma_pos_temp_inv = + brown_gammatype_nan; // just an indication of the infinity } } else - // Default temperature but particle-specific gamma - if (temperature > 0.0) { - brown_sigma_pos_temp_inv = sqrt(p.p.gamma / (langevin_temp_coeff * temperature)); - } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; - } + // Default temperature but particle-specific gamma + if (temperature > 0.0) { + brown_sigma_pos_temp_inv = + sqrt(p.p.gamma / (langevin_temp_coeff * temperature)); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; + } } // particle specific gamma - else - { + else { // No particle-specific gamma, but is there particle-specific temperature - if(p.p.T >= 0.) { - if(p.p.T > 0.0) { - brown_sigma_pos_temp_inv = sqrt(langevin_gamma / (langevin_temp_coeff * p.p.T)); + if (p.p.T >= 0.) { + if (p.p.T > 0.0) { + brown_sigma_pos_temp_inv = + sqrt(langevin_gamma / (langevin_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + brown_sigma_pos_temp_inv = + brown_gammatype_nan; // just an indication of the infinity } } else { - // Defaut values for both + // Defaut values for both brown_sigma_pos_temp_inv = brown_sigma_pos_inv; } } @@ -1123,15 +1127,16 @@ void bd_random_walk(Particle &p, double dt) { #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (brown_sigma_pos_temp_inv[0] != brown_sigma_pos_temp_inv[1]) - || (brown_sigma_pos_temp_inv[1] != brown_sigma_pos_temp_inv[2]); + aniso_flag = (brown_sigma_pos_temp_inv[0] != brown_sigma_pos_temp_inv[1]) || + (brown_sigma_pos_temp_inv[1] != brown_sigma_pos_temp_inv[2]); #endif #ifdef PARTICLE_ANISOTROPY Vector3d delta_pos_body, delta_pos_lab; #endif - // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared magnitude defined in the second eq. (14.38), Schlick2010. + // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared + // magnitude defined in the second eq. (14.38), Schlick2010. for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -1139,13 +1144,15 @@ void bd_random_walk(Particle &p, double dt) { { #ifndef PARTICLE_ANISOTROPY if (brown_sigma_pos_temp_inv > 0.0) { - delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * Thermostat::noise_g(); + delta_pos_body[j] = + (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * Thermostat::noise_g(); } else { delta_pos_body[j] = 0.0; } #else if (brown_sigma_pos_temp_inv[j] > 0.0) { - delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * Thermostat::noise_g(); + delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * + Thermostat::noise_g(); } else { delta_pos_body[j] = 0.0; } @@ -1162,7 +1169,7 @@ void bd_random_walk(Particle &p, double dt) { if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += aniso_flag ? delta_pos_lab[j] : delta_pos_body[j]; + p.r.p[j] += aniso_flag ? delta_pos_lab[j] : delta_pos_body[j]; } } } diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 4b2e2d0a58b..d26cd8cf030 100644 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -32,6 +32,7 @@ */ #include "rotation.hpp" +#include "brownian_inline.hpp" #include "cells.hpp" #include "communication.hpp" #include "cuda_interface.hpp" @@ -44,7 +45,6 @@ #include "particle_data.hpp" #include "thermostat.hpp" #include "utils.hpp" -#include "brownian_inline.hpp" #include #include #include @@ -376,14 +376,16 @@ void convert_torques_propagate_omega() { #ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) { - bd_drag_vel_rot(p,0.5 * time_step); - bd_random_walk_vel_rot(p,0.5 * time_step); + bd_drag_vel_rot(p, 0.5 * time_step); + bd_random_walk_vel_rot(p, 0.5 * time_step); } else #endif // BROWNIAN_DYNAMICS { ONEPART_TRACE(if (p.p.identity == check_id) fprintf( - stderr, "%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n", - this_node, p.f.f[0], p.f.f[1], p.f.f[2], p.m.v[0], p.m.v[1], p.m.v[2])); + stderr, + "%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n", + this_node, p.f.f[0], p.f.f[1], p.f.f[2], p.m.v[0], p.m.v[1], + p.m.v[2])); p.m.omega[0] += time_step_half * p.f.torque[0] / p.p.rinertia[0]; p.m.omega[1] += time_step_half * p.f.torque[1] / p.p.rinertia[1]; @@ -400,15 +402,15 @@ void convert_torques_propagate_omega() { for (int times = 0; times <= 5; times++) { double Wd[3]; - Wd[0] = - (p.m.omega[1] * p.m.omega[2] * (p.p.rinertia[1] - p.p.rinertia[2])) / - p.p.rinertia[0]; - Wd[1] = - (p.m.omega[2] * p.m.omega[0] * (p.p.rinertia[2] - p.p.rinertia[0])) / - p.p.rinertia[1]; - Wd[2] = - (p.m.omega[0] * p.m.omega[1] * (p.p.rinertia[0] - p.p.rinertia[1])) / - p.p.rinertia[2]; + Wd[0] = (p.m.omega[1] * p.m.omega[2] * + (p.p.rinertia[1] - p.p.rinertia[2])) / + p.p.rinertia[0]; + Wd[1] = (p.m.omega[2] * p.m.omega[0] * + (p.p.rinertia[2] - p.p.rinertia[0])) / + p.p.rinertia[1]; + Wd[2] = (p.m.omega[0] * p.m.omega[1] * + (p.p.rinertia[0] - p.p.rinertia[1])) / + p.p.rinertia[2]; p.m.omega[0] = omega_0[0] + time_step_half * Wd[0]; p.m.omega[1] = omega_0[1] + time_step_half * Wd[1]; @@ -416,8 +418,8 @@ void convert_torques_propagate_omega() { } ONEPART_TRACE(if (p.p.identity == check_id) fprintf( - stderr, "%d: OPT: PV_2 v_new = (%.3e,%.3e,%.3e)\n", this_node, p.m.v[0], - p.m.v[1], p.m.v[2])); + stderr, "%d: OPT: PV_2 v_new = (%.3e,%.3e,%.3e)\n", this_node, + p.m.v[0], p.m.v[1], p.m.v[2])); } } } @@ -561,8 +563,7 @@ void local_rotate_particle(Particle *p, double *aSpaceFrame, double phi) { } /** Rotate the particle p around the body axis "a" by amount phi */ -void rotate_particle_body(Particle* p, double* a, double phi) -{ +void rotate_particle_body(Particle *p, double *a, double phi) { // printf("%g %g %g - ",a[0],a[1],a[2]); // Rotation turned off entirely? if (!p->p.rotation) @@ -578,12 +579,8 @@ void rotate_particle_body(Particle* p, double* a, double phi) for (int i = 0; i < 3; i++) a[i] /= l; - double q[] = { - cos(phi / 2), - sin(phi / 2) * a[0], - sin(phi / 2) * a[1], - sin(phi / 2) * a[2] - }; + double q[] = {cos(phi / 2), sin(phi / 2) * a[0], sin(phi / 2) * a[1], + sin(phi / 2) * a[2]}; // Normalize normalize_quaternion(q); @@ -601,8 +598,7 @@ void rotate_particle_body(Particle* p, double* a, double phi) } /** Rotate the particle p around the j-th body axis by amount phi */ -void rotate_particle_body_j(Particle* p, int j, double phi) -{ +void rotate_particle_body_j(Particle *p, int j, double phi) { double u_dphi[3] = {0.0, 0.0, 0.0}; if (phi != 0.0) { u_dphi[j] = 1.0; @@ -616,7 +612,8 @@ void rotate_particle_body_j(Particle* p, int j, double phi) /*********************************************************/ /** \name bd_drag_rot */ /*********************************************************/ -/**(An analogy of eq. (14.39) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) +/**(An analogy of eq. (14.39) T. Schlick, + * https://doi.org/10.1007/978-1-4419-6351-2 (2010)) * @param &p Reference to the particle (Input) * @param dt Time interval (Input) */ @@ -628,7 +625,7 @@ void bd_drag_rot(Particle &p, double dt) { a[0] = a[1] = a[2] = 1.0; rotation_fix(p, a); - if(p.p.gamma_rot >= Thermostat::GammaType{}) { + if (p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; } else { local_gamma = langevin_gamma_rotation; @@ -646,15 +643,17 @@ void bd_drag_rot(Particle &p, double dt) { #else dphi[j] = a[j] * p.f.torque[j] * dt / (local_gamma[j]); #endif // ROTATIONAL_INERTIA - //rotate_particle_body_j(p, j, dphi[j]); + // rotate_particle_body_j(p, j, dphi[j]); } - } //j + } // j double dphi_m = 0.0; - for (int j = 0; j < 3; j++) dphi_m += pow(dphi[j], 2); + for (int j = 0; j < 3; j++) + dphi_m += pow(dphi[j], 2); dphi_m = sqrt(dphi_m); double dphi_u[3]; if (dphi_m) { - for (int j = 0; j < 3; j++) dphi_u[j] = dphi[j] / dphi_m; + for (int j = 0; j < 3; j++) + dphi_u[j] = dphi[j] / dphi_m; rotate_particle_body(&(p), dphi_u, dphi_m); } } @@ -663,7 +662,8 @@ void bd_drag_rot(Particle &p, double dt) { /*********************************************************/ /** \name bd_drag_vel_rot */ /*********************************************************/ -/**(An analogy of the 1st term of the eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) +/**(An analogy of the 1st term of the eq. (14.34) T. Schlick, + * https://doi.org/10.1007/978-1-4419-6351-2 (2010)) * @param &p Reference to the particle (Input) * @param dt Time interval (Input) */ @@ -674,7 +674,7 @@ void bd_drag_vel_rot(Particle &p, double dt) { a[0] = a[1] = a[2] = 1.0; rotation_fix(p, a); - if(p.p.gamma_rot >= Thermostat::GammaType{}) { + if (p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; } else { local_gamma = langevin_gamma_rotation; @@ -688,7 +688,8 @@ void bd_drag_vel_rot(Particle &p, double dt) { #endif { // only conservative part of the force is used here - // NOTE: velocity is assigned here and propagated by thermal part further on top of it + // NOTE: velocity is assigned here and propagated by thermal part further + // on top of it #ifndef PARTICLE_ANISOTROPY p.m.omega[j] = a[j] * p.f.torque[j] / (local_gamma); #else @@ -702,7 +703,8 @@ void bd_drag_vel_rot(Particle &p, double dt) { /*********************************************************/ /** \name bd_random_walk_rot */ /*********************************************************/ -/**(An analogy of eq. (14.37) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) +/**(An analogy of eq. (14.37) T. Schlick, + * https://doi.org/10.1007/978-1-4419-6351-2 (2010)) * @param &p Reference to the particle (Input) * @param dt Time interval (Input) */ @@ -720,33 +722,37 @@ void bd_random_walk_rot(Particle &p, double dt) { #ifdef LANGEVIN_PER_PARTICLE auto const constexpr langevin_temp_coeff = 2.0; - if(p.p.gamma_rot >= Thermostat::GammaType{}) { + if (p.p.gamma_rot >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? - if(p.p.T >= 0.) - { + if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_temp_inv = sqrt(p.p.gamma_rot / (langevin_temp_coeff * p.p.T) ); + brown_sigma_pos_temp_inv = + sqrt(p.p.gamma_rot / (langevin_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + brown_sigma_pos_temp_inv = + brown_gammatype_nan; // just an indication of the infinity } } else - // Default temperature but particle-specific gamma - if (temperature > 0.) { - brown_sigma_pos_temp_inv = sqrt(p.p.gamma_rot / (langevin_temp_coeff * temperature)); - } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; - } + // Default temperature but particle-specific gamma + if (temperature > 0.) { + brown_sigma_pos_temp_inv = + sqrt(p.p.gamma_rot / (langevin_temp_coeff * temperature)); + } else { + brown_sigma_pos_temp_inv = brown_gammatype_nan; + } } // particle specific gamma else { // No particle-specific gamma, but is there particle-specific temperature - if(p.p.T >= 0.) { + if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_temp_inv = sqrt(langevin_gamma_rotation / (langevin_temp_coeff * p.p.T)); + brown_sigma_pos_temp_inv = + sqrt(langevin_gamma_rotation / (langevin_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity + brown_sigma_pos_temp_inv = + brown_gammatype_nan; // just an indication of the infinity } } else { - // Defaut values for both + // Defaut values for both brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; } } @@ -761,13 +767,15 @@ void bd_random_walk_rot(Particle &p, double dt) { dphi[0] = dphi[1] = dphi[2] = 0.0; #ifndef PARTICLE_ANISOTROPY if (brown_sigma_pos_temp_inv > 0.0) { - dphi[j] = a[j] * Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); + dphi[j] = a[j] * Thermostat::noise_g() * + (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); } else { dphi[j] = 0.0; } #else if (brown_sigma_pos_temp_inv[j] > 0.0) { - dphi[j] = a[j] * Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); + dphi[j] = a[j] * Thermostat::noise_g() * + (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); } else { dphi[j] = 0.0; } @@ -781,7 +789,8 @@ void bd_random_walk_rot(Particle &p, double dt) { /*********************************************************/ /** \name bd_random_walk_vel_rot */ /*********************************************************/ -/**(An analogy of eq. (10.2.16) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010)) +/**(An analogy of eq. (10.2.16) N. Pottier, + * https://doi.org/10.1007/s10955-010-0114-6 (2010)) * @param &p Reference to the particle (Input) * @param dt Time interval (Input) */ @@ -810,8 +819,10 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - // velocity is added here. It is already initialized in the terminal drag part. - p.m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p.p.rinertia[j]); + // velocity is added here. It is already initialized in the terminal drag + // part. + p.m.omega[j] += a[j] * brown_sigma_vel_temp * Thermostat::noise_g() / + sqrt(p.p.rinertia[j]); } } } diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 30ee9c5b32b..b506da23b2d 100644 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -118,9 +118,9 @@ inline void convert_quatu_to_dip(const Vector3d &quatu, double dipm, /** Rotate the particle p around the NORMALIZED axis a by amount phi */ void local_rotate_particle(Particle *p, double *a, double phi); /** Rotate the particle p around the body axis "a" by amount phi */ -void rotate_particle_body(Particle* p, double* a, double phi); +void rotate_particle_body(Particle *p, double *a, double phi); /** Rotate the particle p around the j-th body axis by amount phi */ -void rotate_particle_body_j(Particle* p, int j, double phi); +void rotate_particle_body_j(Particle *p, int j, double phi); inline void normalize_quaternion(double *q) { double tmp = sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 2705651bc89..7ff9a4c9e29 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -167,20 +167,25 @@ void thermo_init_npt_isotropic() { // brown_sigma_pos determines here the BD position random walk dispersion // default particle mass is assumed to be unitary in this global parameters void thermo_init_brownian() { - // Dispersions correspond to the Gaussian noise only which is only valid for the BD. - // Just a square root of kT, see (10.2.17) and comments in 2 paragraphs afterwards, Pottier2010 https://doi.org/10.1007/s10955-010-0114-6 + // Dispersions correspond to the Gaussian noise only which is only valid for + // the BD. Just a square root of kT, see (10.2.17) and comments in 2 + // paragraphs afterwards, Pottier2010 + // https://doi.org/10.1007/s10955-010-0114-6 brown_sigma_vel = sqrt(temperature); - // Position dispersion is defined by the second eq. (14.38) of Schlick2010 https://doi.org/10.1007/978-1-4419-6351-2. - // Its time interval factor will be added in the Brownian Dynamics functions. - // Its square root is the standard deviation. A multiplicative inverse of the position standard deviation: + // Position dispersion is defined by the second eq. (14.38) of Schlick2010 + // https://doi.org/10.1007/978-1-4419-6351-2. Its time interval factor will be + // added in the Brownian Dynamics functions. Its square root is the standard + // deviation. A multiplicative inverse of the position standard deviation: if (temperature > 0.0) { brown_sigma_pos_inv = sqrt(langevin_gamma / (2.0 * temperature)); } else { - brown_sigma_pos_inv = brown_gammatype_nan; // just an indication of the infinity + brown_sigma_pos_inv = + brown_gammatype_nan; // just an indication of the infinity } #ifdef ROTATION // Note: the BD thermostat assigns the langevin viscous parameters as well. - // They correspond to the friction tensor Z from the eq. (14.31) of Schlick2010: + // They correspond to the friction tensor Z from the eq. (14.31) of + // Schlick2010: /* If gamma_rotation is not set explicitly, we use the translational one. */ if (langevin_gamma_rotation < GammaType{}) { @@ -189,30 +194,39 @@ void thermo_init_brownian() { brown_sigma_vel_rotation = sqrt(temperature); // Position dispersion is defined by the second eq. (14.38) of Schlick2010. // Its time interval factor will be added in the Brownian Dynamics functions. - // Its square root is the standard deviation. A multiplicative inverse of the position standard deviation: + // Its square root is the standard deviation. A multiplicative inverse of the + // position standard deviation: if (temperature > 0.0) { brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (2.0 * temperature)); } else { - brown_sigma_pos_rotation_inv = brown_gammatype_nan; // just an indication of the infinity + brown_sigma_pos_rotation_inv = + brown_gammatype_nan; // just an indication of the infinity } #endif // ROTATION #ifdef PARTICLE_ANISOTROPY - THERMO_TRACE(fprintf(stderr, - "%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos_inv=(%f,%f,%f)", - this_node, - brown_sigma_vel, - brown_sigma_pos_inv[0], brown_sigma_pos_inv[1], brown_sigma_pos_inv[2])); + THERMO_TRACE(fprintf( + stderr, + "%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos_inv=(%f,%f,%f)", + this_node, brown_sigma_vel, brown_sigma_pos_inv[0], + brown_sigma_pos_inv[1], brown_sigma_pos_inv[2])); #ifdef ROTATION - THERMO_TRACE(fprintf(stderr, - "%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation_inv=(%f,%f,%f)", - this_node, - brown_sigma_vel_rotation, - brown_sigma_pos_rotation_inv[0], brown_sigma_pos_rotation_inv[1], brown_sigma_pos_rotation_inv[2])); + THERMO_TRACE(fprintf( + stderr, + "%d: thermo_init_bd: brown_sigma_vel_rotation=%f, " + "brown_sigma_pos_rotation_inv=(%f,%f,%f)", + this_node, brown_sigma_vel_rotation, brown_sigma_pos_rotation_inv[0], + brown_sigma_pos_rotation_inv[1], brown_sigma_pos_rotation_inv[2])); #endif // ROTATION #else - THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos=%f",this_node,brown_sigma_vel,brown_sigma_pos_inv)); + THERMO_TRACE(fprintf( + stderr, "%d: thermo_init_bd: brown_sigma_vel=%f, brown_sigma_pos=%f", + this_node, brown_sigma_vel, brown_sigma_pos_inv)); #ifdef ROTATION - THERMO_TRACE(fprintf(stderr,"%d: thermo_init_bd: brown_sigma_vel_rotation=%f, brown_sigma_pos_rotation=%f",this_node, brown_sigma_vel_rotation,brown_sigma_pos_rotation_inv)); + THERMO_TRACE(fprintf(stderr, + "%d: thermo_init_bd: brown_sigma_vel_rotation=%f, " + "brown_sigma_pos_rotation=%f", + this_node, brown_sigma_vel_rotation, + brown_sigma_pos_rotation_inv)); #endif // ROTATION #endif // PARTICLE_ANISOTROPY } @@ -243,7 +257,7 @@ void thermo_init() { thermo_init_ghmc(); #endif #ifdef BROWNIAN_DYNAMICS - if(thermo_switch & THERMO_BROWNIAN) + if (thermo_switch & THERMO_BROWNIAN) thermo_init_brownian(); #endif } diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 44b70508715..235974067c9 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -51,7 +51,8 @@ namespace Thermostat { static auto noise = []() { return (d_random() - 0.5); }; -// Only Gaussian noise is allowed for the BD, otherwise the Maxwell distribution will fail. +// Only Gaussian noise is allowed for the BD, otherwise the Maxwell distribution +// will fail. static auto noise_g = []() { return gaussian_random(); }; #ifdef PARTICLE_ANISOTROPY diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index f7fc9db2972..e576d225af6 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -466,11 +466,14 @@ cdef class Thermostat(object): else: scalar_gamma_rot_def = True - if kT is None or gamma is None: raise ValueError( "Both, kT and gamma have to be given as keyword args") - utils.check_type_or_throw_except(kT, 1, float, "kT must be a number") + utils.check_type_or_throw_except( + kT, + 1, + float, + "kT must be a number") if scalar_gamma_def: utils.check_type_or_throw_except( gamma, 1, float, "gamma must be a number") diff --git a/testsuite/langevin_thermostat.py b/testsuite/langevin_thermostat.py index 26f4bf9e1f3..ec9b98aaf4e 100644 --- a/testsuite/langevin_thermostat.py +++ b/testsuite/langevin_thermostat.py @@ -136,7 +136,8 @@ def test_global_langevin(self): # to wrong results. system.integrator.run(3) # Less number of loops are needed in case of BD because the velocity - # distribution is already as required. It is not a result of a real dynamics. + # distribution is already as required. It is not a result of a real + # dynamics. self.global_langevin_run_check(N, kT, 40) system.thermostat.turn_off() diff --git a/testsuite/mass-and-rinertia_per_particle.py b/testsuite/mass-and-rinertia_per_particle.py index 315681e289d..78d37c5464e 100644 --- a/testsuite/mass-and-rinertia_per_particle.py +++ b/testsuite/mass-and-rinertia_per_particle.py @@ -110,8 +110,8 @@ def set_langevin_global_defaults(self): # Global NVT thermostat parameters are assigning by default for k in range(2): - self.gamma_tran_p_validate[k, :] = self.gamma_global[:] - self.gamma_rot_p_validate[k, :] = self.gamma_global[:] + self.gamma_tran_p_validate[k,:] = self.gamma_global[:] + self.gamma_rot_p_validate[k,:] = self.gamma_global[:] self.halfkT_p_validate[k] = self.kT / 2.0 def set_langevin_global_defaults_rot_differ(self): @@ -122,8 +122,8 @@ def set_langevin_global_defaults_rot_differ(self): """ # Global NVT thermostat parameters are assigning by default for k in range(2): - self.gamma_tran_p_validate[k, :] = self.gamma_global[:] - self.gamma_rot_p_validate[k, :] = self.gamma_global_rot[:] + self.gamma_tran_p_validate[k,:] = self.gamma_global[:] + self.gamma_rot_p_validate[k,:] = self.gamma_global_rot[:] self.halfkT_p_validate[k] = self.kT / 2.0 def dissipation_param_setup(self): @@ -171,7 +171,7 @@ def dissipation_param_setup(self): self.gamma_tran_p[0, 0] = self.generate_scalar_ranged_rnd(0.5, 1.0) self.gamma_tran_p[0, 1] = self.gamma_tran_p[0, 0] self.gamma_tran_p[0, 2] = self.gamma_tran_p[0, 0] - self.gamma_rot_p[0, :] = self.generate_vec_ranged_rnd(0.5, 2.0 / 3.0) + self.gamma_rot_p[0,:] = self.generate_vec_ranged_rnd(0.5, 2.0 / 3.0) self.gamma_tran_p[1, 0] = self.generate_scalar_ranged_rnd(0.5, 1.0) self.gamma_tran_p[1, 1] = self.gamma_tran_p[1, 0] self.gamma_tran_p[1, 2] = self.gamma_tran_p[1, 0] @@ -207,7 +207,7 @@ def dissipation_viscous_drag_setup(self): self.gamma_global_rot[1] = self.gamma_global_rot[0] self.gamma_global_rot[2] = self.gamma_global_rot[0] # Isotropy is required here for the drag tests - self.gamma_rot_p[0, 0] = self.generate_scalar_ranged_rnd(0.5,2.0/3.0) + self.gamma_rot_p[0, 0] = self.generate_scalar_ranged_rnd(0.5, 2.0/3.0) self.gamma_rot_p[0, 1] = self.gamma_rot_p[0, 0] self.gamma_rot_p[0, 2] = self.gamma_rot_p[0, 0] @@ -243,8 +243,8 @@ def fluctuation_dissipation_param_setup(self, n): # Per-particle parameters self.kT_p = 2.5, 2.0 for k in range(2): - self.gamma_tran_p[k, :] = self.generate_vec_ranged_rnd(0.4, 10.0) - self.gamma_rot_p[k, :] = self.generate_vec_ranged_rnd(0.2, 20.0) + self.gamma_tran_p[k,:] = self.generate_vec_ranged_rnd(0.4, 10.0) + self.gamma_rot_p[k,:] = self.generate_vec_ranged_rnd(0.2, 20.0) # Particles # As far as the problem characteristic time is t0 ~ mass / gamma @@ -315,20 +315,20 @@ def check_dissipation_viscous_drag(self): system.part[k].v = np.zeros((3)) system.part[k].omega_body = np.zeros((3)) # Just some random forces - f0 = -1.2,58.3578,0.002 - f1 = -15.112,-2.0,368.0 + f0 = -1.2, 58.3578, 0.002 + f1 = -15.112, -2.0, 368.0 system.part[0].ext_force = f0 system.part[1].ext_force = f1 if "ROTATION" in espressomd.features(): # Just some random torques - tor0 = 12,0.022,87 - tor1 = -0.03,-174,368 + tor0 = 12, 0.022, 87 + tor1 = -0.03, -174, 368 system.part[0].ext_torque = tor0 system.part[1].ext_torque = tor1 # Let's set the dipole perpendicular to the torque if "DIPOLES" in espressomd.features(): - dip0 = 0.0,tor0[2],-tor0[1] - dip1 = -tor1[2],0.0,tor1[0] + dip0 = 0.0, tor0[2], -tor0[1] + dip1 = -tor1[2], 0.0, tor1[0] system.part[0].dip = dip0 system.part[1].dip = dip1 tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) @@ -366,12 +366,12 @@ def check_dissipation_viscous_drag(self): if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): # Same, a rotational analogy. One is implemented using a simple linear algebra; # the polar angles with a sign control just for a correct inverse trigonometric functions application. - cos_alpha0 = np.dot(dip0,system.part[0].dip) / (np.linalg.norm(dip0) * system.part[0].dipm) + cos_alpha0 = np.dot(dip0, system.part[0].dip) / (np.linalg.norm(dip0) * system.part[0].dipm) cos_alpha0_test = np.cos(system.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0]) sgn0 = np.sign(np.dot(system.part[0].dip, tmp_axis0)) sgn0_test = np.sign(np.sin(system.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0])) - cos_alpha1 = np.dot(dip1,system.part[1].dip) / (np.linalg.norm(dip1) * system.part[1].dipm) + cos_alpha1 = np.dot(dip1, system.part[1].dip) / (np.linalg.norm(dip1) * system.part[1].dipm) cos_alpha1_test = np.cos(system.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0]) sgn1 = np.sign(np.dot(system.part[1].dip, tmp_axis1)) sgn1_test = np.sign(np.sin(system.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0])) @@ -416,7 +416,7 @@ def check_fluctuation_dissipation(self, n, therm_steps, loops): for p in range(n): for k in range(2): ind = p + k * n - pos0[ind, :] = system.part[ind].pos + pos0[ind,:] = system.part[ind].pos dt0 = self.mass / self.gamma_tran_p_validate system.integrator.run(therm_steps) @@ -431,10 +431,10 @@ def check_fluctuation_dissipation(self, n, therm_steps, loops): v = system.part[ind].v if "ROTATION" in espressomd.features(): o = system.part[ind].omega_body - o2[k, :] = o2[k, :] + np.power(o[:], 2) + o2[k,:] = o2[k,:] + np.power(o[:], 2) pos = system.part[ind].pos - v2[k, :] = v2[k, :] + np.power(v[:], 2) - dr2[k, :] = np.power((pos[:] - pos0[ind, :]), 2) + v2[k,:] = v2[k,:] + np.power(v[:], 2) + dr2[k,:] = np.power((pos[:] - pos0[ind,:]), 2) dt = (int_steps * (i + 1) + therm_steps) * \ system.time_step # translational diffusion variance: after a closed-form @@ -454,7 +454,7 @@ def check_fluctuation_dissipation(self, n, therm_steps, loops): k, j]) - math.exp(- 2.0 * dt / dt0[k, j]))) - dr_norm[k] += (sum(dr2[k, :]) - + dr_norm[k] += (sum(dr2[k,:]) - sigma2_tr[k]) / sigma2_tr[k] tolerance = 0.15 @@ -464,9 +464,9 @@ def check_fluctuation_dissipation(self, n, therm_steps, loops): do = np.zeros((2)) do_vec = np.zeros((2, 3)) for k in range(2): - dv[k] = sum(Ev[k, :]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 - do[k] = sum(Eo[k, :]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 - do_vec[k, :] = Eo[k, :] / self.halfkT_p_validate[k] - 1.0 + dv[k] = sum(Ev[k,:]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 + do[k] = sum(Eo[k,:]) / (3.0 * self.halfkT_p_validate[k]) - 1.0 + do_vec[k,:] = Eo[k,:] / self.halfkT_p_validate[k] - 1.0 dr_norm /= (n * loops) for k in range(2): @@ -508,13 +508,13 @@ def set_particle_specific_gamma(self, n): """ for k in range(2): - self.gamma_tran_p_validate[k, :] = self.gamma_tran_p[k, :] - self.gamma_rot_p_validate[k, :] = self.gamma_rot_p[k, :] + self.gamma_tran_p_validate[k,:] = self.gamma_tran_p[k,:] + self.gamma_rot_p_validate[k,:] = self.gamma_rot_p[k,:] for i in range(n): ind = i + k * n - self.system.part[ind].gamma = self.gamma_tran_p[k, :] + self.system.part[ind].gamma = self.gamma_tran_p[k,:] if "ROTATION" in espressomd.features(): - self.system.part[ind].gamma_rot = self.gamma_rot_p[k, :] + self.system.part[ind].gamma_rot = self.gamma_rot_p[k,:] def set_particle_specific_temperature(self, n): """ @@ -541,8 +541,8 @@ def set_diffusivity_tran(self): for k in range(2): # Translational diffusivity for a validation - self.D_tran_p_validate[k, :] = 2.0 * \ - self.halfkT_p_validate[k] / self.gamma_tran_p_validate[k, :] + self.D_tran_p_validate[k,:] = 2.0 * \ + self.halfkT_p_validate[k] / self.gamma_tran_p_validate[k,:] if "BROWNIAN_DYNAMICS" in espressomd.features(): def check_fluctuation_dissipation_bd(self, n): diff --git a/testsuite/tests_common.py b/testsuite/tests_common.py index 8089a95d280..6c3a0d31e10 100644 --- a/testsuite/tests_common.py +++ b/testsuite/tests_common.py @@ -228,6 +228,7 @@ def transform_vel_from_cartesian_to_polar_coordinates(pos, vel): vel[0]) / (pos[0]**2.0 + pos[1]**2.0), vel[2]]) + def define_rotation_matrix(system, part): A = np.zeros((3, 3)) quat = system.part[part].quat @@ -247,10 +248,12 @@ def define_rotation_matrix(system, part): return A + def convert_vec_body_to_space(system, part, vec): A = define_rotation_matrix(system, part) return np.dot(A.transpose(), vec) + def rotation_matrix(axis, theta): """ Return the rotation matrix associated with counterclockwise rotation about From 0f25fd861eab071fc839ea2a23fb1e1265d6dc46 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 30 Dec 2018 18:14:01 +0200 Subject: [PATCH 065/150] Formatting rules alignments --- src/core/rotation.cpp | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 37830315392..8fda67c6dc6 100644 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -341,37 +341,42 @@ void convert_torques_propagate_omega() { #endif // BROWNIAN_DYNAMICS { ONEPART_TRACE(if (p.p.identity == check_id) fprintf( - stderr, "%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n", - this_node, p.f.f[0], p.f.f[1], p.f.f[2], p.m.v[0], p.m.v[1], p.m.v[2])); + stderr, + "%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n", + this_node, p.f.f[0], p.f.f[1], p.f.f[2], p.m.v[0], p.m.v[1], + p.m.v[2])); // Propagation of angular velocities p.m.omega[0] += time_step_half * p.f.torque[0] / p.p.rinertia[0]; p.m.omega[1] += time_step_half * p.f.torque[1] / p.p.rinertia[1]; p.m.omega[2] += time_step_half * p.f.torque[2] / p.p.rinertia[2]; - + // zeroth estimate of omega Vector3d omega_0 = p.m.omega; - + /* if the tensor of inertia is isotropic, the following refinement is not needed. Otherwise repeat this loop 2-3 times depending on the required accuracy */ - + const double rinertia_diff_01 = p.p.rinertia[0] - p.p.rinertia[1]; const double rinertia_diff_12 = p.p.rinertia[1] - p.p.rinertia[2]; const double rinertia_diff_20 = p.p.rinertia[2] - p.p.rinertia[0]; for (int times = 0; times <= 5; times++) { Vector3d Wd; - - Wd[0] = p.m.omega[1] * p.m.omega[2] * rinertia_diff_12 / p.p.rinertia[0]; - Wd[1] = p.m.omega[2] * p.m.omega[0] * rinertia_diff_20 / p.p.rinertia[1]; - Wd[2] = p.m.omega[0] * p.m.omega[1] * rinertia_diff_01 / p.p.rinertia[2]; - + + Wd[0] = + p.m.omega[1] * p.m.omega[2] * rinertia_diff_12 / p.p.rinertia[0]; + Wd[1] = + p.m.omega[2] * p.m.omega[0] * rinertia_diff_20 / p.p.rinertia[1]; + Wd[2] = + p.m.omega[0] * p.m.omega[1] * rinertia_diff_01 / p.p.rinertia[2]; + p.m.omega = omega_0 + time_step_half * Wd; } ONEPART_TRACE(if (p.p.identity == check_id) fprintf( - stderr, "%d: OPT: PV_2 v_new = (%.3e,%.3e,%.3e)\n", this_node, p.m.v[0], - p.m.v[1], p.m.v[2])); + stderr, "%d: OPT: PV_2 v_new = (%.3e,%.3e,%.3e)\n", this_node, + p.m.v[0], p.m.v[1], p.m.v[2])); } } } @@ -429,7 +434,7 @@ void rotation_fix(Particle &p, Vector3d &rot_vector) { * aBodyFrame by amount phi */ void local_rotate_particle_body(Particle &p, const Vector3d &axis_body_frame, - const double phi) { + const double phi) { Vector3d axis = axis_body_frame; // Rotation turned off entirely? @@ -626,15 +631,15 @@ void bd_random_walk_rot(Particle &p, double dt) { { #ifndef PARTICLE_ANISOTROPY if (brown_sigma_pos_temp_inv > 0.0) { - dphi[j] = Thermostat::noise_g() * - (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); + dphi[j] = + Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); } else { dphi[j] = 0.0; } #else if (brown_sigma_pos_temp_inv[j] > 0.0) { - dphi[j] = Thermostat::noise_g() * - (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); + dphi[j] = Thermostat::noise_g() * (1.0 / brown_sigma_pos_temp_inv[j]) * + sqrt(dt); } else { dphi[j] = 0.0; } @@ -680,8 +685,8 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { { // velocity is added here. It is already initialized in the terminal drag // part. - domega[j] = brown_sigma_vel_temp * Thermostat::noise_g() / - sqrt(p.p.rinertia[j]); + domega[j] = + brown_sigma_vel_temp * Thermostat::noise_g() / sqrt(p.p.rinertia[j]); } } rotation_fix(p, domega); From b091e8cbd2b10e06c1fe0e86abf7695c400633ee Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 10 Jan 2019 23:47:29 +0200 Subject: [PATCH 066/150] Added get_state of the BD thermostat --- src/python/espressomd/thermostat.pyx | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index e576d225af6..feaf2b8ed52 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -102,9 +102,10 @@ cdef class Thermostat(object): "p_diff"], piston=thmst["piston"]) if thmst["type"] == "DPD": self.set_dpd(kT=thmst["kT"]) - if thmst["type"] == "BROWNIAN": - self.set_brownian(kT=thmst["kT"], gamma=thmst[ - "gamma"], gamma_rotation=thmst["gamma_rotation"]) + IF BROWNIAN_DYNAMICS: + if thmst["type"] == "BROWNIAN": + self.set_brownian(kT=thmst["kT"], gamma=thmst[ + "gamma"], gamma_rotation=thmst["gamma_rotation"]) def get_ts(self): return thermo_switch @@ -138,6 +139,29 @@ cdef class Thermostat(object): lang_dict["gamma_rotation"] = None thermo_list.append(lang_dict) + IF BROWNIAN_DYNAMICS: + if thermo_switch & THERMO_BROWNIAN: + lang_dict = {} + lang_dict["type"] = "BROWNIAN" + lang_dict["kT"] = temperature + lang_dict["act_on_virtual"] = thermo_virtual + IF PARTICLE_ANISOTROPY: + lang_dict["gamma"] = [langevin_gamma[0], + langevin_gamma[1], + langevin_gamma[2]] + ELSE: + lang_dict["gamma"] = langevin_gamma + IF ROTATION: + IF PARTICLE_ANISOTROPY: + lang_dict["gamma_rotation"] = [langevin_gamma_rotation[0], + langevin_gamma_rotation[1], + langevin_gamma_rotation[2]] + ELSE: + lang_dict["gamma_rotation"] = langevin_gamma_rotation + ELSE: + lang_dict["gamma_rotation"] = None + + thermo_list.append(lang_dict) if thermo_switch & THERMO_LB: lb_dict = {} lb_dict["type"] = "LB" From c740070e4312f48bdf6db28be46d14260f36a731 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Fri, 11 Jan 2019 23:11:35 +0200 Subject: [PATCH 067/150] Refactoring: BD test cases separation where one makes sense --- .../python/mass-and-rinertia_per_particle.py | 252 ++++++++++++------ 1 file changed, 168 insertions(+), 84 deletions(-) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index 78d37c5464e..c389fe93da9 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -68,6 +68,21 @@ def setUpClass(cls): def setUp(self): self.system.time = 0.0 self.system.part.clear() + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.system.thermostat.turn_off() + + def set_initial_cond(self): + """ + Set all the particles to zero coordinates and velocities; same for time. + The quaternion is set to default value. + + """ + system = self.system + system.time = 0.0 + system.part[:].pos = np.zeros((3)) + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.part[:].quat = np.array([1., 0., 0., 0.]) def generate_scalar_ranged_rnd(self, min_par, max_par): """ @@ -104,7 +119,7 @@ def generate_vec_ranged_rnd(self, min_par, max_par): def set_langevin_global_defaults(self): """ - Setup the NVT thermostat viscous friction parameters. + Setup the expected NVT thermostat viscous friction parameters. """ @@ -116,7 +131,7 @@ def set_langevin_global_defaults(self): def set_langevin_global_defaults_rot_differ(self): """ - Setup the NVT thermostat viscous friction parameters + Setup the expected NVT thermostat viscous friction parameters with a rotation-specific gamma. """ @@ -191,10 +206,11 @@ def dissipation_param_setup(self): system.part[i].mass = self.mass system.part[i].rinertia = self.J - def dissipation_viscous_drag_setup(self): + def dissipation_viscous_drag_setup_bd(self): """ Setup the specific parameters for the following dissipation test of the viscous drag terminal velocity stationarity. + It is used by the BD test cases only for the moment. """ ## Time @@ -310,10 +326,6 @@ def check_dissipation_viscous_drag(self): system = self.system tol = 7E-3 if "EXTERNAL_FORCES" in espressomd.features(): - for k in range(2): - system.part[k].pos = np.zeros((3)) - system.part[k].v = np.zeros((3)) - system.part[k].omega_body = np.zeros((3)) # Just some random forces f0 = -1.2, 58.3578, 0.002 f1 = -15.112, -2.0, 368.0 @@ -508,8 +520,10 @@ def set_particle_specific_gamma(self, n): """ for k in range(2): + # for the expected metrics calc self.gamma_tran_p_validate[k,:] = self.gamma_tran_p[k,:] self.gamma_rot_p_validate[k,:] = self.gamma_rot_p[k,:] + # init for i in range(n): ind = i + k * n self.system.part[ind].gamma = self.gamma_tran_p[k,:] @@ -528,7 +542,9 @@ def set_particle_specific_temperature(self, n): """ for k in range(2): + # expected self.halfkT_p_validate[k] = self.kT_p[k] / 2.0 + # init for i in range(n): ind = i + k * n self.system.part[ind].temp = self.kT_p[k] @@ -544,35 +560,11 @@ def set_diffusivity_tran(self): self.D_tran_p_validate[k,:] = 2.0 * \ self.halfkT_p_validate[k] / self.gamma_tran_p_validate[k,:] - if "BROWNIAN_DYNAMICS" in espressomd.features(): - def check_fluctuation_dissipation_bd(self, n): - system = self.system - # Large time-step is OK for BD. - system.time_step = 42 - # Less number of loops are needed in case of BD because the velocity - # distribution is already as required. It is not a result of a real dynamics. - loops = 8 - # The BD does not require so the warmup. Only 1 step is enough. - # More steps are taken just to be sure that they will not lead - # to wrong results. - therm_steps = 2 - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - self.check_fluctuation_dissipation(n, therm_steps, loops) - - def check_dissipation_viscous_drag_bd(self): - system = self.system - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) - # Actual integration and validation run - self.check_dissipation_viscous_drag() - - # Test case 0.0: no particle specific values / dissipation only - def test_case_00(self): + # Test case 0.0.0: + # no particle specific values / dissipation only / LD only. + # No meaning for the simple BD propagation cause + # it has no inertial features. + def test_case_000(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 @@ -582,11 +574,29 @@ def test_case_00(self): system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) # Actual integration and validation run self.check_dissipation() - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.dissipation_viscous_drag_setup() - self.check_dissipation_viscous_drag_bd() + + # Test case 0.0.1: + # no particle specific values / dissipation viscous drag only / BD only. + # LD will require too much computational time + # (one is tested offline though). + if "BROWNIAN_DYNAMICS" in espressomd.features(): + def test_case_001(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 0.1: no particle specific values / fluctuation & dissipation + # Same particle and thermostat parameters for LD and BD are required in order + # to test the BD consistency by means of NVT-ensemble. + # Less number of steps and other specific integration parameters of BD + # reflect its temporal scale advances. def test_case_01(self): system = self.system # Each of 2 kind of particles will be represented by n instances: @@ -596,35 +606,59 @@ def test_case_01(self): self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_diffusivity_tran() # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.check_fluctuation_dissipation_bd(n) + self.set_initial_cond() + # Large time-step is OK for BD. + system.time_step = 42 + # Less number of loops are needed in case of BD because the velocity + # distribution is already as required. It is not a result of a real dynamics. + loops = 8 + # The BD does not require so the warmup. Only 1 step is enough. + # More steps are taken just to be sure that they will not lead + # to wrong results. + therm_steps = 2 + # The test case-specific thermostat + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) - # Test case 1.0: particle specific gamma but not temperature / dissipation - # only - def test_case_10(self): + # Test case 1.0.0: particle specific gamma but not temperature / dissipation + # only / LD only + def test_case_100(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) # Actual integration and validation run self.check_dissipation() - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.dissipation_viscous_drag_setup() + + # Test case 1.0.1: particle specific gamma but not temperature / + # dissipation viscous drag only / BD only. + if "BROWNIAN_DYNAMICS" in espressomd.features(): + def test_case_101(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) - self.check_dissipation_viscous_drag_bd() + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 1.1: particle specific gamma but not temperature / fluctuation - # & dissipation + # & dissipation / LD and BD def test_case_11(self): system = self.system # Each of 2 kind of particles will be represented by n instances: @@ -634,35 +668,54 @@ def test_case_11(self): self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) self.set_diffusivity_tran() # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.check_fluctuation_dissipation_bd(n) + self.set_initial_cond() + system.time_step = 42 + loops = 8 + therm_steps = 2 + # The test case-specific thermostat + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) - # Test case 2.0: particle specific temperature but not gamma / dissipation - # only - def test_case_20(self): + # Test case 2.0.0: particle specific temperature but not gamma / dissipation + # only / LD only + def test_case_200(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_temperature(n) # Actual integration and validation run self.check_dissipation() - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.dissipation_viscous_drag_setup() - self.check_dissipation_viscous_drag_bd() + + # Test case 2.0.1: particle specific temperature but not gamma / dissipation + # viscous drag only / BD only + if "BROWNIAN_DYNAMICS" in espressomd.features(): + def test_case_201(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + self.set_particle_specific_temperature(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 2.1: particle specific temperature but not gamma / fluctuation - # & dissipation + # & dissipation / LD and BD def test_case_21(self): system = self.system # Each of 2 kind of particles will be represented by n instances: @@ -672,37 +725,56 @@ def test_case_21(self): self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_temperature(n) self.set_diffusivity_tran() # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.check_fluctuation_dissipation_bd(n) + self.set_initial_cond() + system.time_step = 42 + loops = 8 + therm_steps = 2 + # The test case-specific thermostat and per-particle parameters + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) - # Test case 3.0: both particle specific gamma and temperature / - # dissipation only - def test_case_30(self): + # Test case 3.0.0: both particle specific gamma and temperature / + # dissipation only / LD only + def test_case_300(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) self.set_particle_specific_temperature(n) # Actual integration and validation run self.check_dissipation() - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.dissipation_viscous_drag_setup() + + # Test case 3.0.1: both particle specific gamma and temperature / + # dissipation viscous drag only / BD only + if "BROWNIAN_DYNAMICS" in espressomd.features(): + def test_case_301(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) - self.check_dissipation_viscous_drag_bd() + self.set_particle_specific_temperature(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag() # Test case 3.1: both particle specific gamma and temperature / - # fluctuation & dissipation + # fluctuation & dissipation / LD and BD def test_case_31(self): system = self.system # Each of 2 kind of particles will be represented by n instances: @@ -712,7 +784,6 @@ def test_case_31(self): self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) self.set_particle_specific_temperature(n) @@ -720,30 +791,43 @@ def test_case_31(self): # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.check_fluctuation_dissipation_bd(n) + self.set_initial_cond() + system.time_step = 42 + loops = 8 + therm_steps = 2 + # The test case-specific thermostat + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) - # Test case 4.0: no particle specific values / rotational specific global - # thermostat / dissipation only - def test_case_40(self): + # Test case 4.0.0: no particle specific values / rotational specific global + # thermostat / dissipation only / LD only + def test_case_400(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 self.dissipation_param_setup() self.set_langevin_global_defaults_rot_differ() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin( kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) # Actual integration and validation run self.check_dissipation() - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.dissipation_viscous_drag_setup() + + # Test case 4.0.1: no particle specific values / rotational specific global + # thermostat / dissipation only / BD only + if "BROWNIAN_DYNAMICS" in espressomd.features(): + def test_case_401(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_param_setup() + self.dissipation_viscous_drag_setup_bd() self.set_langevin_global_defaults_rot_differ() - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() + # The test case-specific thermostat and per-particle parameters system.thermostat.set_brownian( kT=self.kT, gamma=self.gamma_global, @@ -752,7 +836,7 @@ def test_case_40(self): self.check_dissipation_viscous_drag() # Test case 4.1: no particle specific values / rotational specific global - # thermostat / fluctuation & dissipation + # thermostat / fluctuation & dissipation / LD and BD def test_case_41(self): system = self.system # Each of 2 kind of particles will be represented by n instances: @@ -762,7 +846,6 @@ def test_case_41(self): self.fluctuation_dissipation_param_setup(n) self.set_langevin_global_defaults_rot_differ() # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() system.thermostat.set_langevin( kT=self.kT, gamma=self.gamma_global, @@ -771,16 +854,17 @@ def test_case_41(self): # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.set_initial_cond() system.time_step = 42 loops = 8 therm_steps = 2 - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) + # The test case-specific thermostat system.thermostat.turn_off() system.thermostat.set_brownian( kT=self.kT, gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) + # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) if __name__ == '__main__': From bcabe8f0a2ba3c869a7018b2769b6216ac739d45 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Fri, 11 Jan 2019 23:19:51 +0200 Subject: [PATCH 068/150] Style --- src/python/espressomd/thermostat.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index feaf2b8ed52..46ba1313b78 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -153,7 +153,8 @@ cdef class Thermostat(object): lang_dict["gamma"] = langevin_gamma IF ROTATION: IF PARTICLE_ANISOTROPY: - lang_dict["gamma_rotation"] = [langevin_gamma_rotation[0], + lang_dict[ + "gamma_rotation"] = [langevin_gamma_rotation[0], langevin_gamma_rotation[1], langevin_gamma_rotation[2]] ELSE: From f12edb65520f309af103bdeaf00d9b4715f122eb Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Fri, 11 Jan 2019 23:23:11 +0200 Subject: [PATCH 069/150] Style --- src/python/espressomd/thermostat.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 46ba1313b78..f394c2e5d71 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -155,8 +155,8 @@ cdef class Thermostat(object): IF PARTICLE_ANISOTROPY: lang_dict[ "gamma_rotation"] = [langevin_gamma_rotation[0], - langevin_gamma_rotation[1], - langevin_gamma_rotation[2]] + langevin_gamma_rotation[1], + langevin_gamma_rotation[2]] ELSE: lang_dict["gamma_rotation"] = langevin_gamma_rotation ELSE: From 098b14f48bd86b3b1c4ef241b32f1519604daf30 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 13 Jan 2019 14:01:19 +0200 Subject: [PATCH 070/150] Disable BD for virtual sites by default --- src/python/espressomd/thermostat.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index f394c2e5d71..48b0aee0754 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -456,7 +456,8 @@ cdef class Thermostat(object): IF BROWNIAN_DYNAMICS: @AssertThermostatType(THERMO_BROWNIAN) - def set_brownian(self, kT=None, gamma=None, gamma_rotation=None): + def set_brownian(self, kT=None, gamma=None, gamma_rotation=None, + act_on_virtual=False): """Sets the Brownian Dynamics thermostat with required parameters 'kT' 'gamma' and optional parameter 'gamma_rotation'. From 807a8ea6068a35b6ebd724e70125d59007a65853 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 13 Jan 2019 15:27:02 +0200 Subject: [PATCH 071/150] Test refactoring --- .../python/mass-and-rinertia_per_particle.py | 142 ++++++++++-------- 1 file changed, 76 insertions(+), 66 deletions(-) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index c389fe93da9..04a11f95fb9 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -317,81 +317,91 @@ def check_dissipation(self): # Note: the decelleration test is needed for the Langevin thermostat only. Brownian thermostat is defined # over a larger time-step by its concept. - def check_dissipation_viscous_drag(self): + def check_dissipation_viscous_drag(self, n): """ Check the dissipation relations: the drag terminal velocity tests, aka the drift in case of the electrostatics + Parameters + ---------- + n : :obj:`int` + Number of particles of the each type. There are 2 types. + """ system = self.system + f = np.zeros((2 * n, 3)) + tor = np.zeros((2 * n, 3)) + dip = np.zeros((2 * n, 3)) + tmp_axis = np.zeros((2 * n, 3)) tol = 7E-3 if "EXTERNAL_FORCES" in espressomd.features(): - # Just some random forces - f0 = -1.2, 58.3578, 0.002 - f1 = -15.112, -2.0, 368.0 - system.part[0].ext_force = f0 - system.part[1].ext_force = f1 - if "ROTATION" in espressomd.features(): - # Just some random torques - tor0 = 12, 0.022, 87 - tor1 = -0.03, -174, 368 - system.part[0].ext_torque = tor0 - system.part[1].ext_torque = tor1 - # Let's set the dipole perpendicular to the torque - if "DIPOLES" in espressomd.features(): - dip0 = 0.0, tor0[2], -tor0[1] - dip1 = -tor1[2], 0.0, tor1[0] - system.part[0].dip = dip0 - system.part[1].dip = dip1 - tmp_axis0 = np.cross(tor0, dip0) / (np.linalg.norm(tor0) * np.linalg.norm(dip0)) - tmp_axis1 = np.cross(tor1, dip1) / (np.linalg.norm(tor1) * np.linalg.norm(dip1)) + for k in range(2): + for i in range(n): + ind = i + k * n + # Just some random forces + f[ind, :] = self.generate_vec_ranged_rnd(-0.5, 500.) + system.part[ind].ext_force = f[ind, :] + if "ROTATION" in espressomd.features(): + # Just some random torques + tor[ind, :] = self.generate_vec_ranged_rnd(-0.5, 500.) + system.part[ind].ext_torque = tor[ind, :] + # Let's set the dipole perpendicular to the torque + if "DIPOLES" in espressomd.features(): + # 2 types of particles correspond to 2 different + # perpendicular vectors + if ind % 2 == 0: + dip[ind, :] = 0.0, tor[ind, 2], -tor[ind, 1] + else: + dip[ind, :] = -tor[ind, 2], 0.0, tor[ind, 0] + system.part[ind].dip = dip[ind, :] + # 3rd dynamic axis + tmp_axis[ind, :] = np.cross(tor[ind, :], dip[ind, :]) \ + / (np.linalg.norm(tor[ind]) * np.linalg.norm(dip[ind])) # Small number of steps is enough for the terminal velocity within the BD by its definition. # A simulation of the original saturation of the velocity. system.integrator.run(7) system.time = 0.0 - for k in range(2): - system.part[k].pos = np.zeros((3)) - if "DIPOLES" in espressomd.features(): - system.part[0].dip = dip0 - system.part[1].dip = dip1 - for i in range(3): + for i in range(n): + for k in range(2): + ind = i + k * n + system.part[ind].pos = np.zeros((3)) + if "DIPOLES" in espressomd.features(): + system.part[ind].dip = dip[ind,:] + for step in range(3): # Small number of steps system.integrator.run(2) - for k in range(3): - # Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010) - # First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). - self.assertLess( - abs(system.part[0].v[k] - f0[k] / self.gamma_tran_p_validate[0, k]), tol) - self.assertLess( - abs(system.part[1].v[k] - f1[k] / self.gamma_tran_p_validate[1, k]), tol) - # Second (deterministic) term of the Eq. (14.39) of Schlick2010. - self.assertLess( - abs(system.part[0].pos[k] - system.time * f0[k] / self.gamma_tran_p_validate[0, k]), tol) - self.assertLess( - abs(system.part[1].pos[k] - system.time * f1[k] / self.gamma_tran_p_validate[1, k]), tol) - # Same, a rotational analogy. - if "ROTATION" in espressomd.features(): - self.assertLess(abs( - system.part[0].omega_lab[k] - tor0[k] / self.gamma_rot_p_validate[0, k]), tol) - self.assertLess(abs( - system.part[1].omega_lab[k] - tor1[k] / self.gamma_rot_p_validate[1, k]), tol) - if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): - # Same, a rotational analogy. One is implemented using a simple linear algebra; - # the polar angles with a sign control just for a correct inverse trigonometric functions application. - cos_alpha0 = np.dot(dip0, system.part[0].dip) / (np.linalg.norm(dip0) * system.part[0].dipm) - cos_alpha0_test = np.cos(system.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0]) - sgn0 = np.sign(np.dot(system.part[0].dip, tmp_axis0)) - sgn0_test = np.sign(np.sin(system.time * np.linalg.norm(tor0) / self.gamma_rot_p_validate[0, 0])) - - cos_alpha1 = np.dot(dip1, system.part[1].dip) / (np.linalg.norm(dip1) * system.part[1].dipm) - cos_alpha1_test = np.cos(system.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0]) - sgn1 = np.sign(np.dot(system.part[1].dip, tmp_axis1)) - sgn1_test = np.sign(np.sin(system.time * np.linalg.norm(tor1) / self.gamma_rot_p_validate[1, 0])) - - self.assertLess(abs(cos_alpha0 - cos_alpha0_test), tol) - self.assertLess(abs(cos_alpha1 - cos_alpha1_test), tol) - self.assertEqual(sgn0, sgn0_test) - self.assertEqual(sgn1, sgn1_test) + for k in range(2): + ind = i + k * n + for j in range(3): + # Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010) + # First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). + self.assertLess( + abs(system.part[ind].v[j] - f[ind, j] / \ + self.gamma_tran_p_validate[k, j]), tol) + # Second (deterministic) term of the Eq. (14.39) of Schlick2010. + self.assertLess( + abs(system.part[ind].pos[j] - \ + system.time * f[ind, j] / self.gamma_tran_p_validate[k, j]), tol) + # Same, a rotational analogy. + if "ROTATION" in espressomd.features(): + self.assertLess(abs( + system.part[ind].omega_lab[j] - tor[ind, j] \ + / self.gamma_rot_p_validate[k, j]), tol) + if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): + # Same, a rotational analogy. One is implemented using a simple linear algebra; + # the polar angles with a sign control just for a correct inverse trigonometric functions application. + cos_alpha = np.dot(dip[ind, :], system.part[ind].dip[:]) / \ + (np.linalg.norm(dip[ind, :]) * system.part[ind].dipm) + # Isoptropic particle for the BD. Single gamma equals to other components + cos_alpha_test = np.cos(system.time * np.linalg.norm(tor[ind, :]) / \ + self.gamma_rot_p_validate[k, 0]) + # The sign instead of sin calc additionally (equivalent approach) + sgn = np.sign(np.dot(system.part[ind].dip[:], tmp_axis[ind, :])) + sgn_test = np.sign(np.sin(system.time * np.linalg.norm(tor[ind, :]) / \ + self.gamma_rot_p_validate[k, 0])) + + self.assertLess(abs(cos_alpha - cos_alpha_test), tol) + self.assertEqual(sgn, sgn_test) def check_fluctuation_dissipation(self, n, therm_steps, loops): """ @@ -590,7 +600,7 @@ def test_case_001(self): # The test case-specific thermostat and per-particle parameters system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag(n) # Test case 0.1: no particle specific values / fluctuation & dissipation # Same particle and thermostat parameters for LD and BD are required in order @@ -655,7 +665,7 @@ def test_case_101(self): system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_gamma(n) # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag(n) # Test case 1.1: particle specific gamma but not temperature / fluctuation # & dissipation / LD and BD @@ -712,7 +722,7 @@ def test_case_201(self): system.thermostat.set_brownian(kT=self.kT, gamma=self.gamma_global) self.set_particle_specific_temperature(n) # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag(n) # Test case 2.1: particle specific temperature but not gamma / fluctuation # & dissipation / LD and BD @@ -771,7 +781,7 @@ def test_case_301(self): self.set_particle_specific_gamma(n) self.set_particle_specific_temperature(n) # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag(n) # Test case 3.1: both particle specific gamma and temperature / # fluctuation & dissipation / LD and BD @@ -833,7 +843,7 @@ def test_case_401(self): gamma=self.gamma_global, gamma_rotation=self.gamma_global_rot) # Actual integration and validation run - self.check_dissipation_viscous_drag() + self.check_dissipation_viscous_drag(n) # Test case 4.1: no particle specific values / rotational specific global # thermostat / fluctuation & dissipation / LD and BD From daefcb99eeb64cf9db5e79b16b372bff1e4a4efb Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 13 Jan 2019 15:34:04 +0200 Subject: [PATCH 072/150] Style --- .../python/mass-and-rinertia_per_particle.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index 04a11f95fb9..ac34afde131 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -339,23 +339,23 @@ def check_dissipation_viscous_drag(self, n): for i in range(n): ind = i + k * n # Just some random forces - f[ind, :] = self.generate_vec_ranged_rnd(-0.5, 500.) - system.part[ind].ext_force = f[ind, :] + f[ind,:] = self.generate_vec_ranged_rnd(-0.5, 500.) + system.part[ind].ext_force = f[ind,:] if "ROTATION" in espressomd.features(): # Just some random torques - tor[ind, :] = self.generate_vec_ranged_rnd(-0.5, 500.) - system.part[ind].ext_torque = tor[ind, :] + tor[ind,:] = self.generate_vec_ranged_rnd(-0.5, 500.) + system.part[ind].ext_torque = tor[ind,:] # Let's set the dipole perpendicular to the torque if "DIPOLES" in espressomd.features(): # 2 types of particles correspond to 2 different # perpendicular vectors if ind % 2 == 0: - dip[ind, :] = 0.0, tor[ind, 2], -tor[ind, 1] + dip[ind,:] = 0.0, tor[ind, 2], -tor[ind, 1] else: - dip[ind, :] = -tor[ind, 2], 0.0, tor[ind, 0] - system.part[ind].dip = dip[ind, :] + dip[ind,:] = -tor[ind, 2], 0.0, tor[ind, 0] + system.part[ind].dip = dip[ind,:] # 3rd dynamic axis - tmp_axis[ind, :] = np.cross(tor[ind, :], dip[ind, :]) \ + tmp_axis[ind,:] = np.cross(tor[ind,:], dip[ind,:]) \ / (np.linalg.norm(tor[ind]) * np.linalg.norm(dip[ind])) # Small number of steps is enough for the terminal velocity within the BD by its definition. # A simulation of the original saturation of the velocity. @@ -390,14 +390,14 @@ def check_dissipation_viscous_drag(self, n): if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): # Same, a rotational analogy. One is implemented using a simple linear algebra; # the polar angles with a sign control just for a correct inverse trigonometric functions application. - cos_alpha = np.dot(dip[ind, :], system.part[ind].dip[:]) / \ - (np.linalg.norm(dip[ind, :]) * system.part[ind].dipm) + cos_alpha = np.dot(dip[ind,:], system.part[ind].dip[:]) / \ + (np.linalg.norm(dip[ind,:]) * system.part[ind].dipm) # Isoptropic particle for the BD. Single gamma equals to other components - cos_alpha_test = np.cos(system.time * np.linalg.norm(tor[ind, :]) / \ + cos_alpha_test = np.cos(system.time * np.linalg.norm(tor[ind,:]) / \ self.gamma_rot_p_validate[k, 0]) # The sign instead of sin calc additionally (equivalent approach) - sgn = np.sign(np.dot(system.part[ind].dip[:], tmp_axis[ind, :])) - sgn_test = np.sign(np.sin(system.time * np.linalg.norm(tor[ind, :]) / \ + sgn = np.sign(np.dot(system.part[ind].dip[:], tmp_axis[ind,:])) + sgn_test = np.sign(np.sin(system.time * np.linalg.norm(tor[ind,:]) / \ self.gamma_rot_p_validate[k, 0])) self.assertLess(abs(cos_alpha - cos_alpha_test), tol) From fcd6ca3eea21015429090cdb99db44a463451e5e Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 13 Jan 2019 15:43:25 +0200 Subject: [PATCH 073/150] More tight tolerance --- testsuite/python/mass-and-rinertia_per_particle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index ac34afde131..28a6ab17502 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -333,7 +333,7 @@ def check_dissipation_viscous_drag(self, n): tor = np.zeros((2 * n, 3)) dip = np.zeros((2 * n, 3)) tmp_axis = np.zeros((2 * n, 3)) - tol = 7E-3 + tol = 1E-11 if "EXTERNAL_FORCES" in espressomd.features(): for k in range(2): for i in range(n): From ee03e44623bb6fa4ae7c99673c074c8df460c8f2 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 13 Jan 2019 20:41:46 +0200 Subject: [PATCH 074/150] Tune the tolerance for specific Gitlab platforms --- testsuite/python/mass-and-rinertia_per_particle.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index 28a6ab17502..501102a0c3c 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -333,7 +333,7 @@ def check_dissipation_viscous_drag(self, n): tor = np.zeros((2 * n, 3)) dip = np.zeros((2 * n, 3)) tmp_axis = np.zeros((2 * n, 3)) - tol = 1E-11 + tol = 1E-10 if "EXTERNAL_FORCES" in espressomd.features(): for k in range(2): for i in range(n): From 711e4ceec7eb8c1a715dd6443760e4d9c3c2f1d0 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Tue, 15 Jan 2019 00:37:18 +0200 Subject: [PATCH 075/150] Virtual sites propagation only for rotations --- src/core/integrate.cpp | 73 ++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 8f9538aa507..b114ea0a8a7 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -127,12 +127,16 @@ void force_and_velocity_display(); void finalize_p_inst_npt(); #ifdef BROWNIAN_DYNAMICS -/** Propagate position: random walk part.*/ +/** Propagate position: translational random walk part.*/ void bd_random_walk(Particle &p, double dt); -/** Propagate velocities: all parts.*/ -void bd_vel_steps(Particle &p, double dt); -/** Propagate positions: all parts.*/ -void bd_pos_steps(Particle &p, double dt); +/** Propagate velocities: all the translations.*/ +void bd_vel_steps_tran(Particle &p, double dt); +/** Propagate velocities: all the rotations.*/ +void bd_vel_steps_rot(Particle &p, double dt); +/** Propagate positions: all the translations.*/ +void bd_pos_steps_tran(Particle &p, double dt); +/** Propagate positions: all the rotations.*/ +void bd_pos_steps_rot(Particle &p, double dt); #endif /*@}*/ @@ -708,6 +712,9 @@ void propagate_vel() { for (auto &p : local_cells.particles()) { #ifdef ROTATION propagate_omega_quat_particle(&p); +#ifdef BROWNIAN_DYNAMICS + bd_vel_steps_rot(p, 0.5 * time_step); +#endif // BROWNIAN_DYNAMICS #endif // Don't propagate translational degrees of freedom of vs @@ -716,7 +723,7 @@ void propagate_vel() { continue; #endif #ifdef BROWNIAN_DYNAMICS - bd_vel_steps(p, 0.5 * time_step); + bd_vel_steps_tran(p, 0.5 * time_step); #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES @@ -774,12 +781,16 @@ void propagate_pos() { propagate_press_box_pos_and_rescale_npt(); else { for (auto &p : local_cells.particles()) { +#if defined(ROTATION) && defined(BROWNIAN_DYNAMICS) + bd_pos_steps_rot(p, 0.5 * time_step); +#endif +// Don't propagate translational degrees of freedom of vs #ifdef VIRTUAL_SITES if (p.p.is_virtual) continue; #endif #ifdef BROWNIAN_DYNAMICS - bd_pos_steps(p, time_step); + bd_pos_steps_tran(p, time_step); #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES @@ -820,6 +831,10 @@ void propagate_vel_pos() { for (auto &p : local_cells.particles()) { #ifdef ROTATION propagate_omega_quat_particle(&p); +#ifdef BROWNIAN_DYNAMICS + bd_vel_steps_rot(p, 0.5 * time_step); + bd_pos_steps_rot(p, time_step); +#endif // BROWNIAN_DYNAMICS #endif // Don't propagate translational degrees of freedom of vs @@ -828,8 +843,8 @@ void propagate_vel_pos() { continue; #endif #ifdef BROWNIAN_DYNAMICS - bd_vel_steps(p, 0.5 * time_step); - bd_pos_steps(p, time_step); + bd_vel_steps_tran(p, 0.5 * time_step); + bd_pos_steps_tran(p, time_step); #endif // BROWNIAN_DYNAMICS for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES @@ -1034,35 +1049,59 @@ int integrate_set_npt_isotropic(double ext_pressure, double piston, int xdir, } #ifdef BROWNIAN_DYNAMICS -/** Propagate the velocities: all parts.*/ +/** Propagate the velocities: all the translations.*/ /*********************************************************/ -/** \name bd_vel_steps */ +/** \name bd_vel_steps_tran */ /*********************************************************/ /** * @param &p Reference to the particle (Input) * @param dt Time interval (Input) */ -void bd_vel_steps(Particle &p, double dt) { +void bd_vel_steps_tran(Particle &p, double dt) { if (thermo_switch & THERMO_BROWNIAN) { bd_drag_vel(p, dt); - bd_drag_vel_rot(p, dt); bd_random_walk_vel(p, dt); + } +} +/** Propagate the velocities: all the rotations.*/ +/*********************************************************/ +/** \name bd_vel_steps_rot */ +/*********************************************************/ +/** + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_vel_steps_rot(Particle &p, double dt) { + if (thermo_switch & THERMO_BROWNIAN) { + bd_drag_vel_rot(p, dt); bd_random_walk_vel_rot(p, dt); } } -/** Propagate the positions: all parts.*/ +/** Propagate the positions: all the translations.*/ /*********************************************************/ -/** \name bd_pos_steps */ +/** \name bd_pos_steps_tran */ /*********************************************************/ /** * @param &p Reference to the particle (Input) * @param dt Time interval (Input) */ -void bd_pos_steps(Particle &p, double dt) { +void bd_pos_steps_tran(Particle &p, double dt) { if (thermo_switch & THERMO_BROWNIAN) { bd_drag(p, dt); - bd_drag_rot(p, dt); bd_random_walk(p, dt); + } +} +/** Propagate the positions: all the rotations.*/ +/*********************************************************/ +/** \name bd_pos_steps_rot */ +/*********************************************************/ +/** + * @param &p Reference to the particle (Input) + * @param dt Time interval (Input) + */ +void bd_pos_steps_rot(Particle &p, double dt) { + if (thermo_switch & THERMO_BROWNIAN) { + bd_drag_rot(p, dt); bd_random_walk_rot(p, dt); } } From 6db21f88bb46f6f16f987a4ba15b49a84e9cdfcf Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Tue, 15 Jan 2019 00:39:38 +0200 Subject: [PATCH 076/150] Formatting --- src/core/integrate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index b114ea0a8a7..a76e5e7a4f2 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -782,7 +782,7 @@ void propagate_pos() { else { for (auto &p : local_cells.particles()) { #if defined(ROTATION) && defined(BROWNIAN_DYNAMICS) - bd_pos_steps_rot(p, 0.5 * time_step); + bd_pos_steps_rot(p, 0.5 * time_step); #endif // Don't propagate translational degrees of freedom of vs #ifdef VIRTUAL_SITES From 179d80167cba814820cfb21bce42cdc17fbaeab4 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Tue, 15 Jan 2019 01:10:29 +0200 Subject: [PATCH 077/150] Virtual sites translational thermostat control --- src/core/brownian_inline.hpp | 4 ++++ src/core/integrate.cpp | 4 ++++ src/python/espressomd/thermostat.pyx | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/core/brownian_inline.hpp b/src/core/brownian_inline.hpp index 932e1e066a6..bae03725d93 100644 --- a/src/core/brownian_inline.hpp +++ b/src/core/brownian_inline.hpp @@ -107,6 +107,10 @@ inline void bd_drag_vel(Particle &p, double dt) { * @param dt Time interval (Input) */ inline void bd_random_walk_vel(Particle &p, double dt) { + // skip the translation thermalizing for virtual sites unless enabled + extern bool thermo_virtual; + if (p.p.is_virtual && !thermo_virtual ) + return; // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs // afterwards, Pottier2010 extern double brown_sigma_vel; diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index a76e5e7a4f2..03ac450b921 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1114,6 +1114,10 @@ void bd_pos_steps_rot(Particle &p, double dt) { * @param dt Time interval (Input) */ void bd_random_walk(Particle &p, double dt) { + // skip the translation thermalizing for virtual sites unless enabled + extern bool thermo_virtual; + if (p.p.is_virtual && !thermo_virtual ) + return; // Position dispersion is defined by the second eq. (14.38) of Schlick2010 // taking into account eq. (14.35). Its time interval factor will be added at // the end of this function. Its square root is the standard deviation. A diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 48b0aee0754..238a88032e6 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -585,4 +585,7 @@ cdef class Thermostat(object): global thermo_switch thermo_switch = (thermo_switch | THERMO_BROWNIAN) mpi_bcast_parameter(FIELD_THERMO_SWITCH) + global thermo_virtual + thermo_virtual = act_on_virtual + mpi_bcast_parameter(FIELD_THERMO_VIRTUAL) return True From 4b9905201681f365685c2b8c5f2e68ebf1d3b374 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Tue, 15 Jan 2019 08:27:38 +0200 Subject: [PATCH 078/150] Formatting --- src/core/brownian_inline.hpp | 2 +- src/core/integrate.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/brownian_inline.hpp b/src/core/brownian_inline.hpp index bae03725d93..80601e94a69 100644 --- a/src/core/brownian_inline.hpp +++ b/src/core/brownian_inline.hpp @@ -109,7 +109,7 @@ inline void bd_drag_vel(Particle &p, double dt) { inline void bd_random_walk_vel(Particle &p, double dt) { // skip the translation thermalizing for virtual sites unless enabled extern bool thermo_virtual; - if (p.p.is_virtual && !thermo_virtual ) + if (p.p.is_virtual && !thermo_virtual) return; // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs // afterwards, Pottier2010 diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 03ac450b921..c7ee8a974b7 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1116,7 +1116,7 @@ void bd_pos_steps_rot(Particle &p, double dt) { void bd_random_walk(Particle &p, double dt) { // skip the translation thermalizing for virtual sites unless enabled extern bool thermo_virtual; - if (p.p.is_virtual && !thermo_virtual ) + if (p.p.is_virtual && !thermo_virtual) return; // Position dispersion is defined by the second eq. (14.38) of Schlick2010 // taking into account eq. (14.35). Its time interval factor will be added at From f687f2777621f87c51a3817f62c1aaa25e31311e Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 17 Jan 2019 21:57:20 +0200 Subject: [PATCH 079/150] Perrin's rot test for BD --- .../python/rotational-diffusion-aniso.py | 118 ++++++++++++++---- 1 file changed, 93 insertions(+), 25 deletions(-) diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index b0b0d7771a1..589625c72bc 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -14,6 +14,7 @@ "Features not available, skipping test!") class RotDiffAniso(ut.TestCase): longMessage = True + round_error_prec = 1E-14 # Handle for espresso system system = espressomd.System(box_l=[1.0, 1.0, 1.0]) system.cell_system.skin = 5.0 @@ -24,20 +25,20 @@ class RotDiffAniso(ut.TestCase): gamma_global = np.zeros((3)) # Particle properties - J = 0.0, 0.0, 0.0 + J = np.zeros((3)) @classmethod def setUpClass(cls): - seed(4) + seed(42) def setUp(self): self.system.time = 0.0 self.system.part.clear() - def rot_diffusion_param_setup(self, n): + def add_particles_setup(self, n): """ - Setup the parameters for the rotational diffusion - test check_rot_diffusion(). + Adding particles according to the + previously set parameters. Parameters ---------- @@ -46,19 +47,23 @@ def rot_diffusion_param_setup(self, n): """ - # Time - # The time step should be less than t0 ~ mass / gamma - self.system.time_step = 3E-3 + for ind in range(n): + part_pos = np.random.random(3) * self.system.box_l[0] + self.system.part.add(rotation=(1, 1, 1), id=ind, rinertia=self.J, + pos=part_pos) + if "ROTATION" in espressomd.features(): + self.system.part[ind].omega_body = 0.0, 0.0, 0.0 - # Space - box = 10.0 - self.system.box_l = box, box, box - if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.system.periodicity = 0, 0, 0 + def set_anisotropic_param(self): + """ + Select parameters for anisotropic particles. + + Parameters + ---------- + + """ # NVT thermostat - # Just some temperature range to cover by the test: - self.kT = uniform(1.5, 6.5) # Note: here & hereinafter specific variations in the random parameter ranges are related to # the test execution duration to achieve the required statistical averages faster. # The friction gamma_global should be large enough in order to have the small enough D ~ kT / gamma and @@ -72,7 +77,7 @@ def rot_diffusion_param_setup(self, n): # https://doi.org/10.1007/s10955-010-0114-6 (2010)]. self.gamma_global = 1E2 * uniform(0.35, 1.05, (3)) - # Particles + # Particles' properties # As far as the problem characteristic time is t0 ~ J / gamma # and the Langevin equation finite-difference approximation is stable # only for time_step << t0, it is needed to set the moment of inertia higher than @@ -82,12 +87,47 @@ def rot_diffusion_param_setup(self, n): # too much of the CPU time: the in silico time should clock over the # t0. self.J = uniform(1.5, 16.5, (3)) - for ind in range(n): - part_pos = np.random.random(3) * box - self.system.part.add(rotation=(1, 1, 1), id=ind, rinertia=self.J, - pos=part_pos) - if "ROTATION" in espressomd.features(): - self.system.part[ind].omega_body = 0.0, 0.0, 0.0 + + def set_isotropic_param(self): + """ + Select parameters for isotropic particles. + + Parameters + ---------- + + """ + + # NVT thermostat + # see the comments in set_anisotropic_param() + self.gamma_global[0] = 1E2 * uniform(0.35, 1.05, (1)) + self.gamma_global[1] = self.gamma_global[0] + self.gamma_global[2] = self.gamma_global[0] + # Particles' properties + # see the comments in set_anisotropic_param() + self.J[0] = uniform(1.5, 16.5, (1)) + self.J[1] = self.J[0] + self.J[2] = self.J[0] + + def rot_diffusion_param_setup(self): + """ + Setup the parameters for the rotational diffusion + test check_rot_diffusion(). + + """ + + # Time + # The time step should be less than t0 ~ mass / gamma + self.system.time_step = 3E-3 + + # Space + box = 10.0 + self.system.box_l = box, box, box + if espressomd.has_features(("PARTIAL_PERIODIC",)): + self.system.periodicity = 0, 0, 0 + + # NVT thermostat + # Just some temperature range to cover by the test: + self.kT = uniform(1.5, 6.5) def check_rot_diffusion(self, n): """ @@ -104,7 +144,7 @@ def check_rot_diffusion(self, n): """ # Global diffusivity tensor in the body frame: D = self.kT / self.gamma_global - dt0 = self.J / self.gamma_global + #dt0 = self.J / self.gamma_global # Thermalizing... therm_steps = 100 @@ -174,7 +214,7 @@ def check_rot_diffusion(self, n): # Actual comparison. - tolerance = 0.195 + tolerance = 0.15 # Too small values of the direction cosines are out of interest # compare to 0..1 range. min_value = 0.14 @@ -231,6 +271,9 @@ def check_rot_diffusion(self, n): if i != j: D1D1 += D[i] * D[j] D1D1 /= 6.0 + # Technical workaround of a digital arithmetic issue for isotropic particle + if np.absolute((D0**2 - D1D1)/(D0**2 + D1D1)) < self.round_error_prec: + D1D1 *= (1.0 - 2.0 * self.round_error_prec) # Eq. (32) [Perrin1936]. dcosjj2_validate = 1. / 3. + (1. / 3.) * (1. + (D - D0) / (2. * np.sqrt(D0**2 - D1D1))) \ * np.exp(-6. * (D0 - np.sqrt(D0**2 - D1D1)) * self.system.time) \ @@ -303,14 +346,39 @@ def check_rot_diffusion(self, n): msg='Relative deviation dcosij2_dev[{0},{1}] in a rotational diffusion is too large: {2}'.format( i, j, dcosij2_dev[i, j])) + # Langevin Dynamics / Anisotropic def test_case_00(self): n = 800 - self.rot_diffusion_param_setup(n) + self.rot_diffusion_param_setup() + self.set_anisotropic_param() + self.add_particles_setup(n) + self.system.thermostat.set_langevin( + kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_rot_diffusion(n) + + # Langevin Dynamics / Isotropic + def test_case_01(self): + n = 800 + self.rot_diffusion_param_setup() + self.set_isotropic_param() + self.add_particles_setup(n) self.system.thermostat.set_langevin( kT=self.kT, gamma=self.gamma_global) # Actual integration and validation run self.check_rot_diffusion(n) + # Brownian Dynamics / Isotropic + def test_case_10(self): + n = 800 + self.rot_diffusion_param_setup() + self.set_isotropic_param() + self.add_particles_setup(n) + self.system.thermostat.turn_off() + self.system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global) + # Actual integration and validation run + self.check_rot_diffusion(n) if __name__ == '__main__': ut.main() From cc43e1a91ba7b7c46a5d2f7ab69ad1195ffa6b6a Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Fri, 18 Jan 2019 00:31:17 +0200 Subject: [PATCH 080/150] Formatting --- testsuite/python/rotational-diffusion-aniso.py | 5 +++-- testsuite/python/rotational_inertia.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index 589625c72bc..f2915274b1a 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -271,8 +271,9 @@ def check_rot_diffusion(self, n): if i != j: D1D1 += D[i] * D[j] D1D1 /= 6.0 - # Technical workaround of a digital arithmetic issue for isotropic particle - if np.absolute((D0**2 - D1D1)/(D0**2 + D1D1)) < self.round_error_prec: + # Technical workaround of a digital arithmetic issue for isotropic + # particle + if np.absolute((D0**2 - D1D1) / (D0**2 + D1D1)) < self.round_error_prec: D1D1 *= (1.0 - 2.0 * self.round_error_prec) # Eq. (32) [Perrin1936]. dcosjj2_validate = 1. / 3. + (1. / 3.) * (1. + (D - D0) / (2. * np.sqrt(D0**2 - D1D1))) \ diff --git a/testsuite/python/rotational_inertia.py b/testsuite/python/rotational_inertia.py index 066bb13f6ba..9cb4a3c8404 100644 --- a/testsuite/python/rotational_inertia.py +++ b/testsuite/python/rotational_inertia.py @@ -42,11 +42,13 @@ def L_body(self, part): # Set the angular momentum def set_L_0(self, part): L_0_body = self.L_body(part) - self.L_0_lab = tests_common.convert_vec_body_to_space(self.system, part, L_0_body) + self.L_0_lab = tests_common.convert_vec_body_to_space( + self.system, part, L_0_body) def set_L(self, part): L_body = self.L_body(part) - self.L_lab = tests_common.convert_vec_body_to_space(self.system, part, L_body) + self.L_lab = tests_common.convert_vec_body_to_space( + self.system, part, L_body) def test_stability(self): self.system.part.clear() From 109627d2876e0d9a3c6f86973d5ab577886dcee8 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 20 Jan 2019 14:27:59 +0200 Subject: [PATCH 081/150] Parameters for multi-core stable run / refactoring --- .../python/mass-and-rinertia_per_particle.py | 102 ++++++++++++------ 1 file changed, 71 insertions(+), 31 deletions(-) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index 501102a0c3c..2b3580c6754 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -31,7 +31,7 @@ class ThermoTest(ut.TestCase): longMessage = True # Handle for espresso system system = espressomd.System(box_l=[1.0, 1.0, 1.0]) - system.seed = system.cell_system.get_state()['n_nodes'] * [1234] + system.seed = [s * 15 for s in range(system.cell_system.get_state()["n_nodes"])] system.cell_system.skin = 5.0 # The NVT thermostat parameters @@ -63,7 +63,7 @@ class ThermoTest(ut.TestCase): @classmethod def setUpClass(cls): - np.random.seed(15) + np.random.seed(20) def setUp(self): self.system.time = 0.0 @@ -183,17 +183,15 @@ def dissipation_param_setup(self): # or both translational and rotational ones. # Otherwise these types of motion will interfere. # ..Let's test both cases depending on the particle index. - self.gamma_tran_p[0, 0] = self.generate_scalar_ranged_rnd(0.5, 1.0) - self.gamma_tran_p[0, 1] = self.gamma_tran_p[0, 0] - self.gamma_tran_p[0, 2] = self.gamma_tran_p[0, 0] + for k in range(2): + gamma_rnd = self.generate_scalar_ranged_rnd(0.5, 1.0) + for j in range(3): + self.gamma_tran_p[k, j] = gamma_rnd self.gamma_rot_p[0,:] = self.generate_vec_ranged_rnd(0.5, 2.0 / 3.0) - self.gamma_tran_p[1, 0] = self.generate_scalar_ranged_rnd(0.5, 1.0) - self.gamma_tran_p[1, 1] = self.gamma_tran_p[1, 0] - self.gamma_tran_p[1, 2] = self.gamma_tran_p[1, 0] - self.gamma_rot_p[1, 0] = self.generate_scalar_ranged_rnd( + gamma_rnd = self.generate_scalar_ranged_rnd( 0.5, 2.0 / 3.0) - self.gamma_rot_p[1, 1] = self.gamma_rot_p[1, 0] - self.gamma_rot_p[1, 2] = self.gamma_rot_p[1, 0] + for j in range(3): + self.gamma_rot_p[1, j] = gamma_rnd # Particles self.mass = 12.74 @@ -213,19 +211,62 @@ def dissipation_viscous_drag_setup_bd(self): It is used by the BD test cases only for the moment. """ + + system = self.system ## Time # Large time_step is OK for the BD by its definition & its benefits self.system.time_step = 17.0 - ## NVT thermostat - # Isotropic reassignment is required here for the drag tests - self.gamma_global_rot = np.zeros((3)) - self.gamma_global_rot[0] = (0.5 + np.random.random()) * 2.0 / 3.0 - self.gamma_global_rot[1] = self.gamma_global_rot[0] - self.gamma_global_rot[2] = self.gamma_global_rot[0] + + # Space + # A large box is reuired due to huge steps over the space: + # large time_step is natural for the BD. + box = 1.0E4 + self.system.box_l = box, box, box + if espressomd.has_features(("PARTIAL_PERIODIC",)): + self.system.periodicity = 0, 0, 0 + + # NVT thermostat + self.kT = 0.0 + # The translational gamma isotropy is required here. + # Global gamma for tests without particle-specific gammas. + # + # As far as the problem characteristic time is t0 ~ mass / gamma + # and the Langevin equation finite-difference approximation is stable + # only for time_step << t0, it is needed to set the gamma less than + # some maximal value according to the value max_gamma_param. + # Also, it cannot be very small (min_gamma_param), otherwise the thermalization will require + # too much of the CPU time. Same: for all such gamma assignments throughout the test. + # + min_gamma_param = 0.5 + max_gamma_param = 2.0 / 3.0 + gamma_rnd = self.generate_scalar_ranged_rnd( + min_gamma_param, max_gamma_param) + self.gamma_global = gamma_rnd, gamma_rnd, gamma_rnd + # Additional test case for the specific global rotational gamma set. + gamma_rnd = self.generate_scalar_ranged_rnd( + min_gamma_param, max_gamma_param) + self.gamma_global_rot = gamma_rnd, gamma_rnd, gamma_rnd + # Per-paricle values: + self.kT_p = 0.0, 0.0 # Isotropy is required here for the drag tests - self.gamma_rot_p[0, 0] = self.generate_scalar_ranged_rnd(0.5, 2.0/3.0) - self.gamma_rot_p[0, 1] = self.gamma_rot_p[0, 0] - self.gamma_rot_p[0, 2] = self.gamma_rot_p[0, 0] + for k in range(2): + gamma_rnd_tran = self.generate_scalar_ranged_rnd(0.5, 1.0) + gamma_rnd_rot = self.generate_scalar_ranged_rnd( + 0.5, 2.0 / 3.0) + for j in range(3): + self.gamma_tran_p[k, j] = gamma_rnd_tran + self.gamma_rot_p[k, j] = gamma_rnd_rot + + # Particles + self.mass = 12.74 + self.J = 10.0, 10.0, 10.0 + for i in range(2): + system.part.add(rotation=(1, 1, 1), pos=(0.0, 0.0, 0.0), id=i) + system.part[i].v = 0.0, 0.0, 0.0 + if "ROTATION" in espressomd.features(): + system.part[i].omega_body = 0.0, 0.0, 0.0 + system.part[i].mass = self.mass + system.part[i].rinertia = self.J def fluctuation_dissipation_param_setup(self, n): """ @@ -242,7 +283,11 @@ def fluctuation_dissipation_param_setup(self, n): self.system.time_step = 0.03 # Space - box = 10.0 + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # for large steps and multi-core run stability + box = 1E2 + else: + box = 10.0 self.system.box_l = box, box, box if espressomd.has_features(("PARTIAL_PERIODIC",)): self.system.periodicity = 0, 0, 0 @@ -594,7 +639,6 @@ def test_case_001(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 - self.dissipation_param_setup() self.dissipation_viscous_drag_setup_bd() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters @@ -623,7 +667,7 @@ def test_case_01(self): if "BROWNIAN_DYNAMICS" in espressomd.features(): self.set_initial_cond() # Large time-step is OK for BD. - system.time_step = 42 + system.time_step = 10.0 # Less number of loops are needed in case of BD because the velocity # distribution is already as required. It is not a result of a real dynamics. loops = 8 @@ -658,7 +702,6 @@ def test_case_101(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 - self.dissipation_param_setup() self.dissipation_viscous_drag_setup_bd() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters @@ -685,7 +728,7 @@ def test_case_11(self): self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): self.set_initial_cond() - system.time_step = 42 + system.time_step = 10.0 loops = 8 therm_steps = 2 # The test case-specific thermostat @@ -715,7 +758,6 @@ def test_case_201(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 - self.dissipation_param_setup() self.dissipation_viscous_drag_setup_bd() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters @@ -742,7 +784,7 @@ def test_case_21(self): self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): self.set_initial_cond() - system.time_step = 42 + system.time_step = 10.0 loops = 8 therm_steps = 2 # The test case-specific thermostat and per-particle parameters @@ -773,7 +815,6 @@ def test_case_301(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 - self.dissipation_param_setup() self.dissipation_viscous_drag_setup_bd() self.set_langevin_global_defaults() # The test case-specific thermostat and per-particle parameters @@ -802,7 +843,7 @@ def test_case_31(self): self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): self.set_initial_cond() - system.time_step = 42 + system.time_step = 10.0 loops = 8 therm_steps = 2 # The test case-specific thermostat @@ -834,7 +875,6 @@ def test_case_401(self): system = self.system # Each of 2 kind of particles will be represented by n instances: n = 1 - self.dissipation_param_setup() self.dissipation_viscous_drag_setup_bd() self.set_langevin_global_defaults_rot_differ() # The test case-specific thermostat and per-particle parameters @@ -865,7 +905,7 @@ def test_case_41(self): self.check_fluctuation_dissipation(n, therm_steps, loops) if "BROWNIAN_DYNAMICS" in espressomd.features(): self.set_initial_cond() - system.time_step = 42 + system.time_step = 10.0 loops = 8 therm_steps = 2 # The test case-specific thermostat From fbc00a825b5bffd272a79b775c6a9087ebf9efc6 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sun, 20 Jan 2019 23:54:19 +0200 Subject: [PATCH 082/150] Making the algorithm to be independ on an order of the rotations --- src/core/rotation.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 8fda67c6dc6..3925402a384 100644 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -646,9 +646,17 @@ void bd_random_walk_rot(Particle &p, double dt) { #endif // ROTATIONAL_INERTIA } } - rotation_fix(p, dphi); + /*rotation_fix(p, dphi); for (int j = 0; j < 3; j++) { rotate_particle_body_j(p, j, dphi[j]); + }*/ + rotation_fix(p, dphi); + // making the algorithm to be independ on an order of the rotations + double dphi_m = dphi.norm(); + if (dphi_m) { + Vector3d dphi_u; + dphi_u = dphi / dphi_m; + local_rotate_particle_body(p, dphi_u, dphi_m); } } From d22265bd50226618afa01a7595c177ae672481c4 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 6 Jun 2019 22:17:30 +0300 Subject: [PATCH 083/150] documentation rules fixing --- src/core/thermostat.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 85678a39727..ac3785f4043 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -193,7 +193,7 @@ inline Utils::Vector3d v_noise(int particle_id, RNGSalt salt) { * The standard deviation = 1.0. * * @param particle_id Particle ID (decorrelates particles) - * @param the salt (decorrelates different thermostat types) + * @param salt (decorrelates different thermostat types) * * @return 3D vector of Gaussian random numbers. * @@ -229,7 +229,7 @@ inline Utils::Vector3d v_noise_g(int particle_id, RNGSalt salt) { * to have the unitary standard deviation. * * @param particle_id Particle ID (decorrelates particles) - * @param the salt (decorrelates different thermostat types) + * @param salt (decorrelates different thermostat types) * * @return 3D vector of Gaussian random numbers. * From 4eacd66b5372a474be89d090c4cb71addb7dd4aa Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 6 Jun 2019 22:18:43 +0300 Subject: [PATCH 084/150] technical revert --- src/core/thermostat.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index ac3785f4043..85678a39727 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -193,7 +193,7 @@ inline Utils::Vector3d v_noise(int particle_id, RNGSalt salt) { * The standard deviation = 1.0. * * @param particle_id Particle ID (decorrelates particles) - * @param salt (decorrelates different thermostat types) + * @param the salt (decorrelates different thermostat types) * * @return 3D vector of Gaussian random numbers. * @@ -229,7 +229,7 @@ inline Utils::Vector3d v_noise_g(int particle_id, RNGSalt salt) { * to have the unitary standard deviation. * * @param particle_id Particle ID (decorrelates particles) - * @param salt (decorrelates different thermostat types) + * @param the salt (decorrelates different thermostat types) * * @return 3D vector of Gaussian random numbers. * From e7ce993a2876c7e296245c86c4bffe1689257078 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 6 Jun 2019 22:19:38 +0300 Subject: [PATCH 085/150] style --- src/core/integrate.cpp | 17 +++++++-------- src/core/random.hpp | 21 +++++++++---------- src/core/rotation.cpp | 31 +++++++++++++++------------- src/core/thermostat.cpp | 3 +-- src/core/thermostat.hpp | 19 ++++++++--------- src/python/espressomd/thermostat.pyx | 13 +++++++----- 6 files changed, 53 insertions(+), 51 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 8ed085f3218..4ab97221eb6 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -59,8 +59,8 @@ #include "brownian_inline.hpp" #include -#include #include +#include #include #include @@ -659,12 +659,12 @@ void propagate_vel() { } else #endif #ifdef BROWNIAN_DYNAMICS - if (!(thermo_switch & THERMO_BROWNIAN)) + if (!(thermo_switch & THERMO_BROWNIAN)) #endif // BROWNIAN_DYNAMICS - { + { /* Propagate velocities: v(t+0.5*dt) = v(t) + 0.5*dt * a(t) */ - p.m.v[j] += 0.5 * time_step * p.f.f[j] / p.p.mass; - } + p.m.v[j] += 0.5 * time_step * p.f.f[j] / p.p.mass; + } } ONEPART_TRACE(if (p.p.identity == check_id) fprintf( @@ -1094,15 +1094,14 @@ void bd_random_walk(Particle &p, double dt) { #ifndef PARTICLE_ANISOTROPY if (brown_sigma_pos_temp_inv > 0.0) { delta_pos_body[j] = - (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * - noise[j]; + (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } #else if (brown_sigma_pos_temp_inv[j] > 0.0) { - delta_pos_body[j] = (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * - noise[j]; + delta_pos_body[j] = + (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } diff --git a/src/core/random.hpp b/src/core/random.hpp index 87989e1b08b..7786a0a88eb 100644 --- a/src/core/random.hpp +++ b/src/core/random.hpp @@ -165,7 +165,7 @@ inline double gaussian_random_cut() { } /** @brief Generator for Gaussian random numbers. - * + * * Uses the Box-Muller * transformation to generate two Gaussian random numbers from two * uniform random numbers. @@ -173,11 +173,12 @@ inline double gaussian_random_cut() { * @param d1 decorrelated uniform random from (0..1). * @param d2 decorrelated uniform random from (0..1). * @param &repeat_flag whether we need to calc new rnd numbers. - * + * * @return Gaussian random number. * */ -inline double gaussian_random_box_muller(double d1, double d2, int &repeat_flag) { +inline double gaussian_random_box_muller(double d1, double d2, + int &repeat_flag) { double x1, x2, r2, fac; static int calc_new = 1; static double save; @@ -190,9 +191,9 @@ inline double gaussian_random_box_muller(double d1, double d2, int &repeat_flag) if (calc_new) { /* draw two uniform random numbers in the unit circle */ - x1 = 2.0*d1; - x2 = 2.0*d2; - r2 = x1*x1 + x2*x2; + x1 = 2.0 * d1; + x2 = 2.0 * d2; + r2 = x1 * x1 + x2 * x2; if ((r2 >= 1.0) || (r2 == 0.0)) { repeat_flag = 1; return NAN; // actually, no numbers @@ -200,14 +201,14 @@ inline double gaussian_random_box_muller(double d1, double d2, int &repeat_flag) repeat_flag = 0; /* perform Box-Muller transformation */ - fac = sqrt(-2.0*log(r2)/r2); + fac = sqrt(-2.0 * log(r2) / r2); /* save one number for later use */ - save = x1*fac; + save = x1 * fac; calc_new = 0; /* return the second number */ - return x2*fac; + return x2 * fac; } } else { @@ -217,9 +218,7 @@ inline double gaussian_random_box_muller(double d1, double d2, int &repeat_flag) /* return the stored gaussian random number */ return save; - } - } #endif diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index bab0d4de725..91eff06f74c 100644 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -53,8 +53,8 @@ #include "particle_data.hpp" #include "thermostat.hpp" -#include #include +#include #include #include @@ -345,8 +345,10 @@ void convert_torques_propagate_omega() { #endif // BROWNIAN_DYNAMICS { ONEPART_TRACE(if (p.p.identity == check_id) fprintf( - stderr, "%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n", - this_node, p.f.f[0], p.f.f[1], p.f.f[2], p.m.v[0], p.m.v[1], p.m.v[2])); + stderr, + "%d: OPT: SCAL f = (%.3e,%.3e,%.3e) v_old = (%.3e,%.3e,%.3e)\n", + this_node, p.f.f[0], p.f.f[1], p.f.f[2], p.m.v[0], p.m.v[1], + p.m.v[2])); // Propagation of angular velocities p.m.omega[0] += time_step_half * p.f.torque[0] / p.p.rinertia[0]; @@ -367,9 +369,12 @@ void convert_torques_propagate_omega() { for (int times = 0; times <= 5; times++) { Utils::Vector3d Wd; - Wd[0] = p.m.omega[1] * p.m.omega[2] * rinertia_diff_12 / p.p.rinertia[0]; - Wd[1] = p.m.omega[2] * p.m.omega[0] * rinertia_diff_20 / p.p.rinertia[1]; - Wd[2] = p.m.omega[0] * p.m.omega[1] * rinertia_diff_01 / p.p.rinertia[2]; + Wd[0] = + p.m.omega[1] * p.m.omega[2] * rinertia_diff_12 / p.p.rinertia[0]; + Wd[1] = + p.m.omega[2] * p.m.omega[0] * rinertia_diff_20 / p.p.rinertia[1]; + Wd[2] = + p.m.omega[0] * p.m.omega[1] * rinertia_diff_01 / p.p.rinertia[2]; p.m.omega = omega_0 + time_step_half * Wd; } @@ -430,8 +435,9 @@ void rotation_fix(Particle &p, Utils::Vector3d &rot_vector) { /** Rotate the particle p around the body-frame defined NORMALIZED axis * aBodyFrame by amount phi */ -void local_rotate_particle_body(Particle &p, const Utils::Vector3d &axis_body_frame, - const double phi) { +void local_rotate_particle_body(Particle &p, + const Utils::Vector3d &axis_body_frame, + const double phi) { Utils::Vector3d axis = axis_body_frame; // Rotation turned off entirely? @@ -619,15 +625,13 @@ void bd_random_walk_rot(Particle &p, double dt) { { #ifndef PARTICLE_ANISOTROPY if (brown_sigma_pos_temp_inv > 0.0) { - dphi[j] = - noise[j] * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); + dphi[j] = noise[j] * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); } else { dphi[j] = 0.0; } #else if (brown_sigma_pos_temp_inv[j] > 0.0) { - dphi[j] = noise[j] * (1.0 / brown_sigma_pos_temp_inv[j]) * - sqrt(dt); + dphi[j] = noise[j] * (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); } else { dphi[j] = 0.0; } @@ -678,8 +682,7 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { { // velocity is added here. It is already initialized in the terminal drag // part. - domega[j] = - brown_sigma_vel_temp * noise[j] / sqrt(p.p.rinertia[j]); + domega[j] = brown_sigma_vel_temp * noise[j] / sqrt(p.p.rinertia[j]); } } rotation_fix(p, domega); diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 905cb26bea9..1dcbcedf9a3 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -103,8 +103,7 @@ void mpi_bcast_langevin_rng_counter(const uint64_t counter) { } void langevin_rng_counter_increment() { - if (thermo_switch & - (THERMO_LANGEVIN | THERMO_BROWNIAN)) + if (thermo_switch & (THERMO_LANGEVIN | THERMO_BROWNIAN)) langevin_rng_counter->increment(); } diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 85678a39727..ef57238d62d 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -173,8 +173,7 @@ inline Utils::Vector3d v_noise(int particle_id, RNGSalt salt) { using ctr_type = rng_type::ctr_type; using key_type = rng_type::key_type; - ctr_type c{{langevin_rng_counter->value(), - static_cast(salt)}}; + ctr_type c{{langevin_rng_counter->value(), static_cast(salt)}}; key_type k{{static_cast(particle_id)}}; @@ -187,14 +186,14 @@ inline Utils::Vector3d v_noise(int particle_id, RNGSalt salt) { } /** @brief Generator for Gaussian random 3d vector. - * + * * Box-Muller transformation uses two * uniform random numbers from the philox thermostat. * The standard deviation = 1.0. * * @param particle_id Particle ID (decorrelates particles) * @param the salt (decorrelates different thermostat types) - * + * * @return 3D vector of Gaussian random numbers. * */ @@ -202,7 +201,7 @@ inline Utils::Vector3d v_noise_g(int particle_id, RNGSalt salt) { Utils::Vector3d v_noise_gaussian = {NAN, NAN, NAN}; - for (int j=0; j < 3; j++) { + for (int j = 0; j < 3; j++) { int repeat_flag = 1; double s_noise_val = NAN; // scalar (component) noise value while (repeat_flag) /*means NAN*/ { @@ -211,8 +210,7 @@ inline Utils::Vector3d v_noise_g(int particle_id, RNGSalt salt) { Utils::Vector3d v_noise_val = v_noise(particle_id, salt); // .. and we use these doubles by the box-muller // Gaussian number generator - s_noise_val = gaussian_random_box_muller(v_noise_val[0], - v_noise_val[1], + s_noise_val = gaussian_random_box_muller(v_noise_val[0], v_noise_val[1], repeat_flag); // brownian thermostat uses Langevin counter / // philox RNG as well @@ -230,13 +228,14 @@ inline Utils::Vector3d v_noise_g(int particle_id, RNGSalt salt) { * * @param particle_id Particle ID (decorrelates particles) * @param the salt (decorrelates different thermostat types) - * + * * @return 3D vector of Gaussian random numbers. * */ inline Utils::Vector3d v_noise_gcut(int particle_id, RNGSalt salt) { - Utils::Vector3d v_noise_gaussian_cut = {NAN, NAN, NAN};; + Utils::Vector3d v_noise_gaussian_cut = {NAN, NAN, NAN}; + ; // a result of the probability distribution integral // (inculding the Dirac deltas at the cut points +-2*renorm_coef @@ -245,7 +244,7 @@ inline Utils::Vector3d v_noise_gcut(int particle_id, RNGSalt salt) { double coef = 1.042267973; const Utils::Vector3d random_vector = coef * v_noise_g(particle_id, salt); - for (int j=0; j < 3; j++) { + for (int j = 0; j < 3; j++) { if (fabs(random_vector[j]) > 2 * coef) { if (random_vector[j] > 0) { v_noise_gaussian_cut[j] = 2 * coef; diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 45497bc5a7a..c3cd3471d2b 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -110,7 +110,7 @@ cdef class Thermostat(object): IF BROWNIAN_DYNAMICS: if thmst["type"] == "BROWNIAN": self.set_brownian(kT=thmst["kT"], gamma=thmst[ - "gamma"], gamma_rotation=thmst["gamma_rotation"],act_on_virtual=thmst["act_on_virtual"], seed=thmst["seed"]) + "gamma"], gamma_rotation=thmst["gamma_rotation"], act_on_virtual=thmst["act_on_virtual"], seed=thmst["seed"]) def get_ts(self): return thermo_switch @@ -160,9 +160,11 @@ cdef class Thermostat(object): lang_dict["gamma"] = langevin_gamma IF ROTATION: IF PARTICLE_ANISOTROPY: - lang_dict["gamma_rotation"] = [langevin_gamma_rotation[0], - langevin_gamma_rotation[1], - langevin_gamma_rotation[2]] + lang_dict[ + "gamma_rotation"] = [langevin_gamma_rotation[0], + langevin_gamma_rotation[ + 1], + langevin_gamma_rotation[2]] ELSE: lang_dict["gamma_rotation"] = langevin_gamma_rotation ELSE: @@ -512,7 +514,8 @@ cdef class Thermostat(object): self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) global thermo_switch - # this is safe because this combination of thermostats is not allowed + # this is safe because this combination of thermostats is not + # allowed thermo_switch = (thermo_switch & (~THERMO_LANGEVIN)) thermo_switch = (thermo_switch | THERMO_BROWNIAN) mpi_bcast_parameter(FIELD_THERMO_SWITCH) From 5d1c93e439d4c75bd8757aa6c2989b7828f19b1a Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 6 Jun 2019 22:20:53 +0300 Subject: [PATCH 086/150] documentation rules fixing --- src/core/thermostat.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index ef57238d62d..fa474dc1f60 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -192,7 +192,7 @@ inline Utils::Vector3d v_noise(int particle_id, RNGSalt salt) { * The standard deviation = 1.0. * * @param particle_id Particle ID (decorrelates particles) - * @param the salt (decorrelates different thermostat types) + * @param salt (decorrelates different thermostat types) * * @return 3D vector of Gaussian random numbers. * @@ -227,7 +227,7 @@ inline Utils::Vector3d v_noise_g(int particle_id, RNGSalt salt) { * to have the unitary standard deviation. * * @param particle_id Particle ID (decorrelates particles) - * @param the salt (decorrelates different thermostat types) + * @param salt (decorrelates different thermostat types) * * @return 3D vector of Gaussian random numbers. * From 6e4f4c5198948130643dcbd3d510394b4fa29f92 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 6 Jun 2019 22:56:41 +0300 Subject: [PATCH 087/150] clang build fix --- src/core/random.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/random.hpp b/src/core/random.hpp index 7786a0a88eb..87d26dff405 100644 --- a/src/core/random.hpp +++ b/src/core/random.hpp @@ -182,6 +182,7 @@ inline double gaussian_random_box_muller(double d1, double d2, double x1, x2, r2, fac; static int calc_new = 1; static double save; + double res = NAN; /* On every second call two gaussian random numbers are calculated via the Box-Muller transformation. One is returned as the result @@ -196,7 +197,7 @@ inline double gaussian_random_box_muller(double d1, double d2, r2 = x1 * x1 + x2 * x2; if ((r2 >= 1.0) || (r2 == 0.0)) { repeat_flag = 1; - return NAN; // actually, no numbers + res = NAN; // actually, no numbers } else { repeat_flag = 0; @@ -208,7 +209,7 @@ inline double gaussian_random_box_muller(double d1, double d2, calc_new = 0; /* return the second number */ - return x2 * fac; + res = x2 * fac; } } else { @@ -217,8 +218,10 @@ inline double gaussian_random_box_muller(double d1, double d2, calc_new = 1; /* return the stored gaussian random number */ - return save; + res = save; } + + return res; } #endif From 04c7550be703ee4714feb601329f04c66905283b Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 6 Jun 2019 22:56:50 +0300 Subject: [PATCH 088/150] default build fix --- .../python/rotational-diffusion-aniso.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index 5927bebbb48..7cded141bdf 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -369,17 +369,18 @@ def test_case_01(self): # Actual integration and validation run self.check_rot_diffusion(n) - # Brownian Dynamics / Isotropic - def test_case_10(self): - n = 800 - self.system.thermostat.turn_off() - self.rot_diffusion_param_setup() - self.set_isotropic_param() - self.add_particles_setup(n) - self.system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - # Actual integration and validation run - self.check_rot_diffusion(n) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Brownian Dynamics / Isotropic + def test_case_10(self): + n = 800 + self.system.thermostat.turn_off() + self.rot_diffusion_param_setup() + self.set_isotropic_param() + self.add_particles_setup(n) + self.system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + # Actual integration and validation run + self.check_rot_diffusion(n) if __name__ == '__main__': ut.main() From 8357b86424e4a69f96e938009d0040a7fbfeef3c Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Thu, 6 Jun 2019 23:23:37 +0300 Subject: [PATCH 089/150] clang build fix --- src/core/brownian_inline.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/brownian_inline.hpp b/src/core/brownian_inline.hpp index 7aae7b610ab..a7a52ded17a 100644 --- a/src/core/brownian_inline.hpp +++ b/src/core/brownian_inline.hpp @@ -115,7 +115,7 @@ inline void bd_random_walk_vel(Particle &p, double dt) { // afterwards, Pottier2010 extern double brown_sigma_vel; // first, set defaults - double brown_sigma_vel_temp = brown_sigma_vel; + double brown_sigma_vel_temp; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE From 9b98323d08c3e2214d4c2c2df820840068136506 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Fri, 7 Jun 2019 00:00:31 +0300 Subject: [PATCH 090/150] clang build fixes --- src/core/integrate.cpp | 2 +- src/core/rotation.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 4ab97221eb6..52556d980d5 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -1029,7 +1029,7 @@ void bd_random_walk(Particle &p, double dt) { // Just a NAN setter, technical variable: extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults - Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_inv; + Thermostat::GammaType brown_sigma_pos_temp_inv; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE diff --git a/src/core/rotation.cpp b/src/core/rotation.cpp index 91eff06f74c..eb9db6bda03 100644 --- a/src/core/rotation.cpp +++ b/src/core/rotation.cpp @@ -574,7 +574,7 @@ void bd_random_walk_rot(Particle &p, double dt) { extern Thermostat::GammaType brown_sigma_pos_rotation_inv; extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults - Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; + Thermostat::GammaType brown_sigma_pos_temp_inv; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -660,7 +660,7 @@ void bd_random_walk_rot(Particle &p, double dt) { void bd_random_walk_vel_rot(Particle &p, double dt) { extern double brown_sigma_vel_rotation; // first, set defaults - double brown_sigma_vel_temp = brown_sigma_vel_rotation; + double brown_sigma_vel_temp; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE From c3fdb00fd5dc88a7c29d6314046d08d477bf03aa Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Fri, 2 Aug 2019 17:26:29 +0200 Subject: [PATCH 091/150] Merge regression and accuracy in testsuite --- testsuite/python/langevin_thermostat.py | 2 +- testsuite/python/mass-and-rinertia_per_particle.py | 3 +-- testsuite/python/rotational-diffusion-aniso.py | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/testsuite/python/langevin_thermostat.py b/testsuite/python/langevin_thermostat.py index f536319302c..b82e283548c 100644 --- a/testsuite/python/langevin_thermostat.py +++ b/testsuite/python/langevin_thermostat.py @@ -216,7 +216,7 @@ def test_03__friction_rot(self): def test_04__global_langevin(self): """Test for global Langevin parameters.""" - N = 200 + N = 400 system = self.system system.part.clear() system.time_step = 0.06 diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index fd813420cac..36c395d6bf3 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -200,8 +200,7 @@ def dissipation_viscous_drag_setup_bd(self): # large time_step is natural for the BD. box = 1.0E4 self.system.box_l = box, box, box - if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.system.periodicity = 0, 0, 0 + self.system.periodicity = 0, 0, 0 # NVT thermostat self.kT = 0.0 diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index 88ead1be32b..b0798ceb9d2 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -135,8 +135,7 @@ def rot_diffusion_param_setup(self): # Space self.box = 10.0 self.system.box_l = 3 * [self.box] - if espressomd.has_features(("PARTIAL_PERIODIC",)): - self.system.periodicity = [0, 0, 0] + self.system.periodicity = [0, 0, 0] # NVT thermostat # Just some temperature range to cover by the test: From a98f39246b25da7a8dbc18e75203c45cb258bd40 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Fri, 2 Aug 2019 17:34:05 +0200 Subject: [PATCH 092/150] Formatting --- src/core/thermostat.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 7fb023d32fa..93029982d7d 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -326,8 +326,8 @@ inline Utils::Vector3d friction_thermo_langevin(const Particle *p) { hadamard_product(langevin_pref_friction_buf, A * velocity); }() : hadamard_product(langevin_pref_friction_buf, velocity); - return friction + - hadamard_product(langevin_pref_noise_buf, v_noise(p->p.identity, RNGSalt::LANGEVIN)); + return friction + hadamard_product(langevin_pref_noise_buf, + v_noise(p->p.identity, RNGSalt::LANGEVIN)); #else // Do the actual (isotropic) thermostatting return langevin_pref_friction_buf * velocity + From c7d10cc661f3b24b7eede87af3f19b330b7f098d Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sat, 9 Nov 2019 20:39:18 +0100 Subject: [PATCH 093/150] Style --- src/core/random.hpp | 9 ++- src/core/rotation.hpp | 15 ++-- src/core/thermostat.hpp | 4 +- src/python/espressomd/integrate.pyx | 2 +- src/python/espressomd/thermostat.pyx | 4 +- testsuite/python/langevin_thermostat.py | 4 +- .../python/mass-and-rinertia_per_particle.py | 69 +++++++++++-------- .../python/rotational-diffusion-aniso.py | 8 ++- testsuite/python/tests_common.py | 30 ++++---- 9 files changed, 81 insertions(+), 64 deletions(-) diff --git a/src/core/random.hpp b/src/core/random.hpp index cab2008e192..ce6efa5f5e1 100644 --- a/src/core/random.hpp +++ b/src/core/random.hpp @@ -41,7 +41,14 @@ * noise on the particle coupling and the fluid * thermalization. */ -enum class RNGSalt { FLUID, PARTICLES, LANGEVIN, SALT_DPD, THERMALIZED_BOND, BROWNIAN }; +enum class RNGSalt { + FLUID, + PARTICLES, + LANGEVIN, + SALT_DPD, + THERMALIZED_BOND, + BROWNIAN +}; namespace Random { extern std::mt19937 generator; diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 6865f1c4f54..f0967f6bb60 100644 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -32,9 +32,9 @@ #include "ParticleRange.hpp" #include +#include #include #include -#include /** Propagate angular velocities and update quaternions on a particle */ void propagate_omega_quat_particle(Particle &p); @@ -86,8 +86,8 @@ inline void rotation_fix(Particle &p, Utils::Vector3d &rot_vector) { * aBodyFrame by amount phi */ inline void local_rotate_particle_body(Particle &p, - const Utils::Vector3d &axis_body_frame, - const double phi) { + const Utils::Vector3d &axis_body_frame, + const double phi) { auto axis = axis_body_frame; // Rotation turned off entirely? @@ -95,9 +95,7 @@ inline void local_rotate_particle_body(Particle &p, return; // Convert rotation axis to body-fixed frame - axis = - mask(p.p.rotation, axis) - .normalize(); + axis = mask(p.p.rotation, axis).normalize(); auto const s = std::sin(phi / 2); auto const q = @@ -110,8 +108,9 @@ inline void local_rotate_particle_body(Particle &p, /** Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi */ -inline void local_rotate_particle(Particle &p, const Utils::Vector3d &axis_space_frame, - const double phi) { +inline void local_rotate_particle(Particle &p, + const Utils::Vector3d &axis_space_frame, + const double phi) { // Convert rotation axis to body-fixed frame Utils::Vector3d axis = convert_vector_space_to_body(p, axis_space_frame); local_rotate_particle_body(p, axis, phi); diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 528030734e3..081e9da24ed 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -322,8 +322,8 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { hadamard_product(langevin_pref_friction_buf, A * velocity); }() : hadamard_product(langevin_pref_friction_buf, velocity); - return friction + - hadamard_product(langevin_pref_noise_buf, v_noise(p.p.identity, RNGSalt::LANGEVIN)); + return friction + hadamard_product(langevin_pref_noise_buf, + v_noise(p.p.identity, RNGSalt::LANGEVIN)); #else // Do the actual (isotropic) thermostatting return langevin_pref_friction_buf * velocity + diff --git a/src/python/espressomd/integrate.pyx b/src/python/espressomd/integrate.pyx index 372fd8ee6a2..2d0d489d9bf 100644 --- a/src/python/espressomd/integrate.pyx +++ b/src/python/espressomd/integrate.pyx @@ -142,7 +142,7 @@ cdef class Integrator: """ self._method = "BD" integrate_set_bd() - + def set_isotropic_npt(self, ext_pressure, piston, direction=(True, True, True), cubic_box=False): """ diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 121ee395518..c11c2656e53 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -521,7 +521,7 @@ cdef class Thermostat: act_on_virtual=False, seed=None): """Sets the Brownian Dynamics thermostat with required parameters 'kT' 'gamma' and optional parameter 'gamma_rotation'. - + Parameters ----------- kT : :obj:`float` @@ -539,7 +539,7 @@ cdef class Thermostat: seed : :obj:`int`, required Initial counter value (or seed) of the philox RNG. Required on first activation of the langevin thermostat. - + """ self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) diff --git a/testsuite/python/langevin_thermostat.py b/testsuite/python/langevin_thermostat.py index b2c26941ac1..e99d07b0498 100644 --- a/testsuite/python/langevin_thermostat.py +++ b/testsuite/python/langevin_thermostat.py @@ -39,7 +39,7 @@ class LangevinThermostat(ut.TestCase): @classmethod def setUpClass(cls): np.random.seed(42) - + def setUp(self): if "BROWNIAN_DYNAMICS" in espressomd.features(): self.system.thermostat.turn_off() @@ -78,7 +78,7 @@ def global_langevin_run_check(self, N, kT, loops): Number of integration steps to sample. """ system = self.system - + # Sampling loops = 150 v_stored = np.zeros((N * loops, 3)) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index bddcdd4ca8b..2138aca9e8b 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -76,7 +76,7 @@ def setUp(self): if "BROWNIAN_DYNAMICS" in espressomd.features(): self.system.thermostat.turn_off() self.system.integrator.set_nvt() - + def set_initial_cond(self): """ Set all the particles to zero coordinates and velocities; same for time. @@ -182,7 +182,7 @@ def dissipation_param_setup(self, n): self.system.part[ind].omega_body = [1.0, 1.0, 1.0] self.system.part[ind].mass = self.mass self.system.part[ind].rinertia = self.J - + def dissipation_viscous_drag_setup_bd(self): """ Setup the specific parameters for the following dissipation @@ -192,7 +192,7 @@ def dissipation_viscous_drag_setup_bd(self): """ system = self.system - ## Time + # Time # Large time_step is OK for the BD by its definition & its benefits self.system.time_step = 17.0 @@ -336,7 +336,7 @@ def check_dissipation(self, n): if espressomd.has_features("ROTATION"): self.assertLess(abs( self.system.part[ind].omega_body[j] - math.exp(- self.gamma_rot_p_validate[k, j] * self.system.time / self.J[j])), tol) - + # Note: the decelleration test is needed for the Langevin thermostat only. Brownian thermostat is defined # over a larger time-step by its concept. def check_dissipation_viscous_drag(self, n): @@ -361,23 +361,23 @@ def check_dissipation_viscous_drag(self, n): for i in range(n): ind = i + k * n # Just some random forces - f[ind,:] = uniform(-0.5, 500., 3) - system.part[ind].ext_force = f[ind,:] + f[ind, :] = uniform(-0.5, 500., 3) + system.part[ind].ext_force = f[ind, :] if "ROTATION" in espressomd.features(): # Just some random torques - tor[ind,:] = uniform(-0.5, 500., 3) - system.part[ind].ext_torque = tor[ind,:] + tor[ind, :] = uniform(-0.5, 500., 3) + system.part[ind].ext_torque = tor[ind, :] # Let's set the dipole perpendicular to the torque if "DIPOLES" in espressomd.features(): # 2 types of particles correspond to 2 different # perpendicular vectors if ind % 2 == 0: - dip[ind,:] = 0.0, tor[ind, 2], -tor[ind, 1] + dip[ind, :] = 0.0, tor[ind, 2], -tor[ind, 1] else: - dip[ind,:] = -tor[ind, 2], 0.0, tor[ind, 0] - system.part[ind].dip = dip[ind,:] + dip[ind, :] = -tor[ind, 2], 0.0, tor[ind, 0] + system.part[ind].dip = dip[ind, :] # 3rd dynamic axis - tmp_axis[ind,:] = np.cross(tor[ind,:], dip[ind,:]) \ + tmp_axis[ind, :] = np.cross(tor[ind, :], dip[ind, :]) \ / (np.linalg.norm(tor[ind]) * np.linalg.norm(dip[ind])) # Small number of steps is enough for the terminal velocity within the BD by its definition. # A simulation of the original saturation of the velocity. @@ -388,7 +388,7 @@ def check_dissipation_viscous_drag(self, n): ind = i + k * n system.part[ind].pos = np.zeros((3)) if "DIPOLES" in espressomd.features(): - system.part[ind].dip = dip[ind,:] + system.part[ind].dip = dip[ind, :] for step in range(3): # Small number of steps system.integrator.run(2) @@ -396,31 +396,38 @@ def check_dissipation_viscous_drag(self, n): ind = i + k * n for j in range(3): # Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010) - # First (deterministic) term of the eq. (14.34) of Schlick2010 taking into account eq. (14.35). + # First (deterministic) term of the eq. (14.34) of + # Schlick2010 taking into account eq. (14.35). self.assertLess( - abs(system.part[ind].v[j] - f[ind, j] / \ + abs(system.part[ind].v[j] - f[ind, j] / self.gamma_tran_p_validate[k, j]), tol) - # Second (deterministic) term of the Eq. (14.39) of Schlick2010. + # Second (deterministic) term of the Eq. (14.39) of + # Schlick2010. self.assertLess( - abs(system.part[ind].pos[j] - \ + abs(system.part[ind].pos[j] - system.time * f[ind, j] / self.gamma_tran_p_validate[k, j]), tol) # Same, a rotational analogy. if "ROTATION" in espressomd.features(): self.assertLess(abs( - system.part[ind].omega_lab[j] - tor[ind, j] \ - / self.gamma_rot_p_validate[k, j]), tol) + system.part[ind].omega_lab[j] - tor[ind, j] + / self.gamma_rot_p_validate[k, j]), tol) if "ROTATION" in espressomd.features() and "DIPOLES" in espressomd.features(): # Same, a rotational analogy. One is implemented using a simple linear algebra; - # the polar angles with a sign control just for a correct inverse trigonometric functions application. - cos_alpha = np.dot(dip[ind,:], system.part[ind].dip[:]) / \ - (np.linalg.norm(dip[ind,:]) * system.part[ind].dipm) - # Isoptropic particle for the BD. Single gamma equals to other components - cos_alpha_test = np.cos(system.time * np.linalg.norm(tor[ind,:]) / \ - self.gamma_rot_p_validate[k, 0]) - # The sign instead of sin calc additionally (equivalent approach) - sgn = np.sign(np.dot(system.part[ind].dip[:], tmp_axis[ind,:])) - sgn_test = np.sign(np.sin(system.time * np.linalg.norm(tor[ind,:]) / \ - self.gamma_rot_p_validate[k, 0])) + # the polar angles with a sign control just for a + # correct inverse trigonometric functions application. + cos_alpha = np.dot(dip[ind, :], system.part[ind].dip[:]) / \ + (np.linalg.norm(dip[ind, :]) + * system.part[ind].dipm) + # Isoptropic particle for the BD. Single gamma equals + # to other components + cos_alpha_test = np.cos(system.time * np.linalg.norm(tor[ind, :]) / + self.gamma_rot_p_validate[k, 0]) + # The sign instead of sin calc additionally (equivalent + # approach) + sgn = np.sign( + np.dot(system.part[ind].dip[:], tmp_axis[ind, :])) + sgn_test = np.sign(np.sin(system.time * np.linalg.norm(tor[ind, :]) / + self.gamma_rot_p_validate[k, 0])) self.assertLess(abs(cos_alpha - cos_alpha_test), tol) self.assertEqual(sgn, sgn_test) @@ -642,7 +649,8 @@ def test_case_01(self): # Large time-step is OK for BD. system.time_step = 10.0 # Less number of loops are needed in case of BD because the velocity - # distribution is already as required. It is not a result of a real dynamics. + # distribution is already as required. It is not a result of a real + # dynamics. loops = 8 # The BD does not require so the warmup. Only 1 step is enough. # More steps are taken just to be sure that they will not lead @@ -915,5 +923,6 @@ def test_case_41(self): # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) + if __name__ == '__main__': ut.main() diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index 89d47bae789..bb8f9179f71 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -60,7 +60,7 @@ def add_particles_setup(self, n): Number of particles. """ - + for ind in range(n): part_pos = np.random.random(3) * self.box self.system.part.add(rotation=(1, 1, 1), id=ind, @@ -138,7 +138,7 @@ def rot_diffusion_param_setup(self): self.box = 10.0 self.system.box_l = 3 * [self.box] self.system.periodicity = [0, 0, 0] - + # NVT thermostat # Just some temperature range to cover by the test: self.kT = np.random.uniform(1.5, 6.5) @@ -284,7 +284,8 @@ def check_rot_diffusion(self, n): D1D1 /= 6.0 # Technical workaround of a digital arithmetic issue for isotropic # particle - if np.absolute((D0**2 - D1D1) / (D0**2 + D1D1)) < self.round_error_prec: + if np.absolute((D0**2 - D1D1) / (D0**2 + D1D1) + ) < self.round_error_prec: D1D1 *= (1.0 - 2.0 * self.round_error_prec) # Eq. (32) [Perrin1936]. dcosjj2_validate = 1. / 3. + (1. / 3.) * (1. + (D - D0) / (2. * np.sqrt(D0**2 - D1D1))) \ @@ -385,5 +386,6 @@ def test_case_10(self): # Actual integration and validation run self.check_rot_diffusion(n) + if __name__ == '__main__': ut.main() diff --git a/testsuite/python/tests_common.py b/testsuite/python/tests_common.py index 7a5127d0f26..ca12bb7599b 100644 --- a/testsuite/python/tests_common.py +++ b/testsuite/python/tests_common.py @@ -174,28 +174,28 @@ def transform_vel_from_cartesian_to_polar_coordinates(pos, vel): def define_rotation_matrix(system, part): - A = np.zeros((3, 3)) - quat = system.part[part].quat - qq = np.power(quat, 2) + A = np.zeros((3, 3)) + quat = system.part[part].quat + qq = np.power(quat, 2) - A[0, 0] = qq[0] + qq[1] - qq[2] - qq[3] - A[1, 1] = qq[0] - qq[1] + qq[2] - qq[3] - A[2, 2] = qq[0] - qq[1] - qq[2] + qq[3] + A[0, 0] = qq[0] + qq[1] - qq[2] - qq[3] + A[1, 1] = qq[0] - qq[1] + qq[2] - qq[3] + A[2, 2] = qq[0] - qq[1] - qq[2] + qq[3] - A[0, 1] = 2 * (quat[1] * quat[2] + quat[0] * quat[3]) - A[0, 2] = 2 * (quat[1] * quat[3] - quat[0] * quat[2]) - A[1, 0] = 2 * (quat[1] * quat[2] - quat[0] * quat[3]) + A[0, 1] = 2 * (quat[1] * quat[2] + quat[0] * quat[3]) + A[0, 2] = 2 * (quat[1] * quat[3] - quat[0] * quat[2]) + A[1, 0] = 2 * (quat[1] * quat[2] - quat[0] * quat[3]) - A[1, 2] = 2 * (quat[2] * quat[3] + quat[0] * quat[1]) - A[2, 0] = 2 * (quat[1] * quat[3] + quat[0] * quat[2]) - A[2, 1] = 2 * (quat[2] * quat[3] - quat[0] * quat[1]) + A[1, 2] = 2 * (quat[2] * quat[3] + quat[0] * quat[1]) + A[2, 0] = 2 * (quat[1] * quat[3] + quat[0] * quat[2]) + A[2, 1] = 2 * (quat[2] * quat[3] - quat[0] * quat[1]) - return A + return A def convert_vec_body_to_space(system, part, vec): - A = define_rotation_matrix(system, part) - return np.dot(A.transpose(), vec) + A = define_rotation_matrix(system, part) + return np.dot(A.transpose(), vec) def rotation_matrix(axis, theta): From f9abec9ba2c559a6c6b9a8dd7f502f0525805087 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sat, 9 Nov 2019 21:21:16 +0100 Subject: [PATCH 094/150] Merge typo fix --- src/python/espressomd/thermostat.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index c11c2656e53..adf6721b49d 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -110,7 +110,7 @@ cdef class Thermostat: self.set_npt(kT=thmst["kT"], gamma0=thmst["gamma0"], gammav=thmst["gammav"]) if thmst["type"] == "DPD": - self.set_dpd(kT=thmst["kT"]) + self.set_dpd(kT=thmst["kT"], seed=thmst["seed"]) IF BROWNIAN_DYNAMICS: if thmst["type"] == "BROWNIAN": self.set_brownian(kT=thmst["kT"], gamma=thmst[ @@ -538,7 +538,7 @@ cdef class Thermostat: If true the thermostat will act on virtual sites, default is off. seed : :obj:`int`, required Initial counter value (or seed) of the philox RNG. - Required on first activation of the langevin thermostat. + Required on first activation of the Brownian Dynamics thermostat. """ From 1a8b181f3d785142435a5a2e80afc5d4c2358c17 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sat, 9 Nov 2019 21:21:47 +0100 Subject: [PATCH 095/150] Trivial parametric issue (the rnd sequence has been changed by extra tests) --- testsuite/python/mass-and-rinertia_per_particle.py | 2 +- testsuite/python/rotational-diffusion-aniso.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index 2138aca9e8b..c2a5f28ac15 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -320,7 +320,7 @@ def check_dissipation(self, n): """ - tol = 1.2E-3 + tol = 1.21E-3 for _ in range(100): self.system.integrator.run(2) for i in range(n): diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index bb8f9179f71..a09e88c16df 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -225,7 +225,7 @@ def check_rot_diffusion(self, n): # Actual comparison. - tolerance = 0.2 + tolerance = 0.21 # Too small values of the direction cosines are out of interest # compare to 0..1 range. min_value = 0.14 From f68443d680229b52e29e1576198f25f617e6d418 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sat, 9 Nov 2019 21:42:42 +0100 Subject: [PATCH 096/150] Refactoring: new mask routine usage --- src/core/integrators/brownian_inline.hpp | 8 ++++---- src/core/rotation.hpp | 12 ------------ 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 91522673133..a6eee4a1f7b 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -297,7 +297,7 @@ void bd_drag_rot(Particle &p, double dt) { #endif // ROTATIONAL_INERTIA } } // j - rotation_fix(p, dphi); + dphi = mask(p.p.rotation, dphi); double dphi_m = dphi.norm(); if (dphi_m) { Utils::Vector3d dphi_u; @@ -341,7 +341,7 @@ void bd_drag_vel_rot(Particle &p, double dt) { #endif // ROTATIONAL_INERTIA } } - rotation_fix(p, p.m.omega); + p.m.omega = mask(p.p.rotation, p.m.omega); } /** Propagate the quaternions: random walk part.*/ @@ -421,7 +421,7 @@ void bd_random_walk_rot(Particle &p, double dt) { #endif // ROTATIONAL_INERTIA } } - rotation_fix(p, dphi); + dphi = mask(p.p.rotation, dphi); // making the algorithm to be independ on an order of the rotations double dphi_m = dphi.norm(); if (dphi_m) { @@ -468,7 +468,7 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { domega[j] = brown_sigma_vel_temp * noise[j] / sqrt(p.p.rinertia[j]); } } - rotation_fix(p, domega); + domega = mask(p.p.rotation, domega); p.m.omega += domega; } #endif // ROTATION diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index f0967f6bb60..a0feeaeaae7 100644 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -70,18 +70,6 @@ convert_dip_to_quat(const Utils::Vector3d &dip) { #endif -/** Fixing the per-particle per-axis rotations - */ -inline void rotation_fix(Particle &p, Utils::Vector3d &rot_vector) { - // Per coordinate fixing - if (!(p.p.rotation & ROTATION_X)) - rot_vector[0] = 0; - if (!(p.p.rotation & ROTATION_Y)) - rot_vector[1] = 0; - if (!(p.p.rotation & ROTATION_Z)) - rot_vector[2] = 0; -} - /** Rotate the particle p around the body-frame defined NORMALIZED axis * aBodyFrame by amount phi */ From c64d488eae671a52e5337ca59b449ddf698c2658 Mon Sep 17 00:00:00 2001 From: Brian Tanygin Date: Sat, 9 Nov 2019 21:56:16 +0100 Subject: [PATCH 097/150] Brownian dynamics docs update --- doc/sphinx/system_setup.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index d3072a226da..ec80d003791 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -488,9 +488,8 @@ step :math:`\Delta r` are fully driven by conservative forces :math:`F`: A positional random walk variance of each coordinate :math:`\sigma_p^2` corresponds to a diffusion within the Wiener process: -.. math:: \sigma_p^2 = 2 D \cdot \Delta t +.. math:: \sigma_p^2 = 2 \frac{kT}{\gamma} \cdot \Delta t -with the diffusion coefficient :math:`D` defined in the :ref:`Langevin thermostat` section. Each velocity component random walk variance :math:`\sigma_v^2` is defined by the heat component: From b5af9e26ce79ed2f46b3f87f8699a580f3737f40 Mon Sep 17 00:00:00 2001 From: Florian Weik Date: Tue, 12 Nov 2019 21:25:42 +0100 Subject: [PATCH 098/150] Formatting --- src/core/thermostat.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 0060842a746..85c1fb2257f 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -170,7 +170,8 @@ inline Utils::Vector3d v_noise(int particle_id, RNGSalt salt) { using ctr_type = rng_type::ctr_type; using key_type = rng_type::key_type; - const ctr_type c{{langevin_rng_counter->value(), static_cast(salt)}}; + const ctr_type c{ + {langevin_rng_counter->value(), static_cast(salt)}}; const key_type k{{static_cast(particle_id)}}; @@ -310,7 +311,8 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { #endif // PARTICLE_ANISOTROPY // Do the actual (isotropic) thermostatting - return friction_op * velocity + noise_op * v_noise(p.p.identity, RNGSalt::LANGEVIN); + return friction_op * velocity + + noise_op * v_noise(p.p.identity, RNGSalt::LANGEVIN); } #ifdef ROTATION From 45088428a35131a8d0b3824672454923bfbbcf3d Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Wed, 13 Nov 2019 15:54:03 +0100 Subject: [PATCH 099/150] config: Remove BROWNIAN_DyNAMICS as compile-time feature --- maintainer/configs/maxset.hpp | 2 - src/config/features.def | 1 - src/core/integrate.cpp | 6 - src/core/integrate.hpp | 2 - src/core/integrators/brownian_inline.hpp | 4 - src/core/thermostat.cpp | 6 - src/python/espressomd/integrate.pxd | 3 +- src/python/espressomd/integrate.pyx | 15 +- src/python/espressomd/thermostat.pyx | 115 ++++---- testsuite/python/langevin_thermostat.py | 42 ++- .../python/mass-and-rinertia_per_particle.py | 249 +++++++++--------- .../python/rotational-diffusion-aniso.py | 32 ++- 12 files changed, 217 insertions(+), 260 deletions(-) diff --git a/maintainer/configs/maxset.hpp b/maintainer/configs/maxset.hpp index 0af791c34b5..28ac699bb2b 100644 --- a/maintainer/configs/maxset.hpp +++ b/maintainer/configs/maxset.hpp @@ -45,8 +45,6 @@ #define ENGINE -#define BROWNIAN_DYNAMICS - #ifdef CUDA #define LB_BOUNDARIES_GPU #define ELECTROKINETICS diff --git a/src/config/features.def b/src/config/features.def index 8b8e32b4613..e554af14f6d 100644 --- a/src/config/features.def +++ b/src/config/features.def @@ -25,7 +25,6 @@ NPT SWIMMER_REACTIONS ENGINE implies ROTATION, EXTERNAL_FORCES PARTICLE_ANISOTROPY implies ROTATION -BROWNIAN_DYNAMICS /* Rotation */ ROTATION diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index c6213e4f29c..18776958db4 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -138,12 +138,10 @@ bool integrator_step_1(ParticleRange &particles) { velocity_verlet_npt_step_1(particles); break; #endif -#ifdef BROWNIAN_DYNAMICS case INTEG_METHOD_BD: // the Ermak-McCammon's Brownian Dynamics requires a single step // so, just skip here break; -#endif default: throw std::runtime_error("Unknown value for integ_switch"); } @@ -164,12 +162,10 @@ void integrator_step_2(ParticleRange &particles) { velocity_verlet_npt_step_2(particles); break; #endif -#ifdef BROWNIAN_DYNAMICS case INTEG_METHOD_BD: // the Ermak-McCammon's Brownian Dynamics requires a single step brownian_dynamics_propagator(particles); break; -#endif default: throw std::runtime_error("Unknown value for INTEG_SWITCH"); } @@ -406,12 +402,10 @@ void integrate_set_nvt() { mpi_bcast_parameter(FIELD_INTEG_SWITCH); } -#ifdef BROWNIAN_DYNAMICS void integrate_set_bd() { integ_switch = INTEG_METHOD_BD; mpi_bcast_parameter(FIELD_INTEG_SWITCH); } -#endif #ifdef NPT int integrate_set_npt_isotropic(double ext_pressure, double piston, diff --git a/src/core/integrate.hpp b/src/core/integrate.hpp index 9abcfa82e21..44eeac8343a 100644 --- a/src/core/integrate.hpp +++ b/src/core/integrate.hpp @@ -130,10 +130,8 @@ int python_integrate(int n_steps, bool recalc_forces, bool reuse_forces); /** @brief Set the NVT integrator. */ void integrate_set_nvt(); -#ifdef BROWNIAN_DYNAMICS /** @brief Set the Brownian Dynamics integrator. */ void integrate_set_bd(); -#endif /** @brief Set the NpT isotropic integrator. * diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index a6eee4a1f7b..2f5a346b1ab 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -25,8 +25,6 @@ #include "thermostat.hpp" -#ifdef BROWNIAN_DYNAMICS - /** Propagate position: viscous drag driven by conservative forces.*/ /*********************************************************/ /** \name bd_drag */ @@ -505,6 +503,4 @@ inline void brownian_dynamics_propagator(const ParticleRange &particles) { sim_time += time_step; } -#endif // BROWNIAN_DYNAMICS - #endif // BROWNIAN_INLINE_HPP diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 569fb5129ec..b6341fba503 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -67,14 +67,12 @@ GammaType langevin_gamma_rotation = sentinel(GammaType{}); GammaType langevin_pref1; GammaType langevin_pref2; GammaType langevin_pref2_rotation; -#ifdef BROWNIAN_DYNAMICS // Brownian position random walk standard deviation GammaType brown_sigma_pos_inv = sentinel(GammaType{}); GammaType brown_sigma_pos_rotation_inv = sentinel(GammaType{}); GammaType brown_gammatype_nan = set_nan(GammaType{}); double brown_sigma_vel; double brown_sigma_vel_rotation; -#endif // BROWNIAN_DYNAMICS /* NPT ISOTROPIC THERMOSTAT */ double nptiso_gamma0 = 0.0; @@ -152,7 +150,6 @@ void thermo_init_npt_isotropic() { } #endif -#ifdef BROWNIAN_DYNAMICS // brown_sigma_vel determines here the heat velocity random walk dispersion // brown_sigma_pos determines here the BD position random walk dispersion // default particle mass is assumed to be unitary in this global parameters @@ -194,7 +191,6 @@ void thermo_init_brownian() { } #endif // ROTATION } -#endif // BROWNIAN_DYNAMICS void thermo_init() { // Init thermalized bond despite of thermostat @@ -214,10 +210,8 @@ void thermo_init() { if (thermo_switch & THERMO_NPT_ISO) thermo_init_npt_isotropic(); #endif -#ifdef BROWNIAN_DYNAMICS if (thermo_switch & THERMO_BROWNIAN) thermo_init_brownian(); -#endif } void langevin_heat_up() { diff --git a/src/python/espressomd/integrate.pxd b/src/python/espressomd/integrate.pxd index c2b5af01c20..c8816467ab5 100644 --- a/src/python/espressomd/integrate.pxd +++ b/src/python/espressomd/integrate.pxd @@ -29,8 +29,7 @@ cdef extern from "integrate.hpp" nogil: cdef int python_integrate(int n_steps, cbool recalc_forces, int reuse_forces) cdef void integrate_set_nvt() cdef extern cbool skin_set - IF BROWNIAN_DYNAMICS: - cdef void integrate_set_bd() + cdef void integrate_set_bd() IF NPT: cdef extern from "integrate.hpp" nogil: diff --git a/src/python/espressomd/integrate.pyx b/src/python/espressomd/integrate.pyx index 2d0d489d9bf..8be8123b9ba 100644 --- a/src/python/espressomd/integrate.pyx +++ b/src/python/espressomd/integrate.pyx @@ -134,14 +134,13 @@ cdef class Integrator: self._method = "NVT" integrate_set_nvt() - IF BROWNIAN_DYNAMICS: - def set_brownian_dynamics(self): - """ - Set the integration method to BD. - - """ - self._method = "BD" - integrate_set_bd() + def set_brownian_dynamics(self): + """ + Set the integration method to BD. + + """ + self._method = "BD" + integrate_set_bd() def set_isotropic_npt(self, ext_pressure, piston, direction=(True, True, True), cubic_box=False): diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index adf6721b49d..3ab23719678 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -111,10 +111,9 @@ cdef class Thermostat: gammav=thmst["gammav"]) if thmst["type"] == "DPD": self.set_dpd(kT=thmst["kT"], seed=thmst["seed"]) - IF BROWNIAN_DYNAMICS: - if thmst["type"] == "BROWNIAN": - self.set_brownian(kT=thmst["kT"], gamma=thmst[ - "gamma"], gamma_rotation=thmst["gamma_rotation"], act_on_virtual=thmst["act_on_virtual"], seed=thmst["seed"]) + if thmst["type"] == "BROWNIAN": + self.set_brownian(kT=thmst["kT"], gamma=thmst[ + "gamma"], gamma_rotation=thmst["gamma_rotation"], act_on_virtual=thmst["act_on_virtual"], seed=thmst["seed"]) def get_ts(self): return thermo_switch @@ -149,32 +148,31 @@ cdef class Thermostat: lang_dict["gamma_rotation"] = None thermo_list.append(lang_dict) - IF BROWNIAN_DYNAMICS: - if thermo_switch & THERMO_BROWNIAN: - lang_dict = {} - lang_dict["type"] = "BROWNIAN" - lang_dict["kT"] = temperature - lang_dict["act_on_virtual"] = thermo_virtual - lang_dict["seed"] = int(langevin_get_rng_state()) + if thermo_switch & THERMO_BROWNIAN: + lang_dict = {} + lang_dict["type"] = "BROWNIAN" + lang_dict["kT"] = temperature + lang_dict["act_on_virtual"] = thermo_virtual + lang_dict["seed"] = int(langevin_get_rng_state()) + IF PARTICLE_ANISOTROPY: + lang_dict["gamma"] = [langevin_gamma[0], + langevin_gamma[1], + langevin_gamma[2]] + ELSE: + lang_dict["gamma"] = langevin_gamma + IF ROTATION: IF PARTICLE_ANISOTROPY: - lang_dict["gamma"] = [langevin_gamma[0], - langevin_gamma[1], - langevin_gamma[2]] + lang_dict[ + "gamma_rotation"] = [langevin_gamma_rotation[0], + langevin_gamma_rotation[ + 1], + langevin_gamma_rotation[2]] ELSE: - lang_dict["gamma"] = langevin_gamma - IF ROTATION: - IF PARTICLE_ANISOTROPY: - lang_dict[ - "gamma_rotation"] = [langevin_gamma_rotation[0], - langevin_gamma_rotation[ - 1], - langevin_gamma_rotation[2]] - ELSE: - lang_dict["gamma_rotation"] = langevin_gamma_rotation - ELSE: - lang_dict["gamma_rotation"] = None + lang_dict["gamma_rotation"] = langevin_gamma_rotation + ELSE: + lang_dict["gamma_rotation"] = None - thermo_list.append(lang_dict) + thermo_list.append(lang_dict) if thermo_switch & THERMO_LB: lb_dict = {} lb_dict["LB_fluid"] = self._LB_fluid @@ -515,38 +513,37 @@ cdef class Thermostat: mpi_bcast_parameter(FIELD_THERMO_SWITCH) mpi_bcast_parameter(FIELD_TEMPERATURE) - IF BROWNIAN_DYNAMICS: - @AssertThermostatType(THERMO_BROWNIAN) - def set_brownian(self, kT=None, gamma=None, gamma_rotation=None, - act_on_virtual=False, seed=None): - """Sets the Brownian Dynamics thermostat with required parameters 'kT' 'gamma' - and optional parameter 'gamma_rotation'. + @AssertThermostatType(THERMO_BROWNIAN) + def set_brownian(self, kT=None, gamma=None, gamma_rotation=None, + act_on_virtual=False, seed=None): + """Sets the Brownian Dynamics thermostat with required parameters 'kT' 'gamma' + and optional parameter 'gamma_rotation'. - Parameters - ----------- - kT : :obj:`float` - Thermal energy of the simulated heat bath. - gamma : :obj:`float` - Contains the friction coefficient of the bath. If the feature 'PARTICLE_ANISOTROPY' - is compiled in then 'gamma' can be a list of three positive floats, for the friction - coefficient in each cardinal direction. - gamma_rotation : :obj:`float`, optional - The same applies to 'gamma_rotation', which requires the feature - 'ROTATION' to work properly. But also accepts three floating point numbers - if 'PARTICLE_ANISOTROPY' is also compiled in. - act_on_virtual : :obj:`bool`, optional - If true the thermostat will act on virtual sites, default is off. - seed : :obj:`int`, required - Initial counter value (or seed) of the philox RNG. - Required on first activation of the Brownian Dynamics thermostat. + Parameters + ----------- + kT : :obj:`float` + Thermal energy of the simulated heat bath. + gamma : :obj:`float` + Contains the friction coefficient of the bath. If the feature 'PARTICLE_ANISOTROPY' + is compiled in then 'gamma' can be a list of three positive floats, for the friction + coefficient in each cardinal direction. + gamma_rotation : :obj:`float`, optional + The same applies to 'gamma_rotation', which requires the feature + 'ROTATION' to work properly. But also accepts three floating point numbers + if 'PARTICLE_ANISOTROPY' is also compiled in. + act_on_virtual : :obj:`bool`, optional + If true the thermostat will act on virtual sites, default is off. + seed : :obj:`int`, required + Initial counter value (or seed) of the philox RNG. + Required on first activation of the Brownian Dynamics thermostat. - """ + """ - self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) - global thermo_switch - # this is safe because this combination of thermostats is not - # allowed - thermo_switch = (thermo_switch & (~THERMO_LANGEVIN)) - thermo_switch = (thermo_switch | THERMO_BROWNIAN) - mpi_bcast_parameter(FIELD_THERMO_SWITCH) - return True + self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) + global thermo_switch + # this is safe because this combination of thermostats is not + # allowed + thermo_switch = (thermo_switch & (~THERMO_LANGEVIN)) + thermo_switch = (thermo_switch | THERMO_BROWNIAN) + mpi_bcast_parameter(FIELD_THERMO_SWITCH) + return True diff --git a/testsuite/python/langevin_thermostat.py b/testsuite/python/langevin_thermostat.py index e99d07b0498..8e2e4f5d658 100644 --- a/testsuite/python/langevin_thermostat.py +++ b/testsuite/python/langevin_thermostat.py @@ -41,10 +41,9 @@ def setUpClass(cls): np.random.seed(42) def setUp(self): - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.system.thermostat.turn_off() - # the default integrator is supposed implicitly - self.system.integrator.set_nvt() + self.system.thermostat.turn_off() + # the default integrator is supposed implicitly + self.system.integrator.set_nvt() def check_velocity_distribution(self, vel, minmax, n_bins, error_tol, kT): """check the recorded particle distributions in velocity against a @@ -247,24 +246,23 @@ def test_04__global_langevin(self): self.global_langevin_run_check(N, kT, 150) - if espressomd.has_features("BROWNIAN_DYNAMICS"): - # Large time-step is OK for BD. - system.time_step = 7.214 - system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) - system.thermostat.turn_off() - system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=41) - system.integrator.set_brownian_dynamics() - # Warmup - # The BD does not require so the warmup. Only 1 step is enough. - # More steps are taken just to be sure that they will not lead - # to wrong results. - system.integrator.run(3) - # Less number of loops are needed in case of BD because the velocity - # distribution is already as required. It is not a result of a real - # dynamics. - self.global_langevin_run_check(N, kT, 70) - system.thermostat.turn_off() + # Large time-step is OK for BD. + system.time_step = 7.214 + system.part[:].v = np.zeros((3)) + system.part[:].omega_body = np.zeros((3)) + system.thermostat.turn_off() + system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=41) + system.integrator.set_brownian_dynamics() + # Warmup + # The BD does not require so the warmup. Only 1 step is enough. + # More steps are taken just to be sure that they will not lead + # to wrong results. + system.integrator.run(3) + # Less number of loops are needed in case of BD because the velocity + # distribution is already as required. It is not a result of a real + # dynamics. + self.global_langevin_run_check(N, kT, 70) + system.thermostat.turn_off() @utx.skipIfMissingFeatures("LANGEVIN_PER_PARTICLE") def test_05__langevin_per_particle(self): diff --git a/testsuite/python/mass-and-rinertia_per_particle.py b/testsuite/python/mass-and-rinertia_per_particle.py index b794688958c..21fba4d4dba 100644 --- a/testsuite/python/mass-and-rinertia_per_particle.py +++ b/testsuite/python/mass-and-rinertia_per_particle.py @@ -73,9 +73,8 @@ def setUpClass(cls): def setUp(self): self.system.time = 0.0 self.system.part.clear() - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.system.thermostat.turn_off() - self.system.integrator.set_nvt() + self.system.thermostat.turn_off() + self.system.integrator.set_nvt() def set_initial_cond(self): """ @@ -255,11 +254,8 @@ def fluctuation_dissipation_param_setup(self, n): self.system.time_step = 0.03 # Space - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # for large steps and multi-core run stability - box = 1E2 - else: - box = 10.0 + # for large steps and multi-core run stability + box = 1E2 self.system.box_l = 3 * [box] self.system.periodicity = [0, 0, 0] @@ -610,19 +606,18 @@ def test_case_000(self): # no particle specific values / dissipation viscous drag only / BD only. # LD will require too much computational time # (one is tested offline though). - if "BROWNIAN_DYNAMICS" in espressomd.features(): - def test_case_001(self): - system = self.system - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_viscous_drag_setup_bd() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_dissipation_viscous_drag(n) + def test_case_001(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_dissipation_viscous_drag(n) # Test case 0.1: no particle specific values / fluctuation & dissipation # Same particle and thermostat parameters for LD and BD are required in order @@ -680,20 +675,19 @@ def test_case_100(self): # Test case 1.0.1: particle specific gamma but not temperature / # dissipation viscous drag only / BD only. - if "BROWNIAN_DYNAMICS" in espressomd.features(): - def test_case_101(self): - system = self.system - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_viscous_drag_setup_bd() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - system.integrator.set_brownian_dynamics() - self.set_particle_specific_gamma(n) - # Actual integration and validation run - self.check_dissipation_viscous_drag(n) + def test_case_101(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + system.integrator.set_brownian_dynamics() + self.set_particle_specific_gamma(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag(n) # Test case 1.1: particle specific gamma but not temperature / fluctuation # & dissipation / LD and BD @@ -712,18 +706,17 @@ def test_case_11(self): self.set_diffusivity_tran() # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.set_initial_cond() - system.time_step = 10.0 - loops = 8 - therm_steps = 2 - # The test case-specific thermostat - system.thermostat.turn_off() - system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.set_initial_cond() + system.time_step = 10.0 + loops = 8 + therm_steps = 2 + # The test case-specific thermostat + system.thermostat.turn_off() + system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) # Test case 2.0.0: particle specific temperature but not gamma / dissipation # only / LD only @@ -742,20 +735,19 @@ def test_case_200(self): # Test case 2.0.1: particle specific temperature but not gamma / dissipation # viscous drag only / BD only - if "BROWNIAN_DYNAMICS" in espressomd.features(): - def test_case_201(self): - system = self.system - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_viscous_drag_setup_bd() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - system.integrator.set_brownian_dynamics() - self.set_particle_specific_temperature(n) - # Actual integration and validation run - self.check_dissipation_viscous_drag(n) + def test_case_201(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + system.integrator.set_brownian_dynamics() + self.set_particle_specific_temperature(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag(n) # Test case 2.1: particle specific temperature but not gamma / fluctuation # & dissipation / LD and BD @@ -774,18 +766,17 @@ def test_case_21(self): self.set_diffusivity_tran() # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.set_initial_cond() - system.time_step = 10.0 - loops = 8 - therm_steps = 2 - # The test case-specific thermostat and per-particle parameters - system.thermostat.turn_off() - system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.set_initial_cond() + system.time_step = 10.0 + loops = 8 + therm_steps = 2 + # The test case-specific thermostat and per-particle parameters + system.thermostat.turn_off() + system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) # Test case 3.0.0: both particle specific gamma and temperature / # dissipation only / LD only @@ -805,21 +796,20 @@ def test_case_300(self): # Test case 3.0.1: both particle specific gamma and temperature / # dissipation viscous drag only / BD only - if "BROWNIAN_DYNAMICS" in espressomd.features(): - def test_case_301(self): - system = self.system - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_viscous_drag_setup_bd() - self.set_langevin_global_defaults() - # The test case-specific thermostat and per-particle parameters - system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - system.integrator.set_brownian_dynamics() - self.set_particle_specific_gamma(n) - self.set_particle_specific_temperature(n) - # Actual integration and validation run - self.check_dissipation_viscous_drag(n) + def test_case_301(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + system.integrator.set_brownian_dynamics() + self.set_particle_specific_gamma(n) + self.set_particle_specific_temperature(n) + # Actual integration and validation run + self.check_dissipation_viscous_drag(n) # Test case 3.1: both particle specific gamma and temperature / # fluctuation & dissipation / LD and BD @@ -839,18 +829,17 @@ def test_case_31(self): self.set_diffusivity_tran() # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.set_initial_cond() - system.time_step = 10.0 - loops = 8 - therm_steps = 2 - # The test case-specific thermostat - system.thermostat.turn_off() - system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.set_initial_cond() + system.time_step = 10.0 + loops = 8 + therm_steps = 2 + # The test case-specific thermostat + system.thermostat.turn_off() + system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) # Test case 4.0.0: no particle specific values / rotational specific global # thermostat / dissipation only / LD only @@ -871,22 +860,21 @@ def test_case_400(self): # Test case 4.0.1: no particle specific values / rotational specific global # thermostat / dissipation only / BD only - if "BROWNIAN_DYNAMICS" in espressomd.features(): - def test_case_401(self): - system = self.system - # Each of 2 kind of particles will be represented by n instances: - n = 1 - self.dissipation_viscous_drag_setup_bd() - self.set_langevin_global_defaults_rot_differ() - # The test case-specific thermostat and per-particle parameters - system.thermostat.set_brownian( - kT=self.kT, - gamma=self.gamma_global, - gamma_rotation=self.gamma_global_rot, - seed=42) - system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_dissipation_viscous_drag(n) + def test_case_401(self): + system = self.system + # Each of 2 kind of particles will be represented by n instances: + n = 1 + self.dissipation_viscous_drag_setup_bd() + self.set_langevin_global_defaults_rot_differ() + # The test case-specific thermostat and per-particle parameters + system.thermostat.set_brownian( + kT=self.kT, + gamma=self.gamma_global, + gamma_rotation=self.gamma_global_rot, + seed=42) + system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_dissipation_viscous_drag(n) # Test case 4.1: no particle specific values / rotational specific global # thermostat / fluctuation & dissipation / LD and BD @@ -906,21 +894,20 @@ def test_case_41(self): self.set_diffusivity_tran() # Actual integration and validation run self.check_fluctuation_dissipation(n, therm_steps, loops) - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.set_initial_cond() - system.time_step = 10.0 - loops = 8 - therm_steps = 2 - # The test case-specific thermostat - system.thermostat.turn_off() - system.thermostat.set_brownian( - kT=self.kT, - gamma=self.gamma_global, - gamma_rotation=self.gamma_global_rot, - seed=42) - system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_fluctuation_dissipation(n, therm_steps, loops) + self.set_initial_cond() + system.time_step = 10.0 + loops = 8 + therm_steps = 2 + # The test case-specific thermostat + system.thermostat.turn_off() + system.thermostat.set_brownian( + kT=self.kT, + gamma=self.gamma_global, + gamma_rotation=self.gamma_global_rot, + seed=42) + system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_fluctuation_dissipation(n, therm_steps, loops) if __name__ == '__main__': diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index a09e88c16df..c405eed4bfa 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -44,10 +44,9 @@ class RotDiffAniso(ut.TestCase): def setUp(self): self.system.time = 0.0 self.system.part.clear() - if "BROWNIAN_DYNAMICS" in espressomd.features(): - self.system.thermostat.turn_off() - # the default integrator is supposed implicitly - self.system.integrator.set_nvt() + self.system.thermostat.turn_off() + # the default integrator is supposed implicitly + self.system.integrator.set_nvt() def add_particles_setup(self, n): """ @@ -372,19 +371,18 @@ def test_case_01(self): # Actual integration and validation run self.check_rot_diffusion(n) - if "BROWNIAN_DYNAMICS" in espressomd.features(): - # Brownian Dynamics / Isotropic - def test_case_10(self): - n = 800 - self.system.thermostat.turn_off() - self.rot_diffusion_param_setup() - self.set_isotropic_param() - self.add_particles_setup(n) - self.system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - self.system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_rot_diffusion(n) + # Brownian Dynamics / Isotropic + def test_case_10(self): + n = 800 + self.system.thermostat.turn_off() + self.rot_diffusion_param_setup() + self.set_isotropic_param() + self.add_particles_setup(n) + self.system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + self.system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_rot_diffusion(n) if __name__ == '__main__': From ab6a54f937827b43709c7960cb0df000950a3efe Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Sat, 30 Nov 2019 22:46:31 +0100 Subject: [PATCH 100/150] BD: body gamma and lab force match --- src/core/integrators/brownian_inline.hpp | 121 +++++++++++++++++++---- 1 file changed, 102 insertions(+), 19 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 2f5a346b1ab..5ac6d4204c1 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -43,18 +43,55 @@ inline void bd_drag(Particle &p, double dt) { local_gamma = langevin_gamma; } + bool aniso_flag = true; // particle anisotropy flag + +#ifdef PARTICLE_ANISOTROPY + // Particle frictional isotropy check. + aniso_flag = (local_gamma[0] != local_gamma[1]) || + (local_gamma[1] != local_gamma[2]); +#else + aniso_flag = false; +#endif + + Utils::Vector3d force_body; + Utils::Vector3d delta_pos_body, delta_pos_lab; + + if (aniso_flag) { + force_body = convert_vector_space_to_body(p, p.f.f); + } + for (int j = 0; j < 3; j++) { + // Second (deterministic) term of the Eq. (14.39) of Schlick2010. + // Only a conservative part of the force is used here +#ifdef PARTICLE_ANISOTROPY + if (aniso_flag) { + delta_pos_body[j] = force_body[j] * dt / (local_gamma[j]); + } else { +#ifdef EXTERNAL_FORCES + if (!(p.p.ext_flag & COORD_FIXED(j))) +#endif + { + p.r.p[j] += p.f.f[j] * dt / (local_gamma[j]); + } + } +#else #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - // Second (deterministic) term of the Eq. (14.39) of Schlick2010. - // Only a conservative part of the force is used here -#ifndef PARTICLE_ANISOTROPY p.r.p[j] += p.f.f[j] * dt / (local_gamma); -#else - p.r.p[j] += p.f.f[j] * dt / (local_gamma[j]); + } #endif // PARTICLE_ANISOTROPY + } + if (aniso_flag) { + delta_pos_lab = convert_vector_body_to_space(p, delta_pos_body); + for (int j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p.p.ext_flag & COORD_FIXED(j))) +#endif + { + p.r.p[j] += delta_pos_lab[j]; + } } } } @@ -77,22 +114,68 @@ inline void bd_drag_vel(Particle &p, double dt) { local_gamma = langevin_gamma; } + bool aniso_flag = true; // particle anisotropy flag + +#ifdef PARTICLE_ANISOTROPY + // Particle frictional isotropy check. + aniso_flag = (local_gamma[0] != local_gamma[1]) || + (local_gamma[1] != local_gamma[2]); +#else + aniso_flag = false; +#endif + + Utils::Vector3d force_body; + Utils::Vector3d vel_body, vel_lab; + + if (aniso_flag) { + force_body = convert_vector_space_to_body(p, p.f.f); + } + for (int j = 0; j < 3; j++) { + // First (deterministic) term of the eq. (14.34) of Schlick2010 taking + // into account eq. (14.35). Only conservative part of the force is used + // here NOTE: velocity is assigned here and propagated by thermal part + // further on top of it +#ifdef PARTICLE_ANISOTROPY + if (aniso_flag) { + vel_body[j] = force_body[j] * dt / (local_gamma[j]); + } else { #ifdef EXTERNAL_FORCES - if (p.p.ext_flag & COORD_FIXED(j)) { - p.m.v[j] = 0.0; - } else + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif - { - // First (deterministic) term of the eq. (14.34) of Schlick2010 taking - // into account eq. (14.35). Only conservative part of the force is used - // here NOTE: velocity is assigned here and propagated by thermal part - // further on top of it -#ifndef PARTICLE_ANISOTROPY - p.m.v[j] = p.f.f[j] / (local_gamma); + { + p.m.v[j] = p.f.f[j] / (local_gamma[j]); + } +#ifdef EXTERNAL_FORCES + else { + p.m.v[j] = 0.0; + } +#endif + } #else - p.m.v[j] = p.f.f[j] / (local_gamma[j]); +#ifdef EXTERNAL_FORCES + if (!(p.p.ext_flag & COORD_FIXED(j))) +#endif + { + p.r.p[j] += p.f.f[j] * dt / (local_gamma); + } #endif // PARTICLE_ANISOTROPY + } + + if (aniso_flag) { + vel_lab = convert_vector_body_to_space(p, vel_body); + for (int j = 0; j < 3; j++) { +#ifdef EXTERNAL_FORCES + if (!(p.p.ext_flag & COORD_FIXED(j))) +#endif + { + p.m.v[j] = vel_lab[j]; + } +#ifdef EXTERNAL_FORCES + else { + p.m.v[j] = 0.0; + } +#endif } } } @@ -166,11 +249,11 @@ void bd_random_walk(Particle &p, double dt) { // Particle frictional isotropy check. aniso_flag = (brown_sigma_pos_temp_inv[0] != brown_sigma_pos_temp_inv[1]) || (brown_sigma_pos_temp_inv[1] != brown_sigma_pos_temp_inv[2]); -#endif +#else + aniso_flag = false; +#endif // PARTICLE_ANISOTROPY -#ifdef PARTICLE_ANISOTROPY Utils::Vector3d delta_pos_body, delta_pos_lab; -#endif // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared // magnitude defined in the second eq. (14.38), Schlick2010. From adf9fb4a22a7f69195bb23e1258802caa387b738 Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Sat, 30 Nov 2019 22:46:46 +0100 Subject: [PATCH 101/150] Code deduplication --- testsuite/python/tests_common.py | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/testsuite/python/tests_common.py b/testsuite/python/tests_common.py index 54de6a8d344..c1ab8213041 100644 --- a/testsuite/python/tests_common.py +++ b/testsuite/python/tests_common.py @@ -172,32 +172,10 @@ def transform_vel_from_cartesian_to_polar_coordinates(pos, vel): (pos[0] * vel[0] + pos[1] * vel[1]) / np.sqrt(pos[0]**2 + pos[1]**2), (pos[0] * vel[1] - pos[1] * vel[0]) / (pos[0]**2 + pos[1]**2), vel[2]]) - -def define_rotation_matrix(system, part): - A = np.zeros((3, 3)) - quat = system.part[part].quat - qq = np.power(quat, 2) - - A[0, 0] = qq[0] + qq[1] - qq[2] - qq[3] - A[1, 1] = qq[0] - qq[1] + qq[2] - qq[3] - A[2, 2] = qq[0] - qq[1] - qq[2] + qq[3] - - A[0, 1] = 2 * (quat[1] * quat[2] + quat[0] * quat[3]) - A[0, 2] = 2 * (quat[1] * quat[3] - quat[0] * quat[2]) - A[1, 0] = 2 * (quat[1] * quat[2] - quat[0] * quat[3]) - - A[1, 2] = 2 * (quat[2] * quat[3] + quat[0] * quat[1]) - A[2, 0] = 2 * (quat[1] * quat[3] + quat[0] * quat[2]) - A[2, 1] = 2 * (quat[2] * quat[3] - quat[0] * quat[1]) - - return A - - def convert_vec_body_to_space(system, part, vec): - A = define_rotation_matrix(system, part) + A = rotation_matrix_quat(system, part) return np.dot(A.transpose(), vec) - def rotation_matrix(axis, theta): """ Return the rotation matrix associated with counterclockwise rotation about From 70a9341d31f86dc29eaf6112ccda151ecde9b6f7 Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Sat, 30 Nov 2019 23:16:09 +0100 Subject: [PATCH 102/150] Style aligning --- src/core/integrators/brownian_inline.hpp | 8 ++++---- testsuite/python/tests_common.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 5ac6d4204c1..86eb70f51ee 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -47,8 +47,8 @@ inline void bd_drag(Particle &p, double dt) { #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (local_gamma[0] != local_gamma[1]) || - (local_gamma[1] != local_gamma[2]); + aniso_flag = + (local_gamma[0] != local_gamma[1]) || (local_gamma[1] != local_gamma[2]); #else aniso_flag = false; #endif @@ -118,8 +118,8 @@ inline void bd_drag_vel(Particle &p, double dt) { #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (local_gamma[0] != local_gamma[1]) || - (local_gamma[1] != local_gamma[2]); + aniso_flag = + (local_gamma[0] != local_gamma[1]) || (local_gamma[1] != local_gamma[2]); #else aniso_flag = false; #endif diff --git a/testsuite/python/tests_common.py b/testsuite/python/tests_common.py index c1ab8213041..1952a445b05 100644 --- a/testsuite/python/tests_common.py +++ b/testsuite/python/tests_common.py @@ -172,10 +172,12 @@ def transform_vel_from_cartesian_to_polar_coordinates(pos, vel): (pos[0] * vel[0] + pos[1] * vel[1]) / np.sqrt(pos[0]**2 + pos[1]**2), (pos[0] * vel[1] - pos[1] * vel[0]) / (pos[0]**2 + pos[1]**2), vel[2]]) + def convert_vec_body_to_space(system, part, vec): A = rotation_matrix_quat(system, part) return np.dot(A.transpose(), vec) + def rotation_matrix(axis, theta): """ Return the rotation matrix associated with counterclockwise rotation about From f203cfa1db845bc38d78a412ef4e81228ef6b6a8 Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Sun, 1 Dec 2019 00:27:58 +0100 Subject: [PATCH 103/150] Empty and nortation build and tests fixes --- src/core/integrators/brownian_inline.hpp | 44 ++++++++++++++++++------ testsuite/python/langevin_thermostat.py | 3 +- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 86eb70f51ee..7765a69d752 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -37,9 +37,12 @@ inline void bd_drag(Particle &p, double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: Thermostat::GammaType local_gamma; +#ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{}) { local_gamma = p.p.gamma; - } else { + } else +#endif + { local_gamma = langevin_gamma; } @@ -56,9 +59,11 @@ inline void bd_drag(Particle &p, double dt) { Utils::Vector3d force_body; Utils::Vector3d delta_pos_body, delta_pos_lab; +#ifdef PARTICLE_ANISOTROPY if (aniso_flag) { force_body = convert_vector_space_to_body(p, p.f.f); } +#endif for (int j = 0; j < 3; j++) { // Second (deterministic) term of the Eq. (14.39) of Schlick2010. @@ -83,6 +88,7 @@ inline void bd_drag(Particle &p, double dt) { } #endif // PARTICLE_ANISOTROPY } +#ifdef PARTICLE_ANISOTROPY if (aniso_flag) { delta_pos_lab = convert_vector_body_to_space(p, delta_pos_body); for (int j = 0; j < 3; j++) { @@ -94,6 +100,7 @@ inline void bd_drag(Particle &p, double dt) { } } } +#endif // PARTICLE_ANISOTROPY } /** Set the terminal velocity driven by the conservative forces drag.*/ @@ -108,9 +115,12 @@ inline void bd_drag_vel(Particle &p, double dt) { // The friction tensor Z from the eq. (14.31) of Schlick2010: Thermostat::GammaType local_gamma; +#ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{}) { local_gamma = p.p.gamma; - } else { + } else +#endif + { local_gamma = langevin_gamma; } @@ -127,14 +137,16 @@ inline void bd_drag_vel(Particle &p, double dt) { Utils::Vector3d force_body; Utils::Vector3d vel_body, vel_lab; +#ifdef PARTICLE_ANISOTROPY if (aniso_flag) { force_body = convert_vector_space_to_body(p, p.f.f); } +#endif for (int j = 0; j < 3; j++) { // First (deterministic) term of the eq. (14.34) of Schlick2010 taking // into account eq. (14.35). Only conservative part of the force is used - // here NOTE: velocity is assigned here and propagated by thermal part + // here. NOTE: velocity is assigned here and propagated by thermal part // further on top of it #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { @@ -152,16 +164,17 @@ inline void bd_drag_vel(Particle &p, double dt) { } #endif } -#else +#else // PARTICLE_ANISOTROPY #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += p.f.f[j] * dt / (local_gamma); + p.m.v[j] = p.f.f[j] / (local_gamma); } #endif // PARTICLE_ANISOTROPY } +#ifdef PARTICLE_ANISOTROPY if (aniso_flag) { vel_lab = convert_vector_body_to_space(p, vel_body); for (int j = 0; j < 3; j++) { @@ -178,6 +191,7 @@ inline void bd_drag_vel(Particle &p, double dt) { #endif } } +#endif // PARTICLE_ANISOTROPY } /** Propagate the positions: random walk part.*/ @@ -201,7 +215,7 @@ void bd_random_walk(Particle &p, double dt) { // Just a NAN setter, technical variable: extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults - Thermostat::GammaType brown_sigma_pos_temp_inv; + Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_inv; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -281,9 +295,11 @@ void bd_random_walk(Particle &p, double dt) { } } +#ifdef PARTICLE_ANISOTROPY if (aniso_flag) { delta_pos_lab = convert_vector_body_to_space(p, delta_pos_body); } +#endif for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES @@ -312,7 +328,7 @@ inline void bd_random_walk_vel(Particle &p, double dt) { // afterwards, Pottier2010 extern double brown_sigma_vel; // first, set defaults - double brown_sigma_vel_temp; + double brown_sigma_vel_temp = brown_sigma_vel; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -358,9 +374,12 @@ inline void bd_random_walk_vel(Particle &p, double dt) { void bd_drag_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; +#ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; - } else { + } else +#endif + { local_gamma = langevin_gamma_rotation; } @@ -399,9 +418,12 @@ void bd_drag_rot(Particle &p, double dt) { void bd_drag_vel_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; +#ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; - } else { + } else +#endif + { local_gamma = langevin_gamma_rotation; } @@ -438,7 +460,7 @@ void bd_random_walk_rot(Particle &p, double dt) { extern Thermostat::GammaType brown_sigma_pos_rotation_inv; extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults - Thermostat::GammaType brown_sigma_pos_temp_inv; + Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -524,7 +546,7 @@ void bd_random_walk_rot(Particle &p, double dt) { void bd_random_walk_vel_rot(Particle &p, double dt) { extern double brown_sigma_vel_rotation; // first, set defaults - double brown_sigma_vel_temp; + double brown_sigma_vel_temp = brown_sigma_vel_rotation; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE diff --git a/testsuite/python/langevin_thermostat.py b/testsuite/python/langevin_thermostat.py index 8e2e4f5d658..8a45d725d9c 100644 --- a/testsuite/python/langevin_thermostat.py +++ b/testsuite/python/langevin_thermostat.py @@ -249,7 +249,8 @@ def test_04__global_langevin(self): # Large time-step is OK for BD. system.time_step = 7.214 system.part[:].v = np.zeros((3)) - system.part[:].omega_body = np.zeros((3)) + if espressomd.has_features("ROTATION"): + system.part[:].omega_body = np.zeros((3)) system.thermostat.turn_off() system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=41) system.integrator.set_brownian_dynamics() From 2a62b41bd6517dff3615d01edcf5579bde0a0d3b Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Sun, 1 Dec 2019 00:43:35 +0100 Subject: [PATCH 104/150] Unset the unused variable --- src/core/integrators/brownian_inline.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 7765a69d752..6f02ba4a777 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -46,7 +46,7 @@ inline void bd_drag(Particle &p, double dt) { local_gamma = langevin_gamma; } - bool aniso_flag = true; // particle anisotropy flag + bool aniso_flag; // particle anisotropy flag #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. @@ -124,7 +124,7 @@ inline void bd_drag_vel(Particle &p, double dt) { local_gamma = langevin_gamma; } - bool aniso_flag = true; // particle anisotropy flag + bool aniso_flag; // particle anisotropy flag #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. @@ -257,7 +257,7 @@ void bd_random_walk(Particle &p, double dt) { } #endif /* LANGEVIN_PER_PARTICLE */ - bool aniso_flag = true; // particle anisotropy flag + bool aniso_flag; // particle anisotropy flag #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. From d16a340e14ff04080673ae1f1ebacb96f86fa967 Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Sun, 1 Dec 2019 01:03:06 +0100 Subject: [PATCH 105/150] Trigger From e611efbf625d2d6963545c39e66fe6fa2e93792d Mon Sep 17 00:00:00 2001 From: Bogdan Tanygin Date: Sun, 1 Dec 2019 10:45:55 +0100 Subject: [PATCH 106/150] Refactoring for unused values --- src/core/integrators/brownian_inline.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 6f02ba4a777..090650c1129 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -52,8 +52,6 @@ inline void bd_drag(Particle &p, double dt) { // Particle frictional isotropy check. aniso_flag = (local_gamma[0] != local_gamma[1]) || (local_gamma[1] != local_gamma[2]); -#else - aniso_flag = false; #endif Utils::Vector3d force_body; @@ -130,8 +128,6 @@ inline void bd_drag_vel(Particle &p, double dt) { // Particle frictional isotropy check. aniso_flag = (local_gamma[0] != local_gamma[1]) || (local_gamma[1] != local_gamma[2]); -#else - aniso_flag = false; #endif Utils::Vector3d force_body; @@ -327,8 +323,7 @@ inline void bd_random_walk_vel(Particle &p, double dt) { // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs // afterwards, Pottier2010 extern double brown_sigma_vel; - // first, set defaults - double brown_sigma_vel_temp = brown_sigma_vel; + double brown_sigma_vel_temp; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -339,6 +334,9 @@ inline void bd_random_walk_vel(Particle &p, double dt) { } else { brown_sigma_vel_temp = brown_sigma_vel; } +#else + // defaults + brown_sigma_vel_temp = brown_sigma_vel; #endif /* LANGEVIN_PER_PARTICLE */ Utils::Vector3d noise = v_noise_g(p.p.identity, RNGSalt::BROWNIAN); @@ -545,8 +543,7 @@ void bd_random_walk_rot(Particle &p, double dt) { */ void bd_random_walk_vel_rot(Particle &p, double dt) { extern double brown_sigma_vel_rotation; - // first, set defaults - double brown_sigma_vel_temp = brown_sigma_vel_rotation; + double brown_sigma_vel_temp; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -557,6 +554,9 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { } else { brown_sigma_vel_temp = brown_sigma_vel_rotation; } +#else + // set defaults + brown_sigma_vel_temp = brown_sigma_vel_rotation; #endif /* LANGEVIN_PER_PARTICLE */ Utils::Vector3d domega; From 6a86e449b6ed6261ba7b7a540c04199ba1f6c3df Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Mon, 20 Jan 2020 17:31:12 +0100 Subject: [PATCH 107/150] Core: Add RNG salts for all different randoms used in Brownian dynamics --- src/core/integrators/brownian_inline.hpp | 8 ++++---- src/core/random.hpp | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 4fced1e78af..1e074bf6532 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -268,7 +268,7 @@ void bd_random_walk(Particle &p, double dt) { // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared // magnitude defined in the second eq. (14.38), Schlick2010. - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(),p.p.identity); + Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(),p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -340,7 +340,7 @@ inline void bd_random_walk_vel(Particle &p, double dt) { brown_sigma_vel_temp = brown_sigma_vel; #endif /* LANGEVIN_PER_PARTICLE */ - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.identity()); + Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.identity()); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -502,7 +502,7 @@ void bd_random_walk_rot(Particle &p, double dt) { #endif /* LANGEVIN_PER_PARTICLE */ Utils::Vector3d dphi = {0.0, 0.0, 0.0}; - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.p.identity); + Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -561,7 +561,7 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { #endif /* LANGEVIN_PER_PARTICLE */ Utils::Vector3d domega; - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.p.identity); + Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) diff --git a/src/core/random.hpp b/src/core/random.hpp index 32bf6a9c8b2..0ec807de48f 100644 --- a/src/core/random.hpp +++ b/src/core/random.hpp @@ -50,8 +50,10 @@ enum class RNGSalt : uint64_t { PARTICLES, LANGEVIN, LANGEVIN_ROT, - BROWNIAN, - BROWNIAN_ROT, + BROWNIAN_WALK, + BROWNIAN_INC, + BROWNIAN_ROT_INC, + BROWNIAN_ROT_WALK, SALT_DPD, THERMALIZED_BOND }; From fd04ef14dced94a27077212486f5d67b3cc7a2e5 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Mon, 20 Jan 2020 17:33:09 +0100 Subject: [PATCH 108/150] Core: Increment Langevin counter for Brownian dynamics --- src/core/integrate.cpp | 2 +- testsuite/python/CMakeLists.txt | 1 + testsuite/python/brownian_dynamics.py | 300 ++++++++++++++++++++++++++ 3 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 testsuite/python/brownian_dynamics.py diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 568cd7c8778..4beaa0f2b94 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -324,7 +324,7 @@ void integrate_vv(int n_steps, int reuse_forces) { /************************************************************/ void philox_counter_increment() { - if (thermo_switch & THERMO_LANGEVIN) { + if (thermo_switch & THERMO_LANGEVIN or thermo_switch & THERMO_BROWNIAN) { langevin_rng_counter_increment(); } if (thermo_switch & THERMO_DPD) { diff --git a/testsuite/python/CMakeLists.txt b/testsuite/python/CMakeLists.txt index b21ada65540..721ccdfc8eb 100644 --- a/testsuite/python/CMakeLists.txt +++ b/testsuite/python/CMakeLists.txt @@ -113,6 +113,7 @@ python_test(FILE ek_eof_one_species_y.py MAX_NUM_PROC 1 LABELS gpu) python_test(FILE ek_eof_one_species_z.py MAX_NUM_PROC 1 LABELS gpu) python_test(FILE exclusions.py MAX_NUM_PROC 2) python_test(FILE langevin_thermostat.py MAX_NUM_PROC 1) +python_test(FILE brownian_dynamics.py MAX_NUM_PROC 1) python_test(FILE nsquare.py MAX_NUM_PROC 4) python_test(FILE virtual_sites_relative.py MAX_NUM_PROC 2) python_test(FILE virtual_sites_tracers.py MAX_NUM_PROC 2) diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py new file mode 100644 index 00000000000..13213b88e8c --- /dev/null +++ b/testsuite/python/brownian_dynamics.py @@ -0,0 +1,300 @@ +# +# Copyright (C) 2013-2019 The ESPResSo project +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +import unittest as ut +import unittest_decorators as utx +import espressomd +import numpy as np +from espressomd.accumulators import Correlator, TimeSeries +from espressomd.observables import ParticleVelocities, ParticleBodyAngularVelocities, ParticlePositions +from tests_common import single_component_maxwell + + +class BrownianDynamics(ut.TestCase): + + """Tests velocity distributions and diffusion for Brownian Dynamics""" + system = espressomd.System(box_l=[1.0, 1.0, 1.0]) + system.cell_system.set_domain_decomposition(use_verlet_lists=True) + system.cell_system.skin = 0 + system.seed = range(system.cell_system.get_state()["n_nodes"]) + system.periodicity = [0, 0, 0] + system.integrator.set_brownian_dynamics() + + @classmethod + def setUpClass(cls): + np.random.seed(42) + + def check_velocity_distribution(self, vel, minmax, n_bins, error_tol, kT): + """check the recorded particle distributions in velocity against a + histogram with n_bins bins. Drop velocities outside minmax. Check + individual histogram bins up to an accuracy of error_tol against the + analytical result for kT.""" + for i in range(3): + hist = np.histogram( + vel[:, i], range=(-minmax, minmax), bins=n_bins, density=False) + data = hist[0] / float(vel.shape[0]) + bins = hist[1] + for j in range(n_bins): + found = data[j] + expected = single_component_maxwell(bins[j], bins[j + 1], kT) + self.assertLessEqual(abs(found - expected), error_tol) + + def test_00_verify_single_component_maxwell(self): + """Verifies the normalization of the analytical expression.""" + self.assertLessEqual( + abs(single_component_maxwell(-10, 10, 4.) - 1.), 1E-4) + + def check_vel_dist_global_temp(self, recalc_forces, loops): + """Test velocity distribution for global temperature parameters. + + Parameters + ---------- + recalc_forces : :obj:`bool` + True if the forces should be recalculated after every step. + loops : :obj:`int` + Number of sampling loops + """ + N = 200 + system = self.system + system.part.clear() + system.time_step = 1.6 + + # Place particles + system.part.add(pos=np.random.random((N, 3))) + + # Enable rotation if compiled in + if espressomd.has_features("ROTATION"): + system.part[:].rotation = [1, 1, 1] + + kT = 1.1 + gamma = 3.5 + system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=41) + + # Warmup + system.integrator.run(20) + + # Sampling + v_stored = np.zeros((N * loops, 3)) + omega_stored = np.zeros((N * loops, 3)) + for i in range(loops): + system.integrator.run(1, recalc_forces=recalc_forces) + v_stored[i * N:(i + 1) * N, :] = system.part[:].v + if espressomd.has_features("ROTATION"): + omega_stored[i * N:(i + 1) * N, :] = system.part[:].omega_body + + v_minmax = 5 + bins = 4 + error_tol = 0.01 + self.check_velocity_distribution( + v_stored, v_minmax, bins, error_tol, kT) + if espressomd.has_features("ROTATION"): + self.check_velocity_distribution( + omega_stored, v_minmax, bins, error_tol, kT) + + def test_vel_dist_global_temp(self): + """Test velocity distribution for global temperature.""" + self.check_vel_dist_global_temp(False, loops=1500) + + def test_vel_dist_global_temp_initial_forces(self): + """Test velocity distribution for global Langevin parameters, + when using the initial force calculation. + """ + self.check_vel_dist_global_temp(True, loops=170) + + @utx.skipIfMissingFeatures("LANGEVIN_PER_PARTICLE") + def test_05__langevin_per_particle(self): + """Test Brownian dynamics with particle specific kT and gamma. Covers all combinations of + particle specific gamma and temp set or not set. + """ + N = 400 + system = self.system + system.part.clear() + system.time_step = 1.9 + system.part.add(pos=np.random.random((N, 3))) + if espressomd.has_features("ROTATION"): + system.part[:].rotation = [1, 1, 1] + + kT = 0.9 + gamma = 3.2 + gamma2 = 14.3 + kT2 = 1.5 + system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=41) + # Set different kT on 2nd half of particles + system.part[int(N / 2):].temp = kT2 + # Set different gamma on half of the particles (overlap over both kTs) + if espressomd.has_features("PARTICLE_ANISOTROPY"): + system.part[int(N / 4):int(3 * N / 4)].gamma = 3 * [gamma2] + else: + system.part[int(N / 4):int(3 * N / 4)].gamma = gamma2 + + system.integrator.run(50) + loops = 300 + + v_kT = np.zeros((int(N / 2) * loops, 3)) + v_kT2 = np.zeros((int(N / 2 * loops), 3)) + + if espressomd.has_features("ROTATION"): + omega_kT = np.zeros((int(N / 2) * loops, 3)) + omega_kT2 = np.zeros((int(N / 2 * loops), 3)) + + for i in range(loops): + system.integrator.run(1) + v_kT[int(i * N / 2):int((i + 1) * N / 2), + :] = system.part[:int(N / 2)].v + v_kT2[int(i * N / 2):int((i + 1) * N / 2), + :] = system.part[int(N / 2):].v + + if espressomd.has_features("ROTATION"): + omega_kT[int(i * N / 2):int((i + 1) * N / 2), :] = \ + system.part[:int(N / 2)].omega_body + omega_kT2[int(i * N / 2):int((i + 1) * N / 2), :] = \ + system.part[int(N / 2):].omega_body + v_minmax = 5 + bins = 4 + error_tol = 0.012 + self.check_velocity_distribution(v_kT, v_minmax, bins, error_tol, kT) + self.check_velocity_distribution(v_kT2, v_minmax, bins, error_tol, kT2) + + if espressomd.has_features("ROTATION"): + self.check_velocity_distribution( + omega_kT, v_minmax, bins, error_tol, kT) + self.check_velocity_distribution( + omega_kT2, v_minmax, bins, error_tol, kT2) + + def setup_diff_mass_rinertia(self, p): + if espressomd.has_features("MASS"): + p.mass = 0.5 + if espressomd.has_features("ROTATION"): + p.rotation = [1, 1, 1] + # Make sure rinertia does not change diff coeff + if espressomd.has_features("ROTATIONAL_INERTIA"): + p.rinertia = [0.4, 0.4, 0.4] + + + def test_msd_global_temp(self): + """Tests diffusion via MSD for global gamma and temeprature""" + + gamma = 9.4 + kT = 0.37 + dt = 0.5 + + system = self.system + system.part.clear() + p = system.part.add(pos=(0, 0, 0), id=0) + system.time_step = dt + system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=42) + system.cell_system.skin = 0.4 + + pos_obs = ParticlePositions(ids=(0,)) + + c_pos = Correlator(obs1=pos_obs, tau_lin=16, tau_max=100., delta_N=10, + corr_operation="square_distance_componentwise", + compress1="discard1") + system.auto_update_accumulators.add(c_pos) + + system.integrator.run(500000) + + c_pos.finalize() + + + # Check MSD + msd = c_pos.result() + + + def expected_msd(x): + return 2. * kT / gamma * x + + + for i in range(2, 6): + np.testing.assert_allclose(msd[i, 2:5], expected_msd(msd[i, 0]),rtol=0.02) + + @utx.skipIfMissingFeatures("VIRTUAL_SITES") + def test_07__virtual(self): + system = self.system + system.time_step = 0.01 + system.part.clear() + + virtual = system.part.add(pos=[0, 0, 0], virtual=True, v=[1, 0, 0]) + physical = system.part.add(pos=[0, 0, 0], virtual=False, v=[1, 0, 0]) + + system.thermostat.set_brownian( + kT=0, gamma=1, gamma_rotation=1., act_on_virtual=False, seed=41) + + system.integrator.run(1) + + np.testing.assert_almost_equal(np.copy(virtual.v), [1, 0, 0]) + np.testing.assert_almost_equal(np.copy(physical.v), [0, 0, 0]) + + system.thermostat.set_brownian( + kT=0, gamma=1, gamma_rotation=1., act_on_virtual=True, seed=41) + system.integrator.run(1) + + np.testing.assert_almost_equal(np.copy(virtual.f), [0, 0, 0]) + np.testing.assert_almost_equal(np.copy(physical.f), [0, 0, 0]) + + def test_08__noise_correlation(self): + """Checks that the Langevin noise is uncorrelated""" + + system = self.system + system.part.clear() + system.time_step = 0.01 + system.cell_system.skin = 0.1 + system.part.add(id=(1, 2), pos=np.zeros((2, 3))) + vel_obs = ParticleVelocities(ids=system.part[:].id) + vel_series = TimeSeries(obs=vel_obs) + system.auto_update_accumulators.add(vel_series) + if espressomd.has_features("ROTATION"): + system.part[:].rotation = (1, 1, 1) + omega_obs = ParticleBodyAngularVelocities(ids=system.part[:].id) + omega_series = TimeSeries(obs=omega_obs) + system.auto_update_accumulators.add(omega_series) + + kT = 3.2 + system.thermostat.set_brownian(kT=kT, gamma=2.1, seed=17) + steps = int(1e6) + system.integrator.run(steps) + + # test translational noise correlation + vel = np.array(vel_series.time_series()) + for i in range(6): + for j in range(i, 6): + corrcoef = np.dot(vel[:, i], vel[:, j]) / steps / kT + if i == j: + self.assertAlmostEqual(corrcoef, 1.0, delta=0.04) + else: + self.assertLessEqual(np.abs(corrcoef), 0.04) + + # test rotational noise correlation + if espressomd.has_features("ROTATION"): + omega = np.array(omega_series.time_series()) + for i in range(6): + for j in range(6): + corrcoef = np.dot(omega[:, i], omega[:, j]) / steps / kT + if i == j: + self.assertAlmostEqual(corrcoef, 1.0, delta=0.04) + else: + self.assertLessEqual(np.abs(corrcoef), 0.04) + # translational and angular velocities should be independent + for i in range(6): + for j in range(6): + corrcoef = np.dot(vel[:, i], omega[:, j]) / steps / kT + self.assertLessEqual(np.abs(corrcoef), 0.04) + + +if __name__ == "__main__": + ut.main() From adce6a96be8516bee14cf7acdc08265fc74e4c41 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Mon, 20 Jan 2020 17:33:48 +0100 Subject: [PATCH 109/150] Py: Cope with Brownian-dynamics/ Langevin entanglement --- src/python/espressomd/thermostat.pyx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 3f5250c5311..baf99982c4d 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -539,8 +539,13 @@ cdef class Thermostat: """ - self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) + # Note: hack due to entanglement of Brownian dynamics and Langevin thermostat + # The setup code fro Brownian dynamics mis-uses the Langevin setup. + # This needs to be changed global thermo_switch + thermo_switch = (thermo_switch & (~THERMO_BROWNIAN)) + + self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) # this is safe because this combination of thermostats is not # allowed thermo_switch = (thermo_switch & (~THERMO_LANGEVIN)) From 0361b0e9fb1a4792c1f5b7d0dc31389cb7465a24 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Mon, 20 Jan 2020 17:38:37 +0100 Subject: [PATCH 110/150] Formatting --- src/core/integrators/brownian_inline.hpp | 14 +++++---- src/core/random.hpp | 37 ++++++++++++------------ src/python/espressomd/thermostat.pyx | 2 +- testsuite/python/brownian_dynamics.py | 25 +++++++--------- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 1e074bf6532..e651dc82a1f 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -23,8 +23,8 @@ #ifndef BROWNIAN_INLINE_HPP #define BROWNIAN_INLINE_HPP -#include "thermostat.hpp" #include "random.hpp" +#include "thermostat.hpp" /** Propagate position: viscous drag driven by conservative forces.*/ /*********************************************************/ @@ -268,7 +268,8 @@ void bd_random_walk(Particle &p, double dt) { // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared // magnitude defined in the second eq. (14.38), Schlick2010. - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(),p.p.identity); + Utils::Vector3d noise = Random::v_noise_g( + langevin_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -340,7 +341,8 @@ inline void bd_random_walk_vel(Particle &p, double dt) { brown_sigma_vel_temp = brown_sigma_vel; #endif /* LANGEVIN_PER_PARTICLE */ - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.identity()); + Utils::Vector3d noise = Random::v_noise_g( + langevin_rng_counter->value(), p.identity()); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -502,7 +504,8 @@ void bd_random_walk_rot(Particle &p, double dt) { #endif /* LANGEVIN_PER_PARTICLE */ Utils::Vector3d dphi = {0.0, 0.0, 0.0}; - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.p.identity); + Utils::Vector3d noise = Random::v_noise_g( + langevin_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -561,7 +564,8 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { #endif /* LANGEVIN_PER_PARTICLE */ Utils::Vector3d domega; - Utils::Vector3d noise = Random::v_noise_g(langevin_rng_counter->value(), p.p.identity); + Utils::Vector3d noise = Random::v_noise_g( + langevin_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) diff --git a/src/core/random.hpp b/src/core/random.hpp index 0ec807de48f..48329767a73 100644 --- a/src/core/random.hpp +++ b/src/core/random.hpp @@ -70,7 +70,8 @@ namespace Random { * */ template -Utils::Vector philox_4_uint64s(uint64_t counter, int key1, int key2 = 0) { +Utils::Vector philox_4_uint64s(uint64_t counter, int key1, + int key2 = 0) { using rng_type = r123::Philox4x64; using ctr_type = rng_type::ctr_type; @@ -82,7 +83,7 @@ Utils::Vector philox_4_uint64s(uint64_t counter, int key1, int key2 auto const id2 = static_cast(key2); const key_type k{id1, id2}; - auto const res =rng_type{}(c, k); + auto const res = rng_type{}(c, k); return {res[0], res[1], res[2], res[3]}; } @@ -111,13 +112,13 @@ Utils::Vector3d v_noise(uint64_t counter, int key1, int key2 = 0) { * * Mean = 0, standard deviation = 1.0 * Based on the Philox RNG using 4x64 bits. - * The Box-Muller transform is used to convert from uniform to normal + * The Box-Muller transform is used to convert from uniform to normal * distribution. The transform is only valid, if the uniformly distributed * random numbers are not zero (approx one in 2^64). To avoid this case, * such numbers are replaced by std::numeric_limits::min() * This breaks statistics in rare cases but allows for consistent RNG * counters across MPI ranks. - * + * * @param counter counter for the random number generation * @param key1 key for random number generation * @param key2 key for random number generation @@ -131,22 +132,23 @@ inline Utils::Vector3d v_noise_g(uint64_t counter, int key1, int key2 = 0) { auto const noise = philox_4_uint64s(counter, key1, key2); using Utils::uniform; - Utils::Vector4d u{uniform(noise[0]), uniform(noise[1]), uniform(noise[2]), uniform(noise[3])}; - + Utils::Vector4d u{uniform(noise[0]), uniform(noise[1]), uniform(noise[2]), + uniform(noise[3])}; + // Replace zeros from uniformly distributed numbers (see doc string) static const double epsilon = std::numeric_limits::min(); - for (int i=0; i<4; i++) - if (u[i] uniform_real_distribution; @@ -217,5 +219,4 @@ inline double d_random() { return uniform_real_distribution(generator); } - #endif diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index baf99982c4d..032fb7ed90f 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -544,7 +544,7 @@ cdef class Thermostat: # This needs to be changed global thermo_switch thermo_switch = (thermo_switch & (~THERMO_BROWNIAN)) - + self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) # this is safe because this combination of thermostats is not # allowed diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py index 13213b88e8c..ad7daed1d33 100644 --- a/testsuite/python/brownian_dynamics.py +++ b/testsuite/python/brownian_dynamics.py @@ -185,44 +185,41 @@ def setup_diff_mass_rinertia(self, p): if espressomd.has_features("ROTATIONAL_INERTIA"): p.rinertia = [0.4, 0.4, 0.4] - def test_msd_global_temp(self): """Tests diffusion via MSD for global gamma and temeprature""" gamma = 9.4 kT = 0.37 dt = 0.5 - + system = self.system system.part.clear() p = system.part.add(pos=(0, 0, 0), id=0) system.time_step = dt system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=42) system.cell_system.skin = 0.4 - + pos_obs = ParticlePositions(ids=(0,)) - + c_pos = Correlator(obs1=pos_obs, tau_lin=16, tau_max=100., delta_N=10, corr_operation="square_distance_componentwise", compress1="discard1") system.auto_update_accumulators.add(c_pos) - + system.integrator.run(500000) - + c_pos.finalize() - - + # Check MSD msd = c_pos.result() - - + def expected_msd(x): return 2. * kT / gamma * x - - + for i in range(2, 6): - np.testing.assert_allclose(msd[i, 2:5], expected_msd(msd[i, 0]),rtol=0.02) - + np.testing.assert_allclose( + msd[i, 2:5], expected_msd(msd[i, 0]), rtol=0.02) + @utx.skipIfMissingFeatures("VIRTUAL_SITES") def test_07__virtual(self): system = self.system From e78dfb8bdbca5b501b2d585b9a7123568dc7ab64 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Mon, 20 Jan 2020 17:57:58 +0100 Subject: [PATCH 111/150] Testsuite: Brownian dynamics, minor fixes --- testsuite/python/brownian_dynamics.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py index ad7daed1d33..abaa0bd4157 100644 --- a/testsuite/python/brownian_dynamics.py +++ b/testsuite/python/brownian_dynamics.py @@ -199,7 +199,7 @@ def test_msd_global_temp(self): system.thermostat.set_brownian(kT=kT, gamma=gamma, seed=42) system.cell_system.skin = 0.4 - pos_obs = ParticlePositions(ids=(0,)) + pos_obs = ParticlePositions(ids=(p.id,)) c_pos = Correlator(obs1=pos_obs, tau_lin=16, tau_max=100., delta_N=10, corr_operation="square_distance_componentwise", @@ -212,6 +212,8 @@ def test_msd_global_temp(self): # Check MSD msd = c_pos.result() + system.auto_update_accumulators.clear() + def expected_msd(x): return 2. * kT / gamma * x @@ -251,7 +253,7 @@ def test_08__noise_correlation(self): system.part.clear() system.time_step = 0.01 system.cell_system.skin = 0.1 - system.part.add(id=(1, 2), pos=np.zeros((2, 3))) + system.part.add(id=(0, 1), pos=np.zeros((2, 3))) vel_obs = ParticleVelocities(ids=system.part[:].id) vel_series = TimeSeries(obs=vel_obs) system.auto_update_accumulators.add(vel_series) @@ -265,6 +267,7 @@ def test_08__noise_correlation(self): system.thermostat.set_brownian(kT=kT, gamma=2.1, seed=17) steps = int(1e6) system.integrator.run(steps) + system.auto_update_accumulators.clear() # test translational noise correlation vel = np.array(vel_series.time_series()) From cc831ec94df4a1a05dc7bff198cf32cef2fab0b4 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Mon, 20 Jan 2020 18:27:21 +0100 Subject: [PATCH 112/150] Formatting --- testsuite/python/brownian_dynamics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py index abaa0bd4157..0b06dac8989 100644 --- a/testsuite/python/brownian_dynamics.py +++ b/testsuite/python/brownian_dynamics.py @@ -214,7 +214,6 @@ def test_msd_global_temp(self): msd = c_pos.result() system.auto_update_accumulators.clear() - def expected_msd(x): return 2. * kT / gamma * x From 138fe0060d725e8294a60cf98b15869a3867baf3 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Tue, 21 Jan 2020 07:53:51 +0100 Subject: [PATCH 113/150] Revert rotational-diffusion-aniso test to before merge and use low peclet nr --- .../python/rotational-diffusion-aniso.py | 118 +++++++++++++----- 1 file changed, 84 insertions(+), 34 deletions(-) diff --git a/testsuite/python/rotational-diffusion-aniso.py b/testsuite/python/rotational-diffusion-aniso.py index 425c0f9f6b8..9492e87248b 100644 --- a/testsuite/python/rotational-diffusion-aniso.py +++ b/testsuite/python/rotational-diffusion-aniso.py @@ -22,10 +22,11 @@ import tests_common -@utx.skipIfMissingFeatures(["PARTICLE_ANISOTROPY", +@utx.skipIfMissingFeatures(["ROTATION", "PARTICLE_ANISOTROPY", "ROTATIONAL_INERTIA", "DIPOLES"]) class RotDiffAniso(ut.TestCase): longMessage = True + round_error_prec = 1E-14 # Handle for espresso system system = espressomd.System(box_l=[1.0, 1.0, 1.0]) system.cell_system.skin = 5.0 @@ -43,11 +44,15 @@ class RotDiffAniso(ut.TestCase): def setUp(self): self.system.time = 0.0 self.system.part.clear() + if "BROWNIAN_DYNAMICS" in espressomd.features(): + self.system.thermostat.turn_off() + # the default integrator is supposed implicitly + self.system.integrator.set_nvt() - def rot_diffusion_param_setup(self, n): + def add_particles_setup(self, n): """ - Setup the parameters for the rotational diffusion - test check_rot_diffusion(). + Adding particles according to the + previously set parameters. Parameters ---------- @@ -56,18 +61,21 @@ def rot_diffusion_param_setup(self, n): """ - # Time - # The time step should be less than t0 ~ mass / gamma - self.system.time_step = 3E-3 + for ind in range(n): + part_pos = np.random.random(3) * self.box + self.system.part.add(rotation=(1, 1, 1), id=ind, + pos=part_pos) + self.system.part[ind].rinertia = self.J + if espressomd.has_features("ROTATION"): + self.system.part[ind].omega_body = [0.0, 0.0, 0.0] - # Space - box = 10.0 - self.system.box_l = box, box, box - self.system.periodicity = [0, 0, 0] + def set_anisotropic_param(self): + """ + Select parameters for anisotropic particles. + + """ # NVT thermostat - # Just some temperature range to cover by the test: - self.kT = np.random.uniform(1.0, 1.5) # Note: here & hereinafter specific variations in the random parameter # ranges are related to the test execution duration to achieve the # required statistical averages faster. The friction gamma_global should @@ -84,7 +92,7 @@ def rot_diffusion_param_setup(self, n): # eq. (10.2.26) [N. Pottier, doi:10.1007/s10955-010-0114-6 (2010)]. self.gamma_global = 1E2 * np.random.uniform(0.35, 1.05, (3)) - # Particles + # Particles' properties # As far as the problem characteristic time is t0 ~ J / gamma # and the Langevin equation finite-difference approximation is stable # only for time_step << t0, it is needed to set the moment of inertia @@ -94,11 +102,46 @@ def rot_diffusion_param_setup(self, n): # too much of the CPU time: the in silico time should clock over the # t0. self.J = np.random.uniform(1.5, 16.5, (3)) - for ind in range(n): - part_pos = np.random.random(3) * box - self.system.part.add(rotation=(1, 1, 1), id=ind, rinertia=self.J, - pos=part_pos) - self.system.part[ind].omega_body = [0.0, 0.0, 0.0] + + def set_isotropic_param(self): + """ + Select parameters for isotropic particles. + + Parameters + ---------- + + """ + + # NVT thermostat + # see the comments in set_anisotropic_param() + self.gamma_global[0] = 1E2 * np.random.uniform(0.35, 1.05) + self.gamma_global[1] = self.gamma_global[0] + self.gamma_global[2] = self.gamma_global[0] + # Particles' properties + # see the comments in set_anisotropic_param() + self.J[0] = np.random.uniform(1.5, 16.5) + self.J[1] = self.J[0] + self.J[2] = self.J[0] + + def rot_diffusion_param_setup(self): + """ + Setup the parameters for the rotational diffusion + test check_rot_diffusion(). + + """ + + # Time + # The time step should be less than t0 ~ mass / gamma + self.system.time_step = 3E-3 + + # Space + self.box = 10.0 + self.system.box_l = 3 * [self.box] + self.system.periodicity = [0, 0, 0] + + # NVT thermostat + # Just some temperature range to cover by the test: + self.kT = np.random.uniform(0.5, 1.5) def check_rot_diffusion(self, n): """ @@ -239,6 +282,11 @@ def check_rot_diffusion(self, n): if i != j: D1D1 += D[i] * D[j] D1D1 /= 6.0 + # Technical workaround of a digital arithmetic issue for isotropic + # particle + if np.absolute((D0**2 - D1D1) / (D0**2 + D1D1) + ) < self.round_error_prec: + D1D1 *= (1.0 - 2.0 * self.round_error_prec) # Eq. (32) [Perrin1936]. dcosjj2_validate = 1. / 3. + (1. / 3.) * (1. + (D - D0) / (2. * np.sqrt(D0**2 - D1D1))) \ * np.exp(-6. * (D0 - np.sqrt(D0**2 - D1D1)) * self.system.time) \ @@ -302,8 +350,9 @@ def check_rot_diffusion(self, n): 'rotational diffusion is too large: {2}' .format(i, j, dcosij2_dev[i, j])) + # Langevin Dynamics / Anisotropic def test_case_00(self): - n = 300 + n = 800 self.rot_diffusion_param_setup() self.set_anisotropic_param() self.add_particles_setup(n) @@ -314,8 +363,8 @@ def test_case_00(self): # Langevin Dynamics / Isotropic def test_case_01(self): - n = 300 - self.rot_diffusion_param_setup(n) + n = 800 + self.rot_diffusion_param_setup() self.set_isotropic_param() self.add_particles_setup(n) self.system.thermostat.set_langevin( @@ -323,18 +372,19 @@ def test_case_01(self): # Actual integration and validation run self.check_rot_diffusion(n) - # Brownian Dynamics / Isotropic - def test_case_10(self): - n = 300 - self.system.thermostat.turn_off() - self.rot_diffusion_param_setup() - self.set_isotropic_param() - self.add_particles_setup(n) - self.system.thermostat.set_brownian( - kT=self.kT, gamma=self.gamma_global, seed=42) - self.system.integrator.set_brownian_dynamics() - # Actual integration and validation run - self.check_rot_diffusion(n) + if "BROWNIAN_DYNAMICS" in espressomd.features(): + # Brownian Dynamics / Isotropic + def test_case_10(self): + n = 800 + self.system.thermostat.turn_off() + self.rot_diffusion_param_setup() + self.set_isotropic_param() + self.add_particles_setup(n) + self.system.thermostat.set_brownian( + kT=self.kT, gamma=self.gamma_global, seed=42) + self.system.integrator.set_brownian_dynamics() + # Actual integration and validation run + self.check_rot_diffusion(n) if __name__ == '__main__': From 379bff1562f5d777c4aa358d89f2e2ad3071c71b Mon Sep 17 00:00:00 2001 From: "kodiakhq[bot]" <49736102+kodiakhq[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2020 15:09:41 +0000 Subject: [PATCH 114/150] Tutorial 12: support both pint 0.9 and 10.1 (#3423) Fixes #3420, fixes #3422 --- doc/tutorials/12-constant_pH/12-constant_pH.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/tutorials/12-constant_pH/12-constant_pH.ipynb b/doc/tutorials/12-constant_pH/12-constant_pH.ipynb index 96667cb798f..19f76b21b94 100644 --- a/doc/tutorials/12-constant_pH/12-constant_pH.ipynb +++ b/doc/tutorials/12-constant_pH/12-constant_pH.ipynb @@ -170,7 +170,9 @@ "\n", "# dependent parameters\n", "Box_V = (N_acid/N_A/c_acid)\n", - "Box_L = np.cbrt(Box_V.to('m**3'))*ureg('m')\n", + "Box_L = np.cbrt(Box_V.to('m**3'))\n", + "if tuple(map(int, pint.__version__.split('.'))) < (0, 10):\n", + " Box_L *= ureg('m')\n", "# we shall often need the numerical value of box length in sigma\n", "Box_L_in_sigma = Box_L.to('sigma').magnitude\n", "# unfortunately, pint module cannot handle cube root of m**3, so we need to explicitly set the unit\n", From 4634a6abf15977cfe57e210cc7d1c9e112963732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 21 Jan 2020 19:42:34 +0100 Subject: [PATCH 115/150] Fix typos, code formatting, constants --- doc/sphinx/system_setup.rst | 52 ++++++++++++++-------------- src/core/random.hpp | 5 +-- src/python/espressomd/thermostat.pyx | 16 ++++----- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index 94bcfc572a0..9d93c296725 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -267,15 +267,15 @@ The Langevin thermostat is based on an extension of Newton's equation of motion .. math:: m_i \dot{v}_i(t) = f_i(\{x_j\},v_i,t) - \gamma v_i(t) + \sqrt{2\gamma k_B T} \eta_i(t). -Here, :math:`f_i` are all deterministic forces from interactions, -:math:`\gamma` the bare friction coefficient and :math:`\eta` a random, "thermal" force. +Here, :math:`f_i` are all deterministic forces from interactions, +:math:`\gamma` the bare friction coefficient and :math:`\eta` a random, "thermal" force. The friction term accounts for dissipation in a surrounding fluid whereas -the random force mimics collisions of the particle with solvent molecules +the random force mimics collisions of the particle with solvent molecules at temperature :math:`T` and satisfies .. math:: <\eta(t)> = 0 , <\eta^\alpha_i(t)\eta^\beta_j(t')> = \delta_{\alpha\beta} \delta_{ij}\delta(t-t') -(:math:`<\cdot>` denotes the ensemble average and :math:`\alpha,\beta` are spatial coordinates). +(:math:`<\cdot>` denotes the ensemble average and :math:`\alpha,\beta` are spatial coordinates). In the |es| implementation of the Langevin thermostat, the additional terms only enter in the force calculation. @@ -283,9 +283,9 @@ This reduces the accuracy of the Velocity Verlet integrator by one order in :math:`dt` because forces are now velocity-dependent. The random process :math:`\eta(t)` is discretized by drawing an uncorrelated random number -:math:`\overline{\eta}` for each component of all the particle forces. +:math:`\overline{\eta}` for each component of all the particle forces. The distribution of :math:`\overline{\eta}` is uniform and satisfies - + .. math:: <\overline{\eta}> = 0 , <\overline{\eta}\overline{\eta}> = 1/dt The keyword ``seed`` controls the state of the random number generator (Philox @@ -305,9 +305,9 @@ can be useful, for instance, in high Péclet number active matter systems, where one only wants to thermalize only the rotational degrees of freedom and translational motion is effected by the self-propulsion. -The keywords ``gamma`` and ``gamma_rotate`` can be specified as a scalar, -or, with feature ``PARTICLE_ANISOTROPY`` compiled in, as the three eigenvalues -of the respective friction coefficient tensor. This is enables the simulation of +The keywords ``gamma`` and ``gamma_rotate`` can be specified as a scalar, +or, with feature ``PARTICLE_ANISOTROPY`` compiled in, as the three eigenvalues +of the respective friction coefficient tensor. This is enables the simulation of the anisotropic diffusion of anisotropic colloids (rods, etc.). Using the Langevin thermostat, it is possible to set a temperature and a @@ -324,17 +324,17 @@ The :ref:`Lattice-Boltzmann` thermostat acts similar to the :ref:`Langevin therm .. math:: m_i \dot{v}_i(t) = f_i(\{x_j\},v_i,t) - \gamma (v_i(t)-u(x_i(t),t)) + \sqrt{2\gamma k_B T} \eta_i(t). -where :math:`u(x,t)` is the fluid velocity at position :math:`x` and time :math:`t`. -To preserve momentum, an equal and opposite friction force and random force act on the fluid. +where :math:`u(x,t)` is the fluid velocity at position :math:`x` and time :math:`t`. +To preserve momentum, an equal and opposite friction force and random force act on the fluid. -Numerically the fluid velocity is determined from the lattice-Boltzmann node velocities +Numerically the fluid velocity is determined from the lattice-Boltzmann node velocities by interpolating as described in :ref:`Interpolating velocities`. -The backcoupling of friction forces and noise to the fluid is also done by distributing those forces amongst the nearest LB nodes. +The backcoupling of friction forces and noise to the fluid is also done by distributing those forces amongst the nearest LB nodes. Details for both the interpolation and the force distribution can be found in :cite:`ahlrichs99` and :cite:`duenweg08a`. The LB fluid can be used to thermalize particles, while also including their hydrodynamic interactions. The LB thermostat expects an instance of either :class:`espressomd.lb.LBFluid` or :class:`espressomd.lb.LBFluidGPU`. -Temperature is set via the ``kT`` argument of the LB fluid. +Temperature is set via the ``kT`` argument of the LB fluid. Furthermore a ``seed`` has to be given for the thermalization of the particle coupling. The magnitude of the frictional coupling can be adjusted by @@ -362,8 +362,8 @@ Dissipative Particle Dynamics (DPD) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The DPD thermostat adds friction and noise to the particle -dynamics like the :ref:`Langevin thermostat`, but these -are not applied to every particle individually but instead +dynamics like the :ref:`Langevin thermostat`, but these +are not applied to every particle individually but instead encoded in a dissipative interaction between particles :cite:`soddeman03a`. To realize a complete DPD fluid model in |es|, three parts are needed: @@ -376,7 +376,7 @@ The temperature is set via which takes ``kT`` as the only argument. The friction coefficients and cutoff are controlled via the -:ref:`DPD interaction` on a per type-pair basis. For details +:ref:`DPD interaction` on a per type-pair basis. For details see there. The friction (dissipative) and noise (random) term are coupled via the @@ -444,31 +444,31 @@ The hydrodynamic interactions feature will be available later as a part of the present Brownian Dynamics or implemented separately within the Stokesian Dynamics. -In order to activate the Brownian thermostat the member function +In order to activate the Brownian thermostat, the member function :py:attr:`~espressomd.thermostat.Thermostat.set_brownian` of the thermostat class :class:`espressomd.thermostat.Thermostat` has to be invoked. The system integrator should be also changed. Best explained in an example:: - + import espressomd system = espressomd.System() system.thermostat.set_brownian(kT=1.0, gamma=1.0, seed=41) system.integrator.set_brownian_dynamics() where ``gamma`` (hereinafter :math:`\gamma`) is a viscous friction coefficient. -In terms of the Python interface and setup, Brownian thermostat derives most -properties of the :ref:`Langevin thermostat`. Same feature -``LANGEVIN_PER_PARTICLE`` is using to be able to control the per-particle +In terms of the Python interface and setup, Brownian thermostat derives most +properties of the :ref:`Langevin thermostat`. The feature +``LANGEVIN_PER_PARTICLE`` is used to control the per-particle temperature and the friction coefficient setup. Major differences are its internal integrator implementation and other temporal constraints. The integrator is still a symplectic Velocity Verlet-like one. It is implemented via a viscous drag part and a random walk of both the position and velocity. Due to a nature of the Brownian Dynamics method, its time step :math:`\Delta t` -should be large enough compare to the relaxation time +should be large enough compared to the relaxation time :math:`m/\gamma` where :math:`m` is the particle mass. This requirement is just a conceptual one without specific implementation technical restrictions. -Note, that with all similarities of +Note that with all similarities of Langevin and Brownian Dynamics, the Langevin thermostat temporal constraint is opposite. A velocity is restarting from zero at every step. Formally, the previous step velocity at the beginning of the the :math:`\Delta t` interval @@ -491,11 +491,11 @@ corresponds to a diffusion within the Wiener process: .. math:: \sigma_p^2 = 2 \frac{kT}{\gamma} \cdot \Delta t Each velocity component random walk variance :math:`\sigma_v^2` is defined by the heat -component: +component: .. math:: \sigma_v^2 = \frac{kT}{m} -Note, that the velocity random walk is propagated from zero at each step. +Note that the velocity random walk is propagated from zero at each step. A rotational motion is implemented similarly. Note: the rotational Brownian dynamics implementation is compatible with particles which have diff --git a/src/core/random.hpp b/src/core/random.hpp index 48329767a73..08f02aad059 100644 --- a/src/core/random.hpp +++ b/src/core/random.hpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -60,7 +61,7 @@ enum class RNGSalt : uint64_t { namespace Random { /** - * @brief get 4 random uint 64 fomr the Philox RNG + * @brief get 4 random uint 64 from the Philox RNG * * This uses the Philox PRNG, the state is controlled * by the counter, the salt and two keys. @@ -144,7 +145,7 @@ inline Utils::Vector3d v_noise_g(uint64_t counter, int key1, int key2 = 0) { // Box muller transform code adapted from // https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform - static const double two_pi = 2.0 * 3.14159265358979323846; + static const double two_pi = 2.0 * Utils::pi(); return {sqrt(-2.0 * log(u[0])) * cos(two_pi * u[1]), sqrt(-2.0 * log(u[0])) * sin(two_pi * u[1]), sqrt(-2.0 * log(u[2])) * cos(two_pi * u[3])}; diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 032fb7ed90f..d6d5d73063e 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -112,8 +112,10 @@ cdef class Thermostat: if thmst["type"] == "DPD": self.set_dpd(kT=thmst["kT"], seed=thmst["seed"]) if thmst["type"] == "BROWNIAN": - self.set_brownian(kT=thmst["kT"], gamma=thmst[ - "gamma"], gamma_rotation=thmst["gamma_rotation"], act_on_virtual=thmst["act_on_virtual"], seed=thmst["seed"]) + self.set_brownian(kT=thmst["kT"], gamma=thmst["gamma"], + gamma_rotation=thmst["gamma_rotation"], + act_on_virtual=thmst["act_on_virtual"], + seed=thmst["seed"]) def get_ts(self): return thermo_switch @@ -162,11 +164,9 @@ cdef class Thermostat: lang_dict["gamma"] = langevin_gamma IF ROTATION: IF PARTICLE_ANISOTROPY: - lang_dict[ - "gamma_rotation"] = [langevin_gamma_rotation[0], - langevin_gamma_rotation[ - 1], - langevin_gamma_rotation[2]] + lang_dict["gamma_rotation"] = [langevin_gamma_rotation[0], + langevin_gamma_rotation[1], + langevin_gamma_rotation[2]] ELSE: lang_dict["gamma_rotation"] = langevin_gamma_rotation ELSE: @@ -540,7 +540,7 @@ cdef class Thermostat: """ # Note: hack due to entanglement of Brownian dynamics and Langevin thermostat - # The setup code fro Brownian dynamics mis-uses the Langevin setup. + # The setup code for Brownian dynamics mis-uses the Langevin setup. # This needs to be changed global thermo_switch thermo_switch = (thermo_switch & (~THERMO_BROWNIAN)) From 545f4e2942a51071ad2fd91f74b8defdfe9ebe2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 21 Jan 2020 20:24:06 +0100 Subject: [PATCH 116/150] Update bibliography and doxygen Reformat BibTeX entries and use doxygen citation commands. Reformat the Brownian Dynamics doxygen blocks. --- doc/doxygen/bibliography.bib | 25 ++++++- doc/sphinx/analysis.rst | 4 +- doc/sphinx/system_setup.rst | 2 +- doc/sphinx/zrefs.bib | 11 +-- src/core/integrators/brownian_inline.hpp | 94 +++++++++--------------- src/core/thermostat.cpp | 37 +++++----- 6 files changed, 85 insertions(+), 88 deletions(-) diff --git a/doc/doxygen/bibliography.bib b/doc/doxygen/bibliography.bib index e30b3f9fd6b..df73a90672e 100644 --- a/doc/doxygen/bibliography.bib +++ b/doc/doxygen/bibliography.bib @@ -351,6 +351,17 @@ @Article{neumann85b doi = {10.1063/1.448553}, } +@Book{Pottier2010, + title={{Nonequilibrium Statistical Physics}}, + subtitle={{Linear Irreversible Processes}}, + author={Pottier, No\"{e}lle}, + year={2010}, + series={Oxford Graduate Texts}, + publisher={OUP Oxford}, + isbn={9780199556885}, + url={https://global.oup.com/academic/product/nonequilibrium-statistical-physics-9780199556885}, +} + @Article{reed92a, title = {{Monte Carlo study of titration of linear polyelectrolytes}}, author = {Reed, C. E. and Reed, W. F.}, @@ -361,6 +372,18 @@ @Article{reed92a doi = {10.1063/1.462145}, } +@Book{schlick2010, +title = {{Molecular Modeling and Simulation: An Interdisciplinary Guide}}, +author = {Schlick, Tamar}, +series = {Interdisciplinary Applied Mathematics}, +volume = {21}, +year = {2010}, +publisher = {Springer New York}, +address = {New York, NY}, +isbn = {978-1-4419-6350-5}, +doi = {10.1007/978-1-4419-6351-2}, +} + @Article{smith94c, title={{The reaction ensemble method for the computer simulation of chemical and phase equilibria. I. Theory and basic examples}}, author={Smith, W. R. and Triska, B.}, @@ -398,7 +421,7 @@ @book{allen2017 title={Computer simulation of liquids}, author={Allen, Michael P and Tildesley, Dominic J}, year={2017}, - publisher={Oxford university press}, + publisher={Oxford University Press}, url={https://global.oup.com/academic/product/computer-simulation-of-liquids-9780198803201}, doi={10.1093/oso/9780198803195.001.0001}, isbn={9780198803195}, diff --git a/doc/sphinx/analysis.rst b/doc/sphinx/analysis.rst index 7fabba2fdb5..a4214956f67 100644 --- a/doc/sphinx/analysis.rst +++ b/doc/sphinx/analysis.rst @@ -411,7 +411,7 @@ are calculated is beyond the scope of this manual. Three body potentials are implemented following the procedure in Ref. :cite:`thompson09a`. A different formula is used to calculate contribution from electrostatic interactions. For -electrostatic interactions in P3M, the :math:`k`-space contribution is implemented according to :cite:`essmann1995smooth`. +electrostatic interactions in P3M, the :math:`k`-space contribution is implemented according to :cite:`essmann95a`. The implementation of the Coulomb P3M pressure is tested against LAMMPS. Four-body dihedral potentials are not included. Except of @@ -439,7 +439,7 @@ The instantaneous virial stress tensor is calculated by where the notation is the same as for the pressure. The superscripts :math:`k` and :math:`l` correspond to the components in the tensors and vectors. -If electrostatic interactions are present then also the coulombic parts of the stress tensor need to be calculated. If P3M is present, then the instantaneous stress tensor is added to the above equation in accordance with :cite:`essmann1995smooth` : +If electrostatic interactions are present then also the coulombic parts of the stress tensor need to be calculated. If P3M is present, then the instantaneous stress tensor is added to the above equation in accordance with :cite:`essmann95a` : .. math :: p^\text{Coulomb, P3M}_{(k,l)} =p^\text{Coulomb, P3M, dir}_{(k,l)} + p^\text{Coulomb, P3M, rec}_{(k,l)}, diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index 9d93c296725..88738fde0f7 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -436,7 +436,7 @@ Brownian thermostat Brownian thermostat is a formal name of a thermostat enabling the Brownian Dynamics feature (see :cite:`schlick2010`) which implies a propagation scheme involving systematic and thermal parts of the -classical Ermak-McCammom's (see :cite:`ermak1978brownian`) +classical Ermak-McCammom's (see :cite:`ermak78a`) Brownian Dynamics. Currently it is implemented without hydrodynamic interactions, i.e. with a diagonal diffusion tensor. diff --git a/doc/sphinx/zrefs.bib b/doc/sphinx/zrefs.bib index a876b74fde5..82d4d9b7ce2 100644 --- a/doc/sphinx/zrefs.bib +++ b/doc/sphinx/zrefs.bib @@ -1002,18 +1002,19 @@ @book{schlick2010 series = {Interdisciplinary Applied Mathematics}, title = {{Molecular Modeling and Simulation: An Interdisciplinary Guide}}, volume = {21}, -year = {2010} +year = {2010}, } -@article{ermak1978brownian, +@article{ermak78a, title={Brownian dynamics with hydrodynamic interactions}, author={Ermak, Donald L and McCammon, J Andrew}, - journal={The Journal of chemical physics}, + journal={J. Chem. Phys.}, volume={69}, number={4}, pages={1352--1360}, year={1978}, - publisher={AIP} + publisher={AIP}, + doi={10.1063/1.436761}, } @Article{cerda08d, @@ -1029,7 +1030,7 @@ @Article{cerda08d timestamp = {2008.01.14} } -@article{essmann1995smooth, +@article{essmann95a, title={A smooth particle mesh Ewald method}, author={Essmann, Ulrich and Perera, Lalith and Berkowitz, Max L and Darden, Tom and Lee, Hsing and Pedersen, Lee G}, journal={J. Chem. Phys.}, diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index e651dc82a1f..e4bba0ce46a 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -/** \file brownian_inline.hpp */ +/** \file */ #ifndef BROWNIAN_INLINE_HPP #define BROWNIAN_INLINE_HPP @@ -26,13 +26,10 @@ #include "random.hpp" #include "thermostat.hpp" -/** Propagate position: viscous drag driven by conservative forces.*/ -/*********************************************************/ -/** \name bd_drag */ -/*********************************************************/ -/**(Eq. (14.39) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Propagate position: viscous drag driven by conservative forces. + * From eq. (14.39) in @cite Schlick2010. + * @param[in,out] p Particle + * @param[in] dt Time interval */ inline void bd_drag(Particle &p, double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: @@ -102,13 +99,10 @@ inline void bd_drag(Particle &p, double dt) { #endif // PARTICLE_ANISOTROPY } -/** Set the terminal velocity driven by the conservative forces drag.*/ -/*********************************************************/ -/** \name bd_drag_vel */ -/*********************************************************/ -/**(Eq. (14.34) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Set the terminal velocity driven by the conservative forces drag. + * From eq. (14.34) in @cite Schlick2010. + * @param[in,out] p Particle + * @param[in] dt Time interval */ inline void bd_drag_vel(Particle &p, double dt) { // The friction tensor Z from the eq. (14.31) of Schlick2010: @@ -191,13 +185,10 @@ inline void bd_drag_vel(Particle &p, double dt) { #endif // PARTICLE_ANISOTROPY } -/** Propagate the positions: random walk part.*/ -/*********************************************************/ -/** \name bd_random_walk */ -/*********************************************************/ -/**(Eq. (14.37) T. Schlick, https://doi.org/10.1007/978-1-4419-6351-2 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Propagate the positions: random walk part. + * From eq. (14.37) in @cite Schlick2010. + * @param[in,out] p Particle + * @param[in] dt Time interval */ void bd_random_walk(Particle &p, double dt) { // skip the translation thermalizing for virtual sites unless enabled @@ -309,13 +300,10 @@ void bd_random_walk(Particle &p, double dt) { } } -/** Determine the velocities: random walk part.*/ -/*********************************************************/ -/** \name bd_random_walk_vel */ -/*********************************************************/ -/**(Eq. (10.2.16) N. Pottier, https://doi.org/10.1007/s10955-010-0114-6 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Determine the velocities: random walk part. + * From eq. (10.2.16) in @cite Pottier2010. + * @param[in, out] p Particle + * @param[in] dt Time interval */ inline void bd_random_walk_vel(Particle &p, double dt) { // skip the translation thermalizing for virtual sites unless enabled @@ -363,14 +351,10 @@ inline void bd_random_walk_vel(Particle &p, double dt) { #ifdef ROTATION -/** Propagate quaternions: viscous drag driven by conservative torques.*/ -/*********************************************************/ -/** \name bd_drag_rot */ -/*********************************************************/ -/**(An analogy of eq. (14.39) T. Schlick, - * https://doi.org/10.1007/978-1-4419-6351-2 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Propagate quaternions: viscous drag driven by conservative torques. + * An analogy of eq. (14.39) in @cite Schlick2010. + * @param[in,out] p Particle + * @param[in] dt Time interval */ void bd_drag_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; @@ -407,14 +391,10 @@ void bd_drag_rot(Particle &p, double dt) { } } -/** Set the terminal angular velocity driven by the conservative torques drag.*/ -/*********************************************************/ -/** \name bd_drag_vel_rot */ -/*********************************************************/ -/**(An analogy of the 1st term of the eq. (14.34) T. Schlick, - * https://doi.org/10.1007/978-1-4419-6351-2 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Set the terminal angular velocity driven by the conservative torques drag. + * An analogy of the 1st term of eq. (14.34) in @cite Schlick2010. + * @param[in,out] p Particle + * @param[in] dt Time interval */ void bd_drag_vel_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; @@ -448,14 +428,10 @@ void bd_drag_vel_rot(Particle &p, double dt) { p.m.omega = mask(p.p.rotation, p.m.omega); } -/** Propagate the quaternions: random walk part.*/ -/*********************************************************/ -/** \name bd_random_walk_rot */ -/*********************************************************/ -/**(An analogy of eq. (14.37) T. Schlick, - * https://doi.org/10.1007/978-1-4419-6351-2 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Propagate the quaternions: random walk part. + * An analogy of eq. (14.37) in @cite Schlick2010. + * @param[in,out] p Particle + * @param[in] dt Time interval */ void bd_random_walk_rot(Particle &p, double dt) { extern Thermostat::GammaType brown_sigma_pos_rotation_inv; @@ -536,14 +512,10 @@ void bd_random_walk_rot(Particle &p, double dt) { } } -/** Determine the angular velocities: random walk part.*/ -/*********************************************************/ -/** \name bd_random_walk_vel_rot */ -/*********************************************************/ -/**(An analogy of eq. (10.2.16) N. Pottier, - * https://doi.org/10.1007/s10955-010-0114-6 (2010)) - * @param &p Reference to the particle (Input) - * @param dt Time interval (Input) +/** Determine the angular velocities: random walk part. + * An analogy of eq. (10.2.16) in @cite Pottier2010. + * @param[in,out] p Particle + * @param[in] dt Time interval */ void bd_random_walk_vel_rot(Particle &p, double dt) { extern double brown_sigma_vel_rotation; diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 35a11f5eebb..d62d0f6898e 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -142,19 +142,22 @@ void thermo_init_npt_isotropic() { } #endif -// brown_sigma_vel determines here the heat velocity random walk dispersion -// brown_sigma_pos determines here the BD position random walk dispersion -// default particle mass is assumed to be unitary in this global parameters +/** Brownian thermostat initializer. + * + * Default particle mass is assumed to be unitary in these global parameters. + */ void thermo_init_brownian() { - // Dispersions correspond to the Gaussian noise only which is only valid for - // the BD. Just a square root of kT, see (10.2.17) and comments in 2 - // paragraphs afterwards, Pottier2010 - // https://doi.org/10.1007/s10955-010-0114-6 + /** The heat velocity dispersion corresponds to the Gaussian noise only, + * which is only valid for the BD. Just a square root of kT, see (10.2.17) + * and comments in 2 paragraphs afterwards, @cite Pottier2010. + */ + // Heat velocity dispersion: brown_sigma_vel = sqrt(temperature); - // Position dispersion is defined by the second eq. (14.38) of Schlick2010 - // https://doi.org/10.1007/978-1-4419-6351-2. Its time interval factor will be - // added in the Brownian Dynamics functions. Its square root is the standard - // deviation. A multiplicative inverse of the position standard deviation: + /** The random walk position dispersion is defined by the second eq. (14.38) + * of @cite Schlick2010. Its time interval factor will be added in the + * Brownian Dynamics functions. Its square root is the standard deviation. + */ + // A multiplicative inverse of the position standard deviation: if (temperature > 0.0) { brown_sigma_pos_inv = sqrt(langevin_gamma / (2.0 * temperature)); } else { @@ -162,19 +165,17 @@ void thermo_init_brownian() { brown_gammatype_nan; // just an indication of the infinity } #ifdef ROTATION - // Note: the BD thermostat assigns the langevin viscous parameters as well. - // They correspond to the friction tensor Z from the eq. (14.31) of - // Schlick2010: + /** Note: the BD thermostat assigns the langevin viscous parameters as well. + * They correspond to the friction tensor Z from the eq. (14.31) of + * @cite Schlick2010. + */ /* If gamma_rotation is not set explicitly, we use the translational one. */ if (langevin_gamma_rotation < GammaType{}) { langevin_gamma_rotation = langevin_gamma; } brown_sigma_vel_rotation = sqrt(temperature); - // Position dispersion is defined by the second eq. (14.38) of Schlick2010. - // Its time interval factor will be added in the Brownian Dynamics functions. - // Its square root is the standard deviation. A multiplicative inverse of the - // position standard deviation: + // A multiplicative inverse of the position rotation standard deviation: if (temperature > 0.0) { brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (2.0 * temperature)); } else { From b522d0466fe645f24c1ee354b73c5300819042c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 21 Jan 2020 21:41:20 +0100 Subject: [PATCH 117/150] Test Brownian Dynamics checkpointing --- testsuite/python/CMakeLists.txt | 2 +- testsuite/python/save_checkpoint.py | 4 ++++ testsuite/python/test_checkpoint.py | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/testsuite/python/CMakeLists.txt b/testsuite/python/CMakeLists.txt index ed90811b335..fef42948fb3 100644 --- a/testsuite/python/CMakeLists.txt +++ b/testsuite/python/CMakeLists.txt @@ -48,7 +48,7 @@ endfunction(PYTHON_TEST) # Checkpointing tests: semicolon-separated list of mutually-compatible features. # Separate features with hyphens, use a period to add an optional flag. -foreach(TEST_COMBINATION lb.cpu-p3m.cpu-lj-therm.lb;lb.gpu-p3m.cpu-lj-therm.lb;ek.gpu;lb.off-therm.npt-int.npt-minimization;lb.off-therm.langevin-int.nvt;lb.off-therm.dpd-int.sd) +foreach(TEST_COMBINATION lb.cpu-p3m.cpu-lj-therm.lb;lb.gpu-p3m.cpu-lj-therm.lb;ek.gpu;lb.off-therm.npt-int.npt-minimization;lb.off-therm.langevin-int.nvt;lb.off-therm.dpd-int.sd;lb.off-therm.bd-int.bd) if(${TEST_COMBINATION} MATCHES "\\.gpu") set(TEST_LABELS "gpu") else() diff --git a/testsuite/python/save_checkpoint.py b/testsuite/python/save_checkpoint.py index deb226d42f7..377e3018436 100644 --- a/testsuite/python/save_checkpoint.py +++ b/testsuite/python/save_checkpoint.py @@ -138,6 +138,8 @@ # set thermostat if 'THERM.LANGEVIN' in modes: system.thermostat.set_langevin(kT=1.0, gamma=2.0, seed=42) + elif 'THERM.BD' in modes: + system.thermostat.set_brownian(kT=1.0, gamma=2.0, seed=42) elif 'THERM.NPT' in modes and has_features('NPT'): system.thermostat.set_npt(kT=1.0, gamma0=2.0, gammav=0.1) elif 'THERM.DPD' in modes and has_features('DPD'): @@ -151,6 +153,8 @@ max_displacement=0.01) elif 'INT.NVT' in modes: system.integrator.set_nvt() + elif 'INT.BD' in modes: + system.integrator.set_brownian_dynamics() # set minimization if 'MINIMIZATION' in modes: steepest_descent(system, f_max=1, gamma=10, max_steps=0, diff --git a/testsuite/python/test_checkpoint.py b/testsuite/python/test_checkpoint.py index 7c4e623862d..d07d0660d88 100644 --- a/testsuite/python/test_checkpoint.py +++ b/testsuite/python/test_checkpoint.py @@ -157,7 +157,22 @@ def test_thermostat_Langevin(self): self.assertEqual(thmst['type'], 'LANGEVIN') self.assertEqual(thmst['kT'], 1.0) self.assertEqual(thmst['seed'], 42) - np.testing.assert_array_equal(thmst['gamma'], np.array(3 * [2.0])) + self.assertFalse(thmst['act_on_virtual']) + np.testing.assert_array_equal(thmst['gamma'], 3 * [2.0]) + if espressomd.has_features('ROTATION'): + np.testing.assert_array_equal(thmst['gamma_rotation'], 3 * [2.0]) + + @ut.skipIf('THERM.BD' not in modes, + 'Brownian thermostat not in modes') + def test_thermostat_Brownian(self): + thmst = system.thermostat.get_state()[0] + self.assertEqual(thmst['type'], 'BROWNIAN') + self.assertEqual(thmst['kT'], 1.0) + self.assertEqual(thmst['seed'], 42) + self.assertFalse(thmst['act_on_virtual']) + np.testing.assert_array_equal(thmst['gamma'], 3 * [2.0]) + if espressomd.has_features('ROTATION'): + np.testing.assert_array_equal(thmst['gamma_rotation'], 3 * [2.0]) @utx.skipIfMissingFeatures('DPD') @ut.skipIf('THERM.DPD' not in modes, 'DPD thermostat not in modes') @@ -210,6 +225,13 @@ def test_integrator_VV(self): params = integ.get_params() self.assertEqual(params, {}) + @ut.skipIf('INT.BD' not in modes, 'BD integrator not in modes') + def test_integrator_BD(self): + integ = system.integrator.get_state() + self.assertIsInstance(integ, espressomd.integrate.BrownianDynamics) + params = integ.get_params() + self.assertEqual(params, {}) + @utx.skipIfMissingFeatures('LENNARD_JONES') @ut.skipIf('LJ' not in modes, "Skipping test due to missing mode.") def test_non_bonded_inter(self): From ede6e7e1a73185b1f12601cec1e6f99519bbb631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 21 Jan 2020 22:23:18 +0100 Subject: [PATCH 118/150] Split Brownian and Langevin code --- doc/sphinx/system_setup.rst | 8 +- maintainer/configs/maxset.hpp | 1 + maintainer/configs/no_rotation.hpp | 1 + src/config/features.def | 1 + src/config/myconfig-default.hpp | 1 + src/core/global.cpp | 21 ++- src/core/global.hpp | 6 +- src/core/integrate.cpp | 5 +- src/core/integrators/brownian_inline.hpp | 64 +++---- src/core/thermostat.cpp | 46 ++++- src/core/thermostat.hpp | 14 ++ src/python/espressomd/globals.pxd | 2 + src/python/espressomd/thermostat.pxd | 7 + src/python/espressomd/thermostat.pyx | 225 ++++++++++++++++++----- testsuite/python/brownian_dynamics.py | 10 +- 15 files changed, 311 insertions(+), 101 deletions(-) diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index 88738fde0f7..85e71acce01 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -456,10 +456,10 @@ Best explained in an example:: system.integrator.set_brownian_dynamics() where ``gamma`` (hereinafter :math:`\gamma`) is a viscous friction coefficient. -In terms of the Python interface and setup, Brownian thermostat derives most -properties of the :ref:`Langevin thermostat`. The feature -``LANGEVIN_PER_PARTICLE`` is used to control the per-particle -temperature and the friction coefficient setup. Major differences are +In terms of the Python interface and setup, the Brownian thermostat is very +similar to the :ref:`Langevin thermostat`. The feature +``BROWNIAN_PER_PARTICLE`` is used to control the per-particle +temperature and the friction coefficient setup. The major differences are its internal integrator implementation and other temporal constraints. The integrator is still a symplectic Velocity Verlet-like one. It is implemented via a viscous drag part and a random walk of both the position and diff --git a/maintainer/configs/maxset.hpp b/maintainer/configs/maxset.hpp index aac46dbfe72..7ea4862c139 100644 --- a/maintainer/configs/maxset.hpp +++ b/maintainer/configs/maxset.hpp @@ -33,6 +33,7 @@ #define BOND_CONSTRAINT #define COLLISION_DETECTION #define LANGEVIN_PER_PARTICLE +#define BROWNIAN_PER_PARTICLE #define SWIMMER_REACTIONS #define NPT diff --git a/maintainer/configs/no_rotation.hpp b/maintainer/configs/no_rotation.hpp index 5412eadf2fc..8e2fd495f81 100644 --- a/maintainer/configs/no_rotation.hpp +++ b/maintainer/configs/no_rotation.hpp @@ -30,6 +30,7 @@ #define MASS #define EXTERNAL_FORCES #define LANGEVIN_PER_PARTICLE +#define BROWNIAN_PER_PARTICLE #define BOND_CONSTRAINT #define NPT #define DPD diff --git a/src/config/features.def b/src/config/features.def index 8bfe30874a3..a16d9319e4d 100644 --- a/src/config/features.def +++ b/src/config/features.def @@ -19,6 +19,7 @@ MASS EXCLUSIONS BOND_CONSTRAINT LANGEVIN_PER_PARTICLE +BROWNIAN_PER_PARTICLE COLLISION_DETECTION METADYNAMICS NPT diff --git a/src/config/myconfig-default.hpp b/src/config/myconfig-default.hpp index da600142b02..54465b344f7 100644 --- a/src/config/myconfig-default.hpp +++ b/src/config/myconfig-default.hpp @@ -33,6 +33,7 @@ #define PARTICLE_ANISOTROPY #define EXTERNAL_FORCES #define LANGEVIN_PER_PARTICLE +#define BROWNIAN_PER_PARTICLE #define BOND_CONSTRAINT #define NPT #define DPD diff --git a/src/core/global.cpp b/src/core/global.cpp index cde3fe5e04f..74c661a0ab4 100644 --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -168,7 +168,26 @@ const std::unordered_map fields{ "n_thermalized_bonds"}}, /* 56 from thermalized_bond.cpp */ {FIELD_FORCE_CAP, {&force_cap, Datafield::Type::DOUBLE, 1, "force_cap"}}, {FIELD_THERMO_VIRTUAL, - {&thermo_virtual, Datafield::Type::BOOL, 1, "thermo_virtual"}}}; + {&thermo_virtual, Datafield::Type::BOOL, 1, "thermo_virtual"}}, +#ifndef PARTICLE_ANISOTROPY + {FIELD_BROWNIAN_GAMMA_ROTATION, + {&brownian_gamma_rotation, Datafield::Type::DOUBLE, 1, + "gamma_rot"}}, /* 57 from thermostat.cpp */ +#else + {FIELD_BROWNIAN_GAMMA_ROTATION, + {brownian_gamma_rotation.data(), Datafield::Type::DOUBLE, 3, + "gamma_rot"}}, /* 57 from thermostat.cpp */ +#endif +#ifndef PARTICLE_ANISOTROPY + {FIELD_BROWNIAN_GAMMA, + {&brownian_gamma, Datafield::Type::DOUBLE, 1, + "gamma"}}, /* 58 from thermostat.cpp */ +#else + {FIELD_BROWNIAN_GAMMA, + {brownian_gamma.data(), Datafield::Type::DOUBLE, 3, + "gamma"}}, /* 58 from thermostat.cpp */ +#endif // PARTICLE_ANISOTROPY +}; std::size_t hash_value(Datafield const &field) { using boost::hash_range; diff --git a/src/core/global.hpp b/src/core/global.hpp index d2c28952e86..f78984e5784 100644 --- a/src/core/global.hpp +++ b/src/core/global.hpp @@ -98,7 +98,11 @@ enum Fields { FIELD_THERMALIZEDBONDS, FIELD_FORCE_CAP, FIELD_THERMO_VIRTUAL, - FIELD_SWIMMING_PARTICLES_EXIST + FIELD_SWIMMING_PARTICLES_EXIST, + /** index of \ref brownian_gamma */ + FIELD_BROWNIAN_GAMMA, + /** index of \ref brownian_gamma_rotation */ + FIELD_BROWNIAN_GAMMA_ROTATION, }; #endif diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 1d6e1798c41..7ea4e93a683 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -312,9 +312,12 @@ int integrate(int n_steps, int reuse_forces) { } void philox_counter_increment() { - if (thermo_switch & THERMO_LANGEVIN or thermo_switch & THERMO_BROWNIAN) { + if (thermo_switch & THERMO_LANGEVIN) { langevin_rng_counter_increment(); } + if (thermo_switch & THERMO_BROWNIAN) { + brownian_rng_counter_increment(); + } if (thermo_switch & THERMO_DPD) { #ifdef DPD dpd_rng_counter_increment(); diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index e4bba0ce46a..78b1b1df3fd 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -35,13 +35,13 @@ inline void bd_drag(Particle &p, double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: Thermostat::GammaType local_gamma; -#ifdef LANGEVIN_PER_PARTICLE +#ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{}) { local_gamma = p.p.gamma; } else #endif { - local_gamma = langevin_gamma; + local_gamma = brownian_gamma; } bool aniso_flag; // particle anisotropy flag @@ -108,13 +108,13 @@ inline void bd_drag_vel(Particle &p, double dt) { // The friction tensor Z from the eq. (14.31) of Schlick2010: Thermostat::GammaType local_gamma; -#ifdef LANGEVIN_PER_PARTICLE +#ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{}) { local_gamma = p.p.gamma; } else #endif { - local_gamma = langevin_gamma; + local_gamma = brownian_gamma; } bool aniso_flag; // particle anisotropy flag @@ -206,15 +206,15 @@ void bd_random_walk(Particle &p, double dt) { Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_inv; // Override defaults if per-particle values for T and gamma are given -#ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 2.0; +#ifdef BROWNIAN_PER_PARTICLE + auto const constexpr brownian_temp_coeff = 2.0; if (p.p.gamma >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { brown_sigma_pos_temp_inv = - sqrt(p.p.gamma / (langevin_temp_coeff * p.p.T)); + sqrt(p.p.gamma / (brownian_temp_coeff * p.p.T)); } else { brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity @@ -223,7 +223,7 @@ void bd_random_walk(Particle &p, double dt) { // Default temperature but particle-specific gamma if (temperature > 0.0) { brown_sigma_pos_temp_inv = - sqrt(p.p.gamma / (langevin_temp_coeff * temperature)); + sqrt(p.p.gamma / (brownian_temp_coeff * temperature)); } else { brown_sigma_pos_temp_inv = brown_gammatype_nan; } @@ -233,7 +233,7 @@ void bd_random_walk(Particle &p, double dt) { if (p.p.T >= 0.) { if (p.p.T > 0.0) { brown_sigma_pos_temp_inv = - sqrt(langevin_gamma / (langevin_temp_coeff * p.p.T)); + sqrt(brownian_gamma / (brownian_temp_coeff * p.p.T)); } else { brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity @@ -243,7 +243,7 @@ void bd_random_walk(Particle &p, double dt) { brown_sigma_pos_temp_inv = brown_sigma_pos_inv; } } -#endif /* LANGEVIN_PER_PARTICLE */ +#endif /* BROWNIAN_PER_PARTICLE */ bool aniso_flag; // particle anisotropy flag @@ -260,7 +260,7 @@ void bd_random_walk(Particle &p, double dt) { // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared // magnitude defined in the second eq. (14.38), Schlick2010. Utils::Vector3d noise = Random::v_noise_g( - langevin_rng_counter->value(), p.p.identity); + brownian_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -316,21 +316,21 @@ inline void bd_random_walk_vel(Particle &p, double dt) { double brown_sigma_vel_temp; // Override defaults if per-particle values for T and gamma are given -#ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 1.0; +#ifdef BROWNIAN_PER_PARTICLE + auto const constexpr brownian_temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p.p.T); + brown_sigma_vel_temp = sqrt(brownian_temp_coeff * p.p.T); } else { brown_sigma_vel_temp = brown_sigma_vel; } #else // defaults brown_sigma_vel_temp = brown_sigma_vel; -#endif /* LANGEVIN_PER_PARTICLE */ +#endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d noise = Random::v_noise_g( - langevin_rng_counter->value(), p.identity()); + brownian_rng_counter->value(), p.identity()); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -359,13 +359,13 @@ inline void bd_random_walk_vel(Particle &p, double dt) { void bd_drag_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; -#ifdef LANGEVIN_PER_PARTICLE +#ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; } else #endif { - local_gamma = langevin_gamma_rotation; + local_gamma = brownian_gamma_rotation; } Utils::Vector3d dphi = {0.0, 0.0, 0.0}; @@ -399,13 +399,13 @@ void bd_drag_rot(Particle &p, double dt) { void bd_drag_vel_rot(Particle &p, double dt) { Thermostat::GammaType local_gamma; -#ifdef LANGEVIN_PER_PARTICLE +#ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{}) { local_gamma = p.p.gamma_rot; } else #endif { - local_gamma = langevin_gamma_rotation; + local_gamma = brownian_gamma_rotation; } for (int j = 0; j < 3; j++) { @@ -440,15 +440,15 @@ void bd_random_walk_rot(Particle &p, double dt) { Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; // Override defaults if per-particle values for T and gamma are given -#ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 2.0; +#ifdef BROWNIAN_PER_PARTICLE + auto const constexpr brownian_temp_coeff = 2.0; if (p.p.gamma_rot >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { brown_sigma_pos_temp_inv = - sqrt(p.p.gamma_rot / (langevin_temp_coeff * p.p.T)); + sqrt(p.p.gamma_rot / (brownian_temp_coeff * p.p.T)); } else { brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity @@ -457,7 +457,7 @@ void bd_random_walk_rot(Particle &p, double dt) { // Default temperature but particle-specific gamma if (temperature > 0.) { brown_sigma_pos_temp_inv = - sqrt(p.p.gamma_rot / (langevin_temp_coeff * temperature)); + sqrt(p.p.gamma_rot / (brownian_temp_coeff * temperature)); } else { brown_sigma_pos_temp_inv = brown_gammatype_nan; } @@ -467,7 +467,7 @@ void bd_random_walk_rot(Particle &p, double dt) { if (p.p.T >= 0.) { if (p.p.T > 0.0) { brown_sigma_pos_temp_inv = - sqrt(langevin_gamma_rotation / (langevin_temp_coeff * p.p.T)); + sqrt(brownian_gamma_rotation / (brownian_temp_coeff * p.p.T)); } else { brown_sigma_pos_temp_inv = brown_gammatype_nan; // just an indication of the infinity @@ -477,11 +477,11 @@ void bd_random_walk_rot(Particle &p, double dt) { brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; } } -#endif /* LANGEVIN_PER_PARTICLE */ +#endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d dphi = {0.0, 0.0, 0.0}; Utils::Vector3d noise = Random::v_noise_g( - langevin_rng_counter->value(), p.p.identity); + brownian_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -522,22 +522,22 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { double brown_sigma_vel_temp; // Override defaults if per-particle values for T and gamma are given -#ifdef LANGEVIN_PER_PARTICLE - auto const constexpr langevin_temp_coeff = 1.0; +#ifdef BROWNIAN_PER_PARTICLE + auto const constexpr brownian_temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - brown_sigma_vel_temp = sqrt(langevin_temp_coeff * p.p.T); + brown_sigma_vel_temp = sqrt(brownian_temp_coeff * p.p.T); } else { brown_sigma_vel_temp = brown_sigma_vel_rotation; } #else // set defaults brown_sigma_vel_temp = brown_sigma_vel_rotation; -#endif /* LANGEVIN_PER_PARTICLE */ +#endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d domega; Utils::Vector3d noise = Random::v_noise_g( - langevin_rng_counter->value(), p.p.identity); + brownian_rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index d62d0f6898e..a3fc7d34f14 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -42,8 +42,8 @@ bool thermo_virtual = true; using Thermostat::GammaType; namespace { -/** @name Langevin parameters sentinels. - * These functions return the sentinel value for the Langevin +/** @name Integrators parameters sentinels. + * These functions return the sentinel value for the Langevin/Brownian * parameters, indicating that they have not been set yet. */ /*@{*/ @@ -59,6 +59,8 @@ GammaType langevin_gamma_rotation = sentinel(GammaType{}); GammaType langevin_pref1; GammaType langevin_pref2; GammaType langevin_pref2_rotation; +GammaType brownian_gamma = sentinel(GammaType{}); +GammaType brownian_gamma_rotation = sentinel(GammaType{}); // Brownian position random walk standard deviation GammaType brown_sigma_pos_inv = sentinel(GammaType{}); GammaType brown_sigma_pos_rotation_inv = sentinel(GammaType{}); @@ -87,6 +89,7 @@ double nptiso_pref4; #endif std::unique_ptr> langevin_rng_counter; +std::unique_ptr> brownian_rng_counter; void mpi_bcast_langevin_rng_counter_slave(const uint64_t counter) { langevin_rng_counter = std::make_unique>(counter); @@ -94,27 +97,54 @@ void mpi_bcast_langevin_rng_counter_slave(const uint64_t counter) { REGISTER_CALLBACK(mpi_bcast_langevin_rng_counter_slave) +void mpi_bcast_brownian_rng_counter_slave(const uint64_t counter) { + brownian_rng_counter = std::make_unique>(counter); +} + +REGISTER_CALLBACK(mpi_bcast_brownian_rng_counter_slave) + void mpi_bcast_langevin_rng_counter(const uint64_t counter) { mpi_call(mpi_bcast_langevin_rng_counter_slave, counter); } +void mpi_bcast_brownian_rng_counter(const uint64_t counter) { + mpi_call(mpi_bcast_brownian_rng_counter_slave, counter); +} + void langevin_rng_counter_increment() { - if (thermo_switch & (THERMO_LANGEVIN | THERMO_BROWNIAN)) + if (thermo_switch & THERMO_LANGEVIN) langevin_rng_counter->increment(); } +void brownian_rng_counter_increment() { + if (thermo_switch & THERMO_BROWNIAN) + brownian_rng_counter->increment(); +} + bool langevin_is_seed_required() { /* Seed is required if rng is not initialized */ return langevin_rng_counter == nullptr; } +bool brownian_is_seed_required() { + /* Seed is required if rng is not initialized */ + return brownian_rng_counter == nullptr; +} + void langevin_set_rng_state(const uint64_t counter) { mpi_bcast_langevin_rng_counter(counter); langevin_rng_counter = std::make_unique>(counter); } +void brownian_set_rng_state(const uint64_t counter) { + mpi_bcast_brownian_rng_counter(counter); + brownian_rng_counter = std::make_unique>(counter); +} + uint64_t langevin_get_rng_state() { return langevin_rng_counter->value(); } +uint64_t brownian_get_rng_state() { return brownian_rng_counter->value(); } + void thermo_init_langevin() { langevin_pref1 = -langevin_gamma; langevin_pref2 = sqrt(24.0 * temperature / time_step * langevin_gamma); @@ -159,25 +189,25 @@ void thermo_init_brownian() { */ // A multiplicative inverse of the position standard deviation: if (temperature > 0.0) { - brown_sigma_pos_inv = sqrt(langevin_gamma / (2.0 * temperature)); + brown_sigma_pos_inv = sqrt(brownian_gamma / (2.0 * temperature)); } else { brown_sigma_pos_inv = brown_gammatype_nan; // just an indication of the infinity } #ifdef ROTATION - /** Note: the BD thermostat assigns the langevin viscous parameters as well. + /** Note: the BD thermostat assigns the brownian viscous parameters as well. * They correspond to the friction tensor Z from the eq. (14.31) of * @cite Schlick2010. */ /* If gamma_rotation is not set explicitly, we use the translational one. */ - if (langevin_gamma_rotation < GammaType{}) { - langevin_gamma_rotation = langevin_gamma; + if (brownian_gamma_rotation < GammaType{}) { + brownian_gamma_rotation = brownian_gamma; } brown_sigma_vel_rotation = sqrt(temperature); // A multiplicative inverse of the position rotation standard deviation: if (temperature > 0.0) { - brown_sigma_pos_rotation_inv = sqrt(langevin_gamma / (2.0 * temperature)); + brown_sigma_pos_rotation_inv = sqrt(brownian_gamma / (2.0 * temperature)); } else { brown_sigma_pos_rotation_inv = brown_gammatype_nan; // just an indication of the infinity diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 38b0ab2f7f2..920130bfc5f 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -94,6 +94,14 @@ extern double nptiso_gammav; /** Langevin RNG counter, used for both translation and rotation. */ extern std::unique_ptr> langevin_rng_counter; +/** Brownian friction coefficient gamma for translation. */ +extern Thermostat::GammaType brownian_gamma; +/** Brownian friction coefficient gamma for rotation. */ +extern Thermostat::GammaType brownian_gamma_rotation; + +/** Brownian RNG counter, used for both translation and rotation. */ +extern std::unique_ptr> brownian_rng_counter; + /************************************************ * functions ************************************************/ @@ -101,11 +109,17 @@ extern std::unique_ptr> langevin_rng_counter; /** Only require seed if rng is not initialized. */ bool langevin_is_seed_required(); +/** Only require seed if rng is not initialized. */ +bool brownian_is_seed_required(); + /** @name philox functionality: increment, get/set */ /*@{*/ void langevin_rng_counter_increment(); void langevin_set_rng_state(uint64_t counter); uint64_t langevin_get_rng_state(); +void brownian_rng_counter_increment(); +void brownian_set_rng_state(uint64_t counter); +uint64_t brownian_get_rng_state(); /*@}*/ /** Initialize constants of the thermostat at the start of integration */ diff --git a/src/python/espressomd/globals.pxd b/src/python/espressomd/globals.pxd index d4f0b8b07dd..95ab83edaa7 100644 --- a/src/python/espressomd/globals.pxd +++ b/src/python/espressomd/globals.pxd @@ -36,9 +36,11 @@ cdef extern from "global.hpp": int FIELD_THERMO_VIRTUAL int FIELD_TEMPERATURE int FIELD_LANGEVIN_GAMMA + int FIELD_BROWNIAN_GAMMA int FIELD_SWIMMING_PARTICLES_EXIST IF ROTATION: int FIELD_LANGEVIN_GAMMA_ROTATION + int FIELD_BROWNIAN_GAMMA_ROTATION IF NPT: int FIELD_NPTISO_G0 int FIELD_NPTISO_GV diff --git a/src/python/espressomd/thermostat.pxd b/src/python/espressomd/thermostat.pxd index 779080aecc4..0a5d988343e 100644 --- a/src/python/espressomd/thermostat.pxd +++ b/src/python/espressomd/thermostat.pxd @@ -36,14 +36,21 @@ cdef extern from "thermostat.hpp": IF PARTICLE_ANISOTROPY: Vector3d langevin_gamma_rotation Vector3d langevin_gamma + Vector3d brownian_gamma_rotation + Vector3d brownian_gamma ELSE: double langevin_gamma_rotation double langevin_gamma + double brownian_gamma_rotation + double brownian_gamma void langevin_set_rng_state(stdint.uint64_t counter) + void brownian_set_rng_state(stdint.uint64_t counter) cbool langevin_is_seed_required() + cbool brownian_is_seed_required() stdint.uint64_t langevin_get_rng_state() + stdint.uint64_t brownian_get_rng_state() cdef extern from "dpd.hpp": IF DPD: diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index d6d5d73063e..f1774b56c2e 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -155,20 +155,20 @@ cdef class Thermostat: lang_dict["type"] = "BROWNIAN" lang_dict["kT"] = temperature lang_dict["act_on_virtual"] = thermo_virtual - lang_dict["seed"] = int(langevin_get_rng_state()) + lang_dict["seed"] = int(brownian_get_rng_state()) IF PARTICLE_ANISOTROPY: - lang_dict["gamma"] = [langevin_gamma[0], - langevin_gamma[1], - langevin_gamma[2]] + lang_dict["gamma"] = [brownian_gamma[0], + brownian_gamma[1], + brownian_gamma[2]] ELSE: - lang_dict["gamma"] = langevin_gamma + lang_dict["gamma"] = brownian_gamma IF ROTATION: IF PARTICLE_ANISOTROPY: - lang_dict["gamma_rotation"] = [langevin_gamma_rotation[0], - langevin_gamma_rotation[1], - langevin_gamma_rotation[2]] + lang_dict["gamma_rotation"] = [brownian_gamma_rotation[0], + brownian_gamma_rotation[1], + brownian_gamma_rotation[2]] ELSE: - lang_dict["gamma_rotation"] = langevin_gamma_rotation + lang_dict["gamma_rotation"] = brownian_gamma_rotation ELSE: lang_dict["gamma_rotation"] = None @@ -217,6 +217,13 @@ cdef class Thermostat: ELSE: langevin_gamma = 0. mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA) + global brownian_gamma + IF PARTICLE_ANISOTROPY: + for i in range(3): + brownian_gamma[i] = 0. + ELSE: + brownian_gamma = 0. + mpi_bcast_parameter(FIELD_BROWNIAN_GAMMA) global langevin_gamma_rotation IF ROTATION: IF PARTICLE_ANISOTROPY: @@ -225,6 +232,14 @@ cdef class Thermostat: ELSE: langevin_gamma_rotation = 0. mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA_ROTATION) + global brownian_gamma_rotation + IF ROTATION: + IF PARTICLE_ANISOTROPY: + for i in range(3): + brownian_gamma_rotation[i] = 0. + ELSE: + brownian_gamma_rotation = 0. + mpi_bcast_parameter(FIELD_BROWNIAN_GAMMA_ROTATION) global thermo_switch thermo_switch = THERMO_OFF @@ -385,6 +400,158 @@ cdef class Thermostat: mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA_ROTATION) return True + @AssertThermostatType(THERMO_BROWNIAN) + def set_brownian(self, kT=None, gamma=None, gamma_rotation=None, + act_on_virtual=False, seed=None): + """Sets the Brownian thermostat. + + Parameters + ----------- + kT : :obj:`float` + Thermal energy of the simulated heat bath. + gamma : :obj:`float` + Contains the friction coefficient of the bath. If the feature + ``PARTICLE_ANISOTROPY`` is compiled in, then ``gamma`` can be a list + of three positive floats, for the friction coefficient in each + cardinal direction. + gamma_rotation : :obj:`float`, optional + The same applies to ``gamma_rotation``, which requires the feature + ``ROTATION`` to work properly. But also accepts three floats + if ``PARTICLE_ANISOTROPY`` is also compiled in. + act_on_virtual : :obj:`bool`, optional + If ``True`` the thermostat will act on virtual sites, default is + ``False``. + seed : :obj:`int` + Initial counter value (or seed) of the philox RNG. + Required on first activation of the Brownian thermostat. + Must be positive. + + """ + + scalar_gamma_def = True + scalar_gamma_rot_def = True + IF PARTICLE_ANISOTROPY: + if hasattr(gamma, "__iter__"): + scalar_gamma_def = False + else: + scalar_gamma_def = True + + IF PARTICLE_ANISOTROPY: + if hasattr(gamma_rotation, "__iter__"): + scalar_gamma_rot_def = False + else: + scalar_gamma_rot_def = True + + if kT is None or gamma is None: + raise ValueError( + "Both, kT and gamma have to be given as keyword args") + utils.check_type_or_throw_except(kT, 1, float, "kT must be a number") + if scalar_gamma_def: + utils.check_type_or_throw_except( + gamma, 1, float, "gamma must be a number") + else: + utils.check_type_or_throw_except( + gamma, 3, float, "diagonal elements of the gamma tensor must be numbers") + if gamma_rotation is not None: + if scalar_gamma_rot_def: + utils.check_type_or_throw_except( + gamma_rotation, 1, float, "gamma_rotation must be a number") + else: + utils.check_type_or_throw_except( + gamma_rotation, 3, float, "diagonal elements of the gamma_rotation tensor must be numbers") + + if scalar_gamma_def: + if float(kT) < 0. or float(gamma) < 0.: + raise ValueError( + "temperature and gamma must be positive numbers") + else: + if float(kT) < 0. or float(gamma[0]) < 0. or float( + gamma[1]) < 0. or float(gamma[2]) < 0.: + raise ValueError( + "temperature and diagonal elements of the gamma tensor must be positive numbers") + if gamma_rotation is not None: + if scalar_gamma_rot_def: + if float(gamma_rotation) < 0.: + raise ValueError( + "gamma_rotation must be positive number") + else: + if float(gamma_rotation[0]) < 0. or float( + gamma_rotation[1]) < 0. or float(gamma_rotation[2]) < 0.: + raise ValueError( + "diagonal elements of the gamma_rotation tensor must be positive numbers") + + # Seed is required if the RNG is not initialized + if seed is None and brownian_is_seed_required(): + raise ValueError( + "A seed has to be given as keyword argument on first activation of the thermostat") + + if seed is not None: + utils.check_type_or_throw_except( + seed, 1, int, "seed must be a positive integer") + if seed < 0: + raise ValueError("seed must be a positive integer") + brownian_set_rng_state(seed) + + global temperature + temperature = float(kT) + global brownian_gamma + IF PARTICLE_ANISOTROPY: + if scalar_gamma_def: + brownian_gamma[0] = gamma + brownian_gamma[1] = gamma + brownian_gamma[2] = gamma + else: + brownian_gamma[0] = gamma[0] + brownian_gamma[1] = gamma[1] + brownian_gamma[2] = gamma[2] + ELSE: + brownian_gamma = float(gamma) + + global brownian_gamma_rotation + IF ROTATION: + if gamma_rotation is not None: + IF PARTICLE_ANISOTROPY: + if scalar_gamma_rot_def: + brownian_gamma_rotation[0] = gamma_rotation + brownian_gamma_rotation[1] = gamma_rotation + brownian_gamma_rotation[2] = gamma_rotation + else: + brownian_gamma_rotation[0] = gamma_rotation[0] + brownian_gamma_rotation[1] = gamma_rotation[1] + brownian_gamma_rotation[2] = gamma_rotation[2] + ELSE: + if scalar_gamma_rot_def: + brownian_gamma_rotation = gamma_rotation + else: + raise ValueError( + "gamma_rotation must be a scalar since feature PARTICLE_ANISOTROPY is disabled") + else: + IF PARTICLE_ANISOTROPY: + if scalar_gamma_def: + brownian_gamma_rotation[0] = gamma + brownian_gamma_rotation[1] = gamma + brownian_gamma_rotation[2] = gamma + else: + brownian_gamma_rotation[0] = gamma[0] + brownian_gamma_rotation[1] = gamma[1] + brownian_gamma_rotation[2] = gamma[2] + ELSE: + brownian_gamma_rotation = brownian_gamma + + global thermo_switch + thermo_switch = (thermo_switch | THERMO_BROWNIAN) + mpi_bcast_parameter(FIELD_THERMO_SWITCH) + mpi_bcast_parameter(FIELD_TEMPERATURE) + mpi_bcast_parameter(FIELD_BROWNIAN_GAMMA) + + global thermo_virtual + thermo_virtual = act_on_virtual + mpi_bcast_parameter(FIELD_THERMO_VIRTUAL) + + IF ROTATION: + mpi_bcast_parameter(FIELD_BROWNIAN_GAMMA_ROTATION) + return True + @AssertThermostatType(THERMO_LB, THERMO_DPD) def set_lb( self, @@ -512,43 +679,3 @@ cdef class Thermostat: mpi_bcast_parameter(FIELD_THERMO_SWITCH) mpi_bcast_parameter(FIELD_TEMPERATURE) - - @AssertThermostatType(THERMO_BROWNIAN) - def set_brownian(self, kT=None, gamma=None, gamma_rotation=None, - act_on_virtual=False, seed=None): - """Sets the Brownian Dynamics thermostat with required parameters 'kT' 'gamma' - and optional parameter 'gamma_rotation'. - - Parameters - ----------- - kT : :obj:`float` - Thermal energy of the simulated heat bath. - gamma : :obj:`float` - Contains the friction coefficient of the bath. If the feature 'PARTICLE_ANISOTROPY' - is compiled in then 'gamma' can be a list of three positive floats, for the friction - coefficient in each cardinal direction. - gamma_rotation : :obj:`float`, optional - The same applies to 'gamma_rotation', which requires the feature - 'ROTATION' to work properly. But also accepts three floating point numbers - if 'PARTICLE_ANISOTROPY' is also compiled in. - act_on_virtual : :obj:`bool`, optional - If true the thermostat will act on virtual sites, default is off. - seed : :obj:`int`, required - Initial counter value (or seed) of the philox RNG. - Required on first activation of the Brownian Dynamics thermostat. - - """ - - # Note: hack due to entanglement of Brownian dynamics and Langevin thermostat - # The setup code for Brownian dynamics mis-uses the Langevin setup. - # This needs to be changed - global thermo_switch - thermo_switch = (thermo_switch & (~THERMO_BROWNIAN)) - - self.set_langevin(kT, gamma, gamma_rotation, act_on_virtual, seed) - # this is safe because this combination of thermostats is not - # allowed - thermo_switch = (thermo_switch & (~THERMO_LANGEVIN)) - thermo_switch = (thermo_switch | THERMO_BROWNIAN) - mpi_bcast_parameter(FIELD_THERMO_SWITCH) - return True diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py index 0b06dac8989..8e5795fe55c 100644 --- a/testsuite/python/brownian_dynamics.py +++ b/testsuite/python/brownian_dynamics.py @@ -111,20 +111,20 @@ def test_vel_dist_global_temp(self): self.check_vel_dist_global_temp(False, loops=1500) def test_vel_dist_global_temp_initial_forces(self): - """Test velocity distribution for global Langevin parameters, + """Test velocity distribution for global Brownian parameters, when using the initial force calculation. """ self.check_vel_dist_global_temp(True, loops=170) - @utx.skipIfMissingFeatures("LANGEVIN_PER_PARTICLE") - def test_05__langevin_per_particle(self): + @utx.skipIfMissingFeatures("BROWNIAN_PER_PARTICLE") + def test_05__brownian_per_particle(self): """Test Brownian dynamics with particle specific kT and gamma. Covers all combinations of particle specific gamma and temp set or not set. """ N = 400 system = self.system system.part.clear() - system.time_step = 1.9 + system.time_step = 1.9 system.part.add(pos=np.random.random((N, 3))) if espressomd.has_features("ROTATION"): system.part[:].rotation = [1, 1, 1] @@ -246,7 +246,7 @@ def test_07__virtual(self): np.testing.assert_almost_equal(np.copy(physical.f), [0, 0, 0]) def test_08__noise_correlation(self): - """Checks that the Langevin noise is uncorrelated""" + """Checks that the Brownian noise is uncorrelated""" system = self.system system.part.clear() From 3f29600f34f22a70ddfc1362d496653bbc698010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 22 Jan 2020 18:54:10 +0100 Subject: [PATCH 119/150] Make sentinels constexpr and move them --- src/core/thermostat.cpp | 13 ------------- src/core/thermostat.hpp | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index a3fc7d34f14..caa2a98b265 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -41,19 +41,6 @@ bool thermo_virtual = true; using Thermostat::GammaType; -namespace { -/** @name Integrators parameters sentinels. - * These functions return the sentinel value for the Langevin/Brownian - * parameters, indicating that they have not been set yet. - */ -/*@{*/ -constexpr double sentinel(double) { return -1.0; } -Utils::Vector3d sentinel(Utils::Vector3d) { return {-1.0, -1.0, -1.0}; } -constexpr double set_nan(double) { return NAN; } -Utils::Vector3d set_nan(Utils::Vector3d) { return {NAN, NAN, NAN}; } -/*@}*/ -} // namespace - GammaType langevin_gamma = sentinel(GammaType{}); GammaType langevin_gamma_rotation = sentinel(GammaType{}); GammaType langevin_pref1; diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 920130bfc5f..4422bf4392a 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -59,6 +59,21 @@ using GammaType = double; #endif } // namespace Thermostat +namespace { +/** @name Integrators parameters sentinels. + * These functions return the sentinel value for the Langevin/Brownian + * parameters, indicating that they have not been set yet. + */ +/*@{*/ +constexpr double sentinel(double) { return -1.0; } +constexpr Utils::Vector3d sentinel(Utils::Vector3d) { + return {-1.0, -1.0, -1.0}; +} +constexpr double set_nan(double) { return NAN; } +constexpr Utils::Vector3d set_nan(Utils::Vector3d) { return {NAN, NAN, NAN}; } +/*@}*/ +} // namespace + /************************************************ * exported variables ************************************************/ From c6c896395332435c46d4ac54921ab79ce547adf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 22 Jan 2020 18:54:59 +0100 Subject: [PATCH 120/150] Move Brownian Dynamics globals in a struct --- src/core/global.cpp | 16 +- src/core/global.hpp | 4 +- src/core/integrators/brownian_inline.hpp | 186 ++++++++++------------- src/core/thermostat.cpp | 44 +++--- src/core/thermostat.hpp | 40 ++++- src/python/espressomd/thermostat.pxd | 16 +- src/python/espressomd/thermostat.pyx | 73 +++++---- 7 files changed, 191 insertions(+), 188 deletions(-) diff --git a/src/core/global.cpp b/src/core/global.cpp index 74c661a0ab4..c6dc5802fc3 100644 --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -171,21 +171,21 @@ const std::unordered_map fields{ {&thermo_virtual, Datafield::Type::BOOL, 1, "thermo_virtual"}}, #ifndef PARTICLE_ANISOTROPY {FIELD_BROWNIAN_GAMMA_ROTATION, - {&brownian_gamma_rotation, Datafield::Type::DOUBLE, 1, - "gamma_rot"}}, /* 57 from thermostat.cpp */ + {&brownian.gamma_rotation, Datafield::Type::DOUBLE, 1, + "brownian.gamma_rotation"}}, /* 57 from thermostat.cpp */ #else {FIELD_BROWNIAN_GAMMA_ROTATION, - {brownian_gamma_rotation.data(), Datafield::Type::DOUBLE, 3, - "gamma_rot"}}, /* 57 from thermostat.cpp */ + {brownian.gamma_rotation.data(), Datafield::Type::DOUBLE, 3, + "brownian.gamma_rotation"}}, /* 57 from thermostat.cpp */ #endif #ifndef PARTICLE_ANISOTROPY {FIELD_BROWNIAN_GAMMA, - {&brownian_gamma, Datafield::Type::DOUBLE, 1, - "gamma"}}, /* 58 from thermostat.cpp */ + {&brownian.gamma, Datafield::Type::DOUBLE, 1, + "brownian.gamma"}}, /* 58 from thermostat.cpp */ #else {FIELD_BROWNIAN_GAMMA, - {brownian_gamma.data(), Datafield::Type::DOUBLE, 3, - "gamma"}}, /* 58 from thermostat.cpp */ + {brownian.gamma.data(), Datafield::Type::DOUBLE, 3, + "brownian.gamma"}}, /* 58 from thermostat.cpp */ #endif // PARTICLE_ANISOTROPY }; diff --git a/src/core/global.hpp b/src/core/global.hpp index f78984e5784..30e5417b11d 100644 --- a/src/core/global.hpp +++ b/src/core/global.hpp @@ -99,9 +99,9 @@ enum Fields { FIELD_FORCE_CAP, FIELD_THERMO_VIRTUAL, FIELD_SWIMMING_PARTICLES_EXIST, - /** index of \ref brownian_gamma */ + /** index of \ref BrownianThermostat::gamma */ FIELD_BROWNIAN_GAMMA, - /** index of \ref brownian_gamma_rotation */ + /** index of \ref BrownianThermostat::gamma_rotation */ FIELD_BROWNIAN_GAMMA_ROTATION, }; diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 78b1b1df3fd..35ae8a3d09c 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -1,23 +1,23 @@ /* - Copyright (C) 2010-2018 The ESPResSo project - Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - Max-Planck-Institute for Polymer Research, Theory Group - - This file is part of ESPResSo. - - ESPResSo is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - ESPResSo is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ + * Copyright (C) 2010-2019 The ESPResSo project + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 + * Max-Planck-Institute for Polymer Research, Theory Group + * + * This file is part of ESPResSo. + * + * ESPResSo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ESPResSo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ /** \file */ #ifndef BROWNIAN_INLINE_HPP @@ -26,6 +26,8 @@ #include "random.hpp" #include "thermostat.hpp" +extern BrownianThermostat brownian; + /** Propagate position: viscous drag driven by conservative forces. * From eq. (14.39) in @cite Schlick2010. * @param[in,out] p Particle @@ -41,7 +43,7 @@ inline void bd_drag(Particle &p, double dt) { } else #endif { - local_gamma = brownian_gamma; + local_gamma = brownian.gamma; } bool aniso_flag; // particle anisotropy flag @@ -114,7 +116,7 @@ inline void bd_drag_vel(Particle &p, double dt) { } else #endif { - local_gamma = brownian_gamma; + local_gamma = brownian.gamma; } bool aniso_flag; // particle anisotropy flag @@ -195,52 +197,42 @@ void bd_random_walk(Particle &p, double dt) { extern bool thermo_virtual; if (p.p.is_virtual && !thermo_virtual) return; - // Position dispersion is defined by the second eq. (14.38) of Schlick2010 - // taking into account eq. (14.35). Its time interval factor will be added at - // the end of this function. Its square root is the standard deviation. A - // multiplicative inverse of the position standard deviation: - extern Thermostat::GammaType brown_sigma_pos_inv; - // Just a NAN setter, technical variable: - extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults - Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_inv; + Thermostat::GammaType brown_sigma_pos_inv = brownian.sigma_pos_inv; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brownian_temp_coeff = 2.0; + auto const constexpr brown_temp_coeff = 2.0; if (p.p.gamma >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_temp_inv = - sqrt(p.p.gamma / (brownian_temp_coeff * p.p.T)); + brown_sigma_pos_inv = sqrt(p.p.gamma / (brown_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = - brown_gammatype_nan; // just an indication of the infinity + // just an indication of the infinity + brown_sigma_pos_inv = brownian.gammatype_nan; } } else - // Default temperature but particle-specific gamma + // default temperature but particle-specific gamma if (temperature > 0.0) { - brown_sigma_pos_temp_inv = - sqrt(p.p.gamma / (brownian_temp_coeff * temperature)); + brown_sigma_pos_inv = sqrt(p.p.gamma / (brown_temp_coeff * temperature)); } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; + brown_sigma_pos_inv = brownian.gammatype_nan; } - } // particle specific gamma + } // particle-specific gamma else { // No particle-specific gamma, but is there particle-specific temperature if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_temp_inv = - sqrt(brownian_gamma / (brownian_temp_coeff * p.p.T)); + brown_sigma_pos_inv = sqrt(brownian.gamma / (brown_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = - brown_gammatype_nan; // just an indication of the infinity + // just an indication of the infinity + brown_sigma_pos_inv = brownian.gammatype_nan; } } else { - // Defaut values for both - brown_sigma_pos_temp_inv = brown_sigma_pos_inv; + // default values for both + brown_sigma_pos_inv = brownian.sigma_pos_inv; } } #endif /* BROWNIAN_PER_PARTICLE */ @@ -249,8 +241,8 @@ void bd_random_walk(Particle &p, double dt) { #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (brown_sigma_pos_temp_inv[0] != brown_sigma_pos_temp_inv[1]) || - (brown_sigma_pos_temp_inv[1] != brown_sigma_pos_temp_inv[2]); + aniso_flag = (brown_sigma_pos_inv[0] != brown_sigma_pos_inv[1]) || + (brown_sigma_pos_inv[1] != brown_sigma_pos_inv[2]); #else aniso_flag = false; #endif // PARTICLE_ANISOTROPY @@ -260,23 +252,22 @@ void bd_random_walk(Particle &p, double dt) { // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared // magnitude defined in the second eq. (14.38), Schlick2010. Utils::Vector3d noise = Random::v_noise_g( - brownian_rng_counter->value(), p.p.identity); + brownian.rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { #ifndef PARTICLE_ANISOTROPY - if (brown_sigma_pos_temp_inv > 0.0) { - delta_pos_body[j] = - (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt) * noise[j]; + if (brown_sigma_pos_inv > 0.0) { + delta_pos_body[j] = (1.0 / brown_sigma_pos_inv) * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } #else - if (brown_sigma_pos_temp_inv[j] > 0.0) { + if (brown_sigma_pos_inv[j] > 0.0) { delta_pos_body[j] = - (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt) * noise[j]; + (1.0 / brown_sigma_pos_inv[j]) * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } @@ -312,25 +303,24 @@ inline void bd_random_walk_vel(Particle &p, double dt) { return; // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs // afterwards, Pottier2010 - extern double brown_sigma_vel; - double brown_sigma_vel_temp; + double brown_sigma_vel; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brownian_temp_coeff = 1.0; + auto const constexpr brown_temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - brown_sigma_vel_temp = sqrt(brownian_temp_coeff * p.p.T); + brown_sigma_vel = sqrt(brown_temp_coeff * p.p.T); } else { - brown_sigma_vel_temp = brown_sigma_vel; + brown_sigma_vel = brownian.sigma_vel; } #else // defaults - brown_sigma_vel_temp = brown_sigma_vel; + brown_sigma_vel = brownian.sigma_vel; #endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d noise = Random::v_noise_g( - brownian_rng_counter->value(), p.identity()); + brownian.rng_counter->value(), p.identity()); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -344,7 +334,7 @@ inline void bd_random_walk_vel(Particle &p, double dt) { // of Schlick2010. A difference is the mass factor to the friction tensor. // The noise is Gaussian according to the convention at p. 237 (last // paragraph), Pottier2010. - p.m.v[j] += brown_sigma_vel_temp * noise[j] / sqrt(p.p.mass); + p.m.v[j] += brown_sigma_vel * noise[j] / sqrt(p.p.mass); } } } @@ -365,7 +355,7 @@ void bd_drag_rot(Particle &p, double dt) { } else #endif { - local_gamma = brownian_gamma_rotation; + local_gamma = brownian.gamma_rotation; } Utils::Vector3d dphi = {0.0, 0.0, 0.0}; @@ -405,7 +395,7 @@ void bd_drag_vel_rot(Particle &p, double dt) { } else #endif { - local_gamma = brownian_gamma_rotation; + local_gamma = brownian.gamma_rotation; } for (int j = 0; j < 3; j++) { @@ -434,68 +424,65 @@ void bd_drag_vel_rot(Particle &p, double dt) { * @param[in] dt Time interval */ void bd_random_walk_rot(Particle &p, double dt) { - extern Thermostat::GammaType brown_sigma_pos_rotation_inv; - extern Thermostat::GammaType brown_gammatype_nan; // first, set defaults - Thermostat::GammaType brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; + Thermostat::GammaType brown_sigma_pos_inv = brownian.sigma_pos_rotation_inv; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brownian_temp_coeff = 2.0; + auto const constexpr brown_temp_coeff = 2.0; if (p.p.gamma_rot >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_temp_inv = - sqrt(p.p.gamma_rot / (brownian_temp_coeff * p.p.T)); + brown_sigma_pos_inv = sqrt(p.p.gamma_rot / (brown_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = - brown_gammatype_nan; // just an indication of the infinity + // just an indication of the infinity + brown_sigma_pos_inv = brownian.gammatype_nan; } - } else - // Default temperature but particle-specific gamma - if (temperature > 0.) { - brown_sigma_pos_temp_inv = - sqrt(p.p.gamma_rot / (brownian_temp_coeff * temperature)); + } else if (temperature > 0.) { + // Default temperature but particle-specific gamma + brown_sigma_pos_inv = + sqrt(p.p.gamma_rot / (brown_temp_coeff * temperature)); } else { - brown_sigma_pos_temp_inv = brown_gammatype_nan; + // just an indication of the infinity + brown_sigma_pos_inv = brownian.gammatype_nan; } - } // particle specific gamma + } // particle-specific gamma else { // No particle-specific gamma, but is there particle-specific temperature if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_temp_inv = - sqrt(brownian_gamma_rotation / (brownian_temp_coeff * p.p.T)); + brown_sigma_pos_inv = + sqrt(brownian.gamma_rotation / (brown_temp_coeff * p.p.T)); } else { - brown_sigma_pos_temp_inv = - brown_gammatype_nan; // just an indication of the infinity + // just an indication of the infinity + brown_sigma_pos_inv = brownian.gammatype_nan; } } else { // Defaut values for both - brown_sigma_pos_temp_inv = brown_sigma_pos_rotation_inv; + brown_sigma_pos_inv = brownian.sigma_pos_rotation_inv; } } #endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d dphi = {0.0, 0.0, 0.0}; Utils::Vector3d noise = Random::v_noise_g( - brownian_rng_counter->value(), p.p.identity); + brownian.rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { #ifndef PARTICLE_ANISOTROPY - if (brown_sigma_pos_temp_inv > 0.0) { - dphi[j] = noise[j] * (1.0 / brown_sigma_pos_temp_inv) * sqrt(dt); + if (brown_sigma_pos_inv > 0.0) { + dphi[j] = noise[j] * (1.0 / brown_sigma_pos_inv) * sqrt(dt); } else { dphi[j] = 0.0; } #else - if (brown_sigma_pos_temp_inv[j] > 0.0) { - dphi[j] = noise[j] * (1.0 / brown_sigma_pos_temp_inv[j]) * sqrt(dt); + if (brown_sigma_pos_inv[j] > 0.0) { + dphi[j] = noise[j] * (1.0 / brown_sigma_pos_inv[j]) * sqrt(dt); } else { dphi[j] = 0.0; } @@ -518,26 +505,25 @@ void bd_random_walk_rot(Particle &p, double dt) { * @param[in] dt Time interval */ void bd_random_walk_vel_rot(Particle &p, double dt) { - extern double brown_sigma_vel_rotation; - double brown_sigma_vel_temp; + double brown_sigma_vel; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brownian_temp_coeff = 1.0; + auto const constexpr brown_temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - brown_sigma_vel_temp = sqrt(brownian_temp_coeff * p.p.T); + brown_sigma_vel = sqrt(brown_temp_coeff * p.p.T); } else { - brown_sigma_vel_temp = brown_sigma_vel_rotation; + brown_sigma_vel = brownian.sigma_vel_rotation; } #else // set defaults - brown_sigma_vel_temp = brown_sigma_vel_rotation; + brown_sigma_vel = brownian.sigma_vel_rotation; #endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d domega; Utils::Vector3d noise = Random::v_noise_g( - brownian_rng_counter->value(), p.p.identity); + brownian.rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -545,7 +531,7 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { { // velocity is added here. It is already initialized in the terminal drag // part. - domega[j] = brown_sigma_vel_temp * noise[j] / sqrt(p.p.rinertia[j]); + domega[j] = brown_sigma_vel * noise[j] / sqrt(p.p.rinertia[j]); } } domega = mask(p.p.rotation, domega); @@ -554,7 +540,6 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { #endif // ROTATION inline void brownian_dynamics_propagator(const ParticleRange &particles) { - auto const skin2 = Utils::sqr(0.5 * skin); for (auto &p : particles) { // Don't propagate translational degrees of freedom of vs #ifdef VIRTUAL_SITES @@ -565,11 +550,8 @@ inline void brownian_dynamics_propagator(const ParticleRange &particles) { bd_drag_vel(p, time_step); bd_random_walk(p, time_step); bd_random_walk_vel(p, time_step); - /* Verlet criterion check*/ - if (Utils::sqr(p.r.p[0] - p.l.p_old[0]) + - Utils::sqr(p.r.p[1] - p.l.p_old[1]) + - Utils::sqr(p.r.p[2] - p.l.p_old[2]) > - skin2) + /* Verlet criterion check */ + if ((p.r.p - p.l.p_old).norm2() > Utils::sqr(0.5 * skin)) set_resort_particles(Cells::RESORT_LOCAL); } #ifdef ROTATION diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index caa2a98b265..63355bbc75b 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -46,14 +46,7 @@ GammaType langevin_gamma_rotation = sentinel(GammaType{}); GammaType langevin_pref1; GammaType langevin_pref2; GammaType langevin_pref2_rotation; -GammaType brownian_gamma = sentinel(GammaType{}); -GammaType brownian_gamma_rotation = sentinel(GammaType{}); -// Brownian position random walk standard deviation -GammaType brown_sigma_pos_inv = sentinel(GammaType{}); -GammaType brown_sigma_pos_rotation_inv = sentinel(GammaType{}); -GammaType brown_gammatype_nan = set_nan(GammaType{}); -double brown_sigma_vel; -double brown_sigma_vel_rotation; +BrownianThermostat brownian = {}; /* NPT ISOTROPIC THERMOSTAT */ double nptiso_gamma0 = 0.0; @@ -76,7 +69,6 @@ double nptiso_pref4; #endif std::unique_ptr> langevin_rng_counter; -std::unique_ptr> brownian_rng_counter; void mpi_bcast_langevin_rng_counter_slave(const uint64_t counter) { langevin_rng_counter = std::make_unique>(counter); @@ -85,7 +77,7 @@ void mpi_bcast_langevin_rng_counter_slave(const uint64_t counter) { REGISTER_CALLBACK(mpi_bcast_langevin_rng_counter_slave) void mpi_bcast_brownian_rng_counter_slave(const uint64_t counter) { - brownian_rng_counter = std::make_unique>(counter); + brownian.rng_counter = std::make_unique>(counter); } REGISTER_CALLBACK(mpi_bcast_brownian_rng_counter_slave) @@ -105,7 +97,7 @@ void langevin_rng_counter_increment() { void brownian_rng_counter_increment() { if (thermo_switch & THERMO_BROWNIAN) - brownian_rng_counter->increment(); + brownian.rng_counter->increment(); } bool langevin_is_seed_required() { @@ -115,7 +107,7 @@ bool langevin_is_seed_required() { bool brownian_is_seed_required() { /* Seed is required if rng is not initialized */ - return brownian_rng_counter == nullptr; + return brownian.rng_counter == nullptr; } void langevin_set_rng_state(const uint64_t counter) { @@ -125,12 +117,12 @@ void langevin_set_rng_state(const uint64_t counter) { void brownian_set_rng_state(const uint64_t counter) { mpi_bcast_brownian_rng_counter(counter); - brownian_rng_counter = std::make_unique>(counter); + brownian.rng_counter = std::make_unique>(counter); } uint64_t langevin_get_rng_state() { return langevin_rng_counter->value(); } -uint64_t brownian_get_rng_state() { return brownian_rng_counter->value(); } +uint64_t brownian_get_rng_state() { return brownian.rng_counter->value(); } void thermo_init_langevin() { langevin_pref1 = -langevin_gamma; @@ -168,18 +160,16 @@ void thermo_init_brownian() { * which is only valid for the BD. Just a square root of kT, see (10.2.17) * and comments in 2 paragraphs afterwards, @cite Pottier2010. */ - // Heat velocity dispersion: - brown_sigma_vel = sqrt(temperature); + brownian.sigma_vel = sqrt(temperature); /** The random walk position dispersion is defined by the second eq. (14.38) * of @cite Schlick2010. Its time interval factor will be added in the * Brownian Dynamics functions. Its square root is the standard deviation. */ - // A multiplicative inverse of the position standard deviation: if (temperature > 0.0) { - brown_sigma_pos_inv = sqrt(brownian_gamma / (2.0 * temperature)); + brownian.sigma_pos_inv = sqrt(brownian.gamma / (2.0 * temperature)); } else { - brown_sigma_pos_inv = - brown_gammatype_nan; // just an indication of the infinity + brownian.sigma_pos_inv = + brownian.gammatype_nan; // just an indication of the infinity } #ifdef ROTATION /** Note: the BD thermostat assigns the brownian viscous parameters as well. @@ -188,16 +178,16 @@ void thermo_init_brownian() { */ /* If gamma_rotation is not set explicitly, we use the translational one. */ - if (brownian_gamma_rotation < GammaType{}) { - brownian_gamma_rotation = brownian_gamma; + if (brownian.gamma_rotation < GammaType{}) { + brownian.gamma_rotation = brownian.gamma; } - brown_sigma_vel_rotation = sqrt(temperature); - // A multiplicative inverse of the position rotation standard deviation: + brownian.sigma_vel_rotation = sqrt(temperature); if (temperature > 0.0) { - brown_sigma_pos_rotation_inv = sqrt(brownian_gamma / (2.0 * temperature)); + brownian.sigma_pos_rotation_inv = + sqrt(brownian.gamma / (2.0 * temperature)); } else { - brown_sigma_pos_rotation_inv = - brown_gammatype_nan; // just an indication of the infinity + brownian.sigma_pos_rotation_inv = + brownian.gammatype_nan; // just an indication of the infinity } #endif // ROTATION } diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 4422bf4392a..c15c4246896 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -109,13 +109,39 @@ extern double nptiso_gammav; /** Langevin RNG counter, used for both translation and rotation. */ extern std::unique_ptr> langevin_rng_counter; -/** Brownian friction coefficient gamma for translation. */ -extern Thermostat::GammaType brownian_gamma; -/** Brownian friction coefficient gamma for rotation. */ -extern Thermostat::GammaType brownian_gamma_rotation; - -/** Brownian RNG counter, used for both translation and rotation. */ -extern std::unique_ptr> brownian_rng_counter; +/** %Thermostat for Brownian dynamics. */ +struct BrownianThermostat { +private: + using GammaType = Thermostat::GammaType; + +public: + /** Translational friction coefficient @f$ \gamma_{\text{trans}} @f$. */ + GammaType gamma = sentinel(GammaType{}); + /** Rotational friction coefficient @f$ \gamma_{\text{rot}} @f$. */ + GammaType gamma_rotation = sentinel(GammaType{}); + /** Inverse of the translational noise standard deviation. + * Stores @f$ \left(\sqrt{2D_{\text{trans}}}\right)^{-1} @f$ with + * @f$ D_{\text{trans}} = k_B T/\gamma_{\text{trans}} @f$ + * the translational diffusion coefficient + */ + GammaType sigma_pos_inv = sentinel(GammaType{}); + /** Inverse of the rotational noise standard deviation. + * Stores @f$ \left(\sqrt{2D_{\text{rot}}}\right)^{-1} @f$ with + * @f$ D_{\text{rot}} = k_B T/\gamma_{\text{rot}} @f$ + * the rotational diffusion coefficient + */ + GammaType sigma_pos_rotation_inv = sentinel(GammaType{}); + /** Sentinel value for divisions by zero. */ + GammaType const gammatype_nan = set_nan(GammaType{}); + /** Translational velocity noise standard deviation. */ + double sigma_vel = 0; + /** Angular velocity noise standard deviation. */ + double sigma_vel_rotation = 0; + /** RNG counter, used for both translation and rotation. */ + std::unique_ptr> rng_counter; +}; + +extern BrownianThermostat brownian; /************************************************ * functions diff --git a/src/python/espressomd/thermostat.pxd b/src/python/espressomd/thermostat.pxd index 0a5d988343e..860cae7cd1f 100644 --- a/src/python/espressomd/thermostat.pxd +++ b/src/python/espressomd/thermostat.pxd @@ -36,13 +36,21 @@ cdef extern from "thermostat.hpp": IF PARTICLE_ANISOTROPY: Vector3d langevin_gamma_rotation Vector3d langevin_gamma - Vector3d brownian_gamma_rotation - Vector3d brownian_gamma ELSE: double langevin_gamma_rotation double langevin_gamma - double brownian_gamma_rotation - double brownian_gamma + + IF PARTICLE_ANISOTROPY: + ctypedef struct brownian_thermostat_struct "BrownianThermostat": + Vector3d gamma_rotation + Vector3d gamma + ELSE: + ctypedef struct brownian_thermostat_struct "BrownianThermostat": + double gamma_rotation + double gamma + + # links intern C-struct with python object + cdef extern brownian_thermostat_struct brownian void langevin_set_rng_state(stdint.uint64_t counter) void brownian_set_rng_state(stdint.uint64_t counter) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index f1774b56c2e..e2b0798be8e 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -157,18 +157,18 @@ cdef class Thermostat: lang_dict["act_on_virtual"] = thermo_virtual lang_dict["seed"] = int(brownian_get_rng_state()) IF PARTICLE_ANISOTROPY: - lang_dict["gamma"] = [brownian_gamma[0], - brownian_gamma[1], - brownian_gamma[2]] + lang_dict["gamma"] = [brownian.gamma[0], + brownian.gamma[1], + brownian.gamma[2]] ELSE: - lang_dict["gamma"] = brownian_gamma + lang_dict["gamma"] = brownian.gamma IF ROTATION: IF PARTICLE_ANISOTROPY: - lang_dict["gamma_rotation"] = [brownian_gamma_rotation[0], - brownian_gamma_rotation[1], - brownian_gamma_rotation[2]] + lang_dict["gamma_rotation"] = [brownian.gamma_rotation[0], + brownian.gamma_rotation[1], + brownian.gamma_rotation[2]] ELSE: - lang_dict["gamma_rotation"] = brownian_gamma_rotation + lang_dict["gamma_rotation"] = brownian.gamma_rotation ELSE: lang_dict["gamma_rotation"] = None @@ -217,12 +217,12 @@ cdef class Thermostat: ELSE: langevin_gamma = 0. mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA) - global brownian_gamma + global brownian IF PARTICLE_ANISOTROPY: for i in range(3): - brownian_gamma[i] = 0. + brownian.gamma[i] = 0. ELSE: - brownian_gamma = 0. + brownian.gamma = 0. mpi_bcast_parameter(FIELD_BROWNIAN_GAMMA) global langevin_gamma_rotation IF ROTATION: @@ -232,13 +232,12 @@ cdef class Thermostat: ELSE: langevin_gamma_rotation = 0. mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA_ROTATION) - global brownian_gamma_rotation IF ROTATION: IF PARTICLE_ANISOTROPY: for i in range(3): - brownian_gamma_rotation[i] = 0. + brownian.gamma_rotation[i] = 0. ELSE: - brownian_gamma_rotation = 0. + brownian.gamma_rotation = 0. mpi_bcast_parameter(FIELD_BROWNIAN_GAMMA_ROTATION) global thermo_switch @@ -494,49 +493,47 @@ cdef class Thermostat: global temperature temperature = float(kT) - global brownian_gamma + global brownian IF PARTICLE_ANISOTROPY: if scalar_gamma_def: - brownian_gamma[0] = gamma - brownian_gamma[1] = gamma - brownian_gamma[2] = gamma + brownian.gamma[0] = gamma + brownian.gamma[1] = gamma + brownian.gamma[2] = gamma else: - brownian_gamma[0] = gamma[0] - brownian_gamma[1] = gamma[1] - brownian_gamma[2] = gamma[2] + brownian.gamma[0] = gamma[0] + brownian.gamma[1] = gamma[1] + brownian.gamma[2] = gamma[2] ELSE: - brownian_gamma = float(gamma) - - global brownian_gamma_rotation + brownian.gamma = float(gamma) IF ROTATION: if gamma_rotation is not None: IF PARTICLE_ANISOTROPY: if scalar_gamma_rot_def: - brownian_gamma_rotation[0] = gamma_rotation - brownian_gamma_rotation[1] = gamma_rotation - brownian_gamma_rotation[2] = gamma_rotation + brownian.gamma_rotation[0] = gamma_rotation + brownian.gamma_rotation[1] = gamma_rotation + brownian.gamma_rotation[2] = gamma_rotation else: - brownian_gamma_rotation[0] = gamma_rotation[0] - brownian_gamma_rotation[1] = gamma_rotation[1] - brownian_gamma_rotation[2] = gamma_rotation[2] + brownian.gamma_rotation[0] = gamma_rotation[0] + brownian.gamma_rotation[1] = gamma_rotation[1] + brownian.gamma_rotation[2] = gamma_rotation[2] ELSE: if scalar_gamma_rot_def: - brownian_gamma_rotation = gamma_rotation + brownian.gamma_rotation = gamma_rotation else: raise ValueError( "gamma_rotation must be a scalar since feature PARTICLE_ANISOTROPY is disabled") else: IF PARTICLE_ANISOTROPY: if scalar_gamma_def: - brownian_gamma_rotation[0] = gamma - brownian_gamma_rotation[1] = gamma - brownian_gamma_rotation[2] = gamma + brownian.gamma_rotation[0] = gamma + brownian.gamma_rotation[1] = gamma + brownian.gamma_rotation[2] = gamma else: - brownian_gamma_rotation[0] = gamma[0] - brownian_gamma_rotation[1] = gamma[1] - brownian_gamma_rotation[2] = gamma[2] + brownian.gamma_rotation[0] = gamma[0] + brownian.gamma_rotation[1] = gamma[1] + brownian.gamma_rotation[2] = gamma[2] ELSE: - brownian_gamma_rotation = brownian_gamma + brownian.gamma_rotation = brownian.gamma global thermo_switch thermo_switch = (thermo_switch | THERMO_BROWNIAN) From 3821370d8a9e8177ad97e9e677d01e417af84389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 22 Jan 2020 19:26:39 +0100 Subject: [PATCH 121/150] Move Langevin Dynamics globals in a struct --- src/core/global.cpp | 16 +++--- src/core/global.hpp | 4 +- src/core/thermostat.cpp | 39 +++++--------- src/core/thermostat.hpp | 81 +++++++++++++++------------- src/python/espressomd/thermostat.pxd | 14 ++--- src/python/espressomd/thermostat.pyx | 73 ++++++++++++------------- 6 files changed, 108 insertions(+), 119 deletions(-) diff --git a/src/core/global.cpp b/src/core/global.cpp index c6dc5802fc3..e03b929a255 100644 --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -78,12 +78,12 @@ const std::unordered_map fields{ "cell_grid"}}, /* 1 from cells.cpp */ #ifndef PARTICLE_ANISOTROPY {FIELD_LANGEVIN_GAMMA, - {&langevin_gamma, Datafield::Type::DOUBLE, 1, - "gamma"}}, /* 5 from thermostat.cpp */ + {&langevin.gamma, Datafield::Type::DOUBLE, 1, + "langevin.gamma"}}, /* 5 from thermostat.cpp */ #else {FIELD_LANGEVIN_GAMMA, - {langevin_gamma.data(), Datafield::Type::DOUBLE, 3, - "gamma"}}, /* 5 from thermostat.cpp */ + {langevin.gamma.data(), Datafield::Type::DOUBLE, 3, + "langevin.gamma"}}, /* 5 from thermostat.cpp */ #endif // PARTICLE_ANISOTROPY {FIELD_INTEG_SWITCH, {&integ_switch, Datafield::Type::INT, 1, @@ -152,12 +152,12 @@ const std::unordered_map fields{ "swimming_particles_exist"}}, /* from particle_data.cpp */ #ifndef PARTICLE_ANISOTROPY {FIELD_LANGEVIN_GAMMA_ROTATION, - {&langevin_gamma_rotation, Datafield::Type::DOUBLE, 1, - "gamma_rot"}}, /* 55 from thermostat.cpp */ + {&langevin.gamma_rotation, Datafield::Type::DOUBLE, 1, + "langevin.gamma_rotation"}}, /* 55 from thermostat.cpp */ #else {FIELD_LANGEVIN_GAMMA_ROTATION, - {langevin_gamma_rotation.data(), Datafield::Type::DOUBLE, 3, - "gamma_rot"}}, /* 55 from thermostat.cpp */ + {langevin.gamma_rotation.data(), Datafield::Type::DOUBLE, 3, + "langevin.gamma_rotation"}}, /* 55 from thermostat.cpp */ #endif #ifdef OIF_GLOBAL_FORCES {FIELD_MAX_OIF_OBJECTS, diff --git a/src/core/global.hpp b/src/core/global.hpp index 30e5417b11d..44d69bd16ed 100644 --- a/src/core/global.hpp +++ b/src/core/global.hpp @@ -48,7 +48,7 @@ enum Fields { FIELD_BOXL = 0, /** index of \ref DomainDecomposition::cell_grid */ FIELD_CELLGRID, - /** index of \ref langevin_gamma */ + /** index of \ref LangevinThermostat::gamma */ FIELD_LANGEVIN_GAMMA, /** index of \ref integ_switch */ FIELD_INTEG_SWITCH, @@ -91,7 +91,7 @@ enum Fields { FIELD_LATTICE_SWITCH, /** index of \ref min_global_cut */ FIELD_MIN_GLOBAL_CUT, - /** index of \ref langevin_gamma_rotation */ + /** index of \ref LangevinThermostat::gamma_rotation */ FIELD_LANGEVIN_GAMMA_ROTATION, FIELD_MAX_OIF_OBJECTS, // soft objects as per the object-in-fluid method /** index of \ref n_thermalized_bonds */ diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 63355bbc75b..bf1cf025594 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -41,26 +41,13 @@ bool thermo_virtual = true; using Thermostat::GammaType; -GammaType langevin_gamma = sentinel(GammaType{}); -GammaType langevin_gamma_rotation = sentinel(GammaType{}); -GammaType langevin_pref1; -GammaType langevin_pref2; -GammaType langevin_pref2_rotation; +LangevinThermostat langevin = {}; BrownianThermostat brownian = {}; /* NPT ISOTROPIC THERMOSTAT */ double nptiso_gamma0 = 0.0; double nptiso_gammav = 0.0; -/** @name Langevin buffers - * Buffers for the workaround for the correlated random values which cool the - * system, and require a magical heat up whenever reentering the integrator. - */ -/*@{*/ -static GammaType langevin_pref2_buffer; -static GammaType langevin_pref2_rotation_buffer; -/*@}*/ - #ifdef NPT double nptiso_pref1; double nptiso_pref2; @@ -68,10 +55,8 @@ double nptiso_pref3; double nptiso_pref4; #endif -std::unique_ptr> langevin_rng_counter; - void mpi_bcast_langevin_rng_counter_slave(const uint64_t counter) { - langevin_rng_counter = std::make_unique>(counter); + langevin.rng_counter = std::make_unique>(counter); } REGISTER_CALLBACK(mpi_bcast_langevin_rng_counter_slave) @@ -92,7 +77,7 @@ void mpi_bcast_brownian_rng_counter(const uint64_t counter) { void langevin_rng_counter_increment() { if (thermo_switch & THERMO_LANGEVIN) - langevin_rng_counter->increment(); + langevin.rng_counter->increment(); } void brownian_rng_counter_increment() { @@ -102,7 +87,7 @@ void brownian_rng_counter_increment() { bool langevin_is_seed_required() { /* Seed is required if rng is not initialized */ - return langevin_rng_counter == nullptr; + return langevin.rng_counter == nullptr; } bool brownian_is_seed_required() { @@ -112,7 +97,7 @@ bool brownian_is_seed_required() { void langevin_set_rng_state(const uint64_t counter) { mpi_bcast_langevin_rng_counter(counter); - langevin_rng_counter = std::make_unique>(counter); + langevin.rng_counter = std::make_unique>(counter); } void brownian_set_rng_state(const uint64_t counter) { @@ -120,21 +105,21 @@ void brownian_set_rng_state(const uint64_t counter) { brownian.rng_counter = std::make_unique>(counter); } -uint64_t langevin_get_rng_state() { return langevin_rng_counter->value(); } +uint64_t langevin_get_rng_state() { return langevin.rng_counter->value(); } uint64_t brownian_get_rng_state() { return brownian.rng_counter->value(); } void thermo_init_langevin() { - langevin_pref1 = -langevin_gamma; - langevin_pref2 = sqrt(24.0 * temperature / time_step * langevin_gamma); + langevin.pref_friction = -langevin.gamma; + langevin.pref_noise = sqrt(24.0 * temperature / time_step * langevin.gamma); /* If gamma_rotation is not set explicitly, use the linear one. */ - if (langevin_gamma_rotation < GammaType{}) { - langevin_gamma_rotation = langevin_gamma; + if (langevin.gamma_rotation < GammaType{}) { + langevin.gamma_rotation = langevin.gamma; } - langevin_pref2_rotation = - sqrt(24.0 * temperature * langevin_gamma_rotation / time_step); + langevin.pref_noise_rotation = + sqrt(24.0 * temperature * langevin.gamma_rotation / time_step); } #ifdef NPT diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index c15c4246896..97a203b42be 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -92,10 +92,27 @@ extern double temperature; /** True if the thermostat should act on virtual particles. */ extern bool thermo_virtual; -/** Langevin friction coefficient gamma for translation. */ -extern Thermostat::GammaType langevin_gamma; -/** Langevin friction coefficient gamma for rotation. */ -extern Thermostat::GammaType langevin_gamma_rotation; +/** %Thermostat for Langevin dynamics. */ +struct LangevinThermostat { +private: + using GammaType = Thermostat::GammaType; + +public: + /** Translational friction coefficient @f$ \gamma_{\text{trans}} @f$. */ + GammaType gamma = sentinel(GammaType{}); + /** Rotational friction coefficient @f$ \gamma_{\text{rot}} @f$. */ + GammaType gamma_rotation = sentinel(GammaType{}); + /** Prefactor for the friction. */ + GammaType pref_friction; + /** Prefactor for the translational velocity noise. */ + GammaType pref_noise; + /** Prefactor for the angular velocity noise. */ + GammaType pref_noise_rotation; + /** RNG counter, used for both translation and rotation. */ + std::unique_ptr> rng_counter; +}; + +extern LangevinThermostat langevin; /** Friction coefficient for nptiso-thermostat's function * @ref friction_therm0_nptiso @@ -106,9 +123,6 @@ extern double nptiso_gamma0; */ extern double nptiso_gammav; -/** Langevin RNG counter, used for both translation and rotation. */ -extern std::unique_ptr> langevin_rng_counter; - /** %Thermostat for Brownian dynamics. */ struct BrownianThermostat { private: @@ -210,22 +224,19 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { return {}; } - // Determine prefactors for the friction (pref1) and the noise (pref2) term - extern Thermostat::GammaType langevin_pref1; - extern Thermostat::GammaType langevin_pref2; + // Determine prefactors for the friction and the noise term // first, set defaults - Thermostat::GammaType langevin_pref_friction_buf = langevin_pref1; - Thermostat::GammaType langevin_pref_noise_buf = langevin_pref2; + Thermostat::GammaType langevin_pref_friction = langevin.pref_friction; + Thermostat::GammaType langevin_pref_noise = langevin.pref_noise; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{} or p.p.T >= 0.) { auto const constexpr langevin_temp_coeff = 24.0; auto const kT = p.p.T >= 0. ? p.p.T : temperature; auto const gamma = - p.p.gamma >= Thermostat::GammaType{} ? p.p.gamma : langevin_gamma; - langevin_pref_friction_buf = -gamma; - langevin_pref_noise_buf = - sqrt(langevin_temp_coeff * kT * gamma / time_step); + p.p.gamma >= Thermostat::GammaType{} ? p.p.gamma : langevin.gamma; + langevin_pref_friction = -gamma; + langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); } #endif /* LANGEVIN_PER_PARTICLE */ @@ -240,25 +251,24 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check auto const aniso_flag = - (langevin_pref_friction_buf[0] != langevin_pref_friction_buf[1]) || - (langevin_pref_friction_buf[1] != langevin_pref_friction_buf[2]); + (langevin_pref_friction[0] != langevin_pref_friction[1]) || + (langevin_pref_friction[1] != langevin_pref_friction[2]); // In case of anisotropic particle: body-fixed reference frame. Otherwise: // lab-fixed reference frame. auto const friction_op = - aniso_flag - ? convert_body_to_space(p, diag_matrix(langevin_pref_friction_buf)) - : diag_matrix(langevin_pref_friction_buf); - auto const noise_op = diag_matrix(langevin_pref_noise_buf); + aniso_flag ? convert_body_to_space(p, diag_matrix(langevin_pref_friction)) + : diag_matrix(langevin_pref_friction); + auto const noise_op = diag_matrix(langevin_pref_noise); #else - auto const &friction_op = langevin_pref_friction_buf; - auto const &noise_op = langevin_pref_noise_buf; + auto const &friction_op = langevin_pref_friction; + auto const &noise_op = langevin_pref_noise; #endif // PARTICLE_ANISOTROPY using Random::v_noise; // Do the actual (isotropic) thermostatting return friction_op * velocity + - noise_op * v_noise(langevin_rng_counter->value(), + noise_op * v_noise(langevin.rng_counter->value(), p.p.identity); } @@ -269,10 +279,9 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. */ inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { - extern Thermostat::GammaType langevin_pref2_rotation; - auto langevin_pref_friction_buf = -langevin_gamma_rotation; - auto langevin_pref_noise_buf = langevin_pref2_rotation; + auto langevin_pref_friction = -langevin.gamma_rotation; + auto langevin_pref_noise = langevin.pref_noise_rotation; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE @@ -281,10 +290,9 @@ inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { auto const kT = p.p.T >= 0. ? p.p.T : temperature; auto const gamma = p.p.gamma_rot >= Thermostat::GammaType{} ? p.p.gamma_rot - : langevin_gamma_rotation; - langevin_pref_friction_buf = -gamma; - langevin_pref_noise_buf = - sqrt(langevin_temp_coeff * kT * gamma / time_step); + : langevin.gamma_rotation; + langevin_pref_friction = -gamma; + langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); } #endif /* LANGEVIN_PER_PARTICLE */ @@ -292,13 +300,12 @@ inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { // Here the thermostats happens auto const noise = v_noise( - langevin_rng_counter->value(), p.p.identity); + langevin.rng_counter->value(), p.p.identity); #ifdef PARTICLE_ANISOTROPY - return hadamard_product(langevin_pref_friction_buf, p.m.omega) + - hadamard_product(langevin_pref_noise_buf, noise); + return hadamard_product(langevin_pref_friction, p.m.omega) + + hadamard_product(langevin_pref_noise, noise); #else - return langevin_pref_friction_buf * p.m.omega + - langevin_pref_noise_buf * noise; + return langevin_pref_friction * p.m.omega + langevin_pref_noise * noise; #endif } diff --git a/src/python/espressomd/thermostat.pxd b/src/python/espressomd/thermostat.pxd index 860cae7cd1f..0dbdb25c334 100644 --- a/src/python/espressomd/thermostat.pxd +++ b/src/python/espressomd/thermostat.pxd @@ -34,22 +34,22 @@ cdef extern from "thermostat.hpp": int THERMO_BROWNIAN IF PARTICLE_ANISOTROPY: - Vector3d langevin_gamma_rotation - Vector3d langevin_gamma - ELSE: - double langevin_gamma_rotation - double langevin_gamma - - IF PARTICLE_ANISOTROPY: + ctypedef struct langevin_thermostat_struct "LangevinThermostat": + Vector3d gamma_rotation + Vector3d gamma ctypedef struct brownian_thermostat_struct "BrownianThermostat": Vector3d gamma_rotation Vector3d gamma ELSE: + ctypedef struct langevin_thermostat_struct "LangevinThermostat": + double gamma_rotation + double gamma ctypedef struct brownian_thermostat_struct "BrownianThermostat": double gamma_rotation double gamma # links intern C-struct with python object + cdef extern langevin_thermostat_struct langevin cdef extern brownian_thermostat_struct brownian void langevin_set_rng_state(stdint.uint64_t counter) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index e2b0798be8e..0de98569447 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -134,18 +134,18 @@ cdef class Thermostat: lang_dict["act_on_virtual"] = thermo_virtual lang_dict["seed"] = int(langevin_get_rng_state()) IF PARTICLE_ANISOTROPY: - lang_dict["gamma"] = [langevin_gamma[0], - langevin_gamma[1], - langevin_gamma[2]] + lang_dict["gamma"] = [langevin.gamma[0], + langevin.gamma[1], + langevin.gamma[2]] ELSE: - lang_dict["gamma"] = langevin_gamma + lang_dict["gamma"] = langevin.gamma IF ROTATION: IF PARTICLE_ANISOTROPY: - lang_dict["gamma_rotation"] = [langevin_gamma_rotation[0], - langevin_gamma_rotation[1], - langevin_gamma_rotation[2]] + lang_dict["gamma_rotation"] = [langevin.gamma_rotation[0], + langevin.gamma_rotation[1], + langevin.gamma_rotation[2]] ELSE: - lang_dict["gamma_rotation"] = langevin_gamma_rotation + lang_dict["gamma_rotation"] = langevin.gamma_rotation ELSE: lang_dict["gamma_rotation"] = None @@ -210,12 +210,12 @@ cdef class Thermostat: temperature = 0. mpi_bcast_parameter(FIELD_THERMO_VIRTUAL) mpi_bcast_parameter(FIELD_TEMPERATURE) - global langevin_gamma + global langevin IF PARTICLE_ANISOTROPY: for i in range(3): - langevin_gamma[i] = 0. + langevin.gamma[i] = 0. ELSE: - langevin_gamma = 0. + langevin.gamma = 0. mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA) global brownian IF PARTICLE_ANISOTROPY: @@ -224,13 +224,12 @@ cdef class Thermostat: ELSE: brownian.gamma = 0. mpi_bcast_parameter(FIELD_BROWNIAN_GAMMA) - global langevin_gamma_rotation IF ROTATION: IF PARTICLE_ANISOTROPY: for i in range(3): - langevin_gamma_rotation[i] = 0. + langevin.gamma_rotation[i] = 0. ELSE: - langevin_gamma_rotation = 0. + langevin.gamma_rotation = 0. mpi_bcast_parameter(FIELD_LANGEVIN_GAMMA_ROTATION) IF ROTATION: IF PARTICLE_ANISOTROPY: @@ -341,49 +340,47 @@ cdef class Thermostat: global temperature temperature = float(kT) - global langevin_gamma + global langevin IF PARTICLE_ANISOTROPY: if scalar_gamma_def: - langevin_gamma[0] = gamma - langevin_gamma[1] = gamma - langevin_gamma[2] = gamma + langevin.gamma[0] = gamma + langevin.gamma[1] = gamma + langevin.gamma[2] = gamma else: - langevin_gamma[0] = gamma[0] - langevin_gamma[1] = gamma[1] - langevin_gamma[2] = gamma[2] + langevin.gamma[0] = gamma[0] + langevin.gamma[1] = gamma[1] + langevin.gamma[2] = gamma[2] ELSE: - langevin_gamma = float(gamma) - - global langevin_gamma_rotation + langevin.gamma = float(gamma) IF ROTATION: if gamma_rotation is not None: IF PARTICLE_ANISOTROPY: if scalar_gamma_rot_def: - langevin_gamma_rotation[0] = gamma_rotation - langevin_gamma_rotation[1] = gamma_rotation - langevin_gamma_rotation[2] = gamma_rotation + langevin.gamma_rotation[0] = gamma_rotation + langevin.gamma_rotation[1] = gamma_rotation + langevin.gamma_rotation[2] = gamma_rotation else: - langevin_gamma_rotation[0] = gamma_rotation[0] - langevin_gamma_rotation[1] = gamma_rotation[1] - langevin_gamma_rotation[2] = gamma_rotation[2] + langevin.gamma_rotation[0] = gamma_rotation[0] + langevin.gamma_rotation[1] = gamma_rotation[1] + langevin.gamma_rotation[2] = gamma_rotation[2] ELSE: if scalar_gamma_rot_def: - langevin_gamma_rotation = gamma_rotation + langevin.gamma_rotation = gamma_rotation else: raise ValueError( "gamma_rotation must be a scalar since feature PARTICLE_ANISOTROPY is disabled") else: IF PARTICLE_ANISOTROPY: if scalar_gamma_def: - langevin_gamma_rotation[0] = gamma - langevin_gamma_rotation[1] = gamma - langevin_gamma_rotation[2] = gamma + langevin.gamma_rotation[0] = gamma + langevin.gamma_rotation[1] = gamma + langevin.gamma_rotation[2] = gamma else: - langevin_gamma_rotation[0] = gamma[0] - langevin_gamma_rotation[1] = gamma[1] - langevin_gamma_rotation[2] = gamma[2] + langevin.gamma_rotation[0] = gamma[0] + langevin.gamma_rotation[1] = gamma[1] + langevin.gamma_rotation[2] = gamma[2] ELSE: - langevin_gamma_rotation = langevin_gamma + langevin.gamma_rotation = langevin.gamma global thermo_switch thermo_switch = (thermo_switch | THERMO_LANGEVIN) From ee8f47d74d3bdb18b982339c5a9d93e57e5d34d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 22 Jan 2020 19:36:23 +0100 Subject: [PATCH 122/150] Move Langevin Dynamics to dedicated header file --- src/core/forces_inline.hpp | 1 + src/core/integrate.cpp | 1 + src/core/integrators/langevin_inline.hpp | 128 +++++++++++++++++++++++ src/core/thermostat.hpp | 97 ----------------- 4 files changed, 130 insertions(+), 97 deletions(-) create mode 100644 src/core/integrators/langevin_inline.hpp diff --git a/src/core/forces_inline.hpp b/src/core/forces_inline.hpp index c27add0b7fe..27728f027e7 100644 --- a/src/core/forces_inline.hpp +++ b/src/core/forces_inline.hpp @@ -38,6 +38,7 @@ #include "forces.hpp" #include "immersed_boundary/ibm_tribend.hpp" #include "immersed_boundary/ibm_triel.hpp" +#include "integrators/langevin_inline.hpp" #include "metadynamics.hpp" #include "nonbonded_interactions/bmhtf-nacl.hpp" #include "nonbonded_interactions/buckingham.hpp" diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 7ea4e93a683..549d4cba6a7 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -58,6 +58,7 @@ #include "virtual_sites.hpp" #include "integrators/brownian_inline.hpp" +#include "integrators/langevin_inline.hpp" #include "integrators/steepest_descent.hpp" #include "integrators/velocity_verlet_inline.hpp" #include "integrators/velocity_verlet_npt.hpp" diff --git a/src/core/integrators/langevin_inline.hpp b/src/core/integrators/langevin_inline.hpp new file mode 100644 index 00000000000..ba1107a1f97 --- /dev/null +++ b/src/core/integrators/langevin_inline.hpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2010-2019 The ESPResSo project + * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 + * Max-Planck-Institute for Polymer Research, Theory Group + * + * This file is part of ESPResSo. + * + * ESPResSo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ESPResSo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +/** \file */ + +#ifndef LANGEVIN_INLINE_HPP +#define LANGEVIN_INLINE_HPP + +#include "random.hpp" +#include "thermostat.hpp" + +extern LangevinThermostat langevin; + +/** Langevin thermostat for particle translational velocities. + * Collects the particle velocity (different for ENGINE, PARTICLE_ANISOTROPY). + * Collects the langevin parameters kT, gamma (different for + * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. + */ +inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { + // Early exit for virtual particles without thermostat + if (p.p.is_virtual && !thermo_virtual) { + return {}; + } + + // Determine prefactors for the friction and the noise term + // first, set defaults + Thermostat::GammaType langevin_pref_friction = langevin.pref_friction; + Thermostat::GammaType langevin_pref_noise = langevin.pref_noise; + // Override defaults if per-particle values for T and gamma are given +#ifdef LANGEVIN_PER_PARTICLE + if (p.p.gamma >= Thermostat::GammaType{} or p.p.T >= 0.) { + auto const constexpr langevin_temp_coeff = 24.0; + auto const kT = p.p.T >= 0. ? p.p.T : temperature; + auto const gamma = + p.p.gamma >= Thermostat::GammaType{} ? p.p.gamma : langevin.gamma; + langevin_pref_friction = -gamma; + langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); + } +#endif /* LANGEVIN_PER_PARTICLE */ + + // Get effective velocity in the thermostatting +#ifdef ENGINE + auto const &velocity = (p.p.swim.v_swim != 0) + ? p.m.v - p.p.swim.v_swim * p.r.calc_director() + : p.m.v; +#else + auto const &velocity = p.m.v; +#endif +#ifdef PARTICLE_ANISOTROPY + // Particle frictional isotropy check + auto const aniso_flag = + (langevin_pref_friction[0] != langevin_pref_friction[1]) || + (langevin_pref_friction[1] != langevin_pref_friction[2]); + + // In case of anisotropic particle: body-fixed reference frame. Otherwise: + // lab-fixed reference frame. + auto const friction_op = + aniso_flag ? convert_body_to_space(p, diag_matrix(langevin_pref_friction)) + : diag_matrix(langevin_pref_friction); + auto const noise_op = diag_matrix(langevin_pref_noise); +#else + auto const &friction_op = langevin_pref_friction; + auto const &noise_op = langevin_pref_noise; +#endif // PARTICLE_ANISOTROPY + using Random::v_noise; + + // Do the actual (isotropic) thermostatting + return friction_op * velocity + + noise_op * v_noise(langevin.rng_counter->value(), + p.p.identity); +} + +#ifdef ROTATION +/** Langevin thermostat for particle angular velocities. + * Collects the particle velocity (different for PARTICLE_ANISOTROPY). + * Collects the langevin parameters kT, gamma_rot (different for + * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. + */ +inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { + + auto langevin_pref_friction = -langevin.gamma_rotation; + auto langevin_pref_noise = langevin.pref_noise_rotation; + + // Override defaults if per-particle values for T and gamma are given +#ifdef LANGEVIN_PER_PARTICLE + if (p.p.gamma_rot >= Thermostat::GammaType{} or p.p.T >= 0.) { + auto const constexpr langevin_temp_coeff = 24.0; + auto const kT = p.p.T >= 0. ? p.p.T : temperature; + auto const gamma = p.p.gamma_rot >= Thermostat::GammaType{} + ? p.p.gamma_rot + : langevin.gamma_rotation; + langevin_pref_friction = -gamma; + langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); + } +#endif /* LANGEVIN_PER_PARTICLE */ + + using Random::v_noise; + + // Here the thermostats happens + auto const noise = v_noise( + langevin.rng_counter->value(), p.p.identity); +#ifdef PARTICLE_ANISOTROPY + return hadamard_product(langevin_pref_friction, p.m.omega) + + hadamard_product(langevin_pref_noise, noise); +#else + return langevin_pref_friction * p.m.omega + langevin_pref_noise * noise; +#endif +} + +#endif // ROTATION +#endif diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 97a203b42be..857ea61cbbc 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -213,101 +213,4 @@ inline double friction_thermV_nptiso(double p_diff) { } #endif -/** Langevin thermostat for particle translational velocities. - * Collects the particle velocity (different for ENGINE, PARTICLE_ANISOTROPY). - * Collects the langevin parameters kT, gamma (different for - * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. - */ -inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { - // Early exit for virtual particles without thermostat - if (p.p.is_virtual && !thermo_virtual) { - return {}; - } - - // Determine prefactors for the friction and the noise term - // first, set defaults - Thermostat::GammaType langevin_pref_friction = langevin.pref_friction; - Thermostat::GammaType langevin_pref_noise = langevin.pref_noise; - // Override defaults if per-particle values for T and gamma are given -#ifdef LANGEVIN_PER_PARTICLE - if (p.p.gamma >= Thermostat::GammaType{} or p.p.T >= 0.) { - auto const constexpr langevin_temp_coeff = 24.0; - auto const kT = p.p.T >= 0. ? p.p.T : temperature; - auto const gamma = - p.p.gamma >= Thermostat::GammaType{} ? p.p.gamma : langevin.gamma; - langevin_pref_friction = -gamma; - langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); - } -#endif /* LANGEVIN_PER_PARTICLE */ - - // Get effective velocity in the thermostatting -#ifdef ENGINE - auto const &velocity = (p.p.swim.v_swim != 0) - ? p.m.v - p.p.swim.v_swim * p.r.calc_director() - : p.m.v; -#else - auto const &velocity = p.m.v; -#endif -#ifdef PARTICLE_ANISOTROPY - // Particle frictional isotropy check - auto const aniso_flag = - (langevin_pref_friction[0] != langevin_pref_friction[1]) || - (langevin_pref_friction[1] != langevin_pref_friction[2]); - - // In case of anisotropic particle: body-fixed reference frame. Otherwise: - // lab-fixed reference frame. - auto const friction_op = - aniso_flag ? convert_body_to_space(p, diag_matrix(langevin_pref_friction)) - : diag_matrix(langevin_pref_friction); - auto const noise_op = diag_matrix(langevin_pref_noise); -#else - auto const &friction_op = langevin_pref_friction; - auto const &noise_op = langevin_pref_noise; -#endif // PARTICLE_ANISOTROPY - using Random::v_noise; - - // Do the actual (isotropic) thermostatting - return friction_op * velocity + - noise_op * v_noise(langevin.rng_counter->value(), - p.p.identity); -} - -#ifdef ROTATION -/** Langevin thermostat for particle angular velocities. - * Collects the particle velocity (different for PARTICLE_ANISOTROPY). - * Collects the langevin parameters kT, gamma_rot (different for - * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. - */ -inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { - - auto langevin_pref_friction = -langevin.gamma_rotation; - auto langevin_pref_noise = langevin.pref_noise_rotation; - - // Override defaults if per-particle values for T and gamma are given -#ifdef LANGEVIN_PER_PARTICLE - if (p.p.gamma_rot >= Thermostat::GammaType{} or p.p.T >= 0.) { - auto const constexpr langevin_temp_coeff = 24.0; - auto const kT = p.p.T >= 0. ? p.p.T : temperature; - auto const gamma = p.p.gamma_rot >= Thermostat::GammaType{} - ? p.p.gamma_rot - : langevin.gamma_rotation; - langevin_pref_friction = -gamma; - langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); - } -#endif /* LANGEVIN_PER_PARTICLE */ - - using Random::v_noise; - - // Here the thermostats happens - auto const noise = v_noise( - langevin.rng_counter->value(), p.p.identity); -#ifdef PARTICLE_ANISOTROPY - return hadamard_product(langevin_pref_friction, p.m.omega) + - hadamard_product(langevin_pref_noise, noise); -#else - return langevin_pref_friction * p.m.omega + langevin_pref_noise * noise; -#endif -} - -#endif // ROTATION #endif From 3e4bb5eb8bc9bdec3a5dd2fea8a44c9c89ce4b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 22 Jan 2020 19:52:33 +0100 Subject: [PATCH 123/150] Remove redundant prefixes --- src/core/integrators/brownian_inline.hpp | 133 +++++++++++------------ src/core/integrators/langevin_inline.hpp | 41 ++++--- 2 files changed, 84 insertions(+), 90 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 35ae8a3d09c..0f5a166fd4d 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -35,23 +35,22 @@ extern BrownianThermostat brownian; */ inline void bd_drag(Particle &p, double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: - Thermostat::GammaType local_gamma; + Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{}) { - local_gamma = p.p.gamma; + gamma = p.p.gamma; } else #endif { - local_gamma = brownian.gamma; + gamma = brownian.gamma; } bool aniso_flag; // particle anisotropy flag #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = - (local_gamma[0] != local_gamma[1]) || (local_gamma[1] != local_gamma[2]); + aniso_flag = (gamma[0] != gamma[1]) || (gamma[1] != gamma[2]); #endif Utils::Vector3d force_body; @@ -68,13 +67,13 @@ inline void bd_drag(Particle &p, double dt) { // Only a conservative part of the force is used here #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { - delta_pos_body[j] = force_body[j] * dt / (local_gamma[j]); + delta_pos_body[j] = force_body[j] * dt / (gamma[j]); } else { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += p.f.f[j] * dt / (local_gamma[j]); + p.r.p[j] += p.f.f[j] * dt / (gamma[j]); } } #else @@ -82,7 +81,7 @@ inline void bd_drag(Particle &p, double dt) { if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += p.f.f[j] * dt / (local_gamma); + p.r.p[j] += p.f.f[j] * dt / (gamma); } #endif // PARTICLE_ANISOTROPY } @@ -108,23 +107,22 @@ inline void bd_drag(Particle &p, double dt) { */ inline void bd_drag_vel(Particle &p, double dt) { // The friction tensor Z from the eq. (14.31) of Schlick2010: - Thermostat::GammaType local_gamma; + Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{}) { - local_gamma = p.p.gamma; + gamma = p.p.gamma; } else #endif { - local_gamma = brownian.gamma; + gamma = brownian.gamma; } bool aniso_flag; // particle anisotropy flag #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = - (local_gamma[0] != local_gamma[1]) || (local_gamma[1] != local_gamma[2]); + aniso_flag = (gamma[0] != gamma[1]) || (gamma[1] != gamma[2]); #endif Utils::Vector3d force_body; @@ -143,13 +141,13 @@ inline void bd_drag_vel(Particle &p, double dt) { // further on top of it #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { - vel_body[j] = force_body[j] * dt / (local_gamma[j]); + vel_body[j] = force_body[j] * dt / (gamma[j]); } else { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.m.v[j] = p.f.f[j] / (local_gamma[j]); + p.m.v[j] = p.f.f[j] / (gamma[j]); } #ifdef EXTERNAL_FORCES else { @@ -162,7 +160,7 @@ inline void bd_drag_vel(Particle &p, double dt) { if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.m.v[j] = p.f.f[j] / (local_gamma); + p.m.v[j] = p.f.f[j] / (gamma); } #endif // PARTICLE_ANISOTROPY } @@ -198,41 +196,41 @@ void bd_random_walk(Particle &p, double dt) { if (p.p.is_virtual && !thermo_virtual) return; // first, set defaults - Thermostat::GammaType brown_sigma_pos_inv = brownian.sigma_pos_inv; + Thermostat::GammaType sigma_pos_inv = brownian.sigma_pos_inv; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brown_temp_coeff = 2.0; + auto const constexpr temp_coeff = 2.0; if (p.p.gamma >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_inv = sqrt(p.p.gamma / (brown_temp_coeff * p.p.T)); + sigma_pos_inv = sqrt(p.p.gamma / (temp_coeff * p.p.T)); } else { // just an indication of the infinity - brown_sigma_pos_inv = brownian.gammatype_nan; + sigma_pos_inv = brownian.gammatype_nan; } } else // default temperature but particle-specific gamma if (temperature > 0.0) { - brown_sigma_pos_inv = sqrt(p.p.gamma / (brown_temp_coeff * temperature)); + sigma_pos_inv = sqrt(p.p.gamma / (temp_coeff * temperature)); } else { - brown_sigma_pos_inv = brownian.gammatype_nan; + sigma_pos_inv = brownian.gammatype_nan; } } // particle-specific gamma else { // No particle-specific gamma, but is there particle-specific temperature if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_inv = sqrt(brownian.gamma / (brown_temp_coeff * p.p.T)); + sigma_pos_inv = sqrt(brownian.gamma / (temp_coeff * p.p.T)); } else { // just an indication of the infinity - brown_sigma_pos_inv = brownian.gammatype_nan; + sigma_pos_inv = brownian.gammatype_nan; } } else { // default values for both - brown_sigma_pos_inv = brownian.sigma_pos_inv; + sigma_pos_inv = brownian.sigma_pos_inv; } } #endif /* BROWNIAN_PER_PARTICLE */ @@ -241,8 +239,8 @@ void bd_random_walk(Particle &p, double dt) { #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (brown_sigma_pos_inv[0] != brown_sigma_pos_inv[1]) || - (brown_sigma_pos_inv[1] != brown_sigma_pos_inv[2]); + aniso_flag = (sigma_pos_inv[0] != sigma_pos_inv[1]) || + (sigma_pos_inv[1] != sigma_pos_inv[2]); #else aniso_flag = false; #endif // PARTICLE_ANISOTROPY @@ -259,15 +257,14 @@ void bd_random_walk(Particle &p, double dt) { #endif { #ifndef PARTICLE_ANISOTROPY - if (brown_sigma_pos_inv > 0.0) { - delta_pos_body[j] = (1.0 / brown_sigma_pos_inv) * sqrt(dt) * noise[j]; + if (sigma_pos_inv > 0.0) { + delta_pos_body[j] = (1.0 / sigma_pos_inv) * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } #else - if (brown_sigma_pos_inv[j] > 0.0) { - delta_pos_body[j] = - (1.0 / brown_sigma_pos_inv[j]) * sqrt(dt) * noise[j]; + if (sigma_pos_inv[j] > 0.0) { + delta_pos_body[j] = (1.0 / sigma_pos_inv[j]) * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } @@ -303,20 +300,20 @@ inline void bd_random_walk_vel(Particle &p, double dt) { return; // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs // afterwards, Pottier2010 - double brown_sigma_vel; + double sigma_vel; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brown_temp_coeff = 1.0; + auto const constexpr temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - brown_sigma_vel = sqrt(brown_temp_coeff * p.p.T); + sigma_vel = sqrt(temp_coeff * p.p.T); } else { - brown_sigma_vel = brownian.sigma_vel; + sigma_vel = brownian.sigma_vel; } #else // defaults - brown_sigma_vel = brownian.sigma_vel; + sigma_vel = brownian.sigma_vel; #endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d noise = Random::v_noise_g( @@ -334,7 +331,7 @@ inline void bd_random_walk_vel(Particle &p, double dt) { // of Schlick2010. A difference is the mass factor to the friction tensor. // The noise is Gaussian according to the convention at p. 237 (last // paragraph), Pottier2010. - p.m.v[j] += brown_sigma_vel * noise[j] / sqrt(p.p.mass); + p.m.v[j] += sigma_vel * noise[j] / sqrt(p.p.mass); } } } @@ -347,15 +344,15 @@ inline void bd_random_walk_vel(Particle &p, double dt) { * @param[in] dt Time interval */ void bd_drag_rot(Particle &p, double dt) { - Thermostat::GammaType local_gamma; + Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{}) { - local_gamma = p.p.gamma_rot; + gamma = p.p.gamma_rot; } else #endif { - local_gamma = brownian.gamma_rotation; + gamma = brownian.gamma_rotation; } Utils::Vector3d dphi = {0.0, 0.0, 0.0}; @@ -366,9 +363,9 @@ void bd_drag_rot(Particle &p, double dt) { { // only a conservative part of the torque is used here #ifndef PARTICLE_ANISOTROPY - dphi[j] = p.f.torque[j] * dt / (local_gamma); + dphi[j] = p.f.torque[j] * dt / (gamma); #else - dphi[j] = p.f.torque[j] * dt / (local_gamma[j]); + dphi[j] = p.f.torque[j] * dt / (gamma[j]); #endif // ROTATIONAL_INERTIA } } // j @@ -387,15 +384,15 @@ void bd_drag_rot(Particle &p, double dt) { * @param[in] dt Time interval */ void bd_drag_vel_rot(Particle &p, double dt) { - Thermostat::GammaType local_gamma; + Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{}) { - local_gamma = p.p.gamma_rot; + gamma = p.p.gamma_rot; } else #endif { - local_gamma = brownian.gamma_rotation; + gamma = brownian.gamma_rotation; } for (int j = 0; j < 3; j++) { @@ -409,9 +406,9 @@ void bd_drag_vel_rot(Particle &p, double dt) { // NOTE: velocity is assigned here and propagated by thermal part further // on top of it #ifndef PARTICLE_ANISOTROPY - p.m.omega[j] = p.f.torque[j] / (local_gamma); + p.m.omega[j] = p.f.torque[j] / (gamma); #else - p.m.omega[j] = p.f.torque[j] / (local_gamma[j]); + p.m.omega[j] = p.f.torque[j] / (gamma[j]); #endif // ROTATIONAL_INERTIA } } @@ -425,43 +422,41 @@ void bd_drag_vel_rot(Particle &p, double dt) { */ void bd_random_walk_rot(Particle &p, double dt) { // first, set defaults - Thermostat::GammaType brown_sigma_pos_inv = brownian.sigma_pos_rotation_inv; + Thermostat::GammaType sigma_pos_inv = brownian.sigma_pos_rotation_inv; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brown_temp_coeff = 2.0; + auto const constexpr temp_coeff = 2.0; if (p.p.gamma_rot >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_inv = sqrt(p.p.gamma_rot / (brown_temp_coeff * p.p.T)); + sigma_pos_inv = sqrt(p.p.gamma_rot / (temp_coeff * p.p.T)); } else { // just an indication of the infinity - brown_sigma_pos_inv = brownian.gammatype_nan; + sigma_pos_inv = brownian.gammatype_nan; } } else if (temperature > 0.) { // Default temperature but particle-specific gamma - brown_sigma_pos_inv = - sqrt(p.p.gamma_rot / (brown_temp_coeff * temperature)); + sigma_pos_inv = sqrt(p.p.gamma_rot / (temp_coeff * temperature)); } else { // just an indication of the infinity - brown_sigma_pos_inv = brownian.gammatype_nan; + sigma_pos_inv = brownian.gammatype_nan; } } // particle-specific gamma else { // No particle-specific gamma, but is there particle-specific temperature if (p.p.T >= 0.) { if (p.p.T > 0.0) { - brown_sigma_pos_inv = - sqrt(brownian.gamma_rotation / (brown_temp_coeff * p.p.T)); + sigma_pos_inv = sqrt(brownian.gamma_rotation / (temp_coeff * p.p.T)); } else { // just an indication of the infinity - brown_sigma_pos_inv = brownian.gammatype_nan; + sigma_pos_inv = brownian.gammatype_nan; } } else { // Defaut values for both - brown_sigma_pos_inv = brownian.sigma_pos_rotation_inv; + sigma_pos_inv = brownian.sigma_pos_rotation_inv; } } #endif /* BROWNIAN_PER_PARTICLE */ @@ -475,14 +470,14 @@ void bd_random_walk_rot(Particle &p, double dt) { #endif { #ifndef PARTICLE_ANISOTROPY - if (brown_sigma_pos_inv > 0.0) { - dphi[j] = noise[j] * (1.0 / brown_sigma_pos_inv) * sqrt(dt); + if (sigma_pos_inv > 0.0) { + dphi[j] = noise[j] * (1.0 / sigma_pos_inv) * sqrt(dt); } else { dphi[j] = 0.0; } #else - if (brown_sigma_pos_inv[j] > 0.0) { - dphi[j] = noise[j] * (1.0 / brown_sigma_pos_inv[j]) * sqrt(dt); + if (sigma_pos_inv[j] > 0.0) { + dphi[j] = noise[j] * (1.0 / sigma_pos_inv[j]) * sqrt(dt); } else { dphi[j] = 0.0; } @@ -505,20 +500,20 @@ void bd_random_walk_rot(Particle &p, double dt) { * @param[in] dt Time interval */ void bd_random_walk_vel_rot(Particle &p, double dt) { - double brown_sigma_vel; + double sigma_vel; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr brown_temp_coeff = 1.0; + auto const constexpr temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - brown_sigma_vel = sqrt(brown_temp_coeff * p.p.T); + sigma_vel = sqrt(temp_coeff * p.p.T); } else { - brown_sigma_vel = brownian.sigma_vel_rotation; + sigma_vel = brownian.sigma_vel_rotation; } #else // set defaults - brown_sigma_vel = brownian.sigma_vel_rotation; + sigma_vel = brownian.sigma_vel_rotation; #endif /* BROWNIAN_PER_PARTICLE */ Utils::Vector3d domega; @@ -531,7 +526,7 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { { // velocity is added here. It is already initialized in the terminal drag // part. - domega[j] = brown_sigma_vel * noise[j] / sqrt(p.p.rinertia[j]); + domega[j] = sigma_vel * noise[j] / sqrt(p.p.rinertia[j]); } } domega = mask(p.p.rotation, domega); diff --git a/src/core/integrators/langevin_inline.hpp b/src/core/integrators/langevin_inline.hpp index ba1107a1f97..2cae1427bbe 100644 --- a/src/core/integrators/langevin_inline.hpp +++ b/src/core/integrators/langevin_inline.hpp @@ -41,17 +41,17 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { // Determine prefactors for the friction and the noise term // first, set defaults - Thermostat::GammaType langevin_pref_friction = langevin.pref_friction; - Thermostat::GammaType langevin_pref_noise = langevin.pref_noise; + Thermostat::GammaType pref_friction = langevin.pref_friction; + Thermostat::GammaType pref_noise = langevin.pref_noise; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{} or p.p.T >= 0.) { - auto const constexpr langevin_temp_coeff = 24.0; + auto const constexpr temp_coeff = 24.0; auto const kT = p.p.T >= 0. ? p.p.T : temperature; auto const gamma = p.p.gamma >= Thermostat::GammaType{} ? p.p.gamma : langevin.gamma; - langevin_pref_friction = -gamma; - langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); + pref_friction = -gamma; + pref_noise = sqrt(temp_coeff * kT * gamma / time_step); } #endif /* LANGEVIN_PER_PARTICLE */ @@ -65,19 +65,18 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { #endif #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check - auto const aniso_flag = - (langevin_pref_friction[0] != langevin_pref_friction[1]) || - (langevin_pref_friction[1] != langevin_pref_friction[2]); + auto const aniso_flag = (pref_friction[0] != pref_friction[1]) || + (pref_friction[1] != pref_friction[2]); // In case of anisotropic particle: body-fixed reference frame. Otherwise: // lab-fixed reference frame. auto const friction_op = - aniso_flag ? convert_body_to_space(p, diag_matrix(langevin_pref_friction)) - : diag_matrix(langevin_pref_friction); - auto const noise_op = diag_matrix(langevin_pref_noise); + aniso_flag ? convert_body_to_space(p, diag_matrix(pref_friction)) + : diag_matrix(pref_friction); + auto const noise_op = diag_matrix(pref_noise); #else - auto const &friction_op = langevin_pref_friction; - auto const &noise_op = langevin_pref_noise; + auto const &friction_op = pref_friction; + auto const &noise_op = pref_noise; #endif // PARTICLE_ANISOTROPY using Random::v_noise; @@ -95,19 +94,19 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { */ inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { - auto langevin_pref_friction = -langevin.gamma_rotation; - auto langevin_pref_noise = langevin.pref_noise_rotation; + auto pref_friction = -langevin.gamma_rotation; + auto pref_noise = langevin.pref_noise_rotation; // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{} or p.p.T >= 0.) { - auto const constexpr langevin_temp_coeff = 24.0; + auto const constexpr temp_coeff = 24.0; auto const kT = p.p.T >= 0. ? p.p.T : temperature; auto const gamma = p.p.gamma_rot >= Thermostat::GammaType{} ? p.p.gamma_rot : langevin.gamma_rotation; - langevin_pref_friction = -gamma; - langevin_pref_noise = sqrt(langevin_temp_coeff * kT * gamma / time_step); + pref_friction = -gamma; + pref_noise = sqrt(temp_coeff * kT * gamma / time_step); } #endif /* LANGEVIN_PER_PARTICLE */ @@ -117,10 +116,10 @@ inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { auto const noise = v_noise( langevin.rng_counter->value(), p.p.identity); #ifdef PARTICLE_ANISOTROPY - return hadamard_product(langevin_pref_friction, p.m.omega) + - hadamard_product(langevin_pref_noise, noise); + return hadamard_product(pref_friction, p.m.omega) + + hadamard_product(pref_noise, noise); #else - return langevin_pref_friction * p.m.omega + langevin_pref_noise * noise; + return pref_friction * p.m.omega + pref_noise * noise; #endif } From c1984e2a677c80c33b00341515ab8082700746cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 22 Jan 2020 20:20:42 +0100 Subject: [PATCH 124/150] Move NPT Isotropic thermostat globals in a struct --- src/core/global.cpp | 8 +++--- src/core/global.hpp | 4 +-- src/core/thermostat.cpp | 21 ++++---------- src/core/thermostat.hpp | 43 +++++++++++++++++----------- src/python/espressomd/thermostat.pxd | 4 +++ src/python/espressomd/thermostat.pyx | 11 ++++--- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/core/global.cpp b/src/core/global.cpp index e03b929a255..33c7e68f23c 100644 --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -107,11 +107,11 @@ const std::unordered_map fields{ {node_grid.data(), Datafield::Type::INT, 3, "node_grid"}}, /* 20 from grid.cpp */ {FIELD_NPTISO_G0, - {&nptiso_gamma0, Datafield::Type::DOUBLE, 1, - "nptiso_gamma0"}}, /* 21 from thermostat.cpp */ + {&npt_iso.gamma0, Datafield::Type::DOUBLE, 1, + "npt_iso.gamma0"}}, /* 21 from thermostat.cpp */ {FIELD_NPTISO_GV, - {&nptiso_gammav, Datafield::Type::DOUBLE, 1, - "nptiso_gammav"}}, /* 22 from thermostat.cpp */ + {&npt_iso.gammav, Datafield::Type::DOUBLE, 1, + "npt_iso.gammav"}}, /* 22 from thermostat.cpp */ {FIELD_NPTISO_PEXT, {&nptiso.p_ext, Datafield::Type::DOUBLE, 1, "npt_p_ext"}}, /* 23 from pressure.cpp */ diff --git a/src/core/global.hpp b/src/core/global.hpp index 44d69bd16ed..46fb4554579 100644 --- a/src/core/global.hpp +++ b/src/core/global.hpp @@ -64,9 +64,9 @@ enum Fields { FIELD_RIGIDBONDS, /** index of \ref node_grid */ FIELD_NODEGRID, - /** index of \ref nptiso_gamma0 */ + /** index of \ref IsotropicNptThermostat::gamma0 */ FIELD_NPTISO_G0, - /** index of \ref nptiso_gammav */ + /** index of \ref IsotropicNptThermostat::gammav */ FIELD_NPTISO_GV, /** index of \ref nptiso_struct::p_ext */ FIELD_NPTISO_PEXT, diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index bf1cf025594..2968dd91e59 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -43,17 +43,7 @@ using Thermostat::GammaType; LangevinThermostat langevin = {}; BrownianThermostat brownian = {}; - -/* NPT ISOTROPIC THERMOSTAT */ -double nptiso_gamma0 = 0.0; -double nptiso_gammav = 0.0; - -#ifdef NPT -double nptiso_pref1; -double nptiso_pref2; -double nptiso_pref3; -double nptiso_pref4; -#endif +IsotropicNptThermostat npt_iso = {}; void mpi_bcast_langevin_rng_counter_slave(const uint64_t counter) { langevin.rng_counter = std::make_unique>(counter); @@ -125,11 +115,10 @@ void thermo_init_langevin() { #ifdef NPT void thermo_init_npt_isotropic() { if (nptiso.piston != 0.0) { - nptiso_pref1 = -nptiso_gamma0 * 0.5 * time_step; - - nptiso_pref2 = sqrt(12.0 * temperature * nptiso_gamma0 * time_step); - nptiso_pref3 = -nptiso_gammav * (1.0 / nptiso.piston) * 0.5 * time_step; - nptiso_pref4 = sqrt(12.0 * temperature * nptiso_gammav * time_step); + npt_iso.pref1 = -npt_iso.gamma0 * 0.5 * time_step; + npt_iso.pref2 = sqrt(12.0 * temperature * npt_iso.gamma0 * time_step); + npt_iso.pref3 = -npt_iso.gammav * (1.0 / nptiso.piston) * 0.5 * time_step; + npt_iso.pref4 = sqrt(12.0 * temperature * npt_iso.gammav * time_step); } else { thermo_switch = (thermo_switch ^ THERMO_NPT_ISO); } diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 857ea61cbbc..d5eb269ea86 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -114,15 +114,6 @@ struct LangevinThermostat { extern LangevinThermostat langevin; -/** Friction coefficient for nptiso-thermostat's function - * @ref friction_therm0_nptiso - */ -extern double nptiso_gamma0; -/** Friction coefficient for nptiso-thermostat's function - * @ref friction_thermV_nptiso - */ -extern double nptiso_gammav; - /** %Thermostat for Brownian dynamics. */ struct BrownianThermostat { private: @@ -157,6 +148,26 @@ struct BrownianThermostat { extern BrownianThermostat brownian; +/** %Thermostat for isotropic NPT dynamics. */ +struct IsotropicNptThermostat { +private: + using GammaType = Thermostat::GammaType; + +public: + /** Friction coefficient @f$ \gamma_0 @f$ */ + double gamma0; + /** Friction coefficient @f$ \gamma_V @f$ */ + double gammav; +#ifdef NPT + double pref1; + double pref2; + double pref3; + double pref4; +#endif +}; + +extern IsotropicNptThermostat npt_iso; + /************************************************ * functions ************************************************/ @@ -188,12 +199,11 @@ void thermo_init(); * dt (contained in prefactors) */ inline double friction_therm0_nptiso(double vj) { - extern double nptiso_pref1, nptiso_pref2; if (thermo_switch & THERMO_NPT_ISO) { - if (nptiso_pref2 > 0.0) { - return (nptiso_pref1 * vj + nptiso_pref2 * Thermostat::noise()); + if (npt_iso.pref2 > 0.0) { + return npt_iso.pref1 * vj + npt_iso.pref2 * Thermostat::noise(); } - return nptiso_pref1 * vj; + return npt_iso.pref1 * vj; } return 0.0; } @@ -202,12 +212,11 @@ inline double friction_therm0_nptiso(double vj) { * nptiso_struct::p_diff */ inline double friction_thermV_nptiso(double p_diff) { - extern double nptiso_pref3, nptiso_pref4; if (thermo_switch & THERMO_NPT_ISO) { - if (nptiso_pref4 > 0.0) { - return (nptiso_pref3 * p_diff + nptiso_pref4 * Thermostat::noise()); + if (npt_iso.pref4 > 0.0) { + return npt_iso.pref3 * p_diff + npt_iso.pref4 * Thermostat::noise(); } - return nptiso_pref3 * p_diff; + return npt_iso.pref3 * p_diff; } return 0.0; } diff --git a/src/python/espressomd/thermostat.pxd b/src/python/espressomd/thermostat.pxd index 0dbdb25c334..d2a225dcc7a 100644 --- a/src/python/espressomd/thermostat.pxd +++ b/src/python/espressomd/thermostat.pxd @@ -47,10 +47,14 @@ cdef extern from "thermostat.hpp": ctypedef struct brownian_thermostat_struct "BrownianThermostat": double gamma_rotation double gamma + ctypedef struct npt_iso_thermostat_struct "IsotropicNptThermostat": + double gamma0 + double gammav # links intern C-struct with python object cdef extern langevin_thermostat_struct langevin cdef extern brownian_thermostat_struct brownian + cdef extern npt_iso_thermostat_struct npt_iso void langevin_set_rng_state(stdint.uint64_t counter) void brownian_set_rng_state(stdint.uint64_t counter) diff --git a/src/python/espressomd/thermostat.pyx b/src/python/espressomd/thermostat.pyx index 0de98569447..ae1de17df7b 100644 --- a/src/python/espressomd/thermostat.pyx +++ b/src/python/espressomd/thermostat.pyx @@ -185,8 +185,8 @@ cdef class Thermostat: npt_dict = {} npt_dict["type"] = "NPT_ISO" npt_dict["kT"] = temperature - npt_dict["gamma0"] = nptiso_gamma0 - npt_dict["gammav"] = nptiso_gammav + npt_dict["gamma0"] = npt_iso.gamma0 + npt_dict["gammav"] = npt_iso.gammav npt_dict.update(nptiso) thermo_list.append(npt_dict) if thermo_switch & THERMO_DPD: @@ -624,10 +624,9 @@ cdef class Thermostat: temperature = float(kT) global thermo_switch thermo_switch = (thermo_switch | THERMO_NPT_ISO) - global nptiso_gamma0 - nptiso_gamma0 = gamma0 - global nptiso_gammav - nptiso_gammav = gammav + global npt_iso + npt_iso.gamma0 = gamma0 + npt_iso.gammav = gammav mpi_bcast_parameter(FIELD_THERMO_SWITCH) mpi_bcast_parameter(FIELD_TEMPERATURE) mpi_bcast_parameter(FIELD_NPTISO_G0) From a5624cc5774cc44ebb44d89e28af06450703f4ea Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Thu, 23 Jan 2020 13:03:36 +0100 Subject: [PATCH 125/150] Core: Brownian Dynamics Fix handling of thermo_virtual --- src/core/integrators/brownian_inline.hpp | 3 ++- testsuite/python/brownian_dynamics.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 35ae8a3d09c..47a273c83e2 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -543,7 +543,8 @@ inline void brownian_dynamics_propagator(const ParticleRange &particles) { for (auto &p : particles) { // Don't propagate translational degrees of freedom of vs #ifdef VIRTUAL_SITES - if (!(p.p.is_virtual)) + extern bool thermo_virtual; + if (!(p.p.is_virtual) or thermo_virtual) #endif { bd_drag(p, time_step); diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py index 8e5795fe55c..cde60a74dfc 100644 --- a/testsuite/python/brownian_dynamics.py +++ b/testsuite/python/brownian_dynamics.py @@ -238,12 +238,17 @@ def test_07__virtual(self): np.testing.assert_almost_equal(np.copy(virtual.v), [1, 0, 0]) np.testing.assert_almost_equal(np.copy(physical.v), [0, 0, 0]) + + system.part.clear() + virtual = system.part.add(pos=[0, 0, 0], virtual=True, v=[1, 0, 0]) + physical = system.part.add(pos=[0, 0, 0], virtual=False, v=[1, 0, 0]) + system.thermostat.set_brownian( kT=0, gamma=1, gamma_rotation=1., act_on_virtual=True, seed=41) system.integrator.run(1) - np.testing.assert_almost_equal(np.copy(virtual.f), [0, 0, 0]) - np.testing.assert_almost_equal(np.copy(physical.f), [0, 0, 0]) + np.testing.assert_almost_equal(np.copy(virtual.v), [0, 0, 0]) + np.testing.assert_almost_equal(np.copy(physical.v), [0, 0, 0]) def test_08__noise_correlation(self): """Checks that the Brownian noise is uncorrelated""" From ef28de296515f8919bed0edc1a6c0a1ee9a2f4a2 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Thu, 23 Jan 2020 14:23:20 +0100 Subject: [PATCH 126/150] Formatting --- testsuite/python/brownian_dynamics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py index cde60a74dfc..8988f9c5e36 100644 --- a/testsuite/python/brownian_dynamics.py +++ b/testsuite/python/brownian_dynamics.py @@ -238,7 +238,6 @@ def test_07__virtual(self): np.testing.assert_almost_equal(np.copy(virtual.v), [1, 0, 0]) np.testing.assert_almost_equal(np.copy(physical.v), [0, 0, 0]) - system.part.clear() virtual = system.part.add(pos=[0, 0, 0], virtual=True, v=[1, 0, 0]) physical = system.part.add(pos=[0, 0, 0], virtual=False, v=[1, 0, 0]) From 26676a21da9cca432f431fee8d1235baadba8144 Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 24 Jan 2020 21:43:22 +0100 Subject: [PATCH 127/150] Fix typo in the BD vel assignment --- src/core/integrators/brownian_inline.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 47a273c83e2..27d055bceb7 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -143,7 +143,7 @@ inline void bd_drag_vel(Particle &p, double dt) { // further on top of it #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { - vel_body[j] = force_body[j] * dt / (local_gamma[j]); + vel_body[j] = force_body[j] / (local_gamma[j]); } else { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) From 1438ecf45669849ab7abc19ae4668fe58684523a Mon Sep 17 00:00:00 2001 From: "Dr. Bogdan Tanygin" Date: Fri, 24 Jan 2020 21:46:27 +0100 Subject: [PATCH 128/150] Fix: rotational gamma assignment to the sigma_pos_rotation_inv --- src/core/thermostat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 63355bbc75b..ce1fc17833a 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -184,7 +184,7 @@ void thermo_init_brownian() { brownian.sigma_vel_rotation = sqrt(temperature); if (temperature > 0.0) { brownian.sigma_pos_rotation_inv = - sqrt(brownian.gamma / (2.0 * temperature)); + sqrt(brownian.gamma_rotation / (2.0 * temperature)); } else { brownian.sigma_pos_rotation_inv = brownian.gammatype_nan; // just an indication of the infinity From 7a42d8263ff9f8531e7ec6ef895e4a1b1058582b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 23 Jan 2020 14:55:36 +0100 Subject: [PATCH 129/150] Narrow thermostat globals Pass thermostat parameter structs as const reference instead of using globals. --- src/core/forces_inline.hpp | 9 +-- src/core/global.cpp | 3 + src/core/integrate.cpp | 3 +- src/core/integrators/brownian_inline.hpp | 72 ++++++++++++-------- src/core/integrators/langevin_inline.hpp | 10 +-- src/core/integrators/velocity_verlet_npt.cpp | 9 ++- src/core/thermostat.cpp | 20 +++--- src/core/thermostat.hpp | 17 ++--- src/python/espressomd/thermostat.pxd | 11 +-- src/script_interface/Globals.hpp | 28 ++++++++ 10 files changed, 118 insertions(+), 64 deletions(-) create mode 100644 src/script_interface/Globals.hpp diff --git a/src/core/forces_inline.hpp b/src/core/forces_inline.hpp index 27728f027e7..2d155394dae 100644 --- a/src/core/forces_inline.hpp +++ b/src/core/forces_inline.hpp @@ -102,16 +102,17 @@ inline ParticleForce external_force(Particle const &p) { } inline ParticleForce thermostat_force(Particle const &p) { + extern LangevinThermostat langevin; if (!(thermo_switch & THERMO_LANGEVIN)) { return {}; } #ifdef ROTATION - return { - friction_thermo_langevin(p), - convert_vector_body_to_space(p, friction_thermo_langevin_rotation(p))}; + return {friction_thermo_langevin(langevin, p), + convert_vector_body_to_space( + p, friction_thermo_langevin_rotation(langevin, p))}; #else - return friction_thermo_langevin(p); + return friction_thermo_langevin(langevin, p); #endif } diff --git a/src/core/global.cpp b/src/core/global.cpp index 33c7e68f23c..273f067025d 100644 --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -47,6 +47,9 @@ #include extern double force_cap; +extern LangevinThermostat langevin; +extern BrownianThermostat brownian; +extern IsotropicNptThermostat npt_iso; namespace { diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 549d4cba6a7..c2f978d00e3 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -141,6 +141,7 @@ bool integrator_step_1(ParticleRange &particles) { /** Calls the hook of the propagation kernels after force calculation */ void integrator_step_2(ParticleRange &particles) { + extern BrownianThermostat brownian; switch (integ_switch) { case INTEG_METHOD_STEEPEST_DESCENT: // Nothing @@ -155,7 +156,7 @@ void integrator_step_2(ParticleRange &particles) { #endif case INTEG_METHOD_BD: // the Ermak-McCammon's Brownian Dynamics requires a single step - brownian_dynamics_propagator(particles); + brownian_dynamics_propagator(brownian, particles); break; default: throw std::runtime_error("Unknown value for INTEG_SWITCH"); diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 46ced86ba00..1c638a9a5a5 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -26,14 +26,14 @@ #include "random.hpp" #include "thermostat.hpp" -extern BrownianThermostat brownian; - /** Propagate position: viscous drag driven by conservative forces. * From eq. (14.39) in @cite Schlick2010. - * @param[in,out] p Particle + * @param[in] brownian Parameters + * @param[in,out] p %Particle * @param[in] dt Time interval */ -inline void bd_drag(Particle &p, double dt) { +inline void bd_drag(BrownianThermostat const &brownian, Particle &p, + double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: Thermostat::GammaType gamma; @@ -102,10 +102,12 @@ inline void bd_drag(Particle &p, double dt) { /** Set the terminal velocity driven by the conservative forces drag. * From eq. (14.34) in @cite Schlick2010. - * @param[in,out] p Particle + * @param[in] brownian Parameters + * @param[in,out] p %Particle * @param[in] dt Time interval */ -inline void bd_drag_vel(Particle &p, double dt) { +inline void bd_drag_vel(BrownianThermostat const &brownian, Particle &p, + double dt) { // The friction tensor Z from the eq. (14.31) of Schlick2010: Thermostat::GammaType gamma; @@ -187,10 +189,12 @@ inline void bd_drag_vel(Particle &p, double dt) { /** Propagate the positions: random walk part. * From eq. (14.37) in @cite Schlick2010. - * @param[in,out] p Particle - * @param[in] dt Time interval + * @param[in] brownian Parameters + * @param[in,out] p %Particle + * @param[in] dt Time interval */ -void bd_random_walk(Particle &p, double dt) { +void bd_random_walk(BrownianThermostat const &brownian, Particle &p, + double dt) { // skip the translation thermalizing for virtual sites unless enabled extern bool thermo_virtual; if (p.p.is_virtual && !thermo_virtual) @@ -290,10 +294,12 @@ void bd_random_walk(Particle &p, double dt) { /** Determine the velocities: random walk part. * From eq. (10.2.16) in @cite Pottier2010. - * @param[in, out] p Particle - * @param[in] dt Time interval + * @param[in] brownian Parameters + * @param[in,out] p %Particle + * @param[in] dt Time interval */ -inline void bd_random_walk_vel(Particle &p, double dt) { +inline void bd_random_walk_vel(BrownianThermostat const &brownian, Particle &p, + double dt) { // skip the translation thermalizing for virtual sites unless enabled extern bool thermo_virtual; if (p.p.is_virtual && !thermo_virtual) @@ -340,10 +346,11 @@ inline void bd_random_walk_vel(Particle &p, double dt) { /** Propagate quaternions: viscous drag driven by conservative torques. * An analogy of eq. (14.39) in @cite Schlick2010. - * @param[in,out] p Particle + * @param[in] brownian Parameters + * @param[in,out] p %Particle * @param[in] dt Time interval */ -void bd_drag_rot(Particle &p, double dt) { +void bd_drag_rot(BrownianThermostat const &brownian, Particle &p, double dt) { Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE @@ -380,10 +387,12 @@ void bd_drag_rot(Particle &p, double dt) { /** Set the terminal angular velocity driven by the conservative torques drag. * An analogy of the 1st term of eq. (14.34) in @cite Schlick2010. - * @param[in,out] p Particle + * @param[in] brownian Parameters + * @param[in,out] p %Particle * @param[in] dt Time interval */ -void bd_drag_vel_rot(Particle &p, double dt) { +void bd_drag_vel_rot(BrownianThermostat const &brownian, Particle &p, + double dt) { Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE @@ -417,10 +426,12 @@ void bd_drag_vel_rot(Particle &p, double dt) { /** Propagate the quaternions: random walk part. * An analogy of eq. (14.37) in @cite Schlick2010. - * @param[in,out] p Particle + * @param[in] brownian Parameters + * @param[in,out] p %Particle * @param[in] dt Time interval */ -void bd_random_walk_rot(Particle &p, double dt) { +void bd_random_walk_rot(BrownianThermostat const &brownian, Particle &p, + double dt) { // first, set defaults Thermostat::GammaType sigma_pos_inv = brownian.sigma_pos_rotation_inv; @@ -496,10 +507,12 @@ void bd_random_walk_rot(Particle &p, double dt) { /** Determine the angular velocities: random walk part. * An analogy of eq. (10.2.16) in @cite Pottier2010. - * @param[in,out] p Particle + * @param[in] brownian Parameters + * @param[in,out] p %Particle * @param[in] dt Time interval */ -void bd_random_walk_vel_rot(Particle &p, double dt) { +void bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle &p, + double dt) { double sigma_vel; // Override defaults if per-particle values for T and gamma are given @@ -534,7 +547,8 @@ void bd_random_walk_vel_rot(Particle &p, double dt) { } #endif // ROTATION -inline void brownian_dynamics_propagator(const ParticleRange &particles) { +inline void brownian_dynamics_propagator(BrownianThermostat const &brownian, + const ParticleRange &particles) { for (auto &p : particles) { // Don't propagate translational degrees of freedom of vs #ifdef VIRTUAL_SITES @@ -542,10 +556,10 @@ inline void brownian_dynamics_propagator(const ParticleRange &particles) { if (!(p.p.is_virtual) or thermo_virtual) #endif { - bd_drag(p, time_step); - bd_drag_vel(p, time_step); - bd_random_walk(p, time_step); - bd_random_walk_vel(p, time_step); + bd_drag(brownian, p, time_step); + bd_drag_vel(brownian, p, time_step); + bd_random_walk(brownian, p, time_step); + bd_random_walk_vel(brownian, p, time_step); /* Verlet criterion check */ if ((p.r.p - p.l.p_old).norm2() > Utils::sqr(0.5 * skin)) set_resort_particles(Cells::RESORT_LOCAL); @@ -554,10 +568,10 @@ inline void brownian_dynamics_propagator(const ParticleRange &particles) { if (!p.p.rotation) continue; convert_torque_to_body_frame_apply_fix(p); - bd_drag_rot(p, time_step); - bd_drag_vel_rot(p, time_step); - bd_random_walk_rot(p, time_step); - bd_random_walk_vel_rot(p, time_step); + bd_drag_rot(brownian, p, time_step); + bd_drag_vel_rot(brownian, p, time_step); + bd_random_walk_rot(brownian, p, time_step); + bd_random_walk_vel_rot(brownian, p, time_step); #endif // ROTATION } sim_time += time_step; diff --git a/src/core/integrators/langevin_inline.hpp b/src/core/integrators/langevin_inline.hpp index 2cae1427bbe..f746304495e 100644 --- a/src/core/integrators/langevin_inline.hpp +++ b/src/core/integrators/langevin_inline.hpp @@ -26,14 +26,14 @@ #include "random.hpp" #include "thermostat.hpp" -extern LangevinThermostat langevin; - /** Langevin thermostat for particle translational velocities. * Collects the particle velocity (different for ENGINE, PARTICLE_ANISOTROPY). * Collects the langevin parameters kT, gamma (different for * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. */ -inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { +inline Utils::Vector3d +friction_thermo_langevin(LangevinThermostat const &langevin, + Particle const &p) { // Early exit for virtual particles without thermostat if (p.p.is_virtual && !thermo_virtual) { return {}; @@ -92,7 +92,9 @@ inline Utils::Vector3d friction_thermo_langevin(Particle const &p) { * Collects the langevin parameters kT, gamma_rot (different for * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. */ -inline Utils::Vector3d friction_thermo_langevin_rotation(const Particle &p) { +inline Utils::Vector3d +friction_thermo_langevin_rotation(LangevinThermostat const &langevin, + const Particle &p) { auto pref_friction = -langevin.gamma_rotation; auto pref_noise = langevin.pref_noise_rotation; diff --git a/src/core/integrators/velocity_verlet_npt.cpp b/src/core/integrators/velocity_verlet_npt.cpp index f5ad2cc1d5f..350a9e3634e 100644 --- a/src/core/integrators/velocity_verlet_npt.cpp +++ b/src/core/integrators/velocity_verlet_npt.cpp @@ -33,6 +33,7 @@ #include void velocity_verlet_npt_propagate_vel_final(const ParticleRange &particles) { + extern IsotropicNptThermostat npt_iso; nptiso.p_vel[0] = nptiso.p_vel[1] = nptiso.p_vel[2] = 0.0; for (auto &p : particles) { @@ -44,7 +45,7 @@ void velocity_verlet_npt_propagate_vel_final(const ParticleRange &particles) { if (nptiso.geometry & nptiso.nptgeom_dir[j]) { nptiso.p_vel[j] += Utils::sqr(p.m.v[j] * time_step) * p.p.mass; p.m.v[j] += 0.5 * time_step / p.p.mass * p.f.f[j] + - friction_therm0_nptiso(p.m.v[j]) / p.p.mass; + friction_therm0_nptiso(npt_iso, p.m.v[j]) / p.p.mass; } else // Propagate velocity: v(t+dt) = v(t+0.5*dt) + 0.5*dt * a(t+dt) p.m.v[j] += 0.5 * time_step * p.f.f[j] / p.p.mass; @@ -57,6 +58,7 @@ void velocity_verlet_npt_propagate_vel_final(const ParticleRange &particles) { /** Scale and communicate instantaneous NpT pressure */ void velocity_verlet_npt_finalize_p_inst() { + extern IsotropicNptThermostat npt_iso; double p_tmp = 0.0; int i; /* finalize derivation of p_inst */ @@ -73,7 +75,7 @@ void velocity_verlet_npt_finalize_p_inst() { nptiso.p_inst = p_tmp / (nptiso.dimension * nptiso.volume); nptiso.p_diff = nptiso.p_diff + (nptiso.p_inst - nptiso.p_ext) * 0.5 * time_step + - friction_thermV_nptiso(nptiso.p_diff); + friction_thermV_nptiso(npt_iso, nptiso.p_diff); } } @@ -154,6 +156,7 @@ void velocity_verlet_npt_propagate_pos(const ParticleRange &particles) { } void velocity_verlet_npt_propagate_vel(const ParticleRange &particles) { + extern IsotropicNptThermostat npt_iso; #ifdef NPT nptiso.p_vel[0] = nptiso.p_vel[1] = nptiso.p_vel[2] = 0.0; #endif @@ -172,7 +175,7 @@ void velocity_verlet_npt_propagate_vel(const ParticleRange &particles) { if (integ_switch == INTEG_METHOD_NPT_ISO && (nptiso.geometry & nptiso.nptgeom_dir[j])) { p.m.v[j] += p.f.f[j] * 0.5 * time_step / p.p.mass + - friction_therm0_nptiso(p.m.v[j]) / p.p.mass; + friction_therm0_nptiso(npt_iso, p.m.v[j]) / p.p.mass; nptiso.p_vel[j] += Utils::sqr(p.m.v[j] * time_step) * p.p.mass; } else #endif diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 34ff85823c4..e8b81d6e2fa 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -99,7 +99,7 @@ uint64_t langevin_get_rng_state() { return langevin.rng_counter->value(); } uint64_t brownian_get_rng_state() { return brownian.rng_counter->value(); } -void thermo_init_langevin() { +void thermo_init_langevin(LangevinThermostat &langevin) { langevin.pref_friction = -langevin.gamma; langevin.pref_noise = sqrt(24.0 * temperature / time_step * langevin.gamma); @@ -113,7 +113,7 @@ void thermo_init_langevin() { } #ifdef NPT -void thermo_init_npt_isotropic() { +void thermo_init_npt_isotropic(IsotropicNptThermostat &npt_iso) { if (nptiso.piston != 0.0) { npt_iso.pref1 = -npt_iso.gamma0 * 0.5 * time_step; npt_iso.pref2 = sqrt(12.0 * temperature * npt_iso.gamma0 * time_step); @@ -129,7 +129,7 @@ void thermo_init_npt_isotropic() { * * Default particle mass is assumed to be unitary in these global parameters. */ -void thermo_init_brownian() { +void thermo_init_brownian(BrownianThermostat &brownian) { /** The heat velocity dispersion corresponds to the Gaussian noise only, * which is only valid for the BD. Just a square root of kT, see (10.2.17) * and comments in 2 paragraphs afterwards, @cite Pottier2010. @@ -142,8 +142,8 @@ void thermo_init_brownian() { if (temperature > 0.0) { brownian.sigma_pos_inv = sqrt(brownian.gamma / (2.0 * temperature)); } else { - brownian.sigma_pos_inv = - brownian.gammatype_nan; // just an indication of the infinity + // just an indication of the infinity + brownian.sigma_pos_inv = brownian.gammatype_nan; } #ifdef ROTATION /** Note: the BD thermostat assigns the brownian viscous parameters as well. @@ -160,8 +160,8 @@ void thermo_init_brownian() { brownian.sigma_pos_rotation_inv = sqrt(brownian.gamma_rotation / (2.0 * temperature)); } else { - brownian.sigma_pos_rotation_inv = - brownian.gammatype_nan; // just an indication of the infinity + // just an indication of the infinity + brownian.sigma_pos_rotation_inv = brownian.gammatype_nan; } #endif // ROTATION } @@ -175,15 +175,15 @@ void thermo_init() { return; } if (thermo_switch & THERMO_LANGEVIN) - thermo_init_langevin(); + thermo_init_langevin(langevin); #ifdef DPD if (thermo_switch & THERMO_DPD) dpd_init(); #endif #ifdef NPT if (thermo_switch & THERMO_NPT_ISO) - thermo_init_npt_isotropic(); + thermo_init_npt_isotropic(npt_iso); #endif if (thermo_switch & THERMO_BROWNIAN) - thermo_init_brownian(); + thermo_init_brownian(brownian); } diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index d5eb269ea86..64ebe79259b 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -92,6 +92,10 @@ extern double temperature; /** True if the thermostat should act on virtual particles. */ extern bool thermo_virtual; +/************************************************ + * parameter structs + ************************************************/ + /** %Thermostat for Langevin dynamics. */ struct LangevinThermostat { private: @@ -112,8 +116,6 @@ struct LangevinThermostat { std::unique_ptr> rng_counter; }; -extern LangevinThermostat langevin; - /** %Thermostat for Brownian dynamics. */ struct BrownianThermostat { private: @@ -146,8 +148,6 @@ struct BrownianThermostat { std::unique_ptr> rng_counter; }; -extern BrownianThermostat brownian; - /** %Thermostat for isotropic NPT dynamics. */ struct IsotropicNptThermostat { private: @@ -166,8 +166,6 @@ struct IsotropicNptThermostat { #endif }; -extern IsotropicNptThermostat npt_iso; - /************************************************ * functions ************************************************/ @@ -194,11 +192,13 @@ void thermo_init(); #ifdef NPT /** Add velocity-dependent noise and friction for NpT-sims to the particle's * velocity + * @param npt_iso Parameters * @param vj j-component of the velocity * @return j-component of the noise added to the velocity, also scaled by * dt (contained in prefactors) */ -inline double friction_therm0_nptiso(double vj) { +inline double friction_therm0_nptiso(IsotropicNptThermostat const &npt_iso, + double vj) { if (thermo_switch & THERMO_NPT_ISO) { if (npt_iso.pref2 > 0.0) { return npt_iso.pref1 * vj + npt_iso.pref2 * Thermostat::noise(); @@ -211,7 +211,8 @@ inline double friction_therm0_nptiso(double vj) { /** Add p_diff-dependent noise and friction for NpT-sims to \ref * nptiso_struct::p_diff */ -inline double friction_thermV_nptiso(double p_diff) { +inline double friction_thermV_nptiso(IsotropicNptThermostat const &npt_iso, + double p_diff) { if (thermo_switch & THERMO_NPT_ISO) { if (npt_iso.pref4 > 0.0) { return npt_iso.pref3 * p_diff + npt_iso.pref4 * Thermostat::noise(); diff --git a/src/python/espressomd/thermostat.pxd b/src/python/espressomd/thermostat.pxd index d2a225dcc7a..cf9ef7068eb 100644 --- a/src/python/espressomd/thermostat.pxd +++ b/src/python/espressomd/thermostat.pxd @@ -51,11 +51,6 @@ cdef extern from "thermostat.hpp": double gamma0 double gammav - # links intern C-struct with python object - cdef extern langevin_thermostat_struct langevin - cdef extern brownian_thermostat_struct brownian - cdef extern npt_iso_thermostat_struct npt_iso - void langevin_set_rng_state(stdint.uint64_t counter) void brownian_set_rng_state(stdint.uint64_t counter) cbool langevin_is_seed_required() @@ -64,6 +59,12 @@ cdef extern from "thermostat.hpp": stdint.uint64_t langevin_get_rng_state() stdint.uint64_t brownian_get_rng_state() +cdef extern from "Globals.hpp": + # links intern C-struct with python object + cdef extern langevin_thermostat_struct langevin + cdef extern brownian_thermostat_struct brownian + cdef extern npt_iso_thermostat_struct npt_iso + cdef extern from "dpd.hpp": IF DPD: void dpd_set_rng_state(stdint.uint64_t counter) diff --git a/src/script_interface/Globals.hpp b/src/script_interface/Globals.hpp new file mode 100644 index 00000000000..0d9f3e8f7d1 --- /dev/null +++ b/src/script_interface/Globals.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2019 The ESPResSo project + * + * This file is part of ESPResSo. + * + * ESPResSo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ESPResSo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SCRIPT_INTERFACE_GLOBALS_HPP +#define SCRIPT_INTERFACE_GLOBALS_HPP + +#include "thermostat.hpp" + +extern LangevinThermostat langevin; +extern BrownianThermostat brownian; +extern IsotropicNptThermostat npt_iso; + +#endif From b1dd0e5839a71ce60472440f0508940919ebb7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 23 Jan 2020 16:53:22 +0100 Subject: [PATCH 130/150] Move prefactor logic to the structs --- src/core/thermostat.cpp | 80 +++++-------------------------------- src/core/thermostat.hpp | 87 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 74 deletions(-) diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index e8b81d6e2fa..6efcdbfe421 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -99,73 +99,6 @@ uint64_t langevin_get_rng_state() { return langevin.rng_counter->value(); } uint64_t brownian_get_rng_state() { return brownian.rng_counter->value(); } -void thermo_init_langevin(LangevinThermostat &langevin) { - langevin.pref_friction = -langevin.gamma; - langevin.pref_noise = sqrt(24.0 * temperature / time_step * langevin.gamma); - - /* If gamma_rotation is not set explicitly, use the linear one. */ - if (langevin.gamma_rotation < GammaType{}) { - langevin.gamma_rotation = langevin.gamma; - } - - langevin.pref_noise_rotation = - sqrt(24.0 * temperature * langevin.gamma_rotation / time_step); -} - -#ifdef NPT -void thermo_init_npt_isotropic(IsotropicNptThermostat &npt_iso) { - if (nptiso.piston != 0.0) { - npt_iso.pref1 = -npt_iso.gamma0 * 0.5 * time_step; - npt_iso.pref2 = sqrt(12.0 * temperature * npt_iso.gamma0 * time_step); - npt_iso.pref3 = -npt_iso.gammav * (1.0 / nptiso.piston) * 0.5 * time_step; - npt_iso.pref4 = sqrt(12.0 * temperature * npt_iso.gammav * time_step); - } else { - thermo_switch = (thermo_switch ^ THERMO_NPT_ISO); - } -} -#endif - -/** Brownian thermostat initializer. - * - * Default particle mass is assumed to be unitary in these global parameters. - */ -void thermo_init_brownian(BrownianThermostat &brownian) { - /** The heat velocity dispersion corresponds to the Gaussian noise only, - * which is only valid for the BD. Just a square root of kT, see (10.2.17) - * and comments in 2 paragraphs afterwards, @cite Pottier2010. - */ - brownian.sigma_vel = sqrt(temperature); - /** The random walk position dispersion is defined by the second eq. (14.38) - * of @cite Schlick2010. Its time interval factor will be added in the - * Brownian Dynamics functions. Its square root is the standard deviation. - */ - if (temperature > 0.0) { - brownian.sigma_pos_inv = sqrt(brownian.gamma / (2.0 * temperature)); - } else { - // just an indication of the infinity - brownian.sigma_pos_inv = brownian.gammatype_nan; - } -#ifdef ROTATION - /** Note: the BD thermostat assigns the brownian viscous parameters as well. - * They correspond to the friction tensor Z from the eq. (14.31) of - * @cite Schlick2010. - */ - /* If gamma_rotation is not set explicitly, - we use the translational one. */ - if (brownian.gamma_rotation < GammaType{}) { - brownian.gamma_rotation = brownian.gamma; - } - brownian.sigma_vel_rotation = sqrt(temperature); - if (temperature > 0.0) { - brownian.sigma_pos_rotation_inv = - sqrt(brownian.gamma_rotation / (2.0 * temperature)); - } else { - // just an indication of the infinity - brownian.sigma_pos_rotation_inv = brownian.gammatype_nan; - } -#endif // ROTATION -} - void thermo_init() { // Init thermalized bond despite of thermostat if (n_thermalized_bonds) { @@ -175,15 +108,20 @@ void thermo_init() { return; } if (thermo_switch & THERMO_LANGEVIN) - thermo_init_langevin(langevin); + langevin.recalc_prefactors(); #ifdef DPD if (thermo_switch & THERMO_DPD) dpd_init(); #endif #ifdef NPT - if (thermo_switch & THERMO_NPT_ISO) - thermo_init_npt_isotropic(npt_iso); + if (thermo_switch & THERMO_NPT_ISO) { + if (nptiso.piston == 0.0) { + thermo_switch = (thermo_switch ^ THERMO_NPT_ISO); + } else { + npt_iso.recalc_prefactors(nptiso.piston); + } + } #endif if (thermo_switch & THERMO_BROWNIAN) - thermo_init_brownian(brownian); + brownian.recalc_prefactors(); } diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 64ebe79259b..6e571e2b665 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -102,30 +102,94 @@ struct LangevinThermostat { using GammaType = Thermostat::GammaType; public: + /** Recalculate prefactors. + * Needs to be called every time the parameters are changed. + */ + void recalc_prefactors() { + pref_friction = -gamma; + pref_noise = sqrt(24.0 * temperature / time_step * gamma); + // If gamma_rotation is not set explicitly, use the translational one. + if (gamma_rotation < GammaType{}) { + gamma_rotation = gamma; + } + pref_noise_rotation = sqrt(24.0 * temperature * gamma_rotation / time_step); + } + /** @name Parameters */ + /*@{*/ /** Translational friction coefficient @f$ \gamma_{\text{trans}} @f$. */ GammaType gamma = sentinel(GammaType{}); /** Rotational friction coefficient @f$ \gamma_{\text{rot}} @f$. */ GammaType gamma_rotation = sentinel(GammaType{}); + /*@}*/ + /** @name Prefactors */ + /*@{*/ /** Prefactor for the friction. */ GammaType pref_friction; /** Prefactor for the translational velocity noise. */ GammaType pref_noise; /** Prefactor for the angular velocity noise. */ GammaType pref_noise_rotation; + /*@}*/ /** RNG counter, used for both translation and rotation. */ std::unique_ptr> rng_counter; }; -/** %Thermostat for Brownian dynamics. */ +/** %Thermostat for Brownian dynamics. + * Default particle mass is assumed to be unitary in these global parameters. + */ struct BrownianThermostat { private: using GammaType = Thermostat::GammaType; public: + /** Recalculate prefactors. + * Needs to be called every time the parameters are changed. + */ + void recalc_prefactors() { + /** The heat velocity dispersion corresponds to the Gaussian noise only, + * which is only valid for the BD. Just a square root of kT, see (10.2.17) + * and comments in 2 paragraphs afterwards, @cite Pottier2010. + */ + sigma_vel = sqrt(temperature); + /** The random walk position dispersion is defined by the second eq. (14.38) + * of @cite Schlick2010. Its time interval factor will be added in the + * Brownian Dynamics functions. Its square root is the standard deviation. + */ + if (temperature > 0.0) { + sigma_pos_inv = sqrt(gamma / (2.0 * temperature)); + } else { + // just an indication of the infinity + sigma_pos_inv = gammatype_nan; + } +#ifdef ROTATION + /** Note: the BD thermostat assigns the brownian viscous parameters as well. + * They correspond to the friction tensor Z from the eq. (14.31) of + * @cite Schlick2010. + */ + // If gamma_rotation is not set explicitly, use the translational one. + if (gamma_rotation < GammaType{}) { + gamma_rotation = gamma; + } + sigma_vel_rotation = sqrt(temperature); + if (temperature > 0.0) { + sigma_pos_rotation_inv = sqrt(gamma_rotation / (2.0 * temperature)); + } else { + // just an indication of the infinity + sigma_pos_rotation_inv = gammatype_nan; + } +#endif // ROTATION + } + /** @name Parameters */ + /*@{*/ /** Translational friction coefficient @f$ \gamma_{\text{trans}} @f$. */ GammaType gamma = sentinel(GammaType{}); /** Rotational friction coefficient @f$ \gamma_{\text{rot}} @f$. */ GammaType gamma_rotation = sentinel(GammaType{}); + /*@}*/ + /** Sentinel value for divisions by zero. */ + GammaType const gammatype_nan = set_nan(GammaType{}); + /** @name Prefactors */ + /*@{*/ /** Inverse of the translational noise standard deviation. * Stores @f$ \left(\sqrt{2D_{\text{trans}}}\right)^{-1} @f$ with * @f$ D_{\text{trans}} = k_B T/\gamma_{\text{trans}} @f$ @@ -138,12 +202,11 @@ struct BrownianThermostat { * the rotational diffusion coefficient */ GammaType sigma_pos_rotation_inv = sentinel(GammaType{}); - /** Sentinel value for divisions by zero. */ - GammaType const gammatype_nan = set_nan(GammaType{}); /** Translational velocity noise standard deviation. */ double sigma_vel = 0; /** Angular velocity noise standard deviation. */ double sigma_vel_rotation = 0; + /*@}*/ /** RNG counter, used for both translation and rotation. */ std::unique_ptr> rng_counter; }; @@ -154,15 +217,33 @@ struct IsotropicNptThermostat { using GammaType = Thermostat::GammaType; public: +#ifdef NPT + /** Recalculate prefactors. + * Needs to be called every time the parameters are changed. + */ + void recalc_prefactors(double piston) { + assert(piston > 0.0); + pref1 = -gamma0 * 0.5 * time_step; + pref2 = sqrt(12.0 * temperature * gamma0 * time_step); + pref3 = -gammav * (1.0 / piston) * 0.5 * time_step; + pref4 = sqrt(12.0 * temperature * gammav * time_step); + } +#endif + /** @name Parameters */ + /*@{*/ /** Friction coefficient @f$ \gamma_0 @f$ */ double gamma0; /** Friction coefficient @f$ \gamma_V @f$ */ double gammav; + /*@}*/ #ifdef NPT + /** @name Prefactors */ + /*@{*/ double pref1; double pref2; double pref3; double pref4; + /*@}*/ #endif }; From e74518e8f30f31c9a858775a9a04139dba34d7e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 23 Jan 2020 20:58:23 +0100 Subject: [PATCH 131/150] Hadamard specializations --- src/utils/include/utils/Vector.hpp | 63 ++++++++++++++++++++++++++++++ src/utils/tests/Vector_test.cpp | 39 ++++++++++++++++-- 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/src/utils/include/utils/Vector.hpp b/src/utils/include/utils/Vector.hpp index 9744ea8022a..8e0467b09a9 100644 --- a/src/utils/include/utils/Vector.hpp +++ b/src/utils/include/utils/Vector.hpp @@ -417,6 +417,37 @@ auto hadamard_product(Vector const &a, Vector const &b) { return ret; } +// specializations for when one or both operands is a scalar depending on +// compile time features (e.g. when PARTICLE_ANISOTROPY is not enabled) +template ::value)>> +auto hadamard_product(T const &a, Vector const &b) { + using std::declval; + using R = decltype(declval() * declval()); + + Vector ret = a * b; + + return ret; +} + +template ::value)>> +auto hadamard_product(Vector const &a, U const &b) { + using std::declval; + using R = decltype(declval() * declval()); + + Vector ret = a * b; + + return ret; +} + +template ::value or + detail::is_vector::value)>> +auto hadamard_product(T const &a, U const &b) { + return a * b; +} + template auto hadamard_division(Vector const &a, Vector const &b) { using std::declval; @@ -429,6 +460,38 @@ auto hadamard_division(Vector const &a, Vector const &b) { return ret; } +// specializations for when one or both operands is a scalar depending on +// compile time features (e.g. when PARTICLE_ANISOTROPY is not enabled) +template ::value)>> +auto hadamard_division(Vector const &a, U const &b) { + using std::declval; + using R = decltype(declval() * declval()); + + Vector ret = a / b; + + return ret; +} + +template ::value)>> +auto hadamard_division(T const &a, Vector const &b) { + using std::declval; + using R = decltype(declval() * declval()); + + Vector ret; + std::transform(std::begin(b), std::end(b), ret.begin(), + [a](T const &bi) { return a / bi; }); + return ret; +} + +template ::value or + detail::is_vector::value)>> +auto hadamard_division(T const &a, U const &b) { + return a / b; +} + /** * @brief Meta function to turns a Vector<1, T> into T. */ diff --git a/src/utils/tests/Vector_test.cpp b/src/utils/tests/Vector_test.cpp index afb47eb4eef..421bad9f825 100644 --- a/src/utils/tests/Vector_test.cpp +++ b/src/utils/tests/Vector_test.cpp @@ -334,10 +334,43 @@ BOOST_AUTO_TEST_CASE(vector_product_test) { BOOST_AUTO_TEST_CASE(hadamard_product_test) { auto const v1 = Utils::Vector{8, 9}; auto const v2 = Utils::Vector{5, 6}; + auto const a = 6; - auto res = Utils::hadamard_product(v1, v2); - BOOST_CHECK_EQUAL(res[0], v1[0] * v2[0]); - BOOST_CHECK_EQUAL(res[1], v1[1] * v2[1]); + auto res1 = Utils::hadamard_product(v1, v2); + BOOST_CHECK_EQUAL(res1[0], v1[0] * v2[0]); + BOOST_CHECK_EQUAL(res1[1], v1[1] * v2[1]); + + auto res2 = Utils::hadamard_product(a, v1); + BOOST_CHECK_EQUAL(res2[0], a * v1[0]); + BOOST_CHECK_EQUAL(res2[1], a * v1[1]); + + auto res3 = Utils::hadamard_product(v1, a); + BOOST_CHECK_EQUAL(res3[0], a * v1[0]); + BOOST_CHECK_EQUAL(res3[1], a * v1[1]); + + auto res4 = Utils::hadamard_product(a, a); + BOOST_CHECK_EQUAL(res4, a * a); +} + +BOOST_AUTO_TEST_CASE(hadamard_division_test) { + auto const v1 = Utils::Vector{16, 32}; + auto const v2 = Utils::Vector{8, 4}; + auto const a = 2; + + auto res1 = Utils::hadamard_division(v1, v2); + BOOST_CHECK_EQUAL(res1[0], v1[0] / v2[0]); + BOOST_CHECK_EQUAL(res1[1], v1[1] / v2[1]); + + auto res2 = Utils::hadamard_division(a, v1); + BOOST_CHECK_EQUAL(res2[0], a / v1[0]); + BOOST_CHECK_EQUAL(res2[1], a / v1[1]); + + auto res3 = Utils::hadamard_division(v1, a); + BOOST_CHECK_EQUAL(res3[0], v1[0] / a); + BOOST_CHECK_EQUAL(res3[1], v1[1] / a); + + auto res4 = Utils::hadamard_division(a, a); + BOOST_CHECK_EQUAL(res4, 1); } BOOST_AUTO_TEST_CASE(diag_matrix) { From 39ff4e7b91bb5da4926b273a19ba297c6892a01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 23 Jan 2020 21:00:30 +0100 Subject: [PATCH 132/150] Add unit tests for thermostats --- src/core/unit_tests/CMakeLists.txt | 1 + src/core/unit_tests/thermostats_test.cpp | 213 +++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 src/core/unit_tests/thermostats_test.cpp diff --git a/src/core/unit_tests/CMakeLists.txt b/src/core/unit_tests/CMakeLists.txt index ef897bb3c92..6b4391b166b 100644 --- a/src/core/unit_tests/CMakeLists.txt +++ b/src/core/unit_tests/CMakeLists.txt @@ -46,4 +46,5 @@ unit_test(NAME None_test SRC None_test.cpp DEPENDS EspressoScriptInterface) unit_test(NAME grid_test SRC grid_test.cpp DEPENDS EspressoCore) unit_test(NAME BoxGeometry_test SRC BoxGeometry_test.cpp DEPENDS EspressoCore) unit_test(NAME LocalBox_test SRC LocalBox_test.cpp DEPENDS EspressoCore) +unit_test(NAME thermostats_test SRC thermostats_test.cpp DEPENDS EspressoCore) diff --git a/src/core/unit_tests/thermostats_test.cpp b/src/core/unit_tests/thermostats_test.cpp new file mode 100644 index 00000000000..8aa20496f52 --- /dev/null +++ b/src/core/unit_tests/thermostats_test.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2019 The ESPResSo project + * + * This file is part of ESPResSo. + * + * ESPResSo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ESPResSo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Unit tests for thermostats. */ + +#define BOOST_TEST_MODULE Particle test +#define BOOST_TEST_DYN_LINK +#include +#include +#include + +#include +#include +#include + +#include "Particle.hpp" +#include "particle_data.hpp" +#include "cells.hpp" +#include "thermostat.hpp" +#include "integrators/brownian_inline.hpp" +#include "integrators/langevin_inline.hpp" + +extern double time_step; +extern double temperature; + +// multiply by 100 because BOOST_CHECK_CLOSE takes a percentage tolerance, +// and by 6 to account for error accumulation in thermostat functions +auto const tol = 6 * 100 * std::numeric_limits::epsilon(); + +Particle particle_factory() { + Particle p{}; + p.p.identity = 0; + p.f.f = {1.0, 2.0, 3.0}; +#ifdef ROTATION + p.f.torque = 4.0 * p.f.f; + constexpr Utils::Vector4d identity_quat{{1, 0, 0, 0}}; + p.r.quat = identity_quat; // the particle force won't be rotated +#endif + return p; +} + +template T thermostat_factory() { + T thermostat = T{}; +#ifdef PARTICLE_ANISOTROPY + thermostat.gamma = {3.0, 5.0, 7.0}; +#else + thermostat.gamma = 2.0; +#endif + thermostat.gamma_rotation = 3.0 * thermostat.gamma; + thermostat.recalc_prefactors(); + thermostat.rng_counter = std::make_unique>(0); + return thermostat; +} + +BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { + time_step = 0.1; + temperature = 3.0; + auto const brownian = thermostat_factory(); + auto const dispersion = + hadamard_division(particle_factory().f.f, brownian.gamma); + + /* check translation */ + { + auto p = particle_factory(); + auto const ref = time_step * dispersion; + bd_drag(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.r.p[0], ref[0], tol); + BOOST_CHECK_CLOSE(p.r.p[1], ref[1], tol); + BOOST_CHECK_CLOSE(p.r.p[2], ref[2], tol); + } + + /* check translational velocity */ + { + auto p = particle_factory(); + auto const ref = dispersion; + bd_drag_vel(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.m.v[0], ref[0], tol); + BOOST_CHECK_CLOSE(p.m.v[1], ref[1], tol); + BOOST_CHECK_CLOSE(p.m.v[2], ref[2], tol); + } + + /* check walk translation */ + { + auto p = particle_factory(); + auto const sigma = sqrt(brownian.gamma / (2.0 * temperature)); + auto const noise = Random::v_noise_g(0, 0); + auto const ref = hadamard_division(noise, sigma) * sqrt(time_step); + bd_random_walk(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.r.p[0], ref[0], tol); + BOOST_CHECK_CLOSE(p.r.p[1], ref[1], tol); + BOOST_CHECK_CLOSE(p.r.p[2], ref[2], tol); + } + + /* check walk translational velocity */ + { + auto p = particle_factory(); + auto const sigma = sqrt(temperature); + auto const noise = Random::v_noise_g(0, 0); + auto const ref = sigma * noise / sqrt(p.p.mass); + bd_random_walk_vel(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.m.v[0], ref[0], tol); + BOOST_CHECK_CLOSE(p.m.v[1], ref[1], tol); + BOOST_CHECK_CLOSE(p.m.v[2], ref[2], tol); + } + +#ifdef ROTATION + auto const dispersion_rotation = + hadamard_division(particle_factory().f.torque, brownian.gamma_rotation); + + /* check rotation */ + { + auto p = particle_factory(); + p.p.rotation = ROTATION_X; + auto const phi = time_step * dispersion_rotation[0]; + bd_drag_rot(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.r.quat[0], std::cos(phi / 2), tol); + BOOST_CHECK_CLOSE(p.r.quat[1], std::sin(phi / 2), tol); + BOOST_CHECK_CLOSE(p.r.quat[2], 0, tol); + BOOST_CHECK_CLOSE(p.r.quat[3], 0, tol); + } + + /* check rotational velocity */ + { + auto p = particle_factory(); + p.p.rotation = ROTATION_X | ROTATION_Y | ROTATION_Z; + auto const ref = dispersion_rotation; + bd_drag_vel_rot(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.m.omega[0], ref[0], tol); + BOOST_CHECK_CLOSE(p.m.omega[1], ref[1], tol); + BOOST_CHECK_CLOSE(p.m.omega[2], ref[2], tol); + } + + /* check walk rotation */ + { + auto p = particle_factory(); + p.p.rotation = ROTATION_X; + auto const sigma = sqrt(brownian.gamma_rotation / (2.0 * temperature)); + auto const noise = Random::v_noise_g(0, 0); + auto const phi = hadamard_division(noise, sigma)[0] * sqrt(time_step); + bd_random_walk_rot(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.r.quat[0], std::cos(phi / 2), tol); + BOOST_CHECK_CLOSE(p.r.quat[1], std::sin(phi / 2), tol); + BOOST_CHECK_CLOSE(p.r.quat[2], 0, tol); + BOOST_CHECK_CLOSE(p.r.quat[3], 0, tol); + } + + /* check walk rotational velocity */ + { + auto p = particle_factory(); + p.p.rotation = ROTATION_X | ROTATION_Y | ROTATION_Z; + auto const sigma = sqrt(temperature); + auto const noise = Random::v_noise_g(0, 0); + auto const ref = sigma * noise; + bd_random_walk_vel_rot(brownian, p, time_step); + BOOST_CHECK_CLOSE(p.m.omega[0], ref[0], tol); + BOOST_CHECK_CLOSE(p.m.omega[1], ref[1], tol); + BOOST_CHECK_CLOSE(p.m.omega[2], ref[2], tol); + } +#endif // ROTATION +} + +BOOST_AUTO_TEST_CASE(test_langevin_dynamics) { + time_step = 0.1; + temperature = 3.0; + auto const langevin = thermostat_factory(); + auto const prefactor_squared = 24.0 * temperature / time_step; + + /* check translation */ + { + auto p = particle_factory(); + p.m.v = {1.0, 2.0, 3.0}; + auto const noise = Random::v_noise(0, 0); + auto const pref = sqrt(prefactor_squared * langevin.gamma); + auto const ref = hadamard_product(-langevin.gamma, p.m.v) + + hadamard_product(pref, noise); + auto const out = friction_thermo_langevin(langevin, p); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); + } + +#ifdef ROTATION + /* check rotation */ + { + auto p = particle_factory(); + p.m.omega = {1.0, 2.0, 3.0}; + auto const noise = Random::v_noise(0, 0); + auto const pref = sqrt(prefactor_squared * langevin.gamma_rotation); + auto const ref = hadamard_product(-langevin.gamma_rotation, p.m.omega) + + hadamard_product(pref, noise); + auto const out = friction_thermo_langevin_rotation(langevin, p); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); + } +#endif // ROTATION +} From 53d253f4799359bd30929a55588a24d1a6137fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Sat, 25 Jan 2020 16:36:38 +0100 Subject: [PATCH 133/150] Refactor thermostats Narrow interfaces, simplify code and fix include statements. --- src/core/integrators/brownian_inline.hpp | 79 ++++++++++---------- src/core/integrators/langevin_inline.hpp | 14 ++-- src/core/integrators/velocity_verlet_npt.cpp | 5 +- src/core/thermostat.cpp | 13 ++-- src/core/thermostat.hpp | 2 +- src/core/unit_tests/thermostats_test.cpp | 16 ++-- 6 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 1c638a9a5a5..1bbdcd8a6f5 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -23,16 +23,23 @@ #ifndef BROWNIAN_INLINE_HPP #define BROWNIAN_INLINE_HPP +#include "config.hpp" + +#include +#include + +#include "cells.hpp" +#include "particle_data.hpp" #include "random.hpp" #include "thermostat.hpp" /** Propagate position: viscous drag driven by conservative forces. * From eq. (14.39) in @cite Schlick2010. - * @param[in] brownian Parameters + * @param[in] brownian_gamma Brownian translational gamma * @param[in,out] p %Particle * @param[in] dt Time interval */ -inline void bd_drag(BrownianThermostat const &brownian, Particle &p, +inline void bd_drag(Thermostat::GammaType const &brownian_gamma, Particle &p, double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: Thermostat::GammaType gamma; @@ -43,7 +50,7 @@ inline void bd_drag(BrownianThermostat const &brownian, Particle &p, } else #endif { - gamma = brownian.gamma; + gamma = brownian_gamma; } bool aniso_flag; // particle anisotropy flag @@ -67,13 +74,13 @@ inline void bd_drag(BrownianThermostat const &brownian, Particle &p, // Only a conservative part of the force is used here #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { - delta_pos_body[j] = force_body[j] * dt / (gamma[j]); + delta_pos_body[j] = force_body[j] * dt / gamma[j]; } else { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += p.f.f[j] * dt / (gamma[j]); + p.r.p[j] += p.f.f[j] * dt / gamma[j]; } } #else @@ -81,7 +88,7 @@ inline void bd_drag(BrownianThermostat const &brownian, Particle &p, if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += p.f.f[j] * dt / (gamma); + p.r.p[j] += p.f.f[j] * dt / gamma; } #endif // PARTICLE_ANISOTROPY } @@ -102,12 +109,11 @@ inline void bd_drag(BrownianThermostat const &brownian, Particle &p, /** Set the terminal velocity driven by the conservative forces drag. * From eq. (14.34) in @cite Schlick2010. - * @param[in] brownian Parameters + * @param[in] brownian_gamma Brownian translational gamma * @param[in,out] p %Particle - * @param[in] dt Time interval */ -inline void bd_drag_vel(BrownianThermostat const &brownian, Particle &p, - double dt) { +inline void bd_drag_vel(Thermostat::GammaType const &brownian_gamma, + Particle &p) { // The friction tensor Z from the eq. (14.31) of Schlick2010: Thermostat::GammaType gamma; @@ -117,7 +123,7 @@ inline void bd_drag_vel(BrownianThermostat const &brownian, Particle &p, } else #endif { - gamma = brownian.gamma; + gamma = brownian_gamma; } bool aniso_flag; // particle anisotropy flag @@ -143,13 +149,13 @@ inline void bd_drag_vel(BrownianThermostat const &brownian, Particle &p, // further on top of it #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { - vel_body[j] = force_body[j] / (gamma[j]); + vel_body[j] = force_body[j] / gamma[j]; } else { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.m.v[j] = p.f.f[j] / (gamma[j]); + p.m.v[j] = p.f.f[j] / gamma[j]; } #ifdef EXTERNAL_FORCES else { @@ -162,7 +168,7 @@ inline void bd_drag_vel(BrownianThermostat const &brownian, Particle &p, if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.m.v[j] = p.f.f[j] / (gamma); + p.m.v[j] = p.f.f[j] / gamma; } #endif // PARTICLE_ANISOTROPY } @@ -296,10 +302,9 @@ void bd_random_walk(BrownianThermostat const &brownian, Particle &p, * From eq. (10.2.16) in @cite Pottier2010. * @param[in] brownian Parameters * @param[in,out] p %Particle - * @param[in] dt Time interval */ -inline void bd_random_walk_vel(BrownianThermostat const &brownian, Particle &p, - double dt) { +inline void bd_random_walk_vel(BrownianThermostat const &brownian, + Particle &p) { // skip the translation thermalizing for virtual sites unless enabled extern bool thermo_virtual; if (p.p.is_virtual && !thermo_virtual) @@ -346,11 +351,12 @@ inline void bd_random_walk_vel(BrownianThermostat const &brownian, Particle &p, /** Propagate quaternions: viscous drag driven by conservative torques. * An analogy of eq. (14.39) in @cite Schlick2010. - * @param[in] brownian Parameters + * @param[in] brownian_gamma_rotation Brownian rotational gamma * @param[in,out] p %Particle * @param[in] dt Time interval */ -void bd_drag_rot(BrownianThermostat const &brownian, Particle &p, double dt) { +void bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, + Particle &p, double dt) { Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE @@ -359,7 +365,7 @@ void bd_drag_rot(BrownianThermostat const &brownian, Particle &p, double dt) { } else #endif { - gamma = brownian.gamma_rotation; + gamma = brownian_gamma_rotation; } Utils::Vector3d dphi = {0.0, 0.0, 0.0}; @@ -370,9 +376,9 @@ void bd_drag_rot(BrownianThermostat const &brownian, Particle &p, double dt) { { // only a conservative part of the torque is used here #ifndef PARTICLE_ANISOTROPY - dphi[j] = p.f.torque[j] * dt / (gamma); + dphi[j] = p.f.torque[j] * dt / gamma; #else - dphi[j] = p.f.torque[j] * dt / (gamma[j]); + dphi[j] = p.f.torque[j] * dt / gamma[j]; #endif // ROTATIONAL_INERTIA } } // j @@ -387,12 +393,11 @@ void bd_drag_rot(BrownianThermostat const &brownian, Particle &p, double dt) { /** Set the terminal angular velocity driven by the conservative torques drag. * An analogy of the 1st term of eq. (14.34) in @cite Schlick2010. - * @param[in] brownian Parameters + * @param[in] brownian_gamma_rotation Brownian rotational gamma * @param[in,out] p %Particle - * @param[in] dt Time interval */ -void bd_drag_vel_rot(BrownianThermostat const &brownian, Particle &p, - double dt) { +void bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation, + Particle &p) { Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE @@ -401,7 +406,7 @@ void bd_drag_vel_rot(BrownianThermostat const &brownian, Particle &p, } else #endif { - gamma = brownian.gamma_rotation; + gamma = brownian_gamma_rotation; } for (int j = 0; j < 3; j++) { @@ -415,9 +420,9 @@ void bd_drag_vel_rot(BrownianThermostat const &brownian, Particle &p, // NOTE: velocity is assigned here and propagated by thermal part further // on top of it #ifndef PARTICLE_ANISOTROPY - p.m.omega[j] = p.f.torque[j] / (gamma); + p.m.omega[j] = p.f.torque[j] / gamma; #else - p.m.omega[j] = p.f.torque[j] / (gamma[j]); + p.m.omega[j] = p.f.torque[j] / gamma[j]; #endif // ROTATIONAL_INERTIA } } @@ -509,10 +514,8 @@ void bd_random_walk_rot(BrownianThermostat const &brownian, Particle &p, * An analogy of eq. (10.2.16) in @cite Pottier2010. * @param[in] brownian Parameters * @param[in,out] p %Particle - * @param[in] dt Time interval */ -void bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle &p, - double dt) { +void bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle &p) { double sigma_vel; // Override defaults if per-particle values for T and gamma are given @@ -556,10 +559,10 @@ inline void brownian_dynamics_propagator(BrownianThermostat const &brownian, if (!(p.p.is_virtual) or thermo_virtual) #endif { - bd_drag(brownian, p, time_step); - bd_drag_vel(brownian, p, time_step); + bd_drag(brownian.gamma, p, time_step); + bd_drag_vel(brownian.gamma, p); bd_random_walk(brownian, p, time_step); - bd_random_walk_vel(brownian, p, time_step); + bd_random_walk_vel(brownian, p); /* Verlet criterion check */ if ((p.r.p - p.l.p_old).norm2() > Utils::sqr(0.5 * skin)) set_resort_particles(Cells::RESORT_LOCAL); @@ -568,10 +571,10 @@ inline void brownian_dynamics_propagator(BrownianThermostat const &brownian, if (!p.p.rotation) continue; convert_torque_to_body_frame_apply_fix(p); - bd_drag_rot(brownian, p, time_step); - bd_drag_vel_rot(brownian, p, time_step); + bd_drag_rot(brownian.gamma_rotation, p, time_step); + bd_drag_vel_rot(brownian.gamma_rotation, p); bd_random_walk_rot(brownian, p, time_step); - bd_random_walk_vel_rot(brownian, p, time_step); + bd_random_walk_vel_rot(brownian, p); #endif // ROTATION } sim_time += time_step; diff --git a/src/core/integrators/langevin_inline.hpp b/src/core/integrators/langevin_inline.hpp index f746304495e..9bb23ce5551 100644 --- a/src/core/integrators/langevin_inline.hpp +++ b/src/core/integrators/langevin_inline.hpp @@ -23,6 +23,10 @@ #ifndef LANGEVIN_INLINE_HPP #define LANGEVIN_INLINE_HPP +#include "config.hpp" + +#include + #include "random.hpp" #include "thermostat.hpp" @@ -30,6 +34,8 @@ * Collects the particle velocity (different for ENGINE, PARTICLE_ANISOTROPY). * Collects the langevin parameters kT, gamma (different for * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. + * @param[in] langevin Parameters + * @param[in,out] p %Particle */ inline Utils::Vector3d friction_thermo_langevin(LangevinThermostat const &langevin, @@ -80,7 +86,6 @@ friction_thermo_langevin(LangevinThermostat const &langevin, #endif // PARTICLE_ANISOTROPY using Random::v_noise; - // Do the actual (isotropic) thermostatting return friction_op * velocity + noise_op * v_noise(langevin.rng_counter->value(), p.p.identity); @@ -91,6 +96,8 @@ friction_thermo_langevin(LangevinThermostat const &langevin, * Collects the particle velocity (different for PARTICLE_ANISOTROPY). * Collects the langevin parameters kT, gamma_rot (different for * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. + * @param[in] langevin Parameters + * @param[in,out] p %Particle */ inline Utils::Vector3d friction_thermo_langevin_rotation(LangevinThermostat const &langevin, @@ -114,15 +121,10 @@ friction_thermo_langevin_rotation(LangevinThermostat const &langevin, using Random::v_noise; - // Here the thermostats happens auto const noise = v_noise( langevin.rng_counter->value(), p.p.identity); -#ifdef PARTICLE_ANISOTROPY return hadamard_product(pref_friction, p.m.omega) + hadamard_product(pref_noise, noise); -#else - return pref_friction * p.m.omega + pref_noise * noise; -#endif } #endif // ROTATION diff --git a/src/core/integrators/velocity_verlet_npt.cpp b/src/core/integrators/velocity_verlet_npt.cpp index 350a9e3634e..a416e5196b5 100644 --- a/src/core/integrators/velocity_verlet_npt.cpp +++ b/src/core/integrators/velocity_verlet_npt.cpp @@ -59,17 +59,16 @@ void velocity_verlet_npt_propagate_vel_final(const ParticleRange &particles) { /** Scale and communicate instantaneous NpT pressure */ void velocity_verlet_npt_finalize_p_inst() { extern IsotropicNptThermostat npt_iso; - double p_tmp = 0.0; - int i; /* finalize derivation of p_inst */ nptiso.p_inst = 0.0; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { if (nptiso.geometry & nptiso.nptgeom_dir[i]) { nptiso.p_vel[i] /= Utils::sqr(time_step); nptiso.p_inst += nptiso.p_vir[i] + nptiso.p_vel[i]; } } + double p_tmp = 0.0; MPI_Reduce(&nptiso.p_inst, &p_tmp, 1, MPI_DOUBLE, MPI_SUM, 0, comm_cart); if (this_node == 0) { nptiso.p_inst = p_tmp / (nptiso.dimension * nptiso.volume); diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index 6efcdbfe421..84e0402b88d 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -21,19 +21,16 @@ /** \file * Implementation of \ref thermostat.hpp. */ -#include "thermostat.hpp" +#include + +#include + #include "bonded_interactions/thermalized_bond.hpp" #include "communication.hpp" #include "dpd.hpp" #include "grid_based_algorithms/lb_interface.hpp" #include "npt.hpp" - -#include "utils/u32_to_u64.hpp" -#include - -#include -#include -#include +#include "thermostat.hpp" int thermo_switch = THERMO_OFF; double temperature = 0.0; diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 6e571e2b665..0efeb104b90 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -112,7 +112,7 @@ struct LangevinThermostat { if (gamma_rotation < GammaType{}) { gamma_rotation = gamma; } - pref_noise_rotation = sqrt(24.0 * temperature * gamma_rotation / time_step); + pref_noise_rotation = sqrt(24.0 * temperature / time_step * gamma_rotation); } /** @name Parameters */ /*@{*/ diff --git a/src/core/unit_tests/thermostats_test.cpp b/src/core/unit_tests/thermostats_test.cpp index 8aa20496f52..9f21314a1ac 100644 --- a/src/core/unit_tests/thermostats_test.cpp +++ b/src/core/unit_tests/thermostats_test.cpp @@ -30,11 +30,9 @@ #include #include "Particle.hpp" -#include "particle_data.hpp" -#include "cells.hpp" -#include "thermostat.hpp" #include "integrators/brownian_inline.hpp" #include "integrators/langevin_inline.hpp" +#include "thermostat.hpp" extern double time_step; extern double temperature; @@ -79,7 +77,7 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { { auto p = particle_factory(); auto const ref = time_step * dispersion; - bd_drag(brownian, p, time_step); + bd_drag(brownian.gamma, p, time_step); BOOST_CHECK_CLOSE(p.r.p[0], ref[0], tol); BOOST_CHECK_CLOSE(p.r.p[1], ref[1], tol); BOOST_CHECK_CLOSE(p.r.p[2], ref[2], tol); @@ -89,7 +87,7 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { { auto p = particle_factory(); auto const ref = dispersion; - bd_drag_vel(brownian, p, time_step); + bd_drag_vel(brownian.gamma, p); BOOST_CHECK_CLOSE(p.m.v[0], ref[0], tol); BOOST_CHECK_CLOSE(p.m.v[1], ref[1], tol); BOOST_CHECK_CLOSE(p.m.v[2], ref[2], tol); @@ -113,7 +111,7 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto const sigma = sqrt(temperature); auto const noise = Random::v_noise_g(0, 0); auto const ref = sigma * noise / sqrt(p.p.mass); - bd_random_walk_vel(brownian, p, time_step); + bd_random_walk_vel(brownian, p); BOOST_CHECK_CLOSE(p.m.v[0], ref[0], tol); BOOST_CHECK_CLOSE(p.m.v[1], ref[1], tol); BOOST_CHECK_CLOSE(p.m.v[2], ref[2], tol); @@ -128,7 +126,7 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto p = particle_factory(); p.p.rotation = ROTATION_X; auto const phi = time_step * dispersion_rotation[0]; - bd_drag_rot(brownian, p, time_step); + bd_drag_rot(brownian.gamma_rotation, p, time_step); BOOST_CHECK_CLOSE(p.r.quat[0], std::cos(phi / 2), tol); BOOST_CHECK_CLOSE(p.r.quat[1], std::sin(phi / 2), tol); BOOST_CHECK_CLOSE(p.r.quat[2], 0, tol); @@ -140,7 +138,7 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto p = particle_factory(); p.p.rotation = ROTATION_X | ROTATION_Y | ROTATION_Z; auto const ref = dispersion_rotation; - bd_drag_vel_rot(brownian, p, time_step); + bd_drag_vel_rot(brownian.gamma_rotation, p); BOOST_CHECK_CLOSE(p.m.omega[0], ref[0], tol); BOOST_CHECK_CLOSE(p.m.omega[1], ref[1], tol); BOOST_CHECK_CLOSE(p.m.omega[2], ref[2], tol); @@ -167,7 +165,7 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto const sigma = sqrt(temperature); auto const noise = Random::v_noise_g(0, 0); auto const ref = sigma * noise; - bd_random_walk_vel_rot(brownian, p, time_step); + bd_random_walk_vel_rot(brownian, p); BOOST_CHECK_CLOSE(p.m.omega[0], ref[0], tol); BOOST_CHECK_CLOSE(p.m.omega[1], ref[1], tol); BOOST_CHECK_CLOSE(p.m.omega[2], ref[2], tol); From dc47afca68da470ab554d273211ad464ede8b502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 24 Jan 2020 18:32:59 +0100 Subject: [PATCH 134/150] Refactor thermostats noise sigma calculation Simplify and centralize the logic to calculate the noise standard deviation in Brownian/Langevin thermostats. Replace all the inverse sigmas by regular sigmas in the Brownian prefactors; those were no longer needed since the Brownian code is now separate from the Langevin code. --- src/core/integrators/brownian_inline.hpp | 69 +++++++++++------------- src/core/integrators/langevin_inline.hpp | 10 ++-- src/core/thermostat.hpp | 65 +++++++++++----------- 3 files changed, 70 insertions(+), 74 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index 1bbdcd8a6f5..daf78c893fe 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -206,51 +206,48 @@ void bd_random_walk(BrownianThermostat const &brownian, Particle &p, if (p.p.is_virtual && !thermo_virtual) return; // first, set defaults - Thermostat::GammaType sigma_pos_inv = brownian.sigma_pos_inv; + Thermostat::GammaType sigma_pos = brownian.sigma_pos; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr temp_coeff = 2.0; - if (p.p.gamma >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { - sigma_pos_inv = sqrt(p.p.gamma / (temp_coeff * p.p.T)); + sigma_pos = BrownianThermostat::sigma(p.p.T, p.p.gamma); } else { // just an indication of the infinity - sigma_pos_inv = brownian.gammatype_nan; + sigma_pos = Thermostat::GammaType{}; } } else // default temperature but particle-specific gamma if (temperature > 0.0) { - sigma_pos_inv = sqrt(p.p.gamma / (temp_coeff * temperature)); + sigma_pos = BrownianThermostat::sigma(temperature, p.p.gamma); } else { - sigma_pos_inv = brownian.gammatype_nan; + sigma_pos = Thermostat::GammaType{}; } } // particle-specific gamma else { // No particle-specific gamma, but is there particle-specific temperature if (p.p.T >= 0.) { if (p.p.T > 0.0) { - sigma_pos_inv = sqrt(brownian.gamma / (temp_coeff * p.p.T)); + sigma_pos = BrownianThermostat::sigma(p.p.T, brownian.gamma); } else { // just an indication of the infinity - sigma_pos_inv = brownian.gammatype_nan; + sigma_pos = Thermostat::GammaType{}; } } else { // default values for both - sigma_pos_inv = brownian.sigma_pos_inv; + sigma_pos = brownian.sigma_pos; } } -#endif /* BROWNIAN_PER_PARTICLE */ +#endif // BROWNIAN_PER_PARTICLE bool aniso_flag; // particle anisotropy flag #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (sigma_pos_inv[0] != sigma_pos_inv[1]) || - (sigma_pos_inv[1] != sigma_pos_inv[2]); + aniso_flag = (sigma_pos[0] != sigma_pos[1]) || (sigma_pos[1] != sigma_pos[2]); #else aniso_flag = false; #endif // PARTICLE_ANISOTROPY @@ -267,14 +264,14 @@ void bd_random_walk(BrownianThermostat const &brownian, Particle &p, #endif { #ifndef PARTICLE_ANISOTROPY - if (sigma_pos_inv > 0.0) { - delta_pos_body[j] = (1.0 / sigma_pos_inv) * sqrt(dt) * noise[j]; + if (sigma_pos > 0.0) { + delta_pos_body[j] = sigma_pos * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } #else - if (sigma_pos_inv[j] > 0.0) { - delta_pos_body[j] = (1.0 / sigma_pos_inv[j]) * sqrt(dt) * noise[j]; + if (sigma_pos[j] > 0.0) { + delta_pos_body[j] = sigma_pos[j] * sqrt(dt) * noise[j]; } else { delta_pos_body[j] = 0.0; } @@ -315,17 +312,16 @@ inline void bd_random_walk_vel(BrownianThermostat const &brownian, // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - sigma_vel = sqrt(temp_coeff * p.p.T); + sigma_vel = BrownianThermostat::sigma(p.p.T); } else { sigma_vel = brownian.sigma_vel; } #else // defaults sigma_vel = brownian.sigma_vel; -#endif /* BROWNIAN_PER_PARTICLE */ +#endif // BROWNIAN_PER_PARTICLE Utils::Vector3d noise = Random::v_noise_g( brownian.rng_counter->value(), p.identity()); @@ -438,44 +434,42 @@ void bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation, void bd_random_walk_rot(BrownianThermostat const &brownian, Particle &p, double dt) { // first, set defaults - Thermostat::GammaType sigma_pos_inv = brownian.sigma_pos_rotation_inv; + Thermostat::GammaType sigma_pos = brownian.sigma_pos_rotation; // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr temp_coeff = 2.0; - if (p.p.gamma_rot >= Thermostat::GammaType{}) { // Is a particle-specific temperature also specified? if (p.p.T >= 0.) { if (p.p.T > 0.0) { - sigma_pos_inv = sqrt(p.p.gamma_rot / (temp_coeff * p.p.T)); + sigma_pos = BrownianThermostat::sigma(p.p.T, p.p.gamma_rot); } else { // just an indication of the infinity - sigma_pos_inv = brownian.gammatype_nan; + sigma_pos = Utils::Vector3d{}; } } else if (temperature > 0.) { // Default temperature but particle-specific gamma - sigma_pos_inv = sqrt(p.p.gamma_rot / (temp_coeff * temperature)); + sigma_pos = BrownianThermostat::sigma(temperature, p.p.gamma_rot); } else { // just an indication of the infinity - sigma_pos_inv = brownian.gammatype_nan; + sigma_pos = Utils::Vector3d{}; } } // particle-specific gamma else { // No particle-specific gamma, but is there particle-specific temperature if (p.p.T >= 0.) { if (p.p.T > 0.0) { - sigma_pos_inv = sqrt(brownian.gamma_rotation / (temp_coeff * p.p.T)); + sigma_pos = BrownianThermostat::sigma(p.p.T, brownian.gamma_rotation); } else { // just an indication of the infinity - sigma_pos_inv = brownian.gammatype_nan; + sigma_pos = Utils::Vector3d{}; } } else { // Defaut values for both - sigma_pos_inv = brownian.sigma_pos_rotation_inv; + sigma_pos = brownian.sigma_pos_rotation; } } -#endif /* BROWNIAN_PER_PARTICLE */ +#endif // BROWNIAN_PER_PARTICLE Utils::Vector3d dphi = {0.0, 0.0, 0.0}; Utils::Vector3d noise = Random::v_noise_g( @@ -486,14 +480,14 @@ void bd_random_walk_rot(BrownianThermostat const &brownian, Particle &p, #endif { #ifndef PARTICLE_ANISOTROPY - if (sigma_pos_inv > 0.0) { - dphi[j] = noise[j] * (1.0 / sigma_pos_inv) * sqrt(dt); + if (sigma_pos > 0.0) { + dphi[j] = noise[j] * sigma_pos * sqrt(dt); } else { dphi[j] = 0.0; } #else - if (sigma_pos_inv[j] > 0.0) { - dphi[j] = noise[j] * (1.0 / sigma_pos_inv[j]) * sqrt(dt); + if (sigma_pos[j] > 0.0) { + dphi[j] = noise[j] * sigma_pos[j] * sqrt(dt); } else { dphi[j] = 0.0; } @@ -520,17 +514,16 @@ void bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle &p) { // Override defaults if per-particle values for T and gamma are given #ifdef BROWNIAN_PER_PARTICLE - auto const constexpr temp_coeff = 1.0; // Is a particle-specific temperature specified? if (p.p.T >= 0.) { - sigma_vel = sqrt(temp_coeff * p.p.T); + sigma_vel = BrownianThermostat::sigma(p.p.T); } else { sigma_vel = brownian.sigma_vel_rotation; } #else // set defaults sigma_vel = brownian.sigma_vel_rotation; -#endif /* BROWNIAN_PER_PARTICLE */ +#endif // BROWNIAN_PER_PARTICLE Utils::Vector3d domega; Utils::Vector3d noise = Random::v_noise_g( diff --git a/src/core/integrators/langevin_inline.hpp b/src/core/integrators/langevin_inline.hpp index 9bb23ce5551..729a8641e29 100644 --- a/src/core/integrators/langevin_inline.hpp +++ b/src/core/integrators/langevin_inline.hpp @@ -52,14 +52,13 @@ friction_thermo_langevin(LangevinThermostat const &langevin, // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma >= Thermostat::GammaType{} or p.p.T >= 0.) { - auto const constexpr temp_coeff = 24.0; auto const kT = p.p.T >= 0. ? p.p.T : temperature; auto const gamma = p.p.gamma >= Thermostat::GammaType{} ? p.p.gamma : langevin.gamma; pref_friction = -gamma; - pref_noise = sqrt(temp_coeff * kT * gamma / time_step); + pref_noise = LangevinThermostat::sigma(kT, time_step, gamma); } -#endif /* LANGEVIN_PER_PARTICLE */ +#endif // LANGEVIN_PER_PARTICLE // Get effective velocity in the thermostatting #ifdef ENGINE @@ -109,15 +108,14 @@ friction_thermo_langevin_rotation(LangevinThermostat const &langevin, // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE if (p.p.gamma_rot >= Thermostat::GammaType{} or p.p.T >= 0.) { - auto const constexpr temp_coeff = 24.0; auto const kT = p.p.T >= 0. ? p.p.T : temperature; auto const gamma = p.p.gamma_rot >= Thermostat::GammaType{} ? p.p.gamma_rot : langevin.gamma_rotation; pref_friction = -gamma; - pref_noise = sqrt(temp_coeff * kT * gamma / time_step); + pref_noise = LangevinThermostat::sigma(kT, time_step, gamma); } -#endif /* LANGEVIN_PER_PARTICLE */ +#endif // LANGEVIN_PER_PARTICLE using Random::v_noise; diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 0efeb104b90..1a051f71931 100644 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -69,8 +69,6 @@ constexpr double sentinel(double) { return -1.0; } constexpr Utils::Vector3d sentinel(Utils::Vector3d) { return {-1.0, -1.0, -1.0}; } -constexpr double set_nan(double) { return NAN; } -constexpr Utils::Vector3d set_nan(Utils::Vector3d) { return {NAN, NAN, NAN}; } /*@}*/ } // namespace @@ -107,12 +105,17 @@ struct LangevinThermostat { */ void recalc_prefactors() { pref_friction = -gamma; - pref_noise = sqrt(24.0 * temperature / time_step * gamma); + pref_noise = sigma(temperature, time_step, gamma); // If gamma_rotation is not set explicitly, use the translational one. if (gamma_rotation < GammaType{}) { gamma_rotation = gamma; } - pref_noise_rotation = sqrt(24.0 * temperature / time_step * gamma_rotation); + pref_noise_rotation = sigma(temperature, time_step, gamma_rotation); + } + /** Calculate the noise standard deviation. */ + static GammaType sigma(double kT, double time_step, GammaType const &gamma) { + constexpr auto const temp_coeff = 24.0; + return sqrt((temp_coeff * kT / time_step) * gamma); } /** @name Parameters */ /*@{*/ @@ -150,17 +153,12 @@ struct BrownianThermostat { * which is only valid for the BD. Just a square root of kT, see (10.2.17) * and comments in 2 paragraphs afterwards, @cite Pottier2010. */ - sigma_vel = sqrt(temperature); + sigma_vel = sigma(temperature); /** The random walk position dispersion is defined by the second eq. (14.38) * of @cite Schlick2010. Its time interval factor will be added in the * Brownian Dynamics functions. Its square root is the standard deviation. */ - if (temperature > 0.0) { - sigma_pos_inv = sqrt(gamma / (2.0 * temperature)); - } else { - // just an indication of the infinity - sigma_pos_inv = gammatype_nan; - } + sigma_pos = sigma(temperature, gamma); #ifdef ROTATION /** Note: the BD thermostat assigns the brownian viscous parameters as well. * They correspond to the friction tensor Z from the eq. (14.31) of @@ -170,15 +168,20 @@ struct BrownianThermostat { if (gamma_rotation < GammaType{}) { gamma_rotation = gamma; } - sigma_vel_rotation = sqrt(temperature); - if (temperature > 0.0) { - sigma_pos_rotation_inv = sqrt(gamma_rotation / (2.0 * temperature)); - } else { - // just an indication of the infinity - sigma_pos_rotation_inv = gammatype_nan; - } + sigma_vel_rotation = sigma(temperature); + sigma_pos_rotation = sigma(temperature, gamma_rotation); #endif // ROTATION } + /** Calculate the noise standard deviation. */ + static GammaType sigma(double kT, GammaType const &gamma) { + constexpr auto const temp_coeff = 2.0; + return sqrt(Utils::hadamard_division(temp_coeff * kT, gamma)); + } + /** Calculate the noise standard deviation. */ + static double sigma(double kT) { + constexpr auto const temp_coeff = 1.0; + return sqrt(temp_coeff * kT); + } /** @name Parameters */ /*@{*/ /** Translational friction coefficient @f$ \gamma_{\text{trans}} @f$. */ @@ -186,25 +189,27 @@ struct BrownianThermostat { /** Rotational friction coefficient @f$ \gamma_{\text{rot}} @f$. */ GammaType gamma_rotation = sentinel(GammaType{}); /*@}*/ - /** Sentinel value for divisions by zero. */ - GammaType const gammatype_nan = set_nan(GammaType{}); /** @name Prefactors */ /*@{*/ - /** Inverse of the translational noise standard deviation. - * Stores @f$ \left(\sqrt{2D_{\text{trans}}}\right)^{-1} @f$ with + /** Translational noise standard deviation. + * Stores @f$ \sqrt{2D_{\text{trans}}} @f$ with * @f$ D_{\text{trans}} = k_B T/\gamma_{\text{trans}} @f$ - * the translational diffusion coefficient + * the translational diffusion coefficient. */ - GammaType sigma_pos_inv = sentinel(GammaType{}); - /** Inverse of the rotational noise standard deviation. - * Stores @f$ \left(\sqrt{2D_{\text{rot}}}\right)^{-1} @f$ with + GammaType sigma_pos = sentinel(GammaType{}); + /** Rotational noise standard deviation. + * Stores @f$ \sqrt{2D_{\text{rot}}} @f$ with * @f$ D_{\text{rot}} = k_B T/\gamma_{\text{rot}} @f$ - * the rotational diffusion coefficient + * the rotational diffusion coefficient. + */ + GammaType sigma_pos_rotation = sentinel(GammaType{}); + /** Translational velocity noise standard deviation. + * Stores @f$ \sqrt{k_B T} @f$. */ - GammaType sigma_pos_rotation_inv = sentinel(GammaType{}); - /** Translational velocity noise standard deviation. */ double sigma_vel = 0; - /** Angular velocity noise standard deviation. */ + /** Angular velocity noise standard deviation. + * Stores @f$ \sqrt{k_B T} @f$. + */ double sigma_vel_rotation = 0; /*@}*/ /** RNG counter, used for both translation and rotation. */ From be3e2f399c72ceb40a2ec7523d975638a2012f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Sat, 25 Jan 2020 18:45:21 +0100 Subject: [PATCH 135/150] Refactor thermostats using pure functions Remove side effect and hide implementation details of Particles. Fuse loops. Remove comments in Brownian functions that walked through the propagator workflow, because that information is now completely transparent by reading the body of `brownian_dynamics_propagator()`. --- src/core/integrators/brownian_inline.hpp | 252 ++++++++++------------- src/core/integrators/langevin_inline.hpp | 6 +- src/core/rotation.hpp | 16 +- src/core/unit_tests/thermostats_test.cpp | 76 +++---- 4 files changed, 156 insertions(+), 194 deletions(-) diff --git a/src/core/integrators/brownian_inline.hpp b/src/core/integrators/brownian_inline.hpp index daf78c893fe..e9a4df94086 100644 --- a/src/core/integrators/brownian_inline.hpp +++ b/src/core/integrators/brownian_inline.hpp @@ -33,14 +33,14 @@ #include "random.hpp" #include "thermostat.hpp" -/** Propagate position: viscous drag driven by conservative forces. +/** Determine position: viscous drag driven by conservative forces. * From eq. (14.39) in @cite Schlick2010. * @param[in] brownian_gamma Brownian translational gamma - * @param[in,out] p %Particle + * @param[in] p %Particle * @param[in] dt Time interval */ -inline void bd_drag(Thermostat::GammaType const &brownian_gamma, Particle &p, - double dt) { +inline Utils::Vector3d bd_drag(Thermostat::GammaType const &brownian_gamma, + Particle const &p, double dt) { // The friction tensor Z from the Eq. (14.31) of Schlick2010: Thermostat::GammaType gamma; @@ -53,34 +53,35 @@ inline void bd_drag(Thermostat::GammaType const &brownian_gamma, Particle &p, gamma = brownian_gamma; } - bool aniso_flag; // particle anisotropy flag - #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (gamma[0] != gamma[1]) || (gamma[1] != gamma[2]); -#endif - - Utils::Vector3d force_body; - Utils::Vector3d delta_pos_body, delta_pos_lab; - -#ifdef PARTICLE_ANISOTROPY + auto const aniso_flag = (gamma[0] != gamma[1]) || (gamma[1] != gamma[2]); + Utils::Vector3d delta_pos_lab; if (aniso_flag) { - force_body = convert_vector_space_to_body(p, p.f.f); + auto const force_body = convert_vector_space_to_body(p, p.f.f); + auto const delta_pos_body = hadamard_division(force_body * dt, gamma); + delta_pos_lab = convert_vector_body_to_space(p, delta_pos_body); } #endif + Utils::Vector3d position = {}; for (int j = 0; j < 3; j++) { // Second (deterministic) term of the Eq. (14.39) of Schlick2010. // Only a conservative part of the force is used here #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { - delta_pos_body[j] = force_body[j] * dt / gamma[j]; +#ifdef EXTERNAL_FORCES + if (!(p.p.ext_flag & COORD_FIXED(j))) +#endif + { + position[j] = delta_pos_lab[j]; + } } else { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += p.f.f[j] * dt / gamma[j]; + position[j] = p.f.f[j] * dt / gamma[j]; } } #else @@ -88,32 +89,20 @@ inline void bd_drag(Thermostat::GammaType const &brownian_gamma, Particle &p, if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += p.f.f[j] * dt / gamma; + position[j] = p.f.f[j] * dt / gamma; } #endif // PARTICLE_ANISOTROPY } -#ifdef PARTICLE_ANISOTROPY - if (aniso_flag) { - delta_pos_lab = convert_vector_body_to_space(p, delta_pos_body); - for (int j = 0; j < 3; j++) { -#ifdef EXTERNAL_FORCES - if (!(p.p.ext_flag & COORD_FIXED(j))) -#endif - { - p.r.p[j] += delta_pos_lab[j]; - } - } - } -#endif // PARTICLE_ANISOTROPY + return position; } /** Set the terminal velocity driven by the conservative forces drag. * From eq. (14.34) in @cite Schlick2010. * @param[in] brownian_gamma Brownian translational gamma - * @param[in,out] p %Particle + * @param[in] p %Particle */ -inline void bd_drag_vel(Thermostat::GammaType const &brownian_gamma, - Particle &p) { +inline Utils::Vector3d bd_drag_vel(Thermostat::GammaType const &brownian_gamma, + Particle const &p) { // The friction tensor Z from the eq. (14.31) of Schlick2010: Thermostat::GammaType gamma; @@ -126,85 +115,62 @@ inline void bd_drag_vel(Thermostat::GammaType const &brownian_gamma, gamma = brownian_gamma; } - bool aniso_flag; // particle anisotropy flag - #ifdef PARTICLE_ANISOTROPY // Particle frictional isotropy check. - aniso_flag = (gamma[0] != gamma[1]) || (gamma[1] != gamma[2]); -#endif - - Utils::Vector3d force_body; - Utils::Vector3d vel_body, vel_lab; - -#ifdef PARTICLE_ANISOTROPY + auto const aniso_flag = (gamma[0] != gamma[1]) || (gamma[1] != gamma[2]); + Utils::Vector3d vel_lab; if (aniso_flag) { - force_body = convert_vector_space_to_body(p, p.f.f); + auto const force_body = convert_vector_space_to_body(p, p.f.f); + auto const vel_body = hadamard_division(force_body, gamma); + vel_lab = convert_vector_body_to_space(p, vel_body); } #endif + Utils::Vector3d velocity = {}; for (int j = 0; j < 3; j++) { // First (deterministic) term of the eq. (14.34) of Schlick2010 taking // into account eq. (14.35). Only conservative part of the force is used - // here. NOTE: velocity is assigned here and propagated by thermal part - // further on top of it + // here. #ifdef PARTICLE_ANISOTROPY if (aniso_flag) { - vel_body[j] = force_body[j] / gamma[j]; - } else { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.m.v[j] = p.f.f[j] / gamma[j]; + velocity[j] = vel_lab[j]; } + } else { #ifdef EXTERNAL_FORCES - else { - p.m.v[j] = 0.0; - } + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif + { + velocity[j] = p.f.f[j] / gamma[j]; + } } #else // PARTICLE_ANISOTROPY #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.m.v[j] = p.f.f[j] / gamma; + velocity[j] = p.f.f[j] / gamma; } #endif // PARTICLE_ANISOTROPY } - -#ifdef PARTICLE_ANISOTROPY - if (aniso_flag) { - vel_lab = convert_vector_body_to_space(p, vel_body); - for (int j = 0; j < 3; j++) { -#ifdef EXTERNAL_FORCES - if (!(p.p.ext_flag & COORD_FIXED(j))) -#endif - { - p.m.v[j] = vel_lab[j]; - } -#ifdef EXTERNAL_FORCES - else { - p.m.v[j] = 0.0; - } -#endif - } - } -#endif // PARTICLE_ANISOTROPY + return velocity; } -/** Propagate the positions: random walk part. +/** Determine the positions: random walk part. * From eq. (14.37) in @cite Schlick2010. * @param[in] brownian Parameters - * @param[in,out] p %Particle + * @param[in] p %Particle * @param[in] dt Time interval */ -void bd_random_walk(BrownianThermostat const &brownian, Particle &p, - double dt) { +inline Utils::Vector3d bd_random_walk(BrownianThermostat const &brownian, + Particle const &p, double dt) { // skip the translation thermalizing for virtual sites unless enabled extern bool thermo_virtual; if (p.p.is_virtual && !thermo_virtual) - return; + return {}; // first, set defaults Thermostat::GammaType sigma_pos = brownian.sigma_pos; @@ -243,19 +209,9 @@ void bd_random_walk(BrownianThermostat const &brownian, Particle &p, } #endif // BROWNIAN_PER_PARTICLE - bool aniso_flag; // particle anisotropy flag - -#ifdef PARTICLE_ANISOTROPY - // Particle frictional isotropy check. - aniso_flag = (sigma_pos[0] != sigma_pos[1]) || (sigma_pos[1] != sigma_pos[2]); -#else - aniso_flag = false; -#endif // PARTICLE_ANISOTROPY - - Utils::Vector3d delta_pos_body, delta_pos_lab; - // Eq. (14.37) is factored by the Gaussian noise (12.22) with its squared // magnitude defined in the second eq. (14.38), Schlick2010. + Utils::Vector3d delta_pos_body{}; Utils::Vector3d noise = Random::v_noise_g( brownian.rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { @@ -280,32 +236,42 @@ void bd_random_walk(BrownianThermostat const &brownian, Particle &p, } #ifdef PARTICLE_ANISOTROPY + // Particle frictional isotropy check. + auto const aniso_flag = + (sigma_pos[0] != sigma_pos[1]) || (sigma_pos[1] != sigma_pos[2]); + Utils::Vector3d delta_pos_lab; if (aniso_flag) { delta_pos_lab = convert_vector_body_to_space(p, delta_pos_body); } #endif + Utils::Vector3d position = {}; for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - p.r.p[j] += aniso_flag ? delta_pos_lab[j] : delta_pos_body[j]; +#ifdef PARTICLE_ANISOTROPY + position[j] += aniso_flag ? delta_pos_lab[j] : delta_pos_body[j]; +#else + position[j] += delta_pos_body[j]; +#endif } } + return position; } /** Determine the velocities: random walk part. * From eq. (10.2.16) in @cite Pottier2010. * @param[in] brownian Parameters - * @param[in,out] p %Particle + * @param[in] p %Particle */ -inline void bd_random_walk_vel(BrownianThermostat const &brownian, - Particle &p) { +inline Utils::Vector3d bd_random_walk_vel(BrownianThermostat const &brownian, + Particle const &p) { // skip the translation thermalizing for virtual sites unless enabled extern bool thermo_virtual; if (p.p.is_virtual && !thermo_virtual) - return; + return {}; // Just a square root of kT, see eq. (10.2.17) and comments in 2 paragraphs // afterwards, Pottier2010 double sigma_vel; @@ -325,34 +291,36 @@ inline void bd_random_walk_vel(BrownianThermostat const &brownian, Utils::Vector3d noise = Random::v_noise_g( brownian.rng_counter->value(), p.identity()); + Utils::Vector3d velocity = {}; for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - // Random (heat) velocity is added here. It is already initialized in the - // terminal drag part. See eq. (10.2.16) taking into account eq. (10.2.18) - // and (10.2.29), Pottier2010. Note, that the Pottier2010 units system - // (see Eq. (10.1.1) there) has been adapted towards the ESPResSo and the - // referenced above Schlick2010 one, which is defined by the eq. (14.31) - // of Schlick2010. A difference is the mass factor to the friction tensor. - // The noise is Gaussian according to the convention at p. 237 (last - // paragraph), Pottier2010. - p.m.v[j] += sigma_vel * noise[j] / sqrt(p.p.mass); + // Random (heat) velocity. See eq. (10.2.16) taking into account eq. + // (10.2.18) and (10.2.29), Pottier2010. Note, that the Pottier2010 units + // system (see Eq. (10.1.1) there) has been adapted towards the ESPResSo + // and the referenced above Schlick2010 one, which is defined by the eq. + // (14.31) of Schlick2010. A difference is the mass factor to the friction + // tensor. The noise is Gaussian according to the convention at p. 237 + // (last paragraph), Pottier2010. + velocity[j] += sigma_vel * noise[j] / sqrt(p.p.mass); } } + return velocity; } #ifdef ROTATION -/** Propagate quaternions: viscous drag driven by conservative torques. +/** Determine quaternions: viscous drag driven by conservative torques. * An analogy of eq. (14.39) in @cite Schlick2010. * @param[in] brownian_gamma_rotation Brownian rotational gamma - * @param[in,out] p %Particle + * @param[in] p %Particle * @param[in] dt Time interval */ -void bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, - Particle &p, double dt) { +inline Utils::Vector4d +bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, Particle &p, + double dt) { Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE @@ -364,7 +332,7 @@ void bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, gamma = brownian_gamma_rotation; } - Utils::Vector3d dphi = {0.0, 0.0, 0.0}; + Utils::Vector3d dphi = {}; for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES if (!(p.p.ext_flag & COORD_FIXED(j))) @@ -377,23 +345,25 @@ void bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, dphi[j] = p.f.torque[j] * dt / gamma[j]; #endif // ROTATIONAL_INERTIA } - } // j + } dphi = mask(p.p.rotation, dphi); double dphi_m = dphi.norm(); if (dphi_m) { Utils::Vector3d dphi_u; dphi_u = dphi / dphi_m; - local_rotate_particle_body(p, dphi_u, dphi_m); + return local_rotate_particle_body(p, dphi_u, dphi_m); } + return {}; } /** Set the terminal angular velocity driven by the conservative torques drag. * An analogy of the 1st term of eq. (14.34) in @cite Schlick2010. * @param[in] brownian_gamma_rotation Brownian rotational gamma - * @param[in,out] p %Particle + * @param[in] p %Particle */ -void bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation, - Particle &p) { +inline Utils::Vector3d +bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation, + Particle const &p) { Thermostat::GammaType gamma; #ifdef BROWNIAN_PER_PARTICLE @@ -405,34 +375,31 @@ void bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation, gamma = brownian_gamma_rotation; } + Utils::Vector3d omega = {}; for (int j = 0; j < 3; j++) { #ifdef EXTERNAL_FORCES - if (p.p.ext_flag & COORD_FIXED(j)) { - p.m.omega[j] = 0.0; - } else + if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { // only conservative part of the force is used here - // NOTE: velocity is assigned here and propagated by thermal part further - // on top of it #ifndef PARTICLE_ANISOTROPY - p.m.omega[j] = p.f.torque[j] / gamma; + omega[j] = p.f.torque[j] / gamma; #else - p.m.omega[j] = p.f.torque[j] / gamma[j]; + omega[j] = p.f.torque[j] / gamma[j]; #endif // ROTATIONAL_INERTIA } } - p.m.omega = mask(p.p.rotation, p.m.omega); + return mask(p.p.rotation, omega); } -/** Propagate the quaternions: random walk part. +/** Determine the quaternions: random walk part. * An analogy of eq. (14.37) in @cite Schlick2010. * @param[in] brownian Parameters - * @param[in,out] p %Particle + * @param[in] p %Particle * @param[in] dt Time interval */ -void bd_random_walk_rot(BrownianThermostat const &brownian, Particle &p, - double dt) { +inline Utils::Vector4d bd_random_walk_rot(BrownianThermostat const &brownian, + Particle const &p, double dt) { // first, set defaults Thermostat::GammaType sigma_pos = brownian.sigma_pos_rotation; @@ -471,7 +438,7 @@ void bd_random_walk_rot(BrownianThermostat const &brownian, Particle &p, } #endif // BROWNIAN_PER_PARTICLE - Utils::Vector3d dphi = {0.0, 0.0, 0.0}; + Utils::Vector3d dphi = {}; Utils::Vector3d noise = Random::v_noise_g( brownian.rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { @@ -482,34 +449,32 @@ void bd_random_walk_rot(BrownianThermostat const &brownian, Particle &p, #ifndef PARTICLE_ANISOTROPY if (sigma_pos > 0.0) { dphi[j] = noise[j] * sigma_pos * sqrt(dt); - } else { - dphi[j] = 0.0; } #else if (sigma_pos[j] > 0.0) { dphi[j] = noise[j] * sigma_pos[j] * sqrt(dt); - } else { - dphi[j] = 0.0; } #endif // ROTATIONAL_INERTIA } } dphi = mask(p.p.rotation, dphi); - // making the algorithm to be independ on an order of the rotations + // making the algorithm independent of the order of the rotations double dphi_m = dphi.norm(); if (dphi_m) { Utils::Vector3d dphi_u; dphi_u = dphi / dphi_m; - local_rotate_particle_body(p, dphi_u, dphi_m); + return local_rotate_particle_body(p, dphi_u, dphi_m); } + return {}; } /** Determine the angular velocities: random walk part. * An analogy of eq. (10.2.16) in @cite Pottier2010. * @param[in] brownian Parameters - * @param[in,out] p %Particle + * @param[in] p %Particle */ -void bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle &p) { +inline Utils::Vector3d +bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle const &p) { double sigma_vel; // Override defaults if per-particle values for T and gamma are given @@ -525,7 +490,7 @@ void bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle &p) { sigma_vel = brownian.sigma_vel_rotation; #endif // BROWNIAN_PER_PARTICLE - Utils::Vector3d domega; + Utils::Vector3d domega{}; Utils::Vector3d noise = Random::v_noise_g( brownian.rng_counter->value(), p.p.identity); for (int j = 0; j < 3; j++) { @@ -533,13 +498,10 @@ void bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle &p) { if (!(p.p.ext_flag & COORD_FIXED(j))) #endif { - // velocity is added here. It is already initialized in the terminal drag - // part. domega[j] = sigma_vel * noise[j] / sqrt(p.p.rinertia[j]); } } - domega = mask(p.p.rotation, domega); - p.m.omega += domega; + return mask(p.p.rotation, domega); } #endif // ROTATION @@ -552,10 +514,10 @@ inline void brownian_dynamics_propagator(BrownianThermostat const &brownian, if (!(p.p.is_virtual) or thermo_virtual) #endif { - bd_drag(brownian.gamma, p, time_step); - bd_drag_vel(brownian.gamma, p); - bd_random_walk(brownian, p, time_step); - bd_random_walk_vel(brownian, p); + p.r.p += bd_drag(brownian.gamma, p, time_step); + p.m.v = bd_drag_vel(brownian.gamma, p); + p.r.p += bd_random_walk(brownian, p, time_step); + p.m.v += bd_random_walk_vel(brownian, p); /* Verlet criterion check */ if ((p.r.p - p.l.p_old).norm2() > Utils::sqr(0.5 * skin)) set_resort_particles(Cells::RESORT_LOCAL); @@ -564,10 +526,10 @@ inline void brownian_dynamics_propagator(BrownianThermostat const &brownian, if (!p.p.rotation) continue; convert_torque_to_body_frame_apply_fix(p); - bd_drag_rot(brownian.gamma_rotation, p, time_step); - bd_drag_vel_rot(brownian.gamma_rotation, p); - bd_random_walk_rot(brownian, p, time_step); - bd_random_walk_vel_rot(brownian, p); + p.r.quat = bd_drag_rot(brownian.gamma_rotation, p, time_step); + p.m.omega = bd_drag_vel_rot(brownian.gamma_rotation, p); + p.r.quat = bd_random_walk_rot(brownian, p, time_step); + p.m.omega += bd_random_walk_vel_rot(brownian, p); #endif // ROTATION } sim_time += time_step; diff --git a/src/core/integrators/langevin_inline.hpp b/src/core/integrators/langevin_inline.hpp index 729a8641e29..9b5b52d2d13 100644 --- a/src/core/integrators/langevin_inline.hpp +++ b/src/core/integrators/langevin_inline.hpp @@ -35,7 +35,7 @@ * Collects the langevin parameters kT, gamma (different for * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. * @param[in] langevin Parameters - * @param[in,out] p %Particle + * @param[in] p %Particle */ inline Utils::Vector3d friction_thermo_langevin(LangevinThermostat const &langevin, @@ -96,11 +96,11 @@ friction_thermo_langevin(LangevinThermostat const &langevin, * Collects the langevin parameters kT, gamma_rot (different for * LANGEVIN_PER_PARTICLE). Applies the noise and friction term. * @param[in] langevin Parameters - * @param[in,out] p %Particle + * @param[in] p %Particle */ inline Utils::Vector3d friction_thermo_langevin_rotation(LangevinThermostat const &langevin, - const Particle &p) { + Particle const &p) { auto pref_friction = -langevin.gamma_rotation; auto pref_noise = langevin.pref_noise_rotation; diff --git a/src/core/rotation.hpp b/src/core/rotation.hpp index 4018dcfb72d..191269560ae 100644 --- a/src/core/rotation.hpp +++ b/src/core/rotation.hpp @@ -93,16 +93,17 @@ convert_dip_to_quat(const Utils::Vector3d &dip) { #endif /** Rotate the particle p around the body-frame defined NORMALIZED axis - * aBodyFrame by amount phi + * @p aBodyFrame by amount @p phi. */ -inline void local_rotate_particle_body(Particle &p, - const Utils::Vector3d &axis_body_frame, - const double phi) { +inline Utils::Vector4d +local_rotate_particle_body(Particle const &p, + const Utils::Vector3d &axis_body_frame, + const double phi) { auto axis = axis_body_frame; // Rotation turned off entirely? if (!p.p.rotation) - return; + return {}; // Convert rotation axis to body-fixed frame axis = mask(p.p.rotation, axis).normalize(); @@ -112,8 +113,7 @@ inline void local_rotate_particle_body(Particle &p, Utils::Vector4d{cos(phi / 2), s * axis[0], s * axis[1], s * axis[2]} .normalize(); - // Rotate the particle - p.r.quat = Utils::multiply_quaternions(p.r.quat, q); + return Utils::multiply_quaternions(p.r.quat, q); } /** Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi @@ -123,7 +123,7 @@ inline void local_rotate_particle(Particle &p, const double phi) { // Convert rotation axis to body-fixed frame Utils::Vector3d axis = convert_vector_space_to_body(p, axis_space_frame); - local_rotate_particle_body(p, axis, phi); + p.r.quat = local_rotate_particle_body(p, axis, phi); } inline void convert_torque_to_body_frame_apply_fix(Particle &p) { diff --git a/src/core/unit_tests/thermostats_test.cpp b/src/core/unit_tests/thermostats_test.cpp index 9f21314a1ac..d66206dc290 100644 --- a/src/core/unit_tests/thermostats_test.cpp +++ b/src/core/unit_tests/thermostats_test.cpp @@ -75,46 +75,46 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { /* check translation */ { - auto p = particle_factory(); + auto const p = particle_factory(); auto const ref = time_step * dispersion; - bd_drag(brownian.gamma, p, time_step); - BOOST_CHECK_CLOSE(p.r.p[0], ref[0], tol); - BOOST_CHECK_CLOSE(p.r.p[1], ref[1], tol); - BOOST_CHECK_CLOSE(p.r.p[2], ref[2], tol); + auto const out = bd_drag(brownian.gamma, p, time_step); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); } /* check translational velocity */ { - auto p = particle_factory(); + auto const p = particle_factory(); auto const ref = dispersion; - bd_drag_vel(brownian.gamma, p); - BOOST_CHECK_CLOSE(p.m.v[0], ref[0], tol); - BOOST_CHECK_CLOSE(p.m.v[1], ref[1], tol); - BOOST_CHECK_CLOSE(p.m.v[2], ref[2], tol); + auto const out = bd_drag_vel(brownian.gamma, p); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); } /* check walk translation */ { - auto p = particle_factory(); + auto const p = particle_factory(); auto const sigma = sqrt(brownian.gamma / (2.0 * temperature)); auto const noise = Random::v_noise_g(0, 0); auto const ref = hadamard_division(noise, sigma) * sqrt(time_step); - bd_random_walk(brownian, p, time_step); - BOOST_CHECK_CLOSE(p.r.p[0], ref[0], tol); - BOOST_CHECK_CLOSE(p.r.p[1], ref[1], tol); - BOOST_CHECK_CLOSE(p.r.p[2], ref[2], tol); + auto const out = bd_random_walk(brownian, p, time_step); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); } /* check walk translational velocity */ { - auto p = particle_factory(); + auto const p = particle_factory(); auto const sigma = sqrt(temperature); auto const noise = Random::v_noise_g(0, 0); auto const ref = sigma * noise / sqrt(p.p.mass); - bd_random_walk_vel(brownian, p); - BOOST_CHECK_CLOSE(p.m.v[0], ref[0], tol); - BOOST_CHECK_CLOSE(p.m.v[1], ref[1], tol); - BOOST_CHECK_CLOSE(p.m.v[2], ref[2], tol); + auto const out = bd_random_walk_vel(brownian, p); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); } #ifdef ROTATION @@ -126,11 +126,11 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto p = particle_factory(); p.p.rotation = ROTATION_X; auto const phi = time_step * dispersion_rotation[0]; - bd_drag_rot(brownian.gamma_rotation, p, time_step); - BOOST_CHECK_CLOSE(p.r.quat[0], std::cos(phi / 2), tol); - BOOST_CHECK_CLOSE(p.r.quat[1], std::sin(phi / 2), tol); - BOOST_CHECK_CLOSE(p.r.quat[2], 0, tol); - BOOST_CHECK_CLOSE(p.r.quat[3], 0, tol); + auto const out = bd_drag_rot(brownian.gamma_rotation, p, time_step); + BOOST_CHECK_CLOSE(out[0], std::cos(phi / 2), tol); + BOOST_CHECK_CLOSE(out[1], std::sin(phi / 2), tol); + BOOST_CHECK_CLOSE(out[2], 0.0, tol); + BOOST_CHECK_CLOSE(out[3], 0.0, tol); } /* check rotational velocity */ @@ -138,10 +138,10 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto p = particle_factory(); p.p.rotation = ROTATION_X | ROTATION_Y | ROTATION_Z; auto const ref = dispersion_rotation; - bd_drag_vel_rot(brownian.gamma_rotation, p); - BOOST_CHECK_CLOSE(p.m.omega[0], ref[0], tol); - BOOST_CHECK_CLOSE(p.m.omega[1], ref[1], tol); - BOOST_CHECK_CLOSE(p.m.omega[2], ref[2], tol); + auto const out = bd_drag_vel_rot(brownian.gamma_rotation, p); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); } /* check walk rotation */ @@ -151,11 +151,11 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto const sigma = sqrt(brownian.gamma_rotation / (2.0 * temperature)); auto const noise = Random::v_noise_g(0, 0); auto const phi = hadamard_division(noise, sigma)[0] * sqrt(time_step); - bd_random_walk_rot(brownian, p, time_step); - BOOST_CHECK_CLOSE(p.r.quat[0], std::cos(phi / 2), tol); - BOOST_CHECK_CLOSE(p.r.quat[1], std::sin(phi / 2), tol); - BOOST_CHECK_CLOSE(p.r.quat[2], 0, tol); - BOOST_CHECK_CLOSE(p.r.quat[3], 0, tol); + auto const out = bd_random_walk_rot(brownian, p, time_step); + BOOST_CHECK_CLOSE(out[0], std::cos(phi / 2), tol); + BOOST_CHECK_CLOSE(out[1], std::sin(phi / 2), tol); + BOOST_CHECK_CLOSE(out[2], 0.0, tol); + BOOST_CHECK_CLOSE(out[3], 0.0, tol); } /* check walk rotational velocity */ @@ -165,10 +165,10 @@ BOOST_AUTO_TEST_CASE(test_brownian_dynamics) { auto const sigma = sqrt(temperature); auto const noise = Random::v_noise_g(0, 0); auto const ref = sigma * noise; - bd_random_walk_vel_rot(brownian, p); - BOOST_CHECK_CLOSE(p.m.omega[0], ref[0], tol); - BOOST_CHECK_CLOSE(p.m.omega[1], ref[1], tol); - BOOST_CHECK_CLOSE(p.m.omega[2], ref[2], tol); + auto const out = bd_random_walk_vel_rot(brownian, p); + BOOST_CHECK_CLOSE(out[0], ref[0], tol); + BOOST_CHECK_CLOSE(out[1], ref[1], tol); + BOOST_CHECK_CLOSE(out[2], ref[2], tol); } #endif // ROTATION } From 484a0080c510455e9e52303f85735b46fac987e1 Mon Sep 17 00:00:00 2001 From: Florian Weik Date: Tue, 17 Dec 2019 16:34:51 +0100 Subject: [PATCH 136/150] utils: find_if + test --- src/utils/include/utils/tuple.hpp | 51 +++++++++++++++++++++++++++++++ src/utils/tests/tuple_test.cpp | 16 ++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/utils/include/utils/tuple.hpp b/src/utils/include/utils/tuple.hpp index aa093b5abc7..457281c627d 100644 --- a/src/utils/include/utils/tuple.hpp +++ b/src/utils/include/utils/tuple.hpp @@ -19,6 +19,9 @@ #ifndef ESPRESSO_TUPLE_HPP #define ESPRESSO_TUPLE_HPP +#include +#include + /** * @file * Algorithms for tuple-like inhomogeneous containers. @@ -73,6 +76,54 @@ template void for_each(F &&f, Tuple &&t) { std::make_index_sequence< std::tuple_size>::value>{}); } + +namespace detail { +template struct find_if_impl { + template + static constexpr bool eval(Pred &&pred, Tuple const &t, F &&f) { + using Utils::get; + auto const &e = get(t); + + if (pred(e)) { + f(e); + return true; + } + + return find_if_impl::eval(std::forward(pred), t, + std::forward(f)); + } +}; + +template struct find_if_impl { + template + static constexpr bool eval(Pred, Tuple, F) { + return false; + } +}; +} // namespace detail + +/** + * @brief Find first element in tuple for which a predicate holds, + * and call a Callable with the element. + * + * Any return value of the Callable is ignored. + * + * @tparam Pred Must be callable with all type occurring as elements + * in Tuple, returning a value convertible to bool. + * @tparam Tuple a tuple-like type supporting Utils::get + * @tparam F Must be callable with all type occurring as elements + * in Tuple. + * @param pred The predicate. + * @param t Tuple for search in. + * @param f Is called for first found element. + * @return Result of invocation of f if an element was found, + * nothing otherwise. + */ +template +constexpr auto find_if(Pred &&pred, Tuple const &t, F &&f) { + return detail::find_if_impl<0, Utils::tuple_size::value>::eval( + std::forward(pred), t, std::forward(f)); +} } // namespace Utils #endif // ESPRESSO_TUPLE_HPP diff --git a/src/utils/tests/tuple_test.cpp b/src/utils/tests/tuple_test.cpp index dfcb59076f2..06c80d7d9d0 100644 --- a/src/utils/tests/tuple_test.cpp +++ b/src/utils/tests/tuple_test.cpp @@ -107,3 +107,19 @@ BOOST_AUTO_TEST_CASE(apply) { BOOST_CHECK(called); } } + +BOOST_AUTO_TEST_CASE(find_if_) { + { + auto const result = Utils::find_if([](int e) { return e == 2; }, + std::array{1, 2, 3, 4}, + [](int e) { BOOST_CHECK_EQUAL(e, 2); }); + BOOST_CHECK(result); + } + + { + auto const result = Utils::find_if([](int e) { return e == 5; }, + std::array{1, 2, 3, 4}, + [](int e) { BOOST_CHECK(false); }); + BOOST_CHECK(not result); + } +} \ No newline at end of file From c039dc7184306c6232fef0639eb7c8b41fa80580 Mon Sep 17 00:00:00 2001 From: Florian Weik Date: Tue, 28 Jan 2020 14:26:49 +0100 Subject: [PATCH 137/150] utils: filter + test --- src/utils/include/utils/tuple.hpp | 54 +++++++++++++++++++++++++++++++ src/utils/tests/tuple_test.cpp | 10 ++++++ 2 files changed, 64 insertions(+) diff --git a/src/utils/include/utils/tuple.hpp b/src/utils/include/utils/tuple.hpp index 457281c627d..04f7fe18a36 100644 --- a/src/utils/include/utils/tuple.hpp +++ b/src/utils/include/utils/tuple.hpp @@ -124,6 +124,60 @@ constexpr auto find_if(Pred &&pred, Tuple const &t, F &&f) { return detail::find_if_impl<0, Utils::tuple_size::value>::eval( std::forward(pred), t, std::forward(f)); } + +namespace detail { +template