-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from mrc-ide/mrc-5454
Simple event/root finding support
- Loading branch information
Showing
14 changed files
with
465 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ src/malaria.cpp | |
src/sir.cpp | ||
src/sirode.cpp | ||
src/walk.cpp | ||
inst/include/lostturnip.hpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: dust2 | ||
Title: Next Generation dust | ||
Version: 0.3.10 | ||
Version: 0.3.11 | ||
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), | ||
email = "[email protected]"), | ||
person("Imperial College of Science, Technology and Medicine", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
#include <vector> | ||
|
||
namespace dust2 { | ||
namespace ode { | ||
|
||
// Do we detect an event when passing through the root as we increase | ||
// (negative to positive), decrease (positive to negative) or both: | ||
enum class root_type { | ||
both, | ||
increase, | ||
decrease | ||
}; | ||
|
||
// The actual logic for the above | ||
template <typename real_type> | ||
bool is_root(const real_type a, const real_type b, const root_type& root) { | ||
switch(root) { | ||
case root_type::both: | ||
return a * b < 0; | ||
case root_type::increase: | ||
return a < 0 && b > 0; | ||
case root_type::decrease: | ||
return a > 0 && b < 0; | ||
} | ||
return false; | ||
} | ||
|
||
template <typename real_type> | ||
struct event { | ||
using test_type = std::function<real_type(const real_type, const real_type*)>; | ||
using action_type = std::function<void(const real_type, const real_type, real_type*)>; | ||
std::vector<size_t> index; | ||
root_type root = root_type::both; | ||
test_type test; | ||
action_type action; | ||
|
||
event(const std::vector<size_t>& index, test_type test, action_type action, root_type root = root_type::both) : | ||
index(index), root(root), test(test), action(action) { | ||
} | ||
|
||
event(size_t index, action_type action, root_type root = root_type::both) : | ||
event({index}, [](real_type t, const real_type* y) { return y[0]; }, action, root) { | ||
} | ||
}; | ||
|
||
template <typename real_type> | ||
using events_type = std::vector<event<real_type>>; | ||
|
||
template <typename real_type> | ||
struct event_history_element { | ||
real_type time; | ||
size_t index; | ||
real_type sign; | ||
}; | ||
|
||
template <typename real_type> | ||
using event_history = std::vector<event_history_element<real_type>>; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.