Skip to content

Commit c7179c2

Browse files
committed
Update old deprecated mesh/spde code.
1 parent 4037afc commit c7179c2

File tree

5 files changed

+45
-68
lines changed

5 files changed

+45
-68
lines changed

rinla/R/mesh.R

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,23 +1622,34 @@ inla.mesh.1d <- function(loc,
16221622
#' Use [fmesher::fm_bary()] instead.
16231623
inla.mesh.1d.bary <- function(mesh, loc, method = c("linear", "nearest")) {
16241624
fmesher_deprecate(
1625-
"soft",
1625+
"warn",
16261626
2L,
16271627
"23.08.18",
16281628
"inla.mesh.1d.bary()",
16291629
"fmesher::fm_bary()",
16301630
details =
16311631
c(
1632-
"An `index` field his being included for backwards compatibility.",
1633-
"The canconical element from `fm_bary()` is `t`."
1632+
"From fmesher 0.2.0.9001, fmesher::fm_bary() returns a special fm_bary object.",
1633+
"inla.mesh.1d.bary returns the old format."
16341634
)
16351635
)
1636+
mesh <- fmesher::fm_as_mesh_1d(mesh)
16361637
result <- fmesher::fm_bary(
1637-
fmesher::fm_as_mesh_1d(mesh),
1638+
mesh,
16381639
loc,
16391640
method = method
16401641
)
1641-
result$index <- result$t
1642+
if (package_version(utils::packageVersion("fmesher")) <= "0.2.0.9000") {
1643+
result$index <- result$t
1644+
return(result)
1645+
}
1646+
# Convert to old format
1647+
index <- fmesher::fm_bary_simplex(mesh, result)
1648+
result <- list(
1649+
index = index,
1650+
t = index,
1651+
bary = result$bary
1652+
)
16421653
return(result)
16431654
}
16441655

@@ -1669,7 +1680,7 @@ inla.mesh.1d.A <- function(mesh, loc,
16691680
derivatives = NULL,
16701681
method = NULL) {
16711682
fmesher_deprecate(
1672-
"soft",
1683+
"warn",
16731684
2L,
16741685
"23.08.18",
16751686
"inla.mesh.1d.A()",

rinla/R/meshbuilder.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ meshbuilder.app <- function() {
17271727
)
17281728
))
17291729
}
1730-
A <- fmesher::fm_evaluator(mesh(), clicks$meshplot.loc)$proj$A
1730+
A <- fmesher::fm_basis(mesh(), clicks$meshplot.loc)
17311731
if (!(sum(A) > 0)) {
17321732
A <- NULL
17331733
}
@@ -1747,7 +1747,7 @@ meshbuilder.app <- function() {
17471747
)
17481748
))
17491749
}
1750-
A <- fmesher::fm_evaluator(fine(), clicks$meshplot.loc)$proj$A
1750+
A <- fmesher::fm_basis(fine(), clicks$meshplot.loc)
17511751
if (!(sum(A) > 0)) {
17521752
A <- NULL
17531753
}

rinla/R/spde.common.R

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -879,18 +879,12 @@ inla.spde.make.A <-
879879
} else if (inherits(mesh, "inla.spde")) {
880880
spde <- mesh
881881
mesh <- spde$mesh
882-
inla.require.inherits(spde$mesh, c("inla.mesh", "inla.mesh.1d"), "'spde$mesh'")
883882
n.spde <- spde$n.spde
884883
} else {
885-
inla.require.inherits(mesh, c("inla.mesh", "inla.mesh.1d"), "'mesh'")
886-
if (inherits(mesh, "inla.mesh.1d")) {
887-
n.spde <- mesh$m
888-
} else {
889-
n.spde <- mesh$n
890-
}
884+
n.spde <- fmesher::fm_dof(mesh)
891885
}
892886
if (!is.null(group.mesh)) {
893-
inla.require.inherits(group.mesh, "inla.mesh.1d", "'mesh'")
887+
inla.require.inherits(group.mesh, "fm_mesh_1d", "'mesh'")
894888
}
895889

896890
n.group <-
@@ -936,7 +930,7 @@ inla.spde.make.A <-
936930
stop("'loc' specified but 'mesh' is NULL.")
937931
}
938932

939-
A.loc <- fmesher::fm_evaluator(mesh, loc = loc)$proj$A
933+
A.loc <- fmesher::fm_basis(mesh, loc = loc)
940934
}
941935
if (is.null(index)) {
942936
index <- seq_len(nrow(A.loc))
@@ -975,7 +969,7 @@ inla.spde.make.A <-
975969
}
976970

977971
if (!is.null(group.mesh) && is.null(A.group)) {
978-
A.group <- inla.mesh.1d.A(group.mesh, loc = group)
972+
A.group <- fmesher::fm_basis(group.mesh, loc = group)
979973
}
980974
## Now 'group.index' points into the rows of 'A.group' or 'group'
981975

