From 7618fd36d143ef45c33dc01ae42ba4ad89aeb6ca Mon Sep 17 00:00:00 2001 From: Florian Weik Date: Tue, 25 Jul 2017 15:16:28 +0200 Subject: [PATCH 1/2] thermostat: Removed selectable noise --- src/core/thermostat.cpp | 79 ++++++++++++----------------------------- src/core/thermostat.hpp | 56 +++++++---------------------- 2 files changed, 35 insertions(+), 100 deletions(-) diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index a6767b1905d..ed7b5188bf9 100755 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -30,11 +30,6 @@ #include #include -#if (!defined(FLATNOISE) && !defined(GAUSSRANDOMCUT) && !defined(GAUSSRANDOM)) -#define FLATNOISE -#endif - - /* thermostat switch */ int thermo_switch = THERMO_OFF; /** Temperature */ @@ -117,25 +112,13 @@ void thermo_init_langevin() int j; #ifndef PARTICLE_ANISOTROPY langevin_pref1 = -langevin_gamma/time_step; -#if defined (FLATNOISE) langevin_pref2 = sqrt(24.0*temperature*langevin_gamma/time_step); -#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM) - langevin_pref2 = sqrt(2.0*temperature*langevin_gamma/time_step); -#else -#error No Noise defined -#endif // Noise #else - for ( j = 0 ; j < 3 ; j++) - { - langevin_pref1[j] = -langevin_gamma[j]/time_step; -#if defined (FLATNOISE) - langevin_pref2[j] = sqrt(24.0*temperature*langevin_gamma[j]/time_step); -#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM) - langevin_pref2[j] = sqrt(2.0*temperature*langevin_gamma[j]/time_step); -#else -#error No Noise defined -#endif // Noise - } + for (j = 0; j < 3; j++) { + langevin_pref1[j] = -langevin_gamma[j] / time_step; + langevin_pref2[j] = + sqrt(24.0 * temperature * langevin_gamma[j] / time_step); +} #endif // PARTICLE_ANISOTROPY #ifdef MULTI_TIMESTEP @@ -171,21 +154,9 @@ void thermo_init_langevin() #endif // ROTATIONAL_INERTIA #ifndef ROTATIONAL_INERTIA -#if defined (FLATNOISE) langevin_pref2_rotation = sqrt(24.0*temperature*langevin_gamma_rotation/time_step); -#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM) - langevin_pref2_rotation = sqrt(2.0*temperature*langevin_gamma_rotation/time_step); -#else -#error No Noise defined -#endif // FLATNOISE #else -#if defined (FLATNOISE) for ( j = 0 ; j < 3 ; j++) langevin_pref2_rotation[j] = sqrt(24.0*temperature*langevin_gamma_rotation[j]/time_step); -#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM) - for ( j = 0 ; j < 3 ; j++) langevin_pref2_rotation[j] = sqrt(2.0*temperature*langevin_gamma_rotation[j]/time_step); -#else -#error No Noise defined -#endif // FLATNOISE #endif // ROTATIONAL_INERTIA THERMO_TRACE(fprintf(stderr,"%d: thermo_init_langevin: langevin_gamma_rotation=%f, langevin_pref2_rotation=%f",this_node, langevin_gamma_rotation,langevin_pref2_rotation)); #endif @@ -193,32 +164,28 @@ void thermo_init_langevin() } #ifdef NPT -void thermo_init_npt_isotropic() -{ +void thermo_init_npt_isotropic() { if (nptiso.piston != 0.0) { -#if defined (FLATNOISE) - nptiso_pref1 = -nptiso_gamma0*0.5 * time_step; + nptiso_pref1 = -nptiso_gamma0 * 0.5 * time_step; #ifdef MULTI_TIMESTEP - if (smaller_time_step > 0.) - nptiso_pref2 = sqrt(12.0*temperature*nptiso_gamma0*time_step) * smaller_time_step; + if (smaller_time_step > 0.) + nptiso_pref2 = sqrt(12.0 * temperature * nptiso_gamma0 * time_step) * + smaller_time_step; else #endif - nptiso_pref2 = sqrt(12.0*temperature*nptiso_gamma0*time_step) * time_step; - nptiso_pref3 = -nptiso_gammav*(1.0/nptiso.piston)*0.5*time_step; - nptiso_pref4 = sqrt(12.0*temperature*nptiso_gammav*time_step); -#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM) - nptiso_pref1 = -nptiso_gamma0*0.5 * time_step; - nptiso_pref2 = sqrt(1.0*temperature*nptiso_gamma0*time_step) * time_step; - nptiso_pref3 = -nptiso_gammav*(1.0/nptiso.piston)*0.5*time_step; - nptiso_pref4 = sqrt(1.0*temperature*nptiso_gammav*time_step); -#else -#error No Noise defined -#endif - THERMO_TRACE(fprintf(stderr,"%d: thermo_init_npt_isotropic: nptiso_pref1=%f, nptiso_pref2=%f, nptiso_pref3=%f, nptiso_pref4=%f \n",this_node,nptiso_pref1,nptiso_pref2,nptiso_pref3,nptiso_pref4)); - } - else { - thermo_switch = ( thermo_switch ^ THERMO_NPT_ISO ); - THERMO_TRACE(fprintf(stderr,"%d: thermo_init_npt_isotropic: switched off nptiso (piston=%f; thermo_switch=%d) \n",this_node,nptiso.piston,thermo_switch)); + nptiso_pref2 = + sqrt(12.0 * temperature * nptiso_gamma0 * time_step) * time_step; + nptiso_pref3 = -nptiso_gammav * (1.0 / nptiso.piston) * 0.5 * time_step; + nptiso_pref4 = sqrt(12.0 * temperature * nptiso_gammav * time_step); + THERMO_TRACE(fprintf( + stderr, "%d: thermo_init_npt_isotropic: nptiso_pref1=%f, " + "nptiso_pref2=%f, nptiso_pref3=%f, nptiso_pref4=%f \n", + this_node, nptiso_pref1, nptiso_pref2, nptiso_pref3, nptiso_pref4)); + } else { + thermo_switch = (thermo_switch ^ THERMO_NPT_ISO); + THERMO_TRACE(fprintf(stderr, "%d: thermo_init_npt_isotropic: switched off " + "nptiso (piston=%f; thermo_switch=%d) \n", + this_node, nptiso.piston, thermo_switch)); } } #endif diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index e3b93fdcb69..6dea8063e58 100755 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -25,7 +25,7 @@ */ #include -#include "utils.hpp" +//#include "utils.hpp" #include "debug.hpp" #include "particle_data.hpp" #include "random.hpp" @@ -50,23 +50,9 @@ #define THERMO_CPU 64 /*@}*/ -// Handle switching of noise function flat vs Gaussian -#if (!defined(FLATNOISE) && !defined(GAUSSRANDOMCUT) && !defined(GAUSSRANDOM)) -#define FLATNOISE -#endif - -#if defined (FLATNOISE) - #define noise (d_random() -0.5) -#elif defined (GAUSSRANDOMCUT) - #define noise gaussian_random_cut() -#elif defined (GAUSSRANDOM) - #define noise gaussian_random() -#else - #error "No noise function defined" -#endif - - - +namespace Thermostat { + auto noise = []() { return (d_random() - 0.5); }; +} /************************************************ * exported variables @@ -213,7 +199,7 @@ inline double le_frameV(int i, double *vel, double *pos) inline double friction_therm0_nptiso(double dt_vj) { extern double nptiso_pref1, nptiso_pref2; if(thermo_switch & THERMO_NPT_ISO) - return ( nptiso_pref1*dt_vj + nptiso_pref2*noise ); + return ( nptiso_pref1*dt_vj + nptiso_pref2*Thermostat::noise() ); return 0.0; } @@ -222,7 +208,7 @@ inline double friction_therm0_nptiso(double dt_vj) { inline double friction_thermV_nptiso(double p_diff) { extern double nptiso_pref3, nptiso_pref4; if(thermo_switch & THERMO_NPT_ISO) - return ( nptiso_pref3*p_diff + nptiso_pref4*noise ); + return ( nptiso_pref3*p_diff + nptiso_pref4*Thermostat::noise() ); return 0.0; } #endif @@ -240,7 +226,6 @@ inline void friction_thermo_langevin(Particle *p) double langevin_pref1_temp[3], langevin_pref2_temp[3]; #endif - double langevin_temp_coeff; double particle_force[3] = {0.0, 0.0, 0.0}; #ifdef MULTI_TIMESTEP @@ -314,14 +299,7 @@ inline void friction_thermo_langevin(Particle *p) // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE - // If a particle-specific gamma is given -#if defined (FLATNOISE) - langevin_temp_coeff = 24.0; -#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM) - langevin_temp_coeff = 2.0; -#else -#error No Noise defined -#endif + auto const constexpr langevin_temp_coeff = 24.0; #ifndef PARTICLE_ANISOTROPY if(p->p.gamma >= 0.) @@ -410,9 +388,9 @@ inline void friction_thermo_langevin(Particle *p) #else // In case of anisotropic particle: body-fixed reference frame. Otherwise: lab-fixed reference frame. if (aniso_flag) - p->f.f[j] = langevin_pref1_temp[j]*velocity_body[j] + switch_trans*langevin_pref2_temp[j]*noise; + p->f.f[j] = langevin_pref1_temp[j]*velocity_body[j] + switch_trans*langevin_pref2_temp[j]*Thermostat::noise(); else - p->f.f[j] = langevin_pref1_temp[j]*velocity[j] + switch_trans*langevin_pref2_temp[j]*noise; + p->f.f[j] = langevin_pref1_temp[j]*velocity[j] + switch_trans*langevin_pref2_temp[j]*Thermostat::noise(); #endif } } // END LOOP OVER ALL COMPONENTS @@ -451,7 +429,6 @@ inline void friction_thermo_langevin_rotation(Particle *p) extern double langevin_pref2_rotation[3]; double langevin_pref1_temp[3], langevin_pref2_temp[3]; #endif - double langevin_temp_coeff; int j; double switch_rotate = 1.0; @@ -475,13 +452,8 @@ inline void friction_thermo_langevin_rotation(Particle *p) // Override defaults if per-particle values for T and gamma are given #ifdef LANGEVIN_PER_PARTICLE // If a particle-specific gamma is given -#if defined (FLATNOISE) - langevin_temp_coeff = 24.0; -#elif defined (GAUSSRANDOMCUT) || defined (GAUSSRANDOM) - langevin_temp_coeff = 2.0; -#else -#error No Noise defined -#endif +auto const constexpr langevin_temp_coeff = 24.0; + #ifndef ROTATIONAL_INERTIA if(p->p.gamma_rot >= 0.) { @@ -539,7 +511,7 @@ inline void friction_thermo_langevin_rotation(Particle *p) for ( j = 0 ; j < 3 ; j++) { #ifdef ROTATIONAL_INERTIA - p->f.torque[j] = -langevin_pref1_temp[j]*p->m.omega[j] + switch_rotate*langevin_pref2_temp[j]*noise; + p->f.torque[j] = -langevin_pref1_temp[j]*p->m.omega[j] + switch_rotate*langevin_pref2_temp[j]*Thermostat::noise(); #else p->f.torque[j] = -langevin_pref1_temp*p->m.omega[j] + switch_rotate*langevin_pref2_temp*noise; #endif @@ -549,9 +521,5 @@ inline void friction_thermo_langevin_rotation(Particle *p) THERMO_TRACE(fprintf(stderr,"%d: Thermo: P %d: force=(%.3e,%.3e,%.3e)\n",this_node,p->p.identity,p->f.f[0],p->f.f[1],p->f.f[2])); } - #endif // ROTATION - - -#undef noise #endif From a7297b6ba818634854b30c1a2f7e933167ae25ae Mon Sep 17 00:00:00 2001 From: Florian Weik Date: Tue, 25 Jul 2017 15:47:46 +0200 Subject: [PATCH 2/2] maintainer: Removed different noise from configs and travis --- .travis.yml | 8 -- maintainer/configs/maxset-gaussrandom.hpp | 82 -------------------- maintainer/configs/maxset-gaussrandomcut.hpp | 81 ------------------- src/core/thermostat.hpp | 7 +- 4 files changed, 4 insertions(+), 174 deletions(-) delete mode 100755 maintainer/configs/maxset-gaussrandom.hpp delete mode 100755 maintainer/configs/maxset-gaussrandomcut.hpp diff --git a/.travis.yml b/.travis.yml index 0b0eaf463dd..885a5a10e09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,14 +28,6 @@ matrix: - os: osx osx_image: xcode8 env: myconfig=maxset image=python3 - - os: linux - sudo: required - services: docker - env: myconfig=maxset-gaussrandom - - os: linux - sudo: required - services: docker - env: myconfig=maxset-gaussrandomcut - os: linux sudo: required services: docker diff --git a/maintainer/configs/maxset-gaussrandom.hpp b/maintainer/configs/maxset-gaussrandom.hpp deleted file mode 100755 index aefcc71134d..00000000000 --- a/maintainer/configs/maxset-gaussrandom.hpp +++ /dev/null @@ -1,82 +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 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 NEMD -#define NPT -#define GHMC - -#define LB -#define LB_BOUNDARIES -#define LB_ELECTROHYDRODYNAMICS - -#define ENGINE - -#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 GAUSSRANDOM - - - - diff --git a/maintainer/configs/maxset-gaussrandomcut.hpp b/maintainer/configs/maxset-gaussrandomcut.hpp deleted file mode 100755 index 6925ab33cbd..00000000000 --- a/maintainer/configs/maxset-gaussrandomcut.hpp +++ /dev/null @@ -1,81 +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 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 NEMD -#define NPT -#define GHMC - -#define LB -#define LB_BOUNDARIES -#define LB_ELECTROHYDRODYNAMICS - -#define ENGINE - -#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 GAUSSRANDOMCUT - - - diff --git a/src/core/thermostat.hpp b/src/core/thermostat.hpp index 6dea8063e58..46e811fe85e 100755 --- a/src/core/thermostat.hpp +++ b/src/core/thermostat.hpp @@ -24,8 +24,9 @@ */ +#include "config.hpp" + #include -//#include "utils.hpp" #include "debug.hpp" #include "particle_data.hpp" #include "random.hpp" @@ -384,7 +385,7 @@ inline void friction_thermo_langevin(Particle *p) { // Apply the force #ifndef PARTICLE_ANISOTROPY - p->f.f[j] = langevin_pref1_temp*velocity[j] + switch_trans*langevin_pref2_temp*noise; + p->f.f[j] = langevin_pref1_temp*velocity[j] + switch_trans*langevin_pref2_temp*Thermostat::noise(); #else // In case of anisotropic particle: body-fixed reference frame. Otherwise: lab-fixed reference frame. if (aniso_flag) @@ -513,7 +514,7 @@ auto const constexpr langevin_temp_coeff = 24.0; #ifdef ROTATIONAL_INERTIA p->f.torque[j] = -langevin_pref1_temp[j]*p->m.omega[j] + switch_rotate*langevin_pref2_temp[j]*Thermostat::noise(); #else - p->f.torque[j] = -langevin_pref1_temp*p->m.omega[j] + switch_rotate*langevin_pref2_temp*noise; + p->f.torque[j] = -langevin_pref1_temp*p->m.omega[j] + switch_rotate*langevin_pref2_temp*Thermostat::noise(); #endif }