forked from douglask3/PhenologyModels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpringTests.r
executable file
·72 lines (57 loc) · 2.63 KB
/
SpringTests.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
##########################################################################################
## cfg ##
##########################################################################################
source("cfg.r")
sourceAllLibs("springs")
sourceAllLibs("forces/forcing")
sourceAllLibs("forces/springs")
sourceAllLibs("forces/viscous")
source("springDynamics.r")
##########################################################################################
## Set up parameters ##
##########################################################################################
## For model
nt=400; dt=0.1;
Fw=1; m=1; k=1;
## For plot
cols=c("green","brown","yellow","blue","cyan","cyan",'cyan')
ltys=c(1,1,1,1,2,3,4)
##########################################################################################
## Open Figure ##
##########################################################################################
pdf("figs/Springs.pdf",height=18,width=18)
lmat=matrix(1:(6*4),6,4)
lmat=rbind(lmat,rep((6*4)+1,4))
layout(lmat,height=c(rep(1,6),0.7))
###########################################################################################
## Run tests ##
###########################################################################################
## For each spring type, run 4 tests:
springDynamicss <- function(...) {
FUN <- function(...) springDynamics(ltys=ltys,cols=cols,...)
# 1. constant force; no viscocity
FUN(...)
# 2. dampened force; no viscocity
FUN(waterFun='Dampend',...)
# 3. constant force, with viscocity
FUN(visocityFun='SpatiallyConstant',...)
# 4. dampened force, with viscocity
FUN(waterFun='Dampend',visocityFun='SpatiallyConstant',...)
# 5. constnat force, with varying viscocity
FUN(visocityFun='SpatiallyVarying',...)
# 6. dampened force, with varying viscocity
FUN(waterFun='Dampend',visocityFun='SpatiallyVarying',...)
}
## Hookes 1 spring ##
springDynamicss()
## Hookes 2 spring ##
springDynamicss(TRUE)
## Non-Linear ##
springDynamicss(springFUN='exponentialSpring')
## Non-Linear ##
springDynamicss(TRUE,springFUN='exponentialSpring')
plot.new()
legend('topleft',legend=c('Phenology','Inertia','Acceleration',"Overall Force",
"Water forcing","Resistance Force","Viscous Force"),
lty=ltys,col=cols,horiz=TRUE,xpd=TRUE)
dev.off()