-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add $EVENT block #1230
Add $EVENT block #1230
Changes from all commits
30ed899
e6968f4
50eabb3
8e83538
ba67c9e
665def8
6ea4d71
ce6bc9c
017b67a
b8de0f2
7a29e1a
59935fb
f900793
aae568a
efbbf4e
e78c79c
da42b01
99160c9
78da749
e49ddd7
3614e1e
4dc7cad
9eeed73
9f4637d
5dc2327
1d02ff2
78341f5
3f41e40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (C) 2013 - 2023 Metrum Research Group | ||
# Copyright (C) 2013 - 2024 Metrum Research Group | ||
# | ||
# This file is part of mrgsolve. | ||
# | ||
|
@@ -17,12 +17,15 @@ | |
|
||
generate_rdefs <- function(pars, | ||
cmt, | ||
func, | ||
init_fun="", | ||
table_fun="", | ||
config_fun="", | ||
model="",omats,smats, | ||
set=list(), | ||
func = "", | ||
init_fun = "", | ||
table_fun = "", | ||
event_fun = "", | ||
config_fun = "", | ||
model = "", | ||
omats, | ||
smats, | ||
set = list(), | ||
plugin = NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just light touchup; this code is really old and probably don't need to pass all the functions separately. |
||
dbsyms = FALSE, ...) { | ||
|
||
|
@@ -91,6 +94,7 @@ generate_rdefs <- function(pars, | |
c(paste0("#define __INITFUN___ ",init_fun), | ||
paste0("#define __ODEFUN___ ",func), | ||
paste0("#define __TABLECODE___ ", table_fun), | ||
paste0("#define __EVENTFUN___ ", event_fun), | ||
paste0("#define __CONFIGFUN___ ", config_fun), | ||
paste0("#define __REGISTERFUN___ ", register_fun(model)), | ||
paste0("#define _nEQ ", ncmt), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,7 @@ param_re_find <- "\\bparam\\s+\\w+\\s*=" | |
# please-deprecate | ||
move_global <- function(x,env) { | ||
|
||
what <- intersect(c("PREAMBLE","MAIN", "ODE", "TABLE", "PRED"),names(x)) | ||
what <- intersect(c("PREAMBLE","MAIN", "ODE", "TABLE", "EVENT", "PRED"),names(x)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated this, but it's not in use any more (see comment). I'd rather get rid of it at this point, but it may or may not be in scope of this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking a quick look at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. |
||
|
||
if(length(what)==0) return(x) | ||
|
||
|
@@ -495,12 +495,17 @@ move_global2 <- function(spec, env, build) { | |
if(!is.null(table$code)) { | ||
spec$TABLE <- table$code | ||
} | ||
event <- c_vars(spec[["EVENT"]], context = "event") | ||
if(!is.null(event$code)) { | ||
spec$EVENT <- event$code | ||
} | ||
to_ns <- bind_rows( | ||
pream$vars, | ||
pred$vars, | ||
main$vars, | ||
ode$vars, | ||
table$vars | ||
table$vars, | ||
event$vars | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this is happening in the new version ( |
||
vars <- bind_rows(glob$vars, to_ns) | ||
if(any(cap <- to_ns$type=="capture")) { | ||
|
@@ -536,7 +541,7 @@ move_global2 <- function(spec, env, build) { | |
} | ||
|
||
find_cpp_dot <- function(spec, env) { | ||
to_check <- c("PREAMBLE", "MAIN", "PRED", "ODE", "TABLE", "GLOBAL") | ||
to_check <- c("PREAMBLE", "MAIN", "PRED", "ODE", "EVENT", "TABLE", "GLOBAL") | ||
x <- spec[names(spec) %in% to_check] | ||
x <- unlist(x, use.names = FALSE) | ||
# Narrow the search first; 10x speed up when searching for `pattern` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,10 +336,11 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
rd <- generate_rdefs( | ||
pars = Pars(x), | ||
cmt = Cmt(x), | ||
ode_func(x), | ||
main_func(x), | ||
table_func(x), | ||
config_func(x), | ||
func = ode_func(x), | ||
init_fun = main_func(x), | ||
table_fun = table_func(x), | ||
event_fun = event_func(x), | ||
config_fun = config_func(x), | ||
model = model(x), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added argument names for safety ... was getting called by position before. |
||
omats = omat(x), | ||
smats = smat(x), | ||
|
@@ -375,7 +376,7 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
} | ||
# autodec | ||
if("autodec" %in% names(plugin)) { | ||
auto_blocks <- c("PREAMBLE", "MAIN", "PRED", "ODE", "TABLE") | ||
auto_blocks <- c("PREAMBLE", "MAIN", "PRED", "ODE", "TABLE", "EVENT") | ||
auto_skip <- cvec_cs(ENV[["MRGSOLVE_AUTODEC_SKIP"]]) | ||
autov <- autodec_vars(spec, blocks = auto_blocks) | ||
autov <- autodec_clean( | ||
|
@@ -461,6 +462,7 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
x@shlib[["nm_import"]] <- mread.env[["nm_import"]] | ||
x@shlib[["source"]] <- file.path(build[["soloc"]],build[["compfile"]]) | ||
x@shlib[["md5"]] <- build[["md5"]] | ||
x@shlib[["call_event"]] <- "EVENT" %in% names(spec) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will pass this into the C+ simulation code to tell if we are using |
||
|
||
# build---- | ||
# In soloc directory | ||
|
@@ -536,6 +538,10 @@ mread <- function(model, project = getOption("mrgsolve.project", getwd()), | |
dbs[["ode"]], | ||
spec[["ODE"]], | ||
"__END_ode__", | ||
"\n// MODELED EVENTS:", | ||
"__BEGIN_event__", | ||
spec[["EVENT"]], | ||
"__END_event__", | ||
"\n// TABLE CODE BLOCK:", | ||
"__BEGIN_table__", | ||
dbs[["cmt"]], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,10 @@ typedef std::vector<double> dvec; | |
#define MRGSOLVE_TABLE_SIGNATURE const dvec& _A_, const dvec& _A_0_, dvec& _THETA_, const dvec& _F_, const dvec& _R_, databox& self, const dvec& _pred_, dvec& _capture_, mrgsolve::resim& simeps | ||
#define MRGSOLVE_TABLE_SIGNATURE_N 9 | ||
|
||
//! signature for <code>$EVENT</code> same as what we use for <code>$TABLE</code> | ||
#define MRGSOLVE_EVENT_SIGNATURE MRGSOLVE_TABLE_SIGNATURE | ||
#define MRGSOLVE_EVENT_SIGNATURE_N MRGSOLVE_TABLE_SIGNATURE_N | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re ordered so that EVENT is by TABLE and re-using the definition so that it's in sync.
|
||
//! signature for <code>$ODE</code> | ||
#define MRGSOLVE_ODE_SIGNATURE const double* _ODETIME_, const double* _A_, double* _DADT_, const dvec& _A_0_, const dvec& _THETA_, const bool _ss_flag_ | ||
#define MRGSOLVE_ODE_SIGNATURE_N 6 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've saved a logical value indicating of
$EVENT
is in the model; if so, tell whether or not to call.