Skip to content

Commit

Permalink
fix linCmt() parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Dec 1, 2024
1 parent 8e7134e commit dd7722b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/genModelVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static inline SEXP sortStateVectors(SEXP ordS) {
int cur = tb.didx[i];
int prop = tb.dprop[i];
int pass = 0;
if (tb.linCmt){
if (tb.linCmt) {
if (tb.hasDepotCmt == 1 && !strcmp("depot", tb.ss.line[tb.di[i]])){
pass = 1;
} else if ((tb.hasCentralCmt == 1 || tb.hasDepotCmt == 1) &&
Expand Down
34 changes: 19 additions & 15 deletions src/parseFunsDosing.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,25 @@ static inline int handleFunctionTadSingleStateCcode(transFunctions *tf,char *v2)
sAppend(&sb, "_%s1(", tf->v);
sAppend(&sbDt, "_%s1(", tf->v);
if (new_de(v2, 0)){
// cannot be lhs statements in tad style assignments
// also cannot be from anywhere
// temporarily turn off that this is a function
// This is not a function
int fn = tb.fn;
tb.fn = 0;
// this is NOT an assignment
nodeInfo ni2;
niReset(&ni2);
char *name = tf->v;
ni2.assignment = 0;
ni2.ini = 0;
add_de(ni2, name, v2, 0, 0);
// turn back on that this is a function
tb.fn = fn;
if (!strcmp("depot", v2)) {
tb.hasDepot = 1;
aAppendN("_DEPOT_)", 8);
return 1;
} else if (!strcmp("central", v2)) {
tb.hasCentral = 1;
aAppendN("_CENTRAL_)", 10);
return 1;
} else {
// cannot be lhs statements in tad style assignments
// also cannot be from anywhere
// temporarily turn off that this is a function
// This is not a function
int fn = tb.fn;
tb.fn = 0;
add_de(tf->ni, tf->name, v2, 0, 0);
// turn back on that this is a function
tb.fn = fn;
}
} else {
new_or_ith(v2);
}
Expand Down
28 changes: 26 additions & 2 deletions tests/testthat/test-tad.R
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,33 @@ rxTest({
})
}

mod2 <- mod2()
expect_error(mod2())

mod2$simulationModel
mod2 <- function() {
ini({
## Table 3 from Savic 2007
cl <- 17.2 # (L/hr)
vc <- 45.1 # L
ka <- 0.38 # 1/hr
mtt <- 1.37 # hr
f2 <-0.5 # Fraction of 1st Order portion
n <- 20.1
})
model({
k <- cl/vc
bio <- 1-f2
ktr = (n+1)/mtt
## note that lgammafn is the same as lgamma in R.
d/dt(depot1) = exp(log(bio*podo(depot1))+
log(ktr)+n*log(ktr*tad(depot1))-
ktr*tad(depot1)-lgammafn(n+1))-ka*depot1
d/dt(depot2) <- -ka*depot2
f(depot2) <-f2
d/dt(cen) <- ka*depot1 + ka*depot2-k*cen
})
}

mod2 <- mod2()

})
})

0 comments on commit dd7722b

Please sign in to comment.