-
Notifications
You must be signed in to change notification settings - Fork 1
/
phbs_cli.jl
134 lines (128 loc) · 3.27 KB
/
phbs_cli.jl
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using ArgParse
using MAT
using PortHamiltonianBenchmarkSystems
using LinearAlgebra
using SparseArrays
function parse_commandline()
s = ArgParseSettings()
@add_arg_table s begin
"pH_msd"
help = "pH-MSD benchmark"
action = :command
"poro"
help = "poro elasticity model"
action = :command
"--filename"
help = "pH-MSD benchmark"
default = "PHSystem.mat"
end
# Add config for MSD-Chain
@add_arg_table s["pH_msd"] begin
"--n_cells"
help = "number of msd cells"
default = 50
arg_type = Int
"--io_dim"
help = "dimension of the input/output"
default = 2
arg_type = Int
"--c"
help = "damping coefficients"
default = 1.0
arg_type = Float64
"--k"
help = "stiffnesses"
default = 4.0
arg_type = Float64
"--m"
help = "masses"
default = 4.0
arg_type = Float64
end
# Add config for Poro-Model
@add_arg_table s["poro"] begin
"--n"
default = 980
arg_type = Int
"--rho"
default = 1e-3
arg_type = Float64
"--alpha"
default = 0.79
arg_type = Float64
"--bm"
default = 1 / 7.80e3
arg_type = Float64
"--kappanu"
default = 633.33
arg_type = Float64
"--eta"
default = 1e-4
arg_type = Float64
end
return parse_args(s)
end
function save(pH::PHSystem, filename::String)
matwrite(
filename,
Dict([
"E" => save_as_matrix(pH.E),
"J" => save_as_matrix(pH.J),
"R" => save_as_matrix(pH.R),
"Q" => save_as_matrix(pH.Q),
"G" => save_as_matrix(pH.G),
"P" => save_as_matrix(pH.P),
"S" => save_as_matrix(pH.S),
"N" => save_as_matrix(pH.N),
]),
)
return nothing
end
function save_as_matrix(M::Matrix)
return M
end
function save_as_matrix(M::SparseMatrixCSC)
return M
end
function save_as_matrix(M::Diagonal)
return sparse(M)
end
function save_as_matrix(M)
return Array(M)
end
function pH_selector(parsed_args)
if parsed_args["%COMMAND%"] == "pH_msd"
config = SingleMSDConfig(
n_cells = parsed_args["pH_msd"]["n_cells"],
io_dim = parsed_args["pH_msd"]["io_dim"],
c = parsed_args["pH_msd"]["c"],
k = parsed_args["pH_msd"]["k"],
m = parsed_args["pH_msd"]["m"],
)
save(PHSystem(config), parsed_args["filename"])
return nothing
elseif parsed_args["%COMMAND%"] == "poro"
E, J, R, B = poro_elasticity_model(;
n=parsed_args["poro"]["n"],
rho=parsed_args["poro"]["rho"],
alpha=parsed_args["poro"]["alpha"],
bm=parsed_args["poro"]["bm"],
kappanu=parsed_args["poro"]["kappanu"],
eta=parsed_args["poro"]["eta"],
)
Q = I(size(E,1))
n, m = size(B)
P = spzeros(n, m)
S = spzeros(m, m)
N = spzeros(m, m)
save(PHSystem(E, J, R, Q, B, P, S, N), parsed_args["filename"])
return nothing
else
error("Unknown command: " + parsed_args["%COMMAND%"])
end
end
function main()
parsed_args = parse_commandline()
pH_selector(parsed_args)
end
main()