Skip to content

Commit

Permalink
Remove more globals (#3738)
Browse files Browse the repository at this point in the history
Partial fix for #2628
  • Loading branch information
kodiakhq[bot] authored May 27, 2020
2 parents 1faa7c0 + 4b4e774 commit e39a7ae
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 37 deletions.
38 changes: 14 additions & 24 deletions src/core/reaction_ensemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,19 +423,18 @@ void WangLandauReactionEnsemble::on_end_reaction(int &accepted_state) {
* randomly in the box. Matching particles simply change the types. If there
* are more reactants than products, old reactant particles are deleted.
*/
bool ReactionAlgorithm::generic_oneway_reaction(int reaction_id) {
void ReactionAlgorithm::generic_oneway_reaction(int reaction_id) {

SingleReaction &current_reaction = reactions[reaction_id];
current_reaction.tried_moves += 1;
bool reaction_is_accepted = false;
particle_inside_exclusion_radius_touched = false;
int old_state_index = -1; // for Wang-Landau algorithm
on_reaction_entry(old_state_index);
if (!all_reactant_particles_exist(reaction_id)) {
// makes sure, no incomplete reaction is performed -> only need to consider
// rollback of complete reactions
on_reaction_rejection_directly_after_entry(old_state_index);
return reaction_is_accepted;
return;
}

// calculate potential energy
Expand Down Expand Up @@ -510,7 +509,6 @@ bool ReactionAlgorithm::generic_oneway_reaction(int reaction_id) {
delete_particle(to_be_deleted_hidden_ids[i]); // delete particle
}
current_reaction.accepted_moves += 1;
reaction_is_accepted = true;
} else {
// reject
accepted_state = old_state_index;
Expand All @@ -524,10 +522,8 @@ bool ReactionAlgorithm::generic_oneway_reaction(int reaction_id) {
// 3) restore previously changed reactant particles
restore_properties(changed_particles_properties,
number_of_saved_properties);
reaction_is_accepted = false;
}
on_end_reaction(accepted_state);
return reaction_is_accepted;
}

/**
Expand Down Expand Up @@ -759,7 +755,6 @@ int WangLandauReactionEnsemble::on_mc_use_WL_get_new_state() {
bool ReactionAlgorithm::do_global_mc_move_for_particles_of_type(
int type, int particle_number_of_type_to_be_changed, bool use_wang_landau) {
m_tried_configurational_MC_moves += 1;
bool got_accepted = false;
particle_inside_exclusion_radius_touched = false;

int old_state_index = -1;
Expand All @@ -774,7 +769,7 @@ bool ReactionAlgorithm::do_global_mc_move_for_particles_of_type(
if (use_wang_landau) {
on_mc_rejection_directly_after_entry(old_state_index);
}
return got_accepted;
return false;
}

const double E_pot_old = calculate_current_potential_energy_of_system();
Expand Down Expand Up @@ -866,21 +861,20 @@ bool ReactionAlgorithm::do_global_mc_move_for_particles_of_type(
if (m_uniform_real_distribution(m_generator) < bf) {
// accept
m_accepted_configurational_MC_moves += 1;
got_accepted = true;
if (use_wang_landau) {
on_mc_accept(new_state_index);
}
} else {
// reject
// modify wang_landau histogram and potential
if (use_wang_landau) {
on_mc_reject(old_state_index);
}
// create particles again at the positions they were
for (int i = 0; i < particle_number_of_type_to_be_changed; i++)
place_particle(p_id_s_changed_particles[i], &particle_positions[3 * i]);
return true;
}
return got_accepted;
// reject
// modify wang_landau histogram and potential
if (use_wang_landau) {
on_mc_reject(old_state_index);
}
// create particles again at the positions they were
for (int i = 0; i < particle_number_of_type_to_be_changed; i++)
place_particle(p_id_s_changed_particles[i], &particle_positions[3 * i]);
return false;
}

///////////////////////////////////////////// Wang-Landau algorithm
Expand Down Expand Up @@ -1246,13 +1240,9 @@ double WangLandauReactionEnsemble::calculate_acceptance_probability(
*/
int WangLandauReactionEnsemble::do_reaction(int reaction_steps) {
m_WL_tries += reaction_steps;
bool got_accepted = false;
for (int step = 0; step < reaction_steps; step++) {
int reaction_id = i_random(reactions.size());
got_accepted = generic_oneway_reaction(reaction_id);
if (got_accepted) {
m_WL_accepted_moves += 1;
}
generic_oneway_reaction(reaction_id);
if (can_refine_wang_landau_one_over_t() && m_WL_tries % 10000 == 0) {
// check for convergence
if (achieved_desired_number_of_refinements_one_over_t()) {
Expand Down
8 changes: 1 addition & 7 deletions src/core/reaction_ensemble.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ReactionAlgorithm {

protected:
std::vector<int> m_empty_p_ids_smaller_than_max_seen_particle;
bool generic_oneway_reaction(int reaction_id);
void generic_oneway_reaction(int reaction_id);
virtual void on_reaction_entry(int &old_state_index) {}
virtual void
on_reaction_rejection_directly_after_entry(int &old_state_index) {}
Expand Down Expand Up @@ -209,10 +209,6 @@ class ReactionAlgorithm {
std::vector<int> &reactant_coefficients,
std::vector<int> &product_coefficients); // should only be used when
// defining a new reaction
int m_invalid_charge =
-10000; // this is the default charge which is assigned to a type which
// occurs in a reaction. this charge has to be overwritten. if it
// is not overwritten the reaction ensemble will complain.
void replace_particle(int p_id, int desired_type);
int create_particle(int desired_type);
void hide_particle(int p_id, int previous_type);
Expand Down Expand Up @@ -319,7 +315,6 @@ class WangLandauReactionEnsemble : public ReactionAlgorithm {
double wang_landau_parameter = 1.0; // equals the logarithm to basis e of the
// modification factor of the degeneracy of
// states when the state is visited
double initial_wang_landau_parameter = 1.0;

int int_fill_value = -10;
double double_fill_value = -10.0;
Expand All @@ -341,7 +336,6 @@ class WangLandauReactionEnsemble : public ReactionAlgorithm {

void update_wang_landau_potential_and_histogram(
int index_of_state_after_acceptance_or_rejection);
int m_WL_accepted_moves = 0;
int m_WL_tries = 0;
bool can_refine_wang_landau_one_over_t();
bool m_system_is_in_1_over_t_regime = false;
Expand Down
2 changes: 1 addition & 1 deletion src/python/espressomd/cellsystem.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
from .grid cimport node_grid
from . cimport integrate
from .globals cimport FIELD_SKIN, FIELD_NODEGRID, FIELD_MAXNUMCELLS, FIELD_MINNUMCELLS
from .globals cimport FIELD_SKIN, FIELD_NODEGRID
from .globals cimport verlet_reuse, skin
from .globals cimport mpi_bcast_parameter
from .cellsystem cimport dd, cell_structure
Expand Down
2 changes: 0 additions & 2 deletions src/python/espressomd/globals.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ cdef extern from "global.hpp":
int FIELD_BOXL
int FIELD_SKIN
int FIELD_NODEGRID
int FIELD_MAXNUMCELLS
int FIELD_MINNUMCELLS
int FIELD_NPTISO_PISTON
int FIELD_NPTISO_PDIFF
int FIELD_PERIODIC
Expand Down
3 changes: 0 additions & 3 deletions src/python/espressomd/reaction_ensemble.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ cdef extern from "reaction_ensemble.hpp" namespace "ReactionEnsemble":
void delete_reaction(int reaction_id)

vector[SingleReaction] reactions
int nr_different_types
map[int, double] charges_of_types
double temperature
double exclusion_radius
Expand All @@ -65,8 +64,6 @@ cdef extern from "reaction_ensemble.hpp" namespace "ReactionEnsemble":
cdef cppclass CWangLandauReactionEnsemble "ReactionEnsemble::WangLandauReactionEnsemble"(CReactionAlgorithm):
CWangLandauReactionEnsemble(int seed)
double wang_landau_parameter
double initial_wang_landau_parameter
int number_of_monte_carlo_moves_between_check_of_convergence
double final_wang_landau_parameter
string output_filename
vector[double] minimum_energies_at_flat_index
Expand Down

0 comments on commit e39a7ae

Please sign in to comment.