Skip to content

Commit

Permalink
OSC_Sim Class Update
Browse files Browse the repository at this point in the history
-updated event calculation functions to use container based function
min_element to select the possible event with the fastest execution time
so that the code is more concise and potentially faster
  • Loading branch information
MikeHeiber committed May 17, 2018
1 parent ffcd4f1 commit 7552afe
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/OSC_Sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,16 +715,15 @@ void OSC_Sim::calculateExcitonEvents(Exciton* exciton_ptr){
return;
}
// Determine fastest valid event
double best_time = possible_events[0]->getExecutionTime();
Event* event_ptr_target = possible_events[0];
for (auto const& event_ptr : possible_events) {
if (event_ptr->getExecutionTime() < best_time) {
best_time = event_ptr->getExecutionTime();
event_ptr_target = event_ptr;
}
Event* event_ptr_target;
auto possible_it = min_element(possible_events.begin(), possible_events.end(), [](Event* ptr1, Event* ptr2) {
return ptr1->getExecutionTime() < ptr2->getExecutionTime();
});
if (possible_it != possible_events.end()) {
event_ptr_target = *possible_it;
}
// Check that the execution time is valid
if (best_time < getTime()) {
if (event_ptr_target->getExecutionTime() < getTime()) {
setObjectEvent(exciton_ptr, nullptr);
cout << getId() << ": Error! The fastest exciton event execution time is less than the current simulation time." << endl;
setErrorMessage(" The fastest exciton event execution time is less than the current simulation time.");
Expand Down Expand Up @@ -946,16 +945,15 @@ void OSC_Sim::calculatePolaronEvents(Polaron* polaron_ptr){
return;
}
// Determine the fastest possible event
double best_time = possible_events[0]->getExecutionTime();
Event* event_ptr_target = possible_events[0];
for (auto const &event_ptr : possible_events) {
if (event_ptr->getExecutionTime() < best_time) {
best_time = event_ptr->getExecutionTime();
event_ptr_target = event_ptr;
}
Event* event_ptr_target;
auto possible_it = min_element(possible_events.begin(), possible_events.end(), [](Event* ptr1, Event* ptr2) {
return ptr1->getExecutionTime() < ptr2->getExecutionTime();
});
if (possible_it != possible_events.end()) {
event_ptr_target = *possible_it;
}
// Check that the execution time is valid
if (best_time < getTime()) {
if (event_ptr_target->getExecutionTime() < getTime()) {
setObjectEvent(polaron_ptr, nullptr);
cout << getId() << ": Error! The fastest polaron event execution time is less than the current simulation time." << endl;
setErrorMessage(" The fastest polaron event execution time is less than the current simulation time.");
Expand Down

0 comments on commit 7552afe

Please sign in to comment.