From 836502a3578a88049c044255397f1b80c80613ce Mon Sep 17 00:00:00 2001 From: pscrozi Date: Wed, 27 Mar 2013 22:16:34 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@9716 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/MC/fix_gcmc.cpp | 96 ++++++++++----------------------------------- src/MC/fix_gcmc.h | 2 - 2 files changed, 21 insertions(+), 77 deletions(-) diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index 997c791f5a..0eb8b5fe9e 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -407,9 +407,7 @@ void FixGCMC::attempt_atomic_translation() if (ngas == 0) return; - int i; - if (regionflag) i = pick_random_gas_atom_in_region(); - else i = pick_random_gas_atom(); + int i = pick_random_gas_atom(); int success = 0; if (i >= 0) { @@ -459,9 +457,7 @@ void FixGCMC::attempt_atomic_deletion() if (ngas == 0) return; - int i; - if (regionflag) i = pick_random_gas_atom_in_region(); - else i = pick_random_gas_atom(); + int i = pick_random_gas_atom(); int success = 0; if (i >= 0) { @@ -565,9 +561,7 @@ void FixGCMC::attempt_molecule_translation() if (ngas == 0) return; - int translation_molecule; - if (regionflag) translation_molecule = pick_random_gas_molecule_in_region(); - else translation_molecule = pick_random_gas_molecule(); + int translation_molecule = pick_random_gas_molecule(); if (translation_molecule == -1) return; double energy_before_sum = molecule_energy(translation_molecule); @@ -625,9 +619,7 @@ void FixGCMC::attempt_molecule_rotation() if (ngas == 0) return; - int rotation_molecule; - if (regionflag) rotation_molecule = pick_random_gas_molecule_in_region(); - else rotation_molecule = pick_random_gas_molecule(); + int rotation_molecule = pick_random_gas_molecule(); if (rotation_molecule == -1) return; double energy_before_sum = molecule_energy(rotation_molecule); @@ -705,9 +697,7 @@ void FixGCMC::attempt_molecule_deletion() if (ngas == 0) return; - int deletion_molecule; - if (regionflag) deletion_molecule = pick_random_gas_molecule_in_region(); - else deletion_molecule = pick_random_gas_molecule(); + int deletion_molecule = pick_random_gas_molecule(); if (deletion_molecule == -1) return; double deletion_energy_sum = molecule_energy(deletion_molecule); @@ -919,34 +909,6 @@ int FixGCMC::pick_random_gas_atom() /* ---------------------------------------------------------------------- ------------------------------------------------------------------------- */ -int FixGCMC::pick_random_gas_atom_in_region() -{ - int i = -1; - int i_own_candidate = 0; - int i_own_candidate_all = 0; - int region_attempt = 0; - double **x = atom->x; - while (!i_own_candidate_all) { - int iwhichglobal = static_cast (ngas*random_equal->uniform()); - if ((iwhichglobal >= ngas_before) && - (iwhichglobal < ngas_before + ngas_local)) { - i_own_candidate = 1; - int iwhichlocal = iwhichglobal - ngas_before; - i = local_gas_list[iwhichlocal]; - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]) == 0) - i_own_candidate = 0; - } - MPI_Allreduce(&i_own_candidate,&i_own_candidate_all,1,MPI_INT,MPI_MAX,world); - region_attempt++; - if (region_attempt >= max_region_attempts) return -1; - } - - return i; -} - -/* ---------------------------------------------------------------------- -------------------------------------------------------------------------- */ - int FixGCMC::pick_random_gas_molecule() { int iwhichglobal = static_cast (ngas*random_equal->uniform()); @@ -964,34 +926,6 @@ int FixGCMC::pick_random_gas_molecule() return gas_molecule_id_all; } -/* ---------------------------------------------------------------------- -------------------------------------------------------------------------- */ - -int FixGCMC::pick_random_gas_molecule_in_region() -{ - int region_attempt = 0; - int gas_molecule_id = 0; - int gas_molecule_id_all = 0; - double **x = atom->x; - while (!gas_molecule_id_all) { - int iwhichglobal = static_cast (ngas*random_equal->uniform()); - if ((iwhichglobal >= ngas_before) && - (iwhichglobal < ngas_before + ngas_local)) { - int iwhichlocal = iwhichglobal - ngas_before; - int i = local_gas_list[iwhichlocal]; - if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]) != 0) { - gas_molecule_id = atom->molecule[i]; - } - } - gas_molecule_id_all = 0; - MPI_Allreduce(&gas_molecule_id,&gas_molecule_id_all,1,MPI_INT,MPI_MAX,world); - region_attempt++; - if (region_attempt >= max_region_attempts) return -1; - } - - return gas_molecule_id_all; -} - /* ---------------------------------------------------------------------- compute the energy of the given gas molecule in its current position sum across all procs that own atoms of the given molecule @@ -1247,10 +1181,22 @@ void FixGCMC::update_gas_atoms_list() } ngas_local = 0; - for (int i = 0; i < atom->nlocal; i++) { - if (atom->mask[i] & groupbit) { - local_gas_list[ngas_local] = i; - ngas_local++; + if (regionflag) { + for (int i = 0; i < atom->nlocal; i++) { + if (atom->mask[i] & groupbit) { + double **x = atom->x; + if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2]) == 1) { + local_gas_list[ngas_local] = i; + ngas_local++; + } + } + } + } else { + for (int i = 0; i < atom->nlocal; i++) { + if (atom->mask[i] & groupbit) { + local_gas_list[ngas_local] = i; + ngas_local++; + } } } diff --git a/src/MC/fix_gcmc.h b/src/MC/fix_gcmc.h index be1617c6a2..dc7254f392 100644 --- a/src/MC/fix_gcmc.h +++ b/src/MC/fix_gcmc.h @@ -41,9 +41,7 @@ class FixGCMC : public Fix { void attempt_molecule_insertion(); double energy(int, int, int, double *); int pick_random_gas_atom(); - int pick_random_gas_atom_in_region(); int pick_random_gas_molecule(); - int pick_random_gas_molecule_in_region(); double molecule_energy(int); void get_rotation_matrix(double, double *); void get_model_molecule();