Changeset 80bf6e
- Timestamp:
- Nov 1, 2022, 10:35:20 PM (3 years ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- fb08cc
- Parents:
- 78e5cf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/PotentialAction/GeneratePotentialsAction.cpp
r78e5cf r80bf6e 44 44 45 45 #include <boost/foreach.hpp> 46 #include <boost/iterator/counting_iterator.hpp> 46 47 47 48 #include "Actions/PotentialAction/GeneratePotentialsAction.hpp" … … 61 62 #include "Action_impl_pre.hpp" 62 63 /** =========== define the function ====================== */ 63 64 64 ActionState::ptr PotentialGeneratePotentialsAction::performCall() 65 65 { … … 124 124 125 125 /** 126 * We have num_particles places and fragmentnumbers.size() elements to place. 127 * We use a "selection" array and pick every possible selection from the 128 * fragmentnumbers array, kudos to https://stackoverflow.com/a/9430993 126 * 2. create all unique combinations for the given elements and the number of particles 127 * 128 * Use the {1,...,fragmentnumbers.size()}, create every permutation and pick the first num_particle 129 * from the given charges. Finally, put all those into a set to retain only unique combinations. 129 130 */ 130 131 /// 2. create all combinations for the given elements and the number of particles 132 std::vector<bool> selection(fragmentnumbers.size()); 133 std::fill(selection.begin(), selection.begin() + num_particles, true); 131 std::set<SerializablePotential::ParticleTypes_t> charges_for_potentials; 132 std::vector<size_t> selection(boost::counting_iterator<int>(0), boost::counting_iterator<int>(fragmentnumbers.size())); 134 133 do { 135 134 charges.clear(); 136 for (unsigned int i = 0; i < fragmentnumbers.size(); ++i) { 137 if (selection[i]) { 138 charges.push_back(fragmentnumbers[i]); 139 } 140 } 135 for (unsigned int i = 0; i < num_particles; ++i) { 136 charges.push_back(fragmentnumbers[selection[i]]); 137 } 138 // LOG(3, "DEBUG: Inserting charges " << charges); 139 charges_for_potentials.insert(charges); 140 } while (std::next_permutation(selection.begin(), selection.end())); 141 142 143 for (std::set<SerializablePotential::ParticleTypes_t>::const_iterator iter = charges_for_potentials.begin(); 144 iter != charges_for_potentials.end(); ++iter) { 141 145 /// 3. create the potential 142 EmpiricalPotential* potential = factory.createInstance(potential_name, charges);146 EmpiricalPotential* potential = factory.createInstance(potential_name, *iter); 143 147 144 148 /// 4. Gather all created potential's binding model in a set … … 157 161 LOG(2, "DEBUG: Discarding potential " << *potential); 158 162 delete(potential); 159 } while (std::prev_permutation(selection.begin(), selection.end()));163 } 160 164 } 161 165
Note:
See TracChangeset
for help on using the changeset viewer.
