tilupy 0.1.5__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tilupy might be problematic. Click here for more details.
- {tilupy-0.1.5/src/tilupy.egg-info → tilupy-1.0.0}/PKG-INFO +1 -1
- {tilupy-0.1.5 → tilupy-1.0.0}/pyproject.toml +1 -1
- tilupy-1.0.0/src/tilupy/cmd.py +179 -0
- tilupy-1.0.0/src/tilupy/models/shaltop/initsimus.py +261 -0
- tilupy-1.0.0/src/tilupy/models/shaltop/read.py +455 -0
- tilupy-1.0.0/src/tilupy/notations.py +402 -0
- tilupy-1.0.0/src/tilupy/plot.py +827 -0
- tilupy-1.0.0/src/tilupy/read.py +982 -0
- tilupy-1.0.0/src/tilupy/utils.py +159 -0
- {tilupy-0.1.5 → tilupy-1.0.0/src/tilupy.egg-info}/PKG-INFO +1 -1
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy.egg-info/SOURCES.txt +3 -0
- tilupy-1.0.0/tests/test_notations.py +68 -0
- tilupy-1.0.0/tests/test_read.py +130 -0
- tilupy-1.0.0/tests/test_read_from_simu.py +103 -0
- tilupy-1.0.0/tests/test_shaltop.py +126 -0
- tilupy-0.1.5/src/tilupy/cmd.py +0 -125
- tilupy-0.1.5/src/tilupy/models/shaltop/initsimus.py +0 -149
- tilupy-0.1.5/src/tilupy/models/shaltop/read.py +0 -300
- tilupy-0.1.5/src/tilupy/notations.py +0 -117
- tilupy-0.1.5/src/tilupy/plot.py +0 -574
- tilupy-0.1.5/src/tilupy/read.py +0 -400
- tilupy-0.1.5/src/tilupy/utils.py +0 -131
- tilupy-0.1.5/tests/test_shaltop.py +0 -106
- {tilupy-0.1.5 → tilupy-1.0.0}/LICENSE +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/MANIFEST.in +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/README.md +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/data/frankslide/rasters/Frankslide_pile.asc +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/data/frankslide/rasters/Frankslide_topography.asc +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/setup.cfg +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/__init__.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/calibration.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/compare.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/download_data.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/initdata.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/make_mass.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/make_topo.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/models/__init__.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/models/ravaflow/__init__.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/models/ravaflow/initsimus.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/models/ravaflow/read.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/models/shaltop/__init__.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy/raster.py +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy.egg-info/dependency_links.txt +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy.egg-info/entry_points.txt +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy.egg-info/requires.txt +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/src/tilupy.egg-info/top_level.txt +0 -0
- {tilupy-0.1.5 → tilupy-1.0.0}/tests/test_generated_data.py +0 -0
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "tilupy"
|
|
9
|
-
version = "0.
|
|
9
|
+
version = "v1.0.0"
|
|
10
10
|
description = "Thin-layer models unified processing tool"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
authors = [{ name = "Marc Peruzzetto", email = "m.peruzzetto@brgm.fr" }]
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Created on Wed Jun 14 18:16:45 2023
|
|
4
|
+
|
|
5
|
+
@author: peruzzetto
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import tilupy.raster
|
|
9
|
+
import tilupy.read
|
|
10
|
+
|
|
11
|
+
import os
|
|
12
|
+
import argparse
|
|
13
|
+
import glob
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def process_results(
|
|
17
|
+
fn_name,
|
|
18
|
+
model,
|
|
19
|
+
res_name,
|
|
20
|
+
folder=None,
|
|
21
|
+
param_files=None,
|
|
22
|
+
kwargs_read=None,
|
|
23
|
+
**kwargs_fn
|
|
24
|
+
):
|
|
25
|
+
assert model is not None
|
|
26
|
+
|
|
27
|
+
if folder is None:
|
|
28
|
+
folder = os.getcwd()
|
|
29
|
+
|
|
30
|
+
if param_files is None:
|
|
31
|
+
param_files = "*.txt"
|
|
32
|
+
|
|
33
|
+
print(folder, param_files)
|
|
34
|
+
|
|
35
|
+
param_files = glob.glob(os.path.join(folder, param_files))
|
|
36
|
+
|
|
37
|
+
if len(param_files) == 0:
|
|
38
|
+
print("No parameter file matching param_files pattern was found")
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
if kwargs_read is None:
|
|
42
|
+
kwargs_read = dict()
|
|
43
|
+
|
|
44
|
+
kw_read = dict(folder_base=folder)
|
|
45
|
+
kw_read.update(kwargs_read)
|
|
46
|
+
|
|
47
|
+
for param_file in param_files:
|
|
48
|
+
print_str = "Processing simulation {:s}, {:s} {:s} ....."
|
|
49
|
+
print(print_str.format(param_file, fn_name, res_name))
|
|
50
|
+
kw_read["file_params"] = param_file
|
|
51
|
+
res = tilupy.read.get_results(model, **kw_read)
|
|
52
|
+
getattr(res, fn_name)(res_name, **kwargs_fn)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def to_raster(
|
|
56
|
+
model=None,
|
|
57
|
+
res_name="h",
|
|
58
|
+
param_files=None,
|
|
59
|
+
folder=None,
|
|
60
|
+
kwargs_read=None,
|
|
61
|
+
**kwargs
|
|
62
|
+
):
|
|
63
|
+
kw = dict(fmt="asc")
|
|
64
|
+
kw.update(kwargs)
|
|
65
|
+
|
|
66
|
+
process_results(
|
|
67
|
+
"save",
|
|
68
|
+
model,
|
|
69
|
+
res_name,
|
|
70
|
+
folder=folder,
|
|
71
|
+
param_files=param_files,
|
|
72
|
+
kwargs_read=kwargs_read,
|
|
73
|
+
**kw
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def plot_results(
|
|
78
|
+
model=None,
|
|
79
|
+
res_name="h",
|
|
80
|
+
param_files=None,
|
|
81
|
+
folder=None,
|
|
82
|
+
kwargs_read=None,
|
|
83
|
+
**kwargs
|
|
84
|
+
):
|
|
85
|
+
kw = dict(save=True)
|
|
86
|
+
kw.update(kwargs)
|
|
87
|
+
|
|
88
|
+
process_results(
|
|
89
|
+
"plot",
|
|
90
|
+
model,
|
|
91
|
+
res_name,
|
|
92
|
+
folder=folder,
|
|
93
|
+
param_files=param_files,
|
|
94
|
+
kwargs_read=kwargs_read,
|
|
95
|
+
**kwargs
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _get_parser(prog, description):
|
|
100
|
+
parser = argparse.ArgumentParser(
|
|
101
|
+
prog=prog,
|
|
102
|
+
description=description,
|
|
103
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
104
|
+
)
|
|
105
|
+
parser.add_argument("model", help="Model name", type=str)
|
|
106
|
+
parser.add_argument(
|
|
107
|
+
"-n",
|
|
108
|
+
"--res_name",
|
|
109
|
+
help="Name of output, only for maps",
|
|
110
|
+
default="h",
|
|
111
|
+
type=str,
|
|
112
|
+
)
|
|
113
|
+
parser.add_argument(
|
|
114
|
+
"-p",
|
|
115
|
+
"--param_files",
|
|
116
|
+
help="Parameter file (globbing)",
|
|
117
|
+
default="*.txt",
|
|
118
|
+
type=str,
|
|
119
|
+
)
|
|
120
|
+
parser.add_argument(
|
|
121
|
+
"-f",
|
|
122
|
+
"--folder",
|
|
123
|
+
help="Root folder, default is current folder",
|
|
124
|
+
default=None,
|
|
125
|
+
type=str,
|
|
126
|
+
)
|
|
127
|
+
return parser
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _tilupy_plot():
|
|
131
|
+
parser = _get_parser("tilupy_plot", "Plot thin-layer simulation results")
|
|
132
|
+
parser.add_argument(
|
|
133
|
+
"--fmt",
|
|
134
|
+
help=("Plot output format " "(any accepted by matplotlib.savefig)"),
|
|
135
|
+
default="png",
|
|
136
|
+
type=str,
|
|
137
|
+
)
|
|
138
|
+
parser.add_argument(
|
|
139
|
+
"--vmin",
|
|
140
|
+
help=("Minimum plotted value, " "adapted to data by default"),
|
|
141
|
+
default=None,
|
|
142
|
+
type=float,
|
|
143
|
+
)
|
|
144
|
+
parser.add_argument(
|
|
145
|
+
"--vmax",
|
|
146
|
+
help=("Maximum plotted value, " "adapted to data by default"),
|
|
147
|
+
default=None,
|
|
148
|
+
type=float,
|
|
149
|
+
)
|
|
150
|
+
parser.add_argument(
|
|
151
|
+
"--minval_abs",
|
|
152
|
+
help=("Minimum plotted absolute value," " adapted to data by default"),
|
|
153
|
+
default=None,
|
|
154
|
+
type=float,
|
|
155
|
+
)
|
|
156
|
+
args = parser.parse_args()
|
|
157
|
+
plot_results(**vars(args))
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _tilupy_to_raster():
|
|
161
|
+
parser = _get_parser(
|
|
162
|
+
"tilupy_to_raster", "Convert simulation results to rasters"
|
|
163
|
+
)
|
|
164
|
+
parser.add_argument(
|
|
165
|
+
"--fmt",
|
|
166
|
+
help=("File output format, " "tif/tiff requires rasterio"),
|
|
167
|
+
default="asc",
|
|
168
|
+
type=str,
|
|
169
|
+
choices=["tif", "tiff", "txt", "asc", "ascii"],
|
|
170
|
+
)
|
|
171
|
+
args = parser.parse_args()
|
|
172
|
+
# plot_results(parser.model, parser.res_name)
|
|
173
|
+
to_raster(**vars(args))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
if __name__ == "__main__":
|
|
177
|
+
# folder = 'd:/Documents/peruzzetto/tmp/test_shaltop/7p30e04_m3/coulomb'
|
|
178
|
+
# plot_results('shaltop', 'h_max', '*18p00.txt', folder=folder)
|
|
179
|
+
_tilupy_plot()
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Created on Tue May 25 15:18:31 2021
|
|
5
|
+
|
|
6
|
+
@author: peruzzetto
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
import posixpath
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from tilupy.utils import format_path_linux
|
|
14
|
+
|
|
15
|
+
import tilupy.notations
|
|
16
|
+
import tilupy.raster
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
README_PARAM_MATCH = dict(
|
|
20
|
+
tmax="tmax", CFL="cflhyp", h_min="eps0", dt_im_output="dt_im"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
SHALTOP_LAW_ID = dict(coulomb=1, voellmy=8, bingham=6, muI=7)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def write_params_file(params, directory=None, file_name="params.txt"):
|
|
27
|
+
"""
|
|
28
|
+
Write params file for shaltop simulations
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
params : TYPE
|
|
33
|
+
DESCRIPTION.
|
|
34
|
+
sup_data : TYPE, optional
|
|
35
|
+
DESCRIPTION. The default is {}.
|
|
36
|
+
directory : TYPE, optional
|
|
37
|
+
DESCRIPTION. The default is None.
|
|
38
|
+
file_name : TYPE, optional
|
|
39
|
+
DESCRIPTION. The default is 'params.txt'.
|
|
40
|
+
|
|
41
|
+
Returns
|
|
42
|
+
-------
|
|
43
|
+
None.
|
|
44
|
+
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
if directory is None:
|
|
48
|
+
directory = os.getcwd()
|
|
49
|
+
with open(os.path.join(directory, file_name), "w") as file_params:
|
|
50
|
+
for name in params:
|
|
51
|
+
val = params[name]
|
|
52
|
+
if isinstance(val, int) or isinstance(val, np.int64):
|
|
53
|
+
file_params.write("{:s} {:d}\n".format(name, val))
|
|
54
|
+
if isinstance(val, float) or isinstance(val, np.float64):
|
|
55
|
+
file_params.write("{:s} {:.8G}\n".format(name, val))
|
|
56
|
+
if isinstance(val, str):
|
|
57
|
+
file_params.write("{:s} {:s}\n".format(name, val))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def raster_to_shaltop_txtfile(file_in, file_out, folder_out=None):
|
|
61
|
+
if folder_out is not None:
|
|
62
|
+
file_out = os.path.join(folder_out, file_out)
|
|
63
|
+
|
|
64
|
+
x, y, rast = tilupy.raster.read_raster(file_in)
|
|
65
|
+
np.savetxt(
|
|
66
|
+
file_out,
|
|
67
|
+
np.reshape(np.flip(rast, axis=0), (rast.size, 1)),
|
|
68
|
+
fmt="%.12G",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
res = dict(
|
|
72
|
+
x0=x[0], y0=y[0], dx=x[1] - x[0], dy=y[1] - y[0], nx=len(x), ny=len(y)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return res
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def write_job_files(
|
|
79
|
+
dirs,
|
|
80
|
+
param_files,
|
|
81
|
+
file_job,
|
|
82
|
+
job_name,
|
|
83
|
+
max_time_hours=24,
|
|
84
|
+
ncores_per_node=6,
|
|
85
|
+
partitions="cpuall,data,datanew",
|
|
86
|
+
shaltop_file="shaltop",
|
|
87
|
+
folder_conf_in_job=None,
|
|
88
|
+
replace_path=None,
|
|
89
|
+
number_conf_file=True,
|
|
90
|
+
):
|
|
91
|
+
"""
|
|
92
|
+
Write job/conf files for slurm jobs. The conf contains all the commands
|
|
93
|
+
needed to run each simulation (one command per simulation).
|
|
94
|
+
|
|
95
|
+
Parameters
|
|
96
|
+
----------
|
|
97
|
+
dirs : list of string
|
|
98
|
+
list of paths where simus will be run.
|
|
99
|
+
param_files : list string
|
|
100
|
+
list of shaltop parameter files.
|
|
101
|
+
file_job : string
|
|
102
|
+
name of job file called by sbatch.
|
|
103
|
+
job_name : string
|
|
104
|
+
name of conf file used by file_job.
|
|
105
|
+
max_time_hours : int, optional
|
|
106
|
+
Maximum job duration in hours before stop. The default is 24.
|
|
107
|
+
ncores_per_node : int, optional
|
|
108
|
+
Number of cores per nodes. Used to know the number of nodes required
|
|
109
|
+
for the job. The default is 6.
|
|
110
|
+
partitions : string, optional
|
|
111
|
+
Names of partitions on which jobs can be launched.
|
|
112
|
+
The default is "cpuall,data,datanew".
|
|
113
|
+
shaltop_file : string, optional
|
|
114
|
+
Bash command used to call shaltop. Can be a path.
|
|
115
|
+
The default is "shaltop".
|
|
116
|
+
folder_conf_in_job : string, optional
|
|
117
|
+
Folder where the conf file is located. The default is the folder
|
|
118
|
+
path of file_job.
|
|
119
|
+
replace_path : list, optional
|
|
120
|
+
replace replace_path[0] by replace_path[1] for every path in dir. This
|
|
121
|
+
is used if simulations are prepared and run on two different machines
|
|
122
|
+
(e.g. laptop and cluster).
|
|
123
|
+
The default is None.
|
|
124
|
+
number_conf_file : bool, optional
|
|
125
|
+
If True, add a number in front of each line of the conf file. Required
|
|
126
|
+
to identify slurm jobs.
|
|
127
|
+
The default is True.
|
|
128
|
+
|
|
129
|
+
Returns
|
|
130
|
+
-------
|
|
131
|
+
None.
|
|
132
|
+
|
|
133
|
+
"""
|
|
134
|
+
ntasks = len(dirs)
|
|
135
|
+
nnodes = int(np.ceil(ntasks / ncores_per_node))
|
|
136
|
+
|
|
137
|
+
if folder_conf_in_job is None:
|
|
138
|
+
folder_conf_in_job = os.path.dirname(file_job)
|
|
139
|
+
if folder_conf_in_job == "":
|
|
140
|
+
folder_conf_in_job = "."
|
|
141
|
+
|
|
142
|
+
with open(file_job + ".conf", "w", newline="\n") as conf_file:
|
|
143
|
+
if number_conf_file:
|
|
144
|
+
line = "{:d} {:s} {:s} {:s}\n"
|
|
145
|
+
else:
|
|
146
|
+
line = "{:s} {:s} {:s}\n"
|
|
147
|
+
for i in range(ntasks):
|
|
148
|
+
if replace_path is not None:
|
|
149
|
+
folder = dirs[i].replace(replace_path[0], replace_path[1])
|
|
150
|
+
param_file = param_files[i].replace(
|
|
151
|
+
replace_path[0], replace_path[1]
|
|
152
|
+
)
|
|
153
|
+
else:
|
|
154
|
+
folder = dirs[i]
|
|
155
|
+
param_file = param_files[i]
|
|
156
|
+
folder = format_path_linux(folder)
|
|
157
|
+
param_file = format_path_linux(param_file)
|
|
158
|
+
if number_conf_file:
|
|
159
|
+
line2 = line.format(i, shaltop_file, folder, param_file)
|
|
160
|
+
else:
|
|
161
|
+
line2 = line.format(shaltop_file, folder, param_file)
|
|
162
|
+
conf_file.write(line2)
|
|
163
|
+
|
|
164
|
+
n_hours = np.floor(max_time_hours)
|
|
165
|
+
n_min = (max_time_hours - n_hours) * 60
|
|
166
|
+
str_time = "{:02.0f}:{:02.0f}:00\n".format(n_hours, n_min)
|
|
167
|
+
|
|
168
|
+
basename = os.path.basename(file_job)
|
|
169
|
+
path_conf_in_job = posixpath.join(folder_conf_in_job, basename + ".conf")
|
|
170
|
+
|
|
171
|
+
with open(file_job + ".job", "w", newline="\n") as job_file:
|
|
172
|
+
job_file.write("#!/bin/sh\n")
|
|
173
|
+
job_file.write("#SBATCH -J multijob\n")
|
|
174
|
+
job_file.write("#SBATCH --job-name={:s}\n".format(job_name))
|
|
175
|
+
job_file.write("#SBATCH --output={:s}%j.out\n".format(job_name))
|
|
176
|
+
job_file.write("#SBATCH --partition " + partitions + "\n")
|
|
177
|
+
job_file.write("#SBATCH --nodes={:d}".format(nnodes) + "\n")
|
|
178
|
+
job_file.write("#SBATCH --ntasks={:d}".format(ntasks) + "\n")
|
|
179
|
+
job_file.write("#SBATCH --time={:s}\n".format(str_time))
|
|
180
|
+
job_file.write("\n")
|
|
181
|
+
job_file.write("module purge\n")
|
|
182
|
+
job_file.write("module load slurm\n")
|
|
183
|
+
job_file.write("\n")
|
|
184
|
+
line = "srun -n {:d} -l --multi-prog {:s}"
|
|
185
|
+
job_file.write(line.format(ntasks, path_conf_in_job))
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def make_simus(law, rheol_params, folder_data, folder_out, readme_file):
|
|
189
|
+
"""
|
|
190
|
+
Write shaltop initial file for simple slope test case
|
|
191
|
+
|
|
192
|
+
Parameters
|
|
193
|
+
----------
|
|
194
|
+
deltas : TYPE
|
|
195
|
+
DESCRIPTION.
|
|
196
|
+
folder_in : TYPE
|
|
197
|
+
DESCRIPTION.
|
|
198
|
+
folder_out : TYPE
|
|
199
|
+
DESCRIPTION.
|
|
200
|
+
|
|
201
|
+
Returns
|
|
202
|
+
-------
|
|
203
|
+
None.
|
|
204
|
+
|
|
205
|
+
"""
|
|
206
|
+
# Get topography and initial mass, and write them in Shaltop format
|
|
207
|
+
zfile = os.path.join(folder_data, "topo.asc")
|
|
208
|
+
mfile = os.path.join(folder_data, "mass.asc")
|
|
209
|
+
x, y, z, dx = tilupy.raster.read_ascii(zfile)
|
|
210
|
+
_, _, m, _ = tilupy.raster.read_ascii(mfile)
|
|
211
|
+
np.savetxt(os.path.join(folder_out, "z.d"), z.T.flatten())
|
|
212
|
+
np.savetxt(os.path.join(folder_out, "m.d"), m.T.flatten())
|
|
213
|
+
|
|
214
|
+
# Get simulation parameters from README.txt and raster .asc files
|
|
215
|
+
params = tilupy.notations.readme_to_params(readme_file, README_PARAM_MATCH)
|
|
216
|
+
params["nx"] = len(x)
|
|
217
|
+
params["ny"] = len(y)
|
|
218
|
+
params["per"] = dx * len(x)
|
|
219
|
+
params["pery"] = dx * len(y)
|
|
220
|
+
params["file_m_init"] = "../m.d"
|
|
221
|
+
params["file_z_init"] = "../z.d"
|
|
222
|
+
|
|
223
|
+
# Folder for rheological law, and set params accordingly
|
|
224
|
+
folder_law = os.path.join(folder_out, law)
|
|
225
|
+
params["icomp"] = SHALTOP_LAW_ID[law]
|
|
226
|
+
|
|
227
|
+
param_names = [param for param in rheol_params]
|
|
228
|
+
|
|
229
|
+
texts = tilupy.notations.make_rheol_string(rheol_params, law)
|
|
230
|
+
|
|
231
|
+
# Run shaltop file
|
|
232
|
+
run_shaltop_file = os.path.join(folder_law, "run_shaltop.sh")
|
|
233
|
+
file_txt = ""
|
|
234
|
+
|
|
235
|
+
for i in range(len(rheol_params[param_names[0]])):
|
|
236
|
+
simu_text = texts[i]
|
|
237
|
+
for param_name in param_names:
|
|
238
|
+
params[param_name] = rheol_params[param_name][i]
|
|
239
|
+
params["folder_output"] = simu_text
|
|
240
|
+
folder_results = os.path.join(folder_law, simu_text)
|
|
241
|
+
os.makedirs(folder_results, exist_ok=True)
|
|
242
|
+
with open(os.path.join(folder_results, ".gitignore"), "w") as fid:
|
|
243
|
+
fid.write("# Ignore everything in this directory")
|
|
244
|
+
fid.write("*")
|
|
245
|
+
fid.write("# Except this file")
|
|
246
|
+
fid.write("!.gitignore")
|
|
247
|
+
|
|
248
|
+
write_params_file(
|
|
249
|
+
params, directory=folder_law, file_name=simu_text + ".txt"
|
|
250
|
+
)
|
|
251
|
+
file_txt += "start_time=`date +%s`\n"
|
|
252
|
+
file_txt += 'shaltop "" ' + simu_text + ".txt\n"
|
|
253
|
+
file_txt += "end_time=`date +%s`\n"
|
|
254
|
+
file_txt += "elapsed_time=$(($end_time - $start_time))\n"
|
|
255
|
+
file_txt += (
|
|
256
|
+
'string_time="${start_time} ' + simu_text + ' ${elapsed_time}"\n'
|
|
257
|
+
)
|
|
258
|
+
file_txt += "echo ${string_time} >> simulation_duration.txt\n\n"
|
|
259
|
+
|
|
260
|
+
with open(run_shaltop_file, "w") as fid:
|
|
261
|
+
fid.write(file_txt)
|