Skip to content

Commit 215f207

Browse files
create script for automatically moving tian parameters in the input file
1 parent b7da80c commit 215f207

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
""" This script reformats the given .prm files to move the Tian 2019 reaction
5+
mode parameters to the correct subsection.
6+
"""
7+
8+
import sys
9+
import os
10+
import re
11+
import argparse
12+
13+
__author__ = 'The authors of the ASPECT code'
14+
__copyright__ = 'Copyright 2024, ASPECT'
15+
__license__ = 'GNU GPL 2 or later'
16+
17+
# Add the ASPECT root directory to the path so we can import from the aspect_data module
18+
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
19+
import python.scripts.aspect_input as aspect
20+
21+
22+
23+
def create_tian2019_reaction_subsection(parameters):
24+
""" Move the Tian 2019 reaction parameters to their own subsection. """
25+
26+
27+
parameters_to_move = ["Maximum weight percent water in sediment", \
28+
"Maximum weight percent water in MORB", \
29+
"Maximum weight percent water in gabbro", \
30+
"Maximum weight percent water in peridotite"]
31+
32+
# Collect existing parameters and delete old entries
33+
reactive_fluid_params = dict({})
34+
if "Reactive Fluid Transport Model" in parameters["Material model"]["value"]:
35+
reactive_fluid_params = parameters["Material model"]["value"]["Reactive Fluid Transport Model"]
36+
for param in parameters_to_move:
37+
if "Tian 2019 model" not in reactive_fluid_params["value"]:
38+
reactive_fluid_params["value"]["Tian 2019 model"] = {"comment": "", "value" : dict({}), "type": "subsection"}
39+
40+
if param in reactive_fluid_params["value"]:
41+
reactive_fluid_params["value"]["Tian 2019 model"]["value"][param] = reactive_fluid_params["value"][param]
42+
del reactive_fluid_params["value"][param]
43+
44+
return parameters
45+
46+
47+
48+
def main(input_file, output_file):
49+
"""Echo the input arguments to standard output"""
50+
parameters = aspect.read_parameter_file(input_file)
51+
52+
parameters = create_tian2019_reaction_subsection(parameters)
53+
54+
aspect.write_parameter_file(parameters, output_file)
55+
56+
57+
58+
if __name__ == '__main__':
59+
parser = argparse.ArgumentParser(
60+
prog='ASPECT .prm file reformatter',
61+
description='Reformats ASPECT .prm files to follow our general formatting guidelines. See the documentation of this script for details.')
62+
parser.add_argument('input_file', type=str, help='The .prm file to reformat')
63+
parser.add_argument('output_file', type=str, help='The .prm file to write the reformatted file to')
64+
args = parser.parse_args()
65+
66+
sys.exit(main(args.input_file, args.output_file))

0 commit comments

Comments
 (0)