rinla/R/spde2.R

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -768,25 +768,9 @@ inla.spde2.matern <- function(mesh,
768768
n.spde <- inla.ifelse(d == 2, mesh$n, mesh$m)
769769
n.theta <- ncol(B.kappa) - 1L
770770

771-
if (fmesher_deprecate_allow(2L)) {
772-
fem <- fmesher::fm_fem(fmesher::fm_as_fm(mesh), order = 2)
773-
if ((d == 1) && (mesh$degree == 2)) {
774-
fem$c0 <- fem$c1 ## Use higher order matrix.
775-
}
776-
} else {
777-
if (d == 2) {
778-
fem <-
779-
inla.fmesher.smorg(mesh$loc,
780-
mesh$graph$tv,
781-
fem = 2,
782-
output = list("c0", "c1", "g1", "g2")
783-
)
784-
} else {
785-
fem <- inla.mesh.1d.fem(mesh)
786-
if (mesh$degree == 2) {
787-
fem$c0 <- fem$c1 ## Use higher order matrix.
788-
}
789-
}
771+
fem <- fmesher::fm_fem(fmesher::fm_as_fm(mesh), order = 2)
772+
if ((d == 1) && (mesh$degree == 2)) {
773+
fem$c0 <- fem$c1 ## Use higher order matrix.
790774
}
791775

792776
if (alpha == 2) {
@@ -1315,11 +1299,11 @@ inla.spde2.iheat <- function(mesh.space,
13151299
## gamma.E and alpha.E known
13161300

13171301
inla.require.inherits(
1318-
mesh.space, c("inla.mesh", "inla.mesh.1d"),
1302+
mesh.space, c("fm_mesh_2d", "fm_mesh_1d"),
13191303
"'mesh.space'"
13201304
)
13211305
inla.require.inherits(
1322-
mesh.time, c("inla.mesh.1d"),
1306+
mesh.time, c("fm_mesh_1d"),
13231307
"'mesh.time'"
13241308
)
13251309

@@ -1332,22 +1316,22 @@ inla.spde2.iheat <- function(mesh.space,
13321316
## theta.prior.prec)
13331317
}
13341318

1335-
d.space <- inla.ifelse(inherits(mesh.space, "inla.mesh.1d"), 1, 2)
1336-
d.time <- 1
1337-
n.space <- inla.ifelse(d.space == 2, mesh.space$n, mesh.space$m)
1338-
n.time <- mesh.time$m
1319+
d.space <- fmesher::fm_manifold_dim(mesh.space)
1320+
d.time <- fmesher::fm_manifold_dim(mesh.time)
1321+
n.space <- fmesher::fm_dof(mesh.space)
1322+
n.time <- fmesher::fm_dof(mesh.time)
13391323
n.spde <- n.space * n.time
13401324
n.theta <- 2L ## gamma.s, gamma.t
13411325

13421326
if (d.space == 2) {
1343-
fem.space <- inla.mesh.fem(mesh.space$loc, 2)
1327+
fem.space <- fmesher::fm_fem(mesh.space, order = 2)
13441328
} else {
1345-
fem.space <- inla.mesh.1d.fem(mesh.space)
1329+
fem.space <- fmesher::fm_fem(mesh.space, order = 2)
13461330
if (mesh.space$degree == 2) {
13471331
fem.space$c0 <- fem.space$c1 ## Use higher order matrix.
13481332
}
13491333
}
1350-
fem.time <- inla.mesh.1d.fem(mesh.time)
1334+
fem.time <- fmesher::fm_fem(mesh.time, order = 2)
13511335
if (mesh.time$degree == 2) {
13521336
fem.time$c0 <- fem.time$c1 ## Use higher order matrix.
13531337
}

rinla/R/spde3.R

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -453,17 +453,9 @@ inla.spde3.matern =
453453
n.spde = inla.ifelse(d==2, mesh$n, mesh$m)
454454
n.theta = ncol(B.kappa)-1L
455455

456-
if (d==2) {
457-
fem =
458-
inla.fmesher.smorg(mesh$loc,
459-
mesh$graph$tv,
460-
fem=2,
461-
output=list("c0", "c1", "g1", "g2"))
462-
} else {
463-
fem = inla.mesh.1d.fem(mesh)
464-
if (mesh$degree==2) {
465-
fem$c0 = fem$c1 ## Use higher order matrix.
466-
}
456+
fem = fmesher::fm_fem(mesh, order = 2)
457+
if ((d==1) && (mesh$degree==2)) {
458+
fem$c0 = fem$c1 ## Use higher order matrix.
467459
}
468460

469461
if (alpha==2) {
@@ -605,22 +597,18 @@ inla.spde3.iheat =
605597
## theta.prior.prec)
606598
}
607599

608-
d.space = inla.ifelse(inherits(mesh.space, "inla.mesh.1d"), 1, 2)
600+
d.space = fmesher::fm_manifold_dim(mesh.space)
609601
d.time = 1
610-
n.space = inla.ifelse(d.space==2, mesh.space$n, mesh.space$m)
611-
n.time = mesh.time$m
602+
n.space = fmesher::fm_dof(mesh.space)
603+
n.time = fmesher::fm_dof(mesh.time)
612604
n.spde = n.space*n.time
613605
n.theta = 2L ## gamma.s, gamma.t
614606

615-
if (d.space==2) {
616-
fem.space = inla.mesh.fem(mesh.space$loc, 2)
617-
} else {
618-
fem.space = inla.mesh.1d.fem(mesh.space)
619-
if (mesh.space$degree==2) {
620-
fem.space$c0 = fem.space$c1 ## Use higher order matrix.
621-
}
607+
fem.space = fmesher::fm_fem(mesh.space, order = 2)
608+
if ((d.space==1) && (mesh.space$degree==2)) {
609+
fem.space$c0 = fem.space$c1 ## Use higher order matrix.
622610
}
623-
fem.time = inla.mesh.1d.fem(mesh.time)
611+
fem.time = fmesher::fm_fem(mesh.time, order = 2)
624612
if (mesh.time$degree==2) {
625613
fem.time$c0 = fem.time$c1 ## Use higher order matrix.
626614
}

0 commit comments

Comments
 (0)